forked from 0xcds4r/build69-gtasa2.0
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
289 lines (233 loc) · 5.59 KB
/
main.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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#include <jni.h>
#include <android/log.h>
#include <ucontext.h>
#include <pthread.h>
#include <dlfcn.h>
// JNI_VERSION_1_4
#include "main.h"
#include "game/game.h"
#include "net/netgame.h"
#include "gui/gui.h"
#include "chatwindow.h"
#include "keyboard.h"
#include "dialog.h"
#include "spawnscreen.h"
#include "playertags.h"
#include "settings.h"
#include "debug.h"
#include "util/armhook.h"
#include "checkfilehash.h"
#include "str_obfuscator_no_template.hpp"
#include "game/firstperson.h"
CGame *pGame = nullptr;
CNetGame *pNetGame = nullptr;
CChatWindow *pChatWindow = nullptr;
CSpawnScreen *pSpawnScreen = nullptr;
CPlayerTags *pPlayerTags = nullptr;
CDialogWindow *pDialogWindow = nullptr;
CFirstPersonCamera *pFirstPersonCamera = nullptr;
CGUI *pGUI = nullptr;
CKeyBoard *pKeyBoard = nullptr;
CDebug *pDebug = nullptr;
CSettings *pSettings = nullptr;
uintptr_t g_GTASAAdr = 0;
uintptr_t g_SCANDAdr = 0;
bool bSAMPInitialized = false;
bool bScreenUpdated = false;
bool bGameInited = false;
bool bNetworkInited = false;
void InitRenderWareFunctions();
void InstallGlobalHooks();
void ApplyGlobalPatches();
void ApplySCAndPatches();
void InitSAMP(JNIEnv* pEnv, jobject thiz);
extern "C"
{
JNIEXPORT void JNICALL Java_com_nvidia_devtech_NvEventQueueActivity_initSAMP(JNIEnv* pEnv, jobject thiz)
{
InitSAMP(pEnv, thiz);
}
}
void handler(int signum, siginfo_t *info, void* contextPtr)
{
ucontext* context = (ucontext_t*)contextPtr;
if(info->si_signo == SIGSEGV)
{
FLog("TI TI MNE NE CRASH YA S TOBOI NE DRYSY");
FLog("backtrace:");
FLog("1: libGTASA.so + 0x%X", context->uc_mcontext.arm_pc - g_GTASAAdr);
FLog("2: libGTASA.so + 0x%X", context->uc_mcontext.arm_lr - g_GTASAAdr);
FLog("3: libsamp.so + 0x%X", context->uc_mcontext.arm_pc - ARMHook::getLibraryAddress("libsamp.so"));
FLog("4: libsamp.so + 0x%X", context->uc_mcontext.arm_lr - ARMHook::getLibraryAddress("libsamp.so"));
exit(0);
}
return;
}
#include "java/CJava.h"
void InitSAMP(JNIEnv* pEnv, jobject thiz)
{
FLog("Initializing SAMP..");
// WLoader("SAMP Initializing, with directory: %s", g_pszStorage);
// LoadBassLibrary();
// WLoader("Loading libbass.so");
pJava = new CJava(pEnv, thiz);
// pJava->SetUseFullScreen(pSettings->GetReadOnly().iCutout);
}
void InitialiseInterfaces()
{
if(!pKeyBoard)
{
pKeyBoard = new CKeyBoard();
}
if(!pChatWindow)
{
pChatWindow = new CChatWindow();
}
if(!pFirstPersonCamera)
{
pFirstPersonCamera = new CFirstPersonCamera();
}
#ifndef DEBUG_MODE
{
if(!pSpawnScreen)
{
pSpawnScreen = new CSpawnScreen();
}
if(!pPlayerTags)
{
pPlayerTags = new CPlayerTags();
}
if(!pDialogWindow)
{
pDialogWindow = new CDialogWindow();
}
}
#endif
}
void DoInitStuff()
{
if(!bGameInited)
{
pGame->Initialise();
pGame->SetMaxStats();
pGame->ToggleThePassingOfTime(0);
InitialiseInterfaces();
#ifdef DEBUG_MODE
{
pDebug = new CDebug();
if(pDebug)
{
pDebug->SpawnLocalPlayer();
}
}
#endif
bGameInited = true;
return;
}
#ifndef DEBUG_MODE
{
if(!bNetworkInited)
{
if(!pNetGame)
{
pNetGame = new CNetGame(cryptor::create(SRV_IP, MAX_IP_LENGTH).decrypt(), 1485, "Dev_Weikton", nullptr);
}
bNetworkInited = true;
return;
}
}
#endif
}
void MainLoop()
{
DoInitStuff();
}
void InitGUI()
{
pGUI = new CGUI();
}
void TryInitialiseSAMP()
{
if(!bSAMPInitialized)
{
// TODO: перенести в hooks.cpp
// StartGameScreen::OnNewGameCheck
(( int (*)())(g_GTASAAdr + 0x2A7201))();
bSAMPInitialized = true;
}
}
extern "C"
{
JavaVM* javaVM = NULL;
JavaVM* alcGetJavaVM(void)
{
return javaVM;
}
}
jint JNI_OnLoad(JavaVM *vm, void *reserved)
{
__android_log_write(ANDROID_LOG_INFO, "AXL", "SA-MP Library loaded! Build time: " __DATE__ " " __TIME__);
javaVM = vm;
__android_log_write(ANDROID_LOG_INFO, "AXL", "CJava Init.");
g_GTASAAdr = ARMHook::getLibraryAddress("libGTASA.so");
g_SCANDAdr = ARMHook::getLibraryAddress("libSCAnd.so");
if(!g_GTASAAdr) std::terminate();
ARMHook::sa_initializeTrampolines(g_GTASAAdr + 0x180044, 0x800);
ApplyGlobalPatches();
InstallGlobalHooks();
InitRenderWareFunctions();
ApplySCAndPatches();
pGame = new CGame();
struct sigaction act;
act.sa_sigaction = handler;
sigemptyset(&act.sa_mask);
act.sa_flags = SA_SIGINFO;
sigaction(SIGSEGV, &act, 0);
return JNI_VERSION_1_4;
}
void LOGI(const char *fmt, ...)
{
char buffer[0xFF];
memset(buffer, 0, sizeof(buffer));
va_list arg;
va_start(arg, fmt);
vsnprintf(buffer, sizeof(buffer), fmt, arg);
va_end(arg);
__android_log_write(ANDROID_LOG_INFO, "AXL", buffer);
return;
}
void FLog(const char *fmt, ...)
{
const char* g_pszStorage = (const char*)(g_GTASAAdr + 0x6D687C);
if(!g_pszStorage || !strlen(g_pszStorage))
{
return;
}
char buffer[0xFF];
static FILE* flLog = nullptr;
if(flLog == nullptr && g_pszStorage != nullptr)
{
sprintf(buffer, "%sSAMP/client.log", g_pszStorage);
flLog = fopen(buffer, "a");
}
memset(buffer, 0, sizeof(buffer));
va_list arg;
va_start(arg, fmt);
vsnprintf(buffer, sizeof(buffer), fmt, arg);
va_end(arg);
__android_log_write(ANDROID_LOG_INFO, "AXL", buffer);
if(flLog == nullptr) return;
fprintf(flLog, "%s\n", buffer);
fflush(flLog);
return;
}
uint32_t GetTickCount()
{
struct timeval tv;
gettimeofday(&tv, nullptr);
return (tv.tv_sec*1000+tv.tv_usec/1000);
}
const char* GetGameStorage()
{
return (const char*)(g_GTASAAdr+0x6D687C);
}