Added ability for Lua mods to adjust gServerSettings

This commit is contained in:
MysterD 2022-03-26 01:08:15 -07:00
parent 4a9e618efe
commit de048928ce
11 changed files with 148 additions and 8 deletions

View File

@ -16,6 +16,7 @@ in_files = [
"include/mario_animation_ids.h",
"include/sounds.h",
"src/game/characters.h",
"src/pc/network/network.h",
"src/pc/network/network_player.h",
"include/PR/os_cont.h",
"src/game/interaction.c",

View File

@ -19,6 +19,7 @@ in_files = [
'src/pc/lua/utils/smlua_misc_utils.h',
'src/pc/lua/utils/smlua_collision_utils.h',
'src/game/spawn_sound.h',
'src/pc/network/network.h',
]
out_filename_c = 'src/pc/lua/smlua_cobject_autogen.c'
@ -80,10 +81,17 @@ override_field_immutable = {
"Area": [ "localAreaTimer" ],
}
sLuaManuallyDefinedStructs = [
'struct Vec3f { float x; float y; float z; }',
'struct Vec3s { s16 x; s16 y; s16 z; }'
]
override_allowed_structs = {
"src/pc/network/network.h": [ 'ServerSettings' ]
}
sLuaManuallyDefinedStructs = [{
'path': 'n/a',
'structs': [
'struct Vec3f { float x; float y; float z; }',
'struct Vec3s { s16 x; s16 y; s16 z; }'
]
}]
total_structs = 0
total_fields = 0
@ -188,10 +196,15 @@ def parse_struct(struct_str):
return struct
def parse_structs(struct_strs):
def parse_structs(extracted):
structs = []
for struct_str in struct_strs:
structs.append(parse_struct(struct_str))
for e in extracted:
for struct in e['structs']:
parsed = parse_struct(struct)
if e['path'] in override_allowed_structs:
if parsed['identifier'] not in override_allowed_structs[e['path']]:
continue
structs.append(parsed)
return structs
############################################################################
@ -445,7 +458,10 @@ def build_files():
extracted = []
for in_file in in_files:
path = get_path(in_file)
extracted.extend(extract_structs(path))
extracted.append({
'path': in_file,
'structs': extract_structs(path)
})
parsed = parse_structs(extracted)
parsed = sorted(parsed, key=lambda d: d['identifier'])

View File

@ -3727,6 +3727,37 @@ MARIO_HAND_HOLDING_WING_CAP = 4
--- @type MarioHandGSCId
MARIO_HAND_RIGHT_OPEN = 5
--- @type integer
MAX_SYNC_OBJECTS = 256
--- @type integer
MAX_SYNC_OBJECT_FIELDS = 64
--- @type integer
PACKET_LENGTH = 2048
--- @type integer
SYNC_DISTANCE_INFINITE = 0
--- @class NetworkSystemType
--- @type NetworkSystemType
NS_SOCKET = 0
--- @type NetworkSystemType
NS_DISCORD = 1
--- @class PlayerInteractions
--- @type PlayerInteractions
PLAYER_INTERACTIONS_NONE = 0
--- @type PlayerInteractions
PLAYER_INTERACTIONS_SOLID = 1
--- @type PlayerInteractions
PLAYER_INTERACTIONS_PVP = 2
--- @type integer
MAX_RX_SEQ_IDS = 16

View File

@ -1386,6 +1386,16 @@
--- @field public hitPos Vec3f
--- @field public surface Surface
--- @class ServerSettings
--- @field public bubbleDeath integer
--- @field public enableCheats integer
--- @field public headlessServer integer
--- @field public playerInteractions PlayerInteractions
--- @field public playerKnockbackStrength integer
--- @field public shareLives integer
--- @field public skipIntro integer
--- @field public stayInLevelAfterStar integer
--- @class SoundState
--- @field public animFrame1 integer
--- @field public animFrame2 integer

View File

@ -24,6 +24,9 @@
- [enum MarioEyesGSCId](#enum-MarioEyesGSCId)
- [enum MarioGrabPosGSCId](#enum-MarioGrabPosGSCId)
- [enum MarioHandGSCId](#enum-MarioHandGSCId)
- [network.h](#networkh)
- [enum NetworkSystemType](#enum-NetworkSystemType)
- [enum PlayerInteractions](#enum-PlayerInteractions)
- [network_player.h](#network_playerh)
- [enum NetworkPlayerType](#enum-NetworkPlayerType)
- [obj_behaviors.c](#obj_behaviorsc)
@ -1300,6 +1303,29 @@
<br />
## [network.h](#network.h)
- MAX_SYNC_OBJECTS
- MAX_SYNC_OBJECT_FIELDS
- PACKET_LENGTH
- SYNC_DISTANCE_INFINITE
### [enum NetworkSystemType](#NetworkSystemType)
| Identifier | Value |
| :--------- | :---- |
| NS_SOCKET | 0 |
| NS_DISCORD | 1 |
### [enum PlayerInteractions](#PlayerInteractions)
| Identifier | Value |
| :--------- | :---- |
| PLAYER_INTERACTIONS_NONE | 0 |
| PLAYER_INTERACTIONS_SOLID | 1 |
| PLAYER_INTERACTIONS_PVP | 2 |
[:arrow_up_small:](#)
<br />
## [network_player.h](#network_player.h)
- MAX_RX_SEQ_IDS
- NETWORK_PLAYER_TIMEOUT

View File

@ -58,6 +58,15 @@ The `gGlobalObjectCollisionData` table contains references to object collision d
<br />
## [gServerSettings](#gServerSettings)
`gServerSettings`'s fields are listed in [ServerSettings](structs.md#ServerSettings).
__**NOTE**__: You should only change the fields in this struct on init, and it shouldn't be done inside of if statements or functions. Failing to follow this advice can result in desyncs.
[:arrow_up_small:](#)
<br />
## [gGlobalSyncTable](#gGlobalSyncTable)
The `gGlobalSyncTable` is a table used for networking. Any field set inside of this table is automatically synchronized with all other clients. Do not use this table for player-specific variables, keep those in [gPlayerSyncTable](#gPlayerSyncTable). Player-specific variable will desynchronize within this table since it doesn't automatically translate `playerIndex`.

View File

@ -42,6 +42,7 @@
- [PlayerGeometry](#PlayerGeometry)
- [RayIntersectionInfo](#RayIntersectionInfo)
- [SPTask](#SPTask)
- [ServerSettings](#ServerSettings)
- [SoundState](#SoundState)
- [SpawnInfo](#SpawnInfo)
- [SpawnParticlesInfo](#SpawnParticlesInfo)
@ -1731,6 +1732,23 @@
<br />
## [ServerSettings](#ServerSettings)
| Field | Type | Access |
| ----- | ---- | ------ |
| bubbleDeath | `integer` | |
| enableCheats | `integer` | |
| headlessServer | `integer` | |
| playerInteractions | [enum PlayerInteractions](constants.md#enum-PlayerInteractions) | |
| playerKnockbackStrength | `integer` | |
| shareLives | `integer` | |
| skipIntro | `integer` | |
| stayInLevelAfterStar | `integer` | |
[:arrow_up_small:](#)
<br />
## [SoundState](#SoundState)
| Field | Type | Access |

View File

@ -490,6 +490,11 @@ void smlua_cobject_init_globals(void) {
lua_setglobal(L, "gLakituState");
}
{
smlua_push_object(L, LOT_SERVERSETTINGS, &gServerSettings);
lua_setglobal(L, "gServerSettings");
}
}
void smlua_cobject_init_per_file_globals(char* path) {

View File

@ -14,6 +14,7 @@
#include "src/pc/lua/utils/smlua_misc_utils.h"
#include "src/pc/lua/utils/smlua_collision_utils.h"
#include "src/game/spawn_sound.h"
#include "src/pc/network/network.h"
#include "include/object_fields.h"
@ -1522,6 +1523,18 @@ static struct LuaObjectField sRayIntersectionInfoFields[LUA_RAY_INTERSECTION_INF
{ "surface", LVT_COBJECT_P, offsetof(struct RayIntersectionInfo, surface), false, LOT_SURFACE },
};
#define LUA_SERVER_SETTINGS_FIELD_COUNT 8
static struct LuaObjectField sServerSettingsFields[LUA_SERVER_SETTINGS_FIELD_COUNT] = {
{ "bubbleDeath", LVT_U8, offsetof(struct ServerSettings, bubbleDeath), false, LOT_NONE },
{ "enableCheats", LVT_U8, offsetof(struct ServerSettings, enableCheats), false, LOT_NONE },
{ "headlessServer", LVT_U8, offsetof(struct ServerSettings, headlessServer), false, LOT_NONE },
{ "playerInteractions", LVT_S32, offsetof(struct ServerSettings, playerInteractions), false, LOT_NONE },
{ "playerKnockbackStrength", LVT_U8, offsetof(struct ServerSettings, playerKnockbackStrength), false, LOT_NONE },
{ "shareLives", LVT_U8, offsetof(struct ServerSettings, shareLives), false, LOT_NONE },
{ "skipIntro", LVT_U8, offsetof(struct ServerSettings, skipIntro), false, LOT_NONE },
{ "stayInLevelAfterStar", LVT_U8, offsetof(struct ServerSettings, stayInLevelAfterStar), false, LOT_NONE },
};
#define LUA_SOUND_STATE_FIELD_COUNT 4
static struct LuaObjectField sSoundStateFields[LUA_SOUND_STATE_FIELD_COUNT] = {
{ "animFrame1", LVT_S8, offsetof(struct SoundState, animFrame1), false, LOT_NONE },
@ -1719,6 +1732,7 @@ struct LuaObjectTable sLuaObjectAutogenTable[LOT_AUTOGEN_MAX - LOT_AUTOGEN_MIN]
{ LOT_PLAYERCAMERASTATE, sPlayerCameraStateFields, LUA_PLAYER_CAMERA_STATE_FIELD_COUNT },
{ LOT_PLAYERGEOMETRY, sPlayerGeometryFields, LUA_PLAYER_GEOMETRY_FIELD_COUNT },
{ LOT_RAYINTERSECTIONINFO, sRayIntersectionInfoFields, LUA_RAY_INTERSECTION_INFO_FIELD_COUNT },
{ LOT_SERVERSETTINGS, sServerSettingsFields, LUA_SERVER_SETTINGS_FIELD_COUNT },
{ LOT_SOUNDSTATE, sSoundStateFields, LUA_SOUND_STATE_FIELD_COUNT },
{ LOT_SPAWNINFO, sSpawnInfoFields, LUA_SPAWN_INFO_FIELD_COUNT },
{ LOT_SPAWNPARTICLESINFO, sSpawnParticlesInfoFields, LUA_SPAWN_PARTICLES_INFO_FIELD_COUNT },

View File

@ -44,6 +44,7 @@ enum LuaObjectAutogenType {
LOT_PLAYERCAMERASTATE,
LOT_PLAYERGEOMETRY,
LOT_RAYINTERSECTIONINFO,
LOT_SERVERSETTINGS,
LOT_SOUNDSTATE,
LOT_SPAWNINFO,
LOT_SPAWNPARTICLESINFO,

View File

@ -1387,6 +1387,15 @@ char gSmluaConstants[] = ""
"GRAB_POS_LIGHT_OBJ = 1\n"
"GRAB_POS_HEAVY_OBJ = 2\n"
"GRAB_POS_BOWSER = 3\n"
"SYNC_DISTANCE_INFINITE = 0\n"
"MAX_SYNC_OBJECTS = 256\n"
"MAX_SYNC_OBJECT_FIELDS = 64\n"
"PACKET_LENGTH = 2048\n"
"NS_SOCKET = 0\n"
"NS_DISCORD = 1\n"
"PLAYER_INTERACTIONS_NONE = 0\n"
"PLAYER_INTERACTIONS_SOLID = 1\n"
"PLAYER_INTERACTIONS_PVP = 2\n"
"UNKNOWN_LOCAL_INDEX = (-1)\n"
"UNKNOWN_GLOBAL_INDEX = (-1)\n"
"UNKNOWN_NETWORK_INDEX = (-1)\n"