Jump to content

Unofficial Modding Support


Recommended Posts

(2024 may 5th) Update: the original guide post on this thread is outdated and I have moved to a github repository to host guides and docs about modding (https://github.com/zgibberish/rotwood-mods), you should read this guide on the github repo instead (it's updated more frequently, and the repo also includes various other docs).

 

Right now the built in mod loader of Rotwood is not complete and is disabled so by default it will not work properly. But it is possible to load and run mods, if you bypass the mod manager and load them yourself. After tinkering for a while now I have found a method to do so.

Please note that this is still very bare bones and some modding API features might not work correctly or at all. So far I have confirmed that modinfo and some features in the modmain environment like modimport and functions like AddClassPostConstruct work.

How to load mods:

Editing the game scripts requires you to have extracted scripts and use modified scripts, mods will stop working if you decide to switch back to the original scripts. Game updates will also automatically resets your data_scripts.zip file so the game will load original scripts again. ALSO in some rare cases, playing with mods, then reverting back to vanilla scripts can cause bugs and glitches, so you should definitely make backups of your saves.

To enable mods and make the mod manager usable, you will first need to modify a few lines in the game scripts, as follows:

 

In mods.lua

In function CreateEnvironment(modname, isworldgen), comment the following lines:

require("map/lockandkey")

 

GROUND = GROUND,
LOCKS = LOCKS,
KEYS = KEYS,

 

In modutil.lua

In local function InsertPostInitFunctions(env, isworldgen), near the end of the function, comment the following lines:

env.Ingredient = Ingredient

 

env.MOD_RPC = MOD_RPC --legacy, mods should use GetModRPC below

 

In main.lua

After editing the mod loader to make it work, now you have to enable mods by adding this line:

MODS_ENABLED = true

I recommend putting it in the --defines block, like this:

...
--defines
MODS_ENABLED = true
MAIN = 1
IS_QA_BUILD = TheSim:GetCurrentBetaName() == "huwiz"
...

Near the end of main.lua there's also an assert call that was purposefully put there to make the game closes if mods are enabled, so you'll need to disable that too, simply comment that line like this:

    --#V2C no mods for now... deal with this later T_T
	--assert(true)

Last but not least, our very own mod loader, paste this at the end of main.lua:

for _,modname in ipairs(TheSim:GetModDirectoryNames()) do
	if KnownModIndex.savedata and KnownModIndex.savedata.known_mods and KnownModIndex.savedata.known_mods[modname] then
		-- check if the mod's enabled state is nil
		-- if it is then this usually means the mod is newly loaded and hasnt been configured
		-- this will not catch mods that were disabled specifically
		if KnownModIndex.savedata.known_mods[modname].enabled == nil then
			-- new mods are enabled by default
			KnownModIndex.savedata.known_mods[modname].enabled = true
		end

		-- at this point the enabled state should be set and we just need to check
		-- if the mod is enabled or not to load it
		if KnownModIndex.savedata.known_mods[modname].enabled  then
			local fn = kleiloadlua(MODS_ROOT..modname.."/".."modmain.lua")
			local initenv = KnownModIndex:LoadModInfo(modname)
			local env = CreateEnvironment(modname)
			env.modinfo = initenv
			RunInEnvironment(fn, env)
		end
	end
end 
KnownModIndex:Save() -- save mods' enabled states if any were changed during loading

This is the code that is responsible for loading the mod files, basically what it does is go through every subdirectories in the `mods/` folder placed in the game root directory and load every modmain.lua file, along with their modinfo.lua.

 

Thanks for reading

Your game is now patched and it should automatically load all mods put inro `{game directory}/mods`, here's an example directory tree to help you visualize:

Rotwood/
    bin/
        ...
    data/
        licenses/
        scripts/
        ...
    localizations/
        ...
    mods/
        very_awesome_mod/
            modinfo.lua
            modmain.lua
            utils/
                ...
        cool_mod_2/
            modinfo.lua
            modmain.lua
            ...
    data.zip
    ...

The mod scripts are run using the modding environment, not the game environment, so you can write them like normal mods (like DS/T mods).

You can also write `modinfo.lua` files for your mods and they will be read correctly.

Since we're not using the mod manager, but instead load all mods inside `mods/`, you will be the one managing your mods, if you need to disable any mod, you will have to remove it from the `mods/` folder yourself. (this is no longer the case: see section "Mod List" below).

The `mods/` directory and everything inside it will persist through game updates, but the changes you made to your game scripts won't, so you'll have to patch the game to enable mods every time the game updates, it might seem like a lot of work, but this is way better than editing every single game sscript files to add "mods" yourself.

Also you should make backups of everything you want to keep, just to be safe, plus it's good practice.

This might not be the most optimal method, but for now it works, and I hope we can improve it as time goes on. Happy modding :3

 

Mod List

I also made a mod that adds a "Mods" page to the game's options screen, to let you more easily see installed mods and manage them (right now it only supports enabling/disabling mods, I plan on adding mod specific configurations in the future if possible).

 

Tested on patch 605200, please tell me if you find any bugs or issues for both the mod loader and the mod list mod.

Feel free to ask any questions or for help, I will also be posting more update in this thread, but I'm mostly active on Discord :D

2024-04-30_23:47:33_1920x1080.png

2024-04-30_23:47:40_1920x1080.png

modlist.7z

Edited by gibberish
added notice about the guide moving on to github
  • Like 7
Link to comment
Share on other sites

Note: if any of your mods ever causes a crash and on the next startup the game shows you 2 empty buttons in the middle of the screen, that means the game has detected faulty mods and has automatically disabled all mods to ensure safe startup, you can either:

- Re-enable mods manually from the debug console (if you've enabled dev mode) by typing in "KnownModIndex:Enable(modname) KnownModIndex:Save()" (replace modname with the mod's directory name) and then reload.

- Remove your mods from the mods/ folder and reload the game, then place mods back in and reload again (the mod loader automatically enables newly installed mods)

- Or use the first method to just re-enable the Mod List mod if you have it installed so you can easily cherry pick other mods to re-enable.

Link to comment
Share on other sites

Posted (edited)

Update: tested on the latest version (patch 605635) .

edit: I forgot to link them in the original post but here are the sample mods (shown in the mod list screenshots) for you to test out yourself, they do nothing much useful, I just made them to test modding functions really.

modinfo_feedbacktext.7zextra_striker_ammo.7z

Edited by gibberish
added sample mods, i didnt want to post yet another reply because i dont want to flood the thread and keep pushing my thread to the top
Link to comment
Share on other sites

How does this work with multiplayer?

 

4 minutes ago, space iris said:

I'm sorry for the stupid question. should the mods folder be created automatically or should I create it myself?

Just create it yourself

  • Big Ups 1
Link to comment
Share on other sites

where should I create it? by the way, multiplayer is disabled when the game realizes that there are modifications in the game. it's the same with the translation of the game.

Link to comment
Share on other sites

18 hours ago, gibberish said:

Your game is now patched and it should automatically load all mods put inro `{game directory}/mods`, here's an example directory tree to help you visualize:

Rotwood/
    bin/
        ...
    data/
        licenses/
        scripts/
        ...
    localizations/
        ...
    mods/
        very_awesome_mod/
            modinfo.lua
            modmain.lua
            utils/
                ...
        cool_mod_2/
            modinfo.lua
            modmain.lua
            ...
    data.zip
    ...

 

4 minutes ago, space iris said:

where should I create it? by the way, multiplayer is disabled when the game realizes that there are modifications in the game. it's the same with the translation of the game.

Under ../steamapps/common/Rotwood/

  • Big Ups 1
Link to comment
Share on other sites

1 hour ago, space iris said:

by the way, multiplayer is disabled when the game realizes that there are modifications in the game. it's the same with the translation of the game.

Yeah that is intented behavior, the game won't let modded clients play with vanilla clients, so we'll have to deal with that :/

Link to comment
Share on other sites

10 minutes ago, gibberish said:

Да, это намеренное поведение, игра не позволит модифицированным клиентам играть с ванильными клиентами, так что нам придется с этим разобраться :/

how does the game determine that there have been changes in its files? I understood how it highlights the message that the game is modified, but how it defines it is not clear. the version of the game is the same. and why can't modified clients play with the same modified files with other clients?

Link to comment
Share on other sites

Just now, space iris said:

how does the game determine that there have been changes in its files? I understood how it highlights the message that the game is modified, but how it defines it is not clear. the version of the game is the same. and why can't modified clients play with the same modified files with other clients?

The code for determining if the game is modified is unknown, as it's from a compiled library of some sort, iirc TheSim? And those libraries are proxied to lua, so we can't peek in proprietary core game code.

As for modded clients you can actually play with other modded clients (I'm not sure if this was changed for the current release but I tried and it worked back in Playtest/Demo).

Link to comment
Share on other sites

Posted (edited)

Update on what I'm currently working on:

2024-05-01_235006_1920x1080.png.2350647315474f83f5e620c83ca4392b.png2024-05-01_235016_1920x1080.png.e2efb4b49ac71570577fc797379c6b9f.png2024-05-01_235023_1920x1080.png.2b693f23566c243c4667c271d86db445.png2024-05-01_235144_1920x1080.png.9ef441fbb4cef03ab40cc23706432a9b.png

The Mod List mod will be renamed to Mod Menu because I think it fits more considering that it has more features now and not just simply listing mods. If I can get mod configuration settings working that will be great!

 

update: If you've noticed that the cycle icons on the nav bar get pushed to the right when using the Mod List mod, don't worry it's just a minor layout error and this issue has been fixed in the new version.image.png.ea6ea26c5749918af3e0c67ab8f7a221.png

 

update 2: Looks like mod configuration options are working as expected
 

image.png

Edited by gibberish
add update note 2
Link to comment
Share on other sites

Posted (edited)

天哪,这对目前的游戏来说是一个巨大的变化。当我还在寻找继承盔甲属性的东西时,mod 加载器出现了,对于目前体积较小的游戏来说,这是一个非常好的 mod 制作练习项目。

 

Discord 邀请链接,请求。

————————————

OMG, this is a huge change for the current game. When I was still looking for something to inherit the properties of armor, the mod loader appeared, which is a very good mod making exercise project for the current small-sized games.

 

Discord invitation link, please.

 

 

Edited by LXJlin
  • Health 1
Link to comment
Share on other sites

1 hour ago, LXJlin said:

天哪,这对目前的游戏来说是一个巨大的变化。当我还在寻找继承盔甲属性的东西时,mod 加载器出现了,对于目前体积较小的游戏来说,这是一个非常好的 mod 制作练习项目。

 

Discord 邀请链接,请求。

————————————

OMG, this is a huge change for the current game. When I was still looking for something to inherit the properties of armor, the mod loader appeared, which is a very good mod making exercise project for the current small-sized games.

 

Discord invitation link, please.

 

 

Thank you! This has been my main project for a while.

As for the discord, if you haven't, you can join the official Klei discord, I'm very active there in the rotwood channels and I share stuff there very often. It would also be very nice if someone made a modding dedicated discord server, since there isn't yet a rotwood modding channel on Klei's server.

https://discord.gg/klei

Link to comment
Share on other sites

Posted (edited)

Hey everyone! Just letting you know that this guide along with the included mod have been moved to my new repo on github (that includes some other stuff). The guide on this thread is outdated and you should follow the one on github instead.

https://github.com/zgibberish/rotwood-mods

What's new:

- New mod loader script (included in the modloader guide) that fixes a crash that could happen if you had an empty subdirectory in mods/

- New version of the mod list mod (now renamed to Mod Menu) is on there too. It can now manage mod configuration options and there's now a favorite mod feature in the mod list. Some minor bugs have also been fixed.

Edited by gibberish
Link to comment
Share on other sites

New mod loader script just dropped guys, mod priority sorting is supported now, you can get it on github, link is in my previous reply and also at the top of the original post.

image.png.0b676c056c36d4de677318e4f02fee29.png

Link to comment
Share on other sites

Posted (edited)

Hey, does anyone know how to fix AddPrefabPostiInit? I tried copying the code from Don't starve, but it doesn't work

Edited by kipper0k
Link to comment
Share on other sites

6 minutes ago, kipper0k said:

Hey, does anyone know how to fix AddPrefabPostiInit? I tried copying the code from Don't starve, but it doesn't work

Add*PostInit functions are currently not working, I have yet to find out why though :(

Link to comment
Share on other sites

5 hours ago, kipper0k said:

Hey, does anyone know how to fix AddPrefabPostiInit? I tried copying the code from Don't starve, but it doesn't work

5 hours ago, gibberish said:

Add*PostInit functions are currently not working, I have yet to find out why though :(

Much of the functionality was cleaned out.

I'm sure you may have already realized, but the mod loader in Rotwood is essentially just copy pasted over from Don't Starve Together. (Rotwood as a whole could be seen as like. a really, really good and big mod of DST in the first place, haha! A lot of similarities between the two!)

In the case of AddPrefabPostInit,

local modfns = modprefabinitfns[inst.prefab or name]
            if modfns ~= nil then
                for k,mod in pairs(modfns) do
                    mod(inst)
                end
            end

was cleaned out from the `SpawnPrefabFromSim` definition.

And for AddComponentPostInit:

local postinitfns = ModManager:GetPostInitFns("ComponentPostInit", name)

    for i, fn in ipairs(postinitfns) do
        fn(loadedcmp, self)
    end

was cleaned out from the `EntityScript:AddComponent` definition.

I'll leave you to figure out the rest, take a looksies at DST's scripts!

If you don't own DST you can look at a public git my friend hosts: https://github.com/penguin0616/dst_gamescripts

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

local modfns = modprefabinitfns[inst.prefab or name]
            if modfns ~= nil then
                for k,mod in pairs(modfns) do
                    mod(inst)
                end
            end

I already moved this to rotwood but it didn't work, at least it didn't work with player_side

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...