Prototype Lua mod loader

Discuss and distribute tools and methods for modding.
AUTOMATIC
Posts: 24
Joined: Sun Mar 04, 2018 11:59 am

Re: Prototype Lua mod loader

Postby AUTOMATIC » Thu Mar 08, 2018 7:18 pm

How do you add new animations?

In animations.lua, say, there is this code:

Code: Select all

MechLaser =      MechUnit:new{ Image = "units/player/mech_laser.png", PosX = -15, PosY = -8 }
MechLasera =      MechUnit:new{ Image = "units/player/mech_laser_a.png", PosX = -15, PosY = -8, NumFrames = 4 }
MechLaserw =      MechUnit:new{ Image = "units/player/mech_laser_w.png", PosX = -15, PosY = 4 }
MechLaser_broken = MechUnit:new{ Image = "units/player/mech_laser_broken.png", PosX = -15, PosY = -1 }
MechLaserw_broken = MechUnit:new{ Image = "units/player/mech_laser_w_broken.png", PosX = -15, PosY = 9 }
MechLaser_ns =    MechIcon:new{ Image = "units/player/mech_laser_ns.png" }


And it defines the animation for MechLaser mech. I tried to add similar code to my mod to get my squad to use my own animations, but to no avail, the game crashes, even if I copy all class definitions from animations.lua.
I ended up replacing original graphics for some mech instead of adding new, which is very inconvenient because I can't edit offsets (PosX = -15, PosY = -8).
Lemonymous
Posts: 94
Joined: Fri Mar 09, 2018 3:29 am

Re: Prototype Lua mod loader

Postby Lemonymous » Fri Mar 09, 2018 3:36 am

AUTOMATIC wrote:How do you add new animations?

In animations.lua, say, there is this code:

Code: Select all

MechLaser =      MechUnit:new{ Image = "units/player/mech_laser.png", PosX = -15, PosY = -8 }
MechLasera =      MechUnit:new{ Image = "units/player/mech_laser_a.png", PosX = -15, PosY = -8, NumFrames = 4 }
MechLaserw =      MechUnit:new{ Image = "units/player/mech_laser_w.png", PosX = -15, PosY = 4 }
MechLaser_broken = MechUnit:new{ Image = "units/player/mech_laser_broken.png", PosX = -15, PosY = -1 }
MechLaserw_broken = MechUnit:new{ Image = "units/player/mech_laser_w_broken.png", PosX = -15, PosY = 9 }
MechLaser_ns =    MechIcon:new{ Image = "units/player/mech_laser_ns.png" }


And it defines the animation for MechLaser mech. I tried to add similar code to my mod to get my squad to use my own animations, but to no avail, the game crashes, even if I copy all class definitions from animations.lua.
I ended up replacing original graphics for some mech instead of adding new, which is very inconvenient because I can't edit offsets (PosX = -15, PosY = -8).


I was asking Cyberboy2000 this exact same question just earlier. Turns out higher up in animations.lua there is this line:

Code: Select all

setfenv(1, ANIMS)

It makes it so anything in the table ANIMS can be accessed without writing ANIMS, but only within that file. You'll have to write it in full in your own file like so:

Code: Select all

ANIMS.MechLaser =      ANIMS.MechUnit:new{ Image = "units/player/mech_laser.png", PosX = -15, PosY = -8 }
AUTOMATIC
Posts: 24
Joined: Sun Mar 04, 2018 11:59 am

Re: Prototype Lua mod loader

Postby AUTOMATIC » Fri Mar 09, 2018 4:26 am

Thanks, that worked!
User avatar
stickthemantis
Posts: 37
Joined: Wed Jan 29, 2014 4:16 pm

Re: Prototype Lua mod loader

Postby stickthemantis » Fri Mar 09, 2018 11:07 am

Important update!!

The mod loader now supports loading more squads than there are in the base game. Major thanks to Auxarch for being so stubborn in the pursuit of this ideal, which helped point me in the right direction.
Now there are some limitations to this. To be able to view the new squads, you have to exit the squad selection screen to the main menu and then open it again, this will swap out the available selection (go to the next page). It's a little annoying but shouldn't be too bad as long as you don't install too many new squads at the same time. Secondly the custom and random squads lag one page behind, so you might have to reload the screen one more time to get the squad you want. Also because of the page systems there will be certain combinations of squads you won't be able to use if you install too many.

For modders, this means that the old method of adding squads i.e.

Code: Select all

   modApi:addSquad(SQUAD_ARCHIVE_A,{"Name","Mech1","Mech2","Mech3"})
   modApi:overwriteText("TipTitle_Archive_A","Name")
   modApi:overwriteText("TipText_Archive_A","Description")
should be replaced with

Code: Select all

   modApi:addSquadTrue({"Name","Mech1","Mech2","Mech3"},"Name","Description")

The old method still works, but is more complicated and it's possible it will be removed in the future so switch to the new version when you get the opportunity.
I'm Cyberboy2000, known as a modder and community leader of Invisible Inc.
I'm using this old account because I've been unable to get any verification email for a new account. Help with changing my name would be appreciated.
AUTOMATIC
Posts: 24
Joined: Sun Mar 04, 2018 11:59 am

Re: Prototype Lua mod loader

Postby AUTOMATIC » Fri Mar 09, 2018 5:20 pm

stickthemantis, check out this: https://github.com/AUTOMATIC1111/IntoTheBreachLua

This is a library wrapper for lua5.1.dll, which allows the programmer to extend Lua code with C functions.

Among other things, this adds listdirs(dirname) and messagebox(text) functions to all lua VMs created by the game, so you can use this lua code in scripts:

