summaryrefslogtreecommitdiff
path: root/src/cs2/entity.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/cs2/entity.h')
-rw-r--r--src/cs2/entity.h114
1 files changed, 114 insertions, 0 deletions
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 );
+}