From 70d731247217e6ac7165dd43028e4b6c19b17245 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 29 Apr 2017 23:08:41 +0200 Subject: [PATCH] [Script] Allow 6 params for setExpFog --- src/Components/Modules/Colors.cpp | 2 +- src/Components/Modules/Script.cpp | 20 ++++++++++ src/Components/Modules/Script.hpp | 2 + src/Game/Functions.cpp | 1 + src/Game/Functions.hpp | 3 ++ src/Game/Structs.hpp | 65 +++++++++++++++++++++++++++++++ 6 files changed, 92 insertions(+), 1 deletion(-) diff --git a/src/Components/Modules/Colors.cpp b/src/Components/Modules/Colors.cpp index 78440758..01950ce9 100644 --- a/src/Components/Modules/Colors.cpp +++ b/src/Components/Modules/Colors.cpp @@ -142,7 +142,7 @@ namespace Components unsigned int Colors::ColorIndex(char index) { char result = index - '0'; - if (result >= Colors::ColorTable.size() || result < 0) result = 7; + if (static_cast(result) >= Colors::ColorTable.size() || result < 0) result = 7; return result; } diff --git a/src/Components/Modules/Script.cpp b/src/Components/Modules/Script.cpp index fb522f1e..58c3101c 100644 --- a/src/Components/Modules/Script.cpp +++ b/src/Components/Modules/Script.cpp @@ -227,6 +227,24 @@ namespace Components Game::GScr_LoadGameTypeScript(); } + int Script::SetExpFogStub() + { + if(Game::Scr_GetNumParam() == 6) + { + Game::VariableValue*& scr_stack = *reinterpret_cast(0x2040D00); + if(scr_stack) + { + Game::Scr_AddFloat(0); // Push transition time onto the stack + Game::VariableValue transitionTime; + std::memcpy(&transitionTime, scr_stack, sizeof Game::VariableValue); + std::memmove(&scr_stack[0], &scr_stack[1], sizeof(Game::VariableValue) * 6); + std::memcpy(&scr_stack[6], &transitionTime, sizeof Game::VariableValue); + } + } + + return Game::Scr_GetNumParam(); + } + Script::Script() { Utils::Hook(0x612DB0, Script::StoreFunctionNameStub, HOOK_JUMP).install()->quick(); @@ -239,6 +257,8 @@ namespace Components Utils::Hook(0x48EFFE, Script::LoadGameType, HOOK_CALL).install()->quick(); Utils::Hook(0x45D44A, Script::LoadGameTypeScript, HOOK_CALL).install()->quick(); + + Utils::Hook(0x5F41A3, Script::SetExpFogStub, HOOK_CALL).install()->quick(); } Script::~Script() diff --git a/src/Components/Modules/Script.hpp b/src/Components/Modules/Script.hpp index 3033648d..d7f55e39 100644 --- a/src/Components/Modules/Script.hpp +++ b/src/Components/Modules/Script.hpp @@ -34,5 +34,7 @@ namespace Components static void LoadGameType(); static void LoadGameTypeScript(); + + static int SetExpFogStub(); }; } diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 9d2e871f..c292dde4 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -213,6 +213,7 @@ namespace Game Scr_FreeThread_t Scr_FreeThread = Scr_FreeThread_t(0x4BD320); Scr_AddString_t Scr_AddString = Scr_AddString_t(0x412310); + Scr_AddFloat_t Scr_AddFloat = Scr_AddFloat_t(0x61E860); Scr_Notify_t Scr_Notify = Scr_Notify_t(0x4A4750); Scr_ShutdownAllocNode_t Scr_ShutdownAllocNode = Scr_ShutdownAllocNode_t(0x441650); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 4f63655b..7b4f5d87 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -511,6 +511,9 @@ namespace Game typedef void(__cdecl * Scr_AddString_t)(const char* str); extern Scr_AddString_t Scr_AddString; + typedef int(__cdecl * Scr_AddFloat_t)(float); + extern Scr_AddFloat_t Scr_AddFloat; + typedef void(__cdecl * Scr_ShutdownAllocNode_t)(); extern Scr_ShutdownAllocNode_t Scr_ShutdownAllocNode; diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index a1a436d4..3f844f5a 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -3956,6 +3956,71 @@ namespace Game int dataCount; } gameState; + struct VariableStackBuffer + { + const char *pos; + unsigned __int16 size; + unsigned __int16 bufLen; + unsigned __int16 localId; + char time; + char buf[1]; + }; + + enum VariableType + { + VAR_UNDEFINED = 0x0, + VAR_BEGIN_REF = 0x1, + VAR_POINTER = 0x1, + VAR_STRING = 0x2, + VAR_ISTRING = 0x3, + VAR_VECTOR = 0x4, + VAR_END_REF = 0x5, + VAR_FLOAT = 0x5, + VAR_INTEGER = 0x6, + VAR_CODEPOS = 0x7, + VAR_PRECODEPOS = 0x8, + VAR_FUNCTION = 0x9, + VAR_BUILTIN_FUNCTION = 0xA, + VAR_BUILTIN_METHOD = 0xB, + VAR_STACK = 0xC, + VAR_ANIMATION = 0xD, + VAR_PRE_ANIMATION = 0xE, + VAR_THREAD = 0xF, + VAR_NOTIFY_THREAD = 0x10, + VAR_TIME_THREAD = 0x11, + VAR_CHILD_THREAD = 0x12, + VAR_OBJECT = 0x13, + VAR_DEAD_ENTITY = 0x14, + VAR_ENTITY = 0x15, + VAR_ARRAY = 0x16, + VAR_DEAD_THREAD = 0x17, + VAR_COUNT = 0x18, + VAR_FREE = 0x18, + VAR_THREAD_LIST = 0x19, + VAR_ENDON_LIST = 0x1A, + VAR_TOTAL_COUNT = 0x1B, + }; + + union VariableUnion + { + int intValue; + unsigned int uintValue; + float floatValue; + unsigned int stringValue; + const float *vectorValue; + const char *codePosValue; + unsigned int pointerValue; + VariableStackBuffer *stackValue; + unsigned int entityOffset; + }; + + /* 3765 */ + struct VariableValue + { + VariableUnion u; + int type; + }; + #ifndef IDA } #endif