Page 2 of 12 FirstFirst 1234 ... LastLast
Results 26 to 50 of 287

Thread: Interception with DirectX

  1. #26
    Join Date
    Jan 2010
    Location
    Salo, Finland
    Posts
    65
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I have worked on text recognition today, i already found the function that is used to draw all 2D sprites and text. Ill try to make some system to identify all the letters now.

    E: And with same system inventory items too.
    Last edited by Mato; 05-24-2012 at 02:35 PM.

  2. #27
    Join Date
    Mar 2012
    Posts
    690
    Mentioned
    2 Post(s)
    Quoted
    40 Post(s)

    Default

    But when Optimus would land, will this be unaffected right ?

  3. #28
    Join Date
    Jan 2010
    Location
    Salo, Finland
    Posts
    65
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    If they dont disable DirectX totally it will work.

    I managed to access the sprite data before it is drawn and saved them as images. I found a font sprite that contains all the letters that uptext can contain + a whole minimap image from a pretty large area:



    With the minimap i could make a very precise positioning system. If i can get the coordinates of what part of the minimap is drawn currently i can get the exact position of the player in the minimap coordinates. That way i can store for example walking path in minimap coords and make the player walk it very precisely without the risk of misswalking. Sounds good to me.

  4. #29
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    Quote Originally Posted by Mato View Post
    If they dont disable DirectX totally it will work.

    I managed to access the sprite data before it is drawn and saved them as images. I found a font sprite that contains all the letters that uptext can contain + a whole minimap image from a pretty large area:



    With the minimap i could make a very precise positioning system. If i can get the coordinates of what part of the minimap is drawn currently i can get the exact position of the player in the minimap coordinates. That way i can store for example walking path in minimap coords and make the player walk it very precisely without the risk of misswalking. Sounds good to me.
    The minimap is actually rendered from 4 chunks.

    Like this: (EDIT: Takes a while to load the GIF)
    There used to be something meaningful here.

  5. #30
    Join Date
    Jan 2010
    Location
    Salo, Finland
    Posts
    65
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Because the minimap i got is in 1 piece it means it was drawn in just 1 call to the drawing function so what do you mean by 4 chunks?

  6. #31
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    Btw what'd you use to debug the DirectX calls RuneScape makes?

  7. #32
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    Quote Originally Posted by Mato View Post
    Because the minimap i got is in 1 piece it means it was drawn in just 1 call to the drawing function so what do you mean by 4 chunks?
    It might just be the OpenGL then. I haven't personally hooked DirectX.
    There used to be something meaningful here.

  8. #33
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    1,199
    Mentioned
    0 Post(s)
    Quoted
    26 Post(s)

    Default

    Quote Originally Posted by Frement View Post
    It might just be the OpenGL then. I haven't personally hooked DirectX.
    Doesn't it depend on where you are standing on what hunks are loaded? like if someone was standing towards the center of Mato's image, wouldn't all four chunks load then and show as a single loaded chunk?

  9. #34
    Join Date
    Jan 2010
    Location
    Salo, Finland
    Posts
    65
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I debug the functions by just adding the hook of the function i want, for example DrawIndexedPrimitive that is used to draw all the 3D models and then adding a hotkey to it. When i press the hotkey it will return D3D_OK which means like drawing succesfull and then i see it directly in the game what isnt drawn. This is just for drawing functions ofc but i dont use any other programs for this.

    Ill get more minimap images today so i will see about the chunk thing.

  10. #35
    Join Date
    Feb 2007
    Location
    Colorado, USA
    Posts
    3,716
    Mentioned
    51 Post(s)
    Quoted
    624 Post(s)

    Default

    Quote Originally Posted by Chig View Post
    If this works, does that mean dung bot is do-able?

    EDIT: Yay 200 Posts
    Would make it quite a bit easier, yes

    Quote Originally Posted by Sex View Post
    Awesome . Just don't leave us like silentwolf .
    The only true authority stems from knowledge, not from position.

    You can contact me via matrix protocol: @grats:grats.win or you can email me at the same domain, any user/email address.

  11. #36
    Join Date
    Jan 2010
    Location
    Salo, Finland
    Posts
    65
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    My computers harddrive decided to break today, dont worry i had a backup of everything but it might take a few days to get back working on this.

  12. #37
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    Just a warning to everyone, please do NOT use any precompiled binaries without having either source or the approval of a staff member.

    This looks good though, but why not hook OpenGL, that way its cross platform?
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  13. #38
    Join Date
    Nov 2011
    Location
    England
    Posts
    3,072
    Mentioned
    296 Post(s)
    Quoted
    1094 Post(s)

    Default

    Quote Originally Posted by Mato View Post
    If they dont disable DirectX totally it will work.

    I managed to access the sprite data before it is drawn and saved them as images. I found a font sprite that contains all the letters that uptext can contain + a whole minimap image from a pretty large area:



    With the minimap i could make a very precise positioning system. If i can get the coordinates of what part of the minimap is drawn currently i can get the exact position of the player in the minimap coordinates. That way i can store for example walking path in minimap coords and make the player walk it very precisely without the risk of misswalking. Sounds good to me.
    Woah map the whole runescape with that :P would make sps alot more accurate

  14. #39
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    Quote Originally Posted by Mato View Post
    I debug the functions by just adding the hook of the function i want, for example DrawIndexedPrimitive that is used to draw all the 3D models and then adding a hotkey to it. When i press the hotkey it will return D3D_OK which means like drawing succesfull and then i see it directly in the game what isnt drawn. This is just for drawing functions ofc but i dont use any other programs for this.

    Ill get more minimap images today so i will see about the chunk thing.
    Could you PM me (or just post here) some sources? I'd really love to see how you do the hooking

    And out of curiosity, do you hook the gfx drivers directly, d3d9.dll or jagdx.dll?
    There used to be something meaningful here.

  15. #40
    Join Date
    Jan 2010
    Location
    Salo, Finland
    Posts
    65
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I didnt hook OpenGL because firstly i didnt find any DirectX hooks so it was like a challenge for me and second i dont have any experience with OpenGL so with that it would have taken much longer to achieve the same as what i have done now.

    I will post some cleaned up code after i get my own computer running again, i should get a new harddrive tomorrow and then i will have to install windows again + visual studio + bla bla bla...

    And i hook the d3d9.dll

  16. #41
    Join Date
    Apr 2007
    Location
    Colchester, UK
    Posts
    1,220
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Mato View Post
    I didnt hook OpenGL because firstly i didnt find any DirectX hooks so it was like a challenge for me and second i dont have any experience with OpenGL so with that it would have taken much longer to achieve the same as what i have done now.

    I will post some cleaned up code after i get my own computer running again, i should get a new harddrive tomorrow and then i will have to install windows again + visual studio + bla bla bla...

    And i hook the d3d9.dll
    can i suggest setting up a github for it that way you can show your work and not worry to much about loosing it.

    i think you can also make it private if you are worried about people stealing stuff

  17. #42
    Join Date
    Jul 2011
    Location
    /home/litoris
    Posts
    2,226
    Mentioned
    0 Post(s)
    Quoted
    159 Post(s)

    Default

    Hell, this could be the future of botting. Getting the minimap images only would allow us to do so much more.
    Miner & Urn Crafter & 07 Chicken Killer
    SPS BlindWalk Tutorial

    Working on: Nothing

    teacher in every art, brought the fire that hath proved to mortals a means to mighty ends

  18. #43
    Join Date
    Nov 2011
    Location
    England
    Posts
    3,072
    Mentioned
    296 Post(s)
    Quoted
    1094 Post(s)

    Default

    Can you read any camera pos with direct x?

    like if you open the command thing and type in "getcamerapos"
    It comes up with http://puu.sh/wIQs

    would you be able to get any of that with directx? just wondering :P

  19. #44
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Nava2 View Post
    Just a warning to everyone, please do NOT use any precompiled binaries without having either source or the approval of a staff member.

    This looks good though, but why not hook OpenGL, that way its cross platform?
    DirectX is always going to be a ton faster than OpenGL.. OpenGL doesn't converse directly with the screen buffer.. DirectX has Direct access to the screen buffers at least for colouring and rendering graphics; learned that in game programming.
    I am Ggzz..
    Hackintosher

  20. #45
    Join Date
    Jan 2007
    Location
    Kansas
    Posts
    3,760
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    DirectX is always going to be a ton faster than OpenGL.. OpenGL doesn't converse directly with the screen buffer.. DirectX has Direct access to the screen buffers at least for colouring and rendering graphics; learned that in game programming.
    But not cross platform.


  21. #46
    Join Date
    Jan 2010
    Location
    Salo, Finland
    Posts
    65
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    No, i cannot get the exact camera position because the vertex shader doesnt have it as variable. It has only the WorldViewProjection matrix that i use to calculate the screen coordinates of the drawn object but i cannot get the view position because i would need only the View matrix, nothing else combined to it.

  22. #47
    Join Date
    May 2007
    Location
    England/Liverpool
    Posts
    1,004
    Mentioned
    9 Post(s)
    Quoted
    106 Post(s)

    Default

    So can you use what you have now to detect coords of npc's ,objects,items?.

    Would really love to see the source for this also

  23. #48
    Join Date
    Jan 2010
    Location
    Salo, Finland
    Posts
    65
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I can find the coords on anything on the mainscreen but sprite recognition isnt done yet.

  24. #49
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    I'm only interested in the way you hook the functions. That is the only thing I ask, I don't need the whole source code. Just for my curiosity
    There used to be something meaningful here.

  25. #50
    Join Date
    Jan 2010
    Location
    Salo, Finland
    Posts
    65
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I got the harddrive today morning and im at my own computer now

    Here is the current code for main.cpp:
    Code:
    #define _WINSOCKAPI_
    #include <windows.h>
    #include <winsock2.h>
    #include <iostream>
    #include <d3d9.h>
    #include <d3dx9.h>
    
    #include "vTable.h"
    #include "dxhook_proto.h"
    
    #pragma comment(lib, "WS2_32.lib")
    #pragma comment(lib, "d3d9.lib")
    #pragma comment(lib, "d3dx9.lib")
    
    //#define HOOK_SEND
    //#define LOG_PACKETS
    
    #define CHICKEN        (ID == 26870121)
    #define BANK_DESK      (ID == 7500)
    #define DEPOSIT_BOX    (ID == 13110)
    #define BONES          (ID == 11010136)
    #define ORE_ROCK       (ID == 27787767 || ID == 20316628 || ID == 25231890)
    #define COW            (ID == 61998039 || ID == 61211546 || ID == 61211521)
    
    bool logNextFrame = false;
    bool logging = false;
    POINT *logObjects = NULL;
    UINT numObjects = 0;
    UINT maxObjects = 0;
    DWORD searchID = 0;
    
    bool drawIDs = false;
    
    typedef int(WINAPI *send_t)(SOCKET, char *, int, int);
    
    DWORD WINAPI Thread(LPVOID lpParam);
    void* DetourFunc(BYTE *src, const BYTE *dst, const int len);
    void DrawTextF(D3DCOLOR color, int x, int y, const char *fmt, ...);
    void DrawRect(LPDIRECT3DDEVICE9 pDevice, int x, int y, int w, int h, BYTE r, BYTE g, BYTE b);
    bool Compare(const BYTE* pData, const BYTE* bMask, const char* szMask);
    DWORD FindPattern(DWORD dwAddress, DWORD dwLen, BYTE *bMask, char * szMask);
    void doDisassembleShader(LPDIRECT3DDEVICE9 pDevice, char* FileName);
    
    void FindRSWindow();
    BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam);
    BOOL CALLBACK EnumWindowProc(HWND hwnd, LPARAM lParam);
    void WindowToScreen(HWND hWnd, POINT &wnd, POINT &scrn);
    
    #ifdef HOOK_SEND
    int WINAPI hk_send(SOCKET s, char *buf, int len, int flags);
    
    send_t o_send;
    
    SOCKET sckt;
    int flgs;
    #endif
    
    HWND hWnd = NULL;
    LPD3DXFONT font = NULL;
    LPDIRECT3DBASETEXTURE9 tex = NULL;
    
    D3DXVECTOR3 mmCoords(0, 0, 0);
    
    Present_t oPresent;
    DrawIndexedPrimitive_t oDrawIndexedPrimitive;
    DrawPrimitive_t oDrawPrimitive;
    BeginScene_t oBeginScene;
    EndScene_t oEndScene;
    
    HRESULT WINAPI hkPresent(LPDIRECT3DDEVICE9 pDevice, RECT* pSourceRect, RECT* pDestRect, HWND hDestWindowOverride, RGNDATA *pDirtyRegion);
    HRESULT WINAPI hkDrawIndexedPrimitive(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE Type, int BaseVertexIndex, UINT MinIndex, UINT NumVertices, UINT StartIndex, UINT PrimitiveCount);
    HRESULT WINAPI hkDrawPrimitive(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount);
    HRESULT WINAPI hkBeginScene(LPDIRECT3DDEVICE9 pDevice);
    HRESULT WINAPI hkEndScene(LPDIRECT3DDEVICE9 pDevice);
    
    #pragma pack(push)
    #pragma pack(1)
    
    //structs here...
    
    #pragma pack(pop)
    
    BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID reserved)
    {
    	if(dwReason == DLL_PROCESS_ATTACH)
    	{
    		DisableThreadLibraryCalls(hModule);
    
    #ifdef HOOK_SEND
    		DWORD addr_send = (DWORD)GetProcAddress(GetModuleHandle("WS2_32.dll"), "send");
    	    o_send = (send_t)DetourFunc((PBYTE)addr_send, (PBYTE)hk_send, 5);
    #endif
    
    		while(GetModuleHandleA("d3d9.dll") == 0)
    		Sleep(200);
    	    DWORD DXBase = (DWORD)GetModuleHandle("d3d9.dll");
    	    DWORD Pattern = FindPattern(DXBase, 0x128000, (PBYTE)"\xC7\x06\x00\x00\x00\x00\x89\x86\x00\x00\x00\x00\x89\x86", "xx????xx????xx");
    	    DWORD* vTable = NULL;
    	    memcpy(&vTable, (void*)(Pattern+2), 4);
    
    		oPresent = (Present_t)DetourFunc((BYTE*)vTable[PRESENT], (BYTE*)hkPresent, 5);
    		oDrawIndexedPrimitive = (DrawIndexedPrimitive_t)DetourFunc((BYTE*)vTable[DRAWINDEXEDPRIMITIVE], (BYTE*)hkDrawIndexedPrimitive, 5);
    		oDrawPrimitive = (DrawPrimitive_t)DetourFunc((BYTE*)vTable[DRAWPRIMITIVE], (BYTE*)hkDrawPrimitive, 5);
    		oBeginScene = (BeginScene_t)DetourFunc((BYTE*)vTable[BEGINSCENE], (BYTE*)hkBeginScene, 5);
    		oEndScene = (EndScene_t)DetourFunc((BYTE*)vTable[ENDSCENE], (BYTE*)hkEndScene, 5);
    
    		CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)Thread, NULL, NULL, NULL);
    
    		FindRSWindow();
    	}
    	return TRUE;
    }
    
    DWORD WINAPI Thread(LPVOID lpParam)
    {
    	return 0;
    
    	for(;;)
    	{
    		Sleep(50);
    	}
    
    	return 0;
    }
    
    #ifdef HOOK_SEND
    int WINAPI hk_send(SOCKET s, char *buf, int len, int flags)
    {
    	sckt = s;
    	flgs = flags;
    
    #ifdef LOG_PACKETS
    	if(len != 1 && len != 15 && len != 11 && len != 3)
    	{
    	    FILE *file = NULL;
    	    fopen_s(&file, "C:\\Users\\(your computer name)\\Desktop\\packetLog.txt", "a");
    	    if(file)
    	    {
    		    fprintf(file, "Packet sent with length %i; first byte 0x%.2X\n", len, (DWORD)buf[0]);
    		    fclose(file);
    			MessageBox(NULL, "pause", "foo", MB_OK);
    	    }
    	}
    #endif
    
    	return o_send(s, buf, len, flags);
    }
    #endif
    
    HRESULT WINAPI hkPresent(LPDIRECT3DDEVICE9 pDevice, RECT* pSourceRect, RECT* pDestRect, HWND hDestWindowOverride, RGNDATA *pDirtyRegion)
    {
    	return oPresent(pDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
    }
    
    HRESULT WINAPI hkDrawIndexedPrimitive(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE Type, int BaseVertexIndex, UINT MinIndex, UINT NumVertices, UINT StartIndex, UINT PrimitiveCount)
    {
    	DWORD ID = NumVertices | (PrimitiveCount << 16);
    
    	/*UINT stride;
    	UINT offset;
        LPDIRECT3DVERTEXBUFFER9 buffer;  //after the GetStreamSource() call this can be used to get the model vertices
    	pDevice->GetStreamSource(0, &buffer, &offset, &stride);*/
    
    	/*static bool once = true;
    	if(once)
    	{
    		once = false;
    		doDisassembleShader(pDevice, "C:\\Users\\(your computer name)\\Desktop\\shader.txt");
    	}*/
    
    	if(COW)
    		pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
    
    	D3DXMATRIX WVP;
    	pDevice->GetVertexShaderConstantF(0, (float*)&WVP, 4);
    	D3DXMatrixTranspose(&WVP, &WVP);
    
    	D3DXVECTOR3 out;
    	D3DXVECTOR3 in(0, 0, 0);
    	D3DXVec3TransformCoord(&out, &in, &WVP);
    
    	D3DVIEWPORT9 viewport;
    	pDevice->GetViewport(&viewport);
    
    	out.x = (out.x + 1.0f) * viewport.Width * 0.5f + viewport.X;
    	out.y = (1.0f - out.y) * viewport.Height * 0.5f + viewport.Y;
    
    	int x = (int)out.x;
    	int y = (int)out.y;
    
    	if(logging && ID == searchID && numObjects < maxObjects)
    	{
    		logObjects[numObjects].x = x;
    		logObjects[numObjects].y = y;
    		numObjects++;
    	}
    
    	if(drawIDs && out.x >= 0.0f && out.x <= (float)viewport.Width && out.y >= 0.0f && out.y <= (float)viewport.Height)
    	{
    		DrawTextF(D3DCOLOR_XRGB(0, 255, 0), x, y, "%u", ID);
    	}
    
    	HRESULT result = oDrawIndexedPrimitive(pDevice, Type, BaseVertexIndex, MinIndex, NumVertices, StartIndex, PrimitiveCount);
    	pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
    	return result;
    }
    
    HRESULT WINAPI hkDrawPrimitive(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount)
    {
    	if(GetAsyncKeyState(VK_NUMPAD3) & 0x8000)
    		return D3D_OK;
    
    	if(GetAsyncKeyState(VK_INSERT) & 0x8000)
    	{
    		doDisassembleShader(pDevice, "C:\\Users\\(your computer name)\\Desktop\\hkDrawPrimitive_shader.txt");
    		MessageBox(NULL, "done", "hkDrawPrimitive", MB_OK);
    	}
    
    	/*static int numTexturesSaved = 0;
    	static int numTexturesToSave = 2000;
    	if(numTexturesSaved < numTexturesToSave)
    	{
    		if(SUCCEEDED(pDevice->GetTexture(0, &tex)))
    		{
    			char buff[512];
    			memset(buff, 0, 512);
    			sprintf_s(buff, 512, "C:\\Users\\(your computer name)\\Desktop\\textures\\texture_%i.dds", numTexturesSaved);
    			D3DXSaveTextureToFile(buff, D3DXIFF_DDS, tex, NULL);
    			numTexturesSaved++;
    			tex->Release();
    		}
    	}*/
    
    	if(SUCCEEDED(pDevice->GetTexture(0, &tex)))
    	{
    		LPDIRECT3DTEXTURE9 _tex = (LPDIRECT3DTEXTURE9)tex;
    		D3DSURFACE_DESC desc;
    		if(SUCCEEDED(_tex->GetLevelDesc(0, &desc)))
    		{
    			if(desc.Width == 512 && desc.Height == 512)
    			{
    				D3DXMATRIX m;
    				if(SUCCEEDED(pDevice->GetVertexShaderConstantF(0, (float*)&m, 4)))
    				{
    					D3DXMatrixTranspose(&m, &m);
    				
    					D3DXVECTOR3 out;
    					D3DXVECTOR3 in(1.0f, -1.0f, 0);
    					D3DXVec3TransformCoord(&out, &in, &m);
    
    					mmCoords = out;
    				}
    			}
    		}
    		tex->Release();
    	}
    
    	return oDrawPrimitive(pDevice, PrimitiveType, StartVertex, PrimitiveCount);
    }
    
    HRESULT WINAPI hkBeginScene(LPDIRECT3DDEVICE9 pDevice)
    {
    	static bool init = false;
    	if(!init)
    	{
    		init = true;
    		D3DXCreateFontA(pDevice, 12, 0, FW_NORMAL, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Verdana", &font);
    	}
    
    	if(GetAsyncKeyState(VK_NUMPAD1) & 0x8000)
    	{
    		drawIDs = !drawIDs;
    		while(GetAsyncKeyState(VK_NUMPAD1) & 0x8000)
    			Sleep(25);
    	}
    
    	if(logNextFrame)
    	{
    		logNextFrame = false;
    		logging = true;
    	}
    
    	return oBeginScene(pDevice);
    }
    
    HRESULT WINAPI hkEndScene(LPDIRECT3DDEVICE9 pDevice)
    {
    	logging = false;
    
    	DrawTextF(D3DCOLOR_XRGB(0, 255, 0), 10, 30, "(%f, %f)", mmCoords.x, mmCoords.y);
    
    	return oEndScene(pDevice);
    }
    
    void DrawTextF(D3DCOLOR color, int x, int y, const char *fmt, ...)
    {
    	if(font == NULL)
    		return;
    
    	va_list args;
    	va_start(args, fmt);
    	char buff[512];
    	memset(buff, 0, 512);
    	vsprintf_s(buff, 512, fmt, args);
    	va_end(args);
    
    	RECT rct;
    	SetRect(&rct, x, y - 20, x + 500, y + 20);
    	font->DrawTextA(NULL, buff, -1, &rct, DT_LEFT | DT_VCENTER, color);
    }
    
    void DrawRect(LPDIRECT3DDEVICE9 pDevice, int x, int y, int w, int h, BYTE r, BYTE g, BYTE b)
    {
    	D3DCOLOR RctColor = D3DCOLOR_XRGB(r, g, b);
    	D3DRECT Rct = { x, y, x + w, y + h };
    	pDevice->Clear(1, &Rct, D3DCLEAR_TARGET | D3DCLEAR_TARGET, RctColor, 0, 0);
    }
    
    void* DetourFunc(BYTE *src, const BYTE *dst, const int len)
    {
    	BYTE *jmp = (BYTE*)VirtualAlloc(NULL, len+5, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
    	DWORD dwback, dwback2;
    
    	VirtualProtect(src, len, PAGE_READWRITE, &dwback);
    	VirtualProtect(jmp, len+5, PAGE_READWRITE, &dwback2);
    
    	memcpy(jmp, src, len);	jmp += len;
    
    	jmp[0] = 0xE9;
    	*(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5;
    
    	src[0] = 0xE9;
    	*(DWORD*)(src+1) = (DWORD)(dst - src) - 5;
    
    	VirtualProtect(jmp, len+5, dwback2, &dwback2);
    	VirtualProtect(src, len, dwback, &dwback);
    
    	return (jmp-len);
    }
    
    bool Compare(const BYTE* pData, const BYTE* bMask, const char* szMask)
    {
    	for(; *szMask; ++szMask, ++pData, ++bMask)
    		if(*szMask == 'x' && *pData != *bMask) return 0;
    	return (*szMask) == NULL;
    }
    
    DWORD FindPattern(DWORD dwAddress, DWORD dwLen, BYTE *bMask, char * szMask)
    {
    	for(DWORD i = 0; i < dwLen; i++)
    		if(Compare((BYTE*)(dwAddress + i), bMask, szMask))  return (DWORD)(dwAddress + i);
    	return 0;
    }
    
    void doDisassembleShader(LPDIRECT3DDEVICE9 pDevice, char* FileName)
    {
    	FILE* oLogFile = NULL;
    	fopen_s(&oLogFile, FileName, "w");
    
        if (oLogFile == NULL)
    	{
    		MessageBox(NULL, "Failed to open file", "ERROR", MB_OK);
            return;
    	}
    
        IDirect3DVertexShader9* pShader;
    
        pDevice->GetVertexShader(&pShader);
    
        UINT pSizeOfData;
    
        pShader->GetFunction(NULL, &pSizeOfData);
    
        BYTE* pData = new BYTE[pSizeOfData];
    
        pShader->GetFunction(pData,&pSizeOfData);
    
        LPD3DXBUFFER bOut;
    
        D3DXDisassembleShader(reinterpret_cast<DWORD*>(pData),NULL,NULL,&bOut);
    
    	fprintf(oLogFile, "%s", (LPSTR)bOut->GetBufferPointer());
    
    	fclose(oLogFile);
        delete[] pData;
        pShader->Release();
    
    	MessageBox(NULL, "Made file", "", MB_OK);
    }
    
    void FindRSWindow()
    {
    	EnumWindows(EnumWindowProc, 0);
    	if(hWnd == NULL)
    	{
    		MessageBox(NULL, "Failed to find RS window", "info", MB_OK);
    		ExitProcess(0);
    	}
    }
    
    BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam)
    {
    	RECT rct;
    	GetClientRect(hwnd, &rct);
    	if((rct.right-rct.left) == 765 && (rct.bottom-rct.top) == 503)
    	{
    		hWnd = hwnd;
    		return FALSE;
    	}
    	return TRUE;
    }
    
    BOOL CALLBACK EnumWindowProc(HWND hwnd, LPARAM lParam)
    {
    	EnumChildWindows(hwnd, EnumChildProc, 0);
    	if(hWnd)
    		return FALSE;
    	return TRUE;
    }
    
    void WindowToScreen(HWND hWnd, POINT &wnd, POINT &scrn)
    {
    	WINDOWINFO info;
    	memset(&info, 0, sizeof(info));
    	info.cbSize = sizeof(WINDOWINFO);
    	GetWindowInfo(hWnd, &info);
    
    	scrn.x = info.rcWindow.left + wnd.x;
    	scrn.y = info.rcWindow.top + wnd.y;
    }
    
    /*UINT GetObjectsByID(DWORD ID, POINT *pts, UINT maxPoints, bool sortByDistance, POINT *center)
    {
    	logObjects
    }*/
    Some of the functions are made by some other people like the FindPattern that are used by almost everybody in C++ hacking.

    vTable.h:
    Code:
    enum D3D9_vTable
    {
         QUERYINTERFACE,               //0
         ADDREF,                     //1
         RELEASE,                     //2
         TESTCOOPERATIVELEVEL,          //3
         GETAVAILABLETEXTUREMEM,         //4
         EVICTMANAGEDRESOURCES,         //5
         GETDIRECT3D,                  //6
         GET_DEVICE_CAPS,               //7
         GETDISPLAYMODE,               //8
         GETCREATIONPARAMETERS,         //9
         SETCURSORPROPERTIES,            //10
         SETCURSORPOSITION,            //11
         SHOW_CURSOR,                  //12
         CREATEADDITIONALSWAPCHAIN,      //13
         GETSWAPCHAIN,                  //14
         GETNUMBEROFSWAPCHAINS,         //15
         RESET,                     //16
         PRESENT,                     //17
         GETBACKBUFFER,               //18
         GETRASTERSTATUS,               //19
         SETDIALOGBOXMODE,               //20
         GETGAMMARAMP,                  //21
         SETGAMMARAMP,                  //22
         CREATETEXTURE,               //23
         CREATEVOLUMETEXTURE,            //24
         CREATECUBETEXTURE,            //25
         CREATEVERTEXBUFFER,            //26
         CREATEINDEXBUFFER,            //27
         CREATERENDERTARGET,            //28
         CREATEDEPTHSTENCILSURFACE,      //29
         UPDATESURFACE,               //30
         UPDATETEXTURE,               //31
         GETRENDERTARGETDATA,            //32
         GETFRONTBUFFERDATA,            //33
         STRETCHRECT,                  //34
         COLORFILL,                  //35
         CREATEOFFSCREENPLAINSURFACE,      //36
         SETRENDERTARGET,               //37
         GETRENDERTARGET,               //38
         SETDEPTHSTENCILSURFACE,         //39
         GETDEPTHSTENCILSURFACE,         //40
         BEGINSCENE,                  //41
         ENDSCENE,                     //42
         CLEAR,                     //43
         SETTRANSFORM,                  //44
         GETTRANSFORM,                  //45
         MULTIPLYTRANSFORM,            //46
         SETVIEWPORT,                  //47
         GETVIEWPORT,                  //48
         SETMATERIAL,                  //49
         GETMATERIAL,                  //50
         SETLIGHT,                     //51
         GETLIGHT,                     //52
         LIGHTENABLE,                  //53
         GETLIGHTENABLE,               //54
         SETCLIPPLANE,                  //55
         GETCLIPPLANE,                  //56
         SETRENDERSTATE,               //57
         GETRENDERSTATE,               //58
         CREATESTATEBLOCK,               //59
         BEGINSTATEBLOCK,               //60
         ENDSTATEBLOCK,               //61
         SETCLIPSTATUS,               //62
         GETCLIPSTATUS,               //63
         GETTEXTURE,                  //64
         SETTEXTURE,                  //65
         GETTEXTURESTAGESTATE,            //66
         SETTEXTURESTAGESTATE,            //67
         GETSAMPLERSTATE,               //68
         SETSAMPLERSTATE,               //69
         VALIDATEDEVICE,               // 70
         SET_PALETTE_ENTRIES,            // 71
         GET_PALETTE_ENTRIES,            // 72
         SETCURRENTTEXTUREPALETTE,         // 73
         GETCURRENTTEXTUREPALETTE,         // 74
         SETSCISSORRECT,               // 75
         GETSCISSORRECT,               // 76
         SETSOFTWAREVERTEXPROCESSING,      // 77
         GETSOFTWAREVERTEXPROCESSING,      // 78
         SETNPATCHMODE,               // 79
         GETNPATCHMODE,               // 80
         DRAWPRIMITIVE,               // 81
         DRAWINDEXEDPRIMITIVE,            // 82
         DRAWPRIMITIVEUP,               // 83
         DRAWINDEXEDPRIMITIVEUP,         // 84
         PROCESSVERTICES,               // 85
         CREATEVERTEXDECLARATION,         // 86
         SETVERTEXDECLARATION,            // 87
         GETVERTEXDECLARATION,            // 88
         SETFVF,                     // 89
         GETFVF,                     // 90
         CREATEVERTEXSHADER,            // 91
         SETVERTEXSHADER,               // 92
         GETVERTEXSHADER,               // 93
         SETVERTEXSHADERCONSTANTF,         // 94
         GETVERTEXSHADERCONSTANTF,         // 95
         SETVERTEXSHADERCONSTANTI,         // 96
         GETVERTEXSHADERCONSTANTI,         // 97
         SETVERTEXSHADERCONSTANTB,         // 98
         GETVERTEXSHADERCONSTANTB,         // 99
         SETSTREAMSOURCE,               // 100
         GETSTREAMSOURCE,               // 101
         SETSTREAMSOURCEFREQ,            // 102
         GETSTREAMSOURCEFREQ,            // 103
         SETINDICES,                  // 104
         GETINDICES,                  // 105
         CREATEPIXELSHADER,            // 106
         SETPIXELSHADER,               // 107
         GETPIXELSHADER,               // 108
         SETPIXELSHADERCONSTANTF,          // 109
         GETPIXELSHADERCONSTANTF,         // 110
         SETPIXELSHADERCONSTANTI,         // 111
         GETPIXELSHADERCONSTANTI,         // 112
         SETPIXELSHADERCONSTANTB,         // 113
         GETPIXELSHADERCONSTANTB,         // 114
         DRAWRECTPATCH,               // 115
         DRAWTRIPATCH,                  // 116
         DELETEPATCH,                  // 117
         CREATEQUERY,                  // 118
    };
    I got the vTable enum from some forum long time ago, no idea who is the original creator.

    dxhook_proto.h:
    Code:
    #pragma once
    
    typedef HRESULT(WINAPI *Present_t)(LPDIRECT3DDEVICE9 pDevice, RECT* pSourceRect, RECT* pDestRect, HWND hDestWindowOverride, RGNDATA *pDirtyRegion);
    
    typedef HRESULT(WINAPI *DrawIndexedPrimitive_t)(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE Type, int BaseVertexIndex, UINT MinIndex, UINT NumVertices, UINT StartIndex, UINT PrimitiveCount);
    typedef HRESULT(WINAPI *DrawPrimitive_t)(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount);
    
    typedef HRESULT(WINAPI *BeginScene_t)(LPDIRECT3DDEVICE9 pDevice);
    typedef HRESULT(WINAPI *EndScene_t)(LPDIRECT3DDEVICE9 pDevice);
    Contains just the function porotypes for making pointers to them.

    Create a new project, make the files there and compile as DLL and it should work. I use Visual Studio C++ 2008 express edition but it should compile with other versions too. And you need to have the DirectX sdk to have the include files for it to compile.

    I also included the compiled version in attachments if someone wants to try it. Dont care about the name "packetHook" cause i tried to make it originally to hook runescapes packets sent to server and make a bot that way but didnt really get anywhere with it. To run it, start up runescape with the same settings as you use with simba (i havent tried with other settings) open the graphics options ingame and leave it there. Then start the RS_Injector.exe, it should say "Waiting for java.exe" and right after it "java.exe found bla bla bla...". After that you have 15 seconds time to change the graphics to use DirectX. This system is just cause with Vista and 7 the Start as admin screen makes the runescape client go to safe mode atleast for me so you have time to change it back before it injects.

    After injection you know if it injected succesfully when two green numbers appear in the left upper corner, they are the minimap's current drawings position and rotation, i still have to work out how to get them to screen coordinates.

    Its messy i know but i hope you get something out of it.


    EDIT: Success! I can now get the coords in the minimap image of where your char is currently with 1 pixel tolerance! 1 tile in the ground is more than 1 pixel wide in minimap so it can get the exact tile on where you are standing on. I can also calculate very easily now the screen coordinates of where to click to get to some other spot, regardless of the minimap rotation. I can detect the minimap 'change' when you move out of the current image by the change in the coordinates too.
    Last edited by Mato; 05-26-2012 at 05:15 PM.

Page 2 of 12 FirstFirst 1234 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •