Video Tutorial CSGO How to Find TraceRay - Call Traceline Tutorial

  • CSGO recently moved logic from 'client_panorama.dll' to 'client.dll', you must update all code that uses 'client_panorama.dll' and replace it with 'client.dll' or the code will not work.
Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,349
78,998
2,412
1 byte (8 bit): byte, DB, RESB
2 bytes (16 bit): word, DW, RESW
4 bytes (32 bit): dword, DD, RESD
8 bytes (64 bit): qword, DQ, RESQ
10 bytes (80 bit): tword, DT, REST
16 bytes (128 bit): oword, DO, RESO, DDQ, RESDQ ( oword - octoword )
32 bytes (256 bit): yword, DY, RESY
64 bytes (512 bit): zword, DZ, RESZ
If I become president of the New World Order, I am making octowords illegal
 
  • Haha
Reactions: Chucky

abrn

Dank Tier Donator
Full Member
Mar 13, 2020
34
683
1
Hello Rake, and everybody, my game crashes when trace.hit_entity occurs multiple times (in a row i think) even with 2000 Sleep. Is there a fix to this or did i do something wrong?
C++:
while (!(GetAsyncKeyState(VK_END) & 1)) {
    CGameTrace trace;
    Ray_t ray;
    CTraceFilter tracefilter;
    Ent* ent2 = (Ent*)clientEntityList->GetClientEntity(2);
    Ent* pLocal = *(Ent**)(clientdll + offsets::dwLocalPlayer);
    vec3 eyepos = pLocal->origin + pLocal->m_vecViewOffset;
    vec3 targeteyepos = ent2->origin + ent2->m_vecViewOffset;
    tracefilter.pSkip = (void*)pLocal;
    ray.Init(eyepos, targeteyepos);
    EngineTrace->TraceRay(ray, MASK_SHOT | CONTENTS_GRATE, &tracefilter, &trace);
    if (ent2 == trace.hit_entity)
        {
            std::cout << "ent2 health " << ent2->m_iHealth << " is visible\n";
        }
        else {
            std::cout << "ent2 health " << ent2->m_iHealth << "\n";
        }
    Sleep(2000);
}
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,349
78,998
2,412
Hello Rake, and everybody, my game crashes when trace.hit_entity occurs multiple times (in a row i think) even with 2000 Sleep. Is there a fix to this or did i do something wrong?
C++:
while (!(GetAsyncKeyState(VK_END) & 1)) {
    CGameTrace trace;
    Ray_t ray;
    CTraceFilter tracefilter;
    Ent* ent2 = (Ent*)clientEntityList->GetClientEntity(2);
    Ent* pLocal = *(Ent**)(clientdll + offsets::dwLocalPlayer);
    vec3 eyepos = pLocal->origin + pLocal->m_vecViewOffset;
    vec3 targeteyepos = ent2->origin + ent2->m_vecViewOffset;
    tracefilter.pSkip = (void*)pLocal;
    ray.Init(eyepos, targeteyepos);
    EngineTrace->TraceRay(ray, MASK_SHOT | CONTENTS_GRATE, &tracefilter, &trace);
    if (ent2 == trace.hit_entity)
        {
            std::cout << "ent2 health " << ent2->m_iHealth << " is visible\n";
        }
        else {
            std::cout << "ent2 health " << ent2->m_iHealth << "\n";
        }
    Sleep(2000);
}
call it inside a hook

https://guidedhacking.com/threads/glowhack-with-traceray-is-crashing.14868/?view=votes#post-91246
 
  • Like
Reactions: abrn

Solemny

Full Member
Sep 3, 2020
1
102
0
Quick question i have been developing an external cheat does this only work in a hooked process?
 

Kekz

Maybe Pasting
Dank Tier Donator
Nobleman
Jan 10, 2020
157
4,118
15

Erarnitox

🐅
Meme Tier VIP
Trump Tier Donator
May 11, 2018
151
5,023
3
Really cool tutorial series, however i and also some others had some problems with this so i tried to figure some things out... so first of all my code:

