diff --git a/src/Components/Modules/Maps.cpp b/src/Components/Modules/Maps.cpp index c65ec2d7..8391ed84 100644 --- a/src/Components/Modules/Maps.cpp +++ b/src/Components/Modules/Maps.cpp @@ -183,6 +183,18 @@ namespace Components } } + void Maps::LoadRawSun() + { + Game::R_FlushSun(); + + Game::GfxWorld* world = *reinterpret_cast(0x66DEE94); + + if (FileSystem::File(fmt::sprintf("sun/%s.sun", world->baseName)).exists()) + { + Game::R_LoadSunThroughDvars(world->baseName, &world->sun); + } + } + void Maps::GetBSPName(char* buffer, size_t size, const char* format, const char* mapname) { if (!Utils::String::StartsWith(mapname, "mp_") && !Utils::String::StartsWith(mapname, "zm_")) @@ -545,6 +557,9 @@ namespace Components // WorldData pointer replacement Utils::Hook(0x4D90B6, Maps::GetWorldDataStub, HOOK_CALL).install()->quick(); + // Allow loading raw suns + Utils::Hook(0x51B46A, Maps::LoadRawSun, HOOK_CALL).install()->quick(); + Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_GAME_MAP_SP, 1); Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_IMAGE, 7168); Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_LOADED_SOUND, 2700); diff --git a/src/Components/Modules/Maps.hpp b/src/Components/Modules/Maps.hpp index f66b4ce5..88c3b64e 100644 --- a/src/Components/Modules/Maps.hpp +++ b/src/Components/Modules/Maps.hpp @@ -45,6 +45,8 @@ namespace Components static Game::GameMap_Data* GetWorldData(); static void GetWorldDataStub(); + static void LoadRawSun(); + static void AddDlc(DLC dlc); static void UpdateDlcStatus(); diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index bae9dd60..96a57563 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -175,6 +175,7 @@ namespace Game R_LoadGraphicsAssets_t R_LoadGraphicsAssets = (R_LoadGraphicsAssets_t)0x506AC0; R_TextWidth_t R_TextWidth = (R_TextWidth_t)0x5056C0; R_TextHeight_t R_TextHeight = (R_TextHeight_t)0x505770; + R_FlushSun_t R_FlushSun = (R_FlushSun_t)0x53FB50; Scr_LoadGameType_t Scr_LoadGameType = (Scr_LoadGameType_t)0x4D9520; @@ -461,6 +462,36 @@ namespace Game return hash; } + void R_LoadSunThroughDvars(const char* mapname, sunflare_t* sun) + { + __asm + { + push ecx + push sun + mov eax, mapname + + mov ecx, 53F990h + call ecx + + add esp, 4h + pop ecx + } + } + + void R_SetSunFromDvars(sunflare_t* sun) + { + __asm + { + push esi + mov esi, sun + + mov eax, 53F6D0h + call ecx + + pop esi + } + } + void SV_KickClient(client_t* client, const char* reason) { __asm diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index f0d8cde0..b4005860 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -425,6 +425,9 @@ namespace Game typedef int(__cdecl * R_TextHeight_t)(Font* font); extern R_TextHeight_t R_TextHeight; + typedef void(__cdecl * R_FlushSun_t)(); + extern R_FlushSun_t R_FlushSun; + typedef void(__cdecl * Scr_ShutdownAllocNode_t)(); extern Scr_ShutdownAllocNode_t Scr_ShutdownAllocNode; @@ -641,6 +644,8 @@ namespace Game void MessageBox(std::string message, std::string title); unsigned int R_HashString(const char* string); + void R_LoadSunThroughDvars(const char* mapname, sunflare_t* sun); + void R_SetSunFromDvars(sunflare_t* sun); void SV_KickClient(client_t* client, const char* reason); void SV_KickClientError(client_t* client, std::string reason);