[CodeStyle] Refactor the code to match our basic style guidelines

This commit is contained in:
momo5502 2016-11-20 14:09:07 +01:00
parent 98f8b4d04b
commit 8085e4bd88
166 changed files with 2934 additions and 2988 deletions

View File

@ -85,7 +85,7 @@ namespace Components
#ifdef DEBUG
if(!Loader::PerformingUnitTests())
{
Logger::Print("Unregistering component: %s\n", component->GetName());
Logger::Print("Unregistering component: %s\n", component->getName());
}
#endif
delete component;
@ -103,10 +103,10 @@ namespace Components
for (auto component : Loader::Components)
{
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
Logger::Print("Testing '%s'...\n", component->GetName());
Logger::Print("Testing '%s'...\n", component->getName());
#endif
auto startTime = std::chrono::high_resolution_clock::now();
bool testRes = component->UnitTest();
bool testRes = component->unitTest();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - startTime).count();
Logger::Print("Test done (%llims): %s\n\n", duration, (testRes ? "Success" : "Error"));
result &= testRes;
@ -131,7 +131,7 @@ namespace Components
#ifdef DEBUG
if(!Loader::PerformingUnitTests())
{
Logger::Print("Component registered: %s\n", component->GetName());
Logger::Print("Component registered: %s\n", component->getName());
}
#endif
Loader::Components.push_back(component);

View File

@ -7,10 +7,10 @@ namespace Components
virtual ~Component() {};
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
virtual const char* GetName() { return "Unknown"; };
virtual const char* getName() { return "Unknown"; };
#endif
virtual bool UnitTest() { return true; }; // Unit testing entry
virtual bool unitTest() { return true; }; // Unit testing entry
};
class Loader

View File

@ -86,14 +86,14 @@ namespace Components
if (loadLibA && loadLibW)
{
#ifdef DEBUG_LOAD_LIBRARY
AntiCheat::LoadLibHook[0].Initialize(loadLibA, LoadLibaryAStub, HOOK_JUMP);
AntiCheat::LoadLibHook[1].Initialize(loadLibW, LoadLibaryWStub, HOOK_JUMP);
AntiCheat::LoadLibHook[0].initialize(loadLibA, LoadLibaryAStub, HOOK_JUMP);
AntiCheat::LoadLibHook[1].initialize(loadLibW, LoadLibaryWStub, HOOK_JUMP);
#else
AntiCheat::LoadLibHook[0].Initialize(loadLibA, loadLibStub, HOOK_JUMP);
AntiCheat::LoadLibHook[1].Initialize(loadLibW, loadLibStub, HOOK_JUMP);
AntiCheat::LoadLibHook[0].initialize(loadLibA, loadLibStub, HOOK_JUMP);
AntiCheat::LoadLibHook[1].initialize(loadLibW, loadLibStub, HOOK_JUMP);
#endif
//AntiCheat::LoadLibHook[2].Initialize(LoadLibraryExA, loadLibExStub, HOOK_JUMP);
//AntiCheat::LoadLibHook[3].Initialize(LoadLibraryExW, loadLibExStub, HOOK_JUMP);
//AntiCheat::LoadLibHook[2].initialize(LoadLibraryExA, loadLibExStub, HOOK_JUMP);
//AntiCheat::LoadLibHook[3].initialize(LoadLibraryExW, loadLibExStub, HOOK_JUMP);
}
}
}
@ -102,9 +102,9 @@ namespace Components
{
static Utils::Time::Interval check;
if(check.Elapsed(20s))
if(check.elapsed(20s))
{
check.Update();
check.update();
if (HANDLE h = OpenProcess(PROCESS_VM_READ, TRUE, GetCurrentProcessId()))
{
@ -125,9 +125,9 @@ namespace Components
{
static Utils::Time::Interval check;
if (check.Elapsed(30s))
if (check.elapsed(30s))
{
check.Update();
check.update();
unsigned long flags = ((AntiCheat::IntergrityFlag::MAX_FLAG - 1) << 1) - 1;
@ -145,7 +145,7 @@ namespace Components
void AntiCheat::ScanIntegrityCheck()
{
// If there was no check within the last 40 seconds, crash!
if (AntiCheat::LastCheck.Elapsed(40s))
if (AntiCheat::LastCheck.elapsed(40s))
{
#ifdef DEBUG_DETECTIONS
Logger::Print("AntiCheat: Integrity check failed");
@ -161,8 +161,8 @@ namespace Components
void AntiCheat::PerformScan()
{
// Perform check only every 10 seconds
if (!AntiCheat::LastCheck.Elapsed(10s)) return;
AntiCheat::LastCheck.Update();
if (!AntiCheat::LastCheck.elapsed(10s)) return;
AntiCheat::LastCheck.update();
// Hash .text segment
// Add 1 to each value, so searching in memory doesn't reveal anything
@ -219,16 +219,16 @@ namespace Components
{
for (int i = 0; i < ARRAYSIZE(AntiCheat::LoadLibHook); ++i)
{
AntiCheat::LoadLibHook[i].Uninstall();
AntiCheat::LoadLibHook[i].uninstall();
}
}
void AntiCheat::InstallLibHook()
{
AntiCheat::LoadLibHook[0].Install();
AntiCheat::LoadLibHook[1].Install();
//AntiCheat::LoadLibHook[2].Install();
//AntiCheat::LoadLibHook[3].Install();
AntiCheat::LoadLibHook[0].install();
AntiCheat::LoadLibHook[1].install();
//AntiCheat::LoadLibHook[2].install();
//AntiCheat::LoadLibHook[3].install();
}
void AntiCheat::PatchWinAPI()
@ -347,7 +347,7 @@ namespace Components
}
};
allocator.Reference(hToken, [] (void* hToken)
allocator.reference(hToken, [] (void* hToken)
{
if (hToken)
{
@ -361,7 +361,7 @@ namespace Components
if (dwSize)
{
pTokenInfo = allocator.Allocate(dwSize);
pTokenInfo = allocator.allocate(dwSize);
if (!pTokenInfo) return GetLastError();
}
@ -372,17 +372,17 @@ namespace Components
PSID psidEveryone = nullptr;
SID_IDENTIFIER_AUTHORITY sidEveryone = SECURITY_WORLD_SID_AUTHORITY;
if (!AllocateAndInitializeSid(&sidEveryone, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &psidEveryone) || !psidEveryone) return GetLastError();
allocator.Reference(psidEveryone, freeSid);
allocator.reference(psidEveryone, freeSid);
PSID psidSystem = nullptr;
SID_IDENTIFIER_AUTHORITY sidSystem = SECURITY_NT_AUTHORITY;
if (!AllocateAndInitializeSid(&sidSystem, 1, SECURITY_LOCAL_SYSTEM_RID, 0, 0, 0, 0, 0, 0, 0, &psidSystem) || !psidSystem) return GetLastError();
allocator.Reference(psidSystem, freeSid);
allocator.reference(psidSystem, freeSid);
PSID psidAdmins = nullptr;
SID_IDENTIFIER_AUTHORITY sidAdministrators = SECURITY_NT_AUTHORITY;
if (!AllocateAndInitializeSid(&sidAdministrators, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &psidAdmins) || !psidAdmins) return GetLastError();
allocator.Reference(psidAdmins, freeSid);
allocator.reference(psidAdmins, freeSid);
const PSID psidArray[] =
{
@ -406,7 +406,7 @@ namespace Components
dwSize += sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD);
}
PACL pDacl = reinterpret_cast<PACL>(allocator.Allocate(dwSize));
PACL pDacl = reinterpret_cast<PACL>(allocator.allocate(dwSize));
if (!pDacl || !InitializeAcl(pDacl, dwSize, ACL_REVISION)) return GetLastError();
// Mimic Protected Process
@ -444,7 +444,7 @@ namespace Components
// due to Restricted tokens.
if (!AddAccessAllowedAce(pDacl, ACL_REVISION, PROCESS_ALL_ACCESS, psidArray[3])) return GetLastError();
PSECURITY_DESCRIPTOR pSecDesc = allocator.Allocate<SECURITY_DESCRIPTOR>();
PSECURITY_DESCRIPTOR pSecDesc = allocator.allocate<SECURITY_DESCRIPTOR>();
if (!pSecDesc) return GetLastError();
// InitializeSecurityDescriptor initializes a security descriptor in
@ -476,18 +476,18 @@ namespace Components
});
#else
Utils::Hook(0x507BD5, AntiCheat::PatchWinAPI, HOOK_CALL).Install()->Quick();
Utils::Hook(0x5082FD, AntiCheat::LostD3DStub, HOOK_CALL).Install()->Quick();
Utils::Hook(0x51C76C, AntiCheat::CinematicStub, HOOK_CALL).Install()->Quick();
Utils::Hook(0x418209, AntiCheat::SoundInitStub, HOOK_CALL).Install()->Quick();
Utils::Hook(0x60BE9D, AntiCheat::SoundInitStub, HOOK_CALL).Install()->Quick();
Utils::Hook(0x60BE8E, AntiCheat::SoundInitDriverStub, HOOK_CALL).Install()->Quick();
Utils::Hook(0x418204, AntiCheat::SoundInitDriverStub, HOOK_CALL).Install()->Quick();
Utils::Hook(0x507BD5, AntiCheat::PatchWinAPI, HOOK_CALL).install()->quick();
Utils::Hook(0x5082FD, AntiCheat::LostD3DStub, HOOK_CALL).install()->quick();
Utils::Hook(0x51C76C, AntiCheat::CinematicStub, HOOK_CALL).install()->quick();
Utils::Hook(0x418209, AntiCheat::SoundInitStub, HOOK_CALL).install()->quick();
Utils::Hook(0x60BE9D, AntiCheat::SoundInitStub, HOOK_CALL).install()->quick();
Utils::Hook(0x60BE8E, AntiCheat::SoundInitDriverStub, HOOK_CALL).install()->quick();
Utils::Hook(0x418204, AntiCheat::SoundInitDriverStub, HOOK_CALL).install()->quick();
Renderer::OnFrame(AntiCheat::PerformScan);
// Detect aimbots
Utils::Hook(0x426580, AntiCheat::DObjGetWorldTagPosStub, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x56AC60, AntiCheat::AimTargetGetTagPosStub, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x426580, AntiCheat::DObjGetWorldTagPosStub, HOOK_JUMP).install()->quick();
Utils::Hook(0x56AC60, AntiCheat::AimTargetGetTagPosStub, HOOK_JUMP).install()->quick();
// TODO: Probably move that :P
if (!Dedicated::IsEnabled())
@ -514,7 +514,7 @@ namespace Components
for (int i = 0; i < ARRAYSIZE(AntiCheat::LoadLibHook); ++i)
{
AntiCheat::LoadLibHook[i].Uninstall();
AntiCheat::LoadLibHook[i].uninstall();
}
}
}

View File

@ -12,7 +12,7 @@ namespace Components
~AntiCheat();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "AntiCheat"; };
const char* getName() { return "AntiCheat"; };
#endif
static void CrashClient();

View File

@ -104,10 +104,10 @@ namespace Components
Utils::Hook::Set<int>(0x631EBC, sizeof(Game::newMapArena_t));
Utils::Hook::Set<int>(0x6327AF, sizeof(Game::newMapArena_t));
Utils::Hook(0x420720, ArenaLength::ArenaMapOffsetHook1, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x49BD39, ArenaLength::ArenaMapOffsetHook2, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x632799, ArenaLength::ArenaMapOffsetHook3, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x4064B2, ArenaLength::ArenaMapOffsetHook4, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x420720, ArenaLength::ArenaMapOffsetHook1, HOOK_JUMP).install()->quick();
Utils::Hook(0x49BD39, ArenaLength::ArenaMapOffsetHook2, HOOK_JUMP).install()->quick();
Utils::Hook(0x632799, ArenaLength::ArenaMapOffsetHook3, HOOK_JUMP).install()->quick();
Utils::Hook(0x4064B2, ArenaLength::ArenaMapOffsetHook4, HOOK_JUMP).install()->quick();
Utils::Hook::Set<BYTE>(0x4A95F8, 32);

View File

@ -6,7 +6,7 @@ namespace Components
ArenaLength();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "ArenaLength"; };
const char* getName() { return "ArenaLength"; };
#endif
static Game::newMapArena_t NewArenas[128];
@ -16,6 +16,5 @@ namespace Components
static void ArenaMapOffsetHook2();
static void ArenaMapOffsetHook3();
static void ArenaMapOffsetHook4();
static void ArenaMapOffsetHook5();
};
}

View File

@ -16,23 +16,23 @@ namespace Components
void AssetHandler::RegisterInterface(IAsset* iAsset)
{
if (!iAsset) return;
if (iAsset->GetType() == Game::XAssetType::ASSET_TYPE_INVALID)
if (iAsset->getType() == Game::XAssetType::ASSET_TYPE_INVALID)
{
delete iAsset;
return;
}
if (AssetHandler::AssetInterfaces.find(iAsset->GetType()) != AssetHandler::AssetInterfaces.end())
if (AssetHandler::AssetInterfaces.find(iAsset->getType()) != AssetHandler::AssetInterfaces.end())
{
Logger::Print("Duplicate asset interface: %s\n", Game::DB_GetXAssetTypeName(iAsset->GetType()));
delete AssetHandler::AssetInterfaces[iAsset->GetType()];
Logger::Print("Duplicate asset interface: %s\n", Game::DB_GetXAssetTypeName(iAsset->getType()));
delete AssetHandler::AssetInterfaces[iAsset->getType()];
}
else
{
Logger::Print("Asset interface registered: %s\n", Game::DB_GetXAssetTypeName(iAsset->GetType()));
Logger::Print("Asset interface registered: %s\n", Game::DB_GetXAssetTypeName(iAsset->getType()));
}
AssetHandler::AssetInterfaces[iAsset->GetType()] = iAsset;
AssetHandler::AssetInterfaces[iAsset->getType()] = iAsset;
}
void AssetHandler::ClearTemporaryAssets()
@ -237,7 +237,7 @@ namespace Components
void AssetHandler::OffsetToAlias(Utils::Stream::Offset* offset)
{
// Same here, reinterpret the value, as we're operating inside the game's environment
void* pointer = (*Game::g_streamBlocks)[offset->GetUnpackedBlock()].data + offset->GetUnpackedOffset();
void* pointer = (*Game::g_streamBlocks)[offset->getUnpackedBlock()].data + offset->getUnpackedOffset();
if (AssetHandler::Relocations.find(pointer) != AssetHandler::Relocations.end())
{
@ -255,7 +255,7 @@ namespace Components
{
if (AssetHandler::AssetInterfaces.find(asset.type) != AssetHandler::AssetInterfaces.end())
{
AssetHandler::AssetInterfaces[asset.type]->Save(asset.header, builder);
AssetHandler::AssetInterfaces[asset.type]->save(asset.header, builder);
}
else
{
@ -267,7 +267,7 @@ namespace Components
{
if (AssetHandler::AssetInterfaces.find(asset.type) != AssetHandler::AssetInterfaces.end())
{
AssetHandler::AssetInterfaces[asset.type]->Mark(asset.header, builder);
AssetHandler::AssetInterfaces[asset.type]->mark(asset.header, builder);
}
else
{
@ -289,7 +289,7 @@ namespace Components
if (AssetHandler::AssetInterfaces.find(type) != AssetHandler::AssetInterfaces.end())
{
AssetHandler::AssetInterfaces[type]->Load(&header, filename, builder);
AssetHandler::AssetInterfaces[type]->load(&header, filename, builder);
if (header.data)
{
@ -348,16 +348,16 @@ namespace Components
AssetHandler::ClearTemporaryAssets();
// DB_FindXAssetHeader
Utils::Hook(Game::DB_FindXAssetHeader, AssetHandler::FindAssetStub).Install()->Quick();
Utils::Hook(Game::DB_FindXAssetHeader, AssetHandler::FindAssetStub).install()->quick();
// DB_ConvertOffsetToAlias
Utils::Hook(0x4FDFA0, AssetHandler::OffsetToAlias, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x4FDFA0, AssetHandler::OffsetToAlias, HOOK_JUMP).install()->quick();
// DB_AddXAsset
Utils::Hook(0x5BB650, AssetHandler::AddAssetStub, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x5BB650, AssetHandler::AddAssetStub, HOOK_JUMP).install()->quick();
// Store empty assets
Utils::Hook(0x5BB6EC, AssetHandler::StoreEmptyAssetStub, HOOK_CALL).Install()->Quick();
Utils::Hook(0x5BB6EC, AssetHandler::StoreEmptyAssetStub, HOOK_CALL).install()->quick();
// Log missing empty assets
QuickPatch::OnFrame([] ()
@ -375,7 +375,7 @@ namespace Components
AssetHandler::OnLoad([] (Game::XAssetType type, Game::XAssetHeader asset, std::string name, bool*)
{
if (Dvar::Var("r_noVoid").Get<bool>() && type == Game::XAssetType::ASSET_TYPE_XMODEL && name == "void")
if (Dvar::Var("r_noVoid").get<bool>() && type == Game::XAssetType::ASSET_TYPE_XMODEL && name == "void")
{
asset.model->numLods = 0;
}

View File

@ -7,11 +7,11 @@ namespace Components
{
public:
virtual ~IAsset() {};
virtual Game::XAssetType GetType() { return Game::XAssetType::ASSET_TYPE_INVALID; };
virtual void Mark(Game::XAssetHeader /*header*/, ZoneBuilder::Zone* /*builder*/) { /*ErrorTypeNotSupported(this);*/ };
virtual void Save(Game::XAssetHeader /*header*/, ZoneBuilder::Zone* /*builder*/) { /*ErrorTypeNotSupported(this);*/ };
virtual void Dump(Game::XAssetHeader /*header*/) { /*ErrorTypeNotSupported(this);*/ };
virtual void Load(Game::XAssetHeader* /*header*/, std::string name, ZoneBuilder::Zone* /*builder*/) { /*ErrorTypeNotSupported(this);*/ };
virtual Game::XAssetType getType() { return Game::XAssetType::ASSET_TYPE_INVALID; };
virtual void mark(Game::XAssetHeader /*header*/, ZoneBuilder::Zone* /*builder*/) { /*ErrorTypeNotSupported(this);*/ };
virtual void save(Game::XAssetHeader /*header*/, ZoneBuilder::Zone* /*builder*/) { /*ErrorTypeNotSupported(this);*/ };
virtual void dump(Game::XAssetHeader /*header*/) { /*ErrorTypeNotSupported(this);*/ };
virtual void load(Game::XAssetHeader* /*header*/, std::string name, ZoneBuilder::Zone* /*builder*/) { /*ErrorTypeNotSupported(this);*/ };
};
typedef Game::XAssetHeader(Callback)(Game::XAssetType type, std::string name);
@ -21,7 +21,7 @@ namespace Components
~AssetHandler();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "AssetHandler"; };
const char* getName() { return "AssetHandler"; };
#endif
static void OnFind(Game::XAssetType type, Callback* callback);
@ -30,10 +30,6 @@ namespace Components
static void ClearRelocations();
static void Relocate(void* start, void* to, DWORD size = 4);
static void Relocate(DWORD start, DWORD size, DWORD to) {
Relocate((void*)start, (void*)to, size);
}
static void ZoneSave(Game::XAsset asset, ZoneBuilder::Zone* builder);
static void ZoneMark(Game::XAsset asset, ZoneBuilder::Zone* builder);

View File

@ -2,24 +2,24 @@
namespace Assets
{
void IGfxImage::Load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
void IGfxImage::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
{
Game::GfxImage* image = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_IMAGE, name.data()).image;
if (image) return;
image = builder->GetAllocator()->Allocate<Game::GfxImage>();
image = builder->getAllocator()->allocate<Game::GfxImage>();
if (!image)
{
Components::Logger::Error("Failed to allocate GfxImage structure!");
return;
}
image->name = builder->GetAllocator()->DuplicateString(name);
image->name = builder->getAllocator()->duplicateString(name);
image->semantic = 2;
image->category = 0;
image->cardMemory = 0;
image->loadDef = builder->GetAllocator()->Allocate<Game::GfxImageLoadDef>();
image->loadDef = builder->getAllocator()->allocate<Game::GfxImageLoadDef>();
if (!image->loadDef)
{
Components::Logger::Error("Failed to allocate GfxImageLoadDef structure!");
@ -28,13 +28,13 @@ namespace Assets
Components::FileSystem::File iwi(fmt::sprintf("images/%s.iwi", name.data()));
if (!iwi.Exists())
if (!iwi.exists())
{
Components::Logger::Error("Loading image '%s' failed!", iwi.GetName().data());
Components::Logger::Error("Loading image '%s' failed!", iwi.getName().data());
return;
}
auto iwiBuffer = iwi.GetBuffer();
auto iwiBuffer = iwi.getBuffer();
const Game::GfxImageFileHeader* iwiHeader = reinterpret_cast<const Game::GfxImageFileHeader*>(iwiBuffer.data());
@ -88,31 +88,31 @@ namespace Assets
header->image = image;
}
void IGfxImage::Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
void IGfxImage::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{
Assert_Size(Game::GfxImage, 32);
AssertSize(Game::GfxImage, 32);
Utils::Stream* buffer = builder->GetBuffer();
Utils::Stream* buffer = builder->getBuffer();
Game::GfxImage* asset = header.image;
Game::GfxImage* dest = buffer->Dest<Game::GfxImage>();
buffer->Save(asset);
Game::GfxImage* dest = buffer->dest<Game::GfxImage>();
buffer->save(asset);
buffer->PushBlock(Game::XFILE_BLOCK_VIRTUAL);
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
if (asset->name)
{
buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name));
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
Utils::Stream::ClearPointer(&dest->name);
}
buffer->PushBlock(Game::XFILE_BLOCK_TEMP);
buffer->pushBlock(Game::XFILE_BLOCK_TEMP);
if (asset->texture)
{
buffer->Align(Utils::Stream::ALIGN_4);
buffer->align(Utils::Stream::ALIGN_4);
Game::GfxImageLoadDef* destTexture = buffer->Dest<Game::GfxImageLoadDef>();
buffer->Save(asset->texture, 16);
Game::GfxImageLoadDef* destTexture = buffer->dest<Game::GfxImageLoadDef>();
buffer->save(asset->texture, 16);
// Zero the size!
destTexture->dataSize = 0;
@ -120,7 +120,7 @@ namespace Assets
Utils::Stream::ClearPointer(&dest->texture);
}
buffer->PopBlock();
buffer->PopBlock();
buffer->popBlock();
buffer->popBlock();
}
}

View File

@ -3,9 +3,9 @@ namespace Assets
class IGfxImage : public Components::AssetHandler::IAsset
{
public:
virtual Game::XAssetType GetType() override { return Game::XAssetType::ASSET_TYPE_IMAGE; };
virtual Game::XAssetType getType() override { return Game::XAssetType::ASSET_TYPE_IMAGE; };
virtual void Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void Load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override;
virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override;
};
}

View File

@ -2,29 +2,29 @@
namespace Assets
{
void ILocalizedEntry::Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
void ILocalizedEntry::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{
Assert_Size(Game::LocalizedEntry, 8);
AssertSize(Game::LocalizedEntry, 8);
Utils::Stream* buffer = builder->GetBuffer();
Utils::Stream* buffer = builder->getBuffer();
Game::LocalizedEntry* asset = header.localize;
Game::LocalizedEntry* dest = buffer->Dest<Game::LocalizedEntry>();
buffer->Save(asset);
Game::LocalizedEntry* dest = buffer->dest<Game::LocalizedEntry>();
buffer->save(asset);
buffer->PushBlock(Game::XFILE_BLOCK_VIRTUAL);
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
if (asset->value)
{
buffer->SaveString(asset->value);
buffer->saveString(asset->value);
Utils::Stream::ClearPointer(&dest->value);
}
if (asset->name)
{
buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name));
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
Utils::Stream::ClearPointer(&dest->name);
}
buffer->PopBlock();
buffer->popBlock();
}
}

View File

@ -3,8 +3,8 @@ namespace Assets
class ILocalizedEntry : public Components::AssetHandler::IAsset
{
public:
virtual Game::XAssetType GetType() override { return Game::XAssetType::ASSET_TYPE_LOCALIZE; };
virtual Game::XAssetType getType() override { return Game::XAssetType::ASSET_TYPE_LOCALIZE; };
virtual void Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
};
}

View File

@ -2,13 +2,13 @@
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");
if (ents.Exists())
if (ents.exists())
{
Game::MapEnts* entites = builder->GetAllocator()->Allocate<Game::MapEnts>();
Game::MapEnts* orgEnts = Components::AssetHandler::FindOriginalAsset(this->GetType(), name.data()).mapEnts;
Game::MapEnts* entites = builder->getAllocator()->allocate<Game::MapEnts>();
Game::MapEnts* orgEnts = Components::AssetHandler::FindOriginalAsset(this->getType(), name.data()).mapEnts;
if (orgEnts)
{
@ -16,90 +16,90 @@ namespace Assets
}
else
{
entites->name = builder->GetAllocator()->DuplicateString(name);
entites->name = builder->getAllocator()->duplicateString(name);
}
entites->entityString = builder->GetAllocator()->DuplicateString(ents.GetBuffer());
entites->numEntityChars = ents.GetBuffer().size() + 1;
entites->entityString = builder->getAllocator()->duplicateString(ents.getBuffer());
entites->numEntityChars = ents.getBuffer().size() + 1;
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);
AssertSize(Game::MapEnts, 44);
Utils::Stream* buffer = builder->GetBuffer();
Utils::Stream* buffer = builder->getBuffer();
Game::MapEnts* asset = header.mapEnts;
Game::MapEnts* dest = buffer->Dest<Game::MapEnts>();
buffer->Save(asset);
Game::MapEnts* dest = buffer->dest<Game::MapEnts>();
buffer->save(asset);
buffer->PushBlock(Game::XFILE_BLOCK_VIRTUAL);
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
if (asset->name)
{
buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name));
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
Utils::Stream::ClearPointer(&dest->name);
}
if (asset->entityString)
{
buffer->Save(asset->entityString, asset->numEntityChars);
buffer->save(asset->entityString, asset->numEntityChars);
Utils::Stream::ClearPointer(&dest->entityString);
}
if (asset->trigger.models)
{
Assert_Size(Game::TriggerModel, 8);
buffer->Align(Utils::Stream::ALIGN_4);
AssertSize(Game::TriggerModel, 8);
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);
}
if (asset->trigger.hulls)
{
Assert_Size(Game::TriggerHull, 32);
buffer->Align(Utils::Stream::ALIGN_4);
AssertSize(Game::TriggerHull, 32);
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);
}
if (asset->trigger.slabs)
{
Assert_Size(Game::TriggerSlab, 20);
buffer->Align(Utils::Stream::ALIGN_4);
AssertSize(Game::TriggerSlab, 20);
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);
}
if (asset->stages)
{
Assert_Size(Game::Stage, 20);
AssertSize(Game::Stage, 20);
buffer->Align(Utils::Stream::ALIGN_4);
buffer->align(Utils::Stream::ALIGN_4);
Game::Stage* destStages = buffer->Dest<Game::Stage>();
buffer->SaveArray(asset->stages, asset->stageCount);
Game::Stage* destStages = buffer->dest<Game::Stage>();
buffer->saveArray(asset->stages, asset->stageCount);
for (int i = 0; i < asset->stageCount; ++i)
{
Game::Stage* destStage = &destStages[i];
Game::Stage* stage = &asset->stages[i];
buffer->SaveString(stage->stageName);
buffer->saveString(stage->stageName);
Utils::Stream::ClearPointer(&destStage->stageName);
}
Utils::Stream::ClearPointer(&dest->stages);
}
buffer->PopBlock();
buffer->popBlock();
}
}

View File

@ -3,9 +3,9 @@ namespace Assets
class IMapEnts : public Components::AssetHandler::IAsset
{
public:
virtual Game::XAssetType GetType() override { return Game::XAssetType::ASSET_TYPE_MAP_ENTS; };
virtual Game::XAssetType getType() override { return Game::XAssetType::ASSET_TYPE_MAP_ENTS; };
virtual void Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void Load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override;
virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override;
};
}

View File

@ -2,14 +2,14 @@
namespace Assets
{
void IMaterial::Load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
void IMaterial::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
{
Components::FileSystem::File materialInfo(fmt::sprintf("materials/%s.json", name.data()));
if (!materialInfo.Exists()) return;
if (!materialInfo.exists()) return;
std::string errors;
json11::Json infoData = json11::Json::parse(materialInfo.GetBuffer(), errors);
json11::Json infoData = json11::Json::parse(materialInfo.getBuffer(), errors);
if (!infoData.is_object())
{
@ -33,7 +33,7 @@ namespace Assets
return;
}
Game::Material* material = builder->GetAllocator()->Allocate<Game::Material>();
Game::Material* material = builder->getAllocator()->allocate<Game::Material>();
if (!material)
{
@ -43,7 +43,7 @@ namespace Assets
// Copy base material to our structure
std::memcpy(material, baseMaterial, sizeof(Game::Material));
material->name = builder->GetAllocator()->DuplicateString(name);
material->name = builder->getAllocator()->duplicateString(name);
material->textureAtlasRowCount = 1;
material->textureAtlasColumnCount = 1;
@ -75,7 +75,7 @@ namespace Assets
bool replaceTexture = Utils::String::StartsWith(name, "mc/");
if (replaceTexture)
{
Game::MaterialTextureDef* textureTable = builder->GetAllocator()->AllocateArray<Game::MaterialTextureDef>(baseMaterial->textureCount);
Game::MaterialTextureDef* textureTable = builder->getAllocator()->allocateArray<Game::MaterialTextureDef>(baseMaterial->textureCount);
std::memcpy(textureTable, baseMaterial->textureTable, sizeof(Game::MaterialTextureDef) * baseMaterial->textureCount);
material->textureTable = textureTable;
material->textureCount = baseMaterial->textureCount;
@ -138,7 +138,7 @@ namespace Assets
{
if (!textureList.empty())
{
Game::MaterialTextureDef* textureTable = builder->GetAllocator()->AllocateArray<Game::MaterialTextureDef>(textureList.size());
Game::MaterialTextureDef* textureTable = builder->getAllocator()->allocateArray<Game::MaterialTextureDef>(textureList.size());
if (!textureTable)
{
@ -162,13 +162,13 @@ namespace Assets
header->material = material;
}
void IMaterial::Mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
void IMaterial::mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{
Game::Material* asset = header.material;
if (asset->techniqueSet)
{
builder->LoadAsset(Game::XAssetType::ASSET_TYPE_TECHSET, asset->techniqueSet->name);
builder->loadAsset(Game::XAssetType::ASSET_TYPE_TECHSET, asset->techniqueSet->name);
}
if (asset->textureTable)
@ -181,56 +181,56 @@ namespace Assets
{
if (asset->textureTable[i].info.water->image)
{
builder->LoadAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->textureTable[i].info.water->image->name);
builder->loadAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->textureTable[i].info.water->image->name);
}
}
else
{
builder->LoadAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->textureTable[i].info.image->name);
builder->loadAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->textureTable[i].info.image->name);
}
}
}
}
}
void IMaterial::Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
void IMaterial::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{
Assert_Size(Game::Material, 96);
AssertSize(Game::Material, 96);
Utils::Stream* buffer = builder->GetBuffer();
Utils::Stream* buffer = builder->getBuffer();
Game::Material* asset = header.material;
Game::Material* dest = buffer->Dest<Game::Material>();
buffer->Save(asset);
Game::Material* dest = buffer->dest<Game::Material>();
buffer->save(asset);
buffer->PushBlock(Game::XFILE_BLOCK_VIRTUAL);
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
if (asset->name)
{
buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name));
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
Utils::Stream::ClearPointer(&dest->name);
}
if (asset->techniqueSet)
{
dest->techniqueSet = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_TECHSET, asset->techniqueSet->name).materialTechset;
dest->techniqueSet = builder->requireAsset(Game::XAssetType::ASSET_TYPE_TECHSET, asset->techniqueSet->name).materialTechset;
}
if (asset->textureTable)
{
Assert_Size(Game::MaterialTextureDef, 12);
AssertSize(Game::MaterialTextureDef, 12);
// Pointer/Offset insertion is untested, but it worked in T6, so I think it's fine
if (builder->HasPointer(asset->textureTable))
if (builder->hasPointer(asset->textureTable))
{
dest->textureTable = builder->GetPointer(asset->textureTable);
dest->textureTable = builder->getPointer(asset->textureTable);
}
else
{
buffer->Align(Utils::Stream::ALIGN_4);
builder->StorePointer(asset->textureTable);
buffer->align(Utils::Stream::ALIGN_4);
builder->storePointer(asset->textureTable);
Game::MaterialTextureDef* destTextureTable = buffer->Dest<Game::MaterialTextureDef>();
buffer->SaveArray(asset->textureTable, asset->textureCount);
Game::MaterialTextureDef* destTextureTable = buffer->dest<Game::MaterialTextureDef>();
buffer->saveArray(asset->textureTable, asset->textureCount);
for (char i = 0; i < asset->textureCount; ++i)
{
@ -239,41 +239,41 @@ namespace Assets
if (textureDef->semantic == SEMANTIC_WATER_MAP)
{
Assert_Size(Game::water_t, 68);
AssertSize(Game::water_t, 68);
Game::water_t* destWater = buffer->Dest<Game::water_t>();
Game::water_t* destWater = buffer->dest<Game::water_t>();
Game::water_t* water = textureDef->info.water;
if (water)
{
buffer->Align(Utils::Stream::ALIGN_4);
buffer->Save(water);
buffer->align(Utils::Stream::ALIGN_4);
buffer->save(water);
Utils::Stream::ClearPointer(&destTextureDef->info.water);
// Save_water_t
if (water->H0X)
{
buffer->Align(Utils::Stream::ALIGN_4);
buffer->Save(water->H0X, 8, water->M * water->N);
buffer->align(Utils::Stream::ALIGN_4);
buffer->save(water->H0X, 8, water->M * water->N);
Utils::Stream::ClearPointer(&destWater->H0X);
}
if (water->H0Y)
{
buffer->Align(Utils::Stream::ALIGN_4);
buffer->Save(water->H0Y, 4, water->M * water->N);
buffer->align(Utils::Stream::ALIGN_4);
buffer->save(water->H0Y, 4, water->M * water->N);
Utils::Stream::ClearPointer(&destWater->H0Y);
}
if (water->image)
{
destWater->image = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, water->image->name).image;
destWater->image = builder->requireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, water->image->name).image;
}
}
}
else if (textureDef->info.image)
{
destTextureDef->info.image = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, textureDef->info.image->name).image;
destTextureDef->info.image = builder->requireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, textureDef->info.image->name).image;
}
}
@ -283,38 +283,38 @@ namespace Assets
if (asset->constantTable)
{
Assert_Size(Game::MaterialConstantDef, 32);
AssertSize(Game::MaterialConstantDef, 32);
if (builder->HasPointer(asset->constantTable))
if (builder->hasPointer(asset->constantTable))
{
dest->constantTable = builder->GetPointer(asset->constantTable);
dest->constantTable = builder->getPointer(asset->constantTable);
}
else
{
buffer->Align(Utils::Stream::ALIGN_16);
builder->StorePointer(asset->constantTable);
buffer->align(Utils::Stream::ALIGN_16);
builder->storePointer(asset->constantTable);
buffer->SaveArray(asset->constantTable, asset->constantCount);
buffer->saveArray(asset->constantTable, asset->constantCount);
Utils::Stream::ClearPointer(&dest->constantTable);
}
}
if (asset->stateBitTable)
{
if (builder->HasPointer(asset->stateBitTable))
if (builder->hasPointer(asset->stateBitTable))
{
dest->stateBitTable = builder->GetPointer(asset->stateBitTable);
dest->stateBitTable = builder->getPointer(asset->stateBitTable);
}
else
{
buffer->Align(Utils::Stream::ALIGN_4);
builder->StorePointer(asset->stateBitTable);
buffer->align(Utils::Stream::ALIGN_4);
builder->storePointer(asset->stateBitTable);
buffer->Save(asset->stateBitTable, 8, asset->stateBitsCount);
buffer->save(asset->stateBitTable, 8, asset->stateBitsCount);
Utils::Stream::ClearPointer(&dest->stateBitTable);
}
}
buffer->PopBlock();
buffer->popBlock();
}
}

