Skip to content

Commit

Permalink
Fixed loading presets and loading morphs from cosave, added support f…
Browse files Browse the repository at this point in the history
…or ESL
  • Loading branch information
expired6978 committed Nov 1, 2017
1 parent 6cefb80 commit 54c118f
Show file tree
Hide file tree
Showing 7 changed files with 312 additions and 199 deletions.
12 changes: 5 additions & 7 deletions skee/BodyMorphInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,18 @@ void BodyMorphInterface::LoadMods()
if (dataHandler)
{
std::string fixedPath = "Meshes\\" + std::string(MORPH_MOD_DIRECTORY);
UInt8 modCount = dataHandler->modList.loadedMods.count;
for (UInt32 i = 0; i < modCount; i++)

ForEachMod([&](ModInfo * modInfo)
{
ModInfo * modInfo = dataHandler->modList.loadedMods[i];
std::string templatesPath = fixedPath + std::string(modInfo->name) + "\\templates.ini";
ReadBodyMorphTemplates(templatesPath.c_str());
}
});

for (UInt32 i = 0; i < modCount; i++)
ForEachMod([&](ModInfo * modInfo)
{
ModInfo * modInfo = dataHandler->modList.loadedMods[i];
std::string morphsPath = fixedPath + std::string(modInfo->name) + "\\morphs.ini";
ReadBodyMorphs(morphsPath.c_str());
}
});
}
}

Expand Down
81 changes: 81 additions & 0 deletions skee/FileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,84 @@ BGSHeadPart * GetHeadPartByName(std::string & headPartName)

return NULL;
}

ModInfo* GetModInfoByFormID(UInt32 formId, bool allowLight)
{
DataHandler * dataHandler = DataHandler::GetSingleton();

UInt8 modIndex = formId >> 24;
UInt16 lightIndex = ((formId >> 12) & 0xFFF);

ModInfo* modInfo = nullptr;
if (modIndex == 0xFE && allowLight) {
if (lightIndex < dataHandler->modList.loadedCCMods.count)
dataHandler->modList.loadedCCMods.GetNthItem(lightIndex, modInfo);
} else {
if(modIndex < 0xFE)
dataHandler->modList.loadedMods.GetNthItem(modIndex, modInfo);
}

return modInfo;
}

std::string GetFormIdentifier(TESForm * form)
{
char formName[MAX_PATH];
UInt8 modIndex = form->formID >> 24;
UInt32 modForm = form->formID & 0xFFFFFF;

ModInfo* modInfo = nullptr;
if (modIndex == 0xFE)
{
UInt16 lightIndex = (form->formID >> 12) & 0xFFF;
if (lightIndex < (*g_dataHandler)->modList.loadedCCMods.count)
modInfo = (*g_dataHandler)->modList.loadedCCMods[lightIndex];
}
else
{
modInfo = (*g_dataHandler)->modList.loadedMods[modIndex];
}

if (modInfo) {
sprintf_s(formName, "%s|%06X", modInfo->name, modForm);
}

return formName;
}

TESForm * GetFormFromIdentifier(const std::string & formIdentifier)
{
std::size_t pos = formIdentifier.find_first_of('|');
std::string modName = formIdentifier.substr(0, pos);
std::string modForm = formIdentifier.substr(pos + 1);

UInt32 formId = 0;
sscanf_s(modForm.c_str(), "%X", &formId);

UInt8 modIndex = (*g_dataHandler)->GetLoadedModIndex(modName.c_str());
if (modIndex != 0xFF) {
formId |= ((UInt32)modIndex) << 24;
}
else
{
UInt16 lightModIndex = (*g_dataHandler)->GetLoadedLightModIndex(modName.c_str());
if (lightModIndex != 0xFFFF) {
formId |= 0xFE000000 | (UInt32(lightModIndex) << 12);
}
}

return LookupFormByID(formId);
}

void ForEachMod(std::function<void(ModInfo *)> functor)
{
for (UInt32 i = 0; i < (*g_dataHandler)->modList.loadedMods.count; i++)
{
functor((*g_dataHandler)->modList.loadedMods[i]);
}

for (UInt32 i = 0; i < (*g_dataHandler)->modList.loadedCCMods.count; i++)
{
functor((*g_dataHandler)->modList.loadedCCMods[i]);
}
}
10 changes: 9 additions & 1 deletion skee/FileUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class TESRace;
class BGSHeadPart;
class BSResourceNiBinaryStream;
struct ModInfo;

namespace std {
extern inline std::string &ltrim(std::string &s);
Expand All @@ -25,4 +26,11 @@ bool BSReadLine(BSResourceNiBinaryStream* fin, std::string* str);
void BSReadAll(BSResourceNiBinaryStream* fin, std::string* str);

TESRace * GetRaceByName(std::string & raceName);
BGSHeadPart * GetHeadPartByName(std::string & headPartName);
BGSHeadPart * GetHeadPartByName(std::string & headPartName);

ModInfo* GetModInfoByFormID(UInt32 formId, bool allowLight = true);

std::string GetFormIdentifier(TESForm * form);
TESForm * GetFormFromIdentifier(const std::string & formIdentifier);

void ForEachMod(std::function<void(ModInfo *)> functor);
Loading

0 comments on commit 54c118f

Please sign in to comment.