ProgrammingTrying to Modify this DLL
Posted:

ProgrammingTrying to Modify this DLLPosted:

Status: Offline
Joined: Oct 16, 201014Year Member
Posts: 1,081
Reputation Power: 61
Status: Offline
Joined: Oct 16, 201014Year Member
Posts: 1,081
Reputation Power: 61
In DNSpy I'm editing the IL instructions to make the debug menu enabled and creative menu enabled but once I save and replace it I get an error in the game saying Picture of error

gameManager.isEditMode = GameModeEditWorld.TypeName.Equals(GamePrefs.GetString(EnumGamePrefs.GameMode));
      GamePrefs.Set(EnumGamePrefs.DebugStopEnemiesMoving, gameManager.IsEditMode());
      GamePrefs.Set(EnumGamePrefs.DebugMenuEnabled, 1.isEditMode || GameUtils.IsPlaytesting());
      GamePrefs.Set(EnumGamePrefs.CreativeMenuEnabled, 1.isEditMode || GameUtils.IsPlaytesting());

This is the section of the dll I'm editing. Instead of editing the IL intructions I tried to edit the method in c# but when I go to compile it gives me 100s of errors on lines I didn't touch.

I'm following along on a tutorial that's about 5 years out of date but still has correct locations of what I need I just cant figure out how to get it to work. -Edit here's a video of what I'm doing.
#2. Posted:
Status: Offline
Joined: Oct 16, 201014Year Member
Posts: 1,081
Reputation Power: 61
Status: Offline
Joined: Oct 16, 201014Year Member
Posts: 1,081
Reputation Power: 61
Bump
#3. Posted:
Status: Offline
Joined: Oct 16, 201014Year Member
Posts: 1,081
Reputation Power: 61
Status: Offline
Joined: Oct 16, 201014Year Member
Posts: 1,081
Reputation Power: 61
BUmp
#4. Posted:
Status: Offline
Joined: Sep 11, 2024
Posts: 334
Reputation Power: 106
Status: Offline
Joined: Sep 11, 2024
Posts: 334
Reputation Power: 106
I did a little research and found this post.. possibly related to your problems here take a look

Modifying il instructions


Last edited by xLukee ; edited 1 time in total
#5. Posted:
Status: Offline
Joined: Oct 16, 201014Year Member
Posts: 1,081
Reputation Power: 61
Status: Offline
Joined: Oct 16, 201014Year Member
Posts: 1,081
Reputation Power: 61
xLukee wrote I did a little research and found this post.. possibly related to your problems here take a look

Unknown Cheats - Modifying il instructions


Your link takes me to TTG homepage
#6. Posted:
Status: Offline
Joined: Sep 11, 2024
Posts: 334
Reputation Power: 106
Status: Offline
Joined: Sep 11, 2024
Posts: 334
Reputation Power: 106
Exempt wrote
xLukee wrote I did a little research and found this post.. possibly related to your problems here take a look

Unknown Cheats - Modifying il instructions


Your link takes me to TTG homepage


Here you go I took the time to Re-Create the post here. "Material is not mine"

When it comes to modifying the assemblies of C# applications, often times you'll get errors on compiling when you go to save an edited Method or Class. When you decompile the assembly using dnSpy, it's not exact 1:1 code so there's bound to be errors when you view it. When you Edit Method/Edit Class those errors will prevent you from saving it as it acts like an IDE of sorts. References missing or illegal characters being used that were introduced when you disassembled it are common issues. To get around this you simply want to edit the IL Instructions directly, the OpCodes that are sent to your CPU for processing the stack one at a time. A function call in the disassembled code may be incorrect or invalid but the calls to the cpu are fixed and work 100%.


To start, bookmark this page here as we'll be referencing this multiple times. This a cheat sheet for IL Instructions that you want to keep handy at all times: en.wikipedia.org/wiki/List_of_CIL_instructions

To demonstrate, I went ahead and created a simple .Net Console App like so (feel free to copy/paste into VS to follow along this example):

https://imgur.com/0DVvrPD.jpeg

