Quantcast

Jump to content

» «
Photo

[REL|SRC] SCM and DirectX Hooking Source Code

285 replies to this topic
Kryptos
  • Kryptos

    Hacker

  • Members
  • Joined: 05 Nov 2003

#91

Posted 16 October 2004 - 12:17 AM

It's no problem. Just a suggestion, no need to thank me, you're the one taking full advantage of this great modification.

Squiddy
  • Squiddy

    Back!

  • The Connection
  • Joined: 06 Oct 2004

#92

Posted 16 October 2004 - 04:44 PM

Hi. smile.gif
Another day, another problem. I want to output any text i want, so i started working on this. I want to use the same technique like Spookie did with his digitmap.

http://gtareactor.ju...mods/dxfont.jpg

That is my font bitmap i made using 'Bitmap Font Builder'.

At first i modified some parameters on spookie's 'LoadRessources'.
CODE
void LoadResources()
{
BITMAPINFO bmi;  // Standard BITMAPINFO setup, see Win32 SDK dox.
bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;  // Notice 32bit!
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = 0;
bmi.bmiHeader.biXPelsPerMeter = 0;
bmi.bmiHeader.biYPelsPerMeter = 0;
bmi.bmiHeader.biClrUsed = 0;
bmi.bmiHeader.biClrImportant = 0;
HDC hDC = GetDC(0);

bmi.bmiHeader.biWidth = 512;   // Width of font textmap.
bmi.bmiHeader.biHeight = -256;   // Height of font textmap.
pFontMap = (DWORD*)malloc(524288);  // Allocate: 512(w) * 256(h) * 4(bpp) bytes.
HBITMAP Bitmap = LoadBitmap(hInst, "FONT");     // Load the actual resource.
GetDIBits(hDC, Bitmap, 0, 256, pFontMap, &bmi, DIB_RGB_COLORS); // Extract the raw image data.

BYTE* pOpaquer = (BYTE*)pFontMap+3; // The following little loop just makes all the pixels
for (int i=0; i<131072; i++)   // in the raw image data buffer opaque, they come back
{          // as 0x00 (fully transparent) by default as the actual
 *pOpaquer = 0xFF;     // bitmap I made in photoshop is 24bit.
 pOpaquer += 4;
}

DeleteObject(Bitmap);     // Keep britain tidy!
}
My bitmap is 512x256 pixel, i only adjust these values, because the other code should be working independent from what bitmap i use, or am i wrong?

Now i wrote a function similar to 'DrawDigit', with the only difference that the parameter dwDigit is now dwCode (ascii).
CODE
void DrawCharacter(DWORD* pTexData, DWORD PixWidth, int x, int y, DWORD dwCode)
{
DWORD* pFontBuf = pFontMap; // We don't wanna screw with the real pointer.
pFontBuf += ((dwCode-32) * 32); // Move pointer to top-left pixel of the character.

pTexData += (y * PixWidth) + x; // Set pointer to the right pixel of the texture.

for (y = 0; y < 32; y++)  // The charaters are 32 pixels high.
{
 memcpy(pTexData, pFontBuf, 128); // Copy a row of pixels. The characters are 32 pixels wide, * 4bpp.
 pFontBuf += 512;     // Skip to the next row of character data.
 pTexData += PixWidth;    // Skip to next row of texture data.
}

}
The digits are 32x32 px in size.

I'm using pCustomTex as my background texture. In custom render i write on this texture like Spookie did.
CODE
D3DSURFACE_DESC Desc;
  pCustomTex->GetLevelDesc(0, &Desc);    // Get the primary texture level description.
  if (Desc.Format == D3DFMT_A8R8G8B8)    // This should always be true, but blah.
  {
   D3DLOCKED_RECT Rect;
   pCustomTex->LockRect(0, &Rect, NULL, 0); // Lock the texture. Error checking here maybe? :s

   DWORD* pTexData = (DWORD*)Rect.pBits;  // Pointer to the raw texture data.
   int PixRow = Rect.Pitch / 4;    // Pitch of the texture in pixels.
   
   DrawCharacter(pTexData, PixRow, 10, 10, 33); // !
   
   pCustomTex->UnlockRect(0);     // Unlock the texture.
  }
 
  pCustomSprite->Begin(); // This sets up render states and stuff. See the SDK dox.
  pCustomSprite->Draw(pCustomTex, NULL, &vScaling, NULL, 0.0f, &vTranslation, 0xFFFFFFFF);
  pCustomSprite->End(); // Cleanup. Reset render states etc. See SDK dox.



