fork/m-overlay

git clone https://git.julia.blue/fork/m-overlay

BkacjiosBugfixes + Dark Mode skina8034e9

main
35.8 KiB1281 linesraw
1local memory = require("memory")
2local color = require("util.color")
3local bit = require("bit")
4
5MATCH_NO_RESULT = 0x00
6MATCH_GAME = 0x02
7MATCH_STAGE_CLEAR = 0x03
8MATCH_STAGE_FAILURE = 0x04
9MATCH_STAGE_CLEAR3 = 0x05
10MATCH_NEW_RECORD = 0x06
11MATCH_NO_CONTEST = 0x07
12MATCH_RETRY = 0x08
13MATCH_GAME_CLEAR = 0x09
14
15-- MAJOR FLAGS
16SCENE_TITLE_SCREEN = 0x00
17
18SCENE_MAIN_MENU = 0x01
19	-- MENU FLAGS
20	MENU_MAIN = 0x00
21		SELECT_MAIN_1P = 0x00
22		SELECT_MAIN_VS = 0x01
23		SELECT_MAIN_TROPHY = 0x02
24		SELECT_MAIN_OPTIONS = 0x03
25		SELECT_MAIN_DATA = 0x04
26
27	MENU_1P = 0x01
28		SELECT_1P_REGULAR = 0x00
29		SELECT_1P_EVENT = 0x01
30		SELECT_1P_ONLINE = 0x2
31		SELECT_1P_STADIUM = 0x03
32		SELECT_1P_TRAINING = 0x04
33
34	MENU_VS = 0x02
35		SELECT_VS_MELEE = 0x00
36		SELECT_VS_TOURNAMENT = 0x01
37		SELECT_VS_SPECIAL = 0x02
38		SELECT_VS_CUSTOM = 0x03
39		SELECT_VS_NAMEENTRY = 0x04
40
41	MENU_TROPHIES = 0x03
42		SELECT_TROPHIES_GALLERY = 0x00
43		SELECT_TROPHIES_LOTTERY = 0x01
44		SELECT_TROPHIES_COLLECTION = 0x02
45
46	MENU_OPTIONS = 0x04
47		SELECT_OPTIONS_RUMBLE = 0x00
48		SELECT_OPTIONS_SOUND = 0x01
49		SELECT_OPTIONS_DISPLAY = 0x02
50		SELECT_OPTIONS_UNKNOWN = 0x03
51		SELECT_OPTIONS_LANGUAGE = 0x04
52		SELECT_OPTIONS_ERASE_DATA = 0x05
53
54	MENU_ONLINE = 0x08
55		SELECT_ONLINE_RANKED = 0x00
56		SELECT_ONLINE_UNRANKED = 0x01
57		SELECT_ONLINE_DIRECT = 0x02
58		SELECT_ONLINE_TEAMS = 0x03
59		SELECT_ONLINE_LOGOUT = 0x05
60
61	MENU_STADIUM = 0x09
62		SELECT_STADIUM_TARGET_TEST = 0x00
63		SELECT_STADIUM_HOMERUN_CONTEST = 0x01
64		SELECT_STADIUM_MULTIMAN_MELEE = 0x02
65
66	MENU_RUMBLE = 0x13
67	MENU_SOUND = 0x14
68	MENU_DISPLAY = 0x15
69	MENU_UNKNOWN1 = 0x16
70	MENU_LANGUAGE = 0x17
71
72SCENE_VS_MODE = 0x02
73	-- MINOR FLAGS
74	SCENE_VS_CSS = 0x0
75	SCENE_VS_SSS = 0x1
76	SCENE_VS_INGAME = 0x2
77	SCENE_VS_POSTGAME = 0x4
78
79SCENE_CLASSIC_MODE = 0x03
80	SCENE_CLASSIC_LEVEL_1_VS  = 0x00
81	SCENE_CLASSIC_LEVEL_1 = 0x01
82	SCENE_CLASSIC_LEVEL_2_VS = 0x02
83	SCENE_CLASSIC_LEVEL_2 = 0x03
84	SCENE_CLASSIC_LEVEL_3_VS = 0x04
85	SCENE_CLASSIC_LEVEL_3 = 0x05
86	SCENE_CLASSIC_LEVEL_4_VS = 0x06
87	SCENE_CLASSIC_LEVEL_4 = 0x07
88	SCENE_CLASSIC_LEVEL_5_VS = 0x08
89	SCENE_CLASSIC_LEVEL_5 = 0x09
90	SCENE_CLASSIC_LEVEL_5_VS = 0x10
91	SCENE_CLASSIC_LEVEL_5 = 0x09
92
93	SCENE_CLASSIC_LEVEL_16 = 0x20
94	SCENE_CLASSIC_LEVEL_16_VS = 0x21
95
96	SCENE_CLASSIC_LEVEL_24 = 0x30
97	SCENE_CLASSIC_LEVEL_24_VS = 0x31
98
99	SCENE_CLASSIC_BREAK_THE_TARGETS_INTRO = 0x16
100	SCENE_CLASSIC_BREAK_THE_TARGETS = 0x17
101
102	SCENE_CLASSIC_TROPHY_STAGE_INTRO = 0x28
103	SCENE_CLASSIC_TROPHY_STAGE_TARGETS = 0x29
104
105	SCENE_CLASSIC_RACE_TO_FINISH_INTRO = 0x40
106	SCENE_CLASSIC_RACE_TO_FINISH_TARGETS = 0x41
107
108	SCENE_CLASSIC_LEVEL_56 = 0x38
109	SCENE_CLASSIC_LEVEL_56_VS = 0x39
110
111	SCENE_CLASSIC_MASTER_HAND = 0x51
112
113	SCENE_CLASSIC_CONTINUE = 0x69
114	SCENE_CLASSIC_CSS = 0x70
115
116SCENE_ADVENTURE_MODE = 0x04
117
118	SCENE_ADVENTURE_MUSHROOM_KINGDOM_INTRO = 0x00
119	SCENE_ADVENTURE_MUSHROOM_KINGDOM = 0x01
120	SCENE_ADVENTURE_MUSHROOM_KINGDOM_LUIGI = 0x02
121	SCENE_ADVENTURE_MUSHROOM_KINGDOM_BATTLE = 0x03
122
123	SCENE_ADVENTURE_MUSHROOM_KONGO_JUNGLE_INTRO = 0x08
124	SCENE_ADVENTURE_MUSHROOM_KONGO_JUNGLE_TINY_BATTLE = 0x09
125	SCENE_ADVENTURE_MUSHROOM_KONGO_JUNGLE_GIANT_BATTLE = 0x0A
126
127	SCENE_ADVENTURE_UNDERGROUND_MAZE_INTRO = 0x10
128	SCENE_ADVENTURE_UNDERGROUND_MAZE = 0x11
129	SCENE_ADVENTURE_HYRULE_TEMPLE_BATTLE = 0x12
130
131	SCENE_ADVENTURE_BRINSTAR_INTRO = 0x18
132	SCENE_ADVENTURE_BRINSTAR = 0x19
133
134	SCENE_ADVENTURE_ESCAPE_ZEBES_INTRO = 0x1A
135	SCENE_ADVENTURE_ESCAPE_ZEBES = 0x1B
136	SCENE_ADVENTURE_ESCAPE_ZEBES_ESCAPE = 0x1C
137
138	SCENE_ADVENTURE_GREEN_GREENS_INTRO = 0x20
139	SCENE_ADVENTURE_GREEN_GREENS_KIRBY_BATTLE = 0x21
140	SCENE_ADVENTURE_GREEN_GREENS_KIRBY_TEAM_INTRO = 0x22
141	SCENE_ADVENTURE_GREEN_GREENS_KIRBY_TEAM_BATTLE = 0x23
142	SCENE_ADVENTURE_GREEN_GREENS_GIANT_KIRBY_INTRO = 0x24
143	SCENE_ADVENTURE_GREEN_GREENS_GIANT_KIRBY_BATTLE = 0x25
144
145	SCENE_ADVENTURE_CORNARIA_INTRO = 0x28
146	SCENE_ADVENTURE_CORNARIA_BATTLE_1 = 0x29
147	SCENE_ADVENTURE_CORNARIA_RAID = 0x2A
148	SCENE_ADVENTURE_CORNARIA_BATTLE_2 = 0x2B
149	SCENE_ADVENTURE_CORNARIA_BATTLE_3 = 0x2C
150
151	SCENE_ADVENTURE_POKEMON_STADIUM_INTRO = 0x30
152	SCENE_ADVENTURE_POKEMON_STADIUM_BATTLE = 0x31
153
154	SCENE_ADVENTURE_FZERO_GRAND_PRIX_CARS = 0x38
155	SCENE_ADVENTURE_FZERO_GRAND_PRIX_INTRO = 0x39
156	SCENE_ADVENTURE_FZERO_GRAND_PRIX_RACE = 0x3A
157	SCENE_ADVENTURE_FZERO_GRAND_PRIX_BATTLE = 0x3B
158
159	SCENE_ADVENTURE_ONETT_INTRO = 0x40
160	SCENE_ADVENTURE_ONETT_BATTLE = 0x41
161
162	SCENE_ADVENTURE_ICICLE_MOUNTAIN_INTRO = 0x48
163	SCENE_ADVENTURE_ICICLE_MOUNTAIN_CLIMB = 0x49
164
165	SCENE_ADVENTURE_BATTLEFIELD_INTRO = 0x50
166	SCENE_ADVENTURE_BATTLEFIELD_BATTLE = 0x51
167	SCENE_ADVENTURE_BATTLEFIELD_METAL_INTRO = 0x52
168	SCENE_ADVENTURE_BATTLEFIELD_METAL_BATTLE = 0x53
169
170	SCENE_ADVENTURE_FINAL_DESTINATION_INTRO = 0x58
171	SCENE_ADVENTURE_FINAL_DESTINATION_BATTLE = 0x59
172	SCENE_ADVENTURE_FINAL_DESTINATION_POSE = 0x5A
173	SCENE_ADVENTURE_FINAL_DESTINATION_WINNER = 0x5B
174
175	SCENE_ADVENTURE_CSS = 0x70
176
177SCENE_ALL_STAR_MODE = 0x05
178	SCENE_ALL_STAR_LEVEL_1 = 0x00
179	SCENE_ALL_STAR_REST_AREA_1 = 0x01
180	SCENE_ALL_STAR_LEVEL_2 = 0x02
181	SCENE_ALL_STAR_REST_AREA_2 = 0x03
182	SCENE_ALL_STAR_LEVEL_3 = 0x04
183	SCENE_ALL_STAR_REST_AREA_3 = 0x05
184	SCENE_ALL_STAR_LEVEL_4 = 0x06
185	SCENE_ALL_STAR_REST_AREA_4 = 0x07
186	SCENE_ALL_STAR_LEVEL_5 = 0x08
187	SCENE_ALL_STAR_REST_AREA_5 = 0x09
188	SCENE_ALL_STAR_LEVEL_6 = 0x10
189	SCENE_ALL_STAR_REST_AREA_6 = 0x11
190	SCENE_ALL_STAR_LEVEL_7 = 0x12
191	SCENE_ALL_STAR_REST_AREA_7 = 0x13
192	SCENE_ALL_STAR_LEVEL_8 = 0x14
193	SCENE_ALL_STAR_REST_AREA_8 = 0x15
194	SCENE_ALL_STAR_LEVEL_9 = 0x16
195	SCENE_ALL_STAR_REST_AREA_9 = 0x17
196	SCENE_ALL_STAR_LEVEL_10 = 0x18
197	SCENE_ALL_STAR_REST_AREA_10 = 0x19
198	SCENE_ALL_STAR_LEVEL_11 = 0x20
199	SCENE_ALL_STAR_REST_AREA_11 = 0x21
200	SCENE_ALL_STAR_LEVEL_12 = 0x22
201	SCENE_ALL_STAR_REST_AREA_12 = 0x23
202	SCENE_ALL_STAR_LEVEL_13 = 0x24
203	SCENE_ALL_STAR_REST_AREA_13 = 0x25
204	SCENE_ALL_STAR_LEVEL_14 = 0x26
205	SCENE_ALL_STAR_REST_AREA_14 = 0x27
206	SCENE_ALL_STAR_LEVEL_15 = 0x28
207	SCENE_ALL_STAR_REST_AREA_15 = 0x29
208	SCENE_ALL_STAR_LEVEL_16 = 0x30
209	SCENE_ALL_STAR_REST_AREA_16 = 0x31
210	SCENE_ALL_STAR_LEVEL_17 = 0x32
211	SCENE_ALL_STAR_REST_AREA_17 = 0x33
212	SCENE_ALL_STAR_LEVEL_18 = 0x34
213	SCENE_ALL_STAR_REST_AREA_18 = 0x35
214	SCENE_ALL_STAR_LEVEL_19 = 0x36
215	SCENE_ALL_STAR_REST_AREA_19 = 0x37
216	SCENE_ALL_STAR_LEVEL_20 = 0x38
217	SCENE_ALL_STAR_REST_AREA_20 = 0x39
218	SCENE_ALL_STAR_LEVEL_21 = 0x40
219	SCENE_ALL_STAR_REST_AREA_21 = 0x41
220	SCENE_ALL_STAR_LEVEL_22 = 0x42
221	SCENE_ALL_STAR_REST_AREA_22 = 0x43
222	SCENE_ALL_STAR_LEVEL_23 = 0x44
223	SCENE_ALL_STAR_REST_AREA_23 = 0x45
224	SCENE_ALL_STAR_LEVEL_24 = 0x46
225	SCENE_ALL_STAR_REST_AREA_24 = 0x47
226	SCENE_ALL_STAR_LEVEL_25 = 0x48
227	SCENE_ALL_STAR_REST_AREA_25 = 0x49
228	SCENE_ALL_STAR_LEVEL_26 = 0x50
229	SCENE_ALL_STAR_REST_AREA_26 = 0x51
230	SCENE_ALL_STAR_LEVEL_27 = 0x52
231	SCENE_ALL_STAR_REST_AREA_28 = 0x53
232	SCENE_ALL_STAR_LEVEL_29 = 0x54
233	SCENE_ALL_STAR_REST_AREA_29 = 0x55
234	SCENE_ALL_STAR_LEVEL_30 = 0x56
235	SCENE_ALL_STAR_REST_AREA_30 = 0x57
236	SCENE_ALL_STAR_LEVEL_31 = 0x58
237	SCENE_ALL_STAR_REST_AREA_31 = 0x59
238	SCENE_ALL_STAR_LEVEL_32 = 0x60
239	SCENE_ALL_STAR_REST_AREA_32 = 0x61
240	SCENE_ALL_STAR_CSS = 0x70
241
242SCENE_DEBUG = 0x06
243SCENE_SOUND_TEST = 0x07
244
245SCENE_VS_ONLINE = 0x08 -- SLIPPI ONLINE
246	SCENE_VS_ONLINE_CSS = 0x00
247	SCENE_VS_ONLINE_SSS = 0x01
248	SCENE_VS_ONLINE_INGAME = 0x02
249	SCENE_VS_ONLINE_VERSUS = 0x04
250	SCENE_VS_ONLINE_RANKED = 0x05
251
252SCENE_UNKOWN_1 = 0x09
253SCENE_CAMERA_MODE = 0x0A
254SCENE_TROPHY_GALLERY = 0x0B
255SCENE_TROPHY_LOTTERY = 0x0C
256SCENE_TROPHY_COLLECTION = 0x0D
257
258SCENE_START_MATCH = 0x0E -- Slippi Replays
259	SCENE_START_MATCH_INGAME = 0x01 -- Set when the replay is actually playing out
260	SCENE_START_MATCH_UNKNOWN = 0x03 -- Seems to be set right before the match loads
261
262SCENE_TARGET_TEST = 0x0F
263	SCENE_TARGET_TEST_CSS = 0x00
264	SCENE_TARGET_TEST_INGAME = 0x1
265
266SCENE_SUPER_SUDDEN_DEATH = 0x10
267	SCENE_SSD_CSS = 0x00
268	SCENE_SSD_SSS = 0x01
269	SCENE_SSD_INGAME = 0x02
270	SCENE_SSD_POSTGAME = 0x04
271
272MENU_INVISIBLE_MELEE = 0x11
273	MENU_INVISIBLE_MELEE_CSS = 0x00
274	MENU_INVISIBLE_MELEE_SSS = 0x01
275	MENU_INVISIBLE_MELEE_INGAME = 0x02
276	MENU_INVISIBLE_MELEE_POSTGAME = 0x04
277
278MENU_SLOW_MO_MELEE = 0x12
279	MENU_SLOW_MO_MELEE_CSS = 0x00
280	MENU_SLOW_MO_MELEE_SSS = 0x01
281	MENU_SLOW_MO_MELEE_INGAME = 0x02
282	MENU_SLOW_MO_MELEE_POSTGAME = 0x04
283
284MENU_LIGHTNING_MELEE = 0x13
285	MENU_LIGHTNING_MELEE_CSS = 0x00
286	MENU_LIGHTNING_MELEE_SSS = 0x01
287	MENU_LIGHTNING_MELEE_INGAME = 0x02
288	MENU_LIGHTNING_MELEE_POSTGAME = 0x04
289
290SCENE_CHARACTER_APPROACHING = 0x14
291
292SCENE_CLASSIC_MODE_COMPLETE = 0x15
293	SCENE_CLASSIC_MODE_TROPHY = 0x00
294	SCENE_CLASSIC_MODE_CREDITS = 0x01
295	SCENE_CLASSIC_MODE_CHARACTER_VIDEO = 0x02
296	SCENE_CLASSIC_MODE_CONGRATS = 0x03
297
298SCENE_ADVENTURE_MODE_COMPLETE = 0x16
299	SCENE_ADVENTURE_MODE_TROPHY = 0x00
300	SCENE_ADVENTURE_MODE_CREDITS = 0x01
301	SCENE_ADVENTURE_MODE_CHARACTER_VIDEO = 0x02
302	SCENE_ADVENTURE_MODE_CONGRATS = 0x03
303
304SCENE_ALL_STAR_COMPLETE = 0x17
305	SCENE_ALL_STAR_TROPHY = 0x00
306	SCENE_ALL_STAR_CREDITS = 0x01
307	SCENE_ALL_STAR_CHARACTER_VIDEO = 0x02
308	SCENE_ALL_STAR_CONGRATS = 0x03
309
310SCENE_TITLE_SCREEN_IDLE = 0x18
311	SCENE_TITLE_SCREEN_IDLE_INTRO_VIDEO = 0x0
312	SCENE_TITLE_SCREEN_IDLE_FIGHT_1 = 0x1
313	SCENE_TITLE_SCREEN_IDLE_BETWEEN_FIGHTS = 0x2
314	SCENE_TITLE_SCREEN_IDLE_FIGHT_2 = 0x3
315	SCENE_TITLE_SCREEN_IDLE_HOW_TO_PLAY = 0x4
316
317SCENE_ADVENTURE_MODE_CINEMEATIC = 0x19
318SCENE_CHARACTER_UNLOCKED = 0x1A
319
320SCENE_TOURNAMENT = 0x1B
321	SCENE_TOURNAMENT_CSS = 0x0
322	SCENE_TOURNAMENT_BRACKET = 0x1
323	SCENE_TOURNAMENT_INGAME = 0x4
324	SCENE_TOURNAMENT_POSTGAME = 0x6
325
326SCENE_TRAINING_MODE = 0x1C
327	SCENE_TRAINING_CSS = 0x0
328	SCENE_TRAINING_SSS = 0x1
329	SCENE_TRAINING_INGAME = 0x2
330
331SCENE_TINY_MELEE = 0x1D
332	SCENE_TINY_MELEE_CSS = 0x0
333	SCENE_TINY_MELEE_SSS = 0x1
334	SCENE_TINY_MELEE_INGAME = 0x2
335	SCENE_TINY_MELEE_POSTGAME = 0x4
336
337SCENE_GIANT_MELEE = 0x1E
338	SCENE_GIANT_MELEE_CSS = 0x0
339	SCENE_GIANT_MELEE_SSS = 0x1
340	SCENE_GIANT_MELEE_INGAME = 0x2
341	SCENE_GIANT_MELEE_POSTGAME = 0x4
342
343SCENE_STAMINA_MODE = 0x1F
344	SCENE_STAMINA_MODE_CSS = 0x0
345	SCENE_STAMINA_MODE_SSS = 0x1
346	SCENE_STAMINA_MODE_INGAME = 0x2
347	SCENE_STAMINA_MODE_POSTGAME = 0x4
348
349SCENE_HOME_RUN_CONTEST = 0x20
350	SCENE_HOME_RUN_CONTEST_CSS = 0x0
351	SCENE_HOME_RUN_CONTEST_INGAME = 0x1
352
353SCENE_10_MAN_MELEE = 0x21
354	SCENE_10_MAN_MELEE_CSS = 0x00
355	SCENE_10_MAN_MELEE_INGAME = 0x01
356
357SCENE_100_MAN_MELEE = 0x22
358	SCENE_100_MAN_MELEE_CSS = 0x00
359	SCENE_100_MAN_MELEE_INGAME = 0x01
360
361SCENE_3_MINUTE_MELEE = 0x23
362	SCENE_3_MINUTE_MELEE_CSS = 0x00
363	SCENE_3_MINUTE_MELEE_INGAME = 0x01
364
365SCENE_15_MINUTE_MELEE = 0x24
366	SCENE_15_MINUTE_MELEE_CSS = 0x00
367	SCENE_15_MINUTE_MELEE_INGAME = 0x01
368
369SCENE_ENDLESS_MELEE = 0x25
370	SCENE_ENDLESS_MELEE_CSS = 0x00
371	SCENE_ENDLESS_MELEE_INGAME = 0x01
372
373SCENE_CRUEL_MELEE = 0x26
374	SCENE_CRUEL_MELEE_CSS = 0x00
375	SCENE_CRUEL_MELEE_INGAME = 0x01
376	
377SCENE_PROGRESSIVE_SCAN = 0x27
378SCENE_PLAY_INTRO_VIDEO = 0x28
379SCENE_MEMORY_CARD_OVERWRITE = 0x29
380
381SCENE_FIXED_CAMERA_MODE = 0x2A
382	SCENE_FIXED_CAMERA_MODE_CSS = 0x0
383	SCENE_FIXED_CAMERA_MODE_SSS = 0x1
384	SCENE_FIXED_CAMERA_MODE_INGAME = 0x2
385	SCENE_FIXED_CAMERA_MODE_POSTGAME = 0x4
386
387SCENE_EVENT_MATCH = 0x2B
388	SCENE_EVENT_MATCH_SELECT = 0x0
389	SCENE_EVENT_MATCH_INGAME = 0x1
390
391SCENE_SINGLE_BUTTON_MODE = 0x2C
392	SCENE_SINGLE_BUTTON_MODE_CSS = 0x0
393	SCENE_SINGLE_BUTTON_MODE_SSS = 0x1
394	SCENE_SINGLE_BUTTON_MODE_INGAME = 0x2
395
396local character_selections = {
397	[0x00] = {
398		name = "captain",
399		skin = {"original", "black", "red", "white", "green", "blue", "teal"},
400		team_skin = {3, 6, 5},
401		series = "fzero"
402	},
403	[0x01] = {
404		name = "donkey",
405		skin = {"original", "black", "red", "blue", "green", "gold"},
406		team_skin = {3, 4, 5},
407		series = "donkey_kong"
408	},
409	[0x02] = {
410		name = "fox",
411		skin = {"original", "red", "blue", "green", "gold"},
412		team_skin = {2, 3, 4},
413		series = "star_fox"
414	},
415	[0x03] = {
416		name = "gamewatch",
417		skin = {"original", "red", "blue", "green", "white"},
418		team_skin = {2, 3, 4},
419		series = "game_and_watch"
420	},
421	[0x04] = {
422		name = "kirby",
423		skin = {"original", "yellow", "blue", "red", "green", "white", "purple"},
424		team_skin = {4, 3, 5},
425		series = "kirby"
426	},
427	[0x05] = {
428		name = "koopa",
429		skin = {"green", "red", "blue", "black", "orange"},
430		team_skin = {2, 3, 1},
431		series = "mario"
432	},
433	[0x06] = {
434		name = "link",
435		skin = {"green", "red", "blue", "black", "white", "gold"},
436		team_skin = {2, 3, 1},
437		series = "zelda"
438	},
439	[0x07] = {
440		name = "luigi",
441		skin = {"green", "white", "blue", "red", "purple"},
442		team_skin = {4, 3, 1},
443		series = "mario"
444	},
445	[0x08] = {
446		name = "mario",
447		skin = {"red", "yellow", "black", "blue", "green", "teal"},
448		team_skin = {1, 4, 5},
449		series = "mario"
450	},
451	[0x09] = {
452		name = "marth",
453		skin = {"original", "red", "green", "black", "white", "gold"},
454		team_skin = {2, 1, 3},
455		series = "fire_emblem"
456	},
457	[0x10] = {
458		name = "samus",
459		skin = {"red", "pink", "black", "green", "blue", "teal"},
460		team_skin = {1, 5, 4},
461		series = "metroid"
462	},
463	[0x11] = {
464		name = "yoshi",
465		skin = {"green", "red", "blue", "yellow", "pink", "light_blue", "black"},
466		team_skin = {2, 3, 1},
467		series = "yoshi"
468	},
469	[0x12] = {
470		name = "zelda",
471		skin = {"original", "red", "blue", "green", "white", "gold"},
472		team_skin = {2, 3, 4},
473		series = "zelda"
474	},
475	[0x13] = {
476		name = "sheik",
477		skin = {"original", "red", "blue", "green", "white", "gold"},
478		team_skin = {2, 3, 4},
479		series = "zelda"
480	},
481	[0x14] = {
482		name = "falco",
483		skin = {"original", "red", "blue", "green", "pink"},
484		team_skin = {2, 3, 4},
485		series = "star_fox"
486	},
487	[0x15] = {
488		name = "younglink",
489		skin = {"green", "red", "blue", "white", "black", "purple"},
490		team_skin = {2, 3, 1},
491		series = "zelda"
492	},
493	[0x16] = {
494		name = "mariod",
495		skin = {"white", "red", "blue", "green", "black", "purple"},
496		team_skin = {2, 3, 4},
497		series = "mario"
498	},
499	[0x17] = {
500		name = "roy",
501		skin = {"original", "red", "blue", "green", "yellow", "purple"},
502		team_skin = {2, 3, 4},
503		series = "fire_emblem"
504	},
505	[0x18] = {
506		name = "pichu",
507		skin = {"original", "red", "blue", "green", "hat"},
508		team_skin = {2, 3, 4},
509		series = "pokemon"
510	},
511	[0x19] = {
512		name = "ganon",
513		skin = {"original", "red", "blue", "green", "purple", "gold"},
514		team_skin = {2, 3, 4},
515		series = "zelda"
516	},
517	[0x0A] = {
518		name = "mewtwo",
519		skin = {"original", "red", "blue", "green", "black"},
520		team_skin = {2, 3, 4},
521		series = "pokemon"
522	},
523	[0x0B] = {
524		name = "ness",
525		skin = {"original", "yellow", "blue", "green", "pink"},
526		team_skin = {1, 3, 4},
527		series = "earthbound"
528	},
529	[0x0C] = {
530		name = "peach",
531		skin = {"original", "daisy", "white", "blue", "green", "red"},
532		team_skin = {1, 4, 5},
533		series = "mario"
534	},
535	[0x0D] = {
536		name = "pikachu",
537		skin = {"original", "red", "blue", "green", "detective"},
538		team_skin = {2, 3, 4},
539		series = "pokemon"
540	},
541	[0x0E] = {
542		name = "ice_climber",
543		skin = {"original", "green", "orange", "red", "blue"},
544		team_skin = {4, 1, 2},
545		series = "ice_climbers"
546	},
547	[0x0F] = {
548		name = "purin",
549		skin = {"original", "red", "blue", "green", "crown", "pink"},
550		team_skin = {2, 3, 4},
551		series = "pokemon"
552	},
553	[0x1A] = {
554		name = "master_hand",
555		skinless = true,
556		series = "smash"
557	},
558	[0x1E] = {
559		name = "crazy_hand",
560		skinless = true,
561		series = "smash"
562	},
563	[0x1D] = {
564		name = "giga_bowser",
565		skinless = true,
566		series = "smash"
567	},
568	[0x21] = {
569		name = "wireframe",
570		skinless = true,
571		series = "smash"
572	},
573}
574
575local beyondmelee_selection = {
576	[0x00] = {
577		name = "captain",
578		skin = {"original", "black", "red", "white", "green", "blue", "maskless"},
579		team_skin = {3, 6, 5},
580		series = "fzero"
581	},
582	[0x05] = {
583		name = "koopa",
584		skin = {"green", "red", "blue", "black", "bones"},
585		team_skin = {2, 3, 1},
586		series = "mario"
587	},
588	[0x06] = {
589		name = "link",
590		skin = {"green", "red", "blue", "black", "white", "fierce"},
591		team_skin = {2, 3, 1},
592		series = "zelda"
593	},
594	[0x08] = {
595		name = "mario",
596		skin = {"red", "yellow", "black", "blue", "green", "builder"},
597		team_skin = {1, 4, 5},
598		series = "mario"
599	},
600	[0x0D] = {
601		name = "pikachu",
602		skin = {"original", "red", "blue", "green", "luchador"},
603		team_skin = {2, 3, 4},
604		series = "pokemon"
605	},
606	[0x10] = {
607		name = "samus",
608		skin = {"red", "pink", "black", "green", "blue", "white"},
609		team_skin = {1, 5, 4},
610		series = "metroid"
611	},
612	[0x16] = {
613		name = "mariod",
614		skin = {"white", "red", "blue", "green", "black", "hazmat"},
615		team_skin = {2, 3, 4},
616		series = "mario"
617	},
618	[0x18] = {
619		name = "pichu",
620		skin = {"original", "red", "blue", "green", "hat"},
621		team_skin = {2, 3, 4},
622		series = "pokemon"
623	},
624	[0x19] = {
625		name = "ganon",
626		skin = {"original", "red", "blue", "green", "purple", "spirit"},
627		team_skin = {2, 3, 4},
628		series = "zelda"
629	},
630	[0x1A] = {
631		name = "wolf",
632		skin = {"neutral", "red", "blue", "green"},
633		team_skin = {2, 3, 4},
634		series = "star_fox"
635	},
636	[0x1B] = {
637		name = "raichu",
638		skin = {"neutral", "king", "beach", "vomit", "warlock"},
639		team_skin = {2, 3, 4},
640		series = "pokemon"
641	},
642	[0x1C] = {
643		name = "shadowm2",
644		skin = {"black", "red", "blue", "green", "purple"},
645		team_skin = {2, 3, 4},
646		series = "pokemon"
647	},
648	[0x1D] = {
649		name = "fay",
650		skin = {"neutral", "red", "blue", "green"},
651		team_skin = {2, 3, 4},
652		series = "star_fox"
653	},
654	[0x1E] = {
655		name = "skullkid",
656		skin = {"neutral", "blue", "green", "black"},
657		team_skin = {1, 2, 3},
658		series = "zelda"
659	},
660}
661
662local akaneia_selection = {
663	[0x1A] = {
664		name = "wolf",
665		skin = {"neutral", "pink", "blue", "green", "brown"},
666		team_skin = {2, 3, 4},
667		series = "star_fox"
668	},
669}
670
671local textures = {
672	series = {},
673	stocks = {},
674	skinless = {}
675}
676
677local graphics = love.graphics
678local newImage = graphics.newImage
679
680local melee = {}
681
682function melee.isAkaneia()
683	return memory.romstring and memory.romstring.akaneia == "Akaneia"
684end
685
686function melee.isBeyondMelee()
687	return memory.romstring and memory.romstring.beyondmelee == "Beyond Melee"
688end
689
690do
691	local function doload(tbl)
692		for cid, info in pairs(tbl) do
693			if textures.series[cid] then textures.series[cid]:release() end
694			textures.series[cid] = newImage(("textures/series/%s.png"):format(info.series))
695
696			if textures.stocks[cid] then
697				for skin, text in pairs(textures.stocks[cid]) do
698					text:release()
699				end
700			end
701
702			textures.stocks[cid] = {}
703			textures.skinless[cid] = info.skinless
704
705			if info.skin then
706				for sid, skin in ipairs(info.skin) do
707					local stockf = ("textures/stocks/%s-%s.png"):format(info.name, skin)
708					local stockakf = ("textures/stocks/ak/%s-%s.png"):format(info.name, skin)
709					local stockbmf = ("textures/stocks/bm/%s-%s.png"):format(info.name, skin)
710
711					if melee.isAkaneia() and love.filesystem.getInfo(stockakf) then
712						-- Akaneia icon override
713						textures.stocks[cid][sid-1] = newImage(stockakf)
714					elseif melee.isBeyondMelee() and love.filesystem.getInfo(stockbmf) then
715						-- Beyond Melee icon override
716						textures.stocks[cid][sid-1] = newImage(stockbmf)
717					elseif love.filesystem.getInfo(stockf) then
718						textures.stocks[cid][sid-1] = newImage(stockf)
719					end
720				end
721			else
722				if textures.stocks[cid][1] then textures.stocks[cid][1]:release() end
723				textures.stocks[cid][1] = newImage(("textures/stocks/%s.png"):format(info.name))
724			end
725		end
726	end
727
728	function melee.loadTextures()
729		doload(character_selections)
730	end
731
732	function melee.loadRomSpecificTextures()
733		doload(character_selections)
734		if melee.isAkaneia() then
735			print("LOADED AKANEIA TEXTURES")
736			doload(akaneia_selection)
737		elseif melee.isBeyondMelee() then
738			print("LOADED BEYOND MELEE TEXTURES")
739			doload(beyondmelee_selection)
740		end
741	end
742end
743
744function melee.getPlayer(port)
745	if not memory.player then return end
746
747	if melee.isSinglePlayerGame() and not melee.isNetplayGame() and port == memory.menu.player_one_port + 1 then
748		-- Single player games in CSS screen always use PORT 1 character info no matter what port is controlling the menus
749		return memory.player[1].select
750	elseif not melee.isInGame() then
751		return memory.player[port].select
752	end
753
754	return memory.player[port]
755end
756
757function melee.getCharacterID(port)
758	if not memory.player then return end
759
760	local player = melee.getPlayer(port)
761
762	if not player then return end
763
764	local character = player.character
765
766	if melee.isInGame() then
767		local transformed = player.transformed == 256
768
769		-- Handle and detect Zelda/Sheik transformations
770		if character == 0x13 then
771			character = transformed and 0x12 or 0x13
772		elseif character == 0x12 then
773			character = transformed and 0x13 or 0x12
774		end
775	end
776
777	return character
778end
779
780function melee.getStockTexture(id, skin)
781	if textures.skinless[id] == true then
782		skin = 1
783	end
784	if not textures.stocks[id] or not textures.stocks[id][skin] then
785		return textures.stocks[id] and textures.stocks[id][0] or textures.stocks[0x21][1]
786	end
787	return textures.stocks[id][skin]
788end
789
790function melee.getSeriesTexture(id)
791	if not textures.series[id] then
792		return textures.series[0x21]
793	end
794	return textures.series[id]
795end
796
797function melee.drawSeries(port, ...)
798	local id = melee.getCharacterID(port)
799	if not id then return end
800	local series = melee.getSeriesTexture(melee.isPortEnabled(port) and id or 0x21)
801	if not series then return end
802	graphics.easyDraw(series, ...)
803end
804
805function melee.getSinglePlayerPort()
806	if melee.isSinglePlayerGame() and not melee.isNetplayGame() then
807		return 1
808	else
809		return memory.menu.player_one_port+1
810	end
811end
812
813function melee.drawStock(port, ...)
814	if not melee.isPortEnabled(port) then return end
815	local id = melee.getCharacterID(port)
816	if id == 0x21 or not memory.player then return end
817	local player = melee.getPlayer(port)
818	if not player or not id then return end
819	local stock = melee.getStockTexture(id, player.skin)
820	if not stock then return end
821	graphics.easyDraw(stock, ...)
822end
823
824local TEAM_COLORS = {
825	[0x00] = color(245, 46, 46, 255),	-- Red
826	[0x01] = color(84, 99, 255, 255),	-- Blue
827	[0x02] = color(31, 158, 64, 255),	-- Green
828	[0x04] = color(200, 200, 200, 255),	-- CPU/Disabled
829}
830
831function melee.getPlayerTeamColor(port)
832	if not melee.isPortEnabled(port) then return TEAM_COLORS[0x04] end
833	local player = melee.isInGame() and melee.getPlayer(port) or memory.player[port].card
834	if not player then return TEAM_COLORS[0x04] end
835	return TEAM_COLORS[player.team] or color_white
836end
837
838local PLAYER_COLORS = {
839	[1] = color(245, 46, 46, 255),
840	[2] = color(84, 99, 255, 255),
841	[3] = color(255, 199, 23, 255),
842	[4] = color(31, 158, 64, 255),
843}
844
845local PORT_PLAYER = 0x0
846local PORT_CPU = 0x1
847local PORT_DISABLED = 0x3
848
849function melee.isPortEnabled(port)
850	if not port then return false end
851	if melee.isInMenus() and melee.isSinglePlayerGame() and port ~= (memory.menu.player_one_port+1) then return false end
852	return memory.player[port].card.mode ~= PORT_DISABLED
853end
854
855function melee.isPortCPU(port)
856	return memory.player[port].card.mode == PORT_CPU
857end
858
859function melee.getPlayerColor(port)
860	if melee.isPortCPU(port) then
861		return TEAM_COLORS[0x04] or color_white
862	elseif melee.isPortEnabled(port) then
863		return PLAYER_COLORS[port] or color_white
864	end
865	return TEAM_COLORS[0x04] or color_white
866end
867
868local STAGE_SERIES = {
869	[0x02] = "Super Mario", -- Princess Peach's Castle
870	[0x03] = "Super Mario", -- Rainbow Cruise
871	[0x04] = "Donkey Kong", -- Kongo Jungle
872	[0x05] = "Donkey Kong", -- Jungle Japes
873	[0x06] = "The Legend of Zelda", -- Great Bay
874	[0x07] = "The Legend of Zelda", -- Hyrule Temple
875	[0x08] = "Metroid", -- Brinstar
876	[0x09] = "Metroid", -- Brinstar Depths
877	[0x0A] = "Yoshi", -- Yoshi's Story
878	[0x0B] = "Yoshi", -- Yoshi's Island
879	[0x0C] = "Kirby", -- Fountain of Dreams
880	[0x0D] = "Kirby", -- Green Greens
881	[0x0E] = "Star Fox", -- Corneria
882	[0x0F] = "Star Fox", -- Venom
883	[0x10] = "Pokémon", -- Pokémon Stadium
884	[0x11] = "Pokémon", -- Poké Floats
885	[0x12] = "F-Zero", -- Mute City
886	[0x13] = "F-Zero", -- Big Blue
887	[0x14] = "Earthbound", -- Onett
888	[0x15] = "Earthbound", -- Fourside
889	[0x16] = "Ice Climbers", -- Icicle Mountain
890	[0x18] = "Super Mario", -- Mushroom Kingdom
891	[0x19] = "Super Mario", -- Mushroom Kingdom 2
892	[0x1B] = "Game & Watch", -- Flat Zone
893	[0x1C] = "Kirby", -- Dream Land N64
894	[0x1D] = "Yoshi", -- Yoshi's Island N64
895	[0x1E] = "Donkey Kong", -- Kongo Jungle N64
896	[0x24] = "Super Smash Bros", -- Battlefield
897	[0x25] = "Super Smash Bros", -- Final Destination
898	[0x26] = "Super Smash Bros", -- Trophy Collection
899
900	-- Singleplayer stages
901	[0x1F] = "Super Mario", -- Mushroom Kingdom
902	[0x20] = "The Legend of Zelda", -- Underground Maze
903	[0x21] = "Metroid", -- Escape Zebes
904	[0x22] = "F-Zero", -- F-Zero Grand Prix
905	[0x26] = "Super Smash Bros", -- Trophy Collection
906	[0x27] = "Super Smash Bros", -- Race to the Finish
907	[0x42] = "Super Smash Bros", -- All-Star Rest Area
908	[0x43] = "Super Smash Bros", -- Home-Run Contest
909	[0x44] = "Super Mario", -- Trophy Tussel - Goomba
910	[0x45] = "Pokémon", -- Trophy Tussel - Entei
911	[0x46] = "The Legend of Zelda", -- Trophy Tussel - Majora's Mask
912
913
914}
915
916local STAGE_NAMES = {
917	[0x02] = "Princess Peach's Castle",
918	[0x03] = "Rainbow Cruise",
919	[0x04] = "Kongo Jungle",
920	[0x05] = "Jungle Japes",
921	[0x06] = "Great Bay",
922	[0x07] = "Hyrule Temple",
923	[0x08] = "Brinstar",
924	[0x09] = "Brinstar Depths",
925	[0x0A] = "Yoshi's Story",
926	[0x0B] = "Yoshi's Island",
927	[0x0C] = "Fountain of Dreams",
928	[0x0D] = "Green Greens",
929	[0x0E] = "Corneria",
930	[0x0F] = "Venom",
931	[0x10] = "Pokémon Stadium",
932	[0x11] = "Poké Floats",
933	[0x12] = "Mute City",
934	[0x13] = "Big Blue",
935	[0x14] = "Onett",
936	[0x15] = "Fourside",
937	[0x16] = "Icicle Mountain",
938	[0x18] = "Mushroom Kingdom",
939	[0x19] = "Mushroom Kingdom 2",
940	[0x1B] = "Flat Zone",
941	[0x1C] = "Dream Land N64",
942	[0x1D] = "Yoshi's Island N64",
943	[0x1E] = "Kongo Jungle N64",
944	[0x24] = "Battlefield",
945	[0x25] = "Final Destination",
946}
947
948local BREAK_THE_TARGETS_STAGES = {
949	[0x28] = "Mario Target Test",
950	[0x29] = "Captain Falcon Target Test",
951	[0x2A] = "Young Link Target Test",
952	[0x2B] = "Donkey Kong Target Test",
953	[0x2C] = "Dr. Mario Target Test",
954	[0x2D] = "Falco Target Test",
955	[0x2E] = "Fox Target Test",
956	[0x2F] = "Ice Climbers Target Test",
957	[0x30] = "Kirby Target Test",
958	[0x31] = "Bowser Target Test",
959	[0x32] = "Link Target Test",
960	[0x33] = "Luigi Target Test",
961	[0x34] = "Marth Target Test",
962	[0x35] = "Mewtwo Target Test",
963	[0x36] = "Ness Target Test",
964	[0x37] = "Peach Target Test",
965	[0x38] = "Pichu Target Test",
966	[0x39] = "Pikachu Target Test",
967	[0x3A] = "Jigglypuff Target Test",
968	[0x3B] = "Samus Target Test",
969	[0x3C] = "Sheik Target Test",
970	[0x3D] = "Yoshi Target Test",
971	[0x3E] = "Zelda Target Test",
972	[0x3F] = "Mr. G&W Target Test",
973	[0x40] = "Roy Target Test",
974	[0x41] = "Ganondorf Target Test",
975
976	-- Akaneia
977	[0x4E] = "Wolf Target Test",
978}
979
980local SINGLEPLAYER_STAGES = {
981	[0x1F] = "Mushroom Kingdom",
982	[0x20] = "Underground Maze",
983	[0x21] = "Escape Zebes",
984	[0x22] = "F-Zero Grand Prix",
985	[0x26] = "Trophy Collection",
986	[0x27] = "Race to the Finish",
987	[0x42] = "All-Star Rest Area",
988	[0x43] = "Home-Run Contest",
989	[0x44] = "Trophy Tussle - Goomba",
990	[0x45] = "Trophy Tussle - Entei",
991	[0x46] = "Trophy Tussle - Majora's Mask",
992}
993
994local AKANEIA_STAGES = {
995	[0x47] = "Peach's Castle 64",
996	[0x48] = "Hyrule Castle 64",
997	[0x49] = "Saffron City 64",
998	[0x4A] = "Planet Zebes 64",
999	[0x4B] = "Mushroom Kingdom 64",
1000	[0x4C] = "Metal Cavern",
1001	[0x4D] = "Volleyball",
1002}
1003
1004local AKANEIA_SERIES = {
1005	[0x47] = "Super Mario",
1006	[0x48] = "The Legend of Zelda",
1007	[0x49] = "Pokémon",
1008	[0x4A] = "Metroid",
1009	[0x4B] = "Super Mario",
1010	[0x4C] = "Super Mario",
1011	[0x4D] = "Super Smash Bros",
1012}
1013
1014local BEYOND_MELEE_STAGES = {
1015	[0x47] = "Volleyball",
1016	[0x48] = "Smashville",
1017	[0x49] = "Sprout Tower",
1018	[0x4A] = "Fountain of Dreams",
1019	[0x4B] = "Flipper Field",
1020	[0x4C] = "Brinstar Lab",
1021	[0x4D] = "Metal Cavern", -- Metal Cavern? (Currently broken in BM-1.0)
1022	[0x4E] = "Mute Circuit",
1023	[0x4F] = "Kongo Falls",
1024	[0x50] = "Town Greens",
1025	[0x51] = "Kongle Jungle 64",
1026	[0x52] = "Poké Float Stadium 2",
1027	[0x53] = "Rainbow Ride",
1028	[0x54] = "Island Zone",
1029	[0x55] = "Wasteland",
1030	[0x56] = "Baby Bowser's Castle",
1031	[0x57] = "Midnight Destination",
1032	[0x58] = "Midnight Battlefield",
1033	[0x59] = "Dual Zone",
1034	[0x5A] = "Fountain of Dreams", -- Diet (Currently broken in BM-1.0)
1035	[0x5B] = "Stadium-ville", -- Diet (Currently broken in BM-1.0)
1036	[0x5C] = "Yoshi's Story", -- Diet
1037	[0x5D] = "Treasure Hunt",
1038	[0x5E] = "Realgam Colosseum",
1039	[0x5F] = "Vapor Story",
1040	[0x60] = "Final Destination", -- Diet
1041	[0x61] = "Battlefield", -- Diet
1042	[0x62] = "Pokémon Stadium", -- Diet
1043	[0x63] = "Galacta Battleground",
1044}
1045
1046local BEYOND_MELEE_SERIES = {
1047	[0x47] = "Super Smash Bros", -- Volleyball
1048	[0x48] = "Animal Crossing", -- Smashville
1049	[0x49] = "Pokémon", -- Sprout Tower
1050	[0x4A] = "Kirby", -- Fountain of Dreams
1051	[0x4B] = "Super Smash Bros", -- Flipper Field
1052	[0x4C] = "Metroid", -- Brinstar Lab
1053	[0x4D] = "Super Mario", -- Metal Cavern? (Currently broken in BM-1.0)
1054	[0x4E] = "F-Zero", -- Mute Circuit
1055	[0x4F] = "Donkey Kong", -- Kongo Falls
1056	[0x50] = "Kirby", -- Town Greens
1057	[0x51] = "Donkey Kong", -- Kongle Jungle 64
1058	[0x52] = "Pokémon", -- Poké Float Stadium 2
1059	[0x53] = "Super Mario", -- Rainbow Ride
1060	[0x54] = "Yoshi", -- Island Zone
1061	[0x55] = "Kirby", -- Wasteland
1062	[0x56] = "Yoshi", -- Baby Bowser's Castle
1063	[0x57] = "Super Smash Bros", -- Midnight Destination
1064	[0x58] = "Super Smash Bros", -- Midnight Battlefield
1065	[0x59] = "Super Smash Bros", -- Dual Zone
1066	[0x5A] = "Kirby", -- Fountain of Dreams (Diet) (Currently broken in BM-1.0)
1067	[0x5B] = "Pokémon", -- Stadium-ville (Diet) (Currently broken in BM-1.0)
1068	[0x5C] = "Yoshi", -- Yoshi's Story (Diet)
1069	[0x5D] = "Yoshi", -- Treasure Hunt
1070	[0x5E] = "Pokémon", -- Realgam Colosseum
1071	[0x5F] = "Yoshi", -- Vapor Story
1072	[0x60] = "Super Smash Bros", -- Final Destination (Diet)
1073	[0x61] = "Super Smash Bros", -- Battlefield (Diet)
1074	[0x62] = "Pokémon", -- Pokémon Stadium (Diet)
1075	[0x63] = "Kirby", -- Galacta Battleground
1076}
1077
1078function melee.isNetplayGame()
1079	return memory.scene.major == SCENE_VS_ONLINE and (memory.scene.minor == SCENE_VS_ONLINE_INGAME or memory.scene.minor == SCENE_VS_ONLINE_VERSUS)
1080end
1081
1082function melee.isTeams()
1083	if melee.isSinglePlayerGame() and not melee.isNetplayGame() then
1084		return false
1085	elseif melee.isInGame() then
1086		return memory.match.settings.teams
1087	else
1088		return memory.menu.teams
1089	end
1090end
1091
1092function melee.isSinglePlayerGame()
1093	local major = memory.scene.major
1094	return	major == SCENE_ALL_STAR_MODE or major == SCENE_TRAINING_MODE or
1095			major == SCENE_EVENT_MATCH or major == SCENE_CLASSIC_MODE or
1096			major == SCENE_ADVENTURE_MODE or major == SCENE_TARGET_TEST or
1097			(major >= SCENE_HOME_RUN_CONTEST and major <= SCENE_CRUEL_MELEE) or
1098			major == SCENE_VS_ONLINE
1099end
1100
1101function melee.isBTTStage(id)
1102	return BREAK_THE_TARGETS_STAGES[id] ~= nil
1103end
1104
1105function melee.isSinglePlayerStage(id)
1106	return SINGLEPLAYER_STAGES[id] ~= nil
1107end
1108
1109function melee.getSinglePlayerStages()
1110	return SINGLEPLAYER_STAGES
1111end
1112
1113function melee.getAllStages()
1114	return STAGE_NAMES
1115end
1116
1117function melee.getAkaneiaStages()
1118	return AKANEIA_STAGES
1119end
1120
1121function melee.getAkaneiaSeries()
1122	return AKANEIA_SERIES
1123end
1124
1125function melee.isAkaneiaStage(id)
1126	if melee.isAkaneia() then
1127		return AKANEIA_STAGES[id] ~= nil
1128	end
1129	return false
1130end
1131
1132function melee.getBeyondMeleeStages()
1133	return BEYOND_MELEE_STAGES
1134end
1135
1136function melee.getBeyondMeleeSeries()
1137	return BEYOND_MELEE_SERIES
1138end
1139
1140function melee.isBeyondMeleeStage(id)
1141	if melee.isBeyondMelee() then
1142		return BEYOND_MELEE_STAGES[id] ~= nil
1143	end
1144	return false
1145end
1146
1147function melee.getStageName(id)
1148	if melee.isAkaneia() and AKANEIA_STAGES[id] then
1149		return AKANEIA_STAGES[id]
1150	elseif melee.isBeyondMelee() and BEYOND_MELEE_STAGES[id] then
1151		return BEYOND_MELEE_STAGES[id]
1152	end
1153	return STAGE_NAMES[id] or SINGLEPLAYER_STAGES[id] or BREAK_THE_TARGETS_STAGES[id]
1154end
1155
1156function melee.getAllStageSeries()
1157	return STAGE_SERIES
1158end
1159
1160function melee.getStageSeries(id)
1161	if melee.isAkaneia() and AKANEIA_SERIES[id] then
1162		return AKANEIA_SERIES[id]
1163	elseif melee.isBeyondMelee() and BEYOND_MELEE_SERIES[id] then
1164		return BEYOND_MELEE_SERIES[id]
1165	end
1166	return STAGE_SERIES[id]
1167end
1168
1169function melee.matchFinsihed()
1170	return memory.match.info.finished == true
1171end
1172
1173function melee.isPaused()
1174	return memory.match.info.paused
1175end
1176
1177function melee.isInGame()
1178	if not memory.scene then return false end
1179
1180	if memory.scene.major == SCENE_ALL_STAR_MODE and memory.scene.minor < SCENE_ALL_STAR_CSS then
1181		-- Even = playing the match
1182		-- Odd  = in the rest area
1183		--return memory.scene.minor % 2 == 0
1184		return true
1185	end
1186	if PANEL_SETTINGS:IsSlippiReplay() and memory.scene.major == SCENE_START_MATCH then
1187		return memory.scene.minor == SCENE_START_MATCH_INGAME
1188	end
1189	if memory.scene.major == SCENE_VS_MODE or memory.scene.major == SCENE_VS_ONLINE then
1190		return memory.scene.minor == SCENE_VS_INGAME
1191	end
1192	if memory.scene.major >= SCENE_TRAINING_MODE and memory.scene.major <= SCENE_STAMINA_MODE or memory.scene.major == SCENE_FIXED_CAMERA_MODE then
1193		return memory.scene.minor == SCENE_TRAINING_INGAME
1194	end
1195	if memory.scene.major == SCENE_EVENT_MATCH then
1196		return memory.scene.minor == SCENE_EVENT_MATCH_INGAME
1197	end
1198	if memory.scene.major == SCENE_CLASSIC_MODE and memory.scene.minor < SCENE_CLASSIC_CONTINUE then
1199		-- Even = Verus screen
1200		-- Odd  = playing the match
1201		return memory.scene.minor % 2 == 1
1202	end
1203	if memory.scene.major == SCENE_ADVENTURE_MODE then
1204		return
1205		memory.scene.minor == SCENE_ADVENTURE_MUSHROOM_KINGDOM or
1206		memory.scene.minor == SCENE_ADVENTURE_MUSHROOM_KINGDOM_BATTLE or
1207		memory.scene.minor == SCENE_ADVENTURE_MUSHROOM_KONGO_JUNGLE_TINY_BATTLE or
1208		memory.scene.minor == SCENE_ADVENTURE_MUSHROOM_KONGO_JUNGLE_GIANT_BATTLE or
1209		memory.scene.minor == SCENE_ADVENTURE_UNDERGROUND_MAZE or
1210		memory.scene.minor == SCENE_ADVENTURE_HYRULE_TEMPLE_BATTLE or
1211		memory.scene.minor == SCENE_ADVENTURE_BRINSTAR or
1212		memory.scene.minor == SCENE_ADVENTURE_ESCAPE_ZEBES or
1213		memory.scene.minor == SCENE_ADVENTURE_GREEN_GREENS_KIRBY_BATTLE or
1214		memory.scene.minor == SCENE_ADVENTURE_GREEN_GREENS_KIRBY_TEAM_BATTLE or
1215		memory.scene.minor == SCENE_ADVENTURE_GREEN_GREENS_GIANT_KIRBY_BATTLE or
1216		memory.scene.minor == SCENE_ADVENTURE_CORNARIA_BATTLE_1 or
1217		memory.scene.minor == SCENE_ADVENTURE_CORNARIA_BATTLE_2 or
1218		memory.scene.minor == SCENE_ADVENTURE_CORNARIA_BATTLE_3 or
1219		memory.scene.minor == SCENE_ADVENTURE_POKEMON_STADIUM_BATTLE or
1220		memory.scene.minor == SCENE_ADVENTURE_FZERO_GRAND_PRIX_RACE or
1221		memory.scene.minor == SCENE_ADVENTURE_FZERO_GRAND_PRIX_BATTLE or
1222		memory.scene.minor == SCENE_ADVENTURE_ONETT_BATTLE or
1223		memory.scene.minor == SCENE_ADVENTURE_ICICLE_MOUNTAIN_CLIMB or
1224		memory.scene.minor == SCENE_ADVENTURE_BATTLEFIELD_BATTLE or
1225		memory.scene.minor == SCENE_ADVENTURE_BATTLEFIELD_METAL_BATTLE or
1226		memory.scene.minor == SCENE_ADVENTURE_FINAL_DESTINATION_BATTLE
1227	end
1228	if memory.scene.major == SCENE_TARGET_TEST then
1229		return memory.scene.minor == SCENE_TARGET_TEST_INGAME
1230	end
1231	if memory.scene.major >= SCENE_SUPER_SUDDEN_DEATH and memory.scene.major <= MENU_LIGHTNING_MELEE then
1232		return memory.scene.minor == SCENE_SSD_INGAME
1233	end
1234	if memory.scene.major >= SCENE_HOME_RUN_CONTEST and memory.scene.major <= SCENE_CRUEL_MELEE then
1235		return memory.scene.minor == SCENE_HOME_RUN_CONTEST_INGAME
1236	end
1237	if memory.scene.major == SCENE_TITLE_SCREEN_IDLE then
1238		return memory.scene.minor == SCENE_TITLE_SCREEN_IDLE_FIGHT_1 or memory.scene.minor == SCENE_TITLE_SCREEN_IDLE_FIGHT_2
1239	end
1240	return false
1241end
1242
1243function melee.isInMenus()
1244	if not memory.scene then return false end
1245	
1246	if memory.scene.major == SCENE_MAIN_MENU then
1247		return true
1248	end
1249	if memory.scene.major == SCENE_VS_MODE then
1250		return memory.scene.minor == SCENE_VS_CSS or memory.scene.minor == SCENE_VS_SSS
1251	end
1252	if memory.scene.major == SCENE_VS_ONLINE then
1253		return memory.scene.minor == SCENE_VS_ONLINE_CSS or memory.scene.minor == SCENE_VS_ONLINE_SSS or memory.scene.minor == SCENE_VS_ONLINE_RANKED 
1254	end
1255	if memory.scene.major >= SCENE_TRAINING_MODE and memory.scene.major <= SCENE_STAMINA_MODE or memory.scene.major == SCENE_FIXED_CAMERA_MODE then
1256		return memory.scene.minor == SCENE_TRAINING_CSS or memory.scene.minor == SCENE_TRAINING_SSS
1257	end
1258	if memory.scene.major == SCENE_EVENT_MATCH then
1259		return memory.scene.minor == SCENE_EVENT_MATCH_SELECT
1260	end
1261	if memory.scene.major == SCENE_CLASSIC_MODE or memory.scene.major == SCENE_ADVENTURE_MODE or memory.scene.major == SCENE_ALL_STAR_MODE then
1262		-- All the menu_mior values all match in these three modes, so just use the SCENE_CLASSIC_CSS value for simplicity
1263		return memory.scene.minor == SCENE_CLASSIC_CSS
1264	end
1265	if memory.scene.major == SCENE_TARGET_TEST then
1266		return memory.scene.minor == SCENE_TARGET_TEST_CSS
1267	end
1268	if memory.scene.major >= SCENE_SUPER_SUDDEN_DEATH and memory.scene.major <= MENU_LIGHTNING_MELEE then
1269		return memory.scene.minor == SCENE_SSD_CSS or memory.scene.minor == SCENE_SSD_SSS
1270	end
1271	if memory.scene.major >= SCENE_HOME_RUN_CONTEST and memory.scene.major <= SCENE_CRUEL_MELEE then
1272		return memory.scene.minor == SCENE_HOME_RUN_CONTEST_CSS
1273	end
1274	return false
1275end
1276
1277function melee.isCountdownTimer()
1278	return melee.isInGame() and bit.band(memory.match.settings.flags[1], 0x3) == 0x2
1279end
1280
1281return melee