-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathPlusAngelscriptLibrary.cs
More file actions
866 lines (814 loc) · 40.9 KB
/
PlusAngelscriptLibrary.cs
File metadata and controls
866 lines (814 loc) · 40.9 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
using System.Collections.Generic;
using System.IO;
using Ionic.Zlib;
using Ionic.Crc;
using System.Text.RegularExpressions;
using System.Linq;
namespace MLLE
{
public partial struct PlusPropertyList
{
const uint CurrentMLLEData5Version = 0x108;
const string MLLEData5MagicString = "MLLE";
const string CurrentMLLEData5VersionStringForComparison = "0x108";
const string CurrentMLLEData5VersionString = "1.8";
const string AngelscriptLibrary =
@"//This is a standard library created by MLLE to read some JJ2+ properties from a level file whose script includes this library. DO NOT MANUALLY MODIFY THIS FILE.
#pragma require '{0}'
namespace MLLE {{
jjPAL@ Palette;
dictionary@ _layers, _palettes;{1}
array<_offgridObject>@ _offGridObjects;
bool Setup({2}) {{
jjPAL palette = jjBackupPalette;
@Palette = @palette;
dictionary layers;
@_layers = @layers;
dictionary palettes;
@_palettes = @palettes;
jjSTREAM crcCheck('{0}');
string crcLine;
if (crcCheck.isEmpty() || !crcCheck.getLine(crcLine)) {{
jjDebug('MLLE::Setup: Include file has been renamed!');
return false;
}}
array<string> regexResults;
if (!jjRegexMatch(crcLine, '\\/\\/(\\d+)\\r?', regexResults)) {{
jjDebug('MLLE::Setup: Include file is improperly formatted!');
return false;
}}
if (parseUInt(regexResults[1]) != jjCRC32(crcCheck)) {{
jjDebug('MLLE::Setup: Include file has been damaged!');
return false;
}}
jjSTREAM level(jjLevelFileName);
if (level.isEmpty()) {{
jjDebug('MLLE::Setup: Error reading ""' + jjLevelFileName + '""!');
return false;
}}
level.discard(230);
array<uint> CompressedDataSizes(4, 0);
for (uint i = 0; i < CompressedDataSizes.length; ++i) {{
level.pop(CompressedDataSizes[i]);
level.discard(4);
}}
for (uint i = 0; i < CompressedDataSizes.length; ++i)
level.discard(CompressedDataSizes[i]);
if (level.getSize() < 20) {{
jjDebug('MLLE::Setup: Level file does not contain any additional data!');
return false;
}}
string magic;
level.get(magic, '" + MLLEData5MagicString + @"'.length);
if (magic != '" + MLLEData5MagicString + @"') {{
jjDebug('MLLE::Setup: Level was not saved by MLLE!');
return false;
}}
uint levelDataVersion;
level.pop(levelDataVersion);
if (levelDataVersion != " + CurrentMLLEData5VersionStringForComparison + @") {{
jjDebug('MLLE::Setup: Level\'s Data5 section was saved in a different version of MLLE than this script!');
return false;
}}
uint csize, usize;
level.pop(csize); level.pop(usize);
jjSTREAM data5;
if (!jjZlibUncompress(level, data5, usize)) {{
jjDebug('MLLE::Setup: Error during ZLIB uncompression!');
return false;
}}
bool pbool; uint8 pbyte; int8 pchar; int16 pshort; float pfloat; int pint; uint puint, puint2;
data5.pop(pbool); jjIsSnowing = pbool;
data5.pop(pbool); jjIsSnowingOutdoorsOnly = pbool;
data5.pop(pbyte); jjSnowingIntensity = pbyte;
data5.pop(pbyte); jjSnowingType = SNOWING::Type(pbyte);
if (jjIsSnowing) {{
if (jjSnowingType == SNOWING::SNOW && jjAnimSets[ANIM::SNOW] == 0)
jjAnimSets[ANIM::SNOW].load();
else if ((uint(jjSnowingType) & 3) != 0 && jjAnimSets[ANIM::PLUS_SCENERY] == 0)
jjAnimSets[ANIM::PLUS_SCENERY].load();
}}
data5.pop(pbool); jjWarpsTransmuteCoins = pbool;
data5.pop(pbool); jjDelayGeneratedCrateOrigins = pbool;
data5.pop(pint); jjEcho = pint;
data5.pop(puint); jjSetDarknessColor(_colorFromArgb(puint));
data5.pop(pfloat);jjWaterChangeSpeed = pfloat;
data5.pop(pbyte); jjWaterInteraction = WATERINTERACTION::WaterInteraction(pbyte);
data5.pop(pint); jjWaterLayer = pint;
data5.pop(pbyte); jjWaterLighting = WATERLIGHT::wl(pbyte);
data5.pop(pfloat); if (int(pfloat) < jjLayerHeight[4] * 32) jjSetWaterLevel(pfloat, true);
data5.pop(puint); data5.pop(puint2); jjSetWaterGradient(_colorFromArgb(puint), _colorFromArgb(puint2));
data5.pop(pbool); if (pbool) {{
_readPalette(data5, palette);
palette.apply();
data5.pop(pbool);
}}
data5.pop(pbyte);
array<uint8> mappingIndices(pbyte);
puint = 0;
while (pbyte-- != 0) {{
jjPAL extra;
string paletteName = _read7BitEncodedStringFromStream(data5);
_readPalette(data5, extra);
int index = jjSpriteModeFirstFreeMapping();
if (index < 0) {{
jjDebug('MLLE::Setup: Not enough room for additional palette ' + paletteName);
}} else {{
mappingIndices[puint++] = uint8(index);
_palettes.set(paletteName, uint8(index));
array<uint8> indexMapping(256);
for (uint i = 0; i < 256; ++i)
indexMapping[i] = jjPalette.findNearestColor(extra.color[i]);
jjSpriteModeSetMapping(index, indexMapping, extra);
}}
}}
_recolorAnimationIf(data5, ANIM::PINBALL, 0, 4);
_recolorAnimationIf(data5, ANIM::PINBALL, 2, 4);
_recolorAnimationIf(data5, ANIM::CARROTPOLE, 0, 1);
_recolorAnimationIf(data5, ANIM::DIAMPOLE, 0, 1);
_recolorAnimationIf(data5, ANIM::PINBALL, 4, 8);
_recolorAnimationIf(data5, ANIM::JUNGLEPOLE, 0, 1);
_recolorAnimationIf(data5, ANIM::PLUS_SCENERY, 0, 17);
_recolorAnimationIf(data5, ANIM::PSYCHPOLE, 0, 1);
_recolorAnimationIf(data5, ANIM::SMALTREE, 0, 1);
_recolorAnimationIf(data5, ANIM::SNOW, 0, 8);
_recolorAnimationIf(data5, ANIM::COMMON, 2, 18);
_recolorAnimationIf(data5, ANIM::BOLLPLAT, 0, 2);
_recolorAnimationIf(data5, ANIM::FRUITPLAT, 0, 2);
_recolorAnimationIf(data5, ANIM::GRASSPLAT, 0, 2);
_recolorAnimationIf(data5, ANIM::PINKPLAT, 0, 2);
_recolorAnimationIf(data5, ANIM::SONICPLAT, 0, 2);
_recolorAnimationIf(data5, ANIM::SPIKEPLAT, 0, 2);
_recolorAnimationIf(data5, ANIM::SPIKEBOLL, 0, 2);
_recolorAnimationIf(data5, ANIM::SPIKEBOLL3D, 0, 2);
_recolorAnimationIf(data5, ANIM::VINE, 1, 1);
data5.pop(pbyte);
for (uint i = 0; i < pbyte; ++i) {{
string tilesetFilename = _read7BitEncodedStringFromStream(data5);
uint16 tileStart, tileCount;
data5.pop(tileStart); data5.pop(tileCount);
data5.pop(pchar);
if (pchar < 2) {{
array<uint8>@ colors = null;
if (pchar == 1) {{
@colors = array<uint8>(256);
for (uint j = 0; j < 256; ++j)
data5.pop(colors[j]);
}}
if (!jjTilesFromTileset(tilesetFilename, tileStart, tileCount, colors)) {{
jjDebug('MLLE::Setup: Error reading ""' + tilesetFilename + '""!');
return false;
}}
}} else {{
jjPAL@ thisPalette = null;
if (pchar == 3) {{
data5.pop(pchar);
@thisPalette = jjSpriteModeGetColorMapping(mappingIndices[uint8(pchar)]);
}}
if (!jjTilesFromTileset32(tilesetFilename, tileStart, tileCount, thisPalette)) {{
jjDebug('MLLE::Setup: Error reading ""' + tilesetFilename + '""!');
return false;
}}
}}
}}
if (pbyte != 0) {{
array<uint> layersIDsWithTileMaps;
for (uint i = 1; i <= 8; ++i)
if (jjLayers[i].hasTileMap)
layersIDsWithTileMaps.insertLast(i);
if (jjLayersFromLevel(jjLevelFileName, layersIDsWithTileMaps).length == 0) {{
jjDebug('MLLE::Setup: Error reading ""' + jjLevelFileName + '""!');
}}
}}
array<jjLAYER@> newLayerOrder, nonDefaultLayers;
data5.pop(puint);
for (uint i = 8; i < puint; i += 8) {{
array<uint> layerIDsToGrab;
for (uint j = i; j < puint && j < i + 8; ++j) {{
layerIDsToGrab.insertLast((j & 7) + 1);
}}
const string extraLayersFilename = jjLevelFileName.substr(0, jjLevelFileName.length() - 4) + '-MLLE-Data-' + (i/8) + '.j2l';
array<jjLAYER@> extraLayers = jjLayersFromLevel(extraLayersFilename, layerIDsToGrab);
if (extraLayers.length == 0) {{
jjDebug('MLLE::Setup: Error reading ""' + extraLayersFilename + '""!');
return false;
}}
for (uint j = 0; j < extraLayers.length(); ++j)
nonDefaultLayers.insertLast(extraLayers[j]);
}}
uint nextNonDefaultLayerID = 0;
for (uint i = 0; i < puint; ++i) {{
data5.pop(pchar);
jjLAYER@ layer;
if (pchar >= 0)
@layer = jjLayers[pchar + 1];
else
@layer = nonDefaultLayers[nextNonDefaultLayerID++];
string layerName = _read7BitEncodedStringFromStream(data5);
_layers.set(layerName, @layer);
data5.pop(pbool);
if (layer.hasTileMap)
layer.hasTiles = !pbool;
data5.pop(pbyte);
layer.spriteMode = SPRITE::Mode(pbyte);
data5.pop(pbyte);
layer.spriteParam = (layer.spriteMode == SPRITE::MAPPING || layer.spriteMode == SPRITE::TRANSLUCENTMAPPING) ? mappingIndices[pbyte] : pbyte;
data5.pop(pint);
layer.rotationAngle = pint;
data5.pop(pint);
layer.rotationRadiusMultiplier = pint;
data5.pop(pbyte);
layer.xSpeedModel = LAYERSPEEDMODEL::LayerSpeedModel(pbyte);
data5.pop(pbyte);
layer.ySpeedModel = LAYERSPEEDMODEL::LayerSpeedModel(pbyte);
data5.pop(pbyte);
layer.textureSurface = SURFACE::Surface(pbyte);
data5.pop(pbyte);
layer.reflection.tintColor = pbyte;
data5.pop(pfloat);
layer.reflection.fadePositionX = pfloat;
data5.pop(pfloat);
layer.reflection.top = pfloat;
data5.pop(pfloat);
layer.xInnerSpeed = pfloat;
data5.pop(pfloat);
layer.yInnerSpeed = pfloat;
data5.pop(pfloat);
layer.xInnerAutoSpeed = pfloat;
data5.pop(pfloat);
layer.yInnerAutoSpeed = pfloat;
data5.pop(pchar);
if (pchar >= 0)
layer.texture = TEXTURE::Texture(pchar);
else {{
jjPIXELMAP texture(256, 256);
_readImage(data5, texture);
texture.makeTexture(layer);
}}
newLayerOrder.insertLast(layer);
}}
jjLayerOrderSet(newLayerOrder);
uint16 numberOfObjects; data5.pop(numberOfObjects);
while (numberOfObjects-- != 0) {{
uint16 tileID; data5.pop(tileID);
if ((tileID & TILE::VFLIPPED) != 0) {{
jjCOLORMAP tile(32, 32);
_readImage(data5, tile);
tile.save(tileID & (TILE::VFLIPPED - 1), true);
}} else {{
jjPIXELMAP tile(32, 32);
_readImage(data5, tile);
tile.save(tileID, true);
}}
}}
data5.pop(numberOfObjects);
while (numberOfObjects-- != 0) {{
uint16 tileID; data5.pop(tileID);
jjMASKMAP tile;
for (int y = 0; y < 32; ++y)
for (int x = 0; x < 32; ++x)
data5.pop(tile[x,y]);
tile.save(tileID, true);
}}
data5.pop(pshort);
for (uint i = 1; i <= 9; ++i) {{
jjWEAPON@ weapon = jjWeapons[i];
data5.pop(pbool);
data5.pop(pint); weapon.maximum = pint;
data5.pop(pbyte); weapon.comesFromBirds = pbyte != 0; weapon.comesFromBirdsPowerup = pbyte == 2;
data5.pop(pbyte); weapon.comesFromGunCrates = pbyte != 0;
data5.pop(pbyte); weapon.gemsLost = pbyte;
data5.pop(pbyte); weapon.gemsLostPowerup = pbyte;
data5.pop(pbyte); weapon.infinite = pbyte & 1 == 1; weapon.replenishes = pbyte & 2 == 2;
uint8 ammoCrateEventID = 0;
if (i >= 7) {{
data5.pop(ammoCrateEventID);
if (ammoCrateEventID > 32) {{
jjOBJ@ preset = jjObjectPresets[ammoCrateEventID];
if (jjGameConnection == GAME::LOCAL)
preset.behavior = AmmoCrate(ammoCrateEventID);
else
preset.behavior = BEHAVIOR::AMMO15;
preset.playerHandling = HANDLING::SPECIAL;
preset.scriptedCollisions = false;
preset.direction = 1;
preset.energy = 1;
preset.curFrame = jjAnimations[preset.curAnim = (i == 7) ? (jjAnimSets[ANIM::PICKUPS] + 59) : (jjAnimSets[ANIM::PLUS_COMMON] + i - 8)] + (preset.frameID = 0);
preset.killAnim = jjAnimSets[ANIM::AMMO] + 71;
preset.eventID = OBJECT::ICEAMMO15;
preset.var[2] = 31 + i;
preset.var[3] = i - 1;
preset.points = 300;
}}
}}
{3}if (i == 8) {{
data5.pop(pbyte);
if (pbyte == 0)
weapon.spread = SPREAD::GUN8;
else if (pbyte == 1)
weapon.spread = SPREAD::PEPPERSPRAY;
else if (pbyte >= 2)
weapon.spread = SPREAD::NORMAL;
if (pbyte == 2)
weapon.gradualAim = false;
}}
}}
data5.pop(numberOfObjects);
if (numberOfObjects != 0) {{
if (jjGameConnection != GAME::LOCAL)
jjObjectPresets[254].behavior = _replaceMe;
else
jjObjectPresets[254].behavior = BEHAVIOR::INACTIVE;
@_offGridObjects = array<_offgridObject>();
array<uint8> animSetsToLoad(256, 0);
animSetsToLoad[OBJECT::BONUSPOST] = ANIM::BONUS;
animSetsToLoad[OBJECT::SWINGINGVINE] = ANIM::VINE;
animSetsToLoad[OBJECT::TUFTURT] = ANIM::TUFTUR;
animSetsToLoad[OBJECT::LABRAT] = ANIM::LABRAT;
animSetsToLoad[OBJECT::LIZARD] = ANIM::LIZARD;
animSetsToLoad[OBJECT::FLOATLIZARD] = ANIM::LIZARD;
animSetsToLoad[OBJECT::SUCKER] = ANIM::SUCKER;
animSetsToLoad[OBJECT::CATERPILLAR] = ANIM::CATERPIL;
animSetsToLoad[OBJECT::SMOKERING] = ANIM::CATERPIL;
animSetsToLoad[OBJECT::CHESHIRE1] = ANIM::CAT;
animSetsToLoad[OBJECT::CHESHIRE2] = ANIM::CAT2;
animSetsToLoad[OBJECT::HATTER] = ANIM::HATTER;
animSetsToLoad[OBJECT::SKELETON] = ANIM::SKELETON;
animSetsToLoad[OBJECT::DOGGYDOGG] = ANIM::DOG;
animSetsToLoad[OBJECT::NORMTURTLE] = ANIM::TURTLE;
animSetsToLoad[OBJECT::TURTLESHELL] = ANIM::TURTLE;
animSetsToLoad[OBJECT::DEMON] = ANIM::DEMON;
animSetsToLoad[OBJECT::STEAM] = ANIM::STEAM;
animSetsToLoad[OBJECT::ROTATINGROCK] = ANIM::ROCK;
animSetsToLoad[OBJECT::HELMUT] = ANIM::HELMUT;
animSetsToLoad[OBJECT::BILSY] = ANIM::BILSBOSS;
animSetsToLoad[OBJECT::BAT] = ANIM::BAT;
animSetsToLoad[OBJECT::BEE] = ANIM::BUMBEE;
animSetsToLoad[OBJECT::DRAGONFLY] = ANIM::DRAGFLY;
animSetsToLoad[OBJECT::FATCHICK] = ANIM::FATCHK;
animSetsToLoad[OBJECT::FENCER] = ANIM::FENCER;
animSetsToLoad[OBJECT::FISH] = ANIM::FISH;
animSetsToLoad[OBJECT::MOTH] = ANIM::MOTH;
animSetsToLoad[OBJECT::RAPIER] = ANIM::RAPIER;
animSetsToLoad[OBJECT::SPARK] = ANIM::SPARK;
animSetsToLoad[OBJECT::LEFTPADDLE] = ANIM::PINBALL;
animSetsToLoad[OBJECT::RIGHTPADDLE] = ANIM::PINBALL;
animSetsToLoad[OBJECT::FIVEHUNDREDBUMP] = ANIM::PINBALL;
animSetsToLoad[OBJECT::CARROTBUMP] = ANIM::PINBALL;
animSetsToLoad[OBJECT::QUEEN] = ANIM::QUEEN;
animSetsToLoad[OBJECT::FLOATSUCKER] = ANIM::SUCKER;
animSetsToLoad[OBJECT::BRIDGE] = ANIM::BRIDGE;
animSetsToLoad[OBJECT::MONKEY] = ANIM::MONKEY;
animSetsToLoad[OBJECT::STANDMONKEY] = ANIM::MONKEY;
animSetsToLoad[OBJECT::RAVEN] = ANIM::RAVEN;
animSetsToLoad[OBJECT::TUBETURTLE] = ANIM::TUBETURT;
animSetsToLoad[OBJECT::SMALLTREE] = ANIM::SMALTREE;
animSetsToLoad[OBJECT::DIAMONDUSPOLE] = ANIM::DIAMPOLE;
animSetsToLoad[OBJECT::PSYCHPOLE] = ANIM::PSYCHPOLE;
animSetsToLoad[OBJECT::CARROTUSPOLE] = ANIM::CARROTPOLE;
animSetsToLoad[OBJECT::JUNGLEPOLE] = ANIM::JUNGLEPOLE;
animSetsToLoad[OBJECT::UTERUS] = ANIM::UTERUS;
animSetsToLoad[OBJECT::UTERUSSPIKEBALL] = ANIM::UTERUS;
animSetsToLoad[OBJECT::CRAB] = ANIM::UTERUS;
animSetsToLoad[OBJECT::ROBOT] = ANIM::ROBOT;
animSetsToLoad[OBJECT::DEVANROBOT] = ANIM::DEVAN;
animSetsToLoad[OBJECT::FRUITPLATFORM] = ANIM::FRUITPLAT;
animSetsToLoad[OBJECT::BOLLPLATFORM] = ANIM::BOLLPLAT;
animSetsToLoad[OBJECT::GRASSPLATFORM] = ANIM::GRASSPLAT;
animSetsToLoad[OBJECT::PINKPLATFORM] = ANIM::PINKPLAT;
animSetsToLoad[OBJECT::SONICPLATFORM] = ANIM::SONICPLAT;
animSetsToLoad[OBJECT::SPIKEPLATFORM] = ANIM::SPIKEPLAT;
animSetsToLoad[OBJECT::SPIKEBOLL] = ANIM::SPIKEBOLL;
animSetsToLoad[OBJECT::SPIKEBOLL3D] = ANIM::SPIKEBOLL3D;
animSetsToLoad[OBJECT::EVA] = ANIM::EVA;
animSetsToLoad[OBJECT::WITCH] = ANIM::WITCH;
animSetsToLoad[OBJECT::ROCKETTURTLE] = ANIM::ROCKTURT;
animSetsToLoad[OBJECT::BUBBA] = ANIM::BUBBA;
animSetsToLoad[OBJECT::DEVILDEVAN] = ANIM::DEVILDEVAN;
animSetsToLoad[OBJECT::TUFBOSS] = ANIM::TUFBOSS;
animSetsToLoad[OBJECT::BIGROCK] = ANIM::BIGROCK;
animSetsToLoad[OBJECT::BIGBOX] = ANIM::BIGBOX;
animSetsToLoad[OBJECT::BOLLY] = ANIM::SONCSHIP;
animSetsToLoad[OBJECT::BUTTERFLY] = ANIM::BUTTERFLY;
animSetsToLoad[OBJECT::BEEBOY] = ANIM::BEEBOY;
animSetsToLoad[OBJECT::XMASNORMTURTLE] = ANIM::XTURTLE;
animSetsToLoad[OBJECT::XMASLIZARD] = ANIM::XLIZARD;
animSetsToLoad[OBJECT::XMASFLOATLIZARD] = ANIM::XLIZARD;
animSetsToLoad[OBJECT::XMASBILSY] = ANIM::XBILSY;
animSetsToLoad[OBJECT::CAT] = ANIM::ZDOG;
animSetsToLoad[OBJECT::PACMANGHOST] = ANIM::ZSPARK;
do {{
uint16 xPos; data5.pop(xPos);
uint16 yPos; data5.pop(yPos);
int32 params; data5.pop(params);
_offGridObjects.insertLast(_offgridObject(xPos, yPos, params));
uint8 eventID = params;
if (eventID == OBJECT::GENERATOR) eventID = params >> 12;
if (animSetsToLoad[eventID] != 0) {{
jjOBJ@ preset = jjObjectPresets[eventID];
if (preset.curAnim < 100) {{
preset.curFrame = jjAnimations[preset.determineCurAnim(animSetsToLoad[eventID], preset.curAnim)] + preset.frameID;
if ((eventID >= OBJECT::FRUITPLATFORM && eventID <= OBJECT::SPIKEBOLL3D) || eventID == OBJECT::WITCH)
preset.killAnim += jjAnimSets[animSetsToLoad[eventID]];
else if (eventID == OBJECT::CATERPILLAR && jjObjectPresets[OBJECT::SMOKERING].curAnim < 100)
jjObjectPresets[OBJECT::SMOKERING].determineCurAnim(ANIM::CATERPIL, jjObjectPresets[OBJECT::SMOKERING].curAnim);
}}
animSetsToLoad[eventID] = 0;
}}
}} while (--numberOfObjects != 0);
}}
if (!data5.isEmpty()) {{
jjDebug('MLLE::Setup: Warning, Data5 longer than expected');
}}
return true;
}}
jjLAYER@ GetLayer(const string &in name) {{
jjLAYER@ handle = null;
_layers.get(name, @handle);
return handle;
}}
uint8 GetPaletteMappingID(const string &in name) {{
uint8 mappingID;
_palettes.get(name, mappingID);
return mappingID;
}}
jjPAL@ GetPalette(const string &in name) {{
if (name == 'Level Palette')
return Palette;
return jjSpriteModeGetColorMapping(GetPaletteMappingID(name));
}}
void ReapplyPalette() {{
Palette.apply();
}}
class AmmoCrate : jjBEHAVIORINTERFACE {{
uint8 realEventID;
AmmoCrate(uint8 r) {{ realEventID = r; }}
bool onIsSolid(jjOBJ@) {{ return true; }}
void onBehave(jjOBJ@ obj) {{
if (obj.state == STATE::DEACTIVATE)
obj.eventID = realEventID;
obj.behave(BEHAVIOR::AMMO15);
}}
}}
void SpawnOffgrids() {{
if (jjGameConnection == GAME::LOCAL) {{
SpawnOffgridsLocal();
for (int y = 0; y < jjLayerHeight[4]; ++y)
for (int x = 0; x < jjLayerWidth[4]; ++x) {{
const int ev = jjParameterGet(x,y, -12,32);
if (ev == 0)
return;
else if (ev == int(0xFFFFF3FE))
jjParameterSet(x,y, -12,32, 0);
}}
}} else {{
for (uint i = 0; i < _offGridObjects.length; ++i) {{
const auto params = _offGridObjects[i].params;
uint8 eventID = params;
if (eventID == OBJECT::GENERATOR || eventID == OBJECT::GUNCRATE || eventID == OBJECT::CARROTCRATE || eventID == OBJECT::ONEUPCRATE || eventID == OBJECT::BOMBCRATE || eventID == OBJECT::SPRINGCRATE)
eventID = params >> 12;
if ((eventID >= OBJECT::APPLE && eventID <= OBJECT::STRAWBERRY) || (eventID >= OBJECT::LEMON && eventID <= OBJECT::CHEESE)) {{
jjSugarRushAllowed = true;
}} else switch (eventID) {{
case OBJECT::BOUNCERAMMO3:
case OBJECT::BOUNCERAMMO15:
case OBJECT::GUNCRATE:
case OBJECT::GUNBARREL:
jjWeapons[WEAPON::BOUNCER].allowed = true;
break;
case OBJECT::ICEAMMO3:
case OBJECT::ICEAMMO15:
jjWeapons[WEAPON::ICE].allowed = true;
break;
case OBJECT::SEEKERAMMO3:
case OBJECT::RFAMMO3:
case OBJECT::TOASTERAMMO3:
case OBJECT::TNTAMMO3:
case OBJECT::GUN8AMMO3:
case OBJECT::GUN9AMMO3:
jjWeapons[eventID - 31].allowed = true;
break;
case OBJECT::SEEKERAMMO15:
case OBJECT::RFAMMO15:
case OBJECT::TOASTERAMMO15:
jjWeapons[eventID - 51].allowed = true;
break;
case OBJECT::BLASTERPOWERUP:
case OBJECT::BOUNCERPOWERUP:
case OBJECT::ICEPOWERUP:
case OBJECT::SEEKERPOWERUP:
case OBJECT::RFPOWERUP:
case OBJECT::TOASTERPOWERUP: {{
const auto weaponID = eventID - 130;
jjWeapons[weaponID].allowed = jjWeapons[weaponID].allowedPowerup = true;
break; }}
case OBJECT::TNTPOWERUP:
case OBJECT::GUN8POWERUP:
case OBJECT::GUN9POWERUP: {{
const auto weaponID = eventID - 212;
jjWeapons[weaponID].allowed = jjWeapons[weaponID].allowedPowerup = true;
break; }}
}}
}}
}}
}}
void SpawnOffgridsLocal() {{
for (uint i = 0; i < _offGridObjects.length; ++i)
_spawnOffgrid(i);
}}
class _offgridObject {{
float xPos, yPos;
int32 params;
_offgridObject() {{}}
_offgridObject(uint16 x, uint16 y, int32 p) {{ xPos = x; yPos = y; params = p; }}
}}
void _spawnOffgrid(uint i) {{
const _offgridObject@ og = _offGridObjects[i];
const int difficulty = og.params & 0x300;
if (difficulty != 0 && (jjGameMode == GAME::SP || jjGameMode == GAME::COOP || jjGameConnection == GAME::LOCAL)) {{
if (difficulty == 0x100) {{
if (jjDifficulty > 0)
return;
}} else if (difficulty == 0x200) {{
if (jjDifficulty < 2)
return;
}} else {{
if (jjGameConnection == GAME::LOCAL && jjLocalPlayerCount == 1)
return;
}}
}}
const uint xTile = uint(og.xPos) >> 5, yTile = uint(og.yPos) >> 5;
const uint8 eventID = og.params;
if ((eventID <= 32 || eventID == AREA::SUCKERTUBE || eventID == AREA::WATERBLOCK || eventID == AREA::WARPTARGET || eventID == AREA::PATH || eventID == OBJECT::CTFBASE || eventID == AREA::NOFIREZONE || eventID == AREA::TRIGGERZONE || eventID == AREA::TEXT || eventID == AREA::WATERLEVEL || eventID == AREA::MORPHFROG || eventID == 255) && cast<jjVOIDFUNCOBJ>(jjObjectPresets[eventID].behavior) is null) {{
jjDebug('MLLE::Setup: Warning, Event #' + eventID + ' (at ' + xTile + ',' + yTile + ') should not be placed off-grid.');
}} else {{
const int realEvent = jjParameterGet(xTile,yTile, -12,32);
jjParameterSet(xTile,yTile, -12,32, og.params);
jjOBJ@ obj = jjObjects[jjAddObject(eventID, og.xPos, og.yPos, 0, CREATOR::LEVEL)];
jjParameterSet(xTile,yTile, -12,32, realEvent);
if (jjGameConnection == GAME::LOCAL) {{
obj.deactivates = false;
obj.creatorID = 1;
}}
}}
}}
uint _replaceMeIndex = 0;
void _replaceMe(jjOBJ@ obj) {{
jjParameterSet(uint(obj.xOrg)>>5, uint(obj.yOrg)>>5, -12,32, 0);
obj.delete();
_spawnOffgrid(_replaceMeIndex++);
}}
jjPALCOLOR _colorFromArgb(uint Argb) {{
return jjPALCOLOR(Argb >> 16, Argb >> 8, Argb >> 0);
}}
void _readPalette(jjSTREAM& stream, jjPAL& palette) {{
for (uint i = 0; i < 256; ++i) {{
stream.pop(palette.color[i].red);
stream.pop(palette.color[i].green);
stream.pop(palette.color[i].blue);
}}
}}
void _readImage(jjSTREAM& stream, jjPIXELMAP& image) {{
for (uint y = 0; y < image.height; ++y)
for (uint x = 0; x < image.width; ++x)
stream.pop(image[x,y]);
}}
void _readImage(jjSTREAM& stream, jjCOLORMAP& image) {{
for (uint y = 0; y < image.height; ++y)
for (uint x = 0; x < image.width; ++x)
for (uint c = 0; c < 4; ++c)
stream.pop(image[x,y].component[COLOR::Component(c)]);
}}
uint _read7BitEncodedUintFromStream(jjSTREAM& stream) {{
uint result = 0;
while (true) {{
uint8 byteRead; stream.pop(byteRead);
result |= (byteRead & 0x7F);
if (byteRead >= 0x80)
result <<= 7;
else
break;
}}
return result;
}}
string _read7BitEncodedStringFromStream(jjSTREAM& stream) {{
string result;
stream.get(result, _read7BitEncodedUintFromStream(stream));
return result;
}}
void _recolorAnimationIf(jjSTREAM& stream, ANIM::Set set, uint animID, uint frameCount) {{
bool pbool; stream.pop(pbool); if (!pbool) return;
if (jjAnimSets[set] == 0)
jjAnimSets[set].load();
const uint firstFrameID = jjAnimations[jjAnimSets[set] + animID];
array<uint8> colors(256);
for (uint i = 0; i < 256; ++i)
stream.pop(colors[i]);
for (uint i = 0; i < frameCount; ++i) {{
jjANIMFRAME@ frame = jjAnimFrames[firstFrameID + i];
jjPIXELMAP(frame).recolor(colors).save(frame);
}}
}}
}}{4}";
const string AngelscriptLibraryWeaponsPortion1 = @"
se::WeaponHook@ WeaponHook;";
const string AngelscriptLibraryWeaponsPortion2 = "array<MLLEWeaponApply@> w";
const string AngelscriptLibraryWeaponsPortion3 = @"if (pbool) {
if (WeaponHook is null)
@WeaponHook = pshort < 0 ? se::DefaultWeaponHook() : se::DefaultWeaponHook(pshort);
_read7BitEncodedStringFromStream(data5);
jjSTREAM param;
data5.pop(param);
w[i-1].Apply(i, WeaponHook, param, ammoCrateEventID);
} else ";
const string AngelscriptLibraryWeaponsPortion4 = @"
#include 'SEweapon.asc'
#pragma require 'SEweapon.asc'
shared interface MLLEWeaponApply { bool Apply(uint, se::WeaponHook@ = null, jjSTREAM@ = null, uint8 = 0); }";
static readonly internal string TagForProgrammaticallyAddedLines = " ///@MLLE-Generated\r\n";
static string GetPragmaInclude(string filename)
{
return "#include \"" + filename + "\"";
}
static string GetPragmaRequire(string filename)
{
return "#pragma require \"" + filename + "\"";
}
public static string GetExtraDataLevelFilepath(string filepath, int index)
{
return Path.Combine(Path.GetDirectoryName(filepath), Path.GetFileNameWithoutExtension(filepath) + "-MLLE-Data-" + (index + 1) + ".j2l");
}
internal void SaveLibrary(ref string fileContents, string filepath, List<J2TFile> Tilesets, int numberOfExtraDataLevels, WeaponsForm.ExtendedWeapon[] customWeapons)
{
var encoding = J2LFile.FileEncoding;
List<string> RequiredFilenames = new List<string>();
bool weaponLibrary = false;
foreach (var cw in customWeapons)
if (cw != null) {
RequiredFilenames.Add(cw.LibraryFilename);
weaponLibrary = true;
}
string AngelscriptLibraryFilename = "MLLE-Include-" + CurrentMLLEData5VersionString + (!weaponLibrary ? "" : "w") + ".asc";
using (BinaryWriter binwriter = new BinaryWriter(File.Open(Path.Combine(Path.GetDirectoryName(filepath), AngelscriptLibraryFilename), FileMode.Create, FileAccess.Write), encoding)) {
binwriter.Write(encoding.GetBytes("//"));
var libraryFileAsBytes = encoding.GetBytes(string.Format(
AngelscriptLibrary,
AngelscriptLibraryFilename,
!weaponLibrary ? "" : AngelscriptLibraryWeaponsPortion1,
!weaponLibrary ? "" : AngelscriptLibraryWeaponsPortion2,
!weaponLibrary ? "" : AngelscriptLibraryWeaponsPortion3,
!weaponLibrary ? "" : AngelscriptLibraryWeaponsPortion4
));
CRC32 CRCCalculator = new CRC32();
CRCCalculator.SlurpBlock(libraryFileAsBytes, 0, libraryFileAsBytes.Length);
binwriter.Write(encoding.GetBytes(((uint)CRCCalculator.Crc32Result).ToString() + "\r\n"));
binwriter.Write(libraryFileAsBytes);
}
RequiredFilenames.Add(Path.ChangeExtension(Path.GetFileName(filepath), ".j2l"));
for (int i = 1; i < Tilesets.Count; ++i)
RequiredFilenames.Add(Tilesets[i].FilenameOnly);
int extraDataLevelID = 0;
for (extraDataLevelID = 0; extraDataLevelID < numberOfExtraDataLevels; ++extraDataLevelID)
RequiredFilenames.Add(Path.GetFileName(GetExtraDataLevelFilepath(filepath, extraDataLevelID)));
foreach (string fn in RequiredFilenames)
{
string pragma = GetPragmaRequire(fn);
if (!fileContents.Contains(pragma))
fileContents = pragma + TagForProgrammaticallyAddedLines + fileContents;
if (fn.EndsWith("asc", System.StringComparison.InvariantCultureIgnoreCase))
{
pragma = GetPragmaInclude(fn);
if (!fileContents.Contains(pragma))
fileContents = pragma + TagForProgrammaticallyAddedLines + fileContents;
}
}
while (true) //remove extra such pragmas/files if the number of layers has decreased since the last time this level was saved
{
string extraFilepath = GetExtraDataLevelFilepath(filepath, extraDataLevelID++);
File.Delete(extraFilepath);
string pragma = GetPragmaRequire(Path.GetFileName(extraFilepath));
if (fileContents.Contains(pragma))
fileContents = new Regex("^[^\\n]*" + pragma + "\\s*?\\r?\\n?", RegexOptions.Multiline).Replace(fileContents, "");
else
break;
}
fileContents = "#include \"" + AngelscriptLibraryFilename + "\"" + TagForProgrammaticallyAddedLines + fileContents;
Regex setupPattern = new Regex(@"MLLE\s*::\s*Setup\s*\([^;]*\)\s*;");
string desiredSetupCall = "MLLE::Setup(";
if (weaponLibrary)
{
desiredSetupCall += "array<MLLEWeaponApply@> = {";
for (int i = 0; i < 9; ++i)
{
WeaponsForm.ExtendedWeapon cw = customWeapons[i];
if (cw != null)
desiredSetupCall += cw.Initialization;
else
desiredSetupCall += "null";
if (i < 8)
desiredSetupCall += ", ";
}
desiredSetupCall += "}";
}
desiredSetupCall += ");";
Match match = setupPattern.Match(fileContents);
if (!match.Success)
fileContents = "const bool MLLESetupSuccessful = " + desiredSetupCall + TagForProgrammaticallyAddedLines + fileContents;
else if (match.Value != desiredSetupCall)
fileContents = setupPattern.Replace(fileContents, desiredSetupCall);
bool[] hooksNeeded = IncludeHookSpecs.Select(ss => weaponLibrary && ss.WeaponhookMethod && customWeapons.Any(cw => cw != null && ss.WeaponIniHookIdentifier.Match(cw.Hooks).Success)).ToArray();
hooksNeeded[3] = weaponLibrary; //onDrawAmmo is used by ALL custom weapons
hooksNeeded[5] = (Palette != null) && ReapplyPalette;
hooksNeeded[6] = hooksNeeded[7] = OffGridObjects.Count > 0;
for (int specID = 0; specID < IncludeHookSpecs.Length; ++specID)
IncludeHookSpecs[specID].Process(ref fileContents, hooksNeeded[specID]);
}
internal class Spec
{
readonly internal bool WeaponhookMethod;
readonly bool LastCallFromThisHook;
internal readonly Regex WeaponIniHookIdentifier;
readonly string IncludeCall; //e.g. "MLLE::WeaponHook::processMain();"
readonly string AddEntireHook; //e.g. "void onMain() { WeaponHook::processMain(); }" (but with newlines instead of some spaces)
readonly Regex IncludeCallFind; //e.g. a pattern to match "MLLE::WeaponHook::processMain();"
readonly Regex EnclosingFunctionStart; //e.g. a pattern to match "void onMain() {"
readonly Regex EnclosingFunctionEmpty; //e.g. a pattern to match "void onMain() {}"
internal Spec(string[] components, bool w = true, bool l = true)
{
WeaponhookMethod = w;
LastCallFromThisHook = l;
if (WeaponhookMethod)
WeaponIniHookIdentifier = new Regex("\\b" + components[1] + "\\b", RegexOptions.IgnoreCase);
string returnType = components[0];
string hookName = components[1];
string includeName = components[2];
string[] parameters = components.Skip(3).ToArray();
IncludeCallFind = new Regex(@"(return\s+)?MLLE\s*::\s*" + (WeaponhookMethod ? @"WeaponHook\s*\.\s*" : "") + includeName + @"\s*\([^;]*\)(\s*;)?");
IncludeCall = "\r\n\t" + (returnType == "void" ? "" : "return ") + "MLLE::" + (WeaponhookMethod ? "WeaponHook." : "") + includeName + "(";
for (int paramStringID = 0; paramStringID < parameters.Length; paramStringID += 2)
{
IncludeCall += "$" + (paramStringID / 2 + 2).ToString();
if (paramStringID + 2 < parameters.Length)
IncludeCall += ", ";
}
IncludeCall += ");";
string includeCallWithDefaultParameterNames = IncludeCall;
AddEntireHook = "\r\n" + returnType + " " + hookName + "(";
for (int paramStringID = 0; paramStringID < parameters.Length; paramStringID += 2)
{
AddEntireHook += parameters[paramStringID].Replace(" ", "") + " " + parameters[paramStringID + 1];
includeCallWithDefaultParameterNames = includeCallWithDefaultParameterNames.Replace("$" + (paramStringID / 2 + 2).ToString(), parameters[paramStringID + 1]);
if (paramStringID + 2 < parameters.Length)
AddEntireHook += ", ";
}
AddEntireHook += ") {" + includeCallWithDefaultParameterNames + "\r\n}\r\n";
string functionPattern = "(" + returnType + @"\s+" + hookName + @"\s*\(\s*";
for (int paramStringID = 0; paramStringID < parameters.Length; paramStringID += 2)
{
functionPattern += parameters[paramStringID].Replace(" ", @"\s*") + @"\s*(\S+)\s*";
if (paramStringID + 2 < parameters.Length)
functionPattern += @",\s*";
}
functionPattern += @"\)[^{]*{)";
EnclosingFunctionStart = new Regex(functionPattern);
EnclosingFunctionEmpty = new Regex(functionPattern + @"[\s;]*}\r?\n?");
}
internal void Process(ref string fileContents, bool needed)
{
if (needed) {
if (!IncludeCallFind.Match(fileContents).Success) { //include library call not being made
if (EnclosingFunctionStart.Match(fileContents).Success) //hook function already exists
fileContents = EnclosingFunctionStart.Replace(fileContents, "$1" + IncludeCall);
else //add everything from scratch
fileContents += AddEntireHook;
} //else it's already being made, the script is fine already, don't change anything
} else {
fileContents = IncludeCallFind.Replace(fileContents, ""); //remove the method call
if (LastCallFromThisHook)
fileContents = EnclosingFunctionEmpty.Replace(fileContents, ""); //then remove the hook function it was in if that hook is now totally empty
}
}
}
private static readonly Spec[] IncludeHookSpecs = {
new Spec(new string[]{"void", "onMain", "processMain"}),
new Spec(new string[]{"void", "onPlayer", "processPlayer", "jjPLAYER @", "player"}),
new Spec(new string[]{"void", "onPlayerInput", "processPlayerInput", "jjPLAYER @", "player"}),
new Spec(new string[]{"bool", "onDrawAmmo", "drawAmmo", "jjPLAYER @", "player", "jjCANVAS @", "canvas"}),
new Spec(new string[]{"void", "onReceive", "processPacket", "jjSTREAM & in", "packet", "int", "fromClientID" }),
new Spec(new string[]{"void", "onLevelReload", "ReapplyPalette"}, false, false),
new Spec(new string[]{"void", "onLevelBegin", "SpawnOffgrids"}, false),
new Spec(new string[]{"void", "onLevelReload", "SpawnOffgridsLocal"}, false)
};
public static void RemovePriorReferencesToMLLELibrary(ref string fileContents)
{
fileContents = new Regex(
"^[^\\n]*(" +
"///@MLLE-Generated" + //get rid of all lines that end in the "///@MLLE-Generated" tag
"|" +
"///@SaveAndRunArgs" + //older versions before 2.18
"|" +
"#include\\s+['\"]MLLE-Include-\\d+\\.\\d+\\.asc['\"]" + //get rid of existing #include calls to MLLE-Include, especially if they referenced older/newer versions of the file
")[^\\n]*\\r?\\n?", RegexOptions.Multiline | RegexOptions.IgnoreCase).Replace(fileContents, "");
}
}
}