View File

@ -3,10 +3,10 @@ namespace Assets
class IMaterial : public Components::AssetHandler::IAsset
{
public:
virtual Game::XAssetType GetType() override { return Game::XAssetType::ASSET_TYPE_MATERIAL; };
virtual Game::XAssetType getType() override { return Game::XAssetType::ASSET_TYPE_MATERIAL; };
virtual void Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void Mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void Load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override;
virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override;
};
}

View File

@ -2,30 +2,30 @@
namespace Assets
{
void IMaterialPixelShader::Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
void IMaterialPixelShader::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{
Assert_Size(Game::MaterialPixelShader, 16);
AssertSize(Game::MaterialPixelShader, 16);
Utils::Stream* buffer = builder->GetBuffer();
Utils::Stream* buffer = builder->getBuffer();
Game::MaterialPixelShader* asset = header.pixelShader;
Game::MaterialPixelShader* dest = buffer->Dest<Game::MaterialPixelShader>();
buffer->Save(asset);
Game::MaterialPixelShader* dest = buffer->dest<Game::MaterialPixelShader>();
buffer->save(asset);
buffer->PushBlock(Game::XFILE_BLOCK_VIRTUAL);
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
if (asset->name)
{
buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name));
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
Utils::Stream::ClearPointer(&dest->name);
}
if (asset->loadDef.physicalPart)
{
buffer->Align(Utils::Stream::ALIGN_4);
buffer->Save(asset->loadDef.physicalPart, 4, asset->loadDef.cachedPartSize & 0xFFFF);
buffer->align(Utils::Stream::ALIGN_4);
buffer->save(asset->loadDef.physicalPart, 4, asset->loadDef.cachedPartSize & 0xFFFF);
Utils::Stream::ClearPointer(&dest->loadDef.physicalPart);
}
buffer->PopBlock();
buffer->popBlock();
}
}

View File

@ -3,8 +3,8 @@ namespace Assets
class IMaterialPixelShader : public Components::AssetHandler::IAsset
{
public:
virtual Game::XAssetType GetType() override { return Game::XAssetType::ASSET_TYPE_PIXELSHADER; };
virtual Game::XAssetType getType() override { return Game::XAssetType::ASSET_TYPE_PIXELSHADER; };
virtual void Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
};
}

View File

@ -2,7 +2,7 @@
namespace Assets
{
void IMaterialTechniqueSet::Mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
void IMaterialTechniqueSet::mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{
Game::MaterialTechniqueSet* asset = header.materialTechset;
@ -18,36 +18,36 @@ namespace Assets
if (pass->vertexDecl)
{
builder->LoadAsset(Game::XAssetType::ASSET_TYPE_VERTEXDECL, pass->vertexDecl->name);
builder->loadAsset(Game::XAssetType::ASSET_TYPE_VERTEXDECL, pass->vertexDecl->name);
}
if (pass->vertexShader)
{
builder->LoadAsset(Game::XAssetType::ASSET_TYPE_VERTEXSHADER, pass->vertexShader->name);
builder->loadAsset(Game::XAssetType::ASSET_TYPE_VERTEXSHADER, pass->vertexShader->name);
}
if (pass->pixelShader)
{
builder->LoadAsset(Game::XAssetType::ASSET_TYPE_PIXELSHADER, pass->pixelShader->name);
builder->loadAsset(Game::XAssetType::ASSET_TYPE_PIXELSHADER, pass->pixelShader->name);
}
}
}
}
void IMaterialTechniqueSet::Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
void IMaterialTechniqueSet::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{
Assert_Size(Game::MaterialTechniqueSet, 204);
AssertSize(Game::MaterialTechniqueSet, 204);
Utils::Stream* buffer = builder->GetBuffer();
Utils::Stream* buffer = builder->getBuffer();
Game::MaterialTechniqueSet* asset = header.materialTechset;
Game::MaterialTechniqueSet* dest = buffer->Dest<Game::MaterialTechniqueSet>();
buffer->Save(asset);
Game::MaterialTechniqueSet* dest = buffer->dest<Game::MaterialTechniqueSet>();
buffer->save(asset);
buffer->PushBlock(Game::XFILE_BLOCK_VIRTUAL);
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
if (asset->name)
{
buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name));
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
Utils::Stream::ClearPointer(&dest->name);
}
@ -60,56 +60,56 @@ namespace Assets
if (technique)
{
if (builder->HasPointer(technique))
if (builder->hasPointer(technique))
{
dest->techniques[i] = builder->GetPointer(technique);
dest->techniques[i] = builder->getPointer(technique);
}
else
{
// Size-check is obsolete, as the structure is dynamic
buffer->Align(Utils::Stream::ALIGN_4);
builder->StorePointer(technique);
buffer->align(Utils::Stream::ALIGN_4);
builder->storePointer(technique);
Game::MaterialTechnique* destTechnique = buffer->Dest<Game::MaterialTechnique>();
buffer->Save(technique, 8);
Game::MaterialTechnique* destTechnique = buffer->dest<Game::MaterialTechnique>();
buffer->save(technique, 8);
// Save_MaterialPassArray
Game::MaterialPass* destPasses = buffer->Dest<Game::MaterialPass>();
buffer->SaveArray(technique->passes, technique->numPasses);
Game::MaterialPass* destPasses = buffer->dest<Game::MaterialPass>();
buffer->saveArray(technique->passes, technique->numPasses);
for (short j = 0; j < technique->numPasses; ++j)
{
Assert_Size(Game::MaterialPass, 20);
AssertSize(Game::MaterialPass, 20);
Game::MaterialPass* destPass = &destPasses[j];
Game::MaterialPass* pass = &technique->passes[j];
if (pass->vertexDecl)
{
destPass->vertexDecl = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_VERTEXDECL, pass->vertexDecl->name).vertexDecl;
destPass->vertexDecl = builder->requireAsset(Game::XAssetType::ASSET_TYPE_VERTEXDECL, pass->vertexDecl->name).vertexDecl;
}
if (pass->vertexShader)
{
destPass->vertexShader = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_VERTEXSHADER, pass->vertexShader->name).vertexShader;
destPass->vertexShader = builder->requireAsset(Game::XAssetType::ASSET_TYPE_VERTEXSHADER, pass->vertexShader->name).vertexShader;
}
if (pass->pixelShader)
{
destPass->pixelShader = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_PIXELSHADER, pass->pixelShader->name).pixelShader;
destPass->pixelShader = builder->requireAsset(Game::XAssetType::ASSET_TYPE_PIXELSHADER, pass->pixelShader->name).pixelShader;
}
if (pass->argumentDef)
{
buffer->Align(Utils::Stream::ALIGN_4);
buffer->SaveArray(pass->argumentDef, pass->argCount1 + pass->argCount2 + pass->argCount3);
buffer->align(Utils::Stream::ALIGN_4);
buffer->saveArray(pass->argumentDef, pass->argCount1 + pass->argCount2 + pass->argCount3);
Utils::Stream::ClearPointer(&destPass->argumentDef);
}
}
if (technique->name)
{
buffer->SaveString(technique->name);
buffer->saveString(technique->name);
Utils::Stream::ClearPointer(&destTechnique->name);
}
@ -118,6 +118,6 @@ namespace Assets
}
}
buffer->PopBlock();
buffer->popBlock();
}
}

View File

@ -3,9 +3,9 @@ namespace Assets
class IMaterialTechniqueSet : public Components::AssetHandler::IAsset
{
public:
virtual Game::XAssetType GetType() override { return Game::XAssetType::ASSET_TYPE_TECHSET; };
virtual Game::XAssetType getType() override { return Game::XAssetType::ASSET_TYPE_TECHSET; };
virtual void Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void Mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
};
}

View File

@ -2,23 +2,23 @@
namespace Assets
{
void IMaterialVertexDeclaration::Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
void IMaterialVertexDeclaration::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{
Assert_Size(Game::MaterialVertexDeclaration, 100);
AssertSize(Game::MaterialVertexDeclaration, 100);
Utils::Stream* buffer = builder->GetBuffer();
Utils::Stream* buffer = builder->getBuffer();
Game::MaterialVertexDeclaration* asset = header.vertexDecl;
Game::MaterialVertexDeclaration* dest = buffer->Dest<Game::MaterialVertexDeclaration>();
buffer->Save(asset);
Game::MaterialVertexDeclaration* dest = buffer->dest<Game::MaterialVertexDeclaration>();
buffer->save(asset);
buffer->PushBlock(Game::XFILE_BLOCK_VIRTUAL);
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
if (asset->name)
{
buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name));
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
Utils::Stream::ClearPointer(&dest->name);
}
buffer->PopBlock();
buffer->popBlock();
}
}

View File

@ -3,8 +3,8 @@ namespace Assets
class IMaterialVertexDeclaration : public Components::AssetHandler::IAsset
{
public:
virtual Game::XAssetType GetType() override { return Game::XAssetType::ASSET_TYPE_VERTEXDECL; };
virtual Game::XAssetType getType() override { return Game::XAssetType::ASSET_TYPE_VERTEXDECL; };
virtual void Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
};
}

View File

@ -2,30 +2,30 @@
namespace Assets
{
void IMaterialVertexShader::Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
void IMaterialVertexShader::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{
Assert_Size(Game::MaterialVertexShader, 16);
AssertSize(Game::MaterialVertexShader, 16);
Utils::Stream* buffer = builder->GetBuffer();
Utils::Stream* buffer = builder->getBuffer();
Game::MaterialVertexShader* asset = header.vertexShader;
Game::MaterialVertexShader* dest = buffer->Dest<Game::MaterialVertexShader>();
buffer->Save(asset);
Game::MaterialVertexShader* dest = buffer->dest<Game::MaterialVertexShader>();
buffer->save(asset);
buffer->PushBlock(Game::XFILE_BLOCK_VIRTUAL);
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
if (asset->name)
{
buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name));
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
Utils::Stream::ClearPointer(&dest->name);
}
if (asset->loadDef.physicalPart)
{
buffer->Align(Utils::Stream::ALIGN_4);
buffer->Save(asset->loadDef.physicalPart, 4, asset->loadDef.cachedPartSize & 0xFFFF);
buffer->align(Utils::Stream::ALIGN_4);
buffer->save(asset->loadDef.physicalPart, 4, asset->loadDef.cachedPartSize & 0xFFFF);
Utils::Stream::ClearPointer(&dest->loadDef.physicalPart);
}
buffer->PopBlock();
buffer->popBlock();
}
}

View File

@ -3,8 +3,8 @@ namespace Assets
class IMaterialVertexShader : public Components::AssetHandler::IAsset
{
public:
virtual Game::XAssetType GetType() override { return Game::XAssetType::ASSET_TYPE_VERTEXSHADER; };
virtual Game::XAssetType getType() override { return Game::XAssetType::ASSET_TYPE_VERTEXSHADER; };
virtual void Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
};
}

View File

@ -2,27 +2,27 @@
namespace Assets
{
void IPhysCollmap::Save_BrushWrapper(Components::ZoneBuilder::Zone* builder, Game::BrushWrapper* brush)
void IPhysCollmap::saveBrushWrapper(Components::ZoneBuilder::Zone* builder, Game::BrushWrapper* brush)
{
Assert_Size(Game::BrushWrapper, 68);
AssertSize(Game::BrushWrapper, 68);
Utils::Stream* buffer = builder->GetBuffer();
Utils::Stream* buffer = builder->getBuffer();
Game::BrushWrapper* destBrush = buffer->Dest<Game::BrushWrapper>();
buffer->Save(brush);
Game::BrushWrapper* destBrush = buffer->dest<Game::BrushWrapper>();
buffer->save(brush);
// Save_cbrushWrapper_t
{
Assert_Size(Game::cbrushWrapper_t, 36);
AssertSize(Game::cbrushWrapper_t, 36);
if (brush->brush.brushSide)
{
Assert_Size(Game::cbrushside_t, 8);
AssertSize(Game::cbrushside_t, 8);
buffer->Align(Utils::Stream::ALIGN_4);
buffer->align(Utils::Stream::ALIGN_4);
Game::cbrushside_t* destBrushSide = buffer->Dest<Game::cbrushside_t>();
buffer->SaveArray(brush->brush.brushSide, brush->brush.count);
Game::cbrushside_t* destBrushSide = buffer->dest<Game::cbrushside_t>();
buffer->saveArray(brush->brush.brushSide, brush->brush.count);
// Save_cbrushside_tArray
for (short i = 0; i < brush->brush.count; ++i)
@ -32,16 +32,16 @@ namespace Assets
if (side->side)
{
if (builder->HasPointer(side->side))
if (builder->hasPointer(side->side))
{
destSide->side = builder->GetPointer(side->side);
destSide->side = builder->getPointer(side->side);
}
else
{
buffer->Align(Utils::Stream::ALIGN_4);
builder->StorePointer(side->side);
buffer->align(Utils::Stream::ALIGN_4);
builder->storePointer(side->side);
buffer->Save(side->side, sizeof(Game::cplane_t));
buffer->save(side->side, sizeof(Game::cplane_t));
Utils::Stream::ClearPointer(&destSide->side);
}
}
@ -52,38 +52,38 @@ namespace Assets
if (brush->brush.brushEdge)
{
buffer->Save(brush->brush.brushEdge, brush->totalEdgeCount);
buffer->save(brush->brush.brushEdge, brush->totalEdgeCount);
Utils::Stream::ClearPointer(&destBrush->brush.brushEdge);
}
}
if (brush->planes)
{
Assert_Size(Game::cplane_t, 20);
AssertSize(Game::cplane_t, 20);
if (builder->HasPointer(brush->planes))
if (builder->hasPointer(brush->planes))
{
destBrush->planes = builder->GetPointer(brush->planes);
destBrush->planes = builder->getPointer(brush->planes);
}
else
{
buffer->Align(Utils::Stream::ALIGN_4);
builder->StorePointer(brush->planes);
buffer->align(Utils::Stream::ALIGN_4);
builder->storePointer(brush->planes);
buffer->Save(brush->planes, sizeof(Game::cplane_t));
buffer->save(brush->planes, sizeof(Game::cplane_t));
Utils::Stream::ClearPointer(&destBrush->planes);
}
}
}
void IPhysCollmap::Save_PhysGeomInfoArray(Components::ZoneBuilder::Zone* builder, Game::PhysGeomInfo* geoms, unsigned int count)
void IPhysCollmap::savePhysGeomInfoArray(Components::ZoneBuilder::Zone* builder, Game::PhysGeomInfo* geoms, unsigned int count)
{
Assert_Size(Game::PhysGeomInfo, 68);
AssertSize(Game::PhysGeomInfo, 68);
Utils::Stream* buffer = builder->GetBuffer();
Utils::Stream* buffer = builder->getBuffer();
Game::PhysGeomInfo* destGeoms = buffer->Dest<Game::PhysGeomInfo>();
buffer->SaveArray(geoms, count);
Game::PhysGeomInfo* destGeoms = buffer->dest<Game::PhysGeomInfo>();
buffer->saveArray(geoms, count);
for (unsigned int i = 0; i < count; ++i)
{
@ -92,39 +92,39 @@ namespace Assets
if (geom->brush)
{
buffer->Align(Utils::Stream::ALIGN_4);
buffer->align(Utils::Stream::ALIGN_4);
IPhysCollmap::Save_BrushWrapper(builder, geom->brush);
this->saveBrushWrapper(builder, geom->brush);
Utils::Stream::ClearPointer(&destGeom->brush);
}
}
}
void IPhysCollmap::Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
void IPhysCollmap::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{
Assert_Size(Game::XModel, 304);
AssertSize(Game::XModel, 304);
Utils::Stream* buffer = builder->GetBuffer();
Utils::Stream* buffer = builder->getBuffer();
Game::PhysCollmap* asset = header.physCollmap;
Game::PhysCollmap* dest = buffer->Dest<Game::PhysCollmap>();
buffer->Save(asset, sizeof(Game::PhysCollmap));
Game::PhysCollmap* dest = buffer->dest<Game::PhysCollmap>();
buffer->save(asset, sizeof(Game::PhysCollmap));
buffer->PushBlock(Game::XFILE_BLOCK_VIRTUAL);
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
if (asset->name)
{
buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name));
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
Utils::Stream::ClearPointer(&dest->name);
}
if (asset->geoms)
{
buffer->Align(Utils::Stream::ALIGN_4);
buffer->align(Utils::Stream::ALIGN_4);
IPhysCollmap::Save_PhysGeomInfoArray(builder, asset->geoms, asset->count);
this->savePhysGeomInfoArray(builder, asset->geoms, asset->count);
Utils::Stream::ClearPointer(&dest->geoms);
}
buffer->PopBlock();
buffer->popBlock();
}
}

View File

@ -3,12 +3,12 @@ namespace Assets
class IPhysCollmap : public Components::AssetHandler::IAsset
{
public:
virtual Game::XAssetType GetType() override { return Game::XAssetType::ASSET_TYPE_PHYS_COLLMAP; };
virtual Game::XAssetType getType() override { return Game::XAssetType::ASSET_TYPE_PHYS_COLLMAP; };
virtual void Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
private:
void Save_PhysGeomInfoArray(Components::ZoneBuilder::Zone* builder, Game::PhysGeomInfo* geoms, unsigned int count);
void Save_BrushWrapper(Components::ZoneBuilder::Zone* builder, Game::BrushWrapper* brush);
void savePhysGeomInfoArray(Components::ZoneBuilder::Zone* builder, Game::PhysGeomInfo* geoms, unsigned int count);
void saveBrushWrapper(Components::ZoneBuilder::Zone* builder, Game::BrushWrapper* brush);
};
}

View File

@ -2,29 +2,29 @@
namespace Assets
{
void IPhysPreset::Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
void IPhysPreset::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{
Assert_Size(Game::PhysPreset, 44);
AssertSize(Game::PhysPreset, 44);
Utils::Stream* buffer = builder->GetBuffer();
Utils::Stream* buffer = builder->getBuffer();
Game::PhysPreset* asset = header.physPreset;
Game::PhysPreset* dest = buffer->Dest<Game::PhysPreset>();
buffer->Save(asset);
Game::PhysPreset* dest = buffer->dest<Game::PhysPreset>();
buffer->save(asset);
buffer->PushBlock(Game::XFILE_BLOCK_VIRTUAL);
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
if (asset->name)
{
buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name));
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
Utils::Stream::ClearPointer(&dest->name);
}
if (asset->sndAliasPrefix)
{
buffer->SaveString(asset->sndAliasPrefix);
buffer->saveString(asset->sndAliasPrefix);
Utils::Stream::ClearPointer(&dest->sndAliasPrefix);
}
buffer->PopBlock();
buffer->popBlock();
}
}

View File

@ -3,8 +3,8 @@ namespace Assets
class IPhysPreset : public Components::AssetHandler::IAsset
{
public:
virtual Game::XAssetType GetType() override { return Game::XAssetType::ASSET_TYPE_PHYSPRESET; };
virtual Game::XAssetType getType() override { return Game::XAssetType::ASSET_TYPE_PHYSPRESET; };
virtual void Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
};
}

View File

@ -2,42 +2,42 @@
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);
if (rawFile.Exists())
if (rawFile.exists())
{
Game::RawFile* asset = builder->GetAllocator()->Allocate<Game::RawFile>();
Game::RawFile* asset = builder->getAllocator()->allocate<Game::RawFile>();
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->compressedData = builder->GetAllocator()->DuplicateString(rawFile.GetBuffer());
asset->name = builder->getAllocator()->duplicateString(name);
asset->compressedData = builder->getAllocator()->duplicateString(rawFile.getBuffer());
asset->sizeCompressed = 0;//data.size();
asset->sizeUnCompressed = rawFile.GetBuffer().size();
asset->sizeUnCompressed = rawFile.getBuffer().size();
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);
AssertSize(Game::RawFile, 16);
Utils::Stream* buffer = builder->GetBuffer();
Utils::Stream* buffer = builder->getBuffer();
Game::RawFile* asset = header.rawfile;
Game::RawFile* dest = buffer->Dest<Game::RawFile>();
buffer->Save(asset);
Game::RawFile* dest = buffer->dest<Game::RawFile>();
buffer->save(asset);
buffer->PushBlock(Game::XFILE_BLOCK_VIRTUAL);
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
if (asset->name)
{
buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name));
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
Utils::Stream::ClearPointer(&dest->name);
}
@ -45,16 +45,16 @@ namespace Assets
{
if (asset->sizeCompressed)
{
buffer->Save(asset->compressedData, asset->sizeCompressed);
buffer->save(asset->compressedData, asset->sizeCompressed);
}
else
{
buffer->Save(asset->compressedData, asset->sizeUnCompressed + 1);
buffer->save(asset->compressedData, asset->sizeUnCompressed + 1);
}
Utils::Stream::ClearPointer(&dest->compressedData);
}
buffer->PopBlock();
buffer->popBlock();
}
}

View File

@ -3,9 +3,9 @@ namespace Assets
class IRawFile : public Components::AssetHandler::IAsset
{
public:
virtual Game::XAssetType GetType() override { return Game::XAssetType::ASSET_TYPE_RAWFILE; };
virtual Game::XAssetType getType() override { return Game::XAssetType::ASSET_TYPE_RAWFILE; };
virtual void Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void Load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override;
virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override;
};
}

View File

@ -2,50 +2,50 @@
namespace Assets
{
void IStringTable::Save_StringTableCellArray(Components::ZoneBuilder::Zone* builder, Game::StringTableCell* values, int count)
void IStringTable::saveStringTableCellArray(Components::ZoneBuilder::Zone* builder, Game::StringTableCell* values, int count)
{
Assert_Size(Game::StringTableCell, 8);
AssertSize(Game::StringTableCell, 8);
Utils::Stream* buffer = builder->GetBuffer();
Utils::Stream* buffer = builder->getBuffer();
Game::StringTableCell* destValues = buffer->Dest<Game::StringTableCell>();
buffer->SaveArray(destValues, count);
Game::StringTableCell* destValues = buffer->dest<Game::StringTableCell>();
buffer->saveArray(destValues, count);
for (int i = 0; i < count; ++i)
{
Game::StringTableCell* destValue = &destValues[i];
Game::StringTableCell* value = &values[i];
buffer->SaveString(value->string);
Utils::Stream::ClearPointer(&destValue->string);
for (int i = 0; i < count; ++i)
{
Game::StringTableCell* destValue = &destValues[i];
Game::StringTableCell* value = &values[i];
buffer->saveString(value->string);
Utils::Stream::ClearPointer(&destValue->string);
}
}
void IStringTable::Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
void IStringTable::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{
Assert_Size(Game::StringTable, 16);
AssertSize(Game::StringTable, 16);
Utils::Stream* buffer = builder->GetBuffer();
Utils::Stream* buffer = builder->getBuffer();
Game::StringTable* asset = header.stringTable;
Game::StringTable* dest = buffer->Dest<Game::StringTable>();
buffer->Save(asset, sizeof(Game::StringTable));
Game::StringTable* dest = buffer->dest<Game::StringTable>();
buffer->save(asset, sizeof(Game::StringTable));
buffer->PushBlock(Game::XFILE_BLOCK_VIRTUAL);
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
if (asset->name)
{
buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name));
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
Utils::Stream::ClearPointer(&dest->name);
}
if (asset->values)
{
buffer->Align(Utils::Stream::ALIGN_4);
buffer->align(Utils::Stream::ALIGN_4);
IStringTable::Save_StringTableCellArray(builder, asset->values, asset->columnCount * asset->rowCount);
this->saveStringTableCellArray(builder, asset->values, asset->columnCount * asset->rowCount);
Utils::Stream::ClearPointer(&dest->values);
}
buffer->PopBlock();
buffer->popBlock();
}
}

View File

@ -3,11 +3,11 @@ namespace Assets
class IStringTable : public Components::AssetHandler::IAsset
{
public:
virtual Game::XAssetType GetType() override { return Game::XAssetType::ASSET_TYPE_STRINGTABLE; };
virtual Game::XAssetType getType() override { return Game::XAssetType::ASSET_TYPE_STRINGTABLE; };
virtual void Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
private:
void Save_StringTableCellArray(Components::ZoneBuilder::Zone* builder, Game::StringTableCell* values, int count);
void saveStringTableCellArray(Components::ZoneBuilder::Zone* builder, Game::StringTableCell* values, int count);
};
}

View File

@ -2,12 +2,12 @@
namespace Assets
{
void IStructuredDataDefSet::Save_StructuredDataEnumArray(Game::StructuredDataEnum* enums, int numEnums, Components::ZoneBuilder::Zone* builder)
void IStructuredDataDefSet::saveStructuredDataEnumArray(Game::StructuredDataEnum* enums, int numEnums, Components::ZoneBuilder::Zone* builder)
{
Utils::Stream* buffer = builder->GetBuffer();
Utils::Stream* buffer = builder->getBuffer();
Game::StructuredDataEnum* destEnums = buffer->Dest<Game::StructuredDataEnum>();
buffer->SaveArray(enums, numEnums);
Game::StructuredDataEnum* destEnums = buffer->dest<Game::StructuredDataEnum>();
buffer->saveArray(enums, numEnums);
for (int i = 0; i < numEnums; ++i)
{
@ -16,11 +16,11 @@ namespace Assets
if (enum_->indices)
{
Assert_Size(Game::StructuredDataEnumEntry, 8);
buffer->Align(Utils::Stream::ALIGN_4);
AssertSize(Game::StructuredDataEnumEntry, 8);
buffer->align(Utils::Stream::ALIGN_4);
Game::StructuredDataEnumEntry* destIndices = buffer->Dest<Game::StructuredDataEnumEntry>();
buffer->SaveArray(enum_->indices, enum_->numIndices);
Game::StructuredDataEnumEntry* destIndices = buffer->dest<Game::StructuredDataEnumEntry>();
buffer->saveArray(enum_->indices, enum_->numIndices);
for (int j = 0; j < enum_->numIndices; ++j)
{
@ -29,7 +29,7 @@ namespace Assets
if (index->key)
{
buffer->SaveString(index->key);
buffer->saveString(index->key);
Utils::Stream::ClearPointer(&destIndex->key);
}
}
@ -39,12 +39,12 @@ namespace Assets
}
}
void IStructuredDataDefSet::Save_StructuredDataStructArray(Game::StructuredDataStruct* structs, int numStructs, Components::ZoneBuilder::Zone* builder)
void IStructuredDataDefSet::saveStructuredDataStructArray(Game::StructuredDataStruct* structs, int numStructs, Components::ZoneBuilder::Zone* builder)
{
Utils::Stream* buffer = builder->GetBuffer();
Utils::Stream* buffer = builder->getBuffer();
Game::StructuredDataStruct* destStructs = buffer->Dest<Game::StructuredDataStruct>();
buffer->SaveArray(structs, numStructs);
Game::StructuredDataStruct* destStructs = buffer->dest<Game::StructuredDataStruct>();
buffer->saveArray(structs, numStructs);
for (int i = 0; i < numStructs; ++i)
{
@ -53,11 +53,11 @@ namespace Assets
if (struct_->property)
{
Assert_Size(Game::StructuredDataStructProperty, 16);
buffer->Align(Utils::Stream::ALIGN_4);
AssertSize(Game::StructuredDataStructProperty, 16);
buffer->align(Utils::Stream::ALIGN_4);
Game::StructuredDataStructProperty* destProperties = buffer->Dest<Game::StructuredDataStructProperty>();
buffer->SaveArray(struct_->property, struct_->numProperties);
Game::StructuredDataStructProperty* destProperties = buffer->dest<Game::StructuredDataStructProperty>();
buffer->saveArray(struct_->property, struct_->numProperties);
for (int j = 0; j < struct_->numProperties; ++j)
{
@ -66,7 +66,7 @@ namespace Assets
if (property->name)
{
buffer->SaveString(property->name);
buffer->saveString(property->name);
Utils::Stream::ClearPointer(&destProperty->name);
}
}
@ -76,30 +76,30 @@ namespace Assets
}
}
void IStructuredDataDefSet::Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
void IStructuredDataDefSet::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{
Assert_Size(Game::StructuredDataDefSet, 12);
AssertSize(Game::StructuredDataDefSet, 12);
Utils::Stream* buffer = builder->GetBuffer();
Utils::Stream* buffer = builder->getBuffer();
Game::StructuredDataDefSet* asset = header.structuredData;
Game::StructuredDataDefSet* dest = buffer->Dest<Game::StructuredDataDefSet>();
buffer->Save(asset);
Game::StructuredDataDefSet* dest = buffer->dest<Game::StructuredDataDefSet>();
buffer->save(asset);
buffer->PushBlock(Game::XFILE_BLOCK_VIRTUAL);
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
if (asset->name)
{
buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name));
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
Utils::Stream::ClearPointer(&dest->name);
}
if (asset->data)
{
Assert_Size(Game::StructuredDataDef, 52);
buffer->Align(Utils::Stream::ALIGN_4);
AssertSize(Game::StructuredDataDef, 52);
buffer->align(Utils::Stream::ALIGN_4);
Game::StructuredDataDef* destDataArray = buffer->Dest<Game::StructuredDataDef>();
buffer->SaveArray(asset->data, asset->count);
Game::StructuredDataDef* destDataArray = buffer->dest<Game::StructuredDataDef>();
buffer->saveArray(asset->data, asset->count);
for (int i = 0; i < asset->count; ++i)
{
@ -108,37 +108,37 @@ namespace Assets
if (data->enums)
{
Assert_Size(Game::StructuredDataEnum, 12);
buffer->Align(Utils::Stream::ALIGN_4);
AssertSize(Game::StructuredDataEnum, 12);
buffer->align(Utils::Stream::ALIGN_4);
IStructuredDataDefSet::Save_StructuredDataEnumArray(data->enums, data->numEnums, builder);
this->saveStructuredDataEnumArray(data->enums, data->numEnums, builder);
Utils::Stream::ClearPointer(&destData->enums);
}
if (data->structs)
{
Assert_Size(Game::StructuredDataStruct, 16);
buffer->Align(Utils::Stream::ALIGN_4);
AssertSize(Game::StructuredDataStruct, 16);
buffer->align(Utils::Stream::ALIGN_4);
IStructuredDataDefSet::Save_StructuredDataStructArray(data->structs, data->numStructs, builder);
this->saveStructuredDataStructArray(data->structs, data->numStructs, builder);
Utils::Stream::ClearPointer(&destData->structs);
}
if (data->indexedArrays)
{
Assert_Size(Game::StructuredDataIndexedArray, 16);
buffer->Align(Utils::Stream::ALIGN_4);
AssertSize(Game::StructuredDataIndexedArray, 16);
buffer->align(Utils::Stream::ALIGN_4);
buffer->SaveArray(data->indexedArrays, data->numIndexedArrays);
buffer->saveArray(data->indexedArrays, data->numIndexedArrays);
Utils::Stream::ClearPointer(&destData->indexedArrays);
}
if (data->enumArrays)
{
Assert_Size(Game::StructuredDataEnumedArray, 16);
buffer->Align(Utils::Stream::ALIGN_4);
AssertSize(Game::StructuredDataEnumedArray, 16);
buffer->align(Utils::Stream::ALIGN_4);
buffer->SaveArray(data->enumArrays, data->numEnumArrays);
buffer->saveArray(data->enumArrays, data->numEnumArrays);
Utils::Stream::ClearPointer(&destData->enumArrays);
}
}
@ -146,6 +146,6 @@ namespace Assets
Utils::Stream::ClearPointer(&dest->data);
}
buffer->PopBlock();
buffer->popBlock();
}
}

View File

@ -3,11 +3,11 @@ namespace Assets
class IStructuredDataDefSet : public Components::AssetHandler::IAsset
{
public:
virtual Game::XAssetType GetType() override { return Game::XAssetType::ASSET_TYPE_STRUCTUREDDATADEF; };
virtual Game::XAssetType getType() override { return Game::XAssetType::ASSET_TYPE_STRUCTUREDDATADEF; };
virtual void Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
void Save_StructuredDataEnumArray(Game::StructuredDataEnum* enums, int numEnums, Components::ZoneBuilder::Zone* builder);
void Save_StructuredDataStructArray(Game::StructuredDataStruct* structs, int numStructs, Components::ZoneBuilder::Zone* builder);
void saveStructuredDataEnumArray(Game::StructuredDataEnum* enums, int numEnums, Components::ZoneBuilder::Zone* builder);
void saveStructuredDataStructArray(Game::StructuredDataStruct* structs, int numStructs, Components::ZoneBuilder::Zone* builder);
};
}

View File

