From 7c01e405e0d7880d766e54ec7c0324b1ca13f4eb Mon Sep 17 00:00:00 2001
From: Agent X <44549182+AgentXLP@users.noreply.github.com>
Date: Sun, 9 Jun 2024 09:31:48 -0400
Subject: [PATCH] Allow mods to do -- ignore-script-warnings: true
---
autogen/lua_definitions/structs.lua | 4 +++
docs/lua/structs.md | 12 ++++++++
src/pc/lua/smlua.c | 1 +
src/pc/lua/smlua_cobject_autogen.c | 38 ++++++++++++++----------
src/pc/lua/smlua_cobject_autogen.h | 1 +
src/pc/mods/mod.c | 2 ++
src/pc/mods/mod.h | 1 +
src/pc/network/packets/packet_mod_list.c | 2 ++
8 files changed, 46 insertions(+), 15 deletions(-)
diff --git a/autogen/lua_definitions/structs.lua b/autogen/lua_definitions/structs.lua
index 39299403..2f58718f 100644
--- a/autogen/lua_definitions/structs.lua
+++ b/autogen/lua_definitions/structs.lua
@@ -234,6 +234,9 @@
--- @field public shakeSpeed integer
--- @field public unusedIsSleeping integer
+--- @class CameraOverride
+--- @field public override boolean
+
--- @class CameraStoredInfo
--- @field public cannonYOffset number
--- @field public focus Vec3f
@@ -1052,6 +1055,7 @@
--- @field public description string
--- @field public enabled boolean
--- @field public fileCount integer
+--- @field public ignoreScriptWarnings boolean
--- @field public incompatible string
--- @field public index integer
--- @field public isDirectory boolean
diff --git a/docs/lua/structs.md b/docs/lua/structs.md
index 39c29bd7..b7590cfd 100644
--- a/docs/lua/structs.md
+++ b/docs/lua/structs.md
@@ -11,6 +11,7 @@
- [BullyCollisionData](#BullyCollisionData)
- [Camera](#Camera)
- [CameraFOVStatus](#CameraFOVStatus)
+- [CameraOverride](#CameraOverride)
- [CameraStoredInfo](#CameraStoredInfo)
- [CameraTrigger](#CameraTrigger)
- [ChainSegment](#ChainSegment)
@@ -391,6 +392,16 @@
+## [CameraOverride](#CameraOverride)
+
+| Field | Type | Access |
+| ----- | ---- | ------ |
+| override | `boolean` | |
+
+[:arrow_up_small:](#)
+
+
+
## [CameraStoredInfo](#CameraStoredInfo)
| Field | Type | Access |
@@ -1420,6 +1431,7 @@
| description | `string` | read-only |
| enabled | `boolean` | read-only |
| fileCount | `integer` | read-only |
+| ignoreScriptWarnings | `boolean` | read-only |
| incompatible | `string` | read-only |
| index | `integer` | read-only |
| isDirectory | `boolean` | read-only |
diff --git a/src/pc/lua/smlua.c b/src/pc/lua/smlua.c
index 6c0a0b3d..edcfbd51 100644
--- a/src/pc/lua/smlua.c
+++ b/src/pc/lua/smlua.c
@@ -31,6 +31,7 @@ void smlua_mod_warning(void) {
struct Mod* mod = gLuaActiveMod;
if (mod == NULL) { mod = gLuaLastHookMod; }
if (mod == NULL) { return; }
+ if (mod->ignoreScriptWarnings) { return; }
char txt[255] = { 0 };
snprintf(txt, 254, "'%s\\#ffe600\\' is using deprecated functions!", mod->name);
static const struct DjuiColor color = { 255, 230, 0, 255 };
diff --git a/src/pc/lua/smlua_cobject_autogen.c b/src/pc/lua/smlua_cobject_autogen.c
index ad533bd1..f89c1526 100644
--- a/src/pc/lua/smlua_cobject_autogen.c
+++ b/src/pc/lua/smlua_cobject_autogen.c
@@ -287,6 +287,12 @@ static struct LuaObjectField sCameraFOVStatusFields[LUA_CAMERA_FOVSTATUS_FIELD_C
{ "unusedIsSleeping", LVT_U32, offsetof(struct CameraFOVStatus, unusedIsSleeping), false, LOT_NONE },
};
+#define LUA_CAMERA_OVERRIDE_FIELD_COUNT 1
+static struct LuaObjectField sCameraOverrideFields[LUA_CAMERA_OVERRIDE_FIELD_COUNT] = {
+ { "override", LVT_BOOL, offsetof(struct CameraOverride, override), false, LOT_NONE },
+// { "value", LVT_???, offsetof(struct CameraOverride, value), false, LOT_??? }, <--- UNIMPLEMENTED
+};
+
#define LUA_CAMERA_STORED_INFO_FIELD_COUNT 4
static struct LuaObjectField sCameraStoredInfoFields[LUA_CAMERA_STORED_INFO_FIELD_COUNT] = {
{ "cannonYOffset", LVT_F32, offsetof(struct CameraStoredInfo, cannonYOffset), false, LOT_NONE },
@@ -1172,22 +1178,23 @@ static struct LuaObjectField sMarioStateFields[LUA_MARIO_STATE_FIELD_COUNT] = {
{ "waterLevel", LVT_S16, offsetof(struct MarioState, waterLevel), false, LOT_NONE },
};
-#define LUA_MOD_FIELD_COUNT 13
+#define LUA_MOD_FIELD_COUNT 14
static struct LuaObjectField sModFields[LUA_MOD_FIELD_COUNT] = {
- { "basePath", LVT_STRING, offsetof(struct Mod, basePath), true, LOT_NONE },
- { "customBehaviorIndex", LVT_U8, offsetof(struct Mod, customBehaviorIndex), true, LOT_NONE },
- { "description", LVT_STRING_P, offsetof(struct Mod, description), true, LOT_NONE },
- { "enabled", LVT_BOOL, offsetof(struct Mod, enabled), true, LOT_NONE },
- { "fileCount", LVT_U16, offsetof(struct Mod, fileCount), true, LOT_NONE },
- { "incompatible", LVT_STRING_P, offsetof(struct Mod, incompatible), true, LOT_NONE },
- { "index", LVT_S32, offsetof(struct Mod, index), true, LOT_NONE },
- { "isDirectory", LVT_BOOL, offsetof(struct Mod, isDirectory), true, LOT_NONE },
- { "name", LVT_STRING_P, offsetof(struct Mod, name), true, LOT_NONE },
- { "pausable", LVT_BOOL, offsetof(struct Mod, pausable), true, LOT_NONE },
- { "relativePath", LVT_STRING, offsetof(struct Mod, relativePath), true, LOT_NONE },
- { "renderBehindHud", LVT_BOOL, offsetof(struct Mod, renderBehindHud), true, LOT_NONE },
- { "selectable", LVT_BOOL, offsetof(struct Mod, selectable), true, LOT_NONE },
-// { "size", LVT_???, offsetof(struct Mod, size), true, LOT_??? }, <--- UNIMPLEMENTED
+ { "basePath", LVT_STRING, offsetof(struct Mod, basePath), true, LOT_NONE },
+ { "customBehaviorIndex", LVT_U8, offsetof(struct Mod, customBehaviorIndex), true, LOT_NONE },
+ { "description", LVT_STRING_P, offsetof(struct Mod, description), true, LOT_NONE },
+ { "enabled", LVT_BOOL, offsetof(struct Mod, enabled), true, LOT_NONE },
+ { "fileCount", LVT_U16, offsetof(struct Mod, fileCount), true, LOT_NONE },
+ { "ignoreScriptWarnings", LVT_BOOL, offsetof(struct Mod, ignoreScriptWarnings), true, LOT_NONE },
+ { "incompatible", LVT_STRING_P, offsetof(struct Mod, incompatible), true, LOT_NONE },
+ { "index", LVT_S32, offsetof(struct Mod, index), true, LOT_NONE },
+ { "isDirectory", LVT_BOOL, offsetof(struct Mod, isDirectory), true, LOT_NONE },
+ { "name", LVT_STRING_P, offsetof(struct Mod, name), true, LOT_NONE },
+ { "pausable", LVT_BOOL, offsetof(struct Mod, pausable), true, LOT_NONE },
+ { "relativePath", LVT_STRING, offsetof(struct Mod, relativePath), true, LOT_NONE },
+ { "renderBehindHud", LVT_BOOL, offsetof(struct Mod, renderBehindHud), true, LOT_NONE },
+ { "selectable", LVT_BOOL, offsetof(struct Mod, selectable), true, LOT_NONE },
+// { "size", LVT_???, offsetof(struct Mod, size), true, LOT_??? }, <--- UNIMPLEMENTED
};
#define LUA_MOD_AUDIO_FIELD_COUNT 3
@@ -2429,6 +2436,7 @@ struct LuaObjectTable sLuaObjectAutogenTable[LOT_AUTOGEN_MAX - LOT_AUTOGEN_MIN]
{ LOT_BULLYCOLLISIONDATA, sBullyCollisionDataFields, LUA_BULLY_COLLISION_DATA_FIELD_COUNT },
{ LOT_CAMERA, sCameraFields, LUA_CAMERA_FIELD_COUNT },
{ LOT_CAMERAFOVSTATUS, sCameraFOVStatusFields, LUA_CAMERA_FOVSTATUS_FIELD_COUNT },
+ { LOT_CAMERAOVERRIDE, sCameraOverrideFields, LUA_CAMERA_OVERRIDE_FIELD_COUNT },
{ LOT_CAMERASTOREDINFO, sCameraStoredInfoFields, LUA_CAMERA_STORED_INFO_FIELD_COUNT },
{ LOT_CAMERATRIGGER, sCameraTriggerFields, LUA_CAMERA_TRIGGER_FIELD_COUNT },
{ LOT_CHAINSEGMENT, sChainSegmentFields, LUA_CHAIN_SEGMENT_FIELD_COUNT },
diff --git a/src/pc/lua/smlua_cobject_autogen.h b/src/pc/lua/smlua_cobject_autogen.h
index 794a4ea1..0ca897f1 100644
--- a/src/pc/lua/smlua_cobject_autogen.h
+++ b/src/pc/lua/smlua_cobject_autogen.h
@@ -15,6 +15,7 @@ enum LuaObjectAutogenType {
LOT_BULLYCOLLISIONDATA,
LOT_CAMERA,
LOT_CAMERAFOVSTATUS,
+ LOT_CAMERAOVERRIDE,
LOT_CAMERASTOREDINFO,
LOT_CAMERATRIGGER,
LOT_CHAINSEGMENT,
diff --git a/src/pc/mods/mod.c b/src/pc/mods/mod.c
index 526b5949..6056e580 100644
--- a/src/pc/mods/mod.c
+++ b/src/pc/mods/mod.c
@@ -434,6 +434,8 @@ static void mod_extract_fields(struct Mod* mod) {
}
} else if (!mod->pausable && (extracted = extract_lua_field("-- pausable:", buffer))) {
mod->pausable = !strcmp(extracted, "true");
+ } else if (!mod->ignoreScriptWarnings && (extracted = extract_lua_field("-- ignore-script-warnings:", buffer))) {
+ mod->ignoreScriptWarnings = !strcmp(extracted, "true");
}
}
diff --git a/src/pc/mods/mod.h b/src/pc/mods/mod.h
index b4e1a1a7..fcc2108a 100644
--- a/src/pc/mods/mod.h
+++ b/src/pc/mods/mod.h
@@ -35,6 +35,7 @@ struct Mod {
bool selectable;
bool renderBehindHud;
bool pausable;
+ bool ignoreScriptWarnings;
size_t size;
u8 customBehaviorIndex;
};
diff --git a/src/pc/network/packets/packet_mod_list.c b/src/pc/network/packets/packet_mod_list.c
index b3e1bca5..188a7182 100644
--- a/src/pc/network/packets/packet_mod_list.c
+++ b/src/pc/network/packets/packet_mod_list.c
@@ -85,6 +85,7 @@ void network_send_mod_list(void) {
packet_write(&p, &modSize, sizeof(u64));
packet_write(&p, &mod->isDirectory, sizeof(u8));
packet_write(&p, &mod->pausable, sizeof(u8));
+ packet_write(&p, &mod->ignoreScriptWarnings, sizeof(u8));
packet_write(&p, &mod->fileCount, sizeof(u16));
network_send_to(0, &p);
LOG_INFO(" '%s': %llu", mod->name, (u64)mod->size);
@@ -224,6 +225,7 @@ void network_receive_mod_list_entry(struct Packet* p) {
packet_read(p, &mod->size, sizeof(u64));
packet_read(p, &mod->isDirectory, sizeof(u8));
packet_read(p, &mod->pausable, sizeof(u8));
+ packet_read(p, &mod->ignoreScriptWarnings, sizeof(u8));
normalize_path(mod->relativePath);
LOG_INFO(" '%s': %llu", mod->name, (u64)mod->size);