From 0feaf5a6ce246576d2ac778415c01d8b6668bae6 Mon Sep 17 00:00:00 2001
From: Sgt_Imalas <20609939+Sgt-Imalas@users.noreply.github.com>
Date: Mon, 22 Sep 2025 23:43:52 +0200
Subject: [PATCH 1/4] Add an easy to reflect for static getter method for the
mod config
---
src/CustomizeBuildings/_CustomizeBuildingsState.cs | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/src/CustomizeBuildings/_CustomizeBuildingsState.cs b/src/CustomizeBuildings/_CustomizeBuildingsState.cs
index 6fac1da..d70ff8d 100644
--- a/src/CustomizeBuildings/_CustomizeBuildingsState.cs
+++ b/src/CustomizeBuildings/_CustomizeBuildingsState.cs
@@ -6,6 +6,7 @@
using PeterHan.PLib.Options;
using System.IO;
using System;
+using System.Diagnostics;
namespace CustomizeBuildings
{
@@ -14,6 +15,16 @@ namespace CustomizeBuildings
[ModInfo(null, collapse: true)]
public class CustomizeBuildingsState : IManualConfig
{
+ ///
+ /// static method that returns the current config state.
+ /// Makes it possible for other mods to easily reflect for the config state to read values.
+ ///
+ ///
+ public static object GetModConfigState()
+ {
+ return StateManager.State;
+ }
+
public int version { get; set; } = 59;
#region $Reset Button
From 1cdf40f7a6b11f0e20476029e42ed67d23d43f57 Mon Sep 17 00:00:00 2001
From: Sgt_Imalas <20609939+Sgt-Imalas@users.noreply.github.com>
Date: Mon, 22 Sep 2025 23:44:18 +0200
Subject: [PATCH 2/4] Add example mod integration class other mods can copy
---
.../Customize_Buildings_ModIntegration.cs | 78 +++++++++++++++++++
1 file changed, 78 insertions(+)
create mode 100644 src/CustomizeBuildings/Customize_Buildings_ModIntegration.cs
diff --git a/src/CustomizeBuildings/Customize_Buildings_ModIntegration.cs b/src/CustomizeBuildings/Customize_Buildings_ModIntegration.cs
new file mode 100644
index 0000000..bd19717
--- /dev/null
+++ b/src/CustomizeBuildings/Customize_Buildings_ModIntegration.cs
@@ -0,0 +1,78 @@
+using HarmonyLib;
+using System;
+
+namespace CustomizeBuildings
+{
+ ///
+ /// This class can be copied by other mods to easily read values from the mod config of CustomizeBuildings
+ ///
+ public static class Customize_Buildings_ModIntegration
+ {
+ static object ConfigState = null;
+ public static bool IntegrationActive { get; private set; } = false;
+ static bool _initializationRun = false;
+
+ ///
+ /// Fetches a reference to the config state object to later read values from it
+ ///
+ public static void Init()
+ {
+ if (_initializationRun)
+ return;
+ _initializationRun = true;
+
+ ///fetch the config class type
+ var CustomizeBuildings_CustomizeBuildingsState = Type.GetType("CustomizeBuildings.CustomizeBuildingsState, CustomizeBuildings");
+ if (CustomizeBuildings_CustomizeBuildingsState == null)
+ {
+ Debug.Log("CustomizeBuildings types not found.");
+ return;
+ }
+ ///fetch the method info of the static getter method
+ var m_GetModConfigState = AccessTools.Method(CustomizeBuildings_CustomizeBuildingsState.GetType(), "GetModConfigState");
+ if (m_GetModConfigState == null)
+ {
+ Debug.LogWarning("CustomizeBuildings.CustomizeBuildingsState.GetModConfigState method not found.");
+ return;
+ }
+ ///fetch the mod config state object
+ ConfigState = m_GetModConfigState.Invoke(null, null);
+ IntegrationActive = ConfigState != null;
+ }
+
+ ///
+ /// wrapper that allows fetching a config state value of type T
+ /// Can only reliably be called after all mods are loaded, e.g. during a non-transpiler patch
+ ///
+ /// type of the property to fetch
+ /// name of the property
+ /// fetched value of the property. default(T) if not found or the types dont match
+ /// bool if the property was found successfully
+ public static bool TryGetConfigValue(string propertyName, out T value)
+ {
+ value = default(T);
+ Init();
+ if (!IntegrationActive)
+ return false;
+
+ Traverse property = Traverse.Create(ConfigState).Property(propertyName);
+ if (!property.PropertyExists())
+ {
+ Debug.LogWarning("Mod Config State did not have a property with the name: " + propertyName);
+ return false;
+
+ }
+ object propertyValue = property.GetValue();
+ var foundType = propertyValue.GetType();
+ var T_Type = typeof(T);
+ if (foundType != T_Type)
+ {
+ Debug.LogWarning("Mod Config State had a property with the name: " + propertyName + ", but it was typeOf " + foundType.Name + ", instead of the expected " + T_Type.Name);
+ return false;
+ }
+
+ value = (T)propertyValue;
+ return true;
+ }
+ }
+}
From 67003dc280f6adf7043944395b4dcca6be2449b8 Mon Sep 17 00:00:00 2001
From: Sgt_Imalas <20609939+Sgt-Imalas@users.noreply.github.com>
Date: Mon, 22 Sep 2025 23:46:26 +0200
Subject: [PATCH 3/4] rm accidental extra using
---
src/CustomizeBuildings/_CustomizeBuildingsState.cs | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/CustomizeBuildings/_CustomizeBuildingsState.cs b/src/CustomizeBuildings/_CustomizeBuildingsState.cs
index d70ff8d..5fc2469 100644
--- a/src/CustomizeBuildings/_CustomizeBuildingsState.cs
+++ b/src/CustomizeBuildings/_CustomizeBuildingsState.cs
@@ -6,7 +6,6 @@
using PeterHan.PLib.Options;
using System.IO;
using System;
-using System.Diagnostics;
namespace CustomizeBuildings
{
From a057d28ea08399a38ee708f4b8d9701fe377032b Mon Sep 17 00:00:00 2001
From: Sgt_Imalas <20609939+Sgt-Imalas@users.noreply.github.com>
Date: Mon, 22 Sep 2025 23:50:26 +0200
Subject: [PATCH 4/4] additional use comment
---
src/CustomizeBuildings/Customize_Buildings_ModIntegration.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/CustomizeBuildings/Customize_Buildings_ModIntegration.cs b/src/CustomizeBuildings/Customize_Buildings_ModIntegration.cs
index bd19717..4afaa09 100644
--- a/src/CustomizeBuildings/Customize_Buildings_ModIntegration.cs
+++ b/src/CustomizeBuildings/Customize_Buildings_ModIntegration.cs
@@ -42,7 +42,7 @@ public static void Init()
///
/// wrapper that allows fetching a config state value of type T
- /// Can only reliably be called after all mods are loaded, e.g. during a non-transpiler patch
+ /// Can only reliably be called after all mods are loaded, e.g. during a non-transpiler patch or in a building/entity definition method
///
/// type of the property to fetch
/// name of the property