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:
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.
I think you've misunderstood me due to me being completely new to all of this. I have started it from scratch and up until line 12 I have it exactly the same as your file (from what you have shown on your screenshot) however, with line 12 the code is the following:
line offset OpCode Operand
12 40 bne.un -> (15) idarg.0
Now if you look at my screenshot you will see that the dropdown menu for Operand does not have the command ->(15) Idarg.0

How can I create this line so it appears within the dropdown menu or how to I manually insert it?
 

Attachments

  • assembly3.png
    assembly3.png
    119.9 KB · Views: 508
Okay so I have come to the realisation that I have to write the code that you have made and then it automatically creates the lines. Please take a look at my screenshot below and advise what I have done wrong please. Thanks in advance.
 

Attachments

  • assembly4.png
    assembly4.png
    62 KB · Views: 409
That assumption is incorrect... you can't do this in the ilspy version. You have to do it entirely in the instructions.

Don't worry that it's taking a while to get it. It took a lot of time to understand and I needed live advice,

the Instrctuon reference needed in some opcodes can only be done after you've written the rest of the code. You can't create a link to line 15, if you haven't written the correct line 15 yet... (instruction reference literally means 'jump to this line'.) write the rest of the code and come back and point the reference at the correct line later.
 
That assumption is incorrect... you can't do this in the ilspy version. You have to do it entirely in the instructions.

Don't worry that it's taking a while to get it. It took a lot of time to understand and I needed live advice,

the Instrctuon reference needed in some opcodes can only be done after you've written the rest of the code. You can't create a link to line 15, if you haven't written the correct line 15 yet... (instruction reference literally means 'jump to this line'.)

So where do I write the code?
I tried to write the code as you can see from my previous screenshot but it returned errors. I'm so disappointed that I am unable to do this as I have spent all afternoon trying to do this just so I can increase the speed of the game timer :(
 
I spent about three weeks trying to increase it myself.

In the bottom instructions, you just replace everything you have with everything I have, changing the Opcode, Operand type and Operand. When you run out of lines, you should just be able to copy and paste identical lines and move them to where they need to be. You should able to add brand new lines too...

You should download my .dll... and see exactly what I've done. See if you can copy and paste most of it directly into your file.
 
I spent about three weeks trying to increase it myself.

In the bottom instructions, you just replace everything you have with everything I have, changing the Opcode, Operand type and Operand. When you run out of lines, you should just be able to copy and paste identical lines and move them to where they need to be. You should able to add brand new lines too...

You should download my .dll... and see exactly what I've done. See if you can copy and paste most of it directly into your file.

Yes good idea. I will download it now and take a look to see what you've done with yours. What would happen if I replaced the .dll file that I currently have (Enzo's mod) with your .dll file? Would there be any significant changes to game-play?
 
Yes good idea. I will download it now and take a look to see what you've done with yours. What would happen if I replaced the .dll file that I currently have (Enzo's mod) with your .dll file? Would there be any significant changes to game-play?

I didn't even realise Enzoli has his own dll

So no idea.

Also note, my dll is from 1.21 and won't be comparable with 1.23... I'll have to update it before it will work again,
 
I have just opened your .dll and it is showing up exactly the same as the .dll that I have. How can this be? I have closed the assembly (I actually un-installed Reflector and reinstalled it).

So if I were to just copy across your .dll replacing it with the original .dll what changes will happen to the game play?
 
my dll should be different... I havent used the non ilspy one so i don't know whats happening.


My dll also does....
AIBlueFlagBehaviours - set the Blue flag to trigger when the car behind is 0.7s behind instead of 3s.

AIRacingBehaviour - Decreased Comfort Zone to 0.2 - 0.85 from 0.5 - 0.85 so cars behind car run closer to cars in front.

