8 ms·
The real Terraria code isn't much better. Here's their 3MB [decompiled] NPC.cs: https://raw.githubusercontent.com/csnxs/Terraria/67de21a27e1947ee334ac8dc80d9adb
by Scaevolus 9y ago
The real Terraria code isn't much better. Here's their 3MB [decompiled] NPC.cs: https://raw.githubusercontent.com/csnxs/Terraria/67de21a27e1947ee334ac8dc80d9adb3973cd708/Terraria/NPC.cs https://raw.githubusercontent.com/csnxs/Terraria/67de21a27e1...
They had serious problems implementing multiplayer because they had to synchronize objects with 50KB of state every frame.
- warent 9y agoI just scrolled to the bottom and all I see is } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } What the fuck
- mikeash 9y agoThis is decompiled code, not the original source, so much/most/all of the craziness probably comes from that.
- danbruc 9y agoDecompiling .NET or Java binaries usually yields code very close if not identical to the original source code, at least unless an obfuscator was used but that seems not to be the case here. Chances are very good the original source code looks almost exactly like that code, maybe with some additional comments.
- amyjess 9y agoMind you, a lot of Java 5 and later features like generics, switch on Strings, Iterable-based for, etc., are syntactic sugar implemented in the compiler, not part of Java bytecode, so those features don't decompile well.
- thefifthsetpin 9y agoIn this case, it's just that the decompiler didn't think of "else if" as a single control flow construct/keyword in the way that the original programmers did. What was no doubt written like this: if(a < 1){ }else if(a < 2){ }else if(a < 3){ }else{ } Decompiled into this: if(a < 1){ }else{ if(a < 2){ }else{ if(a < 3){ }else{ } } }
- danbruc 9y agoI will try this tomorrow, I am pretty sure dotPeek can recognize and output else if. Might be a coding style option though.
- mikeash 9y agoWouldn’t “else if {“ and “else { if” compile to identical bytecode?
- ufo 9y agoSure, but the decompiler can choose to always decompile to "else if {", which is more readable and more likely to match the original source code.
- mikeash 9y agoThat's my point. The compiler's choice of "else if {" or "else { if" is unrelated to the programmer's choice.
- danbruc 9y agoIt does and at least the current dotPeek 2017.2.2 decompiles it to else if and does, other than I thought, not allow to customize it.
- mikeash 9y agoObviously whatever decompiler was used here decided to do it the other way.
- MrMember 9y agoWow, I just glanced at the how they're generating random names and it's incomprehensible. What a bizarre way to do something rather simple.
- mattchamb 9y agoMy guess is they are using partial classes and generating a bunch of the code from other, much simpler files.
- monsieurbanana 9y agoSurely this file can't be edited by humans as is, right?
- XR0CSWV3h3kZWg 9y agoThis looks as if this was a compile target, not the source code. HitEffect is a quite the function. This reminds me of working on CDDA[1] before many of the refactors hit. CDDA is an interesting case, it stemmed from a situation similar to the original post (one person project, embarked upon it before knowing how to do so). It was a complete mess of macros, spaghetti code and data and code living happily side by side. https://github.com/CleverRaven/Cataclysm-DDA https://github.com/CleverRaven/Cataclysm-DDA
- TeMPOraL 9y agoIt was, or still is? Also, are you still working on it? I'm currently having lots and lots of fun playing this game (experimental builds). It's pretty much halfway there to Dwarf Fortress...
- XR0CSWV3h3kZWg 9y agoI stopped many years ago. I was working on it in between sending out job applications, I was happy to gain experience working on a code base larger than I felt comfortable reading and one that is ugly but a rewrite is not an option. I didn't add too many features, I was mostly reducing the amount of compiler noise and fixing any bugs I ran across.
- kbenson 9y agoFrom the first couple hundred lines, they obviously know how to use a switch statement (as in how it works at least), but the odd cascade of if statements at the bottom makes me question whether they know when to use a switch statement (but then again, the stuff a the top makes me wonder that a bit as well). Edit: As someone else noted, if this is a generated file, that might explain a lot of this.
- jcl 9y agoPer the description on https://github.com/csnxs/Terraria/ https://github.com/csnxs/Terraria/ , this isn't the Terraria source code -- it's a decompilation of the binary.
- maxton 9y agoImportant to note is that this code is not the source code, but rather was generated by dotPeek, a C# decompiler, as mentioned in the repo's README: https://github.com/csnxs/Terraria/ https://github.com/csnxs/Terraria/
- Scaevolus 9y agoVariable names and comments are lost, but the overall control flow structure of decompiled Java and C# code closely matches the original.
- danbruc 9y agoEven variable names are usually not lost.
- TeMPOraL 9y agoStill - does that decompilation roll back any kind of array unrolling C# compiler may be doing (assuming it's doing it)? If not, it could explain those long chains of if/else seen in the decompilation. Maybe they're arrays of constants in the real code?
- kevindqc 9y agoThose SetDefaults methods.. ouch. On the plus side, it's fun to press the page down and see the code 'animate' from left to right
- k__ 9y agoyes, also that it comes back to the left after it hit the right end lol
- saltedmd5 9y agoThis gave me palpitations and then killed my browser.
- taw55 9y agoOh wow. That might explain a lot of my lag I’ve had when multiplaying on large maps (on LAN).