Author Topic: [Tut]How I did W2S  (Read 375 times)

0 Members and 1 Guest are viewing this topic.

Mercenary_Frank

  • Online Villain
  • ***
  • Posts: 177
    • View Profile
[Tut]How I did W2S
« on: March 09, 2016, 04:23:19 am »
Tally-ho chaps!

Since mrmedic is away for a bit I think ill step in to fill his void

This tut continues straight off where worm left off so If you haven't read it go do that before you continue reading. All code is C++ with the lib detours 1.5

In order to do Worldtoscreen(convert 3D coordinates onto a 2D plane) you need several things. A viewmatrix, projectionmatrix, screen hight width(viewport) and ofcourse your 3D coordinates. First things first find the D3DX device pointer with a pattern scan like so

Code: [Select]
DWORD dwDXDevice = utility.FindPattern((DWORD)GetModuleHandle("d3d9.dll"), 0x128000, (PBYTE)"\xC7\x06\x00\x00\x00\x00\x89\x86\x00\x00\x00\x00\x89\x86", "xx????xx????xx")
After REing this game for over 2 months because mrmedic told me about that function that converted the coordinates for you I discovered something. The first time D3DXMATRIXMULTIPLY is called it passes both the viewmatrix and projmatrix. Perfect! so lets hook that!

Code: [Select]
DWORD D3DXMatrixMultiply = (DWORD)GetProcAddress(GetModuleHandleA("d3dx9_42.dll"), "D3DXMatrixMultiply");
and to save the values

Code: [Select]
HRESULT WINAPI hkD3DXMatrixMultiply(_Inout_ D3DXMATRIX *pOut, _In_ D3DXMATRIX *pM1, _In_ D3DXMATRIX *pM2)
{

if (!trigger&&GetAsyncKeyState(VK_NUMPAD1) & 1)
{
D3DXVECTOR3 vector2;
D3DXMATRIX WorldToLocal;
D3DXMatrixIdentity(&WorldToLocal);

for (int i = 0; i < cPlayerBase.size(); i++)
{

D3DXVECTOR3 vector3(cPlayerBase[i]->vec[0], cPlayerBase[i]->vec[1], cPlayerBase[i]->vec[2]);

D3DXVec3Project(&vector2, &vector3, &Viewport, pM2, pM1, &WorldToLocal);
cPlayerBase[i]->vec2Dpoint[0] = vector2.x;
cPlayerBase[i]->vec2Dpoint[1] = vector2.y;
cPlayerBase[i]->vec2Dpoint[2] = vector2.z;

std::cout << " X on screen " << vector2.x << " Y on screen"  << vector2.y << std::endl;

if (i == cPlayerBase.size() - 1)
trigger = true;
}
}

return oD3DXMatrixMultiply(pOut, pM1, pM2);
}

Now only when the function is called does the parameter contain a valid pointer to the viewmatrix so I do the D3DXVec3Project function inside matrixmultiply the first time it called the bool gets set true in present(you can pick wherever you like)

This is the result



big thanks to mrmedic btw may he return back to us :D