PDA

View Full Version : Strange Error with TraceRay()



dirty suka
10-12-2009, 05:07 AM
#include <windows.h>
#include "SDK.h"


IClientEntityList * g_pEntList = NULL;
IEngineTrace * g_pEngineTrace = NULL;
IVEngineClient* g_pEngine = NULL;
IVModelInfoClient* g_pModelInfo = NULL;

CreateInterfaceFn g_ClientFactory = NULL;
CreateInterfaceFn g_EngineFactory = NULL;


void LClick()
{
INPUT inpstr;
ZeroMemory(&inpstr,sizeof(INPUT));
inpstr.type = INPUT_MOUSE;
inpstr.mi.dx = 0;
inpstr.mi.dy = 0;
inpstr.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;

SendInput(1,&inpstr,sizeof(INPUT));

inpstr.mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(1,&inpstr,sizeof(INPUT));

}

bool GetAim( void )
{
trace_t trace;
Ray_t ray;

ZeroMemory(&trace,sizeof(trace_t));
ZeroMemory(&ray,sizeof(Ray_t));

int iLocalIndex = g_pEngine->GetLocalPlayer();

if ( iLocalIndex <= 0 )
return 0;

IClientEntity* pClientEnt = g_pEntList->GetClientEntity( iLocalIndex );

if ( !pClientEnt )
return 0;

CBaseEntity* pBaseEntity = pClientEnt->GetBaseEntity();

if ( !pBaseEntity )
return 0;

Vector vecDir;

AngleVectors( pBaseEntity->GetAbsAngles(), &vecDir );

vecDir = vecDir * 8192 + pBaseEntity->EyePosition();
Vector vecLocalPos = pBaseEntity->EyePosition();

ray.Init(vecLocalPos,vecDir);

g_pEngineTrace->TraceRay(ray,(MASK_NPCWORLDSTATIC|CONTENTS_SOLID|CONTENTS_MOVEABLE|CON TENTS_MONSTER|CONTENTS_WINDOW|CONTENTS_DEBRIS|CONTENTS_HITBOX),NULL,&trace);

if ( trace.m_pEnt )
{
if( trace.m_pEnt->IsPlayer() )
{
if(trace.m_pEnt->GetTeamNumber() != pBaseEntity->GetTeamNumber())
return true;
}
}


return 0;
}



DWORD WINAPI MainThread(LPVOID lpParameter)
{

HMODULE hmClient = GetModuleHandle( "client.dll" );
g_ClientFactory = ( CreateInterfaceFn ) GetProcAddress( hmClient, "CreateInterface" );

HMODULE hmEngine = GetModuleHandle( "engine.dll" );
g_EngineFactory = ( CreateInterfaceFn ) GetProcAddress( hmEngine, "CreateInterface" );

g_pEngineTrace = ( IEngineTrace* ) g_EngineFactory( INTERFACEVERSION_ENGINETRACE_CLIENT, NULL );
g_pModelInfo = ( IVModelInfoClient* ) g_EngineFactory( VMODELINFO_CLIENT_INTERFACE_VERSION, NULL );
g_pEngine = ( IVEngineClient* ) g_EngineFactory( VENGINE_CLIENT_INTERFACE_VERSION, NULL );
g_pEntList = ( IClientEntityList* ) g_ClientFactory( VCLIENTENTITYLIST_INTERFACE_VERSION, NULL );


if( g_pEntList&&
g_pEngineTrace&&
g_pEngine&&
g_pModelInfo)
{


// this ugly block just loops GetAim() if active is true. and toggles active with presses of c
bool active = false;
while(true)
{
Sleep(20);
if (GetAsyncKeyState('C')){
active = !active;
Sleep(100);
}


if(active)
{
if (GetAim())
LClick();
}
}
}
else
Beep(1000,1000);
return 0;
}

BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpReserved )
{
DWORD dwThreadID;

if( dwReason == 1 )
{
DisableThreadLibraryCalls(hinstDLL);
CreateThread( NULL, NULL, (LPTHREAD_START_ROUTINE)MainThread, NULL, NULL, &dwThreadID);
}
return TRUE;
}



This code compiles and runs when injected, it even detects ents and fires correctly, however, the TraceRay function will seemingly randomly after a few seconds causes all ents on the level to fall through the ground and then the game crashes to desktop.

edit: it also creates random invisible walls , as shown in my ub3r h4x video.

