Код:
for those who're stuck at interfaces
template<typename T>
__forceinline static T* create_interface( const char* module_name, const char* interface_name ) {
// check if we problems occured with module name.
if ( !module_name ) {
log_error( "occured problem on module-name -> " + std::string( module_name ) );
return nullptr;
}
// check if we problems occured with interface name.
if ( !interface_name ) {
log_error( "occured problem on interface-name -> " + std::string( interface_name ) );
return nullptr;
}
// get module handle
HMODULE m_module = GetModuleHandle( module_name );
if ( !m_module ) { // do we have problems with the handle?
log_error( "occured problem with module handle -> " + std::string( module_name ) );
return nullptr;
}
// create interface
std::uint8_t* m_create_interface = reinterpret_cast< std::uint8_t* >( GetProcAddress( m_module, "CreateInterface" ) );
if ( !m_create_interface ) { // do we have problems creating the interface?
log_error( "occured problem creating the interface" );
return nullptr;
}
// callback
using interface_callback_fn = void* ( __cdecl* )( );
// like a class brother
typedef struct _interface_reg_t {
interface_callback_fn m_callback;
const char* m_name;
_interface_reg_t* m_flink;
} interface_reg_t;
// get interface list
interface_reg_t* interface_list = *reinterpret_cast< interface_reg_t** >( resolve_rip( m_create_interface, 3, 7 ) );
if ( !interface_list ) {
return nullptr;
}
// create it ?
for ( interface_reg_t* it = interface_list; it; it = it->m_flink ) {
if ( !strcmp( it->m_name, interface_name ) ) {
// we created the interface
log_success( "created interface succesfully -> " + std::string( interface_name ) );
return reinterpret_cast< T* >( it->m_callback( ) );
}
}
return nullptr;
}
// usage
Interfaces::convars = create_interface<ccvar>( "tier0.dll", "VEngineCvar007" );
//reinterpret_cast<ccvar*>(interface_callback_fn(loader_interface->interfaces()->Get(12))());
Interfaces::client = create_interface<i_client>( "client.dll", "Source2Client002" );
Код:
rest of them are on you guys
Interfaces::convars = create_interface<ccvar>( "tier0.dll", "VEngineCvar007" );
//reinterpret_cast<ccvar*>(interface_callback_fn(loader_interface->interfaces()->Get(12))());
Interfaces::client = create_interface<i_client>( "client.dll", "Source2Client002" );
//reinterpret_cast<i_client*>(interface_callback_fn(loader_interface->interfaces()->Get(14))());
Interfaces::engine = create_interface<i_engine_client>( "engine2.dll", "Source2EngineToClient001" );
//reinterpret_cast<i_engine_client*>(interface_callback_fn(loader_interface->interfaces()->Get(11))());
Interfaces::input_system = create_interface<c_input_sys>( "inputsystem.dll", "InputSystemVersion001" );
//reinterpret_cast<c_input_sys*>(interface_callback_fn(loader_interface->interfaces()->Get(8))());
Interfaces::schema_system = create_interface<i_schema_system>( "schemasystem.dll", "SchemaSystem_001" );
//reinterpret_cast<i_schema_system*>(interface_callback_fn(loader_interface->interfaces()->Get(7))());
Interfaces::resource_system = create_interface<c_resource_system>( "engine2.dll", "GameResourceServiceClientV001" );
//reinterpret_cast<c_resource_system*>(interface_callback_fn(loader_interface->interfaces()->Get(6))());
Interfaces::material_system = create_interface<i_material_system>( "materialsystem2.dll", "VMaterialSystem2_001" );
//reinterpret_cast<i_material_system*>(interface_callback_fn(loader_interface->interfaces()->Get(5))());
Interfaces::m_prediction = create_interface<c_prediction>( "client.dll", "Source2ClientPrediction001" );
//reinterpret_cast<c_prediction*>(interface_callback_fn(loader_interface->interfaces()->Get(13))());
Interfaces::m_network_game_service = create_interface<i_network_game_service>( "engine2.dll", "NetworkClientService_001" );
//reinterpret_cast<i_network_game_service*>(interface_callback_fn(loader_interface->interfaces()->Get(10))());
Interfaces::m_base_file_system = create_interface<c_base_file_system>( "filesystem_stdio.dll", "VFileSystem017" ); // or async
//reinterpret_cast<c_base_file_system*>(interface_callback_fn(loader_interface->interfaces()->Get(4))());
Interfaces::m_localize = create_interface<c_localize>( "localize.dll", "Localize_001" );
///reinterpret_cast<c_localize*>(interface_callback_fn(loader_interface->interfaces()->Get(3))());
Interfaces::m_scene_utils = reinterpret_cast<c_scene_utils*>(interface_callback_fn(loader_interface->interfaces()->Get(2))());
Interfaces::m_game_ui_service = reinterpret_cast<c_game_ui_service*>(interface_callback_fn(loader_interface->interfaces()->Get(9))());
Interfaces::m_panorama_engine = reinterpret_cast<CPanoramaUIEngine*>(interface_callback_fn(loader_interface->interfaces()->Get(1))());
Interfaces::m_network_messages = reinterpret_cast<c_network_messages*>(interface_callback_fn(loader_interface->interfaces()->Get(0))());
Последнее редактирование: