Jump to content

How do you add buildings to a mod? (Launch preview)


Recommended Posts

Something changed between QOL3 and the preview. The code, which used to inject buildings into the build menu (BUILDINGS.PLANORDER) is no longer working. It crashes the with the message:

Quote

NullReferenceException: Object reference not set to an instance of an object
  at CodexEntryGenerator.GenerateBuildingEntries () [0x0007c] in D:\JenkinsWorkspace\Preview_Simgame_Windows\game\Assets\scripts\ui\CodexEntryGenerator.cs:24
  at CodexCache.Init () [0x00211] in D:\JenkinsWorkspace\Preview_Simgame_Windows\game\Assets\scripts\ui\CodexScreen.cs:1007
  at ManagementMenu.OnPrefabInit () [0x0000d] in D:\JenkinsWorkspace\Preview_Simgame_Windows\game\Assets\scripts\screens\ManagementMenu.cs:70
  at KMonoBehaviour.InitializeComponent () [0x00082] in D:\JenkinsWorkspace\Preview_Simgame_Windows\game\Assets\Plugins\Klei\util\KMonoBehaviour.cs:132
Rethrow as Exception: Error in TopRightInfoPanelButtons.ManagementMenu.OnPrefabInit
  at KMonoBehaviour.InitializeComponent () [0x000cc] in D:\JenkinsWorkspace\Preview_Simgame_Windows\game\Assets\Plugins\Klei\util\KMonoBehaviour.cs:138
  at KMonoBehaviour.Awake () [0x00011] in D:\JenkinsWorkspace\Preview_Simgame_Windows\game\Assets\Plugins\Klei\util\KMonoBehaviour.cs:44

I don't know what causes the null exception in GenerateBuildingEntries. I assumed it was:

BuildingDef buildingDef = Assets.GetBuildingDef((current.data as IList<string>)[i]);

However calling BuildingConfigManager.Instance.RegisterBuilding to make sure the building is there didn't change anything.

It also crashes later, from which I assume is related to the same building and trying to add that one to the ResearchScreen.

Quote

ArgumentNullException: Argument cannot be null.
Parameter name: key
  at System.Collections.Generic.Dictionary`2[KIconToggleMenu+ToggleInfo,ManagementMenu+ScreenData].Add (.ToggleInfo key, .ScreenData value) [0x00171] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:432
  at ManagementMenu.AddResearchScreen (.ResearchScreen researchScreen) [0x00061] in D:\JenkinsWorkspace\Preview_Simgame_Windows\game\Assets\scripts\screens\ManagementMenu.cs:217
  at ResearchScreen.OnSpawn () [0x006d6] in D:\JenkinsWorkspace\Preview_Simgame_Windows\game\Assets\scripts\ui\ResearchScreen.cs:388
  at KMonoBehaviour.Spawn () [0x00075] in D:\JenkinsWorkspace\Preview_Simgame_Windows\game\Assets\Plugins\Klei\util\KMonoBehaviour.cs:284
Rethrow as Exception: Error in ResearchScreen.ResearchScreen.OnSpawn
  at KMonoBehaviour.Spawn () [0x000bf] in D:\JenkinsWorkspace\Preview_Simgame_Windows\game\Assets\Plugins\Klei\util\KMonoBehaviour.cs:291
  at KMonoBehaviour.Start () [0x00011] in D:\JenkinsWorkspace\Preview_Simgame_Windows\game\Assets\Plugins\Klei\util\KMonoBehaviour.cs:242

I'm really looking forward to the new modding features, but right now it seems I can't even do what I can do in QOL3 :(

Do anybody have any idea on what else I could do to add a modded building?

Link to comment
Share on other sites

I use this code now to insert into plans and techs:

 

	internal class IDS
	{
		public const string ID = "AutoSupermaterialRefinery";
		public const string NAME = "Automatic Supermaterial Refinery";
		public const string DESCRIPTION = "The Automatic Supermaterial Refinery does not need a duplicant to work and has extra recipes.";
		public const string EFFECT = "Supermaterial Refinery that does not need a Duplicant to operate.";
		public const string TECH =  "DupeTrafficControl";
		public const string PLANCATEGORY =   "Refining";
	}
	[HarmonyPatch(typeof(GeneratedBuildings), "LoadGeneratedBuildings")]
	internal class __LoadGeneratedBuildings
	{
		private static void Prefix()
		{
			Strings.Add("STRINGS.BUILDINGS.PREFABS." + IDS.ID.ToUpper() + ".NAME", IDS.NAME);
			Strings.Add("STRINGS.BUILDINGS.PREFABS." + IDS.ID.ToUpper() + ".DESC", IDS.DESCRIPTION);
			Strings.Add("STRINGS.BUILDINGS.PREFABS." + IDS.ID.ToUpper() + ".EFFECT", IDS.EFFECT);

			List<string> category = (List<string>)TUNING.BUILDINGS.PLANORDER.First(po => ((HashedString)IDS.PLANCATEGORY).Equals(po.category)).data;
			category.Add(IDS.ID);

			//TUNING.BUILDINGS.COMPONENT_DESCRIPTION_ORDER.Add(typeof(PressureLiquidReservoirConfig));
		}
	}
	[HarmonyPatch(typeof(Db), "Initialize")]
	internal class __Db_Initialize
	{
		private static void Prefix(Db __instance)
		{
			List<string> ls = new List<string>((string[])Database.Techs.TECH_GROUPING[IDS.TECH]);
			ls.Add(IDS.ID);
			Database.Techs.TECH_GROUPING[IDS.TECH] = (string[])ls.ToArray();
		}
	}

 

Link to comment
Share on other sites

That solution looks really nice and similar to what I'm doing. Sadly the outcome is the same. I tried removing mods.json to reset all mods settings. That didn't change anything either, though it did remove the "mods uninstalled" popup at startup.

I'm still wondering what broke my game. I'm starting to lean towards something went wrong when switching to the test branch and I should reinstall the game.

Link to comment
Share on other sites

4 minutes ago, Nightinggale said:

That solution looks really nice and similar to what I'm doing. Sadly the outcome is the same. I tried removing mods.json to reset all mods settings. That didn't change anything either, though it did remove the "mods uninstalled" popup at startup.

I'm still wondering what broke my game. I'm starting to lean towards something went wrong when switching to the test branch and I should reinstall the game.

My code works for me i really doubt there is a problem with it.

Maybe you should post the debug log

Link to comment
Share on other sites

ARRGGHHHHH!!!!!

I found the error. It only took me an entire weekend (though admittedly I did a bunch of non-modding stuff as well). It turns out that I copy pasted the line "GeneratedBuildings.RegisterWithOverlay(OverlayModes.Logic.HighlightItemIDs, ID);" and forgot to update the ID.

This didn't give me an error, but when I tried to add the building to PLANORDER, then there was nothing to add because calling CreateBuildingDef apparently failed silently, hence failing to add the building.

Lesson learned: don't count on copy pasting working code and assume it to be working.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...