The code is slightly modified version of patricks Trigger bot, so cant see why it doesnt work.

As soon as i comment the TraceRay function out of the code, the crashing stops.

Im completely stumped. I really would like help, this is so fucking annoying, ive spent all sunday working on fixing this.

edit: added video so we can lol at how retarded this is :P

HuЯЯ1cΛиΞ
10-13-2009, 10:25 PM
Strange, I didn't experience that problem at all.

dirty suka
10-14-2009, 01:28 AM
strange indeed, i downloaded my sdk from steam, but perhaps someone can upload a version of the headers and libs of a version they know doesnt crash so i can test on my PC with those.

HuЯЯ1cΛиΞ
10-14-2009, 09:38 AM
Maybe it's how you use TraceRay().
I do it like that:



bool cAim::Triggerbot( QAngle qAngle )
{
AngleVectors( qAngle, &vFinal );

vFinal = vFinal* 8192.0f + Base.MyPlayer->BaseEnt()->EyePosition();
ray.Init( Base.MyPlayer->BaseEnt()->EyePosition(), vFinal );

Base.Enginetrace->TraceRay( ray, MASK_ALL, NULL, &trace );
C_BasePlayer* pPlayer = dynamic_cast<C_BasePlayer*>(trace.m_pEnt->GetIClientEntity());
IClientEntity* pRemoteEnt = (IClientEntity*)Base.EntList->GetClientEntity( trace.m_pEnt->index );
CBaseEntity* pRemoteBEnt = (CBaseEntity*)pRemoteEnt->GetBaseEntity();

if( trace.m_pEnt->GetIClientEntity() == NULL ) //Wouldn't make sense to shoot..
return false;
if( pRemoteBEnt->GetTeamNumber() == Base.MyPlayer->BaseEnt()->GetTeamNumber() ) //Aiming at own team
return false;
if( pPlayer == NULL ) //Wouldn't make sense to shoot..
return false;
if( !pPlayer->IsAlive() || !pPlayer->GetTeamNumber() ) //Dead or not in Team
return false;

return true; //Hopefully the enemy :O
}


And then use it:


bool bTrigger = Base.Aim->Triggerbot( YourViewAngles /*maybe cmd->viewangles*/ );
if( bTrigger )
{
cmd->buttons|=IN_ATTACK;
if ( cmd->buttons & IN_ATTACK ) //AutoPistol
{
static bool bAutoPistol = false;
bAutoPistol = !bAutoPistol;
if(bAutoPistol)
cmd->buttons &= ~IN_ATTACK;
else
cmd->buttons |= IN_ATTACK;
}
}


But yeah, basically it is the same but doesn't generate errors. :confused2:
Here is my SDK, credits go to v3n0m4.
http://rapidshare.com/files/292924304/SDK.zip

PS: Why do you use ZeroMemory() when you fill them up right after?

peterslone
10-14-2009, 10:10 AM
it is much easier with hitboxes .

trace local eye angles if it hits a visible hitbox , shoot .

dirty suka
10-14-2009, 09:19 PM
i zeroed the memory because I thought uninitialised shit might be fucking it up.

thanks for the SDK ill try it tonight.

HuЯЯ1cΛиΞ
10-26-2009, 10:31 AM
it is much easier with hitboxes .

trace local eye angles if it hits a visible hitbox , shoot .

There are many ways using and specifying the TraceRay function. This was just a basic example (with some unnecessary checks though) and any half-way skilled coder could read up the rest on the SDK. :wink:

Why don't you show your "easier" tracing code? :ditsy:

ShitHappens
10-26-2009, 01:05 PM
There are many ways using and specifying the TraceRay function. This was just a basic example (with some unnecessary checks though) and any half-way skilled coder could read up the rest on the SDK. :wink:

Why don't you show your "easier" tracing code? :ditsy:

he's banned.

HuЯЯ1cΛиΞ
10-26-2009, 01:49 PM
he's banned.

Yeah just saw it. Why? Can't see any flaming in his posts. :eek2:

wav
10-26-2009, 05:16 PM
Make sure you're using the right mask for tracing and the correct tracefilter.

b2k5
10-26-2009, 05:43 PM
why would u need a filter?
MASK_SHOT pretty much does the job :D

dirty suka
10-26-2009, 05:58 PM
thanks guys, ill try give it another try.

dirty suka
10-27-2009, 12:25 AM
changing the masks didnt help, im not sure about tracefilters, all the examples ive seen everyone left trace filter null.

