- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBasics.h
More file actions
Latest commit
453 lines (299 loc) · 9.57 KB
/
Copy pathBasics.h
File metadata and controls
453 lines (299 loc) · 9.57 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
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
#pragma once
#ifndef Basics_H
#defineBasics_H
#defineBranchTo(offset,rtype,...) \
((rtype (__fastcall *)(...))offset)(__VA_ARGS__) \
#defineqASMBranch(reg,of1,of2) \
lis reg,of1 \
ori reg,reg,of2 \
mtctr reg \
bctrl \
#defineqASMJump(reg,of1,of2) \
lis reg,of1 \
ori reg,reg,of2 \
mtctr reg \
bctr \
staticvoid__declspec( naked ) savegprl_H(){
__asm{
std r14, -0x98(r1)
std r15, -0x90(r1)
std r16, -0x88(r1)
std r17, -0x80(r1)
std r18, -0x78(r1)
std r19, -0x70(r1)
std r20, -0x68(r1)
std r21, -0x60(r1)
std r22, -0x58(r1)
std r23, -0x50(r1)
std r24, -0x48(r1)
std r25, -0x40(r1)
std r26, -0x38(r1)
std r27, -0x30(r1)
std r28, -0x28(r1)
std r29, -0x20(r1)
std r30, -0x18(r1)
blr
}
}
staticvoid__declspec( naked ) restgprl_H(){
__asm{
std r14, -0x98(r1)
std r15, -0x90(r1)
std r16, -0x88(r1)
std r17, -0x80(r1)
std r18, -0x78(r1)
std r19, -0x70(r1)
std r20, -0x68(r1)
std r21, -0x60(r1)
std r22, -0x58(r1)
std r23, -0x50(r1)
std r24, -0x48(r1)
std r25, -0x40(r1)
std r26, -0x38(r1)
std r27, -0x30(r1)
std r28, -0x28(r1)
std r29, -0x20(r1)
std r30, -0x18(r1)
blr
}
}
#definesavegprl(index) BranchTo((DWORD)(savegprl_H) + (index *4) ,void)
#include<stdlib.h>
#include<boost/make_shared.hpp>
#include<xtl.h>
#include<cassert>
#include<vector>
#include<iostream>
#include<sstream>
#include<ctime>
#include"AtgConsole.h"
#include"AtgUtil.h"
#include"AtgInput.h"
#include"AtgSignIn.h"
#include<map>
#include<Xboxmath.h>
#include<time.h>
// first unsigned macros:
#defineBYTEn(x, n) (*((_BYTE*)&(x)+n))
#defineWORDn(x, n) (*((_WORD*)&(x)+n))
#defineDWORDn(x, n) (*((_DWORD*)&(x)+n))
#defineLOBYTE(x) BYTEn(x,LOW_IND(x,_BYTE))
#defineLOWORD(x) WORDn(x,LOW_IND(x,_WORD))
#defineLODWORD(x) DWORDn(x,LOW_IND(x,_DWORD))
#defineHIBYTE(x) BYTEn(x,HIGH_IND(x,_BYTE))
#defineHIWORD(x) WORDn(x,HIGH_IND(x,_WORD))
#defineHIDWORD(x) DWORDn(x,HIGH_IND(x,_DWORD))
#defineBYTE1(x) BYTEn(x, 1) // byte 1 (counting from 0)
#defineBYTE2(x) BYTEn(x, 2)
#defineBYTE3(x) BYTEn(x, 3)
#defineBYTE4(x) BYTEn(x, 4)
#defineBYTE5(x) BYTEn(x, 5)
#defineBYTE6(x) BYTEn(x, 6)
#defineBYTE7(x) BYTEn(x, 7)
#defineBYTE8(x) BYTEn(x, 8)
#defineBYTE9(x) BYTEn(x, 9)
#defineBYTE10(x) BYTEn(x, 10)
#defineBYTE11(x) BYTEn(x, 11)
#defineBYTE12(x) BYTEn(x, 12)
#defineBYTE13(x) BYTEn(x, 13)
#defineBYTE14(x) BYTEn(x, 14)
#defineBYTE15(x) BYTEn(x, 15)
#defineWORD1(x) WORDn(x, 1)
#defineWORD2(x) WORDn(x, 2) // third word of the object, unsigned
#defineWORD3(x) WORDn(x, 3)
#defineWORD4(x) WORDn(x, 4)
#defineWORD5(x) WORDn(x, 5)
#defineWORD6(x) WORDn(x, 6)
#defineWORD7(x) WORDn(x, 7)
template<classT> T __ROL__(T value, int count)
{
const uint nbits = sizeof(T) * 8;
if ( count > 0 )
{
count %= nbits;
T high = value >> (nbits - count);
if ( T(-1) < 0 ) // signed value
high &= ~((T(-1) << count));
value <<= count;
value |= high;
}
else
{
count = -count % nbits;
T low = value << (nbits - count);
value >>= count;
value |= low;
}
return value;
}
typedefunsignedint uint;
typedefunsignedchar uchar;
typedefunsignedshort ushort;
typedefunsignedlong ulong;
typedefchar int8;
typedefsignedchar sint8;
typedefunsignedchar uint8;
typedefshort int16;
typedefsignedshort sint16;
typedefunsignedshort uint16;
typedefint int32;
typedefsignedint sint32;
typedefunsignedint uint32;
inline uint8 __ROL1__(uint8 value, int count) { return__ROL__((uint8)value, count); }
inline uint16 __ROL2__(uint16 value, int count) { return__ROL__((uint16)value, count); }
inline uint32 __ROL4__(uint32 value, int count) { return__ROL__((uint32)value, count); }
inline uint8 __ROR1__(uint8 value, int count) { return__ROL__((uint8)value, -count); }
inline uint16 __ROR2__(uint16 value, int count) { return__ROL__((uint16)value, -count); }
inline uint32 __ROR4__(uint32 value, int count) { return__ROL__((uint32)value, -count); }
extern"C" {
#include"lua.h"
#include"lualib.h"
#include"lauxlib.h"
}
//#include <luajit.h>
#include<string>
#include<iostream>
#include<cmath>
#defineLAST_IND(x,part_type) (sizeof(x)/sizeof(part_type) - 1)
#defineLOW_IND(x,part_type) LAST_IND(x,part_type)
#defineHIGH_IND(x,part_type) 0
#defineDWORDn(x, n) (*((_DWORD*)&(x)+n))
#defineLODWORD(x) DWORDn(x,LOW_IND(x,_DWORD))
#defineHIDWORD(x) DWORDn(x,HIGH_IND(x,_DWORD))
#define_QWORDunsignedlonglong
#define_DWORDDWORD
#define_BYTEBYTE
typedefshort _WORD;
//class ZLua
//{
//public:
// std::string FilePath;
// lua_State* L;
// bool executed;
// void OpenLua();
// void UseBaseLibs();
// void DoFile(bool);
// void CallFunction();
// ZLua(void);
// ZLua(const char*);
// ~ZLua(void);
//};
#defineDataPointer(type, name, address) \
static type &name = *(type *)address
// Function pointer declarations.
#defineFunctionPointer(RETURN_TYPE, NAME, ARGS, ADDRESS) \
staticRETURN_TYPE (__cdecl *constNAME)ARGS = (RETURN_TYPE (__cdecl *)ARGS)ADDRESS
#defineStdcallFunctionPointer(RETURN_TYPE, NAME, ARGS, ADDRESS) \
staticRETURN_TYPE (__stdcall *constNAME)ARGS = (RETURN_TYPE (__stdcall *)ARGS)ADDRESS
#defineFastcallFunctionPointer(RETURN_TYPE, NAME, ARGS, ADDRESS) \
staticRETURN_TYPE (__fastcall *constNAME)ARGS = (RETURN_TYPE (__fastcall *)ARGS)ADDRESS
#defineThiscallFunctionPointer(RETURN_TYPE, NAME, ARGS, ADDRESS) \
staticRETURN_TYPE (__thiscall *constNAME)ARGS = (RETURN_TYPE (__thiscall *)ARGS)ADDRESS
#defineVoidFunc(NAME, ADDRESS) FunctionPointer(void,NAME,(void),ADDRESS)
#defineFUNCTION_PTR(returnType, callingConvention, function, location, ...) \
returnType (callingConvention *function)(__VA_ARGS__) = (returnType(callingConvention*)(__VA_ARGS__))(location) \
#defineFUNCTION_PTRN(returnType, callingConvention, function, location, ...) \
returnType callingConvention function(__VA_ARGS__)\
{\
return ((returnType (callingConvention *)(__VA_ARGS__))location)(__VA_ARGS__))\
}\
#defineMakeState(NM,TP) \
boost::shared_ptr<TP>& NM(boost::shared_ptr<TP>& a1,int a2){ \
\
boost::shared_ptr<TP> x(newTP((Marathon::PlayerState::StateBaseValueP*)a2));\
a1 = x;\
return a1;\
}\
#defineMakeStateS(TP) \
boost::shared_ptr<TP>& TP##C(boost::shared_ptr<TP>& a1,int a2){ \
\
boost::shared_ptr<TP> x(newTP((Marathon::PlayerState::StateBaseValueP*)a2));\
a1 = x;\
return a1;\
}\
#definemalloc06(size) \
BranchTo(0x82186158,int,60) \
#defineFD(NM) \
(int)(NM##C) \
classZLua
{
public:
std::string FilePath;
lua_State* L;
bool executed;
bool locked;
voidOpenLua();
voidUseBaseLibs();
voidDoFile(bool);
voidCallFunction();
constchar* ZLua::GetGlobalString(constchar* string);
intZLua::GetGlobalBool(constchar* string);
intZLua::GetGlobalInt(constchar* string);
floatZLua::GetGlobalFloat(constchar* string);
intZLua::GetGlobalIntNew(char* str,bool useglobal = false);
staticvoidUseBaseLibsEx(lua_State* L);
ZLua(void);
ZLua(constchar*);
~ZLua(void);
};
staticLPCWSTR g_pwstrButtonsX[1] = { L"------------OK----------------" };
staticvoidShowXenonMessage(LPCWSTR Title,LPCWSTR wTitle){
MESSAGEBOX_RESULT result;
XOVERLAPPED m_Overlapped;
XShowMessageBoxUI(ATG::SignIn::GetSignedInUser(),Title,wTitle,1,g_pwstrButtonsX,1,XMB_ALERTICON,&result,&m_Overlapped);
}
template <typename T>
staticvoidDebugLogPushValueHEX(T value){
std::stringstream ss;
ss << std::hex << value;
std::string hexString = ss.str();
if ( ZLuaN::EnableDebugOutput) InputData::DebugLog.push_back(std::string(hexString));
}
template <typename T>
staticvoidDebugLogPushValue(T value){
std::stringstream ss;
ss << value;
std::string hexString = ss.str();
if ( ZLuaN::EnableDebugOutput) InputData::DebugLog.push_back(std::string(hexString));
}
staticwchar_t *convertCharArrayToLPCWSTR(constchar* charArray)
{
wchar_t* wString=newwchar_t[4096];
MultiByteToWideChar(CP_ACP, 0, charArray, -1, wString, 4096);
return wString;
}
staticvoidShowXenonMessage(LPCWSTR Title,char* wTitle){
MESSAGEBOX_RESULT result;
XOVERLAPPED m_Overlapped;
XShowMessageBoxUI(ATG::SignIn::GetSignedInUser(),Title,convertCharArrayToLPCWSTR(wTitle),1,g_pwstrButtonsX,1,XMB_ALERTICON,&result,&m_Overlapped);
}
staticMESSAGEBOX_RESULT* ShowXenonMessage(LPCWSTR Title,constchar* wTitle){
MESSAGEBOX_RESULT result;
XOVERLAPPED m_Overlapped;
XShowMessageBoxUI(ATG::SignIn::GetSignedInUser(),Title,convertCharArrayToLPCWSTR(wTitle),1,g_pwstrButtonsX,1,XMB_ALERTICON,&result,&m_Overlapped);
return &result;
}
staticvoidShowXenonMessage(LPCWSTR Title,int value,char*){
std::wstringstream ss;
ss << std::hex << value;
std::wstring hexString = ss.str();
ShowXenonMessage(Title,hexString.c_str());
}
template <typename T>
staticvoidPushXenonMessage(T value){
std::wstringstream ss;
ss <<std::hex << value;
MESSAGEBOX_RESULT result;
XOVERLAPPED m_Overlapped;
XShowMessageBoxUI(ATG::SignIn::GetSignedInUser(),L"MSG",ss.str().c_str(),1,g_pwstrButtonsX,1,XMB_ALERTICON,&result,&m_Overlapped);
}
staticvoidShowXenonMessage(LPCWSTR Title,float value,char*){
float vIn = value;
char vOutChar [17];
_gcvt_s(vOutChar,sizeof(vOutChar),vIn,8);
wchar_t vOut[17];
mbstowcs_s(NULL,vOut,sizeof(vOut)/2,vOutChar,sizeof(vOutChar));
ShowXenonMessage(Title,vOut);
}
//Contains Original06 Function
#endif