More Lua improvements

convert_functions.py no longer hardcodes acceptable LOT_ values
Added characters.h and surface_collision.h to convert_structs.py
Prevented mod filenames with a slash in it from being considered acceptable
Sanitized mod filenames when received from the server
This commit is contained in:
MysterD 2022-01-25 20:28:34 -08:00
parent 5a0a2eb9e0
commit a606c99cd1
16 changed files with 287 additions and 483 deletions

1
.gitignore vendored
View File

@ -66,6 +66,7 @@ sm64config.txt
/assets/**/*.bin
/sound/**/*.m64
/sound/**/*.aiff
/autogen/__pycache__
!/levels/**/*custom*.png
!/levels/**/*custom*/**/*.png
!/actors/**/*custom*.png

55
autogen/common.py Normal file
View File

@ -0,0 +1,55 @@
import os
usf_types = ['u8', 'u16', 'u32', 'u64', 's8', 's16', 's32', 's64', 'f32']
vec3_types = ['Vec3s', 'Vec3f']
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):
if ptype in usf_types:
return 'LVT_' + ptype.upper()
if ptype in vec3_types:
return 'LVT_COBJECT'
if ptype == 'float':
return 'LVT_F32'
if 'struct' in ptype:
if '*' in ptype:
return 'LVT_COBJECT_P'
return 'LVT_COBJECT'
return 'LVT_???'
def translate_type_to_lot(ptype):
if '[' in ptype or '{' in ptype:
return 'LOT_???'
if ptype in usf_types:
return 'LOT_NONE'
if ptype in vec3_types:
return 'LOT_' + ptype.upper()
if ptype == 'float':
return 'LOT_NONE'
if 'struct' in ptype:
struct_id = ptype.split(' ')[1].replace('*', '')
if struct_id in exclude_structs:
return 'LOT_???'
return 'LOT_' + struct_id.upper()
return 'LOT_???'
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

View File

@ -1,12 +1,12 @@
import os
import re
from common import *
rejects = ""
integer_types = ["u8", "u16", "u32", "u64", "s8", "s16", "s32", "s64", "int"]
number_types = ["f32", "float"]
cobject_types = ["struct MarioState*", "struct Object*", "struct Surface*"]
cobject_lot_types = ["LOT_MARIO_STATE", "LOT_OBJECT", "LOT_SURFACE"]
param_override_build = {}
out_filename = 'src/pc/lua/smlua_functions_autogen.c'
###########################################################
@ -104,16 +104,6 @@ def normalize_type(t):
t = parts[0] + ' ' + parts[1].replace(' ', '')
return t
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
def process_line(line):
function = {}
@ -165,11 +155,16 @@ def build_param(param, i):
return ' %s %s = smlua_to_integer(L, %d);\n' % (ptype, pid, i)
elif ptype in number_types:
return ' %s %s = smlua_to_number(L, %d);\n' % (ptype, pid, i)
elif ptype in cobject_types:
index = cobject_types.index(ptype)
return ' %s %s = (%s)smlua_to_cobject(L, %d, %s);\n' % (ptype, pid, ptype, i, cobject_lot_types[index])
else:
return ' ' + ptype + ' ' + pid + ' <--- UNIMPLEMENTED' + '\n'
lot = translate_type_to_lot(ptype)
s = ' %s %s = (%s)smlua_to_cobject(L, %d, %s);' % (ptype, pid, ptype, i, lot)
if '???' in lot:
s = '//' + s + ' <--- UNIMPLEMENTED'
else:
s = ' ' + s
return s + '\n'
def build_param_after(param, i):
ptype = param['type']
@ -273,12 +268,15 @@ def process_files():
process_file(dir_path + f)
############################################################################
def main():
process_files()
filename = os.path.dirname(os.path.realpath(__file__)) + '/../src/pc/lua/smlua_functions_autogen.c'
filename = get_path(out_filename)
with open(filename, 'w') as out:
out.write(template.replace("$[FUNCTIONS]", built_functions).replace("$[BINDS]", built_binds))
print('REJECTS:')
print(rejects)
main()
if __name__ == '__main__':
main()

View File

