1 unit speedhackmain;
2
3 {$MODE Delphi}
4
5
6 interface
7 uses windows, classes;
8
9 procedure InitializeSpeedhack(speed: single); stdcall;
10
11 type TGetTickCount=function: DWORD; stdcall;
12 type TQueryPerformanceCounter=function(var x: int64): BOOL; stdcall;
13
14 function speedhackversion_GetTickCount: DWORD; stdcall;
15 function speedhackversion_QueryPerformanceCounter(var x: int64): BOOL; stdcall;
16
17 //function GetTime:dword; stdcall;
18 //function NewQueryPerformanceCounter(var output: int64):BOOl; stdcall;
19 var CETick: dword;
20 CETick64: int64;
21
22 PerformanceFrequency: int64;
23 PerformanceFrequencyMS: int64;
24 acceleration: single;
25 sleeptime: dword;
26 slow: boolean;
27 tickerstopped: boolean;
28 speedhackenabled: boolean;
29
30
31 { timeGetTimeInfo:TAPiInfo;
32 getTickcountInfo: TAPIInfo;
33 QueryPerformanceCounterInfo: TAPIInfo; }
34 winmmlib,kernel32lib: thandle;
35
36 //5.5:
37 confighaschanged: integer;
38 speedmultiplier: single;
39 realgettime: pointer;
40 realGetTickCount: pointer;
41 realQueryPerformanceCounter: pointer;
42 initialoffset: dword;
43 initialtime: dword;
44 initialoffset64: int64;
45 initialtime64: int64;
46
47 implementation
48
49 function speedhackversion_GetTickCount: DWORD; stdcall;
50 var x: dword;
51 begin
52 //also used for timeGetTime
53 x:=TGetTickCount(realgettickcount);
54 //time past since activation, mulitplied by speed multiplier
55 result:=trunc((x-initialtime)*speedmultiplier)+initialoffset;
56
57 end;
58
59 function speedhackversion_QueryPerformanceCounter(var x: int64): BOOL; stdcall;
60 var y: int64;
61 begin
62 x:=0;
63 y:=0;
64
65 //also used for timeGetTime
66 result:=TQueryPerformanceCounter(realQueryPerformanceCounter)(y);
67
68 //time past since activation, mulitplied by speed multiplier
69 x:=trunc((y-initialtime64)*speedmultiplier)+initialoffset64;
70
71 end;
72
73 procedure InitializeSpeedhack(speed: single); stdcall;
74 {
75 Called by createremotethread
76 }
77 var x: int64;
78 begin
79 x:=0;
80
81 // messagebox(0,'called','called',mb_ok);
82 initialoffset:=gettickcount;
83 initialtime:=TGetTickCount(realgettickcount);
84
85 QueryPerformanceCounter(x);
86 initialoffset64:=x;
87 TQueryPerformanceCounter(realQueryPerformanceCounter)(x);
88 initialtime64:=x;
89
90 speedmultiplier:=speed;
91 end;
92
93 end.
;=================================================================================================
; Function: _InjectDll($ProcessId, $DllPath)
; Description: Injects a .dll into a running program.
; Return Value(s): On Success - Returns true
; On Failure - Returns false
; @Error - 0 = No error.
; 1 = Invalid ProcessId.
; 2 = File does not exist.
; 3 = File is not a .dll (invalid file).
; 4 = Failed to open 'Advapi32.dll'.
; 5 = Failed to get the full path.
; 6 = Failed to open the process.
; 7 = Failed to call 'GetModuleHandle'.
; 8 = Failed to call 'GetProcAddress'.
; 9 = Failed to call 'VirtualAllocEx'.
; 10 = Failed to write the memory.
; 11 = Failed to create the 'RemoteThread'.
; Author(s): KillerDeluxe
;=================================================================================================
Func _InjectDll($ProcessId, $DllPath)
If $ProcessId == 0 Then Return SetError(1, "", False)
If Not(FileExists($DllPath)) Then Return SetError(2, "", False)
If Not(StringRight($DllPath, 4) == ".dll") Then Return SetError(3, "", False)
$Kernel32 = DllOpen("kernel32.dll")
If @error Then Return SetError(4, "", False)
$DLL_Path = DllStructCreate("char[255]")
DllCall($Kernel32, "DWORD", "GetFullPathNameA", "str", $DllPath, "DWORD", 255, "ptr", DllStructGetPtr($DLL_Path), "int", 0)
If @error Then Return SetError(5, "", False)
$hProcess = DllCall($Kernel32, "DWORD", "OpenProcess", "DWORD", 0x1F0FFF, "int", 0, "DWORD", $ProcessId)
If @error Then Return SetError(6, "", False)
$hModule = DllCall($Kernel32, "DWORD", "GetModuleHandleA", "str", "kernel32.dll")
If @error Then Return SetError(7, "", False)
$lpStartAddress = DllCall($Kernel32, "DWORD", "GetProcAddress", "DWORD", $hModule[0], "str", "LoadLibraryA")
If @error Then Return SetError(8, "", False)
$lpParameter = DllCall($Kernel32, "DWORD", "VirtualAllocEx", "int", $hProcess[0], "int", 0, "ULONG_PTR", DllStructGetSize($DLL_Path), "DWORD", 0x3000, "int", 4)
If @error Then Return SetError(9, "", False)
DllCall("kernel32.dll", "BOOL", "WriteProcessMemory", "int", $hProcess[0], "DWORD", $lpParameter[0], "str", DllStructGetData($DLL_Path, 1), "ULONG_PTR", DllStructGetSize($DLL_Path), "int", 0)
If @error Then Return SetError(10, "", False)
$hThread = DllCall($Kernel32, "int", "CreateRemoteThread", "DWORD", $hProcess[0], "int", 0, "int", 0, "DWORD", $lpStartAddress[0], "DWORD", $lpParameter[0], "int", 0, "int", 0)
If @error Then Return SetError(11, "", False)
DllCall($Kernel32, "BOOL", "CloseHandle", "DWORD", $hProcess[0])
DllClose($Kernel32)
Return SetError(0, "", True)
EndFunc