#include "engine.h"
cEngine* engine = NULL;
cEngine::cEngine( void )
{
pClientShellBase = NULL;
pGameClientShell = NULL;
pClientInfoMgr = NULL;
pPlayerManager = NULL;
pLTDrawPrim = NULL;
pLTClient = NULL;
pLTModel = NULL;
pLTBase = NULL;
pLocal = NULL;
pWarningFont = NULL;
pSmallFont = NULL;
pMenuFont = NULL;
dwClientFxEntry = (DWORD)GetModuleHandle( STRING_CLIENTFXDOTFXD );
}
void cEngine::InitEnginePointers( void )
{
#ifdef _DEBUG_
tools->add_log( STRING_LOGFILE, "\nIniting Ptrs!->LoL( $$$$ )" );
pClientShellBase = (cLTClientShellBase*)ADDR_L***BASE;
if( ValidPointer( pClientShellBase ) )
{
pLTModel = (cLTModel*)pClientShellBase->ILTModel;
tools->add_log( STRING_LOGFILE, "cLTModel[ 0x%x ]", (DWORD)pLTModel );
pLTDrawPrim = *(cLTDrawPrim**)pClientShellBase->ILTDrawPrim;
tools->add_log( STRING_LOGFILE, "DrawPrim1 0x%x DrawPrim2 0x%x", (DWORD)pLTDrawPrim, (DWORD)&pLTDrawPrim );
pLTBase = (cLTBase*)pClientShellBase->ILTBase;
tools->add_log( STRING_LOGFILE, "cLTBase[ 0x%x ]", (DWORD)pLTBase );
pGameClientShell = *(cGameClientShell**)ADDR_GCS;
tools->add_log( STRING_LOGFILE, "Game Client Shell[ 0x%x ]", (DWORD)pGameClientShell );
tools->add_log( STRING_LOGFILE, "w2s 0x%x", (DWORD)&pLTDrawPrim->WorldToScreen );
if( ValidPointer( pLTBase ) && ValidPointer( pGameClientShell ) )
{
pClientInfoMgr = (cClientInfoMgr*)pGameClientShell->GetClientInfoMgr();
tools->add_log( STRING_LOGFILE, "ClientInfoMgr[ 0x%x ]", (DWORD)pClientInfoMgr );
pPlayerManager = (cPlayerMgr*)pGameClientShell->GetPlayerManager();
tools->add_log( STRING_LOGFILE, "PlayerManager[ 0x%x ]", (DWORD)pPlayerManager );
pLTClient = (cLTClient*)pLTBase->ILTClient;
tools->add_log( STRING_LOGFILE, "cLTClient[ 0x%x ]", (DWORD)pLTClient );
pLocal = (LocalInfo*)ADDR_LOCALPTR;
tools->add_log( STRING_LOGFILE, "Local[ 0x%x ]", (DWORD)pLocal );
}
}
#else
pClientShellBase = (cLTClientShellBase*)ADDR_L***BASE;
if( ValidPointer( pClientShellBase ) )
{
pLTModel = (cLTModel*)pClientShellBase->ILTModel;
//pLTDrawPrim = *(cLTDrawPrim**)pClientShellBase->ILTDrawPrim;
pLTBase = (cLTBase*)pClientShellBase->ILTBase;
pGameClientShell = *(cGameClientShell**)ADDR_GCS;
if( ValidPointer( pLTBase ) && ValidPointer( pGameClientShell ) )
{
pClientInfoMgr = (cClientInfoMgr*)pGameClientShell->GetClientInfoMgr();
pPlayerManager = (cPlayerMgr*)pGameClientShell->GetPlayerManager();
pLTClient = (cLTClient*)pLTBase->ILTClient;
pLocal = (LocalInfo*)ADDR_LOCALPTR;
}
}
#endif
}
void cEngine::InitFonts( void )
{
pSmallFont = (cFont*)BuildFontByFontIndex( 24, 12 );
pWarningFont = (cFont*)BuildFontByFontIndex( 15, 25 );
pMenuFont = (cFont*)BuildFontByFontIndex( 25, 13 );
#ifdef _DEBUG_
tools->add_log( STRING_LOGFILE, STRING_DEBUG_FONTINIT );
#endif
}
int cEngine::GetFontHandle( int index )
{
void* vGetFontHandle = (void*)ADDR_GETFONTHAND;
DWORD dwECX = *(DWORD*)ADDR_FONTECX;
__asm
{
push 0
push index
mov ecx, dwECX
call [vGetFontHandle]
}
}
DWORD cEngine::BuildFontByFontIndex( int index, int FontSize )
{
void* vBuildFont = (void*)ADDR_BUILDFONT;
void* dwFill = (void*)ADDR_FILLFONT;
int FontHandle = GetFontHandle( index );
DWORD dwFontAddr = 0;
BYTE* FontBuffer = new BYTE[0x228];
__asm
{
mov ecx, FontBuffer
call [dwFill]
mov dwFontAddr, eax
mov ecx, eax
push 0
push 0
push 0
push 0
push FontSize
push FontHandle
push 0
push 0
push 0
call [vBuildFont]
}
return dwFontAddr;
}
void cEngine::RenderString( cFont* Renderer, int x, int y, std::wstring text, DWORD color )
{
if( Renderer )
{
Renderer->SetText( (unsigned short*)text.c_str(), 1 );
Renderer->SetPos( x, y );
Renderer->SetColor( color, color, color, (int)-1 );
Renderer->Render();
}
}
bool __cdecl cEngine::IsVisible( D3DXVECTOR3 Point )
{
IntersectQuery iQuery;
IntersectInfo iInfo;
memset( &iQuery, 0, sizeof(iQuery) );
iQuery.Start = esp->local.CameraPos;
iQuery.End = Point;
return !engine->GetLTBase()->IntersectSegment( iQuery, &iInfo );
}
bool MyFilterObjects( int* hObj, void* pUser )
{
cSFXMgr* SFXMgr = engine->GetGameClientShell()->GetSFXMgr();
if( engine->ValidPointer( SFXMgr ) )
{
for( int i = 0; i < SFXMgr->SFXList[SFX_CHARACTER].Num; i++ )
{
cCharacterFX* fx = (cCharacterFX*)SFXMgr->SFXList[SFX_CHARACTER].List[i];
if( engine->ValidPointer( fx ) && engine->ValidPointer( fx->Object ) )
if( hObj == fx->hHitbox )
return true;
}
}
return false;
}
bool IntersectAndPenetrateSegment( IntersectQuery* iQuery, IntersectInfo* qInfo )
{
if( esp->local.iGameMode != 5 )
{
for( int i = 0; i <= 24; i++ )
{
if( esp->bValidObject( i ) && esp->bValidCords( i ) && !esp->Players[i].bIsDead )
{
if( esp->Players[i].Charector->TeamID != esp->local.iTeam )
{
if( esp->local.iTeam != esp->Players[i].Charector->TeamID )
{
iQuery->Start = esp->Players[i].AimTransform.Pos + D3DXVECTOR3( 0.0f, 50.0f, 0.0f );
iQuery->End = esp->Players[i].AimTransform.Pos - D3DXVECTOR3( 0.0f, 50.0f, 0.0f );
iQuery->FilterFn = MyFilterObjects;
bool Result = engine->GetLTBase()->IntersectSegment( *iQuery, qInfo );
if( Result )
{
qInfo->hObjImpact = esp->Players[i].SFXOBJ->hHitbox;
qInfo->vImpactPos = esp->Players[i].AimTransform.Pos;
}
return Result;
}
}
}
}
}
else
{
cSFXMgr* SFXMgr = engine->GetGameClientShell()->GetSFXMgr();
if( engine->ValidPointer( SFXMgr ) )
{
for( int i = 0; i < SFXMgr->SFXList[SFX_CHARACTER].Num; i++ )
{
cCharacterFX* NPC = (cCharacterFX*)SFXMgr->SFXList[SFX_CHARACTER].List[i];
if( engine->ValidPointer( NPC ) && engine->ValidPointer( NPC->Object ) )
{
if( esp->local.Object == NPC->Object )
continue;
int Type = NPC->IsPlayer;
if( Type != 0 )
continue;
Transform HeadTransform;
unsigned int AimSpot;
AimSpot = engine->GetLTModel()->GetNodeTransform( NPC->Object, 8, &HeadTransform, true );
HeadTransform.Pos.y += 7.0f;
if( AimSpot != 0 )
continue;
iQuery->Start = HeadTransform.Pos + D3DXVECTOR3( 0.0f, 50.0f, 0.0f );
iQuery->End = HeadTransform.Pos - D3DXVECTOR3( 0.0f, 50.0f, 0.0f );
iQuery->FilterFn = MyFilterObjects;
bool Result = engine->GetLTBase()->IntersectSegment( *iQuery, qInfo );
if( Result )
{
qInfo->hObjImpact = NPC->hHitbox;
qInfo->vImpactPos = HeadTransform.Pos;
}
return Result;
}
}
}
}
return false;
}
bool cEngine::WorldToScreen( D3DXVECTOR3 Pos, D3DXVECTOR3 *Screen )
{
float x = Pos.x;
float y = Pos.y;
float z = Pos.z;
D3DXVECTOR3 Unk;
_asm
{
mov ecx, dword ptr ds:[ADDR_DRAWPRIM]
lea eax, Unk
push eax
push Screen
push z
push y
push x
mov eax, ADDR_W2S
call eax
}
return( Screen->z < 1.0f );
}
int cEngine::GetConsoleInt( char* cmd, int value )
{
_asm
{
push value
push cmd
mov eax, ADDR_GETCONSOLEINT
call eax
add esp, 8
}
}
void cEngine::SetLocalPlayerPosition( D3DXVECTOR3 Pos )
{
DWORD dwClass = *(DWORD*)( dwClientFxEntry + ADDR_CLIENTFX );
if( dwClass == NULL )
return;
*(float*)( dwClass + 0xC8 ) = Pos.x;
*(float*)( dwClass + 0xCC ) = Pos.y;
*(float*)( dwClass + 0xD0 ) = Pos.z;
}
void cEngine::SetCvar( DWORD CVarBase, float Value )
{
*(float*)( CVarBase + 0x48 ) = Value;
}
bool cEngine::ValidGamePointers( void )
{
if( ValidPointer( pClientShellBase )
&& ValidPointer( pGameClientShell )
&& ValidPointer( pLTModel )
&& ValidPointer( pLTBase )
&& ValidPointer( pLTClient )
&& ValidPointer( pClientInfoMgr )
#ifdef _DEBUG
&& ValidPointer( pLTDrawPrim )
#endif
&& ValidPointer( pPlayerManager )
&& ValidPointer( pLocal ) )
return true;
return false;
}