/
helpbox_2.c
1452 lines (1115 loc) · 32.6 KB
/
helpbox_2.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 "helpbox.h"
#include "armfunc.h"
#include "oam.h"
#include "sound.h"
#include "text.h"
#include "sprite.h"
#include "msg.h"
#include "util.h"
#include "item.h"
#include "talk.h"
#include "bm.h"
#include "chapter.h"
#include "chapterinfo.h"
#include "ui.h"
#include "eventfunctions.h"
#include "constants/videoalloc_global.h"
#include "constants/chapters.h"
#include "constants/songs.h"
struct Unk_0203D404
{
u16 unk_00;
u16 unk_02;
};
struct Unk_0203D40C
{
/* 00 */ struct Font font;
/* 18 */ struct Text text[3];
/* 30 */ u16 unk_30;
};
struct HelpBoxStartPrintProc
{
/* 00 */ PROC_HEADER;
/* 29 */ u8 pad_29[0x58 - 0x29];
/* 58 */ i32 item;
/* 5C */ i32 msg;
/* 60 */ u8 pad_60[0x64 - 0x60];
/* 64 */ i16 unk_64; // NOTE: might not be same proc
};
struct UnkAgainProc
{
/* 00 */ PROC_HEADER;
/* 2C */ i32 x;
/* 30 */ i32 y;
/* 34 */ i32 msg;
/* 38 */ u8 pal;
};
struct HelpBoxPrintProc2
{
/* 00 */ PROC_HEADER;
/* 2C */ char const * str;
/* 30 */ struct Font * font;
/* 34 */ struct Text * text[6];
/* 4C */ i16 line;
/* 4E */ i16 unk_4E;
/* 50 */ i16 unk_50;
/* 52 */ i16 chars_per_frame;
/* 54 */ u8 pad_54[0x56 - 0x54];
/* 56 */ u8 x, y;
/* 58 */ u8 unk_58;
/* 5C */ i32 msg; // Maybe other proc?
};
extern u8 const gUnk_0830C804[]; // img
extern u8 const gUnk_0830CFE0[]; // img
extern u8 const gUnk_0830D4F0[]; // tsa
extern u8 const gUnk_08308A78[]; // img
extern u16 const Pal_08100A48[]; // pal
struct Unk_0203D404 EWRAM_DATA gUnk_0203D404 = { 0 };
int EWRAM_DATA unused_0203D408 = 0;
struct Unk_0203D40C EWRAM_DATA gUnk_0203D40C = { { 0 } };
void func_fe6_08070CB4(int flags, int pal)
{
u16 const * pal_src;
if (flags & 8)
{
ApplyPalette(Pal_Unk_0830D5E4, pal);
return;
}
pal_src = (flags & 1) != 0
? Pal_Unk_08309474
: Pal_Unk_083094F4;
if (flags & 2)
pal_src = pal_src + 0x10;
if (flags & 4)
pal_src = pal_src + 0x20;
ApplyPalette(pal_src, pal);
}
u8 const * CONST_DATA gUnk_08677F20[] =
{
// TODO
(void *) 0x0830D9C0,
(void *) 0x0830DDBC,
(void *) 0x0830E1DC,
(void *) 0x0830E640,
(void *) 0x0830EA4C,
(void *) 0x0830EDC8,
(void *) 0x0830F250,
(void *) 0x0830F6C4,
(void *) 0x0830F9B8,
(void *) 0x0830FE60,
(void *) 0x083102CC,
(void *) 0x083107A8,
(void *) 0x08310BBC,
(void *) 0x08311094,
(void *) 0x083114AC,
(void *) 0x08311890,
(void *) 0x08311D54,
(void *) 0x08312158,
(void *) 0x083124FC,
(void *) 0x083129A0,
(void *) 0x08312D20,
(void *) 0x08313104,
(void *) 0x083135C0,
(void *) 0x0831394C,
(void *) 0x08313D38,
(void *) 0x083140C8,
(void *) 0x083144E4,
(void *) 0x083149C8,
(void *) 0x08314E14,
(void *) 0x083151E8,
(void *) 0x0831569C,
(void *) 0x08315AC0,
(void *) 0x08315F88,
(void *) 0x08316354,
(void *) 0x083167EC,
(void *) 0x08316C00,
(void *) 0x08317014,
(void *) 0x08317484,
(void *) 0x08317858,
(void *) 0x08317AA4,
(void *) 0x08317D94,
(void *) 0x08318040,
(void *) 0x0831833C,
(void *) 0x08318658,
};
void func_fe6_08070D08(int chr, int title_id)
{
// TODO: is this really chapter?
if (title_id < 0 || title_id >= CHAPTER_COUNT)
title_id = CHAPTER_21X;
gUnk_0203D404.unk_02 = chr & 0x3FF;
Decompress(gUnk_08677F20[title_id], ((void *) VRAM) + chr * CHR_SIZE);
}
void func_fe6_08070D48(int chr)
{
gUnk_0203D404.unk_00 = chr & 0x3FF;
Decompress(gUnk_0830C804, ((void *) VRAM) + chr * CHR_SIZE);
}
void func_fe6_08070D78(int chr)
{
gUnk_0203D404.unk_00 = chr & 0x3FF;
Decompress(gUnk_0830CFE0, ((void *) VRAM) + chr * CHR_SIZE);
}
void func_fe6_08070DA8(u16 * tm, int pal)
{
int i, tile = TILEREF(gUnk_0203D404.unk_02, pal);
for (i = 0; i < 0x40; i++)
*tm++ = tile++;
}
void func_fe6_08070DC8(u16 * tm, int pal)
{
int i, tile = TILEREF(gUnk_0203D404.unk_00, pal);
for (i = 0; i < 0x80; i++)
*tm++ = tile++;
}
void func_fe6_08070DE8(u16 * tm, int pal)
{
TmApplyTsa(tm, gUnk_0830D4F0, TILEREF(gUnk_0203D404.unk_00, pal));
}
int func_fe6_08070E0C(struct PlaySt const * play_st)
{
if (play_st == NULL)
return 0x26;
switch (play_st->chapter)
{
case -1:
case 0x28 ... 0x2C:
return 0x2B;
default:
if ((play_st->flags & PLAY_FLAG_COMPLETE) != 0)
{
switch (play_st->ending_id)
{
case ENDING_0:
return 0x2A;
case ENDING_1:
return 0x29;
case ENDING_2:
return 0x28;
}
}
return GetChapterInfo(play_st->chapter)->title_id;
}
}
void func_fe6_08070E70(void * vram, int pal)
{
if (vram == NULL)
vram = ((void *) VRAM) + 0x10000 + OBCHR_HELPBOX_180 * CHR_SIZE;
if (pal < 0)
pal = OBPAL_HELPBOX_5;
pal = (pal & 15) + 0x10;
Decompress(gUnk_08308A78, vram);
InitSpriteTextFont(&gUnk_0203D40C.font, vram, pal);
InitSpriteText(gUnk_0203D40C.text + 0);
InitSpriteText(gUnk_0203D40C.text + 1);
InitSpriteText(gUnk_0203D40C.text + 2);
SetTextFont(NULL);
ApplyPalette(Pal_08100A48, pal);
gUnk_0203D40C.unk_30 = OAM2_CHR(((uptr) vram) / CHR_SIZE) + OAM2_PAL(pal);
}
void func_fe6_08070EEC(void * vram, int pal)
{
if (vram == NULL)
vram = ((void *) VRAM) + 0x10000 + OBCHR_HELPBOX_180 * CHR_SIZE;
if (pal < 0)
pal = OBPAL_HELPBOX_5;
pal = (pal & 15) + 0x10;
Decompress(gUnk_08308A78, vram);
InitSpriteTextFont(&gUnk_0203D40C.font, vram, pal);
InitSpriteText(gUnk_0203D40C.text + 0);
InitSpriteText(gUnk_0203D40C.text + 1);
gUnk_0203D40C.text[2].tile_width = 0; // ok???
SetTextFont(NULL);
ApplyPalette(Pal_08100A48, pal);
gUnk_0203D40C.unk_30 = OAM2_CHR(((uptr) vram) / CHR_SIZE) + OAM2_PAL(pal);
}
void PutSpriteTalkBox(int x_box, int y_box, int w_box, int h_box)
{
int y_count, x_count;
int iy, ix, x_px, y_px;
if (w_box < 0x20)
w_box = 0x20;
if (w_box > 0xC0)
w_box = 0xC0;
if (h_box < 0x10)
h_box = 0x10;
if (h_box > 0x30)
h_box = 0x30;
x_count = (w_box + 0x1F) / 0x20;
y_count = (h_box + 0x0F) / 0x10;
for (ix = x_count - 1; ix >= 0; ix--)
{
for (iy = y_count; iy >= 0; iy--)
{
x_px = (ix + 1) * 0x20;
if (x_px > w_box)
x_px = w_box;
x_px = x_px - 0x20;
y_px = (iy + 1) * 0x10;
if (y_px > h_box)
y_px = h_box;
y_px = y_px - 0x10;
PutSprite(0, x_box + x_px, y_box + y_px, Sprite_32x16, gUnk_0203D40C.unk_30 + ix * 4 + iy * 0x40);
}
}
for (ix = x_count - 1; ix >= 0; ix--)
{
x_px = (ix + 1) * 0x20;
if (x_px > w_box)
x_px = w_box;
x_px = x_px - 0x20;
PutSprite(0, x_box + x_px, y_box - 8, Sprite_32x8, gUnk_0203D40C.unk_30 + 0x1B);
PutSprite(0, x_box + x_px, y_box + h_box, Sprite_32x8_VFlipped, gUnk_0203D40C.unk_30 + 0x1B);
}
for (iy = y_count; iy >= 0; iy--)
{
y_px = (iy + 1) * 0x10;
if (y_px > h_box)
y_px = h_box;
y_px -= 0x10;
PutSprite(0, x_box - 8, y_box + y_px, Sprite_8x16, gUnk_0203D40C.unk_30 + 0x1F);
PutSprite(0, x_box + w_box, y_box + y_px, Sprite_8x16_HFlipped, gUnk_0203D40C.unk_30 + 0x1F);
}
PutSprite(0, x_box - 8, y_box - 8, Sprite_8x8, gUnk_0203D40C.unk_30 + 0x3E);
PutSprite(0, x_box + w_box, y_box - 8, Sprite_8x8_HFlipped, gUnk_0203D40C.unk_30 + 0x3E);
PutSprite(0, x_box - 8, y_box + h_box, Sprite_8x8_VFlipped, gUnk_0203D40C.unk_30 + 0x3E);
PutSprite(0, x_box + w_box, y_box + h_box, Sprite_8x8_HFlipped_VFlipped, gUnk_0203D40C.unk_30 + 0x3E);
}
int DrawHelpBoxWeaponLabels(int item)
{
Text_InsertDrawString(&gUnk_0203D40C.text[0], 0x00, TEXT_COLOR_47CF, GetItemKindString(GetItemKind(item)));
Text_InsertDrawString(&gUnk_0203D40C.text[0], 0x24, TEXT_COLOR_47CF, JTEXT("射程"));
Text_InsertDrawString(&gUnk_0203D40C.text[0], 0x60, TEXT_COLOR_47CF, JTEXT("重さ"));
Text_InsertDrawString(&gUnk_0203D40C.text[1], 0x00, TEXT_COLOR_47CF, JTEXT("威力"));
Text_InsertDrawString(&gUnk_0203D40C.text[1], 0x30, TEXT_COLOR_47CF, JTEXT("命中"));
Text_InsertDrawString(&gUnk_0203D40C.text[1], 0x60, TEXT_COLOR_47CF, JTEXT("必殺"));
return 2; // TODO: what?
}
void DrawHelpBoxWeaponStats(int item)
{
Text_InsertDrawString(&gUnk_0203D40C.text[0], 0x0C, TEXT_COLOR_456F, GetWeaponLevelStringFromExp(GetItemRequiredExp(item)));
Text_InsertDrawString(&gUnk_0203D40C.text[0], 0x38, TEXT_COLOR_456F, GetItemRangeString(item));
Text_InsertDrawNumberOrBlank(&gUnk_0203D40C.text[0], 0x80, TEXT_COLOR_456F, GetItemWeight(item));
Text_InsertDrawNumberOrBlank(&gUnk_0203D40C.text[1], 0x20, TEXT_COLOR_456F, GetItemMight(item));
Text_InsertDrawNumberOrBlank(&gUnk_0203D40C.text[1], 0x50, TEXT_COLOR_456F, GetItemHit(item));
Text_InsertDrawNumberOrBlank(&gUnk_0203D40C.text[1], 0x80, TEXT_COLOR_456F, GetItemCrit(item));
}
int DrawHelpBoxStaffLabels(int item)
{
Text_InsertDrawString(&gUnk_0203D40C.text[0], 0x00, TEXT_COLOR_47CF, JTEXT("杖"));
Text_InsertDrawString(&gUnk_0203D40C.text[0], 0x0C, TEXT_COLOR_456F, GetWeaponLevelStringFromExp(GetItemRequiredExp(item)));
Text_InsertDrawString(&gUnk_0203D40C.text[0], 0x24, TEXT_COLOR_47CF, JTEXT("射程"));
Text_InsertDrawString(&gUnk_0203D40C.text[0], 0x38, TEXT_COLOR_456F, GetItemRangeString(item));
return 1; // TODO: what?
}
void func_fe6_08071274(struct HelpBoxPrintProc * proc)
{
int i;
proc->clock--;
if (proc->clock > 0)
return;
proc->clock = proc->clock_interval;
SetTextFont(proc->font);
for (i = 0; i < proc->chars_per_print; i++)
{
switch (*proc->str_it)
{
// TODO: control character constants
case 0:
Proc_Break(proc);
break;
case 1:
proc->str_it++;
proc->line++;
continue;
case 4:
proc->str_it++;
continue;
default:
proc->str_it = Text_DrawCharacter(proc->text[proc->line], proc->str_it);
continue;
}
break;
}
SetTextFont(NULL);
}
struct ProcScr CONST_DATA ProcScr_Unk_08677FD0[] =
{
PROC_REPEAT(func_fe6_08071274),
PROC_END,
};
void func_fe6_08071308(struct HelpBoxPrintProc * proc)
{
int i;
SetTextFont(proc->font);
// jumping around switches and for loops requires me to use labels
// not the nicest
for (i = 0; i < 6; i++)
{
struct Text * text = proc->text[i];
Text_SetCursor(text, GetStringTextCenteredPos(text->tile_width * 8, proc->str_it));
for (;;)
{
switch (*proc->str_it)
{
// TODO: control character constants
case 0:
goto end;
case 4:
case 5:
proc->str_it++;
continue;
case 1:
proc->str_it++;
goto next_line;
default:
proc->str_it = Text_DrawCharacter(text, proc->str_it);
continue;
}
}
next_line:;
}
end:
// NOTE: is this supposed to be NULL?
SetTextFont(proc->font);
}
struct ProcScr CONST_DATA ProcScr_Unk_08677FE0[] =
{
PROC_SLEEP(0),
PROC_CALL(func_fe6_08071308),
PROC_END,
};
void func_fe6_08071374(struct HelpBoxStartPrintProc * proc)
{
int item = proc->item;
SetTextFont(&gUnk_0203D40C.font);
SetTextFontGlyphs(TEXT_GLYPHS_SYSTEM);
switch (func_fe6_08070B30(item))
{
case HELPBOX_INFO_NONE:
proc->unk_64 = 0;
break;
case HELPBOX_INFO_WEAPON:
DrawHelpBoxWeaponLabels(item);
proc->unk_64 = 2;
break;
case HELPBOX_INFO_STAFF:
DrawHelpBoxStaffLabels(item);
proc->unk_64 = 1;
break;
}
SetTextFont(NULL);
Proc_Break(proc);
}
void func_fe6_080713DC(struct HelpBoxStartPrintProc * proc)
{
int item = proc->item;
SetTextFont(&gUnk_0203D40C.font);
if (func_fe6_08070B30(item) == HELPBOX_INFO_WEAPON)
{
DrawHelpBoxWeaponStats(item);
}
SetTextFont(NULL);
Proc_Break(proc);
}
void func_fe6_08071410(struct HelpBoxStartPrintProc * proc)
{
struct HelpBoxPrintProc * print_proc;
SetTextFont(&gUnk_0203D40C.font);
SetTextFontGlyphs(TEXT_GLYPHS_TALK);
Text_SetColor(&gUnk_0203D40C.text[0], TEXT_COLOR_4DEF);
Text_SetColor(&gUnk_0203D40C.text[1], TEXT_COLOR_4DEF);
Text_SetColor(&gUnk_0203D40C.text[2], TEXT_COLOR_4DEF);
SetTextFont(NULL);
Proc_EndEach(ProcScr_Unk_08677FD0);
print_proc = SpawnProc(ProcScr_Unk_08677FD0, PROC_TREE_3);
print_proc->font = &gUnk_0203D40C.font;
print_proc->text[0] = &gUnk_0203D40C.text[0];
print_proc->text[1] = &gUnk_0203D40C.text[1];
print_proc->text[2] = &gUnk_0203D40C.text[2];
print_proc->line = proc->unk_64;
print_proc->str_it = DecodeMsg(proc->msg);
print_proc->chars_per_print = 1;
print_proc->clock = 0;
switch (gPlaySt.config_talk_speed)
{
// TODO: talk speed enum constants
case 0:
print_proc->clock_interval = 2;
break;
case 1:
print_proc->clock_interval = 1;
break;
case 2:
print_proc->clock_interval = 1;
print_proc->chars_per_print = 2;
break;
case 3:
print_proc->clock_interval = 0;
print_proc->chars_per_print = INT8_MAX;
break;
}
}
struct ProcScr CONST_DATA gUnk_08677FF8[] =
{
PROC_SLEEP(6),
PROC_REPEAT(func_fe6_08071374),
PROC_REPEAT(func_fe6_080713DC),
PROC_CALL(func_fe6_08071410),
PROC_END,
};
void func_fe6_080714F8(int item, int msg)
{
struct HelpBoxStartPrintProc * proc;
proc = SpawnProc(gUnk_08677FF8, PROC_TREE_3);
proc->item = item;
proc->msg = msg;
}
void func_fe6_08071514(void)
{
SetTextFont(&gUnk_0203D40C.font);
SpriteText_DrawBackground(&gUnk_0203D40C.text[0]);
SpriteText_DrawBackground(&gUnk_0203D40C.text[1]);
SpriteText_DrawBackground(&gUnk_0203D40C.text[2]);
Proc_EndEach(ProcScr_Unk_08677FD0);
Proc_EndEach(gUnk_08677FF8);
SetTextFont(NULL);
}
void func_fe6_0807155C(struct HelpBoxProc * proc)
{
UpdateHelpBoxDisplay(proc, INTERPOLATE_RCUBIC);
if (proc->timer < proc->timer_end)
proc->timer++;
}
void func_fe6_08071584(struct HelpBoxProc * proc)
{
func_fe6_08071838(proc);
func_fe6_08071830(proc, proc->info->x, proc->info->y);
proc->timer_end = proc->timer_end / 3;
proc->timer = proc->timer_end;
}
void func_fe6_080715B4(struct HelpBoxProc * proc)
{
UpdateHelpBoxDisplay(proc, INTERPOLATE_LINEAR);
proc->timer--;
if (proc->timer < 0)
Proc_Break(proc);
}
struct ProcScr CONST_DATA gUnk_08678020[] =
{
PROC_REPEAT(func_fe6_0807155C),
PROC_CALL(func_fe6_08071584),
PROC_REPEAT(func_fe6_080715B4),
PROC_END,
};
void func_fe6_080715DC(int x, int y, int msg)
{
static struct HelpBoxInfo EWRAM_DATA static_info = { 0 };
static_info.x = x;
static_info.y = y;
static_info.msg = msg;
static_info.redirect = NULL;
static_info.populate = NULL;
func_fe6_08071748(&static_info);
}
struct HelpBoxInfo const * EWRAM_DATA gUnk_0203D45C = NULL;
void func_fe6_080715FC(struct HelpBoxInfo const * info)
{
struct HelpBoxProc * proc;
int w_text_box, h_text_box;
proc = FindProc(gUnk_08678020);
if (proc == NULL)
{
proc = SpawnProc(gUnk_08678020, PROC_TREE_3);
PlaySe(SONG_70);
func_fe6_08071830(proc, info->x, info->y);
func_fe6_08071838(proc);
}
else
{
proc->x_box_init = proc->x_box;
proc->y_box_init = proc->y_box;
proc->w_box_init = proc->w_box_fini;
proc->h_box_init = proc->h_box_fini;
}
proc->info = info;
proc->timer = 0;
proc->timer_end = 12;
proc->msg = info->msg;
SetTextFontGlyphs(TEXT_GLYPHS_TALK);
GetStringTextBox(DecodeMsg(proc->msg), &w_text_box, &h_text_box);
SetTextFontGlyphs(TEXT_GLYPHS_SYSTEM);
func_fe6_08071778(proc, w_text_box, h_text_box);
func_fe6_080717B8(proc, info->x, info->y);
func_fe6_08071514();
func_fe6_080714F8(proc->item, proc->msg);
gUnk_0203D45C = info;
}
void func_fe6_080716C8(void)
{
PlaySe(SONG_71);
func_fe6_08071514();
Proc_BreakEach(gUnk_08678020);
}
void func_fe6_080716F0(struct HelpBoxProc * proc)
{
proc->move_key_bit = 0;
if (proc->info->redirect)
proc->info->redirect(proc);
func_fe6_080715FC(proc->info);
}
void func_fe6_08071714(struct HelpBoxProc * proc)
{
if (gKeySt->pressed & KEY_BUTTON_A)
Proc_Break(proc);
}
struct ProcScr CONST_DATA gUnk_08678040[] =
{
PROC_SLEEP(1),
PROC_LABEL(0),
PROC_CALL(func_fe6_080716F0),
PROC_REPEAT(func_fe6_08071714),
PROC_CALL(func_fe6_080716C8),
PROC_END,
};
void func_fe6_08071734(struct HelpBoxProc * proc)
{
func_fe6_080716C8();
Proc_End(proc);
}
void func_fe6_08071748(struct HelpBoxInfo const * info)
{
struct HelpBoxProc * proc;
proc = SpawnProc(gUnk_08678040, PROC_TREE_3);
proc->info = info;
}
bool func_fe6_08071760(void)
{
return FindProc(gUnk_08678040) != NULL;
}
void func_fe6_08071778(struct HelpBoxProc * proc, int w_inner, int h_inner)
{
// identical to ApplyHelpBoxContentSize
// except it calls func_fe6_08071848
w_inner = 0xE0 & (w_inner + 31); // align to 32 pixel multiple
switch (func_fe6_08071848(proc->item))
{
case HELPBOX_INFO_WEAPON:
w_inner = 0xA0;
h_inner += 0x20;
break;
case HELPBOX_INFO_STAFF:
if (w_inner < 0x60)
w_inner = 0x60;
h_inner += 0x10;
break;
}
proc->w_box_fini = w_inner;
proc->h_box_fini = h_inner;
}
void func_fe6_080717B8(struct HelpBoxProc * proc, int x, int y)
{
// identical to ApplyHelpBoxPosition
// except it doesn't care for gHelpBoxOrigin
int x_span = proc->w_box_fini + 0x10;
int y_span = proc->h_box_fini + 0x10;
proc->x_box_fini = x - 0x10 - x_span / 6;
if (proc->x_box_fini < 0)
proc->x_box_fini = 0;
if (proc->x_box_fini + x_span > DISPLAY_WIDTH)
proc->x_box_fini = DISPLAY_WIDTH - x_span;
proc->y_box_fini = y + 0x10;
if (proc->y_box_fini + y_span > DISPLAY_HEIGHT)
proc->y_box_fini = y - y_span;
proc->x_box_fini += 8;
proc->y_box_fini += 8;
}
void func_fe6_08071830(struct HelpBoxProc * proc, int x, int y)
{
// identical to SetHelpBoxInitPosition
// except it doesn't care for gHelpBoxOrigin
proc->x_box_init = x;
proc->y_box_init = y;
}
void func_fe6_08071838(struct HelpBoxProc * proc)
{
// identical to ResetHelpBoxInitSize
proc->w_box_init = 32;
proc->h_box_init = 16;
}
int func_fe6_08071848(int item)
{
// identical to func_fe6_08070B30
if (GetItemAttributes(item) & ITEM_ATTR_LOCK_DRAGON)
return HELPBOX_INFO_NONE;
if (GetItemAttributes(item) & ITEM_ATTR_WEAPON)
return HELPBOX_INFO_WEAPON;
if (GetItemAttributes(item) & ITEM_ATTR_STAFF)
return HELPBOX_INFO_STAFF;
return HELPBOX_INFO_NONE;
}
void func_fe6_08071888(struct HelpBoxProc * proc)
{
if (gKeySt->pressed & KEY_BUTTON_A)
Proc_Break(proc);
}
struct ProcScr CONST_DATA gUnk_08678070[] =
{
PROC_REPEAT(func_fe6_08071888),
PROC_END,
};
int func_fe6_080718A8(int msg, ProcPtr parent)
{
func_fe6_08070E70(NULL, -1);
func_fe6_080715DC(GetUiHandPrevX(), GetUiHandPrevY(), msg);
SpawnProcLocking(gUnk_08678070, parent);
return 1; // ?
}
bool func_fe6_080718E0(void)
{
if (FindProc(gUnk_08678080) != NULL)
return TRUE;
return FALSE;
}
struct Unk_0203D40C EWRAM_DATA gUnk_0203D460 = { { 0 } };
void func_fe6_080718FC(void * vram, int pal)
{
// identical to func_fe6_08070E70
// except for gUnk_0203D460 instead of gUnk_0203D40C
if (vram == NULL)
vram = ((void *) VRAM) + 0x10000 + OBCHR_HELPBOX_180 * CHR_SIZE;
if (pal < 0)
pal = OBPAL_HELPBOX_5;
pal = (pal & 15) + 0x10;
Decompress(gUnk_08308A78, vram);
InitSpriteTextFont(&gUnk_0203D460.font, vram, pal);
InitSpriteText(gUnk_0203D460.text + 0);
InitSpriteText(gUnk_0203D460.text + 1);
InitSpriteText(gUnk_0203D460.text + 2);
SetTextFont(NULL);
ApplyPalette(Pal_08100A48, pal);
gUnk_0203D460.unk_30 = OAM2_CHR(((uptr) vram) / CHR_SIZE) + OAM2_PAL(pal);
}
void func_fe6_08071978(struct HelpBoxProc * proc, int x, int y)
{
int x_span, y_span;
y_span = proc->h_box_fini + 0x10;
if (proc->w_box_fini >= 0xC0)
proc->w_box_fini = 0xC0;
x_span = proc->w_box_fini + 0x10;
proc->x_box_fini = x;
if (proc->x_box_fini + x_span > DISPLAY_WIDTH)
proc->x_box_fini = DISPLAY_WIDTH - x_span;
proc->y_box_fini = y + 8;
if (proc->y_box_fini + y_span > DISPLAY_HEIGHT)
proc->y_box_fini = y - y_span - 8;
proc->x_box_fini += 8;
}
void func_fe6_080719D8(struct HelpBoxProc * proc, int w, int h)
{
w = 0xE0 & (w + 8 + 0x1F); // w + 8 aligned 0x20 up
proc->w_box_fini = w;
proc->h_box_fini = h;
}
void func_fe6_080719EC(struct UnkAgainProc * proc)
{
if (proc->pal == UINT8_MAX)
func_fe6_080718FC(NULL, -1);
else
func_fe6_080718FC(NULL, proc->pal);
func_fe6_08071D04(proc->x, proc->y, proc->msg);
}
void func_fe6_08071A20(void)
{
}
void func_fe6_08071A24(void)
{
SetTextFontGlyphs(TEXT_GLYPHS_SYSTEM);
func_fe6_08071B6C();
}
struct ProcScr CONST_DATA gUnk_08678080[] =
{
PROC_CALL(LockGame),
PROC_SLEEP(1),
PROC_CALL(func_fe6_080719EC),
PROC_REPEAT(func_fe6_08071A20),
PROC_LABEL(0),
PROC_CALL(func_fe6_08071A24),
PROC_SLEEP(10),
PROC_CALL(UnlockGame),
PROC_END,
};
void func_fe6_08071A34(struct HelpBoxProc * proc, int interpolate_method)
{
int x_box = Interpolate(interpolate_method, proc->x_box_init, proc->x_box_fini, proc->timer, proc->timer_end);
int y_box = Interpolate(interpolate_method, proc->y_box_init, proc->y_box_fini, proc->timer, proc->timer_end);
int w_box = Interpolate(interpolate_method, proc->w_box_init, proc->w_box_fini, proc->timer, proc->timer_end);
int h_box = Interpolate(interpolate_method, proc->h_box_init, proc->h_box_fini, proc->timer, proc->timer_end);
proc->x_box = x_box;
proc->y_box = y_box;
func_fe6_08071D94(x_box, y_box, w_box, h_box);
}
void func_fe6_08071AF8(struct HelpBoxProc * proc)
{
func_fe6_08071A34(proc, INTERPOLATE_RCUBIC);
if (proc->timer < proc->timer_end)
proc->timer++;
}
void func_fe6_08071B20(struct HelpBoxProc * proc)
{
ResetHelpBoxInitSize(proc);
proc->timer_end = proc->timer_end / 3;
proc->timer = proc->timer_end;
}
void func_fe6_08071B44(struct HelpBoxProc * proc)
{
func_fe6_08071A34(proc, INTERPOLATE_LINEAR);
proc->timer--;
if (proc->timer < 0)
Proc_Break(proc);
}
struct ProcScr CONST_DATA gUnk_086780C8[] =
{
PROC_REPEAT(func_fe6_08071AF8),