Code:
library DepartureLib;
uses
Windows, SysUtils;
{$R *.res}
// Set this up later for easyer use
Type
TPatchRecord = Record
Address: Pointer;
Bytes: array of Byte;
end;
PPatchRecord = ^TPatchRecord;
var
dwThrdHack: Dword = 0;
dwThrdMain: Dword = 0;
Const
//Recoil
AddressRecoil1 = $37465A60;
AddressRecoil2 = $37234EB9;
AddressRecoil3 = $37465A74;
AddressRecoil4 = $37465A77;
AddressRecoil5 = $37465A80;
PatchRecoil1 : Array[0..2] of byte = ($90,$90,$90);
PatchRecoil2 : Array[0..10] of byte = ($90,$90,$90,$90,$90,$90,$90,$90,$90,$90,$90);
PatchRecoil3 : Array[0..2] of byte = ($90,$90,$90);
PatchRecoil4 : Array[0..2] of byte = ($90,$90,$90);
PatchRecoil5 : Array[0..2] of byte = ($90,$90,$90);
OriginalRecoil1 : Array[0..2] of byte = ($D8,$66,$54);
OriginalRecoil2 : Array[0..10] of byte = ($C7,$84,$24,$94,$00,$00,$00,$0F,$00,$00,$00);
OriginalRecoil3 : Array[0..2] of byte = ($D9,$5E,$54);
OriginalRecoil4 : Array[0..2] of byte = ($D9,$46,$48);
OriginalRecoil5 : Array[0..2] of byte = ($D9,$5E,$48);
//ReLoad
AddressReload = $374B1826;
PatchReload : Array[0..7] of byte = ($90,$90,$90,$90,$90,$90,$90,$90);
OriginalReload : Array[0..7] of byte = ($81,$44,$24,$04,$1C,$00,$00,$00);
//PTC Method
function PushToConsole(sValue:string):boolean;cdecl;
begin;
asm
pushad
xor ecx, ecx
mov eax,[$0377f4930]
mov ecx,[eax+$0208]
push sValue
call ecx
add esp,4
popad
end;
Result:= True;
end;
// Write Bytes to Address Method
Function WriteIt(pAddress: Pointer; Bytes: Array of Byte): Boolean;
var
OldProtect, DummyProtect: DWord;
begin
if VirtualProtect(pAddress, SizeOf(Bytes), PAGE_EXECUTE_READWRITE, @OldProtect) then
begin
Move(Bytes, pAddress^, Length(Bytes));
VirtualProtect(pAddress, SizeOf(Bytes), OldProtect, @DummyProtect);
Result := True
end
else
Result := False;
end;
function FuncMain(const LPVOID: variant): Boolean;
var
Recoil, Reload: Boolean;
begin
Recoil := False;
Reload := False;
while (True) do
begin
asm
pushad;
end;
if (GetAsyncKeyState(VK_NUMPAD1) <> 0) then
begin
Sleep(100);
if Recoil then
begin
WriteIt(ptr(AddressRecoil1),OriginalRecoil1);
WriteIt(ptr(AddressRecoil2),OriginalRecoil2);
WriteIt(ptr(AddressRecoil3),OriginalRecoil3);
WriteIt(ptr(AddressRecoil4),OriginalRecoil4);
WriteIt(ptr(AddressRecoil5),OriginalRecoil5);
Recoil:= False;
end
else
begin
WriteIt(ptr(AddressRecoil1),PatchRecoil1);
WriteIt(ptr(AddressRecoil2),PatchRecoil2);
WriteIt(ptr(AddressRecoil3),PatchRecoil3);
WriteIt(ptr(AddressRecoil4),PatchRecoil4);
WriteIt(ptr(AddressRecoil5),PatchRecoil5);
Recoil:= True;
end;
end;
if (GetAsyncKeyState(VK_NUMPAD2) <> 0) then
begin
Sleep(100);
if Reload then
begin
PushToConsole('ShowFps 1');
PushToConsole('SkelModelStencil -1');
//Reload did'nt work :( just crashed when it was time to reload
//WriteIt(ptr(AddressReload),OriginalReload);
Reload:= False;
end
else
begin
PushToConsole('ShowFps 0');
PushToConsole('SkelModelStencil 0');
//Reload Did'nt Work :(
//WriteIt(ptr(AddressReload),OriginalReload);
Reload:= True;
end;
end;
asm
popad;
end;
end;
Sleep(200);
end;
Function IsGameReadyForHook: Boolean;
var
null: variant;
begin
if ((GetModuleHandleA('d3d9.dll') <> null) and
(GetModuleHandleA('ClientFX.fxd') <> null) and
(GetModuleHandleA('CShell.dll') <> null)) then
begin
Result := True;
end
else
Result := False;
end;
Function HackThread(): Dword;
var
cHandle: Cardinal;
begin
Repeat
Sleep(500);
Until ((IsGameReadyForHook = True) and (dwThrdMain = 0));
CreateThread(nil, 0, @FuncMain, nil, 0, dwThrdMain);
cHandle:= GetModuleHandleA('CShell.dll');
MessageBoxA(0, Pchar(inttostr(cHandle)),Pchar('CShell Handle'), MB_OK + MB_ICONINFORMATION);
Result := 0;
end;
procedure DllMain(reason: integer);
begin
case reason of
DLL_PROCESS_ATTACH:
begin
CreateThread(nil, 0, @HackThread, nil, 0, dwThrdHack);
end;
DLL_PROCESS_DETACH:
begin
if dwThrdMain <> 0 then
CloseHandle(dwThrdMain);
if dwThrdHack <> 0 then
CloseHandle(dwThrdHack);
end;
end;
end;
begin
DisableThreadLibraryCalls(hInstance);
DllProc := @DllMain;
DllProc(DLL_PROCESS_ATTACH);
end.