How do I decompile and re-compile properly?

Started by mazacik, August 13, 2016, 07:42:58 AM

Previous topic - Next topic

mazacik

Hello, I wanted to get started with modding, but am unable to figure out what to do. I'm using ILSpy to decompile. After I load Assembly-CSharp.csproj into VB VS, everything seems to work okay. However, even without changing anything and trying to build / run the project, I get about 7000 errors, and 13 warnings.
So, how do I decompile rimworld's source code, make simple changes, and re-compile it all back into a working dll?

PS: before someone suggests to check Haplo's tutorial, I already did. Again, I didn't change a single line of code.

RawCode


mazacik

I'll take that as a bad attempt on a joke. Rimworld's unchanged source code should have minimal errors, not 7000 of them. I obviously did the decompiling / setup wrong, I'm just not sure what or how to solve it.

RawCode


Rihlsul

From what I've seen, decompiling only mostly works and shows you most of the code.   You'll find there are many functions that don't decompile very nicely, and across an entire game, 7000 of those seems likely.

mazacik


cuproPanda

Other than creating topics or reporting bugs, RawCode seems to only give useless information or insult people's intelligence. You'll get used to it.

You did do the setup wrong; you don't load the decompiled code into VB, you need to setup references to the assemblies (as described in Haplo's tutorial), then create your own classes. Decompiling the code can be very helpful in understanding how the code works, but if you just plug in the same code it'll cause problems - most of which come from the IDE not knowing what a ThingDef is, or what "using RimWorld" means.

Checking out modders' GitHubs might help you see how the code should be laid out. I have mine, and there are others as well you can find by going to their mod topics.
cuproPanda's Mods: Survivalist's Additions, Additional Joy Objects, Cupro's Drinks, Quarry, Cupro's Stones, Zen Garden, Cupro's Alloys, Preset Filtered Zones, & more!

RemingtonRyder

^ What he said.

If you need any more help, feel free to send me a message. I was new to this not so long ago.

1000101

Given that RimWorld isn't written in VB (VisualBasic), loading it in VB would produce thousands of errors.

You need to load it into a C# IDE (VisualStudio, Xamarin Studio, SharpDev) and then even you will get lots of errors due to the fact that no decompiler is going to supply a 1:1 translation of the compiled code to the source.  Anything with an enumerable returns or lambda expressions will have limited success in reconstructing the source code from the compiler generated code blocks.

Also, why are you trying to violate copyright by whole-sale decompiling and recompiling?  Tynans license and international copyright laws allow you to decompile small parts for usage in mods, educational purposes, etc, but a whole-sale decompile and recompile would be in far excess of that allowance.

TL;DR:  You're Doing It Wrong(tm).
(2*b)||!(2*b) - That is the question.
There are 10 kinds of people in this world - those that understand binary and those that don't.

Powered By

mazacik

#9
Yes, sorry, I'm using Visual Studio, not Visual Basic. Also, I'm not trying to violate copyright in any way, I'm just trying to make a small mod for personal use (for now) - however, my programming skills are lacking, so I'm figuring things out as I go (I didn't know I shouldn't decompile the whole code and then put it all back; a few other games did it like that - you load the whole thing, make changes, compile, a mod file is created containing only the changed values, with dependencies on the source).

Thanks for help, I think I've got the decompiling and setup parts right now. Since the game's source code seems to have an error in almost every single line, I'll work with Cupro's drinks mod I'm currently playing with, that is perfectly working, if I may. This way I can check the original source code. Now I only get 16 errors, 10 of which are "cannot explicitly call operator or accessor" pointing to lines with get_...() and the rest saying "cannot convert from 'int' to '...'. The first ten are clearly caused by the decompiler. The other few is a mystery for me, since Cupro's code looks very different to what I've got, as if someone deleted half of a line. Is this all the decompiler's fault? If so, can I do something about it?

RemingtonRyder

We could do with a look at the code you've come up with. Otherwise we'll just be guessing.

CallMeDio

I use iLSpy too and I always do my files based on game files or detouring game's methods and it never did any decompiling wrong. With exception of the yields that no decompiler can do properly. I would recommend you to check if your project is set to framework 3.5 (should be under compiling or building settings if I remember right) otherwise it will give errors.
QuoteYou may need a rubber duck.  Also, try some caveman debugging.

Released mods: No Mood Loss on Prisoner Sold or Died

RawCode

Quote from: cuproPanda on August 13, 2016, 03:45:09 PM
Other than creating topics or reporting bugs, RawCode seems to only give useless information or insult people's intelligence. You'll get used to it.

My information in this topic is perfectly correct and there is no other way.

If you unable to read post of TS, i will read it for you:

QuoteI decompiled GAME, not a single class, ENTIRE GAME and unable to compile it back.
I got 7000 errors, what should i do?

and yes, looks like i insulted someone again, sad story.

1000101

Rawcode tends to give technically correct answers (which are the best kind of correct) but sometimes not very helpful answers to people who aren't systems analysts or the like.

I'm sure he means no insult, it's just a pitfall of the language barrier and job.
(2*b)||!(2*b) - That is the question.
There are 10 kinds of people in this world - those that understand binary and those that don't.

Powered By

RemingtonRyder

I'm sure he has better things to do than dive bomb newbie topics and be as cryptic as Kosh.