Skip to content

Commit

Permalink
Fix client paths (#811)
Browse files Browse the repository at this point in the history
  • Loading branch information
EmosewaMC authored Nov 3, 2022
1 parent 353c328 commit 8edade5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.14)
cmake_minimum_required(VERSION 3.18)
project(Darkflame)
include(CTest)

Expand Down
14 changes: 8 additions & 6 deletions dCommon/dClient/AssetManager.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "AssetManager.h"
#include "Game.h"
#include "dLogger.h"

#include <zlib.h>

Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion dCommon/dClient/Pack.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Pack.h"

#include "BinaryIO.h"
#include "ZCompression.h"

Pack::Pack(const std::filesystem::path& filePath) {
Expand All @@ -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)

Expand Down
8 changes: 6 additions & 2 deletions dCommon/dClient/PackIndex.cpp
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8edade5

Please sign in to comment.