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. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    2. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    3. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    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. Portable Games

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

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

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

    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

Hey modders, as promised here's the source code for the Analog Speedometer Mod which demonstrates how to execute scm opcodes from an external program and also how to hook the IDirect3D8 and IDirect3DDevice8 interfaces in order to draw custom stuff in Vice City.

 

It's written in C++ and requires the DirectX 8.1 SDK (this is also included in the later DirectX 9 SDKs, available here - 227mb). It should compile using any recent version of Microsoft Visual C++, but it was developed and has only been tested in version 7.1 (.NET).

 

I've very heavily commented the files GameScripting.cpp and Custom.cpp which contain the scm hooking code and the speedometer stuff respectively. I went a bit crazy with the commenting and i've put quite a bit of info in the ReadMe.txt for the source code and also on the download page, but if you have any problems please post here or email me.

 

And now for the downloads and info:

http://spookie.powerpill.co.uk/speedo/

 

Happy modding!

Link to comment
Share on other sites

I'm speechless... This is incredible, it's a real push to the open source nature of this community. Outstanding.

 

The source code is great, especially with the heavy commenting, something I tend to shy away from. Most of my code is illegible to most other people because I don't include comments whatsoever, or very few at most.

 

Great job on this Spookie, it's amazing.

Edited by Kryptos
Link to comment
Share on other sites

good work, nice and clever execution. one question though; why muck around in global var space when you've already created a threadstruct with 16 locals (partype 3) begging to be used?

Link to comment
Share on other sites

good work, nice and clever execution. one question though; why muck around in global var space when you've already created a threadstruct with 16 locals (partype 3) begging to be used?

I'd wrote that when I only knew what a few of the thread struct members were, before you game me the whole thing.

 

Even afterwards I didn't think of it, but yeah using the locals would be cleaner smile.gif

Link to comment
Share on other sites

Wow, great stuff Spooky, and also thanks for the detailed commenting.

 

Since i'm a Delphi freak, I might try to convert the opcode executor if I find the time. Could get interesting, due to the use of varargs... wink.gif

 

And I promise to also publish source codes of final versions of my tools in the future.

Link to comment
Share on other sites

This is great spooky, by far the coolest speedo i've seen for GTA, and that only as a small demo project for the new GTA modding technology, you guys uncovered.

cookie.gifcookie.gifcookie.gif

 

Do you have any idea what the performance of scm code executed through this hook is, in relation to running it from within the mian.scm ?.

 

If the performance penalty is not too big, it would be great to do mission coding in C++ inlove.gif

 

More stars for spooky and sheep !!!!

bS8xA.png
Link to comment
Share on other sites

Truly brilliant. smile.gif I look forward to the rest of projectx

 

 

Smithers2 gets goes out to buy a learn C++ in 24 hours book

adam broke it.

Link to comment
Share on other sites

ghost of delete key

 

Since i'm a Delphi freak, ...

Huh. Didn't know. nervous.gif

 

Ya learn something new every day, whether you want to or not. turn.gif

 

I've recently seen the light of Delphi, myself. Good gravy, it is.

 

 

 

I might try to convert the opcode executor if I find the time.

Could get interesting, due to the use of varargs... wink.gif

 

What version are you on?

I'm using Delphi 7 Enterprise, and C++ Builder 6. I haven't seen any earlier versions, so I don't know about them, but the Delphi helpfiles in v7 have extensive C++ cross-references, which is a beautiful thing.

 

 

 

And I promise to also publish source codes of final versions of my tools in the future.

 

soo-WEET!

 

will that also include your works to-date?

 

(say 'yes', say 'yes', say 'yes' inlove.gif )

 

we need to talk under the table...

 

after I get some sleep

 

 

BTW @ Spooky-

 

Absolutely great stuff, I've envisioned something like this, but have been mostly clueless up till now. Thanx immensely for the edumacashum, it will not go to waste biggrin.gif

 

I smell an opensource project coming around the corner, just in time for SA4PC.

Just thinking out loud.

scagv35.jpg


"I can just imagine him driving off the edge of a cliff like Thelma & Louise, playing his Q:13 mix at full volume, crying into a bottle." - Craig

Link to comment
Share on other sites

Since i'm a Delphi freak, I might try to convert the opcode executor if I find the time. Could get interesting, due to the use of varargs... wink.gif

