Repository navigation
Expand file tree
/
Copy pathBioMod.csx
More file actions
2224 lines (2000 loc) · 73.5 KB
/
Copy pathBioMod.csx
File metadata and controls
2224 lines (2000 loc) · 73.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Script by BioTomateDE for UndertaleModTool v0.9
// SPDX-License-Identifier: GPL-3.0-only
// NOTE: Still in early development. Use with caution.
using static UndertaleModLib.Models.UndertaleGameObject;
using static UndertaleModLib.Models.EventSubtypeKey;
// ==================== CONFIG ====================
double BG_OPACITY = 0.6; // 0.0 - 1.0
double UI_SCALE = 1.0; // 0.4 - 2.0
int RAINBOWNESS = 150; // 0 - 255
int RAINBOW_SPEED = 30; // 1 - 200
int SPEEDHACK_SLOW_FPS = 10; // 1 - 30
int SPEEDHACK_FAST_FPS = 150; // 30 - 1000
// Gets rid of some crashes and shows more useful information when using the mod.
// (This does not modify any behavior for playing the game normally.)
// Disabling this may show confusing/useless information that more closely mimics what the vanilla game actually does.
bool FIX = true;
// These keys can be any EventSubtypeKey.
// https://github.com/UnderminersTeam/UndertaleModTool/blob/stable-0.9/UndertaleModLib/Models/UndertaleGameObject.cs?plain=1#L793-L1165
var HELP_KEY = vk_f1; // Shows keybinds and what they do
var SHOW_INFO_KEY = I; // Shows miscellaneous info in the top-left
var SHOW_HITBOXES_KEY = H; // Shows bounding boxes of Frisk, Solids, Interactables, Event Triggers
var NOCLIP_KEY = N; // Makes you able to walk through walls and objects
var MOVE_FREE_KEY = M; // Makes you able to walk during cutscenes/dialogue and allows you to open your menu
var PREVIOUS_ROOM_KEY = J; // Jumps to the previous room
var NEXT_ROOM_KEY = K; // Jumps to the next room
var MASH_TEXT_KEY = V; // Skips dialogue as fast as possible when held down
var ROOM_SWITCHER_KEY = R; // Opens an interface where you can type in room IDs/names to teleport to
var BATTLE_SELECTOR_KEY = B; // Opens an interface where you can type in battlegroup IDs/names to fight
var SPEEDHACK_SLOW_KEY = G; // Decreases the game speed to SPEEDHACK_SLOW_FPS frames per second
var SPEEDHACK_FAST_KEY = F; // Increases the game speed to SPEEDHACK_FAST_FPS frames per second
var GET_PUNCHCARD_KEY = P; // Gives you a punchcard in the first inventory slot
var CANCEL_KEY = E; // Stops an encounter or battle immediately, skips the intro, skips gameover
var STOP_AUDIO_KEY = A; // Stops all currently playing music and sounds
var PRECISION_KEY = vk_f2; // Makes you move one pixel per frame (useful for debugging)
// ================================================
const string MOD_VERSION = "0";
const string MAGIC = "$$biomod";
const string WATERMARK = MAGIC + MOD_VERSION;
EnsureDataLoaded();
if (CheckAlreadyPatched()) return;
UndertaleString watermark = Data.Strings.MakeString(WATERMARK + "_BROKEN");
Dictionary<string, (int, UndertaleGameObject)> ObjectMap = new();
MapObjects();
var utVer = DetectUndertaleVersion();
Console.WriteLine("Detected Undertale v" + utVer);
CodeImportGroup importGroup = new(Data)
{
ThrowOnNoOpFindReplace = true,
MainThreadAction = MainThreadAction,
};
List<(string, string)> Macros = new();
MakeMacro("MOD_VERSION", '"' + MOD_VERSION + '"');
MakeMacro("FIX", FIX);
MakeMacro("BG_OPACITY", BG_OPACITY, 0.0, 1.0);
MakeMacro("UI_SCALE", UI_SCALE, 0.4, 2.0);
MakeMacro("SCREEN_WIDTH", 640d / UI_SCALE);
MakeMacro("SCREEN_HEIGHT", 480d / UI_SCALE);
MakeMacro("RAINBOWNESS", RAINBOWNESS, 0, 255);
MakeMacro("RAINBOW_SPEED", RAINBOW_SPEED, 1, 200);
MakeMacro("SPEEDHACK_SLOW_FPS", SPEEDHACK_SLOW_FPS, 1, 30);
MakeMacro("SPEEDHACK_FAST_FPS", SPEEDHACK_FAST_FPS, 30, 1000);
MakeKeyMacro("HELP", HELP_KEY);
MakeKeyMacro("INFO", SHOW_INFO_KEY);
MakeKeyMacro("HITBOXES", SHOW_HITBOXES_KEY);
MakeKeyMacro("NOCLIP", NOCLIP_KEY);
MakeKeyMacro("FREEMOVE", MOVE_FREE_KEY);
MakeKeyMacro("ROOM_PREV", PREVIOUS_ROOM_KEY);
MakeKeyMacro("ROOM_NEXT", NEXT_ROOM_KEY);
MakeKeyMacro("ROOMSWITCHER", ROOM_SWITCHER_KEY);
MakeKeyMacro("BATTLESELECTOR", BATTLE_SELECTOR_KEY);
MakeKeyMacro("MASH", MASH_TEXT_KEY);
MakeKeyMacro("SPEEDHACK_SLOW", SPEEDHACK_SLOW_KEY);
MakeKeyMacro("SPEEDHACK_FAST", SPEEDHACK_FAST_KEY);
MakeKeyMacro("PUNCHCARD", GET_PUNCHCARD_KEY);
MakeKeyMacro("CANCEL", CANCEL_KEY);
MakeKeyMacro("STOPAUDIO", STOP_AUDIO_KEY);
MakeKeyMacro("PRECISION", PRECISION_KEY);
AppendCode(EventHandler("obj_time", EventSubtypeOther.GameStart), @"
display_set_gui_size(SCREEN_WIDTH, SCREEN_HEIGHT);
global._help = 0;
global._info = 1;
global._hitbox = 0;
global._noclip = 0;
global._mashing = 0;
global._movefree = 0;
global._precision = 0;
global._speedhack = 30;
global._thegame = 0;
global._savestateslot = 1;
global._toastmsg = '';
global._toasttimer = 0;
global._stepmin = 0;
global._stepmax = 0;
");
RegisterHotkey(SHOW_HITBOXES_KEY, "global._hitbox = !global._hitbox;", true);
RegisterHotkey(NOCLIP_KEY, "global._noclip = !global._noclip;", true);
RegisterHotkey(MOVE_FREE_KEY, @"
global.interact = 0;
global.flag[17] = 0;
global._movefree = 1;
", false, true);
RegisterHotkey(PREVIOUS_ROOM_KEY, @"
room_goto_previous();
global.interact = 0;
if (FIX) {
global.entrance = 0;
}
");
RegisterHotkey(NEXT_ROOM_KEY, @"
room_goto_next();
global.interact = 0;
if (FIX) {
global.entrance = 0;
}
");
RegisterHotkey(MASH_TEXT_KEY, @"
global._mashing = 1;
with (OBJ_WRITER) {
if (halt) {
event_user(0);
} else if (instance_exists(obj_dialoguer)) {
stringpos = string_length(originalstring);
}
}
", true, true);
RegisterHotkey(STOP_AUDIO_KEY, @"
audio_stop_all();
global._toastmsg = 'Stopped all audio';
global._toasttimer = 0.7;
", true);
RegisterHotkey(CANCEL_KEY, @"
if (room < room_area1 && file_exists('file0')) {
audio_stop_all();
global.filechoice = 0;
scr_load();
exit;
}
if (room == room_gameover) {
audio_stop_all();
room_goto(global.currentroom);
exit;
}
if (room == room_battle) {
if (global.flag[15] == 0) {
audio_stop_sound(global.batmusic);
}
room_goto(global.currentroom);
exit;
}
with (obj_battler) {
global.interact = 0;
instance_destroy();
audio_resume_sound(global.currentsong);
audio_sound_gain(global.currentsong, 1);
}
with (obj_battleblcon) {
global.interact = 0;
instance_destroy();
}
with (obj_tempblack) {
instance_destroy();
}
with (obj_transheart) {
instance_destroy();
}
// fixes SPARE button after fighting asgore
if (FIX) {
global.mercy = 0;
}
", true);
PrependCode(Data.Scripts.ByName("scr_textskip").Code, @"
if (global._mashing) {
with (OBJ_WRITER) {
stringpos = string_length(originalstring);
event_user(0);
}
exit;
}
");
RegisterHotkey(GET_PUNCHCARD_KEY, @"
#macro PUNCHCARD 26
if (global.item[0] == PUNCHCARD) {
global._toastmsg = 'Have fun!';
global._toasttimer = 1;
exit;
};
scr_itemremove(PUNCHCARD);
if (global.item[7]) {
global._toastmsg = 'No space!';
global._toasttimer = 2;
exit;
}
// shift all items up
for (var i = 7; i > 0; i--) {
global.item[i] = global.item[i-1];
}
snd_play(snd_item);
global.item[0] = PUNCHCARD;
global._toastmsg = 'Have fun!';
global._toasttimer = 1.5;
");
RegisterHotkey(SHOW_INFO_KEY, "if (++global._info > 2) global._info = 0;", true);
RegisterHotkey(HELP_KEY, @"
global._help = !global._help;
global._thegame = obj_time.time % 66 == 0;
", true);
ReplaceCode(EventHandler("obj_time", EventSubtypeOther.RoomStart), "room_speed = global._speedhack;");
RegisterHotkey(SPEEDHACK_FAST_KEY, @"
if (global._speedhack == SPEEDHACK_FAST_FPS) {
global._speedhack = 30;
room_speed = 30;
} else {
global._speedhack = SPEEDHACK_FAST_FPS;
room_speed = SPEEDHACK_FAST_FPS;
}
", true);
RegisterHotkey(SPEEDHACK_SLOW_KEY, @"
if (global._speedhack == SPEEDHACK_SLOW_FPS) {
global._speedhack = 30;
room_speed = 30;
} else {
global._speedhack = SPEEDHACK_SLOW_FPS;
room_speed = SPEEDHACK_SLOW_FPS;
}
", true);
RegisterHotkey(ROOM_SWITCHER_KEY, @"
instance_create(0, 0, obj_roomswitcher);
global._help = 0;
", true);
UndertaleGameObject obj_textinput = ImplTextInput();
UndertaleGameObject obj_roomswitcher = new()
{
Name = Data.Strings.MakeString("obj_roomswitcher"),
Visible = true,
Persistent = true,
ParentId = obj_textinput,
};
Data.GameObjects.Add(obj_roomswitcher);
ReplaceCode(EventHandler(obj_roomswitcher, EventType.KeyPress, vk_enter), @"
instance_destroy();
var room_index = scr_parse_room(text);
if (room_index) {
room_goto(room_index);
}
");
ReplaceCode(EventHandler(obj_roomswitcher, EventType.KeyPress, vk_tab), @"
if (sugglen < 1) exit;
var name = suggestions[suggidx];
text = name;
length = string_length(name);
cursor = length;
suggidx = 0;
");
UndertaleGameObject obj_battleselector = new()
{
Name = Data.Strings.MakeString("obj_battleselector"),
Visible = true,
Persistent = true,
ParentId = obj_textinput,
};
Data.GameObjects.Add(obj_battleselector);
ReplaceCode(EventHandler(obj_battleselector, EventType.KeyPress, vk_enter), @"
instance_destroy();
var bgroup = real(text);
if (scr_battlegroup_name(bgroup) != 'Unknown') {
global.battlegroup = bgroup;
room_goto(room_battle);
//instance_create(0, 0, obj_battler);
}
");
RegisterHotkey(BATTLE_SELECTOR_KEY, @"
instance_create(0, 0, obj_battleselector);
global._help = 0;
", true);
RegisterHotkey(PRECISION_KEY, @"global._precision = !global._precision;", true);
var movecode = EventHandler("obj_mainchara", EventSubtypeStep.Step);
FindReplaceCode(movecode, "x -= 2;", "x -= global._precision ? 1 : 2;");
FindReplaceCode(movecode, "x -= 3;", "x -= global._precision ? 1 : 3;");
FindReplaceCode(movecode, "x += 2;", "x += global._precision ? 1 : 2;");
FindReplaceCode(movecode, "y -= 3;", "y -= global._precision ? 1 : 3;");
FindReplaceCode(movecode, "x += 3;", "x += global._precision ? 1 : 3;");
FindReplaceCode(movecode, "y += 3;", "y += global._precision ? 1 : 3;");
var wallcode = CollisionHandler("obj_mainchara", "obj_solidparent");
FindReplaceCode(wallcode, "x -= 3;", "x -= global._precision ? 1 : 3;");
FindReplaceCode(wallcode, "y -= 3;", "y -= global._precision ? 1 : 3;");
FindReplaceCode(wallcode, "x += 3;", "x += global._precision ? 1 : 3;");
FindReplaceCode(wallcode, "y += 3;", "y += global._precision ? 1 : 3;");
foreach (var key in (EventSubtypeKey[])[vk_down, vk_right, vk_up, vk_left])
{
var code = EventHandler("obj_heart", EventType.Keyboard, (uint)key);
FindReplaceCode(code, "global.sp", "_speed");
PrependCode(code, "var _speed = global._precision ? 2 : global.sp;");
}
ReplaceCode(EventHandler("obj_time", EventSubtypeDraw.DrawGUIEnd), @"
scr_savestates(); // warning: this does more than draw
draw_set_halign(fa_left);
draw_set_font(fnt_maintext);
// Draw help
if (global._help) {
scr_draw_overlay('BioMod');
draw_text(xpost+8, y1+6, 'v' + MOD_VERSION);
if (global._thegame) {
draw_sprite(spr_skatebone, 0, x2 - 48, y1 - 1);
}
scr_draw_help_row(KEY_HELP, 'Shows this help lol');
scr_draw_help_row(KEY_ROOMSWITCHER, 'Opens an interface to teleport any room');
scr_draw_help_row(KEY_ROOM_PREV, 'Teleports you to the previous room');
scr_draw_help_row(KEY_ROOM_NEXT, 'Teleports you to the next room');
scr_draw_help_row(KEY_INFO, 'Shows miscellaneous info in the top left');
scr_draw_help_row(KEY_HITBOXES, 'Shows hitboxes of Frisk, walls, interactables and events');
scr_draw_help_row(KEY_NOCLIP, 'Allows you to move through walls and objects');
scr_draw_help_row(KEY_FREEMOVE, 'Allows you to move during cutscenes and enables the menu');
scr_draw_help_row(KEY_SPEEDHACK_SLOW, 'Slows the game down to ' + string(SPEEDHACK_SLOW_FPS) + ' FPS');
scr_draw_help_row(KEY_SPEEDHACK_FAST, 'Speeds the game up to ' + string(SPEEDHACK_FAST_FPS) + ' FPS');
scr_draw_help_row(KEY_MASH, 'Skips dialogue as fast as possible while held');
scr_draw_help_row(KEY_PUNCHCARD, 'Gives you a punchcard (needs menu and dialogue closed)');
scr_draw_help_row(KEY_CANCEL, 'Cancels battles, skips intro/gameover');
scr_draw_help_row(KEY_STOPAUDIO, 'Stops all currently playing music and sounds');
scr_draw_help_row(KEY_PRECISION, 'Limits your speed to 1 pixel per frame');
}
// Draw active modules in rainbow color in the top-right corner
row = 0;
if (global._speedhack != 30) {
scr_draw_module_text('Speedhack ' + string(global._speedhack / 30) + 'x');
}
if (global._hitbox) {
scr_draw_module_text('Hitboxes');
}
if (global._noclip) {
scr_draw_module_text('Noclip');
}
if (global._precision) {
scr_draw_module_text('Precise movement');
}
if (global._mashing) {
scr_draw_module_text('Mashing text');
}
if (global._movefree) {
scr_draw_module_text('Freeing movement');
}
// These variables are set in Keyboard events which are triggered every frame the key is held.
// This makes sure this variables doesn't stay true forever without a KeyRelease event.
global._mashing = 0;
global._movefree = 0;
// Draw Misc Info in the top-left corner
if (global._info) {
var verbose = global._info == 2;
draw_set_color(c_white);
row = 0;
if (room == room_battle) {
draw_text_row('Battle Group: ' + string(global.battlegroup) + ' (' + scr_battlegroup_name(global.battlegroup) + ')');
// in the asgore intro, the monster isnt really initialized yet
if (!FIX || global.battlegroup != 100) {
for (var i = 0; i < 3; i++) {
if (!global.monster[i]) continue;
if (verbose) {
var txt = 'Enemy ' + string(i+1) + ' (' + global.monstername[i] + '): ' + string(global.monsterhp[i]) + '/' + string(global.monstermaxhp[i]) + ' HP | ' + string(global.monsterdef[i]) + ' DF';
if (global.xpreward[i] && global.goldreward[i]) {
txt += ' | ' + string(global.xpreward[i]) + ' XP | ' + string(global.goldreward[i]) + ' G';
}
draw_text_row(txt);
} else {
draw_text_row('Enemy ' + string(i+1) + ': ' + string(global.monsterhp[i]) + '/' + string(global.monstermaxhp[i]) + ' HP');
}
}
}
if (global.mercy == 0) {
var txt = 'Flee Chance: ' + string(scr_fleechance()) + '%';
if (verbose && reason != '') { // set by scr_fleechance
txt += ' (' + reason + ')';
}
draw_text_row(txt);
}
draw_text_row('Turn: ' + string(global.turn));
if (verbose) {
draw_text_row('Attack: ' + string(global.at) + '+' + string(global.wstrength) + ' (' + scr_itemname_good(global.weapon) + ')');
draw_text_row('Defense: ' + string(global.df) + '+' + string(global.adef) + ' (' + scr_itemname_good(global.armor) + ')');
if (global.invc) {
draw_text_row('Invincibility: ' + string(global.invc) + '/' + string(global.inv));
}
} else {
draw_text_row('AT: ' + string(global.at+global.wstrength) + ' | DF: ' + string(global.df+global.adef));
}
var hoveritem = scr_hoveringitem();
if (hoveritem != -1) {
draw_text_row('Item Effect: ' + scr_itemstat(global.item[hoveritem]));
}
if (instance_exists(obj_targetchoice) || instance_exists(obj_targetchoicefist) || instance_exists(obj_shoetargettest)) {
var mindmg = scr_attackdamage(false);
var maxdmg = scr_attackdamage(true);
var avgdmg = round((mindmg + maxdmg) / 2);
draw_text_row('Attack Damage: ' + string(mindmg) + '-' + string(maxdmg) + ' (Avg: ' + string(avgdmg) + ')');
}
if (verbose && (FIX || global.mnfight)) {
draw_text_row('X: ' + string(obj_heart.x) + ', Y: ' + string(obj_heart.y));
}
} else {
if (verbose) {
draw_text_row('Frame: ' + string(time));
draw_text_row('Entrance: ' + string(global.entrance));
if (instance_exists(obj_mainchara)) {
draw_text_row('X: ' + string(obj_mainchara.x) + ', Y: ' + string(obj_mainchara.y));
} else {
draw_text_row('X: ?, Y: ?');
}
}
var route = scr_getroute(); // sets bool variable `genocide`
if (global.plot > 9) {
draw_text_row('Route: ' + route);
}
if (genocide) {
var areakills = scr_areakills(); // sets int variable `maxkills`
if (areakills != -1) {
draw_text_row('Kills: ' + string(areakills) + '/' + string(maxkills) + ' (' + string(global.kills) + ')');
}
}
draw_text_row('Room: ' + string(room) + ' (' + room_get_name(room) + ')');
if (instance_exists(obj_mainchara)) {
draw_text_row('Interact: ' + string(global.interact));
}
draw_text_row('Plot: ' + string(global.plot));
if (instance_exists(obj_encountererparent)) {
draw_text_row('Steps: ' + string(global.encounter) + '/' + string(floor(obj_encountererparent.steps)));
if (verbose) {
draw_text_row('Steps RNG: ' + string(global._stepmin) + '-' + string(global._stepmax) + ' (Avg: ' + string(floor((global._stepmax + global._stepmin) / 2)) + ')');
draw_text_row('Encounterer: ' + object_get_name(obj_encountererparent.object_index));
}
}
if (global.battlegroup) {
draw_text_row('Battle Group: ' + string(global.battlegroup) + ' (' + scr_battlegroup_name(global.battlegroup) + ')');
}
if (global.phasing) {
draw_text_row('Phasing');
}
if (global.flag[17]) {
draw_text_row('Menu Disabled');
}
// this prevents dozens of rows for the Three Switch Room Skip lol
if (!FIX || !instance_exists(obj_triswitchevent)) {
with (OBJ_WRITER) {
row = other.row;
draw_text_row('Textbox: ' + string(stringno+1) + '/' + string(scr_textbox_count(self)));
other.row = row;
}
}
if (verbose) {
var doortime = scr_doortimer();
if (doortime) {
draw_text_row('Door Timer: ' + string(doortime));
}
}
}
}
// draw toast popup thingy
if (global._toasttimer > 0) {
var alpha = 1;
if (global._toasttimer < 0.3 /*seconds*/) {
alpha = global._toasttimer / 0.3;
}
global._toasttimer -= 1/global._speedhack;
var width = string_width(global._toastmsg);
var tx1 = SCREEN_WIDTH/2 - width/2;
var tx2 = SCREEN_WIDTH/2 + width/2;
var ty1 = SCREEN_HEIGHT * 0.15;
var ty2 = ty1 + string_height(global._toastmsg);
draw_set_color(c_black)
draw_set_alpha(alpha * BG_OPACITY);
draw_rectangle(tx1 - 5, ty1, tx2 + 5, ty2, false);
draw_set_alpha(alpha);
draw_set_color(c_white);
draw_text(tx1, ty1, global._toastmsg);
draw_set_alpha(1);
}
with (obj_roomswitcher) {
scr_draw_overlay('Room Switcher');
if (!help) {
if (textprev != text) {
suggestions = scr_roomname_suggestions(text);
sugglen = array_length_1d(suggestions);
}
if (text == '') {
draw_set_color(c_silver);
draw_text(xx, yy, '> Enter Room Name or ID');
} else {
draw_set_color(c_gray);
if (sugglen) {
var suggestion = suggestions[suggidx];
var lower = string_lower(text);
if (string_starts_with(suggestion, lower)) {
suggestion = string_delete(suggestion, 1, length);
} else if string_starts_with(suggestion, 'room_' + lower) {
suggestion = string_delete(suggestion, 1, length+5); // delete 'room_' prefix
} else {
suggestion = '';
}
draw_text(xx + string_width('> ' + text), yy, suggestion);
}
draw_set_color(scr_parse_room(text) ? c_yellow : c_white);
draw_text(xx, yy, '> ' + text);
}
}
textinput_draw();
}
with (obj_battleselector) {
scr_draw_overlay('Battle Selector');
if (!help) {
if (text == '') {
draw_set_color(c_silver);
draw_text(xx, yy, '> Enter Battle Group ID');
} else {
// draw_set_color(c_gray);
// draw_text(xx, yy, '> ' + scr_complete_battlegroup(text));
//draw_set_color(scr_parse_battlegroup(text) ? c_yellow : c_white);
draw_set_color(c_white);
draw_text(xx, yy, '> ' + text);
}
}
textinput_draw();
}
// fix for soundtest gui
draw_set_font(fnt_main);
");
ReplaceCode(EventHandler("obj_mainchara", EventSubtypeDraw.DrawEnd), @"
if (!global._hitbox) exit;
// Draw default/wrongwarp position.
var xs = xstart;
var ys = ystart;
// this garbage logic is taken from gml_Object_obj_mainchara_Create_0
if (xs % 3 == 2) xs++;
if (xs % 3 == 1) xs--;
if (ys % 3 == 2) ys++;
if (ys % 3 == 1) ys--;
draw_set_color(c_orange);
draw_rectangle(xs, ys+19, xs+19, ys+29, true);
// Draw interact seeking box.
// (Coords taken from gml_Object_obj_mainchara_Other_10)
draw_set_color(c_red);
if (global.facing == 1 /* Right */) {
draw_rectangle(x+(sprite_width/2), y+19, x+sprite_width+15, y+sprite_height, true);
} else if (global.facing == 3 /* Left */) {
draw_rectangle(x+(sprite_width/2), y+19, x-15, y+sprite_height, true);
} else if (global.facing == 0 /* Down */) {
draw_rectangle(x+4, y+20, x+sprite_width-4, y+sprite_height+15, true);
} else if (global.facing == 2 /* Up */) {
draw_rectangle(x+4, y+sprite_height-5, x+sprite_width-4, y+8, true);
}
// Draw bounding box for next step.
draw_set_color(c_olive);
draw_set_alpha(0.6);
draw_rectangle(bbox_left-3, bbox_top-3, bbox_right+3, bbox_bottom+3, true);
draw_set_alpha(1);
// Draw bounding box.
draw_set_color(c_yellow);
draw_rectangle(bbox_left, bbox_top, bbox_right, bbox_bottom, true);
");
ReplaceCode(EventHandler("obj_heart", EventSubtypeDraw.DrawEnd), @"
if (!global._hitbox) exit;
draw_set_color(sprite_index == spr_heartyellow_flip ? c_red : c_yellow);
draw_rectangle(bbox_left, bbox_top, bbox_right, bbox_bottom, true);
");
ImplNoclip();
List<UndertaleGameObject> doors = new();
foreach (var obj in Data.GameObjects)
{
if (IsParent(obj, "obj_interactable"))
{
if (!obj.Visible) SuppressRendering(obj);
obj.Visible = true;
}
if (!IsVisible(obj) && FindFriskCollision(obj) is UndertaleCode code)
{
// Exclude empty events with just an Exit instruction.
if (code.Instructions.Count > 1)
{
ShowEvent(obj.Name.Content);
obj.Visible = true;
}
}
if (!obj.Visible && IsParent(obj, "obj_doorparent") && !obj.Name.Content.Contains("iceevent"))
{
doors.Add(obj);
SuppressRendering(obj);
obj.Visible = true;
}
// These objects are solid anyway due to mainchara collison code.
// This fixes noclip for these objects.
if (IsParent(obj, "obj_solidnpcparent"))
{
obj.Solid = false;
}
if (IsParent(obj, "obj_solidparent"))
{
obj.Solid = false;
if (obj.Visible)
{
ReplaceCode(EventHandler(obj, EventSubtypeDraw.Draw), "draw_self(); event_inherited();");
}
obj.Visible = true;
}
if (obj.Name.Content.StartsWith("obj_marker"))
{
obj.Visible = true;
ReplaceCode(EventHandler(obj, EventSubtypeDraw.Draw), @"
if (global._hitbox) {
draw_set_color(c_maroon);
draw_rectangle(bbox_left, bbox_top+19, bbox_left+19, bbox_top+29, true);
}
");
}
// TODO: fix noclip for these fuckass objects
//if (obj.Solid) Console.WriteLine($"{obj} still solid, parent is {obj.ParentId}");
// This fixes invisibility issues because obj_solidsmall
// will be patched to have an empty Draw event.
if (obj.ParentId == GetObject("obj_solidsmall"))
{
obj.ParentId = GetObject("obj_solidparent");
}
}
ReplaceCode(EventHandler("obj_interactable", EventSubtypeDraw.DrawEnd), @"
if (global._hitbox) {
draw_set_color(c_green);
draw_rectangle(bbox_left, bbox_top, bbox_right, bbox_bottom, true);
}
");
ReplaceCode(EventHandler("obj_solidnpcparent", EventSubtypeDraw.DrawEnd), @"
if (global._hitbox) {
draw_set_color(c_lime);
draw_rectangle(bbox_left, bbox_top, bbox_right, bbox_bottom, true);
}
");
ReplaceCode(EventHandler("obj_doorparent", EventSubtypeDraw.DrawEnd), @"
if (global._hitbox) {
draw_set_color(c_fuchsia);
draw_rectangle(bbox_left, bbox_top, bbox_right, bbox_bottom, true);
}
");
SuppressRendering("obj_doorparent");
ReplaceCode(EventHandler("obj_solidparent", EventSubtypeDraw.Draw), @"
if (global._hitbox) {
draw_set_color(c_blue);
draw_set_alpha(0.5);
draw_rectangle(bbox_left, bbox_top, bbox_right, bbox_bottom, false);
draw_set_alpha(1);
}
");
// TODO: are these still neeeded?
ShowEvent("obj_bouncetileparent", true);
GetObject("obj_holedown2").Visible = true;
GetObject("obj_holedown3").Visible = true;
GetObject("obj_iceevent").Visible = false;
GetObject("obj_inwaterspot").Visible = false;
ShowEvent("obj_teleigloo", true);
PrependCode(EventHandler("obj_dogetrigger1", EventSubtypeDraw.Draw), "if (sprite_index == spr_event) exit;");
PrependCode(EventHandler("obj_dogringbell", EventSubtypeDraw.Draw), "if (sprite_index == spr_event) exit;");
string[] slopes = ["obj_sul", "obj_sur", "obj_sdl", "obj_sdr"];
foreach (var objName in slopes)
{
var obj = GetObject(objName);
obj.Visible = true;
ReplaceCode(EventHandler(obj, EventSubtypeStep.Step), "visible = global._hitbox");
}
///////////////////////// scripts
MakeScript("scr_savestates", @"
if (instance_exists(obj_essaystuff) || instance_exists(obj_textinput)) exit;
// number-row digit keys can select slots
for (var i = 0; i <= 9; i++) {
if keyboard_check_pressed(i + 48) {
global._savestateslot = i;
global._toastmsg = 'Selected slot ' + string(i);
global._toasttimer = 1;
break;
}
}
// Credit to Oceanbagel and Spinyspinr for the base functionality
if keyboard_check_pressed(ord('S')) {
global._toastmsg = 'Loaded slot ' + string(global._savestateslot);
global._toasttimer = 2.5;
directory_create('savestates');
// be very careful what the game state is before calling this function
game_save('savestates/' + string(global._savestateslot));
global._toastmsg = 'Saved slot ' + string(global._savestateslot);
}
else if keyboard_check_pressed(ord('L')) {
var file = 'savestates/' + string(global._savestateslot);
if (file_exists(file)) {
game_load(file);
}
else {
global._toastmsg = 'No save in slot ' + string(global._savestateslot);
global._toasttimer = 1.5;
}
}
");
MakeScript("scr_battlegroup_name", BattlegroupCode);
MakeScript("draw_text_row", @"
var yoff = (row == 0) ? -2 : 0;
var xx = 5;
var yy = 5 + 15 * (row++);
var color = draw_get_color();
var alpha = draw_get_alpha();
draw_set_color(c_black);
draw_set_alpha(BG_OPACITY);
draw_rectangle(xx-3, yy+yoff+2, xx+string_width(argument0)+2, yy+16, false);
draw_set_color(color);
draw_set_alpha(alpha);
draw_text(xx, yy, argument0);
");
MakeScript("draw_text_rainbow", @"
var xx = argument0;
var yy = argument1;
var strlen = string_length(argument2);
var oldcolor = draw_get_color();
for (var i = 1; i <= strlen; i++) {
var char = string_char_at(argument2, i);
var hue = (obj_time.time / global._speedhack * RAINBOW_SPEED) + xx + yy;
draw_set_color(make_color_hsv(hue % 255, RAINBOWNESS, 255));
draw_text(xx, yy, char);
xx += string_width(char);
}
draw_set_color(oldcolor);
return xx;
");
MakeScript("scr_draw_module_text", @"
var yoff = (row == 0) ? -2 : 0;
var w = string_width(argument0);
var xx = SCREEN_WIDTH - w - 5;
var yy = 5 + 15 * (row++);
var color = draw_get_color();
var alpha = draw_get_alpha();
draw_set_color(c_black);
draw_set_alpha(BG_OPACITY);
draw_rectangle(xx-3, yy+yoff+2, xx+w+2, yy+16, false);
draw_set_color(color);
draw_set_alpha(alpha);
draw_text_rainbow(xx, yy, argument0);
");
MakeScript("scr_draw_help_row", @"
draw_text_rainbow(xx, yy, argument0);
draw_text(xx + 25, yy, argument1);
yy += 15;
");
// TODO: return an array for ballet shoes/burnt pan
MakeScript("scr_attackdamage", @"
var variance = argument0 ? 2 : 0;
if (instance_exists(obj_shoetargettest)) {
var damage = global.wstrength + global.at - global.monsterdef[global.mytarget];
damage *= ((obj_shoetargettest.myscore / 160) * (4 / obj_shoetargettest.num));
return round(damage) + variance;
}
var damage = global.wstrength + global.at - global.monsterdef[global.mytarget] + variance;
var mult, myx;
if (instance_exists(obj_targetchoice)) {
myx = obj_targetchoice.x + (obj_targetchoice.sprite_width / 2);
mult = 2.2;
} else {
myx = obj_targetchoicefist.x + (obj_targetchoicefist.sprite_width / 2);
mult = 2.1;
}
var bonusfactor = abs(myx - obj_target.x - (obj_target.sprite_width / 2));
if (bonusfactor == 0) {
bonusfactor = 1;
}
if (bonusfactor > 12) {
return round(damage * 2 * (obj_target.sprite_width - bonusfactor) / obj_target.sprite_width);
} else {
return round(damage * mult);
}
");
MakeScript("scr_fleechance", @"
// Logic taken from gml_Script_scr_runaway
reason = '';
if (instance_exists(obj_undyneboss)) {
reason = 'Fighting Undyne';
return 100;
}
if (global.armor == 4 && !global.flag[6]) {
reason = 'Wearing Bandage';
return 100;
}
if (global.flag[6] && global.turn < 1) {
reason = 'Turn 1 in Hard Mode';
return 0;
}
// EVIL flag arithmetic hacking
// (flag 6 is hardmode; hardmode has one extra unfleeable turn)
return min(100, 50 + 10 * (global.turn - global.flag[6]));
");
MakeScript("scr_parse_room", @"
var idx = real(argument0);
if (idx && room_exists(idx)) {
return idx;
}
idx = asset_get_index(argument0);
if (room_exists(idx)) {
return idx;
}
idx = asset_get_index('room_' + argument0);
if (room_exists(idx)) {
return idx;
}
");
{
string src = "";
foreach (var door in doors)
{
src += "with (" + door.Name.Content + ") { if (touched) { return alarm[2]; }}";
}
src += "return -1";
MakeScript("scr_doortimer", src);
}
MakeScript("scr_textbox_count", @"
var len = array_length_1d(argument0.mystring);
for (var i = 0; i < len; i++) {
var s = argument0.mystring[i];
if (string_pos('/%', s) || string_pos('%%', s) || string_pos('\C', s)) {
return i + 1;
}
}
// hopefully never hit lol
");
MakeScript("scr_draw_overlay", @"
x1 = SCREEN_WIDTH * 0.2;
y1 = SCREEN_HEIGHT * 0.22;
x2 = SCREEN_WIDTH * 0.8;
y2 = SCREEN_HEIGHT * 0.78;
draw_set_color(c_black);
draw_set_alpha(BG_OPACITY);
draw_rectangle(x1-10, y1-10, x2+10, y2+10, false);
draw_set_alpha(1);
draw_set_font(fnt_main);
draw_set_halign(fa_left);
draw_text_rainbow(x1, y1-6, argument0);
xpost = x1 + string_width(argument0);
draw_set_color(c_white);
draw_set_font(fnt_maintext);
xx = x1;
yy = y1 + 30;
");
MakeScript("scr_roomname_suggestions", @"
// should return an empty array but whatever gms1 sucks
if (argument0 == '') exit;
var input = string_lower(argument0);
var suggestions = -1 /* empty array?? */;
var maybeid = real(input);
var idx = 0;
if (maybeid && room_exists(maybeid)) {
suggestions[0] = room_get_name(maybeid);
idx++;
}
for (var i = 0; room_exists(i); i++) {
var name = room_get_name(i);
if (string_starts_with(string_lower(name), input)) {
suggestions[idx++] = name;
}
}
for (var i = 0; room_exists(i); i++) {
var name = room_get_name(i);
if (string_starts_with(string_lower(name), 'room_' + input)) {
suggestions[idx++] = name;
}
}
return suggestions;
");
MakeScript("scr_getroute", @"
genocide = global.kills && global.plot < 18;
var soulless = file_exists('system_information_963');
if (global.kills == 0) {
return soulless ? 'Soulless Pacifist' : 'Pacifist';
}
if (murdererlv1()) {
var s = soulless ? 'Soulless Genocide' : 'Genocide';
// very useless special case where you kill everyone in snowdin except for snowdrake
if (global.flag[27] || (global.flag[203] >= 16 && global.flag[57] != 2)) {
s = 'Aborted ' + s;
} else {
genocide = 1;
}
s += ' (MLV ' + string(scr_murderlv()) + ')';
return s;
}