diff --git a/autogen/convert_constants.py b/autogen/convert_constants.py index b92b0b6d..c1de199c 100644 --- a/autogen/convert_constants.py +++ b/autogen/convert_constants.py @@ -17,7 +17,7 @@ in_files = [ "src/pc/network/network_player.h", "include/PR/os_cont.h", "src/game/interaction.c", - "src/pc/djui/djui_gfx_utils.h", + "src/pc/djui/djui_hud_utils.h", ] exclude_constants = [ diff --git a/autogen/convert_functions.py b/autogen/convert_functions.py index 115b8b46..8ab92a97 100644 --- a/autogen/convert_functions.py +++ b/autogen/convert_functions.py @@ -32,7 +32,7 @@ in_files = [ "src/game/level_info.h", "src/game/save_file.h", "src/game/sound_init.h", - "src/pc/djui/djui_gfx_utils.h", + "src/pc/djui/djui_hud_utils.h", ] override_allowed_functions = { @@ -164,6 +164,9 @@ def build_param(param, i): return ' %s %s = smlua_to_number(L, %d);\n' % (ptype, pid, i) elif ptype == 'const char*': return ' %s %s = smlua_to_string(L, %d);\n' % (ptype, pid, i) + elif translate_type_to_lot(ptype) == 'LOT_POINTER': + lvt = translate_type_to_lvt(ptype) + return ' %s %s = (%s)smlua_to_cpointer(L, %d, %s);\n' % (ptype, pid, ptype, i, lvt) else: lot = translate_type_to_lot(ptype) s = ' %s %s = (%s)smlua_to_cobject(L, %d, %s);' % (ptype, pid, ptype, i, lot) diff --git a/developer/network.sh b/developer/network.sh index 75ac1b2f..acbb6c9d 100644 --- a/developer/network.sh +++ b/developer/network.sh @@ -19,8 +19,8 @@ fi # no debug, direct $FILE --server 27015 --configfile sm64config_server.txt & -sleep 2 -$FILE --client 127.0.0.1 27015 --configfile sm64config_client.txt & +#sleep 2 +#$FILE --client 127.0.0.1 27015 --configfile sm64config_client.txt & exit # debug on server diff --git a/docs/lua/constants.md b/docs/lua/constants.md index 4866fb54..fdaea6a2 100644 --- a/docs/lua/constants.md +++ b/docs/lua/constants.md @@ -6,9 +6,9 @@ - [characters.h](#characters.h) - [CharacterSound](#CharacterSound) - [CharacterType](#CharacterType) -- [djui_gfx_utils.h](#djui_gfx_utils.h) +- [djui_hud_utils.h](#djui_hud_utils.h) - [DjuiFontType](#DjuiFontType) - - [GfxUtilsResolution](#GfxUtilsResolution) + - [HudUtilsResolution](#HudUtilsResolution) - [interaction.c](#interaction.c) - [InteractionFlag](#InteractionFlag) - [mario_animation_ids.h](#mario_animation_ids.h) @@ -745,7 +745,7 @@
-## [djui_gfx_utils.h](#djui_gfx_utils.h) +## [djui_hud_utils.h](#djui_hud_utils.h) ### [enum DjuiFontType](#DjuiFontType) | Identifier | Value | @@ -755,7 +755,7 @@ | FONT_HUD | 2 | | FONT_COUNT | 3 | -### [enum GfxUtilsResolution](#GfxUtilsResolution) +### [enum HudUtilsResolution](#HudUtilsResolution) | Identifier | Value | | :--------- | :---- | | RESOLUTION_DJUI | 0 | diff --git a/docs/lua/functions.md b/docs/lua/functions.md index fd58d577..8aa92084 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -26,14 +26,15 @@
-- djui_gfx_utils.h - - [djui_gfx_get_screen_height](#djui_gfx_get_screen_height) - - [djui_gfx_get_screen_width](#djui_gfx_get_screen_width) - - [djui_gfx_measure_text](#djui_gfx_measure_text) - - [djui_gfx_print_text](#djui_gfx_print_text) - - [djui_gfx_set_color](#djui_gfx_set_color) - - [djui_gfx_set_font](#djui_gfx_set_font) - - [djui_gfx_set_resolution](#djui_gfx_set_resolution) +- djui_hud_utils.h + - [djui_hud_get_screen_height](#djui_hud_get_screen_height) + - [djui_hud_get_screen_width](#djui_hud_get_screen_width) + - [djui_hud_measure_text](#djui_hud_measure_text) + - [djui_hud_print_text](#djui_hud_print_text) + - [djui_hud_render_texture](#djui_hud_render_texture) + - [djui_hud_set_color](#djui_hud_set_color) + - [djui_hud_set_font](#djui_hud_set_font) + - [djui_hud_set_resolution](#djui_hud_set_resolution)
@@ -623,15 +624,15 @@
--- -# functions from djui_gfx_utils.h +# functions from djui_hud_utils.h
-## [djui_gfx_get_screen_height](#djui_gfx_get_screen_height) +## [djui_hud_get_screen_height](#djui_hud_get_screen_height) ### Lua Example -`local integerValue = djui_gfx_get_screen_height()` +`local integerValue = djui_hud_get_screen_height()` ### Parameters - None @@ -640,16 +641,16 @@ - integer ### C Prototype -`u32 djui_gfx_get_screen_height(void);` +`u32 djui_hud_get_screen_height(void);` [:arrow_up_small:](#)
-## [djui_gfx_get_screen_width](#djui_gfx_get_screen_width) +## [djui_hud_get_screen_width](#djui_hud_get_screen_width) ### Lua Example -`local integerValue = djui_gfx_get_screen_width()` +`local integerValue = djui_hud_get_screen_width()` ### Parameters - None @@ -658,16 +659,16 @@ - integer ### C Prototype -`u32 djui_gfx_get_screen_width(void);` +`u32 djui_hud_get_screen_width(void);` [:arrow_up_small:](#)
-## [djui_gfx_measure_text](#djui_gfx_measure_text) +## [djui_hud_measure_text](#djui_hud_measure_text) ### Lua Example -`local numberValue = djui_gfx_measure_text(message)` +`local numberValue = djui_hud_measure_text(message)` ### Parameters | Field | Type | @@ -678,16 +679,16 @@ - number ### C Prototype -`f32 djui_gfx_measure_text(const char* message);` +`f32 djui_hud_measure_text(const char* message);` [:arrow_up_small:](#)
-## [djui_gfx_print_text](#djui_gfx_print_text) +## [djui_hud_print_text](#djui_hud_print_text) ### Lua Example -`djui_gfx_print_text(message, x, y, scale)` +`djui_hud_print_text(message, x, y, scale)` ### Parameters | Field | Type | @@ -701,16 +702,43 @@ - None ### C Prototype -`void djui_gfx_print_text(const char* message, float x, float y, float scale);` +`void djui_hud_print_text(const char* message, float x, float y, float scale);` [:arrow_up_small:](#)
-## [djui_gfx_set_color](#djui_gfx_set_color) +## [djui_hud_render_texture](#djui_hud_render_texture) ### Lua Example -`djui_gfx_set_color(r, g, b, a)` +`djui_hud_render_texture(texture, bitSize, x, y, width, height, scaleW, scaleH)` + +### Parameters +| Field | Type | +| ----- | ---- | +| texture | Pointer | +| bitSize | integer | +| x | number | +| y | number | +| width | integer | +| height | integer | +| scaleW | number | +| scaleH | number | + +### Returns +- None + +### C Prototype +`void djui_hud_render_texture(const u8* texture, u32 bitSize, f32 x, f32 y, u32 width, u32 height, f32 scaleW, f32 scaleH);` + +[:arrow_up_small:](#) + +
+ +## [djui_hud_set_color](#djui_hud_set_color) + +### Lua Example +`djui_hud_set_color(r, g, b, a)` ### Parameters | Field | Type | @@ -724,16 +752,16 @@ - None ### C Prototype -`void djui_gfx_set_color(u8 r, u8 g, u8 b, u8 a);` +`void djui_hud_set_color(u8 r, u8 g, u8 b, u8 a);` [:arrow_up_small:](#)
-## [djui_gfx_set_font](#djui_gfx_set_font) +## [djui_hud_set_font](#djui_hud_set_font) ### Lua Example -`djui_gfx_set_font(fontType)` +`djui_hud_set_font(fontType)` ### Parameters | Field | Type | @@ -744,16 +772,16 @@ - None ### C Prototype -`void djui_gfx_set_font(enum DjuiFontType fontType);` +`void djui_hud_set_font(enum DjuiFontType fontType);` [:arrow_up_small:](#)
-## [djui_gfx_set_resolution](#djui_gfx_set_resolution) +## [djui_hud_set_resolution](#djui_hud_set_resolution) ### Lua Example -`djui_gfx_set_resolution(resolutionType)` +`djui_hud_set_resolution(resolutionType)` ### Parameters | Field | Type | @@ -764,7 +792,7 @@ - None ### C Prototype -`void djui_gfx_set_resolution(enum GfxUtilsResolution resolutionType);` +`void djui_hud_set_resolution(enum HudUtilsResolution resolutionType);` [:arrow_up_small:](#) diff --git a/src/pc/djui/djui.c b/src/pc/djui/djui.c index 79dcb5a1..5a396b30 100644 --- a/src/pc/djui/djui.c +++ b/src/pc/djui/djui.c @@ -4,7 +4,6 @@ #include "game/level_update.h" #include "pc/lua/smlua_hooks.h" #include "djui_panel_playerlist.h" -#include "djui_gfx_utils.h" static Gfx* sSavedDisplayListHead = NULL; diff --git a/src/pc/djui/djui_gfx_utils.h b/src/pc/djui/djui_gfx_utils.h deleted file mode 100644 index 56e8cefc..00000000 --- a/src/pc/djui/djui_gfx_utils.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef DJUI_GFX_UTILS_H -#define DJUI_GFX_UTILS_H - -enum GfxUtilsResolution { - RESOLUTION_DJUI, - RESOLUTION_N64, - RESOLUTION_COUNT, -}; - -enum DjuiFontType { - FONT_NORMAL, - FONT_MENU, - FONT_HUD, - FONT_COUNT, -}; - -void djui_gfx_set_resolution(enum GfxUtilsResolution resolutionType); -void djui_gfx_set_font(enum DjuiFontType fontType); -void djui_gfx_set_color(u8 r, u8 g, u8 b, u8 a); - -u32 djui_gfx_get_screen_width(void); -u32 djui_gfx_get_screen_height(void); - -f32 djui_gfx_measure_text(const char* message); -void djui_gfx_print_text(const char* message, float x, float y, float scale); - -#endif \ No newline at end of file diff --git a/src/pc/djui/djui_gfx_utils.c b/src/pc/djui/djui_hud_utils.c similarity index 52% rename from src/pc/djui/djui_gfx_utils.c rename to src/pc/djui/djui_hud_utils.c index f3a3b6f6..2f0536a1 100644 --- a/src/pc/djui/djui_gfx_utils.c +++ b/src/pc/djui/djui_hud_utils.c @@ -6,29 +6,45 @@ #include "pc/gfx/gfx_window_manager_api.h" #include "pc/pc_main.h" +#include "djui_gfx.h" #include "gfx_dimensions.h" #include "config.h" #include "djui.h" -#include "djui_gfx_utils.h" +#include "djui_hud_utils.h" -static enum GfxUtilsResolution sResolution = RESOLUTION_DJUI; +static enum HudUtilsResolution sResolution = RESOLUTION_DJUI; static enum DjuiFontType sFont = FONT_NORMAL; -void djui_gfx_set_resolution(enum GfxUtilsResolution resolutionType) { +static void djui_hud_position_translate(f32* x, f32* y) { + if (sResolution == RESOLUTION_DJUI) { + djui_gfx_position_translate(x, y); + } else { + *x = GFX_DIMENSIONS_FROM_LEFT_EDGE(0) + *x; + *y = SCREEN_HEIGHT - *y; + } +} + +static void djui_hud_size_translate(f32* size) { + if (sResolution == RESOLUTION_DJUI) { + djui_gfx_size_translate(size); + } +} + +void djui_hud_set_resolution(enum HudUtilsResolution resolutionType) { if (resolutionType >= RESOLUTION_COUNT) { return; } sResolution = resolutionType; } -void djui_gfx_set_font(enum DjuiFontType fontType) { +void djui_hud_set_font(enum DjuiFontType fontType) { if (fontType >= FONT_COUNT) { return; } sFont = fontType; } -void djui_gfx_set_color(u8 r, u8 g, u8 b, u8 a) { +void djui_hud_set_color(u8 r, u8 g, u8 b, u8 a) { gDPSetEnvColor(gDisplayListHead++, r, g, b, a); } -u32 djui_gfx_get_screen_width(void) { +u32 djui_hud_get_screen_width(void) { u32 windowWidth, windowHeight; wm_api->get_dimensions(&windowWidth, &windowHeight); @@ -37,7 +53,7 @@ u32 djui_gfx_get_screen_width(void) { : (windowWidth / djui_gfx_get_scale()); } -u32 djui_gfx_get_screen_height(void) { +u32 djui_hud_get_screen_height(void) { u32 windowWidth, windowHeight; wm_api->get_dimensions(&windowWidth, &windowHeight); @@ -46,7 +62,7 @@ u32 djui_gfx_get_screen_height(void) { : (windowHeight / djui_gfx_get_scale()); } -f32 djui_gfx_measure_text(const char* message) { +f32 djui_hud_measure_text(const char* message) { if (message == NULL) { return 0; } const struct DjuiFont* font = gDjuiFonts[sFont]; f32 width = 0; @@ -58,7 +74,7 @@ f32 djui_gfx_measure_text(const char* message) { return width * font->defaultFontScale; } -void djui_gfx_print_text(const char* message, float x, float y, float scale) { +void djui_hud_print_text(const char* message, float x, float y, float scale) { if (message == NULL) { return; } const struct DjuiFont* font = gDjuiFonts[sFont]; f32 fontScale = font->defaultFontScale * scale; @@ -71,19 +87,12 @@ void djui_gfx_print_text(const char* message, float x, float y, float scale) { // translate position f32 translatedX = x; f32 translatedY = y; - if (sResolution == RESOLUTION_DJUI) { - djui_gfx_position_translate(&translatedX, &translatedY); - } else if (sResolution == RESOLUTION_N64) { - translatedX = GFX_DIMENSIONS_FROM_LEFT_EDGE(0) + x; - translatedY = SCREEN_HEIGHT - y; - } + djui_hud_position_translate(&translatedX, &translatedY); create_dl_translation_matrix(DJUI_MTX_PUSH, translatedX, translatedY, 0); // compute font size f32 translatedFontSize = fontScale; - if (sResolution == RESOLUTION_DJUI) { - djui_gfx_size_translate(&translatedFontSize); - } + djui_hud_size_translate(&translatedFontSize); create_dl_scale_matrix(DJUI_MTX_NOPUSH, translatedFontSize, translatedFontSize, 1.0f); // render the line @@ -108,33 +117,23 @@ void djui_gfx_print_text(const char* message, float x, float y, float scale) { gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW); } -void djui_gfx_utils_render(void) { - //struct DjuiColor fore = { .r = 255, .g = 255, .b = 255, .a = 255 }; - //struct DjuiColor back = { .r = 0, .g = 0, .b = 0, .a = 255 }; - //const struct DjuiFont* font = gDjuiFonts[2]; - //djui_gfx_print_text(font, "abcdefghijklmnopqrstuvwxyz:1234567890", 2, 2, 2, back); - //djui_gfx_print_text(font, "1234567890:abcdefghijklmnopqrstuvwxyz", 0, 0, 2, fore); - //float scale = 240.0f / gfx_current_dimensions.height; +void djui_hud_render_texture(const u8* texture, u32 bitSize, f32 x, f32 y, u32 width, u32 height, f32 scaleW, f32 scaleH) { + // translate position + f32 translatedX = x; + f32 translatedY = y; + djui_hud_position_translate(&translatedX, &translatedY); + create_dl_translation_matrix(DJUI_MTX_PUSH, translatedX, translatedY, 0); - /*{ - f32 screenWidth = djui_gfx_get_screen_width(RESOLUTION_N64); - f32 width = djui_gfx_measure_text(font, "PAUSE", RESOLUTION_N64); + // translate scale + f32 translatedW = scaleW; + f32 translatedH = scaleH; + djui_hud_size_translate(&translatedW); + djui_hud_size_translate(&translatedH); + create_dl_scale_matrix(DJUI_MTX_NOPUSH, width * translatedW, height * translatedH, 1.0f); - f32 screenHeight = djui_gfx_get_screen_height(RESOLUTION_N64); - f32 height = 16; + // render + djui_gfx_render_texture(texture, width, height, bitSize); - djui_gfx_print_text(font, "PAUSE", screenWidth - width, screenHeight - height - 32, 1.0f, fore, RESOLUTION_N64); - djui_gfx_print_text(font, "PAUSE", screenWidth - width * 2, screenHeight - height, 1.0f, fore, RESOLUTION_N64); - }*/ - - /*{ - f32 screenWidth = djui_gfx_get_screen_width(RESOLUTION_DJUI); - f32 width = djui_gfx_measure_text(font, "PAUSE", RESOLUTION_DJUI); - - f32 screenHeight = djui_gfx_get_screen_height(RESOLUTION_DJUI); - f32 height = 16; - - djui_gfx_print_text(FONT_NORMAL, "PAUSE", screenWidth - width, screenHeight - height - 32, 1.0f, fore, RESOLUTION_DJUI); - djui_gfx_print_text(FONT_NORMAL, "PAUSE", screenWidth - width * 2, screenHeight - height, 1.0f, fore, RESOLUTION_DJUI); - }*/ -} \ No newline at end of file + // pop + gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW); +} diff --git a/src/pc/djui/djui_hud_utils.h b/src/pc/djui/djui_hud_utils.h new file mode 100644 index 00000000..bb0d4175 --- /dev/null +++ b/src/pc/djui/djui_hud_utils.h @@ -0,0 +1,28 @@ +#ifndef DJUI_HUD_UTILS_H +#define DJUI_HUD_UTILS_H + +enum HudUtilsResolution { + RESOLUTION_DJUI, + RESOLUTION_N64, + RESOLUTION_COUNT, +}; + +enum DjuiFontType { + FONT_NORMAL, + FONT_MENU, + FONT_HUD, + FONT_COUNT, +}; + +void djui_hud_set_resolution(enum HudUtilsResolution resolutionType); +void djui_hud_set_font(enum DjuiFontType fontType); +void djui_hud_set_color(u8 r, u8 g, u8 b, u8 a); + +u32 djui_hud_get_screen_width(void); +u32 djui_hud_get_screen_height(void); + +f32 djui_hud_measure_text(const char* message); +void djui_hud_print_text(const char* message, float x, float y, float scale); +void djui_hud_render_texture(const u8* texture, u32 bitSize, f32 x, f32 y, u32 width, u32 height, f32 scaleW, f32 scaleH); + +#endif \ No newline at end of file diff --git a/src/pc/lua/smlua_cobject.c b/src/pc/lua/smlua_cobject.c index 9dcdea8a..f9e3198a 100644 --- a/src/pc/lua/smlua_cobject.c +++ b/src/pc/lua/smlua_cobject.c @@ -107,7 +107,7 @@ static int smlua__get_field(lua_State* L) { case LVT_S16_P: case LVT_S32_P: case LVT_F32_P: - smlua_push_pointer(L, data->valueType, p); + smlua_push_pointer(L, data->valueType, *(u8**)p); break; default: diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index ed1c0e6f..da8b9ca8 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -16,7 +16,7 @@ #include "src/game/level_info.h" #include "src/game/save_file.h" #include "src/game/sound_init.h" -#include "src/pc/djui/djui_gfx_utils.h" +#include "src/pc/djui/djui_hud_utils.h" ////////////// @@ -203,39 +203,39 @@ int smlua_func_djui_chat_message_create(lua_State* L) { } ////////////////////// - // djui_gfx_utils.h // + // djui_hud_utils.h // ////////////////////// -int smlua_func_djui_gfx_get_screen_height(UNUSED lua_State* L) { +int smlua_func_djui_hud_get_screen_height(UNUSED lua_State* L) { if(!smlua_functions_valid_param_count(L, 0)) { return 0; } - lua_pushinteger(L, djui_gfx_get_screen_height()); + lua_pushinteger(L, djui_hud_get_screen_height()); return 1; } -int smlua_func_djui_gfx_get_screen_width(UNUSED lua_State* L) { +int smlua_func_djui_hud_get_screen_width(UNUSED lua_State* L) { if(!smlua_functions_valid_param_count(L, 0)) { return 0; } - lua_pushinteger(L, djui_gfx_get_screen_width()); + lua_pushinteger(L, djui_hud_get_screen_width()); return 1; } -int smlua_func_djui_gfx_measure_text(lua_State* L) { +int smlua_func_djui_hud_measure_text(lua_State* L) { if(!smlua_functions_valid_param_count(L, 1)) { return 0; } const char* message = smlua_to_string(L, 1); if (!gSmLuaConvertSuccess) { return 0; } - lua_pushnumber(L, djui_gfx_measure_text(message)); + lua_pushnumber(L, djui_hud_measure_text(message)); return 1; } -int smlua_func_djui_gfx_print_text(lua_State* L) { +int smlua_func_djui_hud_print_text(lua_State* L) { if(!smlua_functions_valid_param_count(L, 4)) { return 0; } const char* message = smlua_to_string(L, 1); @@ -247,12 +247,37 @@ int smlua_func_djui_gfx_print_text(lua_State* L) { float scale = smlua_to_number(L, 4); if (!gSmLuaConvertSuccess) { return 0; } - djui_gfx_print_text(message, x, y, scale); + djui_hud_print_text(message, x, y, scale); return 1; } -int smlua_func_djui_gfx_set_color(lua_State* L) { +int smlua_func_djui_hud_render_texture(lua_State* L) { + if(!smlua_functions_valid_param_count(L, 8)) { return 0; } + + const u8* texture = (const u8*)smlua_to_cpointer(L, 1, LVT_U8_P); + if (!gSmLuaConvertSuccess) { return 0; } + u32 bitSize = smlua_to_integer(L, 2); + if (!gSmLuaConvertSuccess) { return 0; } + f32 x = smlua_to_number(L, 3); + if (!gSmLuaConvertSuccess) { return 0; } + f32 y = smlua_to_number(L, 4); + if (!gSmLuaConvertSuccess) { return 0; } + u32 width = smlua_to_integer(L, 5); + if (!gSmLuaConvertSuccess) { return 0; } + u32 height = smlua_to_integer(L, 6); + if (!gSmLuaConvertSuccess) { return 0; } + f32 scaleW = smlua_to_number(L, 7); + if (!gSmLuaConvertSuccess) { return 0; } + f32 scaleH = smlua_to_number(L, 8); + if (!gSmLuaConvertSuccess) { return 0; } + + djui_hud_render_texture(texture, bitSize, x, y, width, height, scaleW, scaleH); + + return 1; +} + +int smlua_func_djui_hud_set_color(lua_State* L) { if(!smlua_functions_valid_param_count(L, 4)) { return 0; } u8 r = smlua_to_integer(L, 1); @@ -264,29 +289,29 @@ int smlua_func_djui_gfx_set_color(lua_State* L) { u8 a = smlua_to_integer(L, 4); if (!gSmLuaConvertSuccess) { return 0; } - djui_gfx_set_color(r, g, b, a); + djui_hud_set_color(r, g, b, a); return 1; } -int smlua_func_djui_gfx_set_font(lua_State* L) { +int smlua_func_djui_hud_set_font(lua_State* L) { if(!smlua_functions_valid_param_count(L, 1)) { return 0; } int fontType = smlua_to_integer(L, 1); if (!gSmLuaConvertSuccess) { return 0; } - djui_gfx_set_font(fontType); + djui_hud_set_font(fontType); return 1; } -int smlua_func_djui_gfx_set_resolution(lua_State* L) { +int smlua_func_djui_hud_set_resolution(lua_State* L) { if(!smlua_functions_valid_param_count(L, 1)) { return 0; } int resolutionType = smlua_to_integer(L, 1); if (!gSmLuaConvertSuccess) { return 0; } - djui_gfx_set_resolution(resolutionType); + djui_hud_set_resolution(resolutionType); return 1; } @@ -3460,14 +3485,15 @@ void smlua_bind_functions_autogen(void) { // djui_chat_message.h smlua_bind_function(L, "djui_chat_message_create", smlua_func_djui_chat_message_create); - // djui_gfx_utils.h - smlua_bind_function(L, "djui_gfx_get_screen_height", smlua_func_djui_gfx_get_screen_height); - smlua_bind_function(L, "djui_gfx_get_screen_width", smlua_func_djui_gfx_get_screen_width); - smlua_bind_function(L, "djui_gfx_measure_text", smlua_func_djui_gfx_measure_text); - smlua_bind_function(L, "djui_gfx_print_text", smlua_func_djui_gfx_print_text); - smlua_bind_function(L, "djui_gfx_set_color", smlua_func_djui_gfx_set_color); - smlua_bind_function(L, "djui_gfx_set_font", smlua_func_djui_gfx_set_font); - smlua_bind_function(L, "djui_gfx_set_resolution", smlua_func_djui_gfx_set_resolution); + // djui_hud_utils.h + smlua_bind_function(L, "djui_hud_get_screen_height", smlua_func_djui_hud_get_screen_height); + smlua_bind_function(L, "djui_hud_get_screen_width", smlua_func_djui_hud_get_screen_width); + smlua_bind_function(L, "djui_hud_measure_text", smlua_func_djui_hud_measure_text); + smlua_bind_function(L, "djui_hud_print_text", smlua_func_djui_hud_print_text); + smlua_bind_function(L, "djui_hud_render_texture", smlua_func_djui_hud_render_texture); + smlua_bind_function(L, "djui_hud_set_color", smlua_func_djui_hud_set_color); + smlua_bind_function(L, "djui_hud_set_font", smlua_func_djui_hud_set_font); + smlua_bind_function(L, "djui_hud_set_resolution", smlua_func_djui_hud_set_resolution); // djui_popup.h smlua_bind_function(L, "djui_popup_create", smlua_func_djui_popup_create); diff --git a/src/pc/lua/smlua_utils.c b/src/pc/lua/smlua_utils.c index 07bf1099..17c1c244 100644 --- a/src/pc/lua/smlua_utils.c +++ b/src/pc/lua/smlua_utils.c @@ -131,6 +131,50 @@ void* smlua_to_cobject(lua_State* L, int index, u16 lot) { return pointer; } +void* smlua_to_cpointer(lua_State* L, int index, u16 lvt) { + if (lua_type(L, index) != LUA_TTABLE) { + LOG_LUA("smlua_to_cpointer received improper type '%d'", lua_type(L, index)); + smlua_logline(); + gSmLuaConvertSuccess = false; + return 0; + } + + // get LVT + lua_getfield(L, index, "_lvt"); + enum LuaObjectType objLvt = smlua_to_integer(L, -1); + lua_pop(L, 1); + if (!gSmLuaConvertSuccess) { return NULL; } + + if (lvt != objLvt) { + LOG_LUA("smlua_to_cpointer received improper LVT. Expected '%d', received '%d'", lvt, objLvt); + smlua_logline(); + gSmLuaConvertSuccess = false; + return NULL; + } + + // get pointer + lua_getfield(L, index, "_pointer"); + void* pointer = (void*)(intptr_t)smlua_to_integer(L, -1); + lua_pop(L, 1); + if (!gSmLuaConvertSuccess) { return NULL; } + + // TODO: check allowlist + /*if (!smlua_cobject_allowlist_contains(lot, (u64)(intptr_t)pointer)) { + LOG_LUA("smlua_to_cobject received a pointer not in allow list. '%u', '%llu", lot, (u64)(intptr_t)pointer); + gSmLuaConvertSuccess = false; + return NULL; + }*/ + + if (pointer == NULL) { + LOG_LUA("smlua_to_cpointer received null pointer."); + smlua_logline(); + gSmLuaConvertSuccess = false; + return NULL; + } + + gSmLuaConvertSuccess = true; + return pointer; +} struct LSTNetworkType smlua_to_lnt(lua_State* L, int index) { struct LSTNetworkType lnt = { 0 }; int valueType = lua_type(L, index); diff --git a/src/pc/lua/smlua_utils.h b/src/pc/lua/smlua_utils.h index d0a8a102..b859c973 100644 --- a/src/pc/lua/smlua_utils.h +++ b/src/pc/lua/smlua_utils.h @@ -14,6 +14,7 @@ lua_Integer smlua_to_integer(lua_State* L, int index); lua_Number smlua_to_number(lua_State* L, int index); const char* smlua_to_string(lua_State* L, int index); void* smlua_to_cobject(lua_State* L, int index, u16 lot); +void* smlua_to_cpointer(lua_State* L, int index, u16 lvt); struct LSTNetworkType smlua_to_lnt(lua_State* L, int index); void smlua_push_object(lua_State* L, u16 lot, void* p);