From a45dbbbeb53de0a402fe8db4734527949d1fde1c Mon Sep 17 00:00:00 2001 From: PeachyPeachSM64 <72323920+PeachyPeachSM64@users.noreply.github.com> Date: Sat, 8 Nov 2025 16:46:59 +0100 Subject: [PATCH] Fix gfx_set_command bug if symbol is a substring of another symbol --- data/dynos_bin_gfx.cpp | 34 ++++++++++++++++--- .../gfx-vtx-demo/actors/shape/model.inc.c | 2 +- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/data/dynos_bin_gfx.cpp b/data/dynos_bin_gfx.cpp index ae61971cc..caae686da 100644 --- a/data/dynos_bin_gfx.cpp +++ b/data/dynos_bin_gfx.cpp @@ -1235,12 +1235,36 @@ struct GfxParamInfo { const GfxParamType *types; }; +// Allow whitespaces before and after the command symbol name +static const char *ExtractGfxSymbol(const char *command, size_t *symbolLength) { + const char *symbol = NULL; + *symbolLength = 0; + for (; *command != 0; command++) { + if ((u8) *command <= (u8) ' ' || *command == '(') { + if (symbol != NULL) { + return symbol; + } + } else { + if (symbol == NULL) { + symbol = command; + } + (*symbolLength)++; + } + } + return symbol; +} + static const struct GfxParamInfo *GetGfxParamInfo(const char *command) { -#define define_gfx_symbol(symb, params, addPtr, ...) \ - static const GfxParamType types_##symb[] = { __VA_ARGS__ }; \ - static struct GfxParamInfo info_##symb = { .count = params, .types = types_##symb }; \ - static_assert(sizeof(types_##symb) == params, "Parameter count does not match for gfx command."); \ - if (!strncmp(#symb, command, strlen(#symb))) { return &info_##symb; } + size_t symbolLength = 0; + const char *symbol = ExtractGfxSymbol(command, &symbolLength); + if (symbol == NULL) { return NULL; } +#define define_gfx_symbol(symb, params, addPtr, ...) \ +{ \ + static const GfxParamType types_##symb[] = { __VA_ARGS__ }; \ + static struct GfxParamInfo info_##symb = { .count = params, .types = types_##symb }; \ + static_assert(sizeof(types_##symb) == params, "Parameter count does not match for gfx symbol: " #symb); \ + if (symbolLength == sizeof(#symb) - 1 && !memcmp(symbol, #symb, symbolLength)) { return &info_##symb; } \ +} #define define_gfx_symbol_manual(...) define_gfx_symbol(__VA_ARGS__) #include "gfx_symbols.h" #undef define_gfx_symbol diff --git a/docs/lua/examples/gfx-vtx-demo/actors/shape/model.inc.c b/docs/lua/examples/gfx-vtx-demo/actors/shape/model.inc.c index 46f01d338..0c50d2832 100644 --- a/docs/lua/examples/gfx-vtx-demo/actors/shape/model.inc.c +++ b/docs/lua/examples/gfx-vtx-demo/actors/shape/model.inc.c @@ -15,6 +15,6 @@ Gfx shape_template_dl[] = { /* [11] */ gsSPDisplayList(NULL), /* [12] */ gsSPTexture(0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_OFF), /* [13] */ gsDPSetCombineMode(G_CC_SHADE, G_CC_SHADE), -/* [14] */ gsSPLoadGeometryMode(G_LIGHTING | G_CULL_BACK), +/* [14] */ gsSPGeometryMode(G_TEXTURE_GEN, G_LIGHTING | G_CULL_BACK), /* [15] */ gsSPEndDisplayList(), };