Skip to content

Commit

Permalink
init: initial
Browse files Browse the repository at this point in the history
  • Loading branch information
Surasia committed Aug 10, 2024
0 parents commit f27815c
Show file tree
Hide file tree
Showing 26 changed files with 2,964 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Set the default behavior for all files.
* text=auto eol=lf

# Normalized and converts to native line endings on checkout.
*.c text
*.cc text
*.cxx
*.cpp text
*.h text
*.hxx text
*.hpp text
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.vs/*
.vscode/*
/.vs
/.vscode
InfExt/src/x64
InfExt/src/x64/*
InfExt/src/build
x64/
/.stfolder
/.trunk
InfExt/build
InfExt/.vscode
vcpkg_installed
build
99 changes: 99 additions & 0 deletions InfExt/InfExt.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{7f811ff4-9143-4a89-a361-f949ea662808}</ProjectGuid>
<RootNamespace>InfExt</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>InfExt</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Label="Vcpkg">
<VcpkgEnableManifest>true</VcpkgEnableManifest>
</PropertyGroup>
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<VcpkgUseStatic>true</VcpkgUseStatic>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<LibraryPath>$(LibraryPath)</LibraryPath>
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);$(IncludePath)</IncludePath>
<OutDir>$(SolutionDir)\build\</OutDir>
<IntDir>$(SolutionDir)\build\compile\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;_USRDLL;SOL_ALL_SAFETIES_ON;WIN32_LEAN_AND_MEAN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>
</PrecompiledHeaderFile>
<LanguageStandard>stdcpplatest</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<ShowIncludes>false</ShowIncludes>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<ModuleDefinitionFile>
</ModuleDefinitionFile>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalOptions>/ignore:4099 /NODEFAULTLIB:library</AdditionalOptions>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
<IgnoreSpecificDefaultLibraries>msvcrtd.lib;LIBCMT.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="src\Client.hpp" />
<ClInclude Include="src\Exports.hpp" />
<ClInclude Include="src\HavokScript\HavokScript.hpp" />
<ClInclude Include="src\ImGuiHook\stdafx.h" />
<ClInclude Include="src\Lua\LuaHook.hpp" />
<ClInclude Include="src\Memory.hpp" />
<ClInclude Include="src\Misc\ChromaSDK.hpp" />
<ClInclude Include="src\Variant\Variant.hpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\Client.cpp" />
<ClCompile Include="src\HavokScript\HavokScript.cpp" />
<ClCompile Include="src\Lua\LuaHook.cpp" />
<ClCompile Include="src\Memory.cpp" />
<ClCompile Include="src\Misc\ChromaSDK.cpp" />
<ClCompile Include="src\Variant\Variant.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
59 changes: 59 additions & 0 deletions InfExt/InfExt.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\Client.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\Exports.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\Memory.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\HavokScript\HavokScript.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\Misc\ChromaSDK.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\Variant\Variant.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\ImGuiHook\stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\Lua\LuaHook.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\Client.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Memory.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\HavokScript\HavokScript.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Misc\ChromaSDK.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Variant\Variant.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Lua\LuaHook.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions InfExt/InfExt.vcxproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
</Project>
117 changes: 117 additions & 0 deletions InfExt/src/Client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#include "Client.hpp"
#include "Exports.hpp"
#include "./HavokScript/HavokScript.hpp"
#include "./Lua/LuaHook.hpp"
#include "./Misc/ChromaSDK.hpp"
#include "./Variant/Variant.hpp"

std::mutex consoleMutex;
std::condition_variable cv;
std::atomic<bool> stopThread(false);
std::thread mainThread;

DWORD WINAPI CreateConsole()
{
FILE *dummy = nullptr;
AllocConsole();
AttachConsole(GetCurrentProcessId());
{
std::lock_guard<std::mutex> lock(consoleMutex);
if (freopen_s(&dummy, "CONIN$", "r", stdin) != 0 || freopen_s(&dummy, "CONOUT$", "w", stdout) != 0 ||
freopen_s(&dummy, "CONOUT$", "w", stderr) != 0) {
std::cerr << "Failed to redirect console streams !" << std::endl;
return 1;
}
}
return 0;
}

DWORD WINAPI DestroyConsole()
{
if (FreeConsole() == 0) {
std::cerr << "Console failed to close!" << std::endl;
}

{
std::lock_guard<std::mutex> lock(consoleMutex);
freopen_s(reinterpret_cast<FILE **>(stdin), "NUL:", "r", stdin);
freopen_s(reinterpret_cast<FILE **>(stdout), "NUL:", "r", stdout);
freopen_s(reinterpret_cast<FILE **>(stderr), "NUL:", "r", stderr);
}

std::cin.clear();
std::cout.clear();
std::cerr.clear();
return 0;
}

DWORD WINAPI DestroyHook()
{
stopThread = true;
cv.notify_all();

if (mainThread.joinable()) {
mainThread.join();
}

MH_DisableHook(MH_ALL_HOOKS);
MH_Uninitialize();
return 0;
}

void ProcessCommands()
{
while (!stopThread) {
LuaVM::ProcessCommand();
}
}


static DWORD SetupHook()
{
uintptr_t ModuleBase = 0;

LPCSTR moduleName = "HaloInfinite.exe";
ModuleBase = reinterpret_cast<uintptr_t>(GetModuleHandleA(moduleName));
if (ModuleBase == 0) {
std::cerr << "Failed to get module handle for " << moduleName << std::endl;
return 1;
}

ChromaSDK::HookChroma(ModuleBase);
Hks::HookHavokScript(ModuleBase);
Variant::HookVariant(ModuleBase);

LuaVM::InitializeLua();
LuaVM::HookVariantFunctions();
mainThread = std::thread(ProcessCommands);
return 0;
}


DWORD WINAPI MainThread(LPVOID lpParameter)
{
SetupHook();
return 0;
}


BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{
switch (dwReason) {
case DLL_PROCESS_ATTACH:
CreateConsole();
DisableThreadLibraryCalls(hModule);
CreateThread(nullptr, 0, MainThread, nullptr, 0, nullptr);
break;
case DLL_PROCESS_DETACH:
DestroyHook();
LuaVM::CleanLua();
DestroyConsole();
FreeLibraryAndExitThread(hModule, TRUE);
break;
default:
break;
}
return TRUE;
}
24 changes: 24 additions & 0 deletions InfExt/src/Client.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef CLIENT_HPP
#define CLIENT_HPP


#include "../include/MinHook.h" // IWYU pragma: keep
#include <array> // IWYU pragma: keep
#include <consoleapi.h>
#include <cstring> // IWYU pragma: keep
#include <fstream> // IWYU pragma: keep
#include <functional> // IWYU pragma: keep
#include <iostream> // IWYU pragma: keep
#include <lua.hpp>
#include <map> // IWYU pragma: keep
#include <psapi.h>
#include <sstream> // IWYU pragma: keep
#include <string> // IWYU pragma: keep
#include <tchar.h>
#include <unordered_map> // IWYU pragma: keep
#include <variant> // IWYU pragma: keep
#include <windows.h>
#include <mutex>


#endif
Loading

0 comments on commit f27815c

Please sign in to comment.