/* * * * * * * * * * * * * * * * 
 * 	 ______     __  __     ______     __  __     ______     ______     __  __    
 *	/\  __ \   /\ \/\ \   /\  == \   /\ \_\ \   /\  __ \   /\  ___\   /\ \/ /    
 *	\ \ \/\ \  \ \ \_\ \  \ \  __<   \ \  __ \  \ \  __ \  \ \ \____  \ \  _"-.  
 *	 \ \_____\  \ \_____\  \ \_____\  \ \_\ \_\  \ \_\ \_\  \ \_____\  \ \_\ \_\ 
 *	  \/_____/   \/_____/   \/_____/   \/_/\/_/   \/_/\/_/   \/_____/   \/_/\/_/ 
 *
 *  - Version : 3L
 *  - By Oubliette
 * * * * * * * * * * * * * * * */

#include "main.h"

#include "oubhack.h"

#include <tier2\tier2.h>

bool OubHack::InitInterfaces(){

	CreateInterfaceFn IEngineInterface =	 (CreateInterfaceFn)GetProcAddress( GetModuleHandle("engine.dll"), "CreateInterface" );
	CreateInterfaceFn IClientInterface =	 (CreateInterfaceFn)GetProcAddress( GetModuleHandle("client.dll"), "CreateInterface" );
	CreateInterfaceFn IMaterialInterface =   (CreateInterfaceFn)GetProcAddress( GetModuleHandle("materialsystem.dll"), "CreateInterface" );
	CreateInterfaceFn ISteamInterface = (CreateInterfaceFn)GetProcAddress( GetModuleHandle("steamclient.dll"), "CreateInterface" );

	Interface oInterface;

	oInterface.pClient  = (IVEngineClient*)IEngineInterface( VENGINE_CLIENT_INTERFACE_VERSION, NULL );
	oInterface.pClientEList = (IClientEntityList*)IClientInterface( VCLIENTENTITYLIST_INTERFACE_VERSION, NULL );
	oInterface.pHLClient = (CHLClient*)IClientInterface( "VClient017", NULL );
	oInterface.pModelRender = (IVModelRender*)IEngineInterface( "VEngineModel016", NULL );
	oInterface.pMatSystem = (IMaterialSystem*)IMaterialInterface( "VMaterialSystem080", NULL );
	oInterface.pModelInfo = (IVModelInfoClient*)IEngineInterface( "VModelInfoClient006", NULL );
	oInterface.pEngineTrace = (IEngineTrace*)IEngineInterface( "EngineTraceClient003", NULL ); 
	oInterface.pDebugOverlay = (IVDebugOverlay*)IEngineInterface( VDEBUG_OVERLAY_INTERFACE_VERSION, NULL );
	oInterface.pVgui = (IEngineVGui*)IEngineInterface( VENGINE_VGUI_VERSION, NULL );
	oInterface.pSteamClient = (ISteamClient*)ISteamInterface( "SteamClient012", NULL );

	if ( oInterface.pClient == NULL || oInterface.pClientEList == NULL || oInterface.pHLClient == NULL || oInterface.pModelRender == NULL || oInterface.pMatSystem == NULL || oInterface.pModelInfo == NULL || oInterface.pEngineTrace == NULL || oInterface.pDebugOverlay == NULL || oInterface.pVgui == NULL || oInterface.pSteamClient == NULL ){

		this->Error("Interfaces failed to initialize!"); 

		if ( oInterface.pClient == NULL ) this->Debug( "IVEngineClient = NULL" );
		if ( oInterface.pClientEList == NULL ) this->Debug( "IClientEntityList = NULL" );
		if ( oInterface.pHLClient == NULL ) this->Debug( "CHLClient = NULL" );
		if ( oInterface.pModelRender == NULL ) this->Debug( "IVModelRender = NULL" );
		if ( oInterface.pMatSystem == NULL ) this->Debug( "IMaterialSystem = NULL" );
		if ( oInterface.pModelInfo == NULL ) this->Debug( "IVModelInfoClient = NULL" );
		if ( oInterface.pEngineTrace == NULL ) this->Debug( "IEngineTrace = NULL" );
		if ( oInterface.pDebugOverlay == NULL ) this->Debug( "IVDebugOverlay = NULL" );
		if ( oInterface.pVgui == NULL ) this->Debug( "IEngineVGui = NULL" );
		if ( oInterface.pSteamClient == NULL ) this->Debug( "ISteamUser = NULL" );

		//if ( oInterface.pSurface == NULL ) this->Debug( "vgui::ISurface = NULL" );

		return false;

	}
	else {

		this->Log( Color( 0, 200, 100, 255 ), "Interfaces initialized!" );

	}

	this->Interfaces = oInterface;

	return true;

}