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
|
#include "global.h"
#include "constants/species.h"
#include "bg.h"
#include "gpu_regs.h"
#include "palette.h"
#include "decompress.h"
#include "malloc.h"
#include "menu.h"
#include "new_menu_helpers.h"
#include "pokemon_icon.h"
#include "mystery_gift_menu.h"
#include "menu_indicators.h"
#include "string_util.h"
#include "link_rfu.h"
#include "mevent.h"
struct UnkStruct_8467FB8
{
u8 textPal1:4;
u8 textPal2:4;
u8 textPal3:4;
u8 textPal4:4;
const u8 * tiles;
const u8 * map;
const u16 * pal;
};
struct UnkStruct_203F3C8_02DC
{
u8 unk_00;
u8 unk_01[41];
u8 unk_42[4];
};
struct UnkStruct_203F3C8
{
/*0000*/ struct MEWonderCardData unk_0000;
/*014c*/ struct MEventBuffer_3430_Sub unk_014C;
/*0170*/ const struct UnkStruct_8467FB8 * unk_0170;
/*0174*/ u8 unk_0174;
/*0175*/ u8 unk_0175;
/*0176*/ u16 unk_0176[3];
/*017C*/ u8 unk_017C;
/*017D*/ u8 unk_017D[7][2];
/*018B*/ u8 unk_018B[41];
/*01B4*/ u8 unk_01B4[41];
/*01DD*/ u8 unk_01DD[7];
/*01E4*/ u8 unk_01E4[4][41];
/*0288*/ u8 unk_0288[41];
/*02B1*/ u8 unk_02B1[41];
/*02DC*/ struct UnkStruct_203F3C8_02DC unk_02DC[8];
/*045C*/ u8 buffer_045C[0x1000];
};
EWRAM_DATA struct UnkStruct_203F3C8 * gUnknown_203F3C8 = NULL;
void sub_8145A98(void);
void sub_8145D18(u8 whichWindow);
void sub_8146060(void);
void sub_81461D8(void);
extern const struct OamData gOamData_83AC9F8;
const u8 gUnknown_8467068[][3] = {
{0, 2, 3},
{0, 1, 2}
};
const u8 ALIGNED(4) gUnknown_8467070[3] = {7, 4, 7};
const struct WindowTemplate gUnknown_8467074[] = {
{0x01, 0x01, 0x01, 0x19, 0x04, 0x0f, 0x029c},
{0x01, 0x01, 0x06, 0x1c, 0x08, 0x0f, 0x01bc},
{0x01, 0x01, 0x0e, 0x1c, 0x05, 0x0f, 0x0130}
};
const u16 gUnknown_846708C[] = INCBIN_U16("data/graphics/mevent/pal_46708C.gbapal");
const u16 gUnknown_84670AC[] = INCBIN_U16("data/graphics/mevent/pal_4670AC.gbapal");
const u16 gUnknown_84670CC[] = INCBIN_U16("data/graphics/mevent/pal_4670CC.gbapal");
const u16 gUnknown_84670EC[] = INCBIN_U16("data/graphics/mevent/pal_4670EC.gbapal");
const u16 gUnknown_846710C[] = INCBIN_U16("data/graphics/mevent/pal_46710C.gbapal");
const u16 gUnknown_846712C[] = INCBIN_U16("data/graphics/mevent/pal_46712C.gbapal");
const u16 gUnknown_846714C[] = INCBIN_U16("data/graphics/mevent/pal_46714C.gbapal");
const u16 gUnknown_846716C[] = INCBIN_U16("data/graphics/mevent/pal_46716C.gbapal");
const u8 gUnknown_846718C[] = INCBIN_U8("data/graphics/mevent/gfx_46718C.4bpp.lz");
const u8 gUnknown_8467288[] = INCBIN_U8("data/graphics/mevent/tilemap_467288.bin.lz");
const u8 gUnknown_846737C[] = INCBIN_U8("data/graphics/mevent/gfx_46737C.4bpp.lz");
const u8 gUnknown_8467470[] = INCBIN_U8("data/graphics/mevent/tilemap_467470.bin.lz");
const u8 gUnknown_8467558[] = INCBIN_U8("data/graphics/mevent/gfx_467558.4bpp.lz");
const u8 gUnknown_846762C[] = INCBIN_U8("data/graphics/mevent/tilemap_46762C.bin.lz");
const u8 gUnknown_8467700[] = INCBIN_U8("data/graphics/mevent/gfx_467700.4bpp.lz");
const u8 gUnknown_8467934[] = INCBIN_U8("data/graphics/mevent/tilemap_467934.bin.lz");
const u8 gUnknown_8467A7C[] = INCBIN_U8("data/graphics/mevent/gfx_467A7C.4bpp.lz");
const u8 gUnknown_8467CAC[] = INCBIN_U8("data/graphics/mevent/tilemap_467CAC.bin.lz");
const u16 gUnknown_8467DF4[] = INCBIN_U16("data/graphics/mevent/pal_467DF4.gbapal");
const u16 gUnknown_8467E14[] = INCBIN_U16("data/graphics/mevent/pal_467E14.gbapal");
const u16 gUnknown_8467E34[] = INCBIN_U16("data/graphics/mevent/pal_467E34.gbapal");
const u16 gUnknown_8467E54[] = INCBIN_U16("data/graphics/mevent/pal_467E54.gbapal");
const u16 gUnknown_8467E74[] = INCBIN_U16("data/graphics/mevent/pal_467E74.gbapal");
const u16 gUnknown_8467E94[] = INCBIN_U16("data/graphics/mevent/pal_467E94.gbapal");
const u16 gUnknown_8467EB4[] = INCBIN_U16("data/graphics/mevent/pal_467EB4.gbapal");
const u16 gUnknown_8467ED4[] = INCBIN_U16("data/graphics/mevent/pal_467ED4.gbapal");
const u32 gUnknown_8467EF4[] = INCBIN_U32("data/graphics/mevent/gfx_467EF4.4bpp.lz");
const struct CompressedSpriteSheet gUnknown_8467F58 = {
gUnknown_8467EF4, 0x100, 0x8000
};
const struct SpritePalette gUnknown_8467F60[] = {
{gUnknown_8467DF4, 0x8000},
{gUnknown_8467E14, 0x8000},
{gUnknown_8467E34, 0x8000},
{gUnknown_8467E54, 0x8000},
{gUnknown_8467E74, 0x8000},
{gUnknown_8467E94, 0x8000},
{gUnknown_8467EB4, 0x8000},
{gUnknown_8467ED4, 0x8000}
};
const struct SpriteTemplate gUnknown_8467FA0 = {
0x8000, 0x8000, &gOamData_83AC9F8, gDummySpriteAnimTable, NULL, gDummySpriteAffineAnimTable, SpriteCallbackDummy
};
const struct UnkStruct_8467FB8 gUnknown_8467FB8[8] = {
{1, 0, 0, 0, gUnknown_846718C, gUnknown_8467288, gUnknown_846708C},
{1, 0, 0, 1, gUnknown_846737C, gUnknown_8467470, gUnknown_84670AC},
{1, 0, 0, 2, gUnknown_8467558, gUnknown_846762C, gUnknown_84670CC},
{1, 0, 0, 3, gUnknown_8467558, gUnknown_846762C, gUnknown_84670EC},
{1, 0, 0, 4, gUnknown_8467558, gUnknown_846762C, gUnknown_846710C},
{1, 0, 0, 5, gUnknown_8467558, gUnknown_846762C, gUnknown_846712C},
{1, 0, 0, 6, gUnknown_8467700, gUnknown_8467934, gUnknown_846714C},
{1, 0, 0, 7, gUnknown_8467A7C, gUnknown_8467CAC, gUnknown_846716C}
};
bool32 InitWonderCardResources(struct MEWonderCardData * r5, struct MEventBuffer_3430_Sub * r6)
{
if (r5 == NULL || r6 == NULL)
return FALSE;
gUnknown_203F3C8 = AllocZeroed(sizeof(struct UnkStruct_203F3C8));
if (gUnknown_203F3C8 == NULL)
return FALSE;
gUnknown_203F3C8->unk_0000 = *r5;
gUnknown_203F3C8->unk_014C = *r6;
if (gUnknown_203F3C8->unk_0000.unk_08_2 >= NELEMS(gUnknown_8467FB8))
gUnknown_203F3C8->unk_0000.unk_08_2 = 0;
if (gUnknown_203F3C8->unk_0000.unk_08_0 >= NELEMS(gUnknown_8467070))
gUnknown_203F3C8->unk_0000.unk_08_0 = 0;
if (gUnknown_203F3C8->unk_0000.unk_09 > NELEMS(gUnknown_203F3C8->unk_017D))
gUnknown_203F3C8->unk_0000.unk_09 = 0;
gUnknown_203F3C8->unk_0170 = &gUnknown_8467FB8[gUnknown_203F3C8->unk_0000.unk_08_2];
return TRUE;
}
void DestroyWonderCardResources(void)
{
if (gUnknown_203F3C8 != NULL)
{
*gUnknown_203F3C8 = (struct UnkStruct_203F3C8){};
Free(gUnknown_203F3C8);
gUnknown_203F3C8 = NULL;
}
}
s32 FadeToWonderCardMenu(void)
{
if (gUnknown_203F3C8 == NULL)
return -1;
switch(gUnknown_203F3C8->unk_0174)
{
case 0:
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, 0);
break;
case 1:
if (UpdatePaletteFade())
return 0;
break;
case 2:
FillBgTilemapBufferRect_Palette0(0, 0x000, 0, 0, 30, 20);
FillBgTilemapBufferRect_Palette0(1, 0x000, 0, 0, 30, 20);
FillBgTilemapBufferRect_Palette0(2, 0x000, 0, 0, 30, 20);
CopyBgTilemapBufferToVram(0);
CopyBgTilemapBufferToVram(1);
CopyBgTilemapBufferToVram(2);
DecompressAndCopyTileDataToVram(2, gUnknown_203F3C8->unk_0170->tiles, 0, 0x008, 0);
gUnknown_203F3C8->unk_0176[0] = AddWindow(&gUnknown_8467074[0]);
gUnknown_203F3C8->unk_0176[1] = AddWindow(&gUnknown_8467074[1]);
gUnknown_203F3C8->unk_0176[2] = AddWindow(&gUnknown_8467074[2]);
break;
case 3:
if (FreeTempTileDataBuffersIfPossible())
return 0;
gPaletteFade.bufferTransferDisabled = TRUE;
LoadPalette(gUnknown_203F3C8->unk_0170->pal, 0x10, 0x20);
LZ77UnCompWram(gUnknown_203F3C8->unk_0170->map, gUnknown_203F3C8->buffer_045C);
CopyRectToBgTilemapBufferRect(2, gUnknown_203F3C8->buffer_045C, 0, 0, 30, 20, 0, 0, 30, 20, 1, 0x008, 0);
CopyBgTilemapBufferToVram(2);
break;
case 4:
sub_8145A98();
break;
case 5:
sub_8145D18(0);
sub_8145D18(1);
sub_8145D18(2);
CopyBgTilemapBufferToVram(1);
break;
case 6:
LoadMonIconPalettes();
break;
case 7:
ShowBg(1);
ShowBg(2);
gPaletteFade.bufferTransferDisabled = FALSE;
sub_8146060();
BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, 0);
UpdatePaletteFade();
break;
default:
if (UpdatePaletteFade())
return 0;
gUnknown_203F3C8->unk_0174 = 0;
return 1;
}
++gUnknown_203F3C8->unk_0174;
return 0;
}
s32 FadeOutFromWonderCard(bool32 flag)
{
if (gUnknown_203F3C8 == NULL)
return -1;
switch (gUnknown_203F3C8->unk_0174)
{
case 0:
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, 0);
break;
case 1:
if (UpdatePaletteFade())
return 0;
break;
case 2:
FillBgTilemapBufferRect_Palette0(0, 0x000, 0, 0, 30, 20);
FillBgTilemapBufferRect_Palette0(1, 0x000, 0, 0, 30, 20);
FillBgTilemapBufferRect_Palette0(2, 0x000, 0, 0, 30, 20);
CopyBgTilemapBufferToVram(0);
CopyBgTilemapBufferToVram(1);
CopyBgTilemapBufferToVram(2);
break;
case 3:
HideBg(1);
HideBg(2);
RemoveWindow(gUnknown_203F3C8->unk_0176[2]);
RemoveWindow(gUnknown_203F3C8->unk_0176[1]);
RemoveWindow(gUnknown_203F3C8->unk_0176[0]);
break;
case 4:
sub_81461D8();
FreeMonIconPalettes();
break;
case 5:
PrintMysteryGiftOrEReaderTopMenu(gGiftIsFromEReader, flag);
break;
case 6:
CopyBgTilemapBufferToVram(0);
BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, 0);
break;
default:
if (UpdatePaletteFade())
return 0;
gUnknown_203F3C8->unk_0174 = 0;
return 1;
}
++gUnknown_203F3C8->unk_0174;
return 0;
}
void sub_8145A98(void)
{
u16 i = 0;
u16 r6;
u16 sp0[3] = {0, 0, 0};
memcpy(gUnknown_203F3C8->unk_018B, gUnknown_203F3C8->unk_0000.unk_0A, 40);
gUnknown_203F3C8->unk_018B[40] = EOS;
memcpy(gUnknown_203F3C8->unk_01B4, gUnknown_203F3C8->unk_0000.unk_32, 40);
gUnknown_203F3C8->unk_01B4[40] = EOS;
if (gUnknown_203F3C8->unk_0000.unk_04 > 999999)
gUnknown_203F3C8->unk_0000.unk_04 = 999999;
ConvertIntToDecimalStringN(gUnknown_203F3C8->unk_01DD, gUnknown_203F3C8->unk_0000.unk_04, STR_CONV_MODE_LEFT_ALIGN, 6);
for (i = 0; i < 4; i++)
{
memcpy(gUnknown_203F3C8->unk_01E4[i], gUnknown_203F3C8->unk_0000.unk_5A[i], 40);
gUnknown_203F3C8->unk_01E4[i][40] = EOS;
}
memcpy(gUnknown_203F3C8->unk_0288, gUnknown_203F3C8->unk_0000.unk_FA, 40);
gUnknown_203F3C8->unk_0288[40] = EOS;
switch (gUnknown_203F3C8->unk_0000.unk_08_0)
{
case 0:
memcpy(gUnknown_203F3C8->unk_02B1, gUnknown_203F3C8->unk_0000.unk_122, 40);
gUnknown_203F3C8->unk_02B1[40] = EOS;
break;
case 1:
gUnknown_203F3C8->unk_02B1[00] = EOS;
break;
case 2:
gUnknown_203F3C8->unk_02B1[00] = EOS;
sp0[0] = gUnknown_203F3C8->unk_014C.unk_00 < 999 ? gUnknown_203F3C8->unk_014C.unk_00 : 999;
sp0[1] = gUnknown_203F3C8->unk_014C.unk_02 < 999 ? gUnknown_203F3C8->unk_014C.unk_02 : 999;
sp0[2] = gUnknown_203F3C8->unk_014C.unk_04 < 999 ? gUnknown_203F3C8->unk_014C.unk_04 : 999;
for (i = 0; i < 8; i++)
{
memset(gUnknown_203F3C8->unk_02DC[i].unk_42, EOS, 4);
memset(gUnknown_203F3C8->unk_02DC[i].unk_01, EOS, 41);
}
for (i = 0, r6 = 0; i < 40; i++)
{
if (gUnknown_203F3C8->unk_0000.unk_122[i] != 0xF7)
{
gUnknown_203F3C8->unk_02DC[gUnknown_203F3C8->unk_0175].unk_01[r6] = gUnknown_203F3C8->unk_0000.unk_122[i];
r6++;
}
else
{
u8 r3 = gUnknown_203F3C8->unk_0000.unk_122[i + 1];
if (r3 > 2)
{
i += 2;
}
else
{
ConvertIntToDecimalStringN(gUnknown_203F3C8->unk_02DC[gUnknown_203F3C8->unk_0175].unk_42, sp0[r3], STR_CONV_MODE_LEADING_ZEROS, 3);
gUnknown_203F3C8->unk_02DC[gUnknown_203F3C8->unk_0175].unk_00 = gUnknown_203F3C8->unk_0000.unk_122[i + 2];
gUnknown_203F3C8->unk_0175++;
if (gUnknown_203F3C8->unk_0175 > 7)
break;
r6 = 0;
i += 2;
}
}
}
}
}
void sub_8145D18(u8 whichWindow)
{
s8 sp0C = 0;
s32 windowId = gUnknown_203F3C8->unk_0176[whichWindow];
PutWindowTilemap(windowId);
FillWindowPixelBuffer(windowId, 0);
switch (whichWindow)
{
case 0:
{
s32 x;
AddTextPrinterParameterized3(windowId, 3, 0, 1, gUnknown_8467068[gUnknown_203F3C8->unk_0170->textPal1], 0, gUnknown_203F3C8->unk_018B);
x = 160 - GetStringWidth(3, gUnknown_203F3C8->unk_01B4, GetFontAttribute(3, 2));
if (x < 0)
x = 0;
AddTextPrinterParameterized3(windowId, 3, x, 17, gUnknown_8467068[gUnknown_203F3C8->unk_0170->textPal1], 0, gUnknown_203F3C8->unk_01B4);
if (gUnknown_203F3C8->unk_0000.unk_04 != 0)
{
AddTextPrinterParameterized3(windowId, 2, 166, 17, gUnknown_8467068[gUnknown_203F3C8->unk_0170->textPal1], 0, gUnknown_203F3C8->unk_01DD);
}
break;
}
case 1:
for (; sp0C < 4; sp0C++)
{
AddTextPrinterParameterized3(windowId, 3, 0, 16 * sp0C + 2, gUnknown_8467068[gUnknown_203F3C8->unk_0170->textPal2], 0, gUnknown_203F3C8->unk_01E4[sp0C]);
}
break;
case 2:
AddTextPrinterParameterized3(windowId, 3, 0, gUnknown_8467070[gUnknown_203F3C8->unk_0000.unk_08_0], gUnknown_8467068[gUnknown_203F3C8->unk_0170->textPal3], 0, gUnknown_203F3C8->unk_0288);
if (gUnknown_203F3C8->unk_0000.unk_08_0 != 2)
{
AddTextPrinterParameterized3(windowId, 3, 0, 16 + gUnknown_8467070[gUnknown_203F3C8->unk_0000.unk_08_0], gUnknown_8467068[gUnknown_203F3C8->unk_0170->textPal3], 0, gUnknown_203F3C8->unk_02B1);
}
else
{
s32 x = 0;
s32 y = gUnknown_8467070[gUnknown_203F3C8->unk_0000.unk_08_0] + 16;
s32 spacing = GetFontAttribute(3, 2);
for (; sp0C < gUnknown_203F3C8->unk_0175; sp0C++)
{
AddTextPrinterParameterized3(windowId, 3, x, y, gUnknown_8467068[gUnknown_203F3C8->unk_0170->textPal3], 0, gUnknown_203F3C8->unk_02DC[sp0C].unk_01);
if (gUnknown_203F3C8->unk_02DC[sp0C].unk_42[0] != EOS)
{
x += GetStringWidth(3, gUnknown_203F3C8->unk_02DC[sp0C].unk_01, spacing);
AddTextPrinterParameterized3(windowId, 2, x, y, gUnknown_8467068[gUnknown_203F3C8->unk_0170->textPal3], 0, gUnknown_203F3C8->unk_02DC[sp0C].unk_42);
x += GetStringWidth(3, gUnknown_203F3C8->unk_02DC[sp0C].unk_42, spacing) + gUnknown_203F3C8->unk_02DC[sp0C].unk_00;
}
}
}
break;
}
CopyWindowToVram(windowId, 3);
}
void sub_8146060(void)
{
u8 r7 = 0;
gUnknown_203F3C8->unk_017C = 0xFF;
if (gUnknown_203F3C8->unk_014C.unk_06 != SPECIES_NONE)
{
gUnknown_203F3C8->unk_017C = CreateMonIcon_HandleDeoxys(MailSpeciesToIconSpecies(gUnknown_203F3C8->unk_014C.unk_06), SpriteCallbackDummy, 0xDC, 0x14, 0, FALSE);
gSprites[gUnknown_203F3C8->unk_017C].oam.priority = 2;
}
if (gUnknown_203F3C8->unk_0000.unk_09 != 0 && gUnknown_203F3C8->unk_0000.unk_08_0 == 1)
{
LoadCompressedSpriteSheetUsingHeap(&gUnknown_8467F58);
LoadSpritePalette(&gUnknown_8467F60[gUnknown_203F3C8->unk_0170->textPal4]);
for (; r7 < gUnknown_203F3C8->unk_0000.unk_09; r7++)
{
gUnknown_203F3C8->unk_017D[r7][0] = 0xFF;
gUnknown_203F3C8->unk_017D[r7][1] = 0xFF;
gUnknown_203F3C8->unk_017D[r7][0] = CreateSprite(&gUnknown_8467FA0, 0xd8 - 32 * r7, 0x90, 8);
if (gUnknown_203F3C8->unk_014C.unk_08[0][r7] != 0)
{
gUnknown_203F3C8->unk_017D[r7][1] = CreateMonIcon_HandleDeoxys(MailSpeciesToIconSpecies(gUnknown_203F3C8->unk_014C.unk_08[0][r7]), SpriteCallbackDummy, 0xd8 - 32 * r7, 0x88, 0, 0);
gSprites[gUnknown_203F3C8->unk_017D[r7][1]].oam.priority = 2;
}
}
}
}
void sub_81461D8(void)
{
u8 r6 = 0;
if (gUnknown_203F3C8->unk_017C != 0xFF)
DestroyMonIcon(&gSprites[gUnknown_203F3C8->unk_017C]);
if (gUnknown_203F3C8->unk_0000.unk_09 != 0 && gUnknown_203F3C8->unk_0000.unk_08_0 == 1)
{
for (; r6 < gUnknown_203F3C8->unk_0000.unk_09; r6++)
{
if (gUnknown_203F3C8->unk_017D[r6][0] != 0xFF)
{
DestroySprite(&gSprites[gUnknown_203F3C8->unk_017D[r6][0]]);
// This might be a typo. Uncomment the next line, and comment the one that follows, to get the presumed intended behavior.
// if (gUnknown_203F3C8->unk_017D[r6][1] != 0xFF)
if (gUnknown_203F3C8->unk_017D[r6][0] != 0xFF)
{
DestroyMonIcon(&gSprites[gUnknown_203F3C8->unk_017D[r6][1]]);
}
}
}
FreeSpriteTilesByTag(0x8000);
FreeSpritePaletteByTag(0x8000);
}
}
struct UnkStruct_203F3CC
{
/*0000*/ struct MEWonderNewsData unk_0000;
/*01bc*/ const struct UnkStruct_8467FB8 * unk_01BC;
/*01c0*/ u8 unk_01C0_0:1;
u8 unk_01C0_1:7;
/*01c1*/ u8 unk_01C1;
/*01c2*/ u8 unk_01C2_0:1;
u8 unk_01C2_1:7;
/*01c3*/ u8 unk_01C3_0:1;
u8 unk_01C3_1:7;
/*01c4*/ u16 unk_01C4;
/*01c6*/ u16 unk_01C6;
/*01c8*/ u16 unk_01C8[2];
/*01cc*/ u8 filler_01CC[2];
/*01ce*/ u8 unk_01CE[41];
/*01f7*/ u8 unk_01F7[10][41];
/*0394*/ struct ScrollArrowsTemplate unk_0394;
/*03a4*/ u8 buffer_03A4[0x1000];
};
EWRAM_DATA struct UnkStruct_203F3CC * gUnknown_203F3CC = NULL;
void sub_8146980(void);
void sub_8146A30(void);
void sub_8146B58(void);
const u8 gUnknown_8468038[][3] = {
{0, 2, 3},
{0, 1, 2}
};
const struct WindowTemplate gUnknown_8468040[] = {
{0, 1, 0, 28, 3, 15, 0x000},
{2, 1, 3, 28, 20, 15, 0x000}
};
const struct ScrollArrowsTemplate gUnknown_8468050 = {
0x02, 0xe8, 0x18, 0x03, 0xe8, 0x98,
0x0000, 0x0002, 0x1000, 0x1000, 0x0,
};
const u16 gUnknown_8468060[] = INCBIN_U16("data/graphics/mevent/pal_468060.gbapal");
const u16 gUnknown_8468080[] = INCBIN_U16("data/graphics/mevent/pal_468080.gbapal");
const u16 gUnknown_84680A0[] = INCBIN_U16("data/graphics/mevent/pal_4680A0.gbapal");
const u8 gUnknown_84680C0[] = INCBIN_U8("data/graphics/mevent/gfx_4680C0.4bpp.lz");
const u8 gUnknown_8468140[] = INCBIN_U8("data/graphics/mevent/tilemap_468140.bin.lz");
const u8 gUnknown_846821C[] = INCBIN_U8("data/graphics/mevent/gfx_46821C.4bpp.lz");
const u8 gUnknown_846824C[] = INCBIN_U8("data/graphics/mevent/tilemap_46824C.bin.lz");
const u8 gUnknown_846830C[] = INCBIN_U8("data/graphics/mevent/gfx_46830C.4bpp.lz");
const u8 gUnknown_846837C[] = INCBIN_U8("data/graphics/mevent/tilemap_46837C.bin.lz");
const u8 gUnknown_8468448[] = INCBIN_U8("data/graphics/mevent/gfx_468448.4bpp.lz");
const u8 gUnknown_84684D8[] = INCBIN_U8("data/graphics/mevent/tilemap_4684D8.bin.lz");
const u8 gUnknown_84685B4[] = INCBIN_U8("data/graphics/mevent/gfx_4685B4.4bpp.lz");
const u8 gUnknown_8468644[] = INCBIN_U8("data/graphics/mevent/tilemap_468644.bin.lz");
const struct UnkStruct_8467FB8 gUnknown_8468720[] = {
{1, 0, 0, 0, gUnknown_84680C0, gUnknown_8468140, gUnknown_8468060},
{1, 0, 0, 0, gUnknown_846821C, gUnknown_846824C, gUnknown_84670AC},
{1, 0, 0, 0, gUnknown_846830C, gUnknown_846837C, gUnknown_84670CC},
{1, 0, 0, 0, gUnknown_846830C, gUnknown_846837C, gUnknown_84670EC},
{1, 0, 0, 0, gUnknown_846830C, gUnknown_846837C, gUnknown_846710C},
{1, 0, 0, 0, gUnknown_846830C, gUnknown_846837C, gUnknown_846712C},
{1, 0, 0, 0, gUnknown_8468448, gUnknown_84684D8, gUnknown_8468080},
{1, 0, 0, 0, gUnknown_84685B4, gUnknown_8468644, gUnknown_84680A0}
};
bool32 InitWonderNewsResources(const struct MEWonderNewsData * a0)
{
if (a0 == NULL)
return FALSE;
gUnknown_203F3CC = AllocZeroed(sizeof(struct UnkStruct_203F3CC));
if (gUnknown_203F3CC == NULL)
return FALSE;
gUnknown_203F3CC->unk_0000 = *a0;
if (gUnknown_203F3CC->unk_0000.unk_03 >= NELEMS(gUnknown_8468720))
gUnknown_203F3CC->unk_0000.unk_03 = 0;
gUnknown_203F3CC->unk_01BC = &gUnknown_8468720[gUnknown_203F3CC->unk_0000.unk_03];
gUnknown_203F3CC->unk_01C1 = 0xFF;
return TRUE;
}
void DestroyWonderNewsResources(void)
{
if (gUnknown_203F3CC != NULL)
{
*gUnknown_203F3CC = (struct UnkStruct_203F3CC){};
Free(gUnknown_203F3CC);
gUnknown_203F3CC = NULL;
}
}
s32 FadeToWonderNewsMenu(void)
{
if (gUnknown_203F3CC == NULL)
return -1;
switch (gUnknown_203F3CC->unk_01C0_1)
{
case 0:
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, 0);
break;
case 1:
if (UpdatePaletteFade())
return 0;
ChangeBgY(0, 0, 0);
ChangeBgY(1, 0, 0);
ChangeBgY(2, 0, 0);
ChangeBgY(3, 0, 0);
SetGpuReg(REG_OFFSET_WIN0H, 0xF0);
SetGpuReg(REG_OFFSET_WIN0V, 0x1A98);
SetGpuReg(REG_OFFSET_WININ, 0x1F);
SetGpuReg(REG_OFFSET_WINOUT, 0x1B);
SetGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON);
break;
case 2:
FillBgTilemapBufferRect_Palette0(0, 0x000, 0, 0, 30, 20);
FillBgTilemapBufferRect_Palette0(1, 0x000, 0, 0, 30, 20);
FillBgTilemapBufferRect_Palette0(2, 0x000, 0, 0, 30, 20);
FillBgTilemapBufferRect_Palette0(3, 0x000, 0, 0, 30, 20);
CopyBgTilemapBufferToVram(0);
CopyBgTilemapBufferToVram(1);
CopyBgTilemapBufferToVram(2);
CopyBgTilemapBufferToVram(3);
DecompressAndCopyTileDataToVram(3, gUnknown_203F3CC->unk_01BC->tiles, 0, 8, 0);
gUnknown_203F3CC->unk_01C8[0] = AddWindow(&gUnknown_8468040[0]);
gUnknown_203F3CC->unk_01C8[1] = AddWindow(&gUnknown_8468040[1]);
break;
case 3:
if (FreeTempTileDataBuffersIfPossible())
return 0;
gPaletteFade.bufferTransferDisabled = TRUE;
LoadPalette(gUnknown_203F3CC->unk_01BC->pal, 0x10, 0x20);
LZ77UnCompWram(gUnknown_203F3CC->unk_01BC->map, gUnknown_203F3CC->buffer_03A4);
CopyRectToBgTilemapBufferRect(1, gUnknown_203F3CC->buffer_03A4, 0, 0, 30, 3, 0, 0, 30, 3, 1, 8, 0);
CopyRectToBgTilemapBufferRect(3, gUnknown_203F3CC->buffer_03A4, 0, 3, 30, 23, 0, 3, 30, 23, 1, 8, 0);
CopyBgTilemapBufferToVram(1);
CopyBgTilemapBufferToVram(3);
break;
case 4:
sub_8146980();
break;
case 5:
sub_8146A30();
CopyBgTilemapBufferToVram(0);
CopyBgTilemapBufferToVram(2);
break;
case 6:
ShowBg(1);
ShowBg(2);
ShowBg(3);
gPaletteFade.bufferTransferDisabled = FALSE;
gUnknown_203F3CC->unk_01C1 = AddScrollIndicatorArrowPair(&gUnknown_203F3CC->unk_0394, &gUnknown_203F3CC->unk_01C6);
BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, 0);
UpdatePaletteFade();
break;
default:
if (UpdatePaletteFade())
return 0;
gUnknown_203F3CC->unk_01C0_1 = 0;
return 1;
}
++gUnknown_203F3CC->unk_01C0_1;
return 0;
}
s32 FadeOutFromWonderNews(bool32 flag)
{
if (gUnknown_203F3CC == NULL)
return -1;
switch (gUnknown_203F3CC->unk_01C0_1)
{
case 0:
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, 0);
break;
case 1:
if (UpdatePaletteFade())
return 0;
ChangeBgY(2, 0, 0);
SetGpuReg(REG_OFFSET_WIN0H, 0);
SetGpuReg(REG_OFFSET_WIN0V, 0);
SetGpuReg(REG_OFFSET_WININ, 0);
SetGpuReg(REG_OFFSET_WINOUT, 0);
ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON);
break;
case 2:
FillBgTilemapBufferRect_Palette0(0, 0x000, 0, 0, 30, 20);
FillBgTilemapBufferRect_Palette0(1, 0x000, 0, 0, 30, 20);
FillBgTilemapBufferRect_Palette0(2, 0x000, 0, 0, 30, 24);
FillBgTilemapBufferRect_Palette0(3, 0x000, 0, 0, 30, 24);
CopyBgTilemapBufferToVram(0);
CopyBgTilemapBufferToVram(1);
CopyBgTilemapBufferToVram(2);
CopyBgTilemapBufferToVram(3);
break;
case 3:
HideBg(1);
HideBg(2);
RemoveWindow(gUnknown_203F3CC->unk_01C8[1]);
RemoveWindow(gUnknown_203F3CC->unk_01C8[0]);
break;
case 4:
ChangeBgY(2, 0, 0);
ChangeBgY(3, 0, 0);
if (gUnknown_203F3CC->unk_01C1 != 0xFF)
{
RemoveScrollIndicatorArrowPair(gUnknown_203F3CC->unk_01C1);
gUnknown_203F3CC->unk_01C1 = 0xFF;
}
break;
case 5:
PrintMysteryGiftOrEReaderTopMenu(gGiftIsFromEReader, flag);
break;
case 6:
MG_DrawCheckerboardPattern();
CopyBgTilemapBufferToVram(0);
CopyBgTilemapBufferToVram(3);
BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, 0);
break;
default:
if (UpdatePaletteFade())
return 0;
gUnknown_203F3CC->unk_01C0_1 = 0;
return 1;
}
++gUnknown_203F3CC->unk_01C0_1;
return 0;
}
void MENews_RemoveScrollIndicatorArrowPair(void)
{
if (!gUnknown_203F3CC->unk_01C0_0 && gUnknown_203F3CC->unk_01C1 != 0xFF)
{
RemoveScrollIndicatorArrowPair(gUnknown_203F3CC->unk_01C1);
gUnknown_203F3CC->unk_01C1 = 0xFF;
gUnknown_203F3CC->unk_01C0_0 = TRUE;
}
}
void MENews_AddScrollIndicatorArrowPair(void)
{
if (gUnknown_203F3CC->unk_01C0_0)
{
gUnknown_203F3CC->unk_01C1 = AddScrollIndicatorArrowPair(&gUnknown_203F3CC->unk_0394, &gUnknown_203F3CC->unk_01C6);
gUnknown_203F3CC->unk_01C0_0 = FALSE;
}
}
u32 MENews_GetInput(u16 input)
{
if (gUnknown_203F3CC->unk_01C2_0)
{
sub_8146B58();
return 0xFF;
}
switch (input)
{
case A_BUTTON:
return 0;
case B_BUTTON:
return 1;
case DPAD_UP:
if (gUnknown_203F3CC->unk_01C6 == 0)
return 0xFF;
if (gUnknown_203F3CC->unk_01C0_0)
return 0xFF;
gUnknown_203F3CC->unk_01C3_0 = FALSE;
break;
case DPAD_DOWN:
if (gUnknown_203F3CC->unk_01C6 == gUnknown_203F3CC->unk_01C4)
return 0xFF;
if (gUnknown_203F3CC->unk_01C0_0)
return 0xFF;
gUnknown_203F3CC->unk_01C3_0 = TRUE;
break;
default:
return 0xFF;
}
gUnknown_203F3CC->unk_01C2_0 = TRUE;
gUnknown_203F3CC->unk_01C2_1 = 2;
gUnknown_203F3CC->unk_01C3_1 = 0;
if (gUnknown_203F3CC->unk_01C3_0 == FALSE)
return 2;
else
return 3;
}
void sub_8146980(void)
{
u8 i = 0;
memcpy(gUnknown_203F3CC->unk_01CE, gUnknown_203F3CC->unk_0000.unk_04, 40);
gUnknown_203F3CC->unk_01CE[40] = EOS;
for (; i < 10; ++i)
{
memcpy(gUnknown_203F3CC->unk_01F7[i], gUnknown_203F3CC->unk_0000.unk_2C[i], 40);
gUnknown_203F3CC->unk_01F7[i][40] = EOS;
if (i > 7 && gUnknown_203F3CC->unk_01F7[i][0] != EOS)
++gUnknown_203F3CC->unk_01C4;
}
gUnknown_203F3CC->unk_0394 = gUnknown_8468050;
gUnknown_203F3CC->unk_0394.fullyDownThreshold = gUnknown_203F3CC->unk_01C4;
}
void sub_8146A30(void)
{
u8 i = 0;
s32 x;
PutWindowTilemap(gUnknown_203F3CC->unk_01C8[0]);
PutWindowTilemap(gUnknown_203F3CC->unk_01C8[1]);
FillWindowPixelBuffer(gUnknown_203F3CC->unk_01C8[0], 0);
FillWindowPixelBuffer(gUnknown_203F3CC->unk_01C8[1], 0);
x = (0xe0 - GetStringWidth(3, gUnknown_203F3CC->unk_01CE, GetFontAttribute(3, 2))) / 2;
if (x < 0)
x = 0;
AddTextPrinterParameterized3(gUnknown_203F3CC->unk_01C8[0], 3, x, 6, gUnknown_8468038[gUnknown_203F3CC->unk_01BC->textPal1], 0, gUnknown_203F3CC->unk_01CE);
for (; i < 10; ++i)
{
AddTextPrinterParameterized3(gUnknown_203F3CC->unk_01C8[1], 3, 0, 16 * i + 2, gUnknown_8468038[gUnknown_203F3CC->unk_01BC->textPal2], 0, gUnknown_203F3CC->unk_01F7[i]);
}
CopyWindowToVram(gUnknown_203F3CC->unk_01C8[0], 3);
CopyWindowToVram(gUnknown_203F3CC->unk_01C8[1], 3);
}
void sub_8146B58(void)
{
u16 r4 = gUnknown_203F3CC->unk_01C2_1;
r4 <<= 8;
if (gUnknown_203F3CC->unk_01C3_0)
{
ChangeBgY(2, r4, 1);
ChangeBgY(3, r4, 1);
}
else
{
ChangeBgY(2, r4, 2);
ChangeBgY(3, r4, 2);
}
gUnknown_203F3CC->unk_01C3_1 += gUnknown_203F3CC->unk_01C2_1;
if (gUnknown_203F3CC->unk_01C3_1 > 15)
{
if (gUnknown_203F3CC->unk_01C3_0)
++gUnknown_203F3CC->unk_01C6;
else
--gUnknown_203F3CC->unk_01C6;
gUnknown_203F3CC->unk_01C2_0 = FALSE;
gUnknown_203F3CC->unk_01C3_1 = 0;
}
}
|