private static bool Prefix(BuildingConfigManager __instance, IBuildingConfig config) { bool result = false; if (Hooked) { return(true); } //CreateBuildingDef BuildingDef buildingDef = config.CreateBuildingDef(); Hooked = true; try { result = RegisterBuilding(__instance, config, buildingDef); } catch (Exception e) { Debug.Log(" === [BuildingModifier] ERROR registering building [" + buildingDef.PrefabID + "]. Incompatible building config."); Debug.Log(e.StackTrace); // __instance.RegisterBuilding(config); //throw e; Application.Quit(); } Hooked = false; return(result); }
private static void Postfix(BuildingConfigManager __instance) { if (!Helper.Config.Enabled) { return; } Helper.Log(" === [BuildingModifier] BuildingModifierMod_BuildingConfigManager_ConfigurePost Postfix === "); // After the execution of BuildingConfigManager.ConfigurePost, this iterates // over all buildings and tries the last attribute modifications foreach (KeyValuePair <IBuildingConfig, BuildingDef> item in (Dictionary <IBuildingConfig, BuildingDef>)configTableF.GetValue(__instance)) { // Check if building has a mod config if (!Helper.Config.Modifiers.ContainsKey(item.Value.PrefabID)) { continue; } Helper.Process("ConfigurePost", item.Value, item.Value.BuildingComplete); } // List all config attributes not found or that throw an error if (Helper.ModifiersAll.Count() != Helper.ModifiersFound.Count()) { Debug.Log(" === [BuildingModifier] ERROR: Not found modifiers:"); foreach (string modifier in Helper.ModifiersAll) { if (!Helper.ModifiersFound.Contains(modifier)) { Debug.Log(modifier); } } } else { Debug.Log(" === [BuildingModifier] No errors found."); } Debug.Log(" === [BuildingModifier] Finished."); }
protected override void OnPrefabInit() { Instance = this; baseTemplate = new GameObject("BuildingTemplate"); baseTemplate.SetActive(false); baseTemplate.AddComponent <KPrefabID>(); baseTemplate.AddComponent <KSelectable>(); baseTemplate.AddComponent <Modifiers>(); baseTemplate.AddComponent <PrimaryElement>(); baseTemplate.AddComponent <BuildingComplete>(); baseTemplate.AddComponent <StateMachineController>(); baseTemplate.AddComponent <Deconstructable>(); baseTemplate.AddComponent <SaveLoadRoot>(); baseTemplate.AddComponent <OccupyArea>(); baseTemplate.AddComponent <DecorProvider>(); baseTemplate.AddComponent <Operational>(); baseTemplate.AddComponent <BuildingEnabledButton>(); baseTemplate.AddComponent <Prioritizable>(); baseTemplate.AddComponent <BuildingHP>(); baseTemplate.AddComponent <LoopingSounds>(); baseTemplate.AddComponent <InvalidPortReporter>(); defaultBuildingCompleteKComponents.Add(typeof(RequiresFoundation)); }
private static bool RegisterBuilding(BuildingConfigManager __instance, IBuildingConfig config, BuildingDef buildingDef) { //Debug.Log(config.CreateBuildingDef().PrefabID); if (!Helper.Config.Enabled) { return(true); } Helper.Log(" === [BuildingModifier] BuildingModifierMod_BuildingConfigManager_RegisterBuilding Prefix === "); //CreateBuildingDef //BuildingDef buildingDef = config.CreateBuildingDef(); // Check if there is a config for the current building if (!Helper.Config.Modifiers.ContainsKey(buildingDef.PrefabID)) { Helper.Log(" === [BuildingModifier] Ignoring: " + buildingDef.PrefabID); return(true); } Debug.Log(" === [BuildingModifier] Processing: " + buildingDef.PrefabID); Helper.Log(" === [BuildingModifier] CreateBuildingDef === "); Helper.Process(buildingDef, null); buildingDef.GenerateOffsets(); // Remake the offsets after modification // Create gameobject //configTable[config] = buildingDef; ((Dictionary <IBuildingConfig, BuildingDef>)configTableF.GetValue(__instance))[config] = buildingDef; //GameObject gameObject = Object.Instantiate(baseTemplate); GameObject gameObject = UnityEngine.Object.Instantiate((GameObject)baseTemplateF.GetValue(__instance)); UnityEngine.Object.DontDestroyOnLoad(gameObject); gameObject.GetComponent <KPrefabID>().PrefabTag = buildingDef.Tag; gameObject.name = buildingDef.PrefabID + "Template"; gameObject.GetComponent <Building>().Def = buildingDef; gameObject.GetComponent <OccupyArea>().OccupiedCellsOffsets = buildingDef.PlacementOffsets; if (buildingDef.Deprecated) { gameObject.GetComponent <KPrefabID>().AddTag(GameTags.DeprecatedContent); } //ConfigureBuildingTemplate config.ConfigureBuildingTemplate(gameObject, buildingDef.Tag); Helper.Log(" === [BuildingModifier] ConfigureBuildingTemplate === "); Helper.Process(buildingDef, gameObject); //ConfigureBuildingTemplate buildingDef.BuildingComplete = BuildingLoader.Instance.CreateBuildingComplete(gameObject, buildingDef); Helper.Log(" === [BuildingModifier] CreateBuildingComplete === "); Helper.Process(buildingDef, gameObject); bool flag = true; //for (int i = 0; i < NonBuildableBuildings.Length; i++) for (int i = 0; i < ((string[])NonBuildableBuildingsF.GetValue(__instance)).Length; i++) { //if (buildingDef.PrefabID == NonBuildableBuildings[i]) if (buildingDef.PrefabID == ((string[])NonBuildableBuildingsF.GetValue(__instance))[i]) { flag = false; break; } } // Previews if (flag) { buildingDef.BuildingUnderConstruction = BuildingLoader.Instance.CreateBuildingUnderConstruction(buildingDef); buildingDef.BuildingUnderConstruction.name = BuildingConfigManager.GetUnderConstructionName(buildingDef.BuildingUnderConstruction.name); buildingDef.BuildingPreview = BuildingLoader.Instance.CreateBuildingPreview(buildingDef); buildingDef.BuildingPreview.name += "Preview"; } buildingDef.PostProcess(); // Try to avoid errors if the gameobject doesn't have RequiereInputs /* * if (gameObject.GetComponent<RequireInputs>() == null) * gameObject.AddOrGet<RequireInputs>(); */ //DoPostConfigureComplete config.DoPostConfigureComplete(buildingDef.BuildingComplete); Helper.Log(" === [BuildingModifier] DoPostConfigureComplete === "); Helper.Process(buildingDef, gameObject); // Previews if (flag) { config.DoPostConfigurePreview(buildingDef, buildingDef.BuildingPreview); Helper.Log(" === [BuildingModifier] CreateBuildingUnderConstruction === "); Helper.Process(buildingDef, gameObject); config.DoPostConfigureUnderConstruction(buildingDef.BuildingUnderConstruction); Helper.Log(" === [BuildingModifier] CreateBuildingPreview === "); Helper.Process(buildingDef, gameObject); } Assets.AddBuildingDef(buildingDef); return(false); }