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

AndnixSH

PMT Elite Modder
Staff member
Modding-Team
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

  • 1540400616200.png
    1540400616200.png
    5.7 KB · Views: 180
  • 1540400633640.png
    1540400633640.png
    8.6 KB · Views: 219
Last edited:
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.
 
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.
 
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.
 
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.
 
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

  • 1.PNG
    1.PNG
    14.3 KB · Views: 219
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.
 
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.
 
Back
Top Bottom