But when i get ingame, i see the black background texture, but the characters are completely white, a white rectangle maybe 32x32px in size. I don't find the mistake, maybe i'm coping the wrong data?!

I'm sorry for this huge post.

Jack_Knife
  • Jack_Knife

    we usually take all niggas garments

  • Leone Family Mafia
  • Joined: 08 Dec 2001

#93

Posted 18 October 2004 - 03:04 AM Edited by Jack_Knife, 18 October 2004 - 03:19 AM.

Edit: Okay, so I don't have that problem anymore... tounge.gif

Kraxxuz
  • Kraxxuz

    Li'l G Loc

  • Members
  • Joined: 19 Jun 2004

#94

Posted 18 October 2004 - 10:05 PM

great work guys Thanx for making a great mod and for the KMPH i needed that u ROCK!!!!! rah.gif

Hammer83
  • Hammer83

    Hustler

  • Members
  • Joined: 11 Jan 2003

#95

Posted 19 October 2004 - 02:29 AM

QUOTE (ST.MU @ Oct 15 2004, 19:08)
I was talking about translating the scm hook, not the whole DirectX stuff, since there's no real SDK for Delphi. Haven't started on that yet, though.

Good work, Squiddy!

Not sure if you heard about this place:
http://clootie.narod...nload_dx90.html

I myself use Erik Unger's converted headers, but mostly because I discovered this page much later. I didn't check this page deeply tough, because the server can be SLOW at times.

Squiddy
  • Squiddy

    Back!

  • The Connection
  • Joined: 06 Oct 2004

#96

Posted 19 October 2004 - 02:04 PM

Hi

Just another problem. smile.gif
I want to use different textures in the game, but dependable on a boolean, one time it should draw the digits on the first, and another time on the second texture.
So i tried using a pointer to a directx texture.

CODE
IDirect3DTexture8* pSpeedoTex;  
IDirect3DTexture8* pSpeedoTex2;
IDirect3DTexture8* *pCurrentSpeedoTex;


Now i want to use that pointer when it draws the digits on the texture.

CODE
D3DSURFACE_DESC Desc;
*pCurrentSpeedoTex->GetLevelDesc(0, &Desc);
...
D3DLOCKED_RECT Rect;
*pCurrentSpeedoTex->LockRect(0, &Rect, NULL, 0);
...
*pCurrentSpeedoTex->UnlockRect(0);

These 3 lines create a error (for example line 1): error C2227: left of '->GetLevelDesc' must point to class/struct/union

How can i use a pointer on these methods? I don't want to copy the whole procedure for both textures.

Thanks in advance
Squiddy

Spooky
  • Spooky

    Prince of the Yolkfolk

  • Members
  • Joined: 13 Jan 2002

#97

Posted 19 October 2004 - 02:13 PM

Remove the * before the calls, even though it is a pointer, using the -> operator on it still calls the function correctly.

