Forum Mod Bakery Docs

Custom Dialogue with International Support with 1.24

Please login to contribute to the conversation.
Hi all,

With the addition of FileSystemRCFs in 1.24, you can now ReadFile files that are contained in those locations. With this in mind, I've created a Lua system in order to dynamically generate the correct dialog SPT file for the language used by the game.

The way the international releases work is that they load a different file per language:
  • English | dialog.spt
  • French | dialogfr.spt
  • German | dialogge.spt
  • Spanish | dialogsp.spt

Unfortunately, the different languages have different available audio files, so you can't just blanket overwrite all 4 with one dialog.spt containing your custom dialog. This method avoids that.

Step 1
First thing you will need to do is add 3 lines to your Meta.ini under the [Miscellaneous] header:
[Miscellaneous]
RequiredHack=CustomFiles
RequiredHack=FileSystemRCFs
RequiredLauncher=1.24
CustomFiles is required for the SPT Path Handler, FileSystemRCFs is required to read the default SPT file and 1.24 is required to use the new hack.

Step 2
If you don't already have one, create a CustomFiles.ini in the root of your mod, next to your Meta.ini.
In that file you need to add 4 lines under the [PathHandlers] header:
[PathHandlers]
sound/scripts/dialog.spt=Resources/HandleDialog.lua
sound/scripts/dialogfr.spt=Resources/HandleDialog.lua
sound/scripts/dialogge.spt=Resources/HandleDialog.lua
sound/scripts/dialogsp.spt=Resources/HandleDialog.lua
This will route all 4 potential dialog SPT files to one Lua handler. This is what will dynamically edit the SPT to suit our needs.

Step 3
If it doesn't already exist, create a Resources folder in the root of your mod, and then create a HandleDialog.lua text file in that folder.
In this file, copy and paste the below code:
-- Load the requested SPT file
local Orig = ReadFile("/GameData/" .. GetPath())
-- Table with conversations we need to remove for whatever reason
local DefaultRemove = {
	["C_icecream_1_convinit_Mrg_L1"] = true,
	["C_icecream_2_convinit_Hom_L1"] = true,
}

-- Loop through each SoundData in the loaded SPT
for SoundData in Orig:gmatch("[^}]+") do
	-- Parse the name of the data
	local name = SoundData:match("named ([^\r\n]+)")
	-- If the name was found (so it's a valid soundData), and it's not a match in the remove table, output it
	if name and not DefaultRemove[name] then
		Output(SoundData)
		Output("}")
	end
end

-- This is now our additional sound data entries. The blank line is intentional for formatting in the SPT file.
Output([[

create daSoundResourceData named C_icecream_1_convinit_Brt_L1
{
    AddFilename ( "conversations/C_icecream_1_convinit_Brt_L1.rsd" 1.000000 )
    SetStreaming ( true )
}
create daSoundResourceData named C_icecream_2_convinit_Apu_L1
{
    AddFilename ( "conversations/C_icecream_2_convinit_Apu_L1.rsd" 1.000000 )
    SetStreaming ( true )
}]])

Step 3
Now we need to modify the above code to our needs. The comments should hopefully explain what it does, but basically:
  • Modify the DefaultRemove table to the list of default sound data names you need to remove. If you don't need to remove anything, set it to local DefaultRemove = {}.
  • Modify the last Output to be your new sound data entries. The blank line is there intentionally and needs to remain as it is used for formatting the SPT file.


This should now be dynamically creating your SPT file and should support all 4 language releases.

This is my first real tutorial, if anything needs changing please let me know.
How do I add custom dialogue to characters?
How do I add custom dialogue to characters?

Not really the thread to ask that, but here's a tutorial.