Quantcast

Jump to content

» «
Photo

Tutorial for spookie's SCM hook (C++)

37 replies to this topic
XcR
  • XcR

    Peon

  • Members
  • Joined: 28 Mar 2005

#1

Posted 07 March 2006 - 03:02 PM Edited by XcR, 08 March 2006 - 06:35 PM.

-- Tutorial on spookie's SCM/D3D hook for Vice City --

Okay well.. this is my first tutorial, it's just a basic guide into modding Vice City with spookie's SCM hook. It's how I started coding and I'm very pleased that I got into it all and decided to pass on the stuff that I've learned.

Firstly, there are some basic requirements.

-> A C++ compiler - For this tutorial we'll be using Microsoft Visual C++ version 6.0
-> Basic knowledge of C++
-> The DirectX 8 SDK
-> A copy of Vice City

The first thing you need to do is install the DirectX 8 SDK. It is around 200mb and is downloadable from this site. This has all the required library and header files that you will need to compile your project. The install is pretty self-explanatory, just write down the path you installed it in as you'll need that later on when setting additional header and library directories in MSVC++.

Now, once you have the DirectX, load up MSVC++6. You'll be faced with a blank screen that looks something like this:

user posted image

The bottom window is the build view, where you will see the compiler building each file and this is where you will see any warnings or errors that it may have encountered while building your project. The left hand side is the active project file tree window - here you will see all the files that are in the project you have opened. It's quite easy to get the hang of the compiler although you may want to customise the interface so it is easier for you to develop and find things quickly. Now, you'll need to set up your compiler to use the DirectX libraries and headers. Click the 'Tools' button on the menu, then click the 'Options' button. You will be faced with a dialog window showing all the compiler and project options, but all you need to do for now is set up the SDK paths. Click the 'Directories' tab in the options menu and you will be faced with this window:

user posted image

Okay now, make sure 'Win32' and 'Include files' are selected in the drop down boxes. Remember the path you had for the SDK? This is where we need it. Click the box with the star in the top left, and enter your DirectX8 directory, followed by '\Include'. It will look something like this:

user posted image

Right, that's the includes set up. Now, we have to go to the library directories. Change the drop-down selection box item from 'Include files' to 'Library files'. Follow the same procedure as you did when adding the include directory, but change the '\Include' to '\Lib\x86'. If your processor is 64bit, it would be '\Lib\x64'. It will look something like this:

user posted image

Well.. that's that set up! Now we can move on to the actual coding and testing. To get started, we'll need the SCM/D3D hook base files from spookie's website which you can visit here. The link to the actual download is here. Download the project and unzip it. The project was written in MSVC++ version 7 so it is not backwards compatible - we will have to create a new project and manually add the files. Click the 'File' menu option and then click 'New'. You will be faced with a dialog that has lots of different project types in it, the one we will be using is 'Win32 Dynamic Link Library'. Set up an appropriate directory for your project. It should look something like this after you have finished:

user posted image

After you have selected the correct options, hit 'OK' and you will be faced with this dialog:

user posted image

Select 'An empty DLL project' and click finish. In the next box that you see, click OK. Now, you will be back in the main compiler window. Click the 'FileView' tab at the bottom of the File Tree window and then click the plus sign beside your project name. You will then see three folders, 'Source Files', 'Header Files' and 'Resource Files'.

user posted image

Now we can begin adding our files to the project. Remember the source files we downloaded earlier? Unrar them to your project directory (C:\VC SCM Hook\ for me). Once you have done that, your directory should look something like this:

user posted image

Go back into the compiler window and right click on the 'Source Files' directory in the file tree. Select the menu option 'Add files to folder...'. Type '*.cpp' in the box that appears and hit enter, this only shows us the C++ source files. Select the source files that appear and click 'Add'.

user posted image

You should now be back in the main compiler window. If you click the plus icon beside 'Source Files', you will see all the source files that your project has. Right click the 'Header Files' folder and select 'Add files to folder...'. You will be presented with the same dialog that you seen when adding source files, this time type '*.h' in the edit box and hit enter. Add all the header files that come up, the way you did with the source files. After adding them and clicking ok, you have one more thing to add. Select the Resource folder and right click it, select the Add files to folder option. This time, select 'All Files' in the 'Files of type' combination box and type look for the files 'Speedo.def' and 'Speedo.rc'. After selecting them, your dialog will look like so:

