From cce3245e4b41856269288f4068c7bc850518add9 Mon Sep 17 00:00:00 2001 From: Drew Cavanaugh Date: Mon, 9 Mar 2026 19:54:41 -0500 Subject: [PATCH 1/5] Add Screen Text Lua functions Committer: Drew C. --- FoCAPI.vcxproj | 1 + FoCAPI.vcxproj.filters | 3 ++ functions/functions.cpp | 1 + functions/functions.h | 1 + functions/screen_text.cpp | 92 +++++++++++++++++++++++++++++++++++++++ lua_hook.cpp | 9 ++++ lua_hook.h | 5 +++ rvas.h | 15 +++++++ 8 files changed, 127 insertions(+) create mode 100644 functions/screen_text.cpp diff --git a/FoCAPI.vcxproj b/FoCAPI.vcxproj index d1e2558..fa53cc3 100644 --- a/FoCAPI.vcxproj +++ b/FoCAPI.vcxproj @@ -166,6 +166,7 @@ + diff --git a/FoCAPI.vcxproj.filters b/FoCAPI.vcxproj.filters index b686d97..0ae6219 100644 --- a/FoCAPI.vcxproj.filters +++ b/FoCAPI.vcxproj.filters @@ -50,6 +50,9 @@ Source Files\Functions + + Source Files\Functions + Source Files\Functions diff --git a/functions/functions.cpp b/functions/functions.cpp index 065519c..d7bca9f 100644 --- a/functions/functions.cpp +++ b/functions/functions.cpp @@ -10,4 +10,5 @@ void Register_All(lua_State* L) { Register_FileIO(L); Register_Players(L); + Register_ScreenText(L); } diff --git a/functions/functions.h b/functions/functions.h index ec9ed67..7651e33 100644 --- a/functions/functions.h +++ b/functions/functions.h @@ -10,3 +10,4 @@ void Register_All(lua_State* L); // Each checks its own required function pointer guards before registering. void Register_FileIO(lua_State* L); void Register_Players(lua_State* L); +void Register_ScreenText(lua_State* L); diff --git a/functions/screen_text.cpp b/functions/screen_text.cpp new file mode 100644 index 0000000..dc72b33 --- /dev/null +++ b/functions/screen_text.cpp @@ -0,0 +1,92 @@ +#include "functions.h" +#include "../lua_hook.h" +#include +#include + +// Maximum number of lines held in the feed at once. +static constexpr int MAX_LINES = 8; + +// Keys used as the RawText identifier for each slot, enabling Remove_Tutorial_Text lookups. +static constexpr float PERPETUAL = -1.0f; + +static char g_keys[MAX_LINES][16]; // "FOCA_0" .. "FOCA_7" +static int g_head = 0; // index of oldest active slot +static int g_count = 0; // number of active slots + +static void reset_feed() +{ + g_head = 0; + g_count = 0; + for (int i = 0; i < MAX_LINES; i++) + wsprintfA(g_keys[i], "FOCA_%d", i); +} + +// Print_Screen_Text(text [, duration]) +// Appends a line to the bottom of the tutorial text feed. +// duration defaults to -1 (perpetual). Pass a positive number of seconds to auto-expire. +static int L_Print_Screen_Text(lua_State* L) +{ + const char* text = pfn_tostring(L, 1); + if (!text || !pfn_add_tutorial_text || !g_command_bar) + return 0; + + float duration = PERPETUAL; + if (pfn_tonumber) + { + double arg2 = pfn_tonumber(L, 2); + if (arg2 != 0.0) + duration = (float)arg2; + } + + // Widen to wchar_t for the game's basic_string parameter. + int wlen = MultiByteToWideChar(CP_ACP, 0, text, -1, nullptr, 0); + std::wstring wtext(wlen - 1, L'\0'); + MultiByteToWideChar(CP_ACP, 0, text, -1, wtext.data(), wlen); + + // If the feed is full, evict the oldest entry. + if (g_count >= MAX_LINES) + { + pfn_remove_tutorial_text(g_command_bar, g_keys[g_head]); + g_head = (g_head + 1) % MAX_LINES; + g_count--; + } + + int slot = (g_head + g_count) % MAX_LINES; + g_count++; + + // Inner overload: (this, wstring*, key, duration, index, teletype, color) + // index=0 so StartTime is set immediately; teletype=false for instant display; color=nullptr for default. + pfn_add_tutorial_text(g_command_bar, &wtext, g_keys[slot], duration, 0, false, nullptr); + + return 0; +} + +// Clear_Screen_Text() +// Removes all active FoCAPI-managed screen text entries. +static int L_Clear_Screen_Text(lua_State* L) +{ + if (!pfn_remove_tutorial_text || !g_command_bar) + return 0; + + for (int i = 0; i < g_count; i++) + { + int slot = (g_head + i) % MAX_LINES; + pfn_remove_tutorial_text(g_command_bar, g_keys[slot]); + } + + g_head = 0; + g_count = 0; + + return 0; +} + +void Register_ScreenText(lua_State* L) +{ + if (!pfn_add_tutorial_text || !pfn_remove_tutorial_text || !g_command_bar) + return; + + reset_feed(); + + register_global(L, "Print_Screen_Text", L_Print_Screen_Text); + register_global(L, "Clear_Screen_Text", L_Clear_Screen_Text); +} diff --git a/lua_hook.cpp b/lua_hook.cpp index efc6dd9..1f9132b 100644 --- a/lua_hook.cpp +++ b/lua_hook.cpp @@ -17,6 +17,9 @@ void* g_player_list = nullptr; fn_PlayerWrapperCreate pfn_player_wrapper_create = nullptr; fn_GetScriptFromState pfn_get_script_from_state = nullptr; fn_MapVarToLua pfn_map_var_to_lua = nullptr; +fn_AddTutorialText pfn_add_tutorial_text = nullptr; +fn_RemoveTutorialText pfn_remove_tutorial_text = nullptr; +void* g_command_bar = nullptr; fn_DebugPrint pfn_debug_print = nullptr; void register_global(lua_State* L, const char* name, lua_CFunction fn) { @@ -72,6 +75,12 @@ bool LuaHook_Init() { pfn_map_var_to_lua = (fn_MapVarToLua)(base + rvas->map_var_to_lua); } + if (rvas->command_bar && rvas->add_tutorial_text && rvas->remove_tutorial_text) { + g_command_bar = (void*)(base + rvas->command_bar); + pfn_add_tutorial_text = (fn_AddTutorialText)(base + rvas->add_tutorial_text); + pfn_remove_tutorial_text = (fn_RemoveTutorialText)(base + rvas->remove_tutorial_text); + } + if (rvas->debug_print) pfn_debug_print = (fn_DebugPrint)(base + rvas->debug_print); diff --git a/lua_hook.h b/lua_hook.h index dfcf5cb..f5a2835 100644 --- a/lua_hook.h +++ b/lua_hook.h @@ -17,6 +17,8 @@ typedef void* (*fn_GetPlayerByIndex)(void*, int); // PlayerListC typedef void* (*fn_PlayerWrapperCreate)(void*, void*); // PlayerWrapper::Create(PlayerClass*, LuaScriptClass*) typedef void* (*fn_GetScriptFromState)(lua_State*); // LuaScriptClass::Get_Script_From_State typedef void (*fn_MapVarToLua)(lua_State*, void*); // LuaScriptClass::Map_Var_To_Lua (static) +typedef void (*fn_AddTutorialText)(void*, void*, const char*, float, unsigned int, bool, void*); // CommandBarClass::Add_Tutorial_Text (inner) +typedef void (*fn_RemoveTutorialText)(void*, const char*); // CommandBarClass::Remove_Tutorial_Text typedef void (*fn_DebugPrint)(const char*); // Debug_Print // Resolved function pointers (defined in lua_hook.cpp) @@ -33,6 +35,9 @@ extern void* g_player_list; extern fn_PlayerWrapperCreate pfn_player_wrapper_create; extern fn_GetScriptFromState pfn_get_script_from_state; extern fn_MapVarToLua pfn_map_var_to_lua; +extern fn_AddTutorialText pfn_add_tutorial_text; +extern fn_RemoveTutorialText pfn_remove_tutorial_text; +extern void* g_command_bar; extern fn_DebugPrint pfn_debug_print; constexpr int LUA_GLOBALSINDEX = -10001; diff --git a/rvas.h b/rvas.h index 9f97c80..a691e0e 100644 --- a/rvas.h +++ b/rvas.h @@ -21,6 +21,11 @@ struct LuaRVAs { uintptr_t get_script_from_state; // LuaScriptClass::Get_Script_From_State (static) uintptr_t map_var_to_lua; // LuaScriptClass::Map_Var_To_Lua (member) + // --- Screen Text --- + uintptr_t command_bar; // TheCommandBar global object (data, not a function) + uintptr_t add_tutorial_text; // CommandBarClass::Add_Tutorial_Text (inner overload: wstring*, char*, float, uint, bool, RGBAClass*) + uintptr_t remove_tutorial_text; // CommandBarClass::Remove_Tutorial_Text(char*) + // --- Debug --- uintptr_t debug_print; // Debug_Print(char*) }; @@ -46,6 +51,11 @@ constexpr LuaRVAs RVAs_StarWarsI = { 0x0537BB0, // LuaScriptClass::Get_Script_From_State 0x0536FE0, // LuaScriptClass::Map_Var_To_Lua + // --- Screen Text --- + 0x1916b80, // TheCommandBar global object + 0x003c83a, // CommandBarClass::Add_Tutorial_Text inner + 0x006e1eb, // CommandBarClass::Remove_Tutorial_Text + // --- Debug --- 0x0476AE0, // Debug_Print }; @@ -71,6 +81,11 @@ constexpr LuaRVAs RVAs_StarWarsG = { 0x0245790, // LuaScriptClass::Get_Script_From_State (TODO) 0x0247700, // LuaScriptClass::Map_Var_To_Lua (TODO) + // --- Screen Text --- + 0, // TheCommandBar (TODO) + 0, // CommandBarClass::Add_Tutorial_Text inner (TODO) + 0, // CommandBarClass::Remove_Tutorial_Text (TODO) + // --- Debug --- 0, // Debug_Print (TODO) }; From a2fda59eebf3132e1a80622ae7ea272252c16f05 Mon Sep 17 00:00:00 2001 From: "Drew C." Date: Mon, 9 Mar 2026 20:16:56 -0500 Subject: [PATCH 2/5] Fix compiler error --- functions/screen_text.cpp | 2 +- minhook/bin/MinHook.x64.exp | Bin 2203 -> 0 bytes minhook/bin/MinHook.x86.exp | Bin 2282 -> 0 bytes minhook/include/MinHook.h | 185 ------------------------------------ 4 files changed, 1 insertion(+), 186 deletions(-) delete mode 100644 minhook/bin/MinHook.x64.exp delete mode 100644 minhook/bin/MinHook.x86.exp delete mode 100644 minhook/include/MinHook.h diff --git a/functions/screen_text.cpp b/functions/screen_text.cpp index dc72b33..459840a 100644 --- a/functions/screen_text.cpp +++ b/functions/screen_text.cpp @@ -41,7 +41,7 @@ static int L_Print_Screen_Text(lua_State* L) // Widen to wchar_t for the game's basic_string parameter. int wlen = MultiByteToWideChar(CP_ACP, 0, text, -1, nullptr, 0); std::wstring wtext(wlen - 1, L'\0'); - MultiByteToWideChar(CP_ACP, 0, text, -1, wtext.data(), wlen); + MultiByteToWideChar(CP_ACP, 0, text, -1, &wtext[0], wlen); // If the feed is full, evict the oldest entry. if (g_count >= MAX_LINES) diff --git a/minhook/bin/MinHook.x64.exp b/minhook/bin/MinHook.x64.exp deleted file mode 100644 index ad66dd6e3392334b6903e20667348fd85eba3a6f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2203 zcmd5-O>f*(6upU)wnS=};9h?Ib7_ZD=zg>cUd+j9;ct@z|E_ zX@>|=kSgE@Ac4e&1*kj3uFFbnSfRoKsTpCl?#T1@3SiSsx>6OR$OXz!xsavZgepXsVruQT6djmtOVME6nirB1VF zIp#ewotHWAxMtda(~i+N88ktYw1@W6KANIw+D{j>zZwKPW`C(_x}HZDR=3WCq4)l! zp6V%=!$zc>MDd{E=uD_bgq1!^%Q|*i-eAg#pO4P@I?;}&cNGtnZ3^Q>8=kbTy1~`K zg3ZK9dhtfkOd{=fc$s&7{bX7Bz7zPUhMX1-7pw%_BWxbHSJ(pZps>rpeZpP^J}1lu zP6@MshlITcoEBCE9u~&#*e|RGJRcC^dLg0+BW#IF|65!Lq zR)Op{gZjW(VdsG_2>SpyC+s5dMPVNSpAohJd`Z|1;IqOefDcej`1CA|@nl*)Wjl6P z`&V$jgSOSvo@;M5$|voX_U(1$DJNET-Ycpf(kpa&j-B)~FC=9K+Mk~iT-A<(IM_}~ z3+peJ&YxR*o4%ws=BRzm{kI)S^%XTv*%zar6FJ?|TiR1Gw$2vZ)N#-8O3kF_>cFm8 zm5ROMCn^dfjYr&U*c(CMVL}tMTs5nU=3=#G)#OE1gE+ZdTe4wx+tdDz$$R0rYjd2I z@KN6S2O)DpL(ZkZVW>t?P!~}7LzRplu77oJ`s3ez z-SY3;{O--2>mQnroO_cuZ=Kkky8X+6yC%^e7-ymW^Ks***@{#g^rE&LZh8l~YMbiq zpc|Ung^R}c)-f*(6upy4I!#(ahVMdvLCPWsWO*h-YN}Saodl&KP1{TwbzvzuV`pl`V~=c4 zGen4jgakhUi3RMsLu?Qmq)IGUflwDnl@M&YM<6P}4$i%fXZ%r#9arP?&OP^i*zeu@ zX1z2)|G>VPBC3&CNwF<6GGm7^ED>2~@1bRz$D`w?SoZFqyU=Eh?fVI$-|?hPr@0I4 z^BRfH)0{kd67BzKOEf`cnxrW@Min|v(=%H_^L?ivtPWXPaYA#~9SvFa(%wbSi5$~)4sGr#%jEitmL0Td_xziq z3EPnw4ZY&Ujkc-$`t0MNSKc3swUj6Sg48+9KE!;#~(G7xpUfNnr+X zT9^uaO4!@L8DUM})517AP6*S0&j`B#P#QF7OdyI`COxec-IH72tEiBH*LK z)_|OE6&eEPgslUg7xpf&D(njI1!3<49}~6(d{Nkkz{iD60{_5s4S9NjN<5fW&KRcA zbG#ck-%-0ea9qpSZq-j4yN+jU+OBPewvo;id)TK}=xmiUsmv3J%|iS8BSKbn0zdTk zqT1r-%eD238*kAkbgoLB1M9z5BztI6>x^+F@VkN8tG(&Cc8H~u3AdeaV7j$-G_V}s zXsC^bvFb&3&<`BE;&#i}@_iQr+MxBO(p*xOnwqM~hphQwbX{9EknD!*c>4;kg(K6d zT$VdXq*U(fszkV^IWjH-z23l4X;uF0Yy>5t*OzfVT9x;@5L_MVjd)g0N)D$|UvDCz zv??blN5%zk6sQ~p#s!2oN5>V0Vf=NR(j3SZ8-k}0 zPbsQ8hy93^^j*&H zQ>OH-%?Dei@NmQIAqhT*7xxLe{hM$`Us0x@8~5T{BI$E*Ik1R69w`eODy&Xl=9C8A z$tg?pLr!VZuQ}y4snd9^c;;nUI<1_hS-5FMqxqcjI;mNuu2L(f)ahzYX;5dR;KlHt zF*e?{_%=+mSm85IELP4XF4|b(J1MbP*-Kosv2svQc#ji{`+SzTXk+E8g7RHK`8lKf z29Gm1Tkx!83q7kG6?j363!CL^L9>!6ITkVn%)&zocO(}^X9|_O6$+HaTw(qTgs8s9 diff --git a/minhook/include/MinHook.h b/minhook/include/MinHook.h deleted file mode 100644 index 492d83f..0000000 --- a/minhook/include/MinHook.h +++ /dev/null @@ -1,185 +0,0 @@ -/* - * MinHook - The Minimalistic API Hooking Library for x64/x86 - * Copyright (C) 2009-2017 Tsuda Kageyu. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#if !(defined _M_IX86) && !(defined _M_X64) && !(defined __i386__) && !(defined __x86_64__) - #error MinHook supports only x86 and x64 systems. -#endif - -#include - -// MinHook Error Codes. -typedef enum MH_STATUS -{ - // Unknown error. Should not be returned. - MH_UNKNOWN = -1, - - // Successful. - MH_OK = 0, - - // MinHook is already initialized. - MH_ERROR_ALREADY_INITIALIZED, - - // MinHook is not initialized yet, or already uninitialized. - MH_ERROR_NOT_INITIALIZED, - - // The hook for the specified target function is already created. - MH_ERROR_ALREADY_CREATED, - - // The hook for the specified target function is not created yet. - MH_ERROR_NOT_CREATED, - - // The hook for the specified target function is already enabled. - MH_ERROR_ENABLED, - - // The hook for the specified target function is not enabled yet, or already - // disabled. - MH_ERROR_DISABLED, - - // The specified pointer is invalid. It points the address of non-allocated - // and/or non-executable region. - MH_ERROR_NOT_EXECUTABLE, - - // The specified target function cannot be hooked. - MH_ERROR_UNSUPPORTED_FUNCTION, - - // Failed to allocate memory. - MH_ERROR_MEMORY_ALLOC, - - // Failed to change the memory protection. - MH_ERROR_MEMORY_PROTECT, - - // The specified module is not loaded. - MH_ERROR_MODULE_NOT_FOUND, - - // The specified function is not found. - MH_ERROR_FUNCTION_NOT_FOUND -} -MH_STATUS; - -// Can be passed as a parameter to MH_EnableHook, MH_DisableHook, -// MH_QueueEnableHook or MH_QueueDisableHook. -#define MH_ALL_HOOKS NULL - -#ifdef __cplusplus -extern "C" { -#endif - - // Initialize the MinHook library. You must call this function EXACTLY ONCE - // at the beginning of your program. - MH_STATUS WINAPI MH_Initialize(VOID); - - // Uninitialize the MinHook library. You must call this function EXACTLY - // ONCE at the end of your program. - MH_STATUS WINAPI MH_Uninitialize(VOID); - - // Creates a hook for the specified target function, in disabled state. - // Parameters: - // pTarget [in] A pointer to the target function, which will be - // overridden by the detour function. - // pDetour [in] A pointer to the detour function, which will override - // the target function. - // ppOriginal [out] A pointer to the trampoline function, which will be - // used to call the original target function. - // This parameter can be NULL. - MH_STATUS WINAPI MH_CreateHook(LPVOID pTarget, LPVOID pDetour, LPVOID *ppOriginal); - - // Creates a hook for the specified API function, in disabled state. - // Parameters: - // pszModule [in] A pointer to the loaded module name which contains the - // target function. - // pszProcName [in] A pointer to the target function name, which will be - // overridden by the detour function. - // pDetour [in] A pointer to the detour function, which will override - // the target function. - // ppOriginal [out] A pointer to the trampoline function, which will be - // used to call the original target function. - // This parameter can be NULL. - MH_STATUS WINAPI MH_CreateHookApi( - LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID *ppOriginal); - - // Creates a hook for the specified API function, in disabled state. - // Parameters: - // pszModule [in] A pointer to the loaded module name which contains the - // target function. - // pszProcName [in] A pointer to the target function name, which will be - // overridden by the detour function. - // pDetour [in] A pointer to the detour function, which will override - // the target function. - // ppOriginal [out] A pointer to the trampoline function, which will be - // used to call the original target function. - // This parameter can be NULL. - // ppTarget [out] A pointer to the target function, which will be used - // with other functions. - // This parameter can be NULL. - MH_STATUS WINAPI MH_CreateHookApiEx( - LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID *ppOriginal, LPVOID *ppTarget); - - // Removes an already created hook. - // Parameters: - // pTarget [in] A pointer to the target function. - MH_STATUS WINAPI MH_RemoveHook(LPVOID pTarget); - - // Enables an already created hook. - // Parameters: - // pTarget [in] A pointer to the target function. - // If this parameter is MH_ALL_HOOKS, all created hooks are - // enabled in one go. - MH_STATUS WINAPI MH_EnableHook(LPVOID pTarget); - - // Disables an already created hook. - // Parameters: - // pTarget [in] A pointer to the target function. - // If this parameter is MH_ALL_HOOKS, all created hooks are - // disabled in one go. - MH_STATUS WINAPI MH_DisableHook(LPVOID pTarget); - - // Queues to enable an already created hook. - // Parameters: - // pTarget [in] A pointer to the target function. - // If this parameter is MH_ALL_HOOKS, all created hooks are - // queued to be enabled. - MH_STATUS WINAPI MH_QueueEnableHook(LPVOID pTarget); - - // Queues to disable an already created hook. - // Parameters: - // pTarget [in] A pointer to the target function. - // If this parameter is MH_ALL_HOOKS, all created hooks are - // queued to be disabled. - MH_STATUS WINAPI MH_QueueDisableHook(LPVOID pTarget); - - // Applies all queued changes in one go. - MH_STATUS WINAPI MH_ApplyQueued(VOID); - - // Translates the MH_STATUS to its name as a string. - const char * WINAPI MH_StatusToString(MH_STATUS status); - -#ifdef __cplusplus -} -#endif From 14f02697be602666009a7798af685b0ae515e3c3 Mon Sep 17 00:00:00 2001 From: "Drew C." Date: Mon, 9 Mar 2026 22:17:35 -0500 Subject: [PATCH 3/5] Dumb down the function -- let Lua control the tutorial pane --- functions/screen_text.cpp | 92 ++++++++++++++------------------------- 1 file changed, 33 insertions(+), 59 deletions(-) diff --git a/functions/screen_text.cpp b/functions/screen_text.cpp index 459840a..0e75de7 100644 --- a/functions/screen_text.cpp +++ b/functions/screen_text.cpp @@ -3,79 +3,55 @@ #include #include -// Maximum number of lines held in the feed at once. -static constexpr int MAX_LINES = 8; - -// Keys used as the RawText identifier for each slot, enabling Remove_Tutorial_Text lookups. -static constexpr float PERPETUAL = -1.0f; - -static char g_keys[MAX_LINES][16]; // "FOCA_0" .. "FOCA_7" -static int g_head = 0; // index of oldest active slot -static int g_count = 0; // number of active slots - -static void reset_feed() +// Add_Tutorial_Text(key, text [, duration [, r, g, b, a]]) +// duration defaults to -1 (perpetual). r/g/b/a default to 1.0 (white, opaque). +// The color pointer must be non-null: the game copies 16 bytes from it unconditionally +// before its own null check, so we always pass a valid buffer. +static int L_Add_Tutorial_Text(lua_State* L) { - g_head = 0; - g_count = 0; - for (int i = 0; i < MAX_LINES; i++) - wsprintfA(g_keys[i], "FOCA_%d", i); -} - -// Print_Screen_Text(text [, duration]) -// Appends a line to the bottom of the tutorial text feed. -// duration defaults to -1 (perpetual). Pass a positive number of seconds to auto-expire. -static int L_Print_Screen_Text(lua_State* L) -{ - const char* text = pfn_tostring(L, 1); - if (!text || !pfn_add_tutorial_text || !g_command_bar) + const char* key = pfn_tostring(L, 1); + const char* text = pfn_tostring(L, 2); + if (!key || !text) return 0; - float duration = PERPETUAL; + float duration = -1.0f; + float color[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + if (pfn_tonumber) { - double arg2 = pfn_tonumber(L, 2); - if (arg2 != 0.0) - duration = (float)arg2; + double arg3 = pfn_tonumber(L, 3); + if (arg3 != 0.0) duration = (float)arg3; + + double r = pfn_tonumber(L, 4); + double g = pfn_tonumber(L, 5); + double b = pfn_tonumber(L, 6); + double a = pfn_tonumber(L, 7); + if (r != 0.0 || g != 0.0 || b != 0.0 || a != 0.0) + { + color[0] = (float)r; + color[1] = (float)g; + color[2] = (float)b; + color[3] = (float)a; + } } - // Widen to wchar_t for the game's basic_string parameter. int wlen = MultiByteToWideChar(CP_ACP, 0, text, -1, nullptr, 0); std::wstring wtext(wlen - 1, L'\0'); MultiByteToWideChar(CP_ACP, 0, text, -1, &wtext[0], wlen); - // If the feed is full, evict the oldest entry. - if (g_count >= MAX_LINES) - { - pfn_remove_tutorial_text(g_command_bar, g_keys[g_head]); - g_head = (g_head + 1) % MAX_LINES; - g_count--; - } - - int slot = (g_head + g_count) % MAX_LINES; - g_count++; - - // Inner overload: (this, wstring*, key, duration, index, teletype, color) - // index=0 so StartTime is set immediately; teletype=false for instant display; color=nullptr for default. - pfn_add_tutorial_text(g_command_bar, &wtext, g_keys[slot], duration, 0, false, nullptr); + pfn_add_tutorial_text(g_command_bar, &wtext, (char*)key, duration, 0, false, color); return 0; } -// Clear_Screen_Text() -// Removes all active FoCAPI-managed screen text entries. -static int L_Clear_Screen_Text(lua_State* L) +// Remove_Tutorial_Text(key) +static int L_Remove_Tutorial_Text(lua_State* L) { - if (!pfn_remove_tutorial_text || !g_command_bar) + const char* key = pfn_tostring(L, 1); + if (!key) return 0; - for (int i = 0; i < g_count; i++) - { - int slot = (g_head + i) % MAX_LINES; - pfn_remove_tutorial_text(g_command_bar, g_keys[slot]); - } - - g_head = 0; - g_count = 0; + pfn_remove_tutorial_text(g_command_bar, (char*)key); return 0; } @@ -85,8 +61,6 @@ void Register_ScreenText(lua_State* L) if (!pfn_add_tutorial_text || !pfn_remove_tutorial_text || !g_command_bar) return; - reset_feed(); - - register_global(L, "Print_Screen_Text", L_Print_Screen_Text); - register_global(L, "Clear_Screen_Text", L_Clear_Screen_Text); + register_global(L, "Add_Tutorial_Text", L_Add_Tutorial_Text); + register_global(L, "Remove_Tutorial_Text", L_Remove_Tutorial_Text); } From 98cdafa094c3fbb7c35b5c1a4815f7f4141ebb9e Mon Sep 17 00:00:00 2001 From: Drew C Date: Mon, 9 Mar 2026 22:26:21 -0500 Subject: [PATCH 4/5] Update README.md for new functions --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 176c9b3..304f73f 100644 --- a/README.md +++ b/README.md @@ -9,5 +9,17 @@ Currently only works with the debug kit `StarWarsI.exe`; `StarWarsG.exe` support ## Functions -- Global `WriteToFile(str a, str b)` - Appends a line of text `b` to the file name `a` in the game directory. +- Global `WriteToFile(file, text)` - Appends a line of text specified file in the game directory. + - Parameter `file` string - The file name to append. + - Parameter `text` string - The text line to append. - Global `Get_All_Players()` - Returns a 1-based Lua table of all active players, iterable with `ipairs()`. Each entry is the same PlayerWrapper type returned by `Find_Player()`. +- Global `Add_Tutorial_Text(key, text, duration, r, g, b, a)` - Adds a line to the tutorial text pane. + - Parameter `key`: string - The key used to identify this line, later can be used to update or remove the text. + - Parameter `text`: string - The text to display. + - Parameter `duration` number? - The duration to display the text. Default: -1 (infinite) + - Parameter `r` number? - The red color component. Default: 1 + - Parameter `g` number? - The green color component. Default: 1 + - Parameter `b` number? - The blue color component. Default: 1 + - Parameter `a` number? - The alpha component. Default: 1 +- Global `Remove_Tutorial_Text(key)` - Removes the line associated with the key. + - Parameter `key` string - The key used to identify the line when it was added. \ No newline at end of file From 5ec3a9a758f953a9839b3104e65cdd3cc862bc43 Mon Sep 17 00:00:00 2001 From: Drew C Date: Mon, 9 Mar 2026 22:48:55 -0500 Subject: [PATCH 5/5] Add RVAs for StarWarsG --- rvas.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/rvas.h b/rvas.h index a691e0e..fccaeee 100644 --- a/rvas.h +++ b/rvas.h @@ -69,23 +69,23 @@ constexpr LuaRVAs RVAs_StarWarsG = { 0x07b9a60, // lua_settable 0x07b9cc0, // lua_tostring 0x07b9bc0, // lua_tonumber - 0x07b9140, // lua_newtable (TODO) - 0x07b9820, // lua_rawseti (TODO) + 0x07b9140, // lua_newtable + 0x07b9820, // lua_rawseti // --- Players --- - 0x0294bc0, // PlayerListClass::Get_Player_By_Index (TODO) - 0x0a16fd0, // PlayerList global object (TODO) - 0x06019f0, // PlayerWrapper::Create (TODO) + 0x0294bc0, // PlayerListClass::Get_Player_By_Index + 0x0a16fd0, // PlayerList global object + 0x06019f0, // PlayerWrapper::Create // --- Scripts --- - 0x0245790, // LuaScriptClass::Get_Script_From_State (TODO) - 0x0247700, // LuaScriptClass::Map_Var_To_Lua (TODO) + 0x0245790, // LuaScriptClass::Get_Script_From_State + 0x0247700, // LuaScriptClass::Map_Var_To_Lua // --- Screen Text --- - 0, // TheCommandBar (TODO) - 0, // CommandBarClass::Add_Tutorial_Text inner (TODO) - 0, // CommandBarClass::Remove_Tutorial_Text (TODO) + 0x0b27f60, // TheCommandBar + 0x02dfd10, // CommandBarClass::Add_Tutorial_Text inner + 0x02ff290, // CommandBarClass::Remove_Tutorial_Text // --- Debug --- - 0, // Debug_Print (TODO) + 0, // Debug_Print (not mapped) };