C++:
inline bool isVisible(Ent* target) {

    vec3 eyepos{ player->origin + player->m_vecViewOffset };
    vec3 targeteyepos{ target->origin + target->m_vecViewOffset };

    CGameTrace trace;
    Ray_t ray;
    CTraceFilter tracefilter;
    tracefilter.pSkip = (void*)player;

    ray.Init(eyepos, targeteyepos);

    EngineTrace->TraceRay(ray, 0x4600400B, &tracefilter, &trace);

    if (trace.allsolid || trace.startsolid) return false;

    //ray hit something:
    if (trace.fraction > 0.97f) {
        //might crash if not a player:
        //if (((Ent*)trace.hit_entity)->iTeamNum == player->iTeamNum) return false;
        
        /* Check if the hit entity is the correct one:
        if (!trace.hit_entity) return false;
        if (trace.hit_entity == target) return false;
        */

        return true;
    }

    return false;
}
- you can see i have used a different mask than Rake did in his original tutorial. I have found this mask by taking a look at what the firebullet function uses as a mask.
- some people say that the game crashes when calling traceline, and that is due to the fact that the raytrace function is not threadsafe, meaning you need to call it from a hook, that gets executed by the games main thread (for example the directx endscene)
- one would need to implement a lot of things to check in a relyable way if the hit entity was infact the target, so because im lazy i just check the if something was hit at all by checking trace.fraction which gives us the distance the ray traveled if it hit something.

Hope this was helpful even tho. it is not the best solution. But it works good enough for me. Just note that this will also return true if for example a friendly player it between you and the enemy (something to keep in mind)
 
  • Like
Reactions: Rake

Kekz

Maybe Pasting
Dank Tier Donator
Nobleman
Jan 10, 2020
157
4,118
15
Really cool tutorial series, however i and also some others had some problems with this so i tried to figure some things out... so first of all my code:

C++:
inline bool isVisible(Ent* target) {

    vec3 eyepos{ player->origin + player->m_vecViewOffset };
    vec3 targeteyepos{ target->origin + target->m_vecViewOffset };

    CGameTrace trace;
    Ray_t ray;
    CTraceFilter tracefilter;
    tracefilter.pSkip = (void*)player;

    ray.Init(eyepos, targeteyepos);

    EngineTrace->TraceRay(ray, 0x4600400B, &tracefilter, &trace);

    if (trace.allsolid || trace.startsolid) return false;

    //ray hit something:
    if (trace.fraction > 0.97f) {
        //might crash if not a player:
        //if (((Ent*)trace.hit_entity)->iTeamNum == player->iTeamNum) return false;
      
        /* Check if the hit entity is the correct one:
        if (!trace.hit_entity) return false;
        if (trace.hit_entity == target) return false;
        */

        return true;
    }

    return false;
}
- you can see i have used a different mask than Rake did in his original tutorial. I have found this mask by taking a look at what the firebullet function uses as a mask.
- some people say that the game crashes when calling traceline, and that is due to the fact that the raytrace function is not threadsafe, meaning you need to call it from a hook, that gets executed by the games main thread (for example the directx endscene)
- one would need to implement a lot of things to check in a relyable way if the hit entity was infact the target, so because im lazy i just check the if something was hit at all by checking trace.fraction which gives us the distance the ray traveled if it hit something.

Hope this was helpful even tho. it is not the best solution. But it works good enough for me. Just note that this will also return true if for example a friendly player it between you and the enemy (something to keep in mind)
I'd like to add some things:
1. For the mask it's always better to use the game's definitions, in this case MASK_SHOT_HULL | CONTENTS_HITBOX
C++:
// Taken from Valve SDK

#define   CONTENTS_EMPTY                0

#define   CONTENTS_SOLID                0x1 // an eye is never valid in a solid
#define   CONTENTS_WINDOW               0x2 // translucent, but not watery (glass)
#define   CONTENTS_AUX                  0x4
#define   CONTENTS_GRATE                0x8 // alpha-tested "grate" textures.  Bullets/sight pass through, but solids don't
#define   CONTENTS_SLIME                0x10
#define   CONTENTS_WATER                0x20
#define   CONTENTS_BLOCKLOS             0x40
#define   CONTENTS_OPAQUE               0x80
#define   LAST_VISIBLE_CONTENTS         CONTENTS_OPAQUE

#define   ALL_VISIBLE_CONTENTS            (LAST_VISIBLE_CONTENTS | (LAST_VISIBLE_CONTENTS-1))

#define   CONTENTS_TESTFOGVOLUME        0x100
#define   CONTENTS_UNUSED               0x200
#define   CONTENTS_BLOCKLIGHT           0x400
#define   CONTENTS_TEAM1                0x800
#define   CONTENTS_TEAM2                0x1000
#define   CONTENTS_IGNORE_NODRAW_OPAQUE 0x2000
#define   CONTENTS_MOVEABLE             0x4000
#define   CONTENTS_AREAPORTAL           0x8000
#define   CONTENTS_PLAYERCLIP           0x10000
#define   CONTENTS_MONSTERCLIP          0x20000
#define   CONTENTS_CURRENT_0            0x40000
#define   CONTENTS_CURRENT_90           0x80000
#define   CONTENTS_CURRENT_180          0x100000
#define   CONTENTS_CURRENT_270          0x200000
#define   CONTENTS_CURRENT_UP           0x400000
#define   CONTENTS_CURRENT_DOWN         0x800000

