Log in

View Full Version : Easily change packet structure in source (Fix for some OT servers)



Tony32
01-29-2015, 18:14
Hey Daniel, this is most likely a proposal that'll never be done, but here it is x)

A lot of OTs use different packets for actions in their custom clients
for example, if let's say the walk packet is normally 26, they might change it to 27 or something totally different. Some OT's have moved around/scrambled the packet structure totally.

I've managed to make blackD work with every OT so far, but it is REALLY REALLY tedious to change all packets/packetstructures as the same code is allover the place.

For example, using a rune on a creature, is coded in magebomb, warbot and the core, so making it work on all three places I must change the packets and its structure on all places. Think how much work it is to change every packet and structure needed to play/bot on Tibia for every action done by the bot multiple times and places in the source code.

So basicly I would like you to make the packet structure easily configured at one place.

So if use rune on X Y Z is normally for example:
26 ID ID XX YY ZZ (where 26 is use item, ID = itemid, followed by XYZ)

Then some ot's have changed the order and packettype to something like this:
26 XX ZZ YY ID ID
Sometimes some 0's as well.

I hope you understand what I mean, but making it easy to change all the packets and its structure in one place, would make it a thousand times easier to make BlackD work on any OT :)

Thanks

oclipper
01-29-2015, 21:45
i had the same problem with sillent cores ot (custom 10.41) and also classicus (7.x).

Hans Henrik
06-13-2015, 13:26
i had this exact problem myself, here's how i fixed it:
i made a packet filter, that, if matched, would replace a known packet with another,




Public Function HHBFilter(ByRef Bytes() As Byte)

Dim count As Integer
count = UBound(Bytes)
Dim buf() As Byte
'<HellKaiser123766>
GetCheatPacket buf, "27 00 0A 02 00 F8 02 00 71 B6 02 00 0F 00 4 0A 00 66 6F 78 6B 69 64 73 38 39 38"
If ComparePackets(Bytes, buf) Then
GetCheatPacket Bytes, "C9 00 0A 03 64 F2 FF 07 00 66 75 63 6B 68 6B 47 67 45 32 4C 32 34 48 61 69 4C 48 76 73 51 59 43 67 3D F7 02 00 71 B6 02 00 0F 00 48 65 6C 6C 20 4B 61 69 0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
Exit Function
End If
GetCheatPacket buf, "04 00 A0 02 00 01"
If ComparePackets(Bytes, buf) Then
GetCheatPacket Bytes, "04 00 A0 02 00 01 03 00 98 03 00 03 00 98 03 00 98 04 00 "
Exit Function
End If
'</HellKaiser123766>

'<RedArrow181939>
'GetCheatPacket buf, "27 00 0A 02 4B 61 69 73 65 72 20 52 79 6F 0A 00 70 61 73 73 77 6F 72 64 64 64"
GetCheatPacket buf, "21 00 0A 02 00 72 6F 77 0A 00 70 61 73 73 77 6F 72 64 64 64 "
'TODO^
If ComparePackets(Bytes, buf) Then
GetCheatPacket Bytes, "C9 00 0A 03 64 F2 FF 07 00 66 75 63 6B 67 6A 72 49 45 70 6F 77 6F 4B 46 6B 66 72 69 72 47 4A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
'FIXED^
Exit Function
End If
'</RedArrow181939&>

End Function


etc. if it finds a packet it KNOWS has changed, it will modify it right before sending it to the client or server. then

HHBFilter packet
sckServer(Index).SendData packet


HHBFilter packet
sckClientGame(Index).SendData packet


HHBFilter goodPacket
SckClient(Index).SendData goodPacket


HHBFilter ReconnectionPacket(Index).packet

frmMain.sckServerGame(Index).SendData ReconnectionPacket(Index).packet


frmMain.HHBFilter goodPacket
clientLess(Index).SendData goodPacket

and its working great. now no need to modify other parts of the code :p everything sent to the client or the server will go through this filter.



Note: This example works for outcastserver.com

Hans Henrik
02-06-2016, 21:02
wups, i forgot the accompanying function ComparePackets



Private Declare Function RtlCompareMemory Lib "NtDll" (Source1 As Any, Source2 As Any, ByVal Length As Long) As Long

Public Function ComparePackets(Packet1() As Byte, Packet2() As Byte) As Boolean
Dim P1Size As Long
Dim P2Size As Long
P1Size = UBound(Packet1)
P2Size = UBound(Packet2)
If (P1Size <> P2Size) Then
ComparePackets = False
Exit Function
End If
If (P1Size + 1 <> RtlCompareMemory(Packet1(0), Packet2(0), P1Size + 1)) Then
ComparePackets = False
Exit Function
End If
ComparePackets = True
End Function


and here is a readable version of HHBFilter


Public Function HHBFilter(ByRef Bytes() As Byte)
Dim buf() As Byte
GetCheatPacket buf, "cipsoft client packet hex here"
If ComparePackets(Bytes, buf) Then
GetCheatPacket Bytes, "custom client packet hex here"
Exit Function
End If
End Function

Spirit
04-24-2016, 03:05
Well.. Daniel never hear our voices...

blackd
01-11-2017, 16:28
Awesome! Thank you a lot Hans.

The only problem here is that all the packet compare/replace operations might lag the connection. Before I can release this feature for public I will need to find an optimized procedure. However, for now, it is worth a sticky for people with custom ot servers.