there will alaways be help wink.gif

 

Currently working on Top Down City Game, a classics top down game similar to GTA1 & GTA2: 

 

Thread Info: https://gtaforums.com/topic/911312-new-game-top-down-city/

Youtube channel: https://www.youtube.com/channel/UCxGfOh3ld7Xm-ic3KEMB6iA 

Discord: https://discord.gg/UXmDPzS - join #bridge channel 

Link to comment
Share on other sites

 

Delfi, if only every great modders retired the way you did...  inlove.gif  biggrin.gif

I've said it before... lol.gif

 

Spooky, or anyone else who knows the answers, i have a few in depth questions about the technical potential for this, which is clearly very high.

 

Coding... (c++)

For example, could you hook a trainer-like function into the code, that would alter the memory addresses of the police weapons, to a different weapon, every time im wasted / busted (using this method of scripting)? The purpose being to write to any address in the game, like a trainer, along with the scm functions, as some of the hardcoded stuff cannot be changed via normal scm-scripting.

 

Art... (directx)

Or how about the material for the water in vice. I think it sucks, and swapping out the texture itself doesnt help much. Is / could there be any way to overwrite the material used by the game, to a new one? If so, would i have the full power of DX8 at my disposal, for other effects? EMBP (environment mapped bump mapping) would look lovely on the water, for instance. Or, can i overwrite any materials in the game? bump mapping on the roads would be a nice touch.

 

These arent requests for features, they're questions of technical feasability. So please, indulge me smile.gif

Edited by ashdexx

Lurking..

Link to comment
Share on other sites

Thanks to everyone for the kind words and support smile.gif

 

 

 

Since I'm a Delphi freak, I might try to convert the opcode executor if I find the time. Could get interesting, due to the use of varargs...

I'm a still a Delphi freak at heart smile.gif It was just easier for the DX stuff using C++. It would be interesting converting this... I think the dynamic array of Variant type would work, but I've still never used it myself.

 

 

 

And I promise to also publish source codes of final versions of my tools in the future.

Don't get me wrong by my other posts, I'm not an open source nut now, I just don't agree with not sharing gta modding information among this community when this community has shared so much with everyone. This is something you could never be accused of as you've helped tirelessly in almost all sections of modding gta.

 

I'm not saying don't share your source, as I've seen from sharing mine it can help people even if it's just for language translation but don't feel obligated to do so.

 

 

 

Do you have any idea what the performance of scm code executed through this hook is, in relation to running it from within the mian.scm ?.

It'll have a bit more overhead with the script stub generation, but the actual number of assembly instructions that get executed to generate it isn't very many, so I can't see it being a noticeable difference.

 

 

 

If the performance penalty is not too big, it would be great to do mission coding in C++

Structuring proper missions might be a bit more challenging than when using the normal scripting language, for example in C++ you couldn't make a loop to check if the player is in a specific position or something, you'd need to do this check once per frame otherwise the game would be frozen until your loop breaks. You could of course make another (windows) thread for your mission scripts... hmm. This has me thinking now smile.gif. Doing this you'd also have to know that when you're executing opcodes - the game isn't. Managing multiple threads can get a bit tricky.

 

 

 

I smell an opensource project coming around the corner

It would be very cool to do an open source community project with this kinda stuff...

 

 

 

Coding... (c++)

For example, could you hook a trainer-like function into the code, that would alter the memory addresses of the police weapons, to a different weapon, every time im wasted / busted (using this method of scripting)? The purpose being to write to any address in the game, like a trainer, along with the scm functions, as some of the hardcoded stuff cannot be changed via normal scm-scripting.

Yep, without a problem. (Most) trainers use WriteProcessMemory in order to write to the games memory, and if it's a recurring thing such as your example, it's usually on a timer that would use ReadProcessMemory to figure out if you're wasted/busted and if so use WriteProcessMemory to change the police guns. In our case we're running from a dll inside the game's process, so you can access the memory directly. e.g.

 

if the wasted/busted flag was a byte at 0x00123456, and the police gun was a dword at 0x00654321, you could simply use...

 

 

BYTE* bWastedBusted = (BYTE*)0x00123456DWORD* dwPoliceGun = (DWORD*)0x00654321if (*bWastedBusted) *dwPoliceGun = 1;

 