#define   CONTENTS_ORIGIN               0x1000000

#define   CONTENTS_MONSTER              0x2000000
#define   CONTENTS_DEBRIS               0x4000000
#define   CONTENTS_DETAIL               0x8000000
#define   CONTENTS_TRANSLUCENT          0x10000000
#define   CONTENTS_LADDER               0x20000000
#define   CONTENTS_HITBOX               0x40000000

#define   MASK_ALL                      (0xFFFFFFFF)
#define   MASK_SOLID                    (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE)  // everything that is normally solid
#define   MASK_PLAYERSOLID              (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_PLAYERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE)
#define   MASK_NPCSOLID                 (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE)
#define   MASK_NPCFLUID                 (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER)
#define   MASK_WATER                    (CONTENTS_WATER|CONTENTS_MOVEABLE|CONTENTS_SLIME)
#define   MASK_OPAQUE                   (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_OPAQUE)
#define   MASK_OPAQUE_AND_NPCS          (MASK_OPAQUE|CONTENTS_MONSTER)
#define   MASK_BLOCKLOS                 (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_BLOCKLOS)
#define   MASK_BLOCKLOS_AND_NPCS        (MASK_BLOCKLOS|CONTENTS_MONSTER)
#define   MASK_VISIBLE                  (MASK_OPAQUE|CONTENTS_IGNORE_NODRAW_OPAQUE)
#define   MASK_VISIBLE_AND_NPCS         (MASK_OPAQUE_AND_NPCS|CONTENTS_IGNORE_NODRAW_OPAQUE)
#define   MASK_SHOT                     (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTER|CONTENTS_WINDOW|CONTENTS_DEBRIS|CONTENTS_HITBOX)  // bullets see these as solid
#define   MASK_SHOT_BRUSHONLY           (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_DEBRIS)
#define   MASK_SHOT_HULL                (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTER|CONTENTS_WINDOW|CONTENTS_DEBRIS|CONTENTS_GRATE)
#define   MASK_SHOT_PORTAL              (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTER)
#define   MASK_SOLID_BRUSHONLY          (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_GRATE)
#define   MASK_PLAYERSOLID_BRUSHONLY    (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_PLAYERCLIP|CONTENTS_GRATE)
#define   MASK_NPCSOLID_BRUSHONLY       (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTERCLIP|CONTENTS_GRATE)
#define   MASK_NPCWORLDSTATIC           (CONTENTS_SOLID|CONTENTS_WINDOW|CONTENTS_MONSTERCLIP|CONTENTS_GRATE)
#define   MASK_NPCWORLDSTATIC_FLUID     (CONTENTS_SOLID|CONTENTS_WINDOW|CONTENTS_MONSTERCLIP)
#define   MASK_SPLITAREAPORTAL          (CONTENTS_WATER|CONTENTS_SLIME)
#define   MASK_CURRENT                  (CONTENTS_CURRENT_0|CONTENTS_CURRENT_90|CONTENTS_CURRENT_180|CONTENTS_CURRENT_270|CONTENTS_CURRENT_UP|CONTENTS_CURRENT_DOWN)
#define   MASK_DEADSOLID                (CONTENTS_SOLID|CONTENTS_PLAYERCLIP|CONTENTS_WINDOW|CONTENTS_GRATE)

#define   DISPSURF_FLAG_SURFACE           (1<<0)
#define   DISPSURF_FLAG_WALKABLE          (1<<1)
#define   DISPSURF_FLAG_BUILDABLE         (1<<2)
#define   DISPSURF_FLAG_SURFPROP1         (1<<3)
#define   DISPSURF_FLAG_SURFPROP2         (1<<4)
(2. True, it's mentioned in the disclaimer under the Part 2 video.)
3. That only depends on the way you're using it. The fraction of the ray will always be valid, no matter if it actually hit a target or not (assuming startsolid is false etc...).
It only tells you how far the ray travelled (1.f -> travelled the whole distance unobstructed, 0.5f -> hit something half way). If for example you want to make an Autowall, checking only for fraction won't do it.
There are various ways of checking if you hit a player:
- Check the trace's hitgroup, if it's not 0 it means we hit a body part (only applicable for players).
- There are various ways of checking if an entity is a player: I recommend checking hit entity's ClassID (CCSPlayer)
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods