Add shop block multipliers

This commit is contained in:
2025-02-23 17:53:54 +01:00
parent 8c58bf504c
commit e16a941413
4 changed files with 141 additions and 17 deletions

View File

@@ -40,6 +40,8 @@ namespace TerraTech {
public static ConfigEntry<float> wirelessChargingPowerPerArcMultiplier; public static ConfigEntry<float> wirelessChargingPowerPerArcMultiplier;
public static ConfigEntry<float> wirelessChargingArcFiringIntervalMultiplier; public static ConfigEntry<float> wirelessChargingArcFiringIntervalMultiplier;
public static ConfigEntry<float> weaponRotationSpeedMultiplier; public static ConfigEntry<float> weaponRotationSpeedMultiplier;
public static ConfigEntry<float> shopBlocksGeneratedTotalMultiplier;
public static ConfigEntry<float> shopPerBlockStopMultiplier;
public void Awake() { public void Awake() {
debug = Config.Bind("General", "Debug", false); debug = Config.Bind("General", "Debug", false);
@@ -128,6 +130,13 @@ namespace TerraTech {
new ConfigDescription("Miner Mining Speed", new AcceptableValueRange<float>(1f, 32f))); new ConfigDescription("Miner Mining Speed", new AcceptableValueRange<float>(1f, 32f)));
allProjectilesHoming = Config.Bind("General", "Make All Projectiles Home", false); 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<float>(1f, 32f)));
shopPerBlockStopMultiplier = Config.Bind(
"Shop", "Shop Per Block Stop Multiplier", 1f,
new ConfigDescription("Shop Per Block Stop Multiplier", new AcceptableValueRange<float>(1f, 32f)));
shootingSpeedMultiplier.SettingChanged += (sender, args) => WeaponPropertiesManager.DoPatch(); shootingSpeedMultiplier.SettingChanged += (sender, args) => WeaponPropertiesManager.DoPatch();
weaponRotationSpeedMultiplier.SettingChanged += (sender, args) => WeaponPropertiesManager.DoPatch(); weaponRotationSpeedMultiplier.SettingChanged += (sender, args) => WeaponPropertiesManager.DoPatch();
@@ -149,6 +158,9 @@ namespace TerraTech {
WirelessChargerPropertiesManager.DoPatch(); WirelessChargerPropertiesManager.DoPatch();
wirelessChargingRadiusMultiplier.SettingChanged += (sender, args) => wirelessChargingRadiusMultiplier.SettingChanged += (sender, args) =>
WirelessChargerPropertiesManager.DoPatch(); WirelessChargerPropertiesManager.DoPatch();
shopBlocksGeneratedTotalMultiplier.SettingChanged += (sender, args) =>
InventorySupplierPropertiesManager.DoPatch();
shopPerBlockStopMultiplier.SettingChanged += (sender, args) => InventorySupplierPropertiesManager.DoPatch();
Logger.LogInfo("Cyka mod loaded"); Logger.LogInfo("Cyka mod loaded");
HarmonyFileLog.Enabled = true; HarmonyFileLog.Enabled = true;

View File

@@ -0,0 +1,111 @@
using System;
using System.Collections.Generic;
using HarmonyLib;
namespace TerraTech {
[HarmonyPatch]
public class InventorySupplierPropertiesManager {
private static Dictionary<InventorySupplier, int> inventoryNumBlockTypes =
new Dictionary<InventorySupplier, int>();
private static Dictionary<InventorySupplier, int> inventoryQuantityPerBlockType =
new Dictionary<InventorySupplier, int>();
[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<InventorySupplier, int> 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());
}
}
}
}

View File

@@ -4,22 +4,22 @@ 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 // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("TerraTech")] [assembly:AssemblyTitle("TerraTech")]
[assembly: AssemblyDescription("")] [assembly:AssemblyDescription("")]
[assembly: AssemblyConfiguration("")] [assembly:AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly:AssemblyCompany("")]
[assembly: AssemblyProduct("TerraTech")] [assembly:AssemblyProduct("TerraTech")]
[assembly: AssemblyCopyright("Copyright © 2023")] [assembly:AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")] [assembly:AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly:AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible // 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 // to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type. // 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 // 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: // Version information for an assembly consists of the following four values:
// //
@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// 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: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")] [assembly:AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")] [assembly:AssemblyFileVersion("1.0.0.0")]

View File

@@ -42,6 +42,7 @@
<Compile Include="FuelPropertiesManager.cs" /> <Compile Include="FuelPropertiesManager.cs" />
<Compile Include="GeneratorPropertiesManager.cs" /> <Compile Include="GeneratorPropertiesManager.cs" />
<Compile Include="HomingAndVelocityProjectilePatch.cs" /> <Compile Include="HomingAndVelocityProjectilePatch.cs" />
<Compile Include="InventorySupplierPropertiesManager.cs" />
<Compile Include="MagnetPropertiesManager.cs" /> <Compile Include="MagnetPropertiesManager.cs" />
<Compile Include="MinerPropertiesManager.cs" /> <Compile Include="MinerPropertiesManager.cs" />
<Compile Include="Patches.cs" /> <Compile Include="Patches.cs" />