Hard-coded FTL Modding

Discuss and distribute tools and methods for modding. Moderator - Grognak
User avatar
NarnKar
Posts: 778
Joined: Thu Jun 19, 2014 4:24 pm

Re: Hard-coded FTL Modding

Postby NarnKar » Sun Mar 12, 2017 6:03 pm

Arguably the most important request in this thread so far:

Can you document your work somewhere? Give us a log of all the bytes you're changing and what byte changed does what, the name of the debugger program you're using, etc. Maybe, if you've written a custom assembly injector, put the code for that on Github?

I'd just like this stuff documented, so that (god forbid) if you leave/vanish from the forums, we at least have some work to go off of.
Northern_Warrior
Posts: 65
Joined: Sun Feb 26, 2017 2:34 pm

Re: Hard-coded FTL Modding

Postby Northern_Warrior » Tue Mar 14, 2017 12:00 pm

Katabatic wrote:Can you change the thruster animation placement on the kestrel & fed cruisers? I hate not having working animations on my custom fed cruiser.

http://www.ftlgame.com/forum/viewtopic.php?t=2725
Above link says it is impossible to change the thruster positions as they're hard-coded.

I can but right now I'm not as focused on graphical changes, and I'll need to dig in to the code a bit more for that.
mr_easy_money wrote:okay, I think I understand what you're doing... sorta. obviously since I hardly know assembly it's hard to picture what exactly you're doing, but you need not describe that.

I was just thinking of some sort of documenting what changes you've made, so that if someone were to do this, they'd know what you've "discovered". if you do make a tutorial, it should be for people who already know the prerequisite knowledge you have (not newbies like me).

maybe some people are interested? who knows? what you're delving into is pretty much untouched material...

Yes, I think I will share what I found, perhaps make a tutorial. Right now I'm re-organizing my code so I can have a better overview of everything.
NarnKar wrote:Arguably the most important request in this thread so far:

Can you document your work somewhere? Give us a log of all the bytes you're changing and what byte changed does what, the name of the debugger program you're using, etc. Maybe, if you've written a custom assembly injector, put the code for that on Github?

I'd just like this stuff documented, so that (god forbid) if you leave/vanish from the forums, we at least have some work to go off of.

I've been using Cheat Engine 6.6's memory viewer, disassembler and debugger to edit the assembly code, while using its other features to create a program in lua to inject that code into the game by pressing F5.
As for documenting my work, I'm thinking about creating a tutorial on all the values and code I've found so far ( so, all the addresses, bytes and opcodes I've edited ). Right now, I'm working on re-organizing my code to look better, so I can have a better overview of everything. While this will take some time, perhaps I'll release the non-buggy features soon and let everyone test them out.
User avatar
Marinealver
Posts: 55
Joined: Thu Jan 24, 2013 1:20 pm

Re: Hard-coded FTL Modding

Postby Marinealver » Thu Mar 30, 2017 9:07 am

Can you put custom crew on the Rebel flag ship? Here is an idea.
Image
The Rebel General from the animated series the Kestrel Adventures.
https://www.youtube.com/watch?v=eg4eSwuxSgA
Warp Drive or Hyperspace?
User avatar
fdagpigj
Posts: 84
Joined: Sat Apr 25, 2015 3:14 pm

Re: Hard-coded FTL Modding

Postby fdagpigj » Fri Mar 31, 2017 8:58 pm

Hmmm, I haven't kept up with the forums too well lately, so I missed this... damn, you're making this stuff seem like it might actually turn into something modders could practically use for their mods one day.

Of course, a few "technical" questions come to mind right away. First of all, do you have any clue if this'll work on all three operating systems? Do you know if there are tools available to do this kind of thing on the other OS'es? Would a mod made for one work on all? I imagine this is a bit tough for you to answer since most people don't have access to computers to test all of the three, but being able to target all three desktop platforms will be key to successful integration into casual users' modded FTL experience.

One thing of course will be safety, since I imagine if it injects assembly code into the program it could be used to transfer viruses... even if this does become reality it might not be very safe to run other people's mods, and given it's assembly it's not gonna be particularly readable to more than a very very small fraction of users, meaning it's very hard for anyone to verify that a mod is safe to use. And if the risk of using it is too great, then it would never lift off because people wouldn't dare to play the mods.

Third thing... please do make a video tutorial, I and many others are extremely curious about how to do this and getting any people from the community with assembly knowledge working on this stuff could speed up the process of turning it into a reality by quite a bit.

I am hyped, but I won't request you to do anything specific (nor will I be truly amazed) until others can install the mods you create - because otherwise this'll fall flat just like many other projects of comparable nature involving FTL.
User avatar
NarnKar
Posts: 778
Joined: Thu Jun 19, 2014 4:24 pm

Re: Hard-coded FTL Modding

Postby NarnKar » Sun Apr 02, 2017 5:23 am

fdagpigj wrote:First of all, do you have any clue if this'll work on all three operating systems? Do you know if there are tools available to do this kind of thing on the other OS'es? Would a mod made for one work on all?


The best thing I can think of is using virtual machines to test.

fdagpigj wrote:One thing of course will be safety, since I imagine if it injects assembly code into the program it could be used to transfer viruses...


I'm not entirely sure it's assembly; it might be bytecode? IDK. If it's a series of hex values it's bytecode, but Northern_Warrior hasn't posted any example code. There is a difference between bytecode and assembly, at any rate.

One thing I thought of for mass/casual distribution was this:

Step 1: Figure out what bytecode does what, and come up with a working, documented set of bytecodes. Let's say, for example, %33 %55 in line 77 changes the zoltan shield value to 8. (This isn't a realistic example, but bear with me.)