@ -1,286 +0,0 @@
import os
import re
rejects = ""
integer_types = ["u8", "u16", "u32", "u64", "s8", "s16", "s32", "s64", "int"]
number_types = ["f32", "float"]
smlua_functions_autogen_c = 'src/pc/lua/smlua_functions_autogen.c'
cobject_types = ["struct MarioState*", "struct Object*", "struct Surface*"]
cobject_lot_types = ["LOT_MARIOSTATE", "LOT_OBJECT", "LOT_SURFACE"]
param_override_build = {}
###########################################################
template = """/* THIS FILE IS AUTOGENERATED */
/* SHOULD NOT BE MANUALLY CHANGED */
#include "smlua.h"
#include "game/level_update.h"
#include "game/area.h"
#include "game/mario.h"
#include "game/mario_step.h"
#include "game/mario_actions_stationary.h"
#include "audio/external.h"
#include "object_fields.h"
#include "engine/math_util.h"
#include "engine/surface_collision.h"
$[FUNCTIONS]
void smlua_bind_functions_autogen(void) {
lua_State* L = gLuaState;
$[BINDS]
}
"""
###########################################################
param_vec3f_before_call = """
f32* $[IDENTIFIER] = smlua_get_vec3f_from_buffer();
$[IDENTIFIER][0] = smlua_get_number_field($[INDEX], "x");
if (!gSmLuaConvertSuccess) { return 0; }
$[IDENTIFIER][1] = smlua_get_number_field($[INDEX], "y");
if (!gSmLuaConvertSuccess) { return 0; }
$[IDENTIFIER][2] = smlua_get_number_field($[INDEX], "z");
"""
param_vec3f_after_call = """
smlua_push_number_field($[INDEX], "x", $[IDENTIFIER][0]);
smlua_push_number_field($[INDEX], "y", $[IDENTIFIER][1]);
smlua_push_number_field($[INDEX], "z", $[IDENTIFIER][2]);
"""
param_override_build['Vec3f'] = {
'before': param_vec3f_before_call,
'after': param_vec3f_after_call
}
param_vec3s_before_call = """
s16* $[IDENTIFIER] = smlua_get_vec3s_from_buffer();
$[IDENTIFIER][0] = smlua_get_integer_field($[INDEX], "x");
if (!gSmLuaConvertSuccess) { return 0; }
$[IDENTIFIER][1] = smlua_get_integer_field($[INDEX], "y");
if (!gSmLuaConvertSuccess) { return 0; }
$[IDENTIFIER][2] = smlua_get_integer_field($[INDEX], "z");
"""
param_vec3s_after_call = """
smlua_push_integer_field($[INDEX], "x", $[IDENTIFIER][0]);
smlua_push_integer_field($[INDEX], "y", $[IDENTIFIER][1]);
smlua_push_integer_field($[INDEX], "z", $[IDENTIFIER][2]);
"""
param_override_build['Vec3s'] = {
'before': param_vec3s_before_call,
'after': param_vec3s_after_call
}
###########################################################
built_functions = ""
built_binds = ""
#######
do_extern = False
header_h = ""
functions = []
def reject_line(line):
if len(line) == 0:
return True
if '(' not in line:
return True
if ')' not in line:
return True
if ';' not in line:
return True
def normalize_type(t):
t = t.strip()
if ' ' in t:
parts = t.split(' ', 1)
t = parts[0] + ' ' + parts[1].replace(' ', '')
return t
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
def process_line(line):
function = {}
line = line.strip()
function['line'] = line
line = line.replace('UNUSED', '')
match = re.search('[a-zA-Z0-9_]+\(', line)
function['type'] = normalize_type(line[0:match.span()[0]])
function['identifier'] = match.group()[0:-1]
function['params'] = []
params_str = line.split('(', 1)[1].rsplit(')', 1)[0].strip()
if len(params_str) == 0 or params_str == 'void':
pass
else:
param_index = 0
for param_str in params_str.split(','):
param = {}
param_str = param_str.strip()
if param_str.endswith('*') or ' ' not in param_str:
param['type'] = normalize_type(param_str)
param['identifier'] = 'arg%d' % param_index
else:
match = re.search('[a-zA-Z0-9_]+$', param_str)
param['type'] = normalize_type(param_str[0:match.span()[0]])
param['identifier'] = match.group()
function['params'].append(param)
param_index += 1
functions.append(function)
def process_lines(file_str):
for line in file_str.splitlines():
if reject_line(line):
global rejects
rejects += line + '\n'
continue
process_line(line)
def build_param(param, i):
ptype = param['type']
pid = param['identifier']
if ptype in param_override_build:
return param_override_build[ptype]['before'].replace('$[IDENTIFIER]', str(pid)).replace('$[INDEX]', str(i))
elif ptype in integer_types:
return ' %s %s = smlua_to_integer(L, %d);\n' % (ptype, pid, i)
elif ptype in number_types:
return ' %s %s = smlua_to_number(L, %d);\n' % (ptype, pid, i)
elif ptype in cobject_types:
index = cobject_types.index(ptype)
return ' %s %s = (%s)smlua_to_cobject(L, %d, %s);\n' % (ptype, pid, ptype, i, cobject_lot_types[index])
else:
return ' ' + ptype + ' ' + pid + ' <--- UNIMPLEMENTED' + '\n'
def build_param_after(param, i):
ptype = param['type']
pid = param['identifier']
if ptype in param_override_build:
return param_override_build[ptype]['after'].replace('$[IDENTIFIER]', str(pid)).replace('$[INDEX]', str(i))
else:
return ''
def build_call(function):
ftype = function['type']
fid = function['identifier']
ccall = '%s(%s)' % (fid, ', '.join([x['identifier'] for x in function['params']]))
if ftype == 'void':
return ' %s;\n' % ccall
lfunc = 'UNIMPLEMENTED -->'
if ftype in integer_types:
lfunc = 'lua_pushinteger'
elif ftype in number_types:
lfunc = 'lua_pushnumber'
return ' %s(L, %s);\n' % (lfunc, ccall)
def build_function(function):
if len(function['params']) <= 0:
s = 'int smlua_func_%s(UNUSED lua_State* L) {\n' % function['identifier']
else:
s = 'int smlua_func_%s(lua_State* L) {\n' % function['identifier']
s += ' if(!smlua_functions_valid_param_count(L, %d)) { return 0; }\n\n' % len(function['params'])
i = 1
for param in function['params']:
s += build_param(param, i)
s += ' if (!gSmLuaConvertSuccess) { return 0; }\n'
i += 1
s += '\n'
global do_extern
if do_extern:
s += ' extern %s\n' % function['line']
s += build_call(function)
i = 1
for param in function['params']:
s += build_param_after(param, i)
i += 1
s += '\n'
s += ' return 1;\n}\n'
function['implemented'] = 'UNIMPLEMENTED' not in s
if 'UNIMPLEMENTED' in s:
s = "/*\n" + s + "*/\n"
global built_functions
built_functions += s + "\n"
def build_functions():
for function in functions:
build_function(function)
def build_bind(function):
s = 'smlua_bind_function(L, "%s", smlua_func_%s);' % (function['identifier'], function['identifier'])
if function['implemented']:
s = ' ' + s
else:
s = ' //' + s + ' <--- UNIMPLEMENTED'
global built_binds
built_binds += s + "\n"
def build_binds(fname):
global built_binds
built_binds += "\n // " + fname.split('/')[-1] + "\n"
for function in functions:
build_bind(function)
def process_file(fname):
functions.clear()
global do_extern
do_extern = fname.endswith(".c")
with open(fname) as file:
process_lines(file.read())
build_functions()
build_binds(fname)
def process_files():
dir_path = os.path.dirname(os.path.realpath(__file__)) + '/lua_functions/'
files = os.listdir(dir_path)
for f in files:
comment_header = "// " + f + " //"
comment_line = "/" * len(comment_header)
global built_functions
built_functions += gen_comment_header(f)
process_file(dir_path + f)
def main():
process_files()
filename = os.path.dirname(os.path.realpath(__file__)) + '/../' + smlua_functions_autogen_c
with open(filename, 'w') as out:
out.write(template.replace("$[FUNCTIONS]", built_functions).replace("$[BINDS]", built_binds))
print('REJECTS:')
print(rejects)
main()

View File