Crash Director - Increased the chances of (race ending) crashes occurring from the vanilla upper bound of 2. It will now be possible to have up to 5 crashes per race (though it's a low chance).

Car Opinion- Increase the effect of negative moral a driver gets when he is unhappy with the car / his car compared to his teammate

GameStatsConstants - Reduced Lower Funds Bound from -5,000,000 to -1,000,000. Reduced Scrutineering Chance from 15% to 5%. Reduced Promotion Parts Stats from x1 to x0.8

GameStatsConstants - Reduced initial reliability for newly created parts to 20%. Increased initial redzone for newly created parts to 30%. This is to accompany changes found in the Assembly.

GameStatsConstants - ncreased the costs of Refueling and Pitcrew to £50,000 when applicable. Increase the cost of Performance tyres from 10,000 to 100,000 and Endurance tyres from 8500 to 10,000. Increased the costs of the tye Tyres from 5000 - 25,000 to 50,000 - 250,000 to add some rule diversity.

Player - ChangedRaceManagementStatMaxChange to 0.2 from 0.5 to slow down the statistic change. Decreased Loyalty and Finance Stat growth from 0.05 per week to 0.025 per week. (I can confirm the stat increases from these have been fixed, where it was once bugged in previous versions)

Mechanic - Changed weekly increase relationships from 2% to 0.5%, and Good Race Relationship from 15% to 2.5%

UIWeatherDropdownBarEntry - Reduced visibility of weather down to 1/20th of race distance when no forecast center is built. Visibility is then set to 5/20, 10/20 and 15/20 of the race for each level of the forecast center.

GameTime - Changed the race play speeds to 1.5x, 5x ,10x

ScoutingManager - Changed the Base Scouting Slots from 3 to 1.

Political System - Changed the number of GMA proposed rule changes has been increased from 4 to 8.

SessionStrategy - Implemented Hudson's fix for the AI retirement
Team - Fixed the fanbase reducing when drivers exceed expectation.
PersonalityTraitsSpecialCase - Fixed an issue where chaser was being activated when in P1 instead of P2.

Driver - changed it so the moraleMaxSessionChange from 20 to 5
Person - Improved reserve driver bonusImprovementAmount from 2 to 4
Race Director - changed yellow flag duration to 30-120s.
Crash Director - changed VSC time from 15-45s to 45s - 120s
AISafetyCarBehaviour - changed duration of the safety car to be between 1-4 laps.
GameStatConstants - increased the retirement rate of 0% condition of non-aerodynamic parts to 90% from 50%
GameStatConstants - Increased the amount you can spend on a chassis, even if it puts you into the red.

CarPartDesign - See the above section for major game mechanics changes:
 
Okay so I had not opened the correct assembly .dll when opening your .dll as I was supposed to open one of the 5 different levels assembly .dll. So moving on, I opened the "Easy" folder and viewed that .dll. The speeds used were 1.6, 4 and 12. I imported this .dll file into the game and it worked perfectly fine with Enzo's mod.

I then loaded a saved game that I had already been playing using Enzo's mod and vanilla .dll before I had used any of your files. This is what I discovered playing short mode;
  1. Scouting slots are still allocated to 3 slots (this maybe because I already had a big list to scout before using your .dll?)
  2. I had a balance of £550k and it would not allow me to go over the -£1m threshold.
  3. Using the "Easy" level, parts took exactly the same length of time to build as with the Vanilla .dll (Engine Avg, build 13 days which was exactly the same length of time on "Vanilla")
  4. Weather was immediately hampered only allowing me to see 1 block per time.
  5. Voting was still set to 4 (this maybe because the season had already started?)
  6. Safety car was dispatched and was out for 3 laps (4 if you include the heading to garage lap)
Personally I really like the .dll you created except that I did not like the safety car being out for so long as on a short game and with 2 different crashes (imagine if there were 4 crashes and shorter lap circuit) it spent 8 of the 19 laps with all the cars on "blue" mode.

Would you be able to edit and upload a "Vanilla" .dll to have the speed of the game to be something like 2x, 5x, 10x as these would be the ideal game speed that I am looking for.
 
Okay so I had not opened the correct assembly .dll when opening your .dll as I was supposed to open one of the 5 different levels assembly .dll. So moving on, I opened the "Easy" folder and viewed that .dll. The speeds used were 1.6, 4 and 12. I imported this .dll file into the game and it worked perfectly fine with Enzo's mod.

I then loaded a saved game that I had already been playing using Enzo's mod and vanilla .dll before I had used any of your files. This is what I discovered playing short mode;
  1. Scouting slots are still allocated to 3 slots (this maybe because I already had a big list to scout before using your .dll?)
  2. I had a balance of £550k and it would not allow me to go over the -£1m threshold.
  3. Using the "Easy" level, parts took exactly the same length of time to build as with the Vanilla .dll (Engine Avg, build 13 days which was exactly the same length of time on "Vanilla")
  4. Weather was immediately hampered only allowing me to see 1 block per time.
  5. Voting was still set to 4 (this maybe because the season had already started?)
  6. Safety car was dispatched and was out for 3 laps (4 if you include the heading to garage lap)
Personally I really like the .dll you created except that I did not like the safety car being out for so long as on a short game and with 2 different crashes (imagine if there were 4 crashes and shorter lap circuit) it spent 8 of the 19 laps with all the cars on "blue" mode.

Would you be able to edit and upload a "Vanilla" .dll to have the speed of the game to be something like 2x, 5x, 10x as these would be the ideal game speed that I am looking for.

Hi mate! Could you upload an edited ASSEMBLY-CSHARP.DLL file so there are up to eight crashes per race? Only that part edited. I've tried to do it myself, I really did, but can't seem to get it right.
Thank you! :)

