summaryrefslogtreecommitdiff
path: root/source/mod.cpp
blob: 3b55e9762a20c938bdf38f92277a1935948aab3c (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
#include "mod.h"

#include <tp/DynamicLink.h>
#include <tp/JFWSystem.h>
#include <tp/d_a_alink.h>
#include <tp/d_com_inf_game.h>
#include <tp/d_item.h>
#include <tp/d_item_data.h>
#include <tp/d_kankyo.h>
#include <tp/d_map_path_dmap.h>
#include <tp/d_meter2_info.h>
#include <tp/d_msg_class.h>
#include <tp/d_msg_flow.h>
#include <tp/d_save.h>
#include <tp/d_stage.h>
#include <tp/dzx.h>
#include <tp/evt_control.h>
#include <tp/f_ap_game.h>
#include <tp/f_op_actor_mng.h>
#include <tp/f_op_scene_req.h>
#include <tp/m_Do_controller_pad.h>
#include <tp/processor.h>
#include <tp/resource.h>

#include <cstdio>
#include <cstring>

#include "HUDConsole.h"
#include "array.h"
#include "chestRando.h"
#include "controller.h"
#include "customChecks.h"
#include "customMessage.h"
#include "defines.h"
#include "eventListener.h"
#include "game_patches.h"
#include "global.h"
#include "itemChecks.h"
#include "items.h"
#include "musicRando.h"
#include "patch.h"
#include "singleton.h"
#include "stage.h"
#include "systemConsole.h"
#include "tools.h"

namespace mod
{
    Mod* global::modPtr = nullptr;
    ChestRandomizer* global::chestRandoPtr = nullptr;
    event::EventListener* global::eventListenerPtr = nullptr;
    mod::HUDConsole* global::hudConsolePtr = nullptr;
    uint64_t* global::seedInSaveFile = nullptr;

    int num_frames = 120;
    int frame_counter = 0;

    tp::d_stage::Actr EponaActr = { "Horse", 0x00000F0D, 0.f, 0.f, 0.f, 0, -180, 0, 0xFFFF };

    void main()
    {
        Mod* mod = new Mod();
        mod->init();
    }

    Mod::Mod()
    {
        eventListener = new event::EventListener();
        chestRandomizer = new ChestRandomizer();
        hudConsole = new HUDConsole( "Settings", 0x80 );
        global::modPtr = this;
        global::chestRandoPtr = this->chestRandomizer;
        global::eventListenerPtr = this->eventListener;
        global::hudConsolePtr = this->hudConsole;
    }

    void Mod::init()
    {
        // Perform any necessary assembly overwrites
        game_patch::assemblyOverwrites();
        game_patch::increaseWalletSize();
        game_patch::increaseClimbSpeed();
        game_patch::setCustomItemData();
        game_patch::setCustomItemFunctions();

        // Causes issues right now (argarok cannot be beaten)
        // game_patch::removeIBLimit();

        // Init rando
        tools::randomSeed = 0x9e3779b97f4a7c15;

        global::seedInSaveFile = reinterpret_cast<u64*>( &tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.eponaName[9] );

        randoEnabled = 1;
        truePause = 1;
        inputBuffering = 0;

        // Print controls
        strcpy( sysConsolePtr->consoleLine[20].line, "D-Pad Nav: Up/Down  Left/Right" );
        strcpy( sysConsolePtr->consoleLine[21].line, "+/- Value: A/B/X/Y  Console  :  R + Z" );
        strcpy( sysConsolePtr->consoleLine[22].line, " Generate: R + Start (auto on new file)" );
        strcpy( sysConsolePtr->consoleLine[23].line, "Bring up the console to use commands" );
        strcpy( sysConsolePtr->consoleLine[24].line, "rando.zeldatp.net | Twitter: @tprandomizer" );

        u8 page = 0;

        // General settings
        hudConsole->addOption( page, "Red:", &reinterpret_cast<u8*>( &sysConsolePtr->consoleColor )[0], 0xFF );
        hudConsole->addOption( page, "Green:", &reinterpret_cast<u8*>( &sysConsolePtr->consoleColor )[1], 0xFF );
        hudConsole->addOption( page, "Blue:", &reinterpret_cast<u8*>( &sysConsolePtr->consoleColor )[2], 0xFF );
        hudConsole->addOption( page, "Alpha:", &reinterpret_cast<u8*>( &sysConsolePtr->consoleColor )[3], 0xFF );
        hudConsole->addOption( page, "True Pause:", &truePause, 0x1 );
        hudConsole->addOption( page, "Input Buffer:", &inputBuffering, 0x1 );

        // Seed settings
        page = hudConsole->addPage( "Seed" );

        hudConsole->addOption( page, "Rando enabled?", &randoEnabled, 0x1 );
        hudConsole->addOption( page, "Custom Seed?", &customSeed, 0x1 );
        hudConsole->addOption( page, "Seed 1:", &reinterpret_cast<u8*>( &tools::randomSeed )[0], 0xFF );
        hudConsole->addOption( page, "Seed 2:", &reinterpret_cast<u8*>( &tools::randomSeed )[1], 0xFF );
        hudConsole->addOption( page, "Seed 3:", &reinterpret_cast<u8*>( &tools::randomSeed )[2], 0xFF );
        hudConsole->addOption( page, "Seed 4:", &reinterpret_cast<u8*>( &tools::randomSeed )[3], 0xFF );

        hudConsole->addOption( page, "Seed 5:", &reinterpret_cast<u8*>( &tools::randomSeed )[4], 0xFF );
        hudConsole->addOption( page, "Seed 6:", &reinterpret_cast<u8*>( &tools::randomSeed )[5], 0xFF );
        hudConsole->addOption( page, "Seed 7:", &reinterpret_cast<u8*>( &tools::randomSeed )[6], 0xFF );
        hudConsole->addOption( page, "Seed 8:", &reinterpret_cast<u8*>( &tools::randomSeed )[7], 0xFF );

        hudConsole->addWatch( page, "Resulting Seed", &tools::randomSeed, 'x', WatchInterpretation::_u64 );

        // Debug
        page = hudConsole->addPage( "Debug Info" );

        hudConsole->addWatch( page, "InSave: ", global::seedInSaveFile, 'x', WatchInterpretation::_u64 );
        hudConsole->addWatch( page, "Function:", &lastItemFunc, 's', WatchInterpretation::_str );
        hudConsole->addWatch( page, "  Source:", &chestRandomizer->lastSourceInfo, 's', WatchInterpretation::_str );
        hudConsole->addWatch( page, "    Dest:", &chestRandomizer->lastDestInfo, 's', WatchInterpretation::_str );

        hudConsole->addWatch( page, "Total Checks:", &chestRandomizer->totalChecks, 'u', WatchInterpretation::_u16 );
        hudConsole->addWatch( page, "Layer Checks:", &chestRandomizer->layerCheckCount, 'u', WatchInterpretation::_u16 );
        hudConsole->addWatch( page, "Empty:", &chestRandomizer->empty, 'u', WatchInterpretation::_u16 );

        hudConsole->addWatch( page, "Active Seed:", &chestRandomizer->currentSeed, 'x', WatchInterpretation::_u64 );
        hudConsole->addWatch( page, "   Checksum:", &chestRandomizer->checkSum, 'x', WatchInterpretation::_u16 );

        // Item search
        page = hudConsole->addPage( "Item Search" );

        hudConsole->addOption( page, "Search ID:", &itemSearchID, 0xFF );
        hudConsole->addOption( page, "Reverse ID:", &itemReverseSearchID, 0xFF );

        hudConsole->addWatch( page, "Search Result:", &itemSearchResults, 's', WatchInterpretation::_str );
        hudConsole->addWatch( page, "Reverse Result:", &itemReverseSearchResults, 's', WatchInterpretation::_str );

        hudConsole->addWatch( page, "MetadataID:", &lastItemDataID, 's', WatchInterpretation::_str );
        hudConsole->addWatch( page, "MetadataX:", &lastItemDataX, 's', WatchInterpretation::_str );
        hudConsole->addWatch( page, "MetadataY:", &lastItemDataY, 's', WatchInterpretation::_str );
        hudConsole->addWatch( page, "MetadataZ:", &lastItemDataZ, 's', WatchInterpretation::_str );

        // Check search
        page = hudConsole->addPage( "Check Search" );

        hudConsole->addOption( page, "Search ID1:", &checkSearchID1, 0xFF );
        hudConsole->addOption( page, "Search ID2:", &checkSearchID2, 0xFF );
        hudConsole->addOption( page, "Reverse ID1:", &checkReverseSearchID1, 0xFF );
        hudConsole->addOption( page, "Reverse ID2:", &checkReverseSearchID2, 0xFF );

        hudConsole->addWatch( page, "Search ID:", &checkSearchID, 'd', WatchInterpretation::_u16 );
        hudConsole->addWatch( page, "Reverse ID:", &checkReverseSearchID, 'd', WatchInterpretation::_u16 );
        hudConsole->addWatch( page, "Search Result:", &checkSearchResults, 's', WatchInterpretation::_str );
        hudConsole->addWatch( page, "Reverse Result:", &checkReverseSearchResults, 's', WatchInterpretation::_str );

        // Shuffled Checks
        page = hudConsole->addPage( "Shuffled Checks" );

        hudConsole->addOption( page, "Bugsanity?", &chestRandomizer->isBugsanityEnabled, 0x1 );
        hudConsole->addOption( page, "Poesanity?", &chestRandomizer->isPoesanityEnabled, 0x1 );
        hudConsole->addOption( page, "Shopsanity?", &chestRandomizer->isShopsanityEnabled, 0x1 );
        hudConsole->addOption( page, "Dungeon Items?", &chestRandomizer->areDungeonItemsRandomized, 0x1 );
        hudConsole->addOption( page, "Key Shuffle?", &chestRandomizer->isKeysanityEnabled, 0x1 );
        hudConsole->addOption( page, "Sky Character?", &Singleton::getInstance()->shuffledSkybook, 0x1 );

        // Game info 1
        page = hudConsole->addPage( "Skips 1" );

        hudConsole->addOption( page, "MDH Skip?", &Singleton::getInstance()->isMDHSkipEnabled, 0x1 );
        hudConsole->addOption( page, "Faron Escape?", &Singleton::getInstance()->isForestEscapeEnabled, 0x1 );
        hudConsole->addOption( page, "Open HF gates?", &Singleton::getInstance()->isGateUnlockEnabled, 0x1 );
        hudConsole->addOption( page, "Skip Twilight?", &Singleton::getInstance()->isTwilightSkipped, 0x1 );
        hudConsole->addOption( page, "Skip Goats?", &Singleton::getInstance()->isGoatSkipEnabled, 0x1 );
        hudConsole->addOption( page, "Skip MS Puzzle?", &Singleton::getInstance()->isMSPuzzleSkipEnabled, 0x1 );
        hudConsole->addOption( page, "Skip Escort?", &Singleton::getInstance()->isCartEscortSkipEnabled, 0x1 );
        hudConsole->addOption( page, "Skip Sewers?", &Singleton::getInstance()->isSewerSkipEnabled, 0x1 );

        hudConsole->addWatch( page, "CurrentStage:", &gameInfo.currentStage, 's', WatchInterpretation::_str );
        hudConsole->addWatch( page, "CurrentRoom:", &tp::d_kankyo::env_light.currentRoom, 'd', WatchInterpretation::_u8 );
        hudConsole->addWatch( page, "CurrentState:", &tp::d_com_inf_game::current_state, 'x', WatchInterpretation::_u8 );

        hudConsole->addWatch( page, "CurrentPosX:", &currentPosX, 's', WatchInterpretation::_str );
        hudConsole->addWatch( page, "CurrentPosY:", &currentPosY, 's', WatchInterpretation::_str );
        hudConsole->addWatch( page, "CurrentPosZ:", &currentPosZ, 's', WatchInterpretation::_str );
        hudConsole->addWatch( page, "CurrentAngle:", &linkAngle, 's', WatchInterpretation::_str );
        hudConsole->addWatch( page, "Sky Angle:", &skyAngle, 's', WatchInterpretation::_str );

        // Game info 2
        page = hudConsole->addPage( "Skips 2" );
        hudConsole->addOption( page, "Early CiTS?", &Singleton::getInstance()->isEarlyCiTSEnabled, 0x1 );
        hudConsole->addOption( page, "Early Desert?", &Singleton::getInstance()->isEarlyDesertEnabled, 0x1 );
        hudConsole->addOption( page, "Boss Keysey?", &Singleton::getInstance()->isBossKeyseyEnabled, 0x1 );
        hudConsole->addOption( page, "No Shop Bottl?", &allowBottleItemsShopAnytime, 0x1 );
        hudConsole->addOption( page, "Fast transform?", &enableQuickTransform, 0x1 );
        hudConsole->addOption( page, "Skip Intro?", &Singleton::getInstance()->isIntroSkipped, 0x1 );
        hudConsole->addOption( page, "Midna ToD Skip?", &Singleton::getInstance()->midnaTimeControl, 0x1 );
        hudConsole->addOption( page, "Early ToT?", &Singleton::getInstance()->isEarlyToTEnabled, 0x1 );
        hudConsole->addOption( page, "Early PoT?", &Singleton::getInstance()->isEarlyPoTEnabled, 0x1 );
        hudConsole->addOption( page, "Open HC?", &Singleton::getInstance()->isEarlyHCEnabled, 0x1 );

        // buttons
        /*page = hudConsole->addPage("Button texts");

        hudConsole->addOption(page, "A button:", &gameInfo.aButtonText, 0xFF);
        hudConsole->addOption(page, "Y button:", &gameInfo.yButtonText, 0xFF);
        hudConsole->addOption(page, "X button:", &gameInfo.xButtonText, 0xFF);
        hudConsole->addOption(page, "B button:", &gameInfo.bButtonText, 0xFF);
        hudConsole->addOption(page, "R button:", &gameInfo.rButtonText, 0xFF);
        hudConsole->addOption(page, "stick button:", &gameInfo.stickButtonText, 0xFF);
        hudConsole->addOption(page, "start button:", &gameInfo.startButtonText, 0xFF);
        hudConsole->addOption(page, "C button:", &gameInfo.cButtonText, 0xFF);
        hudConsole->addOption(page, "X item:", &gameInfo.xItem, 0xFF);
        hudConsole->addOption(page, "Y item:", &gameInfo.yItem, 0xFF);
        hudConsole->addWatch(page, "A button:", &gameInfo.aButtonText, 'x', WatchInterpretation::_u8);
        hudConsole->addWatch(page, "Y button:", &gameInfo.yButtonText, 'x', WatchInterpretation::_u8);
        hudConsole->addWatch(page, "X button:", &gameInfo.xButtonText, 'x', WatchInterpretation::_u8);
        hudConsole->addWatch(page, "B button:", &gameInfo.bButtonText, 'x', WatchInterpretation::_u8);
        hudConsole->addWatch(page, "R button:", &gameInfo.rButtonText, 'x', WatchInterpretation::_u8);
        hudConsole->addWatch(page, "stick:", &gameInfo.stickButtonText, 'x', WatchInterpretation::_u8);
        hudConsole->addWatch(page, "start button:", &gameInfo.startButtonText, 'x', WatchInterpretation::_u8);
        hudConsole->addWatch(page, "C button:", &gameInfo.cButtonText, 'x', WatchInterpretation::_u8);
        hudConsole->addWatch(page, "scoop:", &scoopResult, 'x', WatchInterpretation::_u16);
        hudConsole->addWatch(page, "check:", &checkResult, 'x', WatchInterpretation::_u16);
        hudConsole->addWatch(page, "items:", &itemsResult, 'x', WatchInterpretation::_u16);
        hudConsole->addWatch(page, "map:", &mapResult, 'x', WatchInterpretation::_u16);
hudConsole->addWatch(page, "equip:", &equipResult, 'x', WatchInterpretation::_u16);
hudConsole->addWatch(page, "back:", &backResult, 'x', WatchInterpretation::_u16);
hudConsole->addWatch(page, "zoom in:", &zoomInResult, 'x', WatchInterpretation::_u16);
hudConsole->addWatch(page, "zoom out:", &zoomOutResult, 'x', WatchInterpretation::_u16);
hudConsole->addWatch(page, "move:", &moveResult, 'x', WatchInterpretation::_u16);
hudConsole->addWatch(page, "throw:", &throwResult, 'x', WatchInterpretation::_u16);*/

        // event info
        page = hudConsole->addPage( "Skips 3/ Event" );
        // hudConsole->addOption(page, "Coords as hex?", &coordsAreInHex, 0x1);
        hudConsole->addOption( page, "GM Story Flag?", &Singleton::getInstance()->isGMStoryPatch, 0x1 );
        hudConsole->addOption( page, "Start w/ Crstl?", &Singleton::getInstance()->startWithCrystal, 0x1 );
        hudConsole->addOption( page, "Hidden Skills?", &Singleton::getInstance()->shuffleHiddenSkills, 0x1 );

        hudConsole->addWatch( page, "CurrentEventID:", &gameInfo.eventSystem.currentEventID, 'x', WatchInterpretation::_u8 );
        hudConsole->addWatch( page, "NextEventID:", &gameInfo.eventSystem.nextEventID, 'x', WatchInterpretation::_u8 );
        hudConsole->addWatch( page, "NextStage:", &gameInfo.nextStageVars.nextStage, 's', WatchInterpretation::_str );
        hudConsole->addWatch( page, "NextRoom:", &gameInfo.nextStageVars.nextRoom, 'd', WatchInterpretation::_u8 );
        hudConsole->addWatch( page, "NextSpawnPoint:", &gameInfo.nextStageVars.nextSpawnPoint, 'x', WatchInterpretation::_u8 );
        hudConsole->addWatch( page, "NextSate:", &gameInfo.nextStageVars.nextState, 'x', WatchInterpretation::_u8 );

        // Cosmetic Changes
        page = hudConsole->addPage( "Cosmetic" );
        hudConsole->addOption( page, "LTN In Rd:", &innerRed, 0xFF );
        hudConsole->addOption( page, "LTN In Green:", &innerGreen, 0xFF );
        hudConsole->addOption( page, "LTN In Blue:", &innerBlue, 0xFF );
        hudConsole->addOption( page, "LTN Ot Red:", &outerRed, 0xFF );
        hudConsole->addOption( page, "LTN Ot Green:", &outerGreen, 0xFF );
        hudConsole->addOption( page, "LTN Ot Blue:", &outerBlue, 0xFF );

        // Bgm Options
        page = hudConsole->addPage( "BGM" );
        hudConsole->addOption( page, "BGM Rando: ", &musicrando::musicRandoEnabled, 0x1 );
        hudConsole->addOption( page, "No Enemy BGM?: ", &musicrando::enemyBgmDisabled, 0x1 );
        hudConsole->addOption( page, "Item Fanfares: ", &musicrando::fanfareRandoEnabled, 0x1 );

        // Print
        hudConsole->draw();
        system_console::setState( true, 0 );

        //   =================
        //  | Custom events   |
        //   =================

        // Generate random data when a new game starts
        eventListener->addLoadEvent( stage::allStages[Stage_Faron_Woods],
                                     0x1,
                                     0x15,
                                     0xFF,
                                     0xFF,
                                     tools::triggerRandomGenerator,
                                     event::LoadEventAccuracy::Stage_Room_Spawn );

        // Skip sewers when the load happens
        eventListener->addLoadEvent( stage::allStages[Stage_Hyrule_Castle_Sewers],
                                     0x0,
                                     0x18,
                                     0xFF,
                                     0xFF,
                                     game_patch::skipSewers,
                                     event::LoadEventAccuracy::Stage_Room_Spawn );

        // Fix BiTE
        // eventListener->addLoadEvent(stage::allStages[Stage_Title_Screen], 0x0, 0x17, 0xFF, 0xFF, game_patch::giveEpona,
        // event::LoadEventAccuracy::Stage_Room_Spawn);

        // Kill spider at Link's house
        eventListener->addLoadEvent( stage::allStages[Stage_Ordon_Village],
                                     0x1,
                                     0xFF,
                                     0xFF,
                                     0xFF,
                                     game_patch::killLinkHouseSpider,
                                     event::LoadEventAccuracy::Stage_Room );

        // unlock HF gates and check for MDH
        eventListener->addLoadEvent( stage::allStages[Stage_Hyrule_Field],
                                     0xFF,
                                     0xFF,
                                     0xFF,
                                     0xFF,
                                     game_patch::setFieldBits,
                                     event::LoadEventAccuracy::Stage );

        // skip goats 2
        eventListener->addLoadEvent( stage::allStages[Stage_Ordon_Ranch],
                                     0x0,
                                     0x3,
                                     0xFF,
                                     0xFF,
                                     game_patch::skipGoats,
                                     event::LoadEventAccuracy::Stage_Room_Spawn );

        // skip MS Puzzle
        eventListener->addLoadEvent( stage::allStages[Stage_Sacred_Grove],
                                     0xFF,
                                     0xFF,
                                     0xFF,
                                     0xFF,
                                     game_patch::setGroveFlags,
                                     event::LoadEventAccuracy::Stage );

        // Fix Lanayru Softlock
        eventListener->addLoadEvent( stage::allStages[Stage_Lake_Hylia],
                                     0x0,
                                     0x5,
                                     0xE,
                                     0xFF,
                                     game_patch::setLanayruWolf,
                                     event::LoadEventAccuracy::Stage_Room_Spawn );

        // desert Access
        eventListener->addLoadEvent( stage::allStages[Stage_Gerudo_Desert],
                                     0x0,
                                     0x0,
                                     0xFF,
                                     0xFF,
                                     game_patch::accessDesert,
                                     event::LoadEventAccuracy::Stage_Room_Spawn );

        // Skip Midna Text and CS's
        eventListener->addLoadEvent( stage::allStages[Stage_Faron_Woods],
                                     0x1,
                                     0x15,
                                     0xFF,
                                     0xFF,
                                     game_patch::skipTextAndCS,
                                     event::LoadEventAccuracy::Stage_Room_Spawn_State );

        // Allow Escort Any Time
        eventListener->addLoadEvent( stage::allStages[Stage_Castle_Town_Interiors],
                                     0x5,
                                     0xFF,
                                     0xFF,
                                     0xFF,
                                     game_patch::setEscortState,
                                     event::LoadEventAccuracy::Stage_Room_Spawn );

        // Skip MDH Trigger
        eventListener->addLoadEvent( stage::allStages[Stage_Lake_Hylia],
                                     0x1,
                                     0x16,
                                     0xFF,
                                     0xFF,
                                     game_patch::skipMDHCS,
                                     event::LoadEventAccuracy::Stage_Room_Spawn );

        // Allow Faron Escape
        eventListener->addLoadEvent( stage::allStages[Stage_Faron_Woods],
                                     0xFF,
                                     0xFF,
                                     0xFF,
                                     0xFF,
                                     game_patch::allowFaronEscape,
                                     event::LoadEventAccuracy::Stage );

        // Skip MDH After Lanayru
        eventListener->addLoadEvent( stage::allStages[Stage_Lake_Hylia],
                                     0x1,
                                     0x14,
                                     0xFF,
                                     0xFF,
                                     game_patch::skipMDH,
                                     event::LoadEventAccuracy::Stage_Room_Spawn );

        // set Coro Lantern Flag
        eventListener->addLoadEvent( stage::allStages[Stage_Faron_Woods],
                                     0xFF,
                                     0xFF,
                                     0xFF,
                                     0xFF,
                                     game_patch::setLanternFlag,
                                     event::LoadEventAccuracy::Stage_Room_Spawn );

        // Break Barrier
        eventListener->addLoadEvent( stage::allStages[Stage_Castle_Town],
                                     0xFF,
                                     0xFF,
                                     0xFF,
                                     0xFF,
                                     game_patch::breakBarrier,
                                     event::LoadEventAccuracy::Stage_Room_Spawn );
        //   =================
        //  | Function Hooks  |
        //   =================

        fapGm_Execute_trampoline =
            patch::hookFunction( tp::f_ap_game::fapGm_Execute, []() { global::modPtr->procNewFrame(); } );

        // Hook actor init function to use as a timing for placing custom chests as this function only creates actors at
        // specific times
        actorCommonLayerInit_trampoline = patch::hookFunction(
            tp::d_stage::actorCommonLayerInit,
            []( void* mStatus_roomControl, tp::d_stage::dzxChunkTypeInfo* chunkTypeInfo, int unk3, void* unk4 ) {
                if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Faron_Woods] ) )
                {
                    if ( Singleton::getInstance()->hasActorCommonLayerRan <= 4 )
                    {
                        global::modPtr->doCustomTRESActor( mStatus_roomControl );
                    }
                }
                else if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Hyrule_Field] ) &&
                          gameInfo.nextStageVars.nextSpawnPoint == 0xFC )
                {
                    if ( Singleton::getInstance()->hasActorCommonLayerRan <= 2 )
                    {
                        global::modPtr->doCustomTRESActor( mStatus_roomControl );
                    }
                }
                else
                {
                    global::modPtr->doCustomTRESActor( mStatus_roomControl );
                }
                return global::modPtr->actorCommonLayerInit_trampoline( mStatus_roomControl, chunkTypeInfo, unk3, unk4 );
            } );

        actorInit_always_trampoline = patch::hookFunction(
            tp::d_stage::actorInit_always,
            []( void* mStatus_roomControl, tp::d_stage::dzxChunkTypeInfo* chunkTypeInfo, int unk3, void* unk4 ) {
                if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Faron_Woods] ) )
                {
                    // Add Epona to the global Actor list
                    tp::d_stage::Actr* EponaActrPtr = &EponaActr;
                    tp::d_stage::dzxChunkTypeInfo chunkInfo;
                    strcpy( chunkInfo.tag, "ACTR" );
                    chunkInfo.numChunks = 0x1;
                    typeTransform<u32, float> X, Y, Z;
                    X.a = 0x0;
                    Y.a = 0x0;
                    Z.a = 0x0;
                    EponaActrPtr->pos[0] = X.b;
                    EponaActrPtr->pos[1] = Y.b;
                    EponaActrPtr->pos[2] = Z.b;
                    chunkInfo.chunkDataPtr = EponaActrPtr;
                    // Add the actor to the actor list
                    global::modPtr->actorInit_always_trampoline( mStatus_roomControl, &chunkInfo, 0, nullptr );
                }

                return global::modPtr->actorCommonLayerInit_trampoline( mStatus_roomControl, chunkTypeInfo, unk3, unk4 );
            } );

        putSave_trampoline =
            patch::hookFunction( tp::d_save::putSave, []( tp::d_com_inf_game::GameInfo* gameInfoPtr, s32 areaID ) {
                Singleton::getInstance()->hasActorCommonLayerRan = 0;
                return global::modPtr->putSave_trampoline( gameInfoPtr, areaID );
            } );

        checkTreasureRupeeReturn_trampoline = patch::hookFunction(
            tp::d_a_alink::checkTreasureRupeeReturn,
            []( void* unk1, s32 item ) { return global::modPtr->procCheckTreasureRupeeReturn( unk1, item ); } );

        createItemForPresentDemo_trampoline = patch::hookFunction(
            tp::f_op_actor_mng::createItemForPresentDemo,
            []( const float pos[3], s32 item, u8 unk3, s32 unk4, s32 unk5, const float unk6[3], const float unk7[3] ) {
                // Call replacement function
                /*char txt[50];
                snprintf(txt, 50, "0 = %f 1 = %f 2 = %f", pos[0], pos[1], pos[2]);
                strcpy(sysConsolePtr->consoleLine[20].line, txt);*/

                item = global::modPtr->procItemCreateFunc( pos, item, "createItemForPresentDemo" );

                return global::modPtr->createItemForPresentDemo_trampoline( pos, item, unk3, unk4, unk5, unk6, unk7 );
            } );

        createItemForTrBoxDemo_trampoline = patch::hookFunction(
            tp::f_op_actor_mng::createItemForTrBoxDemo,
            []( const float pos[3], s32 item, s32 unk3, s32 unk4, const float unk5[3], const float unk6[3] ) {
                // Call replacement function
                item = global::modPtr->procItemCreateFunc( pos, item, "createItemForTrBoxDemo" );

                return global::modPtr->createItemForTrBoxDemo_trampoline( pos, item, unk3, unk4, unk5, unk6 );
            } );
        // this function is called when the heart spawns, not when link gets it
        // createItemForTrBoxDemo is called when heart container is gotten
        createItemForBoss_trampoline = patch::hookFunction(
            tp::f_op_actor_mng::createItemForBoss,
            []( const float pos[3],
                s32 item,
                s32 unk3,
                const float unk4[3],
                const float unk5[3],
                float unk6,
                float unk7,
                s32 unk8 ) {
                // Call replacement function
                item = global::modPtr->procItemCreateFunc( pos, item, "createItemForBoss" );

                return global::modPtr->createItemForBoss_trampoline( pos, item, unk3, unk4, unk5, unk6, unk7, unk8 );
            } );

        createItemForMidBoss_trampoline = patch::hookFunction(
            tp::f_op_actor_mng::createItemForMidBoss,
            []( const float pos[3], s32 item, s32 unk3, const float unk4[3], const float unk5[3], s32 unk6, s32 unk7 ) {
                // Call replacement function
                item = global::modPtr->procItemCreateFunc( pos, item, "createItemForMidBoss" );

                return global::modPtr->createItemForMidBoss_trampoline( pos, item, unk3, unk4, unk5, unk6, unk7 );
            } );

        createItemForDirectGet_trampoline = patch::hookFunction(
            tp::f_op_actor_mng::createItemForDirectGet,
            []( const float pos[3], s32 item, s32 unk3, const float unk4[3], const float unk5[3], float unk6, float unk7 ) {
                // Call replacement function
                item = global::modPtr->procItemCreateFunc( pos, item, "createItemForDirectGet" );

                return global::modPtr->createItemForDirectGet_trampoline( pos, item, unk3, unk4, unk5, unk6, unk7 );
            } );

        createItemForSimpleDemo_trampoline = patch::hookFunction(
            tp::f_op_actor_mng::createItemForSimpleDemo,
            []( const float pos[3], s32 item, s32 unk3, const float unk4[3], const float unk5[3], float unk6, float unk7 ) {
                // Call replacement function
                item = global::modPtr->procItemCreateFunc( pos, item, "createItemForSimpleDemo" );

                return global::modPtr->createItemForSimpleDemo_trampoline( pos, item, unk3, unk4, unk5, unk6, unk7 );
            } );

        evt_control_Skipper_trampoline = patch::hookFunction( tp::evt_control::skipper, []( void* evtPtr ) {
            return global::modPtr->procEvtSkipper( evtPtr );
        } );

        query022_trampoline = patch::hookFunction( tp::d_msg_flow::query022, []( void* unk1, void* unk2, s32 unk3 ) {
            return global::modPtr->proc_query022( unk1, unk2, unk3 );
        } );

        query023_trampoline = patch::hookFunction( tp::d_msg_flow::query023, []( void* unk1, void* unk2, s32 unk3 ) {
            return global::modPtr->proc_query023( unk1, unk2, unk3 );
        } );

        query024_trampoline = patch::hookFunction(
            tp::d_msg_flow::query024,
            []( void* dMsgFlow_cPtr, void* mesg_flow_node_branchPtr, void* fopAc_ac_cPtr, int unused ) {
                return global::modPtr->proc_query024( dMsgFlow_cPtr, mesg_flow_node_branchPtr, fopAc_ac_cPtr, unused );
            } );

        query025_trampoline = patch::hookFunction( tp::d_msg_flow::query025, []( void* unk1, void* unk2, s32 unk3 ) {
            return global::modPtr->proc_query025( unk1, unk2, unk3 );
        } );

        isEventBit_trampoline = patch::hookFunction( tp::d_save::isEventBit, []( u8* eventSystem, u16 indexNumber ) {
            return global::modPtr->proc_isEventBit( eventSystem, indexNumber );
        } );

        onEventBit_trampoline = patch::hookFunction( tp::d_save::onEventBit, []( u8* eventSystem, u16 indexNumber ) {
            if ( indexNumber == 0x1E08 && ( gameInfo.scratchPad.form == 1 ) )
            {
                gameInfo.scratchPad.form = 0;
            }
            return global::modPtr->onEventBit_trampoline( eventSystem, indexNumber );
        } );

        setGetItemFace_trampoline = patch::hookFunction( tp::d_a_alink::setGetItemFace, []( void* daAlink_c, u16 itemId ) {
            switch ( itemId )
            {
                case items::Shadow_Crystal:
                {
                    itemId = items::Clawshot;
                    break;
                }
                case items::Master_Sword:
                {
                    itemId = items::Clawshot;
                    break;
                }
                case items::Master_Sword_Light:
                {
                    itemId = items::Clawshot;
                    break;
                }
                default:
                {
                    return global::modPtr->setGetItemFace_trampoline( daAlink_c, itemId );
                }
            }
            return global::modPtr->setGetItemFace_trampoline( daAlink_c, itemId );
        } );

        do_link_trampoline = patch::hookFunction( tp::dynamic_link::do_link, []( tp::dynamic_link::DynamicModuleControl* dmc ) {
            return global::modPtr->procDoLink( dmc );
        } );

        item_func_UTUWA_HEART_trampoline = patch::hookFunction( tp::d_item::item_func_UTUWA_HEART,
                                                                []() { return global::modPtr->procItem_func_UTUWA_HEART(); } );

        setItemBombNumCount_trampoline =
            patch::hookFunction( tp::d_com_inf_game::setItemBombNumCount, []( u32 unk1, u8 bagNb, short amount ) {
                u8 bombtype = 0;
                if ( bagNb == 0 )
                {
                    bombtype = gameInfo.scratchPad.itemWheel.Bomb_Bag_1;
                }
                else if ( bagNb == 1 )
                {
                    bombtype = gameInfo.scratchPad.itemWheel.Bomb_Bag_2;
                }
                else if ( bagNb == 2 )
                {
                    bombtype = gameInfo.scratchPad.itemWheel.Bomb_Bag_3;
                }
                char txt[50];
                snprintf( txt, 50, "bag = %x amount = %d type = %x", bagNb, amount, bombtype );
                strcpy( sysConsolePtr->consoleLine[20].line, txt );
                return global::modPtr->setItemBombNumCount_trampoline( unk1, bagNb, amount );
            } );
        isDungeonItem_trampoline = patch::hookFunction( tp::d_save::isDungeonItem, []( void* memBitPtr, const int param_1 ) {
            return global::modPtr->proc_isDungeonItem( memBitPtr, param_1 );
        } );

        getLayerNo_common_common_trampoline = patch::hookFunction(
            tp::d_com_inf_game::getLayerNo_common_common,
            []( const char* stageName, int roomId, int layerOverride ) {
                int chosenLayer;
                bool condition;
                // Bublin Camp
                bool stageComparison = strcmp( stageName, "F_SP118" );
                if ( stageComparison == 0 )
                {
                    condition = tp::d_a_alink::dComIfGs_isEventBit( 0xb40 );     // Escaped Burning Tent in Bublin Camp
                    if ( condition != false )
                    {
                        if (tp::d_kankyo::env_light.currentRoom == 3)
                        {
                            chosenLayer = 0x1;
                        }
                        else
                        {
                            chosenLayer = 0x3;
                        }
                    }
                    else
                    {
                        chosenLayer = 0x0;
                    }
                    return chosenLayer;
                }
                stageComparison = strcmp( stageName, "F_SP117" );
                if ( ( stageComparison == 0 ) && ( Singleton::getInstance()->isEarlyToTEnabled == 1 ) )
                {
                    chosenLayer = 0x2;
                    return chosenLayer;
                }
                return global::modPtr->getLayerNo_common_common_trampoline( stageName, roomId, layerOverride );
            } );

        setMessageCode_inSequence_trampoline = patch::hookFunction(
            tp::control::setMessageCode_inSequence,
            []( tp::control::TControl* control, const void* TProcessor, u16 unk3, u16 msgId ) {
                // Call the original function immediately, as a lot of stuff needs to be set before our code runs
                const bool ret = global::modPtr->setMessageCode_inSequence_trampoline( control, TProcessor, unk3, msgId );

                // Make sure the function ran successfully
                if ( !ret )
                {
                    return ret;
                }

                // Check if the current text is for an item
                s32 index = global::modPtr->getItemIdFromMsgId( TProcessor, unk3, msgId );
                // The current text is for an item
                switch ( static_cast<u32>( index ) )
                {
                    const char* replacementText;
                    case items::Forest_Temple_Small_Key:
                    {
                        replacementText = customMessage::customForestSKText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Forest_Temple_Dungeon_Map:
                    {
                        replacementText = customMessage::customForestMapText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Forest_Temple_Compass:
                    {
                        replacementText = customMessage::customForestCompassText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Forest_Temple_Big_Key:
                    {
                        replacementText = customMessage::customForestBigKeyText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }

                    case items::Goron_Mines_Small_Key:
                    {
                        replacementText = customMessage::customMinesSKText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Goron_Mines_Dungeon_Map:
                    {
                        replacementText = customMessage::customMinesMapText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Goron_Mines_Compass:
                    {
                        replacementText = customMessage::customMinesCompassText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }

                    case items::Lakebed_Temple_Small_Key:
                    {
                        replacementText = customMessage::customLakebedSKText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Lakebed_Temple_Dungeon_Map:
                    {
                        replacementText = customMessage::customLakebedMapText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Lakebed_Temple_Compass:
                    {
                        replacementText = customMessage::customLakebedCompassText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Lakebed_Temple_Big_Key:
                    {
                        replacementText = customMessage::customLakebedBigKeyText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }

                    case items::Arbiters_Grounds_Small_Key:
                    {
                        replacementText = customMessage::customArbitersSKText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Arbiters_Grounds_Dungeon_Map:
                    {
                        replacementText = customMessage::customArbitersMapText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Arbiters_Grounds_Compass:
                    {
                        replacementText = customMessage::customArbitersCompassText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Arbiters_Grounds_Big_Key:
                    {
                        replacementText = customMessage::customArbitersBigKeyText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }

                    case items::Snowpeak_Ruins_Small_Key:
                    {
                        replacementText = customMessage::customSnowpeakSKText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Snowpeak_Ruins_Dungeon_Map:
                    {
                        replacementText = customMessage::customSnowpeakMapText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Snowpeak_Ruins_Compass:
                    {
                        replacementText = customMessage::customSnowpeakCompassText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }

                    case items::Temple_of_Time_Small_Key:
                    {
                        replacementText = customMessage::customToTSKText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Temple_of_Time_Dungeon_Map:
                    {
                        replacementText = customMessage::customToTMapText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Temple_of_Time_Compass:
                    {
                        replacementText = customMessage::customToTCompassText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Temple_of_Time_Big_Key:
                    {
                        replacementText = customMessage::customToTBigKeyText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }

                    case items::City_in_The_Sky_Small_Key:
                    {
                        replacementText = customMessage::customCitySKText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::City_in_The_Sky_Dungeon_Map:
                    {
                        replacementText = customMessage::customCityMapText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::City_in_The_Sky_Compass:
                    {
                        replacementText = customMessage::customCityCompassText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::City_in_The_Sky_Big_Key:
                    {
                        replacementText = customMessage::customCityBigKeyText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }

                    case items::Palace_of_Twilight_Small_Key:
                    {
                        replacementText = customMessage::customPalaceSKText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Palace_of_Twilight_Dungeon_Map:
                    {
                        replacementText = customMessage::customPalaceMapText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Palace_of_Twilight_Compass:
                    {
                        replacementText = customMessage::customPalaceCompassText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Palace_of_Twilight_Big_Key:
                    {
                        replacementText = customMessage::customPalaceBigKeyText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }

                    case items::Hyrule_Castle_Small_Key:
                    {
                        replacementText = customMessage::customCastleSKText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Hyrule_Castle_Dungeon_Map:
                    {
                        replacementText = customMessage::customCastleMapText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Hyrule_Castle_Compass:
                    {
                        replacementText = customMessage::customCastleCompassText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Hyrule_Castle_Big_Key:
                    {
                        replacementText = customMessage::customCastleBigKeyText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Shadow_Crystal:
                    {
                        replacementText = customMessage::customCrystalText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }

                    case items::Ending_Blow:
                    {
                        replacementText = customMessage::endingBlowText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Shield_Attack:
                    {
                        replacementText = customMessage::shieldAttackText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Back_Slice:
                    {
                        replacementText = customMessage::backSliceText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Helm_Splitter:
                    {
                        replacementText = customMessage::helmSplitterText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Mortal_Draw:
                    {
                        replacementText = customMessage::mortalDrawText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Jump_Strike:
                    {
                        replacementText = customMessage::jumpStrikeText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }
                    case items::Great_Spin:
                    {
                        replacementText = customMessage::greatSpinText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }

                    case items::Item::Bublin_Camp_Key:
                    {
                        replacementText = customMessage::customBublinSKText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }

                    case items::Dominion_Rod_Uncharged:
                    {
                        replacementText = customMessage::customPoweredRodText;
                        control->msg = replacementText;
                        control->wMsgRender = replacementText;
                        break;
                    }

                    default:
                    {
                        break;
                    }
                }

                return ret;
            } );

        getFontCCColorTable_trampoline = patch::hookFunction( tp::d_msg_class::getFontCCColorTable, []( u8 colorId, u8 unk ) {
            if ( colorId >= 0x9 )
            {
                return global::modPtr->getCustomMsgColor( colorId );
            }
            else
            {
                return global::modPtr->getFontCCColorTable_trampoline( colorId, unk );
            }
        } );

        getFontGCColorTable_trampoline = patch::hookFunction( tp::d_msg_class::getFontGCColorTable, []( u8 colorId, u8 unk ) {
            if ( colorId >= 0x9 )
            {
                return global::modPtr->getCustomMsgColor( colorId );
            }
            else
            {
                return global::modPtr->getFontGCColorTable_trampoline( colorId, unk );
            }
        } );

        checkItemGet_trampoline = patch::hookFunction( tp::d_item::checkItemGet, []( u8 item, s32 defaultValue ) {
            return global::modPtr->proc_checkItemGet( item, defaultValue );
        } );

        parseCharacter1Byte_trampoline = patch::hookFunction( tp::resource::parseCharacter_1Byte, []( const char** text ) {
            const char* bigWalletRupeeText = { "600 Rupees" MSG_COLOR( MSG_COLOR_WHITE ) "!" };
            const char* giantWalletRupeeText = { "1,000 Rupees" MSG_COLOR( MSG_COLOR_WHITE ) "!" };
            const char* pauseWalletRupeeText = { "1,000 Rupees." };

            if ( strncmp( *text, bigWalletRupeeText, strlen( bigWalletRupeeText ) ) == 0 )
            {
                // Replacement text
                const char* replacementText = { "5,000 Rupees" MSG_COLOR( MSG_COLOR_WHITE ) "!" };
                *text = replacementText;
            }
            if ( strncmp( *text, giantWalletRupeeText, strlen( giantWalletRupeeText ) ) == 0 )
            {
                // Replacement text
                const char* replacementText = { "9,999 Rupees" MSG_COLOR( MSG_COLOR_WHITE ) "!" };
                *text = replacementText;
            }
            else if ( strncmp( *text, pauseWalletRupeeText, strlen( pauseWalletRupeeText ) ) == 0 )
            {
                // Replacement text
                switch ( gameInfo.scratchPad.equippedWallet )
                {
                    case 0x0:
                    {
                        const char* replacementText = { "1,000 Rupees." };
                        *text = replacementText;
                        break;
                    }
                    case 0x1:
                    {
                        const char* replacementText = { "5,000 Rupees." };
                        *text = replacementText;
                        break;
                    }
                    case 0x2:
                    {
                        const char* replacementText = { "9,999 Rupees." };
                        *text = replacementText;
                        break;
                    }
                }
            }

            return global::modPtr->parseCharacter1Byte_trampoline( text );
        } );
    }

    void Mod::procNewFrame()
    {
        float linkPos[3];
        getPlayerPos( linkPos );

        if ( coordsAreInHex == 1 )
        {
            typeTransform<float, u32> x = { linkPos[0] };
            typeTransform<float, u32> y = { linkPos[1] };
            typeTransform<float, u32> z = { linkPos[2] };

            snprintf( currentPosX, 30, "%04x", x.b );
            snprintf( currentPosY, 30, "%04x", y.b );
            snprintf( currentPosZ, 30, "%04x", z.b );

            snprintf( linkAngle, 30, "%02x", static_cast<u16>( tp::d_map_path_dmap::getMapPlayerAngleY() ) );
        }
        else
        {
            snprintf( currentPosX, 30, "%f", linkPos[0] );
            snprintf( currentPosY, 30, "%f", linkPos[1] );
            snprintf( currentPosZ, 30, "%f", linkPos[2] );

            snprintf( linkAngle, 30, "%d", static_cast<u16>( tp::d_map_path_dmap::getMapPlayerAngleY() ) );
        }

        if ( gameInfo.nextStageVars.nextSpawnPoint != 0xFF )
        {
            lastGoodSpawn = gameInfo.nextStageVars.nextSpawnPoint;
        }

        if ( gameInfo.ColorPtr != nullptr )
        {
            if ( topToggle == 0 )
            {
                gameInfo.ColorPtr->redTopToggle = 0x4;
                gameInfo.ColorPtr->greenTopToggle = 0x4;
                gameInfo.ColorPtr->blueTopToggle = 0x4;
            }
            else
            {
                gameInfo.ColorPtr->redTopToggle = 0x0;
                gameInfo.ColorPtr->greenTopToggle = 0x0;
                gameInfo.ColorPtr->blueTopToggle = 0x0;
            }
            gameInfo.ColorPtr->redTop = redTop;
            gameInfo.ColorPtr->greenTop = greenTop;
            gameInfo.ColorPtr->blueTop = blueTop;
            if ( bottomToggle == 0 )
            {
                gameInfo.ColorPtr->redBottomToggle = 0x4;
                gameInfo.ColorPtr->greenBottomToggle = 0x4;
                gameInfo.ColorPtr->blueBottomToggle = 0x4;
            }
            else
            {
                gameInfo.ColorPtr->redBottomToggle = 0x0;
                gameInfo.ColorPtr->greenBottomToggle = 0x0;
                gameInfo.ColorPtr->blueBottomToggle = 0x0;
            }
            gameInfo.ColorPtr->redBottom = redBottom;
            gameInfo.ColorPtr->greenBottom = greenBottom;
            gameInfo.ColorPtr->blueBottom = blueBottom;
            /*u16 last14 = 0;
            for(colorResult = 0x0; colorResult < 0x6000; colorResult++)
            {

                    if (gameInfo.ColorPtr->unk_0[colorResult] == 0x14)
                    {
                            if (colorResult - last14 == 8)
                            {
                                    break;
                            }
                            else
                            {
                                    last14 = colorResult;
                            }
                    }
            }*/
        }

        if ( trigerLoadSave == 1 )
        {
            trigerLoadSave = 0;
            tools::triggerSaveLoad( stage::allStages[stage], room, spawn, state );
        }

        if ( !tools::checkItemFlag( ItemFlags::Orange_Rupee ) )
        {     // remove the item get animations for floor pickups (except silver rupee)
            u32 loopAmount = sizeof( item::itemGetAnimationFlags ) / sizeof( item::itemGetAnimationFlags[0] );
            for ( u32 i = 0; i < loopAmount; i++ )
            {
                tools::setItemFlag( static_cast<ItemFlags>( item::itemGetAnimationFlags[i] ) );
            }
        }

        if ( enableNormalTime == 0 && setDay == 0 )
        {     // set night
            gameInfo.scratchPad.skyAngle = 0;
        }
        else if ( enableNormalTime == 0 && setDay == 1 )
        {     // set day
            gameInfo.scratchPad.skyAngle = 180;
        }
        // Increment seed
        if ( !customSeed )
        {
            tools::getRandom( 0 );
        }

        // If loading has started check for LoadEvents
        if ( isLoading )
        {
            eventListener->checkLoadEvents();

            // Check if there's a random seed in the current save data
            if ( ( *global::seedInSaveFile > 0 ) && ( *global::seedInSaveFile != tools::randomSeed ) )
            {
                customSeed = 1;
                tools::randomSeed = *global::seedInSaveFile;
                chestRandomizer->generate();
                musicrando::initMusicRando();
            }
        }

        if ( controller::checkForButtonInputSingleFrame(
                 ( controller::PadInputs::Button_R | controller::PadInputs::Button_Z ) ) )
        {
            // Toggle console
            system_console::setState( !sysConsolePtr->consoleEnabled, 0 );
        }

        if ( controller::checkForButtonInputSingleFrame( controller::PadInputs::Button_R | controller::PadInputs::Button_Y ) )
        {
            if ( canQuickTransform() )
            {
                // Transform
                tp::d_a_alink::procCoMetamorphoseInit( gameInfo.linkMapPtr );
            }
        }

        if ( canChangeToD() &&
             controller::checkForButtonInputSingleFrame( controller::PadInputs::Button_R | controller::PadInputs::Button_Y ) )
        {
            if ( gameInfo.scratchPad.skyAngle >= 105 && gameInfo.scratchPad.skyAngle <= 284 )
            {
                gameInfo.scratchPad.skyAngle = 285;
                if ( gameInfo.nextStageVars.nextSpawnPoint == 0xFF )
                {
                    gameInfo.nextStageVars.nextSpawnPoint = lastGoodSpawn;
                }
                gameInfo.nextStageVars.triggerLoad |= 1;
            }
            else if ( gameInfo.scratchPad.skyAngle >= 285 || gameInfo.scratchPad.skyAngle <= 104 )
            {
                gameInfo.scratchPad.skyAngle = 105;
                if ( gameInfo.nextStageVars.nextSpawnPoint == 0xFF )
                {
                    gameInfo.nextStageVars.nextSpawnPoint = lastGoodSpawn;
                }
                gameInfo.nextStageVars.triggerLoad |= 1;
            }
        }

        if ( sysConsolePtr->consoleEnabled )
        {
            if ( controller::checkForButtonInputSingleFrame(
                     ( controller::PadInputs::Button_R | controller::PadInputs::Button_Start ) ) )
            {
                // Check if we have a seed sitting in our save file somewhere and if so, apply this automatically (unless custom
                // seed is turned on)

                if ( !customSeed && ( *global::seedInSaveFile > 0 ) &&
                     !tp::d_a_alink::checkStageName( stage::allStages[Stage_Title_Screen] ) )
                {
                    tools::randomSeed = *global::seedInSaveFile;
                }

                // In case this person hasn't started the run through the load event earlier we still have to store this seed
                // manually in the save data
                *global::seedInSaveFile = tools::randomSeed;
                chestRandomizer->generate();
                musicrando::initMusicRando();
            }

            // Parse inputs of this frame
            switch ( tp::m_do_controller_pad::cpadInfo.buttonInputTrg )
            {
                case controller::PadInputs::Button_A:
                    hudConsole->performAction( ConsoleActions::Option_Increase );
                    break;

                case controller::PadInputs::Button_X:
                    hudConsole->performAction( ConsoleActions::Option_Increase, 0x10 );
                    break;

                case controller::PadInputs::Button_B:
                    hudConsole->performAction( ConsoleActions::Option_Decrease );
                    break;

                case controller::PadInputs::Button_Y:
                    hudConsole->performAction( ConsoleActions::Option_Decrease, 0x10 );
                    break;

                case controller::PadInputs::Button_DPad_Up:
                    hudConsole->performAction( ConsoleActions::Move_Up );
                    break;

                case controller::PadInputs::Button_DPad_Down:
                    hudConsole->performAction( ConsoleActions::Move_Down );
                    break;

                case controller::PadInputs::Button_DPad_Left:
                    hudConsole->performAction( ConsoleActions::Move_Left );
                    break;

                case controller::PadInputs::Button_DPad_Right:
                    hudConsole->performAction( ConsoleActions::Move_Right );
                    break;
            }
            hudConsole->draw();
        }

        if ( truePause && sysConsolePtr->consoleEnabled )
        {
            // Inputs handled, don't pass onto the game
            tp::f_op_scene_req::freezeActors = 1;
            tp::m_do_controller_pad::cpadInfo.buttonInputTrg = 0;
            tp::m_do_controller_pad::cpadInfo.buttonInput = 0;
        }
        else
        {
            tp::f_op_scene_req::freezeActors = 0;
        }

        if ( itemSearchID != lastItemSearchID )
        {
            lastItemSearchID = itemSearchID;

            strcpy( itemSearchResults, "404" );

            for ( u16 i = 0; i < chestRandomizer->totalChecks; i++ )
            {
                item::ItemCheck* check = &item::checks[i];
                if ( check->destination )
                {
                    if ( check->destination->itemID == itemSearchID )
                    {
                        // Found the source
                        snprintf( itemSearchResults,
                                  40,
                                  "ID: %x Stage: %s Room: %d",
                                  check->itemID,
                                  check->stage,
                                  check->room );
                    }
                }
            }
        }
        else if ( itemReverseSearchID != lastItemReverseSearchID )
        {
            lastItemReverseSearchID = itemReverseSearchID;

            strcpy( itemReverseSearchResults, "404" );

            for ( u16 i = 0; i < chestRandomizer->totalChecks; i++ )
            {
                item::ItemCheck* check = &item::checks[i];
                if ( check->source )
                {
                    if ( check->source->itemID == itemReverseSearchID )
                    {
                        // Found the source
                        snprintf( itemReverseSearchResults,
                                  40,
                                  "ID: %x Stage: %s Room: %d",
                                  check->itemID,
                                  check->stage,
                                  check->room );
                    }
                }
            }
        }

        if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Faron_Woods] ) )
        {
            if ( 0xB == gameInfo.eventSystem.currentEventID )
            {
                tools::setCutscene( false, false );
                if ( frame_counter == num_frames )
                {
                    tools::setItemFlag(
                        ItemFlags::Vessel_Of_Light_Faron );     // set flag for vessel since we'll skip it by reloading
                    gameInfo.scratchPad.movingActors.exploredRegions.Eldin =
                        0b1;     // Set Eldin Map Unlocked so we can warp there
                    tools::setCutscene( true, false );
                }
                else
                {
                    frame_counter++;
                }
            }
            else
            {
                frame_counter = 0;
            }
        }
        checkSearchID = ( checkSearchID2 * 0x100 ) + checkSearchID1;
        checkReverseSearchID = ( checkReverseSearchID2 * 0x100 ) + checkReverseSearchID1;
        if ( checkSearchID != lastCheckSearchID )
        {
            lastCheckSearchID = checkSearchID;

            strcpy( checkSearchResults, "404" );
            if ( checkSearchID < chestRandomizer->totalChecks )
            {
                item::ItemCheck* check = &item::checks[checkSearchID];
                if ( check->source )
                {
                    snprintf( checkSearchResults,
                              40,
                              "ID: %x Stage: %s Room: %d",
                              check->source->itemID,
                              check->source->stage,
                              check->source->room );
                }
            }
        }
        else if ( checkReverseSearchID != lastCheckReverseSearchID )
        {
            lastCheckReverseSearchID = checkReverseSearchID;

            strcpy( checkReverseSearchResults, "404" );

            if ( checkReverseSearchID < chestRandomizer->totalChecks )
            {
                item::ItemCheck* check = &item::checks[checkReverseSearchID];
                if ( check->destination )
                {
                    snprintf( checkReverseSearchResults,
                              40,
                              "ID: %x Stage: %s Room: %d",
                              check->destination->itemID,
                              check->destination->stage,
                              check->destination->room );
                }
            }
        }

        /*if (gameInfo.scratchPad.unk_0[0x019] == 0)
        {
                const char* walletText = "Wallet";
                strncpy(tp::d_com_inf_game::wallet_text, walletText, sizeof(tp::d_com_inf_game::wallet_text) - 1);

                const char* walletDescription = "A wallet from your childhood. It holds up to 1,000 Rupees.";
                strncpy(tp::d_com_inf_game::wallet_description, walletDescription,
        sizeof(tp::d_com_inf_game::wallet_description) - 1);
        }
        else if (gameInfo.scratchPad.unk_0[0x019] == 1)
        {
                const char* walletText = "Big Wallet";
                strncpy(tp::d_com_inf_game::wallet_text, walletText, sizeof(tp::d_com_inf_game::wallet_text) - 1);

                const char* walletDescription = "A wallet given to you by Agitha, princess of the insect kingdom. It can hold
        5,000 Rupees."; strncpy(tp::d_com_inf_game::wallet_description, walletDescription,
        sizeof(tp::d_com_inf_game::wallet_description) - 1);
        }
        else if (gameInfo.scratchPad.unk_0[0x019] == 2)
        {
                const char* walletText = "Giant Wallet";
                strncpy(tp::d_com_inf_game::wallet_text, walletText, sizeof(tp::d_com_inf_game::wallet_text) - 1);

                const char* walletDescription = "The wallet given by Agitha to benefactors of the insect kingdom. It can hold up
        to 9,999 Rupees."; strncpy(tp::d_com_inf_game::wallet_description, walletDescription,
        sizeof(tp::d_com_inf_game::wallet_description) - 1);
        }*/

        if ( inputBuffering )
        {
            tp::m_do_controller_pad::cpadInfo.buttonInputTrg = tp::m_do_controller_pad::cpadInfo.buttonInput;
        }

        giveAllStoryItems();

        reorderItemWheel();

        giveAllScents();

        fixYetaAndYeto();

        preventPoweringUpDomRod();

        // Call original function
        fapGm_Execute_trampoline();

        changeLanternColor();
    }

    s32 Mod::procItemCreateFunc( const float pos[3], s32 item, const char funcIdentifier[32] )
    {
        strcpy( lastItemFunc, funcIdentifier );
        snprintf( lastItemDataID, 5, "0x%02x", item );
        snprintf( lastItemDataX, 30, "%f", pos[0] );
        snprintf( lastItemDataY, 30, "%f", pos[1] );
        snprintf( lastItemDataZ, 30, "%f", pos[2] );
        // Runs once when Link picks up an item with text and is holding it towards the camera
        if ( randoEnabled && strcmp( funcIdentifier, "createItemForDirectGet" ) != 0 &&
             strcmp( funcIdentifier, "createItemForBoss" ) != 0 && strcmp( funcIdentifier, "createItemForMidBoss" ) != 0 &&
             strcmp( funcIdentifier, "createItemForSimpleDemo" ) != 0 )
        {
            item = chestRandomizer->getItemReplacement( pos, item );
        }

        return item;
    }

    bool Mod::procCheckTreasureRupeeReturn( void* unk1, s32 item )
    {
        // Allow to open
        return false;
    }

    s32 Mod::procEvtSkipper( void* evtPtr )
    {
        // Runs when the user tries to skip a Cutscene
        if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Sacred_Grove] ) )
        {
            // We're at sacred grove
            if ( 0x2 == gameInfo.eventSystem.currentEventID )
            {
                // Master Sword cutscene
                tools::setCutscene( true, false, cutscene_skip::onMasterSwordSkip );
            }
        }

        // Call original function
        return evt_control_Skipper_trampoline( evtPtr );
    }

    bool Mod::proc_query022( void* unk1, void* unk2, s32 unk3 )
    {
        // Check to see if currently in one of the Ordon interiors
        if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Ordon_Interiors] ) )
        {
            // Check to see if ckecking for the Iron Boots
            u16 item = *reinterpret_cast<u16*>( reinterpret_cast<u32>( unk2 ) + 0x4 );

            if ( item == items::Item::Iron_Boots )
            {
                // Return false so that the door in Bo's house can be opened without having the Iron Boots
                return false;
            }
        }

        // Call original function
        return query022_trampoline( unk1, unk2, unk3 );
    }

    bool Mod::proc_query023( void* unk1, void* unk2, s32 unk3 )
    {
        // Check to see if currently in the Kakariko Interiors. Specifically in Barnes' Bomb Shop
        if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Kakariko_Interiors] ) &&
             tp::d_kankyo::env_light.currentRoom == 1 )
        {
            // If player has not bought Barnes' Bomb Bag, we want to allow them to be able to get the check.
            if ( ( !tp::d_a_alink::dComIfGs_isEventBit( 0x908 ) ) )
            {
                return false;
            }
            // If the player has bought the bomb bag check, we won't allow them to get the check, regardless of if they have
            // bombs or not
            else
            {
                return true;
            }
        }

        // Call original function if the conditions aren't met.
        return query023_trampoline( unk1, unk2, unk3 );
    }

    bool Mod::proc_query024( void* dMsgFlow_cPtr, void* mesg_flow_node_branchPtr, void* fopAc_ac_cPtr, int unused )
    {
        // Check to see if currently in the Castle Town. Specifically in the central square
        if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Castle_Town] ) && tp::d_kankyo::env_light.currentRoom == 0 )
        {
            return true;     // Allow the player to buy arrows, even if the quiver is full
        }
        // Call original function if the conditions aren't met.
        return query024_trampoline( dMsgFlow_cPtr, mesg_flow_node_branchPtr, fopAc_ac_cPtr, unused );
    }

    bool Mod::proc_query025( void* unk1, void* unk2, s32 unk3 )
    {
        // Check to see if currently in a shop and that we have the bottle requirement enabled
        if ( isStageShop() && ( allowBottleItemsShopAnytime == 1 ) )
        {
            // Tell the game that we have an empty bottle, even if we don't
            return false;
        }
        // Call original function if the conditions aren't met.
        return query025_trampoline( unk1, unk2, unk3 );
    }

    bool Mod::proc_isDungeonItem( void* memBitPtr, const int param_1 )
    {
        u32 totalMainDungeonStages = sizeof( stage::mainDungeonStages ) / sizeof( stage::mainDungeonStages[0] );
        for ( u32 i = 0; i < totalMainDungeonStages; i++ )
        {
            if ( tp::d_a_alink::checkStageName( stage::mainDungeonStages[i] ) && ( param_1 == 3 ) )
            {
                if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Forest_Temple] ) && ( param_1 == 7 ) &&
                     ( ( tp::d_kankyo::env_light.currentRoom == 3 ) || ( tp::d_kankyo::env_light.currentRoom == 1 ) ) )
                {
                    return false;
                }
                return false;
            }
        }

        // Call original function
        return isDungeonItem_trampoline( memBitPtr, param_1 );
    }

    bool Mod::proc_isEventBit( u8* eventSystem, u16 indexNumber )
    {
        if ( ( ( indexNumber == 0x2280 ) || ( indexNumber == 0x2320 ) || ( indexNumber == 0x3E02 ) ) &&
             tp::d_a_alink::checkStageName( stage::allStages[Stage_Hidden_Village] ) )
        {
            if ( ( ( gameInfo.scratchPad.eventBits[0x22] & 0x80 ) == 0 ) )
            {
                return false;
            }
        }
        else if ( Singleton::getInstance()->isEarlyHCEnabled == 0 && ( indexNumber == 0x5410 ) &&
                  ( ( gameInfo.scratchPad.allAreaNodes.Palace_of_Twilight.dungeon.bossBeaten == 0 ) ) )
        {
            return false;
        }

        else
        {
            u32 totalAllDungeonStages = sizeof( stage::allDungeonStages ) / sizeof( stage::allDungeonStages[0] );
            u32 totalStageFlags = sizeof( game_patch::dungeonStoryFlags ) / sizeof( game_patch::dungeonStoryFlags[0] );
            for ( u32 i = 0; i < totalAllDungeonStages; i++ )
            {
                if ( tp::d_a_alink::checkStageName( stage::allDungeonStages[i] ) )
                {
                    for ( u32 j = 0; j < totalStageFlags; j++ )
                    {
                        if ( indexNumber == game_patch::dungeonStoryFlags[j] )
                        {
                            if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Zant_Main] ) &&
                                 ( gameInfo.localAreaNodes.dungeon.bossBeaten != 0 ) )
                            {
                                return isEventBit_trampoline( eventSystem, indexNumber );
                            }
                            return false;
                        }
                    }
                }
            }
        }

        // Call original function
        return isEventBit_trampoline( eventSystem, indexNumber );
    }

    bool Mod::procDoLink( tp::dynamic_link::DynamicModuleControl* dmc )
    {
        // Call the original function immediately, as the REL file needs to be linked before applying patches
        const bool result = do_link_trampoline( dmc );

        // Get the pointer to the current REL file
        gc::OSModule::OSModuleInfo* moduleInfo = dmc->moduleInfo;

        // Make sure a REL file is actually loaded, as do_link will clear the pointer if something goes wrong
        if ( !moduleInfo )
        {
            return result;
        }

        // Get the REL pointer as a raw u32, to use for overwrites
        u32 relPtrRaw = reinterpret_cast<u32>( moduleInfo );

        // Modify the current REL file
        switch ( moduleInfo->id )     // May want to set up enums or defines for the module ids
        {
            case 0x121:     // d_a_npc_bouS.rel - Inside Bo's house
            {
                // Prevent Bo from talking after the chest has been opened
                *reinterpret_cast<u32*>( relPtrRaw + 0x1A44 ) = 0x48000028;     // b 0x28
                break;
            }
            case 0x280:     // d_a_obj_swBallC.rel - Light Sword Cutscene
            {
                item::ItemCheck* itemCheck = &item::checks[495];     // Light Sword Item
                // Check if the item has a replacement
                if ( itemCheck->destination )
                {
                    // Replace Item given
                    *reinterpret_cast<u32*>( relPtrRaw + 0xC10 ) =
                        SET_LOAD_IMMEDIATE( 3, itemCheck->destination->itemID );     // 38600000 + item ID
                    // Replace Item Get text
                    *reinterpret_cast<u32*>( relPtrRaw + 0xCD8 ) = SET_LOAD_IMMEDIATE(
                        3,
                        ( itemCheck->destination->itemID + 0x65 ) );     // 38600000 + item index (item ID + 0x65)
                }

                // The cutscene gives link the MS during the cutscene by default, so we just nop out the link to the function.
                *reinterpret_cast<u32*>( relPtrRaw + 0xB50 ) = 0x60000000;
                break;
            }
            case 0x1FA:     // d_a_obj_kshutter.rel - Doors that do not cause a cutscene after opened
            {
                if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Lakebed_Temple] ) &&
                     ( tp::d_kankyo::env_light.currentRoom == 3 ) )
                {
                    // Set it to not remove a small key from the inventory when opening the boss door
                    *reinterpret_cast<u32*>( relPtrRaw + 0x1198 ) = 0x60000000;     // Previous: 0x3803ffff
                }
                break;
            }
            case 0x13F:     // d_a_npc_impal.rel - Impaz
            {
                item::ItemCheck* itemCheck1 = &item::checks[327];     // Ilia's Charm Item
                item::ItemCheck* itemCheck2 = &item::checks[466];     // Empty Skybook Item
                // Replace the Ilias Charm item
                *reinterpret_cast<u32*>( relPtrRaw + 0x2D98 ) =
                    SET_LOAD_IMMEDIATE( 4, itemCheck1->destination->itemID );     // 38800000 + item ID
                // Replace the Ancient Skybook Item
                *reinterpret_cast<u32*>( relPtrRaw + 0x3240 ) =
                    SET_LOAD_IMMEDIATE( 4, itemCheck2->destination->itemID );     // 38800000 + item ID

                break;
            }
            default:
            {
                break;
            }
        }

        return result;
    }

    void Mod::procItem_func_UTUWA_HEART()
    {
        /* Call the original function immediately, as the heart container flag
                for the current area needs to be set before making any adjustments */
        item_func_UTUWA_HEART_trampoline();

        // Clear the heart container flag if not currently in a boss room
        if ( !chestRandomizer->isStageBoss() )
        {
            gameInfo.localAreaNodes.dungeon.containerGotten = 0b0;
        }
    }

    s32 Mod::proc_checkItemGet( u8 item, s32 defaultValue )
    {
        // Check to see if currently in one of the Ordon interiors
        switch ( item )
        {
            case items::Hylian_Shield:
            {
                // Check if we are at Kakariko Malo mart and verify that we have not bought the shield.
                if ( ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Kakariko_Interiors] ) &&
                       tp::d_kankyo::env_light.currentRoom == 3 ) &&
                     ( ( gameInfo.localAreaNodes.unk_0[0xC] & 0x2 ) == 0 ) )
                {
                    // Return false so we can buy the shield.
                    return 0;
                }
                // Check if we are at Castle Town Goron Shops and verify that we have not bought the shield.
                // Since there is not a flag for this, we will just check if the randomizer has set a nullptr for the check.
                else if ( ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Castle_Town_Shops] ) &&
                            tp::d_kankyo::env_light.currentRoom == 4 ) )
                {
                    // Return false so we can buy the shield.
                    return 0;
                }
            }
            case items::Hawkeye:
            {
                // Check if we are at Kakariko Village and that the hawkeye is currently not for sale.
                if ( ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Kakariko_Village] ) &&
                       ( ( gameInfo.localAreaNodes.unk_0[0xC] & 0x40 ) == 0 ) ) )
                {
                    // Return false so we can buy the hawkeye.
                    return 0;
                }
            }
            case items::Ordon_Shield:
            {
                // Check if we are at Kakariko Malo mart.
                if ( ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Kakariko_Interiors] ) &&
                       tp::d_kankyo::env_light.currentRoom == 3 ) )
                {
                    // Return false so we can buy the wooden shield.
                    return 0;
                }
                // Check if we are at the Death Mountain Goron Shop.
                else if ( ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Death_Mountain] ) &&
                            tp::d_kankyo::env_light.currentRoom == 3 ) )
                {
                    // Return false so we can buy the shield.
                    return 0;
                }
            }
            case items::Wooden_Shield:
            {
                // Check if we are at Kakariko Malo mart.
                if ( ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Kakariko_Interiors] ) &&
                       tp::d_kankyo::env_light.currentRoom == 3 ) )
                {
                    // Return false so we can buy the wooden shield.
                    return 0;
                }
                // Check if we are at the Death Mountain Goron Shop.
                else if ( ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Death_Mountain] ) &&
                            tp::d_kankyo::env_light.currentRoom == 3 ) )
                {
                    // Return false so we can buy the shield.
                    return 0;
                }
            }
            default:
            {
                // Call original function if the conditions are not met.
                return global::modPtr->checkItemGet_trampoline( item, defaultValue );
            }
        }
    }

    void Mod::giveAllScents()
    {
        // code to have all scents at once you need to unlock them tho
        if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Hyrule_Field] ) )
        {
            if ( tools::checkItemFlag( ItemFlags::Youths_Scent ) && tp::d_kankyo::env_light.currentRoom == 3 )
            {
                gameInfo.scratchPad.equipedItems.scent = items::Item::Youths_Scent;
            }
            else if ( tools::checkItemFlag( ItemFlags::Ilias_Scent ) &&
                      ( tp::d_kankyo::env_light.currentRoom == 9 || tp::d_kankyo::env_light.currentRoom == 10 ) )
            {
                gameInfo.scratchPad.equipedItems.scent = items::Item::Ilias_Scent;
            }
        }
        else if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Kakariko_Village] ) )
        {
            if ( tools::checkItemFlag( ItemFlags::Youths_Scent ) )
            {
                gameInfo.scratchPad.equipedItems.scent = items::Item::Youths_Scent;
            }
        }
        else if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Outside_Castle_Town] ) )
        {
            if ( tools::checkItemFlag( ItemFlags::Ilias_Scent ) && tp::d_kankyo::env_light.currentRoom == 8 )
            {
                gameInfo.scratchPad.equipedItems.scent = items::Item::Ilias_Scent;
            }
        }
        else if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Castle_Town] ) )
        {
            if ( tools::checkItemFlag( ItemFlags::Medicine_Scent ) )
            {
                gameInfo.scratchPad.equipedItems.scent = items::Item::Medicine_Scent;
            }
            else if ( tools::checkItemFlag( ItemFlags::Ilias_Scent ) )
            {
                gameInfo.scratchPad.equipedItems.scent = items::Item::Ilias_Scent;
            }
        }
        else if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Zoras_Domain] ) ||
                  tp::d_a_alink::checkStageName( stage::allStages[Stage_Snowpeak] ) )
        {
            if ( tools::checkItemFlag( ItemFlags::Reekfish_Scent ) )
            {
                gameInfo.scratchPad.equipedItems.scent = items::Item::Reekfish_Scent;
            }
        }
        else if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Arbiters_Grounds] ) )
        {
            if ( tools::checkItemFlag( ItemFlags::Poe_Scent ) )
            {
                gameInfo.scratchPad.equipedItems.scent = items::Item::Poe_Scent;
            }
        }
        else
        {
            if ( tools::checkItemFlag( ItemFlags::Medicine_Scent ) )
            {
                gameInfo.scratchPad.equipedItems.scent = items::Item::Medicine_Scent;
            }
            else if ( tools::checkItemFlag( ItemFlags::Reekfish_Scent ) )
            {
                gameInfo.scratchPad.equipedItems.scent = items::Item::Reekfish_Scent;
            }
            else if ( tools::checkItemFlag( ItemFlags::Poe_Scent ) )
            {
                gameInfo.scratchPad.equipedItems.scent = items::Item::Poe_Scent;
            }
            else if ( tools::checkItemFlag( ItemFlags::Ilias_Scent ) )
            {
                gameInfo.scratchPad.equipedItems.scent = items::Item::Ilias_Scent;
            }
            else if ( tools::checkItemFlag( ItemFlags::Youths_Scent ) )
            {
                gameInfo.scratchPad.equipedItems.scent = items::Item::Youths_Scent;
            }
        }
    }

    void Mod::giveAllStoryItems()
    {
        if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Lake_Hylia] ) )
        {
            if ( tools::checkItemFlag( ItemFlags::Aurus_Memo ) )
            {
                gameInfo.scratchPad.itemWheel.Story = items::Item::Aurus_Memo;
            }
        }
        else if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Snowpeak] ) ||
                  tp::d_a_alink::checkStageName( stage::allStages[Stage_Zoras_Domain] ) )
        {
            if ( tools::checkItemFlag( ItemFlags::Asheis_Sketch ) )
            {
                gameInfo.scratchPad.itemWheel.Story = items::Item::Asheis_Sketch;
            }
        }
        else if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Kakariko_Graveyard] ) )
        {
            if ( tools::checkItemFlag( ItemFlags::Asheis_Sketch ) )
            {
                gameInfo.scratchPad.itemWheel.Story = items::Item::NullItem;
            }
        }
        else if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Kakariko_Interiors] ) &&
                  tp::d_kankyo::env_light.currentRoom == 0 )
        {
            if ( tools::checkItemFlag( ItemFlags::Ilias_Charm ) )
            {
                gameInfo.scratchPad.itemWheel.Story = items::Item::Ilias_Charm;
            }
            else if ( tools::checkItemFlag( ItemFlags::Wooden_Statue ) )
            {
                gameInfo.scratchPad.itemWheel.Story = items::Item::Wooden_Statue;
            }
            else if ( tools::checkItemFlag( ItemFlags::Renardos_Letter ) )
            {
                gameInfo.scratchPad.itemWheel.Story = items::Item::Renardos_Letter;
            }
        }
        else if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Outside_Castle_Town] ) &&
                  tp::d_kankyo::env_light.currentRoom == 3 )
        {
            if ( tools::checkItemFlag( ItemFlags::Wooden_Statue ) )
            {
                gameInfo.scratchPad.itemWheel.Story = items::Item::Wooden_Statue;
            }
        }
        else if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Castle_Town_Shops] ) &&
                  tp::d_kankyo::env_light.currentRoom == 2 )
        {
            if ( tools::checkItemFlag( ItemFlags::Invoice ) )
            {
                gameInfo.scratchPad.itemWheel.Story = items::Item::Invoice;
            }
        }
        else if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Castle_Town_Interiors] ) &&
                  tp::d_kankyo::env_light.currentRoom == 5 )
        {
            if ( tools::checkItemFlag( ItemFlags::Invoice ) )
            {
                gameInfo.scratchPad.itemWheel.Story = items::Item::Invoice;
            }
            else if ( tools::checkItemFlag( ItemFlags::Renardos_Letter ) )
            {
                gameInfo.scratchPad.itemWheel.Story = items::Item::Renardos_Letter;
            }
        }
        else if ( tp::d_a_alink::checkStageName( stage::allStages[Stage_Hidden_Village] ) ||
                  tp::d_a_alink::checkStageName( stage::allStages[Stage_Impaz_House] ) )
        {
            if ( tools::checkItemFlag( ItemFlags::Ilias_Charm ) )
            {
                gameInfo.scratchPad.itemWheel.Story = items::Item::Ilias_Charm;
            }
        }
        else
        {
            if ( tools::checkItemFlag( ItemFlags::Horse_Call ) )
            {     // finished Ilia Quest
                gameInfo.scratchPad.itemWheel.Story = items::Item::NullItem;
            }
            else if ( tools::checkItemFlag( ItemFlags::Ilias_Charm ) )
            {
                gameInfo.scratchPad.itemWheel.Story = items::Item::Ilias_Charm;
            }
            else if ( tools::checkItemFlag( ItemFlags::Wooden_Statue ) )
            {
                gameInfo.scratchPad.itemWheel.Story = items::Item::Wooden_Statue;
            }
            else if ( tools::checkItemFlag( ItemFlags::Invoice ) )
            {
                gameInfo.scratchPad.itemWheel.Story = items::Item::Invoice;
            }
            else if ( tools::checkItemFlag( ItemFlags::Renardos_Letter ) )
            {
                gameInfo.scratchPad.itemWheel.Story = items::Item::Renardos_Letter;
            }

            if ( tools::checkItemFlag( ItemFlags::Coral_Earring ) )
            {     // given sketch
                gameInfo.scratchPad.itemWheel.Story = items::Item::NullItem;
            }
            else if ( tools::checkItemFlag( ItemFlags::Asheis_Sketch ) )
            {
                gameInfo.scratchPad.itemWheel.Story = items::Item::Asheis_Sketch;
            }

            if ( gameInfo.scratchPad.movingActors.exploredRegions.Desert == 0b1 )
            {     // given memo
                gameInfo.scratchPad.itemWheel.Story = items::Item::NullItem;
            }
            else if ( tools::checkItemFlag( ItemFlags::Aurus_Memo ) )
            {
                gameInfo.scratchPad.itemWheel.Story = items::Item::Aurus_Memo;
            }
        }
    }

    void Mod::reorderItemWheel()
    {
        u8 currentSlot = 0x0;
        if ( tools::checkItemFlag( ItemFlags::Clawshots ) )
        {
            gameInfo.scratchPad.itemWheel.Double_Clawshot = items::Item::Clawshots;
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0xA;
            currentSlot++;
        }
        if ( tools::checkItemFlag( ItemFlags::Dominion_Rod ) )
        {
            gameInfo.scratchPad.itemWheel.Dominion_Rod = items::Item::Dominion_Rod;
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0x8;
            currentSlot++;
        }
        if ( tools::checkItemFlag( ItemFlags::Ball_and_Chain ) )
        {
            gameInfo.scratchPad.itemWheel.Ball_and_Chain = items::Item::Ball_and_Chain;
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0x6;
            currentSlot++;
        }
        if ( tools::checkItemFlag( ItemFlags::Spinner ) )
        {
            gameInfo.scratchPad.itemWheel.Spinner = items::Item::Spinner;
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0x2;
            currentSlot++;
        }
        if ( tools::checkItemFlag( ItemFlags::Clawshot ) )
        {
            gameInfo.scratchPad.itemWheel.Clawshot = items::Item::Clawshot;
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0x9;
            currentSlot++;
        }
        if ( tools::checkItemFlag( ItemFlags::Heros_Bow ) )
        {
            gameInfo.scratchPad.itemWheel.Bow = items::Item::Heros_Bow;
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0x4;
            currentSlot++;
        }
        if ( tools::checkItemFlag( ItemFlags::Iron_Boots ) )
        {
            gameInfo.scratchPad.itemWheel.Iron_Boots = items::Item::Iron_Boots;
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0x3;
            currentSlot++;
        }
        if ( tools::checkItemFlag( ItemFlags::Boomerang ) )
        {
            gameInfo.scratchPad.itemWheel.Boomerang = items::Item::Boomerang;
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0x0;
            currentSlot++;
        }
        if ( tools::checkItemFlag( ItemFlags::Lantern ) )
        {
            gameInfo.scratchPad.itemWheel.Lantern = items::Item::Lantern;
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0x1;
            currentSlot++;
        }
        if ( tools::checkItemFlag( ItemFlags::Slingshot ) )
        {
            gameInfo.scratchPad.itemWheel.Slingshot = items::Item::Slingshot;
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0x17;
            currentSlot++;
        }
        if ( gameInfo.scratchPad.itemWheel.Fishing_Rod != 0xFF )
        {
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0x14;
            currentSlot++;
        }
        if ( tools::checkItemFlag( ItemFlags::Hawkeye ) )
        {
            gameInfo.scratchPad.itemWheel.Hawkeye = items::Item::Hawkeye;
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0x5;
            currentSlot++;
        }
        if ( gameInfo.scratchPad.itemWheel.Bomb_Bag_1 != 0xFF )
        {
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0xF;
            currentSlot++;
        }
        if ( gameInfo.scratchPad.itemWheel.Bomb_Bag_2 != 0xFF )
        {
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0x10;
            currentSlot++;
        }
        if ( gameInfo.scratchPad.itemWheel.Bomb_Bag_3 != 0xFF )
        {
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0x11;
            currentSlot++;
        }
        if ( gameInfo.scratchPad.itemWheel.Bottle_1 != 0xFF )
        {
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0xB;
            currentSlot++;
        }
        if ( gameInfo.scratchPad.itemWheel.Bottle_2 != 0xFF )
        {
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0xC;
            currentSlot++;
        }
        if ( gameInfo.scratchPad.itemWheel.Bottle_3 != 0xFF )
        {
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0xD;
            currentSlot++;
        }
        if ( gameInfo.scratchPad.itemWheel.Bottle_4 != 0xFF )
        {
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0xE;
            currentSlot++;
        }
        if ( gameInfo.scratchPad.itemWheel.Story != 0xFF )
        {
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0x13;
            currentSlot++;
        }
        if ( gameInfo.scratchPad.itemWheel.Ooccoo != 0xFF )
        {
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0x12;
            currentSlot++;
        }
        if ( gameInfo.scratchPad.itemWheel.Sky_Book != 0xFF )
        {
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0x16;
            currentSlot++;
        }
        if ( tools::checkItemFlag( ItemFlags::Horse_Call ) )
        {
            gameInfo.scratchPad.itemWheel.Horse_Call = items::Item::Horse_Call;
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0x15;
            currentSlot++;
        }
        if ( gameInfo.scratchPad.itemWheel.Item_Slot != 0xFF )
        {
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0x7;
            currentSlot++;
        }

        for ( u16 i = currentSlot; i < sizeof( gameInfo.scratchPad.itemSlotsOrder ) / sizeof( u8 ); i++ )
        {
            gameInfo.scratchPad.itemSlotsOrder[currentSlot] = 0xFF;
        }
    }

    void Mod::fixYetaAndYeto()
    {
        if ( tools::checkItemFlag( ItemFlags::Bed_Key ) && tp::d_a_alink::checkStageName( "D_MN11" ) )
        {
            float linkPos[3];
            getPlayerPos( linkPos );

            if ( gameInfo.aButtonText == 0x6 &&
                 ( tp::d_kankyo::env_light.currentRoom == 0 || tp::d_kankyo::env_light.currentRoom == 1 ||
                   tp::d_kankyo::env_light.currentRoom == 2 || tp::d_kankyo::env_light.currentRoom == 3 ||
                   tp::d_kankyo::env_light.currentRoom == 4 || tp::d_kankyo::env_light.currentRoom == 7 ) &&
                 linkPos[1] == 0 )
            {
                gameInfo.localAreaNodes.dungeon.bigKeyGotten = 0b0;
                yetaTrickOn = 1;
            }
            if ( gameInfo.aButtonText == 0x79 && yetaTrickOn == 1 )
            {
                gameInfo.localAreaNodes.dungeon.bigKeyGotten = 0b1;
                yetaTrickOn = 0;
            }
        }
    }

    void Mod::preventPoweringUpDomRod()
    {
        if ( gameInfo.scratchPad.itemWheel.Sky_Book == 0xFF && tools::checkItemFlag( ItemFlags::Ancient_Sky_Book_empty ) &&
             !tools::checkItemFlag( ItemFlags::Ancient_Sky_Book_partly_filled ) )
        {
            gameInfo.scratchPad.itemWheel.Sky_Book = items::Item::Ancient_Sky_Book_empty;
        }
        if ( tp::d_a_alink::checkStageName( "R_SP209" ) )
        {
            if ( gameInfo.scratchPad.itemWheel.Sky_Book == items::Item::Ancient_Sky_Book_empty )
            {
                gameInfo.scratchPad.itemWheel.Sky_Book = 0xFF;
            }
        }
    }

    bool Mod::isStageShop()
    {
        u8 totalShopStages = sizeof( stage::shopStages ) / sizeof( stage::shopStages[0] );
        for ( u8 i = 0; i < totalShopStages; i++ )
        {
            if ( tp::d_a_alink::checkStageName( stage::shopStages[i] ) )
            {
                return true;
            }
        }
        return false;
    }

    void Mod::doCustomTRESActor( void* mStatus_roomControl )
    {
        tp::d_com_inf_game::GameInfo* pGameInfo = &tp::d_com_inf_game::dComIfG_gameInfo;

        u32 numChecks = sizeof( customChecks ) / sizeof( customChecks[0] );

        // Count and temp array for the checks for this stage+room
        u32 checkCount = 0;
        customCheck* checks = new customCheck[5];     // Assume there's never more than 5 custom checks per stage+room

        // Loop through checks and place if correct room and stage
        for ( u32 i = 0; i < numChecks; i++ )
        {
            customCheck* check = &customChecks[i];

            if ( 0 == strcmp( pGameInfo->nextStageVars.nextStage, check->stage ) &&
                 ( 0xFF == check->room ||
                   pGameInfo->nextStageVars.nextRoom == check->room ) &&     // 0xFF = no need to check for room
                 check->requirement() )
            {
                checks[checkCount] = *check;
                checkCount++;
            }
        }

        if ( checkCount > 0 )
        {
            // Create required structs
            tp::d_stage::TRES* TRES = new tp::d_stage::TRES[checkCount];
            tp::d_stage::dzxChunkTypeInfo chunkInfo;
            strcpy( chunkInfo.tag, "ACTR" );     // has to be ACTR for the function we use
            chunkInfo.numChunks = checkCount;
            chunkInfo.chunkDataPtr = TRES;

            // Populate TRES array with data
            for ( u32 i = 0; i < checkCount; i++ )
            {
                customCheck check = checks[i];

                if ( check.overrides != nullptr )
                {
                    check.overrides();
                }

                strcpy( TRES[i].actorName, "tboxA0" );
                TRES[i].flags = 0xFF0FF000 | ( check.chestType << 20 ) | ( check.saveFlag << 4 );

                // Translate hex to float (1:1)
                typeTransform<u32, float> X, Y, Z;
                X.a = check.X;
                Y.a = check.Y;
                Z.a = check.Z;

                TRES[i].X = X.b;
                TRES[i].Y = Y.b;
                TRES[i].Z = Z.b;

                TRES[i].angle = check.Angle;

                TRES[i].item = check.itemID;
            }

            /// Create the actors
            global::modPtr->actorCommonLayerInit_trampoline( mStatus_roomControl, &chunkInfo, 0, nullptr );
            delete[] TRES;
            Singleton::getInstance()->hasActorCommonLayerRan++;
        }

        delete[] checks;
        return;
    }

    void Mod::changeLanternColor()
    {
        // set lantern variables
        u32 lanternVariableAddress = reinterpret_cast<u32>( &tp::d_a_alink::lanternVariables );
        *reinterpret_cast<u8*>( lanternVariableAddress + 0x3D ) = reinterpret_cast<u8>( innerRed );
        *reinterpret_cast<u8*>( lanternVariableAddress + 0x3F ) = reinterpret_cast<u8>( innerGreen );
        *reinterpret_cast<u8*>( lanternVariableAddress + 0x41 ) = reinterpret_cast<u8>( innerBlue );
        *reinterpret_cast<u8*>( lanternVariableAddress + 0x43 ) = reinterpret_cast<u8>( outerRed );
        *reinterpret_cast<u8*>( lanternVariableAddress + 0x45 ) = reinterpret_cast<u8>( outerGreen );
        *reinterpret_cast<u8*>( lanternVariableAddress + 0x47 ) = reinterpret_cast<u8>( outerBlue );
    }

    bool Mod::canQuickTransform()
    {
        // Make sure Link is actually loaded
        tp::d_com_inf_game::LinkMapVars* linkMapPtr = gameInfo.linkMapPtr;
        // check to make sure that the quick transform variable is enabled
        if ( enableQuickTransform == 0 )
        {
            strcpy( sysConsolePtr->consoleLine[20].line, "-> option disabled" );
            return false;
        }

        if ( !linkMapPtr )
        {
            strcpy( sysConsolePtr->consoleLine[20].line, "-> no valid spot" );
            return false;
        }

        // Make sure Link currently isnt in an event
        if ( tp::d_a_alink::checkEventRun( linkMapPtr ) )
        {
            return false;
        }

        // Get the value for the alpha of the Z button
        // Pointer path is not currently defined yet
        u32 zButtonAlphaPtr = reinterpret_cast<u32>( tp::d_meter2_info::wZButtonPtr );
        if ( !zButtonAlphaPtr )
        {
            strcpy( sysConsolePtr->consoleLine[20].line, "-> alpha ptr 1 failed" );
            return false;
        }

        zButtonAlphaPtr = *reinterpret_cast<u32*>( zButtonAlphaPtr + 0x10C );
        if ( !zButtonAlphaPtr )
        {
            strcpy( sysConsolePtr->consoleLine[20].line, "-> alpha ptr 2 failed" );
            return false;
        }

        float zButtonAlpha = *reinterpret_cast<float*>( zButtonAlphaPtr + 0x720 );

        // Check if the Z button is dimmed
        if ( zButtonAlpha != 1.f )
        {
            // Z button is currently dimmed, so don't allow transforming
            strcpy( sysConsolePtr->consoleLine[20].line, "-> z button dimmed" );
            return false;
        }

        // make sure link is not underwater, or talking to anyone
        if ( tp::d_a_alink::linkStatus->status != 0x1 )
        {
            // link is in an invalid state
            return false;
        }

        // Make sure you have the ability to warp
        if ( ( gameInfo.scratchPad.eventBits[0xD] & 0x4 ) == 0 )
        {
            return false;
        }

        // Check to see if link is riding a snowboard
        if ( tp::d_a_alink::checkBoardRide( linkMapPtr ) )
        {
            return false;
        }

        // Check to see if link is riding the canoe
        if ( tp::d_a_alink::checkCanoeRide( linkMapPtr ) )
        {
            return false;
        }

        // Check to see if link is riding Epona
        if ( tp::d_a_alink::checkHorseRide( linkMapPtr ) )
        {
            return false;
        }

        // Check to see if link is riding a boar
        if ( tp::d_a_alink::checkBoarRide( linkMapPtr ) )
        {
            return false;
        }

        // Check to see if link is riding the spinner
        if ( tp::d_a_alink::checkSpinnerRide( linkMapPtr ) )
        {
            return false;
        }

        if ( gameInfo.linkMapPtr->equippedItem == items::Ball_and_Chain )
        {
            return false;
        }

        return true;
    }

    bool Mod::canChangeToD()
    {
        if ( ( gameInfo.scratchPad.eventBits[0xD] & 0x4 ) == 0 )
        {
            return false;
        }

        if ( gameInfo.aButtonText != 0x23 )
        {
            return false;
        }

        if ( gameInfo.eventSystem.actionStatus != 0x29 )
        {
            return false;
        }

        if ( Singleton::getInstance()->midnaTimeControl == 0 )
        {
            return false;
        }

        if ( !chestRandomizer->isStageTOD() )
        {
            return false;
        }
        return true;
    }

    s32 Mod::getMsgIndex( const void* TProcessor, u16 unk2, u32 msgId )
    {
        void* unk = tp::processor::getResource_groupID( TProcessor, unk2 );
        if ( !unk )
        {
            return -1;
        }

        gc::bmgres::TextIndexTable* textIndexTable =
            *reinterpret_cast<gc::bmgres::TextIndexTable**>( reinterpret_cast<u32>( unk ) + 0xC );

        gc::bmgres::MessageEntry* entry = &textIndexTable->entry[0];
        u32 loopCount = textIndexTable->numEntries;

        for ( u32 i = 0; i < loopCount; i++ )
        {
            if ( entry->messageId == msgId )
            {
                return static_cast<s32>( i );
            }
            entry++;
        }

        // Didn't find the index
        return -1;
    }

    s32 Mod::getItemMsgIndex( const void* TProcessor, u16 unk2, u32 itemId )
    {
        // Increment itemId to be at the start of the table entries for items
        u32 msgId = itemId + 0x65;
        return getMsgIndex( TProcessor, unk2, msgId );
    }

    s32 Mod::getItemIdFromMsgId( const void* TProcessor, u16 unk3, u32 msgId )
    {
        void* unk = tp::processor::getResource_groupID( TProcessor, unk3 );
        if ( !unk )
        {
            return -1;
        }

        gc::bmgres::TextIndexTable* textIndexTable =
            *reinterpret_cast<gc::bmgres::TextIndexTable**>( reinterpret_cast<u32>( unk ) + 0xC );

        gc::bmgres::MessageEntry* entry = &textIndexTable->entry[0];
        u32 loopCount = textIndexTable->numEntries;

        // Loop through the item IDs until msgId is found
        u32 itemId = items::Item::Recovery_Heart;
        for ( u32 i = 0; i < loopCount; i++ )
        {
            u16 entryMessageId = entry->messageId;
            if ( entryMessageId == ( itemId + 0x64 ) )
            {
                if ( entryMessageId == msgId )
                {
                    return static_cast<s32>( itemId );
                }
                else
                {
                    itemId++;

                    // Make sure itemId is valid
                    if ( itemId > items::Item::NullItem )
                    {
                        break;
                    }
                }
            }
            entry++;
        }

        // Didn't find the index
        return -1;
    }

    u32 Mod::getCustomMsgColor( u8 colorId )
    {
        u32 newColorCode;     // RGBA
        switch ( colorId )
        {
            case CUSTOM_MSG_COLOR_DARK_GREEN_HEX:
            {
                newColorCode = 0x4BBE4BFF;
                break;
            }
            case CUSTOM_MSG_COLOR_BLUE_HEX:
            {
                newColorCode = 0x4B96D7FF;
                break;
            }
            case CUSTOM_MSG_COLOR_SILVER_HEX:
            {
                newColorCode = 0xBFBFBFFF;
                break;
            }
            default:
            {
                // Return the color white if there is not a match
                newColorCode = 0xFFFFFFFF;
                break;
            }
        }
        return newColorCode;
    }

}     // namespace mod