@ -2,85 +2,85 @@
namespace Assets
{
void IXAnimParts::Load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
void IXAnimParts::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
{
Components::FileSystem::File animFile(fmt::sprintf("xanim/%s.iw4xAnim", name.data()));
if (animFile.Exists())
if (animFile.exists())
{
Utils::Stream::Reader reader(builder->GetAllocator(), animFile.GetBuffer());
Utils::Stream::Reader reader(builder->getAllocator(), animFile.getBuffer());
Game::XAnimParts* xanim = reader.ReadArray<Game::XAnimParts>();
Game::XAnimParts* xanim = reader.readArray<Game::XAnimParts>();
if (xanim)
{
if (xanim->name)
{
xanim->name = reader.ReadCString();
xanim->name = reader.readCString();
}
if (xanim->tagnames)
{
xanim->tagnames = builder->GetAllocator()->AllocateArray<short>(xanim->boneCount[Game::XAnimPartType::PART_TYPE_ALL]);
xanim->tagnames = builder->getAllocator()->allocateArray<short>(xanim->boneCount[Game::XAnimPartType::PART_TYPE_ALL]);
for (int i = 0; i < xanim->boneCount[Game::XAnimPartType::PART_TYPE_ALL]; ++i)
{
xanim->tagnames[i] = Game::SL_GetString(reader.ReadCString(), 0);
xanim->tagnames[i] = Game::SL_GetString(reader.readCString(), 0);
}
}
if (xanim->notetracks)
{
xanim->notetracks = reader.ReadArray<Game::XAnimNotifyInfo>(xanim->notetrackCount);
xanim->notetracks = reader.readArray<Game::XAnimNotifyInfo>(xanim->notetrackCount);
for (int i = 0; i < xanim->notetrackCount; ++i)
{
xanim->notetracks[i].name = Game::SL_GetString(reader.ReadCString(), 0);
xanim->notetracks[i].name = Game::SL_GetString(reader.readCString(), 0);
}
}
if (xanim->dataByte)
{
xanim->dataByte = reader.ReadArray<char>(xanim->dataByteCount);
xanim->dataByte = reader.readArray<char>(xanim->dataByteCount);
}
if (xanim->dataShort)
{
xanim->dataShort = reader.ReadArray<short>(xanim->dataShortCount);
xanim->dataShort = reader.readArray<short>(xanim->dataShortCount);
}
if (xanim->dataInt)
{
xanim->dataInt = reader.ReadArray<int>(xanim->dataIntCount);
xanim->dataInt = reader.readArray<int>(xanim->dataIntCount);
}
if (xanim->randomDataByte)
{
xanim->randomDataByte = reader.ReadArray<char>(xanim->randomDataByteCount);
xanim->randomDataByte = reader.readArray<char>(xanim->randomDataByteCount);
}
if (xanim->randomDataShort)
{
xanim->randomDataShort = reader.ReadArray<short>(xanim->randomDataShortCount);
xanim->randomDataShort = reader.readArray<short>(xanim->randomDataShortCount);
}
if (xanim->randomDataInt)
{
xanim->randomDataInt = reader.ReadArray<int>(xanim->randomDataIntCount);
xanim->randomDataInt = reader.readArray<int>(xanim->randomDataIntCount);
}
if (xanim->indices.data)
{
if (xanim->framecount < 256)
{
xanim->indices._1 = reader.ReadArray<char>(xanim->indexcount);
xanim->indices._1 = reader.readArray<char>(xanim->indexcount);
}
else
{
xanim->indices._2 = reader.ReadArray<unsigned short>(xanim->indexcount);
xanim->indices._2 = reader.readArray<unsigned short>(xanim->indexcount);
}
}
if (!reader.End())
if (!reader.end())
{
Components::Logger::Error(0, "Reading animation '%s' failed, remaining raw data found!", name.data());
}
@ -90,7 +90,7 @@ namespace Assets
}
}
void IXAnimParts::Mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
void IXAnimParts::mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{
Game::XAnimParts* asset = header.xanim;
@ -98,7 +98,7 @@ namespace Assets
{
for (char i = 0; i < asset->boneCount[Game::XAnimPartType::PART_TYPE_ALL]; ++i)
{
builder->AddScriptString(asset->tagnames[i]);
builder->addScriptString(asset->tagnames[i]);
}
}
@ -106,53 +106,53 @@ namespace Assets
{
for (char i = 0; i < asset->notetrackCount; ++i)
{
builder->AddScriptString(asset->notetracks[i].name);
builder->addScriptString(asset->notetracks[i].name);
}
}
}
void IXAnimParts::Save_XAnimDeltaPart(Game::XAnimDeltaPart* delta, unsigned short framecount, Components::ZoneBuilder::Zone* builder)
void IXAnimParts::saveXAnimDeltaPart(Game::XAnimDeltaPart* delta, unsigned short framecount, Components::ZoneBuilder::Zone* builder)
{
Assert_Size(Game::XAnimDeltaPart, 12);
AssertSize(Game::XAnimDeltaPart, 12);
Utils::Stream* buffer = builder->GetBuffer();
Game::XAnimDeltaPart* destDelta = buffer->Dest<Game::XAnimDeltaPart>();
buffer->Save(delta);
Utils::Stream* buffer = builder->getBuffer();
Game::XAnimDeltaPart* destDelta = buffer->dest<Game::XAnimDeltaPart>();
buffer->save(delta);
if (delta->trans)
{
buffer->Align(Utils::Stream::ALIGN_4);
buffer->Save(delta->trans, 4);
buffer->align(Utils::Stream::ALIGN_4);
buffer->save(delta->trans, 4);
if (delta->trans->size)
{
buffer->Save(&delta->trans->u.frames, 28);
buffer->save(&delta->trans->u.frames, 28);
if (framecount > 0xFF)
{
buffer->SaveArray(delta->trans->u.frames.indices._2, delta->trans->size + 1);
buffer->saveArray(delta->trans->u.frames.indices._2, delta->trans->size + 1);
}
else
{
buffer->SaveArray(delta->trans->u.frames.indices._1, delta->trans->size + 1);
buffer->saveArray(delta->trans->u.frames.indices._1, delta->trans->size + 1);
}
if (delta->trans->u.frames.frames._1)
{
if (delta->trans->smallTrans)
{
buffer->Save(delta->trans->u.frames.frames._1, 3, delta->trans->size + 1);
buffer->save(delta->trans->u.frames.frames._1, 3, delta->trans->size + 1);
}
else
{
buffer->Align(Utils::Stream::ALIGN_4);
buffer->Save(delta->trans->u.frames.frames._1, 6, delta->trans->size + 1);
buffer->align(Utils::Stream::ALIGN_4);
buffer->save(delta->trans->u.frames.frames._1, 6, delta->trans->size + 1);
}
}
}
else
{
buffer->Save(delta->trans->u.frame0, 12);
buffer->save(delta->trans->u.frame0, 12);
}
Utils::Stream::ClearPointer(&destDelta->trans);
@ -160,31 +160,31 @@ namespace Assets
if (delta->quat2)
{
buffer->Align(Utils::Stream::ALIGN_4);
buffer->Save(delta->quat2, 4);
buffer->align(Utils::Stream::ALIGN_4);
buffer->save(delta->quat2, 4);
if (delta->quat2->size)
{
buffer->Save(&delta->quat2->u.frames, 4);
buffer->save(&delta->quat2->u.frames, 4);
if (framecount > 0xFF)
{
buffer->Save(delta->quat2->u.frames.indices, 2, delta->quat2->size + 1);
buffer->save(delta->quat2->u.frames.indices, 2, delta->quat2->size + 1);
}
else
{
buffer->Save(delta->quat2->u.frames.indices, 1, delta->quat2->size + 1);
buffer->save(delta->quat2->u.frames.indices, 1, delta->quat2->size + 1);
}
if (delta->quat2->u.frames.frames)
{
buffer->Align(Utils::Stream::ALIGN_4);
buffer->Save(delta->quat2->u.frames.frames, 4, delta->quat2->size + 1);
buffer->align(Utils::Stream::ALIGN_4);
buffer->save(delta->quat2->u.frames.frames, 4, delta->quat2->size + 1);
}
}
else
{
buffer->Save(delta->quat2->u.frame0, 4);
buffer->save(delta->quat2->u.frame0, 4);
}
Utils::Stream::ClearPointer(&destDelta->quat2);
@ -192,64 +192,64 @@ namespace Assets
if (delta->quat)
{
buffer->Align(Utils::Stream::ALIGN_4);
buffer->Save(delta->quat, 4);
buffer->align(Utils::Stream::ALIGN_4);
buffer->save(delta->quat, 4);
if (delta->quat->size)
{
buffer->Save(&delta->quat->u.frames, 4);
buffer->save(&delta->quat->u.frames, 4);
if (framecount > 0xFF)
{
buffer->Save(delta->quat->u.frames.indices, 2, delta->quat->size + 1);
buffer->save(delta->quat->u.frames.indices, 2, delta->quat->size + 1);
}
else
{
buffer->Save(delta->quat->u.frames.indices, 1, delta->quat->size + 1);
buffer->save(delta->quat->u.frames.indices, 1, delta->quat->size + 1);
}
if (delta->quat->u.frames.frames)
{
buffer->Align(Utils::Stream::ALIGN_4);
buffer->Save(delta->quat->u.frames.frames, 4, delta->quat->size + 1);
buffer->align(Utils::Stream::ALIGN_4);
buffer->save(delta->quat->u.frames.frames, 4, delta->quat->size + 1);
}
}
else
{
buffer->Save(delta->quat->u.frame0, 4);
buffer->save(delta->quat->u.frame0, 4);
}
Utils::Stream::ClearPointer(&destDelta->quat);
}
}
void IXAnimParts::Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
void IXAnimParts::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{
Assert_Size(Game::XAnimParts, 88);
AssertSize(Game::XAnimParts, 88);
Utils::Stream* buffer = builder->GetBuffer();
Utils::Stream* buffer = builder->getBuffer();
Game::XAnimParts* asset = header.xanim;
Game::XAnimParts* dest = buffer->Dest<Game::XAnimParts>();
buffer->Save(asset, sizeof(Game::XAnimParts));
Game::XAnimParts* dest = buffer->dest<Game::XAnimParts>();
buffer->save(asset, sizeof(Game::XAnimParts));
buffer->PushBlock(Game::XFILE_BLOCK_VIRTUAL);
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
if (asset->name)
{
buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name));
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
Utils::Stream::ClearPointer(&dest->name);
}
if (asset->tagnames)
{
buffer->Align(Utils::Stream::ALIGN_2);
buffer->align(Utils::Stream::ALIGN_2);
unsigned short* destTagnames = buffer->Dest<unsigned short>();
buffer->SaveArray(asset->tagnames, asset->boneCount[Game::XAnimPartType::PART_TYPE_ALL]);
unsigned short* destTagnames = buffer->dest<unsigned short>();
buffer->saveArray(asset->tagnames, asset->boneCount[Game::XAnimPartType::PART_TYPE_ALL]);
for (char i = 0; i < asset->boneCount[Game::XAnimPartType::PART_TYPE_ALL]; ++i)
{
builder->MapScriptString(&destTagnames[i]);
builder->mapScriptString(&destTagnames[i]);
}
Utils::Stream::ClearPointer(&dest->tagnames);
@ -257,15 +257,15 @@ namespace Assets
if (asset->notetracks)
{
Assert_Size(Game::XAnimNotifyInfo, 8);
buffer->Align(Utils::Stream::ALIGN_4);
AssertSize(Game::XAnimNotifyInfo, 8);
buffer->align(Utils::Stream::ALIGN_4);
Game::XAnimNotifyInfo* destNotetracks = buffer->Dest<Game::XAnimNotifyInfo>();
buffer->SaveArray(asset->notetracks, asset->notetrackCount);
Game::XAnimNotifyInfo* destNotetracks = buffer->dest<Game::XAnimNotifyInfo>();
buffer->saveArray(asset->notetracks, asset->notetrackCount);
for (char i = 0; i < asset->notetrackCount; ++i)
{
builder->MapScriptString(&destNotetracks[i].name);
builder->mapScriptString(&destNotetracks[i].name);
}
Utils::Stream::ClearPointer(&dest->notetracks);
@ -273,51 +273,51 @@ namespace Assets
if (asset->delta)
{
Assert_Size(Game::XAnimDeltaPart, 12);
buffer->Align(Utils::Stream::ALIGN_4);
AssertSize(Game::XAnimDeltaPart, 12);
buffer->align(Utils::Stream::ALIGN_4);
IXAnimParts::Save_XAnimDeltaPart(asset->delta, asset->framecount, builder);
this->saveXAnimDeltaPart(asset->delta, asset->framecount, builder);
Utils::Stream::ClearPointer(&dest->delta);
}
if (asset->dataByte)
{
buffer->SaveArray(asset->dataByte, asset->dataByteCount);
buffer->saveArray(asset->dataByte, asset->dataByteCount);
Utils::Stream::ClearPointer(&dest->dataByte);
}
if (asset->dataShort)
{
buffer->Align(Utils::Stream::ALIGN_2);
buffer->SaveArray(asset->dataShort, asset->dataShortCount);
buffer->align(Utils::Stream::ALIGN_2);
buffer->saveArray(asset->dataShort, asset->dataShortCount);
Utils::Stream::ClearPointer(&dest->dataShort);
}
if (asset->dataInt)
{
buffer->Align(Utils::Stream::ALIGN_4);
buffer->SaveArray(asset->dataInt, asset->dataIntCount);
buffer->align(Utils::Stream::ALIGN_4);
buffer->saveArray(asset->dataInt, asset->dataIntCount);
Utils::Stream::ClearPointer(&dest->dataInt);
}
if (asset->randomDataShort)
{
buffer->Align(Utils::Stream::ALIGN_2);
buffer->SaveArray(asset->randomDataShort, asset->randomDataShortCount);
buffer->align(Utils::Stream::ALIGN_2);
buffer->saveArray(asset->randomDataShort, asset->randomDataShortCount);
Utils::Stream::ClearPointer(&dest->randomDataShort);
}
if (asset->randomDataByte)
{
buffer->SaveArray(asset->randomDataByte, asset->randomDataByteCount);
buffer->saveArray(asset->randomDataByte, asset->randomDataByteCount);
Utils::Stream::ClearPointer(&dest->randomDataByte);
}
if (asset->randomDataInt)
{
buffer->Align(Utils::Stream::ALIGN_4);
buffer->SaveArray(asset->randomDataInt, asset->randomDataIntCount);
buffer->align(Utils::Stream::ALIGN_4);
buffer->saveArray(asset->randomDataInt, asset->randomDataIntCount);
Utils::Stream::ClearPointer(&dest->randomDataInt);
}
@ -325,17 +325,17 @@ namespace Assets
{
if (asset->framecount > 0xFF)
{
buffer->Align(Utils::Stream::ALIGN_2);
buffer->SaveArray(asset->indices._2, asset->indexcount);
buffer->align(Utils::Stream::ALIGN_2);
buffer->saveArray(asset->indices._2, asset->indexcount);
}
else
{
buffer->SaveArray(asset->indices._1, asset->indexcount);
buffer->saveArray(asset->indices._1, asset->indexcount);
}
Utils::Stream::ClearPointer(&dest->indices.data);
}
buffer->PopBlock();
buffer->popBlock();
}
}

View File

@ -3,13 +3,13 @@ namespace Assets
class IXAnimParts : public Components::AssetHandler::IAsset
{
public:
virtual Game::XAssetType GetType() override { return Game::XAssetType::ASSET_TYPE_XANIM; };
virtual Game::XAssetType getType() override { return Game::XAssetType::ASSET_TYPE_XANIM; };
virtual void Mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void Load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override;
virtual void mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override;
private:
void Save_XAnimDeltaPart(Game::XAnimDeltaPart* delta, unsigned short framecount, Components::ZoneBuilder::Zone* builder);
void saveXAnimDeltaPart(Game::XAnimDeltaPart* delta, unsigned short framecount, Components::ZoneBuilder::Zone* builder);
};
}

View File

@ -2,50 +2,50 @@
namespace Assets
{
void IXModel::Load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
void IXModel::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
{
Components::FileSystem::File modelFile(fmt::sprintf("xmodel/%s.iw4xModel", name.data()));
if (modelFile.Exists())
if (modelFile.exists())
{
Game::XModel* baseModel = Components::AssetHandler::FindOriginalAsset(Game::XAssetType::ASSET_TYPE_XMODEL, "viewmodel_mp5k").model;
// Allocate new model and copy the base data to it
Game::XModel* model = builder->GetAllocator()->Allocate<Game::XModel>();
Game::XModel* model = builder->getAllocator()->allocate<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());
model->name = reader.ReadCString();
model->numBones = reader.ReadByte();
model->numRootBones = reader.ReadByte();
model->numSurfaces = reader.ReadByte();
model->numColSurfs = reader.Read<int>();
model->name = reader.readCString();
model->numBones = reader.readByte();
model->numRootBones = reader.readByte();
model->numSurfaces = reader.readByte();
model->numColSurfs = reader.read<int>();
// Read bone names
model->boneNames = builder->GetAllocator()->AllocateArray<short>(model->numBones);
model->boneNames = builder->getAllocator()->allocateArray<short>(model->numBones);
for (int i = 0; i < model->numBones; ++i)
{
model->boneNames[i] = Game::SL_GetString(reader.ReadCString(), 0);
model->boneNames[i] = Game::SL_GetString(reader.readCString(), 0);
}
// Bone count
int boneCount = (model->numBones - model->numRootBones);
// Read bone data
model->parentList = reader.ReadArray<char>(boneCount);
model->tagAngles = reader.ReadArray<Game::XModelAngle>(boneCount);
model->tagPositions = reader.ReadArray<Game::XModelTagPos>(boneCount);
model->partClassification = reader.ReadArray<char>(boneCount);
model->animMatrix = reader.ReadArray<Game::DObjAnimMat>(boneCount);
model->parentList = reader.readArray<char>(boneCount);
model->tagAngles = reader.readArray<Game::XModelAngle>(boneCount);
model->tagPositions = reader.readArray<Game::XModelTagPos>(boneCount);
model->partClassification = reader.readArray<char>(boneCount);
model->animMatrix = reader.readArray<Game::DObjAnimMat>(boneCount);
// Prepare surfaces
Game::XSurface* baseSurface = &baseModel->lods[0].surfaces[0].surfaces[0];
Game::XModelSurfs* surf = builder->GetAllocator()->Allocate<Game::XModelSurfs>();
Game::XModelSurfs* surf = builder->getAllocator()->allocate<Game::XModelSurfs>();
std::memcpy(surf, baseModel->lods[0].surfaces, sizeof(Game::XModelSurfs));
surf->name = builder->GetAllocator()->DuplicateString(fmt::sprintf("%s_lod1", model->name));
surf->surfaces = builder->GetAllocator()->AllocateArray<Game::XSurface>(model->numSurfaces);
surf->name = builder->getAllocator()->duplicateString(fmt::sprintf("%s_lod1", model->name));
surf->surfaces = builder->getAllocator()->allocateArray<Game::XSurface>(model->numSurfaces);
surf->numSurfaces = model->numSurfaces;
// Reset surfaces in remaining lods
@ -54,14 +54,14 @@ namespace Assets
ZeroMemory(&model->lods[i], sizeof(Game::XModelLodInfo));
}
model->lods[0].dist = reader.Read<float>();
model->lods[0].numSurfs = reader.Read<short>();
model->lods[0].maxSurfs = reader.Read<short>();
model->lods[0].dist = reader.read<float>();
model->lods[0].numSurfs = reader.read<short>();
model->lods[0].maxSurfs = reader.read<short>();
model->lods[0].partBits[0] = reader.Read<int>();
model->lods[0].partBits[1] = reader.Read<int>();
model->lods[0].partBits[2] = reader.Read<int>();
model->lods[0].partBits[3] = reader.Read<int>();
model->lods[0].partBits[0] = reader.read<int>();
model->lods[0].partBits[1] = reader.read<int>();
model->lods[0].partBits[2] = reader.read<int>();
model->lods[0].partBits[3] = reader.read<int>();
model->lods[0].numSurfs = model->numSurfaces; // This is needed in case we have more than 1 LOD
model->lods[0].surfaces = surf;
@ -74,43 +74,43 @@ namespace Assets
Game::XSurface* surface = &surf->surfaces[i];
std::memcpy(surface, baseSurface, sizeof(Game::XSurface));
surface->tileMode = reader.Read<char>();
surface->deformed = reader.Read<char>();
surface->tileMode = reader.read<char>();
surface->deformed = reader.read<char>();
surface->streamHandle = reader.Read<unsigned char>();
surface->flags = reader.Read<unsigned short>();
surface->something = reader.Read<short>();
surface->something2 = reader.Read<int>();
surface->streamHandle = reader.read<unsigned char>();
surface->flags = reader.read<unsigned short>();
surface->something = reader.read<short>();
surface->something2 = reader.read<int>();
surface->pad2 = reader.Read<char>();
surface->pad3 = reader.Read<int>();
surface->pad2 = reader.read<char>();
surface->pad3 = reader.read<int>();
surface->numVertices = reader.Read<unsigned short>();
surface->numPrimitives = reader.Read<unsigned short>();
surface->numCT = reader.Read<int>();
surface->numVertices = reader.read<unsigned short>();
surface->numPrimitives = reader.read<unsigned short>();
surface->numCT = reader.read<int>();
surface->blendNum1 = reader.Read<short>();
surface->blendNum2 = reader.Read<short>();
surface->blendNum3 = reader.Read<short>();
surface->blendNum4 = reader.Read<short>();
surface->blendNum1 = reader.read<short>();
surface->blendNum2 = reader.read<short>();
surface->blendNum3 = reader.read<short>();
surface->blendNum4 = reader.read<short>();
surface->blendInfo = reinterpret_cast<char*>(reader.Read(2, surface->blendNum1 + (3 * surface->blendNum2) + (5 * surface->blendNum3) + (7 * surface->blendNum4)));
surface->blendInfo = reinterpret_cast<char*>(reader.read(2, surface->blendNum1 + (3 * surface->blendNum2) + (5 * surface->blendNum3) + (7 * surface->blendNum4)));
surface->vertexBuffer = reader.ReadArray<Game::GfxPackedVertex>(surface->numVertices);
surface->indexBuffer = reader.ReadArray<Game::Face>(surface->numPrimitives);
surface->vertexBuffer = reader.readArray<Game::GfxPackedVertex>(surface->numVertices);
surface->indexBuffer = reader.readArray<Game::Face>(surface->numPrimitives);
// Read vert list
if (reader.ReadByte())
if (reader.readByte())
{
surface->ct = reader.ReadArray<Game::XRigidVertList>(surface->numCT);
surface->ct = reader.readArray<Game::XRigidVertList>(surface->numCT);
for (int j = 0; j < surface->numCT; ++j)
{
Game::XRigidVertList* vertList = &surface->ct[j];
vertList->entry = reader.ReadArray<Game::XSurfaceCollisionTree>();
vertList->entry->node = reinterpret_cast<char*>(reader.Read(16, vertList->entry->numNode));
vertList->entry->leaf = reader.ReadArray<short>(vertList->entry->numLeaf);
vertList->entry = reader.readArray<Game::XSurfaceCollisionTree>();
vertList->entry->node = reinterpret_cast<char*>(reader.read(16, vertList->entry->numNode));
vertList->entry->leaf = reader.readArray<short>(vertList->entry->numLeaf);
}
}
else
@ -120,22 +120,22 @@ namespace Assets
}
// Read materials
model->materials = builder->GetAllocator()->AllocateArray<Game::Material*>(model->numSurfaces);
model->materials = builder->getAllocator()->allocateArray<Game::Material*>(model->numSurfaces);
for (char i = 0; i < model->numSurfaces; ++i)
{
model->materials[i] = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_MATERIAL, reader.ReadString(), builder).material;
model->materials[i] = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_MATERIAL, reader.readString(), builder).material;
}
// Read collision surfaces
if (reader.ReadByte())
if (reader.readByte())
{
model->colSurf = reader.ReadArray<Game::XModelCollSurf>(model->numColSurfs);
model->colSurf = reader.readArray<Game::XModelCollSurf>(model->numColSurfs);
for (int i = 0; i < model->numColSurfs; ++i)
{
if (model->colSurf[i].tris)
{
model->colSurf[i].tris = reader.Read(48, model->colSurf[i].count);
model->colSurf[i].tris = reader.read(48, model->colSurf[i].count);
}
}
}
@ -145,16 +145,16 @@ namespace Assets
}
// Read bone info
if (reader.ReadByte())
if (reader.readByte())
{
model->boneInfo = reader.ReadArray<Game::XBoneInfo>(model->numBones);
model->boneInfo = reader.readArray<Game::XBoneInfo>(model->numBones);
}
else
{
model->boneInfo = nullptr;
}
if (!reader.End())
if (!reader.end())
{
Components::Logger::Error(0, "Reading model '%s' failed, remaining raw data found!", name.data());
}
@ -163,7 +163,7 @@ namespace Assets
}
}
void IXModel::Mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
void IXModel::mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{
Game::XModel* asset = header.model;
@ -171,7 +171,7 @@ namespace Assets
{
for (char i = 0; i < asset->numBones; ++i)
{
builder->AddScriptString(asset->boneNames[i]);
builder->addScriptString(asset->boneNames[i]);
}
}
@ -181,7 +181,7 @@ namespace Assets
{
if (asset->materials[i])
{
builder->LoadAsset(Game::XAssetType::ASSET_TYPE_MATERIAL, asset->materials[i]->name);
builder->loadAsset(Game::XAssetType::ASSET_TYPE_MATERIAL, asset->materials[i]->name);
}
}
}
@ -191,50 +191,50 @@ namespace Assets
if (asset->lods[i].surfaces)
{
// We're not supposed to include xmodelsurfs as standalone asset
//builder->LoadAsset(Game::XAssetType::ASSET_TYPE_XMODELSURFS, asset->lods[i].surfaces->name);
//builder->loadAsset(Game::XAssetType::ASSET_TYPE_XMODELSURFS, asset->lods[i].surfaces->name);
IXModelSurfs().Mark({ asset->lods[i].surfaces }, builder);
IXModelSurfs().mark({ asset->lods[i].surfaces }, builder);
}
}
if (asset->physPreset)
{
builder->LoadAsset(Game::XAssetType::ASSET_TYPE_PHYSPRESET, asset->physPreset->name);
builder->loadAsset(Game::XAssetType::ASSET_TYPE_PHYSPRESET, asset->physPreset->name);
}
if (asset->physCollmap)
{
builder->LoadAsset(Game::XAssetType::ASSET_TYPE_PHYS_COLLMAP, asset->physCollmap->name);
builder->loadAsset(Game::XAssetType::ASSET_TYPE_PHYS_COLLMAP, asset->physCollmap->name);
}
}
void IXModel::Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
void IXModel::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{
Assert_Size(Game::XModel, 304);
AssertSize(Game::XModel, 304);
Utils::Stream* buffer = builder->GetBuffer();
Utils::Stream* buffer = builder->getBuffer();
Game::XModel* asset = header.model;
Game::XModel* dest = buffer->Dest<Game::XModel>();
buffer->Save(asset);
Game::XModel* dest = buffer->dest<Game::XModel>();
buffer->save(asset);
buffer->PushBlock(Game::XFILE_BLOCK_VIRTUAL);
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
if (asset->name)
{
buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name));
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
Utils::Stream::ClearPointer(&dest->name);
}
if (asset->boneNames)
{
buffer->Align(Utils::Stream::ALIGN_2);
buffer->align(Utils::Stream::ALIGN_2);
unsigned short* destBoneNames = buffer->Dest<unsigned short>();
buffer->SaveArray(asset->boneNames, asset->numBones);
unsigned short* destBoneNames = buffer->dest<unsigned short>();
buffer->saveArray(asset->boneNames, asset->numBones);
for (char i = 0; i < asset->numBones; ++i)
{
builder->MapScriptString(&destBoneNames[i]);
builder->mapScriptString(&destBoneNames[i]);
}
Utils::Stream::ClearPointer(&dest->boneNames);
@ -242,55 +242,55 @@ namespace Assets
if (asset->parentList)
{
buffer->Save(asset->parentList, asset->numBones - asset->numRootBones);
buffer->save(asset->parentList, asset->numBones - asset->numRootBones);
Utils::Stream::ClearPointer(&dest->parentList);
}
if (asset->tagAngles)
{
Assert_Size(Game::XModelAngle, 8);
AssertSize(Game::XModelAngle, 8);
buffer->Align(Utils::Stream::ALIGN_2);
buffer->SaveArray(asset->tagAngles, asset->numBones - asset->numRootBones);
buffer->align(Utils::Stream::ALIGN_2);
buffer->saveArray(asset->tagAngles, asset->numBones - asset->numRootBones);
Utils::Stream::ClearPointer(&dest->tagAngles);
}
if (asset->tagPositions)
{
Assert_Size(Game::XModelTagPos, 12);
AssertSize(Game::XModelTagPos, 12);
buffer->Align(Utils::Stream::ALIGN_4);
buffer->SaveArray(asset->tagPositions, asset->numBones - asset->numRootBones);
buffer->align(Utils::Stream::ALIGN_4);
buffer->saveArray(asset->tagPositions, asset->numBones - asset->numRootBones);
Utils::Stream::ClearPointer(&dest->tagPositions);
}
if (asset->partClassification)
{
buffer->Save(asset->partClassification, asset->numBones);
buffer->save(asset->partClassification, asset->numBones);
Utils::Stream::ClearPointer(&dest->partClassification);
}
if (asset->animMatrix)
{
Assert_Size(Game::DObjAnimMat, 32);
AssertSize(Game::DObjAnimMat, 32);
buffer->Align(Utils::Stream::ALIGN_4);
buffer->SaveArray(asset->animMatrix, asset->numBones);
buffer->align(Utils::Stream::ALIGN_4);
buffer->saveArray(asset->animMatrix, asset->numBones);
Utils::Stream::ClearPointer(&dest->animMatrix);
}
if (asset->materials)
{
buffer->Align(Utils::Stream::ALIGN_4);
buffer->align(Utils::Stream::ALIGN_4);
Game::Material** destMaterials = buffer->Dest<Game::Material*>();
buffer->SaveArray(asset->materials, asset->numSurfaces);
Game::Material** destMaterials = buffer->dest<Game::Material*>();
buffer->saveArray(asset->materials, asset->numSurfaces);
for (char i = 0; i < asset->numSurfaces; ++i)
{
if (asset->materials[i])
{
destMaterials[i] = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_MATERIAL, asset->materials[i]->name).material;
destMaterials[i] = builder->requireAsset(Game::XAssetType::ASSET_TYPE_MATERIAL, asset->materials[i]->name).material;
}
}
@ -299,22 +299,22 @@ namespace Assets
// Save_XModelLodInfoArray
{
Assert_Size(Game::XModelLodInfo, 44);
AssertSize(Game::XModelLodInfo, 44);
for (int i = 0; i < 4; ++i)
{
if (asset->lods[i].surfaces)
{
// Requiring this asset is not possible, it has to be loaded as part of the model
//dest->lods[i].surfaces = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_XMODELSURFS, asset->lods[i].surfaces->name).surfaces;
//dest->lods[i].surfaces = builder->requireAsset(Game::XAssetType::ASSET_TYPE_XMODELSURFS, asset->lods[i].surfaces->name).surfaces;
buffer->PushBlock(Game::XFILE_BLOCK_TEMP);
buffer->Align(Utils::Stream::ALIGN_4);
buffer->pushBlock(Game::XFILE_BLOCK_TEMP);
buffer->align(Utils::Stream::ALIGN_4);
IXModelSurfs().Save({ asset->lods[i].surfaces }, builder);
IXModelSurfs().save({ asset->lods[i].surfaces }, builder);
Utils::Stream::ClearPointer(&dest->lods[i].surfaces);
buffer->PopBlock();
buffer->popBlock();
}
}
}
@ -322,12 +322,12 @@ namespace Assets
// Save_XModelCollSurfArray
if (asset->colSurf)
{
Assert_Size(Game::XModelCollSurf, 44);
AssertSize(Game::XModelCollSurf, 44);
buffer->Align(Utils::Stream::ALIGN_4);
buffer->align(Utils::Stream::ALIGN_4);
Game::XModelCollSurf* destColSurfs = buffer->Dest<Game::XModelCollSurf>();
buffer->SaveArray(asset->colSurf, asset->numColSurfs);
Game::XModelCollSurf* destColSurfs = buffer->dest<Game::XModelCollSurf>();
buffer->saveArray(asset->colSurf, asset->numColSurfs);
for (int i = 0; i < asset->numColSurfs; ++i)
{
@ -336,9 +336,9 @@ namespace Assets
if (colSurf->tris)
{
buffer->Align(Utils::Stream::ALIGN_4);
buffer->align(Utils::Stream::ALIGN_4);
buffer->Save(colSurf->tris, 48, colSurf->count);
buffer->save(colSurf->tris, 48, colSurf->count);
Utils::Stream::ClearPointer(&destColSurf->tris);
}
}
@ -348,24 +348,24 @@ namespace Assets
if (asset->boneInfo)
{
Assert_Size(Game::XBoneInfo, 28);
AssertSize(Game::XBoneInfo, 28);
buffer->Align(Utils::Stream::ALIGN_4);
buffer->align(Utils::Stream::ALIGN_4);
buffer->SaveArray(asset->boneInfo, asset->numBones);
buffer->saveArray(asset->boneInfo, asset->numBones);
Utils::Stream::ClearPointer(&dest->boneInfo);
}
if (asset->physPreset)
{
dest->physPreset = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_PHYSPRESET, asset->physPreset->name).physPreset;
dest->physPreset = builder->requireAsset(Game::XAssetType::ASSET_TYPE_PHYSPRESET, asset->physPreset->name).physPreset;
}
if (asset->physCollmap)
{
dest->physCollmap = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_PHYS_COLLMAP, asset->physCollmap->name).physCollmap;
dest->physCollmap = builder->requireAsset(Game::XAssetType::ASSET_TYPE_PHYS_COLLMAP, asset->physCollmap->name).physCollmap;
}
buffer->PopBlock();
buffer->popBlock();
}
}

View File

@ -3,10 +3,10 @@ namespace Assets
class IXModel : public Components::AssetHandler::IAsset
{
public:
virtual Game::XAssetType GetType() override { return Game::XAssetType::ASSET_TYPE_XMODEL; };
virtual Game::XAssetType getType() override { return Game::XAssetType::ASSET_TYPE_XMODEL; };
virtual void Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void Mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void Load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override;
virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override;
};
}

View File

