Admiring the code

General discussion about the game.
gir489
Posts: 11
Joined: Fri Aug 02, 2013 3:09 pm

Admiring the code

Postby gir489 » Tue Aug 13, 2013 2:45 am

It's no secret that FTL is a good game. But nobody really takes the time to look at how the games are built. They just only see the end product and what's displayed. Most people are just not skilled enough or flat out don't care. But for the 12 whole people who played FTL and can program, this thread is for you. I'm going to be talking about my experience reverse engineering this game and what I liked.

The first thing I reversed was the power set function. I placed a breakpoint on the total power variable and found which function was changing it.

PowerSetCall.png
(The comments, function named and variable names are self-assigned, I do not know what the programmers actually called them.)

The first thing I noticed is that it's a __thiscall. This means it's a virtual function. So I thought: "huh, that's odd." I've never really seen vfuncs done well before in a video game engine, mainly because of abstract nature of video game coding, and the all around general lack of skill most video game programmers possess. This is mainly the reason so many people are able to hack games, because some of the code jobs for the engine are just so trash it's easy to exploit. Using vfuncs is great because you can incorporate polymorphism in to your classes. For example, there's many types of ships in FTL. Not all ships might use the same sort of power consuming rules as others. So, what'd you do is say the Kestrel is the base class for all ships. Each ship extends the Kestrel class, but overwrites the function PowerSetCall. Maybe the engi ship gives free power to the health station, or the rock crew allows 2 free pegs of power to the engine. This could all be done with function overriding.

So right off the bat, they're headstrong with OOP standards.

After a while of reversing the engine, I found that I couldn't find things in the code such as rebel advancement and map progress. I later found out that the game utilizes an XML file to load and create levels dynamically based on a set of rules set by the code. So in essence, they could make Q&D DLC for continuing the game. I don't know why they haven't, but I guess they have their reasons. From this I was able to easily edit things I wanted such as map progress, rebel advancement, adding and changing weapons. Fixing some minor bugs I found with the laser cannon's cooldown. All of this neatly zipped in a DAT file that was decompiled with some fairly simple tools.

I can tell these programmers have had some experience in the past either professionally or with professional game programmers and they have learned well.

I tip my hat to you programmers of FTL. I've reversed some really good video game engines (UE3) and I've reversed some really shitty ones (CoD) and I'd rate FTL a 9 out of 10 on the code readability and functionality.
UltraMantis
Posts: 2141
Joined: Thu Sep 20, 2012 3:17 pm

Re: Admiring the code

Postby UltraMantis » Tue Aug 13, 2013 7:50 am

I think this is a first post of it's kind on the forum.

All comments regarding FTL programming have universally been negative. Modders will be inclined to gripe since they dislike hardcoding but even beyond moddability, the comments we're usually that it's a rushed mess. Of course it probably also depends on the knowledge on the person. Nice to read some love for the code. :)
Report spam using the handy Report Button Mod.
gir489
Posts: 11
Joined: Fri Aug 02, 2013 3:09 pm

Re: Admiring the code

Postby gir489 » Tue Aug 13, 2013 2:30 pm

UltraMantis wrote:I think this is a first post of it's kind on the forum.

All comments regarding FTL programming have universally been negative. Modders will be inclined to gripe since they dislike hardcoding but even beyond moddability, the comments we're usually that it's a rushed mess. Of course it probably also depends on the knowledge on the person. Nice to read some love for the code. :)

Nothing is "hardcoded." In fact, I could write a VMT hook to dynamically hook all the vtables to replace code with custom functions on runtime.

I think they're just mad they can't use XML to replace everything. I think they used XML as a Q&D approach to balancing the game so they didn't have to recompile every time they wanted to add/remove something from weapons/ships/events.
iceburg333
Posts: 67
Joined: Tue Jun 25, 2013 8:52 pm
Contact:

Re: Admiring the code

Postby iceburg333 » Wed Aug 14, 2013 2:08 am

gir489 wrote:
UltraMantis wrote:I think this is a first post of it's kind on the forum.

