-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon.cpp
More file actions
156 lines (132 loc) · 4.7 KB
/
Copy pathcommon.cpp
File metadata and controls
156 lines (132 loc) · 4.7 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// the command handler here is wedged in before the normal command handler.
// it doesn't do partial matches like the usual commands
#include "eqclientmod.h"
#include "common.h"
#include "util.h"
#include "settings.h"
#include "eq_titanium.h"
#include <string.h>
//#define DETOUR_SLEEP
// globals
HMODULE hEQGameEXE;
HMODULE hEQGfxDll;
#ifdef COMMAND_HANDLER
std::map<const char *, _slashCommandHandler> ChatCommandMap;
#endif
#ifdef COMMAND_HANDLER
#include <map>
void command_eqclientmod(void *LocalPlayer, char *text, char *cmd, char *&sep)
{
char buf[200];
sprintf(buf, "eqclientmod %s solar@heliacal.net", BUILD_VERSION);
EverQuestObject->dsp_chat(buf, 269, 1);
}
//#include <WerApi.h>
void command_crash(void *LocalPlayer, char *text, char *cmd, char *&sep)
{
//WerSetFlags(WER_FAULT_REPORTING_ALWAYS_SHOW_UI);
//char *crash = 0;
//*crash = 0x90;
//RaiseException(0x0000DEAD, 0, 0, 0);
ZeroMemory(NULL, 100);
//int a = 0;
//int b = 100 / a;
}
// this __fastcall prototype is equivalent to __thiscall, the second argument just isn't meaningful
// int __fastcall CEverQuest__InterpretCmd_Detour_ExecuteCmd(void *this_ptr, void *edx, void *localplayer, char *text)
typedef int(__thiscall *_CEverQuest__InterpretCmd)(void *this_ptr, void *localplayer, char *text);
_CEverQuest__InterpretCmd CEverQuest__InterpretCmd = (_CEverQuest__InterpretCmd)Offset_CEverQuest__InterpretCmd;
class CEverQuest__InterpretCmd_Detour_type
{
public:
int CEverQuest__InterpretCmd_Detour(void *LocalPlayer, char *text)
{
bool handled = false;
if (LocalPlayer && text && *text == '/')
{
char buf2[201];
strcpy_s(buf2, 201, text);
buf2[200] = 0;
char *sep = buf2;
char *cmd = strtok_s(sep, " ", &sep);
//for (auto item : ChatCommandMap)
for (std::map<const char *, _slashCommandHandler>::iterator item = ChatCommandMap.begin(); item != ChatCommandMap.end(); ++item)
{
if (item->first && !strcmp(cmd, item->first))
{
handled = true;
item->second(LocalPlayer, text, cmd, sep);
}
}
}
if (handled)
{
return CEverQuest__InterpretCmd(this, NULL, NULL);
}
return CEverQuest__InterpretCmd(this, LocalPlayer, text);
}
};
#endif
#ifdef DETOUR_SLEEP
#include <intrin.h>
typedef void (__stdcall *_Sleep)(DWORD );
_Sleep Sleep_Trampoline;
void __stdcall Sleep_Detour(DWORD ms)
{
void* returnAddress = _ReturnAddress();
if(ms)
{
if((int)returnAddress != 0x005EBE61)
{
Log("Sleep(%d) 0x%08X thread %d", ms, returnAddress, GetCurrentThreadId());
}
}
Sleep(ms);
}
#endif
void LoadCommon()
{
Log("LoadCommon()");
hEQGfxDll = LoadLibrary("EQGraphicsDX9.DLL");
if (!hEQGfxDll)
{
Log("LoadCommon(): NULL result from LoadLibrary(\"EQGraphicsDX9.DLL\")");
return;
}
//SetProcessAffinityMask(GetCurrentProcess(), 1);
//SetThreadAffinityMask(GetCurrentThread(), 1);
// detour sleep
#ifdef DETOUR_SLEEP
{
intptr_t addr = (intptr_t)Sleep_Detour;
Sleep_Trampoline = (_Sleep)(*(int *)0x0063F120);
Patch((void *)0x0063F120, &addr, 4);
}
#endif
#ifdef COMMAND_HANDLER
bool enableCommandHandler = true;
#ifdef INI_FILE
char buf[2048];
const char *desc = "This mod adds the extra command handling that some of the other hacks use but it's not strictly necessary to enable this to use the other hacks. Basic commands included: /eqclientmod /crash";
WritePrivateProfileStringA("CommandHandler", "Description", desc, INI_FILE);
GetINIString("CommandHandler", "Enabled", "TRUE", buf, sizeof(buf), true);
enableCommandHandler = ParseINIBool(buf);
#endif
Log("LoadCommon(): CommandHandler hack is %s thread %d", enableCommandHandler ? "ENABLED" : "DISABLED", GetCurrentThreadId());
if (enableCommandHandler)
{
//MethodAddressToVariable(NP_CEverQuest__InterpretCmd_Detour, CEverQuest__InterpretCmd_Detour_type::CEverQuest__InterpretCmd_Detour);
intptr_t NP_CEverQuest__InterpretCmd_Detour; { int(__thiscall CEverQuest__InterpretCmd_Detour_type::* fp)(void *, char *) = &CEverQuest__InterpretCmd_Detour_type::CEverQuest__InterpretCmd_Detour; memcpy(&NP_CEverQuest__InterpretCmd_Detour, &fp, 4); }
// CChatWindow::WndNotification - this one is for when text is typed into a chat window's input control
// .text:004F7390 2518 E8 E3 17 FA FF call CEverQuest__InterpretCmd
intptr_t addr = (intptr_t)NP_CEverQuest__InterpretCmd_Detour - (intptr_t)0x004F7390 - 5;
Patch((void *)(0x004F7390 + 1), &addr, 4);
// EQ_Character::DoPassageOfTime
// .text:00424015 388 E8 5E 4B 07 00 call CEverQuest__InterpretCmd
addr = (intptr_t)NP_CEverQuest__InterpretCmd_Detour - (intptr_t)0x00424015 - 5;
Patch((void *)(0x00424015 + 1), &addr, 4);
ChatCommandMap["/eqclientmod"] = command_eqclientmod;
ChatCommandMap["/crash"] = command_crash;
}
#endif
}