@@ -105,57 +105,41 @@ void MemOrFast(U ptr, const T value)
105105bool GetDebugIdEnabled (uint uiDebugId);
106106void LogEvent (uint uiDebugId, const char * szType, const char * szContext, const char * szBody, uint uiAddReportLogId = 0 );
107107
108- struct __THISCALL {};
109- struct __CDECL {};
110- struct __STDCALL {};
111- struct __FASTCALL {};
112- struct __VECTORCALL {};
113-
114- template <typename ... Args>
115- struct GTAFuncSignature
108+ namespace CallingConventions
116109{
117- std::tuple<Args...> args;
118- GTAFuncSignature (Args... a) : args(std::move(a)...) {}
119- };
120-
121- template <typename ... Args>
122- GTAFuncSignature<Args...> PrepareSignature (Args... args)
123- {
124- return GTAFuncSignature<Args...>(std::move (args)...);
125- }
126-
127- template <typename ReturnType, typename Func, typename Tuple, std::size_t ... I>
128- ReturnType apply_helper (Func&& f, Tuple&& t, std::index_sequence<I...>)
129- {
130- return f (std::get<I>(std::forward<Tuple>(t))...);
131- }
110+ struct thiscall {};
111+ struct ___cdecl {};
112+ struct stdcall {};
113+ struct fastcall {};
114+ struct vectorcall {};
115+ } // namespace CallingConventions
132116
133117template <typename ReturnType, typename CallingConvention, typename Func, typename ... Args>
134- typename std::enable_if<std::is_same<CallingConvention, __THISCALL >::value, ReturnType>::type CallGTAFunction (Func function, GTAFuncSignature< Args...>& sig )
118+ typename std::enable_if<std::is_same<CallingConvention, CallingConventions::thiscall >::value, ReturnType>::type CallGTAFunction (Func function, Args... params )
135119{
136- return apply_helper<ReturnType>( reinterpret_cast <ReturnType (__thiscall*)(Args...)>(function), sig. args , std::index_sequence_for<Args...>{} );
120+ return reinterpret_cast <ReturnType (__thiscall*)(Args...)>(function)(params... );
137121}
138122
139123template <typename ReturnType, typename CallingConvention, typename Func, typename ... Args>
140- typename std::enable_if<std::is_same<CallingConvention, __CDECL >::value, ReturnType>::type CallGTAFunction (Func function, GTAFuncSignature< Args...>& sig )
124+ typename std::enable_if<std::is_same<CallingConvention, CallingConventions::___cdecl >::value, ReturnType>::type CallGTAFunction (Func function, Args... params )
141125{
142- return apply_helper<ReturnType>( reinterpret_cast <ReturnType (__cdecl*)(Args...)>(function), sig. args , std::index_sequence_for<Args...>{} );
126+ return reinterpret_cast <ReturnType (__cdecl*)(Args...)>(function)(params... );
143127}
144128
145129template <typename ReturnType, typename CallingConvention, typename Func, typename ... Args>
146- typename std::enable_if<std::is_same<CallingConvention, __STDCALL >::value, ReturnType>::type CallGTAFunction (Func function, GTAFuncSignature< Args...>& sig )
130+ typename std::enable_if<std::is_same<CallingConvention, CallingConventions::stdcall >::value, ReturnType>::type CallGTAFunction (Func function, Args... params )
147131{
148- return apply_helper<ReturnType>( reinterpret_cast <ReturnType (__stdcall*)(Args...)>(function), sig. args , std::index_sequence_for<Args...>{} );
132+ return reinterpret_cast <ReturnType (__stdcall*)(Args...)>(function)(params... );
149133}
150134
151135template <typename ReturnType, typename CallingConvention, typename Func, typename ... Args>
152- typename std::enable_if<std::is_same<CallingConvention, __FASTCALL >::value, ReturnType>::type CallGTAFunction (Func function, GTAFuncSignature< Args...>& sig )
136+ typename std::enable_if<std::is_same<CallingConvention, CallingConventions::fastcall >::value, ReturnType>::type CallGTAFunction (Func function, Args... params )
153137{
154- return apply_helper<ReturnType>( reinterpret_cast <ReturnType (__fastcall*)(Args...)>(function), sig. args , std::index_sequence_for<Args...>{} );
138+ return reinterpret_cast <ReturnType (__fastcall*)(Args...)>(function)(params... );
155139}
156140
157141template <typename ReturnType, typename CallingConvention, typename Func, typename ... Args>
158- typename std::enable_if<std::is_same<CallingConvention, __VECTORCALL >::value, ReturnType>::type CallGTAFunction (Func function, GTAFuncSignature< Args...>& sig )
142+ typename std::enable_if<std::is_same<CallingConvention, CallingConventions::vectorcall >::value, ReturnType>::type CallGTAFunction (Func function, Args... params )
159143{
160- return apply_helper<ReturnType>( reinterpret_cast <ReturnType (__vectorcall*)(Args...)>(function), sig. args , std::index_sequence_for<Args...>{} );
144+ return reinterpret_cast <ReturnType (__vectorcall*)(Args...)>(function)(params... );
161145}
0 commit comments