[EDIT: ...and pCurrentSpeedoTex doesn't need to be a pointer to a pointer]

steve-m
  • steve-m

  • Members
  • Joined: 26 Jul 2002

#98

Posted 19 October 2004 - 03:37 PM

QUOTE (Hammer83 @ Oct 19 2004, 04:29)
Not sure if you heard about this place:
http://clootie.narod...nload_dx90.html

I myself use Erik Unger's converted headers, but mostly because I discovered this page much later. I didn't check this page deeply tough, because the server can be SLOW at times.

No, I was using the Jedi headers for CollEditor, but then switched to OpenGL for other tools.
Aren't there any D3D headers for Delphi that don't need an additional dll to run??

JernejL
  • JernejL

    Big Homie

  • Members
  • Joined: 11 Mar 2002

#99

Posted 19 October 2004 - 07:27 PM

QUOTE (ST.MU @ Oct 19 2004, 16:37)
QUOTE (Hammer83 @ Oct 19 2004, 04:29)
Not sure if you heard about this place:
http://clootie.narod...nload_dx90.html

I myself use Erik Unger's converted headers, but mostly because I discovered this page much later. I didn't check this page deeply tough, because the server can be SLOW at times.

No, I was using the Jedi headers for CollEditor, but then switched to OpenGL for other tools.
Aren't there any D3D headers for Delphi that don't need an additional dll to run??

there are, delphix uses its own nicely translated headers, but they are directx 7 i think..

one less than needed..

steve-m
  • steve-m

  • Members
  • Joined: 26 Jul 2002

#100

Posted 19 October 2004 - 09:42 PM

QUOTE (Delfi @ Oct 19 2004, 21:27)
there are, delphix uses its own nicely translated headers, but they are directx 7 i think..

one less than needed..

Yea, I was using that years ago, but IIRC it was only suitable for sprites, since the 3D stuff wasn't very optimized, if I'm not mistaken.

Cowpat
  • Cowpat

    web schmeb

  • Members
  • Joined: 12 Feb 2004

#101

Posted 23 October 2004 - 07:24 PM


I am calling Kryptos' ViceHook() function from within Spookie's speedo dll code but can't get the call to FindWindow("GTA: Vice City", "GTA:VC") to work.

Is calling FindWindow in a dll the same as calling it in an exe?

thanks

JernejL
  • JernejL

    Big Homie

  • Members
  • Joined: 11 Mar 2002

#102

Posted 23 October 2004 - 08:28 PM

QUOTE (Cowpat @ Oct 23 2004, 20:24)
I am calling Kryptos' ViceHook() function from within Spookie's speedo dll code but can't get the call to FindWindow("GTA: Vice City", "GTA:VC") to work.

Is calling FindWindow in a dll the same as calling it in an exe?

thanks

yes it is same, but you need to search for

FindWindow("GTA: Vice City", "Grand theft auto 3")

because gta-vc window class is 'Grand theft auto 3'

hey, why are you aniway getting access to the gta-vc.exe because your dll is IN the
process and doesn't need any more permissions to access own memory..

see idle's vcdbg source for an example.

Cowpat
  • Cowpat

    web schmeb

  • Members
  • Joined: 12 Feb 2004

#103

Posted 23 October 2004 - 09:49 PM Edited by Cowpat, 23 October 2004 - 10:01 PM.

Thanks Delfi.

So I can use Read and WriteProcess memory without getting a handle to gta-vc?

The reason I want to access memory, in the first case, is because I couldn't get the opcode create_player or create_actor to create an object using the player coordinates properly, at least not for on the first spawn. They spawned quite away away. I traced it to get_player_coords not picking up the Y value, ie.

ScriptCommand(&get_player_coords, PLAYER_CHAR, &fX, &fY, &fZ);
user posted image
ScriptCommand(&get_car_coords, &dwPlayerCar, &fX, &fY, &fZ);
user posted image

Apologies to Spookie, I'll make a different background soon as.

Squiddy
  • Squiddy

    Back!

  • The Connection
  • Joined: 06 Oct 2004

#104

Posted 23 October 2004 - 10:04 PM

QUOTE (Cowpat @ Oct 23 2004, 21:49)
So I can use Read and WriteProcess memory without getting a handle to gta-vc?

Yes, just see the section where Spookie reads the actual gear from memory.

But i don't understand why the opcode should't work. blink.gif
For the texture, did you try CreateTexture? Because then you only have to make another position vector and translate it to the left top corner for example.

Edit: I forgot, is the drawdigit procedure working using the other code i send you?

Cowpat
  • Cowpat

    web schmeb

  • Members
  • Joined: 12 Feb 2004

#105

Posted 23 October 2004 - 10:16 PM Edited by Cowpat, 23 October 2004 - 10:23 PM.

QUOTE (_Squiddy_ @ Oct 23 2004, 22:04)
QUOTE (Cowpat @ Oct 23 2004, 21:49)
So I can use Read and WriteProcess memory without getting a handle to gta-vc?

Yes, just see the section where Spookie reads the actual gear from memory.

But i don't understand why the opcode should't work. blink.gif
For the texture, did you try CreateTexture? Because then you only have to make another position vector and translate it to the left top corner for example.

Edit: I forgot, is the drawdigit procedure working using the other code i send you?


I confess, I'm still using my old if/else statements (with a little bit before to take care of ascii values of 32 or below), I promise to implement your code soonest wink.gif

Strange get_player_coords not picking up the Y value. I have tried many things, including swapping the X and Y values, and they simply swapped.

CODE

   FloatToString( coordStr, fX, STR_SIZE);    
   for(i = 0; i < STR_SIZE; i++)
   DrawDigit(pTexData, PixRow, i*32, 10, (DWORD)coordStr[i]); // Draw X value
   DrawDigit(pTexData, PixRow, i*32, 10, (DWORD)'X'); // Draw X Marker on end

   FloatToString( coordStr, fY, STR_SIZE);    
   for(i = 0; i < STR_SIZE; i++)
   DrawDigit(pTexData, PixRow, i*32, 42, (DWORD)coordStr[i]); // Draw Y value
   DrawDigit(pTexData, PixRow, i*32, 42, (DWORD)'Y'); // Draw Y Marker on end

   FloatToString( coordStr, fZ, STR_SIZE);    
   for(i = 0; i < STR_SIZE; i++)
   DrawDigit(pTexData, PixRow, i*32, 74, (DWORD)coordStr[i]); // Draw Z value
   DrawDigit(pTexData, PixRow, i*32, 74, (DWORD)'Z'); // Draw Z Marker on end

Hammer83
  • Hammer83

    Hustler

  • Members
  • Joined: 11 Jan 2003

#106

Posted 24 October 2004 - 03:29 AM

QUOTE (Cowpat @ Oct 23 2004, 15:24)
I am calling Kryptos' ViceHook() function from within Spookie's speedo dll code but can't get the call to FindWindow("GTA: Vice City", "GTA:VC") to work.

Is calling FindWindow in a dll the same as calling it in an exe?

thanks

I don't like FindWindow method personally, especially since you have the opportunity to avoid it because you are in process memory by using attaching dll.

For instance, your window finding method won't work with GTA: LC because we change window caption. The APIs below seem to work well but don't depend on window caption.

Sorry, it's Delphi syntax, but same thing applies for C++. They are Windows API.

CODE

function GetHwnd: HWND;
var
 GUIInfo: TGUIThreadInfo;
begin
 Result = 0;
 GUIInfo.cbSize := SizeOf(GUIInfo);
 if GetGUIThreadInfo(0, GUIInfo) then
   Result := GUIInfo.hwndActive;
end;

Kryptos
  • Kryptos

    Hacker

  • Members
  • Joined: 05 Nov 2003

#107

Posted 24 October 2004 - 05:15 AM Edited by Kryptos, 24 October 2004 - 05:20 AM.

Sorry about my error in the other topic about the class, Delfi is of course correct, the original purpose of that hook was for GTA3, and I quickly modified it without checking to ensure it worked under Vice.

Everyone is also correct about reading and writing using this modification, there's no real purpose in using a hook since the DLL is loaded into the executable at runtime, thus you have immediate access and it's pointless to run through an arbitrary routine of exiting the process only to re-hook it for purposes that can be just as easily accomplished from the confines of the DLL. I merely posted the hook routine for the purpose of showing the inquiring member how the basic structure of a hook, a simplistic one at that, works. There are of course numerous ways to hook a program, some of which have yet to be exploited.

Cowpat
  • Cowpat

    web schmeb

  • Members
  • Joined: 12 Feb 2004

#108

Posted 24 October 2004 - 05:24 PM


Thanks guys, due to your help I've now got it all sorted. Squiddy, I now don't
need to read player position using opcodes and can now spawn actors beside the player as well as get the missing Y coord value.

Kryptos, sorry about that. Because I'd done a simple loader program for Vice, I thought I had to do roughly the same thing to access memory in this case. Now I see how simple it is to access it.

So here's a little pic to end the drama.

user posted image


Squiddy
  • Squiddy

    Back!

  • The Connection
  • Joined: 06 Oct 2004

#109

Posted 02 November 2004 - 03:09 PM Edited by _Squiddy_, 02 November 2004 - 03:23 PM.

Hi, got lot of work in the last time so i had no time to continue on anything related to this. I'm working on a little function that outputs text, i wanted to know how i could write directly onto the screen without using a sprite and texture. I think that is possible, can someone tell me how please? smile.gif

Edit: I thaught Spookie didn't used a texture for the console of projectx, but i read that it was so. So my post might be useless...

Kryptos
  • Kryptos

    Hacker

  • Members
  • Joined: 05 Nov 2003

#110

Posted 03 November 2004 - 12:23 AM

It's possible to write directly to the screen buffer (or so I've heard) which displays text. This is the same technique that DracoBlue uses I believe, but it's ill-advised since it causes some major issues. Frankly, the method that Spooky has implemented is much cleaner, and once its been implemented it's much simpler.

