From b79fc690ecc149e209ae4677ae618082cfa941fb Mon Sep 17 00:00:00 2001 From: aarjl Date: Sun, 21 Dec 2025 17:46:55 -0500 Subject: [PATCH 1/6] Matched 10 small functions --- src/SB/Game/zTalkBox.cpp | 55 ++++++++++++++++++++++++++++++++++++++++ src/SB/Game/zTalkBox.h | 19 ++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/src/SB/Game/zTalkBox.cpp b/src/SB/Game/zTalkBox.cpp index 0bca75d7..1dac5dff 100644 --- a/src/SB/Game/zTalkBox.cpp +++ b/src/SB/Game/zTalkBox.cpp @@ -365,3 +365,58 @@ void ztalkbox::permit(U32 add_flags, U32 remove_flags) shared.permit &= ~remove_flags; shared.permit |= add_flags; } + +namespace +{ + + static void parse_tag_pause(xtextbox::jot&, const xtextbox&, const xtextbox&, const xtextbox::split_tag&) + { + + } + + static void reset_tag_pause(xtextbox::jot&, const xtextbox&, const xtextbox&, const xtextbox::split_tag&) + { + + } + + static unsigned char trigger_pause(const xtextbox::jot&) + { + return 1; + } +} + +void start_state_type::stop() +{ +} + +signed char start_state_type::update(xScene&, float) +{ + return 2; +} + +void next_state_type::stop() +{ + +} + +void stop_state_type::start() +{ + +} + +void stop_state_type::stop() +{ + +} + +signed char stop_state_type::update(xScene&, float) +{ + return -1; +} + +void wait_context::reset_type() +{ + + *(U16*)&this->type = 0; + +} diff --git a/src/SB/Game/zTalkBox.h b/src/SB/Game/zTalkBox.h index 8c7c3172..a94a7feb 100644 --- a/src/SB/Game/zTalkBox.h +++ b/src/SB/Game/zTalkBox.h @@ -155,6 +155,24 @@ namespace void stop(); }; + struct next_state_type + { + void stop(); + }; + + struct start_state_type + { + void stop(); + signed char update(xScene&, float); + }; + + struct stop_state_type + { + void start(); + void stop(); + signed char update(xScene&, float); + }; + struct jot; struct callback { @@ -252,6 +270,7 @@ namespace F32 delay; U32 event_mask; query_enum query; + void reset_type(); }; struct trigger_pair From 1c483854b405e00969a300d6f54291cb9bf7aa9a Mon Sep 17 00:00:00 2001 From: aarjl Date: Sun, 21 Dec 2025 20:04:20 -0500 Subject: [PATCH 2/6] ztalkbox load and state_type update --- src/SB/Game/zTalkBox.cpp | 11 +++++++++++ src/SB/Game/zTalkBox.h | 7 ++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/SB/Game/zTalkBox.cpp b/src/SB/Game/zTalkBox.cpp index 1dac5dff..b65adb50 100644 --- a/src/SB/Game/zTalkBox.cpp +++ b/src/SB/Game/zTalkBox.cpp @@ -366,6 +366,11 @@ void ztalkbox::permit(U32 add_flags, U32 remove_flags) shared.permit |= add_flags; } +void ztalkbox::load(xBase& data, xDynAsset& asset, unsigned long) +{ + ((ztalkbox&)data).load((const ztalkbox::asset_type&)asset); +} + namespace { @@ -383,6 +388,12 @@ namespace { return 1; } + + state_type::state_type(state_enum t) + { + type = t; + } + } void start_state_type::stop() diff --git a/src/SB/Game/zTalkBox.h b/src/SB/Game/zTalkBox.h index a94a7feb..9d0b8e04 100644 --- a/src/SB/Game/zTalkBox.h +++ b/src/SB/Game/zTalkBox.h @@ -150,9 +150,10 @@ namespace struct state_type { state_enum type; - - void start(); - void stop(); + + state_type(state_enum t); + virtual void start(); + virtual void stop(); }; struct next_state_type From 9ef4f04493dba6af7a215db25eafeb2d4404c97e Mon Sep 17 00:00:00 2001 From: aarjl Date: Sun, 21 Dec 2025 21:43:14 -0500 Subject: [PATCH 3/6] Made suggested changes for primative types and updated variables. also used code formmatting tool --- src/SB/Game/zTalkBox.cpp | 22 ++++++++-------------- src/SB/Game/zTalkBox.h | 11 +++-------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/SB/Game/zTalkBox.cpp b/src/SB/Game/zTalkBox.cpp index b65adb50..9e54f6fa 100644 --- a/src/SB/Game/zTalkBox.cpp +++ b/src/SB/Game/zTalkBox.cpp @@ -373,18 +373,17 @@ void ztalkbox::load(xBase& data, xDynAsset& asset, unsigned long) namespace { - - static void parse_tag_pause(xtextbox::jot&, const xtextbox&, const xtextbox&, const xtextbox::split_tag&) + static void parse_tag_pause(xtextbox::jot&, const xtextbox&, const xtextbox&, + const xtextbox::split_tag&) { - } - static void reset_tag_pause(xtextbox::jot&, const xtextbox&, const xtextbox&, const xtextbox::split_tag&) + static void reset_tag_pause(xtextbox::jot&, const xtextbox&, const xtextbox&, + const xtextbox::split_tag&) { - } - static unsigned char trigger_pause(const xtextbox::jot&) + U8 trigger_pause(const xtextbox::jot&) { return 1; } @@ -394,40 +393,35 @@ namespace type = t; } -} +} // namespace void start_state_type::stop() { } -signed char start_state_type::update(xScene&, float) +S8 start_state_type::update(xScene& scn, F32 dt) { return 2; } void next_state_type::stop() { - } void stop_state_type::start() { - } void stop_state_type::stop() { - } -signed char stop_state_type::update(xScene&, float) +S8 stop_state_type::update(xScene& scn, F32 dt) { return -1; } void wait_context::reset_type() { - *(U16*)&this->type = 0; - } diff --git a/src/SB/Game/zTalkBox.h b/src/SB/Game/zTalkBox.h index 9d0b8e04..879f4458 100644 --- a/src/SB/Game/zTalkBox.h +++ b/src/SB/Game/zTalkBox.h @@ -61,27 +61,22 @@ struct ztalkbox : xBase { callback() { - } virtual void on_signal(U32) { - } virtual void on_start() { - } virtual void on_stop() { - } virtual void on_answer(answer_enum answer) { - } }; @@ -164,14 +159,14 @@ namespace struct start_state_type { void stop(); - signed char update(xScene&, float); + S8 update(xScene& scn, F32 dt); }; struct stop_state_type { void start(); void stop(); - signed char update(xScene&, float); + S8 update(xScene& scn, F32 dt); }; struct jot; @@ -310,6 +305,6 @@ namespace zNPCCommon* speak_npc; // 0x8694 U32 speak_player; // 0x8698 }; -} +} // namespace #endif From da22f62e4199fa1ddd6c8e55ed36ce2414f20f80 Mon Sep 17 00:00:00 2001 From: aarjl Date: Sun, 4 Jan 2026 15:33:57 -0500 Subject: [PATCH 4/6] Update --- src/SB/Game/zTalkBox.cpp | 194 +++++++++++++++++++++++++++++++++++++-- src/SB/Game/zTalkBox.h | 58 ++++++++++-- 2 files changed, 235 insertions(+), 17 deletions(-) diff --git a/src/SB/Game/zTalkBox.cpp b/src/SB/Game/zTalkBox.cpp index 9e54f6fa..81fb3684 100644 --- a/src/SB/Game/zTalkBox.cpp +++ b/src/SB/Game/zTalkBox.cpp @@ -1,6 +1,7 @@ #include "xstransvc.h" #include "zTalkBox.h" - +#include "xDebug.h" +#include "zEntPlayer.h" #include namespace @@ -105,10 +106,6 @@ namespace { } - void reset_auto_wait() - { - } - void deactivate() { stop_audio_effect(); @@ -366,33 +363,203 @@ void ztalkbox::permit(U32 add_flags, U32 remove_flags) shared.permit |= add_flags; } -void ztalkbox::load(xBase& data, xDynAsset& asset, unsigned long) +void ztalkbox::load(xBase& data, xDynAsset& asset, size_t) { ((ztalkbox&)data).load((const ztalkbox::asset_type&)asset); } +void ztalkbox::load_settings(xIniFile& ini) //TODO +{ + shared.volume = xIniGetFloat(&ini, "talk_box.volume", 2.0f); + xDebugAddTweak("Talk Box|\u{1}Globals|volume", &shared.volume, 0.1f, 10.0f, NULL, NULL, 0); +} + namespace { + static U8 read_bool(const substr& s, bool def) //TODO 99% + { + extern const substr negative[6]; + extern const substr positive[6]; + if (def) + { + for (U32 i = 0; i < 6; ++i) + { + if (icompare(s, negative[i]) == 0) + return 0; + } + return 1; + } + else + for (U32 i = 0; i < 6; ++i) + { + if (icompare(s, positive[i]) == 0) + return 1; + } + return 0; + } static void parse_tag_pause(xtextbox::jot&, const xtextbox&, const xtextbox&, const xtextbox::split_tag&) { } + static void parse_tag_trap(xtextbox::jot& j, const xtextbox&, const xtextbox&, + const xtextbox::split_tag& ti) //TODO 99% + { + U8 c = 0; + + if (ti.action.size == 1 && ti.action.text[0] == '=') + { + if (read_bool(ti.value, 1) != 0) + { + c = 1; + } + } + + *(U8*)&j.context = c; + } + static void reset_tag_pause(xtextbox::jot&, const xtextbox&, const xtextbox&, - const xtextbox::split_tag&) + const xtextbox::split_tag&) //DONE { } + static void reset_tag_sound(xtextbox::jot& j, const xtextbox&, const xtextbox& tb, + const xtextbox::split_tag&) //DONE + { + if (!shared.active) + { + return; + } + + if (&shared.active->dialog_box->tb != &tb) + { + return; + } + + sound_context& c = *(sound_context*)j.context; + + j.context_size = 24; + + c.id = 0; + c.action = sound_context::ACTION_SET; + } + static void reset_tag_trap(xtextbox::jot& j, const xtextbox&, const xtextbox& ctb, + const xtextbox::split_tag&) //DONE + { + if (!shared.active) + { + return; + } + + if (&shared.active->dialog_box->tb != &ctb) + { + return; + } + + *(bool*)&j.context = (shared.active->asset->trap != 0); + } + + static void reset_tag_allow_quit(xtextbox::jot& j, const xtextbox&, const xtextbox& ctb, + const xtextbox::split_tag&) //DONE + { + if (!shared.active) + { + return; + } + + if (&shared.active->dialog_box->tb != &ctb) + { + return; + } + + *(bool*)&j.context = (shared.active->asset->allow_quit != 0); + } U8 trigger_pause(const xtextbox::jot&) { return 1; } + U8 trigger_allow_quit(const xtextbox::jot& j) //DONE + { + shared.allow_quit = (j.context != NULL); + + return 1; + } + U8 trigger_auto_wait(const xtextbox::jot& j) //DONE + { + shared.auto_wait = *(const wait_context*)j.context; + + return 1; + } state_type::state_type(state_enum t) { type = t; } + wait_context& wait_context::operator=(const wait_context& rhs) //FIXME + { + type = rhs.type; + need = rhs.need; + delay = rhs.delay; + event_mask = rhs.event_mask; + query = rhs.query; + return *this; + } + + void stop_audio_effect() //TODO + { + if (!shared.active) + { + return; + } + + if (shared.active->asset == 0) + { + return; + } + } + static void reset_auto_wait() //DONE + { + const ztalkbox::asset_type* a = shared.active->asset; + + shared.auto_wait.type.time = a->auto_wait.type.time; + shared.auto_wait.type.prompt = a->auto_wait.type.prompt; + shared.auto_wait.type.sound = a->auto_wait.type.sound; + shared.auto_wait.type.event = a->auto_wait.type.event; + + shared.auto_wait.delay = a->auto_wait.delay; + + shared.auto_wait.need = 0; + + if (a->auto_wait.which_event <= 0 || a->auto_wait.which_event >= 32) + { + shared.auto_wait.event_mask = -1; + } + else + { + shared.auto_wait.event_mask = 1u << a->auto_wait.which_event; + } + + shared.auto_wait.query = Q_SKIP; + } + static void reset_tag_auto_wait(xtextbox::jot& j, const xtextbox&, const xtextbox& ctb, + const xtextbox::split_tag&) //DONE + { + if (!shared.active) + { + return; + } + if (&shared.active->dialog_box->tb != &ctb) + { + return; + } + + wait_context& c = *(wait_context*)j.context; + j.context_size = sizeof(wait_context); + reset_auto_wait(); + c = shared.auto_wait; + } + } // namespace void start_state_type::stop() @@ -425,3 +592,16 @@ void wait_context::reset_type() { *(U16*)&this->type = 0; } + +static U8 trigger_trap(const xtextbox::jot& j) //DONE +{ + if (j.context != 0) + { + zEntPlayerControlOff(CONTROL_OWNER_TALK_BOX); + } + else + { + zEntPlayerControlOn(CONTROL_OWNER_TALK_BOX); + } + return 1; +} diff --git a/src/SB/Game/zTalkBox.h b/src/SB/Game/zTalkBox.h index 879f4458..0ce65c73 100644 --- a/src/SB/Game/zTalkBox.h +++ b/src/SB/Game/zTalkBox.h @@ -34,8 +34,8 @@ struct ztalkbox : xBase bool sound : 8; bool event : 8; } type; - F32 delay; - S32 which_event; + F32 delay; //Offset 8d3c + S32 which_event; //Offset 0x8d40 } auto_wait; struct { @@ -85,9 +85,9 @@ struct ztalkbox : xBase bool visible : 1; } flag; const asset_type* asset; - ztextbox* dialog_box; - ztextbox* prompt_box; - ztextbox* quit_box; + ztextbox* dialog_box; //Offset 0x18 + ztextbox* prompt_box; //Offset 0x1c + ztextbox* quit_box; //Offset 0x20 struct { const char* skip; @@ -145,7 +145,7 @@ namespace struct state_type { state_enum type; - + state_type(state_enum t); virtual void start(); virtual void stop(); @@ -262,11 +262,12 @@ namespace U8 event : 1; U16 pad : 12; } type; - U8 need; + U8 need; //Offset 08d3a F32 delay; - U32 event_mask; - query_enum query; + U32 event_mask; //Offset 08d40 + query_enum query; //Offset 08d44 void reset_type(); + wait_context& operator=(const wait_context& rhs); }; struct trigger_pair @@ -277,7 +278,7 @@ namespace struct shared_type { - S32 flags; + S32 flags; U32 permit; ztalkbox* active; // 0x8 state_type* state; // 0xC @@ -305,6 +306,43 @@ namespace zNPCCommon* speak_npc; // 0x8694 U32 speak_player; // 0x8698 }; + + struct sound_context + { + // total size: 0x18 + U32 id; // offset 0x0, size 0x4 + enum + { + ACTION_SET = 0, + ACTION_PUSH = 1, + ACTION_POP = 2, + } action : 8; // offset 0x4, size 0x4 + enum + { + TYPE_INVALID = 0, + TYPE_VOLUME = 1, + TYPE_TARGET = 2, + TYPE_ORIGIN = 3, + } type : 8; // offset 0x4, size 0x4 + enum + { + SOURCE_MEMORY = 0, + SOURCE_STREAM = 1, + } source : 8; // offset 0x4, size 0x4 + U8 anim; // offset 0x7, size 0x1 + union + { // inferred + struct + { + // total size: 0x8 + float left; // offset 0x0, size 0x4 + float right; // offset 0x4, size 0x4 + } volume; // offset 0x8, size 0x8 + unsigned int target; // offset 0x8, size 0x4 + class xVec3 origin; // offset 0x8, size 0xC + }; + U32 speaker; // offset 0x14, size 0x4 + }; } // namespace #endif From 9785b64ea93abe6c13c34259b18cc36d73c956f2 Mon Sep 17 00:00:00 2001 From: aarjl Date: Sun, 4 Jan 2026 22:52:57 -0500 Subject: [PATCH 5/6] Made suggested updates --- src/SB/Game/zTalkBox.cpp | 40 +++++++++++++++++++++------------------- src/SB/Game/zTalkBox.h | 18 +++++++++--------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/SB/Game/zTalkBox.cpp b/src/SB/Game/zTalkBox.cpp index 81fb3684..c3d3b7e8 100644 --- a/src/SB/Game/zTalkBox.cpp +++ b/src/SB/Game/zTalkBox.cpp @@ -363,23 +363,23 @@ void ztalkbox::permit(U32 add_flags, U32 remove_flags) shared.permit |= add_flags; } -void ztalkbox::load(xBase& data, xDynAsset& asset, size_t) +void ztalkbox::load(xBase& data, xDynAsset& asset, u32) { ((ztalkbox&)data).load((const ztalkbox::asset_type&)asset); } -void ztalkbox::load_settings(xIniFile& ini) //TODO +void ztalkbox::load_settings(xIniFile& ini) { shared.volume = xIniGetFloat(&ini, "talk_box.volume", 2.0f); - xDebugAddTweak("Talk Box|\u{1}Globals|volume", &shared.volume, 0.1f, 10.0f, NULL, NULL, 0); + xDebugAddTweak("Talk Box|\01GlobalsGlobals|volume", &shared.volume, 0.1f, 10.0f, NULL, NULL, 0); } namespace { - static U8 read_bool(const substr& s, bool def) //TODO 99% + static U8 read_bool(const substr& s, bool def) { - extern const substr negative[6]; - extern const substr positive[6]; + const substr negative[6] = {}; + const substr positive[6] = {}; if (def) { for (U32 i = 0; i < 6; ++i) @@ -390,11 +390,13 @@ namespace return 1; } else + { for (U32 i = 0; i < 6; ++i) { if (icompare(s, positive[i]) == 0) return 1; } + } return 0; } static void parse_tag_pause(xtextbox::jot&, const xtextbox&, const xtextbox&, @@ -403,9 +405,9 @@ namespace } static void parse_tag_trap(xtextbox::jot& j, const xtextbox&, const xtextbox&, - const xtextbox::split_tag& ti) //TODO 99% + const xtextbox::split_tag& ti) { - U8 c = 0; + bool c = 0; if (ti.action.size == 1 && ti.action.text[0] == '=') { @@ -415,15 +417,15 @@ namespace } } - *(U8*)&j.context = c; + *(bool*)&j.context = c; } static void reset_tag_pause(xtextbox::jot&, const xtextbox&, const xtextbox&, - const xtextbox::split_tag&) //DONE + const xtextbox::split_tag&) { } static void reset_tag_sound(xtextbox::jot& j, const xtextbox&, const xtextbox& tb, - const xtextbox::split_tag&) //DONE + const xtextbox::split_tag&) { if (!shared.active) { @@ -443,7 +445,7 @@ namespace c.action = sound_context::ACTION_SET; } static void reset_tag_trap(xtextbox::jot& j, const xtextbox&, const xtextbox& ctb, - const xtextbox::split_tag&) //DONE + const xtextbox::split_tag&) { if (!shared.active) { @@ -459,7 +461,7 @@ namespace } static void reset_tag_allow_quit(xtextbox::jot& j, const xtextbox&, const xtextbox& ctb, - const xtextbox::split_tag&) //DONE + const xtextbox::split_tag&) { if (!shared.active) { @@ -479,13 +481,13 @@ namespace return 1; } - U8 trigger_allow_quit(const xtextbox::jot& j) //DONE + U8 trigger_allow_quit(const xtextbox::jot& j) { shared.allow_quit = (j.context != NULL); return 1; } - U8 trigger_auto_wait(const xtextbox::jot& j) //DONE + U8 trigger_auto_wait(const xtextbox::jot& j) { shared.auto_wait = *(const wait_context*)j.context; @@ -506,7 +508,7 @@ namespace return *this; } - void stop_audio_effect() //TODO + void stop_audio_effect() { if (!shared.active) { @@ -518,7 +520,7 @@ namespace return; } } - static void reset_auto_wait() //DONE + static void reset_auto_wait() { const ztalkbox::asset_type* a = shared.active->asset; @@ -543,7 +545,7 @@ namespace shared.auto_wait.query = Q_SKIP; } static void reset_tag_auto_wait(xtextbox::jot& j, const xtextbox&, const xtextbox& ctb, - const xtextbox::split_tag&) //DONE + const xtextbox::split_tag&) { if (!shared.active) { @@ -593,7 +595,7 @@ void wait_context::reset_type() *(U16*)&this->type = 0; } -static U8 trigger_trap(const xtextbox::jot& j) //DONE +static U8 trigger_trap(const xtextbox::jot& j) { if (j.context != 0) { diff --git a/src/SB/Game/zTalkBox.h b/src/SB/Game/zTalkBox.h index 0ce65c73..93b33b16 100644 --- a/src/SB/Game/zTalkBox.h +++ b/src/SB/Game/zTalkBox.h @@ -313,21 +313,21 @@ namespace U32 id; // offset 0x0, size 0x4 enum { - ACTION_SET = 0, - ACTION_PUSH = 1, - ACTION_POP = 2, + ACTION_SET, + ACTION_PUSH, + ACTION_POP, } action : 8; // offset 0x4, size 0x4 enum { - TYPE_INVALID = 0, - TYPE_VOLUME = 1, - TYPE_TARGET = 2, - TYPE_ORIGIN = 3, + TYPE_INVALID, + TYPE_VOLUME, + TYPE_TARGET, + TYPE_ORIGIN, } type : 8; // offset 0x4, size 0x4 enum { - SOURCE_MEMORY = 0, - SOURCE_STREAM = 1, + SOURCE_MEMORY, + SOURCE_STREAM, } source : 8; // offset 0x4, size 0x4 U8 anim; // offset 0x7, size 0x1 union From ae0fe8a52920dc9c5f0778c4245ceb95fea19a0f Mon Sep 17 00:00:00 2001 From: aarjl Date: Sun, 4 Jan 2026 23:52:39 -0500 Subject: [PATCH 6/6] Reverted read_bool back to the state it was at --- src/SB/Game/zTalkBox.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SB/Game/zTalkBox.cpp b/src/SB/Game/zTalkBox.cpp index c3d3b7e8..3e9ac625 100644 --- a/src/SB/Game/zTalkBox.cpp +++ b/src/SB/Game/zTalkBox.cpp @@ -378,8 +378,8 @@ namespace { static U8 read_bool(const substr& s, bool def) { - const substr negative[6] = {}; - const substr positive[6] = {}; + extern const substr negative[6]; + extern const substr positive[6]; if (def) { for (U32 i = 0; i < 6; ++i)