mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-04 09:44:10 +00:00
Add support for packed clients (#802)
* First iteration of pack reader and interface * Fix memory leak and remove logs * Complete packed asset interface and begin on file loading replacement * Implement proper BinaryIO error * Improve AssetMemoryBuffer for reading and implement more reading * Repair more file loading code and improve how navmeshes are loaded * Missing checks implementation * Revert addition of Manifest class and migration changes * Resolved all feedback.
This commit is contained in:
@@ -13,17 +13,22 @@
|
||||
#include "EntityManager.h"
|
||||
#include "CDFeatureGatingTable.h"
|
||||
#include "CDClientManager.h"
|
||||
#include "AssetManager.h"
|
||||
|
||||
Level::Level(Zone* parentZone, const std::string& filepath) {
|
||||
m_ParentZone = parentZone;
|
||||
std::ifstream file(filepath, std::ios_base::in | std::ios_base::binary);
|
||||
if (file) {
|
||||
ReadChunks(file);
|
||||
} else {
|
||||
|
||||
auto buffer = Game::assetManager->GetFileAsBuffer(filepath.c_str());
|
||||
|
||||
if (!buffer.m_Success) {
|
||||
Game::logger->Log("Level", "Failed to load %s", filepath.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
file.close();
|
||||
std::istream file(&buffer);
|
||||
ReadChunks(file);
|
||||
|
||||
buffer.close();
|
||||
}
|
||||
|
||||
Level::~Level() {
|
||||
@@ -41,7 +46,7 @@ const void Level::PrintAllObjects() {
|
||||
}
|
||||
}
|
||||
|
||||
void Level::ReadChunks(std::ifstream& file) {
|
||||
void Level::ReadChunks(std::istream& file) {
|
||||
const uint32_t CHNK_HEADER = ('C' + ('H' << 8) + ('N' << 16) + ('K' << 24));
|
||||
|
||||
while (!file.eof()) {
|
||||
@@ -139,7 +144,7 @@ void Level::ReadChunks(std::ifstream& file) {
|
||||
}
|
||||
}
|
||||
|
||||
void Level::ReadFileInfoChunk(std::ifstream& file, Header& header) {
|
||||
void Level::ReadFileInfoChunk(std::istream& file, Header& header) {
|
||||
FileInfoChunk* fi = new FileInfoChunk;
|
||||
BinaryIO::BinaryRead(file, fi->version);
|
||||
BinaryIO::BinaryRead(file, fi->revision);
|
||||
@@ -152,7 +157,7 @@ void Level::ReadFileInfoChunk(std::ifstream& file, Header& header) {
|
||||
if (header.fileInfo->revision == 3452816845 && m_ParentZone->GetZoneID().GetMapID() == 1100) header.fileInfo->revision = 26;
|
||||
}
|
||||
|
||||
void Level::ReadSceneObjectDataChunk(std::ifstream& file, Header& header) {
|
||||
void Level::ReadSceneObjectDataChunk(std::istream& file, Header& header) {
|
||||
SceneObjectDataChunk* chunk = new SceneObjectDataChunk;
|
||||
uint32_t objectsCount = 0;
|
||||
BinaryIO::BinaryRead(file, objectsCount);
|
||||
|
@@ -67,7 +67,7 @@ private:
|
||||
Zone* m_ParentZone;
|
||||
|
||||
//private functions:
|
||||
void ReadChunks(std::ifstream& file);
|
||||
void ReadFileInfoChunk(std::ifstream& file, Header& header);
|
||||
void ReadSceneObjectDataChunk(std::ifstream& file, Header& header);
|
||||
void ReadChunks(std::istream& file);
|
||||
void ReadFileInfoChunk(std::istream& file, Header& header);
|
||||
void ReadSceneObjectDataChunk(std::istream& file, Header& header);
|
||||
};
|
||||
|
@@ -7,6 +7,7 @@
|
||||
#include "GeneralUtils.h"
|
||||
#include "BinaryIO.h"
|
||||
|
||||
#include "AssetManager.h"
|
||||
#include "CDClientManager.h"
|
||||
#include "CDZoneTableTable.h"
|
||||
#include "Spawner.h"
|
||||
@@ -40,7 +41,8 @@ void Zone::LoadZoneIntoMemory() {
|
||||
m_ZonePath = m_ZoneFilePath.substr(0, m_ZoneFilePath.rfind('/') + 1);
|
||||
if (m_ZoneFilePath == "ERR") return;
|
||||
|
||||
std::ifstream file(m_ZoneFilePath, std::ios::binary);
|
||||
AssetMemoryBuffer buffer = Game::assetManager->GetFileAsBuffer(m_ZoneFilePath.c_str());
|
||||
std::istream file(&buffer);
|
||||
if (file) {
|
||||
BinaryIO::BinaryRead(file, m_ZoneFileFormatVersion);
|
||||
|
||||
@@ -144,17 +146,13 @@ void Zone::LoadZoneIntoMemory() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//m_PathData.resize(m_PathDataLength);
|
||||
//file.read((char*)&m_PathData[0], m_PathDataLength);
|
||||
}
|
||||
} else {
|
||||
Game::logger->Log("Zone", "Failed to open: %s", m_ZoneFilePath.c_str());
|
||||
}
|
||||
m_ZonePath = m_ZoneFilePath.substr(0, m_ZoneFilePath.rfind('/') + 1);
|
||||
|
||||
file.close();
|
||||
buffer.close();
|
||||
}
|
||||
|
||||
std::string Zone::GetFilePathForZoneID() {
|
||||
@@ -162,7 +160,7 @@ std::string Zone::GetFilePathForZoneID() {
|
||||
CDZoneTableTable* zoneTable = CDClientManager::Instance()->GetTable<CDZoneTableTable>("ZoneTable");
|
||||
const CDZoneTable* zone = zoneTable->Query(this->GetZoneID().GetMapID());
|
||||
if (zone != nullptr) {
|
||||
std::string toReturn = "./res/maps/" + zone->zoneName;
|
||||
std::string toReturn = "maps/" + zone->zoneName;
|
||||
std::transform(toReturn.begin(), toReturn.end(), toReturn.begin(), ::tolower);
|
||||
return toReturn;
|
||||
}
|
||||
@@ -222,7 +220,7 @@ const void Zone::PrintAllGameObjects() {
|
||||
}
|
||||
}
|
||||
|
||||
void Zone::LoadScene(std::ifstream& file) {
|
||||
void Zone::LoadScene(std::istream& file) {
|
||||
SceneRef scene;
|
||||
scene.level = nullptr;
|
||||
LWOSCENEID lwoSceneID(LWOZONEID_INVALID, 0);
|
||||
@@ -264,10 +262,17 @@ void Zone::LoadScene(std::ifstream& file) {
|
||||
|
||||
std::vector<LUTriggers::Trigger*> Zone::LoadLUTriggers(std::string triggerFile, LWOSCENEID sceneID) {
|
||||
std::vector<LUTriggers::Trigger*> lvlTriggers;
|
||||
std::ifstream file(m_ZonePath + triggerFile);
|
||||
|
||||
auto buffer = Game::assetManager->GetFileAsBuffer((m_ZonePath + triggerFile).c_str());
|
||||
|
||||
if (!buffer.m_Success) return lvlTriggers;
|
||||
|
||||
std::istream file(&buffer);
|
||||
std::stringstream data;
|
||||
data << file.rdbuf();
|
||||
|
||||
buffer.close();
|
||||
|
||||
if (data.str().size() == 0) return lvlTriggers;
|
||||
|
||||
tinyxml2::XMLDocument* doc = new tinyxml2::XMLDocument();
|
||||
@@ -336,7 +341,7 @@ const Path* Zone::GetPath(std::string name) const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Zone::LoadSceneTransition(std::ifstream& file) {
|
||||
void Zone::LoadSceneTransition(std::istream& file) {
|
||||
SceneTransition sceneTrans;
|
||||
if (m_ZoneFileFormatVersion < Zone::ZoneFileFormatVersion::Auramar) {
|
||||
uint8_t length;
|
||||
@@ -355,14 +360,14 @@ void Zone::LoadSceneTransition(std::ifstream& file) {
|
||||
m_SceneTransitions.push_back(sceneTrans);
|
||||
}
|
||||
|
||||
SceneTransitionInfo Zone::LoadSceneTransitionInfo(std::ifstream& file) {
|
||||
SceneTransitionInfo Zone::LoadSceneTransitionInfo(std::istream& file) {
|
||||
SceneTransitionInfo info;
|
||||
BinaryIO::BinaryRead(file, info.sceneID);
|
||||
BinaryIO::BinaryRead(file, info.position);
|
||||
return info;
|
||||
}
|
||||
|
||||
void Zone::LoadPath(std::ifstream& file) {
|
||||
void Zone::LoadPath(std::istream& file) {
|
||||
// Currently only spawner (type 4) paths are supported
|
||||
Path path = Path();
|
||||
|
||||
|
@@ -225,9 +225,9 @@ private:
|
||||
std::map<LWOSCENEID, uint32_t, mapCompareLwoSceneIDs> m_MapRevisions; //rhs is the revision!
|
||||
|
||||
//private ("helper") functions:
|
||||
void LoadScene(std::ifstream& file);
|
||||
void LoadScene(std::istream& file);
|
||||
std::vector<LUTriggers::Trigger*> LoadLUTriggers(std::string triggerFile, LWOSCENEID sceneID);
|
||||
void LoadSceneTransition(std::ifstream& file);
|
||||
SceneTransitionInfo LoadSceneTransitionInfo(std::ifstream& file);
|
||||
void LoadPath(std::ifstream& file);
|
||||
void LoadSceneTransition(std::istream& file);
|
||||
SceneTransitionInfo LoadSceneTransitionInfo(std::istream& file);
|
||||
void LoadPath(std::istream& file);
|
||||
};
|
||||
|
Reference in New Issue
Block a user