mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
* All libraries have been isolated from each other, and build into separate artifacts. * Project has been restructured to support isolating libraries. * CCrashHandler now calls a callback on crash (setup from core/dllmain.cpp, this can be setup in any way for any project. This callback is getting called when the apllication crashes. Useful for flushing buffers before closing handles to logging files for example). * Tier0 'CoreMsgV' function now calls a callback sink, which could be set by the user (currently setup to the SDK's internal logger in core/dllmain.cpp). TODO: * Add a batch file to autogenerate all projects. * Add support for dedicated server. * Add support for client dll. Bugs: * Game crashes on the title screen after the UI script compiler has finished (root cause unknown). * Curl error messages are getting logged twice for the dedicated server due to the removal of all "DEDICATED" preprocessor directives to support isolating projects. This has to be fixed properly!
88 lines
3.5 KiB
C++
88 lines
3.5 KiB
C++
//===========================================================================//
|
|
//
|
|
// Purpose: Implementation of the CVTableHelper class, used to assist in
|
|
// function rebuilding and reverse engineering.
|
|
// DO NOT USE FOR SHIPPING CODE!!!!!!!!!!
|
|
//
|
|
//===========================================================================//
|
|
#include "tier0_pch.h"
|
|
#include "tier0/vtable.h"
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: create class instance from passed module and virtual table name
|
|
// Input : CModule* -
|
|
// const std::string& -
|
|
// uint32_t
|
|
//-----------------------------------------------------------------------------
|
|
CVTableHelper::CVTableHelper(CModule* module, const string& tableName, uint32_t refIndex) : m_svVirtualTableName(tableName)
|
|
{
|
|
m_pVirtualTable = module->GetVirtualMethodTable(tableName, refIndex);
|
|
m_nVirtualFunctionCount = GetVTableLength();
|
|
GetAllVTableFunctions();
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: create class instance from passed pointer
|
|
// Input : uintptr_t -
|
|
// const std::string& -
|
|
//-----------------------------------------------------------------------------
|
|
CVTableHelper::CVTableHelper(uintptr_t virtualTable, const string& tableName) : m_pVirtualTable(virtualTable), m_svVirtualTableName(tableName)
|
|
{
|
|
m_nVirtualFunctionCount = GetVTableLength();
|
|
GetAllVTableFunctions();
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: create class instance from passed pointer
|
|
// Input : void* -
|
|
// const std::string& -
|
|
//-----------------------------------------------------------------------------
|
|
CVTableHelper::CVTableHelper(void* virtualTable, const string& tableName) : m_pVirtualTable(uintptr_t(virtualTable)), m_svVirtualTableName(tableName)
|
|
{
|
|
m_nVirtualFunctionCount = GetVTableLength();
|
|
GetAllVTableFunctions();
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: gets function count of m_pVirtualTable
|
|
// Output : ptrdiff_t
|
|
//-----------------------------------------------------------------------------
|
|
ptrdiff_t CVTableHelper::GetVTableLength()
|
|
{
|
|
uintptr_t* pStartOfVTable = reinterpret_cast<uintptr_t*>(m_pVirtualTable);
|
|
MEMORY_BASIC_INFORMATION memInfo = { NULL };
|
|
ptrdiff_t vtSize = -1;
|
|
|
|
do {
|
|
vtSize++;
|
|
VirtualQuery(reinterpret_cast<void*>(pStartOfVTable[vtSize]), &memInfo, sizeof(memInfo));
|
|
} while (memInfo.Protect == PAGE_EXECUTE_READ || memInfo.Protect == PAGE_EXECUTE_READWRITE);
|
|
|
|
return vtSize;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: populate m_vVirtualFunctions with all virtual function pointers
|
|
//-----------------------------------------------------------------------------
|
|
void CVTableHelper::GetAllVTableFunctions()
|
|
{
|
|
for (ptrdiff_t i = 0; i < m_nVirtualFunctionCount; i++)
|
|
{
|
|
m_vVirtualFunctions.push_back(*reinterpret_cast<uintptr_t*>(m_pVirtualTable + (8 * i)));
|
|
}
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: call function from m_vVirtualFunctions with passed index
|
|
// Input : int -
|
|
// void* -
|
|
// arg_list -
|
|
// Output : Assigned template return type
|
|
//-----------------------------------------------------------------------------
|
|
template <typename ReturnType, typename ...Args>
|
|
ReturnType CVTableHelper::Call(int index, void* thisPtr, Args... args)
|
|
{
|
|
return reinterpret_cast<ReturnType(__fastcall*)(void*, Args...)>(m_vVirtualFunctions.at(index))(thisPtr, args...);
|
|
} |