mirror of https://github.com/Thracky/GlosSI
Gnar.
parent
ee5199664c
commit
9de5585f4e
@ -1,3 +1,9 @@
|
||||
[submodule "deps/SFML"]
|
||||
path = deps/SFML
|
||||
url = https://github.com/Alia5/SFML
|
||||
[submodule "deps/WinReg"]
|
||||
path = deps/WinReg
|
||||
url = https://github.com/GiovanniDicanio/WinReg
|
||||
[submodule "deps/spdlog"]
|
||||
path = deps/spdlog
|
||||
url = https://github.com/gabime/spdlog
|
||||
|
@ -0,0 +1,97 @@
|
||||
/*
|
||||
Copyright 2021 Peter Repukat - FlatspotSoftware
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
#include "OverlayDetector.h"
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Psapi.h>
|
||||
#define NOMINMAX
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
OverlayDetector::OverlayDetector(std::function<void(bool)> overlay_changed)
|
||||
: overlay_changed_(std::move(overlay_changed))
|
||||
{
|
||||
auto addr_open = findFunctionByPattern(overlay_module_name_, open_func_sig_, open_func_mask_);
|
||||
auto addr_close = findFunctionByPattern(overlay_module_name_, close_func_sig_, close_func_mask_);
|
||||
|
||||
spdlog::info("Overlay opened function: {0:x}", addr_open);
|
||||
spdlog::info("Overlay closed function: {0:x}", addr_close);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void OverlayDetector::update()
|
||||
{
|
||||
}
|
||||
|
||||
uint64_t OverlayDetector::findFunctionByPattern(
|
||||
const std::string_view &mod_name,
|
||||
const char pattern[],
|
||||
const std::string_view &mask) const
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
||||
MODULEINFO mod_info = {NULL};
|
||||
const HMODULE mod = GetModuleHandleA(mod_name.data());
|
||||
|
||||
if (mod == nullptr) {
|
||||
spdlog::error("{} not found!", overlay_module_name_);
|
||||
return 0;
|
||||
}
|
||||
GetModuleInformation(GetCurrentProcess(), mod, &mod_info, sizeof(MODULEINFO));
|
||||
|
||||
auto base_addr = reinterpret_cast<uint64_t>(mod_info.lpBaseOfDll);
|
||||
if (base_addr == 0)
|
||||
return NULL;
|
||||
|
||||
spdlog::debug("overlay module found at: {:x}", base_addr);
|
||||
|
||||
const uint64_t mod_size = mod_info.SizeOfImage;
|
||||
const auto pat_length = mask.size();
|
||||
uint64_t pattern_addr = 0;
|
||||
|
||||
for (uint64_t i = 0; i < mod_size - pat_length; i++) {
|
||||
bool found = true;
|
||||
for (uint64_t j = 0; j < pat_length; j++)
|
||||
found &= mask[j] == '?' || pattern[j] == *reinterpret_cast<char *>(base_addr + j + i);
|
||||
|
||||
if (found)
|
||||
pattern_addr = base_addr + i;
|
||||
}
|
||||
if (pattern_addr == 0)
|
||||
return 0;
|
||||
|
||||
spdlog::debug("signature found at: {:x}", pattern_addr);
|
||||
|
||||
constexpr char start_fn_bytes[] = "\x40\x53";
|
||||
|
||||
for (auto i = pattern_addr; i > base_addr; i--) {
|
||||
bool found = true;
|
||||
for (uint64_t j = 0; j < 2; j++)
|
||||
found &= start_fn_bytes[j] == *reinterpret_cast<char *>(i + j);
|
||||
|
||||
if (found)
|
||||
return i;
|
||||
}
|
||||
return 0;
|
||||
|
||||
#else
|
||||
|
||||
#endif
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
Copyright 2021 Peter Repukat - FlatspotSoftware
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
#pragma once
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
|
||||
class OverlayDetector {
|
||||
public:
|
||||
explicit OverlayDetector(std::function<void(bool)> overlay_changed = [](bool) {});
|
||||
void update();
|
||||
|
||||
private:
|
||||
std::function<void(bool)> overlay_changed_;
|
||||
|
||||
|
||||
uint64_t findFunctionByPattern(
|
||||
const std::string_view &mod_name,
|
||||
const char pattern[],
|
||||
const std::string_view &mask) const;
|
||||
|
||||
#ifdef _WIN32
|
||||
static constexpr std::string_view overlay_module_name_ = "GameOverlayRenderer64.dll";
|
||||
static constexpr char open_func_sig_[] = "\xC6\x41\x5C\x01\x48\x8D\x4C\x24\x30";
|
||||
static constexpr std::string_view open_func_mask_ = "xxxxxxxxx";
|
||||
static constexpr char close_func_sig_[] = "\xC6\x41\x5C\x00\x48\x8D\x4C\x24\x40";
|
||||
static constexpr std::string_view close_func_mask_ = "xxxxxxxxx";
|
||||
|
||||
#else
|
||||
|
||||
#endif
|
||||
};
|
@ -0,0 +1 @@
|
||||
Subproject commit 023ad61dc77c83407e7ae061f177a3ba3d3941e6
|
@ -0,0 +1 @@
|
||||
Subproject commit 8826011c81b69e1f8427be520b357c19c74ea480
|
Loading…
Reference in New Issue