forked from dethrace-labs/dethrace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloading.c
3630 lines (3315 loc) · 127 KB
/
loading.c
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 "loading.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "brender/brender.h"
#include "brucetrk.h"
#include "car.h"
#include "constants.h"
#include "controls.h"
#include "crush.h"
#include "depth.h"
#include "displays.h"
#include "drmem.h"
#include "errors.h"
#include "flicplay.h"
#include "globvars.h"
#include "globvrkm.h"
#include "globvrpb.h"
#include "grafdata.h"
#include "graphics.h"
#include "harness/config.h"
#include "harness/hooks.h"
#include "harness/trace.h"
#include "init.h"
#include "input.h"
#include "newgame.h"
#include "opponent.h"
#include "pd/sys.h"
#include "pedestrn.h"
#include "racestrt.h"
#include "sound.h"
#include "spark.h"
#include "utility.h"
#include "world.h"
#include <errno.h>
#define HITHER_MULTIPLIER 2.0f
#define AMBIENT_MULTIPLIER 0.01f
#define NBR_FUNK_GROVE_FLAGS 30
#define OPPONENT_APC_IDX 3
tHeadup_info gHeadup_image_info[32] = {
// Modified by DethRace to fit the "demo timeout" fancy head-up.
{ "LADY.PIX", eNet_or_otherwise },
{ "GENT.PIX", eNet_or_otherwise },
{ "CODGER.PIX", eNet_or_otherwise },
{ "SPROG.PIX", eNet_or_otherwise },
{ "GO.PIX", eNet_or_otherwise },
{ "NUMBER1.PIX", eNet_or_otherwise },
{ "NUMBER2.PIX", eNet_or_otherwise },
{ "NUMBER3.PIX", eNet_or_otherwise },
{ "NUMBER4.PIX", eNet_or_otherwise },
{ "NUMBER5.PIX", eNet_or_otherwise },
{ "SPLATTER.PIX", eNet_or_otherwise },
{ "PILEDRIV.PIX", eNet_or_otherwise },
{ "EXTRASTY.PIX", eNet_or_otherwise },
{ "ARTISTIC.PIX", eNet_or_otherwise },
{ "2XCOMBO.PIX", eNet_or_otherwise },
{ "3XCOMBO.PIX", eNet_or_otherwise },
{ "4XCOMBO.PIX", eNet_or_otherwise },
{ "5XCOMBO.PIX", eNet_or_otherwise },
{ "BILLIARD.PIX", eNet_or_otherwise },
{ "POLITE.PIX", eNet_or_otherwise },
{ "HEADON.PIX", eNet_or_otherwise },
{ "DESTROY.PIX", eNet_or_otherwise },
{ "CHECKPNT.PIX", eNet_or_otherwise },
{ "TIMEUP.PIX", eNot_net },
{ "RACEOVER.PIX", eNet_or_otherwise },
{ "UWASTED.PIX", eNet_only },
{ "MAD.PIX", eNet_only },
{ "GAMEOVER.PIX", eNet_only },
{ "UBROKE.PIX", eNet_only },
{ "ULOST.PIX", eNet_only },
{ "UWON.PIX", eNet_only },
{ "DTIMEOUT.PIX", eNot_net }, // Only used by the demo, not present in the full version
};
char* gYour_car_names[2][6];
char* gDrivable_car_names[6];
char* gDamage_names[] = {
"engine",
"transmission",
"driver",
"steering",
"lf_brake",
"rf_brake",
"lr_brake",
"rr_brake",
"lf_wheel",
"rf_wheel",
"lr_wheel",
"rr_wheel"
};
char* gWheel_actor_names[] = {
"FLWHEEL.ACT",
"FRWHEEL.ACT",
"RLWHEEL.ACT",
"RRWHEEL.ACT",
"IFLWHEEL.ACT",
"IFRWHEEL.ACT"
};
char* gRaces_file_names[] = {
"RACES.TXT",
"NETRACES.TXT",
"NETRACES.TXT",
"PEDRACES.TXT",
"RACES.TXT",
"RACES.TXT",
"NETRACES.TXT",
"NETRACES.TXT",
"NETRACES.TXT"
};
char* gNet_avail_names[] = { "never", "eagle", "hawk", "all" };
char* gFloorpan_names[] = { "GBUNDER.MAT", "BGLUNDER.MAT", "GRIMBOT.MAT", "DDBASE.MAT", "HFUNDER.MAT" };
int gAllow_open_to_fail = 1;
int gDecode_thing = '@';
char gDecode_string[] = { 0x9B, 0x52, 0x93, 0x9F, 0x52, 0x98, 0x9B, 0x96, 0x96, 0x9E, 0x9B, 0xA0, 0x99, 0x0 };
int gFunk_groove_flags[30];
char gDef_def_water_screen_name[32];
br_material* gDestn_screen_mat;
br_material* gSource_screen_mat;
int gCurrent_race_file_index;
int gGroove_funk_offset;
int gDemo_armour;
int gDemo_rank;
int gDemo_opponents[5];
int gDemo_power;
int gDemo_offensive;
// IDA: tU32 __usercall ReadU32@<EAX>(FILE *pF@<EAX>)
tU32 ReadU32(FILE* pF) {
tU32 raw_long;
LOG_TRACE("(%p)", pF);
fread(&raw_long, sizeof(raw_long), 1, pF);
#if BR_ENDIAN_BIG
raw_long = BrSwap32(raw_long);
#endif
return raw_long;
}
// IDA: tU16 __usercall ReadU16@<AX>(FILE *pF@<EAX>)
tU16 ReadU16(FILE* pF) {
tU16 raw_short;
LOG_TRACE("(%p)", pF);
fread(&raw_short, sizeof(raw_short), 1, pF);
#if BR_ENDIAN_BIG
raw_short = BrSwap16(raw_short);
#endif
return raw_short;
}
// IDA: tU8 __usercall ReadU8@<AL>(FILE *pF@<EAX>)
tU8 ReadU8(FILE* pF) {
tU8 raw_byte;
LOG_TRACE("(%p)", pF);
fread(&raw_byte, sizeof(raw_byte), 1, pF);
return raw_byte;
}
// IDA: tS32 __usercall ReadS32@<EAX>(FILE *pF@<EAX>)
tS32 ReadS32(FILE* pF) {
tS32 raw_long;
LOG_TRACE("(%p)", pF);
fread(&raw_long, sizeof(raw_long), 1, pF);
#if BR_ENDIAN_BIG
raw_long = BrSwap32(raw_long);
#endif
return raw_long;
}
// IDA: tS16 __usercall ReadS16@<AX>(FILE *pF@<EAX>)
tS16 ReadS16(FILE* pF) {
tS16 raw_short;
LOG_TRACE("(%p)", pF);
fread(&raw_short, sizeof(raw_short), 1, pF);
#if BR_ENDIAN_BIG
raw_short = BrSwap16(raw_short);
#endif
return raw_short;
}
// IDA: tS8 __usercall ReadS8@<AL>(FILE *pF@<EAX>)
tS8 ReadS8(FILE* pF) {
tS8 raw_byte;
LOG_TRACE("(%p)", pF);
fread(&raw_byte, sizeof(raw_byte), 1, pF);
return raw_byte;
}
// IDA: void __usercall WriteU32L(FILE *pF@<EAX>, tU32 pNumber@<EDX>)
void WriteU32L(FILE* pF, tU32 pNumber) {
tU32 raw_long;
LOG_TRACE("(%p, %d)", pF, pNumber);
raw_long = pNumber;
#if BR_ENDIAN_BIG
raw_long = BrSwap32(raw_long);
#endif
fwrite(&raw_long, sizeof(raw_long), 1, pF);
}
// IDA: void __usercall WriteU16L(FILE *pF@<EAX>, tU16 pNumber@<EDX>)
void WriteU16L(FILE* pF, tU16 pNumber) {
tU16 raw_short;
LOG_TRACE("(%p, %d)", pF, pNumber);
raw_short = pNumber;
#if BR_ENDIAN_BIG
raw_short = BrSwap16(raw_short);
#endif
fwrite(&raw_short, sizeof(raw_short), 1, pF);
}
// IDA: void __usercall WriteU8L(FILE *pF@<EAX>, tU8 pNumber@<EDX>)
void WriteU8L(FILE* pF, tU8 pNumber) {
tU8 raw_byte;
LOG_TRACE("(%p, %d)", pF, pNumber);
raw_byte = pNumber;
fwrite(&raw_byte, sizeof(raw_byte), 1, pF);
}
// IDA: void __usercall WriteS32L(FILE *pF@<EAX>, tS32 pNumber@<EDX>)
void WriteS32L(FILE* pF, tS32 pNumber) {
tS32 raw_long;
LOG_TRACE("(%p, %d)", pF, pNumber);
raw_long = pNumber;
#if BR_ENDIAN_BIG
raw_long = BrSwap32(raw_long);
#endif
fwrite(&raw_long, sizeof(raw_long), 1, pF);
}
// IDA: void __usercall WriteS16L(FILE *pF@<EAX>, tS16 pNumber@<EDX>)
void WriteS16L(FILE* pF, tS16 pNumber) {
tS16 raw_short;
LOG_TRACE("(%p, %d)", pF, pNumber);
raw_short = pNumber;
#if BR_ENDIAN_BIG
raw_short = BrSwap16(raw_short);
#endif
fwrite(&raw_short, sizeof(raw_short), 1, pF);
}
// IDA: void __usercall WriteS8L(FILE *pF@<EAX>, tS8 pNumber@<EDX>)
void WriteS8L(FILE* pF, tS8 pNumber) {
tS8 raw_byte;
LOG_TRACE("(%p, %d)", pF, pNumber);
raw_byte = pNumber;
fwrite(&raw_byte, sizeof(raw_byte), 1, pF);
}
// IDA: void __usercall SkipBytes(FILE *pF@<EAX>, int pBytes_to_skip@<EDX>)
void SkipBytes(FILE* pF, int pBytes_to_skip) {
LOG_TRACE("(%p, %d)", pF, pBytes_to_skip);
fseek(pF, pBytes_to_skip, 1);
}
// IDA: tU32 __usercall MemReadU32@<EAX>(char **pPtr@<EAX>)
tU32 MemReadU32(char** pPtr) {
tU32 raw_long;
memcpy(&raw_long, *pPtr, sizeof(raw_long));
#if BR_ENDIAN_BIG
raw_long = BrSwap32(raw_long);
#endif
*pPtr += sizeof(raw_long);
return raw_long;
}
// IDA: tU16 __usercall MemReadU16@<AX>(char **pPtr@<EAX>)
tU16 MemReadU16(char** pPtr) {
tU16 raw_short;
memcpy(&raw_short, *pPtr, sizeof(raw_short));
#if BR_ENDIAN_BIG
raw_short = BrSwap16(raw_short);
#endif
*pPtr += sizeof(raw_short);
return raw_short;
}
// IDA: tU8 __usercall MemReadU8@<AL>(char **pPtr@<EAX>)
tU8 MemReadU8(char** pPtr) {
tU8 raw_byte;
memcpy(&raw_byte, *pPtr, sizeof(raw_byte));
*pPtr += sizeof(raw_byte);
return raw_byte;
}
// IDA: tS32 __usercall MemReadS32@<EAX>(char **pPtr@<EAX>)
tS32 MemReadS32(char** pPtr) {
tS32 raw_long;
LOG_TRACE("(%p)", pPtr);
memcpy(&raw_long, *pPtr, sizeof(raw_long));
#if BR_ENDIAN_BIG
raw_long = BrSwap32(raw_long);
#endif
*pPtr += sizeof(raw_long);
return raw_long;
}
// IDA: tS16 __usercall MemReadS16@<AX>(char **pPtr@<EAX>)
tS16 MemReadS16(char** pPtr) {
tS16 raw_short;
memcpy(&raw_short, *pPtr, sizeof(raw_short));
#if BR_ENDIAN_BIG
raw_short = BrSwap16(raw_short);
#endif
*pPtr += sizeof(raw_short);
return raw_short;
}
// IDA: tS8 __usercall MemReadS8@<AL>(char **pPtr@<EAX>)
tS8 MemReadS8(char** pPtr) {
tS8 raw_byte;
memcpy(&raw_byte, *pPtr, sizeof(raw_byte));
*pPtr += sizeof(raw_byte);
return raw_byte;
}
// IDA: void __usercall MemSkipBytes(char **pPtr@<EAX>, int pBytes_to_skip@<EDX>)
void MemSkipBytes(char** pPtr, int pBytes_to_skip) {
*pPtr += pBytes_to_skip;
}
// IDA: void __cdecl LoadGeneralParameters()
void LoadGeneralParameters(void) {
FILE* f;
tPath_name the_path;
int i;
int temp;
char s[256];
char* str;
PathCat(the_path, gApplication_path, "ACTORS");
PathCat(the_path, the_path, "PROG.ACT");
f = fopen(the_path, "rb");
if (f != NULL) {
fgets(s, sizeof(s) - 1, f);
fclose(f);
for (i = 0; i < strlen(gDecode_string); i++) {
gDecode_string[i] -= 50;
}
// trim trailing CRLF etc
while (s[0] != '\0' && s[strlen(s) - 1] < 0x20) {
s[strlen(s) - 1] = 0;
}
if (strcmp(s, gDecode_string) == 0) {
gDecode_thing = 0;
}
for (i = 0; i < strlen(gDecode_string); i++) {
gDecode_string[i] += 50;
}
}
PathCat(the_path, gApplication_path, "GENERAL.TXT");
f = DRfopen(the_path, "rt");
if (f == NULL) {
FatalError(kFatalError_SettingsFile);
}
gCamera_hither = GetAFloat(f) * HITHER_MULTIPLIER;
gCamera_yon = GetAFloat(f);
gCamera_angle = GetAFloat(f);
gAmbient_adjustment = GetAFloat(f) * AMBIENT_MULTIPLIER;
gDim_amount = GetAnInt(f);
gInitial_rank = GetAnInt(f);
GetThreeInts(f, &gInitial_credits[0], &gInitial_credits[1], &gInitial_credits[2]);
GetThreeInts(f, &gCredits_per_rank[0], &gCredits_per_rank[1], &gCredits_per_rank[2]);
gCar_crush_min_fold = GetAFloat(f);
gCar_crush_max_fold = GetAFloat(f);
gCar_crush_wibble = GetAFloat(f);
gCar_crush_limit_deviant = GetAFloat(f);
gCar_crush_split_chance = GetAFloat(f);
gCar_crush_softness = GetAFloat(f);
GetThreeFloats(f, &gRepair_cost[0], &gRepair_cost[1], &gRepair_cost[2]);
GetThreeFloats(f, &gRecovery_cost[0], &gRecovery_cost[1], &gRecovery_cost[2]);
GetThreeInts(f, &gPed_time_value[0], &gPed_time_value[1], &gPed_time_value[2]);
if (gProgram_state.sausage_eater_mode) {
for (i = 0; i < 7; i++) {
GetALineAndDontArgue(f, s);
}
GetThreeFloats(f, gCar_time_value, &gCar_time_value[1], &gCar_time_value[2]);
GetThreeFloats(f, gCar_cred_value, &gCar_cred_value[1], &gCar_cred_value[2]);
GetThreeInts(f, gWasted_time, &gWasted_time[1], &gWasted_time[2]);
GetThreeInts(f, gWasted_creds, &gWasted_creds[1], &gWasted_creds[2]);
GetThreeInts(f, gRoll_over_time, &gRoll_over_time[1], &gRoll_over_time[2]);
GetThreeInts(f, gRoll_over_creds, &gRoll_over_creds[1], &gRoll_over_creds[2]);
GetThreeInts(f, gCheck_point_cash, &gCheck_point_cash[1], &gCheck_point_cash[2]);
} else {
GetThreeFloats(f, gCar_time_value, &gCar_time_value[1], &gCar_time_value[2]);
GetThreeFloats(f, gCar_cred_value, &gCar_cred_value[1], &gCar_cred_value[2]);
GetThreeInts(f, gWasted_time, &gWasted_time[1], &gWasted_time[2]);
GetThreeInts(f, gWasted_creds, &gWasted_creds[1], &gWasted_creds[2]);
GetThreeInts(f, gRoll_over_time, &gRoll_over_time[1], &gRoll_over_time[2]);
GetThreeInts(f, gRoll_over_creds, &gRoll_over_creds[1], &gRoll_over_creds[2]);
GetThreeInts(f, gCheck_point_cash, &gCheck_point_cash[1], &gCheck_point_cash[2]);
for (i = 0; i < 7; i++) {
GetALineAndDontArgue(f, s);
}
}
GetThreeInts(f, gJump_start_fine, &gJump_start_fine[1], &gJump_start_fine[2]);
GetThreeInts(f, gPoints_per_second, &gPoints_per_second[1], &gPoints_per_second[2]);
GetThreeInts(f, gCunning_stunt_bonus, &gCunning_stunt_bonus[1], &gCunning_stunt_bonus[2]);
GetAString(f, gBasic_car_names[0]);
GetAString(f, gBasic_car_names[1]);
gKnobbled_frame_period = GetAnInt(f);
if (gKnobbled_frame_period) {
gKnobbled_frame_period = 1000 / gKnobbled_frame_period;
}
gOpponent_nastyness_frigger = GetAFloat(f);
ParseSpecialVolume(f, &gDefault_default_water_spec_vol, gDef_def_water_screen_name);
GetALineAndDontArgue(f, s);
str = strtok(s, "\t ,/");
for (i = 0; i < 5; i++) {
sscanf(str, "%d", &gInitial_net_credits[i]);
str = strtok(NULL, "\t ,/");
}
gTag_start_time = 1000 * GetAnInt(f);
gFox_start_time = 1000 * GetAnInt(f);
GetALineAndDontArgue(f, s);
str = strtok(s, "\t ,/");
for (i = 0; i < 7; i++) {
sscanf(str, "%f", &gNet_repair_cost[i]);
str = strtok(NULL, "\t ,/");
}
GetALineAndDontArgue(f, s);
str = strtok(s, "\t ,/");
for (i = 0; i < 7; i++) {
sscanf(str, "%f", &gNet_recovery_cost[i]);
str = strtok(NULL, "\t ,/");
}
GetALineAndDontArgue(f, s);
str = strtok(s, "\t ,/");
for (i = 0; i < 7; i++) {
sscanf(str, "%f", &gNet_softness[i]);
str = strtok(NULL, "\t ,/");
}
GetALineAndDontArgue(f, s);
str = strtok(s, "\t ,/");
for (i = 0; i < 7; i++) {
sscanf(str, "%f", &gNet_offensive[i]);
str = strtok(NULL, "\t ,/");
}
GetALineAndDontArgue(f, s);
str = strtok(s, "\t ,/");
for (i = 0; i < 7; i++) {
sscanf(str, "%d", &gNet_target[i]);
str = strtok(NULL, "\t ,/");
}
gMin_respawn_time = 1000 * GetAnInt(f);
gRespawn_variance = 1000 * GetAnInt(f);
gDemo_rank = GetAnInt(f);
gDemo_armour = GetAnInt(f);
gDemo_power = GetAnInt(f);
gDemo_offensive = GetAnInt(f);
for (i = 0; i < 5; i++) {
gDemo_opponents[i] = GetAnInt(f);
}
gDefault_gravity = GetAFloat(f);
gCut_delay_1 = GetAFloat(f);
gCut_delay_2 = GetAFloat(f);
gCut_delay_3 = GetAFloat(f);
gCut_delay_4 = GetAFloat(f);
gZombie_factor = 1.0f;
fclose(f);
}
// IDA: void __cdecl FinishLoadingGeneral()
void FinishLoadingGeneral(void) {
gDefault_default_water_spec_vol.screen_material = BrMaterialFind(gDef_def_water_screen_name);
}
// IDA: br_pixelmap* __usercall LoadPixelmap@<EAX>(char *pName@<EAX>)
br_pixelmap* LoadPixelmap(char* pName) {
tPath_name the_path;
br_pixelmap* pm = NULL;
char* end;
LOG_TRACE("(\"%s\")", pName);
end = strrchr(pName, '.');
if (end == NULL) {
end = &pName[strlen(pName)];
}
if (end - pName == 4 && memcmp(pName, "none", end - pName) == 0) {
return NULL;
}
PossibleService();
PathCat(the_path, gApplication_path, gGraf_specs[gGraf_spec_index].data_dir_name);
PathCat(the_path, the_path, "PIXELMAP");
PathCat(the_path, the_path, pName);
AllowOpenToFail();
pm = DRPixelmapLoad(the_path);
if (pm == NULL) {
PathCat(the_path, gApplication_path, "PIXELMAP");
PathCat(the_path, the_path, pName);
pm = DRPixelmapLoad(the_path);
}
return pm;
}
// IDA: br_uint_32 __usercall LoadPixelmaps@<EAX>(char *pFile_name@<EAX>, br_pixelmap **pPixelmaps@<EDX>, br_uint_16 pNum@<EBX>)
br_uint_32 LoadPixelmaps(char* pFile_name, br_pixelmap** pPixelmaps, br_uint_16 pNum) {
tPath_name path;
int count;
PathCat(path, gApplication_path, gGraf_specs[gGraf_spec_index].data_dir_name);
PathCat(path, path, "PIXELMAP");
PathCat(path, path, pFile_name);
AllowOpenToFail();
count = DRPixelmapLoadMany(path, pPixelmaps, pNum);
if (count == 0) {
PathCat(path, gApplication_path, "PIXELMAP");
PathCat(path, path, pFile_name);
count = DRPixelmapLoadMany(path, pPixelmaps, pNum);
}
return count;
}
// IDA: br_pixelmap* __usercall LoadShadeTable@<EAX>(char *pName@<EAX>)
br_pixelmap* LoadShadeTable(char* pName) {
tPath_name the_path;
LOG_TRACE("(\"%s\")", pName);
PathCat(the_path, gApplication_path, "SHADETAB");
PathCat(the_path, the_path, pName);
return BrPixelmapLoad(the_path);
}
// IDA: br_material* __usercall LoadMaterial@<EAX>(char *pName@<EAX>)
br_material* LoadMaterial(char* pName) {
tPath_name the_path;
br_material* result;
LOG_TRACE("(\"%s\")", pName);
PossibleService();
PathCat(the_path, gApplication_path, "MATERIAL");
PathCat(the_path, the_path, pName);
return BrMaterialLoad(the_path);
}
// IDA: br_model* __usercall LoadModel@<EAX>(char *pName@<EAX>)
br_model* LoadModel(char* pName) {
tPath_name the_path;
br_model* model;
LOG_TRACE("(\"%s\")", pName);
PossibleService();
PathCat(the_path, gApplication_path, "MODELS");
PathCat(the_path, the_path, pName);
return BrModelLoad(the_path);
}
// IDA: br_actor* __usercall LoadActor@<EAX>(char *pName@<EAX>)
br_actor* LoadActor(char* pName) {
tPath_name the_path;
LOG_TRACE("(\"%s\")", pName);
PossibleService();
PathCat(the_path, gApplication_path, "ACTORS");
PathCat(the_path, the_path, pName);
return BrActorLoad(the_path);
}
// IDA: void __usercall DRLoadPalette(char *pPath_name@<EAX>)
void DRLoadPalette(char* pPath_name) {
br_pixelmap* palette_array[100];
int number_of_palettes;
number_of_palettes = DRPixelmapLoadMany(pPath_name, palette_array, COUNT_OF(palette_array));
BrTableAddMany(palette_array, number_of_palettes);
}
// IDA: void __usercall DRLoadShadeTable(char *pPath_name@<EAX>)
void DRLoadShadeTable(char* pPath_name) {
br_pixelmap* table_array[100];
int number_of_tables;
number_of_tables = DRPixelmapLoadMany(pPath_name, table_array, COUNT_OF(table_array));
BrTableAddMany(table_array, number_of_tables);
}
// IDA: void __usercall RezeroPixelmaps(br_pixelmap **pPixelmap_array@<EAX>, int pCount@<EDX>)
void RezeroPixelmaps(br_pixelmap** pPixelmap_array, int pCount) {
LOG_TRACE("(%p, %d)", pPixelmap_array, pCount);
while (pCount != 0) {
pCount--;
pPixelmap_array[pCount]->origin_x = 0;
pPixelmap_array[pCount]->origin_y = 0;
}
}
// IDA: void __usercall DRLoadPixelmaps(char *pPath_name@<EAX>)
void DRLoadPixelmaps(char* pPath_name) {
br_pixelmap* pixelmap_array[100];
int number_of_pixelmaps;
int i;
PossibleService();
number_of_pixelmaps = DRPixelmapLoadMany(pPath_name, pixelmap_array, COUNT_OF(pixelmap_array));
RezeroPixelmaps(pixelmap_array, number_of_pixelmaps);
BrMapAddMany(pixelmap_array, number_of_pixelmaps);
}
// IDA: void __usercall DRLoadMaterials(char *pPath_name@<EAX>)
void DRLoadMaterials(char* pPath_name) {
br_material* material_array[100];
int number_of_materials;
PossibleService();
number_of_materials = BrMaterialLoadMany(pPath_name, material_array, COUNT_OF(material_array));
BrMaterialAddMany(material_array, number_of_materials);
}
// IDA: void __usercall DRLoadModels(char *pPath_name@<EAX>)
void DRLoadModels(char* pPath_name) {
br_model* model_array[100];
int number_of_models;
LOG_TRACE("(\"%s\")", pPath_name);
PossibleService();
number_of_models = BrModelLoadMany(pPath_name, model_array, COUNT_OF(model_array));
BrModelAddMany(model_array, number_of_models);
}
// IDA: void __usercall DRLoadActors(char *pPath_name@<EAX>)
void DRLoadActors(char* pPath_name) {
br_actor* actor_array[100];
int number_of_actors;
int i;
LOG_TRACE("(\"%s\")", pPath_name);
PossibleService();
number_of_actors = BrActorLoadMany(pPath_name, actor_array, COUNT_OF(actor_array));
for (i = 0; i < number_of_actors; i++) {
gActor_array[gNumber_of_actors] = actor_array[i];
gNumber_of_actors++;
}
}
// IDA: void __usercall DRLoadLights(char *pPath_name@<EAX>)
void DRLoadLights(char* pPath_name) {
br_actor* light_array[100];
int number_of_lights;
int i;
PossibleService();
number_of_lights = BrActorLoadMany(pPath_name, light_array, COUNT_OF(light_array));
for (i = 0; i < number_of_lights; i++) {
gLight_array[gNumber_of_lights] = light_array[i];
gNumber_of_lights++;
}
}
// IDA: void __usercall LoadInFiles(char *pThe_base_path@<EAX>, char *pThe_dir_name@<EDX>, void (*pLoad_routine)(char*)@<EBX>)
void LoadInFiles(char* pThe_base_path, char* pThe_dir_name, void (*pLoad_routine)(char*)) {
tPath_name the_path;
LOG_TRACE("(\"%s\", \"%s\", %p)", pThe_base_path, pThe_dir_name, pLoad_routine);
PathCat(the_path, pThe_base_path, pThe_dir_name);
PDForEveryFile(the_path, pLoad_routine);
}
// IDA: void __usercall LoadInRegisteeDir(char *pThe_dir_path@<EAX>)
void LoadInRegisteeDir(char* pThe_dir_path) {
tPath_name the_path;
tPath_name reg_path;
LOG_TRACE("(\"%s\")", pThe_dir_path);
PathCat(reg_path, pThe_dir_path, "REG");
LoadInFiles(reg_path, "PALETTES", DRLoadPalette);
LoadInFiles(reg_path, "SHADETAB", DRLoadShadeTable);
LoadInFiles(reg_path, "PIXELMAP", DRLoadPixelmaps);
LoadInFiles(reg_path, "MATERIAL", DRLoadMaterials);
LoadInFiles(reg_path, "MODELS", DRLoadModels);
LoadInFiles(reg_path, "ACTORS", DRLoadActors);
LoadInFiles(reg_path, "LIGHTS", DRLoadLights);
}
// IDA: void __cdecl LoadInRegistees()
void LoadInRegistees(void) {
LoadInRegisteeDir(gApplication_path);
}
// IDA: void __cdecl LoadKeyMapping()
void LoadKeyMapping(void) {
FILE* f;
tPath_name the_path;
int i;
LOG_TRACE("()");
PathCat(the_path, gApplication_path, "KEYMAP_X.TXT");
the_path[strlen(the_path) - 5] = '0' + gKey_map_index;
f = DRfopen(the_path, "rt");
if (f == NULL) {
FatalError(kFatalError_OpenKeyMapFile);
}
for (i = 0; i < 67; i++) {
fscanf(f, "%d", &gKey_mapping[i]);
}
fclose(f);
}
// IDA: void __usercall LoadInterfaceStuff(int pWithin_race@<EAX>)
void LoadInterfaceStuff(int pWithin_race) {
tPath_name path;
int i;
LOG_TRACE("(%d)", pWithin_race);
if (gProgram_state.sausage_eater_mode) {
strcpy(path, "GHANDX.PIX");
} else {
strcpy(path, "HANDX.PIX");
}
PossibleService();
if (gCursors[0] == NULL && LoadPixelmaps(path, gCursors, 4) == 0) {
FatalError(kFatalError_LoadCursorImage);
}
if (gProgram_state.sausage_eater_mode) {
strcpy(path, "GHANDPX.PIX");
} else {
strcpy(path, "HANDPX.PIX");
}
PossibleService();
if (gCursors[4] == NULL && LoadPixelmaps(path, &gCursors[4], 4) == 0) {
FatalError(kFatalError_LoadCursorImage);
}
PossibleService();
if (gCursor_giblet_images[0] == NULL && LoadPixelmaps("CURSGIBX.PIX", gCursor_giblet_images, COUNT_OF(gCursor_giblet_images)) == 0) {
FatalError(kFatalError_LoadCursorGiblet);
}
}
// IDA: void __cdecl UnlockInterfaceStuff()
void UnlockInterfaceStuff(void) {
int i;
LOG_TRACE("()");
for (i = 0; i < 4; i++) {
if (gCursors[i]) {
BrPixelmapFree(gCursors[i]);
gCursors[i] = NULL;
}
}
PossibleService();
for (i = 0; i < 4; i++) {
if (gCursors[i + 4]) {
BrPixelmapFree(gCursors[i + 4]);
gCursors[i + 4] = NULL;
}
}
PossibleService();
for (i = 0; i < COUNT_OF(gCursor_giblet_images); i++) {
if (gCursor_giblet_images[i]) {
BrPixelmapFree(gCursor_giblet_images[i]);
gCursor_giblet_images[i] = NULL;
}
}
}
// IDA: void __cdecl InitInterfaceLoadState()
void InitInterfaceLoadState(void) {
LOG_TRACE("()");
memset(gCursors, 0, sizeof(gCursors));
}
// IDA: tS8* __usercall ConvertPixTo16BitStripMap@<EAX>(br_pixelmap *pBr_map@<EAX>)
tS8* ConvertPixTo16BitStripMap(br_pixelmap* pBr_map) {
int i;
int j;
int new_line_length;
int current_size;
int counting_blanks;
int counter;
int chunk_counter;
int max_line_bytes;
tU8* next_byte;
tU8* strip_image;
tU8* current_strip_pointer;
tU8* temp_strip_image;
tU8* new_line;
tU8 byte;
tU16* palette_entry;
LOG_TRACE("(%p)", pBr_map);
NOT_IMPLEMENTED();
}
// IDA: tS8* __usercall ConvertPixToStripMap@<EAX>(br_pixelmap *pThe_br_map@<EAX>)
// Jeff: This appears to be used only for dashboard views, either to save memory storage or pixel copies.
// See also: `CopyStripImage`
// It is a simple RLE algorithm, but only targets runs of blank pixels.
// Format:
// number_of_lines (1 byte)
// for each line:
// chunk_count (1 byte)
// for each chunk:
// chunk_length (1 signed byte). If positive, skip this number of blank pixels. If negative, copy the following `length` bytes
tS8* ConvertPixToStripMap(br_pixelmap* pThe_br_map) {
int i;
int j;
int new_line_length;
int current_size;
int counting_blanks;
int counter;
int chunk_counter;
tU8* next_byte;
tU8* the_strip_image;
tU8* current_strip_pointer;
tU8* temp_strip_image;
tU8 new_line[800];
tU8 the_byte;
LOG_TRACE("(%p)", pThe_br_map);
int total;
temp_strip_image = BrMemAllocate(pThe_br_map->row_bytes * pThe_br_map->height, kMem_strip_image);
current_size = 2;
*(br_uint_16*)temp_strip_image = pThe_br_map->height;
current_strip_pointer = temp_strip_image;
for (i = 0; i < pThe_br_map->height; i++) {
next_byte = (tU8*)pThe_br_map->pixels + i * pThe_br_map->row_bytes; // points to start of this line
new_line_length = 2; // leave space at the start of the line to store number of chunks and first chunk length
j = 0;
counter = 0;
total = 0;
counting_blanks = *next_byte == 0;
chunk_counter = 0;
the_byte = 0; // Added to keep compiler happy
while (1) {
while (counter <= 126) {
if (j == pThe_br_map->width) {
break;
}
the_byte = *next_byte;
if ((the_byte == 0 && !counting_blanks) || (the_byte != 0 && counting_blanks)) {
break;
}
if (!counting_blanks) {
new_line[new_line_length] = the_byte;
new_line_length++;
}
counter++;
j++;
next_byte++;
}
if (counting_blanks) {
new_line[new_line_length - 1] = counter;
} else {
new_line[new_line_length - counter - 1] = -counter;
}
counting_blanks = the_byte == 0;
chunk_counter++;
total += counter;
counter = 0;
if (j == pThe_br_map->width) {
break;
}
new_line_length++;
}
new_line[0] = chunk_counter;
current_strip_pointer = &temp_strip_image[current_size];
memcpy(current_strip_pointer, new_line, new_line_length);
current_size += new_line_length;
}
the_strip_image = BrMemAllocate(current_size, kMem_strip_image_perm);
memcpy(the_strip_image, temp_strip_image, current_size);
BrMemFree(temp_strip_image);
return (tS8*)the_strip_image;
}
// IDA: void __usercall KillWindscreen(br_model *pModel@<EAX>, br_material *pMaterial@<EDX>)
void KillWindscreen(br_model* pModel, br_material* pMaterial) {
br_face* face;
int i;
LOG_TRACE("(%p, %p)", pModel, pMaterial);
if (pModel == NULL || pModel->nfaces == 0) {
return;
}
for (i = 0; i < pModel->nfaces; i++) {
face = &pModel->faces[i];
if (face->material == pMaterial) {
face->material = NULL;
}
}
BrModelUpdate(pModel, BR_MODU_ALL);
}
// IDA: void __usercall DropOffDyingPeds(tCar_spec *pCar@<EAX>)
void DropOffDyingPeds(tCar_spec* pCar) {
br_actor* child;
br_actor* next;
LOG_TRACE("(%p)", pCar);
if (pCar->current_car_actor < 0) {
return;
}
child = pCar->car_master_actor->children;
while (child != NULL) {
next = child->next;
if (ActorIsPedestrian(child)) {
DetachPedActorFromCar(child);
}
child = next;
}
}
// IDA: void __usercall DisposeCar(tCar_spec *pCar_spec@<EAX>, int pOwner@<EDX>)
void DisposeCar(tCar_spec* pCar_spec, int pOwner) {
int i;
int j;
LOG_TRACE("(%p, %d)", pCar_spec, pOwner);
if (pCar_spec->driver_name[0] == '\0') {
return;
}
gFunk_groove_flags[pCar_spec->fg_index] = 0;
pCar_spec->driver_name[0] = '\0';
if (pCar_spec->driver == eDriver_local_human) {
for (i = 0; i < COUNT_OF(pCar_spec->cockpit_images); i++) {
if (pCar_spec->cockpit_images[i] != NULL) {
BrMemFree(pCar_spec->cockpit_images[i]);
}
}
if (pCar_spec->speedo_image[0] != NULL) {
BrPixelmapFree(pCar_spec->speedo_image[0]);
}
if (pCar_spec->speedo_image[1] != NULL) {
BrPixelmapFree(pCar_spec->speedo_image[1]);
}
if (pCar_spec->tacho_image[0] != NULL) {
BrPixelmapFree(pCar_spec->tacho_image[0]);
}
if (pCar_spec->tacho_image[1] != NULL) {
BrPixelmapFree(pCar_spec->tacho_image[1]);
}
for (i = 0; i < pCar_spec->number_of_hands_images; i++) {
if (pCar_spec->lhands_images[i] != NULL) {
BrPixelmapFree(pCar_spec->lhands_images[i]);
}
if (pCar_spec->rhands_images[i] != NULL) {
BrPixelmapFree(pCar_spec->rhands_images[i]);
}
}
if (pCar_spec->prat_cam_left != NULL) {
BrPixelmapFree(pCar_spec->prat_cam_left);
}
if (pCar_spec->prat_cam_top != NULL) {
BrPixelmapFree(pCar_spec->prat_cam_top);
}
if (pCar_spec->prat_cam_right != NULL) {
BrPixelmapFree(pCar_spec->prat_cam_right);
}
if (pCar_spec->prat_cam_bottom != NULL) {
BrPixelmapFree(pCar_spec->prat_cam_bottom);
}
for (i = 0; i < COUNT_OF(pCar_spec->damage_units); i++) {
if (pCar_spec->damage_units[i].images != NULL) {
BrPixelmapFree(pCar_spec->damage_units[i].images);
}
}
if (pCar_spec->damage_background != NULL) {
BrPixelmapFree(pCar_spec->damage_background);
}
for (i = 0; i < COUNT_OF(pCar_spec->power_ups); i++) {
for (j = 0; j < pCar_spec->power_ups[i].number_of_parts; j++) {
if (pCar_spec->power_ups[i].info[j].data_ptr != NULL) {
BrMemFree(pCar_spec->power_ups[i].info[j].data_ptr);
}