Step 2: Come up with a program, similar to Slipstream Mod Manager. I'll call it FTL Runtime Mod Loader (RML).

Runtime mods will be written in their own language. A runtime modder wouldn't write "%33 %55 in line 77" in a text file, they would write "SET ZOLTAN_SHIELD 8". Then, the java program automatically translates "SET ZOLTAN_SHIELD 8" into the proper bytecode (%33 %55 in line 77), and automatically handles translating and injecting it.

For modders who aren't interested in the inner workings, the RML program will abstract away the need to write bytecode. For users interested in runtime mods, they can trust the RML program to generate the correct bytecode, rather than trust random bytecode files on the internet.
Phantom332
Posts: 2
Joined: Sat Jan 07, 2017 4:07 pm

Re: Hard-coded FTL Modding

Postby Phantom332 » Sun Apr 02, 2017 12:40 pm

I can only say one thing:
Holy Shit!
User avatar
Marinealver
Posts: 55
Joined: Thu Jan 24, 2013 1:20 pm

Re: Hard-coded FTL Modding

Postby Marinealver » Wed Apr 12, 2017 3:05 am

Northern_Warrior wrote:
Katabatic wrote:Can you change the thruster animation placement on the kestrel & fed cruisers? I hate not having working animations on my custom fed cruiser.

http://www.ftlgame.com/forum/viewtopic.php?t=2725
Above link says it is impossible to change the thruster positions as they're hard-coded.

I can but right now I'm not as focused on graphical changes, and I'll need to dig in to the code a bit more for that.
mr_easy_money wrote:okay, I think I understand what you're doing... sorta. obviously since I hardly know assembly it's hard to picture what exactly you're doing, but you need not describe that.

I was just thinking of some sort of documenting what changes you've made, so that if someone were to do this, they'd know what you've "discovered". if you do make a tutorial, it should be for people who already know the prerequisite knowledge you have (not newbies like me).

maybe some people are interested? who knows? what you're delving into is pretty much untouched material...

Yes, I think I will share what I found, perhaps make a tutorial. Right now I'm re-organizing my code so I can have a better overview of everything.
NarnKar wrote:Arguably the most important request in this thread so far:

Can you document your work somewhere? Give us a log of all the bytes you're changing and what byte changed does what, the name of the debugger program you're using, etc. Maybe, if you've written a custom assembly injector, put the code for that on Github?

I'd just like this stuff documented, so that (god forbid) if you leave/vanish from the forums, we at least have some work to go off of.

