Assembly Editing and Reflexil Instruction

[You may want to sticky this in the mods forum as this is purely a resource thread for modifying the Assembly-CSharp.dll]

ASSEMBLY-CSHARP.DLL

The amount of modding now taking place in the Assembly-CSharp.dll is increasing. Over the last month, my mod, which normally involved changing some random variables, started to become getting more complex, with several new functions being created. As we're currently using ILSPY and REFLEXIL, changing code isn't as simple as writing some C#, but rather altering the 'instructions' and 'opcode' in the dll, altering the code indirectly.

I was talking to Hudson (who many of you may remember did the original blue-flag fix) who taught me how to use these tools, and we talked about storing our changed codes somewhere, mostly for reference, but may benefit some other modders who wish to change their own dlls - or maybe get some more people into modding the game in general.

EDITING THE ASSEMBLY
To edit the Assembly-CSharp.dll you will need:
ILSPY (http://ilspy.net/)
REFLEXIL pluggin for ilspy (http://reflexil.net/)

I'll post below examples of modified code and what they do (I won't show simple number changes, as that would not really be showing anything at all). I'll focus on the areas of the game I have modded as part of my Balance Mod where changes to code has taken place. I won't do them all at once, but when I find time I'll share the code and some insights here.

Others who are modifying this file, please share your work also so we can get a decent database of changes.

UPDATE:

New Editing Techniques

So, when I first started modifying the code, we could really only go one level - via an Injector, I could change some values. Then, one day, we leveled up! Level 2 let us use Relfexil/ILSpy to edit more of the code and begin really making some changes.

This weekend we upgraded to Level 3! We have a new tool provided to us (and thanks to Robery Eady who provided the link). Now we have DNSpy. https://github.com/0xd4d/dnSpy/releases

What's so special about DNSpy? Well, this:

R49IbZLdo.png

Yes! We can now edit the code directly using normal coding methods!

As an example, in just a few minutes, I created that so during a collision, the part chosen is more random.

Original ILSpy
R3vUJgqc4.png


Edited with DNspy
R439hjgha.png


Checking with ILspy that everything is fine!
R436ZRmNY.png


And it works fine!
Race 1:

R3Y7Tcz52.png

R3Y5dvH8Y.png

R3Y3xX60S.png

Race 2:

R42396clE.png

(obviously, damange to these parts isn't going to be added to the mod, but I could have collisions to the rear mean its Rear Wing Damage 20% of the time, and Suspension 50% of the time, and no damage the last 30% of the time)

What this means for the mod

So, now I can edit the code, this means that:

  • I can make far more complex changes.
  • I can make them faster
  • As I am literally changing code, I can copy all my changes into a .txt document. This means that when I have to update the mod to a new dev patch, I can use CTRL+C and CRTL+V to update an entire class, instead of spending an hour having to remake the opcodes!
This means that I can now add as many features as I desire, and I am nearly unrestricted. Because, though I have not began to test it yet, DNSPY has this:

R4myWUclO.png

If I can add classes, I can create entirely new features from scratch. Define new variables, craft new systems. I can make as many rules and manipulate variables however I wish to craft them. This means I can probably make new 'Season Rules', extend the amount of tiers, bascially anything I want.

I still cannot make new "Game Objects", or make new UI, but the scope of watch's acheiveable has probably increased 10-fold. Which is why I asked for wishlists... Anything Code Related is probably now possible. Some things will be simpler then others, but now almost anything is possible.

All this means is that we have New Powers. And more importantly, it means more people are probably going to be able to edit the code themselves (learning opcodes is was a new and long process, but as a mathematician, I can IF and For anything with ease just from seeing examples). This may mean I can get some more collaborators and help making new features!

 
Last edited:
Play and Fast Forward Speeds
GameTimer
GetSimulationTimeScale


kXtdwZyKW.png

I wanted to change the gamespeeds as I felt the fastest 'fast-forward' option was far too slow/ Particularly as I spend a lot of time testing my mod, and I really want to get through these races quicker.

However, the original game speeds are fixed, can cannot be edited simply by changing a number. This is because the number is part of an Array, and by default in this dll, the numbers stored in the arrays are set to Private, and thus, cannot be modified. So with a simple option not available, I gutted this section of code with new IF statements. (Big thanks to Hudson here as he led me through the process of converting my desired IF statements into the Instructions and OpCode. I have been able to use this example to modify various other areas of the game)


kWQBbUeIW.png

Something strange has happened to this code since editing it. It's gone all 'Global' on me, which I assume is some sort of reference issue. However in this case, the code does what it's intended so if it isn't broke, don't fix it.

I once tried a x50 speed, and while it theoretically works, the game struggles to keep up on my system and is very choppy. You can get away with an x20 though.

For those wanting an x1... while its possible I don't recommend it. The Physics of the cars are simplified, and watching races at x1 speed doesn't look good.


 
Last edited:
CrasgDirector
OnSessionStarting


25WDnJis2.png

This was an interesting one. It seems before the green lights even go off, the number of crashes which will happen in the race have already been decided, with the upper limit being two.

Apart from that being quite static, even the Upper Limit of 2 is not always achievable. I changed it so that there should by 8 crashes each and every race, yet sometimes there would only be 5, other times only 3.... in Short, the values are Upper Bounds. Even if the mSessionCrashCount is 2, only one crash may occur depending what happens in the race.

Needless to say sometimes we want more then two crashes ever, so this was a simple extension of the code to allow for upto 5 crashes in a single race, with probabilities for each occurance.

kXqqKPuRH.png



 
Last edited:
Variable Safety Car Deployment
AISafetyCarBehaviour
OnEnter



llN4EgmNe.png

A nice short and sweet one. The variable mLapsLength = 1 is the number of laps that the safety car is deployed for. I don't like how it's such a predictable event. Sure, if its too long some people may get bored, which is probably the reason the Devs decided to stick with 1 lap.

However, a few posts ago I increased the fast forward speed, so if you're behind a safety car for a few laps and you don't want to watch, you can now let time pass you buy quickly.

So in the most recent experimental edition of my balance mod, I changed the length of the safety car period to be anywhere between 1 and 4 laps.

To do this, is a simple bit of code, a half dozen instruction all in one line. Bit it can be quite powerful as it can be used to randomise a number of different things which would normally have only one value. There was nothing really creative here, I stole the line directly from the Virtual Safety Car coding in 'Crash Behavior' and re-purposed it for the real safety car.


llP5sNs2z.png



 
Last edited:
Do you think you can have a look at editing the file so we can have more than ten teams in the game?
Unlikely, it being more of a physical issue. 20 grid slots on the maps, several UI spaces designed to only handle 10 teams. There's a lot of issues with it and would likely need a full team to make any progress what-so-ever, with a likely chance that it wouldn't be possible with our current resources.

If it's an consolation, I can probably adjust it so you can have 9 teams in a series (this might actually be quite simple).
 
Hi FlamingRed, have a question about the Variable Safety Car Deployment. If I wanted to change the min and max to 2-5 which values (or lines need I to change). [Have ILSpy version 2.4.0.1963 & Reflexil v2.1]
 
Hi FlamingRed, have a question about the Variable Safety Car Deployment. If I wanted to change the min and max to 2-5 which values (or lines need I to change). [Have ILSpy version 2.4.0.1963 & Reflexil v2.1]

Ooooh, Requests.

CrashDirector
SetVirtualSafetCarFlag()

You need to get your screen looking like this:
oaiAtfpqe.png


this.mVirtualSafetyFlagDuration = (float)(Mathf.RoundToInt((float)global::RandomUtility.GetRandomInc(3, 8)) * 15);
This is the key line: It's saying A Random Amount, Minimum = 3 * 15 = 45s. Maximum = 8 * 15 = 120s

You can see the "15" part of the equation is in line "10": Opcode: "idc.i4.s". Instruction: "SByte" "15"
You can change 15 to anything you like, and the Max and Min formula will update. Currently in line 11, the 15 is being "Mul"tiplied to the section before it. You can change that to a "add"ition, "sub"traction or "div"isor

The values 3 and 8 are actually Lines "05" and "06". The Opcode "idc.i4.3" is just the number 3. And you guessed it. "idc.i4.8" is the number 8. This style of numbers using only the Opcode only go from 0 to 8, so feel free to change the opcode to whichever range you want. If you want a value outside that, you need to change the Opcode to something else, like "idc.i4.s" "Sbyte" "Any Number".

That should give you enough to go on. Look for patterns in the codes, and you'll be able to alter the code in more ways.
 
Hi FlamingRed I have read all about your Balance Mod and would like to try it although because I am new to Motorsport Manager I would like to get to grips with the game (currently using Enzo's mod) but would love to increase the speed of the race like you have shown above. Unfortunately for me, I have never modded anything in my life and have downloaded both tools that you have advised but have now spent 2 hours looking for a guide upon how to use them to successfully edit the said file.

I have found the file which needs editing in ILSpy but it is locked and will not allow me to edit anything, further more I cannot open Reflexi to have a table like you have shown in the screenshot above. Please could you give me a quick step by step guide upon how to use both of these tools successfully or a link to some kind of guide.

Perhaps it would be good if you could create an edited .dll file with the new speeds so people can just replace the existing .dll with the new speeds already created.

Thanks in advance!
 
Hi FlamingRed I have read all about your Balance Mod and would like to try it although because I am new to Motorsport Manager I would like to get to grips with the game (currently using Enzo's mod) but would love to increase the speed of the race like you have shown above. Unfortunately for me, I have never modded anything in my life and have downloaded both tools that you have advised but have now spent 2 hours looking for a guide upon how to use them to successfully edit the said file.

I have found the file which needs editing in ILSpy but it is locked and will not allow me to edit anything, further more I cannot open Reflexi to have a table like you have shown in the screenshot above. Please could you give me a quick step by step guide upon how to use both of these tools successfully or a link to some kind of guide.

Perhaps it would be good if you could create an edited .dll file with the new speeds so people can just replace the existing .dll with the new speeds already created.

Thanks in advance!

Um... I'll add a couple of screenshots showing folder layout in my ilspy which may help? Do you see the little gear symbol in il spy?

Thanks for the help FlamingRed

Edit: That is for the Virtual SC I guess, and what about the real Safety Car. How can I change his min and max variables.
I read the original message but never saw the edit until today.

Post 4 - second screenshot - lines 12 and 13 are the min /max number of laps. It's using the id4.ic.x system of numbering which I told you about when editing VSC times)
 
Ah, you're using the standard reflexi, as opposed to the ilspy version... I assume though that you can just right click the lines in the instructions and modify them as I have on mine

I had downloaded ILSpy 2.1 but I could not find a way to open Reflexi so I downloaded Reflector as I followed a guide on youtube. What I need to know now is how do I edit the file to add the code lines that you have made? Also, why does your original screenshot say GameTimer when that word is not included in my screenshot?
 
I had downloaded ILSpy 2.1 but I could not find a way to open Reflexi so I downloaded Reflector as I followed a guide on youtube. What I need to know now is how do I edit the file to add the code lines that you have made? Also, why does your original screenshot say GameTimer when that word is not included in my screenshot?
It does... in a different place... look at the top left of the screenshot you have.
 
Okay so I have now right clicked the lines within Reflector and have tried to copy your screenshot although at line 12 it does not give me the ability to change it to 15 like you have. Take a look at my screenshot below please and could you explain why or where I am going wrong.



Am I supposed to just edit lines only or am I supposed to write code?
 

Attachments

  • assembly2.png
    assembly2.png
    191.8 KB · Views: 952
Okay so I have now right clicked the lines within Reflector and have tried to copy your screenshot although at line 12 it does not give me the ability to change it to 15 like you have. Take a look at my screenshot below please and could you explain why or where I am going wrong.



Am I supposed to just edit lines only or am I supposed to write code?

You'd probably do better deleting most of it... and starting again adding in new instructions from the start...
Remember, you can change the top box (opcode) and the operand type as well.
 
You'd probably do better deleting most of it... and starting again adding in new instructions from the start...
Remember, you can change the top box (opcode) and the operand type as well.

So sorry I am taking up your time with this but I have absolutely no idea with code and/or modding. If you look at the screenshot I posted above, it shows that the Operand instruction -> (15) Idarg.o does not exist in my drop down menu. How can I create this?
 
So sorry I am taking up your time with this but I have absolutely no idea with code and/or modding. If you look at the screenshot I posted above, it shows that the Operand instruction -> (15) Idarg.o does not exist in my drop down menu. How can I create this?
thats because at line 15 you have "ret". You need to manually create most of the lines here. If you right click the instruction space, you should be able to "add" new lines.
 

Latest News

Do you prefer licensed hardware?

  • Yes for me it is vital

  • Yes, but only if it's a manufacturer I like

  • Yes, but only if the price is right

  • No, a generic wheel is fine

  • No, I would be ok with a replica


Results are only viewable after voting.
Back
Top