This would check if you're wasted/busted and if so change the police gun to type 1. I hope this makes sense, I'm writing it on the fly, and reading back it doesn't seem very clear wink.gif.

 

 

 

Art... (directx)

Or how about the material for the water in vice. I think it sucks, and swapping out the texture itself doesnt help much. Is / could there be any way to overwrite the material used by the game, to a new one? If so, would i have the full power of DX8 at my disposal, for other effects? EMBP (environment mapped bump mapping) would look lovely on the water, for instance. Or, can i overwrite any materials in the game? bump mapping on the roads would be a nice touch.

Again this is not a problem, anything the game does with Direct3D8, you have control over with the hook. The game will render the water and roads with DrawPrimitive at some stage, the only tricky part is figuring out which call is to draw the roads and which to draw the water...

 

There's a few basic ways I know of determining what is currently being drawn, they are -

  • Counting vertices.

    When calling DrawPrimitive the game specifies how many vertices are in the passed vertices buffer, and it'll usually range from around 24 for a box to thousands for a building. If you know how many vertices are in say the water you can compare for that within the hooked DrawPrimitive function and if found, either stop the call and do your own drawing or simply modify their call.

     

     

  • Texture checking.

    Before a call to DrawPrimitive you have to set the texture to be wrapped onto the vertices using SetTexture. If you did a check on the texture passed to SetTexture to see if it's the water texture, you could set a flag in your code so subsequent calls to DrawPrimitive know it is the water being drawn. When SetTexture is called again and it's not the water texture, reset the flag.

     

     

  • Return address.

    This is a bit more of a low level check - If the game draws the water, roads, building, actors etc from different parts of the game's code, you can check return address of the call to DrawPrimitive on the stack, if it's equal to the one you've determined is the water, do your stuff.

If you decide to go ahead with the stuff mentioned and need any help, don't hesitate to ask smile.gif.

 

 

</novel>

Link to comment
Share on other sites

Whoa, holy s***!

 

 

Spooky's post novel

 

