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

#include "main.h"

#include "oubhack_iluainterface.h"
#include "oubhack_iluaobject.h"
#include "oubhack.h"

ILuaInterface::ILuaInterface( PDWORD_PTR* pdwClass ){

	this->base = pdwClass;

}

template <typename T> T ILuaInterface::GetFunction( PDWORD_PTR* pdwClass, int iIndex ){

	PDWORD_PTR pdwVMT = *pdwClass;

	return (T)pdwVMT[ iIndex ];

}

PDWORD_PTR* ILuaInterface::GetBase( ){

	return this->base;

}

/* ========================================
	Name : ILuaInterface::RunString
	Returns : bool
=========================================== */

bool ILuaInterface::RunString( const char* ccName, const char* ccPath, const char* ccString, bool bRun, bool bErrors ){

	return this->GetFunction< RunStringFn >( this->base, INDEX_LUAINTERFACE_RUNSTRING )( this->base, ccName, ccPath, ccString, bRun, bErrors );

}

/* ========================================
	Name : ILuaInterface::RunStringEx
	Returns : bool
=========================================== */

bool ILuaInterface::RunStringEx( const char* ccName, const char* ccPath, const char* ccString, bool bRun, bool bErrors, bool bSomething ){

	return this->GetFunction< RunStringExFn >( this->base, INDEX_LUAINTERFACE_RUNSTRINGEX )( this->base, ccName, ccPath, ccString, bRun, bErrors, bSomething );

}

/* ========================================
	Name : ILuaInterface::Msg
	Returns : void
=========================================== */

/*
void ILuaInterface::Msg( const char* ccMsg ){

	return this->GetFunction< MsgFn >( this->base, INDEX_LUAINTERFACE_MSG )( this->base, ccMsg );

}
*/
/* ========================================
	Name : ILuaInterface::NewGlobalTable
	Returns : void*
=========================================== */

void* ILuaInterface::NewGlobalTable( const char* ccName ){

	return this->GetFunction< NewGlobalTableFn >( this->base, INDEX_LUAINTERFACE_NEWGLOBALTABLE )( this->base, ccName );

}

/* ========================================
	Name : ILuaInterface::SetField
	Returns : void*
=========================================== */

void* ILuaInterface::SetField( int iStackPos, const char* ccName ){

	return this->GetFunction< SetFieldFn >( this->base, INDEX_LUAINTERFACE_SETFIELD )( this->base, iStackPos, ccName );

}


/* ========================================
	Name : ILuaInterface::GetField
	Returns : void*
=========================================== */

void* ILuaInterface::GetField( int iStackPos, const char* ccName ){

	return this->GetFunction< GetFieldFn >( this->base, INDEX_LUAINTERFACE_GETFIELD )( this->base, iStackPos, ccName );

}

/* ========================================
	Name : ILuaInterface::GetString
	Returns : const char*
=========================================== */

const char* ILuaInterface::GetString( int iStackPos, unsigned int* something ){

	return this->GetFunction< GetStringFn >( this->base, INDEX_LUAINTERFACE_GETSTRING )( this->base, iStackPos, something );

}


/* ========================================
	Name : ILuaInterface::GetNumber
	Returns : double
=========================================== */

double ILuaInterface::GetNumber( int iStackPos ){

	return this->GetFunction< GetNumberFn >( this->base, INDEX_LUAINTERFACE_GETNUMBER )( this->base, iStackPos );

}


/* ========================================
	Name : ILuaInterface::GetBool
	Returns : bool
=========================================== */

bool ILuaInterface::GetBool( int iStackPos ){

	return this->GetFunction< GetBoolFn >( this->base, INDEX_LUAINTERFACE_GETBOOL )( this->base, iStackPos );

}


/* ========================================
	Name : ILuaInterface::GetCFunction
	Returns : void*
=========================================== */

void* ILuaInterface::GetCFunction( int iStackPos ){

	return this->GetFunction< GetCFunctionFn >( this->base, INDEX_LUAINTERFACE_GETCFUNCTION )( this->base, iStackPos );

}

/* ========================================
	Name : ILuaInterface::GetUserdata
	Returns : void*
=========================================== */

void* ILuaInterface::GetUserdata( int iStackPos ){

	UserData* data = (UserData*)this->GetFunction< GetUserdataFn >( this->base, INDEX_LUAINTERFACE_GETUSERDATA )( this->base, iStackPos );
	return data->data;

}

/* ========================================
	Name : ILuaInterface::GetReturn
	Returns : void*
=========================================== */

ILuaObject* ILuaInterface::GetReturn( int iStackPos ){

	return this->IGetObject( iStackPos );

}