Yeah... I'm not taking requests on this. I've enough to do already without starting to accept requests from everybody, as before I know it I'll be making dozens of dlls every week and rinse and repeat again for each patch. I don't get paid enough to do that ;)
 
Yeah... I'm not taking requests on this. I've enough to do already without starting to accept requests from everybody, as before I know it I'll be making dozens of dlls every week and rinse and repeat again for each patch. I don't get paid enough to do that ;)

No worries I understand. I just assumed that as you already had done the code change for the game speed it would have literally been a copy/paste-upload scenario as many gamers would like an increase in speed. Brilliant update btw.
 
I've managed to get the camera zoom altered through assembly and it's actually one of the easier things to edit and is a good starting point to learning the opcodes needed through Reflexil.

We are unable to alter the minZoom constant the same way that we change game speed or crash numbers so have to change an argument that alters how the camera is displayed.

I'd recommend backing up your Assembly.CSharp.dll file before attempting to edit anything.
The object your after is
FreeRoamCamera
LateUpdate

this is the line that needs to be changed - mZoom is the current zoom level which is clamped between minZoom and maxZoom.
upload_2017-2-27_0-55-53.png

Using the Reflexil panel select line 71 and right click => create new
OpCode - ldc.r4
Operand type - Single
Operand - 130
Click => Insert after selection
upload_2017-2-27_1-8-29.png

Select the new line 72, right click => create new
OpCode - sub
Click => insert after selection

The codes work backwards so we define the constant and tell it what to do with it.

Right click on LateUpdate in the explorer panel and Update the ILSpy object model which should change the code to this
upload_2017-2-27_1-14-4.png

Scroll back up to the top of the explorer window and save the file
upload_2017-2-27_1-18-7.png

you can use the same method to alter the maxZoom, minRotation, maxRotation
 

Attachments

  • upload_2017-2-27_1-13-22.png
    upload_2017-2-27_1-13-22.png
    33.7 KB · Views: 386
I've managed to get the camera zoom altered through assembly and it's actually one of the easier things to edit and is a good starting point to learning the opcodes needed through Reflexil.

We are unable to alter the minZoom constant the same way that we change game speed or crash numbers so have to change an argument that alters how the camera is displayed.

I'd recommend backing up your Assembly.CSharp.dll file before attempting to edit anything.
The object your after is
FreeRoamCamera
LateUpdate

this is the line that needs to be changed - mZoom is the current zoom level which is clamped between minZoom and maxZoom.
View attachment 175568
Using the Reflexil panel select line 71 and right click => create new
OpCode - ldc.r4
Operand type - Single
Operand - 130
Click => Insert after selection
View attachment 175569
Select the new line 72, right click => create new
OpCode - sub
Click => insert after selection

The codes work backwards so we define the constant and tell it what to do with it.

Right click on LateUpdate in the explorer panel and Update the ILSpy object model which should change the code to this
View attachment 175571
Scroll back up to the top of the explorer window and save the file
View attachment 175572
you can use the same method to alter the maxZoom, minRotation, maxRotation

Awesome to see I'm not the only one doing this anymore. :) I think Sonic and Hudson have moved onto the next game - I was getting lonely.
 
I've not seen that before, but did a quick google search and one solution said that the unity library might not be loaded correctly. here is a screenshot of all the libraries I have loaded in ILSpy right now
upload_2017-2-27_10-13-26.png

particularly look to see if the unity engine is there - if not load it from the managed folder and try again.
 

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