-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
105 lines (88 loc) · 3.13 KB
/
Main.cpp
File metadata and controls
105 lines (88 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "Main.h"
GetPlayerIObjRWFunc GetPlayerIObjRW;
char* fmtAmmoAndDelay = "%d--%.1f";
char* fmtAmmoAndZeroDelay = "%d--0.0";
char* fmtDelay = "%.1f";
char* fmtAmmo = "%d";
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
void DelayDisplay(unsigned short *equipId, char* buffer, void* unk, int ammoRemaining)
{
CShip** playerShip = (CShip**) &GetPlayerIObjRW()->cobject;
CEquipManager& equipManager = (*playerShip)->equipManager;
CEquip* equip = equipManager.FindByID(*equipId);
CELauncher* launcher = CELauncher::cast(equip);
float totalDelay = launcher->launcherArch->refireDelay;
if (ammoRemaining == -1)
{
if (totalDelay >= 1.0f)
{
float remainingDelay = totalDelay - launcher->delayElapsed;
if (remainingDelay > 0.0f)
sprintf(buffer, fmtDelay, remainingDelay);
else
strcpy(buffer, "0.0");
}
else
{
*buffer = '\0';
}
}
else if (totalDelay >= 1.0f)
{
float remainingDelay = totalDelay - launcher->delayElapsed;
if (remainingDelay > 0.0f)
sprintf(buffer, fmtAmmoAndDelay, ammoRemaining, remainingDelay);
else
sprintf(buffer, fmtAmmoAndZeroDelay, ammoRemaining);
}
else
{
sprintf(buffer, fmtAmmo, ammoRemaining);
}
}
void NAKED DelayDisplay_Hook()
{
__asm {
push ecx
push esi
call DelayDisplay
pop esi
add esp, 0x4
pop eax
add esp, 0x4
add eax, 0xB
mov ecx, [edi+0x50]
jmp eax
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
void WriteHooks()
{
DWORD oldProtect;
BYTE hookPatch[7];
DWORD flBase = (DWORD) GetModuleHandleA(NULL);
hookPatch[0] = 0xB8;
hookPatch[5] = 0xFF;
hookPatch[6] = 0xD0;
*(PDWORD) &hookPatch[1] = (DWORD) &DelayDisplay_Hook;
LPVOID hookPatchAddr = (LPVOID) (flBase + 0xDDFD5);
HANDLE processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
VirtualProtectEx(processHandle, hookPatchAddr, sizeof(hookPatch), PAGE_EXECUTE_READWRITE, &oldProtect);
WriteProcessMemory(processHandle, hookPatchAddr, hookPatch, sizeof(hookPatch), NULL);
CloseHandle(processHandle);
BYTE jmpPatch = 0x00;
LPVOID jmpPatchAddr = (LPVOID) (flBase + 0xDDFC0);
processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
VirtualProtectEx(processHandle, jmpPatchAddr, sizeof(jmpPatch), PAGE_EXECUTE_READWRITE, &oldProtect);
WriteProcessMemory(processHandle, jmpPatchAddr, &jmpPatch, sizeof(jmpPatch), NULL);
CloseHandle(processHandle);
GetPlayerIObjRW = (GetPlayerIObjRWFunc) (flBase + 0x14BAF0);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
if(fdwReason == DLL_PROCESS_ATTACH)
WriteHooks();
//else if(fdwReason == DLL_PROCESS_DETACH)
return true;
}