Solved Problems With CoD W2S/Snaplines

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

omegaweapontmod

I Know Nothing
Trump Tier Donator
Dank Tier Donator
Nobleman
Top Poster Of Month
Aug 21, 2020
55
1,023
2
Game Name
CoD: MW2 (iw4x)
Tutorial Link
N/A
How long you been coding/hacking?
6 Years Full Stack | 0 Years C++/Game Hacking
Coding Language
C++
I seem to have everything I need for a snaplines hack but I'm having trouble figuring out what the issue is with the location of the snaplines (primarily because CoD uses a wonky W2S function in comparison to the others I've seen that make sense to me).

I'm using the W2S function Rake posted for CoD/Quake and there's something off with the my code but I'm not sure where to point the finger.

I've tried every permutation of the 3 view axes order because that's the part I'm mostly unsure about but I still get a foobar result.

Variables Being Passed In to DrawSnaplines:
vec3 localEntPosition = { -389.0, -212.0, 192 }; // src
vec3 botEntPosition = { -536.0, -435.0, 194 }; // dst
// screen is just the local var the info is passed back to
float fovX = 0.637; // fovx
float fovY = 0.478; // fovy
int windowWidth = 800; // windowWidth
int windowHeight = 600; // windowHeight
vec3 axis = { -0.749, -0.651, 0.121 }; // left?
vec3 axis2 = { 0.656, -0.755, 0.0 }; // up?
vec3 axis3 = { 0.091, 0.079, 0.993 }; // forward?
Any pointers would be greatly appreciated!

DrawSnaplines:
void Hack::DrawSnaplines(LPDIRECT3DDEVICE9 pDevice) {
    for (int i = 0; i < 32; i++) {
        Entity* curEnt = &(this->entList->entities[i]);
        if (!this->CheckValidEnt(curEnt))
            continue;

        vec3 window = vec3(windowWidth / 2, windowHeight, 0);
        vec3 screen;
        if (WorldToScreen(this->localEnt->position, curEnt->position, screen, this->refDef->fovX, this->refDef->fovY, (float)windowWidth, (float)windowHeight, this->refDef->axis, this->refDef->axis2, this->refDef->axis3)) {
            DrawLine(screen.x, screen.y, windowWidth / 2, windowHeight, 1.0, this->color.enemy.snapline, pDevice);
        }
    }
}
WorldToScreen:
bool WorldToScreen(vec3 src, vec3 dst, vec3& screen, float fovx, float fovy, float windowWidth, float windowHeight, vec3 left, vec3 up, vec3 forward)
{
    vec3 transform;
    float xc, yc;
    float px, py;
    float z;

    px = tan(fovx * PI / 360.0);
    py = tan(fovy * PI / 360.0);

    transform = Subtract(dst, src);

    xc = windowWidth / 2.0;
    yc = windowHeight / 2.0;

    z = DotProduct(transform, left);

    if (z <= 0.1)
    {
        return false;
    }

    screen.x = xc - DotProduct(transform, up) * xc / (z * px);
    screen.y = yc - DotProduct(transform, forward) * yc / (z * py);

    return true;
}
DrawLine:
void DrawLine(int x1, int y1, int x2, int y2, int thickness, D3DCOLOR color, IDirect3DDevice9* dev)
{
    ID3DXLine* LineL;
    D3DXCreateLine(dev, &LineL);

    D3DXVECTOR2 Line[2];
    Line[0] = D3DXVECTOR2(x1, y1);
    Line[1] = D3DXVECTOR2(x2, y2);
    LineL->SetWidth(thickness);
    LineL->Draw(Line, 2, color);
    LineL->Release();
}
Pictures of issue:

1599513896247.png

1599513918386.png
 

omegaweapontmod

I Know Nothing
Trump Tier Donator
Dank Tier Donator
Nobleman
Top Poster Of Month
Aug 21, 2020
55
1,023
2
Just an update -- the W2S function was in fact wrong as it stood. I swapped it out with another CoD W2S function and everything now works.

I do get a little bit of flickering as the line adjusts and I'm not sure the cause of that but at least the W2S is spitting out good/accurate coordinates now.

Thanks for all your help Rake!
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,061
78,998
2,370
the rotation matrix order is: left, up, forward
which you are doing correctly

Draw a line from:

windowWidth / 2, 0

to

windowWidth / 2, windowheight / 2

and make sure that is drawing correctly before you continue to debug

and this is a very minor thing, but drawing from the bottom of the screen to the enemy makes more sense then drawing from enemy to bottom of screen which is what you're doing right now

Where are you drawing? inside EndScene?
 

omegaweapontmod

I Know Nothing
Trump Tier Donator
Dank Tier Donator
Nobleman
Top Poster Of Month
Aug 21, 2020
55
1,023
2
the rotation matrix order is: left, up, forward
which you are doing correctly

Draw a line from:

windowWidth / 2, 0

to

windowWidth / 2, windowheight / 2

and make sure that is drawing correctly before you continue to debug

and this is a very minor thing, but drawing from the bottom of the screen to the enemy makes more sense then drawing from enemy to bottom of screen which is what you're doing right now

Where are you drawing? inside EndScene?
Thanks for the info. So just to be clear, the order of the rotation matrix in refDef is left, up, forward? Is there a way to differentiate these without just knowing? I've tried different movements, but all the values change (as is to be expected) simultaneously.

I also just noticed what you're talking about as far as draw order goes. I had the direction right for the W2S function but reversed it for some reason on the actual DrawLine call. This definitely wasn't intentional.

And yes, I've hooked EndScene and am drawing inside that hook.

I've also drawn a line from those two coordinates successfully:

1599530731144.png


Thanks for your input. I'm not sure why the snapline is so sensitive. It definitely directs towards the entity but the slightest rotation of the view away from the entity results in a disproportionate change in where the snapline points resulting in an inaccurate snapline. It's almost like it's not correctly taking into account the view angles but I'm not familiar enough with the logic behind CoD's W2S to know right off hand what piece I'm screwing up.
 
Last edited:

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,061
78,998
2,370
yes: left, up, forward

Your regular line I told you to draw, is drawing correctly, so that's good.

Something is wrong with W2S, matrix, refdef_t or the data you're using for src and dst. but the W2S should be good, I would not debug that until you debug everything else first

oh I just noticed:

WorldToScreen(this->localEnt->position

your position arg needs to be camera position, not body position: refdef_t->cameraorigin I believe it is

check the source codes from the COD thread to confirm
 

omegaweapontmod

I Know Nothing
Trump Tier Donator
Dank Tier Donator
Nobleman
Top Poster Of Month
Aug 21, 2020
55
1,023
2
yes: left, up, forward

Your regular line I told you to draw, is drawing correctly, so that's good.

Something is wrong with W2S, matrix, refdef_t or the data you're using for src and dst. but the W2S should be good, I would not debug that until you debug everything else first

oh I just noticed:

WorldToScreen(this->localEnt->position

your position arg needs to be camera position, not body position: refdef_t->cameraorigin I believe it is

check the source codes from the COD thread to confirm
Good Catch. I switched local player position to the origin in the refDef structure and still no luck.

I'm not entirely sure where to go from here. I'm fairly confident in the values that are being passed into W2S and I've seen other W2S functions and they're effectively doing the same thing this one is. So you're definitely right, it's not the W2S, I'm just not sure what it is beyond this point.

I've verified the FOV values (by changing the FOV and seeing the values change) and the screen dimensions (they match what I have the settings set at). The 3 axes are all matching exactly what is in Reclass and the refdef structure matches the structure of the one posted in the Quake/CoD thread verbatim.

So either the order I'm passing in the axes is messed up or my position/refDef origin is wrong (although these coordinates are exactly the same except the Z value on the refDef origin is 60 more than the Z coordinate on my position). This seems to validate both the refDef origin and my position.

I'll get with my friend and see if he can't shed some light as a second pair of eyes.

I've been looking at this for hours and haven't made an ounce of progress. The most annoying issues to solve are just like this -- everything looks right and nothing works lol.
 

omegaweapontmod

I Know Nothing
Trump Tier Donator
Dank Tier Donator
Nobleman
Top Poster Of Month
Aug 21, 2020
55
1,023
2
Haha!
do I need to link you the timeline again? :trollface:

You must suffer like we all have. Imagine trying to learn if GH didn't exist :p
🤣🤣🤣

Oh I'm suffering! I cannot imagine learning all this without this site. I'd have to sort through all the "Plz make aimbot 4 me undetected" on UC and even then would have 25% of the info...
 
  • Like
Reactions: naimcool

omegaweapontmod

I Know Nothing
Trump Tier Donator
Dank Tier Donator
Nobleman
Top Poster Of Month
Aug 21, 2020
55
1,023
2
So I used this:

Working W2S:
bool WorldToScreen(vec3_t vWorldLocation, float Screen[2])
{

    vec3_t local, transformed;

    VectorSubtract(vWorldLocation, refdef->vieworg, local);

    transformed[0] = DotProduct(local, refdef->viewaxis[1]);
    transformed[1] = DotProduct(local, refdef->viewaxis[2]);
    transformed[2] = DotProduct(local, refdef->viewaxis[0]);

    if (transformed[2] < 0.01f) {
        return false;
    }

    Screen[0] = ((refdef->width / 2) * (1 - (transformed[0] / refdef->fov_x / transformed[2])));
    Screen[1] = ((refdef->height / 2) * (1 - (transformed[1] / refdef->fov_y / transformed[2])));
    return true;     
    

}
I'm fairly certain the problem with the W2S in the quake article, for this CoD in particular at least, lies with the 2 lines that call tangent functions.

I didn't bother modifying and testing because I already had a working W2S that made more sense to me at that point but the one above works flawlessly with all the same inputs (in a different format though obviously).
 
  • Like
Reactions: Petko123 and Rake

omegaweapontmod

I Know Nothing
Trump Tier Donator
Dank Tier Donator
Nobleman
Top Poster Of Month
Aug 21, 2020
55
1,023
2
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.

Similar threads

Community Mods