user posted image

XcR
  • XcR

    Peon

  • Members
  • Joined: 28 Mar 2005

#2

Posted 07 March 2006 - 03:11 PM Edited by XcR, 08 March 2006 - 06:45 PM.

Click OK and you are nearly ready to get started! First of all, we just need our project set up to use one library file so it can access the DirectX functions. Click 'Project' and then 'Settings' and then the 'Link' tab. The library we need to add is called 'd3dx8.lib'. Add it to the end of the 'Object/Library modules' edit box so it looks like this:

user posted image

One more thing we have to change before building our project. Click 'Project' and then 'Settings' on the menu bar and select the Link tab. On the left, select the drop-down box saying 'Win32 Debug' and change it to 'All configurations'. Change the 'Output file name' edit box text to your Vice City directory + \d3d8.dll. If my Vice City directory was C:\Program Files\Rockstar Games\Grand Theft Auto Vice City, the path would look like this:

user posted image

Now, we are finally ready to build it and test if it works. Click 'Build' on the menu and then 'Rebuild all'. If all went well, the Build window should look like this:

CODE
Deleting intermediate files and output files for project 'VC SCM Hook - Win32 Debug'.
--------------------Configuration: VC SCM Hook - Win32 Debug--------------------
Compiling resources...
Compiling...
Custom.cpp
GameScripting.cpp
IDirect3D8Hook.cpp
IDirect3DDevice8Hook.cpp
Speedo.cpp
Linking...
  Creating library Debug/d3d8.lib and object Debug/d3d8.exp

d3d8.dll - 0 error(s), 0 warning(s)


This means that our DLL was compiled and created successfully. Now, we will begin adding our own code. Custom.cpp is where it all happens, so let's start from there. Double click the Custom.cpp file in your Source files directory on the left hand side. We don't really need to worry about all the variables defined in the top of this file so let's move down a bit. We need to comment out a line first of all, press CTRL+G and type in 193 and click Go to. To comment out the line, simply put '//' before it. When you have done that, it'll look like this:

CODE
// ReadConfig();


This just comments out the reading of the config file so we won't need to have the config file in our directory. You could leave it uncommented if you wanted to change the speedo settings, or you could just hardcode them, it's up to you. I prefer commenting this as the default settings are fine for me and if I wanted to show anyone what I've done I would only have to send the DLL.

Scroll down to the CustomRender function. This is called every game frame, so it is ideal for checking key presses and whatever else we may want to do. This is where we shall start off. The code you see in CustomRender draws the Speedo on our screen, it is possible to remove the Speedo by simply removing this code, so we are left with just the barebones of the CustomRender function. If you want to remove the speedo, select the code between the brackets of the function and delete it, so your code will look like this:

CODE
void CustomRender(IDirect3DDevice8* pDevice)
{

}


This leaves us with an empty function that gets called every game frame (IDirect3DDevice8Hook::Present). We need to add a basic check now to see if the player is not in the menu but they are created - a way to check if they are in game. First of all we need to define the pointer to the player. The Vice City player pointer is found at the address 0x94AD28. We can define this locally as we will not be using this in any other functions. To add the player pointer variable, we add the following to the top of CustomRender:

CODE
DWORD* dwPlrPointer  = (DWORD*)0x94AD28;


So our CustomRender function should look like this:

CODE
void CustomRender(IDirect3DDevice8* pDevice)
{
DWORD* dwPlrPointer  = (DWORD*)0x94AD28;

}


We can now add the if statement to check if the player is not in the menu and if they are created or not.

CODE
void CustomRender(IDirect3DDevice8* pDevice)
{
DWORD* dwPlrPointer  = (DWORD*)0x94AD28;
if ((*dwPlrPointer) && (!*bInMenu))
{
 // begin code here
}

}


So, that's our main function created that will be called every frame. From here on in it's pretty easy to control stuff on a game level, you can alter the weather, game time, create peds, set car speed, etc. Well, the first thing we will make is an insta-brake and a nos function. These are both very simple things to make and can be done with a few lines of code. There are a lot of opcodes defined already in the GameScripting.h header file, but I have one with lots more added. You can find this file here. To use it simply close your project (after saving all the work you have done), delete the GameScripting.h file in your project directory and replace it with this one.

