From 5a2e060c2dd9a9217642381051013dd8fa21154f Mon Sep 17 00:00:00 2001
From: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com>
Date: Wed, 12 Feb 2025 18:24:01 +1000
Subject: [PATCH] autogen implement structs with name after definition
---
 autogen/convert_structs.py          |  8 ++++++--
 autogen/extract_structs.py          |  2 +-
 autogen/lua_definitions/structs.lua |  4 ++++
 docs/lua/structs.md                 | 12 ++++++++++++
 src/pc/lua/smlua_cobject_autogen.c  |  7 +++++++
 src/pc/lua/smlua_cobject_autogen.h  |  1 +
 6 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/autogen/convert_structs.py b/autogen/convert_structs.py
index 308b79ea7..b126713bc 100644
--- a/autogen/convert_structs.py
+++ b/autogen/convert_structs.py
@@ -260,7 +260,9 @@ def table_to_string(table):
 
 def parse_struct(struct_str, sortFields = True):
     struct = {}
-    identifier = struct_str.split(' ')[1]
+    match = re.match(r"struct\s*(\w+)?\s*{(.*?)}\s*(\w+)?\s*", struct_str.replace("typedef ", ""), re.DOTALL)
+    struct_name, body, trailing_name = match.groups()
+    identifier = struct_name if struct_name else trailing_name
     struct['identifier'] = identifier
 
     body = struct_str.split('{', 1)[1].rsplit('}', 1)[0]
@@ -277,7 +279,9 @@ def parse_struct(struct_str, sortFields = True):
             field_type, field_id = field_str.strip().rsplit('*', 1)
             field_type = field_type.strip() + '*'
         else:
-            field_type, field_id = field_str.strip().rsplit(' ', 1)
+            split_parts = re.split(r'\s+', field_str.strip())
+            field_type = ' '.join(split_parts[:-1])
+            field_id = split_parts[-1]
 
         if '[' in field_id:
             array_str = '[' + field_id.split('[', 1)[1]
diff --git a/autogen/extract_structs.py b/autogen/extract_structs.py
index f70c2867e..a2d65f1e9 100644
--- a/autogen/extract_structs.py
+++ b/autogen/extract_structs.py
@@ -67,7 +67,7 @@ def extract_structs(filename):
             continue
         if ';' not in line:
             continue
-        if not line.startswith('struct '):
+        if not line.startswith('struct ') and not line.startswith('typedef struct '):
             continue
         txt += line + '\n'
 
diff --git a/autogen/lua_definitions/structs.lua b/autogen/lua_definitions/structs.lua
index 81e22cca1..ab2652682 100644
--- a/autogen/lua_definitions/structs.lua
+++ b/autogen/lua_definitions/structs.lua
@@ -2302,6 +2302,10 @@
 --- @field public posPitch integer
 --- @field public posYaw integer
 
+--- @class Vtx_Interp
+--- @field public n string
+--- @field public ob Array_number
+
 --- @class WallCollisionData
 --- @field public normalAddition Vec3f
 --- @field public normalCount integer
diff --git a/docs/lua/structs.md b/docs/lua/structs.md
index d58bde6c2..3f5e4007c 100644
--- a/docs/lua/structs.md
+++ b/docs/lua/structs.md
@@ -109,6 +109,7 @@
 - [Vec3s](#Vec3s)
 - [Vec4f](#Vec4f)
 - [Vec4s](#Vec4s)
+- [Vtx_Interp](#Vtx_Interp)
 - [WallCollisionData](#WallCollisionData)
 - [WarpNode](#WarpNode)
 - [WarpTransition](#WarpTransition)
@@ -3197,6 +3198,17 @@
 
 
 
+## [Vtx_Interp](#Vtx_Interp)
+
+| Field | Type | Access |
+| ----- | ---- | ------ |
+| n | `string` |  |
+| ob | `Array` <`number`> |  |
+
+[:arrow_up_small:](#)
+
+
+
 ## [WallCollisionData](#WallCollisionData)
 
 | Field | Type | Access |
diff --git a/src/pc/lua/smlua_cobject_autogen.c b/src/pc/lua/smlua_cobject_autogen.c
index dddda15db..98827be89 100644
--- a/src/pc/lua/smlua_cobject_autogen.c
+++ b/src/pc/lua/smlua_cobject_autogen.c
@@ -2679,6 +2679,12 @@ static struct LuaObjectField sTransitionInfoFields[LUA_TRANSITION_INFO_FIELD_COU
     { "posYaw",     LVT_S16,     offsetof(struct TransitionInfo, posYaw),     false, LOT_NONE,  1, sizeof(s16)   },
 };
 
+#define LUA_VTX__INTERP_FIELD_COUNT 2
+static struct LuaObjectField sVtx_InterpFields[LUA_VTX__INTERP_FIELD_COUNT] = {
+    { "n",  LVT_STRING, offsetof(struct Vtx_Interp, n),  false, LOT_NONE, 1, sizeof(signed char) },
+    { "ob", LVT_FLOAT,  offsetof(struct Vtx_Interp, ob), false, LOT_NONE, 3, sizeof(float)       },
+};
+
 #define LUA_WALL_COLLISION_DATA_FIELD_COUNT 10
 static struct LuaObjectField sWallCollisionDataFields[LUA_WALL_COLLISION_DATA_FIELD_COUNT] = {
     { "normalAddition", LVT_COBJECT,   offsetof(struct WallCollisionData, normalAddition), true,  LOT_VEC3F,   1, sizeof(Vec3f)           },
@@ -2854,6 +2860,7 @@ struct LuaObjectTable sLuaObjectAutogenTable[LOT_AUTOGEN_MAX - LOT_AUTOGEN_MIN]
     { LOT_SURFACE,                      sSurfaceFields,                      LUA_SURFACE_FIELD_COUNT                         },
     { LOT_TEXTUREINFO,                  sTextureInfoFields,                  LUA_TEXTURE_INFO_FIELD_COUNT                    },
     { LOT_TRANSITIONINFO,               sTransitionInfoFields,               LUA_TRANSITION_INFO_FIELD_COUNT                 },
+    { LOT_VTX_INTERP,                   sVtx_InterpFields,                   LUA_VTX__INTERP_FIELD_COUNT                     },
     { LOT_WALLCOLLISIONDATA,            sWallCollisionDataFields,            LUA_WALL_COLLISION_DATA_FIELD_COUNT             },
     { LOT_WARPNODE,                     sWarpNodeFields,                     LUA_WARP_NODE_FIELD_COUNT                       },
     { LOT_WARPTRANSITION,               sWarpTransitionFields,               LUA_WARP_TRANSITION_FIELD_COUNT                 },
diff --git a/src/pc/lua/smlua_cobject_autogen.h b/src/pc/lua/smlua_cobject_autogen.h
index bb15d56f3..286699f94 100644
--- a/src/pc/lua/smlua_cobject_autogen.h
+++ b/src/pc/lua/smlua_cobject_autogen.h
@@ -114,6 +114,7 @@ enum LuaObjectAutogenType {
     LOT_SURFACE,
     LOT_TEXTUREINFO,
     LOT_TRANSITIONINFO,
+    LOT_VTX_INTERP,
     LOT_WALLCOLLISIONDATA,
     LOT_WARPNODE,
     LOT_WARPTRANSITION,