wav
10-27-2009, 01:12 AM
changing the masks didnt help, im not sure about tracefilters, all the examples ive seen everyone left trace filter null.

Because they're noobs. You're supposed to have a tracefilter in your TraceRay. That's why everybody's aimbot for TF2 failed when the spawn entity was added.



g_pEngineTrace->TraceRay ( ray, 0x4600400B, ( ITraceFilter* )dwTemp, &tr );



why would u need a filter?
MASK_SHOT pretty much does the job :D

Clearly you have much to learn about the source engine. You need a tracefilter for proper visibility checks. Also MASK_SHOT is not what they use in CS:S or half the source games. Pass the mask the mod team uses otherwise you're going to get incorrect results.

b2k5
10-27-2009, 11:22 AM
Clearly you have much to learn about the source engine. You need a tracefilter for proper visibility checks. Also MASK_SHOT is not what they use in CS:S or half the source games. Pass the mask the mod team uses otherwise you're going to get incorrect results.

probably, i've never been into it much.

i'm also perfectly aware of what u said. all i said is that MASK_SHOT pretty much does the job i want it to do. i dont really care what the devs used. im lazy.

wav
10-27-2009, 06:02 PM
DO IT RIGHT OR DON'T DO IT AT ALL.

WaRPiG
10-27-2009, 06:40 PM
raged (yes troll post, delete if needed)

dirty suka
10-27-2009, 06:41 PM
hmm its still totally fucked on my PC. I Dont think its the sdk because ive changed it a few times.

Adding a trace filter is giving me linker errors despite me linking with every lib and obj i could find in the sdk directory.

wav
10-28-2009, 12:36 AM
raged (yes troll post, delete if needed)

monobrow


hmm its still totally fucked on my PC. I Dont think its the sdk because ive changed it a few times.

Adding a trace filter is giving me linker errors despite me linking with every lib and obj i could find in the sdk directory.

You're doing it wrong.

dirty suka
10-28-2009, 12:51 AM
issue resolved thanks to xeno. Cheers buddy.

bobbysing
10-28-2009, 12:55 AM
issue resolved thanks to xeno. Cheers buddy.
Thanks for sharing the solution, that's really nice from you.

dirty suka
10-28-2009, 01:31 AM
the problem is that you can only call traceray at specific times, so creating your own threads doesnt work, you need to do it in a hooked function, such as create move as xeno123 showed me.

kolbybrooks
10-28-2009, 03:40 AM
That wasn't obvious?

dirty suka
10-28-2009, 06:19 AM
if it was SO obvious people would have told me when i asked. and seeing how i wasnt actually editing any game data i dont see how that is totally obvious, ive had hacks running in a similar way in other games no problems.

also, how is it obvious when 3/4 of the functions did work despite this?

Finally, the less obvious part is actually the function thats best to hook. Isnt it obvious you are gonna get flamed for being a prick?

WaRPiG
10-28-2009, 09:59 AM
monobrow


Blah blah blah. YOU HAVE NO PROOF.

kolbybrooks
10-28-2009, 05:52 PM
if it was SO obvious people would have told me when i asked.

I'm sorry, I didn't care about your thread so I couldn't have told you because I didn't waste my time reading it; Although you should realize though when functions are thread specific. Don't flame me for having common knowledge.

Xeno123
10-28-2009, 05:58 PM
http://paste2.org/p/487532
That was my quick-ass solution for him. Yeah the code is shoddy.

Xarg0
10-29-2009, 11:08 AM
@Xeno123
Dude your mainthread routine does never return, did you even try to compile that shit?
And stop casting stuff into LPTHREAD_START_ROUTINE plx, it is very very evil to do so.

http://paste2.org/p/490037

dirty suka
10-30-2009, 08:57 AM
all lies Xargo, thats just anti c&p :P .

yeh ofc you fix up the code yourself , he did code it in notepad without checking... I fixed it up and it worked, except for his Cinput function, the pointer he sets is completely wrong i think.

Xeno123
10-30-2009, 08:59 AM
@Xeno123
Dude your mainthread routine does never return, did you even try to compile that shit?
And stop casting stuff into LPTHREAD_START_ROUTINE plx, it is very very evil to do so.

http://paste2.org/p/490037

No shit sherlock. I wrote it in notepad just to get an example across, we already discussed this on IRC. I never intended for it to be working code.