If we want to make an instant-brake and a nos function, our code has to be triggered by some event. For this tutorial we'll use keypresses. When a certain key is pressed, our code will be triggered. It's pretty easy to check for keypresses, you need a constant loop (In this case our CustomRender function) and a conditional statement. If we wanted to check to see if F5 was pressed, our code would look like this:

CODE
void CustomRender(IDirect3DDevice8* pDevice)
{
DWORD* dwPlrPointer  = (DWORD*)0x94AD28;
if ((*dwPlrPointer) && (!*bInMenu))
{
 if (GetAsyncKeyState(VK_F5)&1)
 {
  // this is triggered when F5 is pressed
 }
}
}


GetAsyncKeyState is a Windows function - its documentation is located here and a full list of virtual key codes that you can check for is located here.

Now that we have our keypress check set up, we can begin to code our nos function. It will be triggered with the F5 key. There are a lot of opcodes that we can use, you can find these in the GameScripting.h file you downloaded. We need a check to see if the player is in a car first of all, if we were to set the car speed without there being a person in the car the game would crash. There is a conditional opcode 'player_in_car' that returns false if the player is not in a car and true if they are. Its usage is as follows:

CODE
if (ScriptCommand(&player_in_car, PLAYER_CHAR))


This checks if the player is in a car. ScriptCommand is our interface between the code and the game. It calls SCM opcodes just as if they were programmed in main.scm, but players do not have to start a new game to see the effects (unlike modifying main.scm). ScriptCommand is pretty easy to grasp, the harder parts are knowing all of the parameters of each opcode. I've tried my best to comment each one in GameScripting.h but there are some that have no comments. You can check the full list of GTA3/Vice City opcodes here.

After we have set up the check in our code, we need to code the actual nos part. For our nos we will simply edit the car speed so it gives the effect of a 'speed boost'. Before we actually code a line to alter the speed, we have to get the CarID (a handle for us to refrence it by). The opcode we can use for that is 'get_player_car' - it stores the current player's car ID in a DWORD. To get the car id we need to define a DWORD then call ScriptCommand with the get_player_car opcode to get the id. Our code will look like this:

CODE

if (GetAsyncKeyState(VK_F5)&1)
{
if (ScriptCommand(&player_in_car, PLAYER_CHAR))
{
 DWORD dwCurrentCar; // this creates a DWORD to store our current car.
 ScriptCommand(&get_player_car, PLAYER_CHAR, &dwCurrentCar); // PLAYER_CHAR = the player.
}
}


Well, now we have a function that gets the ID of the car the player is in - nothing special.. yet! We will now code the actual setting of the speed, there is an opcode 'set_car_speed_instantly' that sets the car speed instantly.. funnily enough tounge.gif . The parameters are our car id and the speed of the car as a float.

We can add this to our code and it'd look like so:

CODE

if (GetAsyncKeyState(VK_F5)&1)
{
if (ScriptCommand(&player_in_car, PLAYER_CHAR))
{
 DWORD dwCurrentCar = 0; // this creates a DWORD to store our current car.
 ScriptCommand(&get_player_car, PLAYER_CHAR, &dwCurrentCar); // PLAYER_CHAR = the player.
 ScriptCommand(&set_car_speed, &dwCurrentCar, 55.0);
}
}


And there you have it! A nos type mod in 3 lines. Easy, huh? So.. our CustomRender function should look like this:

CODE
void CustomRender(IDirect3DDevice8* pDevice)
{
DWORD* dwPlrPointer  = (DWORD*)0x94AD28;
if ((*dwPlrPointer) && (!*bInMenu))
{
 if (GetAsyncKeyState(VK_F5)&1)
 {
  if (ScriptCommand(&player_in_car, PLAYER_CHAR))
  {
   DWORD dwCurrentCar = 0; // this creates a DWORD to store our current car.
   ScriptCommand(&get_player_car, PLAYER_CHAR, &dwCurrentCar); // PLAYER_CHAR = the player.
   ScriptCommand(&set_car_speed, &dwCurrentCar, 55.0);
  }
 }
}
}


