Tutorial dnSpy - How to fix BackingField in getter and setter methods

AndnixSH

PMT Elite Modder
Original poster
Staff member
Modding-Team
Jun 27, 2017
4,756
300,898
1,213
Modding World
You may meet BackingFields in dnSpy but you don’t know what it is and how to fix?

BackingFields are generated by compiler because they use auto Properties like this

Code:
public string Type { get; set; }
I think because some devs are lazy... I don’t know lol

This is how it looks like when editing getter. BackingField is red

1540400603043.png


And when you compile, you get the following errors

1540400608544.png


But it’s easy to fix, edit getter add a new field and return it with your field and compile. In this case, I add public bool isGlobal for IsGlobal

1540400619560.png


Edit setter, edit to (Type) = value; and compile

1540400627737.png


Done!
Now you can mod it like adding if-else statement for mod menu

1540400706489.png
 

Attachments

Last edited:

DaRealPanDa

Co-Administrator
Staff member
Supporting-Team
Global Moderator
Social Media
Mar 12, 2018
6,737
15,581
2,120
27
Skyrim
if editing IL instructions there is no need to do this and it's usually faster if it's just a get or set method..
Only when its a get or set.
When you insert a Mod Menu it's not faster.
And with IL Instructions you can have many Issues too.
+ you don't learn how c# exactly works when you make only copy & paste IL Instructions.
 

AmySilver

Platinian
Dec 19, 2018
17
13
3
26
United Kingdom
Only when its a get or set.
When you insert a Mod Menu it's not faster.
And with IL Instructions you can have many Issues too.
+ you don't learn how c# exactly works when you make only copy & paste IL Instructions.
I coded programs and games myself in c# so I know how it works, and I don't copy and paste the instructions I add them myself according to my own knowledge.
 

AmySilver

Platinian
Dec 19, 2018
17
13
3
26
United Kingdom
Only when its a get or set.
When you insert a Mod Menu it's not faster.
And with IL Instructions you can have many Issues too.
+ you don't learn how c# exactly works when you make only copy & paste IL Instructions.
please try and make sure what you are saying about someone is correct before saying it or you'll end up being shown to be completely wrong as you have here.
 

DaRealPanDa

Co-Administrator
Staff member
Supporting-Team
Global Moderator
Social Media
Mar 12, 2018
6,737
15,581
2,120
27
Skyrim
I coded programs and games myself in c# so I know how it works, and I don't copy and paste the instructions I add them myself according to my own knowledge.
Yes but this tutorial is for beginner/general modding/ for all, when you are familiar with c# then its logicly that you don't need it.
But this is not for ppl with high knowledge, more for beginner/general modding.
And "you" refers to the person as such, not to you. This should be obvious.
 

69unknown69

Platinian
Apr 14, 2019
9
0
3
33
ph
Hi sir, great tuts! can i ask how can i get the default value inside the k_backingfield? because i used this tut but i cant turn-off the cheat. i have attached the source code. Please enlighten me how to turn it off
 

Attachments

AndnixSH

PMT Elite Modder
Original poster
Staff member
Modding-Team
Jun 27, 2017
4,756
300,898
1,213
Modding World
Hi sir, great tuts! can i ask how can i get the default value inside the k_backingfield? because i used this tut but i cant turn-off the cheat. i have attached the source code. Please enlighten me how to turn it off
You have done it correcly. Maybe it just the game that makes change permanently by the feature. Usally restarting battle will apply your changes. Try other functions then.
 

69unknown69

Platinian
Apr 14, 2019
9
0
3
33
ph
You have done it correcly. Maybe it just the game that makes change permanently by the feature. Usally restarting battle will apply your changes. Try other functions then.
this is actually not right. it has no effect at all. what i notice is that the added field has no use at all. anyways the name of the game ive been trying to mod is archero.