r/programminghelp • • Oct 31 '21

C# Modifying a Game

I've been trying to use dnSpy to change code in the Assembly-CSharp.dll. I'm able to understand the code somewhat and change the values of Speed, Jumpheight etc.. I'm just not able to compile. In the tutorial he said this was common but I've looked at the errors for a little bit and cant figure out a fix.
https://imgur.com/a/neMbrsN
I have fixed the last Error on line 368.

4 Upvotes

1 comment sorted by

1

u/KuntaStillSingle Nov 01 '21 edited Nov 01 '21

Assuming you are doing a unity game, I found this quite easy to use and avoids the need to edit IL inside dnspy : edit : Updated doc: https://docs.bepinex.dev/articles/dev_guide/plugin_tutorial/index.html

To modify existing methods I have used harmony, which is included with the above: https://docs.bepinex.dev/articles/dev_guide/preloader_patchers.html

https://harmony.pardeike.net/articles/intro.html


I think the issue in OP is dnspy is not supporting a recent language feature. I think it is the compiler optimizes IL code by changing switch statement like in this question: https://stackoverflow.com/questions/44338751/privateimplementationdetails-function-when-decompiling-a-c , but dnspy does not know how to translate it back in a more human readable form. Assuming that is the case you might need to rewrite it as:

switch(tag) {
    case "FishLeg" : 
        raycastHit.collider.GetComponentInParent<Fish>().leg = true; //etc 
        break;
    case "Fish" :
        raycastHit.collider. //and so on for every case
        break;
}