@ -2,62 +2,62 @@
namespace Assets
{
void IXModelSurfs::Save_XSurfaceCollisionTree(Game::XSurfaceCollisionTree* entry, Components::ZoneBuilder::Zone* builder)
void IXModelSurfs::saveXSurfaceCollisionTree(Game::XSurfaceCollisionTree* entry, Components::ZoneBuilder::Zone* builder)
{
Assert_Size(Game::XSurfaceCollisionTree, 40);
AssertSize(Game::XSurfaceCollisionTree, 40);
Utils::Stream* buffer = builder->GetBuffer();
Utils::Stream* buffer = builder->getBuffer();
Game::XSurfaceCollisionTree* destEntry = buffer->Dest<Game::XSurfaceCollisionTree>();
buffer->Save(entry);
Game::XSurfaceCollisionTree* destEntry = buffer->dest<Game::XSurfaceCollisionTree>();
buffer->save(entry);
if (entry->node)
{
buffer->Align(Utils::Stream::ALIGN_16);
buffer->Save(entry->node, 16, entry->numNode);
buffer->align(Utils::Stream::ALIGN_16);
buffer->save(entry->node, 16, entry->numNode);
Utils::Stream::ClearPointer(&destEntry->node);
}
if (entry->leaf)
{
buffer->Align(Utils::Stream::ALIGN_2);
buffer->SaveArray(entry->leaf, entry->numLeaf);
buffer->align(Utils::Stream::ALIGN_2);
buffer->saveArray(entry->leaf, entry->numLeaf);
Utils::Stream::ClearPointer(&destEntry->leaf);
}
}
void IXModelSurfs::Save_XSurface(Game::XSurface* surf, Game::XSurface* destSurf, Components::ZoneBuilder::Zone* builder)
void IXModelSurfs::saveXSurface(Game::XSurface* surf, Game::XSurface* destSurf, Components::ZoneBuilder::Zone* builder)
{
Utils::Stream* buffer = builder->GetBuffer();
Utils::Stream* buffer = builder->getBuffer();
if (surf->blendInfo)
{
buffer->Align(Utils::Stream::ALIGN_2);
buffer->Save(surf->blendInfo, sizeof(short), surf->blendNum1 + (surf->blendNum2 * 3) + (surf->blendNum3 * 5) + (surf->blendNum4 * 7));
buffer->align(Utils::Stream::ALIGN_2);
buffer->save(surf->blendInfo, sizeof(short), surf->blendNum1 + (surf->blendNum2 * 3) + (surf->blendNum3 * 5) + (surf->blendNum4 * 7));
Utils::Stream::ClearPointer(&destSurf->blendInfo);
}
// Access vertex block
buffer->PushBlock(Game::XFILE_BLOCK_VERTEX);
buffer->pushBlock(Game::XFILE_BLOCK_VERTEX);
if (surf->vertexBuffer)
{
Assert_Size(Game::GfxPackedVertex, 32);
AssertSize(Game::GfxPackedVertex, 32);
buffer->Align(Utils::Stream::ALIGN_16);
buffer->SaveArray(surf->vertexBuffer, surf->numVertices);
buffer->align(Utils::Stream::ALIGN_16);
buffer->saveArray(surf->vertexBuffer, surf->numVertices);
Utils::Stream::ClearPointer(&destSurf->vertexBuffer);
}
buffer->PopBlock();
buffer->popBlock();
// Save_XRigidVertListArray
if (surf->ct)
{
Assert_Size(Game::XRigidVertList, 12);
AssertSize(Game::XRigidVertList, 12);
buffer->Align(Utils::Stream::ALIGN_4);
buffer->align(Utils::Stream::ALIGN_4);
Game::XRigidVertList* destCt = buffer->Dest<Game::XRigidVertList>();
buffer->SaveArray(surf->ct, surf->numCT);
Game::XRigidVertList* destCt = buffer->dest<Game::XRigidVertList>();
buffer->saveArray(surf->ct, surf->numCT);
for (int i = 0; i < surf->numCT; ++i)
{
@ -66,8 +66,8 @@ namespace Assets
if (rigidVertList->entry)
{
buffer->Align(Utils::Stream::ALIGN_4);
IXModelSurfs::Save_XSurfaceCollisionTree(rigidVertList->entry, builder);
buffer->align(Utils::Stream::ALIGN_4);
this->saveXSurfaceCollisionTree(rigidVertList->entry, builder);
Utils::Stream::ClearPointer(&destRigidVertList->entry);
}
}
@ -76,52 +76,52 @@ namespace Assets
}
// Access index block
buffer->PushBlock(Game::XFILE_BLOCK_INDEX);
buffer->pushBlock(Game::XFILE_BLOCK_INDEX);
if (surf->indexBuffer)
{
Assert_Size(Game::Face, 6);
AssertSize(Game::Face, 6);
buffer->Align(Utils::Stream::ALIGN_16);
buffer->SaveArray(surf->indexBuffer, surf->numPrimitives);
buffer->align(Utils::Stream::ALIGN_16);
buffer->saveArray(surf->indexBuffer, surf->numPrimitives);
Utils::Stream::ClearPointer(&destSurf->indexBuffer);
}
buffer->PopBlock();
buffer->popBlock();
}
void IXModelSurfs::Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
void IXModelSurfs::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{
Assert_Size(Game::XModelSurfs, 36);
AssertSize(Game::XModelSurfs, 36);
Utils::Stream* buffer = builder->GetBuffer();
Utils::Stream* buffer = builder->getBuffer();
Game::XModelSurfs* asset = header.surfaces;
Game::XModelSurfs* dest = buffer->Dest<Game::XModelSurfs>();
buffer->Save(asset);
Game::XModelSurfs* dest = buffer->dest<Game::XModelSurfs>();
buffer->save(asset);
buffer->PushBlock(Game::XFILE_BLOCK_VIRTUAL);
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
if (asset->name)
{
buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name));
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
Utils::Stream::ClearPointer(&dest->name);
}
if (asset->surfaces)
{
Assert_Size(Game::XSurface, 64);
AssertSize(Game::XSurface, 64);
buffer->Align(Utils::Stream::ALIGN_4);
buffer->align(Utils::Stream::ALIGN_4);
Game::XSurface* destSurfaces = buffer->Dest<Game::XSurface>();
buffer->SaveArray(asset->surfaces, asset->numSurfaces);
Game::XSurface* destSurfaces = buffer->dest<Game::XSurface>();
buffer->saveArray(asset->surfaces, asset->numSurfaces);
for (int i = 0; i < asset->numSurfaces; ++i)
{
IXModelSurfs::Save_XSurface(&asset->surfaces[i], &destSurfaces[i], builder);
this->saveXSurface(&asset->surfaces[i], &destSurfaces[i], builder);
}
Utils::Stream::ClearPointer(&dest->surfaces);
}
buffer->PopBlock();
buffer->popBlock();
}
}

View File

@ -3,12 +3,12 @@ namespace Assets
class IXModelSurfs : public Components::AssetHandler::IAsset
{
public:
virtual Game::XAssetType GetType() override { return Game::XAssetType::ASSET_TYPE_XMODELSURFS; };
virtual Game::XAssetType getType() override { return Game::XAssetType::ASSET_TYPE_XMODELSURFS; };
virtual void Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
private:
void Save_XSurface(Game::XSurface* surf, Game::XSurface* destSurf, Components::ZoneBuilder::Zone* builder);
void Save_XSurfaceCollisionTree(Game::XSurfaceCollisionTree* entry, Components::ZoneBuilder::Zone* builder);
void saveXSurface(Game::XSurface* surf, Game::XSurface* destSurf, Components::ZoneBuilder::Zone* builder);
void saveXSurfaceCollisionTree(Game::XSurfaceCollisionTree* entry, Components::ZoneBuilder::Zone* builder);
};
}

View File

