SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 03/08/2018, 02:20 PM   #1
dotSILENT
Little Clucker
 
dotSILENT's Avatar
 
Join Date: Aug 2016
Location: Poland
Posts: 27
Reputation: 35
Lightbulb [UNFINISHED] CHandling - custom per-vehicle handling

This is unfinished, garbage, testing only & abandoned

A few months ago I started this little thing just to train some reverse engineering in IDA and stuff. I've noticed that it's farily easy to make a vehicle in gta have it's own, custom handling (so not an handling for all models, but for ONE particular vehicle). So I started digging and looking at things, copied some random stuff from other projects & my old stuff (that's why you can find a lot of garbage from sob etc, lot's of outdated structs and unused code).
I eventually got it to work, hooked some place in SAMPs memory which was called after a vehicle was streamed in and overwrited it's handling pointer to my own.
I've also started creating some HandlingModifiers class, because I wanted to make some sort of Need for Speed style vehicle tuning, where you could buy a turbo set and the server would just apply some modifiers to your handling (this way, different parts could overlap and modify the handling).
Example:
Code:
handlingMgr.vehicleHandlings[createdVehicleID].modifiers.AddModifier(HANDL_FDRAGMULTIPLIER, "*0.97");
handlingMgr.vehicleHandlings[createdVehicleID].modifiers.AddModifier(HANDL_FMASS, "-400.0");
handlingMgr.vehicleHandlings[createdVehicleID].modifiers.AddModifier(HANDL_FTRACTIONMULTIPLIER, "*1.02");
I also added some crash fixes from MTA for objects attached to vehicle. If I remember correctly, you could also do custom vehicle rim sizes pretty easily.

But! I have lost all my interest in SAMP a couple of months ago, I haven't done anything since then and I don't even remember what I was doing. Therefore I decided to put this thing up as it was just rotting on my computer, and I hope that somebody will find the time & effort to re-write this and make it fully functional.
It obviously needs a server-sided plugin which will communicate with the client to do the handling modifications. This plugin would need to store all the handling data and send it to other players so it would work for them too.
Of course this code isn't probably even functional. It was all for testing purposes only, done on a single version of samp and using direct memory addresses.

GitHub source
https://github.com/dotSILENT/chandling

Last edited by dotSILENT; 03/08/2018 at 08:18 PM.
dotSILENT is offline   Reply With Quote
Old 03/08/2018, 05:10 PM   #2
RogueDrifter
High-roller
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 1,564
Reputation: 338
Default Re: [UNFINISHED] CHandling - custom per-vehicle handling

That's very interesting i haven't tested it but I'll give it a try and see if it actually achieves what you claim it does then well done.
__________________
Code:
I'm available to script stuff for cash PM me here or on discord @ Andy[RDZ]#0040
[Tutorial]:Anti-cheat guide ||Mini-game 101||VC/LC maps install||
Array index out of bounds


[Github]:Link [Pastebin]:Link [Forum]:Link [Server]:Link [Discord]:Link


RogueDrifter is offline   Reply With Quote
Old 03/08/2018, 05:58 PM   #3
Chaprnks
Gangsta
 
Chaprnks's Avatar
 
Join Date: Sep 2007
Location: Soviet America
Posts: 745
Reputation: 64
Default Re: [UNFINISHED] CHandling - custom per-vehicle handling

Interesting, does this work as a standalone server side plugin? or does it require some type of client & server installation to work?
__________________
Chaprnks is offline   Reply With Quote
Old 03/08/2018, 07:35 PM   #4
dotSILENT
Little Clucker
 
dotSILENT's Avatar
 
Join Date: Aug 2016
Location: Poland
Posts: 27
Reputation: 35
Default Re: [UNFINISHED] CHandling - custom per-vehicle handling

The code I provided is the client-sided part (.asi), it's a piece of garbage as I was testing random stuff and put a lot of things inside, I was going to tidy everything up when I was done but I stopped working on everything.
The server sided plugin needs to be done too, I haven't even started it as I was testing the handling stuff on my client and I didn't even finish it, it was working but with some ugly mid-func hook at a static address that would obviously change with different samp versions.
It works, I've tested it many times, you just need the correct addresses & Stuff.

Edit
I'll try to explain how this plugin works, at least the things I remember (haven't touched this in a long time):
First we hook into GTAs function which loads the handlings & calculates some values (these calculations are very important, if you modify some stuff in real time without re-calculating, the game will crash).
We copy the entire loaded handling (as it is in handling.cfg) - this is called the raw handling data. It's worth noting that the handlings aren't ordered by vehicle IDs, and that if I remember correctly there are only 210 handling lines in the handling file (so not for every vehicle).
This is done in main.cpp at void __declspec(naked) Hook_CalculateHandling()

This way we have all the default handlings stored, so when creating new vehicles we can assign clear, unmodified handlings to them, or we can just restore the original handling if we want. We also need clear unmodified handling if we want to re-calculate it. Therefore, for each handling modification you need to copy the original handling, apply all modifiers that were done before together with the new one you just added and then recalculate it.

Then the rest of magic happens at void __declspec(naked) CreateVehicle()
This function gets called each time a vehicle is spawned in the game (and so when a vehicle streams in, so you also need to re-apply the new custom handling each time the vehicle gets streamed in as it simply gets deleted when it streams out).
We first overwrite the vehicle's handling pointer to our "modelHandlings" array, this way we can still do per-model handling modifications.
Later on, in if (createdVehicleID == 3 && !handlingMgr.vehicleHandlings[createdVehicleID].modified)
we modify the handling for the first time for the car with ID 3 (for testing purposes, it was an infernus in my case).
The modified flag gets set to true, therefore when this vehicle re-spawns, the handling pointer is just overwritten again:
Code:
sampvehptr->gtaVehicle->m_pHandlingData = &handlingMgr.vehicleHandlings[createdVehicleID].calcHandling;
As the custom handling is already modified & recalculated.

That's pretty much everything, it works but of course if you want to modify aircraft & boats it's a different story as they have separate handling datas. I haven't even tried that out, I would probably ignore it as it wasn't needed for my server, I only wanted the cars.

Last edited by dotSILENT; 03/08/2018 at 08:18 PM.
dotSILENT is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vehicle Handling Include feheristi97 Scripting Help 2 15/04/2017 09:23 PM
[Include] Vehicle Handling Hesse Includes 7 02/10/2014 06:28 PM
Best way for handling custom textdraw menus? (enums, dialog style IDs) RajatPawar Scripting Help 2 08/10/2013 03:06 PM


All times are GMT. The time now is 06:40 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.