This is a good time to go in game and test it. There are lots of possibilities for example, if you weren't in a car you could create one beside you and put the player in it smile.gif Lots and lots of things to do, you just have to be creative!

Alright.. lets code the insta-brake function. This is pretty much exactly the same.. except you have to change 2 things. The keypress to check for and the car speed. Instant brake is good for getting out of situations with the cops i.e driving at a wall full speed then putting on the brake and watching them slam into it tounge.gif

We will change the keycode for the instant brake to F6 as we can't have the nos on the same keypress as it. We also need to change the speed to 0.0 (which is stopped).

CODE
void CustomRender(IDirect3DDevice8* pDevice)
{
DWORD* dwPlrPointer  = (DWORD*)0x94AD28;
if ((*dwPlrPointer) && (!*bInMenu))
{
 if (GetAsyncKeyState(VK_F5)&1)
 {
  if (ScriptCommand(&player_in_car, PLAYER_CHAR))
  {
   DWORD dwCurrentCar = 0; // this creates a DWORD to store our current car.
   ScriptCommand(&get_player_car, PLAYER_CHAR, &dwCurrentCar); // PLAYER_CHAR = the player.
   ScriptCommand(&set_car_speed, &dwCurrentCar, 55.0);
  }
 }
 if (GetAsyncKeyState(VK_F6)&1)
 {
  if (ScriptCommand(&player_in_car, PLAYER_CHAR))
  {
   DWORD dwCurrentCar = 0; // this creates a DWORD to store our current car.
   ScriptCommand(&get_player_car, PLAYER_CHAR, &dwCurrentCar); // PLAYER_CHAR = the player.
   ScriptCommand(&set_car_speed, &dwCurrentCar, 0.0);
  }
 }
}
}


As you can see I've combined the two checks together.. you could have a check for every single key on the keyboard if you wanted. It's also very easy to make missions and such with this, the possibilites really are endless. Just have a look through the opcode list and see what you can do wink.gif

XcR
  • XcR

    Peon

  • Members
  • Joined: 28 Mar 2005

#3

Posted 07 March 2006 - 03:11 PM Edited by XcR, 07 March 2006 - 09:58 PM.

Some DirectX stuff

Right.. now that we've covered a basic aspect of mission coding in C++, I'll show you how to draw some text on the screen. This can come in handy for missions so I thought I'd add this.

First of all, we need to define some things that are needed to draw the font. Put the following code at the top of Custom.cpp:

CODE
LOGFONT LogFont = {13,0,0,0,FW_NORMAL,false,false,false,DEFAULT_CHARSET,OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,PROOF_QUALITY,DEFAULT_PITCH,"Tahoma"};
LPD3DXFONT g_Font = NULL;  // font object
RECT FontPosition;


This creates the font structure that contains the attributes of our font. the first parameter is 13 which is the size of the font and the last parameter is the font name. After you have added it, it should look like this:

user posted image

Next thing we need to do is add a few more lines to CustomInitialize.

CODE
D3DXCreateFontIndirect(pDevice,&LogFont,&g_Font);
FontPosition.top = 10;
FontPosition.left = 10;
FontPosition.right = (long)(fScreenWidth);
FontPosition.bottom = (long)(fScreenHeight);


This goes directly below the PLAYER_ACTOR definition. Now finally, to create some text, we need to add one line to our CustomRender function.

CODE
void CustomRender(IDirect3DDevice8* pDevice)
{
DWORD* dwPlrPointer  = (DWORD*)0x94AD28;
if ((*dwPlrPointer) && (!*bInMenu))
{
 g_Font->DrawText("DirectX tutorial by XcR",-1,&FontPosition,DT_LEFT,0xFFFFFFFF); // draws the first parameter as a string at position 10, 10
 if (GetAsyncKeyState(VK_F5)&1)
 {
  if (ScriptCommand(&player_in_car, PLAYER_CHAR))
  {
   DWORD dwCurrentCar = 0; // this creates a DWORD to store our current car.
   ScriptCommand(&get_player_car, PLAYER_CHAR, &dwCurrentCar); // PLAYER_CHAR = the player.
   ScriptCommand(&set_car_speed, &dwCurrentCar, 55.0);
  }
 }
 if (GetAsyncKeyState(VK_F6)&1)
 {
  if (ScriptCommand(&player_in_car, PLAYER_CHAR))
  {
   DWORD dwCurrentCar = 0; // this creates a DWORD to store our current car.
   ScriptCommand(&get_player_car, PLAYER_CHAR, &dwCurrentCar); // PLAYER_CHAR = the player.
   ScriptCommand(&set_car_speed, &dwCurrentCar, 0.0);
  }
 }
}
}


