Merge branch 'master'
This commit is contained in:
commit
0d5183b31d
@ -6,6 +6,8 @@ namespace Components
|
||||
|
||||
void Colors::Strip(const char* in, char* out, int max)
|
||||
{
|
||||
if (!in || !out) return;
|
||||
|
||||
max--;
|
||||
int current = 0;
|
||||
while (*in != 0 && current < max)
|
||||
@ -18,9 +20,9 @@ namespace Components
|
||||
}
|
||||
else
|
||||
{
|
||||
*in++;
|
||||
in++;
|
||||
}
|
||||
*in++;
|
||||
in++;
|
||||
}
|
||||
*out = '\0';
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ namespace Components
|
||||
|
||||
void Maps::LoadMapZones(Game::XZoneInfo *zoneInfo, unsigned int zoneCount, int sync)
|
||||
{
|
||||
if (!zoneInfo) return;
|
||||
|
||||
Maps::CurrentDependencies.clear();
|
||||
for (auto i = Maps::DependencyList.begin(); i != Maps::DependencyList.end(); i++)
|
||||
{
|
||||
@ -24,19 +26,25 @@ namespace Components
|
||||
}
|
||||
}
|
||||
|
||||
Game::XZoneInfo* data = new Game::XZoneInfo[zoneCount + Maps::CurrentDependencies.size()];
|
||||
memcpy(data, zoneInfo, sizeof(Game::XZoneInfo) * zoneCount);
|
||||
std::vector<Game::XZoneInfo> data;
|
||||
|
||||
for (unsigned int i = 0; i < zoneCount; i++)
|
||||
{
|
||||
data.push_back(zoneInfo[i]);
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < Maps::CurrentDependencies.size(); i++)
|
||||
{
|
||||
data[zoneCount + i].name = (&Maps::CurrentDependencies[i])->data();
|
||||
data[zoneCount + i].allocFlags = data->allocFlags;
|
||||
data[zoneCount + i].freeFlags = data->freeFlags;
|
||||
Game::XZoneInfo info;
|
||||
|
||||
info.name = (&Maps::CurrentDependencies[i])->data();
|
||||
info.allocFlags = zoneInfo->allocFlags;
|
||||
info.freeFlags = zoneInfo->freeFlags;
|
||||
|
||||
data.push_back(info);
|
||||
}
|
||||
|
||||
Game::DB_LoadXAssets(data, zoneCount + Maps::CurrentDependencies.size(), sync);
|
||||
|
||||
delete[] data;
|
||||
Game::DB_LoadXAssets(data.data(), data.size(), sync);
|
||||
}
|
||||
|
||||
bool Maps::LoadAssetRestrict(Game::XAssetType type, Game::XAssetHeader asset, const char* name)
|
||||
|
@ -69,6 +69,11 @@ namespace Components
|
||||
script->next = NULL;
|
||||
|
||||
source = (Game::source_t *)calloc(1, sizeof(Game::source_t));
|
||||
if (!source)
|
||||
{
|
||||
Game::FreeMemory(script);
|
||||
return 0;
|
||||
}
|
||||
|
||||
strncpy(source->filename, "string", 64);
|
||||
source->scriptstack = script;
|
||||
@ -111,7 +116,15 @@ namespace Components
|
||||
Game::menuDef_t* Menus::ParseMenu(int handle)
|
||||
{
|
||||
Game::menuDef_t* menu = (Game::menuDef_t*)calloc(1, sizeof(Game::menuDef_t));
|
||||
if (!menu) return nullptr;
|
||||
|
||||
menu->items = (Game::itemDef_t**)calloc(512, sizeof(Game::itemDef_t*));
|
||||
if (!menu->items)
|
||||
{
|
||||
free(menu);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Menus::MenuList.push_back(menu);
|
||||
|
||||
Game::pc_token_t token;
|
||||
@ -187,7 +200,8 @@ namespace Components
|
||||
|
||||
if (!_stricmp(token.string, "menudef"))
|
||||
{
|
||||
menus.push_back(Menus::ParseMenu(handle));
|
||||
Game::menuDef_t* menudef = Menus::ParseMenu(handle);
|
||||
if (menudef) menus.push_back(menudef);
|
||||
}
|
||||
}
|
||||
|
||||
@ -217,8 +231,16 @@ namespace Components
|
||||
|
||||
// Allocate new menu list
|
||||
Game::MenuList* newList = (Game::MenuList*)calloc(1, sizeof(Game::MenuList));
|
||||
newList->name = _strdup(menu);
|
||||
if (!newList) return nullptr;
|
||||
|
||||
newList->menus = (Game::menuDef_t **)calloc(menus.size(), sizeof(Game::menuDef_t *));
|
||||
if (!newList->menus)
|
||||
{
|
||||
free(newList);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
newList->name = _strdup(menu);
|
||||
newList->menuCount = menus.size();
|
||||
|
||||
// Copy new menus
|
||||
@ -254,8 +276,16 @@ namespace Components
|
||||
|
||||
// Allocate new menu list
|
||||
Game::MenuList* newList = (Game::MenuList*)calloc(1, sizeof(Game::MenuList));
|
||||
newList->name = _strdup(menuList->name);
|
||||
if (!newList) return menuList;
|
||||
|
||||
newList->menus = (Game::menuDef_t **)calloc(menus.size(), sizeof(Game::menuDef_t *));
|
||||
if (!newList->menus)
|
||||
{
|
||||
free(newList);
|
||||
return menuList;
|
||||
}
|
||||
|
||||
newList->name = _strdup(menuList->name);
|
||||
newList->menuCount = menus.size();
|
||||
|
||||
// Copy new menus
|
||||
@ -335,20 +365,22 @@ namespace Components
|
||||
|
||||
void Menus::FreeMenuList(Game::MenuList* menuList)
|
||||
{
|
||||
if (menuList)
|
||||
if (!menuList) return;
|
||||
|
||||
// Keep our compiler happy
|
||||
Game::MenuList list = { menuList->name, menuList->menuCount, menuList->menus };
|
||||
|
||||
if (list.name)
|
||||
{
|
||||
if (menuList->name)
|
||||
{
|
||||
free((void*)menuList->name);
|
||||
}
|
||||
|
||||
if (menuList->menus)
|
||||
{
|
||||
free(menuList->menus);
|
||||
}
|
||||
|
||||
free(menuList);
|
||||
free(list.name);
|
||||
}
|
||||
|
||||
if (list.menus)
|
||||
{
|
||||
free(list.menus);
|
||||
}
|
||||
|
||||
free(menuList);
|
||||
}
|
||||
|
||||
void Menus::RemoveMenu(Game::menuDef_t* menudef)
|
||||
@ -498,7 +530,7 @@ namespace Components
|
||||
Utils::Hook::Nop(0x453406, 5);
|
||||
|
||||
//make Com_Error and similar go back to main_text instead of menu_xboxlive.
|
||||
strcpy((char*)0x6FC790, "main_text");
|
||||
Utils::Hook::SetString(0x6FC790, "main_text");
|
||||
|
||||
Command::Add("openmenu", [] (Command::Params params)
|
||||
{
|
||||
|
@ -102,7 +102,6 @@ namespace Components
|
||||
// increase font sizes for chat on higher resolutions
|
||||
static float float13 = 13.0f;
|
||||
static float float10 = 10.0f;
|
||||
|
||||
Utils::Hook::Set<float*>(0x5814AE, &float13);
|
||||
Utils::Hook::Set<float*>(0x5814C8, &float10);
|
||||
|
||||
@ -134,7 +133,7 @@ namespace Components
|
||||
Utils::Hook::Nop(0x4AA8A1, 6);
|
||||
|
||||
// Rename stat file - TODO: beautify
|
||||
strcpy((char*)0x71C048, "iw4x.stat");
|
||||
Utils::Hook::SetString(0x71C048, "iw4x.stat");
|
||||
|
||||
// Patch stats steamid
|
||||
Utils::Hook::Nop(0x682EBF, 20);
|
||||
|
@ -599,7 +599,7 @@ namespace Game
|
||||
|
||||
struct MenuList
|
||||
{
|
||||
const char *name;
|
||||
char *name;
|
||||
int menuCount;
|
||||
menuDef_t **menus;
|
||||
};
|
||||
|
@ -46,8 +46,8 @@ namespace Utils
|
||||
|
||||
Hook::Installed = true;
|
||||
|
||||
DWORD d;
|
||||
VirtualProtect(Hook::Place, sizeof(Hook::Buffer), PAGE_EXECUTE_READWRITE, &d);
|
||||
DWORD d = 1;
|
||||
VirtualProtect(Hook::Place, sizeof(Hook::Buffer), PAGE_EXECUTE_READWRITE, &this->Protection);
|
||||
memcpy(Hook::Buffer, Hook::Place, sizeof(Hook::Buffer));
|
||||
|
||||
char* Code = (char*)Hook::Place;
|
||||
@ -56,7 +56,7 @@ namespace Utils
|
||||
|
||||
*(size_t*)&Code[1] = (size_t)Hook::Stub - ((size_t)Hook::Place + 5);
|
||||
|
||||
VirtualProtect(Hook::Place, sizeof(Hook::Buffer), d, &d);
|
||||
VirtualProtect(Hook::Place, sizeof(Hook::Buffer), Hook::Protection, &this->Protection);
|
||||
|
||||
FlushInstructionCache(GetCurrentProcess(), Hook::Place, sizeof(Hook::Buffer));
|
||||
|
||||
@ -85,12 +85,11 @@ namespace Utils
|
||||
|
||||
Hook::Installed = false;
|
||||
|
||||
DWORD d;
|
||||
VirtualProtect(Hook::Place, sizeof(Hook::Buffer), PAGE_EXECUTE_READWRITE, &d);
|
||||
VirtualProtect(Hook::Place, sizeof(Hook::Buffer), PAGE_EXECUTE_READWRITE, &this->Protection);
|
||||
|
||||
memcpy(Hook::Place, Hook::Buffer, sizeof(Hook::Buffer));
|
||||
|
||||
VirtualProtect(Hook::Place, sizeof(Hook::Buffer), d, &d);
|
||||
VirtualProtect(Hook::Place, sizeof(Hook::Buffer), Hook::Protection, &this->Protection);
|
||||
|
||||
FlushInstructionCache(GetCurrentProcess(), Hook::Place, sizeof(Hook::Buffer));
|
||||
|
||||
@ -113,4 +112,24 @@ namespace Utils
|
||||
{
|
||||
Nop((void*)place, length);
|
||||
}
|
||||
|
||||
void Hook::SetString(void* place, const char* string, size_t length)
|
||||
{
|
||||
strncpy((char*)place, string, length);
|
||||
}
|
||||
|
||||
void Hook::SetString(DWORD place, const char* string, size_t length)
|
||||
{
|
||||
Hook::SetString((void*)place, string, length);
|
||||
}
|
||||
|
||||
void Hook::SetString(void* place, const char* string)
|
||||
{
|
||||
Hook::SetString(place, string, strlen((char*)place));
|
||||
}
|
||||
|
||||
void Hook::SetString(DWORD place, const char* string)
|
||||
{
|
||||
Hook::SetString((void*)place, string);
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ namespace Utils
|
||||
class Hook
|
||||
{
|
||||
public:
|
||||
Hook() : Place(nullptr), Stub(nullptr), Initialized(false), Installed(false), UseJump(false) { ZeroMemory(Hook::Buffer, sizeof(Hook::Buffer)); }
|
||||
Hook() : Place(nullptr), Stub(nullptr), Initialized(false), Installed(false), UseJump(false), Protection(0) { ZeroMemory(Hook::Buffer, sizeof(Hook::Buffer)); }
|
||||
Hook(void* place, void* stub, bool useJump = true) : Hook() { Hook::Initialize(place, stub, useJump); }
|
||||
Hook(DWORD place, void* stub, bool useJump = true) : Hook((void*)place, stub, useJump) {}
|
||||
|
||||
@ -32,6 +32,12 @@ namespace Utils
|
||||
}
|
||||
}
|
||||
|
||||
static void SetString(void* place, const char* string, size_t length);
|
||||
static void SetString(DWORD place, const char* string, size_t length);
|
||||
|
||||
static void SetString(void* place, const char* string);
|
||||
static void SetString(DWORD place, const char* string);
|
||||
|
||||
static void Nop(void* place, size_t length);
|
||||
static void Nop(DWORD place, size_t length);
|
||||
|
||||
@ -99,6 +105,8 @@ namespace Utils
|
||||
char Buffer[5];
|
||||
bool UseJump;
|
||||
|
||||
DWORD Protection;
|
||||
|
||||
std::mutex StateMutex;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user