-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathUE3_UT3_LScript.cpp
More file actions
3885 lines (3147 loc) · 90.1 KB
/
UE3_UT3_LScript.cpp
File metadata and controls
3885 lines (3147 loc) · 90.1 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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************
*
* LScript Introduction:
* LScript is a tiny scripting engine for the 2.6 version of the AAO game.
* LScript connects a Lua scripting engine up to the 2.6 game engine. You
* can learn more about the Lua scripting language here:
* http://www.lua.org
*
* There is a LScript.txt file that describes how to use this code from Lua.
*
* How to build LScript:
* 1. Download the Lua 5.1 source code from the Lua site.
* 2. Copy all the files from lua-5.1/src directory into your build directory.
* 3. Delete the lua.c and luac.c files.
* 4. Copy this file into the build directory.
* 5. Create a project that includes all the files in the build directory.
* 6. Build it.ylow
*
* Picklelicious 1 Apr 2006 Original Version - April fools day
* Temp2 5 Nov 2006 Converted for AA 2.7.0 - Fireworks night
* Temp2 6 Nov 2006 Ported to UT3369 - Melbourne Cup
* SmokeZ 13 Nov 2006 Added Some Extra Features + Fixed Common Compiler Errors
* Temp2 13 Nov 2006 Changed some stuff for VS 2005
* Temp2 15 Nov 2006 New hooks
* Temp2 24 Dec 2006 Converted for AA 2.8.0 - Christmas Eve
* Temp2 4 Apr 2007 Converted for AA 2.8.1 - Easter Parade.
* HUMM3R 5 Oct 2008 Converted for GOW on UE3
* R00T88 7 Jan 2010 Converted for UT3 on UE3
******************************************************************************/
/******************************************************************************
* you need to set the project configuration to RELEASE
* or the dll will not work!
* for more infomations about that look here:
*
* http://www.mpcforum.com/showpost.php?p=1542459&postcount=62
*
*
* changelog:
*
* (13.11 - smokez)
* {
* key-defines for (restart), (open logfile), (open lua console)
* key-combos only work if the game is also the foregroundwindow
* if you restart the lua-engine the logfile will restart also
* the "'CacheData' : redefinition" error shuld be fixed
* removed the ddraw header coz its not needed
* you can define the default log/botfile now
* if the logfile-define is empty "" the log feature will NOT be used
* bot/logfile now use the lib path as base and not the executable path
* }
*
* FIXTHIS: (line 3152) the ut-window-text is missing
*
* IMPORTANT : Use 4-byte alignment (or aligment used by the engine) !!!
*
******************************************************************************/
#define _CRT_SECURE_NO_DEPRECATE 1
#define _CRT_NONSTDC_NO_DEPRECATE 1
//#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
/*
USER CONFIG
*/
#define DEFAULT_BOTFILE "default.lua"
#define DEFAULT_LOGFILE "default.log"
#define BASEKEY VK_MENU //,VK_SHIFT
#define RESTART_KEY 'r' //BASEKEY + <your_key>
#define OPEN_LOG_KEY 'l' //BASEKEY + <your_key>
#define OPEN_LUA_CONSOLE 'c' //BASEKEY + <your_key>
/*
USER CONFIG END
*/
#include <windows.h>
#include <fcntl.h>
#include <io.h>
#include <process.h>
#include <time.h>
#include <stdlib.h>
#include "detours.h"
extern "C"
{
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
#pragma comment(lib, "Toolkit.lib")
#include "Toolkit.h"
#include "vmthooks.cpp"
#define EngineUFunction "Engine.UFunction"
#define EngineUObject "Engine.UObject"
#define EngineUProperty "Engine.UProperty"
#define MaxFullNameSize 512
#define MaxNameSize 128
#define NoIndex 0x7FFFFFFF
void *processEvent = (void*)0xBD3F50;
/******************************************************************************
*
* LogFile
*
******************************************************************************/
FILE* hLogFile;
char szLogFile[MAX_PATH];
bool bLogActive = false;
void Log(char * pFormat, ...)
{
va_list ArgList;
char Line[32];
time_t Time;
struct tm * TM;
if(hLogFile && bLogActive)
{
Time = time(0);
TM = localtime(&Time);
strftime(Line, sizeof(Line), "%H:%M:%S ", TM);
fwrite(Line, strlen(Line), 1, hLogFile);
va_start(ArgList, pFormat);
vfprintf(hLogFile, pFormat, ArgList);
va_end(ArgList);
fprintf(hLogFile, "\n");
fflush(hLogFile);
}
}
/******************************************************************************
*
* Game Engine (Game dependent stuff here too)
*
******************************************************************************/
#define WINDOWTEXT "Unreal Tournament 3"
#define LEVEL_NAME "World UTFrontEnd.TheWorld"
#define VIEWPORT_NAME "LocalPlayer Transient.GameEngine.LocalPlayer"
#define HASH_ADDRESS 0x1DDDF00
#define OBJECTS_ADDRESS 0x1DE5FA4
#define NAMES_ADDRESS 0x1DD46E8
template<class Type> struct TArray
{
Type * pArray;
DWORD Count;
DWORD Max;
};
typedef DWORD FName;
struct FNameEntry
{
int FNameIndex;
DWORD Unknown0x004;
DWORD Unknown0x008;
DWORD Unknown0x00C;
WCHAR Name[1];
};
struct UClass;
struct UObject
{
DWORD ** pVMT;
DWORD ObjectInternal;
DWORD ObjectFlags1;
DWORD ObjectFlags2;
UObject * pHash;
UObject * pHashOuter;
DWORD * pFrame;
DWORD * pLinkerLoad;
UObject * pLinkerIndex;
DWORD NetIndex;
UObject * pOuter;
FName Name;
DWORD Dummy0;
UClass * pClass;
UObject * pArchetype; // 0x38
void GetCPPName(char * pBuffer);
void GetFullName(char * pBuffer);
void GetName(char * pBuffer);
int IsA(UClass * pClass);
/*
static class UClass * CDECL StaticLoadClass(class UClass *, class UObject *, TCHAR const *, TCHAR const *, DWORD, class UPackageMap *);
static class UObject * CDECL StaticLoadObject(class UClass *, class UObject *, TCHAR const *, TCHAR const *, DWORD, class UPackageMap *);
*/
};
struct UField : UObject
{
UField * pSuper; //0x3C
UField * pNext; //0x40
};
struct ULevelBase : UObject
{
TArray<UObject *> ActorArray;
unsigned char UnknownData0003[ 0x48 ];
};
struct ULevel : ULevelBase
{
unsigned char UnknownData0164[ 0x100 ];
};
struct UWorld : UObject
{
unsigned char UnknownData0004[ 0x8 ];
TArray< ULevel* > Levels;
unsigned char UnknownData0005[ 0x200 ];
};
struct AHUD
{
char Unknown0x408[0x408];
UObject* Canvas;
};
struct UProperty : UField
{
DWORD ElementCount; // 0x44
DWORD ElementSize; // 0x48
DWORD Flags; // 0x4C
FName Category; //0x50
DWORD Dummy1; //0x54
DWORD ReplicationOffset; //0x58
DWORD ReplicationIndex; //0x5C
DWORD Unknown3; //0x60
DWORD CStructOffset; //0x64
char Unknown0x005C[0x1C];
UClass * pRelatedClass;
};
struct UStruct : UField
{
DWORD ScriptText; //0x44
DWORD CppText; //0x48
UField * pChildren; //0x4C
DWORD Size; //0x50
TArray<BYTE> Script; //0x54
char Unknown0x0060[0x030];
};
struct UFunction : UStruct
{
DWORD Flags;
WORD NativeIndex;
WORD RepOffset;
unsigned char OperPrecedence;
FName FriendlyName;
unsigned char NumParms;
WORD ParmsSize;
WORD ReturnValueOffset;
void* Func;
};
struct UState : UStruct
{
};
struct UClass : UState
{
};
struct AActor : UObject
{
/*
char Unknown0x0034[0x110];
ULevel * XLevel; //0x0134 013c
*/
};
//Viewport not used , just declared for compatibility
struct UViewport : UObject
{
char Unknown0x003C[0x004]; // 0x3C
AActor * Actor;
};
TArray<UObject *> * pAActorArray;
TArray<FNameEntry *> * pFNameEntryArray;
TArray<UObject *> * pUObjectArray;
UObject ** pUObjectHash;
UViewport * pViewport;
UClass * pActorClass;
UClass * pClassClass;
UClass * pFunctionClass;
UClass * pStructClass;
UClass * pArrayPropertyClass;
UClass * pBoolPropertyClass;
UClass * pBytePropertyClass;
UClass * pClassPropertyClass;
UClass * pDelegatePropertyClass;
UClass * pFixedArrayPropertyClass;
UClass * pFloatPropertyClass;
UClass * pIntPropertyClass;
UClass * pMapPropertyClass;
UClass * pNamePropertyClass;
UClass * pObjectPropertyClass;
UClass * pPointerPropertyClass;
UClass * pPropertyClass;
UClass * pStructPropertyClass;
UClass * pStrPropertyClass;
UClass * pInterfacePropertyClass;
UClass * pComponentPropertyClass;
//void (__stdcall * pFString_ConstructPChar)(char *);
//void (__stdcall * pFString_Destruct)(void);
UObject * FindActorByFullName(const char * pFullName)
{
char Name[MaxFullNameSize];
int ObjectCount;
UObject * pObject;
UObject ** ppObject;
UWorld* pWorld = *(UWorld **)0x1DEE5EC;
pAActorArray = &pWorld->Levels.pArray[0]->ActorArray;
ObjectCount = pAActorArray->Count;
ppObject = (UObject **)pAActorArray->pArray;
while (ObjectCount)
{
pObject = *ppObject;
if (pObject)
{
pObject->GetFullName(Name);
if (!strcmp(Name, pFullName))
return(pObject);
}
++ppObject;
--ObjectCount;
}
return(0);
}
UObject * FindObjectByFullName(const char * pFullName)
{
char Name[MaxFullNameSize];
int ObjectCount;
UObject * pObject;
UObject ** ppObject;
ObjectCount = pUObjectArray->Count;
ppObject = (UObject **)pUObjectArray->pArray;
while (ObjectCount)
{
pObject = *ppObject;
if (pObject)
{
pObject->GetFullName(Name);
if (!strcmp(Name, pFullName))
return(pObject);
}
++ppObject;
--ObjectCount;
}
return(0);
}
UObject * FindObjectByName(const char * pName)
{
char Name[MaxFullNameSize];
int ObjectCount;
UObject * pObject;
UObject ** ppObject;
ObjectCount = pUObjectArray->Count;
ppObject = (UObject **)pUObjectArray->pArray;
while (ObjectCount)
{
pObject = *ppObject;
if (pObject)
{
pObject->GetName(Name);
if (!strcmp(Name, pName))
return(pObject);
}
++ppObject;
--ObjectCount;
}
return(0);
}
WCHAR * GetFName(FName Name)
{
if ((Name >= pFNameEntryArray->Count) || !pFNameEntryArray->pArray[Name])
return(L"[empty]");
return(pFNameEntryArray->pArray[Name]->Name);
}
void UObject::GetCPPName(char * pBuffer)
{
if (pClass == pStructClass)
{
*pBuffer = 'F';
}
else
{
UClass * pNextClass;
*pBuffer = 'U';
if (pClass == pClassClass)
pNextClass = (UClass *)this;
else
pNextClass = this->pClass;
while (pNextClass)
{
if (pNextClass == pActorClass)
{
*pBuffer = 'A';
break;
}
if (pNextClass == pNextClass->pSuper)
break;
pNextClass = (UClass *)pNextClass->pSuper;
}
}
sprintf(&pBuffer[1], "%S", GetFName(Name));
}
void AddPath(UObject * pObject, char * pBuffer)
{
if (pObject->pOuter)
AddPath(pObject->pOuter, pBuffer);
sprintf(pBuffer, "%S.", GetFName(pObject->Name));
}
void UObject::GetFullName(char * pBuffer)
{
/*if(this->pClass)
sprintf(pBuffer, "%S ", GetFName(this->pClass->Name));
else
sprintf(pBuffer, "%S ", GetFName(this->Name));
if (this->pOuter)
AddPath(this->pOuter, &pBuffer[strlen(pBuffer)]);
sprintf(&pBuffer[strlen(pBuffer)], "%S", GetFName(this->Name));*/
if(this->pClass && this->pOuter)
{
if(this->pOuter->pOuter)
sprintf_s(&pBuffer[0], 256, "%S %S.%S.%S", GetFName(this->pClass->Name), GetFName(this->pOuter->pOuter->Name), GetFName(this->pOuter->Name), GetFName(this->Name));
else
sprintf_s(&pBuffer[0], 256, "%S %S.%S", GetFName(this->pClass->Name), GetFName(this->pOuter->Name), GetFName(this->Name));
}
else
sprintf_s(&pBuffer[0], 256, "(null)");
}
void UObject::GetName(char * pBuffer)
{
sprintf(pBuffer, "%S", GetFName(Name));
}
int UObject::IsA(UClass * pClass)
{
UClass * pNextClass;
if(!this->pClass)
return(0);
pNextClass = this->pClass;
while (pNextClass)
{
if (pNextClass == pClass)
return(1);
if (!pNextClass->pSuper || pNextClass == pNextClass->pSuper)
return(0);
if(!pNextClass->pSuper)
return 0;
else
pNextClass = (UClass *)pNextClass->pSuper;
}
return(0);
}
void AppendType(char * pString, UProperty * pProperty)
{
if (pProperty->IsA(pArrayPropertyClass))
{
strcat(pString, "TArray<");
AppendType(pString, (UProperty *)pProperty->pRelatedClass);
strcat(pString, ">");
}
else if (pProperty->IsA(pBoolPropertyClass))
{
strcat(pString, "bool");
}
else if (pProperty->IsA(pBytePropertyClass))
{
strcat(pString, "byte");
}
else if (pProperty->IsA(pClassPropertyClass))
{
strcat(pString, "UClass *");
}
else if (pProperty->IsA(pDelegatePropertyClass))
{
strcat(pString, "delegate");
}
else if (pProperty->IsA(pFixedArrayPropertyClass))
{
strcat(pString, "fixed");
}
else if (pProperty->IsA(pFloatPropertyClass))
{
strcat(pString, "float");
}
else if (pProperty->IsA(pIntPropertyClass))
{
strcat(pString, "int");
}
else if (pProperty->IsA(pMapPropertyClass))
{
strcat(pString, "map");
}
else if (pProperty->IsA(pNamePropertyClass))
{
strcat(pString, "FName");
}
else if (pProperty->IsA(pObjectPropertyClass))
{
pProperty->pRelatedClass->GetCPPName(&pString[strlen(pString)]);
strcat(pString, " *");
}
else if (pProperty->IsA(pPointerPropertyClass))
{
strcat(pString, "void *");
}
else if (pProperty->IsA(pStrPropertyClass))
{
strcat(pString, "FString");
}
else if (pProperty->IsA(pStructPropertyClass))
{
pProperty->pRelatedClass->GetCPPName(&pString[strlen(pString)]);
}
else if (pProperty->IsA(pInterfacePropertyClass))
{
pProperty->pRelatedClass->GetCPPName(&pString[strlen(pString)]);
}
else if (pProperty->IsA(pComponentPropertyClass))
{
strcat(pString, "component");
}
else
{
strcat(pString, "[unknown]");
}
}
void AppendValue(char * pString, UProperty * pProperty, char * pData, int Index)
{
if (pProperty->IsA(pArrayPropertyClass))
{
TArray<void> * pValue;
pValue = (TArray<void> *)(pData + pProperty->CStructOffset);
if (!pValue->Count || !pValue->pArray)
{
sprintf(&pString[strlen(pString)], "[%d][%d][nil]", pValue->Count, pValue->Max);
}
else
{
sprintf(&pString[strlen(pString)], "[%d][%d]", pValue->Count, pValue->Max);
AppendValue(pString, (UProperty *)pProperty->pRelatedClass, (char *)pValue->pArray, 0);
}
}
else if (pProperty->IsA(pBoolPropertyClass))
{
int Value;
Value = *(int *)(pData + pProperty->CStructOffset +
(pProperty->ElementSize * Index));
Value &= (DWORD)pProperty->pRelatedClass;
if (Value)
Value = 1;
sprintf(&pString[strlen(pString)], "[%d]", Value);
}
else if (pProperty->IsA(pBytePropertyClass))
{
int Value;
Value = *(BYTE *)(pData + pProperty->CStructOffset +
(pProperty->ElementSize * Index));
sprintf(&pString[strlen(pString)], "[%d]", Value);
}
else if (pProperty->IsA(pClassPropertyClass))
{
int Value;
Value = *(int *)(pData + pProperty->CStructOffset +
(pProperty->ElementSize * Index));
sprintf(&pString[strlen(pString)], "[0x00%X]", Value);
}
else if (pProperty->IsA(pFloatPropertyClass))
{
float Value;
Value = *(float *)(pData + pProperty->CStructOffset +
(pProperty->ElementSize * Index));
sprintf(&pString[strlen(pString)], "[%0.3f]", Value);
}
else if (pProperty->IsA(pIntPropertyClass))
{
int Value;
Value = *(int *)(pData + pProperty->CStructOffset +
(pProperty->ElementSize * Index));
sprintf(&pString[strlen(pString)], "[%d]", Value);
}
else if (pProperty->IsA(pNamePropertyClass))
{
FName Value;
Value = *(FName *)(pData + pProperty->CStructOffset +
(pProperty->ElementSize * Index));
sprintf(&pString[strlen(pString)], "[%S]", GetFName(Value));
}
else if (pProperty->IsA(pObjectPropertyClass))
{
UObject * pValue;
pValue = *(UObject **)(pData + pProperty->CStructOffset +
(pProperty->ElementSize * Index));
if (pValue)
sprintf(&pString[strlen(pString)], "[%S]", GetFName(pValue->Name));
else
strcat(pString, "[nil]");
}
else if (pProperty->IsA(pPointerPropertyClass))
{
int Value;
Value = *(int *)(pData + pProperty->CStructOffset +
(pProperty->ElementSize * Index));
sprintf(&pString[strlen(pString)], "[0x00%X]", Value);
}
else if (pProperty->IsA(pStrPropertyClass))
{
TArray<WCHAR> * Value;
Value = (TArray<WCHAR> *)(pData + pProperty->CStructOffset +
(pProperty->ElementSize * Index));
if (Value->pArray)
sprintf(&pString[strlen(pString)], "[%S]", Value->pArray);
else
strcat(pString, "[nil]");
}
else if (pProperty->IsA(pStructPropertyClass))
{
UProperty * pSubProp;
pSubProp = (UProperty *)pProperty->pRelatedClass->pChildren;
while (pSubProp)
{
if (pSubProp->IsA(pPropertyClass))
{
pSubProp->GetName(&pString[strlen(pString)]);
AppendValue(pString, pSubProp, pData + pProperty->CStructOffset +
(pProperty->ElementSize * Index), 0);
strcat(pString, " ");
}
pSubProp = (UProperty *)pSubProp->pNext;
}
}
else if (pProperty->IsA(pDelegatePropertyClass))
{
UObject * pValue;
pValue = *(UObject **)(pData + pProperty->CStructOffset +
(pProperty->ElementSize * Index));
if (pValue)
sprintf(&pString[strlen(pString)], "[%S]", GetFName(pValue->Name));
else
strcat(pString, "[nil]");
}
else if (pProperty->IsA(pInterfacePropertyClass))
{
UObject * pValue;
pValue = *(UObject **)(pData + pProperty->CStructOffset +
(pProperty->ElementSize * Index));
if (pValue)
sprintf(&pString[strlen(pString)], "[%S]", GetFName(pValue->Name));
else
strcat(pString, "[nil]");
}
//pFixedArrayPropertyClass
//pMapPropertyClass
//pComponentClass
}
wchar_t* convertToWide(const char* orig) {
size_t origsize = strlen(orig) + 1;
const size_t newsize = 1024;
size_t convertedChars = 0;
wchar_t wcstring[newsize];
convertedChars = mbstowcs(wcstring, orig, origsize);
return _wcsdup(wcstring);
}
void FStringConstructor(void * pThis, const char * pString)
{
((TArray<CHAR>*)pThis)->Count = (*pString ? strlen(pString) * sizeof(wchar_t) + 1 : 0);
((TArray<CHAR>*)pThis)->Max = ((TArray<CHAR>*)pThis)->Count;
((TArray<CHAR>*)pThis)->pArray = (char*)malloc(((TArray<CHAR>*)pThis)->Count * sizeof(wchar_t));
wchar_t* wc = convertToWide(pString);
if(((TArray<CHAR>*)pThis)->Count > 0) {
memcpy(&((TArray<CHAR>*)pThis)->pArray[0], wc, ((TArray<CHAR>*)pThis)->Count*sizeof(wchar_t) );
}
free(wc);
/*
__asm mov eax,pString;
__asm push eax
__asm mov ecx,pThis;
__asm call pFString_ConstructPChar;
*/
}
void FStringDestructor(void * pThis)
{
try {
((TArray<CHAR>*)pThis)->Count = 0;
((TArray<CHAR>*)pThis)->Max = 0;
if (((TArray<CHAR>*)pThis)->pArray) {
free(((TArray<CHAR>*)pThis)->pArray);
}
} catch (...) {
Log("Error in FStringDestructor, it was internally created");
}
/*
__asm mov ecx,pThis;
__asm call pFString_Destruct;
*/
}
void InitNameArray() {
pFNameEntryArray = (TArray<FNameEntry *> *) NAMES_ADDRESS;
}
void EngineInit(void)
{
if (!pUObjectArray)
{
//HMODULE hCore;
//hCore = GetModuleHandle("core.dll");
//Log("1");
InitNameArray();
//Log("2");
//(TArray<FNameEntry *> *)GetProcAddress(hCore, "?Names@FName@@0V?$TArray@PAUFNameEntry@@@@A");
//pFString_ConstructPChar = (void (__stdcall *)(char *))GetProcAddress(hCore, "??0FString@@QAE@PBD@Z");
//pFString_Destruct = (void (__stdcall *)(void))GetProcAddress(hCore, "??1FString@@QAE@XZ");
pUObjectArray = (TArray<UObject *> *) OBJECTS_ADDRESS;
//(TArray<UObject *> *)GetProcAddress(hCore, "?GObjObjects@UObject@@0V?$TArray@PAVUObject@@@@A");
pUObjectHash = (UObject **) HASH_ADDRESS;
//(UObject **)GetProcAddress(hCore, "?GObjHash@UObject@@0PAPAV1@A");
pViewport = (UViewport *)FindObjectByFullName(VIEWPORT_NAME);
//Log("3");
pActorClass = (UClass *)FindObjectByFullName("Class Engine.Actor");
pClassClass = (UClass *)FindObjectByFullName("Class Core.Class");
pFunctionClass = (UClass *)FindObjectByFullName("Class Core.Function");
pStructClass = (UClass *)FindObjectByFullName("Class Core.ScriptStruct");
pArrayPropertyClass = (UClass *)FindObjectByFullName("Class Core.ArrayProperty");
pBoolPropertyClass = (UClass *)FindObjectByFullName("Class Core.BoolProperty");
pBytePropertyClass = (UClass *)FindObjectByFullName("Class Core.ByteProperty");
pClassPropertyClass = (UClass *)FindObjectByFullName("Class Core.ClassProperty");
pDelegatePropertyClass = (UClass *)FindObjectByFullName("Class Core.DelegateProperty");
pFixedArrayPropertyClass = (UClass *)FindObjectByFullName("Class Core.FixedArrayProperty");
pFloatPropertyClass = (UClass *)FindObjectByFullName("Class Core.FloatProperty");
pIntPropertyClass = (UClass *)FindObjectByFullName("Class Core.IntProperty");
pMapPropertyClass = (UClass *)FindObjectByFullName("Class Core.MapProperty");
pNamePropertyClass = (UClass *)FindObjectByFullName("Class Core.NameProperty");
pObjectPropertyClass = (UClass *)FindObjectByFullName("Class Core.ObjectProperty");
pPointerPropertyClass = (UClass *)FindObjectByFullName("Class Core.PointerProperty");
pPropertyClass = (UClass *)FindObjectByFullName("Class Core.Property");
pStructPropertyClass = (UClass *)FindObjectByFullName("Class Core.StructProperty");
pStrPropertyClass = (UClass *)FindObjectByFullName("Class Core.StrProperty");
pInterfacePropertyClass = (UClass *)FindObjectByFullName("Class Core.InterfaceProperty");
pComponentPropertyClass = (UClass *)FindObjectByFullName("Class Core.ComponentProperty");
//Log("4");
}
}
/******************************************************************************
*
* Lua Engine Functions
*
******************************************************************************/
struct UFunctionData
{
UObject * pObject;
UFunction * pFunction;
};
struct UObjectData
{
UObject * pObject;
UClass * pClass;
char * pData;
DWORD ActorIndex;
};
struct UObjectProp
{
UObject * pObject;
UProperty * pProperty;
char * pData;
};
HANDLE hConsole;
HANDLE hInputEvent;
char Input[MaxFullNameSize];
char Path[MAX_PATH];
bool RestartLua;
HANDLE StdErr;
HANDLE StdIn;
HANDLE StdOut;
int CloseConsole(lua_State * /*L*/)
{
if (hConsole)
{
SetStdHandle(STD_INPUT_HANDLE, StdIn);
SetStdHandle(STD_OUTPUT_HANDLE, StdOut);
SetStdHandle(STD_ERROR_HANDLE, StdErr);
CloseHandle(hConsole);
FreeConsole();
hConsole = 0;
SetEvent(hInputEvent);
}
return(0);
}
BOOL WINAPI ConsoleHandlerRoutine(DWORD /*dwCtrlType*/)
{
FreeConsole();
return(1);
}
void DumpProperty(UProperty * pProperty, char * pData, char * pName)
{
int Len;
if (pProperty->IsA(pPropertyClass))
{
AppendType(pName, pProperty);
strcat(pName, " ");
Len = strlen(pName);
if (Len < 40)
{
memset(&pName[Len], ' ', 40 - Len);
pName[40] = 0;
}
pProperty->GetName(&pName[strlen(pName)]);
if (pProperty->ElementCount > 1)
{
sprintf(&pName[strlen(pName)], "[%d]",
pProperty->ElementCount);
}
strcat(pName, " ");
Len = strlen(pName);
if (Len < 80)
{
memset(&pName[Len], ' ', 80 - Len);
pName[80] = 0;
}
AppendValue(pName, pProperty, pData, 0);
}
}
int Dump(lua_State * L)
{
int Found;
DWORD Index;
char Name[MaxFullNameSize*8];
char * pData;
UClass * pClass;
UObject * pObject;
UObjectData * pObjectData;
UObjectProp * pObjectProp;
UProperty * pProperty;
//Plain data type.
if (!lua_touserdata(L, 1))
{
pData = Name;
if (lua_isnoneornil(L, 1))
pData = "[nil]";
else if (lua_isnumber(L, 1))
sprintf(pData, "[%0.3f]", (float)lua_tonumber(L, 1));
else
sprintf(pData, "[%s]", lua_tostring(L, 1));
fputs("\n", stdout);
fputs(pData, stdout);
fputs("\n\n", stdout);