Skip to content

Commit 36e25f7

Browse files
committed
Add GetItemNames project
1 parent 3ca46a3 commit 36e25f7

7 files changed

Lines changed: 216 additions & 10 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
<ReleaseVersion>0.1.3</ReleaseVersion>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\..\TibiaAPI\TibiaAPI.csproj" />
11+
</ItemGroup>
12+
13+
</Project>

Apps/GetItemNames/Program.cs

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
using System;
2+
using System.Text;
3+
using OXGaming.TibiaAPI;
4+
using OXGaming.TibiaAPI.Constants;
5+
using OXGaming.TibiaAPI.Network.ClientPackets;
6+
using OXGaming.TibiaAPI.Network.ServerPackets;
7+
8+
namespace DumpItems
9+
{
10+
class Message
11+
{
12+
public byte[] Data { get; set; }
13+
14+
public long Timestamp { get; set; }
15+
16+
public PacketType Type { get; set; }
17+
}
18+
19+
class Program
20+
{
21+
static Client _client;
22+
23+
static string _tibiaDirectory = "<path to your tibia installation>/packages/Tibia";
24+
25+
public class GetObjectIdAndName : GetObjectInfo
26+
{
27+
public GetObjectIdAndName(Client client, ushort from, ushort to) : base(client)
28+
{
29+
Client = client;
30+
PacketType = ClientPacketType.GetObjectInfo;
31+
32+
for (ushort i = from; i < to; ++i)
33+
{
34+
Objects.Add((i, 0));
35+
}
36+
}
37+
}
38+
39+
40+
private static void SendItemNamesRequests()
41+
{
42+
StringBuilder sb = new StringBuilder();
43+
44+
const ushort MaxObjectsPerPacket = 255;
45+
46+
ushort start = 100;
47+
ushort end = Convert.ToUInt16(_client.AppearanceStorage.LastObjectId + 1);
48+
49+
ushort from = start;
50+
ushort to = Convert.ToUInt16(Math.Min(from + MaxObjectsPerPacket, end));
51+
52+
Console.WriteLine("Last object ID: " + (end - 1));
53+
54+
_client.Connection.OnReceivedServerObjectInfoPacket += (packet) =>
55+
{
56+
var objectInfoPacket = (ObjectInfo)packet;
57+
58+
Console.WriteLine($"Received ids {from}-{to}");
59+
60+
foreach (var (Id, _, Name) in objectInfoPacket.Objects)
61+
{
62+
if (!string.IsNullOrEmpty(Name))
63+
{
64+
sb.AppendLine($"[{Id}] {Name}");
65+
}
66+
}
67+
68+
if (to != end)
69+
{
70+
from = to;
71+
to = Convert.ToUInt16(Math.Min(from + MaxObjectsPerPacket, end));
72+
73+
var nextPacket = new GetObjectIdAndName(_client, from, to);
74+
_client.Connection.SendToServer(nextPacket);
75+
}
76+
else
77+
{
78+
System.IO.File.WriteAllText(@"./item_names.txt", sb.ToString());
79+
Console.WriteLine("Done. Item names have been written to ./item_names.txt.");
80+
}
81+
82+
return true;
83+
};
84+
85+
var firstPacket = new GetObjectIdAndName(_client, from, to);
86+
_client.Connection.SendToServer(firstPacket);
87+
}
88+
89+
static void Main(string[] args)
90+
{
91+
try
92+
{
93+
using (_client = new Client(_tibiaDirectory))
94+
{
95+
_client.Connection.IsServerPacketModificationEnabled = false;
96+
_client.serverMessageParseFilter.Add(ServerPacketType.ObjectInfo);
97+
_client.StartConnection();
98+
99+
Console.WriteLine(@"Usage:
100+
1. Start this program (already done).
101+
2. Login to a Tibia server that is not protected by Battleye (Zuna/Zunera)
102+
3. Write 'send' in this terminal once your character is online.
103+
");
104+
105+
bool exit = false;
106+
while (!exit)
107+
{
108+
var input = Console.ReadLine();
109+
switch (input)
110+
{
111+
case "send":
112+
SendItemNamesRequests();
113+
break;
114+
case "quit":
115+
exit = true;
116+
break;
117+
default:
118+
break;
119+
}
120+
}
121+
}
122+
}
123+
catch (Exception ex)
124+
{
125+
Console.WriteLine(ex);
126+
}
127+
finally
128+
{
129+
Shutdown();
130+
}
131+
}
132+
133+
134+
private static void Shutdown()
135+
{
136+
if (_client != null)
137+
{
138+
_client.StopConnection();
139+
}
140+
141+
}
142+
}
143+
}

Apps/GetItemNames/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Get Tibia item names
2+
3+
## 1 Compilation
4+
5+
1. Open `TibiaAPI.sln` in Visual Studio
6+
2. In `./Apps/GetItemNames/Program.cs:21`, update `_tibiaDirectory = "<path to your tibia installation>/packages/Tibia"` to match your tibia directory
7+
3. Build the solution (change to Release mode for faster runtime execution)
8+
9+
## 2 Modifying the client to connect to our proxy
10+
11+
1. Open `<path to your tibia installation>/packages/Tibia/bin/client.exe` in a text editor
12+
2. Replace the Tibia RSA
13+
14+
`BC27F992A96B8E2A43F4DFBE1CEF8FD51CF43D2803EE34FBBD8634D8B4FA32F7D9D9E159978DD29156D62F4153E9C5914263FC4986797E12245C1A6C4531EFE48A6F7C2EFFFFF18F2C9E1C504031F3E4A2C788EE96618FFFCEC2C3E5BFAFAF743B3FC7A872EE60A52C29AA688BDAF8692305312882F1F66EE9D8AEB7F84B1949`
15+
16+
with the OpenTibia RSA
17+
18+
`9B646903B45B07AC956568D87353BD7165139DD7940703B03E6DD079399661B4A837AA60561D7CCB9452FA0080594909882AB5BCA58A1A1B35F8B1059B72B1212611C6152AD3DBB3CFBEE7ADC142A75D3D75971509C321C5C24A5BD51FD460F01B4E15BEB0DE1930528A5D3F15C1E3CBF5C401D6777E10ACAAB33DBE8D5B7FF5`
19+
3. Search for the line with `loginWebService` and replace it with
20+
21+
`loginWebService=http://127.0.0.1:7171/ `
22+
23+
## 3 Generating the item name list
24+
25+
1. Start your tibia client using `<path to your tibia installation>/packages/Tibia/bin/client.exe --battleye`
26+
2. From the project root, navigate to `./Apps/GetItemNames/bin/Release/netcoreapp3.1`
27+
3. In that directory, run `./GetItemNames.exe`
28+
4. Connect to a game world that is not BattlEye protected (Zuna/Zunera)
29+
5. Write `send` in the terminal window

TibiaAPI.sln

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.28010.2003
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31320.298
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TibiaAPI", "TibiaAPI\TibiaAPI.csproj", "{FEDE2A7B-8203-443E-9CF7-97A562AABB92}"
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Apps", "Apps", "{C086BFA7-CE77-4DDF-9474-C65709DBA8A8}"
99
EndProject
10-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Extract", "Apps\Extract\Extract.csproj", "{EE3A6146-B1A6-44F0-9C5D-CBD5D44CEF83}"
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Extract", "Apps\Extract\Extract.csproj", "{EE3A6146-B1A6-44F0-9C5D-CBD5D44CEF83}"
1111
EndProject
12-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Record", "Apps\Record\Record.csproj", "{75DB22C7-8FE1-4BF6-8778-AE67B236DFED}"
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Record", "Apps\Record\Record.csproj", "{75DB22C7-8FE1-4BF6-8778-AE67B236DFED}"
1313
EndProject
14-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Watch", "Apps\Watch\Watch.csproj", "{D9E8B07D-C3D8-431D-8E1C-B52EE2AF49C9}"
14+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Watch", "Apps\Watch\Watch.csproj", "{D9E8B07D-C3D8-431D-8E1C-B52EE2AF49C9}"
1515
EndProject
16-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Redact", "Apps\Redact\Redact.csproj", "{F9D5BF93-D832-4AA0-9B1E-2FAE3E5235A2}"
16+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Redact", "Apps\Redact\Redact.csproj", "{F9D5BF93-D832-4AA0-9B1E-2FAE3E5235A2}"
17+
EndProject
18+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetItemNames", "Apps\GetItemNames\GetItemNames.csproj", "{BA342F96-99DD-42C1-A7E5-4B199B48D42F}"
19+
ProjectSection(ProjectDependencies) = postProject
20+
{FEDE2A7B-8203-443E-9CF7-97A562AABB92} = {FEDE2A7B-8203-443E-9CF7-97A562AABB92}
21+
EndProjectSection
1722
EndProject
1823
Global
1924
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -41,6 +46,10 @@ Global
4146
{F9D5BF93-D832-4AA0-9B1E-2FAE3E5235A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
4247
{F9D5BF93-D832-4AA0-9B1E-2FAE3E5235A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
4348
{F9D5BF93-D832-4AA0-9B1E-2FAE3E5235A2}.Release|Any CPU.Build.0 = Release|Any CPU
49+
{BA342F96-99DD-42C1-A7E5-4B199B48D42F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
50+
{BA342F96-99DD-42C1-A7E5-4B199B48D42F}.Debug|Any CPU.Build.0 = Debug|Any CPU
51+
{BA342F96-99DD-42C1-A7E5-4B199B48D42F}.Release|Any CPU.ActiveCfg = Release|Any CPU
52+
{BA342F96-99DD-42C1-A7E5-4B199B48D42F}.Release|Any CPU.Build.0 = Release|Any CPU
4453
EndGlobalSection
4554
GlobalSection(SolutionProperties) = preSolution
4655
HideSolutionNode = FALSE
@@ -50,6 +59,7 @@ Global
5059
{75DB22C7-8FE1-4BF6-8778-AE67B236DFED} = {C086BFA7-CE77-4DDF-9474-C65709DBA8A8}
5160
{D9E8B07D-C3D8-431D-8E1C-B52EE2AF49C9} = {C086BFA7-CE77-4DDF-9474-C65709DBA8A8}
5261
{F9D5BF93-D832-4AA0-9B1E-2FAE3E5235A2} = {C086BFA7-CE77-4DDF-9474-C65709DBA8A8}
62+
{BA342F96-99DD-42C1-A7E5-4B199B48D42F} = {C086BFA7-CE77-4DDF-9474-C65709DBA8A8}
5363
EndGlobalSection
5464
GlobalSection(ExtensibilityGlobals) = postSolution
5565
SolutionGuid = {779085CF-5BE0-48BA-A204-511A8914A67C}

TibiaAPI/Appearances/AppearanceStorage.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ public class AppearanceStorage
99
{
1010
private Utilities.Appearances appearances;
1111

12-
private uint lastObjectId;
12+
public uint LastObjectId { get; private set; }
1313
private uint lastOutfitId;
1414

1515
public void LoadAppearances(FileStream datFileStream)
1616
{
1717
appearances = Utilities.Appearances.Parser.ParseFrom(datFileStream);
18-
lastObjectId = appearances.Object.Aggregate((last, current) => last.Id > current.Id ? last : current).Id;
18+
LastObjectId = appearances.Object.Aggregate((last, current) => last.Id > current.Id ? last : current).Id;
1919
lastOutfitId = appearances.Outfit.Aggregate((last, current) => last.Id > current.Id ? last : current).Id;
2020
}
2121

2222
public ObjectInstance CreateObjectInstance(uint id, uint data)
2323
{
24-
if (id >= (uint)CreatureInstanceType.Creature && id <= lastObjectId)
24+
if (id >= (uint)CreatureInstanceType.Creature && id <= LastObjectId)
2525
{
2626
return new ObjectInstance(id, appearances.Object.FirstOrDefault(i => i.Id == id), data);
2727
}
@@ -39,7 +39,7 @@ public OutfitInstance CreateOutfitInstance(uint id, byte colorHead, byte colorTo
3939

4040
public Utilities.Appearance GetObjectType(uint id)
4141
{
42-
if (id > (uint)CreatureInstanceType.Creature && id <= lastObjectId)
42+
if (id > (uint)CreatureInstanceType.Creature && id <= LastObjectId)
4343
{
4444
return appearances.Object.FirstOrDefault(o => o.Id == id);
4545
}

TibiaAPI/Client.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
using System;
22
using System.IO;
33
using System.Runtime.InteropServices;
4+
using System.Collections.Generic;
45

56
namespace OXGaming.TibiaAPI
67
{
78
public class Client : IDisposable
89
{
910
private string _appearanceDatFile;
1011

12+
public HashSet<Constants.ServerPacketType> serverMessageParseFilter { get; } = new HashSet<Constants.ServerPacketType>();
13+
1114
public Appearances.AppearanceStorage AppearanceStorage { get; } = new Appearances.AppearanceStorage();
1215

1316
public Creatures.CreatureStorage CreatureStorage { get; } = new Creatures.CreatureStorage();

TibiaAPI/Network/Communication.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,14 @@ public void ParseServerMessage(Client client, NetworkMessage inMessage, NetworkM
881881
var opcode = inMessage.ReadByte();
882882
currentPacket = (ServerPacketType)opcode;
883883

884+
if (client.serverMessageParseFilter.Count > 0)
885+
{
886+
if (!client.serverMessageParseFilter.Contains(currentPacket))
887+
{
888+
return;
889+
}
890+
}
891+
884892
client.Logger.Debug($"[SERVER:{inMessage.SequenceNumber}] {opcode:X2} - {currentPacket}");
885893

886894
var packet = ServerPacket.CreateInstance(client, currentPacket);

0 commit comments

Comments
 (0)