As you can see, I declare an Int32 named value with the value of 100. I then write that value to the console and then listen for input using ReadLine() (to prevent the console from auto closing. Go ahead and and build this project and then open up dnSpy.

In dnSpy you'll want to open you assembly file for the project you just built. In my case, my project is called ConsoleApp1 so my assembly is ConsoleApp1.dll and that's the file you'll want to open. Once opened in dnSpy, use the Assembly Explorer to navigate to your Program class where you'll see your code you've written.

https://imgur.com/QxZDVg5.jpeg

From here you want to simply Right Click -> Edit IL Instructions... on your code on the right hand side of dnSpy.

https://imgur.com/AwHBQWG.jpeg

You'll be greeted with a screen as follows:
https://imgur.com/U9pB6gj.jpeg

You'll notice at the top of the stack, the very first instruction (opCode) is "ldc.i4.s", and if you refer back to the IL Instructions cheat sheet on Wikipedia, you can do a search for that OpCode and see that ldc.i4.s is "Push num onto the stack as int32, short form.". Short form is more efficient when using a value from -128 to 127 in an Int32. This is done when you compile your code.

If you attempt to add another 0 you'll notice you won't be able to save the changes you've made as a value of 1,000 is beyond what a short form Int32 can store (-128 through 127). You'll want to click on the OpCode and scroll through the dropdown to find the instruction "ldc.i4", which again if you refer back to the cheat sheet you'll see is "Push num of type int32 onto the stack as int32.". Once you've changed the instruction you can change the value to be something within the limits of a signed 32bit integer, in this case I'll add two 0's to make it 10,000. Your instructions should look as follows:
https://imgur.com/7iqHeFD.jpeg

Go ahead and click okay and you should see your code has changed and should now read:
Code:
https://imgur.com/KUceP5q.jpeg

Go ahead and click File -> Save Module... and click OK to save you modified DLL. Now if you run your built application in the same folder as that assembly, you should see your new value print instead of the 100 you coded into the project:
https://imgur.com/SgXjJx9.jpeg

And that's it! IL Instructions can be a lot more indepth than that but with referring to the cheat sheet you should be able to figure a lot of stuff out on your own. Sometimes you want to change a function to always return true, and editing the method returns errors when saving. Instead you'd just edit the IL Instructions directly and find the call "ldarg.0", which loads a 0 into the stack (0 being false). You'd click it and receive a dropdown of all available OpCodes, simply find "ldarg.1" to load a 1 into the stack (1 being true) and save. You'll find these calls just prior to a return call which is "ret".
#7. Posted:
Status: Offline
Joined: Oct 16, 201014Year Member
Posts: 1,081
Reputation Power: 61
Status: Offline
Joined: Oct 16, 201014Year Member
Posts: 1,081
Reputation Power: 61
xLukee wrote
Exempt wrote
xLukee wrote I did a little research and found this post.. possibly related to your problems here take a look

Unknown Cheats - Modifying il instructions


Your link takes me to TTG homepage


Here you go I took the time to Re-Create the post here. "Material is not mine"

When it comes to modifying the assemblies of C# applications, often times you'll get errors on compiling when you go to save an edited Method or Class. When you decompile the assembly using dnSpy, it's not exact 1:1 code so there's bound to be errors when you view it. When you Edit Method/Edit Class those errors will prevent you from saving it as it acts like an IDE of sorts. References missing or illegal characters being used that were introduced when you disassembled it are common issues. To get around this you simply want to edit the IL Instructions directly, the OpCodes that are sent to your CPU for processing the stack one at a time. A function call in the disassembled code may be incorrect or invalid but the calls to the cpu are fixed and work 100%.


To start, bookmark this page here as we'll be referencing this multiple times. This a cheat sheet for IL Instructions that you want to keep handy at all times: en.wikipedia.org/wiki/List_of_CIL_instructions

To demonstrate, I went ahead and created a simple .Net Console App like so (feel free to copy/paste into VS to follow along this example):

https://imgur.com/0DVvrPD.jpeg

As you can see, I declare an Int32 named value with the value of 100. I then write that value to the console and then listen for input using ReadLine() (to prevent the console from auto closing. Go ahead and and build this project and then open up dnSpy.

In dnSpy you'll want to open you assembly file for the project you just built. In my case, my project is called ConsoleApp1 so my assembly is ConsoleApp1.dll and that's the file you'll want to open. Once opened in dnSpy, use the Assembly Explorer to navigate to your Program class where you'll see your code you've written.

https://imgur.com/QxZDVg5.jpeg

From here you want to simply Right Click -> Edit IL Instructions... on your code on the right hand side of dnSpy.

https://imgur.com/AwHBQWG.jpeg

You'll be greeted with a screen as follows:
https://imgur.com/U9pB6gj.jpeg

You'll notice at the top of the stack, the very first instruction (opCode) is "ldc.i4.s", and if you refer back to the IL Instructions cheat sheet on Wikipedia, you can do a search for that OpCode and see that ldc.i4.s is "Push num onto the stack as int32, short form.". Short form is more efficient when using a value from -128 to 127 in an Int32. This is done when you compile your code.

If you attempt to add another 0 you'll notice you won't be able to save the changes you've made as a value of 1,000 is beyond what a short form Int32 can store (-128 through 127). You'll want to click on the OpCode and scroll through the dropdown to find the instruction "ldc.i4", which again if you refer back to the cheat sheet you'll see is "Push num of type int32 onto the stack as int32.". Once you've changed the instruction you can change the value to be something within the limits of a signed 32bit integer, in this case I'll add two 0's to make it 10,000. Your instructions should look as follows:
https://imgur.com/7iqHeFD.jpeg

Go ahead and click okay and you should see your code has changed and should now read:
Code:
https://imgur.com/KUceP5q.jpeg

Go ahead and click File -> Save Module... and click OK to save you modified DLL. Now if you run your built application in the same folder as that assembly, you should see your new value print instead of the 100 you coded into the project:
https://imgur.com/SgXjJx9.jpeg

And that's it! IL Instructions can be a lot more indepth than that but with referring to the cheat sheet you should be able to figure a lot of stuff out on your own. Sometimes you want to change a function to always return true, and editing the method returns errors when saving. Instead you'd just edit the IL Instructions directly and find the call "ldarg.0", which loads a 0 into the stack (0 being false). You'd click it and receive a dropdown of all available OpCodes, simply find "ldarg.1" to load a 1 into the stack (1 being true) and save. You'll find these calls just prior to a return call which is "ret".


I actually googled the name of your link and found the post I ended up getting the dll to work. Its unconventional but all the corresponding IL's after the ones I modify that threw and error I replaced with NOP and it works lmao. An admin can close this post if needed
#8. Posted:
Status: Offline
Joined: Sep 11, 2024
Posts: 334
Reputation Power: 106
Status: Offline
Joined: Sep 11, 2024
Posts: 334
Reputation Power: 106
Exempt wrote
xLukee wrote
Exempt wrote
xLukee wrote I did a little research and found this post.. possibly related to your problems here take a look

Unknown Cheats - Modifying il instructions


Your link takes me to TTG homepage


Here you go I took the time to Re-Create the post here. "Material is not mine"

When it comes to modifying the assemblies of C# applications, often times you'll get errors on compiling when you go to save an edited Method or Class. When you decompile the assembly using dnSpy, it's not exact 1:1 code so there's bound to be errors when you view it. When you Edit Method/Edit Class those errors will prevent you from saving it as it acts like an IDE of sorts. References missing or illegal characters being used that were introduced when you disassembled it are common issues. To get around this you simply want to edit the IL Instructions directly, the OpCodes that are sent to your CPU for processing the stack one at a time. A function call in the disassembled code may be incorrect or invalid but the calls to the cpu are fixed and work 100%.


To start, bookmark this page here as we'll be referencing this multiple times. This a cheat sheet for IL Instructions that you want to keep handy at all times: en.wikipedia.org/wiki/List_of_CIL_instructions

To demonstrate, I went ahead and created a simple .Net Console App like so (feel free to copy/paste into VS to follow along this example):

https://imgur.com/0DVvrPD.jpeg

As you can see, I declare an Int32 named value with the value of 100. I then write that value to the console and then listen for input using ReadLine() (to prevent the console from auto closing. Go ahead and and build this project and then open up dnSpy.

In dnSpy you'll want to open you assembly file for the project you just built. In my case, my project is called ConsoleApp1 so my assembly is ConsoleApp1.dll and that's the file you'll want to open. Once opened in dnSpy, use the Assembly Explorer to navigate to your Program class where you'll see your code you've written.

https://imgur.com/QxZDVg5.jpeg

From here you want to simply Right Click -> Edit IL Instructions... on your code on the right hand side of dnSpy.

https://imgur.com/AwHBQWG.jpeg

You'll be greeted with a screen as follows:
https://imgur.com/U9pB6gj.jpeg

You'll notice at the top of the stack, the very first instruction (opCode) is "ldc.i4.s", and if you refer back to the IL Instructions cheat sheet on Wikipedia, you can do a search for that OpCode and see that ldc.i4.s is "Push num onto the stack as int32, short form.". Short form is more efficient when using a value from -128 to 127 in an Int32. This is done when you compile your code.

If you attempt to add another 0 you'll notice you won't be able to save the changes you've made as a value of 1,000 is beyond what a short form Int32 can store (-128 through 127). You'll want to click on the OpCode and scroll through the dropdown to find the instruction "ldc.i4", which again if you refer back to the cheat sheet you'll see is "Push num of type int32 onto the stack as int32.". Once you've changed the instruction you can change the value to be something within the limits of a signed 32bit integer, in this case I'll add two 0's to make it 10,000. Your instructions should look as follows:
https://imgur.com/7iqHeFD.jpeg

Go ahead and click okay and you should see your code has changed and should now read:
Code:
https://imgur.com/KUceP5q.jpeg

Go ahead and click File -> Save Module... and click OK to save you modified DLL. Now if you run your built application in the same folder as that assembly, you should see your new value print instead of the 100 you coded into the project:
https://imgur.com/SgXjJx9.jpeg

And that's it! IL Instructions can be a lot more indepth than that but with referring to the cheat sheet you should be able to figure a lot of stuff out on your own. Sometimes you want to change a function to always return true, and editing the method returns errors when saving. Instead you'd just edit the IL Instructions directly and find the call "ldarg.0", which loads a 0 into the stack (0 being false). You'd click it and receive a dropdown of all available OpCodes, simply find "ldarg.1" to load a 1 into the stack (1 being true) and save. You'll find these calls just prior to a return call which is "ret".


I actually googled the name of your link and found the post I ended up getting the dll to work. Its unconventional but all the corresponding IL's after the ones I modify that threw and error I replaced with NOP and it works lmao. An admin can close this post if needed


Happy days I'm glad you got it sorted out
Users browsing this topic: None
Jump to:


RECENT POSTS

HOT TOPICS