📄 gamepacket.pas
字号:
unit GamePacket;
interface
uses
Windows, Sysutils, Classes, Winsock2;
procedure MyRecvData(buf: Pchar; len: integer);
procedure MySendData(buf: Pchar; len: integer);
procedure GamePacketSend(buf: Pchar; len: integer);
procedure GamePacketRecv(buf: Pchar; len: integer);
procedure SendMsg(source: Pchar; size: integer);
function SaveLog(LogStr: String):bool;
var
SendNum : integer = 0;
RecvNum : integer = 0;
GameSocket : Tsocket; //定义socket
implementation
uses DllForm, GameCode, hook;
procedure MyRecvData(buf: Pchar; len: integer);
var
i, onelen : integer;
PacketH : Pchar;
begin
i := 0;
onelen := 0;
PacketH := buf;
while i < len do
begin
if buf[i] = '(' then
begin
onelen := 1;
PacketH := @buf[i];
end;
if buf[i] = ')' then
begin
GamePacketRecv(PacketH, onelen);
end;
inc(onelen);
inc(i);
end;
end;
procedure MySendData(buf: Pchar; len: integer);
var
i,onelen : integer;
PacketH : Pchar;
begin
i := 0;
onelen := 0;
PacketH := buf;
while i < len do
begin
if buf[i] = '(' then
begin
onelen := 1;
PacketH := @buf[i] ;
end;
if buf[i] = ')' then
begin
GamePacketSend(PacketH, onelen);
end;
inc(onelen);
inc(i);
end;
end;
procedure GamePacketSend(buf: Pchar; len: integer);
var
OutLen : integer;
OutChar, RecvBuf : array [0..3000] of char;
LogStr : string;
begin
CopyMemory(@RecvBuf[0], @buf[0], len);
OutLen := Decode(@RecvBuf[1], len-1, @OutChar);
if Dllform1.Checksend.Checked = false then exit;
with DllForm1.Listsend.Items.Add do //填加记录到表
begin
Caption := IntToStr(SendNum);
inc(SendNum);
SubItems.add(CharToAscii(@OutChar[0], 2)); //封包长度
SubItems.add(CharToAscii(@OutChar[2], 2)); //封包代号
SubItems.add(CharToAscii(@OutChar[4], 4)); //0000 0000
SubItems.add(CharToAscii(@OutChar[8], 2)); //标识符后数据长度
SubItems.add(CharToAscii(@OutChar[10], 1)); //标识符
SubItems.add(CharToAscii(@OutChar[11], OutLen-11)); //参数
SubItems.add(Pchar(@OutChar[11])); //参数
end;
if DllForm1.CheckSave.Checked = true then //保存到文件
begin
LogStr := 'send'+' '+IntToStr(sendnum)+' '+ CharToAscii(@OutChar[10], 1)
+' '+CharToAscii (@OutChar[11],outlen-11)+' '+Pchar(@OutChar[11]);
SaveLog(logstr);
end;
end;
procedure gamePacketrecv (buf:Pchar; len:integer);
var
outlen : integer;
OutChar, RecvBuf : array [0..3000] of char;
logstr : string;
begin
CopyMemory(@RecvBuf[0], @buf, len);
outlen := Decode(@RecvBuf[1], len-1, @OutChar);
if DllForm1.Checkrecv.Checked = false then exit;
with DllForm1.Listrecv.Items.Add do
begin
caption := IntToStr(RecvNum);
inc(RecvNum);
SubItems.add(CharToAscii(@OutChar[0], 2)); //封包长度
SubItems.add(CharToAscii(@OutChar[2], 2)); //封包代号
SubItems.add(CharToAscii(@OutChar[4], 4)); //0000 0000
SubItems.add(CharToAscii(@OutChar[8], 2)); //标识符后数据长度
SubItems.add(CharToAscii(@OutChar[10], 1)); //标识符
SubItems.add(CharToAscii(@OutChar[11], outlen-11)); //参数
SubItems.add(Pchar(@OutChar[11])); //参数
end;
if DllForm1.CheckSave.Checked = true then
begin
logstr := 'recv' + ' ' + IntToStr(RecvNum)+ ' '+ CharToAscii(@OutChar[10], 1)
+ ' '+CharToAscii(@OutChar[11], outlen-11)+' '+Pchar(@OutChar[11]);
SaveLog(logstr);
end;
end;
procedure SendMsg(source: Pchar; size: integer); //加密并调用发送封包
var
len : integer;
OutChar, SendBuf : array [0..1000] of char;
begin
len := Encode(source, size, @OutChar[1]);
CopyMemory(@sendbuf[0], @OutChar[0], len + 1);
SendBuf[0] := '(';
SendBuf[len + 1] := ')';
if GameSocket <> 0 then
mysend(GameSocket, sendbuf, len + 2, 0);
end;
function SaveLog(LogStr: String):bool; //log记录
var
logFile : TextFile;
begin
AssignFile(logFile, DllForm1.Edit1.text);
if FileExists(DllForm1.Edit1.text) = false then ReWrite(logFile)
else
Append(logFile);
Writeln(logFile, LogStr);
CloseFile(logFile);
result := true;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -