Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
Hooks.cpp
Go to the documentation of this file.
1#include "Hooks.h"
2
3#include <string>
4
5#include <Logger/Logger.h>
6
7#include "Offsets.h"
8#include "IBaseApi.h"
9#include <detours.h>
10
11namespace API
12{
14 {
15 //No Longer Required.
16 }
17
19 {
21 if (target == nullptr)
22 {
23 Log::GetLog()->error("{} does not exist", func_name);
24 return false;
25 }
26
28
30 ? target
32
33
35 {
36 Log::GetLog()->error("Failed to create Detour Transaction for {}", func_name);
38 return false;
39 }
41 {
42 Log::GetLog()->error("Failed to update thread for {}", func_name);
44 return false;
45 }
47 {
48 Log::GetLog()->error("Failed to attach hook for {}", func_name);
50 return false;
51 }
52
54 {
55 Log::GetLog()->error("Failed to commit Detour Transaction for {}", func_name);
57 return false;
58 }
59 *original = new_target; //same as ppOriginal in MH_CreateHook
60
62
63 return true;
64 }
65
67 {
69 if (target == nullptr)
70 {
71 Log::GetLog()->error("{} does not exist", func_name);
72 return false;
73 }
74
76
77 const auto iter = std::find_if(hook_vector.begin(), hook_vector.end(),
78 [detour](const std::shared_ptr<Hook>& hook) -> bool
79 {
80 return hook->detour == detour;
81 });
82
83 if (iter == hook_vector.end())
84 {
85 Log::GetLog()->warn("Failed to find hook ({})", func_name);
86 return false;
87 }
88
90 {
91 Log::GetLog()->error("Failed to create Detour Transaction for {}", func_name);
93 return false;
94 }
96 {
97 Log::GetLog()->error("Failed to update thread for {}", func_name);
99 return false;
100 }
101
102 // Remove all hooks placed on this function
103 for (const auto& hook : hook_vector)
104 {
106 {
107 Log::GetLog()->error("Failed to detach Detour Transaction for {}", func_name);
109 return false;
110 }
111 }
112
114 {
115 Log::GetLog()->error("Failed to commit Detour Transaction for {}", func_name);
117 return false;
118 }
119
120 // Remove hook from all_hooks vector
122
125
126 // Enable all hooks again
127 for (const auto& hook : hook_vec)
128 {
130 }
131
132 return true;
133 }
134} // namespace API
135
136// Free function
138{
139 return reinterpret_cast<IHooks&>(*API::game_api->GetHooks());
140}
Definition IBaseApi.h:9
ARK_API IHooks &APIENTRY GetHooks()
Definition Hooks.cpp:137