I'm trying to understand how the procedural generation in a particular Unity 3D game works. I do not have the source code/project file, just a windows build.

I've opened up a dll called Assembly-UnityScript.dll with ILSpy and found some classes, but it's not immediately apparent how the classes are put together, i.e. how and when methods on the classes are called.

I've looked at some tutorials but they are all concerned with injecting their own code into the game. I'm just interested in how my target game does what it does.

Is there any straightforward way to figure out how the classes are used?

  • Sidenote: Its propably not worth the effort of reverse engineering for the purpose of reimplementation. There are tons of resources about procedural generation. Calculate a seed, generate 2d-noise (heightmap), tune in some parameters and use your seed for randomness. – Nordwald Oct 10 '17 at 6:24
  • Everything you need should be within Assembly-UnityScript.dll, have you tried exporting the files via ILSpy, and opening the project in Visual Studio? – Jacob Persi Oct 10 '17 at 17:10
  • @JacobPersi I have now. I opened the dll, clicked File -> Save Code, which produced a .csproj file along with the same .cs files I had seen inside ILSpy. I didn't expect building to work but I tried it anyways and the build errors out when it gets to a part in a CompilerGenerated namespace called __enterName_Update$callable0$30_61__. I'm guessing that's some kind of hook/callback back into the rest of the game, where the part I"m currently interested in takes place. – Ryan1729 Oct 10 '17 at 18:58

it's not immediately apparent how the classes are put together, i.e. how and when methods on the classes are called

I'm afraid there is no free lunch here.

What you can tackle this with two approaches:

  1. Static disassembly (look at the disassembled code and try to make sense of it)

  2. Dynamic analysis (e.g. use a debugger like dnSpy) This way you can 'watch' the acutal generation process.

  • Until this dnSpy issue is addressed, it looks like I'm stuck with option 1. That, or copying the disassembled code out, guessing at how the classes interact and creating an executable that generates stuff and debugging that. – Ryan1729 Oct 10 '17 at 19:33
  • You could also try any other debugger capable of debugging mono binaries. There are some VS plugins for that, or you could try command line debugging. – Nordwald Oct 11 '17 at 5:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.