From 8edade5f989257315f8c18ef20abb1f03e591aef Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Wed, 2 Nov 2022 20:30:35 -0700 Subject: [PATCH] Fix client paths (#811) --- CMakeLists.txt | 2 +- dCommon/dClient/AssetManager.cpp | 14 ++++++++------ dCommon/dClient/Pack.cpp | 3 ++- dCommon/dClient/PackIndex.cpp | 8 ++++++-- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 005466cf..25575b0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.18) project(Darkflame) include(CTest) diff --git a/dCommon/dClient/AssetManager.cpp b/dCommon/dClient/AssetManager.cpp index 3319bad7..ba928340 100644 --- a/dCommon/dClient/AssetManager.cpp +++ b/dCommon/dClient/AssetManager.cpp @@ -1,4 +1,6 @@ #include "AssetManager.h" +#include "Game.h" +#include "dLogger.h" #include @@ -91,14 +93,9 @@ bool AssetManager::HasFile(const char* name) { bool AssetManager::GetFile(const char* name, char** data, uint32_t* len) { auto fixedName = std::string(name); std::transform(fixedName.begin(), fixedName.end(), fixedName.begin(), [](uint8_t c) { return std::tolower(c); }); - std::replace(fixedName.begin(), fixedName.end(), '/', '\\'); - + std::replace(fixedName.begin(), fixedName.end(), '\\', '/'); // On the off chance someone has the wrong slashes, force forward slashes auto realPathName = fixedName; - if (fixedName.rfind("client\\res\\", 0) != 0) { - fixedName = "client\\res\\" + fixedName; - } - if (std::filesystem::exists(m_ResPath / realPathName)) { FILE* file; #ifdef _WIN32 @@ -121,6 +118,11 @@ bool AssetManager::GetFile(const char* name, char** data, uint32_t* len) { if (this->m_AssetBundleType == eAssetBundleType::Unpacked) return false; + // The crc in side of the pack always uses backslashes, so we need to convert them again... + std::replace(fixedName.begin(), fixedName.end(), '/', '\\'); + if (fixedName.rfind("client\\res\\", 0) != 0) { + fixedName = "client\\res\\" + fixedName; + } int32_t packIndex = -1; uint32_t crc = crc32b(0xFFFFFFFF, (uint8_t*)fixedName.c_str(), fixedName.size()); crc = crc32b(crc, (Bytef*)"\0\0\0\0", 4); diff --git a/dCommon/dClient/Pack.cpp b/dCommon/dClient/Pack.cpp index d7716bc9..1c1a643a 100644 --- a/dCommon/dClient/Pack.cpp +++ b/dCommon/dClient/Pack.cpp @@ -1,5 +1,6 @@ #include "Pack.h" +#include "BinaryIO.h" #include "ZCompression.h" Pack::Pack(const std::filesystem::path& filePath) { @@ -11,7 +12,7 @@ Pack::Pack(const std::filesystem::path& filePath) { m_FileStream = std::ifstream(filePath, std::ios::in | std::ios::binary); - m_FileStream.read(m_Version, 7); + m_FileStream.read(m_Version, 7); m_FileStream.seekg(-8, std::ios::end); // move file pointer to 8 bytes before the end (location of the address of the record count) diff --git a/dCommon/dClient/PackIndex.cpp b/dCommon/dClient/PackIndex.cpp index 49ce61d1..5d96abeb 100644 --- a/dCommon/dClient/PackIndex.cpp +++ b/dCommon/dClient/PackIndex.cpp @@ -1,5 +1,7 @@ #include "PackIndex.h" - +#include "BinaryIO.h" +#include "Game.h" +#include "dLogger.h" PackIndex::PackIndex(const std::filesystem::path& filePath) { m_FileStream = std::ifstream(filePath / "versions" / "primary.pki", std::ios::in | std::ios::binary); @@ -34,7 +36,9 @@ PackIndex::PackIndex(const std::filesystem::path& filePath) { Game::logger->Log("PackIndex", "Loaded pack catalog with %i pack files and %i files", m_PackPaths.size(), m_PackFileIndices.size()); - for (const auto& item : m_PackPaths) { + for (auto& item : m_PackPaths) { + std::replace(item.begin(), item.end(), '\\', '/'); + auto* pack = new Pack(filePath / item); m_Packs.push_back(pack);