mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-24 14:37:25 +00:00
4a6f3e44ee
* 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.
59 lines
1.3 KiB
C++
59 lines
1.3 KiB
C++
#include "BinaryIO.h"
|
|
#include <string>
|
|
|
|
void BinaryIO::WriteString(const std::string& stringToWrite, std::ofstream& outstream) {
|
|
//BinaryWrite(outstream, uint32_t(stringToWrite.length()));
|
|
|
|
for (size_t i = 0; i < size_t(stringToWrite.length()); ++i) {
|
|
BinaryIO::BinaryWrite(outstream, stringToWrite[i]);
|
|
}
|
|
}
|
|
|
|
//For reading null-terminated strings
|
|
std::string BinaryIO::ReadString(std::istream& instream) {
|
|
std::string toReturn;
|
|
char buffer;
|
|
|
|
BinaryIO::BinaryRead(instream, buffer);
|
|
|
|
while (buffer != 0x00) {
|
|
toReturn += buffer;
|
|
BinaryRead(instream, buffer);
|
|
}
|
|
|
|
return toReturn;
|
|
}
|
|
|
|
//For reading strings of a specific size
|
|
std::string BinaryIO::ReadString(std::istream& instream, size_t size) {
|
|
std::string toReturn;
|
|
char buffer;
|
|
|
|
for (size_t i = 0; i < size; ++i) {
|
|
BinaryIO::BinaryRead(instream, buffer);
|
|
toReturn += buffer;
|
|
}
|
|
|
|
return toReturn;
|
|
}
|
|
|
|
std::string BinaryIO::ReadWString(std::istream& instream) {
|
|
size_t size;
|
|
BinaryRead(instream, size);
|
|
//toReturn.resize(size);
|
|
std::string test;
|
|
unsigned char buf;
|
|
|
|
for (size_t i = 0; i < size; ++i) {
|
|
//instream.ignore(1);
|
|
BinaryRead(instream, buf);
|
|
test += buf;
|
|
}
|
|
|
|
//printf("%s\n", test.c_str());
|
|
|
|
//instream.read((char*)&toReturn[0], size * 2);
|
|
//std::string str(toReturn.begin(), toReturn.end());
|
|
return test;
|
|
}
|