Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Tuners
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. Grand Theft Auto Series

      1. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
    6. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
    7. GTA III

      1. Guides & Strategies
      2. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

      1. GTANet 20th Anniversary
    2. Support

    3. Suggestions

[REL|SRC] SCM and DirectX Hooking Source Code


Spooky
 Share

Recommended Posts

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.justgamers.de/squiddy/mods/dxfont.jpg

 

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

 

At first i modified some parameters on spookie's 'LoadRessources'.

 

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 pixelsfor (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).

 

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.

 

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.

Link to post
Share on other sites

Edit: Okay, so I don't have that problem anymore... tounge.gif Edited by Jack_Knife
Link to post
Share on other sites

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.ru/delphi/download_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.

Link to post
Share on other sites

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.

 

 

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

 

 

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

 

 

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

Link to post
Share on other sites

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]

Link to post
Share on other sites

Not sure if you heard about this place:

http://clootie.narod.ru/delphi/download_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??

Link to post
Share on other sites

Not sure if you heard about this place:

http://clootie.narod.ru/delphi/download_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..

 

Link to post
Share on other sites

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.

Link to post
Share on other sites

 

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

Link to post
Share on other sites

 

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.

 

Link to post
Share on other sites

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.

Edited by Cowpat
Link to post
Share on other sites

 

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?

Link to post
Share on other sites

 

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.

 

 

   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

 

Edited by Cowpat
Link to post
Share on other sites

 

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.

 

 

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

 

Link to post
Share on other sites

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.

Edited by Kryptos
Link to post
Share on other sites

 

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

 

 

Link to post
Share on other sites

  • 2 weeks later...

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...

Edited by _Squiddy_
Link to post
Share on other sites

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.

Link to post
Share on other sites

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

Link to post
Share on other sites

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

Edited by Cowpat
Link to post
Share on other sites

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.

Link to post
Share on other sites

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

 

Link to post
Share on other sites

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

Link to post
Share on other sites

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.justgamers.de/squiddy/mods/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?

Link to post
Share on other sites

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.
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.