diff --git a/src/Features/TerrainHelper.cpp b/src/Features/TerrainHelper.cpp index 413540a210..b7266ab4aa 100644 --- a/src/Features/TerrainHelper.cpp +++ b/src/Features/TerrainHelper.cpp @@ -71,10 +71,10 @@ bool TerrainHelper::TESObjectLAND_SetupMaterial(RE::TESObjectLAND* land) std::array textureSets; auto defTexture = land->loadedData->defQuadTextures[quadI]; if (defTexture != nullptr && defTexture->formID != 0) { - textureSets[0] = defTexture->textureSet; + textureSets[0] = Util::GetSeasonalSwap(defTexture->textureSet); } else { // this is a default texture - textureSets[0] = defaultLandTexture; + textureSets[0] = Util::GetSeasonalSwap(defaultLandTexture); } for (uint32_t textureI = 0; textureI < 5; ++textureI) { auto curTexture = land->loadedData->quadTextures[quadI][textureI]; @@ -85,9 +85,9 @@ bool TerrainHelper::TESObjectLAND_SetupMaterial(RE::TESObjectLAND* land) if (curTexture->formID == 0) { // this is a default texture - textureSets[textureI + 1] = defaultLandTexture; + textureSets[textureI + 1] = Util::GetSeasonalSwap(defaultLandTexture); } else { - textureSets[textureI + 1] = land->loadedData->quadTextures[quadI][textureI]->textureSet; + textureSets[textureI + 1] = Util::GetSeasonalSwap(land->loadedData->quadTextures[quadI][textureI]->textureSet); } } diff --git a/src/Hooks.cpp b/src/Hooks.cpp index 06380bd758..05a7771fbe 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -806,6 +806,8 @@ namespace Hooks { static bool thunk(RE::TESObjectLAND* land) { + bool vanillaResult = func(land); + // setup material for PBR auto TruePBRSingleton = globals::truePBR; if (TruePBRSingleton->TESObjectLAND_SetupMaterial(land)) { @@ -813,8 +815,6 @@ namespace Hooks return true; } - bool vanillaResult = func(land); - // setup material for terrain helper auto terrainHelper = globals::features::terrainHelper; if (vanillaResult && terrainHelper->loaded) { diff --git a/src/TruePBR.cpp b/src/TruePBR.cpp index bb02c35e24..e82daf3f19 100644 --- a/src/TruePBR.cpp +++ b/src/TruePBR.cpp @@ -1059,13 +1059,13 @@ void SetupLandscapeTexture(BSLightingShaderMaterialPBRLandscape& material, RE::T return; } - auto textureSet = landTexture.textureSet; + auto textureSet = Util::GetSeasonalSwap(landTexture.textureSet); if (textureSet == nullptr) { return; } auto truePBR = globals::truePBR; - auto* textureSetData = truePBR->GetPBRTextureSetData(landTexture.textureSet); + auto* textureSetData = truePBR->GetPBRTextureSetData(textureSet); const bool isPbr = textureSetData != nullptr; textureSets[textureIndex] = textureSetData; @@ -1099,7 +1099,7 @@ bool TruePBR::TESObjectLAND_SetupMaterial(RE::TESObjectLAND* land) if (land->loadedData != nullptr) { for (uint32_t quadIndex = 0; quadIndex < 4; ++quadIndex) { if (land->loadedData->defQuadTextures[quadIndex] != nullptr) { - if (singleton->IsPBRTextureSet(land->loadedData->defQuadTextures[quadIndex]->textureSet)) { + if (singleton->IsPBRTextureSet(Util::GetSeasonalSwap(land->loadedData->defQuadTextures[quadIndex]->textureSet))) { isPbr = true; break; } @@ -1108,7 +1108,7 @@ bool TruePBR::TESObjectLAND_SetupMaterial(RE::TESObjectLAND* land) } for (uint32_t textureIndex = 0; textureIndex < 6; ++textureIndex) { if (land->loadedData->quadTextures[quadIndex][textureIndex] != nullptr) { - if (singleton->IsPBRTextureSet(land->loadedData->quadTextures[quadIndex][textureIndex]->textureSet)) { + if (singleton->IsPBRTextureSet(Util::GetSeasonalSwap(land->loadedData->quadTextures[quadIndex][textureIndex]->textureSet))) { isPbr = true; break; } diff --git a/src/Utils/Game.cpp b/src/Utils/Game.cpp index 5030cf9c78..7ad5ce6c13 100644 --- a/src/Utils/Game.cpp +++ b/src/Utils/Game.cpp @@ -182,4 +182,19 @@ namespace Util { return IsNewFrame(globals::state->frameCount); } + + RE::BGSTextureSet* GetSeasonalSwap(RE::BGSTextureSet* textureSet) + { + if (textureSet == nullptr) { + return nullptr; + } + + if (textureSet->pad12C > 0) { + if (auto* form = RE::TESForm::LookupByID(textureSet->pad12C)) { + return form; + } + } + + return textureSet; + } } // namespace Util diff --git a/src/Utils/Game.h b/src/Utils/Game.h index 1e1479434e..6b5bf09fba 100644 --- a/src/Utils/Game.h +++ b/src/Utils/Game.h @@ -77,4 +77,19 @@ namespace Util } bool IsNewFrame(); }; + + /** + * @brief Retrieves the seasonal texture swap for a given texture set, if available. + * + * This function checks if a given texture set has been swapped by Seasons of Skyrim. + * If swapped, pad12C will be > 0 and will be the formid of the swapped texture set. + * + * @param textureSet Pointer to the original BGSTextureSet to check for seasonal swaps. + * Can be nullptr. + * + * @return Pointer to the seasonal swap texture set if found and valid, otherwise + * returns the original textureSet parameter. Returns nullptr if the input + * textureSet is nullptr. + */ + [[nodiscard]] RE::BGSTextureSet* GetSeasonalSwap(RE::BGSTextureSet* textureSet); } // namespace Util