-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses.cpp
More file actions
1852 lines (1386 loc) · 45.1 KB
/
classes.cpp
File metadata and controls
1852 lines (1386 loc) · 45.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
#include "classes.h"
#include "eorder.h"
//ENEMY STUFF
void PullEnemies(FILE* rom, struct Enemy* enemy)
{
long int offset = 0;
int a;
int b;
unsigned char ch;
fseek(rom, 0x1597e7, SEEK_SET);
fflush(rom);
for (a = 0; a < 230; a++)
{
enemy[a].number = a;
enemy[a].address = 1415143 + offset;
enemy[a].theFlag = fgetc(rom);
for (b = 0; b < 25; b++)
{
ch = fgetc(rom);
if (ch == 0)
enemy[a].name[b] = 0;
else
enemy[a].name[b] = ch - 48;
}
ch = fgetc(rom); // Unknown, varies from 0-3 or so
// unknown5.txt
enemy[a].type = fgetc(rom); // 0 - normal, 1 - insect, 2 - metal
enemy[a].insidePic = fgetc(rom);
enemy[a].insidePic += (fgetc(rom) << 8);
enemy[a].outsidePic = fgetc(rom);
enemy[a].outsidePic += (fgetc(rom) << 8);
enemy[a].runFlag = fgetc(rom);
enemy[a].hp = fgetc(rom);
enemy[a].hp += (fgetc(rom) * 256);
enemy[a].pp = fgetc(rom);
enemy[a].pp += (fgetc(rom) * 256);
enemy[a].exp = fgetc(rom);
enemy[a].exp += (fgetc(rom) * 256);
enemy[a].exp += (fgetc(rom) * 256 * 256);
enemy[a].exp += (fgetc(rom) * 256 * 256 * 256);
enemy[a].money = fgetc(rom);
enemy[a].money += (fgetc(rom) * 256);
enemy[a].movement = fgetc(rom);
ch = fgetc(rom); // Appears to always be 0
enemy[a].startAddress = fgetc(rom);
enemy[a].startAddress += (fgetc(rom) << 8);
enemy[a].startAddress += (fgetc(rom) << 16);
enemy[a].startAddress += (fgetc(rom) << 24);
enemy[a].dieAddress = fgetc(rom);
enemy[a].dieAddress += (fgetc(rom) << 8);
enemy[a].dieAddress += (fgetc(rom) << 16);
enemy[a].dieAddress += (fgetc(rom) << 24);
enemy[a].palette = fgetc(rom);
enemy[a].level = fgetc(rom);
enemy[a].music = fgetc(rom);
enemy[a].offense = fgetc(rom);
ch = fgetc(rom); // Appears to always be 0
enemy[a].defense = fgetc(rom);
ch = fgetc(rom); // Unknown, but mostly 0, sometimes 1
// unknown4.txt
enemy[a].speed = fgetc(rom);
enemy[a].guts = fgetc(rom);
enemy[a].iq = fgetc(rom);
ch = fgetc(rom); // Appears to vary from 0-4 or so
ch = fgetc(rom); // Appears to vary from 0-3
ch = fgetc(rom); // Appears to vary from 0-3
ch = fgetc(rom); // Appears to vary from 0-3
ch = fgetc(rom); // Appears to vary from 0-3
enemy[a].missRate = fgetc(rom); // 0 = almost never, 255 = always
enemy[a].order = fgetc(rom);
enemy[a].action[0] = fgetc(rom);
enemy[a].action[0] += (fgetc(rom) << 8);
enemy[a].action[1] = fgetc(rom);
enemy[a].action[1] += (fgetc(rom) << 8);
enemy[a].action[2] = fgetc(rom);
enemy[a].action[2] += (fgetc(rom) << 8);
enemy[a].action[3] = fgetc(rom);
enemy[a].action[3] += (fgetc(rom) << 8);
enemy[a].finalAction = fgetc(rom);
enemy[a].finalAction += (fgetc(rom) << 8);
enemy[a].amigo[0] = fgetc(rom);
enemy[a].amigo[1] = fgetc(rom);
enemy[a].amigo[2] = fgetc(rom);
enemy[a].amigo[3] = fgetc(rom);
ch = fgetc(rom); // dunno, always 0, except Carbon Dog, who has 83
ch = fgetc(rom); // seems to be size, or maybe precedence, possibly
// linked to calling enemies, unknown3.txt
enemy[a].bossFlag = fgetc(rom);
enemy[a].freq = fgetc(rom);
enemy[a].item = fgetc(rom);
enemy[a].status = fgetc(rom);
enemy[a].dieSound = fgetc(rom);
ch = fgetc(rom); // Has to do with battle layout, 0 or 1
// unknown2.txt
enemy[a].maxCall = fgetc(rom); // Very max = 8
ch = fgetc(rom); // Unknown, numbers vary somewhat, maybe enemy type
// unknown1.txt
offset += 94;
}
}
void Enemy::ChangeTheFlag(FILE* rom, unsigned char newValue)
{
// rom must already be open, and in write mode
// is assumed newValue is 0 or 1
// if newValue is 1, then this enemy will have the word "the"
// displayed in front of its name during battle
fseek(rom, address, SEEK_SET);
fflush(rom);
fputc(newValue, rom);
theFlag = newValue;
}
void Enemy::ChangeName(FILE* rom, char* newName)
{
// Assumes rom is in write binary mode
// Assumes newName is 25 characters long, last one is 0
fseek(rom, address + 1, SEEK_SET);
fflush(rom);
for (int i = 0; i < 25; i++)
{
if (newName[i] == 0)
{
fputc(0, rom);
name[i] = 0;
}
else
{
fputc(newName[i] + 48, rom);
name[i] = newName[i];
}
}
}
void Enemy::ChangeInsidePic(FILE* rom, unsigned char newValue)
{
// Assumes rom is in write binary mode
// Allowed values are found in a file called inside.txt.
// It may turn out that the inside pic is decided using an address
// instead of an array index. I'll keep you posted.
fseek(rom, address + 28, SEEK_SET);
fflush(rom);
fputc(newValue, rom);
insidePic = newValue;
}
void Enemy::ChangeOutsidePic(FILE* rom, int newValue)
{
// Assumes rom is in write binary mode
// Allowed values for newValue are written in a text file called
// outside.txt
fseek(rom, address + 30, SEEK_SET);
fflush(rom);
// fputc(newValue, rom);
fputc(newValue & 255, rom);
fputc((newValue >> 8) & 255, rom);
outsidePic = newValue;
}
void Enemy::ChangeRunFlag(FILE* rom, unsigned char newValue)
{
// Assumes rom is in write binary mode
// Have no idea of possible #'s, except that only 6 and 7 are used
// in EarthBound. I'll figure this out later.
fseek(rom, address + 32, SEEK_SET);
fflush(rom);
fputc(newValue, rom);
runFlag = newValue;
}
void Enemy::ChangeHp(FILE* rom, unsigned int newValue)
{
// Assumes rom is in write binary mode
// Assumes integer is from 0 to 65535
fseek(rom, address + 33, SEEK_SET);
fflush(rom);
fputc(newValue & 255, rom);
fputc((newValue >> 8) & 255, rom);
hp = newValue;
}
void Enemy::ChangePp(FILE* rom, unsigned int newValue)
{
// Assumes rom is in write binary mode
// Assumes integer is from 0 to 65535
fseek(rom, address + 35, SEEK_SET);
fflush(rom);
fputc(newValue & 255, rom);
fputc((newValue >> 8) & 255, rom);
pp = newValue;
}
void Enemy::ChangeExp(FILE* rom, unsigned int newValue)
{
// Assumes rom is in write binary mode
// Assumes integer is from 0 to 2^32 (over 4 billion!)
fseek(rom, address + 37, SEEK_SET);
fflush(rom);
fputc(newValue & 255, rom);
fputc((newValue >> 8) & 255 , rom);
fputc((newValue >> 16) & 255, rom);
fputc((newValue >> 24) & 255, rom);
exp = newValue;
}
void Enemy::ChangeMoney(FILE* rom, unsigned int newValue)
{
// Assumes rom is in write binary mode
// Assumes integer is from 0 to 65535
fseek(rom, address + 41, SEEK_SET);
fflush(rom);
fputc(newValue & 255, rom);
fputc((newValue >> 8) & 255, rom);
money = newValue;
}
void Enemy::ChangeSpeed(FILE* rom, unsigned char newValue)
{
// Assumes rom is in write binary mode
// Allowed values are from 0 - 255
fseek(rom, address + 60, SEEK_SET);
fflush(rom);
fputc(newValue, rom);
speed = newValue;
}
void Enemy::ChangePalette(FILE* rom, unsigned char newValue)
{
// Assumes rom is in write binary mode
// Valid #'s are from 0 - 31
// Maybe later I'll have exact palette info for ya
fseek(rom, address + 53, SEEK_SET);
fflush(rom);
fputc(newValue, rom);
palette = newValue;
}
void Enemy::ChangeOffense(FILE* rom, unsigned char newValue)
{
// Assumes rom is in write binary mode
// Allowed values are from 0-255
fseek(rom, address + 56, SEEK_SET);
fflush(rom);
fputc(newValue, rom);
offense = newValue;
}
void Enemy::ChangeDefense(FILE* rom, unsigned char newValue)
{
// Assumes rom is in write binary mode
// Allowed values are from 0-255
fseek(rom, address + 58, SEEK_SET);
fflush(rom);
fputc(newValue, rom);
defense = newValue;
}
void Enemy::ChangeItem(FILE* rom, unsigned char newValue)
{
// Assumes rom is in write binary mode
// Allowed values are 0-255, but 254 and 255 are sorta non-existent
// items (at least in EB...)
fseek(rom, address + 88, SEEK_SET);
fflush(rom);
fputc(newValue, rom);
item = newValue;
}
void Enemy::ChangeFreq(FILE* rom, unsigned char newValue)
{
// Assumes rom is in write binary mode
// Allowed values are from 0-7
// The frequency equation seems to work this way:
// drop percentage = (2^newValue)/128 of a chance
// Thanks for bringing that to my attention, Spiffage ;)
fseek(rom, address + 87, SEEK_SET);
fflush(rom);
fputc(newValue, rom);
freq = newValue;
}
void Enemy::ChangeStatus(FILE* rom, unsigned char newValue)
{
// Assumes rom is in write binary mode
// Allowed values are found in a file called enstatus.txt.
fseek(rom, address + 89, SEEK_SET);
fflush(rom);
fputc(newValue, rom);
status = newValue;
}
void Enemy::ChangeAction(FILE* rom, int newValue, int index)
{
// Assumes rom is in write binary mode
// Allowed values for newValue are shown in effects.txt
// Allowed values for index are 0-3. index is the specific action
// to be edited. i.e. action[0], action[1], action[2], or action[3]
fseek(rom, address + 70 + (index * 2), SEEK_SET);
fflush(rom);
fputc(newValue & 255, rom);
fputc((newValue >> 8) & 255, rom);
action[index] = newValue;
}
void Enemy::ChangeFinalAction(FILE* rom, int newValue)
{
// Assumes rom is in write binary mode
// Allowed values for newValue are listed in effects.txt
fseek(rom, address + 78, SEEK_SET);
fflush(rom);
fputc(newValue & 255, rom);
fputc((newValue >> 8) & 255, rom);
finalAction = newValue;
}
void Enemy::ChangeLevel(FILE* rom, unsigned char newValue)
{
// Assumes rom is in write binary mode
// Allowed values for newValue are 0 to 255
fseek(rom, address + 54, SEEK_SET);
fflush(rom);
fputc(newValue, rom);
level = newValue;
}
void Enemy::ChangeGuts(FILE* rom, unsigned char newValue)
{
// Assumes rom is in write binary mode
// Allowed values for newValue are 0 to 255
fseek(rom, address + 61, SEEK_SET);
fflush(rom);
fputc(newValue, rom);
guts = newValue;
}
void Enemy::ChangeIq(FILE* rom, unsigned char newValue)
{
// Assumes rom is in write binary mode
// Allowed values for newValue are 0 to 255
fseek(rom, address + 62, SEEK_SET);
fflush(rom);
fputc(newValue, rom);
iq = newValue;
}
void Enemy::ChangeStartAction(FILE* rom, unsigned int newValue)
{
// Assumes rom is in write binary mode
// Allowed values for newValue appear to be 0 to 2^32. But not all
// values will be happy. newValue acts sort of as a pointer to
// the game text. Except I haven't figured out why it's a 32 bit
// address or number.
fseek(rom, address + 45, SEEK_SET);
fflush(rom);
fputc(newValue & 255, rom);
fputc((newValue >> 8) & 255, rom);
fputc((newValue >> 16) & 255, rom);
fputc((newValue >> 24) & 255, rom);
startAddress = newValue;
}
void Enemy::ChangeDieAction(FILE* rom, unsigned int newValue)
{
// Assumes rom is in write binary mode
// Allowed values for newValue appear to be 0 to 2^32. Works like
// ChangeStartAction.
fseek(rom, address + 49, SEEK_SET);
fflush(rom);
fputc(newValue & 255, rom);
fputc((newValue >> 8) & 255, rom);
fputc((newValue >> 16) & 255, rom);
fputc((newValue >> 24) & 255, rom);
dieAddress = newValue;
}
void Enemy::ChangeMovement(FILE* rom, unsigned char newValue)
{
// Assumes rom is in write binary mode
// Allowed values for newValue are given in movement.txt
// Note that any values other than listed in that text file
// may result in unplayable roms and or totally screwy stuff
// may occur.
fseek(rom, address + 43, SEEK_SET);
fflush(rom);
fputc(newValue, rom);
movement = newValue;
}
void Enemy::ChangeOrder(FILE* rom, unsigned char newValue)
{
// Assumes rom is in write binary mode
// Changes the order in which enemies attack, depending on
// newValue, which can be one of 4 numbers:
// 0 - Random
// 1 - Random, but tends to do the 3rd attack often
// 2 - In order (Attack 1, Attack 2, Attack 3, Attack 4, repeat...)
// 3 - "Staggered Order" (difficult to explain, just it goes something
// like "Attack 3, 4, 3, 4, 3, 4, 3, 1, 2, 1, 2, etc. It's not
// a very logical pattern, but it's a pattern. This is what Buzz
// Buzz does when he's in your party, and what other enemies do to.
// Just call it "Staggered Order" in the GUI, cuz it's too hard
// to figure out a better name for it.
fseek(rom, address + 69, SEEK_SET);
fflush(rom);
fputc(newValue, rom);
order = newValue;
}
void Enemy::ChangeFriend(FILE* rom, unsigned char slot, unsigned char enVal)
{
// Assumes rom is in write binary mode
// slot is from 0 to 3, designates one of the four friends this enemy
// can have.
// enVal is the number ID of the new enemy to be put in the given slot.
// (Internal note: I have to add 1 to enVal, for some reason. Weird.)
fseek(rom, address + 80 + slot, SEEK_SET);
fflush(rom);
fputc(enVal, rom);
amigo[slot] = enVal; // I don't add 1 here for confusing reasons
}
void Enemy::ChangeMaxCall(FILE* rom, unsigned char newValue)
{
// Assumes rom is in write binary mode
// newValue can be from 0 to 255, but the game will only allow a max of
// 8 it seems. Anything over 8 seems to be treated as 8. Best to leave
// this fully editable with a text field instead of a dropdown list.
// This function changes how many called enemies there can be total.
fseek(rom, address + 92, SEEK_SET);
fflush(rom);
fputc(newValue, rom);
maxCall = newValue;
}
void Enemy::ChangeMissRate(FILE* rom, unsigned char newValue)
{
// Assumes rom is in write binary mode
// newValue can be from 0 to 255. 0 means never miss, 255 means always
// miss. This is when they attack you. Anyway, I'm not completely sure
// how this figures in with your speed setting or whatever. Perhaps there
// are supposed to be enemies that always hit you, no matter what your
// speed or something.
fseek(rom, address + 68, SEEK_SET);
fflush(rom);
fputc(newValue, rom);
missRate = newValue;
}
void Enemy::ChangeDieSound(FILE* rom, unsigned char newValue)
{
// Assumes rom is in write binary mode
// newValue can be 0 or 1. Other values *may* be allowed, but all the
// other ones I tried just did the same as if it were just 1.
// This changes the sound as the enemy is fading away. 0 makes it sound
// like how a normal enemy dies. 1 makes it sound a bit like how bosses
// die.
fseek(rom, address + 90, SEEK_SET);
fflush(rom);
fputc(newValue, rom);
dieSound = newValue;
}
void Enemy::ChangeType(FILE* rom, unsigned char newValue)
{
// Assumes rom is in write binary mode
// Allowed values are from 0 - normal, 1 - insect, 2 - metal
fseek(rom, address + 27, SEEK_SET);
fflush(rom);
fputc(newValue, rom);
type = newValue;
}
void Enemy::ChangeMusic(FILE* rom, unsigned char newValue)
{
// Assumes rom is in write binary form
// Allowed values are from 0 to 191
fseek(rom, address + 55, SEEK_SET);
fflush(rom);
fputc(newValue, rom);
music = newValue;
}
int Enemy::CanCall(void)
{
// Returns 1 if this enemy has at least one action that will let it
// call enemies. Returns 0 if it doesn't have any enemy-calling
// actions.
// I wrote this in here for some possible stuff we'll want to use for
// internal code of PK Hack, but for now you prolly won't need it.
int returnVal = 0;
if (action[0] == 62 || action[1] == 62 || action[2] == 62 || action[3] == 62)
returnVal = 1;
else if (action[0] == 63 || action[1] == 63 || action[2] == 63 || action[3] == 63)
returnVal = 1;
return returnVal;
}
void SortEnemiesAlpha(Enemy* enemy)
{
// Assumes enemy is allocated with at least 230 entries.
// Only entries 0 through 229 will be rearranged alphabetically
// (ascending order).
// In the case that two enemies have the same name, they're rearranged
// according to the "number" field, in ascending order.
// No complaining anymore, spaan! ;)
Enemy temp;
char currName[25];
char bigName[25];
int biggest;
int result;
int tempNum;
int i;
int j;
for (i = 0; i < 229; i++)
{
biggest = i;
for (j = i; j < 230; j++)
{
strcpy(bigName, enemy[biggest].name);
strcpy(currName, enemy[j].name);
strupr(bigName);
strupr(currName);
result = strcmp(currName, bigName);
if (result < 0)
biggest = j;
else if (result == 0)
{
if (enemy[biggest].number > enemy[j].number)
biggest = j;
}
}
if (biggest != i)
SwapEnemy(enemy[i], enemy[biggest]);
}
}
void SwapEnemy(Enemy& enemy1, Enemy& enemy2)
{
Enemy temp;
temp = enemy1;
strcpy(temp.name, enemy1.name);
temp.action[0] = enemy1.action[0];
temp.action[1] = enemy1.action[1];
temp.action[2] = enemy1.action[2];
temp.action[3] = enemy1.action[3];
enemy1 = enemy2;
strcpy(enemy1.name, enemy2.name);
enemy1.action[0] = enemy2.action[0];
enemy1.action[1] = enemy2.action[1];
enemy1.action[2] = enemy2.action[2];
enemy1.action[3] = enemy2.action[3];
enemy2 = temp;
strcpy(enemy2.name, temp.name);
enemy2.action[0] = temp.action[0];
enemy2.action[1] = temp.action[1];
enemy2.action[2] = temp.action[2];
enemy2.action[3] = temp.action[3];
}
void SortEnemiesGameOrder(Enemy* enemy)
{
// Sorts this enemy array into the order listed in eorder.h
// Assumes there are at least 230 entries allocated in the array
// Only entries 0 thru 229 are sorted.
int i;
int j;
for (i = 0; i < 229; i++)
{
for (j = i; j < 230; j++)
{
if (enemy[j].number == enemyGameOrder[i])
SwapEnemy(enemy[j], enemy[i]);
}
}
}
void SortEnemiesOriginal(Enemy* enemy)
{
// Assumes enemy is allocated with at least 230 entries.
// Only entries 0 through 229 will be rearranged.
// The enemy array gets rearranged to the original order as the items
// appear in the ROM. In other words, the order you get is exactly
// the same as if you had just called PullEnemies.
Enemy temp;
char currName[25];
char bigName[25];
int biggest;
int result;
int tempNum;
int i;
int j;
for (i = 0; i < 229; i++)
{
biggest = i;
for (j = i; j < 230; j++)
{
if (enemy[biggest].number > enemy[j].number)
biggest = j;
}
if (biggest != i)
SwapEnemy(enemy[i], enemy[biggest]);
}
}
int SearchEnemy(Enemy* enemy, char* searchStr, int results[])
{
int index = 0;
for (int i = 0; i < 230; i++)
{
if (strstr(enemy[i].name, searchStr) != NULL)
results[index++] = i; // enemy[i].number;
}
return index;
}
void DumpEnemies(Enemy* enemy, char* filename, int stats, int actions, int gfx)
{
// Dumps enemy information into a text file.
// If stats is non-zero, stats info will be printed
// If actions is non-zero, action info will be printed
// If gfx is non-zero, gfx info will be printed
FILE* dumpFile;
dumpFile = fopen(filename, "w");
fprintf(dumpFile, "EarthBound enemy info dump generated by PK Hack\n");
fprintf(dumpFile, "PK Hack by Tomato (tomato@starmen.net)");
fprintf(dumpFile, " and spaanoft (spaanoft@starmen.net)\n");
fprintf(dumpFile, "--------------------------------------");
fprintf(dumpFile, "------------------------------------\n\n");
for (int i = 0; i < 230; i++)
{
fprintf(dumpFile, "Enemy #: %d\n", enemy[i].number);
fprintf(dumpFile, "Name: %s\n", enemy[i].name);
if (stats)
{
fprintf(dumpFile, "the Flag: %d\n", enemy[i].theFlag);
fprintf(dumpFile, "HP: %d\n", enemy[i].hp);
fprintf(dumpFile, "PP: %d\n", enemy[i].pp);
fprintf(dumpFile, "Exp: %u\n", enemy[i].exp);
fprintf(dumpFile, "Money: $%d\n", enemy[i].money);
fprintf(dumpFile, "Speed: %d\n", enemy[i].speed);
fprintf(dumpFile, "Offense: %d\n", enemy[i].offense);
fprintf(dumpFile, "Defense: %d\n", enemy[i].defense);
fprintf(dumpFile, "Status: %d\n", enemy[1].status);
fprintf(dumpFile, "Level: %d\n", enemy[i].level);
fprintf(dumpFile, "Guts: %d\n", enemy[i].guts);
fprintf(dumpFile, "IQ: %d\n", enemy[i].iq);
fprintf(dumpFile, "Miss rate: %d\n", enemy[i].missRate);
fprintf(dumpFile, "Item: %d\n", enemy[i].item);
fprintf(dumpFile, "Drop %%: %d\n", enemy[i].freq);
fprintf(dumpFile, "Type: %d\n", enemy[i].type);
fprintf(dumpFile, "Music: %s\n", bgm[enemy[i].music]);
fprintf(dumpFile, "Die Sound: %d\n", enemy[i].dieSound);
fprintf(dumpFile, "Is a Boss: %d\n", enemy[i].bossFlag);
}
if (actions)
{
fprintf(dumpFile, "Action 1: %s\n", action[enemy[i].action[0]]);
fprintf(dumpFile, "Action 2: %s\n", action[enemy[i].action[1]]);
fprintf(dumpFile, "Action 3: %s\n", action[enemy[i].action[2]]);
fprintf(dumpFile, "Action 4: %s\n", action[enemy[i].action[3]]);
fprintf(dumpFile, "Order: %d\n", enemy[i].order);
fprintf(dumpFile, "F. Action: %s\n", action[enemy[i].finalAction]);
fprintf(dumpFile, "Arg. 1: %d\n", enemy[i].amigo[0]);
fprintf(dumpFile, "Arg. 2: %d\n", enemy[i].amigo[1]);
fprintf(dumpFile, "Arg. 3: %d\n", enemy[i].amigo[2]);
fprintf(dumpFile, "Arg. 4: %d\n", enemy[i].amigo[3]);
fprintf(dumpFile, "Max Call: %d\n", enemy[i].maxCall);
fprintf(dumpFile, "S Address: 0x%x\n", enemy[i].startAddress);
fprintf(dumpFile, "D Address: 0x%x\n", enemy[i].dieAddress);
}
if (gfx)
{
fprintf(dumpFile, "Out Pic #: %d\n", enemy[i].outsidePic);
fprintf(dumpFile, "Movement: %d\n", enemy[i].movement);
fprintf(dumpFile, "In Pic #: %d\n", enemy[i].insidePic);
fprintf(dumpFile, "Palette #: %d\n", enemy[i].palette);
}
fprintf(dumpFile, "\n");
}
fclose(dumpFile);
}
void PullItems(FILE* rom, Item* item)
{
// Assumes rom is in read binary
// Assumes item is an array of 256 Item types
char ch;
int offset = 0;
fseek(rom, 0x155200, SEEK_SET);
fflush(rom);
for (int i = 0; i < 256; i++)
{
item[i].number = i;
item[i].address = 0x155200 + offset;
for (int j = 0; j < 25; j++)
{
ch = fgetc(rom);
if (ch == 0)
item[i].name[j] = 0;
else
item[i].name[j] = ch - 48;
}
item[i].type = fgetc(rom);
item[i].cost = fgetc(rom);
item[i].cost += (fgetc(rom) << 8);
item[i].ownership = fgetc(rom);
item[i].effect = fgetc(rom);
item[i].effect += (fgetc(rom) << 8);
item[i].strength = fgetc(rom);
item[i].increase = fgetc(rom);
item[i].extraPower = fgetc(rom);
item[i].specialProperties = fgetc(rom);
item[i].descAddress = fgetc(rom);
item[i].descAddress += (fgetc(rom) << 8);
item[i].descAddress += (fgetc(rom) << 16);
item[i].descAddress += (fgetc(rom) << 24);
offset += 39;
}
}
void Item::ChangeName(FILE* rom, char* newName)
{
// Assumes rom is in write binary
// Assumes newName is at most 25 characters (last one being null)
fseek(rom, address, SEEK_SET);
fflush(rom);
for (int i = 0; i < 25; i++)
{
if (newName[i] == 0)
fputc(0, rom);
else
fputc(newName[i] + 48, rom);
name[i] = newName[i];
}
}
void Item::ChangeType(FILE* rom, unsigned char newValue)
{
// Assumes rom is in write binary mode
// Input values are limited, so please use the following chart:
// 16 = Weapon
// 20 = Body equipment
// 24 = Arm Equipment
// 28 = Other Equipment
// 32 = if edible item, will say "... ate the ..."
// 36 = if edible item, will say "... drank the ..."
// 40 = condiment
// Here are other possible #'s, but their effect on the game
// don't appear to be noticeable, so don't implement these until
// I figure them out better.
// 0 = no idea (only the Franklin Badge uses it)
// 2 = only one of the semi-non-existent items uses it, prolly useless
// 4 = Teddy Bear flag
// 8 = Broken item
// 44 = large pizza?
// 48 = healing item
// 52 = weird item, seems to mostly be stuff that affects enemy status
// 53 = no idea (dragonite, fly honey, etc.)
// 56 = no idea (piggy nose, for sale sign, etc.)
// 58 = no idea (bicycle, hawk eye, zombie paper only)
// 59 = important event item
// 255 = Null
fseek(rom, address + 25, SEEK_SET);
fflush(rom);
fputc(newValue, rom);
type = newValue;
}
void Item::ChangeCost(FILE* rom, int newValue)
{
// Assumes rom is in write binary mode
// newValue must be from 0 to 65535
fseek(rom, address + 26, SEEK_SET);
fflush(rom);
fputc(newValue & 255, rom);
fputc((newValue >> 8) & 255, rom);
cost = newValue;
}
void Item::ChangeOwnership(FILE* rom, unsigned char newValue)
{
// Assumes rom is in write binary mode.