Modding:Compatibility Framework

From bg3.wiki
Revision as of 19:02, 2 April 2024 by EmeraldTechno (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Modding index

Compatibility Framework[edit | edit source]

First big thank you to NellsRelo and perseidipity

To use the Compatibility Framework you need to install it alongside your mod. CF however needs to be at the bottom of the load order. So the bottom of the list.

Json[edit | edit source]

So this is considered the easier format to setup for using the Compatibility Framework in order to make your edits to the Races.lsx compatible with other mods. Partially due to reacting easier to multiple sections for defining each race and having multiple values.

You do not need to send anything to be added to the Compatibility Framework mod, just remember to have it at the bottom of your load order and if making a public mod to remind people CF goes to the bottom.

So first you want to make some new folders:

Modname/Mods/YourShared/ScriptExtender

In the Script extender folder you want to create a CompatibilityFrameworkConfig.json you can do this by creating a txt file and renaming it and its extension to CompatibilityFrameworkConfig.json

Using part of the code example we are given here: but edited.

{
 "FileVersion": 1,
 "Races": [
   {
     "UUID": "Race's UUID",
     "Children": [
       {
         "Type": "Visuals",
         "modGuid": "UUID of required mod (Optional)",
         "Values": ["bdf9b779-002c-4077-b377-8ea7c1faa795", "3e4d5829-7bfd-446a-9e7d-ac8d0948c1e4"],
         "Action": "Insert"
       }
     ]
   }
 ]
}
     "UUID": "Race's UUID",

In this line we want to change it to the race we are adding to in the Races.lsx file. The most commonly used one is Humanoid for hair/beard mods. Which is 899d275e-9893-490a-9cd5-be856794929f. This will apply it to all races including modded races if they use it as the parent. For others see here in the Races.lsx section for example if you want it only added to Humans and Elves your code would look like this.

{
 "FileVersion": 1,
 "Races": [
   {
     "UUID": "0eb594cb-8820-4be6-a58d-8be7a1a98fba", This being the Human races uuid
     "Children": [
       {
         "Type": "Visuals",
         "modGuid": "UUID of required mod (Optional)",
         "Values": ["bdf9b779-002c-4077-b377-8ea7c1faa795"],
         "Action": "Insert"
       }
     ]
   },
   {
     "UUID": "6c038dcb-7eb5-431d-84f8-cecfaf1c0c5a", This being the Elves races uuid
     "Children": [
       {
         "Type": "Visuals",
         "modGuid": "UUID of required mod (Optional)",
         "Values": ["bdf9b779-002c-4077-b377-8ea7c1faa795"],
         "Action": "Insert"
       }
     ]
   }
 ]
}

Now to continue explaining the other lines:

         "Type": "Visuals",

Visuals pertains to assets such as Hair, Beards, Tails, Horns and such. Pretty much the assets we add to SharedVisuals.

         "modGuid": "UUID of required mod (Optional)",

So as this line says it is optional, but personally I add it in. The UUID we add in the meta.

         "Values": ["bdf9b779-002c-4077-b377-8ea7c1faa795"],

This uuid has to match the one you gave for the UUID line in your CharacterCreationSharedVisuals. If you have multiple assets add a , after the final " and then make a new " " with your uuid in between for example from the first example given:

         "Values": ["bdf9b779-002c-4077-b377-8ea7c1faa795", "3e4d5829-7bfd-446a-9e7d-ac8d0948c1e4"],

Now we come to the last line:

         "Action": "Insert"

For the sake of SharedVisual mods we likely wouldn't change this line, however if you want to remove something instead of add something to a section in Races.lsx change Insert to Remove

Congrats you setup your mod for using the Compatibility Framework via json. Just remember always load Compatibility Framework at the bottom of your load order.

Lua[edit | edit source]

This is a possible use of the Compatibility Framework though it is advised to use the json method instead. Both do not require adding anything directly to the framework, they will work alongside it out of the box.

So first you want to make some new folders:

Modname/Mods/YourShared/ScriptExtender/Lua

In the Script extender folder you want to create a Config.json you can do this by creating a text file and just renaming it and its extension Config.json. In the json you want:

{
   "RequiredVersion": 9,
   "ModTable": "YOUR_MOD_NAME_HERE",
   "FeatureFlags": ["Lua"]
}

Where it says YOUR_MOD_NAME_HERE, write the name of your mod.

Now in the Lua folder do the same again make a new txt file but this time rename it BootstrapClient.lua

if Ext.Mod.IsModLoaded("67fbbd53-7c7d-4cfa-9409-6d737b4d92a9") then
   local raceChildData = {
     ModName = {
       modGuid = "the UUID you gave in your meta.lsx",
       raceGuid = "899d275e-9893-490a-9cd5-be856794929f",
       children = {
        entry1 = {
           Type = "Visuals",
           Value = "3ae3e4fc-e792-473a-8853-43520dfc1147",
         },
      }
   }
}
   local function OnStatsLoaded()
     Mods.SubclassCompatibilityFramework.Api.InsertRaceChildData(raceChildData)
   end
 
   Ext.Events.StatsLoaded:Subscribe(OnStatsLoaded)
 end
       raceGuid = "899d275e-9893-490a-9cd5-be856794929f",

this you want to be the race you're adding your hair too. The one currently in there is humanoid. This will apply it to all races including modded races if they use it as the parent. For others see here

           Type = "Visuals",

This line is what you're adding to. Visuals is either Hair or Beards or other assets defined in the SharedVisuals file.

           Value = "3ae3e4fc-e792-473a-8853-43520dfc1147",

This uuid has to match the one you gave for the UUID line in your CharacterCreationSharedVisuals

If wanting to create more than one hair copy and paste this section:

        entry1 = {
           Type = "Visuals",
           Value = "3ae3e4fc-e792-473a-8853-43520dfc1147",
         },

Changing entry1 to entry2 and so on. You can also use entrya, entryb as well.

     Mods.SubclassCompatibilityFramework.Api.InsertRaceChildData(raceChildData)

Not fully related to this tutorial but just in case you come up with a use, swap out InsertRaceChildData for RemoveRaceChildData if you want to remove lines from the Races.lsx instead of adding.

Congrats you setup your mod for using the Compatibility Framework via lua. Just remember always load Compatibility Framework at the bottom of your load order.