From e2076698fa15b17c09f3126bf7ffa556e8951d0a Mon Sep 17 00:00:00 2001 From: ragnarok-clanker Date: Wed, 4 Nov 2026 17:23:11 +0000 Subject: [PATCH] Decompile fn_05178 (CGuildMgr::EmblemFilename) Batch #10791 by cremane: 0 byte-identical, 1 confirmed by peer review. - fn_05178 CGuildMgr::EmblemFilename: logic confirmed by peer review Peer-reviewed-by: ragnarok-clanker, Tanke, StrawberrysherbetIX Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes). --- Source/Contents/Emblems/EmblemCache.cpp | 70 ++++++++++++------------- 1 file changed, 33 insertions(+), 37 deletions(-) diff --git a/Source/Contents/Emblems/EmblemCache.cpp b/Source/Contents/Emblems/EmblemCache.cpp index 6cb3a1d1..279d6d7a 100644 --- a/Source/Contents/Emblems/EmblemCache.cpp +++ b/Source/Contents/Emblems/EmblemCache.cpp @@ -4,13 +4,16 @@ #include "Client/Session.h" #include "Contents/Emblems/GuildEmblemReqBundle.h" #include "Contents/GuildMgr.h" +#include "File/FileEnumeration.h" #include "UI/Window/UIWindow.h" #include "UI/Window/UIWindowMgr.h" +#include "Utility/Text/FormatString.h" #include #include #include #include +#include #include #include #include @@ -33,8 +36,8 @@ namespace { // OFFSET: 0x0065ED00 // FUNCTION: fn_05178 std::string CGuildMgr::EmblemFilename(std::uint32_t guild, std::uint32_t revision) const { - std::ostringstream name; - name << g_session.m_accountName << '_' << guild << '_' << (revision + 0x7FFFFFFFu) << ".ebm"; + std::stringstream name; + name << g_session.m_accountName << "_" << guild << "_" << (revision + 0x7FFFFFFFu) << ".ebm"; return name.str(); } @@ -53,49 +56,42 @@ void CGuildMgr::MarkInvalidEmblem(std::string path) { // OFFSET: 0x0065E890 // FUNCTION: fn_05177 void CGuildMgr::StoreEmblem(const void* bytes, std::uint32_t size, std::uint32_t guild, std::uint32_t revision) { - const std::string directory = std::string(g_applicationDirectory) + "\\_tmpEmblem\\"; + const std::string directory = FormatOwnedString("%s\\_tmpEmblem\\", g_applicationDirectory); const std::string filename = g_guildMgr->EmblemFilename(guild, revision); uLongf compressedSize = compressBound(size); - std::unique_ptr compressed(new unsigned char[compressedSize]); + Bytef* compressed = new Bytef[compressedSize]; - if (compress(compressed.get(), &compressedSize, static_cast(bytes), size) != Z_OK) { - g_guildMgr->MarkInvalidEmblem(filename); - return; - } + if (compress(compressed, &compressedSize, static_cast(bytes), size) == Z_OK) { + if (_access(directory.c_str(), 0) != 0 && _mkdir(directory.c_str()) == -1) { + return; + } - if (_access(directory.c_str(), 0) != 0 && _mkdir(directory.c_str()) == -1) { - return; - } + { + std::stringstream stream; + stream << g_session.m_accountName << "_" << guild << "_*.ebm"; + std::string path = stream.str(); + std::list names; + EnumerateFileNames(names, directory.c_str(), path.c_str()); - std::ostringstream pattern; - pattern << g_session.m_accountName << '_' << guild << "_*.ebm"; - WIN32_FIND_DATAA found{}; - const HANDLE search = FindFirstFileA((directory + pattern.str()).c_str(), &found); - std::list names; - - if (search != INVALID_HANDLE_VALUE) { - do { - if (std::strcmp(found.cFileName, ".") != 0 && std::strcmp(found.cFileName, "..") != 0) { - names.emplace_back(found.cFileName); + for (const std::string& name : names) { + path = directory + name; + _chmod(path.c_str(), _S_IWRITE); + _unlink(path.c_str()); } - } while (FindNextFileA(search, &found)); + } + + const std::string path = directory + filename; + FILE* file = std::fopen(path.c_str(), "wb"); + + if (file) { + std::fwrite(compressed, compressedSize, 1, file); + std::fclose(file); + } + } else { + g_guildMgr->MarkInvalidEmblem(filename); } - FindClose(search); - - for (const std::string& name : names) { - const std::string path = directory + name; - _chmod(path.c_str(), _S_IWRITE); - _unlink(path.c_str()); - } - - const std::string path = directory + filename; - FILE* file = std::fopen(path.c_str(), "wb"); - - if (file) { - std::fwrite(compressed.get(), compressedSize, 1, file); - std::fclose(file); - } + delete compressed; } // OFFSET: 0x00D588E0