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

Discuss and distribute tools and methods for modding. Moderator - Grognak
BFrizzleFoShizzle
Posts: 17
Joined: Sun Jul 19, 2015 3:43 am

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

Postby BFrizzleFoShizzle » Sat Sep 05, 2015 3:53 am

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?

*edit*
GitHub:
https://github.com/BrydenFrizzell/FTLAPI
Last edited by BFrizzleFoShizzle on Sun Oct 25, 2015 8:49 am, edited 2 times in total.
User avatar
kartoFlane
Posts: 1488
Joined: Mon Jan 14, 2013 10:20 pm

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

Postby kartoFlane » Sat Sep 05, 2015 7:52 pm

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.
Superluminal2 - a ship editor for FTL
User avatar
Gencool
Posts: 409
Joined: Sun Jun 16, 2013 1:21 pm

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

Postby Gencool » Sat Sep 05, 2015 8:06 pm

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)
ImageImageImage
- Gencool (aka Puppetsquid) -- I make weird stuff
User avatar
Chrono Vortex
Posts: 275
Joined: Thu Jun 25, 2015 8:51 pm

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

Postby Chrono Vortex » Sun Sep 06, 2015 11:43 am

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.
ImageImageImageImageImageImageImageImage
BFrizzleFoShizzle
Posts: 17
Joined: Sun Jul 19, 2015 3:43 am

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

Postby BFrizzleFoShizzle » Tue Sep 08, 2015 10:16 am

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:
Image
The script is getting the player ship's current health, and drawing it on the screen.
BFrizzleFoShizzle
Posts: 17
Joined: Sun Jul 19, 2015 3:43 am

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

Postby BFrizzleFoShizzle » Wed Sep 09, 2015 12:27 am

Set the Git repo up.
https://github.com/BrydenFrizzell/FTLAPI
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:
https://www.youtube.com/watch?v=ilr7y2gLtvI
BFrizzleFoShizzle
Posts: 17
Joined: Sun Jul 19, 2015 3:43 am

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

Postby BFrizzleFoShizzle » Fri Oct 16, 2015 10:13 am

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!
Image
Image
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.
User avatar
R4V3-0N
Posts: 1291
Joined: Sun Oct 06, 2013 11:44 am

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

Postby R4V3-0N » Fri Oct 16, 2015 9:21 pm

That is... interesting.
R4V3-0N, a dreamer.
User avatar
kartoFlane
Posts: 1488
Joined: Mon Jan 14, 2013 10:20 pm

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

Postby kartoFlane » Sat Oct 17, 2015 12:09 am

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...
Superluminal2 - a ship editor for FTL
User avatar
SumoToad987
Posts: 9
Joined: Thu Aug 11, 2016 5:07 pm

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

Postby SumoToad987 » Sun Aug 14, 2016 9:49 pm

Are you still working on this or have you stopped in order to work on your multiplayer mod?