summaryrefslogtreecommitdiff
path: root/src/cs2
diff options
context:
space:
mode:
authornavewindre <nw@moneybot.cc>2024-07-12 05:40:41 +0200
committernavewindre <nw@moneybot.cc>2024-07-12 05:40:41 +0200
commit28f41cf689def99fb586bfca47b7e1786227a5a2 (patch)
tree4a843c7785035ca548625ccf988ac924b8815f85 /src/cs2
parent2ebf959ec02048c15323e1bbfc63faedcf5067b6 (diff)
base shit
Diffstat (limited to 'src/cs2')
-rw-r--r--src/cs2/cs2.h46
-rw-r--r--src/cs2/hack.cpp22
-rw-r--r--src/cs2/hack.h9
-rw-r--r--src/cs2/iface.h106
-rw-r--r--src/cs2/schema.h0
5 files changed, 183 insertions, 0 deletions
diff --git a/src/cs2/cs2.h b/src/cs2/cs2.h
new file mode 100644
index 0000000..58eba14
--- /dev/null
+++ b/src/cs2/cs2.h
@@ -0,0 +1,46 @@
+#pragma once
+
+#include "../process64.h"
+
+class CS2 : public PROCESS64 {
+public:
+ CS2() : PROCESS64( "cs2.exe" ) {};
+
+ bool open() {
+ if( !PROCESS64::open() )
+ return false;
+
+ mod.client = get_module64( "client.dll"fnv );
+ mod.engine = get_module64( "engine.dll"fnv );
+ mod.schema = get_module64( "schemasystem.dll"fnv );
+
+ // todo: handle this using loader
+ iface.client = get_iface( "Source2Client0" );
+ iface.engine = get_iface( "Source2EngineToClient0" );
+
+ return true;
+ }
+
+ IFACE_ENTRY get_iface( const char* name ) {
+ 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;
+ }
+ }
+
+ return {};
+ }
+
+ struct {
+ MODULE_ENTRY client;
+ MODULE_ENTRY engine;
+ MODULE_ENTRY schema;
+ } mod;
+
+ struct {
+ IFACE_ENTRY client;
+ IFACE_ENTRY engine;
+ } iface;
+}; \ No newline at end of file
diff --git a/src/cs2/hack.cpp b/src/cs2/hack.cpp
new file mode 100644
index 0000000..b5f0242
--- /dev/null
+++ b/src/cs2/hack.cpp
@@ -0,0 +1,22 @@
+#include "hack.h"
+#include "iface.h"
+
+SETTING_HOLDER gcfg;
+
+#include "cs2.h"
+
+PROCESS64* hack_init() {
+ CS2* p = new CS2();
+ if( !p->open() ) {
+ delete p;
+ return nullptr;
+ }
+
+ VECTOR<IFACE_ENTRY> entries = iface_get_all( p );
+
+ return p;
+}
+
+bool hack_run( PROCESS64* p ) {
+ return true;
+} \ No newline at end of file
diff --git a/src/cs2/hack.h b/src/cs2/hack.h
new file mode 100644
index 0000000..18bd4e3
--- /dev/null
+++ b/src/cs2/hack.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#include "../process64.h"
+#include "../setting.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
new file mode 100644
index 0000000..6c3b34b
--- /dev/null
+++ b/src/cs2/iface.h
@@ -0,0 +1,106 @@
+#pragma once
+
+#include "../process64.h"
+
+struct IFACE_ENTRY {
+ U64 ptr;
+ STR<64> name;
+ U64 module;
+ STR<64> module_name;
+};
+
+struct IFACE_REG {
+ U64 create_fn;
+ U64 name;
+ U64 next;
+};
+
+inline bool iface_is_createinterface_export( PROCESS64* p, U64 exp ) {
+ U8 data[64];
+ p->read( exp, data, 64 );
+
+ // mov r9, cs:iface_list
+ // mov r10, rdx
+ return
+ data[0] == 0x4c && data[1] == 0x8b && data[2] == 0x0d &&
+ data[7] == 0x4c && data[8] == 0x8b && data[9] == 0xd2;
+}
+
+inline U64 iface_get_list( PROCESS64* p, U64 createiface ) {
+ U8 data[64];
+ p->read( createiface, data, 64 );
+
+ U32 off = *(U32*)&data[3];
+ U64 list = createiface + off + 7;
+
+ return p->read<U64>( list );
+}
+
+inline U64 iface_get_address( PROCESS64* p, U64 create_fn ) {
+ U8 data[64];
+ p->read( create_fn, data, 64 );
+
+ U32 off = *(U32*)&data[3];
+ U64 addr = create_fn + off + 7;
+}
+
+inline U64 iface_get_createinterface( PROCESS64* p, U64 module ) {
+ VECTOR<MODULE_EXPORT64> exports = module_get_exports64( module, p->get_base() );
+ for( auto& it : exports ) {
+ if( fnv1a( it.name ) == "CreateInterface"fnv )
+ return it.base;
+ }
+
+ return {};
+}
+
+inline VECTOR<IFACE_ENTRY> iface_dump_module( PROCESS64* p, MODULE_ENTRY module ) {
+ VECTOR<IFACE_ENTRY> entries;
+ U64 createiface, list, head, prev;
+ IFACE_REG reg;
+
+ createiface = iface_get_createinterface( p, module.base );
+ if( !createiface )
+ return entries;
+
+ if( !iface_is_createinterface_export( p, createiface ) )
+ return entries;
+
+ list = iface_get_list( p, createiface );
+ if( !list )
+ return entries;
+
+ head = list;
+ prev = 0;
+ p->read( head, &reg, sizeof( IFACE_REG ) );
+
+ for( ;; ) {
+ IFACE_ENTRY entry;
+ p->read( reg.name, entry.name.data, 64 );
+ entry.ptr = reg.create_fn;
+ entry.module = module.base;
+ entry.module_name = module.name;
+ entries.push_back( entry );
+
+ if( reg.next == head || reg.next == prev || !reg.next )
+ break;
+
+ prev = reg.next;
+ p->read( reg.next, &reg, sizeof( IFACE_REG ) );
+ }
+
+ return entries;
+}
+
+inline VECTOR<IFACE_ENTRY> iface_get_all( PROCESS64* p ) {
+ VECTOR<IFACE_ENTRY> entries;
+
+ VECTOR<MODULE_ENTRY> modules = p->dump_modules();
+ for( auto& it : modules ) {
+ VECTOR<IFACE_ENTRY> module_entries = iface_dump_module( p, it );
+ entries.insert( entries.end(), module_entries.begin(), module_entries.end() );
+ }
+
+ return entries;
+}
+
diff --git a/src/cs2/schema.h b/src/cs2/schema.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/cs2/schema.h