From 51c1af7c685dbd83a12ddde512f7cc030ce5b0af Mon Sep 17 00:00:00 2001 From: MysterD Date: Tue, 29 Mar 2022 21:42:41 -0700 Subject: [PATCH] Allow lua's network_init_object() to use 16 and 8 bit fields --- src/pc/lua/smlua_functions.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/pc/lua/smlua_functions.c b/src/pc/lua/smlua_functions.c index 3dd8acb7..12d4b061 100644 --- a/src/pc/lua/smlua_functions.c +++ b/src/pc/lua/smlua_functions.c @@ -134,15 +134,20 @@ int smlua_func_network_init_object(lua_State* L) { if (data == NULL) { data = smlua_get_custom_field(L, LOT_OBJECT, lua_gettop(L)); } - bool validLvt = (data->valueType == LVT_U32) || (data->valueType == LVT_S32) || (data->valueType == LVT_F32); - if (data == NULL || !validLvt) { + + u8 lvtSize = 0; + if ((data->valueType == LVT_U32) || (data->valueType == LVT_S32) || (data->valueType == LVT_F32)) { lvtSize = 32; } + if ((data->valueType == LVT_U16) || (data->valueType == LVT_S16)) { lvtSize = 16; } + if ((data->valueType == LVT_U8) || (data->valueType == LVT_S8)) { lvtSize = 8; } + + if (data == NULL || lvtSize == 0) { LOG_LUA("Invalid field passed to network_init_object(): %s", fieldIdentifier); lua_pop(L, 1); // pop value continue; } u8* field = ((u8*)(intptr_t)obj) + data->valueOffset; - network_init_object_field(obj, field); + network_init_object_field_with_size(obj, field, lvtSize); lua_pop(L, 1); // pop value }