main
Peter Repukat 3 years ago
parent ee5199664c
commit 9de5585f4e

6
.gitmodules vendored

@ -1,3 +1,9 @@
[submodule "deps/SFML"] [submodule "deps/SFML"]
path = deps/SFML path = deps/SFML
url = https://github.com/Alia5/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

@ -80,14 +80,14 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>
<ExternalIncludePath>..\deps\SFML\include;$(ExternalIncludePath)</ExternalIncludePath> <ExternalIncludePath>..\deps\SFML\include;..\deps\WinReg;..\deps\spdlog\include;..\deps\subhook;$(ExternalIncludePath)</ExternalIncludePath>
<LibraryPath>..\deps\SFML\out\build\x64-Debug\lib;$(LibraryPath)</LibraryPath> <LibraryPath>..\deps\SFML\out\build\x64-Debug\lib;$(LibraryPath)</LibraryPath>
<CopyLocalProjectReference>false</CopyLocalProjectReference> <CopyLocalProjectReference>false</CopyLocalProjectReference>
<CopyLocalDeploymentContent>true</CopyLocalDeploymentContent> <CopyLocalDeploymentContent>true</CopyLocalDeploymentContent>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental> <LinkIncremental>false</LinkIncremental>
<ExternalIncludePath>..\deps\SFML\include;$(ExternalIncludePath)</ExternalIncludePath> <ExternalIncludePath>..\deps\SFML\include;..\deps\WinReg;..\deps\spdlog\include;..\deps\subhook;$(ExternalIncludePath)</ExternalIncludePath>
<LibraryPath>..\deps\SFML\out\build\x64-Release\lib;$(LibraryPath)</LibraryPath> <LibraryPath>..\deps\SFML\out\build\x64-Release\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
@ -122,7 +122,7 @@
<ClCompile> <ClCompile>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_DEBUG;_CONSOLE;SPDLOG_WCHAR_TO_UTF8_SUPPORT;SUBHOOK_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard> <LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile> </ClCompile>
@ -138,7 +138,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>NDEBUG;_CONSOLE;SPDLOG_WCHAR_TO_UTF8_SUPPORT;SUBHOOK_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard> <LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile> </ClCompile>
@ -150,11 +150,15 @@
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\deps\subhook\subhook.c" />
<ClCompile Include="main.cpp" /> <ClCompile Include="main.cpp" />
<ClCompile Include="OverlayDetector.cpp" />
<ClCompile Include="SteamTarget.cpp" /> <ClCompile Include="SteamTarget.cpp" />
<ClCompile Include="TargetWindow.cpp" /> <ClCompile Include="TargetWindow.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\deps\subhook\subhook.h" />
<ClInclude Include="OverlayDetector.h" />
<ClInclude Include="SteamTarget.h" /> <ClInclude Include="SteamTarget.h" />
<ClInclude Include="TargetWindow.h" /> <ClInclude Include="TargetWindow.h" />
</ItemGroup> </ItemGroup>

@ -24,6 +24,12 @@
<ClCompile Include="TargetWindow.cpp"> <ClCompile Include="TargetWindow.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="OverlayDetector.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\deps\subhook\subhook.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="SteamTarget.h"> <ClInclude Include="SteamTarget.h">
@ -32,6 +38,12 @@
<ClInclude Include="TargetWindow.h"> <ClInclude Include="TargetWindow.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="OverlayDetector.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\deps\subhook\subhook.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="..\deps\SFML\out\build\x64-Debug\lib\sfml-system-d-2.dll" /> <None Include="..\deps\SFML\out\build\x64-Debug\lib\sfml-system-d-2.dll" />

@ -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
};

@ -15,8 +15,6 @@ limitations under the License.
*/ */
#include "SteamTarget.h" #include "SteamTarget.h"
#include <iostream>
SteamTarget::SteamTarget(int argc, char *argv[]) : window_([this] { run_ = false; }) SteamTarget::SteamTarget(int argc, char *argv[]) : window_([this] { run_ = false; })
{ {
} }
@ -26,6 +24,7 @@ int SteamTarget::run()
run_ = true; run_ = true;
window_.setFpsLimit(90); window_.setFpsLimit(90);
while (run_) { while (run_) {
detector_.update();
window_.update(); window_.update();
} }
return 1; return 1;