holdenrulz
  • holdenrulz

    Trick

  • Members
  • Joined: 24 Jan 2004

#111

Posted 03 November 2004 - 07:45 AM

If it's possible using directx could you use other key other then the set vice keys

eg if F12 isn't used at all ingame using a function to when that key is pressed a scm call is implemented

If you can't do this please accept my apology for wasting your time

Cowpat
  • Cowpat

    web schmeb

  • Members
  • Joined: 12 Feb 2004

#112

Posted 03 November 2004 - 12:23 PM Edited by Cowpat, 03 November 2004 - 01:55 PM.

I think I'd be easiest done by a loader program like Spooshdemo, obtaining a keyboard hook (if necessary), filtering the keystrokes, and passing on somehow those commands which were meant for Vice.

Here's stuff I was looking at for this here or even better here

Squiddy
  • Squiddy

    Back!

  • The Connection
  • Joined: 06 Oct 2004

#113

Posted 03 November 2004 - 04:28 PM

For the keys, can't we just hook the directinput interface, if vice city uses one ?
I think it does.

Cowpat
  • Cowpat

    web schmeb

  • Members
  • Joined: 12 Feb 2004

#114

Posted 03 November 2004 - 07:26 PM

QUOTE (_Squiddy_ @ Nov 3 2004, 16:28)
For the keys, can't we just hook the directinput interface, if vice city uses one ?
I think it does.