Now, you'll need to release the font so you can tab out and go back in without it crashing. It basically resets the font so it can be reused.

To release it, put the following code in CustomRelease:

CODE
SAFE_RELEASE(g_Font);


So it looks like this:

CODE
void CustomReset()
{
SAFE_RELEASE(pSpeedoTex);  // Release speedometer texture
SAFE_RELEASE(pSpeedoSprite); // Release speedometer sprite
SAFE_RELEASE(pNeedleTex);  // Release needle texture
SAFE_RELEASE(pNeedleSprite); // Release needle sprite
SAFE_RELEASE(g_Font);   // Release font
}


So it's pretty easy really. That concludes this tutorial, I hope you found it helpful and any questions or queries you may have please post them in this topic smile.gif . I'll probably revise this topic soon, it took me a good few hours to write. I'll be adding more examples as well. If you want me to code anything to show you how it is done, don't hesitate to ask.

Greets to: Luke, TwoZero, Mike, littlewhitey, Dalpura, spookie, kyeman, MrJax, Cam, ModelingMan, jax, JernejL, aru, SuctionTesticleMan, himselfe, Alfresco, Waddy, BroDan

Special thanks to spookie for making this great tool!

XcR
  • XcR

    Peon

  • Members
  • Joined: 28 Mar 2005

#4

Posted 07 March 2006 - 03:12 PM

-- Reserved post for future examples and additions --

Y_Less
  • Y_Less

    629

  • Members
  • Joined: 14 Mar 2004

#5

Posted 08 March 2006 - 11:41 AM

Nice tutorial XcR. I've been playing with this recently and this would have helped hugely.

You may want to make a note that some people have had problems with setcursorposition() as at some points it is defined as:

int, int, unsigned long

but at other points it is:

unsigned int, unsigned int, unsigned long

It took me a while to find that problem and correct it (had to resort to asking on IRC)

XcR
  • XcR

    Peon

  • Members
  • Joined: 28 Mar 2005

#6

Posted 08 March 2006 - 11:55 AM

QUOTE (Y_Less @ Mar 8 2006, 11:41)
Nice tutorial XcR.  I've been playing with this recently and this would have helped hugely.

You may want to make a note that some people have had problems with setcursorposition() as at some points it is defined as:

int, int, unsigned long

but at other points it is:

unsigned int, unsigned int, unsigned long

It took me a while to find that problem and correct it (had to resort to asking on IRC)

I've not had this problem before so I'm not really sure what you mean. The two refrences to SetCursorPosition() are like this for me:

IDirect3DDevice8Hook.cpp:

CODE

void __stdcall IDirect3DDevice8Hook::SetCursorPosition(int X, int Y, DWORD Flags)
{
pD3DDevice->SetCursorPosition(X, Y, Flags);
}


IDirect3DDevice8Hook.h:

CODE
STDMETHOD_(void, SetCursorPosition)(THIS_ int X,int Y,DWORD Flags);


So if anyone is having problems with this I'd advise them to change lines 191-194 in IDirect3DDevice8Hook.cpp to the one above, and line 32 in IDirect3DDevice8Hook.h to the one above also.

Y_Less
  • Y_Less

    629

  • Members
  • Joined: 14 Mar 2004

#7

Posted 08 March 2006 - 12:12 PM

Hmm, I redownloaded it and now can't find the error, but I know it existed, I'm not going mad, there was a reason it wouldn't compile for me originally, meh forget it then, I would test a recompile now but I don't hae the DX SDK installed on my uni account and only have 50Mb. Anyway, for anyone interested ignore me and link to speedo download.

Y_Less
  • Y_Less

    629

  • Members
  • Joined: 14 Mar 2004

#8

Posted 11 March 2006 - 08:12 PM Edited by Y_Less, 11 March 2006 - 08:40 PM.

Sorry for the double post, but the DirectX 8 sdk is not obviously linked from the Microsoft site (at least I couldn't see it). All the dx downloads are updates and DX 9 only downloads.

After a lot of searching I found this download address on another site so it may be an idea to add it to the first post to save a lot of searching.

Edit: Oh, it doesn't work on XP/NT confused.gif

XcR
  • XcR

    Peon

  • Members
  • Joined: 28 Mar 2005

#9

Posted 11 March 2006 - 09:28 PM

Ah, I could have sworn that it was still on the site. Another alternative is to download the DirectX9 Feb 2006 SDK and extract this rar file into the main DirectX SDK folder. That'll add the DX8 libs and headers to the DX9 SDK installation - sorry for all those folks on 64bit processors, I don't have the DX8 library files for that.

Thanks for the info, Y_Less.

sueey
  • sueey

    KILLA7 = sueey

  • Members
  • Joined: 31 Jul 2005

#10

Posted 12 March 2006 - 09:25 AM

How crazy!!Master-hand!!!! blink.gif

Y_Less
  • Y_Less

    629

  • Members
  • Joined: 14 Mar 2004

#11

Posted 12 March 2006 - 04:41 PM Edited by Y_Less, 12 March 2006 - 08:02 PM.

Cheers XcR, I know there is a download somewhere on the internet, I got it barely 4 weeks ago, but I've lost it now and lost the files in a PC death.

Edit: try this, I found a download that requires a 'validated' copy of windows which requires either an activex control or firefox plugin (it's quite funny seeing microsoft give out firefox plugins and have screen shots of how to install it). I go that and got that address, if it doesn't work remove the hash part from the end and you'll have to validate yourself. It's a 337Mb download so should be everything but I'm stil getting it to see.

Edit 2: OK, after 3 hours downloading that IS the full February 2006 DX 8+9, I just didn't see it before due to the authorisation required, my bad, sorry.

dustcrazy
  • dustcrazy

    Just simply, the crazy one.

  • BUSTED!
  • Joined: 11 Apr 2004

#12

Posted 23 March 2006 - 02:04 PM Edited by dustcrazy, 23 March 2006 - 02:29 PM.

Greet job, XcR.

Thanks to you now Y_Less and squiddy won't have to answer my nOOb questions on MSN. What you have shown is in very good detail and should help me learn it alot faster.
Thanks again colgate.gif colgate.gif colgate.gif colgate.gif

Dustcrazy

EDIT:
Your GameScripting.h header file is invaild link

XcR
  • XcR

    Peon

  • Members
  • Joined: 28 Mar 2005

#13

Posted 23 March 2006 - 03:10 PM

Fixed now, thanks for the info.

dustcrazy
  • dustcrazy

    Just simply, the crazy one.

  • BUSTED!
  • Joined: 11 Apr 2004

#14

Posted 23 March 2006 - 11:52 PM

Am I the only person that has readed this and have tryed it? I mean I've got everything to work expect the key functions. nervous.gif nervous.gif nervous.gif nervous.gif

[FP]Gunner
  • [FP]Gunner

    Codename Multiplayer Coder

  • Members
  • Joined: 11 Jun 2005

#15

Posted 28 March 2006 - 01:45 PM Edited by [FP]Gunner, 28 March 2006 - 01:48 PM.

--------------------Configuration: d3d hook - Win32 Debug--------------------
Compiling...
Custom.cpp
e:\spooky's speedo scr\custom.h(13) : fatal error C1083: Cannot open include file: 'd3dx8.h': No such file or directory
GameScripting.cpp
IDirect3D8Hook.cpp
e:\spooky's speedo scr\custom.h(13) : fatal error C1083: Cannot open include file: 'd3dx8.h': No such file or directory
IDirect3DDevice8Hook.cpp
e:\spooky's speedo scr\custom.h(13) : fatal error C1083: Cannot open include file: 'd3dx8.h': No such file or directory
Speedo.cpp
Error executing cl.exe.

d3d8.dll - 3 error(s), 0 warning(s)


confused.gif help nervous.gif

Cowpat
  • Cowpat

    web schmeb

  • Members
  • Joined: 12 Feb 2004

#16

Posted 28 March 2006 - 02:05 PM Edited by Cowpat, 30 March 2006 - 09:21 AM.

Do you have d3dx8.lib included in your linker options?

Edit: do you have d3dx9.h in your include folder?

[FP]Gunner
  • [FP]Gunner

    Codename Multiplayer Coder

  • Members
  • Joined: 11 Jun 2005

#17

Posted 28 March 2006 - 02:07 PM Edited by [FP]Gunner, 28 March 2006 - 02:18 PM.

U mean d3dx8.dll rite? wow.gif

Edit: Hmm my bad. I changed it too .lib wink.gif It still doesnt work tho cryani.gif

Edit 2: OO yeah i got it working thanks to adtec that gave me this zipzor: http://eyebro.ws/tut/dxfiles.rar

J-Fox.GEMM
  • J-Fox.GEMM

    Ello...

  • Members
  • Joined: 31 Aug 2004

#18

Posted 30 March 2006 - 11:44 AM

Nice tut XcR... biggrin.gif

ATM I try to hook present only by modding the pointers in the mem. Any Idea how I would call sthin like -> SetRenderState?

My game ceeps crashing:

CODE
Header:

IDirect3DDevice9* dx_D3DDevice = (IDirect3DDevice9*)0xC97C28;

Code:

*(IDirect3DDevice9*)dx_D3DDevice->SetRenderState( D3DRS_SHADEMODE, 1 );

DexX
  • DexX

    Black Hat

  • Feroci Racing
  • Joined: 16 May 2002

#19

Posted 30 March 2006 - 05:10 PM

that information would be handy to know. actually tying any of the Dx-specific functions, like setting render states or lights and materials and such, tying those into script commands, or specific user defined events, would be of tremendous help.

Just to cite one example; i have an address that is checked when vehicles are being rendered. with the xbox-specular mod i released months ago, i could check against this address and enable D3DRS_SPECULARENABLE when its true, and disable it when its not, thus rendering spec on JUST the vehicles, and not every object onscreen.

So yea, if you could shed some light on connecting dx-specific events, like renderstates and materials, to say a scriptcommand, or key press, we'd appreciate it very much smile.gif cookie.gif

Y_Less
  • Y_Less

    629

  • Members
  • Joined: 14 Mar 2004

#20

Posted 30 March 2006 - 05:31 PM

Couldn't you just do something like:

CODE
int iSCMVar = *(int *)(SCRIPT_BASE + dwDmaScmVar)


Then in the SCM do:

0004: 40?? = 1 (or whatever value you want)

and set dwDmaScmVar to 40 (not 0x40), then you can just use iSCMVar (or even just a direct access to the SCM memory section) to test and act on.

SCRIPT_BASE is already defined in spookies code.


Alternatively hook an OpCode by rerouting the pointer in the jump tables.


As for keypresses, Cowpats d3d9 code in Misc has the code for a keyboard hook, and not using DirectInput (which wouldn't matter anyway as DX9 still uses DI8)

DexX
  • DexX

    Black Hat

  • Feroci Racing
  • Joined: 16 May 2002

#21

Posted 02 April 2006 - 01:05 PM

@ Y_less i'm not sure who you're addressing, but that wouldn't provide any direct, directx access. and i need to re-phrase my request in my previous post; a "scriptcommand" for accessing directx isn't what i had in mind, and im not sure what i was thinking when i wrote it.

re-phrased;
Xcr, could you, if you know how yourself, explain how to change renderstates, just as an example, in the customrender function, of custom.cpp. Right now the only way i know how to do it successfully, is in IDirect3DDevice8Hook.cpp, and the changes are only made once when the dll is loaded, i cannot tie them to any user-defined actions triggers functions etc.
Preferably, i would like to set up a light and/or material via customrender if at all possible. any help is appreciated.

XcR
  • XcR

    Peon

  • Members
  • Joined: 28 Mar 2005

#22

Posted 03 April 2006 - 01:43 PM Edited by XcR, 03 April 2006 - 02:02 PM.

Well you're able to call any of the functions that are in IDirect3DDevice8Hook.cpp in Custom.cpp through the IDirect3DDevice8 pointer (pD3DDevice). Here is an example of how you would call SetRenderState in the CustomRender function - triggered when the F5 key is pressed:

CODE

void CustomRender(IDirect3DDevice8 *pD3DDevice)
{
       if (GetAsyncKevState(VK_F5)&1)
       {
               pD3DDevice->SetRenderState(D3DRS_FILLMODE, 2); //wireframe
               pD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE); //fullbright
               pD3DDevice->SetRenderState(D3DRS_SRCBLEND, 10); // strange sky
               pD3DDevice->SetRenderState(D3DRS_TEXTUREFACTOR, -256); // coloured textures
               pD3DDevice->SetRenderState(D3DRS_ALPHAFUNC, 2); // no fog
               pD3DDevice->SetRenderState(D3DRS_AMBIENT, 1); // more ambient
               pD3DDevice->SetRenderState(D3DRS_SHADEMODE, 1); //cell shaded mode
       }
}


Obviously you can't set them all at the same time, but you get the idea.

I hope this is the info you needed, DexX tounge.gif . You can find information on SetRenderState here.

dustcrazy
  • dustcrazy

    Just simply, the crazy one.

  • BUSTED!
  • Joined: 11 Apr 2004

#23

Posted 20 April 2006 - 05:32 PM

This is sweet and all, but how would I go about setting the game to window mode?

GamerShotgun
  • GamerShotgun

    The main protagonist.

  • Members
  • Joined: 03 Oct 2005

#24

Posted 21 April 2006 - 02:55 PM Edited by MasterK, 21 April 2006 - 03:01 PM.

hi! I followed ur tut, and i stuck at the Rebuild all section.. Cus i've got this error:

c:\scm mod\custom.h(13) : fatal error C1083: Cannot open include file: 'd3dx8.h': No such file or directory

I've searched the downloaded archive for this file, but it isn't contains it! Pls help me!

*EDIT*

Oops! Sorry.. I've read back a lil' bit in this topic and found [FP]Gunner's post.. Problem solved!

Lauriux
  • Lauriux

    Player Hater

  • Members
  • Joined: 24 Jan 2007

#25

Posted 05 February 2007 - 06:05 AM

Hello! may someone can post new link or upload Speedo source code because old link dead and I can't find other anywhere confused.gif

ceedj
  • ceedj

    PEDS Creator

  • Feroci Racing
  • Joined: 21 May 2005
  • None

#26

Posted 05 February 2007 - 12:53 PM

Hosted at Pawfect Films. smile.gif

Spookie's Speedo Source

Lauriux
  • Lauriux

    Player Hater

  • Members
  • Joined: 24 Jan 2007

#27

Posted 05 February 2007 - 07:04 PM

Thanks ceedj ! icon14.gif

grovespaz
  • grovespaz

    Group: Morons

  • Members
  • Joined: 22 Feb 2004

#28

Posted 07 April 2007 - 05:14 PM Edited by grovespaz, 07 April 2007 - 09:38 PM.

Or download them directly from spookie's site. http://spookie.gameoverlay.com/.

I know the powerpill one is down, but this one is still up wink.gif
EDIT: I am terribly sorry, for some reason, this topic appeared in my recent reply list.. mercie_blink.gif

MartijnD
  • MartijnD

    Player Hater

  • Members
  • Joined: 25 Jul 2007

#29

Posted 25 July 2007 - 11:06 PM

A realy good tutorial, thanks!

xanser
  • xanser

    Player Hater

  • Members
  • Joined: 12 Sep 2006
  • None

#30

Posted 19 September 2007 - 01:57 PM Edited by xanser, 25 September 2007 - 05:55 AM.

I download MS VC++ 6.0 and DirectX 8.1 SDK
What is wrong? cry.gif
CODE
error C2259: 'IDirect3DDevice8Hook' : cannot instantiate abstract class due to following members: idirect3ddevice8hook.h(13) : see declaration of 'IDirect3DDevice8Hook'
warning C4259: 'void __stdcall IDirect3DDevice8::SetCursorPosition(unsigned int,unsigned int,unsigned long)' : pure virtual function was not defined \include\d3d8.h(263) : see declaration of 'SetCursorPosition'

...it's seems the suggestion was in the begining of this topic, sorry...




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users