CS2-Kit
C++23 library for CS2 Metamod:Source plugin development
Loading...
Searching...
No Matches
VirtualCall.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4
5namespace CS2Kit::Sdk
6{
7
8/**
9 * Call a virtual function by vtable index on a given object.
10 */
11template <typename Ret, typename... Args>
12constexpr Ret CallVirtual(int index, void* thisPtr, Args... args) noexcept
13{
14 auto vtable = *reinterpret_cast<void***>(thisPtr);
15 auto fn = reinterpret_cast<Ret (*)(void*, Args...)>(vtable[index]);
16 return fn(thisPtr, args...);
17}
18
19} // namespace CS2Kit::Sdk
constexpr Ret CallVirtual(int index, void *thisPtr, Args... args) noexcept