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