/* ========================================
	Name : ILuaInterface::CallInternalGetString
	Returns : const char*
=========================================== */

const char* ILuaInterface::CallInternalGetString( int iStackPos ){

	return this->GetFunction< CallInternalGetStringFn >( this->base, INDEX_LUAINTERFACE_CALLINTERNALGETSTRING )( this->base, iStackPos );

}

/* ========================================
	Name : ILuaInterface::Call
	Returns : void*
=========================================== */

void* ILuaInterface::Call( int iStackPos, int iArgs ){

	return this->GetFunction< CallFn >( this->base, INDEX_LUAINTERFACE_CALL )( this->base, iStackPos, iArgs );

}

/* ========================================
	Name : ILuaInterface::PCall
	Returns : const char*
=========================================== */

void* ILuaInterface::PCall( int iStackPos, int iArgs, int iSomething ){

	return this->GetFunction< PCallFn >( this->base, INDEX_LUAINTERFACE_PCALL )( this->base, iStackPos, iArgs, iSomething );

}

/* ========================================
	Name : ILuaInterface::IsServer
	Returns : bool
=========================================== */

bool ILuaInterface::IsServer( ){

	return this->GetFunction< IsServerFn >( this->base, INDEX_LUAINTERFACE_ISSERVER )( this->base );

}

/* ========================================
	Name : ILuaInterface::IsClient
	Returns : bool
=========================================== */

bool ILuaInterface::IsClient( ){

	return this->GetFunction< IsClientFn >( this->base, INDEX_LUAINTERFACE_ISCLIENT )( this->base );

}

/* ========================================
	Name : ILuaInterface::PushString
	Returns : void*
=========================================== */

void* ILuaInterface::PushString( const char* ccStr, unsigned int* uiLen ){

	return this->GetFunction< PushStringFn >( this->base, INDEX_LUAINTERFACE_PUSHSTRING )( this->base, ccStr, uiLen );

}

/* ========================================
	Name : ILuaInterface::PushNumber
	Returns : void*
=========================================== */

void* ILuaInterface::PushNumber( double dNum ){

	return this->GetFunction< PushNumberFn >( this->base, INDEX_LUAINTERFACE_PUSHNUMBER )( this->base, dNum );

}

/* ========================================
	Name : ILuaInterface::PushBool
	Returns : void*
=========================================== */

void* ILuaInterface::PushBool( bool bBool ){

	return this->GetFunction< PushBoolFn >( this->base, INDEX_LUAINTERFACE_PUSHBOOL )( this->base, bBool );

}

/* ========================================
	Name : ILuaInterface::PushCFunction
	Returns : void*
=========================================== */

void* ILuaInterface::PushCFunction( void* pFunc ){

	return this->GetFunction< PushCFunctionFn >( this->base, INDEX_LUAINTERFACE_PUSHCFUNCTION )( this->base, pFunc );

}

/* ========================================
	Name : ILuaInterface::PushCClosure
	Returns : void*
=========================================== */

void* ILuaInterface::PushCClosure( void* pClosure, int iSomething ){

	return this->GetFunction< PushCClosureFn >( this->base, INDEX_LUAINTERFACE_PUSHCCLOSURE )( this->base, pClosure, iSomething );

}

/* ========================================
	Name : ILuaInterface::PushUserdata
	Returns : void*
=========================================== */

void* ILuaInterface::PushUserdata( void* pUserdata ){

	return this->GetFunction< PushUserdataFn >( this->base, INDEX_LUAINTERFACE_PUSHUSERDATA )( this->base, pUserdata );

}

/* ========================================
	Name : ILuaInterface::Push
	Returns : void*
=========================================== */

void* ILuaInterface::Push( int iVal ){

	return this->GetFunction< PushFn >( this->base, INDEX_LUAINTERFACE_PUSH )( this->base, iVal );

}

/* ========================================
	Name : ILuaInterface::PushLong
	Returns : void*
=========================================== */

void* ILuaInterface::PushLong( long lVal ){

	return this->GetFunction< PushLongFn >( this->base, INDEX_LUAINTERFACE_PUSHLONG )( this->base, lVal );

}

/* ========================================
	Name : ILuaInterface::ReferencePush
	Returns : void*
=========================================== */

void* ILuaInterface::ReferencePush( int iStackPos ){

	return this->GetFunction< ReferencePushFn >( this->base, INDEX_LUAINTERFACE_REFERENCEPUSH )( this->base, iStackPos );

}

/* ========================================
	Name : ILuaInterface::ReferenceFree
	Returns : void*
=========================================== */