@ -2,28 +2,21 @@ import os
import re
import sys
from extract_structs import *
usf_types = ['u8', 'u16', 'u32', 'u64', 's8', 's16', 's32', 's64', 'f32']
vec3_types = ['Vec3s', 'Vec3f']
from common import *
in_files = [
'include/types.h',
'src/game/area.h',
'src/game/camera.h',
'src/game/characters.h'
]
exclude_structs = [
'SPTask',
'VblankHandler',
'GraphNodeRoot',
'MarioAnimDmaRelatedThing',
'UnusedArea28',
'src/game/characters.h',
'src/engine/surface_collision.h'
]
smlua_cobject_autogen = 'src/pc/lua/smlua_cobject_autogen'
c_template = """$[INCLUDES]
c_template = """/* THIS FILE IS AUTOGENERATED */
/* SHOULD NOT BE MANUALLY CHANGED */
$[INCLUDES]
$[BODY]
struct LuaObjectField* smlua_get_object_field_autogen(u16 lot, const char* key) {
struct LuaObjectTable* ot = &sLuaObjectAutogenTable[lot - LOT_AUTOGEN_MIN - 1];
@ -38,7 +31,9 @@ struct LuaObjectField* smlua_get_object_field_autogen(u16 lot, const char* key)
"""
h_template = """#ifndef SMLUA_COBJECT_AUTOGEN_H
h_template = """/* THIS FILE IS AUTOGENERATED */
/* SHOULD NOT BE MANUALLY CHANGED */
#ifndef SMLUA_COBJECT_AUTOGEN_H
#define SMLUA_COBJECT_AUTOGEN_H
$[BODY]
@ -56,10 +51,12 @@ override_field_types = {
"Surface": { "normal": "Vec3f" },
}
############################################################################
override_field_immutable = {
"MarioState": [ "playerIndex" ],
"Character": [ "*" ],
}
def get_path(p):
return os.path.dirname(os.path.realpath(__file__)) + '/../' + p
############################################################################
def strip_internal_blocks(body):
# strip internal structs/enums/etc
@ -92,36 +89,6 @@ def identifier_to_caps(identifier):
caps += c.upper()
return caps
def translate_type_to_lvt(ptype):
if ptype in usf_types:
return 'LVT_' + ptype.upper()
if ptype in vec3_types:
return 'LVT_COBJECT'
if ptype == 'float':
return 'LVT_F32'
if 'struct' in ptype:
if '*' in ptype:
return 'LVT_COBJECT_P'
return 'LVT_COBJECT'
return 'LVT_???'
def translate_type_to_lot(ptype):
if '[' in ptype or '{' in ptype:
return 'LOT_???'
if ptype in usf_types:
return 'LOT_NONE'
if ptype in vec3_types:
return 'LOT_' + ptype.upper()
if ptype == 'float':
return 'LOT_NONE'
if 'struct' in ptype:
struct_id = ptype.split(' ')[1].replace('*', '')
if struct_id in exclude_structs:
return 'LOT_???'
return 'LOT_' + struct_id.upper()
return 'LOT_???'
def table_to_string(table):
count = 0
columns = 0
@ -212,14 +179,20 @@ def build_struct(struct):
lvt = translate_type_to_lvt(ftype)
lot = translate_type_to_lot(ftype)
fimmutable = str(lvt == 'LVT_COBJECT').lower()
if sid in override_field_immutable:
if fid in override_field_immutable[sid] or '*' in override_field_immutable[sid]:
fimmutable = 'true'
row = []
row.append(' { ' )
row.append('"%s", ' % fid )
row.append('%s, ' % lvt )
row.append('offsetof(struct %s, %s), ' % (sid, field['identifier']) )
row.append('%s, ' % str(lvt == 'LVT_COBJECT').lower() )
row.append("%s" % lot )
row.append(' },' )
row.append(' { ' )
row.append('"%s", ' % fid )
row.append('%s, ' % lvt )
row.append('offsetof(struct %s, %s), ' % (sid, field['identifier']) )
row.append('%s, ' % fimmutable )
row.append("%s" % lot )
row.append(' },' )
field_table.append(row)
field_table_str, field_count = table_to_string(field_table)
@ -310,4 +283,7 @@ def build_files():
with open(out_h_filename, 'w') as out:
out.write(h_template.replace("$[BODY]", built_enum))
build_files()
############################################################################
if __name__ == '__main__':
build_files()

View File

@ -15,6 +15,9 @@ _CObject = {
end,
__newindex = function (t,k,v)
_set_field(t['_lot'], t['_pointer'], k, v);
end,
__eq = function (a, b)
return a['_pointer'] == b['_pointer'] and a['_lot'] == b['_lot'] and a['_pointer'] ~= nil and a['_lot'] ~= nil
end
}
@ -109,6 +112,12 @@ end
MAX_PLAYERS = 16
CT_MARIO = 0
CT_LUIGI = 1
CT_TOAD = 2
CT_WALUIGI = 3
CT_MAX = 4
------------
-- layers --
------------

View File

@ -9,11 +9,11 @@
-- Mario: wall kick slide all the way down wall
gMarioStateExtras = {}
gStateExtras = {}
for i=0,(MAX_PLAYERS-1) do
gMarioStateExtras[i] = {}
gStateExtras[i] = {}
local m = gMarioStates[i]
local e = gMarioStateExtras[i]
local e = gStateExtras[i]
e.lastAction = m.action
e.animFrame = 0
e.scuttle = 0
@ -24,7 +24,7 @@ end
-----------
function luigi_before_phys_step(m)
local e = gMarioStateExtras[m.playerIndex]
local e = gStateExtras[m.playerIndex]
local hScale = 1.0
local vScale = 1.0
@ -50,7 +50,7 @@ function luigi_before_phys_step(m)
end
function luigi_on_set_action(m)
local e = gMarioStateExtras[m.playerIndex]
local e = gStateExtras[m.playerIndex]
-- extra height to the backflip
if m.action == ACT_BACKFLIP then
@ -75,7 +75,7 @@ function luigi_on_set_action(m)
end
function luigi_update(m)
local e = gMarioStateExtras[m.playerIndex]
local e = gStateExtras[m.playerIndex]
-- air scuttle
e.scuttle = 0
@ -103,29 +103,27 @@ end
-- main --
----------
function mario_before_phys_step(m)
-- if luigi then
luigi_before_phys_step(m)
-- end
if (m.character == gCharacters[CT_LUIGI]) then
luigi_before_phys_step(m)
end
end
function mario_on_set_action(m)
-- if luigi then
luigi_on_set_action(m)
-- end
if (m.character == gCharacters[CT_LUIGI]) then
luigi_on_set_action(m)
end
end
function mario_action_on_change(m)
-- if luigi then
luigi_update(m)
-- end
if (m.character == gCharacters[CT_LUIGI]) then
luigi_update(m)
end
end
function mario_update(m)
local e = gMarioStateExtras[m.playerIndex]
-- if luigi then
luigi_update(m)
-- end
if (m.character == gCharacters[CT_LUIGI]) then
luigi_update(m)
end
end
-----------

View File

@ -51,18 +51,6 @@ static void smlua_load_script(char* path) {
}
}
static void smlua_init_mario_states(void) {
lua_State* L = gLuaState;
lua_newtable(L);
int t = lua_gettop(gLuaState);
for (int i = 0; i < MAX_PLAYERS; i++) {
lua_pushinteger(L, i);
smlua_push_object(L, LOT_MARIOSTATE, &gMarioStates[i]);
lua_settable(L, t);
}
lua_setglobal(L, "gMarioStates");
}
void smlua_init(void) {
smlua_shutdown();
smlua_cobject_allowlist_init();
@ -90,7 +78,7 @@ void smlua_init(void) {
extern char gSmluaConstants[];
smlua_exec_str(gSmluaConstants);
smlua_init_mario_states();
smlua_cobject_init_globals();
// load scripts
LOG_INFO("Loading scripts:");

View File

@ -154,6 +154,33 @@ static int smlua__set_field(lua_State* L) {
return 1;
}
void smlua_cobject_init_globals(void) {
lua_State* L = gLuaState;
{
lua_newtable(L);
int t = lua_gettop(gLuaState);
for (int i = 0; i < MAX_PLAYERS; i++) {
lua_pushinteger(L, i);
smlua_push_object(L, LOT_MARIOSTATE, &gMarioStates[i]);
lua_settable(L, t);
}
lua_setglobal(L, "gMarioStates");
}
{
lua_newtable(L);
int t = lua_gettop(gLuaState);
for (int i = 0; i < CT_MAX; i++) {
lua_pushinteger(L, i);
smlua_push_object(L, LOT_CHARACTER, &gCharacters[i]);
lua_settable(L, t);
}
lua_setglobal(L, "gCharacters");
}
}
void smlua_bind_cobject(void) {
lua_State* L = gLuaState;

View File

@ -35,6 +35,7 @@ struct LuaObjectTable {
};
bool smlua_valid_lot(u16 lot);
void smlua_cobject_init_globals(void);
void smlua_bind_cobject(void);
#endif

View File

@ -1,8 +1,11 @@
/* THIS FILE IS AUTOGENERATED */
/* SHOULD NOT BE MANUALLY CHANGED */
#include "smlua.h"
#include "include/types.h"
#include "src/game/area.h"
#include "src/game/camera.h"
#include "src/game/characters.h"
#include "src/engine/surface_collision.h"
#define LUA_CONTROLLER_FIELD_COUNT 10
static struct LuaObjectField sControllerFields[LUA_CONTROLLER_FIELD_COUNT] = {
@ -199,7 +202,7 @@ static struct LuaObjectField sMarioAnimationFields[LUA_MARIO_ANIMATION_FIELD_COU
#define LUA_MARIO_STATE_FIELD_COUNT 72
static struct LuaObjectField sMarioStateFields[LUA_MARIO_STATE_FIELD_COUNT] = {
{ "playerIndex", LVT_U16, offsetof(struct MarioState, playerIndex), false, LOT_NONE },
{ "playerIndex", LVT_U16, offsetof(struct MarioState, playerIndex), true, LOT_NONE },
{ "input", LVT_U16, offsetof(struct MarioState, input), false, LOT_NONE },
{ "flags", LVT_U32, offsetof(struct MarioState, flags), false, LOT_NONE },
{ "particleFlags", LVT_U32, offsetof(struct MarioState, particleFlags), false, LOT_NONE },
@ -552,65 +555,84 @@ static struct LuaObjectField sLakituStateFields[LUA_LAKITU_STATE_FIELD_COUNT] =
#define LUA_CHARACTER_FIELD_COUNT 54
static struct LuaObjectField sCharacterFields[LUA_CHARACTER_FIELD_COUNT] = {
// { "name", LVT_???, offsetof(struct Character, name), false, LOT_??? }, <--- UNIMPLEMENTED
// { "hudHead", LVT_???, offsetof(struct Character, hudHead), false, LOT_??? }, <--- UNIMPLEMENTED
// { "hudHeadTexture", LVT_???, offsetof(struct Character, hudHeadTexture), false, LOT_??? }, <--- UNIMPLEMENTED
{ "cameraHudHead", LVT_U32, offsetof(struct Character, cameraHudHead), false, LOT_NONE },
{ "modelId", LVT_U32, offsetof(struct Character, modelId), false, LOT_NONE },
{ "capModelId", LVT_U32, offsetof(struct Character, capModelId), false, LOT_NONE },
{ "capMetalModelId", LVT_U32, offsetof(struct Character, capMetalModelId), false, LOT_NONE },
{ "capWingModelId", LVT_U32, offsetof(struct Character, capWingModelId), false, LOT_NONE },
{ "capMetalWingModelId", LVT_U32, offsetof(struct Character, capMetalWingModelId), false, LOT_NONE },
{ "capEnemyLayer", LVT_U8, offsetof(struct Character, capEnemyLayer), false, LOT_NONE },
// { "capEnemyGfx", LVT_???, offsetof(struct Character, capEnemyGfx), false, LOT_??? }, <--- UNIMPLEMENTED
// { "capEnemyDecalGfx", LVT_???, offsetof(struct Character, capEnemyDecalGfx), false, LOT_??? }, <--- UNIMPLEMENTED
{ "animOffsetEnabled", LVT_U8, offsetof(struct Character, animOffsetEnabled), false, LOT_NONE },
{ "animOffsetLowYPoint", LVT_F32, offsetof(struct Character, animOffsetLowYPoint), false, LOT_NONE },
{ "animOffsetFeet", LVT_F32, offsetof(struct Character, animOffsetFeet), false, LOT_NONE },
{ "animOffsetHand", LVT_F32, offsetof(struct Character, animOffsetHand), false, LOT_NONE },
{ "soundFreqScale", LVT_F32, offsetof(struct Character, soundFreqScale), false, LOT_NONE },
{ "soundYahWahHoo", LVT_S32, offsetof(struct Character, soundYahWahHoo), false, LOT_NONE },
{ "soundHoohoo", LVT_S32, offsetof(struct Character, soundHoohoo), false, LOT_NONE },
{ "soundYahoo", LVT_S32, offsetof(struct Character, soundYahoo), false, LOT_NONE },
{ "soundUh", LVT_S32, offsetof(struct Character, soundUh), false, LOT_NONE },
{ "soundHrmm", LVT_S32, offsetof(struct Character, soundHrmm), false, LOT_NONE },
{ "soundWah2", LVT_S32, offsetof(struct Character, soundWah2), false, LOT_NONE },
{ "soundWhoa", LVT_S32, offsetof(struct Character, soundWhoa), false, LOT_NONE },
{ "soundEeuh", LVT_S32, offsetof(struct Character, soundEeuh), false, LOT_NONE },
{ "soundAttacked", LVT_S32, offsetof(struct Character, soundAttacked), false, LOT_NONE },
{ "soundOoof", LVT_S32, offsetof(struct Character, soundOoof), false, LOT_NONE },
{ "soundOoof2", LVT_S32, offsetof(struct Character, soundOoof2), false, LOT_NONE },
{ "soundHereWeGo", LVT_S32, offsetof(struct Character, soundHereWeGo), false, LOT_NONE },
{ "soundYawning", LVT_S32, offsetof(struct Character, soundYawning), false, LOT_NONE },
{ "soundSnoring1", LVT_S32, offsetof(struct Character, soundSnoring1), false, LOT_NONE },
{ "soundSnoring2", LVT_S32, offsetof(struct Character, soundSnoring2), false, LOT_NONE },
{ "soundWaaaooow", LVT_S32, offsetof(struct Character, soundWaaaooow), false, LOT_NONE },
{ "soundHaha", LVT_S32, offsetof(struct Character, soundHaha), false, LOT_NONE },
{ "soundHaha_2", LVT_S32, offsetof(struct Character, soundHaha_2), false, LOT_NONE },
{ "soundUh2", LVT_S32, offsetof(struct Character, soundUh2), false, LOT_NONE },
{ "soundUh2_2", LVT_S32, offsetof(struct Character, soundUh2_2), false, LOT_NONE },
{ "soundOnFire", LVT_S32, offsetof(struct Character, soundOnFire), false, LOT_NONE },
{ "soundDying", LVT_S32, offsetof(struct Character, soundDying), false, LOT_NONE },
{ "soundPantingCold", LVT_S32, offsetof(struct Character, soundPantingCold), false, LOT_NONE },
{ "soundPanting", LVT_S32, offsetof(struct Character, soundPanting), false, LOT_NONE },
{ "soundCoughing1", LVT_S32, offsetof(struct Character, soundCoughing1), false, LOT_NONE },
{ "soundCoughing2", LVT_S32, offsetof(struct Character, soundCoughing2), false, LOT_NONE },
{ "soundCoughing3", LVT_S32, offsetof(struct Character, soundCoughing3), false, LOT_NONE },
{ "soundPunchYah", LVT_S32, offsetof(struct Character, soundPunchYah), false, LOT_NONE },
{ "soundPunchHoo", LVT_S32, offsetof(struct Character, soundPunchHoo), false, LOT_NONE },
{ "soundMamaMia", LVT_S32, offsetof(struct Character, soundMamaMia), false, LOT_NONE },
{ "soundGroundPoundWah", LVT_S32, offsetof(struct Character, soundGroundPoundWah), false, LOT_NONE },
{ "soundDrowning", LVT_S32, offsetof(struct Character, soundDrowning), false, LOT_NONE },
{ "soundPunchWah", LVT_S32, offsetof(struct Character, soundPunchWah), false, LOT_NONE },
{ "soundYahooWahaYippee", LVT_S32, offsetof(struct Character, soundYahooWahaYippee), false, LOT_NONE },
{ "soundDoh", LVT_S32, offsetof(struct Character, soundDoh), false, LOT_NONE },
{ "soundGameOver", LVT_S32, offsetof(struct Character, soundGameOver), false, LOT_NONE },
{ "soundHello", LVT_S32, offsetof(struct Character, soundHello), false, LOT_NONE },
{ "soundPressStartToPlay", LVT_S32, offsetof(struct Character, soundPressStartToPlay), false, LOT_NONE },
{ "soundTwirlBounce", LVT_S32, offsetof(struct Character, soundTwirlBounce), false, LOT_NONE },
{ "soundSnoring3", LVT_S32, offsetof(struct Character, soundSnoring3), false, LOT_NONE },
{ "soundSoLongaBowser", LVT_S32, offsetof(struct Character, soundSoLongaBowser), false, LOT_NONE },
{ "soundImaTired", LVT_S32, offsetof(struct Character, soundImaTired), false, LOT_NONE },
// { "name", LVT_???, offsetof(struct Character, name), true, LOT_??? }, <--- UNIMPLEMENTED
// { "hudHead", LVT_???, offsetof(struct Character, hudHead), true, LOT_??? }, <--- UNIMPLEMENTED
// { "hudHeadTexture", LVT_???, offsetof(struct Character, hudHeadTexture), true, LOT_??? }, <--- UNIMPLEMENTED
{ "cameraHudHead", LVT_U32, offsetof(struct Character, cameraHudHead), true, LOT_NONE },
{ "modelId", LVT_U32, offsetof(struct Character, modelId), true, LOT_NONE },
{ "capModelId", LVT_U32, offsetof(struct Character, capModelId), true, LOT_NONE },
{ "capMetalModelId", LVT_U32, offsetof(struct Character, capMetalModelId), true, LOT_NONE },
{ "capWingModelId", LVT_U32, offsetof(struct Character, capWingModelId), true, LOT_NONE },
{ "capMetalWingModelId", LVT_U32, offsetof(struct Character, capMetalWingModelId), true, LOT_NONE },
{ "capEnemyLayer", LVT_U8, offsetof(struct Character, capEnemyLayer), true, LOT_NONE },
// { "capEnemyGfx", LVT_???, offsetof(struct Character, capEnemyGfx), true, LOT_??? }, <--- UNIMPLEMENTED
// { "capEnemyDecalGfx", LVT_???, offsetof(struct Character, capEnemyDecalGfx), true, LOT_??? }, <--- UNIMPLEMENTED
{ "animOffsetEnabled", LVT_U8, offsetof(struct Character, animOffsetEnabled), true, LOT_NONE },
{ "animOffsetLowYPoint", LVT_F32, offsetof(struct Character, animOffsetLowYPoint), true, LOT_NONE },
{ "animOffsetFeet", LVT_F32, offsetof(struct Character, animOffsetFeet), true, LOT_NONE },
{ "animOffsetHand", LVT_F32, offsetof(struct Character, animOffsetHand), true, LOT_NONE },
{ "soundFreqScale", LVT_F32, offsetof(struct Character, soundFreqScale), true, LOT_NONE },
{ "soundYahWahHoo", LVT_S32, offsetof(struct Character, soundYahWahHoo), true, LOT_NONE },
{ "soundHoohoo", LVT_S32, offsetof(struct Character, soundHoohoo), true, LOT_NONE },
{ "soundYahoo", LVT_S32, offsetof(struct Character, soundYahoo), true, LOT_NONE },
{ "soundUh", LVT_S32, offsetof(struct Character, soundUh), true, LOT_NONE },
{ "soundHrmm", LVT_S32, offsetof(struct Character, soundHrmm), true, LOT_NONE },
{ "soundWah2", LVT_S32, offsetof(struct Character, soundWah2), true, LOT_NONE },
{ "soundWhoa", LVT_S32, offsetof(struct Character, soundWhoa), true, LOT_NONE },
{ "soundEeuh", LVT_S32, offsetof(struct Character, soundEeuh), true, LOT_NONE },
{ "soundAttacked", LVT_S32, offsetof(struct Character, soundAttacked), true, LOT_NONE },
{ "soundOoof", LVT_S32, offsetof(struct Character, soundOoof), true, LOT_NONE },
{ "soundOoof2", LVT_S32, offsetof(struct Character, soundOoof2), true, LOT_NONE },
{ "soundHereWeGo", LVT_S32, offsetof(struct Character, soundHereWeGo), true, LOT_NONE },
{ "soundYawning", LVT_S32, offsetof(struct Character, soundYawning), true, LOT_NONE },
{ "soundSnoring1", LVT_S32, offsetof(struct Character, soundSnoring1), true, LOT_NONE },
{ "soundSnoring2", LVT_S32, offsetof(struct Character, soundSnoring2), true, LOT_NONE },
{ "soundWaaaooow", LVT_S32, offsetof(struct Character, soundWaaaooow), true, LOT_NONE },
{ "soundHaha", LVT_S32, offsetof(struct Character, soundHaha), true, LOT_NONE },
{ "soundHaha_2", LVT_S32, offsetof(struct Character, soundHaha_2), true, LOT_NONE },
{ "soundUh2", LVT_S32, offsetof(struct Character, soundUh2), true, LOT_NONE },
{ "soundUh2_2", LVT_S32, offsetof(struct Character, soundUh2_2), true, LOT_NONE },
{ "soundOnFire", LVT_S32, offsetof(struct Character, soundOnFire), true, LOT_NONE },
{ "soundDying", LVT_S32, offsetof(struct Character, soundDying), true, LOT_NONE },
{ "soundPantingCold", LVT_S32, offsetof(struct Character, soundPantingCold), true, LOT_NONE },
{ "soundPanting", LVT_S32, offsetof(struct Character, soundPanting), true, LOT_NONE },
{ "soundCoughing1", LVT_S32, offsetof(struct Character, soundCoughing1), true, LOT_NONE },
{ "soundCoughing2", LVT_S32, offsetof(struct Character, soundCoughing2), true, LOT_NONE },
{ "soundCoughing3", LVT_S32, offsetof(struct Character, soundCoughing3), true, LOT_NONE },
{ "soundPunchYah", LVT_S32, offsetof(struct Character, soundPunchYah), true, LOT_NONE },
{ "soundPunchHoo", LVT_S32, offsetof(struct Character, soundPunchHoo), true, LOT_NONE },
{ "soundMamaMia", LVT_S32, offsetof(struct Character, soundMamaMia), true, LOT_NONE },
{ "soundGroundPoundWah", LVT_S32, offsetof(struct Character, soundGroundPoundWah), true, LOT_NONE },
{ "soundDrowning", LVT_S32, offsetof(struct Character, soundDrowning), true, LOT_NONE },
{ "soundPunchWah", LVT_S32, offsetof(struct Character, soundPunchWah), true, LOT_NONE },
{ "soundYahooWahaYippee", LVT_S32, offsetof(struct Character, soundYahooWahaYippee), true, LOT_NONE },
{ "soundDoh", LVT_S32, offsetof(struct Character, soundDoh), true, LOT_NONE },
{ "soundGameOver", LVT_S32, offsetof(struct Character, soundGameOver), true, LOT_NONE },
{ "soundHello", LVT_S32, offsetof(struct Character, soundHello), true, LOT_NONE },
{ "soundPressStartToPlay", LVT_S32, offsetof(struct Character, soundPressStartToPlay), true, LOT_NONE },
{ "soundTwirlBounce", LVT_S32, offsetof(struct Character, soundTwirlBounce), true, LOT_NONE },
{ "soundSnoring3", LVT_S32, offsetof(struct Character, soundSnoring3), true, LOT_NONE },
{ "soundSoLongaBowser", LVT_S32, offsetof(struct Character, soundSoLongaBowser), true, LOT_NONE },
{ "soundImaTired", LVT_S32, offsetof(struct Character, soundImaTired), true, LOT_NONE },
};
#define LUA_WALL_COLLISION_DATA_FIELD_COUNT 4
static struct LuaObjectField sWallCollisionDataFields[LUA_WALL_COLLISION_DATA_FIELD_COUNT] = {
// { "z", LVT_???, offsetof(struct WallCollisionData, z), false, LOT_??? }, <--- UNIMPLEMENTED
{ "offsetY", LVT_F32, offsetof(struct WallCollisionData, offsetY), false, LOT_NONE },
{ "radius", LVT_F32, offsetof(struct WallCollisionData, radius), false, LOT_NONE },
{ "unk14", LVT_S16, offsetof(struct WallCollisionData, unk14), false, LOT_NONE },
{ "numWalls", LVT_S16, offsetof(struct WallCollisionData, numWalls), false, LOT_NONE },
// { "walls", LVT_COBJECT_P, offsetof(struct WallCollisionData, walls), false, LOT_??? }, <--- UNIMPLEMENTED
};
#define LUA_FLOOR_GEOMETRY_FIELD_COUNT 4
static struct LuaObjectField sFloorGeometryFields[LUA_FLOOR_GEOMETRY_FIELD_COUNT] = {
// { "unused", LVT_???, offsetof(struct FloorGeometry, unused), false, LOT_??? }, <--- UNIMPLEMENTED
{ "normalX", LVT_F32, offsetof(struct FloorGeometry, normalX), false, LOT_NONE },
{ "normalY", LVT_F32, offsetof(struct FloorGeometry, normalY), false, LOT_NONE },
{ "normalZ", LVT_F32, offsetof(struct FloorGeometry, normalZ), false, LOT_NONE },
{ "originOffset", LVT_F32, offsetof(struct FloorGeometry, originOffset), false, LOT_NONE },
};
struct LuaObjectTable sLuaObjectAutogenTable[LOT_AUTOGEN_MAX - LOT_AUTOGEN_MIN] = {
@ -652,6 +674,8 @@ struct LuaObjectTable sLuaObjectAutogenTable[LOT_AUTOGEN_MAX - LOT_AUTOGEN_MIN]
{ LOT_CAMERA, sCameraFields, LUA_CAMERA_FIELD_COUNT },
{ LOT_LAKITUSTATE, sLakituStateFields, LUA_LAKITU_STATE_FIELD_COUNT },
{ LOT_CHARACTER, sCharacterFields, LUA_CHARACTER_FIELD_COUNT },
{ LOT_WALLCOLLISIONDATA, sWallCollisionDataFields, LUA_WALL_COLLISION_DATA_FIELD_COUNT },
{ LOT_FLOORGEOMETRY, sFloorGeometryFields, LUA_FLOOR_GEOMETRY_FIELD_COUNT },
};
struct LuaObjectField* smlua_get_object_field_autogen(u16 lot, const char* key) {

View File

@ -1,3 +1,5 @@
/* THIS FILE IS AUTOGENERATED */
/* SHOULD NOT BE MANUALLY CHANGED */
#ifndef SMLUA_COBJECT_AUTOGEN_H
#define SMLUA_COBJECT_AUTOGEN_H
@ -41,6 +43,8 @@ enum LuaObjectAutogenType {
LOT_CAMERA,
LOT_LAKITUSTATE,
LOT_CHARACTER,
LOT_WALLCOLLISIONDATA,
LOT_FLOORGEOMETRY,
LOT_AUTOGEN_MAX,
};

View File

@ -10,6 +10,9 @@ char gSmluaConstants[] = "HOOK_UPDATE = 0\n"
" end,\n"
" __newindex = function (t,k,v)\n"
" _set_field(t['_lot'], t['_pointer'], k, v);\n"
" end,\n"
" __eq = function (a, b)\n"
" return a['_pointer'] == b['_pointer'] and a['_lot'] == b['_lot'] and a['_pointer'] ~= nil and a['_lot'] ~= nil\n"
" end\n"
"}\n"
"function vec3f_copy(dest, src)\n"
@ -87,6 +90,11 @@ char gSmluaConstants[] = "HOOK_UPDATE = 0\n"
" return current;\n"
"end\n"
"MAX_PLAYERS = 16\n"
"CT_MARIO = 0\n"
"CT_LUIGI = 1\n"
"CT_TOAD = 2\n"
"CT_WALUIGI = 3\n"
"CT_MAX = 4\n"
"LAYER_FORCE = 0\n"
"LAYER_OPAQUE = 1\n"
"LAYER_OPAQUE_DECAL = 2\n"

View File

@ -417,7 +417,6 @@ int smlua_func_resolve_and_return_wall_collisions(lua_State* L) {
}
*/
/*
int smlua_func_vec3f_find_ceil(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 3)) { return 0; }
@ -431,7 +430,7 @@ int smlua_func_vec3f_find_ceil(lua_State* L) {
if (!gSmLuaConvertSuccess) { return 0; }
f32 height = smlua_to_number(L, 2);
if (!gSmLuaConvertSuccess) { return 0; }
struct Surface** ceil <--- UNIMPLEMENTED
struct Surface** ceil = (struct Surface**)smlua_to_cobject(L, 3, LOT_SURFACE);
if (!gSmLuaConvertSuccess) { return 0; }
lua_pushnumber(L, vec3f_find_ceil(pos, height, ceil));
@ -442,7 +441,6 @@ int smlua_func_vec3f_find_ceil(lua_State* L) {
return 1;
}
*/
int smlua_func_mario_facing_downhill(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 2)) { return 0; }
@ -1901,7 +1899,7 @@ int smlua_func_spawn_obj_at_mario_rel_yaw(lua_State* L) {
if (!gSmLuaConvertSuccess) { return 0; }
s32 model = smlua_to_integer(L, 2);
if (!gSmLuaConvertSuccess) { return 0; }
BehaviorScript * behavior <--- UNIMPLEMENTED
// BehaviorScript * behavior = (BehaviorScript *)smlua_to_cobject(L, 3, LOT_???); <--- UNIMPLEMENTED
if (!gSmLuaConvertSuccess) { return 0; }
s16 relYaw = smlua_to_integer(L, 4);
if (!gSmLuaConvertSuccess) { return 0; }
@ -2916,11 +2914,11 @@ int smlua_func_set_vel_from_pitch_and_yaw(lua_State* L) {
int smlua_func_f32_find_wall_collision(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 5)) { return 0; }
f32 * xPtr <--- UNIMPLEMENTED
// f32 * xPtr = (f32 *)smlua_to_cobject(L, 1, LOT_???); <--- UNIMPLEMENTED
if (!gSmLuaConvertSuccess) { return 0; }
f32 * yPtr <--- UNIMPLEMENTED
// f32 * yPtr = (f32 *)smlua_to_cobject(L, 2, LOT_???); <--- UNIMPLEMENTED
if (!gSmLuaConvertSuccess) { return 0; }
f32 * zPtr <--- UNIMPLEMENTED
// f32 * zPtr = (f32 *)smlua_to_cobject(L, 3, LOT_???); <--- UNIMPLEMENTED
if (!gSmLuaConvertSuccess) { return 0; }
f32 offsetY = smlua_to_number(L, 4);
if (!gSmLuaConvertSuccess) { return 0; }
@ -2933,20 +2931,17 @@ int smlua_func_f32_find_wall_collision(lua_State* L) {
}
*/
/*
int smlua_func_find_wall_collisions(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
struct WallCollisionData* colData <--- UNIMPLEMENTED
struct WallCollisionData* colData = (struct WallCollisionData*)smlua_to_cobject(L, 1, LOT_WALLCOLLISIONDATA);
if (!gSmLuaConvertSuccess) { return 0; }
lua_pushinteger(L, find_wall_collisions(colData));
return 1;
}
*/
/*
int smlua_func_find_ceil(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 4)) { return 0; }
@ -2956,16 +2951,14 @@ int smlua_func_find_ceil(lua_State* L) {
if (!gSmLuaConvertSuccess) { return 0; }
f32 posZ = smlua_to_number(L, 3);
if (!gSmLuaConvertSuccess) { return 0; }
struct Surface** pceil <--- UNIMPLEMENTED
struct Surface** pceil = (struct Surface**)smlua_to_cobject(L, 4, LOT_SURFACE);
if (!gSmLuaConvertSuccess) { return 0; }
lua_pushnumber(L, find_ceil(posX, posY, posZ, pceil));
return 1;
}
*/
/*
int smlua_func_find_floor_height_and_data(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 4)) { return 0; }
@ -2975,14 +2968,13 @@ int smlua_func_find_floor_height_and_data(lua_State* L) {
if (!gSmLuaConvertSuccess) { return 0; }
f32 zPos = smlua_to_number(L, 3);
if (!gSmLuaConvertSuccess) { return 0; }
struct FloorGeometry** floorGeo <--- UNIMPLEMENTED
struct FloorGeometry** floorGeo = (struct FloorGeometry**)smlua_to_cobject(L, 4, LOT_FLOORGEOMETRY);
if (!gSmLuaConvertSuccess) { return 0; }
lua_pushnumber(L, find_floor_height_and_data(xPos, yPos, zPos, floorGeo));
return 1;
}
*/
int smlua_func_find_floor_height(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 3)) { return 0; }
@ -2999,7 +2991,6 @@ int smlua_func_find_floor_height(lua_State* L) {
return 1;
}
/*
int smlua_func_find_floor(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 4)) { return 0; }
@ -3009,14 +3000,13 @@ int smlua_func_find_floor(lua_State* L) {
if (!gSmLuaConvertSuccess) { return 0; }
f32 zPos = smlua_to_number(L, 3);
if (!gSmLuaConvertSuccess) { return 0; }
struct Surface** pfloor <--- UNIMPLEMENTED
struct Surface** pfloor = (struct Surface**)smlua_to_cobject(L, 4, LOT_SURFACE);
if (!gSmLuaConvertSuccess) { return 0; }
lua_pushnumber(L, find_floor(xPos, yPos, zPos, pfloor));
return 1;
}
*/
int smlua_func_find_water_level(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 2)) { return 0; }
@ -3044,7 +3034,6 @@ int smlua_func_find_poison_gas_level(lua_State* L) {
return 1;
}
/*
int smlua_func_find_surface_on_ray(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 4)) { return 0; }
@ -3064,7 +3053,7 @@ int smlua_func_find_surface_on_ray(lua_State* L) {
if (!gSmLuaConvertSuccess) { return 0; }
dir[2] = smlua_get_number_field(2, "z");
if (!gSmLuaConvertSuccess) { return 0; }
struct Surface** hit_surface <--- UNIMPLEMENTED
struct Surface** hit_surface = (struct Surface**)smlua_to_cobject(L, 3, LOT_SURFACE);
if (!gSmLuaConvertSuccess) { return 0; }
f32* hit_pos = smlua_get_vec3f_from_buffer();
@ -3091,7 +3080,6 @@ int smlua_func_find_surface_on_ray(lua_State* L) {
return 1;
}
*/
///////////////
// thread6.c //
@ -3181,7 +3169,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "mario_get_floor_class", smlua_func_mario_get_floor_class);
smlua_bind_function(L, "mario_get_terrain_sound_addend", smlua_func_mario_get_terrain_sound_addend);
//smlua_bind_function(L, "resolve_and_return_wall_collisions", smlua_func_resolve_and_return_wall_collisions); <--- UNIMPLEMENTED
//smlua_bind_function(L, "vec3f_find_ceil", smlua_func_vec3f_find_ceil); <--- UNIMPLEMENTED
smlua_bind_function(L, "vec3f_find_ceil", smlua_func_vec3f_find_ceil);
smlua_bind_function(L, "mario_facing_downhill", smlua_func_mario_facing_downhill);
smlua_bind_function(L, "mario_floor_is_slippery", smlua_func_mario_floor_is_slippery);
smlua_bind_function(L, "mario_floor_is_slope", smlua_func_mario_floor_is_slope);
@ -3387,14 +3375,14 @@ void smlua_bind_functions_autogen(void) {
// surface_collision.h
//smlua_bind_function(L, "f32_find_wall_collision", smlua_func_f32_find_wall_collision); <--- UNIMPLEMENTED
//smlua_bind_function(L, "find_wall_collisions", smlua_func_find_wall_collisions); <--- UNIMPLEMENTED
//smlua_bind_function(L, "find_ceil", smlua_func_find_ceil); <--- UNIMPLEMENTED
//smlua_bind_function(L, "find_floor_height_and_data", smlua_func_find_floor_height_and_data); <--- UNIMPLEMENTED
smlua_bind_function(L, "find_wall_collisions", smlua_func_find_wall_collisions);
smlua_bind_function(L, "find_ceil", smlua_func_find_ceil);
smlua_bind_function(L, "find_floor_height_and_data", smlua_func_find_floor_height_and_data);
smlua_bind_function(L, "find_floor_height", smlua_func_find_floor_height);
//smlua_bind_function(L, "find_floor", smlua_func_find_floor); <--- UNIMPLEMENTED
smlua_bind_function(L, "find_floor", smlua_func_find_floor);
smlua_bind_function(L, "find_water_level", smlua_func_find_water_level);
smlua_bind_function(L, "find_poison_gas_level", smlua_func_find_poison_gas_level);
//smlua_bind_function(L, "find_surface_on_ray", smlua_func_find_surface_on_ray); <--- UNIMPLEMENTED
smlua_bind_function(L, "find_surface_on_ray", smlua_func_find_surface_on_ray);
// thread6.c
smlua_bind_function(L, "queue_rumble_data", smlua_func_queue_rumble_data);

View File

@ -14,6 +14,8 @@ static char sTmpSession[MAX_SESSION_CHARS] = { 0 };
static char sTmpPath[PATH_MAX] = { 0 };
static bool acceptable_file(char* string) {
if (strchr(string, '/') != NULL) { return false; }
if (strchr(string, '\\') != NULL) { return false; }
string = strrchr(string, '.');
return (string != NULL && !strcmp(string, ".lua"));
}
@ -26,7 +28,6 @@ static void mod_list_delete_tmp(void) {
static char path[PATH_MAX] = { 0 };
while ((dir = readdir(d)) != NULL) {
if (!acceptable_file(dir->d_name)) { continue; }
snprintf(path, PATH_MAX - 1, "%s/%s", sTmpPath, dir->d_name);
if (!fs_sys_file_exists(path)) { continue; }
@ -68,7 +69,18 @@ void mod_list_add_tmp(u16 index, u16 remoteIndex, char* name, size_t size) {
entry->size = size;
table->totalSize += size;
snprintf(entry->path, PATH_MAX - 1, "%s/%s-%s", sTmpPath, sTmpSession, name);
char sanitizedName[PATH_MAX] = { 0 };
char* n = name;
char* s = sanitizedName;
while (*n != '\0') {
if (*n >= 'a' && *n <= 'z') { *s = *n; s++; }
if (*n >= 'A' && *n <= 'Z') { *s = *n; s++; }
if (*n >= '0' && *n <= '9') { *s = *n; s++; }
if (*n == '_' || *n == '-' || *n == '.') { *s = *n; s++; }
n++;
}
snprintf(entry->path, PATH_MAX - 1, "%s/%s-%u-%s", sTmpPath, sTmpSession, index, sanitizedName);
entry->fp = fopen(entry->path, "wb");
entry->remoteIndex = remoteIndex;
@ -164,6 +176,7 @@ static void mod_list_load_local(const char* path) {
}
void mod_list_init(void) {
srand(time(0));
snprintf(sTmpSession, MAX_SESSION_CHARS, "%06X", (u32)(rand() % 0xFFFFFF));
snprintf(sTmpPath, PATH_MAX - 1, "%s", fs_get_write_path("tmp"));
if (!fs_sys_dir_exists(sTmpPath)) { fs_sys_mkdir(sTmpPath); }