From bf2969be04685be6c6ca7fdd06814afba9f8cea5 Mon Sep 17 00:00:00 2001 From: MysterD Date: Tue, 25 Jan 2022 20:28:34 -0800 Subject: [PATCH] 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 --- .gitignore | 1 + .../extract_structs.cpython-39.pyc | Bin 1158 -> 0 bytes autogen/common.py | 55 ++++ autogen/convert_functions.py | 34 +-- autogen/convert_header.py | 286 ------------------ autogen/convert_structs.py | 86 ++---- autogen/lua_constants/constants.lua | 9 + mods/character-abilities.lua | 38 ++- src/pc/lua/smlua.c | 14 +- src/pc/lua/smlua_cobject.c | 29 +- src/pc/lua/smlua_cobject.h | 1 + src/pc/lua/smlua_cobject_autogen.c | 144 +++++---- src/pc/lua/smlua_cobject_autogen.h | 4 + src/pc/lua/smlua_constants_autogen.c | 8 + src/pc/lua/smlua_functions_autogen.c | 44 +-- src/pc/mod_list.c | 17 +- 16 files changed, 287 insertions(+), 483 deletions(-) delete mode 100644 autogen/__pycache__/extract_structs.cpython-39.pyc create mode 100644 autogen/common.py delete mode 100644 autogen/convert_header.py diff --git a/.gitignore b/.gitignore index 4f898933..9db654a8 100644 --- a/.gitignore +++ b/.gitignore @@ -66,6 +66,7 @@ sm64config.txt /assets/**/*.bin /sound/**/*.m64 /sound/**/*.aiff +/autogen/__pycache__ !/levels/**/*custom*.png !/levels/**/*custom*/**/*.png !/actors/**/*custom*.png diff --git a/autogen/__pycache__/extract_structs.cpython-39.pyc b/autogen/__pycache__/extract_structs.cpython-39.pyc deleted file mode 100644 index 057647f0394c2c4f5997b418073bb272f1f89abc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1158 zcmZ8hy>1gh5Z>9{v-b|i7!wJCgfIdj5-=uF1VJDKf{FqmfrKy#(c!rega2}ShG6b! z_^FUUJb_(;cmSS&ih_b_OQ_O-MCk@*&vq2CtJ$4z=9`(DxwHMLDUZ>5^Yyp?EyLJP z3wAC};1Y>GN(VB82CI&4s6vW)l_N*-l2rx5O*SjHh{>+kz+U5JYbcT{B-*2#5sTRi zc)LG=82T_^3BOHQCG8giSgSD4^s& z=#FzfM=ut{`V|Xed6t!AVq(uQ!n;zOB}|cV7R3zPXP@LVv9su+B(_NP98PWPdE9Mv zEZEHNAUv5e3M2MA*eFJ-@8TYWSPX=XAN7JNQL#h4+(_KmMfVY>*hZ{SrCLPK?b_~J zYN8Po_ zpZA9FtjC{`wN&aIynD|t_b!*Kr_1M7SME-f6U)a>%`MLkA?amx6n1M-Y1T8c-3eO8 z4Few=^;V#bL%w>)sGx=VNj+LOp6)d2(a7oP$Pc5D-AU~x8wQ<*UkeNm10!_zJ|$Ia z^+wS0n}Ly5Gfo;^713s7q}7dxnjORSJjsH|)LXiafpKf=e(2YtApF3>L)7PRp|V-I z5w;%&wMbWV^UPwfS+2F)or>R$+7E(OCD@E?#OkOaeX8@+?EcT@*dN#$9Sl4;#wAyf zhXdRb5+vkE=b)efd9vr|E{Yu8IpP*XKIKUAdvPtbQLd_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); }