Softmodding
Softmodding
The Softmod Mod: Introduces a ``hijack.lua`` that allows you to "softmod" a mod into your save files. Just don't forget to put ``require("hijack")`` at the end of your save files ``control.lua``
This is noteably useful for both multiplayer servers as they may distribute a modded save files but have the mods embedded in the save instead of syncing with mod portal, and with scenarios.
To add your mod to the save file, extract the mod to a folder (remove versions _0.x) and put it in the save .zip, then add the name of the folder to the top of ``hijack.lua`` in ``config.mod={"name","of","mods"}``.
And that's it.
Enjoy.
Let me know of any bugs.
Pros:
- Compatability with mod portal mods. You can just extract and forget.
- Saves, and scenarios can be distributed with included mods without the need for their players to syncronize their mods with the save. They're just embedded with the save. Easy.
- This also affects multiplayers: Have an almost "Modded" server, but zero mods to sync with mod portal, as they come with the save.
Cons:
- Softmodding has limitations: It cannot extend the data.raw and it cannot register settings. Although i cannot do anything about the data, i CAN simulate the "settings" registration, so that mods don't need to account for this issue - the hijack does this internally.
- Further Limitations: Mod portal mods ("Hard Mods") typically have their own lua environment. This means variables not declared as local will be shared between mods which is not normal. There is little i can do about this.
- Further Limitations: Because of the lua environments, the "global" table is given special treatment. All mods are forced to refer to a set table within their simulated environment. This helps to reduce any potential overlap or problems with the shared lua environment.
- There is however a global ``softmod`` variable that you can use to read your environment with ``softmod.environment`` (you can write to it too - please don't) for custom handling, which should never be needed.
- Mod updates currently are not managed, and updating a mod in your save must be done manually. This cannot be avoided - but it's also fairly easy. Just replace contents of the folder. No special handling beyond that required.
This may eventually be updated to manage migrations and version changes.
I make no promises.
This is noteably useful for both multiplayer servers as they may distribute a modded save files but have the mods embedded in the save instead of syncing with mod portal, and with scenarios.
To add your mod to the save file, extract the mod to a folder (remove versions _0.x) and put it in the save .zip, then add the name of the folder to the top of ``hijack.lua`` in ``config.mod={"name","of","mods"}``.
And that's it.
Enjoy.
Let me know of any bugs.
Pros:
- Compatability with mod portal mods. You can just extract and forget.
- Saves, and scenarios can be distributed with included mods without the need for their players to syncronize their mods with the save. They're just embedded with the save. Easy.
- This also affects multiplayers: Have an almost "Modded" server, but zero mods to sync with mod portal, as they come with the save.
Cons:
- Softmodding has limitations: It cannot extend the data.raw and it cannot register settings. Although i cannot do anything about the data, i CAN simulate the "settings" registration, so that mods don't need to account for this issue - the hijack does this internally.
- Further Limitations: Mod portal mods ("Hard Mods") typically have their own lua environment. This means variables not declared as local will be shared between mods which is not normal. There is little i can do about this.
- Further Limitations: Because of the lua environments, the "global" table is given special treatment. All mods are forced to refer to a set table within their simulated environment. This helps to reduce any potential overlap or problems with the shared lua environment.
- There is however a global ``softmod`` variable that you can use to read your environment with ``softmod.environment`` (you can write to it too - please don't) for custom handling, which should never be needed.
- Mod updates currently are not managed, and updating a mod in your save must be done manually. This cannot be avoided - but it's also fairly easy. Just replace contents of the folder. No special handling beyond that required.
This may eventually be updated to manage migrations and version changes.
I make no promises.
- Attachments
-
- softmod-wizardry.zip
- (2.85 MiB) Downloaded 121 times
Last edited by PyroFire on Mon Aug 26, 2019 5:03 am, edited 1 time in total.
Re: Softmodding
Why do you need a hijack.lua?
Just add another lib to the control.lua, and have it run with the base game event handler
Just add another lib to the control.lua, and have it run with the base game event handler
- eradicator
- Smart Inserter
- Posts: 5207
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Softmodding
Presumably because if you just rename->copy->paste->require() a bunch of random modded control.lua files then they'll overwrite each others event registrations. And hijack seems to try to automatically wrap them by overwriting _ENV.script.on_event etc. and constructing a single event handler function.
I.e. "make a bunch of random mods work together in a shared lua-state without modifying each mod"
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
- Deadlock989
- Smart Inserter
- Posts: 2529
- Joined: Fri Nov 06, 2015 7:41 pm
Re: Softmodding
Exactly this.eradicator wrote: ↑Sun Aug 25, 2019 9:15 am Presumably because if you just rename->copy->paste->require() a bunch of random modded control.lua files then they'll overwrite each others event registrations. And hijack seems to try to automatically wrap them by overwriting _ENV.script.on_event etc. and constructing a single event handler function.
It should contain an override for _ENV too but i didn't know about that while writing it.
- eradicator
- Smart Inserter
- Posts: 5207
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Softmodding
I've tried something vaguely similar before, It's a very deep rabbit hole and i haven't seen the bottom yet.PyroFire wrote: ↑Mon Aug 26, 2019 5:01 amExactly this.eradicator wrote: ↑Sun Aug 25, 2019 9:15 am Presumably because if you just rename->copy->paste->require() a bunch of random modded control.lua files then they'll overwrite each others event registrations. And hijack seems to try to automatically wrap them by overwriting _ENV.script.on_event etc. and constructing a single event handler function.
It should contain an override for _ENV too but i didn't know about that while writing it.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: Softmodding
If you were to add _ENV overrides, they would go where the softmod.environment and softmod.inscript is, or you would give _ENV a metatable that checks the _trueENV.softmod.environment and indexes/newindexes with softmod._env[softmod.environment], with a fallback index to _trueENV.eradicator wrote: ↑Mon Aug 26, 2019 7:59 am I've tried something vaguely similar before, It's a very deep rabbit hole and i haven't seen the bottom yet.
The current override for the "global" table already does something similar to this.
I don't think it's needed, but easily done.
By resetting to the previous setting, it'll eventually revert back to the defaults ("global" and inscript=false) when all the scripts are done executing.
The problem is catching all cases similar to script.raise_event where it can jump to multiple different environments.
remote.call is similar, and that should probably be overridden too for the same reason (currently isn't) so softmods that call remotes don't break.
- Attachments
-
- hijack.lua
- the bottom of the rabbit hole
- (9.13 KiB) Downloaded 105 times
Re: Softmodding
Hi all,
I have experimented with this. I attempted to add several mods - each individual at at one time. Some real basic ones like playtime, and enhanced map color while some others too; and it doesn't seem to take as I followed the initial OP instructions. I even got it to not error out as I loaded the save file correctly as I added the mods to the hijack.lua config and added the mods to the zip file. Not sure if I'm doing something wrong or missing something. I want to say it had to be working at some point for the OP and since it's recent enough in august of 2019; however the thread seemed to be dead - which to me indicates that somehow this may have been obsolete or non-working to begin with. I will keep on trying this to see what it will work with, but so far, I've yet to get the any feature of the mod working. Any clue, or feedback is welcomed. Just figured I'd give some feedback since I tried it, and seems like a fantastic idea to be able to integrate regular mods into softmods if this could work. Thanks all.
I have experimented with this. I attempted to add several mods - each individual at at one time. Some real basic ones like playtime, and enhanced map color while some others too; and it doesn't seem to take as I followed the initial OP instructions. I even got it to not error out as I loaded the save file correctly as I added the mods to the hijack.lua config and added the mods to the zip file. Not sure if I'm doing something wrong or missing something. I want to say it had to be working at some point for the OP and since it's recent enough in august of 2019; however the thread seemed to be dead - which to me indicates that somehow this may have been obsolete or non-working to begin with. I will keep on trying this to see what it will work with, but so far, I've yet to get the any feature of the mod working. Any clue, or feedback is welcomed. Just figured I'd give some feedback since I tried it, and seems like a fantastic idea to be able to integrate regular mods into softmods if this could work. Thanks all.
Re: Softmodding
Not all mods are soft-moddable. Actually, very very few are. Among other things, any mod that has a data.lua, or data*.lua won't work. Also, mods that use the events on_init or on_load or on_configuration_changed (or maybe few other) won't work. And I'm sure there are a few other edge cases that would prevent a mod from being soft-modded.
Re: Softmodding
Hi there,
Yes,I kept that all in mind from the OP about the data.lua and or event factors; and have read throughly in-depth the con list. I’m just not seeing any compatibility with any mods that I have attempted. I almost feel like I’m missing something. Maybe it’s just the mods that have those compatibility factors that I have tried so far like you said. I’m curious though now, and begs to question, which mods do actually work if you don’t mind to name a few? I’m an avid game host within the community and actually very familiar with modding / debugging lua code for many scenarios, to give you a quick background if that helps. Which is why it frustrates me to not be able to use this for simple softmodding. Thanks for quick reply.
Yes,I kept that all in mind from the OP about the data.lua and or event factors; and have read throughly in-depth the con list. I’m just not seeing any compatibility with any mods that I have attempted. I almost feel like I’m missing something. Maybe it’s just the mods that have those compatibility factors that I have tried so far like you said. I’m curious though now, and begs to question, which mods do actually work if you don’t mind to name a few? I’m an avid game host within the community and actually very familiar with modding / debugging lua code for many scenarios, to give you a quick background if that helps. Which is why it frustrates me to not be able to use this for simple softmodding. Thanks for quick reply.
kizrak wrote: ↑Fri Jan 10, 2020 3:42 am Not all mods are soft-moddable. Actually, very very few are. Among other things, any mod that has a data.lua, or data*.lua won't work. Also, mods that use the events on_init or on_load or on_configuration_changed (or maybe few other) won't work. And I'm sure there are a few other edge cases that would prevent a mod from being soft-modded.
Re: Softmodding
Some of the very early versions of my mods https://mods.factorio.com/user/kizrak were soft-moddable, however I don't think any of newest releases for any of them are any more (if for no other reason than settings). Also, the old original deprecated long/far? reach was (can't find it anymore, but I remember using it during testing), or any modern version that doesn't have settings would probably work. Also a lot of the redmew/fishbus soft mods can be mixed-and-matched with hijack.lua (normally those soft mods don't play nice together). This is actually where most of the development for hijack came from, I was trying to integrate my own code into the redmew/fishbus frameworks and encountered issues with their/mine code un-registering the other's events. Because their "mods" are "softmods" and not on mods.factorio.com, the only way to get them is to join one of their servers, and save the map (which will include their soft-mods).
PyroFire might have more to add or know of some other mods on mods.factorio.com if he used any.
I think the bigger take away is that hijack is a concept one can use to allow multiple event handlers with less conflicts. However as I understand it (and I haven't experimented with it yet) the newest ...\Factorio\data\base\scenarios\freeplay\control.lua includes a way to do pretty much the same thing, and it was included by the Factorio Devs (sometime during 0.17.X's). That requires changing the code's event handling a bit, but is probably much better going forward. (Unless you are using some pre-0.17.32'ish(?) version that doesn't have that yet.)
If you want to see some really bad code, but my justification for the initial development of hijack, you could look through github > Auto-Zip-Inserter > saves for examples.
PyroFire might have more to add or know of some other mods on mods.factorio.com if he used any.
I think the bigger take away is that hijack is a concept one can use to allow multiple event handlers with less conflicts. However as I understand it (and I haven't experimented with it yet) the newest ...\Factorio\data\base\scenarios\freeplay\control.lua includes a way to do pretty much the same thing, and it was included by the Factorio Devs (sometime during 0.17.X's). That requires changing the code's event handling a bit, but is probably much better going forward. (Unless you are using some pre-0.17.32'ish(?) version that doesn't have that yet.)
If you want to see some really bad code, but my justification for the initial development of hijack, you could look through github > Auto-Zip-Inserter > saves for examples.
Re: Softmodding
Have you seen the comfyfactorio stuff? They have a lot of "modules" that get mixed and matched for different maps. There's a few conflicts I ran into (player_modifiers hard sets bonuses... ruining other mods or research effects). I have my own patch for that. I've had to edit my save file's lua files because some of the maps had errors or behavior I didn't like.
In terms of on_init/on_load/on_config_changed whatever events, there's ways around that, mostly in a slightly worse style, like if it's not defined in an on_tick function, then create it, but it comes out the same.
In terms of on_init/on_load/on_config_changed whatever events, there's ways around that, mostly in a slightly worse style, like if it's not defined in an on_tick function, then create it, but it comes out the same.
I have mods! I guess!
Link
Link
Re: Softmodding
Hi kizrak,
Thanks for the insight, much appreciated. I saw PyroFire pre-softmod two mods already. Been always using the latest 0.17.79 as of this message for any softmods integration. Hoping I can find some mods that will work, but I'm starting to realize this was more a good concept and pretext work in attempt to make softmods easier.
Redmew mods always seemed to be on Github so I never had to "steal" it from a save; as well explosive gaming, factorio RPG.
I will have to experiment more with the new code control.lua as you mentioned to quickly be able to softmod; however it will always be a imitation if Wubu software does not allow us to directly with data.raw, and other event handlers. Again, appreciate the insight! Happy softmodding!
Thanks for the insight, much appreciated. I saw PyroFire pre-softmod two mods already. Been always using the latest 0.17.79 as of this message for any softmods integration. Hoping I can find some mods that will work, but I'm starting to realize this was more a good concept and pretext work in attempt to make softmods easier.
Redmew mods always seemed to be on Github so I never had to "steal" it from a save; as well explosive gaming, factorio RPG.
I will have to experiment more with the new code control.lua as you mentioned to quickly be able to softmod; however it will always be a imitation if Wubu software does not allow us to directly with data.raw, and other event handlers. Again, appreciate the insight! Happy softmodding!
kizrak wrote: ↑Fri Jan 10, 2020 10:35 pm Some of the very early versions of my mods https://mods.factorio.com/user/kizrak were soft-moddable, however I don't think any of newest releases for any of them are any more (if for no other reason than settings). Also, the old original deprecated long/far? reach was (can't find it anymore, but I remember using it during testing), or any modern version that doesn't have settings would probably work. Also a lot of the redmew/fishbus soft mods can be mixed-and-matched with hijack.lua (normally those soft mods don't play nice together). This is actually where most of the development for hijack came from, I was trying to integrate my own code into the redmew/fishbus frameworks and encountered issues with their/mine code un-registering the other's events. Because their "mods" are "softmods" and not on mods.factorio.com, the only way to get them is to join one of their servers, and save the map (which will include their soft-mods).
PyroFire might have more to add or know of some other mods on mods.factorio.com if he used any.
I think the bigger take away is that hijack is a concept one can use to allow multiple event handlers with less conflicts. However as I understand it (and I haven't experimented with it yet) the newest ...\Factorio\data\base\scenarios\freeplay\control.lua includes a way to do pretty much the same thing, and it was included by the Factorio Devs (sometime during 0.17.X's). That requires changing the code's event handling a bit, but is probably much better going forward. (Unless you are using some pre-0.17.32'ish(?) version that doesn't have that yet.)
If you want to see some really bad code, but my justification for the initial development of hijack, you could look through github > Auto-Zip-Inserter > saves for examples.
Re: Softmodding
Yes, I have seen comfyfactorio, though I admit, I have not checked or tried it recently within the last few months. I'll check them out again to see of any good code. Thanks all! Much appreciate it.
Honktown wrote: ↑Fri Jan 10, 2020 11:55 pm Have you seen the comfyfactorio stuff? They have a lot of "modules" that get mixed and matched for different maps. There's a few conflicts I ran into (player_modifiers hard sets bonuses... ruining other mods or research effects). I have my own patch for that. I've had to edit my save file's lua files because some of the maps had errors or behavior I didn't like.
In terms of on_init/on_load/on_config_changed whatever events, there's ways around that, mostly in a slightly worse style, like if it's not defined in an on_tick function, then create it, but it comes out the same.
Re: Softmodding
I've only come across other people's soft-mods by accident, AKA joining some random public server and realizing it was running custom LUA. I really wish there was like *one* place that soft-modders could publish, like Wube has for hard mods. (And a way to search specifically for them, like some type of tag.) Or maybe there is and I just haven't stumbled upon it yet.
I'll have to look into explosive gaming, factorio RPG, and comfyfactorio --- I haven't heard of them before now.
Thanks!
I'll have to look into explosive gaming, factorio RPG, and comfyfactorio --- I haven't heard of them before now.
Thanks!
- BlueTemplar
- Smart Inserter
- Posts: 3110
- Joined: Fri Jun 08, 2018 2:16 pm
- Contact:
Re: Softmodding
Doesn't "factorio softmod" in a search engine works ?
BobDiggity (mod-scenario-pack)