Revert change to ZoneBuilder
& Add simple callback function to add commands
This commit is contained in:
parent
020201ab1f
commit
b720166913
@ -457,7 +457,7 @@ namespace Components
|
|||||||
{
|
{
|
||||||
if (params->size() < 2)
|
if (params->size() < 2)
|
||||||
{
|
{
|
||||||
uint32_t level = Auth::GetZeroBits(Auth::GuidToken, Auth::GuidKey.getPublicKey());
|
const auto level = Auth::GetZeroBits(Auth::GuidToken, Auth::GuidKey.getPublicKey());
|
||||||
Logger::Print("Your current security level is {}\n", level);
|
Logger::Print("Your current security level is {}\n", level);
|
||||||
Logger::Print("Your security token is: {}\n", Utils::String::DumpHex(Auth::GuidToken.toString(), ""));
|
Logger::Print("Your security token is: {}\n", Utils::String::DumpHex(Auth::GuidToken.toString(), ""));
|
||||||
Logger::Print("Your computation token is: {}\n", Utils::String::DumpHex(Auth::ComputeToken.toString(), ""));
|
Logger::Print("Your computation token is: {}\n", Utils::String::DumpHex(Auth::ComputeToken.toString(), ""));
|
||||||
@ -466,7 +466,7 @@ namespace Components
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint32_t level = static_cast<uint32_t>(atoi(params->get(1)));
|
const auto level = static_cast<uint32_t>(atoi(params->get(1)));
|
||||||
Auth::IncreaseSecurityLevel(level);
|
Auth::IncreaseSecurityLevel(level);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -60,7 +60,15 @@ namespace Components
|
|||||||
return Game::sv_cmd_args->argv[this->nesting_][index];
|
return Game::sv_cmd_args->argv[this->nesting_][index];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Command::Add(const char* name, std::function<void(Command::Params*)> callback)
|
void Command::Add(const char* name, const std::function<void()>& callback)
|
||||||
|
{
|
||||||
|
Add(name, [callback]([[maybe_unused]] const Command::Params* params)
|
||||||
|
{
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void Command::Add(const char* name, const std::function<void(Command::Params*)>& callback)
|
||||||
{
|
{
|
||||||
const auto command = Utils::String::ToLower(name);
|
const auto command = Utils::String::ToLower(name);
|
||||||
|
|
||||||
@ -72,7 +80,7 @@ namespace Components
|
|||||||
Command::FunctionMap.insert_or_assign(command, std::move(callback));
|
Command::FunctionMap.insert_or_assign(command, std::move(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Command::AddSV(const char* name, std::function<void(Command::Params*)> callback)
|
void Command::AddSV(const char* name, const std::function<void(Command::Params*)>& callback)
|
||||||
{
|
{
|
||||||
if (Loader::IsPregame())
|
if (Loader::IsPregame())
|
||||||
{
|
{
|
||||||
|
@ -51,8 +51,9 @@ namespace Components
|
|||||||
|
|
||||||
static Game::cmd_function_t* Allocate();
|
static Game::cmd_function_t* Allocate();
|
||||||
|
|
||||||
static void Add(const char* name, std::function<void(Command::Params*)> callback);
|
static void Add(const char* name, const std::function<void()>& callback);
|
||||||
static void AddSV(const char* name, std::function<void(Command::Params*)> callback);
|
static void Add(const char* name, const std::function<void(Command::Params*)>& callback);
|
||||||
|
static void AddSV(const char* name, const std::function<void(Command::Params*)>& callback);
|
||||||
static void AddRaw(const char* name, void(*callback)(), bool key = false);
|
static void AddRaw(const char* name, void(*callback)(), bool key = false);
|
||||||
static void AddRawSV(const char* name, void(*callback)());
|
static void AddRawSV(const char* name, void(*callback)());
|
||||||
static void Execute(std::string command, bool sync = true);
|
static void Execute(std::string command, bool sync = true);
|
||||||
|
@ -589,7 +589,7 @@ namespace Components
|
|||||||
|
|
||||||
Command::Add("addFriend", [](Command::Params* params)
|
Command::Add("addFriend", [](Command::Params* params)
|
||||||
{
|
{
|
||||||
if (params->size() < 2u)
|
if (params->size() < 2)
|
||||||
{
|
{
|
||||||
Logger::Print("Usage: {} <Steam ID in hexadecimal format>\n", params->get(0));
|
Logger::Print("Usage: {} <Steam ID in hexadecimal format>\n", params->get(0));
|
||||||
return;
|
return;
|
||||||
|
@ -503,10 +503,7 @@ namespace Components
|
|||||||
// Ignore call to print 'Offhand class mismatch when giving weapon...'
|
// Ignore call to print 'Offhand class mismatch when giving weapon...'
|
||||||
Utils::Hook(0x5D9047, 0x4BB9B0, HOOK_CALL).install()->quick();
|
Utils::Hook(0x5D9047, 0x4BB9B0, HOOK_CALL).install()->quick();
|
||||||
|
|
||||||
Command::Add("unlockstats", [](Command::Params*)
|
Command::Add("unlockstats", QuickPatch::UnlockStats);
|
||||||
{
|
|
||||||
QuickPatch::UnlockStats();
|
|
||||||
});
|
|
||||||
|
|
||||||
Command::Add("dumptechsets", [](Command::Params* param)
|
Command::Add("dumptechsets", [](Command::Params* param)
|
||||||
{
|
{
|
||||||
@ -515,23 +512,26 @@ namespace Components
|
|||||||
Logger::Print("usage: dumptechsets <fastfile> | all\n");
|
Logger::Print("usage: dumptechsets <fastfile> | all\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::vector<std::string> fastfiles;
|
|
||||||
|
std::vector<std::string> fastFiles;
|
||||||
|
|
||||||
if (param->get(1) == "all"s)
|
if (param->get(1) == "all"s)
|
||||||
{
|
{
|
||||||
for (std::string f : Utils::IO::ListFiles("zone/english"))
|
for (const auto& f : Utils::IO::ListFiles("zone/english"))
|
||||||
fastfiles.push_back(f.substr(7, f.length() - 10));
|
fastFiles.emplace_back(f.substr(7, f.length() - 10));
|
||||||
for (std::string f : Utils::IO::ListFiles("zone/dlc"))
|
|
||||||
fastfiles.push_back(f.substr(3, f.length() - 6));
|
for (const auto& f : Utils::IO::ListFiles("zone/dlc"))
|
||||||
for (std::string f : Utils::IO::ListFiles("zone/patch"))
|
fastFiles.emplace_back(f.substr(3, f.length() - 6));
|
||||||
fastfiles.push_back(f.substr(5, f.length() - 8));
|
|
||||||
|
for (const auto& f : Utils::IO::ListFiles("zone/patch"))
|
||||||
|
fastFiles.emplace_back(f.substr(5, f.length() - 8));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fastfiles.push_back(param->get(1));
|
fastFiles.emplace_back(param->get(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
int count = 0;
|
auto count = 0;
|
||||||
|
|
||||||
AssetHandler::OnLoad([](Game::XAssetType type, Game::XAssetHeader asset, const std::string& name, bool* /*restrict*/)
|
AssetHandler::OnLoad([](Game::XAssetType type, Game::XAssetHeader asset, const std::string& name, bool* /*restrict*/)
|
||||||
{
|
{
|
||||||
@ -553,7 +553,7 @@ namespace Components
|
|||||||
if (Utils::IO::FileExists(Utils::String::VA(formatString, name.data()))) return;
|
if (Utils::IO::FileExists(Utils::String::VA(formatString, name.data()))) return;
|
||||||
|
|
||||||
Utils::Stream buffer(0x1000);
|
Utils::Stream buffer(0x1000);
|
||||||
Game::MaterialPixelShader* dest = buffer.dest<Game::MaterialPixelShader>();
|
auto* dest = buffer.dest<Game::MaterialPixelShader>();
|
||||||
buffer.save(asset.pixelShader);
|
buffer.save(asset.pixelShader);
|
||||||
|
|
||||||
if (asset.pixelShader->prog.loadDef.program)
|
if (asset.pixelShader->prog.loadDef.program)
|
||||||
@ -565,31 +565,6 @@ namespace Components
|
|||||||
Utils::IO::WriteFile(Utils::String::VA(formatString, name.data()), buffer.toBuffer());
|
Utils::IO::WriteFile(Utils::String::VA(formatString, name.data()), buffer.toBuffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::map<const void*, unsigned int> pointerMap;
|
|
||||||
|
|
||||||
// Check if the given pointer has already been mapped
|
|
||||||
std::function<bool(const void*)> hasPointer = [](const void* pointer)
|
|
||||||
{
|
|
||||||
return (pointerMap.find(pointer) != pointerMap.end());
|
|
||||||
};
|
|
||||||
|
|
||||||
// Get stored offset for given file pointer
|
|
||||||
std::function<unsigned int(const void*)> getPointer = [hasPointer](const void* pointer)
|
|
||||||
{
|
|
||||||
if (hasPointer(pointer))
|
|
||||||
{
|
|
||||||
return pointerMap[pointer];
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0U;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::function<void(const void*, unsigned int)> storePointer = [hasPointer](const void* ptr, unsigned int offset)
|
|
||||||
{
|
|
||||||
if (hasPointer(ptr)) return;
|
|
||||||
pointerMap[ptr] = offset;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (type == Game::ASSET_TYPE_TECHNIQUE_SET)
|
if (type == Game::ASSET_TYPE_TECHNIQUE_SET)
|
||||||
{
|
{
|
||||||
Utils::IO::CreateDir("userraw/techsets");
|
Utils::IO::CreateDir("userraw/techsets");
|
||||||
@ -609,59 +584,54 @@ namespace Components
|
|||||||
|
|
||||||
if (technique)
|
if (technique)
|
||||||
{
|
{
|
||||||
dest->techniques[i] = reinterpret_cast<Game::MaterialTechnique*>(getPointer(technique));
|
// Size-check is obsolete, as the structure is dynamic
|
||||||
if (!dest->techniques)
|
buffer.align(Utils::Stream::ALIGN_4);
|
||||||
|
|
||||||
|
Game::MaterialTechnique* destTechnique = buffer.dest<Game::MaterialTechnique>();
|
||||||
|
buffer.save(technique, 8);
|
||||||
|
|
||||||
|
// Save_MaterialPassArray
|
||||||
|
Game::MaterialPass* destPasses = buffer.dest<Game::MaterialPass>();
|
||||||
|
buffer.saveArray(technique->passArray, technique->passCount);
|
||||||
|
|
||||||
|
for (std::uint16_t j = 0; j < technique->passCount; ++j)
|
||||||
{
|
{
|
||||||
// Size-check is obsolete, as the structure is dynamic
|
AssertSize(Game::MaterialPass, 20);
|
||||||
buffer.align(Utils::Stream::ALIGN_4);
|
|
||||||
//storePointer(technique, buffer->);
|
|
||||||
|
|
||||||
Game::MaterialTechnique* destTechnique = buffer.dest<Game::MaterialTechnique>();
|
Game::MaterialPass* destPass = &destPasses[j];
|
||||||
buffer.save(technique, 8);
|
Game::MaterialPass* pass = &technique->passArray[j];
|
||||||
|
|
||||||
// Save_MaterialPassArray
|
if (pass->vertexDecl)
|
||||||
Game::MaterialPass* destPasses = buffer.dest<Game::MaterialPass>();
|
|
||||||
buffer.saveArray(technique->passArray, technique->passCount);
|
|
||||||
|
|
||||||
for (short j = 0; j < technique->passCount; ++j)
|
|
||||||
{
|
{
|
||||||
AssertSize(Game::MaterialPass, 20);
|
|
||||||
|
|
||||||
Game::MaterialPass* destPass = &destPasses[j];
|
|
||||||
Game::MaterialPass* pass = &technique->passArray[j];
|
|
||||||
|
|
||||||
if (pass->vertexDecl)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pass->args)
|
|
||||||
{
|
|
||||||
buffer.align(Utils::Stream::ALIGN_4);
|
|
||||||
buffer.saveArray(pass->args, pass->perPrimArgCount + pass->perObjArgCount + pass->stableArgCount);
|
|
||||||
Utils::Stream::ClearPointer(&destPass->args);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (technique->name)
|
if (pass->args)
|
||||||
{
|
{
|
||||||
buffer.saveString(technique->name);
|
buffer.align(Utils::Stream::ALIGN_4);
|
||||||
Utils::Stream::ClearPointer(&destTechnique->name);
|
buffer.saveArray(pass->args, pass->perPrimArgCount + pass->perObjArgCount + pass->stableArgCount);
|
||||||
|
Utils::Stream::ClearPointer(&destPass->args);
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::Stream::ClearPointer(&dest->techniques[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (technique->name)
|
||||||
|
{
|
||||||
|
buffer.saveString(technique->name);
|
||||||
|
Utils::Stream::ClearPointer(&destTechnique->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
Utils::Stream::ClearPointer(&dest->techniques[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (std::string fastfile : fastfiles)
|
for (const auto& fastFile : fastFiles)
|
||||||
{
|
{
|
||||||
if (!Game::DB_IsZoneLoaded(fastfile.data()))
|
if (!Game::DB_IsZoneLoaded(fastFile.data()))
|
||||||
{
|
{
|
||||||
Game::XZoneInfo info;
|
Game::XZoneInfo info;
|
||||||
info.name = fastfile.data();
|
info.name = fastFile.data();
|
||||||
info.allocFlags = 0x20;
|
info.allocFlags = 0x20;
|
||||||
info.freeFlags = 0;
|
info.freeFlags = 0;
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ namespace Components
|
|||||||
|
|
||||||
bool ZoneBuilder::MainThreadInterrupted;
|
bool ZoneBuilder::MainThreadInterrupted;
|
||||||
DWORD ZoneBuilder::InterruptingThreadId;
|
DWORD ZoneBuilder::InterruptingThreadId;
|
||||||
bool ZoneBuilder::Terminate;
|
volatile bool ZoneBuilder::Terminate = false;
|
||||||
std::thread ZoneBuilder::CommandThread;
|
std::thread ZoneBuilder::CommandThread;
|
||||||
|
|
||||||
Dvar::Var ZoneBuilder::PreferDiskAssetsDvar;
|
Dvar::Var ZoneBuilder::PreferDiskAssetsDvar;
|
||||||
@ -801,7 +801,12 @@ namespace Components
|
|||||||
{ "localized_ui_mp", Game::DB_ZONE_GAME, 0 }
|
{ "localized_ui_mp", Game::DB_ZONE_GAME, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
int __stdcall ZoneBuilder::EntryPoint(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nShowCmd*/)
|
void ZoneBuilder::Com_Quitf_t()
|
||||||
|
{
|
||||||
|
ExitProcess(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int APIENTRY ZoneBuilder::EntryPoint(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nShowCmd*/)
|
||||||
{
|
{
|
||||||
Utils::Hook::Call<void()>(0x42F0A0)(); // Com_InitCriticalSections
|
Utils::Hook::Call<void()>(0x42F0A0)(); // Com_InitCriticalSections
|
||||||
Utils::Hook::Call<void()>(0x4301B0)(); // Com_InitMainThread
|
Utils::Hook::Call<void()>(0x4301B0)(); // Com_InitMainThread
|
||||||
@ -835,8 +840,7 @@ namespace Components
|
|||||||
//Utils::Hook::Call<void()>(0x464A90)(); // Com_ParseCommandLine
|
//Utils::Hook::Call<void()>(0x464A90)(); // Com_ParseCommandLine
|
||||||
Utils::Hook::Call<void()>(0x43D140)(); // Com_EventLoop
|
Utils::Hook::Call<void()>(0x43D140)(); // Com_EventLoop
|
||||||
|
|
||||||
ZoneBuilder::Terminate = false;
|
ZoneBuilder::CommandThread = std::thread([]
|
||||||
ZoneBuilder::CommandThread = std::thread([]()
|
|
||||||
{
|
{
|
||||||
while (!ZoneBuilder::Terminate)
|
while (!ZoneBuilder::Terminate)
|
||||||
{
|
{
|
||||||
@ -847,10 +851,7 @@ namespace Components
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Command::Add("quit", []([[maybe_unused]] Command::Params* params)
|
Command::Add("quit", ZoneBuilder::Com_Quitf_t);
|
||||||
{
|
|
||||||
Game::Com_Quitf_t();
|
|
||||||
});
|
|
||||||
|
|
||||||
// now load default assets and shaders
|
// now load default assets and shaders
|
||||||
if (FastFiles::Exists("defaults") && FastFiles::Exists("techsets"))
|
if (FastFiles::Exists("defaults") && FastFiles::Exists("techsets"))
|
||||||
@ -1085,6 +1086,9 @@ namespace Components
|
|||||||
// set new entry point
|
// set new entry point
|
||||||
Utils::Hook(0x4513DA, ZoneBuilder::EntryPoint, HOOK_JUMP).install()->quick();
|
Utils::Hook(0x4513DA, ZoneBuilder::EntryPoint, HOOK_JUMP).install()->quick();
|
||||||
|
|
||||||
|
// set quit handler
|
||||||
|
Utils::Hook(0x4D4000, ZoneBuilder::Com_Quitf_t, HOOK_JUMP).install()->quick();
|
||||||
|
|
||||||
// handle Com_error Calls
|
// handle Com_error Calls
|
||||||
Utils::Hook(Game::Com_Error, ZoneBuilder::HandleError, HOOK_JUMP).install()->quick();
|
Utils::Hook(Game::Com_Error, ZoneBuilder::HandleError, HOOK_JUMP).install()->quick();
|
||||||
|
|
||||||
@ -1535,7 +1539,7 @@ namespace Components
|
|||||||
ZoneBuilder::~ZoneBuilder()
|
ZoneBuilder::~ZoneBuilder()
|
||||||
{
|
{
|
||||||
ZoneBuilder::Terminate = true;
|
ZoneBuilder::Terminate = true;
|
||||||
if(ZoneBuilder::CommandThread.joinable())
|
if (ZoneBuilder::CommandThread.joinable())
|
||||||
{
|
{
|
||||||
ZoneBuilder::CommandThread.join();
|
ZoneBuilder::CommandThread.join();
|
||||||
}
|
}
|
||||||
|
@ -147,10 +147,12 @@ namespace Components
|
|||||||
|
|
||||||
static bool IsThreadMainThreadHook();
|
static bool IsThreadMainThreadHook();
|
||||||
|
|
||||||
|
static void Com_Quitf_t();
|
||||||
|
|
||||||
static bool MainThreadInterrupted;
|
static bool MainThreadInterrupted;
|
||||||
static DWORD InterruptingThreadId;
|
static DWORD InterruptingThreadId;
|
||||||
|
|
||||||
static bool Terminate;
|
static volatile bool Terminate;
|
||||||
static std::thread CommandThread;
|
static std::thread CommandThread;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user