All comments regarding FTL programming have universally been negative. Modders will be inclined to gripe since they dislike hardcoding but even beyond moddability, the comments we're usually that it's a rushed mess. Of course it probably also depends on the knowledge on the person. Nice to read some love for the code. :)

Nothing is "hardcoded." In fact, I could write a VMT hook to dynamically hook all the vtables to replace code with custom functions on runtime.

I think they're just mad they can't use XML to replace everything. I think they used XML as a Q&D approach to balancing the game so they didn't have to recompile every time they wanted to add/remove something from weapons/ships/events.

Man Gir489, you really sound like you know your stuff! It's really cool to hear that FTL was well programmed, and that you were having success reverse engineering it. I just started learning Java this summer, and so it was cool to read your post and understand (for the most part) what you were talking about. I'm really loving learning OOP... :D

Out of curiosity, have you checked out theFTL Overdrive thread? Some programmers are trying to reverse engineer FTL so that it's open source and more modable, but I think progress has stalled. I think it might be something you'd be interested in?

Anyway, cool to hear FTL has found yet another good programmer. :D
Ice
Image
aaaaaa50
Posts: 258
Joined: Thu Apr 11, 2013 9:08 pm

Re: Admiring the code

Postby aaaaaa50 » Wed Aug 14, 2013 4:51 am

All FTL modding has been XML stuff since the game released. If you've got the coding chops to modify things beyond that, then you've basically got the keys to the forbidden kingdom.

And I'm really disappointed that the devs barely make changes to the game anymore. Even with modding being really limited, there's been so much content made that most potential DLC is already pointless.
First ever AE-exclusive ship mod: The Extra Features!
Ye Olde and Outdated Pre-AE Ship Mod Recommendation List!
User avatar
Sleeper Service
Posts: 2305
Joined: Sun Mar 24, 2013 8:49 pm

Re: Admiring the code

Postby Sleeper Service » Wed Aug 14, 2013 10:41 am

gir489 wrote:I later found out that the game utilizes an XML file to load and create levels dynamically based on a set of rules set by the code. So in essence, they could make Q&D DLC for continuing the game. I don't know why they haven't, but I guess they have their reasons.


Well yeah, that's what the whole modding community is about... there are no official DLC, but modders have created dozens of deeply game changing modifications since release, by modifying the xmls. You might want to check out the modding section of the forum. Few of us are coders though (I guess, well I'm definitely not) so the stuff you poke around in there is indeed a big mystery to many. :shock:

While I'm sometimes disappointed that the code/xml structure doesn't allow me to do everything I want with the game, I'm still very glad that FTL is at last modifiable to the degree it is. As far as I can guess that wasn't even directly intended. I think the xml's exist to make balancing, adjusting and patching the game easier? Well what do I know...
gir489
Posts: 11
Joined: Fri Aug 02, 2013 3:09 pm

Re: Admiring the code

Postby gir489 » Fri Aug 16, 2013 1:23 am

iceburg333 wrote:
gir489 wrote:
UltraMantis wrote:I think this is a first post of it's kind on the forum.

All comments regarding FTL programming have universally been negative. Modders will be inclined to gripe since they dislike hardcoding but even beyond moddability, the comments we're usually that it's a rushed mess. Of course it probably also depends on the knowledge on the person. Nice to read some love for the code. :)

Nothing is "hardcoded." In fact, I could write a VMT hook to dynamically hook all the vtables to replace code with custom functions on runtime.

I think they're just mad they can't use XML to replace everything. I think they used XML as a Q&D approach to balancing the game so they didn't have to recompile every time they wanted to add/remove something from weapons/ships/events.

Man Gir489, you really sound like you know your stuff! It's really cool to hear that FTL was well programmed, and that you were having success reverse engineering it. I just started learning Java this summer, and so it was cool to read your post and understand (for the most part) what you were talking about. I'm really loving learning OOP... :D

Out of curiosity, have you checked out theFTL Overdrive thread? Some programmers are trying to reverse engineer FTL so that it's open source and more modable, but I think progress has stalled. I think it might be something you'd be interested in?

Anyway, cool to hear FTL has found yet another good programmer. :D
Ice

Yes but they took the easy way out by trying to code it in Lua. This was one of the dilemmas when I tried to apply for a programmer position on Final Frontier mod. All of the code was in Lua and I don't want to learn such a garbage language. I prefer more low level languages because when you translate languages in to byte code then to processor code, you have a much greater chance to have your code lost in translation. I write remote code execution hacks for the JVM and then sell them to a friend who does pentesting for a good chunk of cash. 90% of the exploits I find are a problem with the JVM and/or the stock libraries themselves. It's mainly because the JVM has a hard time testing and figuring out which code is bad code and which code is good code. It can't really tell because bytecode is bytecode. It's not like C++ remote code execution where you're trying to run ASM off the stack, the ASM is very platform dependent. You need to find a position in the code that you can overflow EIP to a JMP ESP instruction. With Java, you can basically RCE an entire fucking program off one piggyback. I don't want to get in to a rant about why Java is trash, it's very clear why it's garbage and why it should not be used, but yet I constantly get tasked to Java projects.

You have to remember, when dealing with anything you need native code. No matter what you're doing. Even web-based Java code still needs a Java driver to interface with the database or the JVM needs a file parser. You can't stay inside you little VM bubble forever. With the FTL developers using C++, I highly doubt they gave 2 shits or a fuck about the mod community, and why should they? Their job was to make a game. They did it. Huzzah. So it's not Lua skiddie friendly. Cry a river. But I will say it's very C++ friendly. If you have even the most basic knowledge of C++, you could easily reverse the entire game. If anyone has IDA 6.1 and would like my notes on FTLGame.exe, you can PM me.
UltraMantis
Posts: 2141
Joined: Thu Sep 20, 2012 3:17 pm

Re: Admiring the code

Postby UltraMantis » Fri Aug 16, 2013 3:29 am

Seems harsh, but i will not get into it. I'm barely literate. ;)

I will say that FTL devs were 2 people (disregarding music and writing assistance which included another 2) and with a hugely succesfull Kickstarter they probably had to focus on delivering the game that was promised, getting it working on three platforms and pretty much nothing else. Moddability was never a realistic option, and what exists today is down to community efforts.
Report spam using the handy Report Button Mod.
textheavy
Posts: 17
Joined: Fri Jul 26, 2013 8:33 am

Re: Admiring the code

Postby textheavy » Sat Aug 17, 2013 12:17 am

I enjoy the game more than most I've paid for.

The code may be admirable for a number of reasons, but I have to wonder why a game that is so graphically unsophisticated, and spends most of its time paused, hogs so much of my system's resources that my machine's fan has to kick up to the highest setting.

Last night I was playing with a small browser window open to stream a Netflix video, and both the video and FTL kept going unresponsive for blocks of time. This happened even outside of combat, and when paused during combat.

It surprised me, because it doesn't seem like FTL should require so much in terms of system resources, particularly when it's basically idle.
User avatar
Twinge
Posts: 281
Joined: Thu Sep 20, 2012 4:04 am
Contact:

Re: Admiring the code

Postby Twinge » Sat Aug 17, 2013 10:51 am

gir489 wrote:Fixing some minor bugs I found with the laser cannon's cooldown.


What're you referring to here out of curiosity?


What're you using to decompile? My only experience in this area was actually disassembling ADOM code with someone's help; assumedly you aren't needing to resort to assembly in this case. I've loosely considered investigating decompile possibilities for further enhancing the Balance Mod, but wasn't sure it'd really be worth the time it took. (As one example, I'd like to reduce the experience required to level up in Shields.)
FTL Tips & Tricks Video Series

Catch my stream on Twitch

Improve game balance, fix bugs, and have more decisions: Twinge's Balance & Bugfix Mod

Who is online

Users browsing this forum: No registered users and 24 guests