I've been using Cheat Engine 6.6's memory viewer, disassembler and debugger to edit the assembly code, while using its other features to create a program in lua to inject that code into the game by pressing F5.
As for documenting my work, I'm thinking about creating a tutorial on all the values and code I've found so far ( so, all the addresses, bytes and opcodes I've edited ). Right now, I'm working on re-organizing my code to look better, so I can have a better overview of everything. While this will take some time, perhaps I'll release the non-buggy features soon and let everyone test them out.

Okay, about crew changes is there changes to functionality as well as sprites? Such as one takes less fire damage? or one has higher health. And is there a way to spawn them in scripted events such as a Dread Pirate Tuco sptie in the Dread Pirate Tuco encounter?
Warp Drive or Hyperspace?
BFrizzleFoShizzle
Posts: 17
Joined: Sun Jul 19, 2015 3:43 am

Re: Hard-coded FTL Modding

Postby BFrizzleFoShizzle » Thu Apr 27, 2017 6:24 am

So, someone flicked me a message and lead me to this post, and I figured I should leave a message.

A while back, I was working on writing a scripting API for FTL (https://github.com/BFrizzleFoShizzle/FTLAPI) that would have allowed modders to easily modify "hard-coded" features using a programming language called ChaiScript (which is very similar to JavaScript).
I've got a document containing reverse-engineered structs and useful pointers which you might find useful here: (https://github.com/BFrizzleFoShizzle/FT ... everse.txt)
I've actually got a longer doc with more structs and pointers on one of my machines somewhere... if you wanted I could probably find it for you?

I originally started working on that project as a side project to making an FTL multiplayer mod, since I had to build an API for interacting with the FTL process either way. I stopped working on both of those projects a couple years ago, as I didn't have enough time to work on it by myself and couldn't find any other programmers to help. I don't know what your programming and reverse-engineering skills are like, but if you're interested, I'd be happy to go back to working on either (or both!) of those projects if I could get some help.
BFrizzleFoShizzle
Posts: 17
Joined: Sun Jul 19, 2015 3:43 am

Re: Hard-coded FTL Modding

Postby BFrizzleFoShizzle » Thu Apr 27, 2017 7:36 am

I might as well answer some questions while I'm around. I'm not OP, but I know plenty about this stuff.

fdagpigj wrote:First of all, do you have any clue if this'll work on all three operating systems? ...
Would a mod made for one work on all?

This method works on all operating systems, but you pretty much have to implement your "mod" separately for each platform. If the FTL executable was compiled with a different compiler on different platforms, the assembly code will almost certainly be completely different between executables. This means you will have to reverse-engineer the game 3 times, and implement your mod 3 times.

fdagpigj wrote:Do you know if there are tools available to do this kind of thing on the other OS'es?

There definitely are.

fdagpigj wrote:One thing of course will be safety, since I imagine if it injects assembly code into the program it could be used to transfer viruses

This is 100% true. If you're running a script that modifies the game's code, you are effectively giving the script 100% control of your computer. From a security perspective, it's the same as running an executable that someone has made. Ideally, you would want "mods" like this to be open-source so that you can read through the source code and make sure it's safe, and you have a good point that mods that involve modifying assembly could be quite hard to read.
There are a whole lot of windows reverse-engineering tutorials on the internet. If OP disappears, I could probably make an FTL-specific video tutorial, but any "complicated" modification is going to require modders have a whole lot of experience with this stuff, and one tutorial really won't be enough to get people there.

NarnKar wrote:I'm not entirely sure it's assembly; it might be bytecode? IDK. If it's a series of hex values it's bytecode

"Machine code" is the binary code that your CPU executes.
"Bytecode" reffers to machine code designed for a virtual machine (i.e. a fake CPU, e.g. Java)
"Assembler" is a human-readable textual representation of machine code.
For example, the x86 Assembler instruction "pop eax" is represented as the hexadecimal byte "58" in x86 machine code (or "1011000" in binary if you're an edgy kid).
A disassembler (what OP and any sane reverse-engineerer uses) displays a program's code as assembly, human-readable machine code. Usually, the disassembler will also have the hexadecimal machine code representation for each displayed instruction juxtaposed next to it.

NarnKar wrote:One thing I thought of for mass/casual distribution was this:

This is exactly what I was working on two years ago! Except it exposed a full-feature programming language for modders to use, with simple-to-use hooks so they could change core aspects of the game in any way they wanted. Unfortunately, at the time I couldn't find anyone to work on it with me, and I really did not have enough time to implement it by myself (work, uni, etc :roll:). Again, if there are any programmers around here who want to help, I'd be more than happy to start working on that project again.

And here's my input for anyone interested in this thread:
Working in assembler isn't particularly easy to get into, even for people with existing programming experience. In fact, there's a beautiful image on the internet that sums it up pretty well:
Image
That's why I was previously working on building a simple scripting API built on top of my own interface with the game, so that no modder would have to come anywhere near the game's machine code. this would also allow modders to write their mod on one platform and have it work on all. It would also alleviate some of the security concerns, since the interface layer between FTL and the modders scripts is the only part that would need to have access to the game's assembly. The modders scripts themselves wouldn't need to directly modify the game's assembly at all.

Apart from that, to answer all your questions of what is and isn't possible, literally anything is possible when "modding" the assembly in the game, since you are literally re-programming the game.

Wow... this post ended up a whole lot longer than I thought it would.
/rant over
User avatar
NarnKar
Posts: 778
Joined: Thu Jun 19, 2014 4:24 pm

Re: Hard-coded FTL Modding

Postby NarnKar » Fri Apr 28, 2017 6:01 pm

Thanks for the clarification on terminology, BFrizzleFoShizzle.

(I've seen that image before, it's hilarious, but I shudder thinking about it every time)

I might be interested in collaborating, and it's definitely an interesting project. But even though I took a course that involved assembly, I wouldn't call myself an expert in it. If I joined, I'd probably need some assistance before I knew what I was doing. And I already pledged some assistance to this thread, so I'm not really sure if I would have the time to dedicate to two massive FTL-related efforts.

The other thing is that if John Luke Pack Hard's Overdrive gets off the ground, it kind of makes assembly/"run-time modding" obsolete. The converse is true; if run-time modding takes off, then there's not really a need to clone FTL or make Overdrive.

/shrug