Fallback to default shader when a non-shader form is set in INI
This commit is contained in:
parent
f6fda7cdf0
commit
394036d849
@ -32,11 +32,11 @@ void EventListener::Install()
|
|||||||
|
|
||||||
LoadINI(&settings, std::format("Data/SKSE/Plugins/{}.ini", SKSE::PluginDeclaration::GetSingleton()->GetName()).c_str());
|
LoadINI(&settings, std::format("Data/SKSE/Plugins/{}.ini", SKSE::PluginDeclaration::GetSingleton()->GetName()).c_str());
|
||||||
|
|
||||||
RE::TESEffectShader* defaultShader = RE::TESForm::LookupByID<RE::TESEffectShader>(0xC5EF7);
|
RE::TESEffectShader* defaultShader = RE::TESForm::LookupByID<RE::TESEffectShader>(0xB6BF9);
|
||||||
|
|
||||||
EventListener::regularBookShader = retrieveFormByString(std::any_cast<std::string>(settings["sRegularBookShader"]), defaultShader)->As<RE::TESEffectShader>();
|
EventListener::regularBookShader = retrieveFormByString<RE::TESEffectShader>(std::any_cast<std::string>(settings["sRegularBookShader"]), defaultShader);
|
||||||
EventListener::spellBookShader = retrieveFormByString(std::any_cast<std::string>(settings["sSpellBookShader"]), defaultShader)->As<RE::TESEffectShader>();
|
EventListener::spellBookShader = retrieveFormByString<RE::TESEffectShader>(std::any_cast<std::string>(settings["sSpellBookShader"]), defaultShader);
|
||||||
EventListener::skillBookShader = retrieveFormByString(std::any_cast<std::string>(settings["sSkillBookShader"]), defaultShader)->As<RE::TESEffectShader>();
|
EventListener::skillBookShader = retrieveFormByString<RE::TESEffectShader>(std::any_cast<std::string>(settings["sSkillBookShader"]), defaultShader);
|
||||||
|
|
||||||
if (EventListener::bEnderalMode = RE::TESDataHandler::GetSingleton()->GetModIndex("Enderal - Forgotten Stories.esm") != std::nullopt) {
|
if (EventListener::bEnderalMode = RE::TESDataHandler::GetSingleton()->GetModIndex("Enderal - Forgotten Stories.esm") != std::nullopt) {
|
||||||
logger::info("Detected Enderal SE, learning books will be highlighted as well");
|
logger::info("Detected Enderal SE, learning books will be highlighted as well");
|
||||||
|
17
src/Util.h
17
src/Util.h
@ -61,7 +61,8 @@ inline void ClearOldShaders()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
inline RE::TESForm* retrieveFormByString(std::string a_str, RE::TESForm* a_defaultForm)
|
template <class T>
|
||||||
|
inline T* retrieveFormByString(std::string a_str, T* defaultForm)
|
||||||
{
|
{
|
||||||
int pos = a_str.find_first_of('@');
|
int pos = a_str.find_first_of('@');
|
||||||
std::string sHex = a_str.substr(pos + 1),
|
std::string sHex = a_str.substr(pos + 1),
|
||||||
@ -72,14 +73,14 @@ inline RE::TESForm* retrieveFormByString(std::string a_str, RE::TESForm* a_defau
|
|||||||
ss << std::hex << sHex;
|
ss << std::hex << sHex;
|
||||||
ss >> id;
|
ss >> id;
|
||||||
|
|
||||||
RE::TESForm* result = RE::TESDataHandler::GetSingleton()->LookupForm(id, sFilename);
|
RE::TESForm* form = RE::TESDataHandler::GetSingleton()->LookupForm(id, sFilename);
|
||||||
|
T* result = form ? form->As<T>() : nullptr;
|
||||||
if (!result) {
|
|
||||||
logger::error("Unable to retrieve {}, using default value", a_str);
|
|
||||||
return a_defaultForm;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (result) {
|
||||||
logger::info("Successfully retrieved {}", a_str);
|
logger::info("Successfully retrieved {}", a_str);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger::error("Unable to retrieve {}, using default value", a_str);
|
||||||
|
return defaultForm;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user