diff options
Diffstat (limited to 'src')
| -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 |
15 files changed, 316 insertions, 17 deletions
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 |
