From 0c462c115265e741d4e4865c2cf127f0236ca63a Mon Sep 17 00:00:00 2001 From: Rackover Xiaochad Date: Sat, 6 Feb 2021 21:25:55 +0100 Subject: [PATCH 1/2] Fix device recovery issues on CODO maps >359 --- src/Components/Modules/Zones.cpp | 15 +++++++++++++++ src/Game/Structs.hpp | 13 +++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/Components/Modules/Zones.cpp b/src/Components/Modules/Zones.cpp index f47850ee..0db4cb9e 100644 --- a/src/Components/Modules/Zones.cpp +++ b/src/Components/Modules/Zones.cpp @@ -1655,6 +1655,21 @@ namespace Components image->delayLoadPixels = image359.loaded; image->name = image359.name; + // CODO makes use of additional enumerator values (9, 10, 11) that don't exist in IW4 + // We have to translate them. 9 is for Reflection probes, 11 is for Compass, 10 is for Lightmap + switch (image->category) + { + case 9: + image->category = Game::ImageCategory::IMG_CATEGORY_AUTO_GENERATED; + break; + case 10: + image->category = Game::ImageCategory::IMG_CATEGORY_LIGHTMAP; + break; + case 11: + image->category = Game::ImageCategory::IMG_CATEGORY_LOAD_FROM_FILE; + break; + } + // Used for later stuff (&image->delayLoadPixels)[1] = image359.pad3[1]; } diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 6636d28d..28e82bfe 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -98,6 +98,19 @@ namespace Game DVAR_FLAG_NONEXISTENT = 0xFFFFFFFF //no such dvar } dvar_flag; + enum ImageCategory : char + { + IMG_CATEGORY_UNKNOWN = 0x0, + IMG_CATEGORY_AUTO_GENERATED = 0x1, + IMG_CATEGORY_LIGHTMAP = 0x2, + IMG_CATEGORY_LOAD_FROM_FILE = 0x3, + IMG_CATEGORY_RAW = 0x4, + IMG_CATEGORY_FIRST_UNMANAGED = 0x5, + IMG_CATEGORY_WATER = 0x5, + IMG_CATEGORY_RENDERTARGET = 0x6, + IMG_CATEGORY_TEMP = 0x7, + } ; + enum DvarSetSource { DVAR_SOURCE_INTERNAL = 0x0, From 49a2fc8b70b6496f4a48330aea5f585f4be09903 Mon Sep 17 00:00:00 2001 From: Rackover Xiaochad Date: Sun, 7 Feb 2021 11:54:15 +0100 Subject: [PATCH 2/2] Fix 332+ maps aswell as 359+ --- src/Components/Modules/Zones.cpp | 43 +++++++++++++++++++++----------- src/Components/Modules/Zones.hpp | 1 + 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/Components/Modules/Zones.cpp b/src/Components/Modules/Zones.cpp index 0db4cb9e..16c22bff 100644 --- a/src/Components/Modules/Zones.cpp +++ b/src/Components/Modules/Zones.cpp @@ -1655,20 +1655,7 @@ namespace Components image->delayLoadPixels = image359.loaded; image->name = image359.name; - // CODO makes use of additional enumerator values (9, 10, 11) that don't exist in IW4 - // We have to translate them. 9 is for Reflection probes, 11 is for Compass, 10 is for Lightmap - switch (image->category) - { - case 9: - image->category = Game::ImageCategory::IMG_CATEGORY_AUTO_GENERATED; - break; - case 10: - image->category = Game::ImageCategory::IMG_CATEGORY_LIGHTMAP; - break; - case 11: - image->category = Game::ImageCategory::IMG_CATEGORY_LOAD_FROM_FILE; - break; - } + FixImageCategory(image); // Used for later stuff (&image->delayLoadPixels)[1] = image359.pad3[1]; @@ -1676,12 +1663,40 @@ namespace Components else { std::memcpy(buffer + 28, buffer + (size - 4), 4); + + Game::GfxImage* image = reinterpret_cast(buffer); + FixImageCategory(image); } } return result; } + void Zones::FixImageCategory(Game::GfxImage* image) { + // CODO makes use of additional enumerator values (9, 10, 11) that don't exist in IW4 + // We have to translate them. 9 is for Reflection probes, 11 is for Compass, 10 is for Lightmap + switch (image->category) + { + case 9: + image->category = Game::ImageCategory::IMG_CATEGORY_AUTO_GENERATED; + break; + case 10: + image->category = Game::ImageCategory::IMG_CATEGORY_LIGHTMAP; + break; + case 11: + image->category = Game::ImageCategory::IMG_CATEGORY_LOAD_FROM_FILE; + break; + } + + + if (image->category > 7 || image->category < 0) { + +#ifdef DEBUG + if (IsDebuggerPresent()) __debugbreak(); +#endif + } + } + bool Zones::LoadXAsset(bool atStreamStart, char* buffer, int size) { int count = 0; diff --git a/src/Components/Modules/Zones.hpp b/src/Components/Modules/Zones.hpp index f97fba5e..c38f4400 100644 --- a/src/Components/Modules/Zones.hpp +++ b/src/Components/Modules/Zones.hpp @@ -100,5 +100,6 @@ namespace Components static void LoadMaterialAsset(Game::Material** asset); static void LoadTracerDef(bool atStreamStart, Game::TracerDef* tracer, int size); static void LoadTracerDefFxEffect(); + static void FixImageCategory(Game::GfxImage* image); }; }