-
Notifications
You must be signed in to change notification settings - Fork 1
/
import-mario-geo.py
executable file
·108 lines (85 loc) · 3.09 KB
/
import-mario-geo.py
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
#!/usr/bin/env python3
import os
import shutil
import urllib.request
GEO_URL = "https://raw.githubusercontent.com/n64decomp/sm64/06ec56df7f951f88da05f468cdcacecba496145a/actors/mario/geo.inc.c"
MODEL_URL = "https://raw.githubusercontent.com/n64decomp/sm64/06ec56df7f951f88da05f468cdcacecba496145a/actors/mario/model.inc.c"
geo_inc_c_header = """
#include "../include/sm64.h"
#include "../include/types.h"
#include "../include/geo_commands.h"
#include "../game/rendering_graph_node.h"
#include "../shim.h"
#include "../game/object_stuff.h"
#include "../game/behavior_actions.h"
#include "model.inc.h"
#define SHADOW_CIRCLE_PLAYER 99
"""
geo_inc_c_footer = """
const GeoLayout mario_geo_libsm64[] = {
GEO_SHADOW(SHADOW_CIRCLE_PLAYER, 0xB4, 100),
GEO_OPEN_NODE(),
GEO_ZBUFFER(1),
GEO_OPEN_NODE(),
GEO_SCALE(0x00, 16384),
GEO_OPEN_NODE(),
GEO_ASM(0, geo_mirror_mario_backface_culling),
GEO_ASM(0, geo_mirror_mario_set_alpha),
GEO_BRANCH(1, mario_geo_load_body),
GEO_ASM(1, geo_mirror_mario_backface_culling),
GEO_CLOSE_NODE(),
GEO_CLOSE_NODE(),
GEO_CLOSE_NODE(),
GEO_END(),
};
void *mario_geo_ptr = (void*)mario_geo_libsm64;
"""
geo_inc_h = """
#pragma once
extern void *mario_geo_ptr;
"""
model_inc_h = """
#pragma once
#include "../include/types.h"
#include "../include/PR/gbi.h"
extern Lights1 mario_blue_lights_group[];
extern Lights1 mario_red_lights_group[];
extern Lights1 mario_white_lights_group[];
extern Lights1 mario_brown1_lights_group[];
extern Lights1 mario_beige_lights_group[];
extern Lights1 mario_brown2_lights_group[];
"""
def main():
global model_inc_h
shutil.rmtree("src/decomp/mario", ignore_errors=True)
os.makedirs("src/decomp/mario", exist_ok=True)
print("Downloading " + GEO_URL)
geo_inc_c = urllib.request.urlopen(GEO_URL).read().decode('utf8')
print("Downloading " + MODEL_URL)
model_inc_c = urllib.request.urlopen(MODEL_URL).read().decode('utf8')
lines = model_inc_c.splitlines()
skip = 0
for i in range(len(lines)):
if skip > 0:
skip = skip - 1
lines[i] = "//" + lines[i]
elif lines[i].startswith("ALIGNED8 static const u8 mario_"):
skip = 2
lines[i] = "//" + lines[i]
elif lines[i].startswith("const "):
model_inc_h += "\nextern " + lines[i].replace(" = {", ";")
elif lines[i].startswith("static const Lights1 "):
lines[i] = lines[i].replace("static const Lights1", "Lights1")
lines.insert(0, "#include \"../../gfx_macros.h\"")
lines.insert(0, "#include \"../../load_tex_data.h\"")
model_inc_c = "\n".join(lines)
with open("src/decomp/mario/geo.inc.c", "w") as file:
file.write(geo_inc_c_header + geo_inc_c + geo_inc_c_footer)
with open("src/decomp/mario/model.inc.c", "w") as file:
file.write(model_inc_c)
with open("src/decomp/mario/model.inc.h", "w") as file:
file.write(model_inc_h)
with open("src/decomp/mario/geo.inc.h", "w") as file:
file.write(geo_inc_h)
if __name__ == "__main__":
main()