Skip to content

Commit

Permalink
The injector now checks for updates
Browse files Browse the repository at this point in the history
  • Loading branch information
AltimorTASDK committed Jun 16, 2021
1 parent 8ccd5b6 commit e029e91
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "striveinjector/cpp-httplib"]
path = striveinjector/cpp-httplib
url = https://github.com/yhirose/cpp-httplib
8 changes: 0 additions & 8 deletions strivehitboxes.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,17 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5EE1E800-E7E9-4FD9-90C2-A3943F1D438D}.Debug|x64.ActiveCfg = Debug|x64
{5EE1E800-E7E9-4FD9-90C2-A3943F1D438D}.Debug|x64.Build.0 = Debug|x64
{5EE1E800-E7E9-4FD9-90C2-A3943F1D438D}.Debug|x86.ActiveCfg = Debug|x64
{5EE1E800-E7E9-4FD9-90C2-A3943F1D438D}.Release|x64.ActiveCfg = Release|x64
{5EE1E800-E7E9-4FD9-90C2-A3943F1D438D}.Release|x64.Build.0 = Release|x64
{5EE1E800-E7E9-4FD9-90C2-A3943F1D438D}.Release|x86.ActiveCfg = Release|x64
{CC05D813-C703-4EC8-8330-31DE5CF6E0F4}.Debug|x64.ActiveCfg = Debug|x64
{CC05D813-C703-4EC8-8330-31DE5CF6E0F4}.Debug|x64.Build.0 = Debug|x64
{CC05D813-C703-4EC8-8330-31DE5CF6E0F4}.Debug|x86.ActiveCfg = Debug|Win32
{CC05D813-C703-4EC8-8330-31DE5CF6E0F4}.Debug|x86.Build.0 = Debug|Win32
{CC05D813-C703-4EC8-8330-31DE5CF6E0F4}.Release|x64.ActiveCfg = Release|x64
{CC05D813-C703-4EC8-8330-31DE5CF6E0F4}.Release|x64.Build.0 = Release|x64
{CC05D813-C703-4EC8-8330-31DE5CF6E0F4}.Release|x86.ActiveCfg = Release|Win32
{CC05D813-C703-4EC8-8330-31DE5CF6E0F4}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 4 additions & 2 deletions strivehitboxes/strivehitboxes.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>CURL_STATICLIB;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
Expand All @@ -68,7 +70,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>CURL_STATICLIB;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
Expand Down
1 change: 1 addition & 0 deletions striveinjector/cpp-httplib
Submodule cpp-httplib added at 676f1b
82 changes: 82 additions & 0 deletions striveinjector/main.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#define CPPHTTPLIB_OPENSSL_SUPPORT
#include "cpp-httplib/httplib.h"

#include <json/json.h>

#include <Windows.h>
#include <TlHelp32.h>
#include <Psapi.h>
#include <iostream>

const auto *exe = "GGST-Win64-Shipping.exe";
const auto *dll = "strivehitboxes.dll";
const auto *version = "v1.1";

bool elevate_privileges()
{
Expand Down Expand Up @@ -33,6 +39,80 @@ bool elevate_privileges()
return true;
}

bool get_newest_version(std::string *out)
{
httplib::Client client("https://api.github.com");
const auto result = client.Get("/repos/AltimorTASDK/strivehitboxes/tags");

if (result->status != 200)
return false;

const auto body = result->body;

Json::CharReaderBuilder builder;
const auto reader = builder.newCharReader();

Json::Value root;
if (!reader->parse(body.c_str(), body.c_str() + body.length(), &root, nullptr))
return false;

*out = root[0]["name"].asString();
return true;
}

int version_compare(const std::string &a, const std::string &b)
{
if (a.empty() || b.empty())
return 0;

// Skip "v" version prefix
size_t index_a = a[0] == 'v' ? 1 : 0;
size_t index_b = b[0] == 'v' ? 1 : 0;

while (true) {
const auto num_a = strtol(&a[index_a], nullptr, 10);
const auto num_b = strtol(&b[index_b], nullptr, 10);

if (num_a > num_b)
return 1;
else if (num_a < num_b)
return -1;

index_a = a.find('.', index_a);
index_b = b.find('.', index_b);

if (index_a != std::string::npos && index_b == std::string::npos)
return 1;
else if (index_a == std::string::npos && index_b != std::string::npos)
return -1;
else if (index_a == std::string::npos && index_b == std::string::npos)
return 0;

index_a++;
index_b++;
}
}

void check_version()
{
std::string newest;
if (!get_newest_version(&newest)) {
std::cerr << "Failed to check for updates." << std::endl;
return;
}

if (version_compare(version, newest) >= 0)
return;

std::cout << "A newer version (" << newest << ") of this tool is available at ";
std::cout << "https://github.com/AltimorTASDK/strivehitboxes/releases" << std::endl;
std::cout << "Your version: " << version << std::endl;
std::cout << std::endl;
std::cout << "Press enter to continue anyways." << std::endl;

std::cin.get();
}

bool inject()
{
if (!elevate_privileges())
Expand Down Expand Up @@ -93,6 +173,8 @@ bool inject()

int main()
{
check_version();

const auto result = inject();
Sleep(2000);
return result ? 0 : 1;
Expand Down
14 changes: 14 additions & 0 deletions striveinjector/striveinjector.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,19 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<LibraryPath>$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<VcpkgUseStatic>true</VcpkgUseStatic>
</PropertyGroup>
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<VcpkgUseStatic>true</VcpkgUseStatic>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand Down Expand Up @@ -117,10 +127,12 @@
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -132,12 +144,14 @@
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down

0 comments on commit e029e91

Please sign in to comment.