More fixes and optimizations
This commit is contained in:
parent
9562285ed7
commit
2ea490382b
@ -7,7 +7,7 @@ namespace Assets
|
|||||||
Game::GfxImage* image = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_IMAGE, name.data()).image;
|
Game::GfxImage* image = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_IMAGE, name.data()).image;
|
||||||
if (image) return; // TODO: Check for default?
|
if (image) return; // TODO: Check for default?
|
||||||
|
|
||||||
image = builder->GetAllocator()->AllocateArray<Game::GfxImage>();
|
image = builder->GetAllocator()->Allocate<Game::GfxImage>();
|
||||||
if (!image)
|
if (!image)
|
||||||
{
|
{
|
||||||
Components::Logger::Error("Failed to allocate GfxImage structure!");
|
Components::Logger::Error("Failed to allocate GfxImage structure!");
|
||||||
@ -19,7 +19,7 @@ namespace Assets
|
|||||||
image->category = 0;
|
image->category = 0;
|
||||||
image->cardMemory = 0;
|
image->cardMemory = 0;
|
||||||
|
|
||||||
image->texture = builder->GetAllocator()->AllocateArray<Game::GfxImageLoadDef>();
|
image->texture = builder->GetAllocator()->Allocate<Game::GfxImageLoadDef>();
|
||||||
if (!image->texture)
|
if (!image->texture)
|
||||||
{
|
{
|
||||||
Components::Logger::Error("Failed to allocate GfxImageLoadDef structure!");
|
Components::Logger::Error("Failed to allocate GfxImageLoadDef structure!");
|
||||||
|
@ -1,106 +1,106 @@
|
|||||||
#include <STDInclude.hpp>
|
#include <STDInclude.hpp>
|
||||||
|
|
||||||
namespace Assets
|
namespace Assets
|
||||||
{
|
{
|
||||||
void IMapEnts::Load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
|
void IMapEnts::Load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
|
||||||
{
|
{
|
||||||
Components::FileSystem::File ents(name + ".ents");
|
Components::FileSystem::File ents(name + ".ents");
|
||||||
if (ents.Exists())
|
if (ents.Exists())
|
||||||
{
|
{
|
||||||
Game::MapEnts* entites = builder->GetAllocator()->AllocateArray<Game::MapEnts>();
|
Game::MapEnts* entites = builder->GetAllocator()->Allocate<Game::MapEnts>();
|
||||||
Game::MapEnts* orgEnts = Components::AssetHandler::FindOriginalAsset(this->GetType(), name.data()).mapEnts;
|
Game::MapEnts* orgEnts = Components::AssetHandler::FindOriginalAsset(this->GetType(), name.data()).mapEnts;
|
||||||
|
|
||||||
if (orgEnts)
|
if (orgEnts)
|
||||||
{
|
{
|
||||||
std::memcpy(entites, orgEnts, sizeof Game::MapEnts);
|
std::memcpy(entites, orgEnts, sizeof Game::MapEnts);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
entites->name = builder->GetAllocator()->DuplicateString(name);
|
entites->name = builder->GetAllocator()->DuplicateString(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
entites->entityString = builder->GetAllocator()->DuplicateString(ents.GetBuffer());
|
entites->entityString = builder->GetAllocator()->DuplicateString(ents.GetBuffer());
|
||||||
entites->numEntityChars = ents.GetBuffer().size() + 1;
|
entites->numEntityChars = ents.GetBuffer().size() + 1;
|
||||||
|
|
||||||
header->mapEnts = entites;
|
header->mapEnts = entites;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IMapEnts::Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
void IMapEnts::Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
||||||
{
|
{
|
||||||
Assert_Size(Game::MapEnts, 44);
|
Assert_Size(Game::MapEnts, 44);
|
||||||
|
|
||||||
Utils::Stream* buffer = builder->GetBuffer();
|
Utils::Stream* buffer = builder->GetBuffer();
|
||||||
Game::MapEnts* asset = header.mapEnts;
|
Game::MapEnts* asset = header.mapEnts;
|
||||||
Game::MapEnts* dest = buffer->Dest<Game::MapEnts>();
|
Game::MapEnts* dest = buffer->Dest<Game::MapEnts>();
|
||||||
buffer->Save(asset);
|
buffer->Save(asset);
|
||||||
|
|
||||||
buffer->PushBlock(Game::XFILE_BLOCK_VIRTUAL);
|
buffer->PushBlock(Game::XFILE_BLOCK_VIRTUAL);
|
||||||
|
|
||||||
if (asset->name)
|
if (asset->name)
|
||||||
{
|
{
|
||||||
buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name));
|
buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name));
|
||||||
Utils::Stream::ClearPointer(&dest->name);
|
Utils::Stream::ClearPointer(&dest->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (asset->entityString)
|
if (asset->entityString)
|
||||||
{
|
{
|
||||||
buffer->Save(asset->entityString, asset->numEntityChars);
|
buffer->Save(asset->entityString, asset->numEntityChars);
|
||||||
Utils::Stream::ClearPointer(&dest->entityString);
|
Utils::Stream::ClearPointer(&dest->entityString);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (asset->trigger.models)
|
if (asset->trigger.models)
|
||||||
{
|
{
|
||||||
Assert_Size(Game::TriggerModel, 8);
|
Assert_Size(Game::TriggerModel, 8);
|
||||||
buffer->Align(Utils::Stream::ALIGN_4);
|
buffer->Align(Utils::Stream::ALIGN_4);
|
||||||
|
|
||||||
buffer->SaveArray(asset->trigger.models, asset->trigger.modelCount);
|
buffer->SaveArray(asset->trigger.models, asset->trigger.modelCount);
|
||||||
|
|
||||||
Utils::Stream::ClearPointer(&dest->trigger.models);
|
Utils::Stream::ClearPointer(&dest->trigger.models);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (asset->trigger.hulls)
|
if (asset->trigger.hulls)
|
||||||
{
|
{
|
||||||
Assert_Size(Game::TriggerHull, 32);
|
Assert_Size(Game::TriggerHull, 32);
|
||||||
buffer->Align(Utils::Stream::ALIGN_4);
|
buffer->Align(Utils::Stream::ALIGN_4);
|
||||||
|
|
||||||
buffer->SaveArray(asset->trigger.hulls, asset->trigger.hullCount);
|
buffer->SaveArray(asset->trigger.hulls, asset->trigger.hullCount);
|
||||||
|
|
||||||
Utils::Stream::ClearPointer(&dest->trigger.hulls);
|
Utils::Stream::ClearPointer(&dest->trigger.hulls);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (asset->trigger.slabs)
|
if (asset->trigger.slabs)
|
||||||
{
|
{
|
||||||
Assert_Size(Game::TriggerSlab, 20);
|
Assert_Size(Game::TriggerSlab, 20);
|
||||||
buffer->Align(Utils::Stream::ALIGN_4);
|
buffer->Align(Utils::Stream::ALIGN_4);
|
||||||
|
|
||||||
buffer->SaveArray(asset->trigger.slabs, asset->trigger.slabCount);
|
buffer->SaveArray(asset->trigger.slabs, asset->trigger.slabCount);
|
||||||
|
|
||||||
Utils::Stream::ClearPointer(&dest->trigger.slabs);
|
Utils::Stream::ClearPointer(&dest->trigger.slabs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (asset->stages)
|
if (asset->stages)
|
||||||
{
|
{
|
||||||
Assert_Size(Game::Stage, 20);
|
Assert_Size(Game::Stage, 20);
|
||||||
|
|
||||||
buffer->Align(Utils::Stream::ALIGN_4);
|
buffer->Align(Utils::Stream::ALIGN_4);
|
||||||
|
|
||||||
Game::Stage* destStages = buffer->Dest<Game::Stage>();
|
Game::Stage* destStages = buffer->Dest<Game::Stage>();
|
||||||
buffer->SaveArray(asset->stages, asset->stageCount);
|
buffer->SaveArray(asset->stages, asset->stageCount);
|
||||||
|
|
||||||
for (int i = 0; i < asset->stageCount; ++i)
|
for (int i = 0; i < asset->stageCount; ++i)
|
||||||
{
|
{
|
||||||
Game::Stage* destStage = &destStages[i];
|
Game::Stage* destStage = &destStages[i];
|
||||||
Game::Stage* stage = &asset->stages[i];
|
Game::Stage* stage = &asset->stages[i];
|
||||||
|
|
||||||
buffer->SaveString(stage->stageName);
|
buffer->SaveString(stage->stageName);
|
||||||
|
|
||||||
Utils::Stream::ClearPointer(&destStage->stageName);
|
Utils::Stream::ClearPointer(&destStage->stageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::Stream::ClearPointer(&dest->stages);
|
Utils::Stream::ClearPointer(&dest->stages);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer->PopBlock();
|
buffer->PopBlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ namespace Assets
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::Material* material = builder->GetAllocator()->AllocateArray<Game::Material>();
|
Game::Material* material = builder->GetAllocator()->Allocate<Game::Material>();
|
||||||
|
|
||||||
if (!material)
|
if (!material)
|
||||||
{
|
{
|
||||||
|
@ -1,60 +1,60 @@
|
|||||||
#include <STDInclude.hpp>
|
#include <STDInclude.hpp>
|
||||||
|
|
||||||
namespace Assets
|
namespace Assets
|
||||||
{
|
{
|
||||||
void IRawFile::Load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
|
void IRawFile::Load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
|
||||||
{
|
{
|
||||||
Components::FileSystem::File rawFile(name);
|
Components::FileSystem::File rawFile(name);
|
||||||
|
|
||||||
if (rawFile.Exists())
|
if (rawFile.Exists())
|
||||||
{
|
{
|
||||||
Game::RawFile* asset = builder->GetAllocator()->AllocateArray<Game::RawFile>();
|
Game::RawFile* asset = builder->GetAllocator()->Allocate<Game::RawFile>();
|
||||||
|
|
||||||
if (asset)
|
if (asset)
|
||||||
{
|
{
|
||||||
//std::string data = Utils::Compression::ZLib::Compress(rawFile.GetBuffer());
|
//std::string data = Utils::Compression::ZLib::Compress(rawFile.GetBuffer());
|
||||||
|
|
||||||
asset->name = builder->GetAllocator()->DuplicateString(name);
|
asset->name = builder->GetAllocator()->DuplicateString(name);
|
||||||
asset->compressedData = builder->GetAllocator()->DuplicateString(rawFile.GetBuffer());
|
asset->compressedData = builder->GetAllocator()->DuplicateString(rawFile.GetBuffer());
|
||||||
asset->sizeCompressed = 0;//data.size();
|
asset->sizeCompressed = 0;//data.size();
|
||||||
asset->sizeUnCompressed = rawFile.GetBuffer().size();
|
asset->sizeUnCompressed = rawFile.GetBuffer().size();
|
||||||
|
|
||||||
header->rawfile = asset;
|
header->rawfile = asset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRawFile::Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
void IRawFile::Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
||||||
{
|
{
|
||||||
Assert_Size(Game::RawFile, 16);
|
Assert_Size(Game::RawFile, 16);
|
||||||
|
|
||||||
Utils::Stream* buffer = builder->GetBuffer();
|
Utils::Stream* buffer = builder->GetBuffer();
|
||||||
Game::RawFile* asset = header.rawfile;
|
Game::RawFile* asset = header.rawfile;
|
||||||
Game::RawFile* dest = buffer->Dest<Game::RawFile>();
|
Game::RawFile* dest = buffer->Dest<Game::RawFile>();
|
||||||
buffer->Save(asset);
|
buffer->Save(asset);
|
||||||
|
|
||||||
buffer->PushBlock(Game::XFILE_BLOCK_VIRTUAL);
|
buffer->PushBlock(Game::XFILE_BLOCK_VIRTUAL);
|
||||||
|
|
||||||
if (asset->name)
|
if (asset->name)
|
||||||
{
|
{
|
||||||
buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name));
|
buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name));
|
||||||
Utils::Stream::ClearPointer(&dest->name);
|
Utils::Stream::ClearPointer(&dest->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (asset->compressedData)
|
if (asset->compressedData)
|
||||||
{
|
{
|
||||||
if (asset->sizeCompressed)
|
if (asset->sizeCompressed)
|
||||||
{
|
{
|
||||||
buffer->Save(asset->compressedData, asset->sizeCompressed);
|
buffer->Save(asset->compressedData, asset->sizeCompressed);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
buffer->Save(asset->compressedData, asset->sizeUnCompressed + 1);
|
buffer->Save(asset->compressedData, asset->sizeUnCompressed + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::Stream::ClearPointer(&dest->compressedData);
|
Utils::Stream::ClearPointer(&dest->compressedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer->PopBlock();
|
buffer->PopBlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ namespace Assets
|
|||||||
Game::XModel* baseModel = Components::AssetHandler::FindOriginalAsset(Game::XAssetType::ASSET_TYPE_XMODEL, "viewmodel_mp5k").model;
|
Game::XModel* baseModel = Components::AssetHandler::FindOriginalAsset(Game::XAssetType::ASSET_TYPE_XMODEL, "viewmodel_mp5k").model;
|
||||||
|
|
||||||
// Allocate new model and copy the base data to it
|
// Allocate new model and copy the base data to it
|
||||||
Game::XModel* model = builder->GetAllocator()->AllocateArray<Game::XModel>();
|
Game::XModel* model = builder->GetAllocator()->Allocate<Game::XModel>();
|
||||||
std::memcpy(model, baseModel, sizeof(Game::XModel));
|
std::memcpy(model, baseModel, sizeof(Game::XModel));
|
||||||
|
|
||||||
Utils::Stream::Reader reader(builder->GetAllocator(), modelFile.GetBuffer());
|
Utils::Stream::Reader reader(builder->GetAllocator(), modelFile.GetBuffer());
|
||||||
@ -41,7 +41,7 @@ namespace Assets
|
|||||||
|
|
||||||
// Prepare surfaces
|
// Prepare surfaces
|
||||||
Game::XSurface* baseSurface = &baseModel->lods[0].surfaces[0].surfaces[0];
|
Game::XSurface* baseSurface = &baseModel->lods[0].surfaces[0].surfaces[0];
|
||||||
Game::XModelSurfs* surf = builder->GetAllocator()->AllocateArray<Game::XModelSurfs>();
|
Game::XModelSurfs* surf = builder->GetAllocator()->Allocate<Game::XModelSurfs>();
|
||||||
|
|
||||||
std::memcpy(surf, baseModel->lods[0].surfaces, sizeof(Game::XModelSurfs));
|
std::memcpy(surf, baseModel->lods[0].surfaces, sizeof(Game::XModelSurfs));
|
||||||
surf->name = builder->GetAllocator()->DuplicateString(fmt::sprintf("%s1", model->name));
|
surf->name = builder->GetAllocator()->DuplicateString(fmt::sprintf("%s1", model->name));
|
||||||
|
@ -19,7 +19,7 @@ namespace Components
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::LocalizedEntry* entry = Utils::Memory::AllocateArray<Game::LocalizedEntry>(1);
|
Game::LocalizedEntry* entry = Utils::Memory::Allocate<Game::LocalizedEntry>();
|
||||||
if (!entry) return;
|
if (!entry) return;
|
||||||
|
|
||||||
entry->name = Utils::Memory::DuplicateString(key);
|
entry->name = Utils::Memory::DuplicateString(key);
|
||||||
@ -75,7 +75,7 @@ namespace Components
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Game::LocalizedEntry* entry = Utils::Memory::AllocateArray<Game::LocalizedEntry>(1);
|
Game::LocalizedEntry* entry = Utils::Memory::Allocate<Game::LocalizedEntry>();
|
||||||
if (!entry) return;
|
if (!entry) return;
|
||||||
|
|
||||||
entry->name = Utils::Memory::DuplicateString(key);
|
entry->name = Utils::Memory::DuplicateString(key);
|
||||||
|
@ -68,7 +68,7 @@ namespace Components
|
|||||||
|
|
||||||
script->next = NULL;
|
script->next = NULL;
|
||||||
|
|
||||||
source = Utils::Memory::AllocateArray<Game::source_t>(1);
|
source = Utils::Memory::Allocate<Game::source_t>();
|
||||||
if (!source)
|
if (!source)
|
||||||
{
|
{
|
||||||
Game::FreeMemory(script);
|
Game::FreeMemory(script);
|
||||||
@ -112,7 +112,7 @@ namespace Components
|
|||||||
|
|
||||||
Game::menuDef_t* Menus::ParseMenu(int handle)
|
Game::menuDef_t* Menus::ParseMenu(int handle)
|
||||||
{
|
{
|
||||||
Game::menuDef_t* menu = Utils::Memory::AllocateArray<Game::menuDef_t>(1);
|
Game::menuDef_t* menu = Utils::Memory::Allocate<Game::menuDef_t>();
|
||||||
if (!menu) return nullptr;
|
if (!menu) return nullptr;
|
||||||
|
|
||||||
menu->items = Utils::Memory::AllocateArray<Game::itemDef_t*>(512);
|
menu->items = Utils::Memory::AllocateArray<Game::itemDef_t*>(512);
|
||||||
@ -239,7 +239,7 @@ namespace Components
|
|||||||
if (menus.empty()) return nullptr;
|
if (menus.empty()) return nullptr;
|
||||||
|
|
||||||
// Allocate new menu list
|
// Allocate new menu list
|
||||||
Game::MenuList* newList = Utils::Memory::AllocateArray<Game::MenuList>(1);
|
Game::MenuList* newList = Utils::Memory::Allocate<Game::MenuList>();
|
||||||
if (!newList) return nullptr;
|
if (!newList) return nullptr;
|
||||||
|
|
||||||
newList->menus = Utils::Memory::AllocateArray<Game::menuDef_t*>(menus.size());
|
newList->menus = Utils::Memory::AllocateArray<Game::menuDef_t*>(menus.size());
|
||||||
@ -285,7 +285,7 @@ namespace Components
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Allocate new menu list
|
// Allocate new menu list
|
||||||
Game::MenuList* newList = Utils::Memory::AllocateArray<Game::MenuList>(1);
|
Game::MenuList* newList = Utils::Memory::Allocate<Game::MenuList>();
|
||||||
if (!newList) return menuList;
|
if (!newList) return menuList;
|
||||||
|
|
||||||
size_t size = menus.size();
|
size_t size = menus.size();
|
||||||
|
@ -1,92 +1,92 @@
|
|||||||
#include "STDInclude.hpp"
|
#include "STDInclude.hpp"
|
||||||
|
|
||||||
namespace Components
|
namespace Components
|
||||||
{
|
{
|
||||||
Utils::Memory::Allocator StringTable::MemAllocator;
|
Utils::Memory::Allocator StringTable::MemAllocator;
|
||||||
std::map<std::string, Game::StringTable*> StringTable::StringTableMap;
|
std::map<std::string, Game::StringTable*> StringTable::StringTableMap;
|
||||||
|
|
||||||
int StringTable::Hash(const char* data)
|
int StringTable::Hash(const char* data)
|
||||||
{
|
{
|
||||||
int hash = 0;
|
int hash = 0;
|
||||||
|
|
||||||
while (*data != 0)
|
while (*data != 0)
|
||||||
{
|
{
|
||||||
hash = tolower(*data) + (31 * hash);
|
hash = tolower(*data) + (31 * hash);
|
||||||
|
|
||||||
++data;
|
++data;
|
||||||
}
|
}
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::StringTable* StringTable::LoadObject(std::string filename)
|
Game::StringTable* StringTable::LoadObject(std::string filename)
|
||||||
{
|
{
|
||||||
Game::StringTable* table = nullptr;
|
Game::StringTable* table = nullptr;
|
||||||
FileSystem::File rawTable(filename);
|
FileSystem::File rawTable(filename);
|
||||||
|
|
||||||
if (rawTable.Exists())
|
if (rawTable.Exists())
|
||||||
{
|
{
|
||||||
Utils::CSV parsedTable(rawTable.GetBuffer(), false, false);
|
Utils::CSV parsedTable(rawTable.GetBuffer(), false, false);
|
||||||
|
|
||||||
table = StringTable::MemAllocator.AllocateArray<Game::StringTable>(1);
|
table = StringTable::MemAllocator.Allocate<Game::StringTable>();
|
||||||
|
|
||||||
if (table)
|
if (table)
|
||||||
{
|
{
|
||||||
table->name = StringTable::MemAllocator.DuplicateString(filename);
|
table->name = StringTable::MemAllocator.DuplicateString(filename);
|
||||||
table->columnCount = parsedTable.GetColumns();
|
table->columnCount = parsedTable.GetColumns();
|
||||||
table->rowCount = parsedTable.GetRows();
|
table->rowCount = parsedTable.GetRows();
|
||||||
|
|
||||||
table->values = StringTable::MemAllocator.AllocateArray<Game::StringTableCell>(table->columnCount * table->rowCount);
|
table->values = StringTable::MemAllocator.AllocateArray<Game::StringTableCell>(table->columnCount * table->rowCount);
|
||||||
|
|
||||||
if (!table->values)
|
if (!table->values)
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < table->rowCount; ++i)
|
for (int i = 0; i < table->rowCount; ++i)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < table->columnCount; ++j)
|
for (int j = 0; j < table->columnCount; ++j)
|
||||||
{
|
{
|
||||||
Game::StringTableCell* cell = &table->values[i * table->columnCount + j];
|
Game::StringTableCell* cell = &table->values[i * table->columnCount + j];
|
||||||
cell->hash = StringTable::Hash(parsedTable.GetElementAt(i, j).data());
|
cell->hash = StringTable::Hash(parsedTable.GetElementAt(i, j).data());
|
||||||
cell->string = StringTable::MemAllocator.DuplicateString(parsedTable.GetElementAt(i, j));
|
cell->string = StringTable::MemAllocator.DuplicateString(parsedTable.GetElementAt(i, j));
|
||||||
//if (!cell->string) cell->string = ""; // We have to assume it allocated successfully
|
//if (!cell->string) cell->string = ""; // We have to assume it allocated successfully
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StringTable::StringTableMap[filename] = table;
|
StringTable::StringTableMap[filename] = table;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
StringTable::StringTableMap[filename] = nullptr;
|
StringTable::StringTableMap[filename] = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringTable::StringTable()
|
StringTable::StringTable()
|
||||||
{
|
{
|
||||||
AssetHandler::OnFind(Game::XAssetType::ASSET_TYPE_STRINGTABLE, [] (Game::XAssetType, std::string filename)
|
AssetHandler::OnFind(Game::XAssetType::ASSET_TYPE_STRINGTABLE, [] (Game::XAssetType, std::string filename)
|
||||||
{
|
{
|
||||||
Game::XAssetHeader header = { 0 };
|
Game::XAssetHeader header = { 0 };
|
||||||
|
|
||||||
if (StringTable::StringTableMap.find(filename) != StringTable::StringTableMap.end())
|
if (StringTable::StringTableMap.find(filename) != StringTable::StringTableMap.end())
|
||||||
{
|
{
|
||||||
header.stringTable = StringTable::StringTableMap[filename];
|
header.stringTable = StringTable::StringTableMap[filename];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
header.stringTable = StringTable::LoadObject(filename);
|
header.stringTable = StringTable::LoadObject(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
return header;
|
return header;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
StringTable::~StringTable()
|
StringTable::~StringTable()
|
||||||
{
|
{
|
||||||
StringTable::StringTableMap.clear();
|
StringTable::StringTableMap.clear();
|
||||||
StringTable::MemAllocator.Free();
|
StringTable::MemAllocator.Free();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -304,7 +304,7 @@ namespace Components
|
|||||||
FileSystem::DeleteFile("demos", fmt::sprintf("%s.json", files[i].data()));
|
FileSystem::DeleteFile("demos", fmt::sprintf("%s.json", files[i].data()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Command::Execute(fmt::sprintf("record auto_%I64d", time(0)), true);
|
Command::Execute(fmt::format("record auto_{}", time(0)), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Utils::Hook::Call<DWORD()>(0x42BBB0)();
|
return Utils::Hook::Call<DWORD()>(0x42BBB0)();
|
||||||
|
@ -1,193 +1,193 @@
|
|||||||
#include "STDInclude.hpp"
|
#include "STDInclude.hpp"
|
||||||
|
|
||||||
namespace Steam
|
namespace Steam
|
||||||
{
|
{
|
||||||
int Matchmaking::GetFavoriteGameCount()
|
int Matchmaking::GetFavoriteGameCount()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matchmaking::GetFavoriteGame(int iGame, unsigned int *pnAppID, unsigned int *pnIP, unsigned short *pnConnPort, unsigned short *pnQueryPort, unsigned int *punFlags, unsigned int *pRTime32LastPlayedOnServer)
|
bool Matchmaking::GetFavoriteGame(int iGame, unsigned int *pnAppID, unsigned int *pnIP, unsigned short *pnConnPort, unsigned short *pnQueryPort, unsigned int *punFlags, unsigned int *pRTime32LastPlayedOnServer)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Matchmaking::AddFavoriteGame(unsigned int nAppID, unsigned int nIP, unsigned short nConnPort, unsigned short nQueryPort, unsigned int unFlags, unsigned int rTime32LastPlayedOnServer)
|
int Matchmaking::AddFavoriteGame(unsigned int nAppID, unsigned int nIP, unsigned short nConnPort, unsigned short nQueryPort, unsigned int unFlags, unsigned int rTime32LastPlayedOnServer)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matchmaking::RemoveFavoriteGame(unsigned int nAppID, unsigned int nIP, unsigned short nConnPort, unsigned short nQueryPort, unsigned int unFlags)
|
bool Matchmaking::RemoveFavoriteGame(unsigned int nAppID, unsigned int nIP, unsigned short nConnPort, unsigned short nQueryPort, unsigned int unFlags)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned __int64 Matchmaking::RequestLobbyList()
|
unsigned __int64 Matchmaking::RequestLobbyList()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matchmaking::AddRequestLobbyListStringFilter(const char *pchKeyToMatch, const char *pchValueToMatch, int eComparisonType)
|
void Matchmaking::AddRequestLobbyListStringFilter(const char *pchKeyToMatch, const char *pchValueToMatch, int eComparisonType)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matchmaking::AddRequestLobbyListNumericalFilter(const char *pchKeyToMatch, int nValueToMatch, int eComparisonType)
|
void Matchmaking::AddRequestLobbyListNumericalFilter(const char *pchKeyToMatch, int nValueToMatch, int eComparisonType)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matchmaking::AddRequestLobbyListNearValueFilter(const char *pchKeyToMatch, int nValueToBeCloseTo)
|
void Matchmaking::AddRequestLobbyListNearValueFilter(const char *pchKeyToMatch, int nValueToBeCloseTo)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matchmaking::AddRequestLobbyListFilterSlotsAvailable(int nSlotsAvailable)
|
void Matchmaking::AddRequestLobbyListFilterSlotsAvailable(int nSlotsAvailable)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SteamID Matchmaking::GetLobbyByIndex(int iLobby)
|
SteamID Matchmaking::GetLobbyByIndex(int iLobby)
|
||||||
{
|
{
|
||||||
return SteamID();
|
return SteamID();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned __int64 Matchmaking::CreateLobby(int eLobbyType, int cMaxMembers)
|
unsigned __int64 Matchmaking::CreateLobby(int eLobbyType, int cMaxMembers)
|
||||||
{
|
{
|
||||||
uint64_t result = Callbacks::RegisterCall();
|
uint64_t result = Callbacks::RegisterCall();
|
||||||
LobbyCreated* retvals = ::Utils::Memory::AllocateArray<LobbyCreated>();
|
LobbyCreated* retvals = ::Utils::Memory::Allocate<LobbyCreated>();
|
||||||
SteamID id;
|
SteamID id;
|
||||||
|
|
||||||
id.AccountID = 1337132;
|
id.AccountID = 1337132;
|
||||||
id.Universe = 1;
|
id.Universe = 1;
|
||||||
id.AccountType = 8;
|
id.AccountType = 8;
|
||||||
id.AccountInstance = 0x40000;
|
id.AccountInstance = 0x40000;
|
||||||
|
|
||||||
retvals->m_eResult = 1;
|
retvals->m_eResult = 1;
|
||||||
retvals->m_ulSteamIDLobby = id;
|
retvals->m_ulSteamIDLobby = id;
|
||||||
|
|
||||||
Callbacks::ReturnCall(retvals, sizeof(LobbyCreated), LobbyCreated::CallbackID, result);
|
Callbacks::ReturnCall(retvals, sizeof(LobbyCreated), LobbyCreated::CallbackID, result);
|
||||||
|
|
||||||
Matchmaking::JoinLobby(id);
|
Matchmaking::JoinLobby(id);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned __int64 Matchmaking::JoinLobby(SteamID steamIDLobby)
|
unsigned __int64 Matchmaking::JoinLobby(SteamID steamIDLobby)
|
||||||
{
|
{
|
||||||
uint64_t result = Callbacks::RegisterCall();
|
uint64_t result = Callbacks::RegisterCall();
|
||||||
LobbyEnter* retvals = ::Utils::Memory::AllocateArray<LobbyEnter>();
|
LobbyEnter* retvals = ::Utils::Memory::Allocate<LobbyEnter>();
|
||||||
retvals->m_bLocked = false;
|
retvals->m_bLocked = false;
|
||||||
retvals->m_EChatRoomEnterResponse = 1;
|
retvals->m_EChatRoomEnterResponse = 1;
|
||||||
retvals->m_rgfChatPermissions = 0xFFFFFFFF;
|
retvals->m_rgfChatPermissions = 0xFFFFFFFF;
|
||||||
retvals->m_ulSteamIDLobby = steamIDLobby;
|
retvals->m_ulSteamIDLobby = steamIDLobby;
|
||||||
|
|
||||||
Callbacks::ReturnCall(retvals, sizeof(LobbyEnter), LobbyEnter::CallbackID, result);
|
Callbacks::ReturnCall(retvals, sizeof(LobbyEnter), LobbyEnter::CallbackID, result);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matchmaking::LeaveLobby(SteamID steamIDLobby)
|
void Matchmaking::LeaveLobby(SteamID steamIDLobby)
|
||||||
{
|
{
|
||||||
Components::Party::RemoveLobby(steamIDLobby);
|
Components::Party::RemoveLobby(steamIDLobby);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matchmaking::InviteUserToLobby(SteamID steamIDLobby, SteamID steamIDInvitee)
|
bool Matchmaking::InviteUserToLobby(SteamID steamIDLobby, SteamID steamIDInvitee)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Matchmaking::GetNumLobbyMembers(SteamID steamIDLobby)
|
int Matchmaking::GetNumLobbyMembers(SteamID steamIDLobby)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SteamID Matchmaking::GetLobbyMemberByIndex(SteamID steamIDLobby, int iMember)
|
SteamID Matchmaking::GetLobbyMemberByIndex(SteamID steamIDLobby, int iMember)
|
||||||
{
|
{
|
||||||
return SteamUser()->GetSteamID();
|
return SteamUser()->GetSteamID();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *Matchmaking::GetLobbyData(SteamID steamIDLobby, const char *pchKey)
|
const char *Matchmaking::GetLobbyData(SteamID steamIDLobby, const char *pchKey)
|
||||||
{
|
{
|
||||||
return Components::Party::GetLobbyInfo(steamIDLobby, pchKey);
|
return Components::Party::GetLobbyInfo(steamIDLobby, pchKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matchmaking::SetLobbyData(SteamID steamIDLobby, const char *pchKey, const char *pchValue)
|
bool Matchmaking::SetLobbyData(SteamID steamIDLobby, const char *pchKey, const char *pchValue)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Matchmaking::GetLobbyDataCount(SteamID steamIDLobby)
|
int Matchmaking::GetLobbyDataCount(SteamID steamIDLobby)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matchmaking::GetLobbyDataByIndex(SteamID steamIDLobby, int iLobbyData, char *pchKey, int cchKeyBufferSize, char *pchValue, int cchValueBufferSize)
|
bool Matchmaking::GetLobbyDataByIndex(SteamID steamIDLobby, int iLobbyData, char *pchKey, int cchKeyBufferSize, char *pchValue, int cchValueBufferSize)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matchmaking::DeleteLobbyData(SteamID steamIDLobby, const char *pchKey)
|
bool Matchmaking::DeleteLobbyData(SteamID steamIDLobby, const char *pchKey)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *Matchmaking::GetLobbyMemberData(SteamID steamIDLobby, SteamID steamIDUser, const char *pchKey)
|
const char *Matchmaking::GetLobbyMemberData(SteamID steamIDLobby, SteamID steamIDUser, const char *pchKey)
|
||||||
{
|
{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matchmaking::SetLobbyMemberData(SteamID steamIDLobby, const char *pchKey, const char *pchValue)
|
void Matchmaking::SetLobbyMemberData(SteamID steamIDLobby, const char *pchKey, const char *pchValue)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matchmaking::SendLobbyChatMsg(SteamID steamIDLobby, const void *pvMsgBody, int cubMsgBody)
|
bool Matchmaking::SendLobbyChatMsg(SteamID steamIDLobby, const void *pvMsgBody, int cubMsgBody)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Matchmaking::GetLobbyChatEntry(SteamID steamIDLobby, int iChatID, SteamID *pSteamIDUser, void *pvData, int cubData, int *peChatEntryType)
|
int Matchmaking::GetLobbyChatEntry(SteamID steamIDLobby, int iChatID, SteamID *pSteamIDUser, void *pvData, int cubData, int *peChatEntryType)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matchmaking::RequestLobbyData(SteamID steamIDLobby)
|
bool Matchmaking::RequestLobbyData(SteamID steamIDLobby)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matchmaking::SetLobbyGameServer(SteamID steamIDLobby, unsigned int unGameServerIP, unsigned short unGameServerPort, SteamID steamIDGameServer)
|
void Matchmaking::SetLobbyGameServer(SteamID steamIDLobby, unsigned int unGameServerIP, unsigned short unGameServerPort, SteamID steamIDGameServer)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matchmaking::GetLobbyGameServer(SteamID steamIDLobby, unsigned int *punGameServerIP, unsigned short *punGameServerPort, SteamID *psteamIDGameServer)
|
bool Matchmaking::GetLobbyGameServer(SteamID steamIDLobby, unsigned int *punGameServerIP, unsigned short *punGameServerPort, SteamID *psteamIDGameServer)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matchmaking::SetLobbyMemberLimit(SteamID steamIDLobby, int cMaxMembers)
|
bool Matchmaking::SetLobbyMemberLimit(SteamID steamIDLobby, int cMaxMembers)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Matchmaking::GetLobbyMemberLimit(SteamID steamIDLobby)
|
int Matchmaking::GetLobbyMemberLimit(SteamID steamIDLobby)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matchmaking::SetLobbyType(SteamID steamIDLobby, int eLobbyType)
|
bool Matchmaking::SetLobbyType(SteamID steamIDLobby, int eLobbyType)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matchmaking::SetLobbyJoinable(SteamID steamIDLobby, bool bLobbyJoinable)
|
bool Matchmaking::SetLobbyJoinable(SteamID steamIDLobby, bool bLobbyJoinable)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SteamID Matchmaking::GetLobbyOwner(SteamID steamIDLobby)
|
SteamID Matchmaking::GetLobbyOwner(SteamID steamIDLobby)
|
||||||
{
|
{
|
||||||
return SteamUser()->GetSteamID();
|
return SteamUser()->GetSteamID();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matchmaking::SetLobbyOwner(SteamID steamIDLobby, SteamID steamIDNewOwner)
|
bool Matchmaking::SetLobbyOwner(SteamID steamIDLobby, SteamID steamIDNewOwner)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,9 @@ namespace Utils
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
uint8_t* dest = Utils::Memory::AllocateArray<uint8_t>(CHUNK);
|
Utils::Memory::Allocator allocator;
|
||||||
|
|
||||||
|
uint8_t* dest = allocator.AllocateArray<uint8_t>(CHUNK);
|
||||||
const char* dataPtr = data.data();
|
const char* dataPtr = data.data();
|
||||||
|
|
||||||
do
|
do
|
||||||
@ -52,7 +54,6 @@ namespace Utils
|
|||||||
if (ret == Z_STREAM_ERROR)
|
if (ret == Z_STREAM_ERROR)
|
||||||
{
|
{
|
||||||
inflateEnd(&stream);
|
inflateEnd(&stream);
|
||||||
Utils::Memory::Free(dest);
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,9 +64,6 @@ namespace Utils
|
|||||||
} while (ret != Z_STREAM_END);
|
} while (ret != Z_STREAM_END);
|
||||||
|
|
||||||
inflateEnd(&stream);
|
inflateEnd(&stream);
|
||||||
|
|
||||||
Utils::Memory::Free(dest);
|
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,324 +1,324 @@
|
|||||||
namespace Utils
|
namespace Utils
|
||||||
{
|
{
|
||||||
namespace Cryptography
|
namespace Cryptography
|
||||||
{
|
{
|
||||||
void Initialize();
|
void Initialize();
|
||||||
|
|
||||||
class Token
|
class Token
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Token() { this->TokenString.clear(); };
|
Token() { this->TokenString.clear(); };
|
||||||
Token(const Token& obj) : TokenString(obj.TokenString) { };
|
Token(const Token& obj) : TokenString(obj.TokenString) { };
|
||||||
Token(std::string token) : TokenString(token.begin(), token.end()) { };
|
Token(std::string token) : TokenString(token.begin(), token.end()) { };
|
||||||
Token(std::basic_string<uint8_t> token) : TokenString(token.begin(), token.end()) { };
|
Token(std::basic_string<uint8_t> token) : TokenString(token.begin(), token.end()) { };
|
||||||
|
|
||||||
Token& operator++ ()
|
Token& operator++ ()
|
||||||
{
|
{
|
||||||
if (this->TokenString.empty())
|
if (this->TokenString.empty())
|
||||||
{
|
{
|
||||||
this->TokenString.append(reinterpret_cast<uint8_t*>("\0"), 1);
|
this->TokenString.append(reinterpret_cast<uint8_t*>("\0"), 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (unsigned int i = (this->TokenString.size() - 1); i >= 0; i--)
|
for (unsigned int i = (this->TokenString.size() - 1); i >= 0; i--)
|
||||||
{
|
{
|
||||||
if (this->TokenString[i] == 0xFF)
|
if (this->TokenString[i] == 0xFF)
|
||||||
{
|
{
|
||||||
this->TokenString[i] = 0;
|
this->TokenString[i] = 0;
|
||||||
|
|
||||||
if (!i)
|
if (!i)
|
||||||
{
|
{
|
||||||
// Prepend here, as /dev/urandom says so ;) https://github.com/IW4x/iw4x-client-node/wikis/technical-information#incrementing-the-token
|
// Prepend here, as /dev/urandom says so ;) https://github.com/IW4x/iw4x-client-node/wikis/technical-information#incrementing-the-token
|
||||||
this->TokenString = std::basic_string<uint8_t>(reinterpret_cast<uint8_t*>("\0"), 1) + this->TokenString;
|
this->TokenString = std::basic_string<uint8_t>(reinterpret_cast<uint8_t*>("\0"), 1) + this->TokenString;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
++this->TokenString[i];
|
++this->TokenString[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Token operator++ (int)
|
Token operator++ (int)
|
||||||
{
|
{
|
||||||
Token result = *this;
|
Token result = *this;
|
||||||
this->operator++();
|
this->operator++();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const Token& token) const
|
bool operator==(const Token& token) const
|
||||||
{
|
{
|
||||||
return (this->ToString() == token.ToString());
|
return (this->ToString() == token.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const Token& token) const
|
bool operator!=(const Token& token) const
|
||||||
{
|
{
|
||||||
return !(*this == token);
|
return !(*this == token);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator<(const Token& token) const
|
bool operator<(const Token& token) const
|
||||||
{
|
{
|
||||||
if (*this == token)
|
if (*this == token)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (this->ToString().size() < token.ToString().size())
|
else if (this->ToString().size() < token.ToString().size())
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (this->ToString().size() > token.ToString().size())
|
else if (this->ToString().size() > token.ToString().size())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto lStr = this->ToString();
|
auto lStr = this->ToString();
|
||||||
auto rStr = token.ToString();
|
auto rStr = token.ToString();
|
||||||
|
|
||||||
for (unsigned int i = 0; i < lStr.size(); ++i)
|
for (unsigned int i = 0; i < lStr.size(); ++i)
|
||||||
{
|
{
|
||||||
if (lStr[i] < rStr[i])
|
if (lStr[i] < rStr[i])
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator>(const Token& token) const
|
bool operator>(const Token& token) const
|
||||||
{
|
{
|
||||||
return (token < *this && *this != token);
|
return (token < *this && *this != token);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator<=(const Token& token) const
|
bool operator<=(const Token& token) const
|
||||||
{
|
{
|
||||||
return !(*this > token);
|
return !(*this > token);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator>=(const Token& token) const
|
bool operator>=(const Token& token) const
|
||||||
{
|
{
|
||||||
return !(*this < token);
|
return !(*this < token);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ToString()
|
std::string ToString()
|
||||||
{
|
{
|
||||||
return std::string(this->TokenString.begin(), this->TokenString.end());
|
return std::string(this->TokenString.begin(), this->TokenString.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string ToString() const
|
const std::string ToString() const
|
||||||
{
|
{
|
||||||
return std::string(this->TokenString.begin(), this->TokenString.end());
|
return std::string(this->TokenString.begin(), this->TokenString.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::basic_string<uint8_t> ToUnsignedString()
|
std::basic_string<uint8_t> ToUnsignedString()
|
||||||
{
|
{
|
||||||
return this->TokenString;
|
return this->TokenString;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clear()
|
void Clear()
|
||||||
{
|
{
|
||||||
this->TokenString.clear();
|
this->TokenString.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::basic_string<uint8_t> TokenString;
|
std::basic_string<uint8_t> TokenString;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Rand
|
class Rand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static uint32_t GenerateInt();
|
static uint32_t GenerateInt();
|
||||||
static void Initialize();
|
static void Initialize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static prng_state State;
|
static prng_state State;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ECC
|
class ECC
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
class Key
|
class Key
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Key() : KeyStorage(new ecc_key)
|
Key() : KeyStorage(new ecc_key)
|
||||||
{
|
{
|
||||||
ZeroMemory(this->GetKeyPtr(), sizeof(*this->GetKeyPtr()));
|
ZeroMemory(this->GetKeyPtr(), sizeof(*this->GetKeyPtr()));
|
||||||
};
|
};
|
||||||
Key(ecc_key* key) : Key() { if(key) std::memmove(this->GetKeyPtr(), key, sizeof(*key)); };
|
Key(ecc_key* key) : Key() { if(key) std::memmove(this->GetKeyPtr(), key, sizeof(*key)); };
|
||||||
Key(ecc_key key) : Key(&key) {};
|
Key(ecc_key key) : Key(&key) {};
|
||||||
~Key()
|
~Key()
|
||||||
{
|
{
|
||||||
if (this->KeyStorage.use_count() <= 1)
|
if (this->KeyStorage.use_count() <= 1)
|
||||||
{
|
{
|
||||||
this->Free();
|
this->Free();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool IsValid()
|
bool IsValid()
|
||||||
{
|
{
|
||||||
return (!Utils::MemIsSet(this->GetKeyPtr(), 0, sizeof(*this->GetKeyPtr())));
|
return (!Utils::Memory::IsSet(this->GetKeyPtr(), 0, sizeof(*this->GetKeyPtr())));
|
||||||
}
|
}
|
||||||
|
|
||||||
ecc_key* GetKeyPtr()
|
ecc_key* GetKeyPtr()
|
||||||
{
|
{
|
||||||
return this->KeyStorage.get();
|
return this->KeyStorage.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetPublicKey()
|
std::string GetPublicKey()
|
||||||
{
|
{
|
||||||
uint8_t buffer[512] = { 0 };
|
uint8_t buffer[512] = { 0 };
|
||||||
DWORD length = sizeof(buffer);
|
DWORD length = sizeof(buffer);
|
||||||
|
|
||||||
if (ecc_ansi_x963_export(this->GetKeyPtr(), buffer, &length) == CRYPT_OK)
|
if (ecc_ansi_x963_export(this->GetKeyPtr(), buffer, &length) == CRYPT_OK)
|
||||||
{
|
{
|
||||||
return std::string(reinterpret_cast<char*>(buffer), length);
|
return std::string(reinterpret_cast<char*>(buffer), length);
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Set(std::string pubKeyBuffer)
|
void Set(std::string pubKeyBuffer)
|
||||||
{
|
{
|
||||||
this->Free();
|
this->Free();
|
||||||
|
|
||||||
if (ecc_ansi_x963_import(reinterpret_cast<const uint8_t*>(pubKeyBuffer.data()), pubKeyBuffer.size(), this->GetKeyPtr()) != CRYPT_OK)
|
if (ecc_ansi_x963_import(reinterpret_cast<const uint8_t*>(pubKeyBuffer.data()), pubKeyBuffer.size(), this->GetKeyPtr()) != CRYPT_OK)
|
||||||
{
|
{
|
||||||
ZeroMemory(this->KeyStorage.get(), sizeof(*this->GetKeyPtr()));
|
ZeroMemory(this->KeyStorage.get(), sizeof(*this->GetKeyPtr()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Import(std::string key, int type = PK_PRIVATE)
|
void Import(std::string key, int type = PK_PRIVATE)
|
||||||
{
|
{
|
||||||
this->Free();
|
this->Free();
|
||||||
|
|
||||||
if (ecc_import(reinterpret_cast<const uint8_t*>(key.data()), key.size(), this->GetKeyPtr()) != CRYPT_OK)
|
if (ecc_import(reinterpret_cast<const uint8_t*>(key.data()), key.size(), this->GetKeyPtr()) != CRYPT_OK)
|
||||||
{
|
{
|
||||||
ZeroMemory(this->KeyStorage.get(), sizeof(*this->GetKeyPtr()));
|
ZeroMemory(this->KeyStorage.get(), sizeof(*this->GetKeyPtr()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Export(int type = PK_PRIVATE)
|
std::string Export(int type = PK_PRIVATE)
|
||||||
{
|
{
|
||||||
uint8_t buffer[4096] = { 0 };
|
uint8_t buffer[4096] = { 0 };
|
||||||
DWORD length = sizeof(buffer);
|
DWORD length = sizeof(buffer);
|
||||||
|
|
||||||
if (ecc_export(buffer, &length, type, this->GetKeyPtr()) == CRYPT_OK)
|
if (ecc_export(buffer, &length, type, this->GetKeyPtr()) == CRYPT_OK)
|
||||||
{
|
{
|
||||||
return std::string(reinterpret_cast<char*>(buffer), length);
|
return std::string(reinterpret_cast<char*>(buffer), length);
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Free()
|
void Free()
|
||||||
{
|
{
|
||||||
if (this->IsValid())
|
if (this->IsValid())
|
||||||
{
|
{
|
||||||
ecc_free(this->GetKeyPtr());
|
ecc_free(this->GetKeyPtr());
|
||||||
}
|
}
|
||||||
|
|
||||||
ZeroMemory(this->GetKeyPtr(), sizeof(*this->GetKeyPtr()));
|
ZeroMemory(this->GetKeyPtr(), sizeof(*this->GetKeyPtr()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<ecc_key> KeyStorage;
|
std::shared_ptr<ecc_key> KeyStorage;
|
||||||
};
|
};
|
||||||
|
|
||||||
static Key GenerateKey(int bits);
|
static Key GenerateKey(int bits);
|
||||||
static std::string SignMessage(Key key, std::string message);
|
static std::string SignMessage(Key key, std::string message);
|
||||||
static bool VerifyMessage(Key key, std::string message, std::string signature);
|
static bool VerifyMessage(Key key, std::string message, std::string signature);
|
||||||
};
|
};
|
||||||
|
|
||||||
class RSA
|
class RSA
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
class Key
|
class Key
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Key() : KeyStorage(new rsa_key)
|
Key() : KeyStorage(new rsa_key)
|
||||||
{
|
{
|
||||||
ZeroMemory(this->GetKeyPtr(), sizeof(*this->GetKeyPtr()));
|
ZeroMemory(this->GetKeyPtr(), sizeof(*this->GetKeyPtr()));
|
||||||
};
|
};
|
||||||
Key(rsa_key* key) : Key() { if (key) std::memmove(this->GetKeyPtr(), key, sizeof(*key)); };
|
Key(rsa_key* key) : Key() { if (key) std::memmove(this->GetKeyPtr(), key, sizeof(*key)); };
|
||||||
Key(rsa_key key) : Key(&key) {};
|
Key(rsa_key key) : Key(&key) {};
|
||||||
~Key()
|
~Key()
|
||||||
{
|
{
|
||||||
if (this->KeyStorage.use_count() <= 1)
|
if (this->KeyStorage.use_count() <= 1)
|
||||||
{
|
{
|
||||||
this->Free();
|
this->Free();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
rsa_key* GetKeyPtr()
|
rsa_key* GetKeyPtr()
|
||||||
{
|
{
|
||||||
return this->KeyStorage.get();
|
return this->KeyStorage.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsValid()
|
bool IsValid()
|
||||||
{
|
{
|
||||||
return (!Utils::MemIsSet(this->GetKeyPtr(), 0, sizeof(*this->GetKeyPtr())));
|
return (!Utils::Memory::IsSet(this->GetKeyPtr(), 0, sizeof(*this->GetKeyPtr())));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Free()
|
void Free()
|
||||||
{
|
{
|
||||||
if (this->IsValid())
|
if (this->IsValid())
|
||||||
{
|
{
|
||||||
rsa_free(this->GetKeyPtr());
|
rsa_free(this->GetKeyPtr());
|
||||||
}
|
}
|
||||||
|
|
||||||
ZeroMemory(this->GetKeyPtr(), sizeof(*this->GetKeyPtr()));
|
ZeroMemory(this->GetKeyPtr(), sizeof(*this->GetKeyPtr()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<rsa_key> KeyStorage;
|
std::shared_ptr<rsa_key> KeyStorage;
|
||||||
};
|
};
|
||||||
|
|
||||||
static Key GenerateKey(int bits);
|
static Key GenerateKey(int bits);
|
||||||
static std::string SignMessage(Key key, std::string message);
|
static std::string SignMessage(Key key, std::string message);
|
||||||
static bool VerifyMessage(Key key, std::string message, std::string signature);
|
static bool VerifyMessage(Key key, std::string message, std::string signature);
|
||||||
};
|
};
|
||||||
|
|
||||||
class TDES
|
class TDES
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void Initialize();
|
static void Initialize();
|
||||||
static std::string Encrypt(std::string text, std::string iv, std::string key);
|
static std::string Encrypt(std::string text, std::string iv, std::string key);
|
||||||
static std::string Decrpyt(std::string text, std::string iv, std::string key);
|
static std::string Decrpyt(std::string text, std::string iv, std::string key);
|
||||||
};
|
};
|
||||||
|
|
||||||
class Tiger
|
class Tiger
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static std::string Compute(std::string data, bool hex = false);
|
static std::string Compute(std::string data, bool hex = false);
|
||||||
static std::string Compute(const uint8_t* data, size_t length, bool hex = false);
|
static std::string Compute(const uint8_t* data, size_t length, bool hex = false);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SHA256
|
class SHA256
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static std::string Compute(std::string data, bool hex = false);
|
static std::string Compute(std::string data, bool hex = false);
|
||||||
static std::string Compute(const uint8_t* data, size_t length, bool hex = false);
|
static std::string Compute(const uint8_t* data, size_t length, bool hex = false);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SHA512
|
class SHA512
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static std::string Compute(std::string data, bool hex = false);
|
static std::string Compute(std::string data, bool hex = false);
|
||||||
static std::string Compute(const uint8_t* data, size_t length, bool hex = false);
|
static std::string Compute(const uint8_t* data, size_t length, bool hex = false);
|
||||||
};
|
};
|
||||||
|
|
||||||
class JenkinsOneAtATime
|
class JenkinsOneAtATime
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static unsigned int Compute(std::string data);
|
static unsigned int Compute(std::string data);
|
||||||
static unsigned int Compute(const char *key, size_t len);
|
static unsigned int Compute(const char *key, size_t len);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,38 +1,54 @@
|
|||||||
#include "STDInclude.hpp"
|
#include "STDInclude.hpp"
|
||||||
|
|
||||||
namespace Utils
|
namespace Utils
|
||||||
{
|
{
|
||||||
void* Memory::Allocate(size_t length)
|
void* Memory::Allocate(size_t length)
|
||||||
{
|
{
|
||||||
void* data = new char[length];
|
void* data = new char[length];
|
||||||
|
|
||||||
assert(data != nullptr);
|
assert(data != nullptr);
|
||||||
|
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
ZeroMemory(data, length);
|
ZeroMemory(data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* Memory::DuplicateString(std::string string)
|
char* Memory::DuplicateString(std::string string)
|
||||||
{
|
{
|
||||||
char* newString = Memory::AllocateArray<char>(string.size() + 1);
|
char* newString = Memory::AllocateArray<char>(string.size() + 1);
|
||||||
std::memcpy(newString, string.data(), string.size());
|
std::memcpy(newString, string.data(), string.size());
|
||||||
return newString;
|
return newString;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Memory::Free(void* data)
|
void Memory::Free(void* data)
|
||||||
{
|
{
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
delete[] data;
|
delete[] data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Memory::Free(const void* data)
|
void Memory::Free(const void* data)
|
||||||
{
|
{
|
||||||
Memory::Free(const_cast<void*>(data));
|
Memory::Free(const_cast<void*>(data));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// Complementary function for memset, which checks if memory is filled with a char
|
||||||
|
bool Memory::IsSet(void* mem, char chr, size_t length)
|
||||||
|
{
|
||||||
|
char* memArr = reinterpret_cast<char*>(mem);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < length; ++i)
|
||||||
|
{
|
||||||
|
if (memArr[i] != chr)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,80 +1,90 @@
|
|||||||
namespace Utils
|
namespace Utils
|
||||||
{
|
{
|
||||||
class Memory
|
class Memory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
class Allocator
|
class Allocator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef void(*FreeCallback)(void*);
|
typedef void(*FreeCallback)(void*);
|
||||||
|
|
||||||
Allocator()
|
Allocator()
|
||||||
{
|
{
|
||||||
this->Pool.clear();
|
this->Pool.clear();
|
||||||
this->RefMemory.clear();
|
this->RefMemory.clear();
|
||||||
}
|
}
|
||||||
~Allocator()
|
~Allocator()
|
||||||
{
|
{
|
||||||
this->Free();
|
this->Free();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Free()
|
void Free()
|
||||||
{
|
{
|
||||||
for (auto i = this->RefMemory.begin(); i != this->RefMemory.end(); ++i)
|
for (auto i = this->RefMemory.begin(); i != this->RefMemory.end(); ++i)
|
||||||
{
|
{
|
||||||
if (i->first && i->second)
|
if (i->first && i->second)
|
||||||
{
|
{
|
||||||
i->second(i->first);
|
i->second(i->first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this->RefMemory.clear();
|
this->RefMemory.clear();
|
||||||
|
|
||||||
for (auto data : this->Pool)
|
for (auto data : this->Pool)
|
||||||
{
|
{
|
||||||
Memory::Free(data);
|
Memory::Free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->Pool.clear();
|
this->Pool.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Reference(void* memory, FreeCallback callback)
|
void Reference(void* memory, FreeCallback callback)
|
||||||
{
|
{
|
||||||
this->RefMemory[memory] = callback;
|
this->RefMemory[memory] = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* Allocate(size_t length)
|
void* Allocate(size_t length)
|
||||||
{
|
{
|
||||||
void* data = Memory::Allocate(length);
|
void* data = Memory::Allocate(length);
|
||||||
this->Pool.push_back(data);
|
this->Pool.push_back(data);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
template <typename T> T* AllocateArray(size_t count = 1)
|
template <typename T> T* Allocate()
|
||||||
{
|
{
|
||||||
return static_cast<T*>(this->Allocate(count * sizeof(T)));
|
return this->AllocateArray<T>(1);
|
||||||
}
|
}
|
||||||
|
template <typename T> T* AllocateArray(size_t count = 1)
|
||||||
char* DuplicateString(std::string string)
|
{
|
||||||
{
|
return static_cast<T*>(this->Allocate(count * sizeof(T)));
|
||||||
char* data = Memory::DuplicateString(string);
|
}
|
||||||
this->Pool.push_back(data);
|
|
||||||
return data;
|
char* DuplicateString(std::string string)
|
||||||
}
|
{
|
||||||
|
char* data = Memory::DuplicateString(string);
|
||||||
private:
|
this->Pool.push_back(data);
|
||||||
std::vector<void*> Pool;
|
return data;
|
||||||
std::map<void*, FreeCallback> RefMemory;
|
}
|
||||||
};
|
|
||||||
|
private:
|
||||||
static void* Allocate(size_t length);
|
std::vector<void*> Pool;
|
||||||
template <typename T> static T* AllocateArray(size_t count = 1)
|
std::map<void*, FreeCallback> RefMemory;
|
||||||
{
|
};
|
||||||
return static_cast<T*>(Allocate(count * sizeof(T)));
|
|
||||||
}
|
static void* Allocate(size_t length);
|
||||||
|
template <typename T> static T* Allocate()
|
||||||
static char* DuplicateString(std::string string);
|
{
|
||||||
|
return AllocateArray<T>(1);
|
||||||
static void Free(void* data);
|
}
|
||||||
static void Free(const void* data);
|
template <typename T> static T* AllocateArray(size_t count = 1)
|
||||||
};
|
{
|
||||||
}
|
return static_cast<T*>(Allocate(count * sizeof(T)));
|
||||||
|
}
|
||||||
|
|
||||||
|
static char* DuplicateString(std::string string);
|
||||||
|
|
||||||
|
static void Free(void* data);
|
||||||
|
static void Free(const void* data);
|
||||||
|
|
||||||
|
static bool IsSet(void* mem, char chr, size_t length);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -16,22 +16,6 @@ namespace Utils
|
|||||||
return "application/octet-stream";
|
return "application/octet-stream";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Complementary function for memset, which checks if a memory is set
|
|
||||||
bool MemIsSet(void* mem, char chr, size_t length)
|
|
||||||
{
|
|
||||||
char* memArr = reinterpret_cast<char*>(mem);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < length; ++i)
|
|
||||||
{
|
|
||||||
if (memArr[i] != chr)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string ParseChallenge(std::string data)
|
std::string ParseChallenge(std::string data)
|
||||||
{
|
{
|
||||||
auto pos = data.find_first_of("\n ");
|
auto pos = data.find_first_of("\n ");
|
||||||
|
@ -2,7 +2,6 @@ namespace Utils
|
|||||||
{
|
{
|
||||||
std::string GetMimeType(std::string url);
|
std::string GetMimeType(std::string url);
|
||||||
std::string ParseChallenge(std::string data);
|
std::string ParseChallenge(std::string data);
|
||||||
bool MemIsSet(void* mem, char chr, size_t length);
|
|
||||||
|
|
||||||
template <typename T> void Merge(std::vector<T>* target, T* source, size_t length)
|
template <typename T> void Merge(std::vector<T>* target, T* source, size_t length)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user