From bb67a439b5f09899d6834ac8cd396acdcd46a372 Mon Sep 17 00:00:00 2001 From: ragnarok-clanker Date: Thu, 29 Oct 2026 19:05:08 +0000 Subject: [PATCH] Decompile 3 functions in Source/Contents/MapSkyMgr.cpp, Source/Contents/MapSkyMgr.h, ... Batch #2793 by willerthal: 0 byte-identical, 3 confirmed by peer review. - fn_03431 CMapSkyMgr::CMapSkyMgr: logic confirmed by peer review - fn_03436 CMapSkyMgr::CreateClouds: logic confirmed by peer review - fn_18325 LuaScriptBag::Add: logic confirmed by peer review Peer-reviewed-by: ntrl, meitogi, youko Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes). --- Source/Contents/MapSkyMgr.cpp | 212 ++++++++++++++++++++++++++++++++++ Source/Contents/MapSkyMgr.h | 18 +++ Source/Script/LuaScript.cpp | 23 ++++ Source/Script/LuaScript.h | 1 + 4 files changed, 254 insertions(+) diff --git a/Source/Contents/MapSkyMgr.cpp b/Source/Contents/MapSkyMgr.cpp index 7d7801f0..2d0daf4d 100644 --- a/Source/Contents/MapSkyMgr.cpp +++ b/Source/Contents/MapSkyMgr.cpp @@ -1,4 +1,48 @@ #include "Contents/MapSkyMgr.h" +#include "Client/Mode/CGameMode.h" +#include "Client/Mode/ModeMgr.h" +#include "Contents/Effects/EffectActor.h" +#include "Contents/Effects/EffectLists.h" +#include "Contents/World/World.h" +#include "File/MapName.h" +#include "Render/Renderer.h" +#include "Resource/World/TerrainResource.h" + +#include + +struct MapSkyCloud : CEffect { + /* 00CC */ unsigned char unknown_00CC[0x28]; + /* 00F4 */ unsigned char colorR; + /* 00F5 */ unsigned char colorG; + /* 00F6 */ unsigned char colorB; + /* 00F7 */ unsigned char unknown_00F7; + /* 00F8 */ float velocityX; + /* 00FC */ float velocityY; + /* 0100 */ float velocityZ; + /* 0104 */ float unknown_0104; + /* 0108 */ float unknown_0108; + /* 010C */ int unknown_010C; + /* 0110 */ int unknown_0110; + /* 0114 */ int unknown_0114; + /* 0118 */ int unknown_0118; + /* 011C */ float unknown_011C; + /* 0120 */ float spanX; + /* 0124 */ float spanZ; + /* 0128 */ unsigned char flag; +}; + +// GLOBAL: gl_24482 +CWeatherEffect g_weatherEffect; + +// GLOBAL: gl_24633 +float g_depthAverageHalf = 0.5f; + +// OFFSET: 0x005B8D50 +// FUNCTION: fn_03431 +CMapSkyMgr::CMapSkyMgr() : m_script(nullptr) { + this->m_script = new LuaScript(); + this->m_script->Open(); +} // OFFSET: 0x005B8DD0 // FUNCTION: fn_03432 @@ -10,3 +54,171 @@ void CMapSkyMgr::Unused() { bool CMapSkyMgr::LoadData() { return this->m_script->Load("Lua Files\\MapSkyData\\MapSkyData", true, false); } + +// OFFSET: 0x00C7B790 +// FUNCTION: fn_20367 +void CWeatherEffect::Play(char kind) { + CGameMode* mode = static_cast(g_modeMgr.GetGameMode()); + this->actor = mode->scene->player; + + int effectId = 0; + switch (kind) { + case 0: + effectId = 0xe5; + break; + case 1: + effectId = 0xe6; + break; + case 2: + effectId = 0xe9; + break; + case 3: + effectId = 0x203; + break; + case 4: + effectId = 0x204; + break; + case 5: + effectId = 0x250; + break; + case 7: + effectId = 0x2b9; + break; + case 8: + effectId = 0x2ba; + break; + case 9: + effectId = 0x3b1; + break; + case 10: + effectId = 0x415; + break; + case 11: + effectId = 0x45b; + break; + case 15: + effectId = 0x479; + break; + default: + return; + } + + static_cast(this->actor)->LaunchEffect(effectId, vector3d{0.0f, 0.0f, 0.0f}, 0.0f); +} + +// OFFSET: 0x005B90F0 +// FUNCTION: fn_03436 +void CMapSkyMgr::CreateClouds(const std::string& mapName) { + int typeCount = 0; + this->m_script->Call("GetCloudTypeNum", "s>d", mapName.c_str(), &typeCount); + + CGameMode* mode = static_cast(g_modeMgr.GetGameMode()); + C3dAttr* terrain = mode->scene->terrain; + const int mapWidth = terrain->width * terrain->cellSize; + const int mapHeight = terrain->height * terrain->cellSize; + + for (int type = 1; type <= typeCount; ++type) { + int count = 0; + int range = 0x82; + int red = 0; + int green = 0; + int blue = 0; + double velX = 0.0; + double velY = 0.0; + double velZ = 0.0; + int param0 = 0; + int param1 = 0; + double param2 = 0.0; + int param3 = 0; + int param4 = 0; + double param5 = 0.0; + double posY = 0.0; + double param7 = 0.0; + unsigned char flag = 1; + + this->m_script->Call( + "GetCloudInfo", + "sd>dddddlllddlddlllb", + mapName.c_str(), + type, + &count, + &range, + &red, + &green, + &blue, + &velX, + &velY, + &velZ, + ¶m0, + ¶m1, + ¶m2, + ¶m3, + ¶m4, + ¶m5, + &posY, + ¶m7, + &flag + ); + + const float spanX = static_cast(mapWidth) / static_cast(count + 1); + const float spanZ = static_cast(mapHeight) / static_cast(count + 1); + if (count <= 0) { + continue; + } + + const int halfWidth = static_cast(static_cast(mapWidth) * g_depthAverageHalf); + const int halfHeight = static_cast(static_cast(mapHeight) * g_depthAverageHalf); + + for (int index = 0; index < count; ++index) { + const int signX = rand() % 2; + int offsetX = 0; + if (halfWidth != 0) { + offsetX = rand() % halfWidth; + if (offsetX < 0) { + offsetX = 0; + } + } + + const float x = static_cast((1 - 2 * signX) * offsetX); + + const int signZ = rand() % 2; + int offsetZ = 0; + if (halfHeight != 0) { + offsetZ = rand() % halfHeight; + if (offsetZ < 0) { + offsetZ = 0; + } + } + + const float z = static_cast((1 - 2 * signZ) * offsetZ); + const float y = static_cast(posY); + + CEffect* spawned = g_effectMgr->Spawn(0, 0x47a, x, y, z, 0, -1, 0, 0); + if (!spawned) { + continue; + } + + auto* cloud = static_cast(spawned); + cloud->range = range; + cloud->colorR = static_cast(red); + cloud->colorG = static_cast(green); + cloud->colorB = static_cast(blue); + cloud->velocityX = static_cast(velX); + cloud->velocityY = static_cast(velY); + cloud->velocityZ = static_cast(velZ); + cloud->unknown_010C = param0; + cloud->unknown_0110 = param1; + cloud->unknown_0114 = param3; + cloud->unknown_0118 = param4; + cloud->unknown_0104 = static_cast(param2); + cloud->unknown_0108 = static_cast(param5); + cloud->unknown_011C = static_cast(param7); + cloud->spanX = spanX; + cloud->spanZ = spanZ; + cloud->flag = flag; + cloud->Slot07(); + } + } +} + +// OFFSET: 0x005B95F0 diff --git a/Source/Contents/MapSkyMgr.h b/Source/Contents/MapSkyMgr.h index 11d78367..6bc12996 100644 --- a/Source/Contents/MapSkyMgr.h +++ b/Source/Contents/MapSkyMgr.h @@ -3,8 +3,21 @@ #include "Script/LuaScript.h" +#include + +class CWeatherEffect { +public: + void Play(char kind); + + /* 0000 */ unsigned char unknown_0000[0x10]; + /* 0010 */ void* actor; + /* 0014 */ unsigned char unknown_0014[0x30]; + /* 0044 */ void* unknown_0044; +}; + class CMapSkyMgr { public: + CMapSkyMgr(); // INLINED virtual ~CMapSkyMgr() { if (this->m_script) { @@ -16,9 +29,14 @@ public: bool LoadData(); void Unused(); + void CreateClouds(const std::string& mapName); + void Apply(const std::string& mapName); private: /* 0004 */ LuaScript* m_script; }; +extern CWeatherEffect g_weatherEffect; +extern float g_depthAverageHalf; + #endif diff --git a/Source/Script/LuaScript.cpp b/Source/Script/LuaScript.cpp index b47905d9..c539ed3c 100644 --- a/Source/Script/LuaScript.cpp +++ b/Source/Script/LuaScript.cpp @@ -5,12 +5,33 @@ extern "C" { #include +#include } #include #include +#include #include +struct LuaScriptPair { + std::string left; + std::string right; +}; + +class LuaScriptBag { +public: + void Add(std::string left, std::string right); + + /* 0000 */ unsigned char unknown_0000[0x7C]; + /* 007C */ std::vector pairs; +}; + +// OFFSET: 0x00AFC8B0 +// FUNCTION: fn_18325 +void LuaScriptBag::Add(std::string left, std::string right) { + this->pairs.push_back(LuaScriptPair{left, right}); +} + // OFFSET: 0x00AFC830 // FUNCTION: fn_18323 LuaScript::LuaScript() : m_state(nullptr) { @@ -31,6 +52,8 @@ void LuaScript::Close() { } } +// OFFSET: 0x00AFDDD0 + // OFFSET: 0x00AFDD60 // FUNCTION: fn_18335 bool LuaScript::Execute(const void* bytes, std::size_t size) { diff --git a/Source/Script/LuaScript.h b/Source/Script/LuaScript.h index 6688f6a2..0c76bcca 100644 --- a/Source/Script/LuaScript.h +++ b/Source/Script/LuaScript.h @@ -13,6 +13,7 @@ class LuaScript { public: LuaScript(); ~LuaScript(); + void Open(); bool Call(std::string function, const char* signature, ...); bool CallTable(std::string table, std::string function, const char* signature, ...); bool Execute(const void* bytes, std::size_t size);