October 26, 2013

Terraria Server on Linux?

This isn't directly RomTerraria related, but could be related to how RomTerraria is going to be working going forward.

The biggest problem with making a non-source mod like RomTerraria is that every time the game changes, even if your code wouldn't normally be affected, your app completely breaks because the binding changes.  There's no way to ensure a consistent experience for your code.

With early versions of RomTerraria, I took advantage of the XNA component framework.  That gave me a perfect place to inject my code where it would work nicely with all of the code that already exists in the game.  However, with v1.2, the call to base.Draw() removed my ability to easily inject rendering calls for things like the minimap and HUD updates I had put in before.  In addition, since Terraria uses some Win32 calls internally, you can't really use Terraria in a non-Windows environment.

What would work out well was if I could take an arbitrary Terraria executable and inject code without distributing Terraria's code.  Fortunately, a tool set does exist for doing this: ildasm and ilasm. You run ildasm against Terraria.exe or TerrariaServer.exe and you get the MSIL for the executable.  You apply your patches, then run ilasm to recreate your executable.

Example disassembly:
ildasm TerrariaServer.exe /out=TerrariaServer.il

Example reassembly:
ilasm /32bitpreferred /output:TerrariaServerRecompile.exe TerrariaServer.il

Then you can just run TerrariaServerRecompile.exe and have a round-tripped server executable.

So what I was thinking of doing was writing dummy stubs for most of the interop code (NATUPNPLib.UPnPNAT, etc.) and trying to get TerrariaServer.exe able to run on Linux as an experiment.  If I can get this to work, I can then make the next step for RomTerraria: inject entry points directly into the Terraria executable without redistributing any Terraria code.

Thoughts?

4 comments:

Anonymous said...

https://github.com/Deathmax/TerrariaAPI-Server

Michael Russell said...

Zack,

The biggest downside to that tactic is that it requires disassembling client code and redistributing the modified code.

My hope is to make a rewriter that will inject hooks into the code and not redistribute any Terraria code (in accordance with the EULA).

Unknown said...

I think Zack understood your intentions and just wanted to clarify that a Linux compatible version exists.

Michael Russell said...

Hussein,

Understood completely.