More optimization.

This commit is contained in:
momo5502 2016-01-24 21:08:14 +01:00
parent 388d5836cd
commit ba3187ce9e
12 changed files with 22 additions and 32 deletions

View File

@ -230,12 +230,10 @@ namespace Components
Game::XAssetHeader AssetHandler::FindOriginalAsset(Game::XAssetType type, const char* filename) Game::XAssetHeader AssetHandler::FindOriginalAsset(Game::XAssetType type, const char* filename)
{ {
Game::XAssetHeader header = { 0 };
bool OriginalState = AssetHandler::BypassState; bool OriginalState = AssetHandler::BypassState;
AssetHandler::BypassState = true; AssetHandler::BypassState = true;
header = Game::DB_FindXAssetHeader(type, filename); Game::XAssetHeader header = Game::DB_FindXAssetHeader(type, filename);
if(!OriginalState) AssetHandler::BypassState = false; if(!OriginalState) AssetHandler::BypassState = false;
return header; return header;

View File

@ -28,7 +28,6 @@ namespace Components
char ownPth[MAX_PATH] = { 0 }; char ownPth[MAX_PATH] = { 0 };
char workdir[MAX_PATH] = { 0 }; char workdir[MAX_PATH] = { 0 };
char regred[MAX_PATH] = { 0 };
DWORD dwsize = MAX_PATH; DWORD dwsize = MAX_PATH;
HMODULE hModule = GetModuleHandle(NULL); HMODULE hModule = GetModuleHandle(NULL);
@ -67,6 +66,8 @@ namespace Components
LONG openRes = RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\Classes\\iw4x\\shell\\open\\command", 0, KEY_ALL_ACCESS, &hKey); LONG openRes = RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\Classes\\iw4x\\shell\\open\\command", 0, KEY_ALL_ACCESS, &hKey);
if (openRes == ERROR_SUCCESS) if (openRes == ERROR_SUCCESS)
{ {
char regred[MAX_PATH] = { 0 };
// Check if the game has been moved. // Check if the game has been moved.
openRes = RegQueryValueEx(hKey, 0, 0, 0, reinterpret_cast<BYTE*>(regred), &dwsize); openRes = RegQueryValueEx(hKey, 0, 0, 0, reinterpret_cast<BYTE*>(regred), &dwsize);
if (openRes == ERROR_SUCCESS) if (openRes == ERROR_SUCCESS)

View File

@ -92,7 +92,7 @@ namespace Components
{ {
std::regex _(expression); std::regex _(expression);
} }
catch (std::exception e) catch (const std::exception e)
{ {
MessageBoxA(0, Utils::VA("Invalid regular expression: %s", expression.data()), "Warning", MB_ICONEXCLAMATION); MessageBoxA(0, Utils::VA("Invalid regular expression: %s", expression.data()), "Warning", MB_ICONEXCLAMATION);
return; return;

View File

@ -126,8 +126,6 @@ namespace Components
} }
Game::pc_token_t token; Game::pc_token_t token;
Game::keywordHash_t *key;
if (!Game::PC_ReadTokenHandle(handle, &token) || token.string[0] != '{') if (!Game::PC_ReadTokenHandle(handle, &token) || token.string[0] != '{')
{ {
Utils::Memory::Free(menu->items); Utils::Memory::Free(menu->items);
@ -152,7 +150,7 @@ namespace Components
int idx = Menus::KeywordHash(token.string); int idx = Menus::KeywordHash(token.string);
key = Game::menuParseKeywordHash[idx]; Game::keywordHash_t* key = Game::menuParseKeywordHash[idx];
if (!key) if (!key)
{ {
@ -186,9 +184,6 @@ namespace Components
if (Menus::IsValidSourceHandle(handle)) if (Menus::IsValidSourceHandle(handle))
{ {
// Sanitize event name
std::string menuName = menu;
while (true) while (true)
{ {
ZeroMemory(&token, sizeof(token)); ZeroMemory(&token, sizeof(token));
@ -320,36 +315,32 @@ namespace Components
{ {
if (!Menus::IsValidSourceHandle(handle)) return; if (!Menus::IsValidSourceHandle(handle)) return;
Game::script_t *script;
Game::token_t *token;
Game::define_t *define;
Game::indent_t *indent;
Game::source_t *source = Game::sourceFiles[handle]; Game::source_t *source = Game::sourceFiles[handle];
while (source->scriptstack) while (source->scriptstack)
{ {
script = source->scriptstack; Game::script_t* script = source->scriptstack;
source->scriptstack = source->scriptstack->next; source->scriptstack = source->scriptstack->next;
Game::FreeMemory(script); Game::FreeMemory(script);
} }
while (source->tokens) while (source->tokens)
{ {
token = source->tokens; Game::token_t* token = source->tokens;
source->tokens = source->tokens->next; source->tokens = source->tokens->next;
Game::FreeMemory(token); Game::FreeMemory(token);
} }
while (source->defines) while (source->defines)
{ {
define = source->defines; Game::define_t* define = source->defines;
source->defines = source->defines->next; source->defines = source->defines->next;
Game::FreeMemory(define); Game::FreeMemory(define);
} }
while (source->indentstack) while (source->indentstack)
{ {
indent = source->indentstack; Game::indent_t* indent = source->indentstack;
source->indentstack = source->indentstack->next; source->indentstack = source->indentstack->next;
Utils::Memory::Free(indent); Utils::Memory::Free(indent);
} }

View File

@ -10,7 +10,7 @@ namespace Components
Address(std::string addrString); Address(std::string addrString);
Address(Game::netadr_t addr) : address(addr) {} Address(Game::netadr_t addr) : address(addr) {}
Address(Game::netadr_t* addr) : Address(*addr) {} Address(Game::netadr_t* addr) : Address(*addr) {}
Address(const Address& obj) { this->address = obj.address; }; Address(const Address& obj) : address(obj.address) {};
bool operator!=(const Address &obj) { return !(*this == obj); }; bool operator!=(const Address &obj) { return !(*this == obj); };
bool operator==(const Address &obj); bool operator==(const Address &obj);

View File

@ -3,7 +3,7 @@
namespace Components namespace Components
{ {
ZoneBuilder::Zone::Zone(std::string name) : DataMap("zone_source/" + name + ".csv"), ZoneName(name), IndexStart(0), ZoneBuilder::Zone::Zone(std::string name) : DataMap("zone_source/" + name + ".csv"), ZoneName(name), IndexStart(0), Branding { 0 },
// Reserve 100MB by default. // Reserve 100MB by default.
// That's totally fine, as the dedi doesn't load images and therefore doesn't need much memory. // That's totally fine, as the dedi doesn't load images and therefore doesn't need much memory.
@ -307,9 +307,9 @@ namespace Components
void ZoneBuilder::Zone::AddBranding() void ZoneBuilder::Zone::AddBranding()
{ {
char* data = "FastFile built using iw4x IW4 ZoneTool!"; char* data = "FastFile built using iw4x IW4 ZoneTool!";
branding = { ZoneBuilder::Zone::ZoneName.data(), (int)strlen(data), 0, data }; ZoneBuilder::Zone::Branding = { ZoneBuilder::Zone::ZoneName.data(), (int)strlen(data), 0, data };
Game::XAssetHeader header = { &branding }; Game::XAssetHeader header = { &Branding };
Game::XAsset brandingAsset = { Game::XAssetType::ASSET_TYPE_RAWFILE, header }; Game::XAsset brandingAsset = { Game::XAssetType::ASSET_TYPE_RAWFILE, header };
ZoneBuilder::Zone::LoadedAssets.push_back(brandingAsset); ZoneBuilder::Zone::LoadedAssets.push_back(brandingAsset);
} }

View File

@ -65,7 +65,7 @@ namespace Components
std::map<std::string, std::string> RenameMap[Game::XAssetType::ASSET_TYPE_COUNT]; std::map<std::string, std::string> RenameMap[Game::XAssetType::ASSET_TYPE_COUNT];
std::map<const void*, uint32_t> PointerMap; std::map<const void*, uint32_t> PointerMap;
Game::RawFile branding; Game::RawFile Branding;
}; };
ZoneBuilder(); ZoneBuilder();

View File

@ -48,7 +48,7 @@
#define ASIO_STANDALONE #define ASIO_STANDALONE
#include <zlib.h> #include <zlib.h>
#include <curses.h> #include <curses.h>
#include <asio.hpp> //#include <asio.hpp>
#include <json11.hpp> #include <json11.hpp>
#pragma warning(pop) #pragma warning(pop)

View File

@ -51,7 +51,7 @@ namespace Steam
unsigned __int64 Matchmaking::CreateLobby(int eLobbyType, int cMaxMembers) unsigned __int64 Matchmaking::CreateLobby(int eLobbyType, int cMaxMembers)
{ {
uint64_t result = Callbacks::RegisterCall(); uint64_t result = Callbacks::RegisterCall();
LobbyCreated* retvals = new LobbyCreated; LobbyCreated* retvals = ::Utils::Memory::AllocateArray<LobbyCreated>();
SteamID id; SteamID id;
id.AccountID = 1337132; id.AccountID = 1337132;
@ -72,7 +72,7 @@ namespace Steam
unsigned __int64 Matchmaking::JoinLobby(SteamID steamIDLobby) unsigned __int64 Matchmaking::JoinLobby(SteamID steamIDLobby)
{ {
uint64_t result = Callbacks::RegisterCall(); uint64_t result = Callbacks::RegisterCall();
LobbyEnter* retvals = new LobbyEnter; LobbyEnter* retvals = ::Utils::Memory::AllocateArray<LobbyEnter>();
retvals->m_bLocked = false; retvals->m_bLocked = false;
retvals->m_EChatRoomEnterResponse = 1; retvals->m_EChatRoomEnterResponse = 1;
retvals->m_rgfChatPermissions = 0xFFFFFFFF; retvals->m_rgfChatPermissions = 0xFFFFFFFF;

View File

@ -61,7 +61,7 @@ namespace Steam
if (result.data) if (result.data)
{ {
delete[] result.data; ::Utils::Memory::Free(result.data);
} }
} }
@ -77,9 +77,9 @@ namespace Steam
if (!Overlay) if (!Overlay)
{ {
HKEY hRegKey; HKEY hRegKey;
char steamPath[MAX_PATH] = { 0 };
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Valve\\Steam", 0, KEY_QUERY_VALUE, &hRegKey) == ERROR_SUCCESS) if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Valve\\Steam", 0, KEY_QUERY_VALUE, &hRegKey) == ERROR_SUCCESS)
{ {
char steamPath[MAX_PATH] = { 0 };
DWORD dwLength = sizeof(steamPath); DWORD dwLength = sizeof(steamPath);
RegQueryValueExA(hRegKey, "InstallPath", NULL, NULL, reinterpret_cast<BYTE*>(steamPath), &dwLength); RegQueryValueExA(hRegKey, "InstallPath", NULL, NULL, reinterpret_cast<BYTE*>(steamPath), &dwLength);
RegCloseKey(hRegKey); RegCloseKey(hRegKey);

View File

@ -8,7 +8,7 @@ namespace Utils
class Hook class Hook
{ {
public: public:
Hook() : Place(nullptr), Stub(nullptr), Initialized(false), Installed(false), UseJump(false), Protection(0) { ZeroMemory(Hook::Buffer, sizeof(Hook::Buffer)); } Hook() : Place(nullptr), Stub(nullptr), Initialized(false), Installed(false), Original(0), 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(reinterpret_cast<void*>(place), stub, useJump) {} Hook(DWORD place, void* stub, bool useJump = true) : Hook(reinterpret_cast<void*>(place), stub, useJump) {}
Hook(DWORD place, DWORD stub, bool useJump = true) : Hook(reinterpret_cast<void*>(place), reinterpret_cast<void*>(stub), useJump) {} Hook(DWORD place, DWORD stub, bool useJump = true) : Hook(reinterpret_cast<void*>(place), reinterpret_cast<void*>(stub), useJump) {}

View File

@ -24,8 +24,8 @@ namespace Utils
{ {
public: public:
InfoString() {}; InfoString() {};
InfoString(std::string buffer) :InfoString() { this->Parse(buffer); }; InfoString(std::string buffer) : InfoString() { this->Parse(buffer); };
InfoString(const InfoString &obj) { this->KeyValuePairs = obj.KeyValuePairs; }; InfoString(const InfoString &obj) : KeyValuePairs(obj.KeyValuePairs) {};
void Set(std::string key, std::string value); void Set(std::string key, std::string value);
std::string Get(std::string key); std::string Get(std::string key);