summaryrefslogtreecommitdiff
path: root/src/cs2
diff options
context:
space:
mode:
Diffstat (limited to 'src/cs2')
-rw-r--r--src/cs2/cs2.h1
-rw-r--r--src/cs2/entity.cpp4
-rw-r--r--src/cs2/entity.h114
-rw-r--r--src/cs2/hack.cpp26
-rw-r--r--src/cs2/hack.h2
-rw-r--r--src/cs2/iface.h14
-rw-r--r--src/cs2/schema.h71
7 files changed, 226 insertions, 6 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 );