2022-01-26 04:28:34 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
usf_types = ['u8', 'u16', 'u32', 'u64', 's8', 's16', 's32', 's64', 'f32']
|
2022-09-27 02:11:51 +00:00
|
|
|
vec3_types = ['Vec3s', 'Vec3f', 'Color']
|
2022-11-30 08:37:12 +00:00
|
|
|
vec4_types = ['Vec4s', 'Vec4f']
|
|
|
|
mat4_types = ['Mat4', 'Mtx']
|
2022-04-09 04:01:17 +00:00
|
|
|
typedef_pointers = ['BehaviorScript', 'ObjectAnimPointer', 'Collision', 'LevelScript', 'Trajectory']
|
2022-01-26 04:28:34 +00:00
|
|
|
|
|
|
|
exclude_structs = [
|
|
|
|
'SPTask',
|
|
|
|
'VblankHandler',
|
|
|
|
'GraphNodeRoot',
|
|
|
|
'MarioAnimDmaRelatedThing',
|
|
|
|
'UnusedArea28',
|
|
|
|
]
|
|
|
|
|
|
|
|
def get_path(p):
|
|
|
|
return os.path.dirname(os.path.realpath(__file__)) + '/../' + p
|
|
|
|
|
|
|
|
def translate_type_to_lvt(ptype):
|
2022-11-30 08:37:12 +00:00
|
|
|
pointerLvl = 0
|
|
|
|
|
|
|
|
if ptype == "char":
|
|
|
|
ptype = "u8"
|
|
|
|
|
|
|
|
if "const " in ptype:
|
|
|
|
ptype = ptype.replace("const ", "").strip()
|
|
|
|
|
|
|
|
if ("char" in ptype and "[" in ptype):
|
|
|
|
return "LVT_STRING"
|
|
|
|
|
|
|
|
if "[" in ptype or "{" in ptype:
|
|
|
|
return "LOT_???"
|
|
|
|
|
|
|
|
# Strip out our pointer stars to get the true type.
|
|
|
|
if "*" in ptype:
|
|
|
|
# Count how many stars there is for our pointer level.
|
|
|
|
pointerLvl = ptype.count("*")
|
|
|
|
ptype = ptype.replace("*", "").strip()
|
|
|
|
|
|
|
|
if ptype == "char" and pointerLvl == 1:
|
|
|
|
return "LVT_STRING_P"
|
|
|
|
|
|
|
|
if "enum " in ptype:
|
|
|
|
if pointerLvl > 1:
|
|
|
|
return "LVT_???"
|
|
|
|
if pointerLvl == 1:
|
|
|
|
return "LVT_S32_P"
|
|
|
|
return "LVT_S32"
|
|
|
|
|
|
|
|
if ptype == "bool":
|
|
|
|
if pointerLvl > 1:
|
|
|
|
return "LVT_???"
|
|
|
|
if pointerLvl == 1:
|
|
|
|
return "LVT_BOOL_P"
|
|
|
|
return "LVT_BOOL"
|
2022-02-16 06:09:21 +00:00
|
|
|
|
2022-01-26 04:28:34 +00:00
|
|
|
if ptype in usf_types:
|
2022-11-30 08:37:12 +00:00
|
|
|
if pointerLvl > 1:
|
|
|
|
return "LVT_???"
|
|
|
|
if pointerLvl == 1:
|
|
|
|
return "LVT_" + ptype.upper() + "_P"
|
|
|
|
return "LVT_" + ptype.upper()
|
2022-02-16 06:09:21 +00:00
|
|
|
|
2022-01-26 04:28:34 +00:00
|
|
|
if ptype in vec3_types:
|
2022-11-30 08:37:12 +00:00
|
|
|
if pointerLvl > 1:
|
|
|
|
return "LVT_???"
|
|
|
|
if pointerLvl == 1:
|
|
|
|
return "LVT_COBJECT_P"
|
|
|
|
return "LVT_COBJECT"
|
|
|
|
|
|
|
|
if ptype in vec4_types:
|
|
|
|
if pointerLvl > 1:
|
|
|
|
return "LVT_???"
|
|
|
|
if pointerLvl == 1:
|
|
|
|
return "LVT_COBJECT_P"
|
|
|
|
return "LVT_COBJECT"
|
|
|
|
|
|
|
|
if ptype in mat4_types:
|
|
|
|
if pointerLvl > 1:
|
|
|
|
return "LVT_???"
|
|
|
|
if pointerLvl == 1:
|
|
|
|
return "LVT_COBJECT_P"
|
|
|
|
return "LVT_COBJECT"
|
|
|
|
|
|
|
|
if ptype == "float":
|
|
|
|
if pointerLvl > 1:
|
|
|
|
return "LVT_???"
|
|
|
|
if pointerLvl == 1:
|
|
|
|
return "LVT_F32_P"
|
|
|
|
return "LVT_F32"
|
|
|
|
|
|
|
|
if ptype == "LuaFunction":
|
|
|
|
return "LVT_LUAFUNCTION"
|
|
|
|
|
|
|
|
if "struct" in ptype:
|
|
|
|
if pointerLvl > 1:
|
|
|
|
return "LVT_???"
|
|
|
|
if pointerLvl == 1:
|
|
|
|
return "LVT_COBJECT_P"
|
|
|
|
return "LVT_COBJECT"
|
|
|
|
|
|
|
|
if pointerLvl == 1 and "(" not in ptype and "[" not in ptype:
|
|
|
|
ptype = ptype.replace("const", "").replace("*", "").strip()
|
2022-02-23 02:29:30 +00:00
|
|
|
if ptype in usf_types or ptype in typedef_pointers:
|
2022-11-30 08:37:12 +00:00
|
|
|
return "LVT_%s_P" % ptype.upper()
|
2022-02-16 06:09:21 +00:00
|
|
|
|
2022-11-30 08:37:12 +00:00
|
|
|
return "LVT_???"
|
2022-01-26 04:28:34 +00:00
|
|
|
|
|
|
|
def translate_type_to_lot(ptype):
|
2022-11-30 08:37:12 +00:00
|
|
|
if ptype == 'void':
|
|
|
|
return 'LOT_NONE'
|
|
|
|
|
2022-02-03 08:42:31 +00:00
|
|
|
if ptype == 'const char*':
|
|
|
|
return 'LOT_NONE'
|
2022-02-16 06:09:21 +00:00
|
|
|
|
2022-02-03 08:42:31 +00:00
|
|
|
if ptype == 'char*' or ('char' in ptype and '[' in ptype):
|
|
|
|
return 'LOT_NONE'
|
|
|
|
|
2022-02-16 06:13:10 +00:00
|
|
|
if 'const ' in ptype:
|
|
|
|
ptype = ptype.replace('const ', '')
|
|
|
|
|
|
|
|
if ptype == 'char':
|
|
|
|
ptype = 'u8'
|
|
|
|
|
2022-01-26 04:28:34 +00:00
|
|
|
if '[' in ptype or '{' in ptype:
|
|
|
|
return 'LOT_???'
|
2022-02-16 06:09:21 +00:00
|
|
|
|
2022-02-03 03:24:51 +00:00
|
|
|
if 'enum ' in ptype:
|
|
|
|
return 'LOT_NONE'
|
2022-02-16 06:09:21 +00:00
|
|
|
|
2022-02-03 03:24:51 +00:00
|
|
|
if ptype == 'bool':
|
2022-01-27 04:35:13 +00:00
|
|
|
return 'LOT_NONE'
|
2022-02-16 06:09:21 +00:00
|
|
|
|
2022-01-26 04:28:34 +00:00
|
|
|
if ptype in usf_types:
|
|
|
|
return 'LOT_NONE'
|
2022-02-16 06:09:21 +00:00
|
|
|
|
2022-01-26 04:28:34 +00:00
|
|
|
if ptype in vec3_types:
|
|
|
|
return 'LOT_' + ptype.upper()
|
2022-11-30 08:37:12 +00:00
|
|
|
|
|
|
|
if ptype in vec4_types:
|
|
|
|
return 'LOT_' + ptype.upper()
|
|
|
|
|
|
|
|
if ptype in mat4_types:
|
|
|
|
return 'LOT_' + ptype.upper()
|
2022-02-16 06:09:21 +00:00
|
|
|
|
2022-01-26 04:28:34 +00:00
|
|
|
if ptype == 'float':
|
|
|
|
return 'LOT_NONE'
|
2022-02-16 06:09:21 +00:00
|
|
|
|
2022-02-23 07:31:29 +00:00
|
|
|
if ptype == 'LuaFunction':
|
|
|
|
return 'LOT_NONE'
|
|
|
|
|
2022-01-26 04:28:34 +00:00
|
|
|
if 'struct' in ptype:
|
2022-01-27 04:35:13 +00:00
|
|
|
if ptype.count('*') > 1:
|
2022-02-23 02:29:30 +00:00
|
|
|
return 'LOT_???'
|
|
|
|
|
2022-01-26 04:28:34 +00:00
|
|
|
struct_id = ptype.split(' ')[1].replace('*', '')
|
2022-02-23 02:29:30 +00:00
|
|
|
|
2022-01-26 04:28:34 +00:00
|
|
|
if struct_id in exclude_structs:
|
|
|
|
return 'LOT_???'
|
2022-02-23 02:29:30 +00:00
|
|
|
|
2022-01-26 04:28:34 +00:00
|
|
|
return 'LOT_' + struct_id.upper()
|
|
|
|
|
2022-02-16 06:09:21 +00:00
|
|
|
if ptype.count('*') == 1 and '???' not in translate_type_to_lvt(ptype):
|
|
|
|
return 'LOT_POINTER'
|
2022-11-30 08:37:12 +00:00
|
|
|
|
2022-02-16 06:09:21 +00:00
|
|
|
return 'LOT_???'
|
2022-01-30 06:47:22 +00:00
|
|
|
|
|
|
|
def translate_type_to_lua(ptype):
|
|
|
|
if ptype.startswith('struct '):
|
2022-03-05 06:22:31 +00:00
|
|
|
ptype = ptype.split(' ')[1].replace('*', '')
|
|
|
|
return ptype, 'structs.md#%s' % ptype
|
2022-01-30 06:47:22 +00:00
|
|
|
|
2022-02-03 08:42:31 +00:00
|
|
|
if ptype == 'const char*':
|
2022-03-05 06:22:31 +00:00
|
|
|
return '`string`', None
|
2022-02-03 08:42:31 +00:00
|
|
|
|
|
|
|
if ptype == 'char*' or ('char' in ptype and '[' in ptype):
|
2022-03-05 06:22:31 +00:00
|
|
|
return '`string`', None
|
2022-02-03 08:42:31 +00:00
|
|
|
|
2022-03-13 05:28:57 +00:00
|
|
|
ptype = ptype.replace('const ', '')
|
|
|
|
|
2022-01-30 06:47:22 +00:00
|
|
|
if 'Vec3' in ptype:
|
2022-03-05 06:22:31 +00:00
|
|
|
return ptype, 'structs.md#%s' % ptype
|
2022-01-30 06:47:22 +00:00
|
|
|
|
|
|
|
if ptype.startswith('enum '):
|
2022-03-05 06:22:31 +00:00
|
|
|
return ptype, 'constants.md#%s' % ptype.replace(' ', '-')
|
2022-01-30 06:47:22 +00:00
|
|
|
|
|
|
|
if ptype in usf_types:
|
|
|
|
if ptype.startswith('f'):
|
2022-03-05 06:22:31 +00:00
|
|
|
return '`number`', None
|
2022-11-30 08:37:12 +00:00
|
|
|
return '`integer`', None
|
2022-01-30 06:47:22 +00:00
|
|
|
|
2022-03-13 05:28:57 +00:00
|
|
|
if ptype == 'char':
|
|
|
|
return '`integer`', None
|
|
|
|
|
|
|
|
if ptype == 'int':
|
|
|
|
return '`integer`', None
|
|
|
|
|
|
|
|
if ptype == 'float':
|
|
|
|
return '`number`', None
|
|
|
|
|
|
|
|
if ptype == 'bool':
|
|
|
|
return '`boolean`', None
|
|
|
|
|
2022-01-30 06:47:22 +00:00
|
|
|
if 'void' == ptype:
|
2022-03-05 06:22:31 +00:00
|
|
|
return None, None
|
2022-01-30 06:47:22 +00:00
|
|
|
|
2022-02-23 07:31:29 +00:00
|
|
|
if ptype == 'LuaFunction':
|
2022-03-05 06:22:31 +00:00
|
|
|
return '`Lua Function` ()', None
|
2022-02-23 07:31:29 +00:00
|
|
|
|
2022-02-16 06:09:21 +00:00
|
|
|
if ptype.count('*') == 1 and '???' not in translate_type_to_lvt(ptype):
|
|
|
|
ptype = ptype.replace('const', '').replace('*', '').strip()
|
2022-03-05 06:22:31 +00:00
|
|
|
s = '`Pointer` <%s>' % translate_type_to_lua(ptype)[0]
|
|
|
|
return s, None
|
2022-02-16 06:09:21 +00:00
|
|
|
|
2022-03-05 06:22:31 +00:00
|
|
|
if not ptype.startswith('`'):
|
|
|
|
ptype = '`' + ptype + '`'
|
|
|
|
|
|
|
|
return ptype, None
|
2022-02-16 06:09:21 +00:00
|
|
|
|
2023-05-15 08:15:20 +00:00
|
|
|
def translate_type_to_rnd(ltype):
|
|
|
|
if 'enum ' in ltype:
|
|
|
|
ltype = 'integer'
|
|
|
|
elif '[' in ltype:
|
|
|
|
ltype = 'null'
|
|
|
|
elif '{' in ltype:
|
|
|
|
ltype = 'null'
|
|
|
|
elif '}' in ltype:
|
|
|
|
ltype = 'null'
|
|
|
|
elif 'void*' in ltype:
|
|
|
|
ltype = 'null'
|
|
|
|
|
|
|
|
return 'rnd_' + ltype.strip().replace('`', '').replace(' ', '').split('<')[-1].split('>')[0].split('(')[0].split('[')[0].split('*')[0] + '()'
|
|
|
|
|
2022-02-16 06:09:21 +00:00
|
|
|
def gen_comment_header(f):
|
|
|
|
comment_h = "// " + f + " //"
|
|
|
|
comment_l = "/" * len(comment_h)
|
|
|
|
s = ""
|
|
|
|
s += " " + comment_l + "\n"
|
|
|
|
s += " " + comment_h + "\n"
|
|
|
|
s += "" + comment_l + "\n"
|
|
|
|
s += "\n"
|
|
|
|
return s
|
2022-03-13 05:28:57 +00:00
|
|
|
|
|
|
|
def translate_to_def(ptype):
|
|
|
|
if ptype == None:
|
|
|
|
return 'nil'
|
|
|
|
if 'Lua Function' in ptype:
|
|
|
|
return 'function'
|
|
|
|
return ptype.replace('enum ', '').replace('const ', '').replace(' ', '').replace('`', '').replace('<', '_').replace('>', '')
|