From e1aab9c4794cf0f9d5c0a7e858370a2e95ffde60 Mon Sep 17 00:00:00 2001
From: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com>
Date: Thu, 5 Jun 2025 17:07:53 +1000
Subject: [PATCH] gfx_get_texture
returns a pointer to the texture in the gfx command
---
autogen/lua_definitions/functions.lua | 7 +++++++
docs/lua/functions-6.md | 23 +++++++++++++++++++++++
docs/lua/functions.md | 1 +
src/pc/lua/smlua_functions_autogen.c | 18 ++++++++++++++++++
src/pc/lua/utils/smlua_gfx_utils.c | 9 +++++++++
src/pc/lua/utils/smlua_gfx_utils.h | 2 ++
6 files changed, 60 insertions(+)
diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua
index e5d0c0248..ea71d83b3 100644
--- a/autogen/lua_definitions/functions.lua
+++ b/autogen/lua_definitions/functions.lua
@@ -10307,6 +10307,13 @@ function gfx_get_vertex_count(cmd)
-- ...
end
+--- @param cmd Pointer_Gfx
+--- @return Pointer_integer
+--- Gets the texture from a display list command if it has an image related op
+function gfx_get_texture(cmd)
+ -- ...
+end
+
--- @param gfx Pointer_Gfx
--- @return integer
--- Gets the max length of a display list
diff --git a/docs/lua/functions-6.md b/docs/lua/functions-6.md
index 782c9c004..81ec58fe7 100644
--- a/docs/lua/functions-6.md
+++ b/docs/lua/functions-6.md
@@ -2679,6 +2679,29 @@ Gets the number of vertices from a display list command if it has the op `G_VTX`
+## [gfx_get_texture](#gfx_get_texture)
+
+### Description
+Gets the texture from a display list command if it has an image related op
+
+### Lua Example
+`local PointerValue = gfx_get_texture(cmd)`
+
+### Parameters
+| Field | Type |
+| ----- | ---- |
+| cmd | `Pointer` <`Gfx`> |
+
+### Returns
+- `Pointer` <`integer`>
+
+### C Prototype
+`u8 *gfx_get_texture(Gfx *cmd);`
+
+[:arrow_up_small:](#)
+
+
+
## [gfx_get_length](#gfx_get_length)
### Description
diff --git a/docs/lua/functions.md b/docs/lua/functions.md
index 84db1e21c..cbcc0f899 100644
--- a/docs/lua/functions.md
+++ b/docs/lua/functions.md
@@ -1872,6 +1872,7 @@
- [gfx_get_display_list](functions-6.md#gfx_get_display_list)
- [gfx_get_vertex_buffer](functions-6.md#gfx_get_vertex_buffer)
- [gfx_get_vertex_count](functions-6.md#gfx_get_vertex_count)
+ - [gfx_get_texture](functions-6.md#gfx_get_texture)
- [gfx_get_length](functions-6.md#gfx_get_length)
- [gfx_get_command](functions-6.md#gfx_get_command)
- [gfx_get_next_command](functions-6.md#gfx_get_next_command)
diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c
index 96b53d8d5..bd3802b87 100644
--- a/src/pc/lua/smlua_functions_autogen.c
+++ b/src/pc/lua/smlua_functions_autogen.c
@@ -31406,6 +31406,23 @@ int smlua_func_gfx_get_vertex_count(lua_State* L) {
return 1;
}
+int smlua_func_gfx_get_texture(lua_State* L) {
+ if (L == NULL) { return 0; }
+
+ int top = lua_gettop(L);
+ if (top != 1) {
+ LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "gfx_get_texture", 1, top);
+ return 0;
+ }
+
+ Gfx * cmd = (Gfx *)smlua_to_cobject(L, 1, LOT_GFX);
+ if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "gfx_get_texture"); return 0; }
+
+ smlua_push_pointer(L, LVT_U8_P, (void*)gfx_get_texture(cmd), NULL);
+
+ return 1;
+}
+
int smlua_func_gfx_get_length(lua_State* L) {
if (L == NULL) { return 0; }
@@ -36994,6 +37011,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "gfx_get_display_list", smlua_func_gfx_get_display_list);
smlua_bind_function(L, "gfx_get_vertex_buffer", smlua_func_gfx_get_vertex_buffer);
smlua_bind_function(L, "gfx_get_vertex_count", smlua_func_gfx_get_vertex_count);
+ smlua_bind_function(L, "gfx_get_texture", smlua_func_gfx_get_texture);
smlua_bind_function(L, "gfx_get_length", smlua_func_gfx_get_length);
smlua_bind_function(L, "gfx_get_command", smlua_func_gfx_get_command);
smlua_bind_function(L, "gfx_get_next_command", smlua_func_gfx_get_next_command);
diff --git a/src/pc/lua/utils/smlua_gfx_utils.c b/src/pc/lua/utils/smlua_gfx_utils.c
index c9bfe35ba..ebc51c785 100644
--- a/src/pc/lua/utils/smlua_gfx_utils.c
+++ b/src/pc/lua/utils/smlua_gfx_utils.c
@@ -238,6 +238,15 @@ u16 gfx_get_vertex_count(Gfx *cmd) {
return C0(cmd, 12, 8);
}
+u8 *gfx_get_texture(Gfx *cmd) {
+ if (!cmd) { return 0; }
+ u32 op = GFX_OP(cmd);
+ if (op != G_SETCIMG && op != G_SETZIMG && op != G_SETTIMG) { return 0; }
+ if (cmd->words.w1 == 0) { return 0; }
+
+ return (u8 *) cmd->words.w1;
+}
+
u32 gfx_get_length(Gfx *gfx) {
if (!gfx) { return 0; }
diff --git a/src/pc/lua/utils/smlua_gfx_utils.h b/src/pc/lua/utils/smlua_gfx_utils.h
index 9de8ba416..331dcc456 100644
--- a/src/pc/lua/utils/smlua_gfx_utils.h
+++ b/src/pc/lua/utils/smlua_gfx_utils.h
@@ -66,6 +66,8 @@ Gfx *gfx_get_display_list(Gfx *cmd);
Vtx *gfx_get_vertex_buffer(Gfx *cmd);
/* |description|Gets the number of vertices from a display list command if it has the op `G_VTX`|descriptionEnd| */
u16 gfx_get_vertex_count(Gfx *cmd);
+/* |description|Gets the texture from a display list command if it has an image related op|descriptionEnd| */
+u8 *gfx_get_texture(Gfx *cmd);
/* |description|Gets the max length of a display list|descriptionEnd| */
u32 gfx_get_length(Gfx *gfx);