void* ILuaInterface::ReferenceFree( int iStackPos ){

	return this->GetFunction< ReferenceFreeFn >( this->base, INDEX_LUAINTERFACE_REFERENCEFREE )( this->base, iStackPos );

}

/* ========================================
	Name : ILuaInterface::ReferenceCreate
	Returns : int
=========================================== */

int ILuaInterface::ReferenceCreate( ){

	return this->GetFunction< ReferenceCreateFn >( this->base, INDEX_LUAINTERFACE_REFERENCECREATE )( this->base );

}

/* ========================================
	Name : ILuaInterface::PushNil
	Returns : void*
=========================================== */

void* ILuaInterface::PushNil( ){

	return this->GetFunction< PushNilFn >( this->base, INDEX_LUAINTERFACE_PUSHNIL )( this->base );

}

/* ========================================
	Name : ILuaInterface::GetType
	Returns : int
=========================================== */

int ILuaInterface::GetType( int iStackPos ){

	return this->GetFunction< GetTypeFn >( this->base, INDEX_LUAINTERFACE_GETTYPE )( this->base, iStackPos );

}

/* ========================================
	Name : ILuaInterface::GetTypeName
	Returns : const char*
=========================================== */

const char* ILuaInterface::GetTypeName( int iStackPos ){

	return this->GetFunction< GetTypeNameFn >( this->base, INDEX_LUAINTERFACE_GETTYPENAME )( this->base, iStackPos );

}

/* ========================================
	Name : ILuaInterface::Pop
	Returns : void*
=========================================== */

void* ILuaInterface::Pop( int iStackPos ){

	return this->GetFunction< PopFn >( this->base, INDEX_LUAINTERFACE_POP )( this->base, iStackPos );

}

/* ========================================
	Name : ILuaInterface::Next
	Returns : void*
=========================================== */

void* ILuaInterface::Next( int iStackPos ){

	return this->GetFunction< NextFn >( this->base, INDEX_LUAINTERFACE_NEXT )( this->base, iStackPos );

}

/* ========================================
	Name : ILuaInterface::SetTable
	Returns : void*
=========================================== */

void* ILuaInterface::SetTable( int iStackPos ){

	return this->GetFunction< SetTableFn >( this->base, INDEX_LUAINTERFACE_SETTABLE )( this->base, iStackPos );

}

/* ========================================
	Name : ILuaInterface::GetTable
	Returns : void*
=========================================== */

void* ILuaInterface::GetTable( int iStackPos ){

	return this->GetFunction< GetTableFn >( this->base, INDEX_LUAINTERFACE_GETTABLE )( this->base, iStackPos );

}

/* ========================================
	Name : ILuaInterface::IsType
	Returns : bool
=========================================== */

bool ILuaInterface::IsType( int iStackPos, int iType ){

	return this->GetFunction< IsTypeFn >( this->base, INDEX_LUAINTERFACE_ISTYPE )( this->base, iStackPos, iType );

}

/* ========================================
	Name : ILuaInterface::IsType
	Returns : bool
=========================================== */

ILuaObject* ILuaInterface::GetGlobal( const char* ccName ){

	this->GetField( LUA_GLOBALSINDEX, ccName );

	ILuaObject* lo_Glob = new ILuaObject( this, this->ReferenceCreate() );

	this->Pop();

	return lo_Glob;

}

/* ========================================
	Name : ILuaInterface::IGetObject
	Returns : ILuaObject*
=========================================== */

ILuaObject* ILuaInterface::IGetObject( int iStackPos )
{
	if ( iStackPos != 0 ) this->Push( iStackPos );
	return new ILuaObject( this, this->ReferenceCreate() );
}

/* ========================================
	Name : ILuaInterface::CheckType
	Returns : void*
=========================================== */

void* ILuaInterface::CheckType( int iStackPos, int iType )
{

	return this->GetFunction< CheckTypeFn >( this->base, INDEX_LUAINTERFACE_CHECKTYPE )( this->base, iStackPos, iType );

}


/* ========================================
	Name : ILuaInterface::CreateTable
	Returns : void*
=========================================== */

void* ILuaInterface::CreateTable( void )
{

	return this->GetFunction< CreateTableFn >( this->base, INDEX_LUAINTERFACE_CREATETABLE )( this->base );

}

/* ========================================
	Name : ILuaInterface::GetLuaState
	Returns : lua_State*
=========================================== */

lua_State* ILuaInterface::GetLuaState( void )
{

	return this->GetFunction< GetLuaStateFn >( this->base, INDEX_LUAINTERFACE_GETLUASTATE )( this->base );

}