You go first biggrin.gif

Kryptos
  • Kryptos

    Hacker

  • Members
  • Joined: 05 Nov 2003

#115

Posted 03 November 2004 - 11:03 PM

Yes _Squiddy_, you can hook the DirectInput device to obtain keystrokes. You can hook just about anything as long as you know what you're doing, although some things are much more difficult to gain control over then others. Cowpat's method will also efficiently work, although it's not required to create multiple external applications for something that can be just as easily (or not) accomplished through the DLL hook. Either way, it's all based on the programmer's preference in the long run.

JernejL
  • JernejL

    Big Homie

  • Members
  • Joined: 11 Mar 2002

#116

Posted 04 November 2004 - 12:01 AM

QUOTE (Cowpat @ Nov 3 2004, 20:26)
QUOTE (_Squiddy_ @ Nov 3 2004, 16:28)
For the keys, can't we just hook the directinput interface, if vice city uses one ?
I think it does.


You go first biggrin.gif

LOL!!

or use my method as used in developer console: windows system wide keyboard hook tounge.gif

Cowpat
  • Cowpat

    web schmeb

  • Members
  • Joined: 12 Feb 2004

#117

Posted 04 November 2004 - 10:43 AM

QUOTE (Delfi @ Nov 4 2004, 00:01)
or use my method as used in developer console: windows system wide keyboard hook tounge.gif

Yeah, I read about the system-wide hook. I'll have another look at it. The problem is that I like to study these things whilst at work, because I don't study well at home. But I am very busy at work at the moment. Guess I'll wait until the boss is talking to his secretary lol.gif

Squiddy
  • Squiddy

    Back!

  • The Connection
  • Joined: 06 Oct 2004

#118

Posted 04 November 2004 - 07:15 PM

Hm.. i think i'll have a look at these different solutions. I just don't have an idea how to hook directinput, but maybe i find something useful somewhere. biggrin.gif
Kryptos, you don't have to write my nick completely, just squiddy. I think someone else allready took squiddy. tounge.gif

Currently i'm working on a little addon for vc to control winamp. Some time ago, when i had my first experiences in memory manipulating i tried to find a way to control the radiostations, especially the mp3 feature, with no success.
Now i think, it could be useful to control winamp ingame from vice city, because most of the time i'm running winamp in the background while playing vice city.

For now, i have a ticker that shows the actual title winamp is playing. Nothing that special, but a beginning.

http://gtareactor.ju...wamp/vcwmp2.jpg

There is a little bug, i don't know why it displays the first three characters, because they don't have to be there. I hope i can fix this later.

Do you think somebody could be interested in this?

GTA3Freak-2001
  • GTA3Freak-2001

    Run out of Cake.

  • Members
  • Joined: 25 Nov 2001

#119

Posted 05 November 2004 - 08:47 AM

Yeah I could see that as being useful to me since I like listening to my own music but not in the alphabetical order Vice City chooses.

Spooky
  • Spooky

    Prince of the Yolkfolk

  • Members
  • Joined: 13 Jan 2002

#120

Posted 05 November 2004 - 02:42 PM

I used a windows hook for console input the other project. I've copied the code out for squiddy when he asked on IRC, but here it is if anyone else is interested... http://spookie.power...uk/KeybHook.txt





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users