diff --git a/Source/Contents/SkinCatalog.cpp b/Source/Contents/SkinCatalog.cpp new file mode 100644 index 00000000..8e7560ea --- /dev/null +++ b/Source/Contents/SkinCatalog.cpp @@ -0,0 +1,111 @@ +#include "Contents/SkinMgr.h" +#include "Network/TextEncoding.h" +#include "Utility/Text/GroupedInteger.h" + +#include +#include +#include + +// GLOBAL: gl_24533 +const char* g_skinDirectoryPrefix = "..\\..\\skin\\"; +// GLOBAL: gl_24534 +const char* g_skinArchivePrefix = "..\\..\\_tmpskin_\\"; + +// OFFSET: 0x007E1120 +// FUNCTION: fn_09689 +void CSkinMgr::Refresh() { + this->prefixes.clear(); + this->names.clear(); + this->archives.clear(); + this->selected = -1; + + WIN32_FIND_DATAA findData; + std::memset(&findData, 0, sizeof(findData)); + HANDLE find = FindFirstFileA(".\\skin\\*.*", &findData); + if (find == INVALID_HANDLE_VALUE) { + FindClose(find); + return; + } + + const std::string current = "."; + const std::string parent = ".."; + int index = 0; + + if (current != findData.cFileName && parent != findData.cFileName && (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { + std::string path = g_skinDirectoryPrefix; + path += findData.cFileName; + path += "\\"; + this->prefixes.push_back(path.c_str()); + this->names.push_back(findData.cFileName); + this->archives.push_back(0); + this->prepared.push_back(0); + + if (this->m_name == findData.cFileName) { + this->selected = index; + } + ++index; + } else if (current != findData.cFileName && parent != findData.cFileName) { + std::string extension = ReverseFindChar(findData.cFileName, '.'); + LowercaseText(extension); + + if (extension == ".zip") { + std::string path = g_skinArchivePrefix; + path += findData.cFileName; + path.resize(path.size() - 4); + path += "\\"; + this->prefixes.push_back(path.c_str()); + + std::string name = findData.cFileName; + name.resize(name.size() - 4); + this->names.push_back(name.c_str()); + this->archives.push_back(1); + this->prepared.push_back(0); + + if (this->m_name == name) { + this->selected = index; + } + ++index; + } + } + + while (FindNextFileA(find, &findData)) { + if (current != findData.cFileName && parent != findData.cFileName && (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { + std::string path = g_skinDirectoryPrefix; + path += findData.cFileName; + path += "\\"; + this->prefixes.push_back(path.c_str()); + this->names.push_back(findData.cFileName); + this->archives.push_back(0); + this->prepared.push_back(0); + + if (this->m_name == findData.cFileName) { + this->selected = index; + } + ++index; + } else if (current != findData.cFileName && parent != findData.cFileName) { + std::string extension = ReverseFindChar(findData.cFileName, '.'); + LowercaseText(extension); + + if (extension == ".zip") { + std::string path = g_skinArchivePrefix; + path += findData.cFileName; + path.resize(path.size() - 4); + path += "\\"; + this->prefixes.push_back(path.c_str()); + + std::string name = findData.cFileName; + name.resize(name.size() - 4); + this->names.push_back(name.c_str()); + this->archives.push_back(1); + this->prepared.push_back(0); + + if (this->m_name == name) { + this->selected = index; + } + ++index; + } + } + } + + FindClose(find); +} diff --git a/Source/Contents/SkinInfo.cpp b/Source/Contents/SkinInfo.cpp index 711a42b4..83d08c97 100644 --- a/Source/Contents/SkinInfo.cpp +++ b/Source/Contents/SkinInfo.cpp @@ -1,4 +1,5 @@ #include "Contents/SkinMgr.h" +#include "Resource/ResourceMgr.h" #include #include @@ -11,6 +12,16 @@ bool CSkinMgr::Selected() const { return this->selected > -1; } +// OFFSET: 0x007E2140 +// FUNCTION: fn_09691 +void CSkinMgr::Select(int index) { + const int previous = this->selected; + this->selected = index; + if (previous != index) { + ResourceMgr::Instance().ClearUnused("bmp"); + } +} + // OFFSET: 0x007E1020 // FUNCTION: fn_09686 const char* CSkinMgr::Name() const { diff --git a/Source/Contents/SkinMgr.h b/Source/Contents/SkinMgr.h index cc1848f7..7ece54b5 100644 --- a/Source/Contents/SkinMgr.h +++ b/Source/Contents/SkinMgr.h @@ -21,10 +21,12 @@ public: CSkinMgr(); bool Selected() const; + void Select(int index); const char* Prefix() const; const char* Name() const; const char* Name(int index) const; void Prepare(); + void Refresh(); }; #if defined(_WIN32) && !defined(_WIN64) diff --git a/data/compile.json b/data/compile.json index 0ed6d92f..b8ac9a6e 100644 --- a/data/compile.json +++ b/data/compile.json @@ -421,6 +421,7 @@ "Source/Contents/Skills/SkillLevelConfig.cpp": 4, "Source/Contents/Skills/SkillLevelRegistry.cpp": 4, "Source/Contents/Skills/SkillTreeScript.cpp": 4, + "Source/Contents/SkinCatalog.cpp": 4, "Source/Contents/SkinInfo.cpp": 3, "Source/Contents/SkinMgr.cpp": 4, "Source/Contents/Sound/SoundConfiguration.cpp": 4,