More fixes and optimizations
This commit is contained in:
parent
9562285ed7
commit
2ea490382b
@ -7,7 +7,7 @@ namespace Assets
|
|||||||
Game::GfxImage* image = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_IMAGE, name.data()).image;
|
Game::GfxImage* image = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_IMAGE, name.data()).image;
|
||||||
if (image) return; // TODO: Check for default?
|
if (image) return; // TODO: Check for default?
|
||||||
|
|
||||||
image = builder->GetAllocator()->AllocateArray<Game::GfxImage>();
|
image = builder->GetAllocator()->Allocate<Game::GfxImage>();
|
||||||
if (!image)
|
if (!image)
|
||||||
{
|
{
|
||||||
Components::Logger::Error("Failed to allocate GfxImage structure!");
|
Components::Logger::Error("Failed to allocate GfxImage structure!");
|
||||||
@ -19,7 +19,7 @@ namespace Assets
|
|||||||
image->category = 0;
|
image->category = 0;
|
||||||
image->cardMemory = 0;
|
image->cardMemory = 0;
|
||||||
|
|
||||||
image->texture = builder->GetAllocator()->AllocateArray<Game::GfxImageLoadDef>();
|
image->texture = builder->GetAllocator()->Allocate<Game::GfxImageLoadDef>();
|
||||||
if (!image->texture)
|
if (!image->texture)
|
||||||
{
|
{
|
||||||
Components::Logger::Error("Failed to allocate GfxImageLoadDef structure!");
|
Components::Logger::Error("Failed to allocate GfxImageLoadDef structure!");
|
||||||
|
@ -7,7 +7,7 @@ namespace Assets
|
|||||||
Components::FileSystem::File ents(name + ".ents");
|
Components::FileSystem::File ents(name + ".ents");
|
||||||
if (ents.Exists())
|
if (ents.Exists())
|
||||||
{
|
{
|
||||||
Game::MapEnts* entites = builder->GetAllocator()->AllocateArray<Game::MapEnts>();
|
Game::MapEnts* entites = builder->GetAllocator()->Allocate<Game::MapEnts>();
|
||||||
Game::MapEnts* orgEnts = Components::AssetHandler::FindOriginalAsset(this->GetType(), name.data()).mapEnts;
|
Game::MapEnts* orgEnts = Components::AssetHandler::FindOriginalAsset(this->GetType(), name.data()).mapEnts;
|
||||||
|
|
||||||
if (orgEnts)
|
if (orgEnts)
|
||||||
|
@ -33,7 +33,7 @@ namespace Assets
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::Material* material = builder->GetAllocator()->AllocateArray<Game::Material>();
|
Game::Material* material = builder->GetAllocator()->Allocate<Game::Material>();
|
||||||
|
|
||||||
if (!material)
|
if (!material)
|
||||||
{
|
{
|
||||||
|
@ -8,7 +8,7 @@ namespace Assets
|
|||||||
|
|
||||||
if (rawFile.Exists())
|
if (rawFile.Exists())
|
||||||
{
|
{
|
||||||
Game::RawFile* asset = builder->GetAllocator()->AllocateArray<Game::RawFile>();
|
Game::RawFile* asset = builder->GetAllocator()->Allocate<Game::RawFile>();
|
||||||
|
|
||||||
if (asset)
|
if (asset)
|
||||||
{
|
{
|
||||||
|
@ -11,7 +11,7 @@ namespace Assets
|
|||||||
Game::XModel* baseModel = Components::AssetHandler::FindOriginalAsset(Game::XAssetType::ASSET_TYPE_XMODEL, "viewmodel_mp5k").model;
|
Game::XModel* baseModel = Components::AssetHandler::FindOriginalAsset(Game::XAssetType::ASSET_TYPE_XMODEL, "viewmodel_mp5k").model;
|
||||||
|
|
||||||
// Allocate new model and copy the base data to it
|
// Allocate new model and copy the base data to it
|
||||||
Game::XModel* model = builder->GetAllocator()->AllocateArray<Game::XModel>();
|
Game::XModel* model = builder->GetAllocator()->Allocate<Game::XModel>();
|
||||||
std::memcpy(model, baseModel, sizeof(Game::XModel));
|
std::memcpy(model, baseModel, sizeof(Game::XModel));
|
||||||
|
|
||||||
Utils::Stream::Reader reader(builder->GetAllocator(), modelFile.GetBuffer());
|
Utils::Stream::Reader reader(builder->GetAllocator(), modelFile.GetBuffer());
|
||||||
@ -41,7 +41,7 @@ namespace Assets
|
|||||||
|
|
||||||
// Prepare surfaces
|
// Prepare surfaces
|
||||||
Game::XSurface* baseSurface = &baseModel->lods[0].surfaces[0].surfaces[0];
|
Game::XSurface* baseSurface = &baseModel->lods[0].surfaces[0].surfaces[0];
|
||||||
Game::XModelSurfs* surf = builder->GetAllocator()->AllocateArray<Game::XModelSurfs>();
|
Game::XModelSurfs* surf = builder->GetAllocator()->Allocate<Game::XModelSurfs>();
|
||||||
|
|
||||||
std::memcpy(surf, baseModel->lods[0].surfaces, sizeof(Game::XModelSurfs));
|
std::memcpy(surf, baseModel->lods[0].surfaces, sizeof(Game::XModelSurfs));
|
||||||
surf->name = builder->GetAllocator()->DuplicateString(fmt::sprintf("%s1", model->name));
|
surf->name = builder->GetAllocator()->DuplicateString(fmt::sprintf("%s1", model->name));
|
||||||
|
@ -19,7 +19,7 @@ namespace Components
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::LocalizedEntry* entry = Utils::Memory::AllocateArray<Game::LocalizedEntry>(1);
|
Game::LocalizedEntry* entry = Utils::Memory::Allocate<Game::LocalizedEntry>();
|
||||||
if (!entry) return;
|
if (!entry) return;
|
||||||
|
|
||||||
entry->name = Utils::Memory::DuplicateString(key);
|
entry->name = Utils::Memory::DuplicateString(key);
|
||||||
@ -75,7 +75,7 @@ namespace Components
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Game::LocalizedEntry* entry = Utils::Memory::AllocateArray<Game::LocalizedEntry>(1);
|
Game::LocalizedEntry* entry = Utils::Memory::Allocate<Game::LocalizedEntry>();
|
||||||
if (!entry) return;
|
if (!entry) return;
|
||||||
|
|
||||||
entry->name = Utils::Memory::DuplicateString(key);
|
entry->name = Utils::Memory::DuplicateString(key);
|
||||||
|
@ -68,7 +68,7 @@ namespace Components
|
|||||||
|
|
||||||
script->next = NULL;
|
script->next = NULL;
|
||||||
|
|
||||||
source = Utils::Memory::AllocateArray<Game::source_t>(1);
|
source = Utils::Memory::Allocate<Game::source_t>();
|
||||||
if (!source)
|
if (!source)
|
||||||
{
|
{
|
||||||
Game::FreeMemory(script);
|
Game::FreeMemory(script);
|
||||||
@ -112,7 +112,7 @@ namespace Components
|
|||||||
|
|
||||||
Game::menuDef_t* Menus::ParseMenu(int handle)
|
Game::menuDef_t* Menus::ParseMenu(int handle)
|
||||||
{
|
{
|
||||||
Game::menuDef_t* menu = Utils::Memory::AllocateArray<Game::menuDef_t>(1);
|
Game::menuDef_t* menu = Utils::Memory::Allocate<Game::menuDef_t>();
|
||||||
if (!menu) return nullptr;
|
if (!menu) return nullptr;
|
||||||
|
|
||||||
menu->items = Utils::Memory::AllocateArray<Game::itemDef_t*>(512);
|
menu->items = Utils::Memory::AllocateArray<Game::itemDef_t*>(512);
|
||||||
@ -239,7 +239,7 @@ namespace Components
|
|||||||
if (menus.empty()) return nullptr;
|
if (menus.empty()) return nullptr;
|
||||||
|
|
||||||
// Allocate new menu list
|
// Allocate new menu list
|
||||||
Game::MenuList* newList = Utils::Memory::AllocateArray<Game::MenuList>(1);
|
Game::MenuList* newList = Utils::Memory::Allocate<Game::MenuList>();
|
||||||
if (!newList) return nullptr;
|
if (!newList) return nullptr;
|
||||||
|
|
||||||
newList->menus = Utils::Memory::AllocateArray<Game::menuDef_t*>(menus.size());
|
newList->menus = Utils::Memory::AllocateArray<Game::menuDef_t*>(menus.size());
|
||||||
@ -285,7 +285,7 @@ namespace Components
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Allocate new menu list
|
// Allocate new menu list
|
||||||
Game::MenuList* newList = Utils::Memory::AllocateArray<Game::MenuList>(1);
|
Game::MenuList* newList = Utils::Memory::Allocate<Game::MenuList>();
|
||||||
if (!newList) return menuList;
|
if (!newList) return menuList;
|
||||||
|
|
||||||
size_t size = menus.size();
|
size_t size = menus.size();
|
||||||
|
@ -28,7 +28,7 @@ namespace Components
|
|||||||
{
|
{
|
||||||
Utils::CSV parsedTable(rawTable.GetBuffer(), false, false);
|
Utils::CSV parsedTable(rawTable.GetBuffer(), false, false);
|
||||||
|
|
||||||
table = StringTable::MemAllocator.AllocateArray<Game::StringTable>(1);
|
table = StringTable::MemAllocator.Allocate<Game::StringTable>();
|
||||||
|
|
||||||
if (table)
|
if (table)
|
||||||
{
|
{
|
||||||
|
@ -304,7 +304,7 @@ namespace Components
|
|||||||
FileSystem::DeleteFile("demos", fmt::sprintf("%s.json", files[i].data()));
|
FileSystem::DeleteFile("demos", fmt::sprintf("%s.json", files[i].data()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Command::Execute(fmt::sprintf("record auto_%I64d", time(0)), true);
|
Command::Execute(fmt::format("record auto_{}", time(0)), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Utils::Hook::Call<DWORD()>(0x42BBB0)();
|
return Utils::Hook::Call<DWORD()>(0x42BBB0)();
|
||||||
|
@ -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 = ::Utils::Memory::AllocateArray<LobbyCreated>();
|
LobbyCreated* retvals = ::Utils::Memory::Allocate<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 = ::Utils::Memory::AllocateArray<LobbyEnter>();
|
LobbyEnter* retvals = ::Utils::Memory::Allocate<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;
|
||||||
|
@ -35,7 +35,9 @@ namespace Utils
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
uint8_t* dest = Utils::Memory::AllocateArray<uint8_t>(CHUNK);
|
Utils::Memory::Allocator allocator;
|
||||||
|
|
||||||
|
uint8_t* dest = allocator.AllocateArray<uint8_t>(CHUNK);
|
||||||
const char* dataPtr = data.data();
|
const char* dataPtr = data.data();
|
||||||
|
|
||||||
do
|
do
|
||||||
@ -52,7 +54,6 @@ namespace Utils
|
|||||||
if (ret == Z_STREAM_ERROR)
|
if (ret == Z_STREAM_ERROR)
|
||||||
{
|
{
|
||||||
inflateEnd(&stream);
|
inflateEnd(&stream);
|
||||||
Utils::Memory::Free(dest);
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,9 +64,6 @@ namespace Utils
|
|||||||
} while (ret != Z_STREAM_END);
|
} while (ret != Z_STREAM_END);
|
||||||
|
|
||||||
inflateEnd(&stream);
|
inflateEnd(&stream);
|
||||||
|
|
||||||
Utils::Memory::Free(dest);
|
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -163,7 +163,7 @@ namespace Utils
|
|||||||
|
|
||||||
bool IsValid()
|
bool IsValid()
|
||||||
{
|
{
|
||||||
return (!Utils::MemIsSet(this->GetKeyPtr(), 0, sizeof(*this->GetKeyPtr())));
|
return (!Utils::Memory::IsSet(this->GetKeyPtr(), 0, sizeof(*this->GetKeyPtr())));
|
||||||
}
|
}
|
||||||
|
|
||||||
ecc_key* GetKeyPtr()
|
ecc_key* GetKeyPtr()
|
||||||
@ -263,7 +263,7 @@ namespace Utils
|
|||||||
|
|
||||||
bool IsValid()
|
bool IsValid()
|
||||||
{
|
{
|
||||||
return (!Utils::MemIsSet(this->GetKeyPtr(), 0, sizeof(*this->GetKeyPtr())));
|
return (!Utils::Memory::IsSet(this->GetKeyPtr(), 0, sizeof(*this->GetKeyPtr())));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Free()
|
void Free()
|
||||||
|
@ -35,4 +35,20 @@ namespace Utils
|
|||||||
{
|
{
|
||||||
Memory::Free(const_cast<void*>(data));
|
Memory::Free(const_cast<void*>(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Complementary function for memset, which checks if memory is filled with a char
|
||||||
|
bool Memory::IsSet(void* mem, char chr, size_t length)
|
||||||
|
{
|
||||||
|
char* memArr = reinterpret_cast<char*>(mem);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < length; ++i)
|
||||||
|
{
|
||||||
|
if (memArr[i] != chr)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,10 @@ namespace Utils
|
|||||||
this->Pool.push_back(data);
|
this->Pool.push_back(data);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
template <typename T> T* Allocate()
|
||||||
|
{
|
||||||
|
return this->AllocateArray<T>(1);
|
||||||
|
}
|
||||||
template <typename T> T* AllocateArray(size_t count = 1)
|
template <typename T> T* AllocateArray(size_t count = 1)
|
||||||
{
|
{
|
||||||
return static_cast<T*>(this->Allocate(count * sizeof(T)));
|
return static_cast<T*>(this->Allocate(count * sizeof(T)));
|
||||||
@ -67,6 +71,10 @@ namespace Utils
|
|||||||
};
|
};
|
||||||
|
|
||||||
static void* Allocate(size_t length);
|
static void* Allocate(size_t length);
|
||||||
|
template <typename T> static T* Allocate()
|
||||||
|
{
|
||||||
|
return AllocateArray<T>(1);
|
||||||
|
}
|
||||||
template <typename T> static T* AllocateArray(size_t count = 1)
|
template <typename T> static T* AllocateArray(size_t count = 1)
|
||||||
{
|
{
|
||||||
return static_cast<T*>(Allocate(count * sizeof(T)));
|
return static_cast<T*>(Allocate(count * sizeof(T)));
|
||||||
@ -76,5 +84,7 @@ namespace Utils
|
|||||||
|
|
||||||
static void Free(void* data);
|
static void Free(void* data);
|
||||||
static void Free(const void* data);
|
static void Free(const void* data);
|
||||||
|
|
||||||
|
static bool IsSet(void* mem, char chr, size_t length);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -16,22 +16,6 @@ namespace Utils
|
|||||||
return "application/octet-stream";
|
return "application/octet-stream";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Complementary function for memset, which checks if a memory is set
|
|
||||||
bool MemIsSet(void* mem, char chr, size_t length)
|
|
||||||
{
|
|
||||||
char* memArr = reinterpret_cast<char*>(mem);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < length; ++i)
|
|
||||||
{
|
|
||||||
if (memArr[i] != chr)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string ParseChallenge(std::string data)
|
std::string ParseChallenge(std::string data)
|
||||||
{
|
{
|
||||||
auto pos = data.find_first_of("\n ");
|
auto pos = data.find_first_of("\n ");
|
||||||
|
@ -2,7 +2,6 @@ namespace Utils
|
|||||||
{
|
{
|
||||||
std::string GetMimeType(std::string url);
|
std::string GetMimeType(std::string url);
|
||||||
std::string ParseChallenge(std::string data);
|
std::string ParseChallenge(std::string data);
|
||||||
bool MemIsSet(void* mem, char chr, size_t length);
|
|
||||||
|
|
||||||
template <typename T> void Merge(std::vector<T>* target, T* source, size_t length)
|
template <typename T> void Merge(std::vector<T>* target, T* source, size_t length)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user