@ -58,7 +58,7 @@ namespace Components
{
// Ensure our certificate is loaded
Steam::SteamUser()->GetSteamID();
if (!Auth::GuidKey.IsValid())
if (!Auth::GuidKey.isValid())
{
Logger::SoftError("Connecting failed: Guid key is invalid!");
return;
@ -69,7 +69,7 @@ namespace Components
Command::Params params(true);
if (params.Length() < 3)
if (params.length() < 3)
{
Game::SV_Cmd_EndTokenizedString();
Logger::SoftError("Connecting failed: Command parsing error!");
@ -77,7 +77,7 @@ namespace Components
}
Utils::InfoString infostr(params[2]);
std::string challenge = infostr.Get("challenge");
std::string challenge = infostr.get("challenge");
if (challenge.empty())
{
@ -89,8 +89,8 @@ namespace Components
Game::SV_Cmd_EndTokenizedString();
Proto::Auth::Connect connectData;
connectData.set_token(Auth::GuidToken.ToString());
connectData.set_publickey(Auth::GuidKey.GetPublicKey());
connectData.set_token(Auth::GuidToken.toString());
connectData.set_publickey(Auth::GuidKey.getPublicKey());
connectData.set_signature(Utils::Cryptography::ECC::SignMessage(Auth::GuidKey, challenge));
connectData.set_infostring(connectString);
@ -109,7 +109,7 @@ namespace Components
return;
}
if (address.IsLoopback()
if (address.isLoopback()
// Simply connect, if we're in debug mode, we ignore all security checks
#ifdef DEBUG
|| true
@ -120,7 +120,7 @@ namespace Components
{
Game::SV_Cmd_EndTokenizedString();
Game::SV_Cmd_TokenizeString(connectData.infostring().data());
Game::SV_DirectConnect(*address.Get());
Game::SV_DirectConnect(*address.get());
}
else
{
@ -144,7 +144,7 @@ namespace Components
Command::Params params(true);
// Ensure there are enough params
if (params.Length() < 3)
if (params.length() < 3)
{
Network::Send(address, "error\nInvalid connect string!");
return;
@ -154,8 +154,8 @@ namespace Components
Utils::InfoString infostr(params[2]);
// Read the required data
std::string steamId = infostr.Get("xuid");
std::string challenge = infostr.Get("challenge");
std::string steamId = infostr.get("xuid");
std::string challenge = infostr.get("challenge");
if (steamId.empty() || challenge.empty())
{
@ -170,7 +170,7 @@ namespace Components
SteamID guid;
guid.Bits = xuid;
if (Bans::IsBanned({ guid, address.GetIP() }))
if (Bans::IsBanned({ guid, address.getIP() }))
{
Network::Send(address, "error\nEXE_ERR_BANNED_PERM");
return;
@ -184,16 +184,16 @@ namespace Components
// Verify the signature
Utils::Cryptography::ECC::Key key;
key.Set(connectData.publickey());
key.set(connectData.publickey());
if (!key.IsValid() || !Utils::Cryptography::ECC::VerifyMessage(key, challenge, connectData.signature()))
if (!key.isValid() || !Utils::Cryptography::ECC::VerifyMessage(key, challenge, connectData.signature()))
{
Network::Send(address, "error\nChallenge signature was invalid!");
return;
}
// Verify the security level
uint32_t ourLevel = static_cast<uint32_t>(Dvar::Var("sv_securityLevel").Get<int>());
uint32_t ourLevel = static_cast<uint32_t>(Dvar::Var("sv_securityLevel").get<int>());
uint32_t userLevel = Auth::GetZeroBits(connectData.token(), connectData.publickey());
if (userLevel < ourLevel)
@ -202,8 +202,8 @@ namespace Components
return;
}
Logger::Print("Verified XUID %llX (%d) from %s\n", xuid, userLevel, address.GetCString());
Game::SV_DirectConnect(*address.Get());
Logger::Print("Verified XUID %llX (%d) from %s\n", xuid, userLevel, address.getCString());
Game::SV_DirectConnect(*address.get());
}
}
@ -223,17 +223,17 @@ namespace Components
unsigned int Auth::GetKeyHash()
{
Auth::LoadKey();
return (Utils::Cryptography::JenkinsOneAtATime::Compute(Auth::GuidKey.GetPublicKey()));
return (Utils::Cryptography::JenkinsOneAtATime::Compute(Auth::GuidKey.getPublicKey()));
}
void Auth::StoreKey()
{
if (!Dedicated::IsEnabled() && !ZoneBuilder::IsEnabled() && Auth::GuidKey.IsValid())
if (!Dedicated::IsEnabled() && !ZoneBuilder::IsEnabled() && Auth::GuidKey.isValid())
{
Proto::Auth::Certificate cert;
cert.set_token(Auth::GuidToken.ToString());
cert.set_ctoken(Auth::ComputeToken.ToString());
cert.set_privatekey(Auth::GuidKey.Export(PK_PRIVATE));
cert.set_token(Auth::GuidToken.toString());
cert.set_ctoken(Auth::ComputeToken.toString());
cert.set_privatekey(Auth::GuidKey.serialize(PK_PRIVATE));
Utils::IO::WriteFile("players/guid.dat", cert.SerializeAsString());
}
@ -242,24 +242,24 @@ namespace Components
void Auth::LoadKey(bool force)
{
if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled()) return;
if (!force && Auth::GuidKey.IsValid()) return;
if (!force && Auth::GuidKey.isValid()) return;
Proto::Auth::Certificate cert;
if (cert.ParseFromString(::Utils::IO::ReadFile("players/guid.dat")))
{
Auth::GuidKey.Import(cert.privatekey());
Auth::GuidKey.deserialize(cert.privatekey());
Auth::GuidToken = cert.token();
Auth::ComputeToken = cert.ctoken();
}
else
{
Auth::GuidKey.Free();
Auth::GuidKey.free();
}
if (!Auth::GuidKey.IsValid())
if (!Auth::GuidKey.isValid())
{
Auth::GuidToken.Clear();
Auth::ComputeToken.Clear();
Auth::GuidToken.clear();
Auth::ComputeToken.clear();
Auth::GuidKey = Utils::Cryptography::ECC::GenerateKey(512);
Auth::StoreKey();
}
@ -267,7 +267,7 @@ namespace Components
uint32_t Auth::GetSecurityLevel()
{
return Auth::GetZeroBits(Auth::GuidToken, Auth::GuidKey.GetPublicKey());
return Auth::GetZeroBits(Auth::GuidToken, Auth::GuidKey.getPublicKey());
}
void Auth::IncreaseSecurityLevel(uint32_t level, std::string command)
@ -289,7 +289,7 @@ namespace Components
Auth::TokenContainer.generating = true;
Auth::TokenContainer.hashes = 0;
Auth::TokenContainer.startTime = Game::Sys_Milliseconds();
Auth::IncrementToken(Auth::GuidToken, Auth::ComputeToken, Auth::GuidKey.GetPublicKey(), Auth::TokenContainer.targetLevel, &Auth::TokenContainer.cancel, &Auth::TokenContainer.hashes);
Auth::IncrementToken(Auth::GuidToken, Auth::ComputeToken, Auth::GuidKey.getPublicKey(), Auth::TokenContainer.targetLevel, &Auth::TokenContainer.cancel, &Auth::TokenContainer.hashes);
Auth::TokenContainer.generating = false;
if (Auth::TokenContainer.cancel)
@ -302,7 +302,7 @@ namespace Components
uint32_t Auth::GetZeroBits(Utils::Cryptography::Token token, std::string publicKey)
{
std::string message = publicKey + token.ToString();
std::string message = publicKey + token.toString();
std::string hash = Utils::Cryptography::SHA512::Compute(message, false);
uint32_t bits = 0;
@ -382,8 +382,8 @@ namespace Components
Dvar::Register<int>("sv_securityLevel", 23, 0, 512, Game::dvar_flag::DVAR_FLAG_SERVERINFO, "Security level for GUID certificates (POW)");
// Install registration hook
Utils::Hook(0x6265F9, Auth::DirectConnectStub, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x41D3E3, Auth::SendConnectDataStub, HOOK_CALL).Install()->Quick();
Utils::Hook(0x6265F9, Auth::DirectConnectStub, HOOK_JUMP).install()->quick();
Utils::Hook(0x41D3E3, Auth::SendConnectDataStub, HOOK_CALL).install()->quick();
// Guid command
Command::Add("guid", [] (Command::Params)
@ -395,12 +395,12 @@ namespace Components
{
Command::Add("securityLevel", [] (Command::Params params)
{
if (params.Length() < 2)
if (params.length() < 2)
{
uint32_t level = Auth::GetZeroBits(Auth::GuidToken, Auth::GuidKey.GetPublicKey());
uint32_t level = Auth::GetZeroBits(Auth::GuidToken, Auth::GuidKey.getPublicKey());
Logger::Print("Your current security level is %d\n", level);
Logger::Print("Your security token is: %s\n", Utils::String::DumpHex(Auth::GuidToken.ToString(), "").data());
Logger::Print("Your computation token is: %s\n", Utils::String::DumpHex(Auth::ComputeToken.ToString(), "").data());
Logger::Print("Your security token is: %s\n", Utils::String::DumpHex(Auth::GuidToken.toString(), "").data());
Logger::Print("Your computation token is: %s\n", Utils::String::DumpHex(Auth::ComputeToken.toString(), "").data());
Toast::Show("cardicon_locked", "^5Security Level", fmt::sprintf("Your security level is %d", level), 3000);
}
@ -433,7 +433,7 @@ namespace Components
Auth::StoreKey();
}
bool Auth::UnitTest()
bool Auth::unitTest()
{
bool success = true;

View File

@ -7,10 +7,10 @@ namespace Components
~Auth();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "Auth"; };
const char* getName() { return "Auth"; };
#endif
bool UnitTest();
bool unitTest();
static void StoreKey();
static void LoadKey(bool force = false);

View File

@ -11,7 +11,7 @@ namespace Components
if (entry.first.Bits)
{
for (auto& idEntry : list.IDList)
for (auto& idEntry : list.idList)
{
if (idEntry.Bits == entry.first.Bits)
{
@ -22,7 +22,7 @@ namespace Components
if (entry.second.full)
{
for (auto& ipEntry : list.IPList)
for (auto& ipEntry : list.ipList)
{
if (ipEntry.full == entry.second.full)
{
@ -44,7 +44,7 @@ namespace Components
if (entry.first.Bits)
{
bool found = false;
for (auto& idEntry : list.IDList)
for (auto& idEntry : list.idList)
{
if (idEntry.Bits == entry.first.Bits)
{
@ -55,14 +55,14 @@ namespace Components
if (!found)
{
list.IDList.push_back(entry.first);
list.idList.push_back(entry.first);
}
}
if (entry.second.full)
{
bool found = false;
for (auto& ipEntry : list.IPList)
for (auto& ipEntry : list.ipList)
{
if (ipEntry.full == entry.second.full)
{
@ -73,19 +73,19 @@ namespace Components
if (!found)
{
list.IPList.push_back(entry.second);
list.ipList.push_back(entry.second);
}
}
std::vector<std::string> idVector;
std::vector<std::string> ipVector;
for (auto& idEntry : list.IDList)
for (auto& idEntry : list.idList)
{
idVector.push_back(fmt::sprintf("%llX", idEntry.Bits));
}
for (auto& ipEntry : list.IPList)
for (auto& ipEntry : list.ipList)
{
ipVector.push_back(fmt::sprintf("%u.%u.%u.%u",
ipEntry.bytes[0] & 0xFF,
@ -101,7 +101,7 @@ namespace Components
};
FileSystem::FileWriter ban("bans.json");
ban.Write(bans.dump());
ban.write(bans.dump());
}
void Bans::LoadBans(Bans::BanList* list)
@ -110,10 +110,10 @@ namespace Components
FileSystem::File bans("bans.json");
if (bans.Exists())
if (bans.exists())
{
std::string error;
json11::Json banData = json11::Json::parse(bans.GetBuffer(), error);
json11::Json banData = json11::Json::parse(bans.getBuffer(), error);
if (!error.empty())
{
@ -140,7 +140,7 @@ namespace Components
SteamID id;
id.Bits = strtoull(idEntry.string_value().data(), nullptr, 16);
list->IDList.push_back(id);
list->idList.push_back(id);
}
}
}
@ -153,7 +153,7 @@ namespace Components
{
Network::Address addr(ipEntry.string_value());
list->IPList.push_back(addr.GetIP());
list->ipList.push_back(addr.getIP());
}
}
}
@ -163,7 +163,7 @@ namespace Components
void Bans::BanClientNum(int num, std::string reason)
{
if (!Dvar::Var("sv_running").Get<bool>())
if (!Dvar::Var("sv_running").get<bool>())
{
Logger::Print("Server is not running.\n");
return;
@ -189,10 +189,10 @@ namespace Components
{
Command::Add("banclient", [] (Command::Params params)
{
if (params.Length() < 2) return;
if (params.length() < 2) return;
std::string reason = "EXE_ERR_BANNED_PERM";
if (params.Length() >= 3) reason = params[2];
if (params.length() >= 3) reason = params[2];
Bans::BanClientNum(atoi(params[1]), reason);
});

View File

@ -9,7 +9,7 @@ namespace Components
~Bans();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "Bans"; };
const char* getName() { return "Bans"; };
#endif
static void BanClientNum(int num, std::string reason);
@ -21,12 +21,11 @@ namespace Components
class BanList
{
public:
std::vector<SteamID> IDList;
std::vector<Game::netIP_t> IPList;
std::vector<SteamID> idList;
std::vector<Game::netIP_t> ipList;
};
static std::mutex AccessMutex;
static void LoadBans(BanList* list);
};
}

View File

@ -46,7 +46,7 @@ namespace Components
#ifdef DEBUG
Command::Add("bm_send", [] (Command::Params params)
{
if (params.Length() < 3) return;
if (params.length() < 3) return;
ustring pubAddrString;
pubAddrString.fromString(params[1]);
@ -55,7 +55,7 @@ namespace Components
if (pubAddr.loadAddr(pubAddrString))
{
ustring msg;
msg.fromString(params.Join(2));
msg.fromString(params.join(2));
Logger::Print("Sending message (this may take a while)...\n");
BitMessage::BMClient->sendMessage(msg, pubAddr, BitMessage::BMClient->PrivAddresses[0]);
@ -69,10 +69,10 @@ namespace Components
Command::Add("bm_sendb", [] (Command::Params params)
{
if (params.Length() < 2) return;
if (params.length() < 2) return;
ustring msg;
msg.appendVarString(params.Join(1));
msg.appendVarString(params.join(1));
Logger::Print("Sending broadcast...\n");
BitMessage::BMClient->sendBroadcast(msg, BitMessage::BMClient->PrivAddresses[0]);
Logger::Print("Broadcast done.\n");
@ -162,10 +162,10 @@ namespace Components
Command::Add("bm_address_public", [] (Command::Params params)
{
if (!BitMessage::BMClient) return;
if (params.Length() < 2) return;
if (params.length() < 2) return;
ustring addre;
addre.fromString(params.Join(1));
addre.fromString(params.join(1));
PubAddr address;
if (address.loadAddr(addre))
@ -183,10 +183,10 @@ namespace Components
Command::Add("bm_address_broadcast", [] (Command::Params params)
{
if (!BitMessage::BMClient) return;
if (params.Length() < 2) return;
if (params.length() < 2) return;
ustring addre;
addre.fromString(params.Join(1));
addre.fromString(params.join(1));
PubAddr address;
if (address.loadAddr(addre))
{

View File

@ -14,7 +14,7 @@ namespace Components
~BitMessage();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "BitMessage"; };
const char* getName() { return "BitMessage"; };
#endif
static void SetDefaultTTL(time_t ttl);

View File

@ -173,7 +173,7 @@ namespace Components
int clrIndex = Colors::ColorIndex(index);
// Use native colors
if (clrIndex <= 7 && !Colors::NewColors.Get<bool>())
if (clrIndex <= 7 && !Colors::NewColors.get<bool>())
{
*color = reinterpret_cast<DWORD*>(0x78DC70)[index - 48];
}
@ -210,19 +210,19 @@ namespace Components
Utils::Hook::Set<BYTE>(0x6258D0, 0xC3);
// Allow colored names ingame
Utils::Hook(0x5D8B40, Colors::ClientUserinfoChanged, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x5D8B40, Colors::ClientUserinfoChanged, HOOK_JUMP).install()->quick();
// Though, don't apply that to overhead names.
Utils::Hook(0x581932, Colors::GetClientName, HOOK_CALL).Install()->Quick();
Utils::Hook(0x581932, Colors::GetClientName, HOOK_CALL).install()->quick();
// Patch RB_LookupColor
Utils::Hook(0x534CD0, Colors::LookupColorStub, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x534CD0, Colors::LookupColorStub, HOOK_JUMP).install()->quick();
// Patch ColorIndex
Utils::Hook(0x417770, Colors::ColorIndex, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x417770, Colors::ColorIndex, HOOK_JUMP).install()->quick();
// Patch I_CleanStr
Utils::Hook(0x4AD470, Colors::CleanStrStub, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x4AD470, Colors::CleanStrStub, HOOK_JUMP).install()->quick();
// Register dvar
Colors::NewColors = Dvar::Register<bool>("cg_newColors", true, Game::dvar_flag::DVAR_FLAG_SAVED, "Use Warfare² color code style.");

View File

@ -7,7 +7,7 @@ namespace Components
~Colors();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "Colors"; };
const char* getName() { return "Colors"; };
#endif
static void Strip(const char* in, char* out, int max);
@ -23,10 +23,10 @@ namespace Components
unsigned char v;
};
static DWORD HsvToRgb(HsvColor hsv);
static Dvar::Var NewColors;
static DWORD HsvToRgb(HsvColor hsv);
static void ClientUserinfoChanged();
static char* GetClientName(int localClientNum, int index, char *buf, size_t size);
static void PatchColorLimit(char limit);

View File

@ -8,22 +8,22 @@ namespace Components
char* Command::Params::operator[](size_t index)
{
if (index >= this->Length()) return "";
if (this->IsSV) return Game::cmd_argv_sv[this->CommandId][index];
else return Game::cmd_argv[this->CommandId][index];
if (index >= this->length()) return "";
if (this->isSV) return Game::cmd_argv_sv[this->commandId][index];
else return Game::cmd_argv[this->commandId][index];
}
size_t Command::Params::Length()
size_t Command::Params::length()
{
if (this->IsSV) return Game::cmd_argc_sv[this->CommandId];
else return Game::cmd_argc[this->CommandId];
if (this->isSV) return Game::cmd_argc_sv[this->commandId];
else return Game::cmd_argc[this->commandId];
}
std::string Command::Params::Join(size_t startIndex)
std::string Command::Params::join(size_t startIndex)
{
std::string result;
for (size_t i = startIndex; i < this->Length(); ++i)
for (size_t i = startIndex; i < this->length(); ++i)
{
if (i > startIndex) result.append(" ");
result.append(this->operator[](i));
@ -116,7 +116,7 @@ namespace Components
Game::cmd_function_t* Command::Allocate()
{
return Command::MemAllocator.Allocate<Game::cmd_function_t>();
return Command::MemAllocator.allocate<Game::cmd_function_t>();
}
void Command::MainCallback()
@ -145,7 +145,7 @@ namespace Components
Command::Command()
{
Assert_Size(Game::cmd_function_t, 24);
AssertSize(Game::cmd_function_t, 24);
// Disable native noclip command
Utils::Hook::Nop(0x474846, 5);
@ -160,7 +160,7 @@ namespace Components
return;
}
if (!Dvar::Var("sv_cheats").Get<bool>())
if (!Dvar::Var("sv_cheats").get<bool>())
{
Logger::Print("Cheats disabled!\n");
Toast::Show("cardicon_stop", "Error", "Cheats disabled!", 3000);
@ -183,7 +183,7 @@ namespace Components
return;
}
if (!Dvar::Var("sv_cheats").Get<bool>())
if (!Dvar::Var("sv_cheats").get<bool>())
{
Logger::Print("Cheats disabled!\n");
Toast::Show("cardicon_stop", "Error", "Cheats disabled!", 3000);
@ -199,7 +199,7 @@ namespace Components
Command::~Command()
{
Command::MemAllocator.Clear();
Command::MemAllocator.clear();
Command::FunctionMap.clear();
Command::FunctionMapSV.clear();
}

View File

@ -6,19 +6,19 @@ namespace Components
class Params
{
public:
Params(bool sv, DWORD id) : CommandId(id), IsSV(sv) {};
Params(bool sv, DWORD id) : commandId(id), isSV(sv) {};
Params(bool sv) : Params(sv, (sv ? *Game::cmd_id_sv : *Game::cmd_id)) {};
Params(const Params &obj) : CommandId(obj.CommandId), IsSV(obj.IsSV) {};
Params(const Params &obj) : commandId(obj.commandId), isSV(obj.isSV) {};
Params() : Params(false, *Game::cmd_id) {};
char* operator[](size_t index);
size_t Length();
size_t length();
std::string Join(size_t startIndex);
std::string join(size_t startIndex);
private:
bool IsSV;
DWORD CommandId;
bool isSV;
DWORD commandId;
};
typedef void(Callback)(Command::Params params);
@ -27,7 +27,7 @@ namespace Components
~Command();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "Command"; };
const char* getName() { return "Command"; };
#endif
static Game::cmd_function_t* Allocate();

View File

@ -2,21 +2,22 @@
namespace Components
{
ConnectProtocol::Container ConnectProtocol::ConnectContainer = { false, "" };
bool ConnectProtocol::Evaluated = false;
std::string ConnectProtocol::ConnectString;
bool ConnectProtocol::Evaluated()
bool ConnectProtocol::IsEvaluated()
{
return ConnectProtocol::ConnectContainer.Evaluated;
return ConnectProtocol::Evaluated;
}
bool ConnectProtocol::Used()
{
if (!ConnectProtocol::Evaluated())
if (!ConnectProtocol::IsEvaluated())
{
ConnectProtocol::EvaluateProtocol();
}
return (!ConnectProtocol::ConnectContainer.ConnectString.empty());
return (!ConnectProtocol::ConnectString.empty());
}
bool ConnectProtocol::InstallProtocol()
@ -172,8 +173,8 @@ namespace Components
void ConnectProtocol::EvaluateProtocol()
{
if (ConnectProtocol::ConnectContainer.Evaluated) return;
ConnectProtocol::ConnectContainer.Evaluated = true;
if (ConnectProtocol::Evaluated) return;
ConnectProtocol::Evaluated = true;
std::string cmdLine = GetCommandLineA();
@ -189,7 +190,7 @@ namespace Components
cmdLine = cmdLine.substr(0, pos);
}
ConnectProtocol::ConnectContainer.ConnectString = cmdLine;
ConnectProtocol::ConnectString = cmdLine;
}
}
@ -203,7 +204,7 @@ namespace Components
}
else
{
Command::Execute(fmt::sprintf("connect %s", ConnectProtocol::ConnectContainer.ConnectString.data()), false);
Command::Execute(fmt::sprintf("connect %s", ConnectProtocol::ConnectString.data()), false);
}
}
}
@ -228,7 +229,7 @@ namespace Components
{
if (!Singleton::IsFirstInstance())
{
IPCPipe::Write("connect", ConnectProtocol::ConnectContainer.ConnectString);
IPCPipe::Write("connect", ConnectProtocol::ConnectString);
ExitProcess(0);
}
else

View File

@ -6,21 +6,15 @@ namespace Components
ConnectProtocol();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "ConnectProtocol"; };
const char* getName() { return "ConnectProtocol"; };
#endif
static bool Evaluated();
static bool IsEvaluated();
static bool Used();
private:
class Container
{
public:
bool Evaluated;
std::string ConnectString;
};
static Container ConnectContainer;
static bool Evaluated;
static std::string ConnectString;
static void EvaluateProtocol();
static bool InstallProtocol();

View File

@ -44,8 +44,8 @@ namespace Components
void Console::RefreshStatus()
{
std::string mapname = Dvar::Var("mapname").Get<const char*>();
std::string hostname = Colors::Strip(Dvar::Var("sv_hostname").Get<const char*>());
std::string mapname = Dvar::Var("mapname").get<const char*>();
std::string hostname = Colors::Strip(Dvar::Var("sv_hostname").get<const char*>());
if (Console::HasConsole)
{
@ -66,7 +66,7 @@ namespace Components
}
else
{
//maxclientCount = Dvar::Var("sv_maxclients").Get<int>();
//maxclientCount = Dvar::Var("sv_maxclients").get<int>();
maxclientCount = Game::Party_GetMaxPlayers(*Game::partyIngame);
clientCount = Game::PartyHost_CountMembers(reinterpret_cast<Game::PartyData_s*>(0x1081C00));
}
@ -532,21 +532,21 @@ namespace Components
Utils::Hook::Set<float*>(0x5A4400, consoleColor);
// Internal console
Utils::Hook(0x4F690C, Console::ToggleConsole, HOOK_CALL).Install()->Quick();
Utils::Hook(0x4F65A5, Console::ToggleConsole, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x4F690C, Console::ToggleConsole, HOOK_CALL).install()->quick();
Utils::Hook(0x4F65A5, Console::ToggleConsole, HOOK_JUMP).install()->quick();
// Patch safearea for ingame-console
Utils::Hook(0x5A50EF, Console::DrawSolidConsoleStub, HOOK_CALL).Install()->Quick();
Utils::Hook(0x5A50EF, Console::DrawSolidConsoleStub, HOOK_CALL).install()->quick();
// Check for bad food ;)
Utils::Hook(0x4CB9F4, Console::GetAutoCompleteFileList, HOOK_CALL).Install()->Quick();
Utils::Hook(0x4CB9F4, Console::GetAutoCompleteFileList, HOOK_CALL).install()->quick();
// Patch console dvars
Utils::Hook(0x4829AB, Console::RegisterConColor, HOOK_CALL).Install()->Quick();
Utils::Hook(0x4829EE, Console::RegisterConColor, HOOK_CALL).Install()->Quick();
Utils::Hook(0x482A31, Console::RegisterConColor, HOOK_CALL).Install()->Quick();
Utils::Hook(0x482A7A, Console::RegisterConColor, HOOK_CALL).Install()->Quick();
Utils::Hook(0x482AC3, Console::RegisterConColor, HOOK_CALL).Install()->Quick();
Utils::Hook(0x4829AB, Console::RegisterConColor, HOOK_CALL).install()->quick();
Utils::Hook(0x4829EE, Console::RegisterConColor, HOOK_CALL).install()->quick();
Utils::Hook(0x482A31, Console::RegisterConColor, HOOK_CALL).install()->quick();
Utils::Hook(0x482A7A, Console::RegisterConColor, HOOK_CALL).install()->quick();
Utils::Hook(0x482AC3, Console::RegisterConColor, HOOK_CALL).install()->quick();
// Modify console style
Utils::Hook::Set<BYTE>(0x428A8E, 0); // Adjust logo Y pos
@ -559,7 +559,7 @@ namespace Components
Utils::Hook::Set<DWORD>(0x428AED, 596); // Reduce output width
// Don't resize the console
Utils::Hook(0x64DC6B, 0x64DCC2, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x64DC6B, 0x64DCC2, HOOK_JUMP).install()->quick();
if (Dedicated::IsEnabled() && !ZoneBuilder::IsEnabled())
{
@ -572,20 +572,20 @@ namespace Components
// External console
if (Flags::HasFlag("stdout"))
{
Utils::Hook(0x4B2080, Console::StdOutPrint, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x43D570, Console::StdOutError, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x4B2080, Console::StdOutPrint, HOOK_JUMP).install()->quick();
Utils::Hook(0x43D570, Console::StdOutError, HOOK_JUMP).install()->quick();
}
else if (Flags::HasFlag("console") || ZoneBuilder::IsEnabled()) // ZoneBuilder uses the game's console, until the native one is adapted.
{
Utils::Hook::Nop(0x60BB58, 11);
// Redirect input (]command)
Utils::Hook(0x47025A, 0x4F5770, HOOK_CALL).Install()->Quick();
Utils::Hook(0x47025A, 0x4F5770, HOOK_CALL).install()->quick();
Utils::Hook(0x60BB68, [] ()
{
Console::ConsoleThread = std::thread(Console::ConsoleRunner);
}, HOOK_CALL).Install()->Quick();
}, HOOK_CALL).install()->quick();
QuickPatch::OnFrame([] ()
{
@ -596,11 +596,11 @@ namespace Components
{
Utils::Hook::Nop(0x60BB58, 11);
Utils::Hook(0x4305E0, Console::Create, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x4528A0, Console::Destroy, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x4B2080, Console::Print, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x43D570, Console::Error, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x4859A5, Console::Input, HOOK_CALL).Install()->Quick();
Utils::Hook(0x4305E0, Console::Create, HOOK_JUMP).install()->quick();
Utils::Hook(0x4528A0, Console::Destroy, HOOK_JUMP).install()->quick();
Utils::Hook(0x4B2080, Console::Print, HOOK_JUMP).install()->quick();
Utils::Hook(0x43D570, Console::Error, HOOK_JUMP).install()->quick();
Utils::Hook(0x4859A5, Console::Input, HOOK_CALL).install()->quick();
}
else
{

View File

@ -10,7 +10,7 @@ namespace Components
~Console();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "Console"; };
const char* getName() { return "Console"; };
#endif
static void SetSkipShutdown();

View File

@ -729,7 +729,7 @@ namespace Components
IDirect3D9* __stdcall D3D9Ex::Direct3DCreate9Stub(UINT sdk)
{
if (Dvar::Var("r_useD3D9Ex").Get<bool>())
if (Dvar::Var("r_useD3D9Ex").get<bool>())
{
IDirect3D9Ex* test;
Direct3DCreate9Ex(sdk, &test);

View File

@ -6,7 +6,7 @@ namespace Components
D3D9Ex();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "D3D9Ex"; };
const char* getName() { return "D3D9Ex"; };
#endif
private:

View File

@ -118,13 +118,13 @@ namespace Components
void Dedicated::MapRotate()
{
if (!Dedicated::IsEnabled() && Dvar::Var("sv_dontrotate").Get<bool>())
if (!Dedicated::IsEnabled() && Dvar::Var("sv_dontrotate").get<bool>())
{
Dvar::Var("sv_dontrotate").SetRaw(0);
Dvar::Var("sv_dontrotate").setRaw(0);
return;
}
if (Dvar::Var("party_enable").Get<bool>() && Dvar::Var("party_host").Get<bool>())
if (Dvar::Var("party_enable").get<bool>() && Dvar::Var("party_host").get<bool>())
{
Logger::Print("Not performing map rotation as we are hosting a party!\n");
return;
@ -133,30 +133,30 @@ namespace Components
Logger::Print("Rotating map...\n");
// if nothing, just restart
if (Dvar::Var("sv_mapRotation").Get<std::string>().empty())
if (Dvar::Var("sv_mapRotation").get<std::string>().empty())
{
Logger::Print("No rotation defined, restarting map.\n");
if (!Dvar::Var("sv_cheats").Get<bool>())
if (!Dvar::Var("sv_cheats").get<bool>())
{
Command::Execute(fmt::sprintf("map %s", Dvar::Var("mapname").Get<const char*>()), true);
Command::Execute(fmt::sprintf("map %s", Dvar::Var("mapname").get<const char*>()), true);
}
else
{
Command::Execute(fmt::sprintf("devmap %s", Dvar::Var("mapname").Get<const char*>()), true);
Command::Execute(fmt::sprintf("devmap %s", Dvar::Var("mapname").get<const char*>()), true);
}
return;
}
// first, check if the string contains nothing
if (Dvar::Var("sv_mapRotationCurrent").Get<std::string>().empty())
if (Dvar::Var("sv_mapRotationCurrent").get<std::string>().empty())
{
Logger::Print("Current map rotation has finished, reloading...\n");
Dvar::Var("sv_mapRotationCurrent").Set(Dvar::Var("sv_mapRotation").Get<const char*>());
Dvar::Var("sv_mapRotationCurrent").set(Dvar::Var("sv_mapRotation").get<const char*>());
}
std::string rotation = Dvar::Var("sv_mapRotationCurrent").Get<std::string>();
std::string rotation = Dvar::Var("sv_mapRotationCurrent").get<std::string>();
auto tokens = Utils::String::Explode(rotation, ' ');
@ -164,7 +164,7 @@ namespace Components
{
if (i + 1 >= tokens.size())
{
Dvar::Var("sv_mapRotationCurrent").Set("");
Dvar::Var("sv_mapRotationCurrent").set("");
Command::Execute("map_rotate", true);
return;
}
@ -182,7 +182,7 @@ namespace Components
rotation += tokens[j];
}
Dvar::Var("sv_mapRotationCurrent").Set(rotation);
Dvar::Var("sv_mapRotationCurrent").set(rotation);
Logger::Print("Loading new map: %s\n", value.data());
Command::Execute(fmt::sprintf("map %s", value.data()), true);
@ -191,7 +191,7 @@ namespace Components
else if (key == "gametype")
{
Logger::Print("Applying new gametype: %s\n", value.data());
Dvar::Var("g_gametype").Set(value);
Dvar::Var("g_gametype").set(value);
}
else
{
@ -202,8 +202,8 @@ namespace Components
void Dedicated::Heartbeat()
{
int masterPort = Dvar::Var("masterPort").Get<int>();
const char* masterServerName = Dvar::Var("masterServerName").Get<const char*>();
int masterPort = Dvar::Var("masterPort").get<int>();
const char* masterServerName = Dvar::Var("masterServerName").get<const char*>();
Network::Address master(fmt::sprintf("%s:%u", masterServerName, masterPort));
@ -243,7 +243,7 @@ namespace Components
{
Dvar::Register<bool>("sv_lanOnly", false, Game::dvar_flag::DVAR_FLAG_NONE, "Don't act as node");
Utils::Hook(0x60BE98, Dedicated::InitDedicatedServer, HOOK_CALL).Install()->Quick();
Utils::Hook(0x60BE98, Dedicated::InitDedicatedServer, HOOK_CALL).install()->quick();
Utils::Hook::Set<BYTE>(0x683370, 0xC3); // steam sometimes doesn't like the server
@ -299,17 +299,17 @@ namespace Components
Utils::Hook::Set<BYTE>(0x4B4D19, 0xEB);
// Dedicated frame handler
Utils::Hook(0x4B0F81, Dedicated::FrameStub, HOOK_CALL).Install()->Quick();
Utils::Hook(0x4B0F81, Dedicated::FrameStub, HOOK_CALL).install()->quick();
// Intercept chat sending
Utils::Hook(0x4D000B, Dedicated::PreSayStub, HOOK_CALL).Install()->Quick();
Utils::Hook(0x4D00D4, Dedicated::PostSayStub, HOOK_CALL).Install()->Quick();
Utils::Hook(0x4D0110, Dedicated::PostSayStub, HOOK_CALL).Install()->Quick();
Utils::Hook(0x4D000B, Dedicated::PreSayStub, HOOK_CALL).install()->quick();
Utils::Hook(0x4D00D4, Dedicated::PostSayStub, HOOK_CALL).install()->quick();
Utils::Hook(0x4D0110, Dedicated::PostSayStub, HOOK_CALL).install()->quick();
if (!ZoneBuilder::IsEnabled())
{
// Post initialization point
Utils::Hook(0x60BFBF, Dedicated::PostInitializationStub, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x60BFBF, Dedicated::PostInitializationStub, HOOK_JUMP).install()->quick();
#ifdef USE_LEGACY_SERVER_LIST
@ -318,7 +318,7 @@ namespace Components
{
static int LastHeartbeat = 0;
if (Dvar::Var("sv_maxclients").Get<int>() > 0 && !LastHeartbeat || (Game::Com_Milliseconds() - LastHeartbeat) > 120 * 1000)
if (Dvar::Var("sv_maxclients").get<int>() > 0 && !LastHeartbeat || (Game::Com_Milliseconds() - LastHeartbeat) > 120 * 1000)
{
LastHeartbeat = Game::Com_Milliseconds();
Dedicated::Heartbeat();
@ -334,10 +334,10 @@ namespace Components
// Say command
Command::AddSV("say", [] (Command::Params params)
{
if (params.Length() < 2) return;
if (params.length() < 2) return;
std::string message = params.Join(1);
std::string name = Dvar::Var("sv_sayName").Get<std::string>();
std::string message = params.join(1);
std::string name = Dvar::Var("sv_sayName").get<std::string>();
if (!name.empty())
{
@ -354,11 +354,11 @@ namespace Components
// Tell command
Command::AddSV("tell", [] (Command::Params params)
{
if (params.Length() < 3) return;
if (params.length() < 3) return;
int client = atoi(params[1]);
std::string message = params.Join(2);
std::string name = Dvar::Var("sv_sayName").Get<std::string>();
std::string message = params.join(2);
std::string name = Dvar::Var("sv_sayName").get<std::string>();
if (!name.empty())
{
@ -375,9 +375,9 @@ namespace Components
// Sayraw command
Command::AddSV("sayraw", [] (Command::Params params)
{
if (params.Length() < 2) return;
if (params.length() < 2) return;
std::string message = params.Join(1);
std::string message = params.join(1);
Game::SV_GameSendServerCommand(-1, 0, Utils::String::VA("%c \"%s\"", 104, message.data()));
Game::Com_Printf(15, "Raw: %s\n", message.data());
});
@ -385,10 +385,10 @@ namespace Components
// Tellraw command
Command::AddSV("tellraw", [] (Command::Params params)
{
if (params.Length() < 3) return;
if (params.length() < 3) return;
int client = atoi(params[1]);
std::string message = params.Join(2);
std::string message = params.join(2);
Game::SV_GameSendServerCommand(client, 0, Utils::String::VA("%c \"%s\"", 104, message.data()));
Game::Com_Printf(15, "Raw -> %i: %s\n", client, message.data());
});
@ -396,7 +396,7 @@ namespace Components
// ! command
Command::AddSV("!", [] (Command::Params params)
{
if (params.Length() != 2) return;
if (params.length() != 2) return;
int client = -1;
if (params[1] != "all"s)

View File

@ -9,7 +9,7 @@ namespace Components
~Dedicated();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "Dedicated"; };
const char* getName() { return "Dedicated"; };
#endif
static bool IsEnabled();

View File

@ -2,11 +2,14 @@
namespace Components
{
Discovery::Container Discovery::DiscoveryContainer = { false, false, std::thread() };
bool Discovery::IsTerminating = false;
bool Discovery::IsPerforming = false;
std::thread Discovery::Thread;
std::string Discovery::Challenge;
void Discovery::Perform()
{
Discovery::DiscoveryContainer.Perform = true;
Discovery::IsPerforming = true;
}
Discovery::Discovery()
@ -16,27 +19,27 @@ namespace Components
// An additional thread prevents lags
// Not sure if that's the best way though
Discovery::DiscoveryContainer.Perform = false;
Discovery::DiscoveryContainer.Terminate = false;
Discovery::DiscoveryContainer.Thread = std::thread([] ()
Discovery::IsPerforming = false;
Discovery::IsTerminating = false;
Discovery::Thread = std::thread([] ()
{
while (!Discovery::DiscoveryContainer.Terminate)
while (!Discovery::IsTerminating)
{
if (Discovery::DiscoveryContainer.Perform)
if (Discovery::IsPerforming)
{
int start = Game::Sys_Milliseconds();
Logger::Print("Starting local server discovery...\n");
Discovery::DiscoveryContainer.Challenge = fmt::sprintf("%X", Utils::Cryptography::Rand::GenerateInt());
Discovery::Challenge = fmt::sprintf("%X", Utils::Cryptography::Rand::GenerateInt());
unsigned int minPort = Dvar::Var("net_discoveryPortRangeMin").Get<unsigned int>();
unsigned int maxPort = Dvar::Var("net_discoveryPortRangeMax").Get<unsigned int>();
Network::BroadcastRange(minPort, maxPort, fmt::sprintf("discovery %s", Discovery::DiscoveryContainer.Challenge.data()));
unsigned int minPort = Dvar::Var("net_discoveryPortRangeMin").get<unsigned int>();
unsigned int maxPort = Dvar::Var("net_discoveryPortRangeMax").get<unsigned int>();
Network::BroadcastRange(minPort, maxPort, fmt::sprintf("discovery %s", Discovery::Challenge.data()));
Logger::Print("Discovery sent within %dms, awaiting responses...\n", Game::Sys_Milliseconds() - start);
Discovery::DiscoveryContainer.Perform = false;
Discovery::IsPerforming = false;
}
std::this_thread::sleep_for(50ms);
@ -45,35 +48,35 @@ namespace Components
Network::Handle("discovery", [] (Network::Address address, std::string data)
{
if (address.IsSelf()) return;
if (address.isSelf()) return;
if (!address.IsLocal())
if (!address.isLocal())
{
Logger::Print("Received discovery request from non-local address: %s\n", address.GetCString());
Logger::Print("Received discovery request from non-local address: %s\n", address.getCString());
return;
}
Logger::Print("Received discovery request from %s\n", address.GetCString());
Logger::Print("Received discovery request from %s\n", address.getCString());
Network::SendCommand(address, "discoveryResponse", data);
});
Network::Handle("discoveryResponse", [] (Network::Address address, std::string data)
{
if (address.IsSelf()) return;
if (address.isSelf()) return;
if (!address.IsLocal())
if (!address.isLocal())
{
Logger::Print("Received discovery response from non-local address: %s\n", address.GetCString());
Logger::Print("Received discovery response from non-local address: %s\n", address.getCString());
return;
}
if (Utils::ParseChallenge(data) != Discovery::DiscoveryContainer.Challenge)
if (Utils::ParseChallenge(data) != Discovery::Challenge)
{
Logger::Print("Received discovery with invalid challenge from: %s\n", address.GetCString());
Logger::Print("Received discovery with invalid challenge from: %s\n", address.getCString());
return;
}
Logger::Print("Received discovery response from: %s\n", address.GetCString());
Logger::Print("Received discovery response from: %s\n", address.getCString());
if (ServerList::IsOfflineList())
{
@ -88,18 +91,18 @@ namespace Components
{
AntiCheat::ScanIntegrityCheck();
return Utils::Hook::Call<void()>(0x4AA720)();
}, HOOK_CALL).Install()->Quick();
}, HOOK_CALL).install()->quick();
#endif
}
Discovery::~Discovery()
{
Discovery::DiscoveryContainer.Perform = false;
Discovery::DiscoveryContainer.Terminate = true;
Discovery::IsPerforming = false;
Discovery::IsPerforming = true;
if (Discovery::DiscoveryContainer.Thread.joinable())
if (Discovery::Thread.joinable())
{
Discovery::DiscoveryContainer.Thread.join();
Discovery::Thread.join();
}
}
}

View File

@ -7,21 +7,15 @@ namespace Components
~Discovery();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "Discovery"; };
const char* getName() { return "Discovery"; };
#endif
static void Perform();
private:
class Container
{
public:
bool Perform;
bool Terminate;
std::thread Thread;
std::string Challenge;
};
static Container DiscoveryContainer;
static bool IsTerminating;
static bool IsPerforming;
static std::thread Thread;
static std::string Challenge;
};
}

View File

@ -9,7 +9,7 @@ namespace Components
void Download::InitiateClientDownload(std::string mod)
{
if (Download::CLDownload.Running) return;
if (Download::CLDownload.running) return;
Localization::SetTemp("MPUI_EST_TIME_LEFT", Utils::String::FormatTimeSpan(0));
Localization::SetTemp("MPUI_PROGRESS_DL", "(0/0) %");
@ -17,17 +17,17 @@ namespace Components
Command::Execute("openmenu mod_download_popmenu", true);
Download::CLDownload.Running = true;
Download::CLDownload.Mod = mod;
Download::CLDownload.TerminateThread = false;
Download::CLDownload.Target = Party::Target();
Download::CLDownload.Thread = std::thread(Download::ModDownloader, &Download::CLDownload);
Download::CLDownload.running = true;
Download::CLDownload.mod = mod;
Download::CLDownload.terminateThread = false;
Download::CLDownload.target = Party::Target();
Download::CLDownload.thread = std::thread(Download::ModDownloader, &Download::CLDownload);
}
bool Download::ParseModList(ClientDownload* download, std::string list)
{
if (!download) return false;
download->Files.clear();
download->files.clear();
std::string error;
json11::Json listData = json11::Json::parse(list, error);
@ -35,7 +35,7 @@ namespace Components
if (!error.empty() || !listData.is_array()) return false;
download->TotalBytes = 0;
download->totalBytes = 0;
for (auto& file : listData.array_items())
{
@ -48,14 +48,14 @@ namespace Components
if (!hash.is_string() || !name.is_string() || !size.is_number()) return false;
Download::ClientDownload::File fileEntry;
fileEntry.Name = name.string_value();
fileEntry.Hash = hash.string_value();
fileEntry.Size = static_cast<size_t>(size.number_value());
fileEntry.name = name.string_value();
fileEntry.hash = hash.string_value();
fileEntry.size = static_cast<size_t>(size.number_value());
if (!fileEntry.Name.empty())
if (!fileEntry.name.empty())
{
download->Files.push_back(fileEntry);
download->TotalBytes += fileEntry.Size;
download->files.push_back(fileEntry);
download->totalBytes += fileEntry.size;
}
}
@ -80,29 +80,29 @@ namespace Components
{
size_t bytes = static_cast<size_t>(*reinterpret_cast<int*>(ev_data));
fDownload->receivedBytes += bytes;
fDownload->download->DownBytes += bytes;
fDownload->download->TimeStampBytes += bytes;
fDownload->download->downBytes += bytes;
fDownload->download->timeStampBytes += bytes;
double progress = (100.0 / fDownload->download->TotalBytes) * fDownload->download->DownBytes;
Localization::SetTemp("MPUI_PROGRESS_DL", fmt::sprintf("(%d/%d) %d%%", fDownload->index + 1, fDownload->download->Files.size(), static_cast<unsigned int>(progress)));
double progress = (100.0 / fDownload->download->totalBytes) * fDownload->download->downBytes;
Localization::SetTemp("MPUI_PROGRESS_DL", fmt::sprintf("(%d/%d) %d%%", fDownload->index + 1, fDownload->download->files.size(), static_cast<unsigned int>(progress)));
int delta = Game::Sys_Milliseconds() - fDownload->download->LastTimeStamp;
int delta = Game::Sys_Milliseconds() - fDownload->download->lastTimeStamp;
if (delta > 300)
{
bool doFormat = fDownload->download->LastTimeStamp != 0;
fDownload->download->LastTimeStamp = Game::Sys_Milliseconds();
bool doFormat = fDownload->download->lastTimeStamp != 0;
fDownload->download->lastTimeStamp = Game::Sys_Milliseconds();
size_t dataLeft = fDownload->download->TotalBytes - fDownload->download->DownBytes;
double timeLeftD = ((1.0 * dataLeft) / fDownload->download->TimeStampBytes) * delta;
size_t dataLeft = fDownload->download->totalBytes - fDownload->download->downBytes;
double timeLeftD = ((1.0 * dataLeft) / fDownload->download->timeStampBytes) * delta;
int timeLeft = static_cast<int>(timeLeftD);
if (doFormat)
{
Localization::SetTemp("MPUI_EST_TIME_LEFT", Utils::String::FormatTimeSpan(timeLeft));
Localization::SetTemp("MPUI_TRANS_RATE", Utils::String::FormatBandwidth(fDownload->download->TimeStampBytes, delta));
Localization::SetTemp("MPUI_TRANS_RATE", Utils::String::FormatBandwidth(fDownload->download->timeStampBytes, delta));
}
fDownload->download->TimeStampBytes = 0;
fDownload->download->timeStampBytes = 0;
}
}
@ -117,23 +117,23 @@ namespace Components
bool Download::DownloadFile(ClientDownload* download, unsigned int index)
{
if (!download || download->Files.size() <= index) return false;
if (!download || download->files.size() <= index) return false;
auto file = download->Files[index];
auto file = download->files[index];
std::string path = download->Mod + "/" + file.Name;
std::string path = download->mod + "/" + file.name;
if (Utils::IO::FileExists(path))
{
std::string data = Utils::IO::ReadFile(path);
if (data.size() == file.Size && Utils::String::DumpHex(Utils::Cryptography::SHA256::Compute(data), "") == file.Hash)
if (data.size() == file.size && Utils::String::DumpHex(Utils::Cryptography::SHA256::Compute(data), "") == file.hash)
{
download->TotalBytes += file.Size;
download->totalBytes += file.size;
return true;
}
}
std::string url = "http://" + download->Target.GetString() + "/file/" + file.Name;
std::string url = "http://" + download->target.getString() + "/file/" + file.name;
Download::FileDownload fDownload;
fDownload.file = file;
@ -144,24 +144,24 @@ namespace Components
Utils::String::Replace(url, " ", "%20");
download->Valid = true;
mg_mgr_init(&download->Mgr, &fDownload);
mg_connect_http(&download->Mgr, Download::DownloadHandler, url.data(), NULL, NULL);
download->valid = true;
mg_mgr_init(&download->mgr, &fDownload);
mg_connect_http(&download->mgr, Download::DownloadHandler, url.data(), NULL, NULL);
while (fDownload.downloading && !fDownload.download->TerminateThread)
while (fDownload.downloading && !fDownload.download->terminateThread)
{
mg_mgr_poll(&download->Mgr, 0);
mg_mgr_poll(&download->mgr, 0);
}
mg_mgr_free(&download->Mgr);
download->Valid = false;
mg_mgr_free(&download->mgr);
download->valid = false;
if (fDownload.buffer.size() != file.Size || Utils::String::DumpHex(Utils::Cryptography::SHA256::Compute(fDownload.buffer), "") != file.Hash)
if (fDownload.buffer.size() != file.size || Utils::String::DumpHex(Utils::Cryptography::SHA256::Compute(fDownload.buffer), "") != file.hash)
{
return false;
}
Utils::IO::CreateDirectory(download->Mod);
Utils::IO::CreateDirectory(download->mod);
Utils::IO::WriteFile(path, fDownload.buffer);
return true;
@ -171,15 +171,15 @@ namespace Components
{
if (!download) download = &Download::CLDownload;
std::string host = "http://" + download->Target.GetString();
std::string list = Utils::WebIO("IW4x", host + "/list").SetTimeout(5000)->Get();
std::string host = "http://" + download->target.getString();
std::string list = Utils::WebIO("IW4x", host + "/list").setTimeout(5000)->get();
if (list.empty())
{
if (download->TerminateThread) return;
if (download->terminateThread) return;
download->Thread.detach();
download->Clear();
download->thread.detach();
download->clear();
QuickPatch::Once([] ()
{
@ -189,14 +189,14 @@ namespace Components
return;
}
if (download->TerminateThread) return;
if (download->terminateThread) return;
if (!Download::ParseModList(download, list))
{
if (download->TerminateThread) return;
if (download->terminateThread) return;
download->Thread.detach();
download->Clear();
download->thread.detach();
download->clear();
QuickPatch::Once([] ()
{
@ -206,25 +206,25 @@ namespace Components
return;
}
if (download->TerminateThread) return;
if (download->terminateThread) return;
static std::string mod = download->Mod;
static std::string mod = download->mod;
for (unsigned int i = 0; i < download->Files.size(); ++i)
for (unsigned int i = 0; i < download->files.size(); ++i)
{
if (download->TerminateThread) return;
if (download->terminateThread) return;
if (!Download::DownloadFile(download, i))
{
if (download->TerminateThread) return;
if (download->terminateThread) return;
mod = fmt::sprintf("Failed to download file: %s!", download->Files[i].Name.data());
download->Thread.detach();
download->Clear();
mod = fmt::sprintf("Failed to download file: %s!", download->files[i].name.data());
download->thread.detach();
download->clear();
QuickPatch::Once([] ()
{
Dvar::Var("partyend_reason").Set(mod);
Dvar::Var("partyend_reason").set(mod);
mod.clear();
Localization::ClearTemp();
@ -236,24 +236,24 @@ namespace Components
}
}
if (download->TerminateThread) return;
if (download->terminateThread) return;
download->Thread.detach();
download->Clear();
download->thread.detach();
download->clear();
// Run this on the main thread
QuickPatch::Once([] ()
{
auto fsGame = Dvar::Var("fs_game");
fsGame.Set(mod);
fsGame.Get<Game::dvar_t*>()->modified = true;
fsGame.set(mod);
fsGame.get<Game::dvar_t*>()->modified = true;
mod.clear();
Localization::ClearTemp();
Command::Execute("closemenu mod_download_popmenu", true);
if (Dvar::Var("cl_modVidRestart").Get<bool>())
if (Dvar::Var("cl_modVidRestart").get<bool>())
{
Command::Execute("vid_restart", false);
}
@ -281,7 +281,7 @@ namespace Components
if (client->state >= 3)
{
if (address.GetIP().full == Network::Address(client->addr).GetIP().full)
if (address.getIP().full == Network::Address(client->addr).getIP().full)
{
return client;
}
@ -316,7 +316,7 @@ namespace Components
static std::string fsGamePre;
static json11::Json jsonList;
std::string fsGame = Dvar::Var("fs_game").Get<std::string>();
std::string fsGame = Dvar::Var("fs_game").get<std::string>();
if (!fsGame.empty() && fsGame != fsGamePre)
{
@ -324,7 +324,7 @@ namespace Components
fsGamePre = fsGame;
std::string path = Dvar::Var("fs_basepath").Get<std::string>() + "\\" + fsGame;
std::string path = Dvar::Var("fs_basepath").get<std::string>() + "\\" + fsGame;
auto list = FileSystem::GetSysFileList(path, "iwd", false);
list.push_back("mod.ff");
@ -384,8 +384,8 @@ namespace Components
return;
}
std::string fsGame = Dvar::Var("fs_game").Get<std::string>();
std::string path = Dvar::Var("fs_basepath").Get<std::string>() + "\\" + fsGame + "\\" + url;
std::string fsGame = Dvar::Var("fs_game").get<std::string>();
std::string path = Dvar::Var("fs_basepath").get<std::string>() + "\\" + fsGame + "\\" + url;
if (fsGame.empty() || !Utils::IO::FileExists(path))
{
@ -429,14 +429,14 @@ namespace Components
std::vector<json11::Json> players;
// Build player list
for (int i = 0; i < atoi(status.Get("sv_maxclients").data()); ++i) // Maybe choose 18 here?
for (int i = 0; i < atoi(status.get("sv_maxclients").data()); ++i) // Maybe choose 18 here?
{
std::map<std::string, json11::Json> playerInfo;
playerInfo["score"] = 0;
playerInfo["ping"] = 0;
playerInfo["name"] = "";
if (Dvar::Var("sv_running").Get<bool>())
if (Dvar::Var("sv_running").get<bool>())
{
if (Game::svs_clients[i].state < 3) continue;
@ -494,7 +494,7 @@ namespace Components
// }
// else
{
//std::string path = (Dvar::Var("fs_basepath").Get<std::string>() + "\\" BASEGAME "\\html");
//std::string path = (Dvar::Var("fs_basepath").get<std::string>() + "\\" BASEGAME "\\html");
//mg_serve_http_opts opts = { 0 };
//opts.document_root = path.data();
//mg_serve_http(nc, message, opts);
@ -511,7 +511,7 @@ namespace Components
{
file = FileSystem::File(url);
if (!file.Exists())
if (!file.exists())
{
url.append("/index.html");
file = FileSystem::File(url);
@ -520,9 +520,9 @@ namespace Components
std::string mimeType = Utils::GetMimeType(url);
if (file.Exists())
if (file.exists())
{
std::string buffer = file.GetBuffer();
std::string buffer = file.getBuffer();
mg_printf(nc,
"HTTP/1.1 200 OK\r\n"
@ -557,7 +557,7 @@ namespace Components
Network::OnStart([] ()
{
mg_connection* nc = mg_bind(&Download::Mgr, Utils::String::VA("%hu", (Dvar::Var("net_port").Get<int>() & 0xFFFF)), Download::EventHandler);
mg_connection* nc = mg_bind(&Download::Mgr, Utils::String::VA("%hu", (Dvar::Var("net_port").get<int>() & 0xFFFF)), Download::EventHandler);
// Handle special requests
mg_register_http_endpoint(nc, "/info", Download::InfoHandler);
@ -576,7 +576,7 @@ namespace Components
{
UIScript::Add("mod_download_cancel", [] ()
{
Download::CLDownload.Clear();
Download::CLDownload.clear();
});
}
}
@ -589,7 +589,7 @@ namespace Components
}
else
{
Download::CLDownload.Clear();
Download::CLDownload.clear();
}
}
}

View File

@ -7,7 +7,7 @@ namespace Components
~Download();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "Download"; };
const char* getName() { return "Download"; };
#endif
static void InitiateClientDownload(std::string mod);
@ -16,50 +16,50 @@ namespace Components
class ClientDownload
{
public:
ClientDownload() : Valid(false), Running(false), TerminateThread(false), TotalBytes(0), DownBytes(0), LastTimeStamp(0), TimeStampBytes(0) {}
~ClientDownload() { this->Clear(); }
ClientDownload() : valid(false), running(false), terminateThread(false), totalBytes(0), downBytes(0), lastTimeStamp(0), timeStampBytes(0) {}
~ClientDownload() { this->clear(); }
bool Running;
bool Valid;
bool TerminateThread;
mg_mgr Mgr;
Network::Address Target;
std::string Mod;
std::thread Thread;
bool running;
bool valid;
bool terminateThread;
mg_mgr mgr;
Network::Address target;
std::string mod;
std::thread thread;
size_t TotalBytes;
size_t DownBytes;
size_t totalBytes;
size_t downBytes;
int LastTimeStamp;
size_t TimeStampBytes;
int lastTimeStamp;
size_t timeStampBytes;
class File
{
public:
std::string Name;
std::string Hash;
size_t Size;
std::string name;
std::string hash;
size_t size;
};
std::vector<File> Files;
std::vector<File> files;
void Clear()
void clear()
{
this->TerminateThread = true;
this->terminateThread = true;
if (this->Thread.joinable())
if (this->thread.joinable())
{
this->Thread.join();
this->thread.join();
}
this->Running = false;
this->Mod.clear();
this->Files.clear();
this->running = false;
this->mod.clear();
this->files.clear();
if (this->Valid)
if (this->valid)
{
this->Valid = false;
mg_mgr_free(&(this->Mgr));
this->valid = false;
mg_mgr_free(&(this->mgr));
}
}
};
@ -75,8 +75,6 @@ namespace Components
unsigned int index;
std::string buffer;
size_t receivedBytes;
};
static mg_mgr Mgr;

View File

@ -16,11 +16,11 @@ namespace Components
}
}
template <> Game::dvar_t* Dvar::Var::Get()
template <> Game::dvar_t* Dvar::Var::get()
{
return this->dvar;
}
template <> char* Dvar::Var::Get()
template <> char* Dvar::Var::get()
{
if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_STRING && this->dvar->current.string)
{
@ -29,11 +29,11 @@ namespace Components
return "";
}
template <> const char* Dvar::Var::Get()
template <> const char* Dvar::Var::get()
{
return this->Get<char*>();
return this->get<char*>();
}
template <> int Dvar::Var::Get()
template <> int Dvar::Var::get()
{
if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_INT)
{
@ -42,11 +42,11 @@ namespace Components
return 0;
}
template <> unsigned int Dvar::Var::Get()
template <> unsigned int Dvar::Var::get()
{
return static_cast<unsigned int>(this->Get<int>());
return static_cast<unsigned int>(this->get<int>());
}
template <> float Dvar::Var::Get()
template <> float Dvar::Var::get()
{
if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT)
{
@ -55,7 +55,7 @@ namespace Components
return 0;
}
template <> float* Dvar::Var::Get()
template <> float* Dvar::Var::get()
{
static float val[4] = { 0 };
@ -66,7 +66,7 @@ namespace Components
return val;
}
template <> bool Dvar::Var::Get()
template <> bool Dvar::Var::get()
{
if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_BOOL)
{
@ -75,34 +75,34 @@ namespace Components
return false;
}
template <> std::string Dvar::Var::Get()
template <> std::string Dvar::Var::get()
{
return this->Get<const char*>();
return this->get<const char*>();
}
void Dvar::Var::Set(char* string)
void Dvar::Var::set(char* string)
{
this->Set(const_cast<const char*>(string));
this->set(const_cast<const char*>(string));
}
void Dvar::Var::Set(const char* string)
void Dvar::Var::set(const char* string)
{
if (this->dvar && this->dvar->name)
{
Game::Dvar_SetCommand(this->dvar->name, string);
}
}
void Dvar::Var::Set(std::string string)
void Dvar::Var::set(std::string string)
{
this->Set(string.data());
this->set(string.data());
}
void Dvar::Var::Set(int integer)
void Dvar::Var::set(int integer)
{
if (this->dvar && this->dvar->name)
{
Game::Dvar_SetCommand(this->dvar->name, Utils::String::VA("%i", integer));
}
}
void Dvar::Var::Set(float value)
void Dvar::Var::set(float value)
{
if (this->dvar && this->dvar->name)
{
@ -110,7 +110,7 @@ namespace Components
}
}
void Dvar::Var::SetRaw(int integer)
void Dvar::Var::setRaw(int integer)
{
if (this->dvar)
{
@ -145,7 +145,7 @@ namespace Components
Renderer::OnFrame([] ()
{
static std::string lastValidName = "Unknown Soldier";
std::string name = Dvar::Var("name").Get<char*>();
std::string name = Dvar::Var("name").get<char*>();
// Don't perform any checks if name didn't change
if (name == lastValidName) return;
@ -154,7 +154,7 @@ namespace Components
if (saneName.size() < 3 || (saneName[0] == '[' && saneName[1] == '{'))
{
Logger::Print("Username '%s' is invalid. It must at least be 3 characters long and not appear empty!\n", name.data());
Dvar::Var("name").Set(lastValidName);
Dvar::Var("name").set(lastValidName);
}
else
{
@ -162,7 +162,7 @@ namespace Components
}
});
return Dvar::Register<const char*>(name, "Unknown Soldier", Dvar::Flag(flag | Game::dvar_flag::DVAR_FLAG_SAVED).val, description).Get<Game::dvar_t*>();
return Dvar::Register<const char*>(name, "Unknown Soldier", Dvar::Flag(flag | Game::dvar_flag::DVAR_FLAG_SAVED).val, description).get<Game::dvar_t*>();
}
Dvar::Dvar()
@ -197,7 +197,7 @@ namespace Components
Utils::Hook::Xor<BYTE>(0x6312DE, Game::dvar_flag::DVAR_FLAG_CHEAT);
// Hook dvar 'name' registration
Utils::Hook(0x40531C, Dvar::RegisterName, HOOK_CALL).Install()->Quick();
Utils::Hook(0x40531C, Dvar::RegisterName, HOOK_CALL).install()->quick();
}
Dvar::~Dvar()

View File

@ -9,7 +9,7 @@ namespace Components
{
public:
Flag(Game::dvar_flag flag) : val(flag){};
Flag(int flag) : Flag((Game::dvar_flag)flag) {};
Flag(int flag) : Flag(static_cast<Game::dvar_flag>(flag)) {};
Game::dvar_flag val;
};
@ -21,19 +21,18 @@ namespace Components
Var(const Var &obj) { this->dvar = obj.dvar; };
Var(Game::dvar_t* _dvar) : dvar(_dvar) {};
Var(std::string dvarName);
Var(std::string dvarName, std::string value);
template<typename T> T Get();
template<typename T> T get();
void Set(char* string);
void Set(const char* string);
void Set(std::string string);
void set(char* string);
void set(const char* string);
void set(std::string string);
void Set(int integer);
void Set(float value);
void set(int integer);
void set(float value);
// TODO: Add others
void SetRaw(int integer);
void setRaw(int integer);
private:
Game::dvar_t* dvar;
@ -43,7 +42,7 @@ namespace Components
~Dvar();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "Dvar"; };
const char* getName() { return "Dvar"; };
#endif
static void OnInit(Callback* callback);

View File

@ -57,9 +57,9 @@ namespace Components
LPTOP_LEVEL_EXCEPTION_FILTER WINAPI Exception::SetUnhandledExceptionFilterStub(LPTOP_LEVEL_EXCEPTION_FILTER)
{
Exception::SetFilterHook.Uninstall();
Exception::SetFilterHook.uninstall();
LPTOP_LEVEL_EXCEPTION_FILTER retval = SetUnhandledExceptionFilter(&Exception::ExceptionFilter);
Exception::SetFilterHook.Install();
Exception::SetFilterHook.install();
return retval;
}
@ -89,20 +89,20 @@ namespace Components
});
#endif
#if !defined(DEBUG) || defined(FORCE_EXCEPTION_HANDLER)
Exception::SetFilterHook.Initialize(SetUnhandledExceptionFilter, Exception::SetUnhandledExceptionFilterStub, HOOK_JUMP);
Exception::SetFilterHook.Install();
Exception::SetFilterHook.initialize(SetUnhandledExceptionFilter, Exception::SetUnhandledExceptionFilterStub, HOOK_JUMP);
Exception::SetFilterHook.install();
SetUnhandledExceptionFilter(&Exception::ExceptionFilter);
#endif
//Utils::Hook(0x4B241F, Exception::ErrorLongJmp, HOOK_CALL).Install()->Quick();
//Utils::Hook(0x4B241F, Exception::ErrorLongJmp, HOOK_CALL).install()->quick();
Command::Add("mapTest", [](Command::Params params)
{
Game::UI_UpdateArenas();
std::string command;
for (int i = 0; i < (params.Length() >= 2 ? atoi(params[1]) : *Game::arenaCount); ++i)
for (int i = 0; i < (params.length() >= 2 ? atoi(params[1]) : *Game::arenaCount); ++i)
{
char* mapname = ArenaLength::NewArenas[i % *Game::arenaCount].mapName;
@ -171,6 +171,6 @@ namespace Components
Exception::~Exception()
{
Exception::SetFilterHook.Uninstall();
Exception::SetFilterHook.uninstall();
}
}

View File

@ -9,7 +9,7 @@ namespace Components
~Exception();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "Exception"; };
const char* getName() { return "Exception"; };
#endif
static LPTOP_LEVEL_EXCEPTION_FILTER Hook();

View File

@ -219,10 +219,10 @@ namespace Components
const char* FastFiles::GetZoneLocation(const char* file)
{
const char* dir = Dvar::Var("fs_basepath").Get<const char*>();
const char* dir = Dvar::Var("fs_basepath").get<const char*>();
std::vector<std::string> paths;
std::string modDir = Dvar::Var("fs_game").Get<std::string>();
std::string modDir = Dvar::Var("fs_game").get<std::string>();
if (file == "mod"s || file == "mod.ff"s || !modDir.empty())
{
paths.push_back(fmt::sprintf("zone\\%s\\", modDir.data()));
@ -366,17 +366,17 @@ namespace Components
Dvar::Register<bool>("ui_zoneDebug", false, Game::dvar_flag::DVAR_FLAG_SAVED, "Display current loaded zone.");
// Redirect zone paths
Utils::Hook(0x44DA90, FastFiles::GetZoneLocation, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x44DA90, FastFiles::GetZoneLocation, HOOK_JUMP).install()->quick();
// Allow loading 'newer' zones
Utils::Hook(0x4158E7, FastFiles::ReadVersionStub, HOOK_CALL).Install()->Quick();
Utils::Hook(0x4158E7, FastFiles::ReadVersionStub, HOOK_CALL).install()->quick();
// Allow custom zone loading
if (!ZoneBuilder::IsEnabled())
{
Utils::Hook(0x506BC7, FastFiles::LoadInitialZones, HOOK_CALL).Install()->Quick();
Utils::Hook(0x60B4AC, FastFiles::LoadDLCUIZones, HOOK_CALL).Install()->Quick();
Utils::Hook(0x506B25, FastFiles::LoadGfxZones, HOOK_CALL).Install()->Quick();
Utils::Hook(0x506BC7, FastFiles::LoadInitialZones, HOOK_CALL).install()->quick();
Utils::Hook(0x60B4AC, FastFiles::LoadDLCUIZones, HOOK_CALL).install()->quick();
Utils::Hook(0x506B25, FastFiles::LoadGfxZones, HOOK_CALL).install()->quick();
}
// basic checks (hash jumps, both normal and playlist)
@ -402,17 +402,17 @@ namespace Components
Utils::Hook::Set<DWORD>(0x5BA603, 1);
// Initialize crypto
Utils::Hook(0x4D02F0, FastFiles::AuthLoadInitCrypto, HOOK_CALL).Install()->Quick();
Utils::Hook(0x4D02F0, FastFiles::AuthLoadInitCrypto, HOOK_CALL).install()->quick();
// Initial stage decryption
Utils::Hook(0x4D0306, FastFiles::InflateInitDecrypt, HOOK_CALL).Install()->Quick();
Utils::Hook(0x4D0306, FastFiles::InflateInitDecrypt, HOOK_CALL).install()->quick();
// Hash bit decryption
Utils::Hook(0x5B9958, FastFiles::AuthLoadInflateCompare, HOOK_CALL).Install()->Quick();
Utils::Hook(0x5B9912, FastFiles::AuthLoadInflateCompare, HOOK_CALL).Install()->Quick();
Utils::Hook(0x5B9958, FastFiles::AuthLoadInflateCompare, HOOK_CALL).install()->quick();
Utils::Hook(0x5B9912, FastFiles::AuthLoadInflateCompare, HOOK_CALL).install()->quick();
// General read
Utils::Hook(0x5B98E4, FastFiles::AuthLoadInflateDecryptBase, HOOK_CALL).Install()->Quick();
Utils::Hook(0x5B98E4, FastFiles::AuthLoadInflateDecryptBase, HOOK_CALL).install()->quick();
// Add custom zone paths
FastFiles::AddZonePath("zone\\patch\\");
@ -420,7 +420,7 @@ namespace Components
Renderer::OnFrame([] ()
{
if (FastFiles::Current().empty() || !Dvar::Var("ui_zoneDebug").Get<bool>()) return;
if (FastFiles::Current().empty() || !Dvar::Var("ui_zoneDebug").get<bool>()) return;
Game::Font* font = Game::R_RegisterFont("fonts/consoleFont"); // Inlining that seems to skip xpos, no idea why xD
float color[4] = { 1.0f, 1.0f, 1.0f, (Game::CL_IsCgameInitialized() ? 0.3f : 1.0f) };
@ -429,7 +429,7 @@ namespace Components
Command::Add("loadzone", [] (Command::Params params)
{
if (params.Length() < 2) return;
if (params.length() < 2) return;
Game::XZoneInfo info;
info.name = params[1];

View File

@ -7,7 +7,7 @@ namespace Components
~FastFiles();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "FastFiles"; };
const char* getName() { return "FastFiles"; };
#endif
static void AddZonePath(std::string path);

View File

@ -5,72 +5,72 @@ namespace Components
std::mutex FileSystem::Mutex;
Utils::Memory::Allocator FileSystem::MemAllocator;
void FileSystem::File::Read()
void FileSystem::File::read()
{
char* buffer = nullptr;
int size = Game::FS_ReadFile(this->FilePath.data(), &buffer);
char* _buffer = nullptr;
int size = Game::FS_ReadFile(this->filePath.data(), &_buffer);
this->Buffer.clear();
this->buffer.clear();
if (size >= 0)
{
this->Buffer.append(buffer, size);
Game::FS_FreeFile(buffer);
this->buffer.append(_buffer, size);
Game::FS_FreeFile(_buffer);
}
}
FileSystem::FileReader::FileReader(std::string file) : Name(file), Handle(0)
FileSystem::FileReader::FileReader(std::string file) : name(file), handle(0)
{
this->Size = Game::FS_FOpenFileReadCurrentThread(this->Name.data(), &this->Handle);
this->size = Game::FS_FOpenFileReadCurrentThread(this->name.data(), &this->handle);
}
FileSystem::FileReader::~FileReader()
{
if (this->Exists() && this->Handle)
if (this->exists() && this->handle)
{
Game::FS_FCloseFile(this->Handle);
Game::FS_FCloseFile(this->handle);
}
}
bool FileSystem::FileReader::Exists()
bool FileSystem::FileReader::exists()
{
return (this->Size >= 0 && this->Handle);
return (this->size >= 0 && this->handle);
}
std::string FileSystem::FileReader::GetName()
std::string FileSystem::FileReader::getName()
{
return this->Name;
return this->name;
}
int FileSystem::FileReader::GetSize()
int FileSystem::FileReader::getSize()
{
return this->Size;
return this->size;
}
std::string FileSystem::FileReader::GetBuffer()
std::string FileSystem::FileReader::getBuffer()
{
Utils::Memory::Allocator allocator;
if (!this->Exists()) return std::string();
if (!this->exists()) return std::string();
int position = Game::FS_FTell(this->Handle);
this->Seek(0, FS_SEEK_SET);
int position = Game::FS_FTell(this->handle);
this->seek(0, FS_SEEK_SET);
char* buffer = allocator.AllocateArray<char>(this->Size);
if (!this->Read(buffer, this->Size))
char* buffer = allocator.allocateArray<char>(this->size);
if (!this->read(buffer, this->size))
{
this->Seek(position, FS_SEEK_SET);
this->seek(position, FS_SEEK_SET);
return std::string();
}
this->Seek(position, FS_SEEK_SET);
this->seek(position, FS_SEEK_SET);
return std::string(buffer, this->Size);
return std::string(buffer, this->size);
}
bool FileSystem::FileReader::Read(void* buffer, size_t size)
bool FileSystem::FileReader::read(void* buffer, size_t _size)
{
if (!this->Exists() || static_cast<size_t>(this->Size) < size || Game::FS_Read(buffer, size, this->Handle) != static_cast<int>(size))
if (!this->exists() || static_cast<size_t>(this->size) < _size || Game::FS_Read(buffer, _size, this->handle) != static_cast<int>(_size))
{
return false;
}
@ -78,32 +78,33 @@ namespace Components
return true;
}
void FileSystem::FileReader::Seek(int offset, int origin)
void FileSystem::FileReader::seek(int offset, int origin)
{
if (this->Exists())
if (this->exists())
{
Game::FS_Seek(this->Handle, offset, origin);
Game::FS_Seek(this->handle, offset, origin);
}
}
void FileSystem::FileWriter::Write(std::string data)
void FileSystem::FileWriter::write(std::string data)
{
if (this->Handle)
if (this->handle)
{
Game::FS_Write(data.data(), data.size(), this->Handle);
Game::FS_Write(data.data(), data.size(), this->handle);
}
}
void FileSystem::FileWriter::Open()
void FileSystem::FileWriter::open()
{
this->Handle = Game::FS_FOpenFileWrite(this->FilePath.data());
this->handle = Game::FS_FOpenFileWrite(this->filePath.data());
}
void FileSystem::FileWriter::Close()
void FileSystem::FileWriter::close()
{
if (this->Handle)
if (this->handle)
{
Game::FS_FCloseFile(this->Handle);
Game::FS_FCloseFile(this->handle);
this->handle = 0;
}
}
@ -156,7 +157,7 @@ namespace Components
void FileSystem::DeleteFile(std::string folder, std::string file)
{
char path[MAX_PATH] = { 0 };
Game::FS_BuildPathToFile(Dvar::Var("fs_basepath").Get<const char*>(), reinterpret_cast<char*>(0x63D0BB8), Utils::String::VA("%s/%s", folder.data(), file.data()), reinterpret_cast<char**>(&path));
Game::FS_BuildPathToFile(Dvar::Var("fs_basepath").get<const char*>(), reinterpret_cast<char*>(0x63D0BB8), Utils::String::VA("%s/%s", folder.data(), file.data()), reinterpret_cast<char**>(&path));
Game::FS_Remove(path);
}
@ -169,11 +170,11 @@ namespace Components
std::lock_guard<std::mutex> _(FileSystem::Mutex);
FileSystem::FileReader reader(path);
int size = reader.GetSize();
if (reader.Exists() && size >= 0)
int size = reader.getSize();
if (reader.exists() && size >= 0)
{
*buffer = FileSystem::AllocateFile(size + 1);
if (reader.Read(*buffer, size)) return size;
if (reader.read(*buffer, size)) return size;
FileSystem::FreeFile(*buffer);
*buffer = nullptr;
@ -184,19 +185,19 @@ namespace Components
char* FileSystem::AllocateFile(int size)
{
return FileSystem::MemAllocator.AllocateArray<char>(size);
return FileSystem::MemAllocator.allocateArray<char>(size);
}
void FileSystem::FreeFile(void* buffer)
{
FileSystem::MemAllocator.Free(buffer);
FileSystem::MemAllocator.free(buffer);
}
void FileSystem::RegisterFolder(const char* folder)
{
std::string fs_cdpath = Dvar::Var("fs_cdpath").Get<std::string>();
std::string fs_basepath = Dvar::Var("fs_basepath").Get<std::string>();
std::string fs_homepath = Dvar::Var("fs_homepath").Get<std::string>();
std::string fs_cdpath = Dvar::Var("fs_cdpath").get<std::string>();
std::string fs_basepath = Dvar::Var("fs_basepath").get<std::string>();
std::string fs_homepath = Dvar::Var("fs_homepath").get<std::string>();
if (!fs_cdpath.empty()) Game::FS_AddLocalizedGameDirectory(fs_cdpath.data(), folder);
if (!fs_basepath.empty()) Game::FS_AddLocalizedGameDirectory(fs_basepath.data(), folder);
@ -232,23 +233,23 @@ namespace Components
int FileSystem::ExecIsFSStub(const char* execFilename)
{
return !File(execFilename).Exists();
return !File(execFilename).exists();
}
FileSystem::FileSystem()
{
FileSystem::MemAllocator.Clear();
FileSystem::MemAllocator.clear();
// Thread safe file system interaction
Utils::Hook(0x4F4BFF, FileSystem::AllocateFile, HOOK_CALL).Install()->Quick();
//Utils::Hook(Game::FS_ReadFile, FileSystem::ReadFile, HOOK_JUMP).Install()->Quick();
Utils::Hook(Game::FS_FreeFile, FileSystem::FreeFile, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x4F4BFF, FileSystem::AllocateFile, HOOK_CALL).install()->quick();
//Utils::Hook(Game::FS_ReadFile, FileSystem::ReadFile, HOOK_JUMP).install()->quick();
Utils::Hook(Game::FS_FreeFile, FileSystem::FreeFile, HOOK_JUMP).install()->quick();
// Filesystem config checks
Utils::Hook(0x6098FD, FileSystem::ExecIsFSStub, HOOK_CALL).Install()->Quick();
Utils::Hook(0x6098FD, FileSystem::ExecIsFSStub, HOOK_CALL).install()->quick();
// Register additional folders
Utils::Hook(0x482647, FileSystem::StartupStub, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x482647, FileSystem::StartupStub, HOOK_JUMP).install()->quick();
// exec whitelist removal (YAYFINITY WARD)
Utils::Hook::Nop(0x609685, 5);
@ -263,6 +264,6 @@ namespace Components
FileSystem::~FileSystem()
{
assert(FileSystem::MemAllocator.Empty());
assert(FileSystem::MemAllocator.empty());
}
}

View File

@ -8,60 +8,60 @@ namespace Components
{
public:
File() {};
File(std::string file) : FilePath(file) { this->Read(); };
File(std::string file) : filePath(file) { this->read(); };
bool Exists() { return !this->Buffer.empty(); };
std::string GetName() { return this->FilePath; };
std::string& GetBuffer() { return this->Buffer; };
bool exists() { return !this->buffer.empty(); };
std::string getName() { return this->filePath; };
std::string& getBuffer() { return this->buffer; };
private:
std::string FilePath;
std::string Buffer;
std::string filePath;
std::string buffer;
void Read();
void read();
};
class FileReader
{
public:
FileReader() : Size(-1), Name(), Handle(0) {};
FileReader() : size(-1), name(), handle(0) {};
FileReader(std::string file);
~FileReader();
bool Exists();
std::string GetName();
std::string GetBuffer();
int GetSize();
bool Read(void* buffer, size_t size);
void Seek(int offset, int origin);
bool exists();
std::string getName();
std::string getBuffer();
int getSize();
bool read(void* buffer, size_t size);
void seek(int offset, int origin);
private:
int Handle;
int Size;
std::string Name;
int handle;
int size;
std::string name;
};
class FileWriter
{
public:
FileWriter(std::string file) : FilePath(file), Handle(0) { this->Open(); };
~FileWriter() { this->Close(); };
FileWriter(std::string file) : filePath(file), handle(0) { this->open(); };
~FileWriter() { this->close(); };
void Write(std::string data);
void write(std::string data);
private:
int Handle;
std::string FilePath;
int handle;
std::string filePath;
void Open();
void Close();
void open();
void close();
};
FileSystem();
~FileSystem();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "FileSystem"; };
const char* getName() { return "FileSystem"; };
#endif
static std::vector<std::string> GetFileList(std::string path, std::string extension);

View File

@ -7,7 +7,7 @@ namespace Components
~Flags();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "Flags"; };
const char* getName() { return "Flags"; };
#endif
static bool HasFlag(std::string flag);

View File

@ -24,8 +24,8 @@ namespace Components
std::string gametype = Game::gameTypes[index].gameType;
Dvar::Var("ui_gametype").Set(gametype);
//Dvar::Var("g_gametype").Set(gametype);
Dvar::Var("ui_gametype").set(gametype);
//Dvar::Var("g_gametype").set(gametype);
}
void* Gametypes::BuildGametypeList(const char*, void* buffer, size_t size)
@ -96,8 +96,8 @@ namespace Components
UIFeeder::Add(29.0f, Gametypes::GetGametypeCount, Gametypes::GetGametypeText, Gametypes::SelectGametype);
// Dynamically grab gametypes
Utils::Hook(0x5FA46C, Gametypes::BuildGametypeList, HOOK_CALL).Install()->Quick(); // Scr_UpdateGameTypeList
Utils::Hook(0x632155, Gametypes::BuildGametypeList, HOOK_CALL).Install()->Quick(); // UI_UpdateGameTypesList
Utils::Hook(0x5FA46C, Gametypes::BuildGametypeList, HOOK_CALL).install()->quick(); // Scr_UpdateGameTypeList
Utils::Hook(0x632155, Gametypes::BuildGametypeList, HOOK_CALL).install()->quick(); // UI_UpdateGameTypesList
// This is placed here in case the anticheat has been disabled!
// Make sure this is called after every onther anticheat check!
@ -106,7 +106,7 @@ namespace Components
{
AntiCheat::FlagIntegrityCheck();
return Utils::Hook::Call<void()>(0x50AB20)();
}, HOOK_CALL).Install()->Quick();
}, HOOK_CALL).install()->quick();
#endif
}
}

View File

@ -6,7 +6,7 @@ namespace Components
Gametypes();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "Gametypes"; };
const char* getName() { return "Gametypes"; };
#endif
private:

View File

@ -2,71 +2,71 @@
namespace Components
{
Pipe* IPCPipe::ServerPipe = 0;
Pipe* IPCPipe::ClientPipe = 0;
Pipe IPCPipe::ServerPipe;
Pipe IPCPipe::ClientPipe;
#pragma region Pipe
Pipe::Pipe() : mType(IPCTYPE_NONE), ReconnectAttempt(0), hPipe(INVALID_HANDLE_VALUE), ConnectCallback(0), mThreadAttached(false)
Pipe::Pipe() : type(IPCTYPE_NONE), reconnectAttempt(0), pipe(INVALID_HANDLE_VALUE), connectCallback(0), threadAttached(false)
{
this->Destroy();
this->destroy();
}
Pipe::~Pipe()
{
this->Destroy();
this->destroy();
}
bool Pipe::Connect(std::string name)
bool Pipe::connect(std::string name)
{
this->Destroy();
this->destroy();
this->mType = IPCTYPE_CLIENT;
this->SetName(name);
this->type = IPCTYPE_CLIENT;
this->setName(name);
this->hPipe = CreateFileA(this->PipeFile, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
this->pipe = CreateFileA(this->pipeFile, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (INVALID_HANDLE_VALUE == this->hPipe)
if (INVALID_HANDLE_VALUE == this->pipe)
{
Logger::Print("Failed to connect to the pipe\n");
if (this->ReconnectAttempt < IPC_MAX_RECONNECTS)
if (this->reconnectAttempt < IPC_MAX_RECONNECTS)
{
Logger::Print("Attempting to reconnect to the pipe.\n");
++this->ReconnectAttempt;
++this->reconnectAttempt;
std::this_thread::sleep_for(500ms);
return this->Connect(name);
return this->connect(name);
}
else
{
this->Destroy();
this->destroy();
return false;
}
}
this->ReconnectAttempt = 0;
this->reconnectAttempt = 0;
Logger::Print("Successfully connected to the pipe\n");
return true;
}
bool Pipe::Create(std::string name)
bool Pipe::create(std::string name)
{
this->Destroy();
this->destroy();
this->mType = IPCTYPE_SERVER;
this->SetName(name);
this->type = IPCTYPE_SERVER;
this->setName(name);
this->hPipe = CreateNamedPipeA(this->PipeFile, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, sizeof(this->mPacket), sizeof(this->mPacket), NMPWAIT_USE_DEFAULT_WAIT, NULL);
this->pipe = CreateNamedPipeA(this->pipeFile, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, sizeof(this->packet), sizeof(this->packet), NMPWAIT_USE_DEFAULT_WAIT, NULL);
if (INVALID_HANDLE_VALUE != this->hPipe)
if (INVALID_HANDLE_VALUE != this->pipe && this->pipe)
{
// Only create the thread, when not performing unit tests!
if (!Loader::PerformingUnitTests())
{
this->mThreadAttached = true;
this->mThread = std::thread(Pipe::ReceiveThread, this);
this->threadAttached = true;
this->thread = std::thread(Pipe::ReceiveThread, this);
}
Logger::Print("Pipe successfully created\n");
@ -74,104 +74,104 @@ namespace Components
}
Logger::Print("Failed to create the pipe\n");
this->Destroy();
this->destroy();
return false;
}
void Pipe::OnConnect(Pipe::Callback callback)
void Pipe::onConnect(Pipe::Callback callback)
{
this->ConnectCallback = callback;
this->connectCallback = callback;
}
void Pipe::SetCallback(std::string command, Pipe::PacketCallback callback)
void Pipe::setCallback(std::string command, Pipe::PacketCallback callback)
{
this->PacketCallbacks[command] = callback;
this->packetCallbacks[command] = callback;
}
bool Pipe::Write(std::string command, std::string data)
bool Pipe::write(std::string command, std::string data)
{
if (this->mType != IPCTYPE_CLIENT || this->hPipe == INVALID_HANDLE_VALUE) return false;
if (this->type != IPCTYPE_CLIENT || this->pipe == INVALID_HANDLE_VALUE) return false;
Pipe::Packet packet;
strcpy_s(packet.Command, command.data());
strcpy_s(packet.Buffer, data.data());
Pipe::Packet _packet;
strcpy_s(_packet.command, command.data());
strcpy_s(_packet.buffer, data.data());
DWORD cbBytes;
return (WriteFile(this->hPipe, &packet, sizeof(packet), &cbBytes, NULL) || GetLastError() == ERROR_IO_PENDING);
return (WriteFile(this->pipe, &_packet, sizeof(_packet), &cbBytes, NULL) || GetLastError() == ERROR_IO_PENDING);
}
void Pipe::Destroy()
void Pipe::destroy()
{
//this->Type = IPCTYPE_NONE;
//*this->PipeFile = 0;
//*this->PipeName = 0;
if (this->hPipe && INVALID_HANDLE_VALUE != this->hPipe)
if (this->pipe && INVALID_HANDLE_VALUE != this->pipe)
{
if (this->mType == IPCTYPE_SERVER) DisconnectNamedPipe(this->hPipe);
if (this->type == IPCTYPE_SERVER) DisconnectNamedPipe(this->pipe);
CloseHandle(this->hPipe);
CloseHandle(this->pipe);
Logger::Print("Disconnected from the pipe.\n");
}
this->mThreadAttached = false;
this->threadAttached = false;
if (this->mThread.joinable())
if (this->thread.joinable())
{
Logger::Print("Terminating pipe thread...\n");
this->mThread.join();
this->thread.join();
Logger::Print("Pipe thread terminated.\n");
}
}
void Pipe::SetName(std::string name)
void Pipe::setName(std::string name)
{
memset(this->PipeName, 0, sizeof(this->PipeName));
memset(this->PipeFile, 0, sizeof(this->PipeFile));
memset(this->pipeName, 0, sizeof(this->pipeName));
memset(this->pipeFile, 0, sizeof(this->pipeFile));
strncpy_s(this->PipeName, name.data(), sizeof(this->PipeName));
sprintf_s(this->PipeFile, sizeof(this->PipeFile), "\\\\.\\Pipe\\%s", this->PipeName);
strncpy_s(this->pipeName, name.data(), sizeof(this->pipeName));
sprintf_s(this->pipeFile, sizeof(this->pipeFile), "\\\\.\\Pipe\\%s", this->pipeName);
}
void Pipe::ReceiveThread(Pipe* pipe)
{
if (!pipe || pipe->mType != IPCTYPE_SERVER || pipe->hPipe == INVALID_HANDLE_VALUE || !pipe->hPipe) return;
if (!pipe || pipe->type != IPCTYPE_SERVER || pipe->pipe == INVALID_HANDLE_VALUE || !pipe->pipe) return;
if (ConnectNamedPipe(pipe->hPipe, NULL) == FALSE)
if (ConnectNamedPipe(pipe->pipe, NULL) == FALSE)
{
Logger::Print("Failed to initialize pipe reading.\n");
return;
}
Logger::Print("Client connected to the pipe\n");
if (pipe->ConnectCallback) pipe->ConnectCallback();
pipe->connectCallback();
DWORD cbBytes;
while (pipe->mThreadAttached && pipe->hPipe && pipe->hPipe != INVALID_HANDLE_VALUE)
while (pipe->threadAttached && pipe->pipe && pipe->pipe != INVALID_HANDLE_VALUE)
{
BOOL bResult = ReadFile(pipe->hPipe, &pipe->mPacket, sizeof(pipe->mPacket), &cbBytes, NULL);
BOOL bResult = ReadFile(pipe->pipe, &pipe->packet, sizeof(pipe->packet), &cbBytes, NULL);
if (bResult && cbBytes)
{
if (pipe->PacketCallbacks.find(pipe->mPacket.Command) != pipe->PacketCallbacks.end())
if (pipe->packetCallbacks.find(pipe->packet.command) != pipe->packetCallbacks.end())
{
pipe->PacketCallbacks[pipe->mPacket.Command](pipe->mPacket.Buffer);
pipe->packetCallbacks[pipe->packet.command](pipe->packet.buffer);
}
}
else if (pipe->mThreadAttached && pipe->hPipe != INVALID_HANDLE_VALUE)
else if (pipe->threadAttached && pipe->pipe != INVALID_HANDLE_VALUE)
{
Logger::Print("Failed to read from client through pipe\n");
DisconnectNamedPipe(pipe->hPipe);
ConnectNamedPipe(pipe->hPipe, NULL);
if (pipe->ConnectCallback) pipe->ConnectCallback();
DisconnectNamedPipe(pipe->pipe);
ConnectNamedPipe(pipe->pipe, NULL);
pipe->connectCallback();
}
ZeroMemory(&pipe->mPacket, sizeof(pipe->mPacket));
ZeroMemory(&pipe->packet, sizeof(pipe->packet));
}
}
@ -180,30 +180,22 @@ namespace Components
// Callback to connect first instance's client pipe to the second instance's server pipe
void IPCPipe::ConnectClient()
{
if (Singleton::IsFirstInstance() && IPCPipe::ClientPipe)
if (Singleton::IsFirstInstance())
{
IPCPipe::ClientPipe->Connect(IPC_PIPE_NAME_CLIENT);
IPCPipe::ClientPipe.connect(IPC_PIPE_NAME_CLIENT);
}
}
// Writes to the process on the other end of the pipe
bool IPCPipe::Write(std::string command, std::string data)
{
if (IPCPipe::ClientPipe)
{
return IPCPipe::ClientPipe->Write(command, data);
}
return false;
return IPCPipe::ClientPipe.write(command, data);
}
// Installs a callback for receiving commands from the process on the other end of the pipe
void IPCPipe::On(std::string command, Pipe::PacketCallback callback)
{
if (IPCPipe::ServerPipe)
{
IPCPipe::ServerPipe->SetCallback(command, callback);
}
IPCPipe::ServerPipe.setCallback(command, callback);
}
IPCPipe::IPCPipe()
@ -211,17 +203,13 @@ namespace Components
if (Dedicated::IsEnabled()) return;
// Server pipe
IPCPipe::ServerPipe = new Pipe();
IPCPipe::ServerPipe->OnConnect(IPCPipe::ConnectClient);
IPCPipe::ServerPipe->Create((Singleton::IsFirstInstance() ? IPC_PIPE_NAME_SERVER : IPC_PIPE_NAME_CLIENT));
// Client pipe
IPCPipe::ClientPipe = new Pipe();
IPCPipe::ServerPipe.onConnect(IPCPipe::ConnectClient);
IPCPipe::ServerPipe.create((Singleton::IsFirstInstance() ? IPC_PIPE_NAME_SERVER : IPC_PIPE_NAME_CLIENT));
// Connect second instance's client pipe to first instance's server pipe
if (!Singleton::IsFirstInstance())
{
IPCPipe::ClientPipe->Connect(IPC_PIPE_NAME_SERVER);
IPCPipe::ClientPipe.connect(IPC_PIPE_NAME_SERVER);
}
IPCPipe::On("ping", [] (std::string data)
@ -242,13 +230,4 @@ namespace Components
IPCPipe::Write("ping", "");
});
}
IPCPipe::~IPCPipe()
{
if (IPCPipe::ServerPipe) delete IPCPipe::ServerPipe;
if (IPCPipe::ClientPipe) delete IPCPipe::ClientPipe;
IPCPipe::ServerPipe = nullptr;
IPCPipe::ClientPipe = nullptr;
}
}

View File

@ -12,8 +12,8 @@ namespace Components
public:
struct Packet
{
char Command[IPC_COMMAND_SIZE];
char Buffer[IPC_BUFFER_SIZE];
char command[IPC_COMMAND_SIZE];
char buffer[IPC_BUFFER_SIZE];
};
enum Type
@ -29,30 +29,30 @@ namespace Components
Pipe();
~Pipe();
bool Connect(std::string name);
bool Create(std::string name);
bool connect(std::string name);
bool create(std::string name);
bool Write(std::string command, std::string data);
void SetCallback(std::string command, PacketCallback callback);
void OnConnect(Callback callback);
bool write(std::string command, std::string data);
void setCallback(std::string command, PacketCallback callback);
void onConnect(Callback callback);
private:
Callback ConnectCallback;
std::map<std::string, PacketCallback> PacketCallbacks;
wink::slot<void()> connectCallback;
std::map<std::string, PacketCallback> packetCallbacks;
HANDLE hPipe;
std::thread mThread;
bool mThreadAttached;
HANDLE pipe;
std::thread thread;
bool threadAttached;
Type mType;
Packet mPacket;
Type type;
Packet packet;
char PipeName[MAX_PATH];
char PipeFile[MAX_PATH];
unsigned int ReconnectAttempt;
char pipeName[MAX_PATH];
char pipeFile[MAX_PATH];
unsigned int reconnectAttempt;
void Destroy();
void SetName(std::string name);
void destroy();
void setName(std::string name);
static void ReceiveThread(Pipe* pipe);
};
@ -60,19 +60,18 @@ namespace Components
class IPCPipe : public Component
{
public:
IPCPipe();
~IPCPipe();
IPCPipe();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "IPCPipe"; };
const char* getName() { return "IPCPipe"; };
#endif
static bool Write(std::string command, std::string data);
static void On(std::string command, Pipe::PacketCallback callback);
private:
static Pipe* ServerPipe;
static Pipe* ClientPipe;
static Pipe ServerPipe;
static Pipe ClientPipe;
static void ConnectClient();
};

View File

@ -64,6 +64,6 @@ namespace Components
Command::AddRaw("+leanright", Lean::IN_LeanRight_Down, true);
Command::AddRaw("-leanright", Lean::IN_LeanRight_Up, true);
Utils::Hook(0x5A6D84, Lean::CL_CmdButtonsStub, HOOK_CALL).Install()->Quick();
Utils::Hook(0x5A6D84, Lean::CL_CmdButtonsStub, HOOK_CALL).install()->quick();
}
}

View File

@ -9,7 +9,7 @@ namespace Components
Lean();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "Lean"; };
const char* getName() { return "Lean"; };
#endif
private:

View File

@ -16,28 +16,28 @@ namespace Components
{
Game::LocalizedEntry* entry = Localization::LocalizeMap[key];
char* newStaticValue = Localization::MemAllocator.DuplicateString(value);
char* newStaticValue = Localization::MemAllocator.duplicateString(value);
if (!newStaticValue) return;
if (entry->value) Localization::MemAllocator.Free(entry->value);
if (entry->value) Localization::MemAllocator.free(entry->value);
entry->value = newStaticValue;
return;
}
Game::LocalizedEntry* entry = Localization::MemAllocator.Allocate<Game::LocalizedEntry>();
Game::LocalizedEntry* entry = Localization::MemAllocator.allocate<Game::LocalizedEntry>();
if (!entry) return;
entry->name = Localization::MemAllocator.DuplicateString(key);
entry->name = Localization::MemAllocator.duplicateString(key);
if (!entry->name)
{
Localization::MemAllocator.Free(entry);
Localization::MemAllocator.free(entry);
return;
}
entry->value = Localization::MemAllocator.DuplicateString(value);
entry->value = Localization::MemAllocator.duplicateString(value);
if (!entry->value)
{
Localization::MemAllocator.Free(entry->name);
Localization::MemAllocator.Free(entry);
Localization::MemAllocator.free(entry->name);
Localization::MemAllocator.free(entry);
return;
}
@ -46,7 +46,7 @@ namespace Components
const char* Localization::Get(const char* key)
{
if (!Localization::UseLocalization.Get<bool>()) return key;
if (!Localization::UseLocalization.get<bool>()) return key;
Game::LocalizedEntry* entry = nullptr;
std::lock_guard<std::mutex> _(Localization::LocalizeMutex);
@ -82,26 +82,26 @@ namespace Components
if (Localization::TempLocalizeMap.find(key) != Localization::TempLocalizeMap.end())
{
Game::LocalizedEntry* entry = Localization::TempLocalizeMap[key];
if(entry->value) Localization::MemAllocator.Free(entry->value);
entry->value = Localization::MemAllocator.DuplicateString(value);
if(entry->value) Localization::MemAllocator.free(entry->value);
entry->value = Localization::MemAllocator.duplicateString(value);
}
else
{
Game::LocalizedEntry* entry = Localization::MemAllocator.Allocate<Game::LocalizedEntry>();
Game::LocalizedEntry* entry = Localization::MemAllocator.allocate<Game::LocalizedEntry>();
if (!entry) return;
entry->name = Localization::MemAllocator.DuplicateString(key);
entry->name = Localization::MemAllocator.duplicateString(key);
if (!entry->name)
{
Localization::MemAllocator.Free(entry);
Localization::MemAllocator.free(entry);
return;
}
entry->value = Localization::MemAllocator.DuplicateString(value);
entry->value = Localization::MemAllocator.duplicateString(value);
if (!entry->value)
{
Localization::MemAllocator.Free(entry->name);
Localization::MemAllocator.Free(entry);
Localization::MemAllocator.free(entry->name);
Localization::MemAllocator.free(entry);
return;
}
@ -117,9 +117,9 @@ namespace Components
{
if (i->second)
{
if (i->second->name) Localization::MemAllocator.Free(i->second->name);
if (i->second->value) Localization::MemAllocator.Free(i->second->value);
Localization::MemAllocator.Free(i->second);
if (i->second->name) Localization::MemAllocator.free(i->second->name);
if (i->second->value) Localization::MemAllocator.free(i->second->value);
Localization::MemAllocator.free(i->second);
}
}
@ -135,11 +135,11 @@ namespace Components
{
//if (ZoneBuilder::IsEnabled())
{
if (FileSystem::File(fmt::sprintf("localizedstrings/iw4x_%s.str", Game::Win_GetLanguage())).Exists())
if (FileSystem::File(fmt::sprintf("localizedstrings/iw4x_%s.str", Game::Win_GetLanguage())).exists())
{
Game::SE_Load(Utils::String::VA("localizedstrings/iw4x_%s.str", Game::Win_GetLanguage()), 0);
}
else if (FileSystem::File("localizedstrings/iw4x_english.str").Exists())
else if (FileSystem::File("localizedstrings/iw4x_english.str").exists())
{
Game::SE_Load("localizedstrings/iw4x_english.str", 0);
}
@ -168,13 +168,13 @@ namespace Components
});
// Resolving hook
Utils::Hook(0x629B90, Localization::Get, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x629B90, Localization::Get, HOOK_JUMP).install()->quick();
// Set loading entry point
Utils::Hook(0x41D859, Localization::SELoadLanguageStub, HOOK_CALL).Install()->Quick();
Utils::Hook(0x41D859, Localization::SELoadLanguageStub, HOOK_CALL).install()->quick();
// Overwrite SetString
Utils::Hook(0x4CE5EE, Localization::SetStringStub, HOOK_CALL).Install()->Quick();
Utils::Hook(0x4CE5EE, Localization::SetStringStub, HOOK_CALL).install()->quick();
/*
// TODO: Get rid of those!
@ -213,6 +213,6 @@ namespace Components
Localization::ClearTemp();
Localization::LocalizeMap.clear();
Localization::MemAllocator.Clear();
Localization::MemAllocator.clear();
}
}

View File

@ -7,7 +7,7 @@ namespace Components
~Localization();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "Localization"; };
const char* getName() { return "Localization"; };
#endif
static void Set(std::string key, std::string value);

View File

@ -193,19 +193,19 @@ namespace Components
QuickPatch::OnFrame(Logger::Frame);
Utils::Hook(0x4B0218, Logger::GameLogStub, HOOK_CALL).Install()->Quick();
Utils::Hook(Game::Com_PrintMessage, Logger::PrintMessageStub, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x4B0218, Logger::GameLogStub, HOOK_CALL).install()->quick();
Utils::Hook(Game::Com_PrintMessage, Logger::PrintMessageStub, HOOK_JUMP).install()->quick();
if (Loader::PerformingUnitTests())
{
Utils::Hook(Game::Com_Printf, Logger::PrintStub, HOOK_JUMP).Install()->Quick();
Utils::Hook(Game::Com_Printf, Logger::PrintStub, HOOK_JUMP).install()->quick();
}
Dvar::OnInit([] ()
{
Command::AddSV("log_add", [] (Command::Params params)
{
if (params.Length() < 2) return;
if (params.length() < 2) return;
Network::Address addr(params[1]);
@ -217,13 +217,13 @@ namespace Components
Command::AddSV("log_del", [] (Command::Params params)
{
if (params.Length() < 2) return;
if (params.length() < 2) return;
int num = atoi(params[1]);
if (fmt::sprintf("%i", num) == params[1] && static_cast<unsigned int>(num) < Logger::LoggingAddresses[0].size())
{
auto addr = Logger::LoggingAddresses[0].begin() + num;
Logger::Print("Address %s removed\n", addr->GetCString());
Logger::Print("Address %s removed\n", addr->getCString());
Logger::LoggingAddresses[0].erase(addr);
}
else
@ -234,11 +234,11 @@ namespace Components
if (i != Logger::LoggingAddresses[0].end())
{
Logger::LoggingAddresses[0].erase(i);
Logger::Print("Address %s removed\n", addr.GetCString());
Logger::Print("Address %s removed\n", addr.getCString());
}
else
{
Logger::Print("Address %s not found!\n", addr.GetCString());
Logger::Print("Address %s not found!\n", addr.getCString());
}
}
});
@ -250,13 +250,13 @@ namespace Components
for (unsigned int i = 0; i < Logger::LoggingAddresses[0].size(); ++i)
{
Logger::Print("#%03d: %5s\n", i, Logger::LoggingAddresses[0][i].GetCString());
Logger::Print("#%03d: %5s\n", i, Logger::LoggingAddresses[0][i].getCString());
}
});
Command::AddSV("g_log_add", [] (Command::Params params)
{
if (params.Length() < 2) return;
if (params.length() < 2) return;
Network::Address addr(params[1]);
@ -268,13 +268,13 @@ namespace Components
Command::AddSV("g_log_del", [] (Command::Params params)
{
if (params.Length() < 2) return;
if (params.length() < 2) return;
int num = atoi(params[1]);
if (fmt::sprintf("%i", num) == params[1] && static_cast<unsigned int>(num) < Logger::LoggingAddresses[1].size())
{
auto addr = Logger::LoggingAddresses[1].begin() + num;
Logger::Print("Address %s removed\n", addr->GetCString());
Logger::Print("Address %s removed\n", addr->getCString());
Logger::LoggingAddresses[1].erase(addr);
}
else
@ -285,11 +285,11 @@ namespace Components
if (i != Logger::LoggingAddresses[1].end())
{
Logger::LoggingAddresses[1].erase(i);
Logger::Print("Address %s removed\n", addr.GetCString());
Logger::Print("Address %s removed\n", addr.getCString());
}
else
{
Logger::Print("Address %s not found!\n", addr.GetCString());
Logger::Print("Address %s not found!\n", addr.getCString());
}
}
});
@ -301,7 +301,7 @@ namespace Components
for (unsigned int i = 0; i < Logger::LoggingAddresses[1].size(); ++i)
{
Logger::Print("#%03d: %5s\n", i, Logger::LoggingAddresses[1][i].GetCString());
Logger::Print("#%03d: %5s\n", i, Logger::LoggingAddresses[1][i].getCString());
}
});
});

View File

@ -7,7 +7,7 @@ namespace Components
~Logger();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "Logger"; };
const char* getName() { return "Logger"; };
#endif
static void MessagePrint(int channel, std::string message);

View File

@ -42,10 +42,10 @@ namespace Components
team.allocFlags = zoneInfo->allocFlags;
team.freeFlags = zoneInfo->freeFlags;
team.name = allocator.DuplicateString(fmt::sprintf("iw4x_team_%s", teams.first.data()));
team.name = allocator.duplicateString(fmt::sprintf("iw4x_team_%s", teams.first.data()));
data.push_back(team);
team.name = allocator.DuplicateString(fmt::sprintf("iw4x_team_%s", teams.second.data()));
team.name = allocator.duplicateString(fmt::sprintf("iw4x_team_%s", teams.second.data()));
data.push_back(team);
for (unsigned int i = 0; i < Maps::CurrentDependencies.size(); ++i)
@ -134,9 +134,9 @@ namespace Components
static std::string mapEntities;
FileSystem::File ents(name + ".ents");
if (ents.Exists())
if (ents.exists())
{
mapEntities = ents.GetBuffer();
mapEntities = ents.getBuffer();
asset.mapEnts->entityString = const_cast<char*>(mapEntities.data());
asset.mapEnts->numEntityChars = mapEntities.size() + 1;
}
@ -313,7 +313,7 @@ namespace Components
Logger::Print("Searching materials...\n");
int materialCount = 0;
Game::Material** materials = allocator.AllocateArray<Game::Material*>(world->dpvs.staticSurfaceCount);
Game::Material** materials = allocator.allocateArray<Game::Material*>(world->dpvs.staticSurfaceCount);
for (unsigned int i = 0; i < world->dpvs.staticSurfaceCount; i++)
{
@ -433,15 +433,15 @@ namespace Components
}
}
Dvar::Var(Utils::String::VA("isDlcInstalled_%d", pack.index)).SetRaw(hasAllMaps ? 1 : 0);
Dvar::Var(Utils::String::VA("isDlcInstalled_%d", pack.index)).setRaw(hasAllMaps ? 1 : 0);
}
Dvar::Var("isDlcInstalled_All").SetRaw(hasAllDlcs ? 1 : 0);
Dvar::Var("isDlcInstalled_All").setRaw(hasAllDlcs ? 1 : 0);
}
void Maps::ReallocateEntryPool()
void Maps::reallocateEntryPool()
{
Assert_Size(Game::XAssetEntry, 16);
AssertSize(Game::XAssetEntry, 16);
Maps::EntryPool.clear();
@ -505,7 +505,7 @@ namespace Components
UIScript::Add("downloadDLC", [] (UIScript::Token token)
{
int dlc = token.Get<int>();
int dlc = token.get<int>();
for (auto pack : Maps::DlcPacks)
{
@ -534,16 +534,16 @@ namespace Components
#endif
// Intercept BSP name resolving
Utils::Hook(0x4C5979, Maps::GetBSPName, HOOK_CALL).Install()->Quick();
Utils::Hook(0x4C5979, Maps::GetBSPName, HOOK_CALL).install()->quick();
// Intercept map zone loading
Utils::Hook(0x42C2AF, Maps::LoadMapZones, HOOK_CALL).Install()->Quick();
Utils::Hook(0x42C2AF, Maps::LoadMapZones, HOOK_CALL).install()->quick();
// Ignore SP entities
Utils::Hook(0x444810, Maps::IgnoreEntityStub, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x444810, Maps::IgnoreEntityStub, HOOK_JUMP).install()->quick();
// WorldData pointer replacement
Utils::Hook(0x4D90B6, Maps::GetWorldDataStub, HOOK_CALL).Install()->Quick();
Utils::Hook(0x4D90B6, Maps::GetWorldDataStub, HOOK_CALL).install()->quick();
Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_GAME_MAP_SP, 1);
Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_IMAGE, 7168);
@ -561,7 +561,7 @@ namespace Components
Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_STRINGTABLE, 800);
Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_IMPACTFX, 8);
Maps::ReallocateEntryPool();
this->reallocateEntryPool();
// Dependencies
//Maps::AddDependency("oilrig", "mp_subbase");

View File

@ -7,7 +7,7 @@ namespace Components
~Maps();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "Maps"; };
const char* getName() { return "Maps"; };
#endif
static void HandleAsSPMap();
@ -52,6 +52,6 @@ namespace Components
static void ExportMap(Game::GfxWorld* world);
#endif
void ReallocateEntryPool();
void reallocateEntryPool();
};
}

View File

@ -12,7 +12,7 @@ namespace Components
cmp eax, 9
je returnSafely
jmp Materials::ImageVersionCheckHook.Original
jmp Materials::ImageVersionCheckHook.original
returnSafely:
mov al, 1
@ -115,23 +115,23 @@ namespace Components
Materials::ImageNameLength = 7;
// Allow codo images
Materials::ImageVersionCheckHook.Initialize(0x53A456, Materials::ImageVersionCheck, HOOK_CALL)->Install();
Materials::ImageVersionCheckHook.initialize(0x53A456, Materials::ImageVersionCheck, HOOK_CALL)->install();
// Fix material pointer exploit
Utils::Hook(0x534E0C, Materials::DrawMaterialStub, HOOK_CALL).Install()->Quick();
Utils::Hook(0x534E0C, Materials::DrawMaterialStub, HOOK_CALL).install()->quick();
// Increment string pointer accordingly
Utils::Hook(0x5358FA, Materials::PostDrawMaterialStub, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x5358FA, Materials::PostDrawMaterialStub, HOOK_JUMP).install()->quick();
// Adapt death message to IW5 material format
Utils::Hook(0x5A30D9, Materials::DeathMessageStub, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x5A30D9, Materials::DeathMessageStub, HOOK_JUMP).install()->quick();
#ifdef DEBUG
if (Flags::HasFlag("dump"))
{
Utils::Hook(0x51F5AC, Materials::DumpImageCfg, HOOK_CALL).Install()->Quick();
Utils::Hook(0x51F4C4, Materials::DumpImageCfg, HOOK_CALL).Install()->Quick();
Utils::Hook(0x53AC62, Materials::DumpImageCfgPath, HOOK_CALL).Install()->Quick();
Utils::Hook(0x51F5AC, Materials::DumpImageCfg, HOOK_CALL).install()->quick();
Utils::Hook(0x51F4C4, Materials::DumpImageCfg, HOOK_CALL).install()->quick();
Utils::Hook(0x53AC62, Materials::DumpImageCfgPath, HOOK_CALL).install()->quick();
}
else
{
@ -152,6 +152,6 @@ namespace Components
Materials::~Materials()
{
Materials::ImageVersionCheckHook.Uninstall();
Materials::ImageVersionCheckHook.uninstall();
}
}

View File

@ -7,7 +7,7 @@ namespace Components
~Materials();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "Materials"; };
const char* getName() { return "Materials"; };
#endif
private:

View File

@ -174,10 +174,10 @@ namespace Components
std::vector<Game::menuDef_t*> menus;
FileSystem::File menuFile(menu);
if (menuFile.Exists())
if (menuFile.exists())
{
Game::pc_token_t token;
int handle = Menus::LoadMenuSource(menu, menuFile.GetBuffer());
int handle = Menus::LoadMenuSource(menu, menuFile.getBuffer());
if (Menus::IsValidSourceHandle(handle))
{
@ -536,7 +536,7 @@ namespace Components
// Parse scriptmenus!
if (menuList->menus[0]->window.name == "default_menu"s || Utils::String::EndsWith(filename, ".menu"))
{
if (FileSystem::File(filename).Exists())
if (FileSystem::File(filename).exists())
{
header.menuList = Menus::LoadScriptMenu(filename.data());
@ -626,7 +626,7 @@ namespace Components
Utils::Hook::Nop(0x428E48, 5);
// Intercept menu painting
Utils::Hook(0x4FFBDF, Menus::IsMenuVisible, HOOK_CALL).Install()->Quick();
Utils::Hook(0x4FFBDF, Menus::IsMenuVisible, HOOK_CALL).install()->quick();
// disable the 2 new tokens in ItemParse_rect
Utils::Hook::Set<BYTE>(0x640693, 0xEB);
@ -639,14 +639,14 @@ namespace Components
Command::Add("openmenu", [] (Command::Params params)
{
if (params.Length() != 2)
if (params.length() != 2)
{
Logger::Print("USAGE: openmenu <menu name>\n");
return;
}
// Not quite sure if we want to do this if we're not ingame, but it's only needed for ingame menus.
if (Dvar::Var("cl_ingame").Get<bool>())
if (Dvar::Var("cl_ingame").get<bool>())
{
Game::Key_SetCatcher(0, 16);
}

View File

@ -10,7 +10,7 @@ namespace Components
~Menus();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "Menus"; };
const char* getName() { return "Menus"; };
#endif
static void FreeEverything();

View File

@ -7,7 +7,7 @@ namespace Components
bool ModList::HasMod(std::string modName)
{
auto list = FileSystem::GetSysFileList(Dvar::Var("fs_basepath").Get<std::string>() + "\\mods", "", true);
auto list = FileSystem::GetSysFileList(Dvar::Var("fs_basepath").get<std::string>() + "\\mods", "", true);
for (auto mod : list)
{
@ -42,7 +42,7 @@ namespace Components
void ModList::UIScript_LoadMods()
{
auto folder = Dvar::Var("fs_basepath").Get<std::string>() + "\\mods";
auto folder = Dvar::Var("fs_basepath").get<std::string>() + "\\mods";
Game::Com_Printf(0, "Searching for mods in %s...\n", folder.data());
ModList::Mods = FileSystem::GetSysFileList(folder, "", true);
Game::Com_Printf(0, "Found %i mods!\n", ModList::Mods.size());
@ -59,10 +59,10 @@ namespace Components
void ModList::UIScript_ClearMods()
{
auto fsGame = Dvar::Var("fs_game");
fsGame.Set("");
fsGame.Get<Game::dvar_t*>()->modified = true;
fsGame.set("");
fsGame.get<Game::dvar_t*>()->modified = true;
if (Dvar::Var("cl_modVidRestart").Get<bool>())
if (Dvar::Var("cl_modVidRestart").get<bool>())
{
Game::Cmd_ExecuteSingleCommand(0, 0, "vid_restart");
}
@ -75,10 +75,10 @@ namespace Components
void ModList::RunMod(std::string mod)
{
auto fsGame = Dvar::Var("fs_game");
fsGame.Set(fmt::sprintf("mods/%s", mod.data()));
fsGame.Get<Game::dvar_t*>()->modified = true;
fsGame.set(fmt::sprintf("mods/%s", mod.data()));
fsGame.get<Game::dvar_t*>()->modified = true;
if (Dvar::Var("cl_modVidRestart").Get<bool>())
if (Dvar::Var("cl_modVidRestart").get<bool>())
{
Command::Execute("vid_restart", false);
}

View File

@ -7,7 +7,7 @@ namespace Components
~ModList();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "ModList"; };
const char* getName() { return "ModList"; };
#endif
static void RunMod(std::string mod);

View File

@ -40,7 +40,7 @@ namespace Components
Utils::Memory::Allocator allocator;
FileSystem::FileReader model(fmt::sprintf("models/%s", name.data()));
if (!model.Exists())
if (!model.exists())
{
#ifdef DEBUG
if (Flags::HasFlag("dump"))
@ -48,7 +48,7 @@ namespace Components
FILE* fp = nullptr;
if (!fopen_s(&fp, "dump.cfg", "a") && fp)
{
fprintf(fp, "dumpraw %s\n", model.GetName().data());
fprintf(fp, "dumpraw %s\n", model.getName().data());
fclose(fp);
}
@ -60,7 +60,7 @@ namespace Components
}
Game::CModelHeader header;
if (!model.Read(&header, sizeof header))
if (!model.read(&header, sizeof header))
{
Logger::Error("Reading header for model %s failed!", name.data());
}
@ -74,13 +74,13 @@ namespace Components
header.sectionHeader[Game::SECTION_MAIN].buffer = Utils::Memory::Allocate(header.sectionHeader[Game::SECTION_MAIN].size);
header.sectionHeader[Game::SECTION_INDEX].buffer = Utils::Memory::AllocateAlign(header.sectionHeader[Game::SECTION_INDEX].size, 16);
header.sectionHeader[Game::SECTION_VERTEX].buffer = Utils::Memory::AllocateAlign(header.sectionHeader[Game::SECTION_VERTEX].size, 16);
header.sectionHeader[Game::SECTION_FIXUP].buffer = allocator.AllocateArray<char>(header.sectionHeader[Game::SECTION_FIXUP].size);
header.sectionHeader[Game::SECTION_FIXUP].buffer = allocator.allocateArray<char>(header.sectionHeader[Game::SECTION_FIXUP].size);
// Load section data
for (int i = 0; i < ARRAY_SIZE(header.sectionHeader); ++i)
{
model.Seek(header.sectionHeader[i].offset, FS_SEEK_SET);
if (!model.Read(header.sectionHeader[i].buffer, header.sectionHeader[i].size))
model.seek(header.sectionHeader[i].offset, FS_SEEK_SET);
if (!model.read(header.sectionHeader[i].buffer, header.sectionHeader[i].size))
{
Logger::Error("Reading section %d for model %s failed!", i, name.data());
}
@ -104,9 +104,9 @@ namespace Components
allocationData->indexBuffer = header.sectionHeader[Game::SECTION_INDEX].buffer;
allocationData->vertexBuffer = header.sectionHeader[Game::SECTION_VERTEX].buffer;
Assert_Size(Game::XSurface, 64);
AssertSize(Game::XSurface, 64);
Game::XModelSurfs* modelSurfs = reinterpret_cast<Game::XModelSurfs*>(allocationData->mainArray);
Game::XSurface* tempSurfaces = allocator.AllocateArray<Game::XSurface>(modelSurfs->numSurfaces);
Game::XSurface* tempSurfaces = allocator.allocateArray<Game::XSurface>(modelSurfs->numSurfaces);
char* surfaceData = reinterpret_cast<char*>(modelSurfs->surfaces);
ModelSurfs::AllocMap[modelSurfs->name] = allocationData;
@ -143,7 +143,7 @@ namespace Components
if (!surfs->surfaces)
{
Assert_Offset(Game::XModelLodInfo, partBits, 12);
AssertOffset(Game::XModelLodInfo, partBits, 12);
Game::XModelSurfs* newSurfs = ModelSurfs::LoadXModelSurfaces(surfs->name);
if (!newSurfs) continue;
@ -320,11 +320,11 @@ namespace Components
Renderer::OnDeviceRecoveryEnd(ModelSurfs::EndRecover);
// Install hooks
Utils::Hook(0x47A6BD, ModelSurfs::XModelSurfsFixup, HOOK_CALL).Install()->Quick();
Utils::Hook(0x558F12, ModelSurfs::GetIndexBaseStub, HOOK_CALL).Install()->Quick();
Utils::Hook(0x4B4DE0, ModelSurfs::GetIndexBufferStub, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x558E70, ModelSurfs::GetIndexBufferStub2, HOOK_CALL).Install()->Quick();
Utils::Hook(0x5BC050, ModelSurfs::GetVertexBufferStub, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x47A6BD, ModelSurfs::XModelSurfsFixup, HOOK_CALL).install()->quick();
Utils::Hook(0x558F12, ModelSurfs::GetIndexBaseStub, HOOK_CALL).install()->quick();
Utils::Hook(0x4B4DE0, ModelSurfs::GetIndexBufferStub, HOOK_JUMP).install()->quick();
Utils::Hook(0x558E70, ModelSurfs::GetIndexBufferStub2, HOOK_CALL).install()->quick();
Utils::Hook(0x5BC050, ModelSurfs::GetVertexBufferStub, HOOK_JUMP).install()->quick();
}
ModelSurfs::~ModelSurfs()

View File

@ -7,7 +7,7 @@ namespace Components
~ModelSurfs();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "ModelSurfs"; };
const char* getName() { return "ModelSurfs"; };
#endif
private:

View File

@ -7,7 +7,7 @@ namespace Components
~MusicalTalent();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "MusicalTalent"; };
const char* getName() { return "MusicalTalent"; };
#endif
static void Replace(std::string sound, const char* file);

View File

@ -18,91 +18,91 @@ namespace Components
{
return Game::NET_CompareAdr(this->address, obj.address);
}
void Network::Address::SetPort(unsigned short port)
void Network::Address::setPort(unsigned short port)
{
this->address.port = htons(port);
}
unsigned short Network::Address::GetPort()
unsigned short Network::Address::getPort()
{
return ntohs(this->address.port);
}
void Network::Address::SetIP(DWORD ip)
void Network::Address::setIP(DWORD ip)
{
this->address.ip.full = ip;
}
void Network::Address::SetIP(Game::netIP_t ip)
void Network::Address::setIP(Game::netIP_t ip)
{
this->address.ip = ip;
}
Game::netIP_t Network::Address::GetIP()
Game::netIP_t Network::Address::getIP()
{
return this->address.ip;
}
void Network::Address::SetType(Game::netadrtype_t type)
void Network::Address::setType(Game::netadrtype_t type)
{
this->address.type = type;
}
Game::netadrtype_t Network::Address::GetType()
Game::netadrtype_t Network::Address::getType()
{
return this->address.type;
}
sockaddr Network::Address::GetSockAddr()
sockaddr Network::Address::getSockAddr()
{
sockaddr addr;
this->ToSockAddr(&addr);
this->toSockAddr(&addr);
return addr;
}
void Network::Address::ToSockAddr(sockaddr* addr)
void Network::Address::toSockAddr(sockaddr* addr)
{
if (addr)
{
Game::NetadrToSockadr(&this->address, addr);
}
}
void Network::Address::ToSockAddr(sockaddr_in* addr)
void Network::Address::toSockAddr(sockaddr_in* addr)
{
this->ToSockAddr(reinterpret_cast<sockaddr*>(addr));
this->toSockAddr(reinterpret_cast<sockaddr*>(addr));
}
Game::netadr_t* Network::Address::Get()
Game::netadr_t* Network::Address::get()
{
return &this->address;
}
const char* Network::Address::GetCString()
const char* Network::Address::getCString()
{
return Game::NET_AdrToString(this->address);
}
std::string Network::Address::GetString()
std::string Network::Address::getString()
{
return this->GetCString();
return this->getCString();
}
bool Network::Address::IsLocal()
bool Network::Address::isLocal()
{
// According to: https://en.wikipedia.org/wiki/Private_network
// 10.X.X.X
if (this->GetIP().bytes[0] == 10) return true;
if (this->getIP().bytes[0] == 10) return true;
// 192.168.X.X
if (this->GetIP().bytes[0] == 192 && this->GetIP().bytes[1] == 168) return true;
if (this->getIP().bytes[0] == 192 && this->getIP().bytes[1] == 168) return true;
// 172.16.X.X - 172.31.X.X
if (this->GetIP().bytes[0] == 172 && (this->GetIP().bytes[1] >= 16) && (this->GetIP().bytes[1] < 32)) return true;
if (this->getIP().bytes[0] == 172 && (this->getIP().bytes[1] >= 16) && (this->getIP().bytes[1] < 32)) return true;
// 127.0.0.1
if (this->GetIP().full == 0x0100007F) return true;
if (this->getIP().full == 0x0100007F) return true;
// TODO: Maybe check for matching localIPs and subnet mask
return false;
}
bool Network::Address::IsSelf()
bool Network::Address::isSelf()
{
if (Game::NET_IsLocalAddress(this->address)) return true; // Loopback
if (this->GetPort() != (Dvar::Var("net_port").Get<int>() & 0xFFFF)) return false; // Port not equal
if (this->getPort() != (Dvar::Var("net_port").get<int>() & 0xFFFF)) return false; // Port not equal
for (int i = 0; i < *Game::numIP; ++i)
{
if (this->GetIP().full == Game::localIP[i].full)
if (this->getIP().full == Game::localIP[i].full)
{
return true;
}
@ -110,29 +110,29 @@ namespace Components
return false;
}
bool Network::Address::IsLoopback()
bool Network::Address::isLoopback()
{
if (this->GetIP().full == 0x100007f) // 127.0.0.1
if (this->getIP().full == 0x100007f) // 127.0.0.1
{
return true;
}
return Game::NET_IsLocalAddress(this->address);
}
bool Network::Address::IsValid()
bool Network::Address::isValid()
{
return (this->GetType() != Game::netadrtype_t::NA_BAD);
return (this->getType() != Game::netadrtype_t::NA_BAD);
}
void Network::Address::Serialize(Proto::Network::Address* protoAddress)
void Network::Address::serialize(Proto::Network::Address* protoAddress)
{
protoAddress->set_ip(this->GetIP().full);
protoAddress->set_port(this->GetPort() & 0xFFFF);
protoAddress->set_ip(this->getIP().full);
protoAddress->set_port(this->getPort() & 0xFFFF);
}
void Network::Address::Deserialize(const Proto::Network::Address& protoAddress)
void Network::Address::deserialize(const Proto::Network::Address& protoAddress)
{
this->SetIP(protoAddress.ip());
this->SetPort(static_cast<uint16_t>(protoAddress.port()));
this->SetType(Game::netadrtype_t::NA_IP);
this->setIP(protoAddress.ip());
this->setPort(static_cast<uint16_t>(protoAddress.port()));
this->setType(Game::netadrtype_t::NA_IP);
}
void Network::Handle(std::string packet, Network::Callback* callback)
@ -167,7 +167,7 @@ namespace Components
{
// NET_OutOfBandData doesn't seem to work properly
//Game::NET_OutOfBandData(type, *target.Get(), data.data(), data.size());
Game::Sys_SendPacket(type, data.size(), data.data(), *target.Get());
Game::Sys_SendPacket(type, data.size(), data.data(), *target.get());
}
void Network::SendRaw(Network::Address target, std::string data)
@ -196,9 +196,9 @@ namespace Components
{
Address target;
target.SetPort(port);
target.SetIP(INADDR_BROADCAST);
target.SetType(Game::netadrtype_t::NA_BROADCAST);
target.setPort(port);
target.setIP(INADDR_BROADCAST);
target.setType(Game::netadrtype_t::NA_BROADCAST);
Network::Send(Game::netsrc_t::NS_CLIENT, target, data);
}
@ -317,7 +317,7 @@ namespace Components
Network::Network()
{
Assert_Size(Game::netadr_t, 20);
AssertSize(Game::netadr_t, 20);
// maximum size in NET_OutOfBandPrint
Utils::Hook::Set<DWORD>(0x4AEF08, 0x1FFFC);
@ -330,18 +330,17 @@ namespace Components
Utils::Hook::Set<char*>(0x4698E3, "%u.%u.%u.%u:%hu");
// Install startup handler
Utils::Hook(0x4FD4D4, Network::NetworkStartStub, HOOK_JUMP).Install()->Quick();
Utils::Hook(0x4FD4D4, Network::NetworkStartStub, HOOK_JUMP).install()->quick();
// Install interception handler
Utils::Hook(0x5AA709, Network::PacketInterceptionHandler, HOOK_CALL).Install()->Quick();
Utils::Hook(0x5AA709, Network::PacketInterceptionHandler, HOOK_CALL).install()->quick();
// Install packet deploy hook
Utils::Hook::RedirectJump(0x5AA713, Network::DeployPacketStub);
// For /dev/urandom :P
Network::Handle("resolveAddress", [] (Address address, std::string data)
{
Network::SendRaw(address, address.GetString());
Network::SendRaw(address, address.getString());
});
}

View File

@ -8,7 +8,7 @@ namespace Components
class Address
{
public:
Address() { this->SetType(Game::netadrtype_t::NA_BAD); };
Address() { setType(Game::netadrtype_t::NA_BAD); };
Address(std::string addrString);
Address(sockaddr* addr);
Address(sockaddr addr) : Address(&addr) {}
@ -17,34 +17,34 @@ namespace Components
Address(Game::netadr_t addr) : address(addr) {}
Address(Game::netadr_t* addr) : Address(*addr) {}
Address(const Address& obj) : address(obj.address) {};
Address(const Proto::Network::Address& addr) { this->Deserialize(addr); };
Address(const Proto::Network::Address& addr) { this->deserialize(addr); };
bool operator!=(const Address &obj) { return !(*this == obj); };
bool operator==(const Address &obj);
void SetPort(unsigned short port);
unsigned short GetPort();
void setPort(unsigned short port);
unsigned short getPort();
void SetIP(DWORD ip);
void SetIP(Game::netIP_t ip);
Game::netIP_t GetIP();
void setIP(DWORD ip);
void setIP(Game::netIP_t ip);
Game::netIP_t getIP();
void SetType(Game::netadrtype_t type);
Game::netadrtype_t GetType();
void setType(Game::netadrtype_t type);
Game::netadrtype_t getType();
sockaddr GetSockAddr();
void ToSockAddr(sockaddr* addr);
void ToSockAddr(sockaddr_in* addr);
Game::netadr_t* Get();
const char* GetCString();
std::string GetString();
sockaddr getSockAddr();
void toSockAddr(sockaddr* addr);
void toSockAddr(sockaddr_in* addr);
Game::netadr_t* get();
const char* getCString();
std::string getString();
bool IsLocal();
bool IsSelf();
bool IsValid();
bool IsLoopback();
bool isLocal();
bool isSelf();
bool isValid();
bool isLoopback();
void Serialize(Proto::Network::Address* protoAddress);
void Deserialize(const Proto::Network::Address& protoAddress);
void serialize(Proto::Network::Address* protoAddress);
void deserialize(const Proto::Network::Address& protoAddress);
private:
Game::netadr_t address;
@ -57,7 +57,7 @@ namespace Components
~Network();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "Network"; };
const char* getName() { return "Network"; };
#endif
static void Handle(std::string packet, Callback* callback);
@ -80,7 +80,6 @@ namespace Components
static void BroadcastAll(std::string data);
private:
static SOCKET TcpSocket;
static std::string SelectedPacket;
static wink::signal<wink::slot<CallbackRaw>> StartupSignal;
static std::map<std::string, wink::slot<Callback>> PacketHandlers;

View File

@ -7,7 +7,7 @@ namespace Components
bool News::Terminate;
std::thread News::Thread;
bool News::UnitTest()
bool News::unitTest()
{
bool result = true;
@ -73,7 +73,7 @@ namespace Components
void News::CheckForUpdate()
{
std::string caches = Utils::WebIO("IW4x", "https://iw4xcachep26muba.onion.to/iw4/caches.xml").SetTimeout(5000)->Get();
std::string caches = Utils::WebIO("IW4x", "https://iw4xcachep26muba.onion.to/iw4/caches.xml").setTimeout(5000)->get();
if (!caches.empty())
{
@ -92,8 +92,8 @@ namespace Components
int version = atoi(caches.data());
Dvar::Var("cl_updateversion").Get<Game::dvar_t*>()->current.integer = version;
Dvar::Var("cl_updateavailable").Get<Game::dvar_t*>()->current.boolean = (version > REVISION);
Dvar::Var("cl_updateversion").get<Game::dvar_t*>()->current.integer = version;
Dvar::Var("cl_updateavailable").get<Game::dvar_t*>()->current.boolean = (version > REVISION);
}
}
}
@ -115,7 +115,7 @@ namespace Components
// hook for getting the news ticker string
Utils::Hook::Nop(0x6388BB, 2); // skip the "if (item->text[0] == '@')" localize check
Utils::Hook(0x6388C1, News::GetNewsText, HOOK_CALL).Install()->Quick();
Utils::Hook(0x6388C1, News::GetNewsText, HOOK_CALL).install()->quick();
// TODO: Probably remove that, if the updater is part of the repo?
if (Utils::IO::FileExists("updater.exe"))
@ -130,7 +130,7 @@ namespace Components
Command::Add("getautoupdate", [] (Command::Params)
{
if (!Dvar::Var("cl_updateavailable").Get<Game::dvar_t*>()->current.boolean) return;
if (!Dvar::Var("cl_updateavailable").get<Game::dvar_t*>()->current.boolean) return;
Localization::SetTemp("MENU_RECONNECTING_TO_PARTY", "Downloading updater");
Command::Execute("openmenu popup_reconnectingtoparty", true);
@ -140,7 +140,7 @@ namespace Components
std::thread([] ()
{
std::string data = Utils::WebIO("IW4x", "https://iw4xcachep26muba.onion.to/iw4/updater.exe").SetTimeout(5000)->Get();
std::string data = Utils::WebIO("IW4x", "https://iw4xcachep26muba.onion.to/iw4/updater.exe").setTimeout(5000)->get();
if (data.empty())
{
@ -162,9 +162,9 @@ namespace Components
News::Terminate = false;
News::Thread = std::thread([] ()
{
Localization::Set("MPUI_CHANGELOG_TEXT", Utils::WebIO("IW4x", "https://iw4xcachep26muba.onion.to/iw4/changelog.txt").SetTimeout(5000)->Get());
Localization::Set("MPUI_CHANGELOG_TEXT", Utils::WebIO("IW4x", "https://iw4xcachep26muba.onion.to/iw4/changelog.txt").setTimeout(5000)->get());
std::string data = Utils::WebIO("IW4x", "https://iw4xcachep26muba.onion.to/iw4/motd.txt").SetTimeout(5000)->Get();
std::string data = Utils::WebIO("IW4x", "https://iw4xcachep26muba.onion.to/iw4/motd.txt").setTimeout(5000)->get();
if (!data.empty())
{

View File

@ -7,10 +7,10 @@ namespace Components
~News();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "News"; };
const char* getName() { return "News"; };
#endif
bool UnitTest();
bool unitTest();
private:
static std::thread Thread;

View File

@ -10,7 +10,7 @@ namespace Components
void Node::LoadNodeRemotePreset()
{
std::string nodes = Utils::WebIO("IW4x", "https://iw4xcachep26muba.onion.to/iw4/nodes.txt").SetTimeout(5000)->Get();
std::string nodes = Utils::WebIO("IW4x", "https://iw4xcachep26muba.onion.to/iw4/nodes.txt").setTimeout(5000)->get();
if (nodes.empty()) return;
auto nodeList = Utils::String::Explode(nodes, '\n');
@ -26,7 +26,7 @@ namespace Components
{
Proto::Node::List list;
FileSystem::File defaultNodes("nodes_default.dat");
if (!defaultNodes.Exists() || !list.ParseFromString(Utils::Compression::ZLib::Decompress(defaultNodes.GetBuffer()))) return;
if (!defaultNodes.exists() || !list.ParseFromString(Utils::Compression::ZLib::Decompress(defaultNodes.getBuffer()))) return;
for (int i = 0; i < list.address_size(); ++i)
{
@ -47,7 +47,7 @@ namespace Components
}
void Node::StoreNodes(bool force)
{
if (Dedicated::IsEnabled() && Dvar::Var("sv_lanOnly").Get<bool>()) return;
if (Dedicated::IsEnabled() && Dvar::Var("sv_lanOnly").get<bool>()) return;
static int lastStorage = 0;
@ -66,7 +66,7 @@ namespace Components
{
if (node.state == Node::STATE_VALID && node.registered)
{
node.address.Serialize(list.add_address());
node.address.serialize(list.add_address());
}
}
@ -121,9 +121,9 @@ namespace Components
void Node::AddNode(Network::Address address)
{
#ifdef DEBUG
if (!address.IsValid() || address.IsSelf()) return;
if (!address.isValid() || address.isSelf()) return;
#else
if (!address.IsValid() || address.IsLocal() || address.IsSelf()) return;
if (!address.isValid() || address.isLocal() || address.isSelf()) return;
#endif
std::lock_guard<std::mutex> _(Node::NodeMutex);
@ -147,14 +147,14 @@ namespace Components
Node::Nodes.push_back(entry);
#if defined(DEBUG) && !defined(DISABLE_NODE_LOG)
Logger::Print("Adding node %s...\n", address.GetCString());
Logger::Print("Adding node %s...\n", address.getCString());
#endif
}
}
void Node::SendNodeList(Network::Address address)
{
if (address.IsSelf()) return;
if (address.isSelf()) return;
Proto::Node::List list;
list.set_is_dedi(Dedicated::IsEnabled());
@ -167,7 +167,7 @@ namespace Components
{
if (node.state == Node::STATE_VALID && node.registered)
{
node.address.Serialize(list.add_address());
node.address.serialize(list.add_address());
}
if (list.address_size() >= NODE_PACKET_LIMIT)
@ -208,7 +208,7 @@ namespace Components
if (node.state == Node::STATE_INVALID && (Game::Sys_Milliseconds() - node.lastHeard) > NODE_INVALID_DELETE)
{
#if defined(DEBUG) && !defined(DISABLE_NODE_LOG)
Logger::Print("Removing invalid node %s\n", node.address.GetCString());
Logger::Print("Removing invalid node %s\n", node.address.getCString());
#endif
}
else
@ -253,14 +253,14 @@ namespace Components
packet.set_challenge(entry->challenge);
#if defined(DEBUG) && !defined(DISABLE_NODE_LOG)
Logger::Print("Sending registration request to %s\n", entry->address.GetCString());
Logger::Print("Sending registration request to %s\n", entry->address.getCString());
#endif
Network::SendCommand(entry->address, "nodeRegisterRequest", packet.SerializeAsString());
}
else
{
#if defined(DEBUG) && !defined(DISABLE_NODE_LOG)
Logger::Print("Sending session request to %s\n", entry->address.GetCString());
Logger::Print("Sending session request to %s\n", entry->address.getCString());
#endif
Network::SendCommand(entry->address, "sessionRequest");
}
@ -268,7 +268,7 @@ namespace Components
void Node::FrameHandler()
{
if (Dedicated::IsEnabled() && Dvar::Var("sv_lanOnly").Get<bool>()) return;
if (Dedicated::IsEnabled() && Dvar::Var("sv_lanOnly").get<bool>()) return;
// Frame limit
static int lastFrame = 0;
@ -291,7 +291,7 @@ namespace Components
node.lastTime = Game::Sys_Milliseconds();
#if defined(DEBUG) && !defined(DISABLE_NODE_LOG)
Logger::Print("Node negotiation timed out. Invalidating %s\n", node.address.GetCString());
Logger::Print("Node negotiation timed out. Invalidating %s\n", node.address.getCString());
#endif
}
@ -393,7 +393,7 @@ namespace Components
{
QuickPatch::OnShutdown([] ()
{
if (Dvar::Var("sv_lanOnly").Get<bool>()) return;
if (Dvar::Var("sv_lanOnly").get<bool>()) return;
std::string challenge = fmt::sprintf("%X", Utils::Cryptography::Rand::GenerateInt());
@ -412,7 +412,7 @@ namespace Components
// If you want to get accepted as node, you have to send a request to this handler
Network::Handle("nodeRegisterRequest", [] (Network::Address address, std::string data)
{
if (Dvar::Var("sv_lanOnly").Get<bool>()) return;
if (Dvar::Var("sv_lanOnly").get<bool>()) return;
// Create a new entry, if we don't already know it
if (!Node::FindNode(address))
@ -425,7 +425,7 @@ namespace Components
Node::NodeEntry* entry = Node::FindNode(address);
#if defined(DEBUG) && !defined(DISABLE_NODE_LOG)
Logger::Print("Received registration request from %s\n", address.GetCString());
Logger::Print("Received registration request from %s\n", address.getCString());
#endif
Proto::Node::Packet packet;
@ -449,7 +449,7 @@ namespace Components
packet.Clear();
packet.set_challenge(challenge);
packet.set_signature(signature);
packet.set_publickey(Node::SignatureKey.GetPublicKey());
packet.set_publickey(Node::SignatureKey.getPublicKey());
entry->lastTime = Game::Sys_Milliseconds();
entry->challenge = challenge;
@ -460,14 +460,14 @@ namespace Components
Network::Handle("nodeRegisterSynchronize", [] (Network::Address address, std::string data)
{
if (Dvar::Var("sv_lanOnly").Get<bool>()) return;
if (Dvar::Var("sv_lanOnly").get<bool>()) return;
std::lock_guard<std::mutex> _(Node::NodeMutex);
Node::NodeEntry* entry = Node::FindNode(address);
if (!entry || entry->state != Node::STATE_NEGOTIATING) return;
#if defined(DEBUG) && !defined(DISABLE_NODE_LOG)
Logger::Print("Received synchronization data for registration from %s!\n", address.GetCString());
Logger::Print("Received synchronization data for registration from %s!\n", address.getCString());
#endif
Proto::Node::Packet packet;
@ -481,10 +481,10 @@ namespace Components
std::string signature = packet.signature();
// Verify signature
entry->publicKey.Set(publicKey);
entry->publicKey.set(publicKey);
if (!Utils::Cryptography::ECC::VerifyMessage(entry->publicKey, entry->challenge, signature))
{
Logger::Print("Signature from %s for challenge '%s' is invalid!\n", address.GetCString(), entry->challenge.data());
Logger::Print("Signature from %s for challenge '%s' is invalid!\n", address.getCString(), entry->challenge.data());
return;
}
@ -494,12 +494,12 @@ namespace Components
entry->registered = true;
#if defined(DEBUG) && !defined(DISABLE_NODE_LOG)
Logger::Print("Signature from %s for challenge '%s' is valid!\n", address.GetCString(), entry->challenge.data());
Logger::Print("Node %s registered\n", address.GetCString());
Logger::Print("Signature from %s for challenge '%s' is valid!\n", address.getCString(), entry->challenge.data());
Logger::Print("Node %s registered\n", address.getCString());
#endif
// Build response
publicKey = Node::SignatureKey.GetPublicKey();
publicKey = Node::SignatureKey.getPublicKey();
signature = Utils::Cryptography::ECC::SignMessage(Node::SignatureKey, challenge);
packet.Clear();
@ -511,7 +511,7 @@ namespace Components
Network::Handle("nodeRegisterAcknowledge", [] (Network::Address address, std::string data)
{
if (Dvar::Var("sv_lanOnly").Get<bool>()) return;
if (Dvar::Var("sv_lanOnly").get<bool>()) return;
// Ignore requests from nodes we don't know
std::lock_guard<std::mutex> _(Node::NodeMutex);
@ -519,7 +519,7 @@ namespace Components
if (!entry || entry->state != Node::STATE_NEGOTIATING) return;
#if defined(DEBUG) && !defined(DISABLE_NODE_LOG)
Logger::Print("Received acknowledgment from %s\n", address.GetCString());
Logger::Print("Received acknowledgment from %s\n", address.getCString());
#endif
Proto::Node::Packet packet;
@ -530,7 +530,7 @@ namespace Components
std::string publicKey = packet.publickey();
std::string signature = packet.signature();
entry->publicKey.Set(publicKey);
entry->publicKey.set(publicKey);
if (Utils::Cryptography::ECC::VerifyMessage(entry->publicKey, entry->challenge, signature))
{
@ -539,21 +539,21 @@ namespace Components
entry->registered = true;
#if defined(DEBUG) && !defined(DISABLE_NODE_LOG)
Logger::Print("Signature from %s for challenge '%s' is valid!\n", address.GetCString(), entry->challenge.data());
Logger::Print("Node %s registered\n", address.GetCString());
Logger::Print("Signature from %s for challenge '%s' is valid!\n", address.getCString(), entry->challenge.data());
Logger::Print("Node %s registered\n", address.getCString());
#endif
}
else
{
#ifdef DEBUG
Logger::Print("Signature from %s for challenge '%s' is invalid!\n", address.GetCString(), entry->challenge.data());
Logger::Print("Signature from %s for challenge '%s' is invalid!\n", address.getCString(), entry->challenge.data());
#endif
}
});
Network::Handle("nodeListRequest", [] (Network::Address address, std::string data)
{
if (Dvar::Var("sv_lanOnly").Get<bool>()) return;
if (Dvar::Var("sv_lanOnly").get<bool>()) return;
// Check if this is a registered node
bool allowed = false;
@ -588,7 +588,7 @@ namespace Components
{
#if defined(DEBUG) && !defined(DISABLE_NODE_LOG)
// Unallowed connection
Logger::Print("Node list requested by %s, but no valid session was present!\n", address.GetCString());
Logger::Print("Node list requested by %s, but no valid session was present!\n", address.getCString());
#endif
Network::SendCommand(address, "nodeListError");
}
@ -596,7 +596,7 @@ namespace Components
Network::Handle("nodeDeregister", [] (Network::Address address, std::string data)
{
if (Dvar::Var("sv_lanOnly").Get<bool>()) return;
if (Dvar::Var("sv_lanOnly").get<bool>()) return;
std::lock_guard<std::mutex> _(Node::NodeMutex);
Node::NodeEntry* entry = Node::FindNode(address);
@ -618,20 +618,20 @@ namespace Components
entry->state = Node::STATE_INVALID;
#if defined(DEBUG) && !defined(DISABLE_NODE_LOG)
Logger::Print("Node %s unregistered\n", address.GetCString());
Logger::Print("Node %s unregistered\n", address.getCString());
#endif
}
else
{
#if defined(DEBUG) && !defined(DISABLE_NODE_LOG)
Logger::Print("Node %s tried to unregister using an invalid signature!\n", address.GetCString());
Logger::Print("Node %s tried to unregister using an invalid signature!\n", address.getCString());
#endif
}
});
Network::Handle("sessionRequest", [] (Network::Address address, std::string data)
{
if (Dvar::Var("sv_lanOnly").Get<bool>()) return;
if (Dvar::Var("sv_lanOnly").get<bool>()) return;
// Search an active session, if we haven't found one, register a template
std::lock_guard<std::mutex> _(Node::SessionMutex);
@ -647,7 +647,7 @@ namespace Components
if (!session) return; // Registering template session failed, odd...
#if defined(DEBUG) && !defined(DISABLE_NODE_LOG)
Logger::Print("Client %s is requesting a new session\n", address.GetCString());
Logger::Print("Client %s is requesting a new session\n", address.getCString());
#endif
// Initialize session data
@ -660,7 +660,7 @@ namespace Components
Network::Handle("sessionSynchronize", [] (Network::Address address, std::string data)
{
if (Dvar::Var("sv_lanOnly").Get<bool>()) return;
if (Dvar::Var("sv_lanOnly").get<bool>()) return;
// Return if we don't have a session for this address
std::lock_guard<std::mutex> _(Node::SessionMutex);
@ -670,7 +670,7 @@ namespace Components
if (session->challenge == data)
{
#if defined(DEBUG) && !defined(DISABLE_NODE_LOG)
Logger::Print("Session for %s validated.\n", address.GetCString());
Logger::Print("Session for %s validated.\n", address.getCString());
#endif
session->valid = true;
Network::SendCommand(address, "sessionAcknowledge");
@ -679,7 +679,7 @@ namespace Components
{
session->lastTime = -1;
#if defined(DEBUG) && !defined(DISABLE_NODE_LOG)
Logger::Print("Challenge mismatch. Validating session for %s failed.\n", address.GetCString());
Logger::Print("Challenge mismatch. Validating session for %s failed.\n", address.getCString());
#endif
}
});
@ -693,7 +693,7 @@ namespace Components
if (!entry) return;
#if defined(DEBUG) && !defined(DISABLE_NODE_LOG)
Logger::Print("Session initialization received from %s. Synchronizing...\n", address.GetCString());
Logger::Print("Session initialization received from %s. Synchronizing...\n", address.getCString());
#endif
entry->lastTime = Game::Sys_Milliseconds();
@ -713,7 +713,7 @@ namespace Components
}
#if defined(DEBUG) && !defined(DISABLE_NODE_LOG)
Logger::Print("Session acknowledged by %s, synchronizing node list...\n", address.GetCString());
Logger::Print("Session acknowledged by %s, synchronizing node list...\n", address.getCString());
#endif
Network::SendCommand(address, "nodeListRequest");
Node::SendNodeList(address);
@ -727,7 +727,7 @@ namespace Components
if (data.empty() || !list.ParseFromString(data))
{
#if defined(DEBUG) && !defined(DISABLE_NODE_LOG)
Logger::Print("Received invalid node list from %s!\n", address.GetCString());
Logger::Print("Received invalid node list from %s!\n", address.getCString());
#endif
return;
}
@ -739,7 +739,7 @@ namespace Components
if (entry->registered)
{
#if defined(DEBUG) && !defined(DISABLE_NODE_LOG)
Logger::Print("Received valid node list with %i entries from %s\n", list.address_size(), address.GetCString());
Logger::Print("Received valid node list with %i entries from %s\n", list.address_size(), address.getCString());
#endif
entry->isDedi = list.is_dedi();
@ -772,13 +772,13 @@ namespace Components
// Version 0 sends port in the wrong byte order!
if (list.version() == 0)
{
_addr.SetPort(ntohs(_addr.GetPort()));
_addr.setPort(ntohs(_addr.getPort()));
}
// if (!Node::FindNode(_addr) && _addr.GetPort() >= 1024 && _addr.GetPort() - 20 < 1024)
// {
// std::string a1 = _addr.GetString();
// std::string a2 = address.GetString();
// std::string a1 = _addr.getString();
// std::string a2 = address.getString();
// Logger::Print("Received weird address %s from %s\n", a1.data(), a2.data());
// }
@ -842,13 +842,13 @@ namespace Components
std::lock_guard<std::mutex> _(Node::NodeMutex);
for (auto node : Node::Nodes)
{
Logger::Print("%s\t(%s)\n", node.address.GetCString(), Node::GetStateName(node.state));
Logger::Print("%s\t(%s)\n", node.address.getCString(), Node::GetStateName(node.state));
}
});
Command::Add("addnode", [] (Command::Params params)
{
if (params.Length() < 2) return;
if (params.length() < 2) return;
Network::Address address(params[1]);
Node::AddNode(address);
@ -892,7 +892,7 @@ namespace Components
Node::~Node()
{
Node::SignatureKey.Free();
Node::SignatureKey.free();
Node::StoreNodes(true);
std::lock_guard<std::mutex> _(Node::NodeMutex);
@ -901,11 +901,11 @@ namespace Components
Node::Sessions.clear();
}
bool Node::UnitTest()
bool Node::unitTest()
{
printf("Testing ECDSA key...");
if (!Node::SignatureKey.IsValid())
if (!Node::SignatureKey.isValid())
{
printf("Error\n");
printf("ECDSA key seems invalid!\n");
@ -950,12 +950,12 @@ namespace Components
printf("Success\n");
printf("Testing ECDSA key import...");
std::string pubKey = Node::SignatureKey.GetPublicKey();
std::string pubKey = Node::SignatureKey.getPublicKey();
std::string message = fmt::sprintf("%X", Utils::Cryptography::Rand::GenerateInt());
std::string signature = Utils::Cryptography::ECC::SignMessage(Node::SignatureKey, message);
Utils::Cryptography::ECC::Key testKey;
testKey.Set(pubKey);
testKey.set(pubKey);
if (!Utils::Cryptography::ECC::VerifyMessage(Node::SignatureKey, message, signature))
{

View File

@ -18,10 +18,10 @@ namespace Components
~Node();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "Node"; };
const char* getName() { return "Node"; };
#endif
bool UnitTest();
bool unitTest();
static void SyncNodeList();
static void AddNode(Network::Address address);

View File

@ -19,20 +19,20 @@ namespace Components
Network::Address Party::Target()
{
return Party::Container.Target;
return Party::Container.target;
}
void Party::Connect(Network::Address target)
{
Node::AddNode(target);
Party::Container.Valid = true;
Party::Container.AwaitingPlaylist = false;
Party::Container.JoinTime = Game::Sys_Milliseconds();
Party::Container.Target = target;
Party::Container.Challenge = fmt::sprintf("%X", Utils::Cryptography::Rand::GenerateInt());
Party::Container.valid = true;
Party::Container.awaitingPlaylist = false;
Party::Container.joinTime = Game::Sys_Milliseconds();
Party::Container.target = target;
Party::Container.challenge = fmt::sprintf("%X", Utils::Cryptography::Rand::GenerateInt());
Network::SendCommand(Party::Container.Target, "getinfo", Party::Container.Challenge);
Network::SendCommand(Party::Container.target, "getinfo", Party::Container.challenge);
Command::Execute("openmenu popup_reconnectingtoparty");
}
@ -45,11 +45,11 @@ namespace Components
if (key == "addr")
{
return Utils::String::VA("%d", address.GetIP().full);
return Utils::String::VA("%d", address.getIP().full);
}
else if (key =="port")
{
return Utils::String::VA("%d", address.GetPort());
return Utils::String::VA("%d", address.getPort());
}
}
@ -68,41 +68,41 @@ namespace Components
{
Localization::ClearTemp();
Command::Execute("closemenu popup_reconnectingtoparty");
Dvar::Var("partyend_reason").Set(message);
Dvar::Var("partyend_reason").set(message);
Command::Execute("openmenu menu_xboxlive_partyended");
}
Game::dvar_t* Party::RegisterMinPlayers(const char* name, int /*value*/, int /*min*/, int max, Game::dvar_flag flag, const char* description)
{
return Dvar::Register<int>(name, 1, 1, max, Game::dvar_flag::DVAR_FLAG_WRITEPROTECTED | flag, description).Get<Game::dvar_t*>();
return Dvar::Register<int>(name, 1, 1, max, Game::dvar_flag::DVAR_FLAG_WRITEPROTECTED | flag, description).get<Game::dvar_t*>();
}
bool Party::PlaylistAwaiting()
{
return Party::Container.AwaitingPlaylist;
return Party::Container.awaitingPlaylist;
}
void Party::PlaylistContinue()
{
Dvar::Var("xblive_privateserver").Set(false);
Dvar::Var("xblive_privateserver").set(false);
// Ensure we can join
*Game::g_lobbyCreateInProgress = false;
Party::Container.AwaitingPlaylist = false;
Party::Container.awaitingPlaylist = false;
SteamID id = Party::GenerateLobbyId();
// Temporary workaround
// TODO: Patch the 127.0.0.1 -> loopback mapping in the party code
if (Party::Container.Target.IsLoopback())
if (Party::Container.target.isLoopback())
{
if (*Game::numIP)
{
Party::Container.Target.SetIP(*Game::localIP);
Party::Container.Target.SetType(Game::netadrtype_t::NA_IP);
Party::Container.target.setIP(*Game::localIP);
Party::Container.target.setType(Game::netadrtype_t::NA_IP);
Logger::Print("Trying to connect to party with loopback address, using a local ip instead: %s\n", Party::Container.Target.GetCString());
Logger::Print("Trying to connect to party with loopback address, using a local ip instead: %s\n", Party::Container.target.getCString());
}
else
{
@ -110,15 +110,15 @@ namespace Components
}
}
Party::LobbyMap[id.Bits] = Party::Container.Target;
Party::LobbyMap[id.Bits] = Party::Container.target;
Game::Steam_JoinLobby(id, 0);
}
void Party::PlaylistError(std::string error)
{
Party::Container.Valid = false;
Party::Container.AwaitingPlaylist = false;
Party::Container.valid = false;
Party::Container.awaitingPlaylist = false;
Party::ConnectError(error);
}
@ -135,8 +135,8 @@ namespace Components
Party::Party()
{
static Game::dvar_t* partyEnable = Dvar::Register<bool>("party_enable", Dedicated::IsEnabled(), Game::dvar_flag::DVAR_FLAG_NONE, "Enable party system").Get<Game::dvar_t*>();
Dvar::Register<bool>("xblive_privatematch", true, Game::dvar_flag::DVAR_FLAG_WRITEPROTECTED, "").Get<Game::dvar_t*>();
static Game::dvar_t* partyEnable = Dvar::Register<bool>("party_enable", Dedicated::IsEnabled(), Game::dvar_flag::DVAR_FLAG_NONE, "Enable party system").get<Game::dvar_t*>();
Dvar::Register<bool>("xblive_privatematch", true, Game::dvar_flag::DVAR_FLAG_WRITEPROTECTED, "").get<Game::dvar_t*>();
// various changes to SV_DirectConnect-y stuff to allow non-party joinees
Utils::Hook::Set<WORD>(0x460D96, 0x90E9);
@ -202,7 +202,7 @@ namespace Components
Utils::Hook::Nop(0x5A8E33, 11);
// Enable XP Bar
Utils::Hook(0x62A2A7, Party::UIDvarIntStub, HOOK_CALL).Install()->Quick();
Utils::Hook(0x62A2A7, Party::UIDvarIntStub, HOOK_CALL).install()->quick();
// Set NAT to open
Utils::Hook::Set<int>(0x79D898, 1);
@ -225,7 +225,7 @@ namespace Components
//Utils::Hook::Set<BYTE>(0x5B71CD, 0xEB);
// Patch party_minplayers to 1 and protect it
//Utils::Hook(0x4D5D51, Party::RegisterMinPlayers, HOOK_CALL).Install()->Quick();
//Utils::Hook(0x4D5D51, Party::RegisterMinPlayers, HOOK_CALL).install()->quick();
// Set ui_maxclients to sv_maxclients
Utils::Hook::Set<char*>(0x42618F, "sv_maxclients");
@ -245,7 +245,7 @@ namespace Components
Command::Add("connect", [] (Command::Params params)
{
if (params.Length() < 2)
if (params.length() < 2)
{
return;
}
@ -254,25 +254,25 @@ namespace Components
});
Command::Add("reconnect", [] (Command::Params)
{
Party::Connect(Party::Container.Target);
Party::Connect(Party::Container.target);
});
Renderer::OnFrame([] ()
{
if (Party::Container.Valid)
if (Party::Container.valid)
{
if ((Game::Sys_Milliseconds() - Party::Container.JoinTime) > 5000)
if ((Game::Sys_Milliseconds() - Party::Container.joinTime) > 5000)
{
Party::Container.Valid = false;
Party::Container.valid = false;
Party::ConnectError("Server connection timed out.");
}
}
if (Party::Container.AwaitingPlaylist)
if (Party::Container.awaitingPlaylist)
{
if ((Game::Sys_Milliseconds() - Party::Container.RequestTime) > 5000)
if ((Game::Sys_Milliseconds() - Party::Container.requestTime) > 5000)
{
Party::Container.AwaitingPlaylist = false;
Party::Container.awaitingPlaylist = false;
Party::ConnectError("Playlist request timed out.");
}
}
@ -296,33 +296,33 @@ namespace Components
}
else
{
//maxclientCount = Dvar::Var("sv_maxclients").Get<int>();
//maxclientCount = Dvar::Var("sv_maxclients").get<int>();
maxclientCount = Game::Party_GetMaxPlayers(*Game::partyIngame);
clientCount = Game::PartyHost_CountMembers(reinterpret_cast<Game::PartyData_s*>(0x1081C00));
}
Utils::InfoString info;
info.Set("challenge", Utils::ParseChallenge(data));
info.Set("gamename", "IW4");
info.Set("hostname", Dvar::Var("sv_hostname").Get<const char*>());
info.Set("gametype", Dvar::Var("g_gametype").Get<const char*>());
info.Set("fs_game", Dvar::Var("fs_game").Get<const char*>());
info.Set("xuid", fmt::sprintf("%llX", Steam::SteamUser()->GetSteamID().Bits));
info.Set("clients", fmt::sprintf("%i", clientCount));
info.Set("sv_maxclients", fmt::sprintf("%i", maxclientCount));
info.Set("protocol", fmt::sprintf("%i", PROTOCOL));
info.Set("shortversion", SHORTVERSION);
info.Set("checksum", fmt::sprintf("%d", Game::Sys_Milliseconds()));
info.Set("mapname", Dvar::Var("mapname").Get<const char*>());
info.Set("isPrivate", (Dvar::Var("g_password").Get<std::string>().size() ? "1" : "0"));
info.Set("hc", (Dvar::Var("g_hardcore").Get<bool>() ? "1" : "0"));
info.Set("securityLevel", fmt::sprintf("%i", Dvar::Var("sv_securityLevel").Get<int>()));
info.Set("sv_running", (Dvar::Var("sv_running").Get<bool>() ? "1" : "0"));
info.set("challenge", Utils::ParseChallenge(data));
info.set("gamename", "IW4");
info.set("hostname", Dvar::Var("sv_hostname").get<const char*>());
info.set("gametype", Dvar::Var("g_gametype").get<const char*>());
info.set("fs_game", Dvar::Var("fs_game").get<const char*>());
info.set("xuid", fmt::sprintf("%llX", Steam::SteamUser()->GetSteamID().Bits));
info.set("clients", fmt::sprintf("%i", clientCount));
info.set("sv_maxclients", fmt::sprintf("%i", maxclientCount));
info.set("protocol", fmt::sprintf("%i", PROTOCOL));
info.set("shortversion", SHORTVERSION);
info.set("checksum", fmt::sprintf("%d", Game::Sys_Milliseconds()));
info.set("mapname", Dvar::Var("mapname").get<const char*>());
info.set("isPrivate", (Dvar::Var("g_password").get<std::string>().size() ? "1" : "0"));
info.set("hc", (Dvar::Var("g_hardcore").get<bool>() ? "1" : "0"));
info.set("securityLevel", fmt::sprintf("%i", Dvar::Var("sv_securityLevel").get<int>()));
info.set("sv_running", (Dvar::Var("sv_running").get<bool>() ? "1" : "0"));
// Ensure mapname is set
if (info.Get("mapname").empty() || (Dvar::Var("party_enable").Get<bool>() && Dvar::Var("party_host").Get<bool>() && !Dvar::Var("sv_running").Get<bool>()))
if (info.get("mapname").empty() || (Dvar::Var("party_enable").get<bool>() && Dvar::Var("party_host").get<bool>() && !Dvar::Var("sv_running").get<bool>()))
{
info.Set("mapname", Dvar::Var("ui_mapname").Get<const char*>());
info.set("mapname", Dvar::Var("ui_mapname").get<const char*>());
}
// Set matchtype
@ -330,20 +330,20 @@ namespace Components
// 1 - Party, use Steam_JoinLobby to connect
// 2 - Match, use CL_ConnectFromParty to connect
if (Dvar::Var("party_enable").Get<bool>() && Dvar::Var("party_host").Get<bool>()) // Party hosting
if (Dvar::Var("party_enable").get<bool>() && Dvar::Var("party_host").get<bool>()) // Party hosting
{
info.Set("matchtype", "1");
info.set("matchtype", "1");
}
else if (Dvar::Var("sv_running").Get<bool>()) // Match hosting
else if (Dvar::Var("sv_running").get<bool>()) // Match hosting
{
info.Set("matchtype", "2");
info.set("matchtype", "2");
}
else
{
info.Set("matchtype", "0");
info.set("matchtype", "0");
}
Network::SendCommand(address, "infoResponse", "\\" + info.Build());
Network::SendCommand(address, "infoResponse", "\\" + info.build());
});
Network::Handle("infoResponse", [] (Network::Address address, std::string data)
@ -351,18 +351,18 @@ namespace Components
Utils::InfoString info(data);
// Handle connection
if (Party::Container.Valid)
if (Party::Container.valid)
{
if (Party::Container.Target == address)
if (Party::Container.target == address)
{
// Invalidate handler for future packets
Party::Container.Valid = false;
Party::Container.Info = info;
Party::Container.valid = false;
Party::Container.info = info;
Party::Container.MatchType = atoi(info.Get("matchtype").data());
uint32_t securityLevel = static_cast<uint32_t>(atoi(info.Get("securityLevel").data()));
Party::Container.matchType = atoi(info.get("matchtype").data());
uint32_t securityLevel = static_cast<uint32_t>(atoi(info.get("securityLevel").data()));
if (info.Get("challenge") != Party::Container.Challenge)
if (info.get("challenge") != Party::Container.challenge)
{
Party::ConnectError("Invalid join response: Challenge mismatch.");
}
@ -372,24 +372,24 @@ namespace Components
Command::Execute("closemenu popup_reconnectingtoparty");
Auth::IncreaseSecurityLevel(securityLevel, "reconnect");
}
else if (!Party::Container.MatchType)
else if (!Party::Container.matchType)
{
Party::ConnectError("Server is not hosting a match.");
}
else if(Party::Container.MatchType > 2 || Party::Container.MatchType < 0)
else if(Party::Container.matchType > 2 || Party::Container.matchType < 0)
{
Party::ConnectError("Invalid join response: Unknown matchtype");
}
else if(!info.Get("fs_game").empty() && Utils::String::ToLower(Dvar::Var("fs_game").Get<std::string>()) != Utils::String::ToLower(info.Get("fs_game")))
else if(!info.get("fs_game").empty() && Utils::String::ToLower(Dvar::Var("fs_game").get<std::string>()) != Utils::String::ToLower(info.get("fs_game")))
{
Command::Execute("closemenu popup_reconnectingtoparty");
Download::InitiateClientDownload(info.Get("fs_game"));
Download::InitiateClientDownload(info.get("fs_game"));
}
else if (!Dvar::Var("fs_game").Get<std::string>().empty() && info.Get("fs_game").empty())
else if (!Dvar::Var("fs_game").get<std::string>().empty() && info.get("fs_game").empty())
{
Dvar::Var("fs_game").Set("");
Dvar::Var("fs_game").set("");
if (Dvar::Var("cl_modVidRestart").Get<bool>())
if (Dvar::Var("cl_modVidRestart").get<bool>())
{
Command::Execute("vid_restart", false);
}
@ -398,12 +398,12 @@ namespace Components
}
else
{
if (Party::Container.MatchType == 1) // Party
if (Party::Container.matchType == 1) // Party
{
// Send playlist request
Party::Container.RequestTime = Game::Sys_Milliseconds();
Party::Container.AwaitingPlaylist = true;
Network::SendCommand(Party::Container.Target, "getplaylist");
Party::Container.requestTime = Game::Sys_Milliseconds();
Party::Container.awaitingPlaylist = true;
Network::SendCommand(Party::Container.target, "getplaylist");
// This is not a safe method
// TODO: Fix actual error!
@ -412,24 +412,24 @@ namespace Components
Command::Execute("disconnect", true);
}
}
else if (Party::Container.MatchType == 2) // Match
else if (Party::Container.matchType == 2) // Match
{
if (atoi(Party::Container.Info.Get("clients").data()) >= atoi(Party::Container.Info.Get("sv_maxclients").data()))
if (atoi(Party::Container.info.get("clients").data()) >= atoi(Party::Container.info.get("sv_maxclients").data()))
{
Party::ConnectError("@EXE_SERVERISFULL");
}
if (Party::Container.Info.Get("mapname") == "" || Party::Container.Info.Get("gametype") == "")
if (Party::Container.info.get("mapname") == "" || Party::Container.info.get("gametype") == "")
{
Party::ConnectError("Invalid map or gametype.");
}
else
{
Dvar::Var("xblive_privateserver").Set(true);
Dvar::Var("xblive_privateserver").set(true);
Game::Menus_CloseAll(Game::uiContext);
Game::_XSESSION_INFO hostInfo;
Game::CL_ConnectFromParty(0, &hostInfo, *Party::Container.Target.Get(), 0, 0, Party::Container.Info.Get("mapname").data(), Party::Container.Info.Get("gametype").data());
Game::CL_ConnectFromParty(0, &hostInfo, *Party::Container.target.get(), 0, 0, Party::Container.info.get("mapname").data(), Party::Container.info.get("gametype").data());
}
}
}

View File

@ -7,7 +7,7 @@ namespace Components
~Party();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* GetName() { return "Party"; };
const char* getName() { return "Party"; };
#endif
static Network::Address Target();
@ -25,17 +25,17 @@ namespace Components
class JoinContainer
{
public:
Network::Address Target;
std::string Challenge;
DWORD JoinTime;
bool Valid;
int MatchType;
Network::Address target;
std::string challenge;
DWORD joinTime;
bool valid;
int matchType;
Utils::InfoString Info;
Utils::InfoString info;
// Party-specific stuff
DWORD RequestTime;
bool AwaitingPlaylist;
DWORD requestTime;
bool awaitingPlaylist;
};
static JoinContainer Container;

Some files were not shown because too many files have changed in this diff Show More