-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEG_client.cpp
129 lines (109 loc) · 3.04 KB
/
EG_client.cpp
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
#include <IO.H>
#include "EG_client.h"
#include "Preferences.h"
/// TODO:
/// make display options for widescreen
/// try to make dynamic windowed mode
/// lightning fix, engine fix
/// fix screen shaking
/// chat log conflicts?
/// decentralize headers
////////////////////////////////////////////////////////////////////////////////////////
HMODULE hModSelf, hModFL;
//FILE* fLog;
////////////////////////////////////////////////////////////////////////////////////////
void DacomSelfInstall()
{
wchar_t wszModPath[MAX_PATH];
GetModuleFileName(hModSelf, wszModPath, MAX_PATH);
std::wstring wscModPath(wszModPath);
size_t posSep = wscModPath.find_last_of(L'\\');
std::wstring wscIniPath = wscModPath.substr(0, posSep + 1) + L"dacom.ini";
std::string scMod = wstos(wscModPath.substr(posSep + 1).c_str(), CP_ACP);
std::ci_string scIni;
FILE *fp = _wfopen(wscIniPath.c_str(), L"r+b");
try
{
if (!fp)
throw L"_wfopen";
if (fseek(fp, 0, SEEK_END))
throw L"fseek";
long fileSize = ftell(fp);
if (EOF == fileSize)
throw L"ftell";
scIni.resize(fileSize);
rewind(fp);
if (fread(&scIni[0], 1, fileSize, fp) != fileSize)
throw L"fread";
size_t posSection = scIni.find("[libraries]");
size_t posNext = scIni.find('[', posSection + 1);
size_t posDll;
posDll = scIni.find("CursorConfine.dll", posSection + 12);
if (std::string::npos == posDll || posDll > posNext)
{
scIni.insert(posNext, "CursorConfine.dll\r\n");
}
posDll = scIni.find(scMod.c_str(), posSection + 12);
if (std::string::npos == posDll || posDll > posNext)
{
scIni.insert(posNext, "\r\n");
scIni.insert(posNext, scMod.c_str());
}
posDll = scIni.find("HudShift.dll", posSection + 12);
if (std::string::npos == posDll || posDll > posNext)
{
scIni.insert(posNext, "HudShift.dll\r\n");
}
posDll = scIni.find("jflp.dll", posSection + 12);
if (std::string::npos == posDll || posDll > posNext)
{
scIni.insert(posNext, "jflp.dll nostats no4way no8way\r\n");
}
if (scIni.length() != fileSize)
{
rewind(fp);
if (_chsize(_fileno(fp), 0))
throw L"_chsize";
if (fwrite(scIni.c_str(), 1, scIni.length(), fp) != scIni.length())
throw L"fwrite";
}
}
CATCH(L"DacomSelfInstall", DO_NOTHING)
if (fp)
fclose(fp);
}
BOOL CALLBACK DllMain(HINSTANCE hModule, DWORD fdwReason, LPVOID lpReserved)
{
if(!lpReserved)
{
if(fdwReason == DLL_PROCESS_ATTACH)
{
/*
fLog = fopen("_log.log", "a+t");
if(!fLog)
return FALSE;
*/
DisableThreadLibraryCalls(hModule);
hModSelf = hModule;
hModFL = GetModuleHandle(NULL);
DacomSelfInstall();
if(!InitPrefs())
return FALSE;
InitHacks();
if(!InitHooks())
return FALSE;
}
else if(fdwReason == DLL_PROCESS_DETACH)
{
/*
if(fLog != NULL)
fclose(fLog);
*/
UnloadHooks();
UnloadHacks();
UnloadPrefs();
}
}
return TRUE;
}
////////////////////////////////////////////////////////////////////////////////////////