Fix client paths (#811)

This commit is contained in:
David Markowitz 2022-11-02 20:30:35 -07:00 committed by GitHub
parent 353c328485
commit 8edade5f98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 10 deletions

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.14) cmake_minimum_required(VERSION 3.18)
project(Darkflame) project(Darkflame)
include(CTest) include(CTest)

View File

@ -1,4 +1,6 @@
#include "AssetManager.h" #include "AssetManager.h"
#include "Game.h"
#include "dLogger.h"
#include <zlib.h> #include <zlib.h>
@ -91,14 +93,9 @@ bool AssetManager::HasFile(const char* name) {
bool AssetManager::GetFile(const char* name, char** data, uint32_t* len) { bool AssetManager::GetFile(const char* name, char** data, uint32_t* len) {
auto fixedName = std::string(name); auto fixedName = std::string(name);
std::transform(fixedName.begin(), fixedName.end(), fixedName.begin(), [](uint8_t c) { return std::tolower(c); }); 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; auto realPathName = fixedName;
if (fixedName.rfind("client\\res\\", 0) != 0) {
fixedName = "client\\res\\" + fixedName;
}
if (std::filesystem::exists(m_ResPath / realPathName)) { if (std::filesystem::exists(m_ResPath / realPathName)) {
FILE* file; FILE* file;
#ifdef _WIN32 #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; 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; int32_t packIndex = -1;
uint32_t crc = crc32b(0xFFFFFFFF, (uint8_t*)fixedName.c_str(), fixedName.size()); uint32_t crc = crc32b(0xFFFFFFFF, (uint8_t*)fixedName.c_str(), fixedName.size());
crc = crc32b(crc, (Bytef*)"\0\0\0\0", 4); crc = crc32b(crc, (Bytef*)"\0\0\0\0", 4);

View File

@ -1,5 +1,6 @@
#include "Pack.h" #include "Pack.h"
#include "BinaryIO.h"
#include "ZCompression.h" #include "ZCompression.h"
Pack::Pack(const std::filesystem::path& filePath) { Pack::Pack(const std::filesystem::path& filePath) {

View File

@ -1,5 +1,7 @@
#include "PackIndex.h" #include "PackIndex.h"
#include "BinaryIO.h"
#include "Game.h"
#include "dLogger.h"
PackIndex::PackIndex(const std::filesystem::path& filePath) { PackIndex::PackIndex(const std::filesystem::path& filePath) {
m_FileStream = std::ifstream(filePath / "versions" / "primary.pki", std::ios::in | std::ios::binary); 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()); 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); auto* pack = new Pack(filePath / item);
m_Packs.push_back(pack); m_Packs.push_back(pack);