what i would like to do is to hook winsock and recieve incoming data from the game and place it into a byte array, what code would i need
thx, in advance
Code: Select all
//CODE FOR LOADER
program CaveBot;
uses
Windows,
Sysutils,
madCodeHook;
var
StartInfo: TStartupInfo;
ProcInfo: TProcessInformation;
begin
ZeroMemory(@StartInfo, SizeOf(TStartupInfo));
ZeroMemory(@ProcInfo, SizeOf(TProcessInformation));
StartInfo.dwFlags := STARTF_USESHOWWINDOW;
StartInfo.wShowWindow := SW_SHOW;
CreateProcessEx(PChar(ExtractFilePath(paramstr(0)) + '\tibia.exe'), nil, nil, nil, False, 0, nil, nil, StartInfo, ProcInfo, PChar(ExtractFilePath(paramstr(0)) + '\CaveBot.dll'));
end.
Code: Select all
//DLL
library Project1;
uses
Windows,
Winsock,
madCodeHook,
Math,
Forms,
Classes,
SysUtils,
Unit1 in 'Unit1.pas' {Form1};
var
Form1: TForm1;
Application: TApplication;
const
szTargetExe: string = 'tibia.exe';
szTargetClass: string = 'TibiaClient';
function IsTibiaWindow(Window: HWND): boolean;
var
PID: dword;
begin
GetWindowThreadProcessId(Window, @PID);
Result := GetCurrentProcessId = PID;
end;
function HighOrderBitSet (theWord: Word): Boolean;
const
HighOrderBit = 15;
type
BitSet = set of 0..15;
begin
HighOrderBitSet := (HighOrderBit in BitSet(theWord));
end;
procedure Main;
begin
Application := TApplication.Create(nil);
Form1 := TForm1.Create(Application);
Form1.Show;
while True do
begin
Application.ProcessMessages;
if IsTibiaWindow(GetForegroundWindow) then
begin
if HighOrderBitSet(Word(GetKeyState(VK_CONTROL))) then
begin
if HighOrderBitSet(Word(GetKeyState(VK_F12))) then
begin
if Form1.Visible then
Form1.Hide
else
Form1.Show;
Sleep(200);
end;
end;
end;
Sleep(1);
end;
end;
procedure EntryPoint(Reason: dword); stdcall;
var
TID: dword;
begin
if Reason = DLL_PROCESS_ATTACH then
begin
CreateThread(nil, 0, @Main, nil, 0, TID);
end;
end;
begin
DLLProc := @EntryPoint;
EntryPoint(DLL_PROCESS_ATTACH);
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Math, Winsock, madCodeHook, ExtCtrls, StdCtrls;
var
Form1: TForm1;
DataSocket: TSocket;
sendNextHook: function(s: TSocket; var Buf; len, flags: Integer): Integer; stdcall;
const
szTargetExe: string = 'tibia.exe';
szTargetClass: string = 'TibiaClient';
implementation
{$R *.dfm}
function sendHookProc(s: TSocket; var Buf; len, flags: Integer): Integer; stdcall;
begin
DataSocket := s;
Result := sendNextHook(s, Buf, len, flags);
end;
procedure CastSpell(Spell: string);
var
Buffer: array [0..255] of byte;
begin
Buffer[0] := byte(Length(Spell) + 4);
Buffer[1] := $00;
Buffer[2] := $96;
Buffer[3] := $01;
Buffer[4] := Length(Spell);
Buffer[5] := $00;
CopyMemory(@Buffer[6], @Spell[1], Length(Spell));
sendNextHook(DataSocket, Buffer, Length(Spell) + 6, 0);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DataSocket := 0;
HookCode(@send, @sendHookProc, @sendNextHook);
end;
end.