Page 1 of 2

[MOD Idea] FTL Advanced Modding API (Anyone know C/C++?)

Posted: Sat Sep 05, 2015 3:53 am
by BFrizzleFoShizzle
As some of you know, I just released a mod that removes the player ship limits, written in C++, and am currently working on a multiplayer mod.

As everyone here seems very interested in being able to create more advanced mods, which cannot currently be made with classical mod tools, I've got an idea to propose.

When I started working on my multiplayer mod, I also had a plan to write an open-source API in C++, for easily interacting with FTL. This would include simple methods for adding hooks to useful functions, and simple interfaces for interacting with FTL structures in memory. Later on, I was thinking of adding some scripting language such as Lua in order to make writing scripts for it somewhat easier, as C++ isn't exactly the simplest of languages.

I probably won't be working on that in any significant capacity till after the multiplayer mod is several months further in development. However, if someone around here is familiar with c/c++, I could probably write up enough methods for hooking functions and interacting with FTL's memory that they could write the rest.

This would allow modders to do many things, including but certainly not limited to:
custom races
Weapons that disable doors, or force them to open
more complex events
Shields that block projectiles based on complex conditions (e.g. only blocks missiles)
potentially adding new ship systems, or modifying how existing ones work
Maps that get modified as the user plays (e.g. only show beacons on the map that the user can currently move to)
Make shields use continuous values (e.g. shield at 100%, charges 10% per second, weapon X does 11.5% shield damage)
Modify how sectors work (e.g. be able to go to previous sector)
Modify which ship the user has (e.g. being able to steal enemy ships, or purchase a new ship)
pretty much any insane thing you could think of

So, is there anyone out there with C/C++ experience who would want to help make this?


Re: [MOD Idea] FTL Advanced Modding API (Anyone know C/C++?)

Posted: Sat Sep 05, 2015 7:52 pm
by kartoFlane
This would be extremely useful, far more than the ability to add new ships. I'd be interested in trying my hand at this, though I can't promise anything, seeing as my C/C++ skills are rather abysmal... I certainly wouldn't be able to deal with the intricacies of C, Windows interfacing, and all the other black magic I've seen you perform in the Github repo :P

Depends on what you expect the other programmers to do, really. As long as I have relatively high-level hooks / function calls to work with, I'll probably be able to make some stuff, with some additional research.
Some of the other programmers that lurk these forums might also be interested enough to check it out.

Re: [MOD Idea] FTL Advanced Modding API (Anyone know C/C++?)

Posted: Sat Sep 05, 2015 8:06 pm
by Gencool
I haven't touched C since I was a kid and my dad got a bbc from work, but daaammn that list makes me want to learn.

Like karto said - if there's any easy stuff I could help with, I'd love to pitch in (particularly if there's any crew/animation stuff involved - I pretty much know the surface system inside-out now)

Re: [MOD Idea] FTL Advanced Modding API (Anyone know C/C++?)

Posted: Sun Sep 06, 2015 11:43 am
by Chrono Vortex
If you want people who can do more than just xml coding, you should probably talk the the Hyperspace Admirals devs like rannl and Sleeper Service. I'd be happy to design new UI components that would be required though.

Re: [MOD Idea] FTL Advanced Modding API (Anyone know C/C++?)

Posted: Tue Sep 08, 2015 10:16 am
by BFrizzleFoShizzle
So, I've looked into things a bit further. I think I've decided on the "ChaiScript" scripting language, since it's simple to use (somewhat ECMAScript-inspired) and super easy to integrate C++ code with.

As far as others helping, I mostly need people to write and test wrapper classes for the structs in memory. These need to be created to stop bad things happening when objects are accessed when they don't exist in memory.
An example of this problem is with the player ship. The player ship isn't created until you leave the hangar. This means without a wrapper class, if a modder tried to get the player ship health before the player ship is created, you would get a segfault. By creating a wrapper object, you can check if a player ship currently exists before accessing the player ship pointer, and throw a nice, non-SEH exception that the ChaiScript can handle.

I'll push some code onto GitHub in a bit showing what I mean.
For now, here's a proof-of-concept teaser:
The script is getting the player ship's current health, and drawing it on the screen.

Re: [MOD Idea] FTL Advanced Modding API (Anyone know C/C++?)

Posted: Wed Sep 09, 2015 12:27 am
by BFrizzleFoShizzle
Set the Git repo up.
I guess I'll have to make some documentation at some point, maybe a wiki?
I also made a quick vid of the example script from the repo running in FTL:

Re: [MOD Idea] FTL Advanced Modding API (Anyone know C/C++?)

Posted: Fri Oct 16, 2015 10:13 am
by BFrizzleFoShizzle
It's been just over a month since my last post, so I thought I'd show you guys where I'm at.

I've been working on improving the hooks (which are used to inject code into FTL's methods in memory), which took some solid effort. The new hooks I wrote automate a lot of work I had to do myself, so that should make adding new hooks a crapload easier.
I've also been working on writing a GUI library in ChaiScript, and after weeks of messing around, I've finally got an in-game ChaiScript console running!
For some reason, the performance is terrible while running it, which I think is to do with the windows message hooks I'm using to get keyboard and mouse input. That should be fixable, though.
The console will make testing new code a million times easier.

I've also decided that the API DLL will only provide a low-level interface. The base API will be a direct conversion of the C++ API, which is based entirely around how things exist in memory. I will, however, release a series of "standard ChaiScript libraries" that will provide a better layer of abstraction than the raw C++ API.
An example would be the events library ("eventslib.chai" in the repo), which will provide an event/listener interface similar to javascript and actionscript, which will likely be cleaner to work with than the addXHook functions defined by the DLL.

I'm going to pause work on the ChaiScript API while I do more development on the multiplayer mod, as that's been lagging behind. If someone wants to help with developing the API, as I mentioned before, I'm going to need wrapper classes made. An example of what I mean is the ShipWrapper class defined in FTLShip.h/FTLShip.cpp. They shouldn't be too hard to implement, but it's time-consuming making and testing them.

Re: [MOD Idea] FTL Advanced Modding API (Anyone know C/C++?)

Posted: Fri Oct 16, 2015 9:21 pm
by R4V3-0N
That is... interesting.

Re: [MOD Idea] FTL Advanced Modding API (Anyone know C/C++?)

Posted: Sat Oct 17, 2015 12:09 am
by kartoFlane
Awesome progress -- sorry I didn't really get to help, I got sidetracked with life stuff and other projects. I'll try my hand with the wrappers when I find the time, they indeed seem like a simple enough task. Though I have no experience whatsoever with DLL injection, I'll need to research that...

Re: [MOD Idea] FTL Advanced Modding API (Anyone know C/C++?)

Posted: Sun Aug 14, 2016 9:49 pm
by SumoToad987
Are you still working on this or have you stopped in order to work on your multiplayer mod?