-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
scrcmd.c
2307 lines (1895 loc) · 55.5 KB
/
scrcmd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "global.h"
#include "frontier_util.h"
#include "battle_setup.h"
#include "berry.h"
#include "clock.h"
#include "coins.h"
#include "contest.h"
#include "contest_util.h"
#include "contest_painting.h"
#include "data.h"
#include "decoration.h"
#include "decoration_inventory.h"
#include "event_data.h"
#include "field_door.h"
#include "field_effect.h"
#include "event_object_lock.h"
#include "event_object_movement.h"
#include "field_message_box.h"
#include "field_player_avatar.h"
#include "field_screen_effect.h"
#include "field_specials.h"
#include "field_tasks.h"
#include "field_weather.h"
#include "fieldmap.h"
#include "item.h"
#include "lilycove_lady.h"
#include "main.h"
#include "menu.h"
#include "money.h"
#include "mystery_event_script.h"
#include "palette.h"
#include "party_menu.h"
#include "pokemon_storage_system.h"
#include "random.h"
#include "overworld.h"
#include "rotating_tile_puzzle.h"
#include "rtc.h"
#include "script.h"
#include "script_menu.h"
#include "script_movement.h"
#include "script_pokemon_util.h"
#include "shop.h"
#include "slot_machine.h"
#include "sound.h"
#include "string_util.h"
#include "text.h"
#include "text_window.h"
#include "trainer_see.h"
#include "tv.h"
#include "window.h"
#include "constants/event_objects.h"
typedef u16 (*SpecialFunc)(void);
typedef void (*NativeFunc)(void);
EWRAM_DATA const u8 *gRamScriptRetAddr = NULL;
static EWRAM_DATA u32 sAddressOffset = 0; // For relative addressing in vgoto etc., used by saved scripts (e.g. Mystery Event)
static EWRAM_DATA u16 sPauseCounter = 0;
static EWRAM_DATA u16 sMovingNpcId = 0;
static EWRAM_DATA u16 sMovingNpcMapGroup = 0;
static EWRAM_DATA u16 sMovingNpcMapNum = 0;
static EWRAM_DATA u16 sFieldEffectScriptId = 0;
static u8 sBrailleWindowId;
extern const SpecialFunc gSpecials[];
extern const u8 *gStdScripts[];
extern const u8 *gStdScripts_End[];
static void CloseBrailleWindow(void);
// This is defined in here so the optimizer can't see its value when compiling
// script.c.
void * const gNullScriptPtr = NULL;
static const u8 sScriptConditionTable[6][3] =
{
// < = >
{1, 0, 0}, // <
{0, 1, 0}, // =
{0, 0, 1}, // >
{1, 1, 0}, // <=
{0, 1, 1}, // >=
{1, 0, 1}, // !=
};
static u8 * const sScriptStringVars[] =
{
gStringVar1,
gStringVar2,
gStringVar3,
};
bool8 ScrCmd_nop(struct ScriptContext *ctx)
{
return FALSE;
}
bool8 ScrCmd_nop1(struct ScriptContext *ctx)
{
return FALSE;
}
bool8 ScrCmd_end(struct ScriptContext *ctx)
{
StopScript(ctx);
return FALSE;
}
bool8 ScrCmd_gotonative(struct ScriptContext *ctx)
{
bool8 (*addr)(void) = (bool8 (*)(void))ScriptReadWord(ctx);
SetupNativeScript(ctx, addr);
return TRUE;
}
bool8 ScrCmd_special(struct ScriptContext *ctx)
{
u16 index = ScriptReadHalfword(ctx);
gSpecials[index]();
return FALSE;
}
bool8 ScrCmd_specialvar(struct ScriptContext *ctx)
{
u16 *var = GetVarPointer(ScriptReadHalfword(ctx));
*var = gSpecials[ScriptReadHalfword(ctx)]();
return FALSE;
}
bool8 ScrCmd_callnative(struct ScriptContext *ctx)
{
NativeFunc func = (NativeFunc)ScriptReadWord(ctx);
func();
return FALSE;
}
bool8 ScrCmd_waitstate(struct ScriptContext *ctx)
{
ScriptContext_Stop();
return TRUE;
}
bool8 ScrCmd_goto(struct ScriptContext *ctx)
{
const u8 *ptr = (const u8 *)ScriptReadWord(ctx);
ScriptJump(ctx, ptr);
return FALSE;
}
bool8 ScrCmd_return(struct ScriptContext *ctx)
{
ScriptReturn(ctx);
return FALSE;
}
bool8 ScrCmd_call(struct ScriptContext *ctx)
{
const u8 *ptr = (const u8 *)ScriptReadWord(ctx);
ScriptCall(ctx, ptr);
return FALSE;
}
bool8 ScrCmd_goto_if(struct ScriptContext *ctx)
{
u8 condition = ScriptReadByte(ctx);
const u8 *ptr = (const u8 *)ScriptReadWord(ctx);
if (sScriptConditionTable[condition][ctx->comparisonResult] == 1)
ScriptJump(ctx, ptr);
return FALSE;
}
bool8 ScrCmd_call_if(struct ScriptContext *ctx)
{
u8 condition = ScriptReadByte(ctx);
const u8 *ptr = (const u8 *)ScriptReadWord(ctx);
if (sScriptConditionTable[condition][ctx->comparisonResult] == 1)
ScriptCall(ctx, ptr);
return FALSE;
}
bool8 ScrCmd_setvaddress(struct ScriptContext *ctx)
{
u32 addr1 = (u32)ctx->scriptPtr - 1;
u32 addr2 = ScriptReadWord(ctx);
sAddressOffset = addr2 - addr1;
return FALSE;
}
bool8 ScrCmd_vgoto(struct ScriptContext *ctx)
{
u32 addr = ScriptReadWord(ctx);
ScriptJump(ctx, (u8 *)(addr - sAddressOffset));
return FALSE;
}
bool8 ScrCmd_vcall(struct ScriptContext *ctx)
{
u32 addr = ScriptReadWord(ctx);
ScriptCall(ctx, (u8 *)(addr - sAddressOffset));
return FALSE;
}
bool8 ScrCmd_vgoto_if(struct ScriptContext *ctx)
{
u8 condition = ScriptReadByte(ctx);
const u8 *ptr = (const u8 *)(ScriptReadWord(ctx) - sAddressOffset);
if (sScriptConditionTable[condition][ctx->comparisonResult] == 1)
ScriptJump(ctx, ptr);
return FALSE;
}
bool8 ScrCmd_vcall_if(struct ScriptContext *ctx)
{
u8 condition = ScriptReadByte(ctx);
const u8 *ptr = (const u8 *)(ScriptReadWord(ctx) - sAddressOffset);
if (sScriptConditionTable[condition][ctx->comparisonResult] == 1)
ScriptCall(ctx, ptr);
return FALSE;
}
bool8 ScrCmd_gotostd(struct ScriptContext *ctx)
{
u8 index = ScriptReadByte(ctx);
const u8 **ptr = &gStdScripts[index];
if (ptr < gStdScripts_End)
ScriptJump(ctx, *ptr);
return FALSE;
}
bool8 ScrCmd_callstd(struct ScriptContext *ctx)
{
u8 index = ScriptReadByte(ctx);
const u8 **ptr = &gStdScripts[index];
if (ptr < gStdScripts_End)
ScriptCall(ctx, *ptr);
return FALSE;
}
bool8 ScrCmd_gotostd_if(struct ScriptContext *ctx)
{
u8 condition = ScriptReadByte(ctx);
u8 index = ScriptReadByte(ctx);
if (sScriptConditionTable[condition][ctx->comparisonResult] == 1)
{
const u8 **ptr = &gStdScripts[index];
if (ptr < gStdScripts_End)
ScriptJump(ctx, *ptr);
}
return FALSE;
}
bool8 ScrCmd_callstd_if(struct ScriptContext *ctx)
{
u8 condition = ScriptReadByte(ctx);
u8 index = ScriptReadByte(ctx);
if (sScriptConditionTable[condition][ctx->comparisonResult] == 1)
{
const u8 **ptr = &gStdScripts[index];
if (ptr < gStdScripts_End)
ScriptCall(ctx, *ptr);
}
return FALSE;
}
bool8 ScrCmd_returnram(struct ScriptContext *ctx)
{
ScriptJump(ctx, gRamScriptRetAddr);
return FALSE;
}
bool8 ScrCmd_endram(struct ScriptContext *ctx)
{
ClearRamScript();
StopScript(ctx);
return TRUE;
}
bool8 ScrCmd_setmysteryeventstatus(struct ScriptContext *ctx)
{
u8 status = ScriptReadByte(ctx);
SetMysteryEventScriptStatus(status);
return FALSE;
}
bool8 ScrCmd_loadword(struct ScriptContext *ctx)
{
u8 index = ScriptReadByte(ctx);
ctx->data[index] = ScriptReadWord(ctx);
return FALSE;
}
bool8 ScrCmd_loadbytefromptr(struct ScriptContext *ctx)
{
u8 index = ScriptReadByte(ctx);
ctx->data[index] = *(const u8 *)ScriptReadWord(ctx);
return FALSE;
}
bool8 ScrCmd_setptr(struct ScriptContext *ctx)
{
u8 value = ScriptReadByte(ctx);
*(u8 *)ScriptReadWord(ctx) = value;
return FALSE;
}
bool8 ScrCmd_loadbyte(struct ScriptContext *ctx)
{
u8 index = ScriptReadByte(ctx);
ctx->data[index] = ScriptReadByte(ctx);
return FALSE;
}
bool8 ScrCmd_setptrbyte(struct ScriptContext *ctx)
{
u8 index = ScriptReadByte(ctx);
*(u8 *)ScriptReadWord(ctx) = ctx->data[index];
return FALSE;
}
bool8 ScrCmd_copylocal(struct ScriptContext *ctx)
{
u8 destIndex = ScriptReadByte(ctx);
u8 srcIndex = ScriptReadByte(ctx);
ctx->data[destIndex] = ctx->data[srcIndex];
return FALSE;
}
bool8 ScrCmd_copybyte(struct ScriptContext *ctx)
{
u8 *ptr = (u8 *)ScriptReadWord(ctx);
*ptr = *(const u8 *)ScriptReadWord(ctx);
return FALSE;
}
bool8 ScrCmd_setvar(struct ScriptContext *ctx)
{
u16 *ptr = GetVarPointer(ScriptReadHalfword(ctx));
*ptr = ScriptReadHalfword(ctx);
return FALSE;
}
bool8 ScrCmd_copyvar(struct ScriptContext *ctx)
{
u16 *ptr = GetVarPointer(ScriptReadHalfword(ctx));
*ptr = *GetVarPointer(ScriptReadHalfword(ctx));
return FALSE;
}
bool8 ScrCmd_setorcopyvar(struct ScriptContext *ctx)
{
u16 *ptr = GetVarPointer(ScriptReadHalfword(ctx));
*ptr = VarGet(ScriptReadHalfword(ctx));
return FALSE;
}
u8 Compare(u16 a, u16 b)
{
if (a < b)
return 0;
if (a == b)
return 1;
return 2;
}
bool8 ScrCmd_compare_local_to_local(struct ScriptContext *ctx)
{
const u8 value1 = ctx->data[ScriptReadByte(ctx)];
const u8 value2 = ctx->data[ScriptReadByte(ctx)];
ctx->comparisonResult = Compare(value1, value2);
return FALSE;
}
bool8 ScrCmd_compare_local_to_value(struct ScriptContext *ctx)
{
const u8 value1 = ctx->data[ScriptReadByte(ctx)];
const u8 value2 = ScriptReadByte(ctx);
ctx->comparisonResult = Compare(value1, value2);
return FALSE;
}
bool8 ScrCmd_compare_local_to_ptr(struct ScriptContext *ctx)
{
const u8 value1 = ctx->data[ScriptReadByte(ctx)];
const u8 value2 = *(const u8 *)ScriptReadWord(ctx);
ctx->comparisonResult = Compare(value1, value2);
return FALSE;
}
bool8 ScrCmd_compare_ptr_to_local(struct ScriptContext *ctx)
{
const u8 value1 = *(const u8 *)ScriptReadWord(ctx);
const u8 value2 = ctx->data[ScriptReadByte(ctx)];
ctx->comparisonResult = Compare(value1, value2);
return FALSE;
}
bool8 ScrCmd_compare_ptr_to_value(struct ScriptContext *ctx)
{
const u8 value1 = *(const u8 *)ScriptReadWord(ctx);
const u8 value2 = ScriptReadByte(ctx);
ctx->comparisonResult = Compare(value1, value2);
return FALSE;
}
bool8 ScrCmd_compare_ptr_to_ptr(struct ScriptContext *ctx)
{
const u8 value1 = *(const u8 *)ScriptReadWord(ctx);
const u8 value2 = *(const u8 *)ScriptReadWord(ctx);
ctx->comparisonResult = Compare(value1, value2);
return FALSE;
}
bool8 ScrCmd_compare_var_to_value(struct ScriptContext *ctx)
{
const u16 value1 = *GetVarPointer(ScriptReadHalfword(ctx));
const u16 value2 = ScriptReadHalfword(ctx);
ctx->comparisonResult = Compare(value1, value2);
return FALSE;
}
bool8 ScrCmd_compare_var_to_var(struct ScriptContext *ctx)
{
const u16 *ptr1 = GetVarPointer(ScriptReadHalfword(ctx));
const u16 *ptr2 = GetVarPointer(ScriptReadHalfword(ctx));
ctx->comparisonResult = Compare(*ptr1, *ptr2);
return FALSE;
}
// Note: addvar doesn't support adding from a variable in vanilla. If you were to
// add a VarGet() to the above, make sure you change the `addvar VAR_*, -1`
// in the contest scripts to `subvar VAR_*, 1`, else contests will break.
bool8 ScrCmd_addvar(struct ScriptContext *ctx)
{
u16 *ptr = GetVarPointer(ScriptReadHalfword(ctx));
*ptr += ScriptReadHalfword(ctx);
return FALSE;
}
bool8 ScrCmd_subvar(struct ScriptContext *ctx)
{
u16 *ptr = GetVarPointer(ScriptReadHalfword(ctx));
*ptr -= VarGet(ScriptReadHalfword(ctx));
return FALSE;
}
bool8 ScrCmd_random(struct ScriptContext *ctx)
{
u16 max = VarGet(ScriptReadHalfword(ctx));
gSpecialVar_Result = Random() % max;
return FALSE;
}
bool8 ScrCmd_additem(struct ScriptContext *ctx)
{
u16 itemId = VarGet(ScriptReadHalfword(ctx));
u32 quantity = VarGet(ScriptReadHalfword(ctx));
gSpecialVar_Result = AddBagItem(itemId, (u8)quantity);
return FALSE;
}
bool8 ScrCmd_removeitem(struct ScriptContext *ctx)
{
u16 itemId = VarGet(ScriptReadHalfword(ctx));
u32 quantity = VarGet(ScriptReadHalfword(ctx));
gSpecialVar_Result = RemoveBagItem(itemId, (u8)quantity);
return FALSE;
}
bool8 ScrCmd_checkitemspace(struct ScriptContext *ctx)
{
u16 itemId = VarGet(ScriptReadHalfword(ctx));
u32 quantity = VarGet(ScriptReadHalfword(ctx));
gSpecialVar_Result = CheckBagHasSpace(itemId, (u8)quantity);
return FALSE;
}
bool8 ScrCmd_checkitem(struct ScriptContext *ctx)
{
u16 itemId = VarGet(ScriptReadHalfword(ctx));
u32 quantity = VarGet(ScriptReadHalfword(ctx));
gSpecialVar_Result = CheckBagHasItem(itemId, (u8)quantity);
return FALSE;
}
bool8 ScrCmd_checkitemtype(struct ScriptContext *ctx)
{
u16 itemId = VarGet(ScriptReadHalfword(ctx));
gSpecialVar_Result = GetPocketByItemId(itemId);
return FALSE;
}
bool8 ScrCmd_addpcitem(struct ScriptContext *ctx)
{
u16 itemId = VarGet(ScriptReadHalfword(ctx));
u16 quantity = VarGet(ScriptReadHalfword(ctx));
gSpecialVar_Result = AddPCItem(itemId, quantity);
return FALSE;
}
bool8 ScrCmd_checkpcitem(struct ScriptContext *ctx)
{
u16 itemId = VarGet(ScriptReadHalfword(ctx));
u16 quantity = VarGet(ScriptReadHalfword(ctx));
gSpecialVar_Result = CheckPCHasItem(itemId, quantity);
return FALSE;
}
bool8 ScrCmd_adddecoration(struct ScriptContext *ctx)
{
u32 decorId = VarGet(ScriptReadHalfword(ctx));
gSpecialVar_Result = DecorationAdd(decorId);
return FALSE;
}
bool8 ScrCmd_removedecoration(struct ScriptContext *ctx)
{
u32 decorId = VarGet(ScriptReadHalfword(ctx));
gSpecialVar_Result = DecorationRemove(decorId);
return FALSE;
}
bool8 ScrCmd_checkdecorspace(struct ScriptContext *ctx)
{
u32 decorId = VarGet(ScriptReadHalfword(ctx));
gSpecialVar_Result = DecorationCheckSpace(decorId);
return FALSE;
}
bool8 ScrCmd_checkdecor(struct ScriptContext *ctx)
{
u32 decorId = VarGet(ScriptReadHalfword(ctx));
gSpecialVar_Result = CheckHasDecoration(decorId);
return FALSE;
}
bool8 ScrCmd_setflag(struct ScriptContext *ctx)
{
FlagSet(ScriptReadHalfword(ctx));
return FALSE;
}
bool8 ScrCmd_clearflag(struct ScriptContext *ctx)
{
FlagClear(ScriptReadHalfword(ctx));
return FALSE;
}
bool8 ScrCmd_checkflag(struct ScriptContext *ctx)
{
ctx->comparisonResult = FlagGet(ScriptReadHalfword(ctx));
return FALSE;
}
bool8 ScrCmd_incrementgamestat(struct ScriptContext *ctx)
{
IncrementGameStat(ScriptReadByte(ctx));
return FALSE;
}
bool8 ScrCmd_animateflash(struct ScriptContext *ctx)
{
AnimateFlash(ScriptReadByte(ctx));
ScriptContext_Stop();
return TRUE;
}
bool8 ScrCmd_setflashlevel(struct ScriptContext *ctx)
{
SetFlashLevel(VarGet(ScriptReadHalfword(ctx)));
return FALSE;
}
static bool8 IsPaletteNotActive(void)
{
if (!gPaletteFade.active)
return TRUE;
else
return FALSE;
}
bool8 ScrCmd_fadescreen(struct ScriptContext *ctx)
{
FadeScreen(ScriptReadByte(ctx), 0);
SetupNativeScript(ctx, IsPaletteNotActive);
return TRUE;
}
bool8 ScrCmd_fadescreenspeed(struct ScriptContext *ctx)
{
u8 mode = ScriptReadByte(ctx);
u8 speed = ScriptReadByte(ctx);
FadeScreen(mode, speed);
SetupNativeScript(ctx, IsPaletteNotActive);
return TRUE;
}
bool8 ScrCmd_fadescreenswapbuffers(struct ScriptContext *ctx)
{
u8 mode = ScriptReadByte(ctx);
switch (mode)
{
case FADE_TO_BLACK:
case FADE_TO_WHITE:
default:
CpuCopy32(gPlttBufferUnfaded, gPaletteDecompressionBuffer, PLTT_SIZE);
FadeScreen(mode, 0);
break;
case FADE_FROM_BLACK:
case FADE_FROM_WHITE:
CpuCopy32(gPaletteDecompressionBuffer, gPlttBufferUnfaded, PLTT_SIZE);
FadeScreen(mode, 0);
break;
}
SetupNativeScript(ctx, IsPaletteNotActive);
return TRUE;
}
static bool8 RunPauseTimer(void)
{
if (--sPauseCounter == 0)
return TRUE;
else
return FALSE;
}
bool8 ScrCmd_delay(struct ScriptContext *ctx)
{
sPauseCounter = ScriptReadHalfword(ctx);
SetupNativeScript(ctx, RunPauseTimer);
return TRUE;
}
bool8 ScrCmd_initclock(struct ScriptContext *ctx)
{
u8 hour = VarGet(ScriptReadHalfword(ctx));
u8 minute = VarGet(ScriptReadHalfword(ctx));
RtcInitLocalTimeOffset(hour, minute);
return FALSE;
}
bool8 ScrCmd_dotimebasedevents(struct ScriptContext *ctx)
{
DoTimeBasedEvents();
return FALSE;
}
bool8 ScrCmd_gettime(struct ScriptContext *ctx)
{
RtcCalcLocalTime();
gSpecialVar_0x8000 = gLocalTime.hours;
gSpecialVar_0x8001 = gLocalTime.minutes;
gSpecialVar_0x8002 = gLocalTime.seconds;
return FALSE;
}
bool8 ScrCmd_setweather(struct ScriptContext *ctx)
{
u16 weather = VarGet(ScriptReadHalfword(ctx));
SetSavedWeather(weather);
return FALSE;
}
bool8 ScrCmd_resetweather(struct ScriptContext *ctx)
{
SetSavedWeatherFromCurrMapHeader();
return FALSE;
}
bool8 ScrCmd_doweather(struct ScriptContext *ctx)
{
DoCurrentWeather();
return FALSE;
}
bool8 ScrCmd_setstepcallback(struct ScriptContext *ctx)
{
ActivatePerStepCallback(ScriptReadByte(ctx));
return FALSE;
}
bool8 ScrCmd_setmaplayoutindex(struct ScriptContext *ctx)
{
u16 value = VarGet(ScriptReadHalfword(ctx));
SetCurrentMapLayout(value);
return FALSE;
}
bool8 ScrCmd_warp(struct ScriptContext *ctx)
{
u8 mapGroup = ScriptReadByte(ctx);
u8 mapNum = ScriptReadByte(ctx);
u8 warpId = ScriptReadByte(ctx);
u16 x = VarGet(ScriptReadHalfword(ctx));
u16 y = VarGet(ScriptReadHalfword(ctx));
SetWarpDestination(mapGroup, mapNum, warpId, x, y);
DoWarp();
ResetInitialPlayerAvatarState();
return TRUE;
}
bool8 ScrCmd_warpsilent(struct ScriptContext *ctx)
{
u8 mapGroup = ScriptReadByte(ctx);
u8 mapNum = ScriptReadByte(ctx);
u8 warpId = ScriptReadByte(ctx);
u16 x = VarGet(ScriptReadHalfword(ctx));
u16 y = VarGet(ScriptReadHalfword(ctx));
SetWarpDestination(mapGroup, mapNum, warpId, x, y);
DoDiveWarp();
ResetInitialPlayerAvatarState();
return TRUE;
}
bool8 ScrCmd_warpdoor(struct ScriptContext *ctx)
{
u8 mapGroup = ScriptReadByte(ctx);
u8 mapNum = ScriptReadByte(ctx);
u8 warpId = ScriptReadByte(ctx);
u16 x = VarGet(ScriptReadHalfword(ctx));
u16 y = VarGet(ScriptReadHalfword(ctx));
SetWarpDestination(mapGroup, mapNum, warpId, x, y);
DoDoorWarp();
ResetInitialPlayerAvatarState();
return TRUE;
}
bool8 ScrCmd_warphole(struct ScriptContext *ctx)
{
u8 mapGroup = ScriptReadByte(ctx);
u8 mapNum = ScriptReadByte(ctx);
u16 x;
u16 y;
PlayerGetDestCoords(&x, &y);
if (mapGroup == MAP_GROUP(UNDEFINED) && mapNum == MAP_NUM(UNDEFINED))
SetWarpDestinationToFixedHoleWarp(x - MAP_OFFSET, y - MAP_OFFSET);
else
SetWarpDestination(mapGroup, mapNum, WARP_ID_NONE, x - MAP_OFFSET, y - MAP_OFFSET);
DoFallWarp();
ResetInitialPlayerAvatarState();
return TRUE;
}
// RS mossdeep gym warp, unused in Emerald
bool8 ScrCmd_warpteleport(struct ScriptContext *ctx)
{
u8 mapGroup = ScriptReadByte(ctx);
u8 mapNum = ScriptReadByte(ctx);
u8 warpId = ScriptReadByte(ctx);
u16 x = VarGet(ScriptReadHalfword(ctx));
u16 y = VarGet(ScriptReadHalfword(ctx));
SetWarpDestination(mapGroup, mapNum, warpId, x, y);
DoTeleportTileWarp();
ResetInitialPlayerAvatarState();
return TRUE;
}
bool8 ScrCmd_warpmossdeepgym(struct ScriptContext *ctx)
{
u8 mapGroup = ScriptReadByte(ctx);
u8 mapNum = ScriptReadByte(ctx);
u8 warpId = ScriptReadByte(ctx);
u16 x = VarGet(ScriptReadHalfword(ctx));
u16 y = VarGet(ScriptReadHalfword(ctx));
SetWarpDestination(mapGroup, mapNum, warpId, x, y);
DoMossdeepGymWarp();
ResetInitialPlayerAvatarState();
return TRUE;
}
bool8 ScrCmd_setwarp(struct ScriptContext *ctx)
{
u8 mapGroup = ScriptReadByte(ctx);
u8 mapNum = ScriptReadByte(ctx);
u8 warpId = ScriptReadByte(ctx);
u16 x = VarGet(ScriptReadHalfword(ctx));
u16 y = VarGet(ScriptReadHalfword(ctx));
SetWarpDestination(mapGroup, mapNum, warpId, x, y);
return FALSE;
}
bool8 ScrCmd_setdynamicwarp(struct ScriptContext *ctx)
{
u8 mapGroup = ScriptReadByte(ctx);
u8 mapNum = ScriptReadByte(ctx);
u8 warpId = ScriptReadByte(ctx);
u16 x = VarGet(ScriptReadHalfword(ctx));
u16 y = VarGet(ScriptReadHalfword(ctx));
SetDynamicWarpWithCoords(0, mapGroup, mapNum, warpId, x, y);
return FALSE;
}
bool8 ScrCmd_setdivewarp(struct ScriptContext *ctx)
{
u8 mapGroup = ScriptReadByte(ctx);
u8 mapNum = ScriptReadByte(ctx);
u8 warpId = ScriptReadByte(ctx);
u16 x = VarGet(ScriptReadHalfword(ctx));
u16 y = VarGet(ScriptReadHalfword(ctx));
SetFixedDiveWarp(mapGroup, mapNum, warpId, x, y);
return FALSE;
}
bool8 ScrCmd_setholewarp(struct ScriptContext *ctx)
{
u8 mapGroup = ScriptReadByte(ctx);
u8 mapNum = ScriptReadByte(ctx);
u8 warpId = ScriptReadByte(ctx);
u16 x = VarGet(ScriptReadHalfword(ctx));
u16 y = VarGet(ScriptReadHalfword(ctx));
SetFixedHoleWarp(mapGroup, mapNum, warpId, x, y);
return FALSE;
}
bool8 ScrCmd_setescapewarp(struct ScriptContext *ctx)
{
u8 mapGroup = ScriptReadByte(ctx);
u8 mapNum = ScriptReadByte(ctx);
u8 warpId = ScriptReadByte(ctx);
u16 x = VarGet(ScriptReadHalfword(ctx));
u16 y = VarGet(ScriptReadHalfword(ctx));
SetEscapeWarp(mapGroup, mapNum, warpId, x, y);
return FALSE;
}
bool8 ScrCmd_getplayerxy(struct ScriptContext *ctx)
{
u16 *pX = GetVarPointer(ScriptReadHalfword(ctx));
u16 *pY = GetVarPointer(ScriptReadHalfword(ctx));
*pX = gSaveBlock1Ptr->pos.x;
*pY = gSaveBlock1Ptr->pos.y;
return FALSE;
}
bool8 ScrCmd_getpartysize(struct ScriptContext *ctx)
{
gSpecialVar_Result = CalculatePlayerPartyCount();
return FALSE;
}
bool8 ScrCmd_playse(struct ScriptContext *ctx)
{
PlaySE(ScriptReadHalfword(ctx));
return FALSE;
}
static bool8 WaitForSoundEffectFinish(void)
{
if (!IsSEPlaying())
return TRUE;
else
return FALSE;
}
bool8 ScrCmd_waitse(struct ScriptContext *ctx)
{
SetupNativeScript(ctx, WaitForSoundEffectFinish);
return TRUE;
}
bool8 ScrCmd_playfanfare(struct ScriptContext *ctx)
{
PlayFanfare(ScriptReadHalfword(ctx));
return FALSE;
}
static bool8 WaitForFanfareFinish(void)
{
return IsFanfareTaskInactive();
}
bool8 ScrCmd_waitfanfare(struct ScriptContext *ctx)
{
SetupNativeScript(ctx, WaitForFanfareFinish);
return TRUE;
}
bool8 ScrCmd_playbgm(struct ScriptContext *ctx)
{
u16 songId = ScriptReadHalfword(ctx);
bool8 save = ScriptReadByte(ctx);
if (save == TRUE)
Overworld_SetSavedMusic(songId);
PlayNewMapMusic(songId);
return FALSE;
}
bool8 ScrCmd_savebgm(struct ScriptContext *ctx)
{
Overworld_SetSavedMusic(ScriptReadHalfword(ctx));
return FALSE;
}
bool8 ScrCmd_fadedefaultbgm(struct ScriptContext *ctx)
{
Overworld_ChangeMusicToDefault();
return FALSE;
}
bool8 ScrCmd_fadenewbgm(struct ScriptContext *ctx)
{
Overworld_ChangeMusicTo(ScriptReadHalfword(ctx));
return FALSE;
}
bool8 ScrCmd_fadeoutbgm(struct ScriptContext *ctx)
{
u8 speed = ScriptReadByte(ctx);
if (speed != 0)
FadeOutBGMTemporarily(4 * speed);
else
FadeOutBGMTemporarily(4);
SetupNativeScript(ctx, IsBGMPausedOrStopped);
return TRUE;
}
bool8 ScrCmd_fadeinbgm(struct ScriptContext *ctx)
{
u8 speed = ScriptReadByte(ctx);
if (speed != 0)
FadeInBGM(4 * speed);
else
FadeInBGM(4);
return FALSE;
}
bool8 ScrCmd_applymovement(struct ScriptContext *ctx)
{
u16 localId = VarGet(ScriptReadHalfword(ctx));
const void *movementScript = (const void *)ScriptReadWord(ctx);
ScriptMovement_StartObjectMovementScript(localId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, movementScript);
sMovingNpcId = localId;
return FALSE;
}