Well, this is all very good and bad. Good for the community to have such power at their fingertips, and in my case bad, since i dont know enough c++ to write a small trainer (and i've tried!) sad.gif

well...no, i DID work, but it could only write to one address, and had no gui. it was lame.

 

but i simply wont be able to rest until i make some tweaks to Vice's graphics..

 

i just had another realization - lighting is also controlled by directx isn't it..

Spooky, your going to be the death of me cookie.gif

Edited by ashdexx

Lurking..

Link to comment
Share on other sites

Very cool indeed.

 

I just wanted to throw some ideas on the table. Since there is plenty of info on how to call into the scm interpreter directly, and that most of the functional scm instructions relate to either Game, Player, Actor, Vehicle, Object, or Mission, the opportunity is there to implement these scm instructions as methods of OLE/ActiveX objects. What this could do is make GTA mission coding and modding available to Javascript, VBscript and PERLscript, in a completely object oriented manner using the Windows Scripting Host

 

It might be something to think about for San Andreas perhaps. I'm sure there would have been alot more user created missions had it been easier to code them.

Link to comment
Share on other sites

I've been thinking about coding a makeshift SCM interpreter that reads Perl-based syntax. It would then merely use spooky/sheep's method of directly using the interpreter to input the script at runtime. It's a pretty lame idea, but at least it would give people a way of directly debugging missions at runtime and using a nicer syntax, in my opinion anyway. I've always wanted to see a compiler capable of giving a GTA modder the same abilities that MSVC++ has, namely in the debugging field. It's a lot easier then writing a quick SCM script and then debugging it by going back and forth a few hundred times; of course I should mention that Kyeman/eAi's exception handler is an amazing accomplishment as well for SCM debugging. Anyhow, great information and great ideas.

Link to comment
Share on other sites

 

And I promise to also publish source codes of final versions of my tools in the future.

Don't get me wrong by my other posts, I'm not an open source nut now, I just don't agree with not sharing gta modding information among this community when this community has shared so much with everyone. This is something you could never be accused of as you've helped tirelessly in almost all sections of modding gta.

 

I'm not saying don't share your source, as I've seen from sharing mine it can help people even if it's just for language translation but don't feel obligated to do so.

I've bugged steve-o for the realease of his tools every sunday when he's online on ICQ. My calendar have "bug steve-o" on every sunday for a year ahead!

 

He _will_ release his sources! sly.gif

Link to comment
Share on other sites

 

I just wanted to throw some ideas on the table. Since there is plenty of info on how to call into the scm interpreter directly, and that most of the functional scm instructions relate to either Game, Player, Actor, Vehicle, Object, or Mission, the opportunity is there to implement these scm instructions as methods of OLE/ActiveX objects. What this could do is make GTA mission coding and modding available to Javascript, VBscript and PERLscript, in a completely object oriented manner using the Windows Scripting Host

Great idea! Although I've had no experience making ActiveX objects myself, so are you offering? smile.gif

 

It might get a bit difficult when people want help in a specific scriping language, but having that freedom of choice would be cool.

 

 

 

I've been thinking about coding a makeshift SCM interpreter that reads Perl-based syntax. It would then merely use spooky/sheep's method of directly using the interpreter to input the script at runtime. It's a pretty lame idea, but at least it would give people a way of directly debugging missions at runtime and using a nicer syntax, in my opinion anyway.

That'd be cool, it's not a lame idea. If you can do it, go for it smile.gif

Link to comment
Share on other sites

The edges of the speedo aren't smoothed out for me like that, I'vr tried changing my res already. I have no idea, I might need to change some settings on my vid card?

Link to comment
Share on other sites

I've noticed a little bug, when you change the radio station, the speedo disappears and comes back when the game has tuned in on the next station happy.gif
Link to comment
Share on other sites

Stop making so damn good mods, I don't want to stand up and get my VC CD to install it again sigh.gif

 

Nice mate !

8jjZhSV.jpg

Link to comment
Share on other sites

 

Great idea! Although I've had no experience making ActiveX objects myself, so are you offering?

 

I haven't had much time for any recreational coding lately, but I'll make a start on it when I do though, if nobody else does first. It's relatively simple if you make use of the msscript control. Implementing all the scms as methods will be the hardest part.

Link to comment
Share on other sites

wouldn't it be better/easier to see which functions the scm opcodes actually call, and instead document those, combine them with known memory addresses, and try to reconstruct the real vehicle/actor/scriptthread objects from that (in which case the ps2 gta3 exe with embedded function names would help a lot)?

Link to comment
Share on other sites

Hi.

I know this may not be the right thread for this, but i don't want to open a new one. At first my respect to this wonderful project!

 

I talked to Spookie yesterday on IRC, he helped me a lot. But one problem couldn't be solved yet. I'm trying to get the actual car health.

 

First attemp: Using a scm opcode

 

 

const SCRIPT_COMMAND get_car_health    = { 0x0227, "vv" };...float fCurrentHealth = 0.0;if (!ScriptCommand(&car_stopped, &dwPlayerCar))    // Is the car moving?...{ScriptCommand(&get_car_health, &dwPlayerCar, &fCurrentHealth);	// Get the car health}

 

It returns 0. confused.gif

 

Second attemp: Getting the value from memory

 

float* fCarHealth=(float*)GameGetVehicle(dwPlayerCar);fCarHealth += 516;float fCarHealth2=*fCarHealth;

 

Same here. blink.gif

 

 

What's wrong? Please help me, i can't find a mistake.

Greets Squiddy

Link to comment
Share on other sites

This is the best speedometer i've seen. And the only one i use smile.gif . BUT...there seems to be a problem... I don't know is it just my pc or something, but this speedometer doesn't work with GTA: LC confused.gif . I've tried reinstalling the game...and gtalc... Anyone have the same problem?

Link to comment
Share on other sites

I talked to Spookie yesterday on IRC, he helped me a lot. But one problem couldn't be solved yet. I'm trying to get the actual car health.

 

First attemp: Using a scm opcode

 

 

const SCRIPT_COMMAND get_car_health    = { 0x0227, "vv" };...float fCurrentHealth = 0.0;if (!ScriptCommand(&car_stopped, &dwPlayerCar))    // Is the car moving?...{ScriptCommand(&get_car_health, &dwPlayerCar, &fCurrentHealth);	// Get the car health}

 

 

I'm not sure it solves the problem, but I think car health is returned as an integer value, and you're putting it in a float variable. Thus interpreting the returned bit-pattern as a float, while is was meant to be a Integer.

 

Just my $0.021

bS8xA.png
Link to comment
Share on other sites

Well, whenever I copy the thing into the root directory the game crashes. is there anything else I should be doing? blink.gif

Link to comment
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.