Introduce library util
This commit is contained in:
parent
1925b191f9
commit
25585fc9a4
2
deps/mongoose
vendored
2
deps/mongoose
vendored
@ -1 +1 @@
|
||||
Subproject commit 806f07db67b624ceb6638a3bf0713286f75e996d
|
||||
Subproject commit ffa981d1728163f8b3d0961c127ef924d68ef84c
|
2
deps/protobuf
vendored
2
deps/protobuf
vendored
@ -1 +1 @@
|
||||
Subproject commit e0e54661f76183684dca66694967a60cbb10f04e
|
||||
Subproject commit 3b001ca6ba6fb51f5e55b1596fb3ce09ee9981e8
|
@ -6,7 +6,7 @@ namespace Assets
|
||||
{
|
||||
Game::MaterialTechniqueSet* asset = header.materialTechset;
|
||||
|
||||
for (int i = 0; i < ARR_SIZE(Game::MaterialTechniqueSet::techniques); ++i)
|
||||
for (int i = 0; i < ARRAYSIZE(Game::MaterialTechniqueSet::techniques); ++i)
|
||||
{
|
||||
Game::MaterialTechnique* technique = asset->techniques[i];
|
||||
|
||||
@ -52,9 +52,9 @@ namespace Assets
|
||||
}
|
||||
|
||||
// Save_MaterialTechniquePtrArray
|
||||
static_assert(ARR_SIZE(Game::MaterialTechniqueSet::techniques) == 48, "Techniques array invalid!");
|
||||
static_assert(ARRAYSIZE(Game::MaterialTechniqueSet::techniques) == 48, "Techniques array invalid!");
|
||||
|
||||
for (int i = 0; i < ARR_SIZE(Game::MaterialTechniqueSet::techniques); ++i)
|
||||
for (int i = 0; i < ARRAYSIZE(Game::MaterialTechniqueSet::techniques); ++i)
|
||||
{
|
||||
Game::MaterialTechnique* technique = asset->techniques[i];
|
||||
|
||||
|
@ -91,6 +91,7 @@
|
||||
#include "Utils\Memory.hpp"
|
||||
#include "Utils\String.hpp"
|
||||
#include "Utils\Hooking.hpp"
|
||||
#include "Utils\Library.hpp"
|
||||
#include "Utils\InfoString.hpp"
|
||||
#include "Utils\Compression.hpp"
|
||||
#include "Utils\Cryptography.hpp"
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
namespace Steam
|
||||
{
|
||||
HMODULE Proxy::Client = nullptr;
|
||||
HMODULE Proxy::Overlay = nullptr;
|
||||
::Utils::Library Proxy::Client;
|
||||
::Utils::Library Proxy::Overlay;
|
||||
|
||||
bool Proxy::Inititalize()
|
||||
{
|
||||
@ -12,20 +12,16 @@ namespace Steam
|
||||
|
||||
SetDllDirectoryA(Proxy::GetSteamDirectory().data());
|
||||
|
||||
Proxy::Client = LoadLibraryA(STEAMCLIENT_LIB);
|
||||
Proxy::Overlay = LoadLibraryA(GAMEOVERLAY_LIB);
|
||||
Proxy::Client = ::Utils::Library(STEAMCLIENT_LIB, false);
|
||||
Proxy::Overlay = ::Utils::Library(GAMEOVERLAY_LIB, false);
|
||||
|
||||
return (Proxy::Client && Proxy::Overlay);
|
||||
return (Proxy::Client.Valid() && Proxy::Overlay.Valid());
|
||||
}
|
||||
|
||||
void Proxy::Uninititalize()
|
||||
{
|
||||
// Freeing libraries causes crashes
|
||||
//if (Proxy::Client) FreeLibrary(Proxy::Client);
|
||||
Proxy::Client = nullptr;
|
||||
|
||||
//if (Proxy::Overlay) FreeLibrary(Proxy::Overlay);
|
||||
Proxy::Overlay = nullptr;
|
||||
Proxy::Client = ::Utils::Library();
|
||||
Proxy::Overlay = ::Utils::Library();
|
||||
}
|
||||
|
||||
std::string Proxy::GetSteamDirectory()
|
||||
@ -46,27 +42,17 @@ namespace Steam
|
||||
|
||||
void Proxy::SetOverlayNotificationPosition(uint32_t eNotificationPosition)
|
||||
{
|
||||
if (Proxy::Overlay)
|
||||
if (Proxy::Overlay.Valid())
|
||||
{
|
||||
FARPROC SetNotificationPositionFn = GetProcAddress(Proxy::Overlay, "SetNotificationPosition");
|
||||
|
||||
if (SetNotificationPositionFn)
|
||||
{
|
||||
::Utils::Hook::Call<void(uint32_t)>(SetNotificationPositionFn)(eNotificationPosition);
|
||||
}
|
||||
Proxy::Overlay.Get<void(uint32_t)>("SetNotificationPosition")(eNotificationPosition);
|
||||
}
|
||||
}
|
||||
|
||||
bool Proxy::IsOverlayEnabled()
|
||||
{
|
||||
if (Proxy::Overlay)
|
||||
if (Proxy::Overlay.Valid())
|
||||
{
|
||||
FARPROC IsOverlayEnabledFn = GetProcAddress(Proxy::Overlay, "IsOverlayEnabled");
|
||||
|
||||
if (IsOverlayEnabledFn)
|
||||
{
|
||||
return ::Utils::Hook::Call<bool()>(IsOverlayEnabledFn)();
|
||||
}
|
||||
return Proxy::Overlay.Get<bool()>("IsOverlayEnabled")();
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -74,14 +60,9 @@ namespace Steam
|
||||
|
||||
bool Proxy::BOverlayNeedsPresent()
|
||||
{
|
||||
if (Proxy::Overlay)
|
||||
if (Proxy::Overlay.Valid())
|
||||
{
|
||||
FARPROC BOverlayNeedsPresentFn = GetProcAddress(Proxy::Overlay, "BOverlayNeedsPresent");
|
||||
|
||||
if (BOverlayNeedsPresentFn)
|
||||
{
|
||||
return ::Utils::Hook::Call<bool()>(BOverlayNeedsPresentFn)();
|
||||
}
|
||||
return Proxy::Overlay.Get<bool()>("BOverlayNeedsPresent")();
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -22,8 +22,8 @@ namespace Steam
|
||||
static bool BOverlayNeedsPresent();
|
||||
|
||||
private:
|
||||
static HMODULE Client;
|
||||
static HMODULE Overlay;
|
||||
static ::Utils::Library Client;
|
||||
static ::Utils::Library Overlay;
|
||||
|
||||
static std::string GetSteamDirectory();
|
||||
};
|
||||
|
@ -1,5 +1,3 @@
|
||||
#define ARR_SIZE(x) (sizeof(x) / sizeof(x[0]))
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
class InfoString
|
||||
|
29
src/Utils/Library.cpp
Normal file
29
src/Utils/Library.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include "STDInclude.hpp"
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
Library::Library(std::string buffer, bool freeOnDestroy) : FreeOnDestroy(freeOnDestroy), Module(nullptr)
|
||||
{
|
||||
this->Module = LoadLibraryExA(buffer.data(), NULL, 0);
|
||||
}
|
||||
|
||||
Library::~Library()
|
||||
{
|
||||
if (this->FreeOnDestroy && this->Valid())
|
||||
{
|
||||
FreeLibrary(this->GetModule());
|
||||
}
|
||||
|
||||
this->Module = nullptr;
|
||||
}
|
||||
|
||||
bool Library::Valid()
|
||||
{
|
||||
return (this->GetModule() != nullptr);
|
||||
}
|
||||
|
||||
HMODULE Library::GetModule()
|
||||
{
|
||||
return this->Module;
|
||||
}
|
||||
}
|
28
src/Utils/Library.hpp
Normal file
28
src/Utils/Library.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
namespace Utils
|
||||
{
|
||||
class Library
|
||||
{
|
||||
public:
|
||||
Library() : Module(nullptr), FreeOnDestroy(false) {};
|
||||
Library(std::string buffer, bool freeOnDestroy = true);
|
||||
~Library();
|
||||
|
||||
bool Valid();
|
||||
HMODULE GetModule();
|
||||
|
||||
template <typename T>
|
||||
std::function<T> Get(std::string process)
|
||||
{
|
||||
if (this->Valid())
|
||||
{
|
||||
throw new std::runtime_error("Library not loaded!");
|
||||
}
|
||||
|
||||
return reinterpret_cast<T*>(GetProcAddress(this->GetModule(), process.data()));
|
||||
}
|
||||
|
||||
private:
|
||||
HMODULE Module;
|
||||
bool FreeOnDestroy;
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user