forked from ZDoom/gzdoom
-
Notifications
You must be signed in to change notification settings - Fork 1
/
d_dehacked.cpp
3142 lines (2834 loc) · 82.4 KB
/
d_dehacked.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
/*
** d_dehacked.cpp
** Parses dehacked/bex patches and changes game structures accordingly
**
**---------------------------------------------------------------------------
** Copyright 1998-2006 Randy Heit
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1. Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** 2. Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3. The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**---------------------------------------------------------------------------
**
** Much of this file is fudging code to compensate for the fact that most of
** what could be changed with Dehacked is no longer in the same state it was
** in as of Doom 1.9. There is a lump in zdoom.wad (DEHSUPP) that stores most
** of the lookup tables used so that they need not be loaded all the time.
** Also, their total size is less in the lump than when they were part of the
** executable, so it saves space on disk as well as in memory.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include "doomtype.h"
#include "templates.h"
#include "doomstat.h"
#include "info.h"
#include "d_dehacked.h"
#include "s_sound.h"
#include "g_level.h"
#include "cmdlib.h"
#include "gstrings.h"
#include "m_alloc.h"
#include "m_misc.h"
#include "w_wad.h"
#include "d_player.h"
#include "r_state.h"
#include "gi.h"
#include "c_dispatch.h"
#include "decallib.h"
#include "v_palette.h"
#include "a_sharedglobal.h"
#include "thingdef/thingdef.h"
#include "thingdef/thingdef_exp.h"
#include "vectors.h"
#include "dobject.h"
#include "r_data/r_translate.h"
#include "sc_man.h"
#include "i_system.h"
#include "doomerrors.h"
#include "p_effect.h"
#include "farchive.h"
// [SO] Just the way Randy said to do it :)
// [RH] Made this CVAR_SERVERINFO
CVAR (Int, infighting, 0, CVAR_SERVERINFO)
static bool LoadDehSupp ();
static void UnloadDehSupp ();
// This is a list of all the action functions used by each of Doom's states.
static TArray<PSymbol *> Actions;
// These are the original heights of every Doom 2 thing. They are used if a patch
// specifies that a thing should be hanging from the ceiling but doesn't specify
// a height for the thing, since these are the heights it probably wants.
static TArray<int> OrgHeights;
// DeHackEd made the erroneous assumption that if a state didn't appear in
// Doom with an action function, then it was incorrect to assign it one.
// This is a list of the states that had action functions, so we can figure
// out where in the original list of states a DeHackEd codepointer is.
// (DeHackEd might also have done this for compatibility between Doom
// versions, because states could move around, but actions would never
// disappear, but that doesn't explain why frame patches specify an exact
// state rather than a code pointer.)
static TArray<int> CodePConv;
// Sprite names in the order Doom originally had them.
struct DEHSprName
{
char c[5];
};
static TArray<DEHSprName> OrgSprNames;
struct StateMapper
{
FState *State;
int StateSpan;
const PClass *Owner;
bool OwnerIsPickup;
};
static TArray<StateMapper> StateMap;
// Sound equivalences. When a patch tries to change a sound,
// use these sound names.
static TArray<FSoundID> SoundMap;
// Names of different actor types, in original Doom 2 order
static TArray<const PClass *> InfoNames;
// bit flags for PatchThing (a .bex extension):
struct BitName
{
char Name[20];
BYTE Bit;
BYTE WhichFlags;
};
static TArray<BitName> BitNames;
// Render styles
struct StyleName
{
char Name[20];
BYTE Num;
};
static TArray<StyleName> StyleNames;
static TArray<const PClass *> AmmoNames;
static TArray<const PClass *> WeaponNames;
// DeHackEd trickery to support MBF-style parameters
// List of states that are hacked to use a codepointer
struct MBFParamState
{
FState *state;
int pointer;
};
static TArray<MBFParamState> MBFParamStates;
// Data on how to correctly modify the codepointers
struct CodePointerAlias
{
char name[20];
char alias[20];
BYTE params;
};
static TArray<CodePointerAlias> MBFCodePointers;
struct AmmoPerAttack
{
actionf_p func;
int ammocount;
};
DECLARE_ACTION(A_Punch)
DECLARE_ACTION(A_FirePistol)
DECLARE_ACTION(A_FireShotgun)
DECLARE_ACTION(A_FireShotgun2)
DECLARE_ACTION(A_FireCGun)
DECLARE_ACTION(A_FireMissile)
DECLARE_ACTION_PARAMS(A_Saw)
DECLARE_ACTION(A_FirePlasma)
DECLARE_ACTION(A_FireBFG)
DECLARE_ACTION(A_FireOldBFG)
DECLARE_ACTION(A_FireRailgun)
// Default ammo use of the various weapon attacks
static AmmoPerAttack AmmoPerAttacks[] = {
{ AF_A_Punch, 0},
{ AF_A_FirePistol, 1},
{ AF_A_FireShotgun, 1},
{ AF_A_FireShotgun2, 2},
{ AF_A_FireCGun, 1},
{ AF_A_FireMissile, 1},
{ AFP_A_Saw, 0},
{ AF_A_FirePlasma, 1},
{ AF_A_FireBFG, -1}, // uses deh.BFGCells
{ AF_A_FireOldBFG, 1},
{ AF_A_FireRailgun, 1},
{ NULL, 0}
};
// Miscellaneous info that used to be constant
DehInfo deh =
{
100, // .StartHealth
50, // .StartBullets
100, // .MaxHealth
200, // .MaxArmor
1, // .GreenAC
2, // .BlueAC
200, // .MaxSoulsphere
100, // .SoulsphereHealth
200, // .MegasphereHealth
100, // .GodHealth
200, // .FAArmor
2, // .FAAC
200, // .KFAArmor
2, // .KFAAC
"PLAY", // Name of player sprite
255, // Rocket explosion style, 255=use cvar
FRACUNIT*2/3, // Rocket explosion alpha
false, // .NoAutofreeze
40, // BFG cells per shot
};
// Doom identified pickup items by their sprites. ZDoom prefers to use their
// class type to identify them instead. To support the traditional Doom
// behavior, for every thing touched by dehacked that has the MF_PICKUP flag,
// a new subclass of ADehackedPickup will be created with properties copied
// from the original actor's defaults. The original actor is then changed to
// spawn the new class.
IMPLEMENT_POINTY_CLASS (ADehackedPickup)
DECLARE_POINTER (RealPickup)
END_POINTERS
TArray<PClass *> TouchedActors;
char *UnchangedSpriteNames;
int NumUnchangedSprites;
// Sprite<->Class map for ADehackedPickup::DetermineType
static struct DehSpriteMap
{
char Sprite[5];
const char *ClassName;
}
DehSpriteMappings[] =
{
{ "AMMO", "ClipBox" },
{ "ARM1", "GreenArmor" },
{ "ARM2", "BlueArmor" },
{ "BFUG", "BFG9000" },
{ "BKEY", "BlueCard" },
{ "BON1", "HealthBonus" },
{ "BON2", "ArmorBonus" },
{ "BPAK", "Backpack" },
{ "BROK", "RocketBox" },
{ "BSKU", "BlueSkull" },
{ "CELL", "Cell" },
{ "CELP", "CellPack" },
{ "CLIP", "Clip" },
{ "CSAW", "Chainsaw" },
{ "LAUN", "RocketLauncher" },
{ "MEDI", "Medikit" },
{ "MEGA", "Megasphere" },
{ "MGUN", "Chaingun" },
{ "PINS", "BlurSphere" },
{ "PINV", "InvulnerabilitySphere" },
{ "PLAS", "PlasmaRifle" },
{ "PMAP", "Allmap" },
{ "PSTR", "Berserk" },
{ "PVIS", "Infrared" },
{ "RKEY", "RedCard" },
{ "ROCK", "RocketAmmo" },
{ "RSKU", "RedSkull" },
{ "SBOX", "ShellBox" },
{ "SGN2", "SuperShotgun" },
{ "SHEL", "Shell" },
{ "SHOT", "Shotgun" },
{ "SOUL", "Soulsphere" },
{ "STIM", "Stimpack" },
{ "SUIT", "RadSuit" },
{ "YKEY", "YellowCard" },
{ "YSKU", "YellowSkull" }
};
#define LINESIZE 2048
#define CHECKKEY(a,b) if (!stricmp (Line1, (a))) (b) = atoi(Line2);
static char *PatchFile, *PatchPt, *PatchName;
static int PatchSize;
static char *Line1, *Line2;
static int dversion, pversion;
static bool including, includenotext;
static const char *unknown_str = "Unknown key %s encountered in %s %d.\n";
static FStringTable *EnglishStrings;
// This is an offset to be used for computing the text stuff.
// Straight from the DeHackEd source which was
// Written by Greg Lewis, [email protected].
static int toff[] = {129044, 129044, 129044, 129284, 129380};
struct Key {
const char *name;
ptrdiff_t offset;
};
static int PatchThing (int);
static int PatchSound (int);
static int PatchFrame (int);
static int PatchSprite (int);
static int PatchAmmo (int);
static int PatchWeapon (int);
static int PatchPointer (int);
static int PatchCheats (int);
static int PatchMisc (int);
static int PatchText (int);
static int PatchStrings (int);
static int PatchPars (int);
static int PatchCodePtrs (int);
static int PatchMusic (int);
static int DoInclude (int);
static bool DoDehPatch();
static const struct {
const char *name;
int (*func)(int);
} Modes[] = {
// These appear in .deh and .bex files
{ "Thing", PatchThing },
{ "Sound", PatchSound },
{ "Frame", PatchFrame },
{ "Sprite", PatchSprite },
{ "Ammo", PatchAmmo },
{ "Weapon", PatchWeapon },
{ "Pointer", PatchPointer },
{ "Cheat", PatchCheats },
{ "Misc", PatchMisc },
{ "Text", PatchText },
// These appear in .bex files
{ "include", DoInclude },
{ "[STRINGS]", PatchStrings },
{ "[PARS]", PatchPars },
{ "[CODEPTR]", PatchCodePtrs },
{ "[MUSIC]", PatchMusic },
{ NULL, NULL },
};
static int HandleMode (const char *mode, int num);
static bool HandleKey (const struct Key *keys, void *structure, const char *key, int value);
static bool ReadChars (char **stuff, int size);
static char *igets (void);
static int GetLine (void);
static void PushTouchedActor(PClass *cls)
{
for(unsigned i = 0; i < TouchedActors.Size(); i++)
{
if (TouchedActors[i] == cls) return;
}
TouchedActors.Push(cls);
}
static int HandleMode (const char *mode, int num)
{
int i = 0;
while (Modes[i].name && stricmp (Modes[i].name, mode))
i++;
if (Modes[i].name)
return Modes[i].func (num);
// Handle unknown or unimplemented data
Printf ("Unknown chunk %s encountered. Skipping.\n", mode);
do
i = GetLine ();
while (i == 1);
return i;
}
static bool HandleKey (const struct Key *keys, void *structure, const char *key, int value)
{
while (keys->name && stricmp (keys->name, key))
keys++;
if (keys->name) {
*((int *)(((BYTE *)structure) + keys->offset)) = value;
return false;
}
return true;
}
static int FindSprite (const char *sprname)
{
int i;
DWORD nameint = *((DWORD *)sprname);
for (i = 0; i < NumUnchangedSprites; ++i)
{
if (*((DWORD *)&UnchangedSpriteNames[i*4]) == nameint)
{
return i;
}
}
return -1;
}
static FState *FindState (int statenum)
{
int stateacc;
unsigned i;
if (statenum == 0)
return NULL;
for (i = 0, stateacc = 1; i < StateMap.Size(); i++)
{
if (stateacc <= statenum && stateacc + StateMap[i].StateSpan > statenum)
{
if (StateMap[i].State != NULL)
{
if (StateMap[i].OwnerIsPickup)
{
PushTouchedActor(const_cast<PClass *>(StateMap[i].Owner));
}
return StateMap[i].State + statenum - stateacc;
}
else return NULL;
}
stateacc += StateMap[i].StateSpan;
}
return NULL;
}
int FindStyle (const char *namestr)
{
for(unsigned i = 0; i < StyleNames.Size(); i++)
{
if (!stricmp(StyleNames[i].Name, namestr)) return StyleNames[i].Num;
}
DPrintf("Unknown render style %s\n", namestr);
return -1;
}
static bool ReadChars (char **stuff, int size)
{
char *str = *stuff;
if (!size) {
*str = 0;
return true;
}
do {
// Ignore carriage returns
if (*PatchPt != '\r')
*str++ = *PatchPt;
else
size++;
PatchPt++;
} while (--size && *PatchPt != 0);
*str = 0;
return true;
}
static void ReplaceSpecialChars (char *str)
{
char *p = str, c;
int i;
while ( (c = *p++) ) {
if (c != '\\') {
*str++ = c;
} else {
switch (*p) {
case 'n':
case 'N':
*str++ = '\n';
break;
case 't':
case 'T':
*str++ = '\t';
break;
case 'r':
case 'R':
*str++ = '\r';
break;
case 'x':
case 'X':
c = 0;
p++;
for (i = 0; i < 2; i++) {
c <<= 4;
if (*p >= '0' && *p <= '9')
c += *p-'0';
else if (*p >= 'a' && *p <= 'f')
c += 10 + *p-'a';
else if (*p >= 'A' && *p <= 'F')
c += 10 + *p-'A';
else
break;
p++;
}
*str++ = c;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
c = 0;
for (i = 0; i < 3; i++) {
c <<= 3;
if (*p >= '0' && *p <= '7')
c += *p-'0';
else
break;
p++;
}
*str++ = c;
break;
default:
*str++ = *p;
break;
}
p++;
}
}
*str = 0;
}
static char *skipwhite (char *str)
{
if (str)
while (*str && isspace(*str))
str++;
return str;
}
static void stripwhite (char *str)
{
char *end = str + strlen(str) - 1;
while (end >= str && isspace(*end))
end--;
end[1] = '\0';
}
static char *igets (void)
{
char *line;
if (*PatchPt == '\0' || PatchPt >= PatchFile + PatchSize )
return NULL;
line = PatchPt;
while (*PatchPt != '\n' && *PatchPt != '\0')
PatchPt++;
if (*PatchPt == '\n')
*PatchPt++ = 0;
return line;
}
static int GetLine (void)
{
char *line, *line2;
do {
while ( (line = igets ()) )
if (line[0] != '#') // Skip comment lines
break;
if (!line)
return 0;
Line1 = skipwhite (line);
} while (Line1 && *Line1 == 0); // Loop until we get a line with
// more than just whitespace.
line = strchr (Line1, '=');
if (line) { // We have an '=' in the input line
line2 = line;
while (--line2 >= Line1)
if (*line2 > ' ')
break;
if (line2 < Line1)
return 0; // Nothing before '='
*(line2 + 1) = 0;
line++;
while (*line && *line <= ' ')
line++;
if (*line == 0)
return 0; // Nothing after '='
Line2 = line;
return 1;
} else { // No '=' in input line
line = Line1 + 1;
while (*line > ' ')
line++; // Get beyond first word
*line++ = 0;
while (*line && *line <= ' ')
line++; // Skip white space
//.bex files don't have this restriction
//if (*line == 0)
// return 0; // No second word
Line2 = line;
return 2;
}
}
// This enum must be in sync with the Aliases array in DEHSUPP.
enum MBFCodePointers
{
// Die and Detonate are not in this list because these codepointers have
// no dehacked arguments and therefore do not need special handling.
// NailBomb has no argument but is implemented as new parameters for A_Explode.
MBF_Mushroom, // misc1 = vrange (arg +3), misc2 = hrange (arg+4)
MBF_Spawn, // misc1 = type (arg +0), misc2 = Z-pos (arg +2)
MBF_Turn, // misc1 = angle (in degrees) (arg +0 but factor in current actor angle too)
MBF_Face, // misc1 = angle (in degrees) (arg +0)
MBF_Scratch, // misc1 = damage, misc 2 = sound
MBF_PlaySound, // misc1 = sound, misc2 = attenuation none (true) or normal (false)
MBF_RandomJump, // misc1 = state, misc2 = probability
MBF_LineEffect, // misc1 = Boom linedef type, misc2 = sector tag
SMMU_NailBomb, // No misc, but it's basically A_Explode with an added effect
};
int PrepareStateParameters(FState * state, int numparams, const PClass *cls);// Should probably be in a .h file.
// Hacks the parameter list for the given state so as to convert MBF-args (misc1 and misc2) into real args.
void SetDehParams(FState * state, int codepointer)
{
int value1 = state->GetMisc1();
int value2 = state->GetMisc2();
if (!(value1|value2)) return;
// Fakey fake script position thingamajig. Because NULL cannot be used instead.
// Even if the lump was parsed by an FScanner, there would hardly be a way to
// identify which line is troublesome.
FScriptPosition * pos = new FScriptPosition(FString("DEHACKED"), 0);
// Let's identify the codepointer we're dealing with.
PSymbolActionFunction * sym; PSymbol * s;
s = RUNTIME_CLASS(AInventory)->Symbols.FindSymbol(FName(MBFCodePointers[codepointer].name), true);
if (!s || s->SymbolType != SYM_ActionFunction) return;
sym = static_cast<PSymbolActionFunction*>(s);
// Bleargh! This will all have to be redone once scripting works
// Not sure exactly why the index for a state is greater by one point than the index for a symbol.
DPrintf("SetDehParams: Paramindex is %d, default is %d.\n",
state->ParameterIndex-1, sym->defaultparameterindex);
if (state->ParameterIndex-1 == sym->defaultparameterindex)
{
int a = PrepareStateParameters(state, MBFCodePointers[codepointer].params+1,
FState::StaticFindStateOwner(state)) -1;
int b = sym->defaultparameterindex;
// StateParams.Copy(a, b, MBFParams[codepointer]);
// Meh, function doesn't work. For some reason it resets the paramindex to the default value.
// For instance, a dehacked Commander Keen calling A_Explode would result in a crash as
// ACTION_PARAM_INT(damage, 0) would properly evaluate at paramindex 1377, but then
// ACTION_PARAM_INT(distance, 1) would improperly evaluate at paramindex 148! Now I'm not sure
// whether it's a genuine problem or working as intended and merely not appropriate for the
// task at hand here. So rather than modify it, I use a simple for loop of Set()s and Get()s,
// with a small modification to Set() that I know will have no repercussion anywhere else.
for (int i = 0; i<MBFCodePointers[codepointer].params; i++)
{
StateParams.Set(a+i, StateParams.Get(b+i), true);
}
DPrintf("New paramindex is %d.\n", state->ParameterIndex-1);
}
int ParamIndex = state->ParameterIndex - 1;
switch (codepointer)
{
case MBF_Mushroom:
StateParams.Set(ParamIndex+2, new FxConstant(1, *pos)); // Flag
// NOTE: Do not convert to float here because it will lose precision. It must be double.
if (value1) StateParams.Set(ParamIndex+3, new FxConstant(value1/65536., *pos)); // vrange
if (value2) StateParams.Set(ParamIndex+4, new FxConstant(value2/65536., *pos)); // hrange
break;
case MBF_Spawn:
if (InfoNames[value1-1] == NULL)
{
I_Error("No class found for dehackednum %d!\n", value1+1);
return;
}
StateParams.Set(ParamIndex+0, new FxConstant(InfoNames[value1-1], *pos)); // type
StateParams.Set(ParamIndex+2, new FxConstant(value2, *pos)); // height
break;
case MBF_Turn:
// Intentional fall through. I tried something more complicated by creating an
// FxExpression that corresponded to "variable angle + angle" so as to use A_SetAngle
// as well, but it became an overcomplicated mess that didn't even work as I had to
// create a compile context as well and couldn't get it right.
case MBF_Face:
StateParams.Set(ParamIndex+0, new FxConstant(value1, *pos)); // angle
break;
case MBF_Scratch: // misc1 = damage, misc 2 = sound
StateParams.Set(ParamIndex+0, new FxConstant(value1, *pos)); // damage
if (value2) StateParams.Set(ParamIndex+1, new FxConstant(SoundMap[value2-1], *pos)); // hit sound
break;
case MBF_PlaySound:
StateParams.Set(ParamIndex+0, new FxConstant(SoundMap[value1-1], *pos)); // soundid
StateParams.Set(ParamIndex+1, new FxConstant(CHAN_BODY, *pos)); // channel
StateParams.Set(ParamIndex+2, new FxConstant(1.0, *pos)); // volume
StateParams.Set(ParamIndex+3, new FxConstant(false, *pos)); // looping
StateParams.Set(ParamIndex+4, new FxConstant((value2 ? ATTN_NONE : ATTN_NORM), *pos)); // attenuation
break;
case MBF_RandomJump:
StateParams.Set(ParamIndex+0, new FxConstant(2, *pos)); // count
StateParams.Set(ParamIndex+1, new FxConstant(value2, *pos)); // maxchance
StateParams.Set(ParamIndex+2, new FxConstant(FindState(value1), *pos)); // jumpto
break;
case MBF_LineEffect:
// This is the second MBF codepointer that couldn't be translated easily.
// Calling P_TranslateLineDef() here was a simple matter, as was adding an
// extra parameter to A_CallSpecial so as to replicate the LINEDONE stuff,
// but unfortunately DEHACKED lumps are processed before the map translation
// arrays are initialized so this didn't work.
StateParams.Set(ParamIndex+0, new FxConstant(value1, *pos)); // special
StateParams.Set(ParamIndex+1, new FxConstant(value2, *pos)); // tag
break;
case SMMU_NailBomb:
// That one does not actually have MBF-style parameters. But since
// we're aliasing it to an extension of A_Explode...
StateParams.Set(ParamIndex+5, new FxConstant(30, *pos)); // nails
StateParams.Set(ParamIndex+6, new FxConstant(10, *pos)); // naildamage
break;
default:
// This simply should not happen.
Printf("Unmanaged dehacked codepointer alias num %i\n", codepointer);
}
}
static int PatchThing (int thingy)
{
enum
{
// Boom flags
MF_TRANSLATION = 0x0c000000, // if 0x4 0x8 or 0xc, use a translation
MF_TRANSSHIFT = 26, // table for player colormaps
// A couple of Boom flags that don't exist in ZDoom
MF_SLIDE = 0x00002000, // Player: keep info about sliding along walls.
MF_TRANSLUCENT = 0x80000000, // Translucent sprite?
// MBF flags: TOUCHY is remapped to flags6, FRIEND is turned into FRIENDLY,
// and finally BOUNCES is replaced by bouncetypes with the BOUNCES_MBF bit.
MF_TOUCHY = 0x10000000, // killough 11/98: dies when solids touch it
MF_BOUNCES = 0x20000000, // killough 7/11/98: for beta BFG fireballs
MF_FRIEND = 0x40000000, // killough 7/18/98: friendly monsters
};
int result;
AActor *info;
BYTE dummy[sizeof(AActor)];
bool hadHeight = false;
bool hadTranslucency = false;
bool hadStyle = false;
FStateDefinitions statedef;
bool patchedStates = false;
int oldflags;
const PClass *type;
SWORD *ednum, dummyed;
type = NULL;
info = (AActor *)&dummy;
ednum = &dummyed;
if (thingy > (int)InfoNames.Size() || thingy <= 0)
{
Printf ("Thing %d out of range.\n", thingy);
}
else
{
DPrintf ("Thing %d\n", thingy);
if (thingy > 0)
{
type = InfoNames[thingy - 1];
if (type == NULL)
{
info = (AActor *)&dummy;
ednum = &dummyed;
// An error for the name has already been printed while loading DEHSUPP.
Printf ("Could not find thing %d\n", thingy);
}
else
{
info = GetDefaultByType (type);
ednum = &type->ActorInfo->DoomEdNum;
}
}
}
oldflags = info->flags;
while ((result = GetLine ()) == 1)
{
char *endptr;
unsigned long val = strtoul (Line2, &endptr, 10);
size_t linelen = strlen (Line1);
if (linelen == 10 && stricmp (Line1, "Hit points") == 0)
{
info->health = val;
}
else if (linelen == 13 && stricmp (Line1, "Reaction time") == 0)
{
info->reactiontime = val;
}
else if (linelen == 11 && stricmp (Line1, "Pain chance") == 0)
{
info->PainChance = (SWORD)val;
}
else if (linelen == 12 && stricmp (Line1, "Translucency") == 0)
{
info->alpha = val;
info->RenderStyle = STYLE_Translucent;
hadTranslucency = true;
hadStyle = true;
}
else if (linelen == 6 && stricmp (Line1, "Height") == 0)
{
info->height = val;
info->projectilepassheight = 0; // needs to be disabled
hadHeight = true;
}
else if (linelen == 14 && stricmp (Line1, "Missile damage") == 0)
{
info->Damage = val;
}
else if (linelen == 5)
{
if (stricmp (Line1, "Speed") == 0)
{
info->Speed = val;
}
else if (stricmp (Line1, "Width") == 0)
{
info->radius = val;
}
else if (stricmp (Line1, "Alpha") == 0)
{
info->alpha = (fixed_t)(atof (Line2) * FRACUNIT);
hadTranslucency = true;
}
else if (stricmp (Line1, "Scale") == 0)
{
info->scaleY = info->scaleX = clamp<fixed_t> (FLOAT2FIXED(atof (Line2)), 1, 256*FRACUNIT);
}
else if (stricmp (Line1, "Decal") == 0)
{
stripwhite (Line2);
const FDecalTemplate *decal = DecalLibrary.GetDecalByName (Line2);
if (decal != NULL)
{
info->DecalGenerator = const_cast <FDecalTemplate *>(decal);
}
else
{
Printf ("Thing %d: Unknown decal %s\n", thingy, Line2);
}
}
}
else if (linelen == 12 && stricmp (Line1, "Render Style") == 0)
{
stripwhite (Line2);
int style = FindStyle (Line2);
if (style >= 0)
{
info->RenderStyle = ERenderStyle(style);
hadStyle = true;
}
}
else if (linelen > 6)
{
if (linelen == 12 && stricmp (Line1, "No Ice Death") == 0)
{
if (val)
{
info->flags4 |= MF4_NOICEDEATH;
}
else
{
info->flags4 &= ~MF4_NOICEDEATH;
}
}
else if (stricmp (Line1 + linelen - 6, " frame") == 0)
{
FState *state = FindState (val);
if (type != NULL && !patchedStates)
{
statedef.MakeStateDefines(type);
patchedStates = true;
}
if (!strnicmp (Line1, "Initial", 7))
statedef.SetStateLabel("Spawn", state ? state : GetDefault<AActor>()->SpawnState);
else if (!strnicmp (Line1, "First moving", 12))
statedef.SetStateLabel("See", state);
else if (!strnicmp (Line1, "Injury", 6))
statedef.SetStateLabel("Pain", state);
else if (!strnicmp (Line1, "Close attack", 12))
{
if (thingy != 1) // Not for players!
{
statedef.SetStateLabel("Melee", state);
}
}
else if (!strnicmp (Line1, "Far attack", 10))
{
if (thingy != 1) // Not for players!
{
statedef.SetStateLabel("Missile", state);
}
}
else if (!strnicmp (Line1, "Death", 5))
statedef.SetStateLabel("Death", state);
else if (!strnicmp (Line1, "Exploding", 9))
statedef.SetStateLabel("XDeath", state);
else if (!strnicmp (Line1, "Respawn", 7))
statedef.SetStateLabel("Raise", state);
}
else if (stricmp (Line1 + linelen - 6, " sound") == 0)
{
FSoundID snd;
if (val == 0 || val >= SoundMap.Size())
{
if (endptr == Line2)
{ // Sound was not a (valid) number,
// so treat it as an actual sound name.
stripwhite (Line2);
snd = Line2;
}
}
else
{
snd = SoundMap[val-1];
}
if (!strnicmp (Line1, "Alert", 5))
info->SeeSound = snd;
else if (!strnicmp (Line1, "Attack", 6))
info->AttackSound = snd;
else if (!strnicmp (Line1, "Pain", 4))
info->PainSound = snd;
else if (!strnicmp (Line1, "Death", 5))
info->DeathSound = snd;
else if (!strnicmp (Line1, "Action", 6))
info->ActiveSound = snd;
}
}
else if (linelen == 4)
{
if (stricmp (Line1, "Mass") == 0)
{
info->Mass = val;
}
else if (stricmp (Line1, "Bits") == 0)
{
DWORD value[4] = { 0, 0, 0 };
bool vchanged[4] = { false, false, false };
// ZDoom used to block the upper range of bits to force use of mnemonics for extra flags.
// MBF also defined extra flags in the same range, but without forcing mnemonics. For MBF
// compatibility, the upper bits are freed, but we have conflicts between the ZDoom bits
// and the MBF bits. The only such flag exposed to DEHSUPP, though, is STEALTH -- the others
// are not available through mnemonics, and aren't available either through their bit value.
// So if we find the STEALTH keyword, it's a ZDoom mod, otherwise assume FRIEND.
bool zdoomflags = false;
char *strval;
for (strval = Line2; (strval = strtok (strval, ",+| \t\f\r")); strval = NULL)
{
if (IsNum (strval))