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)
|
||||
{
|
||||
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 security token is: {}\n", Utils::String::DumpHex(Auth::GuidToken.toString(), ""));
|
||||
Logger::Print("Your computation token is: {}\n", Utils::String::DumpHex(Auth::ComputeToken.toString(), ""));
|
||||
@ -466,7 +466,7 @@ namespace Components
|
||||
}
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
@ -60,7 +60,15 @@ namespace Components
|
||||
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);
|
||||
|
||||
@ -72,7 +80,7 @@ namespace Components
|
||||
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())
|
||||
{
|
||||
|
@ -51,8 +51,9 @@ namespace Components
|
||||
|
||||
static Game::cmd_function_t* Allocate();
|
||||
|
||||
static void Add(const char* name, std::function<void(Command::Params*)> callback);
|
||||
static void AddSV(const char* name, std::function<void(Command::Params*)> callback);
|
||||
static void Add(const char* name, const std::function<void()>& 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 AddRawSV(const char* name, void(*callback)());
|
||||
static void Execute(std::string command, bool sync = true);
|
||||
|
@ -589,7 +589,7 @@ namespace Components
|
||||
|
||||
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));
|
||||
return;
|
||||
|
@ -503,10 +503,7 @@ namespace Components
|
||||
// Ignore call to print 'Offhand class mismatch when giving weapon...'
|
||||
Utils::Hook(0x5D9047, 0x4BB9B0, HOOK_CALL).install()->quick();
|
||||
|
||||
Command::Add("unlockstats", [](Command::Params*)
|
||||
{
|
||||
QuickPatch::UnlockStats();
|
||||
});
|
||||
Command::Add("unlockstats", QuickPatch::UnlockStats);
|
||||
|
||||
Command::Add("dumptechsets", [](Command::Params* param)
|
||||
{
|
||||
@ -515,23 +512,26 @@ namespace Components
|
||||
Logger::Print("usage: dumptechsets <fastfile> | all\n");
|
||||
return;
|
||||
}
|
||||
std::vector<std::string> fastfiles;
|
||||
|
||||
std::vector<std::string> fastFiles;
|
||||
|
||||
if (param->get(1) == "all"s)
|
||||
{
|
||||
for (std::string f : Utils::IO::ListFiles("zone/english"))
|
||||
fastfiles.push_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 (std::string f : Utils::IO::ListFiles("zone/patch"))
|
||||
fastfiles.push_back(f.substr(5, f.length() - 8));
|
||||
for (const auto& f : Utils::IO::ListFiles("zone/english"))
|
||||
fastFiles.emplace_back(f.substr(7, f.length() - 10));
|
||||
|
||||
for (const auto& f : Utils::IO::ListFiles("zone/dlc"))
|
||||
fastFiles.emplace_back(f.substr(3, f.length() - 6));
|
||||
|
||||
for (const auto& f : Utils::IO::ListFiles("zone/patch"))
|
||||
fastFiles.emplace_back(f.substr(5, f.length() - 8));
|
||||
}
|
||||
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*/)
|
||||
{
|
||||
@ -553,7 +553,7 @@ namespace Components
|
||||
if (Utils::IO::FileExists(Utils::String::VA(formatString, name.data()))) return;
|
||||
|
||||
Utils::Stream buffer(0x1000);
|
||||
Game::MaterialPixelShader* dest = buffer.dest<Game::MaterialPixelShader>();
|
||||
auto* dest = buffer.dest<Game::MaterialPixelShader>();
|
||||
buffer.save(asset.pixelShader);
|
||||
|
||||
if (asset.pixelShader->prog.loadDef.program)
|
||||
@ -565,31 +565,6 @@ namespace Components
|
||||
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)
|
||||
{
|
||||
Utils::IO::CreateDir("userraw/techsets");
|
||||
@ -609,59 +584,54 @@ namespace Components
|
||||
|
||||
if (technique)
|
||||
{
|
||||
dest->techniques[i] = reinterpret_cast<Game::MaterialTechnique*>(getPointer(technique));
|
||||
if (!dest->techniques)
|
||||
// Size-check is obsolete, as the structure is dynamic
|
||||
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
|
||||
buffer.align(Utils::Stream::ALIGN_4);
|
||||
//storePointer(technique, buffer->);
|
||||
AssertSize(Game::MaterialPass, 20);
|
||||
|
||||
Game::MaterialTechnique* destTechnique = buffer.dest<Game::MaterialTechnique>();
|
||||
buffer.save(technique, 8);
|
||||
Game::MaterialPass* destPass = &destPasses[j];
|
||||
Game::MaterialPass* pass = &technique->passArray[j];
|
||||
|
||||
// Save_MaterialPassArray
|
||||
Game::MaterialPass* destPasses = buffer.dest<Game::MaterialPass>();
|
||||
buffer.saveArray(technique->passArray, technique->passCount);
|
||||
|
||||
for (short j = 0; j < technique->passCount; ++j)
|
||||
if (pass->vertexDecl)
|
||||
{
|
||||
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);
|
||||
Utils::Stream::ClearPointer(&destTechnique->name);
|
||||
buffer.align(Utils::Stream::ALIGN_4);
|
||||
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;
|
||||
info.name = fastfile.data();
|
||||
info.name = fastFile.data();
|
||||
info.allocFlags = 0x20;
|
||||
info.freeFlags = 0;
|
||||
|
||||
|
@ -7,7 +7,7 @@ namespace Components
|
||||
|
||||
bool ZoneBuilder::MainThreadInterrupted;
|
||||
DWORD ZoneBuilder::InterruptingThreadId;
|
||||
bool ZoneBuilder::Terminate;
|
||||
volatile bool ZoneBuilder::Terminate = false;
|
||||
std::thread ZoneBuilder::CommandThread;
|
||||
|
||||
Dvar::Var ZoneBuilder::PreferDiskAssetsDvar;
|
||||
@ -801,7 +801,12 @@ namespace Components
|
||||
{ "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()>(0x4301B0)(); // Com_InitMainThread
|
||||
@ -835,8 +840,7 @@ namespace Components
|
||||
//Utils::Hook::Call<void()>(0x464A90)(); // Com_ParseCommandLine
|
||||
Utils::Hook::Call<void()>(0x43D140)(); // Com_EventLoop
|
||||
|
||||
ZoneBuilder::Terminate = false;
|
||||
ZoneBuilder::CommandThread = std::thread([]()
|
||||
ZoneBuilder::CommandThread = std::thread([]
|
||||
{
|
||||
while (!ZoneBuilder::Terminate)
|
||||
{
|
||||
@ -847,10 +851,7 @@ namespace Components
|
||||
}
|
||||
});
|
||||
|
||||
Command::Add("quit", []([[maybe_unused]] Command::Params* params)
|
||||
{
|
||||
Game::Com_Quitf_t();
|
||||
});
|
||||
Command::Add("quit", ZoneBuilder::Com_Quitf_t);
|
||||
|
||||
// now load default assets and shaders
|
||||
if (FastFiles::Exists("defaults") && FastFiles::Exists("techsets"))
|
||||
@ -1085,6 +1086,9 @@ namespace Components
|
||||
// set new entry point
|
||||
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
|
||||
Utils::Hook(Game::Com_Error, ZoneBuilder::HandleError, HOOK_JUMP).install()->quick();
|
||||
|
||||
@ -1535,7 +1539,7 @@ namespace Components
|
||||
ZoneBuilder::~ZoneBuilder()
|
||||
{
|
||||
ZoneBuilder::Terminate = true;
|
||||
if(ZoneBuilder::CommandThread.joinable())
|
||||
if (ZoneBuilder::CommandThread.joinable())
|
||||
{
|
||||
ZoneBuilder::CommandThread.join();
|
||||
}
|
||||
|
@ -147,10 +147,12 @@ namespace Components
|
||||
|
||||
static bool IsThreadMainThreadHook();
|
||||
|
||||
static void Com_Quitf_t();
|
||||
|
||||
static bool MainThreadInterrupted;
|
||||
static DWORD InterruptingThreadId;
|
||||
|
||||
static bool Terminate;
|
||||
static volatile bool Terminate;
|
||||
static std::thread CommandThread;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user