1717#include < ios>
1818#include < sstream>
1919
20- #include " scripting/autonative.h"
2120#include " core/function.h"
22- #include " scripting/script_engine.h"
23- #include " core/memory.h"
2421#include " core/log.h"
22+ #include " core/memory.h"
23+ #include " scripting/autonative.h"
24+ #include " scripting/script_engine.h"
2525
2626namespace counterstrikesharp {
2727std::vector<ValveFunction*> m_managed_ptrs;
@@ -44,21 +44,22 @@ ValveFunction* CreateVirtualFunctionBySignature(ScriptContext& script_context)
4444
4545 auto * function_addr = FindSignature (binary_name, signature_hex_string);
4646
47- if (function_addr == nullptr ) {
47+ if (function_addr == nullptr )
48+ {
4849 script_context.ThrowNativeError (" Could not find signature %s" , signature_hex_string);
4950 return nullptr ;
5051 }
5152
5253 auto args = std::vector<DataType_t>();
53- for (int i = 0 ; i < num_arguments; i++) {
54+ for (int i = 0 ; i < num_arguments; i++)
55+ {
5456 args.push_back (script_context.GetArgument <DataType_t>(5 + i));
5557 }
5658
5759 auto function = new ValveFunction (function_addr, CONV_CDECL, args, return_type);
5860 function->SetSignature (signature_hex_string);
5961
60- CSSHARP_CORE_TRACE (" Created virtual function, pointer found at {}, signature {}" , function_addr,
61- signature_hex_string);
62+ CSSHARP_CORE_TRACE (" Created virtual function, pointer found at {}, signature {}" , function_addr, signature_hex_string);
6263
6364 m_managed_ptrs.push_back (function);
6465 return function;
@@ -72,15 +73,17 @@ ValveFunction* CreateVirtualFunction(ScriptContext& script_context)
7273 auto return_type = script_context.GetArgument <DataType_t>(3 );
7374
7475 void ** vtable = *(void ***)ptr;
75- if (!vtable) {
76+ if (!vtable)
77+ {
7678 script_context.ThrowNativeError (" Failed to get the virtual function table." );
7779 return nullptr ;
7880 }
7981
8082 auto function_addr = (void *)vtable[vtable_offset];
8183
8284 auto args = std::vector<DataType_t>();
83- for (int i = 0 ; i < num_arguments; i++) {
85+ for (int i = 0 ; i < num_arguments; i++)
86+ {
8487 args.push_back (script_context.GetArgument <DataType_t>(4 + i));
8588 }
8689
@@ -97,7 +100,8 @@ void HookFunction(ScriptContext& script_context)
97100 auto callback = script_context.GetArgument <CallbackT>(1 );
98101 auto post = script_context.GetArgument <bool >(2 );
99102
100- if (!function) {
103+ if (!function)
104+ {
101105 script_context.ThrowNativeError (" Invalid function pointer" );
102106 return ;
103107 }
@@ -111,7 +115,8 @@ void UnhookFunction(ScriptContext& script_context)
111115 auto callback = script_context.GetArgument <CallbackT>(1 );
112116 auto post = script_context.GetArgument <bool >(2 );
113117
114- if (!function) {
118+ if (!function)
119+ {
115120 script_context.ThrowNativeError (" Invalid function pointer" );
116121 return ;
117122 }
@@ -123,7 +128,8 @@ void ExecuteVirtualFunction(ScriptContext& script_context)
123128{
124129 auto function = script_context.GetArgument <ValveFunction*>(0 );
125130
126- if (!function) {
131+ if (!function)
132+ {
127133 script_context.ThrowNativeError (" Invalid function pointer" );
128134 return ;
129135 }
@@ -140,23 +146,22 @@ int GetNetworkVectorSize(ScriptContext& script_context)
140146
141147void * GetNetworkVectorElementAt (ScriptContext& script_context)
142148{
143- auto vec = script_context.GetArgument <CUtlVector<void * >*>(0 );
149+ auto vec = script_context.GetArgument <CUtlVector<CEntityHandle >*>(0 );
144150 auto index = script_context.GetArgument <int >(1 );
145151
146152 return &vec->Element (index);
147153}
148154
149155void RemoveAllNetworkVectorElements (ScriptContext& script_context)
150156{
151- auto vec = script_context.GetArgument <CUtlVector<void * >*>(0 );
157+ auto vec = script_context.GetArgument <CUtlVector<CEntityHandle >*>(0 );
152158
153159 vec->RemoveAll ();
154160}
155161
156162REGISTER_NATIVES (memory, {
157163 ScriptEngine::RegisterNativeHandler (" CREATE_VIRTUAL_FUNCTION" , CreateVirtualFunction);
158- ScriptEngine::RegisterNativeHandler (" CREATE_VIRTUAL_FUNCTION_BY_SIGNATURE" ,
159- CreateVirtualFunctionBySignature);
164+ ScriptEngine::RegisterNativeHandler (" CREATE_VIRTUAL_FUNCTION_BY_SIGNATURE" , CreateVirtualFunctionBySignature);
160165 ScriptEngine::RegisterNativeHandler (" EXECUTE_VIRTUAL_FUNCTION" , ExecuteVirtualFunction);
161166 ScriptEngine::RegisterNativeHandler (" HOOK_FUNCTION" , HookFunction);
162167 ScriptEngine::RegisterNativeHandler (" UNHOOK_FUNCTION" , UnhookFunction);
0 commit comments