diff --git a/autogen/common.py b/autogen/common.py index 6be11fa5..47074343 100644 --- a/autogen/common.py +++ b/autogen/common.py @@ -17,8 +17,10 @@ def get_path(p): def translate_type_to_lvt(ptype): if '[' in ptype or '{' in ptype: return 'LOT_???' - if 'enum' in ptype: + if 'enum ' in ptype: return 'LVT_S32' + if ptype == 'bool': + return 'LVT_U8' if ptype in usf_types: return 'LVT_' + ptype.upper() if ptype in vec3_types: @@ -36,7 +38,9 @@ def translate_type_to_lvt(ptype): def translate_type_to_lot(ptype): if '[' in ptype or '{' in ptype: return 'LOT_???' - if 'enum' in ptype: + if 'enum ' in ptype: + return 'LOT_NONE' + if ptype == 'bool': return 'LOT_NONE' if ptype in usf_types: return 'LOT_NONE' diff --git a/autogen/convert_functions.py b/autogen/convert_functions.py index 1a4b6ee8..35dfec43 100644 --- a/autogen/convert_functions.py +++ b/autogen/convert_functions.py @@ -100,6 +100,8 @@ def normalize_type(t): def alter_type(t): if t.startswith('enum '): return 'int' + if t == 'bool': + return 'u8' return t diff --git a/autogen/convert_structs.py b/autogen/convert_structs.py index 519c0ef9..d35255a7 100644 --- a/autogen/convert_structs.py +++ b/autogen/convert_structs.py @@ -9,7 +9,8 @@ in_files = [ 'src/game/area.h', 'src/game/camera.h', 'src/game/characters.h', - 'src/engine/surface_collision.h' + 'src/engine/surface_collision.h', + 'src/pc/network/network_player.h' ] smlua_cobject_autogen = 'src/pc/lua/smlua_cobject_autogen' @@ -55,6 +56,7 @@ override_field_types = { override_field_immutable = { "MarioState": [ "playerIndex" ], "Character": [ "*" ], + "NetworkPlayer": [ "*" ], } sLuaManuallyDefinedStructs = [ diff --git a/docs/lua/constants.md b/docs/lua/constants.md index 1ac984de..342c1006 100644 --- a/docs/lua/constants.md +++ b/docs/lua/constants.md @@ -537,6 +537,19 @@ - CT_WALUIGI - CT_MAX +
+ +- NPT_UNKNOWN +- NPT_LOCAL +- NPT_SERVER +- NPT_CLIENT + +
+ +- UNKNOWN_LOCAL_INDEX +- UNKNOWN_GLOBAL_INDEX +- UNKNOWN_NETWORK_INDEX + [:arrow_up_small:](#)
diff --git a/docs/lua/globals.md b/docs/lua/globals.md index 308d5d50..39dff2ae 100644 --- a/docs/lua/globals.md +++ b/docs/lua/globals.md @@ -14,6 +14,15 @@ It is indexed by the local `playerIndex`, so `gMarioStates[0]` is always the loc
+## [gNetworkPlayers](#gNetworkPlayers) +The `gNetworkPlayers[]` table is an array from `0` to `(MAX_PLAYERS - 1)` that contains a [NetworkPlayer](structs.md#NetworkPlayer) struct for each possible player. + +It is indexed by the local `playerIndex`, so `gNetworkPlayers[0]` is always the local player. + +[:arrow_up_small:](#) + +
+ ## [gCharacter](#gCharacter) The `gCharacter[]` table is an array from `0` to `(CT_MAX - 1)` that contains a [Character](structs.md#Character) struct for each possible character. diff --git a/docs/lua/structs.md b/docs/lua/structs.md index 45763ea7..863bfb6f 100644 --- a/docs/lua/structs.md +++ b/docs/lua/structs.md @@ -25,6 +25,7 @@ - [MarioBodyState](#MarioBodyState) - [MarioState](#MarioState) - [ModeTransitionInfo](#ModeTransitionInfo) +- [NetworkPlayer](#NetworkPlayer) - [Object](#Object) - [ObjectHitbox](#ObjectHitbox) - [ObjectNode](#ObjectNode) @@ -557,6 +558,32 @@
+## [NetworkPlayer](#NetworkPlayer) + +| Field | Type | +| ----- | ---- | +| connected | bool | +| currActNum | integer | +| currAreaIndex | integer | +| currAreaSyncValid | bool | +| currCourseNum | integer | +| currLevelAreaSeqId | integer | +| currLevelNum | integer | +| currLevelSyncValid | bool | +| fadeOpacity | integer | +| globalIndex | integer | +| lastReceived | number | +| lastSent | number | +| localIndex | integer | +| modelIndex | integer | +| onRxSeqId | integer | +| paletteIndex | integer | +| type | integer | + +[:arrow_up_small:](#) + +
+ ## [Object](#Object) | Field | Type | diff --git a/src/pc/lua/smlua_cobject.c b/src/pc/lua/smlua_cobject.c index 8430f1f4..e5ac3dcf 100644 --- a/src/pc/lua/smlua_cobject.c +++ b/src/pc/lua/smlua_cobject.c @@ -172,6 +172,17 @@ void smlua_cobject_init_globals(void) { lua_setglobal(L, "gMarioStates"); } + { + lua_newtable(L); + int t = lua_gettop(gLuaState); + for (int i = 0; i < MAX_PLAYERS; i++) { + lua_pushinteger(L, i); + smlua_push_object(L, LOT_NETWORKPLAYER, &gNetworkPlayers[i]); + lua_settable(L, t); + } + lua_setglobal(L, "gNetworkPlayers"); + } + { lua_newtable(L); int t = lua_gettop(gLuaState); diff --git a/src/pc/lua/smlua_cobject_autogen.c b/src/pc/lua/smlua_cobject_autogen.c index b1e07afd..9bf0d869 100644 --- a/src/pc/lua/smlua_cobject_autogen.c +++ b/src/pc/lua/smlua_cobject_autogen.c @@ -6,6 +6,7 @@ #include "src/game/camera.h" #include "src/game/characters.h" #include "src/engine/surface_collision.h" +#include "src/pc/network/network_player.h" #define LUA_ANIMATION_FIELD_COUNT 7 static struct LuaObjectField sAnimationFields[LUA_ANIMATION_FIELD_COUNT] = { @@ -433,6 +434,30 @@ static struct LuaObjectField sModeTransitionInfoFields[LUA_MODE_TRANSITION_INFO_ { "transitionStart", LVT_COBJECT, offsetof(struct ModeTransitionInfo, transitionStart), true, LOT_LINEARTRANSITIONPOINT }, }; +#define LUA_NETWORK_PLAYER_FIELD_COUNT 17 +static struct LuaObjectField sNetworkPlayerFields[LUA_NETWORK_PLAYER_FIELD_COUNT] = { + { "connected", LVT_U8, offsetof(struct NetworkPlayer, connected), true, LOT_NONE }, + { "currActNum", LVT_S16, offsetof(struct NetworkPlayer, currActNum), true, LOT_NONE }, + { "currAreaIndex", LVT_S16, offsetof(struct NetworkPlayer, currAreaIndex), true, LOT_NONE }, + { "currAreaSyncValid", LVT_U8, offsetof(struct NetworkPlayer, currAreaSyncValid), true, LOT_NONE }, + { "currCourseNum", LVT_S16, offsetof(struct NetworkPlayer, currCourseNum), true, LOT_NONE }, + { "currLevelAreaSeqId", LVT_U16, offsetof(struct NetworkPlayer, currLevelAreaSeqId), true, LOT_NONE }, + { "currLevelNum", LVT_S16, offsetof(struct NetworkPlayer, currLevelNum), true, LOT_NONE }, + { "currLevelSyncValid", LVT_U8, offsetof(struct NetworkPlayer, currLevelSyncValid), true, LOT_NONE }, + { "fadeOpacity", LVT_U8, offsetof(struct NetworkPlayer, fadeOpacity), true, LOT_NONE }, + { "globalIndex", LVT_U8, offsetof(struct NetworkPlayer, globalIndex), true, LOT_NONE }, + { "lastReceived", LVT_F32, offsetof(struct NetworkPlayer, lastReceived), true, LOT_NONE }, + { "lastSent", LVT_F32, offsetof(struct NetworkPlayer, lastSent), true, LOT_NONE }, + { "localIndex", LVT_U8, offsetof(struct NetworkPlayer, localIndex), true, LOT_NONE }, + { "modelIndex", LVT_U8, offsetof(struct NetworkPlayer, modelIndex), true, LOT_NONE }, +// { "name", LOT_???, offsetof(struct NetworkPlayer, name), true, LOT_??? }, <--- UNIMPLEMENTED + { "onRxSeqId", LVT_U8, offsetof(struct NetworkPlayer, onRxSeqId), true, LOT_NONE }, + { "paletteIndex", LVT_U8, offsetof(struct NetworkPlayer, paletteIndex), true, LOT_NONE }, +// { "rxPacketHash", LOT_???, offsetof(struct NetworkPlayer, rxPacketHash), true, LOT_??? }, <--- UNIMPLEMENTED +// { "rxSeqIds", LOT_???, offsetof(struct NetworkPlayer, rxSeqIds), true, LOT_??? }, <--- UNIMPLEMENTED + { "type", LVT_U8, offsetof(struct NetworkPlayer, type), true, LOT_NONE }, +}; + #define LUA_OBJECT_FIELD_COUNT 22 static struct LuaObjectField sObjectFields[LUA_OBJECT_FIELD_COUNT] = { { "activeFlags", LVT_S16, offsetof(struct Object, activeFlags), false, LOT_NONE }, @@ -660,6 +685,7 @@ struct LuaObjectTable sLuaObjectAutogenTable[LOT_AUTOGEN_MAX - LOT_AUTOGEN_MIN] { LOT_MARIOBODYSTATE, sMarioBodyStateFields, LUA_MARIO_BODY_STATE_FIELD_COUNT }, { LOT_MARIOSTATE, sMarioStateFields, LUA_MARIO_STATE_FIELD_COUNT }, { LOT_MODETRANSITIONINFO, sModeTransitionInfoFields, LUA_MODE_TRANSITION_INFO_FIELD_COUNT }, + { LOT_NETWORKPLAYER, sNetworkPlayerFields, LUA_NETWORK_PLAYER_FIELD_COUNT }, { LOT_OBJECT, sObjectFields, LUA_OBJECT_FIELD_COUNT }, { LOT_OBJECTHITBOX, sObjectHitboxFields, LUA_OBJECT_HITBOX_FIELD_COUNT }, { LOT_OBJECTNODE, sObjectNodeFields, LUA_OBJECT_NODE_FIELD_COUNT }, diff --git a/src/pc/lua/smlua_cobject_autogen.h b/src/pc/lua/smlua_cobject_autogen.h index c4edc276..77334467 100644 --- a/src/pc/lua/smlua_cobject_autogen.h +++ b/src/pc/lua/smlua_cobject_autogen.h @@ -28,6 +28,7 @@ enum LuaObjectAutogenType { LOT_MARIOBODYSTATE, LOT_MARIOSTATE, LOT_MODETRANSITIONINFO, + LOT_NETWORKPLAYER, LOT_OBJECT, LOT_OBJECTHITBOX, LOT_OBJECTNODE, diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index 18558c40..3d3731f3 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -115,6 +115,13 @@ char gSmluaConstants[] = "HOOK_UPDATE = 0\n" "CT_TOAD = 2\n" "CT_WALUIGI = 3\n" "CT_MAX = 4\n" +"NPT_UNKNOWN = 0\n" +"NPT_LOCAL = 1\n" +"NPT_SERVER = 2\n" +"NPT_CLIENT = 3\n" +"UNKNOWN_LOCAL_INDEX = -1\n" +"UNKNOWN_GLOBAL_INDEX = -1\n" +"UNKNOWN_NETWORK_INDEX = -1\n" "LAYER_FORCE = 0\n" "LAYER_OPAQUE = 1\n" "LAYER_OPAQUE_DECAL = 2\n"