Code: Select all

modlist = listdirs("mods")
for key,value in pairs(modlist) do
   messagebox(value)
end


And it will show a message box with its name for every mod in the mods directory. This can be used to remove the ugly console window that flickers when you start the game with mod loader enabled.
So this line:

Code: Select all

   for dir in io.popen([[dir ".\mods\" /b /ad]]):lines() do table.insert(self.mod_dirs,dir) end

Becomes:

Code: Select all

   local modlist = listdirs("mods")
   for key,value in pairs(modlist) do
      table.insert(self.mod_dirs,value)
   end


You can extend C-Lua interface in a lot of ways, for example, when the game calls the lua function with name GetScripts, you can add some more strings to its output, so that you don't have to alter the file scripts/scripts.lua on disk for the mod loader.

To install and test it, you rename lua5.1.dll in game directory to lua5.1-original.dll, and put lua5.1.dll from https://github.com/AUTOMATIC1111/IntoTh ... a/releases into game directory. Or you can build it yourself from source with Visual Studio.
AUTOMATIC
Posts: 24
Joined: Sun Mar 04, 2018 11:59 am

Re: Prototype Lua mod loader

Postby AUTOMATIC » Fri Mar 09, 2018 7:00 pm

Also, the new squad paging thing messes up achievements. With 9 squads, every time you press new game, all squads are shifted by 1, but achievements remain where they are, which is extremely inconvenient.
Auxarch
Posts: 7
Joined: Mon Mar 05, 2018 3:56 pm

Re: Prototype Lua mod loader

Postby Auxarch » Fri Mar 09, 2018 7:09 pm

I'm not sure it makes sense to have the modApi name be "addSquadTrue" for the add squad functionality.
If anything, "addSquadTrue" should be "addSquad" and "addSquad" should be "addSquadOld"
ALTERNATIVELY, you could put a check into addSquad so that if param 1 is an integer, redirect it to the old addSquad, otherwise continue with the new logic. I'll send you the code on discord.

There are, what, 3 total custom squads posted here? Two of which are between me and you, cyber, and the last is AUTOMATIC's (who is also here).

I'd rather just us 3 get clobbered by the name change than have a weird artifact going forward where it'll be way harder to change when more content is created.

EDIT: same thing but for overwriteText, although this one you can't avoid clobbering the names.

EDIT2: AUTOMATIC you should totally join us on the discord; I think InfiniteMantis reached out to you about the link?
User avatar
stickthemantis
Posts: 37
Joined: Wed Jan 29, 2014 4:16 pm

Re: Prototype Lua mod loader

Postby stickthemantis » Sat Mar 10, 2018 5:10 pm

As requested: You can now use addSquad in the same way as addSquadTrue. There's also a few new API functions.
Haven wrote:Hi! Thanks for your work so far. I've been a huge fan of FTL and the amazing mods that have been put out for it, and I'm excited to try my hand at modding (for the first time) with ITB.

I see your sample mod's .lua files seem to contain only additions to existing files; is there a way to replace existing sections of .lua files? I was hoping to get my feet wet by rewriting/expanding the dialogue options in text_population.lua to add a little more variety (since the existing dialogue gets recycled so quickly), but that would seem to necessitate replacing the existing lines. I'm seeing "modApi:overwriteText" in your mod's init.lua file; would I use "PopEvent" (the relevant section in text_population.lua) with that function to specify replacement of the existing dialogue?
There's now a function addPopEvent which let's you add new lines for the civilians. There's also addOnPopEvent which lets you make them more complex, i.e. the base game replaces instances of #squad and #corp with the squad name and the corporation name and this lets you add other similar behaviour. I can upload an example mod if you're still interested.

The mod now also keeps track of mod settings in the savefile and reloads the mods with them whenever you press load game. Doesn't mean much since we can't actually configure mods but hey it's better to be prepared. At the very least it could be useful if you decide to do version control.
tom_gamebanana wrote:Any chance you would consider adding web browser integration so the manager can launch out of the browser? We have integrated about 10 mod managers at gamebanana.com which launch from custom protocol handles (eg itbmm://) and pass mod download details to the application (e.g itbmm://[downloadUrl],[name],[author]). It's a huge benefit for fans - makes it more convenient for existing mod users and makes modding available to a huge amount of additional gamers who would normally never install mods (either couldn't be bothered learning how or don't feel competent enough or are scared they'll break something etc...). Would be sweet to have...

GameBanana also has an API you can call to get all kinds of additional info on the mod being installed.

Cheers
If I understand correctly, that would require me turning the mod loader into an exe. Right now it's a bunch of scripts which extend off the base game, which might not be the most convenient way to do it, but I'm actually trying to emulate what it would be if the game had official mod support and mods were downloaded from the steam workshop. ITB is a young game, lets hope the devs show the modding community some love.
I'm Cyberboy2000, known as a modder and community leader of Invisible Inc.
I'm using this old account because I've been unable to get any verification email for a new account. Help with changing my name would be appreciated.
Auxarch
Posts: 7
Joined: Mon Mar 05, 2018 3:56 pm

Re: Prototype Lua mod loader

Postby Auxarch » Sat Mar 10, 2018 5:17 pm

Excellent stuff, thanks for the update!
Captain Trek
Posts: 74
Joined: Fri Feb 20, 2015 5:17 am

Re: Prototype Lua mod loader

Postby Captain Trek » Thu Mar 15, 2018 3:01 pm

Uhhh, am I missing something here? Is it supposed to be possible for ordinary people to understand how to get a mod working using this thing, or is this mod programmers only until you guys can come up with a more user-friendly solution?