Dota2Patcher
 
Loading...
Searching...
No Matches
interfaces.h
Go to the documentation of this file.
1#pragma once
2#include "CEngineClient.h"
3#include "CSource2Client.h"
4#include "CDOTAGamerules.h"
5#include "CDOTACamera.h"
6#include "CGameEntitySystem.h"
7#include "CSchemaSystem.h"
8#include "CCvar.h"
9#include "../Hacks/Hacks.h"
10
11class Scanner {
12public:
13 static inline bool find_CGameEntitySystem();
14 static inline bool find_CDOTACamera();
15 static inline bool find_CDOTAGamerules();
16
17 static inline bool find_all();
18};
19
20static class dota_interfaces {
21public:
22 static inline bool find_all() {
23 return Scanner::find_all();
24 }
25
26 static inline CEngineClient* engine = nullptr;
27 static inline CSource2Client* client = nullptr;
28 static inline CDOTAGamerules* gamerules = nullptr;
29 static inline CDOTACamera* camera = nullptr;
30 static inline CGameEntitySystem* entity_system = nullptr;
31 static inline CSchemaSystem* schema_system = nullptr;
32 static inline CCvar* cvar = nullptr;
33} vmt;
34
35
37 bool status = true;
38
39 status &= find_CGameEntitySystem();
40 status &= find_CDOTACamera();
41
42 return status;
43}
44
46 if (vmt.entity_system)
47 return true;
48
49 const auto base = Memory::virtual_function<uintptr_t>(vmt.client, 30);
50 if (!base)
51 return false;
52
53 const auto absolute_address_ptr = Memory::absolute_address<uintptr_t>(base.value());
54 if (!absolute_address_ptr)
55 return false;
56
57 const auto CGameEntitySystem_ptr = Memory::read_memory<uintptr_t>(absolute_address_ptr.value());
58 if (!CGameEntitySystem_ptr || CGameEntitySystem_ptr.value_or(0) == 0)
59 return false;
60
61 vmt.entity_system = reinterpret_cast<CGameEntitySystem*>(CGameEntitySystem_ptr.value());
62 LOG::INFO("CGameEntitySystem -> [{}]", TO_VOID(CGameEntitySystem_ptr.value()));
63 return true;
64}
65
66// #STR: "Failed to create camera\n", "Failed to init camera with file %s", "Usage: <camera_file>\n"
67// lea rax, ??_7CDOTACameraManager@@6B@ ; const CDOTACameraManager::`vftable'
68// mov cs:byte_1851E0C18, 0
69// mov cs:qword_1851E0B90, rax
70// lea rcx, sub_182FD0C10 ; void (__cdecl *)() <<<<
71// lea rax, ??_7CDOTACameraManager@@6B@_0 ; const CDOTACameraManager::`vftable'
72// mov cs:dword_1851E0C1C, 0FFFFFFFFh
73// mov cs:qword_1851E0B98, rax
74// call atexit
75// lea rcx, dword_1851E0C20
76// call _Init_thread_footer
77// jmp loc_181713F7F
78// endp
79//
80// sub_182FD0C10:
81// lea rax, ??_7CDOTACameraManager@@6B@ ; const CDOTACameraManager::`vftable'
82// mov cs:qword_1851E0B90, rax
83// lea rcx, qword_1851E0B90 <<<<
84// lea rax, ??_7CDOTACameraManager@@6B@_0 ; const CDOTACameraManager::`vftable'
85// mov cs:qword_1851E0B98, rax
86// jmp sub_181499FC0
87// endp
89 if (vmt.camera)
90 return true;
91
92 const auto base = Memory::pattern_scan("client.dll", Patches::Patterns::CDOTACamera);
93 if (!base)
94 return false;
95
96 const auto camera_base_address = Memory::absolute_address<uintptr_t>(base.value());
97 if (!camera_base_address || camera_base_address.value_or(0) == 0)
98 return false;
99
100 vmt.camera = reinterpret_cast<CDOTACamera*>(camera_base_address.value() - 0x40);
101 LOG::INFO("CDOTA_Camera -> [{}]", TO_VOID(vmt.camera));
102 return true;
103}
104
106 const auto dota_gamerules_proxy_ptr = vmt.entity_system->find_by_name(ENTITY_NAME_TYPE::BINARY_NAME, "C_DOTAGamerulesProxy");
107 if (!dota_gamerules_proxy_ptr)
108 return false;
109
110 C_DOTAGamerulesProxy* dota_gamerules_proxy = reinterpret_cast<C_DOTAGamerulesProxy*>(dota_gamerules_proxy_ptr.value());
111
112 const auto dota_gamerules_ptr = dota_gamerules_proxy->gamerules();
113 if (!dota_gamerules_ptr)
114 return false;
115
116 if (vmt.gamerules == dota_gamerules_ptr)
117 return false;
118
119 vmt.gamerules = dota_gamerules_ptr;
120 LOG::INFO("C_DOTAGamerules_Proxy -> [{}]", TO_VOID(dota_gamerules_proxy_ptr.value()));
121 LOG::INFO("CDOTAGamerules -> [{}]", TO_VOID(vmt.gamerules));
122 return true;
123}
Definition CCvar.h:29
Definition CDOTACamera.h:6
Definition CDOTAGamerules.h:4
Definition CEngineClient.h:3
Definition CGameEntitySystem.h:31
Definition CSchemaSystem.h:152
Definition CSource2Client.h:3
Definition CDOTAGamerules.h:26
CDOTAGamerules * gamerules() const
Definition CDOTAGamerules.h:28
static optional< T > read_memory(const N &address)
Definition Memory.h:78
static optional< uintptr_t > pattern_scan(const string &target_module, const string &target_pattern)
Definition Memory.cpp:25
Definition interfaces.h:11
static bool find_CDOTAGamerules()
Definition interfaces.h:105
static bool find_all()
Definition interfaces.h:36
static bool find_CDOTACamera()
Definition interfaces.h:88
static bool find_CGameEntitySystem()
Definition interfaces.h:45
static const string CDOTACamera
Definition Dota2Patcher.h:21