diff --git a/Projects/TerraTech/TerraTech/Class1.cs b/Projects/TerraTech/TerraTech/Class1.cs index bda3470..0e8d82c 100644 --- a/Projects/TerraTech/TerraTech/Class1.cs +++ b/Projects/TerraTech/TerraTech/Class1.cs @@ -40,6 +40,8 @@ namespace TerraTech { public static ConfigEntry wirelessChargingPowerPerArcMultiplier; public static ConfigEntry wirelessChargingArcFiringIntervalMultiplier; public static ConfigEntry weaponRotationSpeedMultiplier; + public static ConfigEntry shopBlocksGeneratedTotalMultiplier; + public static ConfigEntry shopPerBlockStopMultiplier; public void Awake() { debug = Config.Bind("General", "Debug", false); @@ -128,6 +130,13 @@ namespace TerraTech { new ConfigDescription("Miner Mining Speed", new AcceptableValueRange(1f, 32f))); allProjectilesHoming = Config.Bind("General", "Make All Projectiles Home", false); + shopBlocksGeneratedTotalMultiplier = + Config.Bind("Shop", "Shop Blocks Generated Total Multiplier", 1f, + new ConfigDescription("Shop Blocks Generated Total Multiplier", + new AcceptableValueRange(1f, 32f))); + shopPerBlockStopMultiplier = Config.Bind( + "Shop", "Shop Per Block Stop Multiplier", 1f, + new ConfigDescription("Shop Per Block Stop Multiplier", new AcceptableValueRange(1f, 32f))); shootingSpeedMultiplier.SettingChanged += (sender, args) => WeaponPropertiesManager.DoPatch(); weaponRotationSpeedMultiplier.SettingChanged += (sender, args) => WeaponPropertiesManager.DoPatch(); @@ -149,6 +158,9 @@ namespace TerraTech { WirelessChargerPropertiesManager.DoPatch(); wirelessChargingRadiusMultiplier.SettingChanged += (sender, args) => WirelessChargerPropertiesManager.DoPatch(); + shopBlocksGeneratedTotalMultiplier.SettingChanged += (sender, args) => + InventorySupplierPropertiesManager.DoPatch(); + shopPerBlockStopMultiplier.SettingChanged += (sender, args) => InventorySupplierPropertiesManager.DoPatch(); Logger.LogInfo("Cyka mod loaded"); HarmonyFileLog.Enabled = true; diff --git a/Projects/TerraTech/TerraTech/InventorySupplierPropertiesManager.cs b/Projects/TerraTech/TerraTech/InventorySupplierPropertiesManager.cs new file mode 100644 index 0000000..61a5127 --- /dev/null +++ b/Projects/TerraTech/TerraTech/InventorySupplierPropertiesManager.cs @@ -0,0 +1,111 @@ +using System; +using System.Collections.Generic; +using HarmonyLib; + +namespace TerraTech { + [HarmonyPatch] + public class InventorySupplierPropertiesManager { + private static Dictionary inventoryNumBlockTypes = + new Dictionary(); + private static Dictionary inventoryQuantityPerBlockType = + new Dictionary(); + + [HarmonyPrefix] + [HarmonyPatch(typeof(InventorySupplier), "CreateRandomInventoryBlockList")] + static void PrefixCreateRandomInventoryBlockList(InventorySupplier __instance) { + if (Main.debug.Value) + Console.WriteLine("InventorySupplier.CreateRandomInventoryBlockList"); + try { + if (!inventoryNumBlockTypes.ContainsKey(__instance)) { + // if (Main.debug.Value) + // Console.WriteLine("Patching; m_NumBlockTypes: {0}", __instance.m_NumBlockTypes); + DoPatchSingle(__instance); + // if (Main.debug.Value) + // Console.WriteLine("Patched; m_NumBlockTypes: {0}", __instance.m_NumBlockTypes); + } + } catch (Exception e) { + Console.WriteLine("Error patching InventorySupplier: {0}\nStack trace: {1}", e.Message, e.StackTrace); + } + } + + public static void DoPatch() { + if (Main.debug.Value) + Console.WriteLine("Modifying {0} InventorySupplier", inventoryNumBlockTypes.Count); + foreach (KeyValuePair keyValuePair in inventoryNumBlockTypes) { + try { + DoRestoreSingle(keyValuePair.Key); + DoPatchSingle(keyValuePair.Key); + } catch (Exception e) { + Console.WriteLine("Error patching InventorySupplier: {0}\nStack trace: {1}", e.Message, + e.StackTrace); + continue; + } + } + } + + static void DoPatchSingle(InventorySupplier inventorySupplier) { + var trav = Traverse.Create(inventorySupplier); + var rarityRange = trav.Field("m_RarityRangeParams").GetValue(); + var blockTypesField = trav.Field("m_RarityRangeParams").Field("m_NumBlockTypes"); + var quantityPerBlockField = trav.Field("m_RarityRangeParams").Field("m_QuantityPerBlockType"); + + if (Main.debug.Value) + Console.WriteLine("Patching {0}; rarityRange: {1}; blockTypesField: {2}; quantityPerBlockField: {3}", + "InventorySupplier", rarityRange, blockTypesField.GetValue(), + quantityPerBlockField.GetValue()); + + if (!inventoryNumBlockTypes.ContainsKey(inventorySupplier)) { + inventoryNumBlockTypes.Add(inventorySupplier, (int)blockTypesField.GetValue()); + if (Main.debug.Value) + Console.WriteLine("Added {0} to inventoryNumBlockTypes with value: {1}", inventorySupplier, + (int)blockTypesField.GetValue()); + } + if (!inventoryQuantityPerBlockType.ContainsKey(inventorySupplier)) { + inventoryQuantityPerBlockType.Add(inventorySupplier, (int)quantityPerBlockField.GetValue()); + if (Main.debug.Value) + Console.WriteLine("Added {0} to inventoryQuantityPerBlockType with value: {1}", inventorySupplier, + (int)quantityPerBlockField.GetValue()); + } + + if (inventoryNumBlockTypes.ContainsKey(inventorySupplier)) { + int newBlockTypesValue = + (int)(inventoryNumBlockTypes[inventorySupplier] * Main.shopBlocksGeneratedTotalMultiplier.Value); + blockTypesField.SetValue(newBlockTypesValue); + if (Main.debug.Value) + Console.WriteLine("Set blockTypesField value to: {0}", newBlockTypesValue); + } + if (inventoryQuantityPerBlockType.ContainsKey(inventorySupplier)) { + int newQuantityPerBlockValue = + (int)(inventoryQuantityPerBlockType[inventorySupplier] * Main.shopPerBlockStopMultiplier.Value); + quantityPerBlockField.SetValue(newQuantityPerBlockValue); + if (Main.debug.Value) + Console.WriteLine("Set quantityPerBlockField value to: {0}", newQuantityPerBlockValue); + } + + if (Main.debug.Value) + Console.WriteLine("Patched {0}; rarityRange: {1}; blockTypesField: {2}; quantityPerBlockField: {3}", + "InventorySupplier", rarityRange, blockTypesField.GetValue(), + quantityPerBlockField.GetValue()); + } + + static void DoRestoreSingle(InventorySupplier inventorySupplier) { + var trav = Traverse.Create(inventorySupplier); + var rarityRange = trav.Field("m_RarityRangeParams").GetValue(); + var blockTypesField = trav.Field("m_RarityRangeParams").Field("m_NumBlockTypes"); + var quantityPerBlockField = trav.Field("m_RarityRangeParams").Field("m_QuantityPerBlockType"); + + if (Main.debug.Value) + Console.WriteLine("Restoring {0}; rarityRange: {1}; blockTypesField: {2}; quantityPerBlockField: {3}", + "InventorySupplier", rarityRange, blockTypesField.GetValue(), + quantityPerBlockField.GetValue()); + if (inventoryNumBlockTypes.ContainsKey(inventorySupplier)) { + blockTypesField.SetValue(inventoryNumBlockTypes[inventorySupplier]); + quantityPerBlockField.SetValue(inventoryQuantityPerBlockType[inventorySupplier]); + if (Main.debug.Value) + Console.WriteLine( + "Restored {0}; rarityRange: {1}; blockTypesField: {2}; quantityPerBlockField: {3}", + "InventorySupplier", rarityRange, blockTypesField.GetValue(), quantityPerBlockField.GetValue()); + } + } + } +} diff --git a/Projects/TerraTech/TerraTech/Properties/AssemblyInfo.cs b/Projects/TerraTech/TerraTech/Properties/AssemblyInfo.cs index e5c11ac..7a7cc0a 100644 --- a/Projects/TerraTech/TerraTech/Properties/AssemblyInfo.cs +++ b/Projects/TerraTech/TerraTech/Properties/AssemblyInfo.cs @@ -1,35 +1,35 @@ using System.Reflection; using System.Runtime.InteropServices; -// General Information about an assembly is controlled through the following +// General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("TerraTech")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("TerraTech")] -[assembly: AssemblyCopyright("Copyright © 2023")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] +[assembly:AssemblyTitle("TerraTech")] +[assembly:AssemblyDescription("")] +[assembly:AssemblyConfiguration("")] +[assembly:AssemblyCompany("")] +[assembly:AssemblyProduct("TerraTech")] +[assembly:AssemblyCopyright("Copyright © 2023")] +[assembly:AssemblyTrademark("")] +[assembly:AssemblyCulture("")] -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] +[assembly:ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("EE5EFB7F-A4DC-44F0-967B-F71ECA2D46AE")] +[assembly:Guid("EE5EFB7F-A4DC-44F0-967B-F71ECA2D46AE")] // Version information for an assembly consists of the following four values: // // Major Version -// Minor Version +// Minor Version // Build Number // Revision // -// You can specify all the values or you can default the Build and Revision Numbers +// You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file +[assembly:AssemblyVersion("1.0.0.0")] +[assembly:AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Projects/TerraTech/TerraTech/TerraTech.csproj b/Projects/TerraTech/TerraTech/TerraTech.csproj index 546f477..96a450d 100644 --- a/Projects/TerraTech/TerraTech/TerraTech.csproj +++ b/Projects/TerraTech/TerraTech/TerraTech.csproj @@ -42,6 +42,7 @@ +