@ -15,8 +15,10 @@ limitations under the License.
*/ */
#pragma once #pragma once
#include "OverlayDetector.h"
#include "TargetWindow.h" #include "TargetWindow.h"
class SteamTarget { class SteamTarget {
public: public:
explicit SteamTarget(int argc, char *argv[]); explicit SteamTarget(int argc, char *argv[]);
@ -25,4 +27,5 @@ class SteamTarget {
private: private:
bool run_ = false; bool run_ = false;
TargetWindow window_; TargetWindow window_;
OverlayDetector detector_;
}; };

@ -15,6 +15,7 @@ limitations under the License.
*/ */
#include "TargetWindow.h" #include "TargetWindow.h"
#include <iostream>
#include <utility> #include <utility>
#include <SFML/Window/Event.hpp> #include <SFML/Window/Event.hpp>
@ -24,9 +25,17 @@ limitations under the License.
#include <dwmapi.h> #include <dwmapi.h>
#endif #endif
TargetWindow::TargetWindow(std::function<void()> on_close) : on_close_(std::move(on_close)) static const bool DEV_MODE = true;
TargetWindow::TargetWindow(std::function<void()> on_close)
: on_close_(std::move(on_close))
{ {
window_.create(sf::VideoMode::getDesktopMode(), "GlosSITarget", sf::Style::None); if (DEV_MODE) {
window_.create(sf::VideoMode{1920, 1080}, "GlosSITarget", sf::Style::Default);
}
else {
window_.create(sf::VideoMode::getDesktopMode(), "GlosSITarget", sf::Style::None);
}
window_.setActive(true); window_.setActive(true);
#ifdef _WIN32 #ifdef _WIN32
@ -34,12 +43,15 @@ TargetWindow::TargetWindow(std::function<void()> on_close) : on_close_(std::move
MARGINS margins; MARGINS margins;
margins.cxLeftWidth = -1; margins.cxLeftWidth = -1;
DwmExtendFrameIntoClientArea(hwnd, &margins); DwmExtendFrameIntoClientArea(hwnd, &margins);
if (!DEV_MODE) {
// always on top // always on top
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
}
#endif #endif
setClickThrough(true); if (!DEV_MODE) {
setClickThrough(true);
}
} }
void TargetWindow::setFpsLimit(unsigned int fps_limit) void TargetWindow::setFpsLimit(unsigned int fps_limit)
@ -70,8 +82,13 @@ void TargetWindow::update()
on_close_(); on_close_();
} }
} }
window_.clear(sf::Color::Transparent); if (DEV_MODE) {
//window_.clear(sf::Color(255,0,0,1)); window_.clear(sf::Color(0, 0, 0, 128));
}
else {
window_.clear(sf::Color::Transparent);
}
window_.display(); window_.display();
} }

@ -30,4 +30,5 @@ class TargetWindow {
private: private:
const std::function<void()> on_close_; const std::function<void()> on_close_;
sf::RenderWindow window_; sf::RenderWindow window_;
}; };

@ -20,6 +20,10 @@ limitations under the License.
#include "SteamTarget.h" #include "SteamTarget.h"
#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>
//int CALLBACK WinMain( //int CALLBACK WinMain(
// _In_ HINSTANCE hInstance, // _In_ HINSTANCE hInstance,
// _In_ HINSTANCE hPrevInstance, // _In_ HINSTANCE hPrevInstance,
@ -34,6 +38,22 @@ limitations under the License.
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
const auto console_sink = std::make_shared<spdlog::sinks::stderr_color_sink_mt>();
console_sink->set_level(spdlog::level::trace);
#ifdef _WIN32
const auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("./glossitarget.log", true);
#else
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("/tmp/glossitarget.log", true);
#endif
file_sink->set_level(spdlog::level::trace);
std::vector<spdlog::sink_ptr> sinks{file_sink, console_sink};
auto logger = std::make_shared<spdlog::logger>("log", sinks.begin(), sinks.end());
logger->set_level(spdlog::level::trace);
logger->flush_on(spdlog::level::info);
spdlog::set_default_logger(logger);
SteamTarget target(argc, argv); SteamTarget target(argc, argv);
return target.run(); const auto exit = target.run();
spdlog::shutdown();
return exit;
} }

1
deps/WinReg vendored

@ -0,0 +1 @@
Subproject commit 023ad61dc77c83407e7ae061f177a3ba3d3941e6

1
deps/spdlog vendored

@ -0,0 +1 @@
Subproject commit 8826011c81b69e1f8427be520b357c19c74ea480
Loading…
Cancel
Save