-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathddwrapper.cpp
1269 lines (1059 loc) · 41.1 KB
/
ddwrapper.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
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
/* DirectDraw Wrapper
* version 1.0, August 6th, 2010
*
* Copyright (C) 2010 Jari Komppa
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
* Jari Komppa http://iki.fi/sol/
*
*************************************
*
* Based on a zlib/libpng licensed source code found on the net,
* http://www.mikoweb.eu/index.php?node=28
* re-worked so much that there's fairly little left of the original.
*
*************************************
* Modified by Doix - not the original wrapper
* More modifications made by Someone else
*/
#include "stdafx.h"
#include <varargs.h>
#include "detours.h"
#include <sys/stat.h>
#include <sstream>
#include <windows.h>
#include "add_on\scriptmath\scriptmath.h"
#include "add_on\scriptmath\scriptmathcomplex.h"
#include "add_on\scriptmath3d\scriptmath3d.h"
#include "add_on\scriptarray\scriptarray.h"
#include "add_on\scriptbuilder\scriptbuilder.h"
#include "add_on\scriptstdstring\scriptstdstring.h"
#include "gameenums.h"
#include "gamearrays.h"
// global variables
#pragma data_seg (".ddraw_shared")
HINSTANCE gl_hOriginalDll;
HINSTANCE gl_hThisInstance;
#pragma data_seg ()
int mode;
int difficulty;
int elapsed_time;
int background = -1;
int bg_width;
int bg_zwidth1;
int bg_zwidth2;
int stage_bound;
int current_phase;
int current_phase_count;
int current_stage;
char stage_clear;
sGame *game = (sGame*)0x458b00;
class Info {
public:
int x;
int y;
int z;
Vector3 position;
double x_real;
double y_real;
double z_real;
char facing;
char holding_up;
char holding_down;
char holding_left;
char holding_right;
char holding_a;
char holding_j;
char holding_d;
char up;
char down;
char left;
char right;
char A;
char J;
char D;
char DrA;
char DlA;
char DuA;
char DdA;
char DrJ;
char DlJ;
char DuJ;
char DdJ;
char DJA;
int hp;
int dark_hp;
int max_hp;
int mp;
int frame;
int bdefend;
int fall;
int team;
int id;
int blink;
int state;
int weapon_type;
int weapon_held;
int weapon_holder;
int shake;
int wait_counter;
int num;
int ctimer;
int arest;
char vrests[400];
int vrest; //backwards compatibility
Vector3 velocity;
double x_velocity;
double y_velocity;
double z_velocity;
int clone;
int type;
int reserve;
sDataFile *data;
Info() {
num = -1;
type = -1;
RefCount = 1;
}
Info(int object_num) {
Info();
operator=(object_num);
}
Info(const Info &info) {
Info();
operator=(info.num);
}
void AddRef(){
RefCount++;
}
void RelRef(){
if(--RefCount == 0) delete this;
}
int operator=(int object_num){
if(object_num<0 || object_num >= 400 || !game->exists[object_num]) return -1;
x = game->objects[object_num]->x;
y = game->objects[object_num]->y;
z = game->objects[object_num]->z;
x_real = game->objects[object_num]->x_real;
y_real = game->objects[object_num]->y_real;
z_real = game->objects[object_num]->z_real;
position = Vector3(x_real, y_real, z_real);
facing = game->objects[object_num]->facing;
holding_up = game->objects[object_num]->holding_up;
holding_down = game->objects[object_num]->holding_down;
holding_left = game->objects[object_num]->holding_left;
holding_right = game->objects[object_num]->holding_right;
holding_a = game->objects[object_num]->holding_a;
holding_j = game->objects[object_num]->holding_j;
holding_d = game->objects[object_num]->holding_d;
up = game->objects[object_num]->up;
down = game->objects[object_num]->down;
left = game->objects[object_num]->left;
right = game->objects[object_num]->right;
A = game->objects[object_num]->A;
J = game->objects[object_num]->J;
D = game->objects[object_num]->D;
DrA = game->objects[object_num]->DrA;
DlA = game->objects[object_num]->DlA;
DuA = game->objects[object_num]->DuA;
DdA = game->objects[object_num]->DdA;
DrJ = game->objects[object_num]->DrJ;
DlJ = game->objects[object_num]->DlJ;
DuJ = game->objects[object_num]->DuJ;
DdJ = game->objects[object_num]->DdJ;
DJA = game->objects[object_num]->DJA;
hp = game->objects[object_num]->hp;
dark_hp = game->objects[object_num]->dark_hp;
max_hp = game->objects[object_num]->max_hp;
mp = game->objects[object_num]->mp;
frame = game->objects[object_num]->frame1;
fall = game->objects[object_num]->fall;
bdefend = game->objects[object_num]->bdefend;
team = game->objects[object_num]->team;
id = game->objects[object_num]->data->id;
blink = game->objects[object_num]->blink;
state = game->objects[object_num]->data->frames[frame].state;
weapon_type = game->objects[object_num]->weapon_type;
if(weapon_type == 0){
weapon_held = -1;
}else{
weapon_held = game->objects[object_num]->weapon_held;
}
weapon_holder = game->objects[object_num]->weapon_holder;
shake = game->objects[object_num]->shake;
wait_counter = game->objects[object_num]->wait_counter;
num = object_num;
ctimer = game->objects[object_num]->ctimer;
arest = game->objects[object_num]->arest;
memcpy(vrests, game->objects[object_num]->vrests, 400);
vrest = (int)(*(char*)(*(int*)(0x458c94+object_num*4)+0xF0));
if(vrest < (int)(*(char*)(*(int*)(0x458c94+object_num*4)+0xF3)))
vrest = (int)(*(char*)(*(int*)(0x458c94+object_num*4)+0xF3));
x_velocity = game->objects[object_num]->x_velocity;
y_velocity = game->objects[object_num]->y_velocity;
z_velocity = game->objects[object_num]->z_velocity;
velocity = Vector3(x_velocity, y_velocity, z_velocity);
clone = game->objects[object_num]->clone;
type = game->objects[object_num]->data->type;
reserve = game->objects[object_num]->reserve;
data = game->objects[object_num]->data;
return type;
}
int operator=(const Info &info){
return operator=(info.num);
}
int operator+=(int object_num){
return operator=(num+object_num);
}
int operator+=(const Info &info){
return operator=(num+info.num);
}
int operator-=(int object_num){
return operator=(num-object_num);
}
int operator-=(const Info &info){
return operator=(num-info.num);
}
int operator++(){
return operator=(num+1);
}
int operator--(){
return operator=(num-1);
}
private:
unsigned int RefCount;
};
Info *Info_Factory(){
return new Info();
}
Info *Info_Factory(int object_num){
return new Info(object_num);
}
Info *Info_Factory(const Info &info){
return new Info(info);
}
Info self;
Info target;
asIScriptModule *ScriptModule;
asIScriptEngine *ScriptEngine;
asIScriptContext *ScriptContext;
#ifdef DEBUG_VERSION
#include <map>
std::map<int,FILETIME> ModuleTimes;
#endif
void startup();
void cleanup();
typedef enum {
INVALID,
VALID,
MODULE
} FileValidity;
int (__stdcall *AI_o )(int target_num, int object_num, int x, int y, int z, int a, int b);
int (__stdcall *AIa_o)(int object_num, int unkwn1);
int random(int max){//random function that works with replays
int result; // eax@2
signed int v3; // eax@3
DWORD &dword_450C34 = *((DWORD *)0x450C34);
DWORD &dword_450BCC = *((DWORD *)0x450BCC);
if ( max > 0 ){
dword_450C34 = (dword_450C34 + 1) % 1234;
v3 = dword_450C34 + (unsigned __int8)*(((BYTE *)0x44FF90) + (dword_450BCC + 1) % 3000);
dword_450BCC = (dword_450BCC + 1) % 3000;
result = v3 % max;
}else{
result = 0;
}
return result;
}
int loadTarget(int target_num)
{
return target = target_num;
}
int setEnemy(int object_num)
{
if (object_num < 0 || object_num >= 400 || !game->exists[object_num]) return -1;
return game->objects[self.num]->enemy = object_num;
}
void up(char key, char holding)
{
game->objects[self.num]->up = key;
game->objects[self.num]->holding_up = holding;
self.up = key;
self.holding_up = holding;
}
void down(char key, char holding)
{
game->objects[self.num]->down = key;
game->objects[self.num]->holding_down = holding;
self.down = key;
self.holding_down = holding;
}
void left(char key, char holding)
{
game->objects[self.num]->left = key;
game->objects[self.num]->holding_left = holding;
self.left = key;
self.holding_left = holding;
}
void right(char key, char holding)
{
game->objects[self.num]->right = key;
game->objects[self.num]->holding_right = holding;
self.right = key;
self.holding_right = holding;
}
void A(char key,char holding)
{
game->objects[self.num]->A = key;
game->objects[self.num]->holding_a = holding;
self.A = key;
self.holding_a = holding;
}
void J(char key,char holding)
{
game->objects[self.num]->J = key;
game->objects[self.num]->holding_j = holding;
self.J = key;
self.holding_j = holding;
}
void D(char key,char holding)
{
game->objects[self.num]->D = key;
game->objects[self.num]->holding_d = holding;
self.D = key;
self.holding_d = holding;
}
void DrA()
{
game->objects[self.num]->DrA = 3;
self.DrA = 3;
}
void DlA()
{
game->objects[self.num]->DlA = 3;
self.DlA = 3;
}
void DuA()
{
game->objects[self.num]->DuA = 3;
self.DuA = 3;
}
void DdA()
{
game->objects[self.num]->DdA = 3;
self.DdA = 3;
}
void DrJ()
{
game->objects[self.num]->DrJ = 3;
self.DrJ = 3;
}
void DlJ()
{
game->objects[self.num]->DlJ = 3;
self.DlJ = 3;
}
void DuJ()
{
game->objects[self.num]->DuJ = 3;
self.DuJ = 3;
}
void DdJ()
{
game->objects[self.num]->DdJ = 3;
self.DdJ = 3;
}
void DJA()
{
game->objects[self.num]->DJA = 3;
self.DJA = 3;
}
void clr(){
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
if(hConsole == INVALID_HANDLE_VALUE) return;
COORD coordScreen = {0,0};
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
if(!GetConsoleScreenBufferInfo(hConsole,&csbi)){
return;
}
dwConSize = csbi.dwSize.X*csbi.dwSize.Y;
if(!FillConsoleOutputCharacter(hConsole,' ',dwConSize,coordScreen,&cCharsWritten)){
return;
}
if(!GetConsoleScreenBufferInfo(hConsole,&csbi)){
return;
}
if(!FillConsoleOutputAttribute(hConsole,csbi.wAttributes,dwConSize,coordScreen,&cCharsWritten)){
return;
}
SetConsoleCursorPosition(hConsole,coordScreen);
}
void printAddr(void *Addr){
printf("%p",Addr);
}
void print(bool p){
if(p){
printf("true");
}else{
printf("false");
}
}
void print(char p){
printf("%d",p);
}
void print(short p){
printf("%d",p);
}
void print(int p){
printf("%d",p);
}
void print(long long p){
printf("%ld",p);
}
void print(unsigned char p){
printf("%u",p);
}
void print(unsigned short p){
printf("%u",p);
}
void print(unsigned int p){
printf("%u",p);
}
void print(unsigned long long p){
printf("%lu",p);
}
void print(float p){
printf("%f",p);
}
void print(double p){
printf("%Lf",p);
}
void print(const std::string &p){
printf("%s",p.c_str());
}
std::string getFileName(int object_num)
{
std::ostringstream oss;
oss << "ai\\" << object_num << ".as";
return oss.str();
}
FileValidity isValidFileName(std::string file)
{
if(file.length()<7) return INVALID;
for(unsigned int i = 0;i<file.length();i++){
if(file.at(i) >= 'A' && file.at(i) <= 'Z') file.at(i) += 'a'-'A';
}
if(file.substr(0,3) != "ai\\") return INVALID;
if(file.at(3) == '_') return MODULE;
size_t i = 3;
if(file.at(i) == '-'){
i = 4;
}
bool zeros = true;
while(i<file.length()-2){
if(zeros && file.at(i) == '0'){
if(file.substr(i) == "0.as") return VALID;
return INVALID;
}
if(file.at(i) == '.'){
if(file.substr(i) == ".as") return VALID;
return INVALID;
}
if(file.at(i) >= '0' && file.at(i) <= '9'){
zeros = INVALID;
i += 1;
continue;
}
return INVALID;
}
return INVALID;
}
std::string getModuleName(const std::string &file){
return file.substr(3,file.length()-3);
}
#ifdef DEBUG_VERSION
bool hasFileTimeChanged(const char *File,FILETIME *Time){
HANDLE hFile;
hFile = CreateFile(File,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL);
FILETIME ftWrite;
if(hFile == INVALID_HANDLE_VALUE){
ftWrite.dwLowDateTime = 0;
ftWrite.dwHighDateTime = 0;
}else{
if(!GetFileTime(hFile,NULL,NULL,&ftWrite)){
CloseHandle(hFile);
return false;
}
CloseHandle(hFile);
}
if(CompareFileTime(&ftWrite,Time) != 0){
(*Time) = ftWrite;
return true;
}
return false;
}
void rebuildIfUpdated(int id_int,const std::string &fileName){
if(ModuleTimes.count(id_int)){
if(hasFileTimeChanged(fileName.c_str(),&(ModuleTimes[id_int]))){
CScriptBuilder Builder;
Builder.DefineWord("debug");
if(fileName.at(0) == '_'){
Builder.DefineWord("module");
}else{
Builder.DefineWord("character");
}
ScriptEngine->WriteMessage(fileName.c_str(),0,0,asMSGTYPE_INFORMATION,"Rebuilding.");
Builder.StartNewModule(ScriptEngine,getModuleName(fileName).c_str());
int r = Builder.AddSectionFromFile(fileName.c_str());
if(r<0){
ScriptEngine->WriteMessage(fileName.c_str(),0,0,asMSGTYPE_ERROR,"Unable to load file.");
ScriptEngine->DiscardModule(getModuleName(fileName).c_str());
return;
}
r = Builder.BuildModule();
if(r<0){
ScriptEngine->WriteMessage(fileName.c_str(),0,0,asMSGTYPE_ERROR,"Unable to build module.");
ScriptEngine->DiscardModule(getModuleName(fileName).c_str());
return;
}
}
}else{
FILETIME Time = {0,0};
if(hasFileTimeChanged(fileName.c_str(),&Time)){
ModuleTimes.insert(std::pair<int,FILETIME>(id_int,Time));
CScriptBuilder Builder;
Builder.DefineWord("debug");
ScriptEngine->WriteMessage(fileName.c_str(),0,0,asMSGTYPE_INFORMATION,"Building.");
Builder.StartNewModule(ScriptEngine,getModuleName(fileName).c_str());
int r = Builder.AddSectionFromFile(fileName.c_str());
if(r<0){
ScriptEngine->WriteMessage(fileName.c_str(),0,0,asMSGTYPE_ERROR,"Unable to load file.");
ScriptEngine->DiscardModule(getModuleName(fileName).c_str());
return;
}
r = Builder.BuildModule();
if(r<0){
ScriptEngine->WriteMessage(fileName.c_str(),0,0,asMSGTYPE_ERROR,"Unable to build module.");
ScriptEngine->DiscardModule(getModuleName(fileName).c_str());
return;
}
}
}
}
int getIdFromFileName(const std::string &file){
int x;
std::stringstream(getModuleName(file)) >> x;
return x;
}
#endif
int callEgo(int object_num,int target_num,asIScriptFunction *Function){
elapsed_time = *(int *)0x450b8c;
difficulty = *(int *)0x450c30;
mode = *(int *)0x451160;
if(background != *(int *)0x44d024){
background = *(int *)0x44d024;
bg_width = game->files->backgrounds[background].bg_width;
bg_zwidth1 = game->files->backgrounds[background].bg_zwidth1;
bg_zwidth2 = game->files->backgrounds[background].bg_zwidth2;
stage_bound = bg_width;
stage_clear = false;
}
if(mode == 1){//stage
stage_bound = *(int *)0x450bb4;
stage_clear = stage_bound == 0;
}
current_phase = *(int *)0x44fb6c;
current_phase_count = *(int *)0x44f880;
current_stage = *(int *)0x450b94;
if((self = object_num) == -1){
#ifdef DEBUG_VERSION
ScriptEngine->WriteMessage(getFileName(game->objects[object_num]->data->id).c_str(),0,0,asMSGTYPE_ERROR,"Unable to prepare self.");
#endif
}
if((target = target_num) == -1){
#ifdef DEBUG_VERSION
ScriptEngine->WriteMessage(getFileName(game->objects[object_num]->data->id).c_str(),0,0,asMSGTYPE_ERROR,"Unable to prepare target.");
#endif
}
int r = ScriptContext->Prepare(Function);
if(r<0){
#ifdef DEBUG_VERSION
ScriptEngine->WriteMessage(getFileName(game->objects[object_num]->data->id).c_str(),0,0,asMSGTYPE_ERROR,"Unable to prepare the context.");
#endif
return 0;
}
r = ScriptContext->Execute();
if(r<0){
#ifdef DEBUG_VERSION
ScriptEngine->WriteMessage(getFileName(game->objects[object_num]->data->id).c_str(),0,0,asMSGTYPE_ERROR,"Unable to execute the context.");
#endif
return 0;
}
return ScriptContext->GetReturnDWord();
}
void callId(int object_num,asIScriptFunction *Function){
elapsed_time = *(int *)0x450b8c;
difficulty = *(int *)0x450c30;
mode = *(int *)0x451160;
if(background != *(int *)0x44d024){
background = *(int *)0x44d024;
bg_width = game->files->backgrounds[background].bg_width;
bg_zwidth1 = game->files->backgrounds[background].bg_zwidth1;
bg_zwidth2 = game->files->backgrounds[background].bg_zwidth2;
stage_bound = bg_width;
stage_clear = false;
}
if(mode == 1){//stage
stage_bound = *(int *)0x450bb4;
stage_clear = stage_bound == 0;
}
current_phase = *(int *)0x44fb6c;
current_phase_count = *(int *)0x44f880;
current_stage = *(int *)0x450b94;
if((self = object_num) == -1){
#ifdef DEBUG_VERSION
ScriptEngine->WriteMessage(getFileName(game->objects[object_num]->data->id).c_str(),0,0,asMSGTYPE_ERROR,"Unable to prepare self.");
#endif
}
int r = ScriptContext->Prepare(Function);
if(r<0){
#ifdef DEBUG_VERSION
ScriptEngine->WriteMessage(getFileName(game->objects[object_num]->data->id).c_str(),0,0,asMSGTYPE_ERROR,"Unable to prepare the context.");
#endif
return;
}
r = ScriptContext->Execute();
#ifdef DEBUG_VERSION
if(r<0){
ScriptEngine->WriteMessage(getFileName(game->objects[object_num]->data->id).c_str(),0,0,asMSGTYPE_ERROR,"Unable to execute the context.");
}
#endif
}
int __stdcall AI(int target_num, int object_num, int unkwn1, int unkwn2, int unkwn3, int unkwn4, int unkwn5)
{
DWORD return_value;
DWORD unkwn6;
__asm
{
mov dword ptr ds:[unkwn6],ecx;
}
int id_int = game->objects[object_num]->data->id;
std::string fileName = getFileName(id_int);
ScriptModule = ScriptEngine->GetModule(getModuleName(fileName).c_str());
if(ScriptModule){
asIScriptFunction *Function = ScriptModule->GetFunctionByDecl("int ego()");
if(Function){
return callEgo(object_num,target_num,Function);
}
}
__asm
{
mov ecx, dword ptr ds:[unkwn5];
push ecx;
mov ecx, dword ptr ds:[unkwn4];
push ecx;
mov ecx, dword ptr ds:[unkwn3];
push ecx;
mov ecx, dword ptr ds:[unkwn2];
push ecx;
mov ecx, dword ptr ds:[unkwn1];
push ecx;
mov ecx, dword ptr ds:[object_num];
push ecx;
mov ecx, dword ptr ds:[target_num];
push ecx;
mov ecx, dword ptr ds:[unkwn6];
call AI_o;
mov dword ptr ds:[return_value], eax;
}
return return_value;
}
void __stdcall AIa( int object_num,int unkwn1)
{
DWORD unkwn2;
_asm
{
mov dword ptr ds:[unkwn2],ecx;
}
int id_int = game->objects[object_num]->data->id;
std::string fileName = getFileName(id_int);
#ifdef DEBUG_VERSION
rebuildIfUpdated(id_int,fileName);
#endif
ScriptModule = ScriptEngine->GetModule(getModuleName(fileName).c_str());
if(ScriptModule){
asIScriptFunction *Function = ScriptModule->GetFunctionByDecl("void id()");
if(Function){
callId(object_num,Function);
return;
}
#ifdef DEBUG_VERSION
else{
if(!ScriptModule->GetFunctionByDecl("int ego()")){
ScriptEngine->WriteMessage(getFileName(game->objects[object_num]->data->id).c_str(),0,0,asMSGTYPE_ERROR,"Neither 'void id()' nor 'int ego()' are defined.");
}
}
#endif
}
_asm
{
mov ecx, dword ptr ds:[unkwn1];
push ecx;
mov ecx, dword ptr ds:[object_num];
push ecx;
mov ecx, dword ptr ds:[unkwn2];
call AIa_o;
}
}
#ifdef DEBUG_VERSION
void MessageCallback(const asSMessageInfo *msg,void *){
if(msg->section[0] == '\0'){
printf("%s: %s\n",msg->type == asMSGTYPE_ERROR?"ERROR":msg->type == asMSGTYPE_WARNING?"WARNING":"INFORMATION",msg->message);
}else if(msg->row == 0 && msg->col == 0){
printf("%s: %s : %s\n",msg->section,msg->type == asMSGTYPE_ERROR?"ERROR":msg->type == asMSGTYPE_WARNING?"WARNING":"INFORMATION",msg->message);
}else{
printf("%s(%d, %d): %s : %s\n",msg->section,msg->row,msg->col,msg->type == asMSGTYPE_ERROR?"ERROR":msg->type == asMSGTYPE_WARNING?"WARNING":"INFORMATION",msg->message);
}
}
#endif
void RegisterScriptFunctions(){
RegisterScriptMath(ScriptEngine);
RegisterScriptMathComplex(ScriptEngine);
RegisterScriptMath3D(ScriptEngine);
RegisterStdString(ScriptEngine);
RegisterScriptArray(ScriptEngine,true);
RegisterStdStringUtils(ScriptEngine);
RegisterGameEnums(ScriptEngine);
RegisterGameArrays(ScriptEngine);
ScriptEngine->RegisterGlobalFunction("void clr()",asFUNCTION(clr),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void print(bool p)",asFUNCTIONPR(print,(bool p),void),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void print(int8 p)",asFUNCTIONPR(print,(char p),void),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void print(int16 p)",asFUNCTIONPR(print,(short p),void),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void print(int32 p)",asFUNCTIONPR(print,(int p),void),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void print(int64 p)",asFUNCTIONPR(print,(long long p),void),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void print(uint8 p)",asFUNCTIONPR(print,(unsigned char p),void),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void print(uint16 p)",asFUNCTIONPR(print,(unsigned short p),void),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void print(uint32 p)",asFUNCTIONPR(print,(unsigned int p),void),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void print(uint64 p)",asFUNCTIONPR(print,(unsigned long long p),void),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void print(float p)",asFUNCTIONPR(print,(float p),void),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void print(double p)",asFUNCTIONPR(print,(double p),void),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void print(const string &in p)",asFUNCTIONPR(print,(const std::string &p),void),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("int loadTarget(int object_num)",asFUNCTION(loadTarget),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("int setEnemy(int object_num)",asFUNCTION(setEnemy),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void up(int8 key = 1,int8 holding = 0)",asFUNCTION(up),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void up(bool key,int8 holding = 0)",asFUNCTION(up),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void up(int8 key,bool holding)",asFUNCTION(up),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void up(bool key,bool holding)",asFUNCTION(up),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void down(int8 key = 1,int8 holding = 0)",asFUNCTION(down),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void down(bool key,int8 holding = 0)",asFUNCTION(down),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void down(int8 key,bool holding)",asFUNCTION(down),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void down(bool key,bool holding)",asFUNCTION(down),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void left(int8 key = 1,int8 holding = 0)",asFUNCTION(left),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void left(bool key,int8 holding = 0)",asFUNCTION(left),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void left(int8 key,bool holding)",asFUNCTION(left),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void left(bool key,bool holding)",asFUNCTION(left),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void right(int8 key = 1,int8 holding = 0)",asFUNCTION(right),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void right(bool key,int8 holding = 0)",asFUNCTION(right),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void right(int8 key,bool holding)",asFUNCTION(right),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void right(bool key,bool holding)",asFUNCTION(right),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void A(int8 key = 1,int8 holding = 0)",asFUNCTION(A),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void A(bool key,int8 holding = 0)",asFUNCTION(A),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void A(int8 key,bool holding)",asFUNCTION(A),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void A(bool key,bool holding)",asFUNCTION(A),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void J(int8 key = 1,int8 holding = 0)",asFUNCTION(J),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void J(bool key,int8 holding = 0)",asFUNCTION(J),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void J(int8 key,bool holding)",asFUNCTION(J),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void J(bool key,bool holding)",asFUNCTION(J),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void D(int8 key = 1,int8 holding = 0)",asFUNCTION(D),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void D(bool key,int8 holding = 0)",asFUNCTION(D),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void D(int8 key,bool holding)",asFUNCTION(D),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void D(bool key,bool holding)",asFUNCTION(D),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void DrA()",asFUNCTION(DrA),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void DlA()",asFUNCTION(DlA),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void DuA()",asFUNCTION(DuA),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void DdA()",asFUNCTION(DdA),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void DrJ()",asFUNCTION(DrJ),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void DlJ()",asFUNCTION(DlJ),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void DuJ()",asFUNCTION(DuJ),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void DdJ()",asFUNCTION(DdJ),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("void DJA()",asFUNCTION(DJA),asCALL_CDECL);
ScriptEngine->RegisterGlobalFunction("int rand(int n)",asFUNCTION(random),asCALL_CDECL);
ScriptEngine->RegisterGlobalProperty("const int mode",&mode);
ScriptEngine->RegisterGlobalProperty("const int difficulty",&difficulty);
ScriptEngine->RegisterGlobalProperty("const int elapsed_time",&elapsed_time);
ScriptEngine->RegisterGlobalProperty("const int background",&background);
ScriptEngine->RegisterGlobalProperty("const int bg_width",&bg_width);
ScriptEngine->RegisterGlobalProperty("const int bg_zwidth1",&bg_zwidth1);
ScriptEngine->RegisterGlobalProperty("const int bg_zwidth2",&bg_zwidth2);
ScriptEngine->RegisterGlobalProperty("const int stage_bound",&stage_bound);
ScriptEngine->RegisterGlobalProperty("const bool stage_clear",&stage_clear);
ScriptEngine->RegisterGlobalProperty("const int current_phase",¤t_phase);
ScriptEngine->RegisterGlobalProperty("const int current_phase_count",¤t_phase_count);
ScriptEngine->RegisterGlobalProperty("const int current_stage",¤t_stage);
ScriptEngine->RegisterObjectType("Info",0,asOBJ_REF);
ScriptEngine->RegisterObjectBehaviour("Info",asBEHAVE_ADDREF,"void f()",asMETHOD(Info,AddRef),asCALL_THISCALL);
ScriptEngine->RegisterObjectBehaviour("Info",asBEHAVE_RELEASE,"void f()",asMETHOD(Info,RelRef),asCALL_THISCALL);
ScriptEngine->RegisterObjectBehaviour("Info",asBEHAVE_FACTORY,"Info @f()",asFUNCTIONPR(Info_Factory,(),Info*),asCALL_CDECL);
ScriptEngine->RegisterObjectBehaviour("Info",asBEHAVE_FACTORY,"Info @f(int)",asFUNCTIONPR(Info_Factory,(int object_num),Info*),asCALL_CDECL);
ScriptEngine->RegisterObjectBehaviour("Info",asBEHAVE_FACTORY,"Info @f(const Info &in info)",asFUNCTIONPR(Info_Factory,(const Info &info),Info*),asCALL_CDECL);
ScriptEngine->RegisterObjectMethod("Info","int opAssign(int object_num)",asMETHODPR(Info,operator=,(int object_num),int),asCALL_THISCALL);
ScriptEngine->RegisterObjectMethod("Info","int opAssign(const Info &in info)",asMETHODPR(Info,operator=,(const Info &info),int),asCALL_THISCALL);
ScriptEngine->RegisterObjectMethod("Info","int opAddAssign(int object_num)",asMETHODPR(Info,operator+=,(int object_num),int),asCALL_THISCALL);
ScriptEngine->RegisterObjectMethod("Info","int opAddAssign(const Info &in info)",asMETHODPR(Info,operator+=,(const Info &info),int),asCALL_THISCALL);
ScriptEngine->RegisterObjectMethod("Info","int opSubAssign(int object_num)",asMETHODPR(Info,operator-=,(int object_num),int),asCALL_THISCALL);
ScriptEngine->RegisterObjectMethod("Info","int opSubAssign(const Info &in info)",asMETHODPR(Info,operator-=,(const Info &info),int),asCALL_THISCALL);
ScriptEngine->RegisterObjectMethod("Info","int opPreInc()",asMETHODPR(Info,operator++,(),int),asCALL_THISCALL);
ScriptEngine->RegisterObjectMethod("Info","int opPreSub()",asMETHODPR(Info,operator--,(),int),asCALL_THISCALL);
ScriptEngine->RegisterObjectMethod("Info","int opPostInc()",asMETHODPR(Info,operator++,(),int),asCALL_THISCALL);
ScriptEngine->RegisterObjectMethod("Info","int opPostSub()",asMETHODPR(Info,operator--,(),int),asCALL_THISCALL);
ScriptEngine->RegisterObjectProperty("Info","int x",asOFFSET(Info,x));
ScriptEngine->RegisterObjectProperty("Info","int y",asOFFSET(Info,y));
ScriptEngine->RegisterObjectProperty("Info","int z",asOFFSET(Info,z));
ScriptEngine->RegisterObjectProperty("Info","vector3 position",asOFFSET(Info,position));
ScriptEngine->RegisterObjectProperty("Info","double x_real",asOFFSET(Info,x_real));
ScriptEngine->RegisterObjectProperty("Info","double y_real",asOFFSET(Info,y_real));
ScriptEngine->RegisterObjectProperty("Info","double z_real",asOFFSET(Info,z_real));
ScriptEngine->RegisterObjectProperty("Info","bool facing",asOFFSET(Info,facing));
ScriptEngine->RegisterObjectProperty("Info","bool holding_up",asOFFSET(Info,holding_up));
ScriptEngine->RegisterObjectProperty("Info","bool holding_down",asOFFSET(Info,holding_down));
ScriptEngine->RegisterObjectProperty("Info","bool holding_left",asOFFSET(Info,holding_left));
ScriptEngine->RegisterObjectProperty("Info","bool holding_right",asOFFSET(Info,holding_right));