diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | dwm/dwm.vcxproj | 159 | ||||
| -rw-r--r-- | dwm/dwm.vcxproj.filters | 30 | ||||
| -rw-r--r-- | dwm/dwm.vcxproj.user | 4 | ||||
| -rw-r--r-- | dwm/source.cpp | 12 | ||||
| -rw-r--r-- | dwm/typedef.h | 2 | ||||
| -rw-r--r-- | dwm/util.h | 2 | ||||
| -rw-r--r-- | heavens-gate.sln | 20 | ||||
| -rw-r--r-- | src/cs2/cs2.h | 1 | ||||
| -rw-r--r-- | src/cs2/entity.cpp | 4 | ||||
| -rw-r--r-- | src/cs2/entity.h | 114 | ||||
| -rw-r--r-- | src/cs2/hack.cpp | 26 | ||||
| -rw-r--r-- | src/cs2/hack.h | 2 | ||||
| -rw-r--r-- | src/cs2/iface.h | 14 | ||||
| -rw-r--r-- | src/cs2/schema.h | 71 | ||||
| -rw-r--r-- | src/heavens-gate.vcxproj | 4 | ||||
| -rw-r--r-- | src/heavens-gate.vcxproj.filters | 12 | ||||
| -rw-r--r-- | src/perf.cpp | 23 | ||||
| -rw-r--r-- | src/perf.h | 23 | ||||
| -rw-r--r-- | src/source.cpp | 12 | ||||
| -rw-r--r-- | src/typedef.h | 5 | ||||
| -rw-r--r-- | src/util.cpp | 16 | ||||
| -rw-r--r-- | src/util.h | 6 |
23 files changed, 546 insertions, 17 deletions
@@ -42,5 +42,6 @@ src/Release/* src/X64/* .idea/* .vs/* +.vscode/* bin/*
\ No newline at end of file diff --git a/dwm/dwm.vcxproj b/dwm/dwm.vcxproj new file mode 100644 index 0000000..bab2871 --- /dev/null +++ b/dwm/dwm.vcxproj @@ -0,0 +1,159 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <VCProjectVersion>16.0</VCProjectVersion> + <Keyword>Win32Proj</Keyword> + <ProjectGuid>{33618e8d-258b-4ce2-968c-ae0ea1f2162e}</ProjectGuid> + <RootNamespace>dwm</RootNamespace> + <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v142</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)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </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 Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <LinkIncremental>true</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <LinkIncremental>false</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(SolutionDir)\bin\</OutDir> + <IntDir>..\intermediate\X64\$(Configuration)\</IntDir> + <TargetName>dwmhook</TargetName> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LinkIncremental>false</LinkIncremental> + <OutDir>$(SolutionDir)\bin\</OutDir> + <IntDir>..\intermediate\X64\$(Configuration)\</IntDir> + <TargetName>dwmhook</TargetName> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions);X64</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + <LanguageStandard>stdcpp17</LanguageStandard> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions);X64</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + <LanguageStandard>stdcpp17</LanguageStandard> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <ClCompile Include="source.cpp" /> + </ItemGroup> + <ItemGroup> + <ClInclude Include="typedef.h" /> + <ClInclude Include="util.h" /> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project>
\ No newline at end of file diff --git a/dwm/dwm.vcxproj.filters b/dwm/dwm.vcxproj.filters new file mode 100644 index 0000000..37e74bf --- /dev/null +++ b/dwm/dwm.vcxproj.filters @@ -0,0 +1,30 @@ +<?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> + <Filter Include="Resource Files"> + <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> + <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> + </Filter> + </ItemGroup> + <ItemGroup> + <ClCompile Include="source.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + </ItemGroup> + <ItemGroup> + <ClInclude Include="typedef.h"> + <Filter>Source Files</Filter> + </ClInclude> + <ClInclude Include="util.h"> + <Filter>Source Files</Filter> + </ClInclude> + </ItemGroup> +</Project>
\ No newline at end of file diff --git a/dwm/dwm.vcxproj.user b/dwm/dwm.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/dwm/dwm.vcxproj.user @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup /> +</Project>
\ No newline at end of file diff --git a/dwm/source.cpp b/dwm/source.cpp new file mode 100644 index 0000000..c8d4951 --- /dev/null +++ b/dwm/source.cpp @@ -0,0 +1,12 @@ +#include <windows.h> +#include "typedef.h" + + +int __stdcall DllMain( void* hinst, U32 reason, void* reserved ) { + // coca cola yayo bought me this + if( reason == DLL_PROCESS_ATTACH ) { + // do a fucking EPIC here + + return 1; + } +}
\ No newline at end of file diff --git a/dwm/typedef.h b/dwm/typedef.h new file mode 100644 index 0000000..8d532d4 --- /dev/null +++ b/dwm/typedef.h @@ -0,0 +1,2 @@ +#pragma once +#include "../src/typedef.h"
\ No newline at end of file diff --git a/dwm/util.h b/dwm/util.h new file mode 100644 index 0000000..b723112 --- /dev/null +++ b/dwm/util.h @@ -0,0 +1,2 @@ +#pragma once +#include "../src/util.h"
\ No newline at end of file diff --git a/heavens-gate.sln b/heavens-gate.sln index aa3a577..754b908 100644 --- a/heavens-gate.sln +++ b/heavens-gate.sln @@ -5,19 +5,39 @@ VisualStudioVersion = 16.0.32002.261 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "heavens-gate", "src\heavens-gate.vcxproj", "{D2960E74-5A8F-4D86-9788-7BBAF0248F68}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dwm", "dwm\dwm.vcxproj", "{33618E8D-258B-4CE2-968C-AE0EA1F2162E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + debug|x64 = debug|x64 debug|x86 = debug|x86 + release|x64 = release|x64 release|x86 = release|x86 + stripped|x64 = stripped|x64 stripped|x86 = stripped|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D2960E74-5A8F-4D86-9788-7BBAF0248F68}.debug|x64.ActiveCfg = Debug|Win32 {D2960E74-5A8F-4D86-9788-7BBAF0248F68}.debug|x86.ActiveCfg = Debug|Win32 {D2960E74-5A8F-4D86-9788-7BBAF0248F68}.debug|x86.Build.0 = Debug|Win32 + {D2960E74-5A8F-4D86-9788-7BBAF0248F68}.release|x64.ActiveCfg = Release|Win32 {D2960E74-5A8F-4D86-9788-7BBAF0248F68}.release|x86.ActiveCfg = Release|Win32 {D2960E74-5A8F-4D86-9788-7BBAF0248F68}.release|x86.Build.0 = Release|Win32 + {D2960E74-5A8F-4D86-9788-7BBAF0248F68}.stripped|x64.ActiveCfg = stripped|Win32 {D2960E74-5A8F-4D86-9788-7BBAF0248F68}.stripped|x86.ActiveCfg = stripped|Win32 {D2960E74-5A8F-4D86-9788-7BBAF0248F68}.stripped|x86.Build.0 = stripped|Win32 + {33618E8D-258B-4CE2-968C-AE0EA1F2162E}.debug|x64.ActiveCfg = Debug|x64 + {33618E8D-258B-4CE2-968C-AE0EA1F2162E}.debug|x64.Build.0 = Debug|x64 + {33618E8D-258B-4CE2-968C-AE0EA1F2162E}.debug|x86.ActiveCfg = Debug|Win32 + {33618E8D-258B-4CE2-968C-AE0EA1F2162E}.debug|x86.Build.0 = Debug|Win32 + {33618E8D-258B-4CE2-968C-AE0EA1F2162E}.release|x64.ActiveCfg = Release|x64 + {33618E8D-258B-4CE2-968C-AE0EA1F2162E}.release|x64.Build.0 = Release|x64 + {33618E8D-258B-4CE2-968C-AE0EA1F2162E}.release|x86.ActiveCfg = Release|x64 + {33618E8D-258B-4CE2-968C-AE0EA1F2162E}.release|x86.Build.0 = Release|x64 + {33618E8D-258B-4CE2-968C-AE0EA1F2162E}.stripped|x64.ActiveCfg = Debug|x64 + {33618E8D-258B-4CE2-968C-AE0EA1F2162E}.stripped|x64.Build.0 = Debug|x64 + {33618E8D-258B-4CE2-968C-AE0EA1F2162E}.stripped|x86.ActiveCfg = Debug|Win32 + {33618E8D-258B-4CE2-968C-AE0EA1F2162E}.stripped|x86.Build.0 = Debug|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/cs2/cs2.h b/src/cs2/cs2.h index db136b9..f8a3f9b 100644 --- a/src/cs2/cs2.h +++ b/src/cs2/cs2.h @@ -14,7 +14,6 @@ public: VECTOR<IFACE_ENTRY> entries = iface_get_all( this ); for( auto it : entries ) { if( strncmp( it.name, name, strlen( name ) ) == 0 ) { - clog( "iface %s: [%llx]\n", it.name.data, it.ptr ); return it; } } diff --git a/src/cs2/entity.cpp b/src/cs2/entity.cpp new file mode 100644 index 0000000..36265e0 --- /dev/null +++ b/src/cs2/entity.cpp @@ -0,0 +1,4 @@ +#include "entity.h" + +CS2* CS2_PAWN::cs; +CS2* CS2_PLAYERCONTROLLER::cs;
\ No newline at end of file diff --git a/src/cs2/entity.h b/src/cs2/entity.h new file mode 100644 index 0000000..999f776 --- /dev/null +++ b/src/cs2/entity.h @@ -0,0 +1,114 @@ +#pragma once +#include "cs2.h" +#include "schema.h" + +static U64 cs2_ent_get_list( CS2* p ); +inline U64 cs2_ent_from_idx( CS2* p, U32 idx ); +inline U64 cs2_ent_from_handle( CS2* p, U32 handle ); +class CS2_PLAYERCONTROLLER; + +class CS2_PAWN { +public: + CS2_PAWN( U64 _ptr ) : ptr( _ptr ) {} + CS2_PAWN() : ptr( 0 ) {} + operator U64() { return ptr; } + + NETVAR_MOD( I32, m_iHealth, "C_BaseEntity", "client.dll" ); + + U64 ptr; + static CS2* cs; +}; + +class CS2_PLAYERCONTROLLER { +public: + CS2_PLAYERCONTROLLER( U64 _ptr ) : ptr( _ptr ) {} + CS2_PLAYERCONTROLLER() : ptr( 0 ) {} + operator U64() { return ptr; } + + NETVAR_MOD( U32, m_hPawn, "CBasePlayerController", "client.dll" ); + + STR<128> m_sSanitizedPlayerName() { + static I32 off = schema_get_offset( cs, "CCSPlayerController", "m_sSanitizedPlayerName", "client.dll" ); + + STR<128> ret; + U64 str = cs->read<U64>( ptr + off ); + cs->read( str, ret, sizeof( ret ) ); + + return ret; + } + + CS2_PAWN get_pawn() { + return cs2_ent_from_handle( cs, m_hPawn() ); + } + + U64 ptr; + static CS2* cs; +}; + +// ------------------------------------------------------------------------------------------------ + +static U64 cs2_ent_get_list( CS2* p ) { + static U64 entitylist = 0; + + if( !entitylist ) { + if( !CS2_PLAYERCONTROLLER::cs ) + CS2_PLAYERCONTROLLER::cs = CS2_PAWN::cs = p; + U64 client = p->mod.client.base; + + // GetEntityByIndex + // xref str: '%s' : '%s' (entindex %d) \n, + // ent_find_index cvar + U64 call = p->code_match( p->mod.client.base, "E8 ? ? ? ? 48 8B D0 48 8B CE FF D7" ); + assert( !!call ); + + U32 off = p->read<U32>( call + 1 ) + 5; + U64 fn = call + off; + + U8 bytes[32]; + p->read( fn, bytes, sizeof( bytes ) ); + + if( bytes[0] != 0x8b || bytes[1] != 0xd1 || // mov edx, ecx + bytes[2] != 0x48 || bytes[3] != 0x8b || bytes[4] != 0x0d // mov rcx, entlist + ) { + assert( false ); + return 0; + } + + off = *(U32*)&bytes[5]; + entitylist = p->read<U64>( fn + off + 9 ); + } + + return entitylist; +} + +// ? ? ? ? ? +// i really wanna know what the actual c++ looks like. +inline U64 cs2_ent_from_idx( CS2* p, U32 idx ) { + U64 entlist = cs2_ent_get_list( p ); + if( !entlist ) + return 0; + + if( idx >= 0x7fff ) + return 0; + + if( (idx >> 9) > 0x3f ) + return 0; + + U64 v2 = entlist + 8 * (idx >> 9) + 0x10; + v2 = p->read<U64>( v2 ); + if( !v2 ) + return 0; + + U64 v3 = 0x78 * (idx & 0x1ff) + v2; + if( !v3 ) + return 0; + + return p->read<U64>( v3 ); +} + +inline U64 cs2_ent_from_handle( CS2* p, U32 handle ) { + if( handle == 0xffffffff ) + return 0; + + return cs2_ent_from_idx( p, handle & 0x7fff ); +} diff --git a/src/cs2/hack.cpp b/src/cs2/hack.cpp index ef4008d..c98337a 100644 --- a/src/cs2/hack.cpp +++ b/src/cs2/hack.cpp @@ -1,9 +1,10 @@ #include "hack.h" +#include "entity.h" +#include "entity.h" #include "iface.h" SETTING_HOLDER gcfg; -#include "cs2.h" PROCESS64* hack_init() { CS2* p = new CS2(); @@ -12,9 +13,32 @@ PROCESS64* hack_init() { return nullptr; } + schema_dump_to_file( p ); + iface_dump_to_file( p ); + return p; } bool hack_run( PROCESS64* p ) { + perf_run_metric( perf_loop_start ); + CS2* cs = (CS2*)p; + + for( I32 i = 0; i < 64; ++i ) { + CS2_PLAYERCONTROLLER pc = cs2_ent_from_idx( cs, i ); + if( !pc ) + continue; + + CS2_PAWN pawn = pc.get_pawn(); + if( !pawn ) + continue; + + STR<128> name = pc.m_sSanitizedPlayerName(); + I32 health = pawn.m_iHealth(); + + clog( "player %d [%llx]: %s, health %d\n", i, pc.ptr, name.data, health ); + } + + + perf_run_metric( perf_loop_end ); return true; }
\ No newline at end of file diff --git a/src/cs2/hack.h b/src/cs2/hack.h index 18bd4e3..3ba769a 100644 --- a/src/cs2/hack.h +++ b/src/cs2/hack.h @@ -2,8 +2,10 @@ #include "../process64.h" #include "../setting.h" +#include "../perf.h" extern SETTING_HOLDER gcfg; + extern PROCESS64* hack_init(); extern bool hack_run( PROCESS64* p );
\ No newline at end of file diff --git a/src/cs2/iface.h b/src/cs2/iface.h index be2137d..61cd91c 100644 --- a/src/cs2/iface.h +++ b/src/cs2/iface.h @@ -109,3 +109,17 @@ inline VECTOR<IFACE_ENTRY> iface_get_all( PROCESS64* p ) { return entries; } +inline void iface_dump_to_file( PROCESS64* p ) { + VECTOR<IFACE_ENTRY> entries = iface_get_all( p ); + + static STR<9999999> output; + memset( output, 0, sizeof( output.data ) ); + + for( auto& it : entries ) { + U64 off = it.ptr - it.module; + + sprintf( output, "%siface: %s @%s+0x%llx [0x%llx]\n", output.data, it.name.data, it.module_name.data, off, it.ptr ); + } + + u_write_to_file( output.data, "interfaces.txt" ); +}
\ No newline at end of file diff --git a/src/cs2/schema.h b/src/cs2/schema.h index f99683d..1c55906 100644 --- a/src/cs2/schema.h +++ b/src/cs2/schema.h @@ -3,6 +3,54 @@ #include "../util.h" #include "sdk.h" +#define NETVAR(type, name, classn) \ +type name() { \ + static I32 off = schema_get_offset( cs, classn, #name ); \ + assert( !!off ); \ + return cs->read<type>( ptr + off ); \ +} \ +void name( type val ) { \ + static I32 off = schema_get_offset( cs, classn, #name ); \ + assert( !!off ); \ + cs->write( ptr + off, val ); \ +} \ + +#define NETVARO(type, name, classn, off1) \ +type name() { \ + static I32 off = schema_get_offset( cs, classn, #name ); \ + assert( !!off ); \ + return cs->read<type>( ptr + off + off1 ); \ +} \ +void name( type val ) { \ + static I32 off = schema_get_offset( cs, classn, #name ); \ + cs->write( ptr + off + off1, val ); \ +} \ + +#define NETVAR_MOD(type, name, classn, mod) \ +type name() { \ + static I32 off = schema_get_offset( cs, classn, #name, mod ); \ + assert( !!off ); \ + return cs->read<type>( ptr + off ); \ +} \ +void name( type val ) { \ + static I32 off = schema_get_offset( cs, classn, #name, mod ); \ + assert( !!off ); \ + cs->write( ptr + off, val ); \ +} \ + +#define NETVARO_MOD(type, name, classn, off1, mod) \ +type name() { \ + static I32 off = schema_get_offset( cs, classn, #name, mod ); \ + assert( !!off ); \ + return cs->read<type>( ptr + off + off1 ) mod; \ +} \ +void name( type val ) { \ + static I32 off = schema_get_offset( cs, classn, #name, mod ); \ + assert( !!off ); \ + cs->write( ptr + off + off1, val mod ); \ +} \ + + inline CS2_SCHEMA_FIELD* schema_class_get_fields( CS2* p, CS2_SCHEMA_CLASS* schclass ) { if( !schclass->fields || !schclass->num_fields ) @@ -75,8 +123,8 @@ static VECTOR<NETVAR_ENTRY> schema_get_all( CS2* p ) { for( U32 j = 0; j < scope->num_classes; ++j ) { CS2_SCHEMA_CLASS* schclass = &classes[j]; - STR<128> classname{}; - p->read( schclass->name, classname.data, 128 ); + STR<256> classname{}; + p->read( schclass->name, classname.data, 256 ); if( classname.data[0] == 0 || !strlen( classname ) ) continue; @@ -93,8 +141,9 @@ static VECTOR<NETVAR_ENTRY> schema_get_all( CS2* p ) { STR<256> buf; p->read( field->name, buf.data, 256 ); entry.prop = buf; - entry.clientclass = buf; - entry.scope = scope->name; + entry.clientclass = classname; + entry.scope = scope->name; + entry.offset = (I32)field->offset; entries.push_back( entry ); } @@ -108,6 +157,20 @@ static VECTOR<NETVAR_ENTRY> schema_get_all( CS2* p ) { return entries; } +static I32 schema_get_offset( CS2* p, const char* classname, const char* prop, const char* scope = nullptr ) { + if( p->netvars.empty() ) + p->netvars = schema_get_all( p ); + + for( auto& it : p->netvars ) { + if( !strcmp( it.clientclass, classname ) && !strcmp( it.prop, prop ) ) { + if( !scope || !strcmp( it.scope, scope ) ) + return it.offset; + } + } + + return -1; +} + static void schema_dump_to_file( CS2* p ) { CS2_SCHEMA schema = schema_read_iface( p, p->iface.schema.ptr ); diff --git a/src/heavens-gate.vcxproj b/src/heavens-gate.vcxproj index 0a41f0b..a7a20bc 100644 --- a/src/heavens-gate.vcxproj +++ b/src/heavens-gate.vcxproj @@ -198,9 +198,11 @@ <ClCompile Include="conout.cpp" /> <ClCompile Include="conin.cpp" /> <ClCompile Include="cs2\cs2.cpp" /> + <ClCompile Include="cs2\entity.cpp" /> <ClCompile Include="cs2\hack.cpp" /> <ClCompile Include="menu.cpp" /> <ClCompile Include="ntutil.cpp" /> + <ClCompile Include="perf.cpp" /> <ClCompile Include="setting.cpp" /> <ClCompile Include="source.cpp" /> <ClCompile Include="util.cpp" /> @@ -208,6 +210,7 @@ <ItemGroup> <ClInclude Include="asmutil.h" /> <ClInclude Include="cs2\cs2.h" /> + <ClInclude Include="cs2\entity.h" /> <ClInclude Include="cs2\hack.h" /> <ClInclude Include="cs2\iface.h" /> <ClInclude Include="cs2\schema.h" /> @@ -216,6 +219,7 @@ <ClInclude Include="fnv.h" /> <ClInclude Include="inet.h" /> <ClInclude Include="mouse.h" /> + <ClInclude Include="perf.h" /> <ClInclude Include="process32.h" /> <ClInclude Include="process64.h" /> <ClInclude Include="resource.h" /> diff --git a/src/heavens-gate.vcxproj.filters b/src/heavens-gate.vcxproj.filters index 643ec4f..2140028 100644 --- a/src/heavens-gate.vcxproj.filters +++ b/src/heavens-gate.vcxproj.filters @@ -20,6 +20,12 @@ <ClCompile Include="cs2\cs2.cpp"> <Filter>Game</Filter> </ClCompile> + <ClCompile Include="cs2\entity.cpp"> + <Filter>Game</Filter> + </ClCompile> + <ClCompile Include="perf.cpp"> + <Filter>Util</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="typedef.h" /> @@ -81,6 +87,12 @@ <ClInclude Include="cs2\sdk.h"> <Filter>Game</Filter> </ClInclude> + <ClInclude Include="cs2\entity.h"> + <Filter>Game</Filter> + </ClInclude> + <ClInclude Include="perf.h"> + <Filter>Util</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <Filter Include="Console"> diff --git a/src/perf.cpp b/src/perf.cpp new file mode 100644 index 0000000..b8f29a6 --- /dev/null +++ b/src/perf.cpp @@ -0,0 +1,23 @@ +#if defined DEBUG || defined PERF_DEBUG +#include "perf.h" + +PERF_DATA perf; + +U64 last_loop = 0; + +void perf_loop_begin() { + perf.readctr = perf.writectr = 0; + + if( !last_loop ) { + last_loop = u_tick(); + } +} + +void perf_loop_end() { + U64 tick = u_tick(); + U64 delta = last_loop - tick; + perf.ticks = delta; + + last_loop = tick; +} +#endif
\ No newline at end of file diff --git a/src/perf.h b/src/perf.h new file mode 100644 index 0000000..25190a8 --- /dev/null +++ b/src/perf.h @@ -0,0 +1,23 @@ +#pragma once +#if defined DEBUG || defined PERF_DEBUG +#include "typedef.h" + +struct PERF_DATA { + U64 ticks; + U64 lastwrites; + U64 lastreads; + U64 avgwrites; + U64 avgreads; + + U64 writectr; + U64 readctr; +}; + +extern void perf_loop_begin(); +extern void perf_loop_end(); + +extern PERF_DATA perf; +#define perf_run_metric( x ) x() +#else +#define perf_run_metric( x ) +#endif diff --git a/src/source.cpp b/src/source.cpp index 1ce0754..b27149f 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -1,6 +1,8 @@ //|_ _ _. _ ._ |_ _. _ | //| | (/_ (_| \/ (/_ | | | | (_| (_ |< +//#define PERF_DEBUG 1 + #include "cs2/hack.h" #include "conin.h" #include "menu.h" @@ -9,18 +11,10 @@ bool run() { con_init(); PROCESS64* p = hack_init(); - Sleep( 1000 ); gcfg.load(); - menu_show_ui( p ); - for( ;; ) { - if( !hack_run( p ) ) { - nt_close64( p->get_base() ); - u_sleep( 5 * T_SEC ); - break; - } - } + for( ; hack_run( p ); ); return false; } diff --git a/src/typedef.h b/src/typedef.h index 97b17da..5cbc038 100644 --- a/src/typedef.h +++ b/src/typedef.h @@ -21,8 +21,11 @@ typedef unsigned long long U64; typedef float F32; typedef double F64; +#ifdef X64 +typedef unsigned long long PTR; +#else typedef unsigned long PTR; - +#endif #define assert( x ) if( !x ) con_set_assert( "ASSERTION FAILED: %s() (line: %d)", __func__, __LINE__ ) #define pause() system( "pause" )
\ No newline at end of file diff --git a/src/util.cpp b/src/util.cpp index 81b1192..7f47677 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -8,11 +8,25 @@ ULONG u_thread_create( LPTHREAD_START_ROUTINE routine, void* param ) { REG64 thread; ULONG ret_id; +#ifndef X64 nt_create_thread64( &thread, 0x1fffff, 0, GetCurrentProcess(), routine, param, 0 ); ret_id = GetThreadId( (HANDLE)thread.u32[0] ); nt_close64( thread ); - +#else + static auto nt_create_thread = (NTSTATUS(__stdcall*)( + PHANDLE, + ACCESS_MASK, + POBJECT_ATTRIBUTES, + HANDLE, + PCLIENT_ID, + PCONTEXT, + PINITIAL_TEB, + BOOLEAN) + )GetProcAddress( GetModuleHandleA( "ntdll.dll" ), "NtCreateThread" ); + + //aaa +#endif return ret_id; } @@ -181,4 +181,10 @@ inline U64 u_tick() { inline F64 u_time() { constexpr F64 NSEC_TO_SEC = 1.f / T_SEC; return u_tick() * NSEC_TO_SEC; +} + +inline void u_write_to_file( const char* str, const char* file ) { + FILE* f = fopen( file, "w" ); + fwrite( str, 1, strlen( str ), f ); + fclose( f ); }
\ No newline at end of file |
