8 Commits

11 changed files with 143 additions and 16 deletions

View File

@@ -7,7 +7,7 @@ using BepInEx.Configuration;
using HarmonyLib;
using HarmonyLib.Tools;
namespace CykaMod {
namespace DavesPhatStore {
[BepInPlugin(pluginGuid, pluginName, pluginVersion)]
public class Main : BaseUnityPlugin {
private const string pluginGuid = "SupermarketTogether";
@@ -15,9 +15,81 @@ namespace CykaMod {
private const string pluginVersion = "1.0.0";
public static ConfigEntry<int> playersAdded;
public static ConfigEntry<int> employeePerPerk;
public static ConfigEntry<float> employeeSpeedPerk;
public static ConfigEntry<float> employeeExtraMoneyPerk;
public static ConfigEntry<float> productCheckoutWait;
public static ConfigEntry<float> productItemPlaceWait;
public static ConfigEntry<float> employeeItemPlaceWait;
public static List<WeakReference<NPC_Info>> NpcInfos = new List<WeakReference<NPC_Info>>();
public void Awake() {
playersAdded = Config.Bind("General", "PlayersAdded", 0);
employeePerPerk = Config.Bind("General", "EmployeePerPerk", 1);
employeeSpeedPerk = Config.Bind("General", "EmployeeSpeedPerk", 0.2f);
employeeExtraMoneyPerk = Config.Bind("General", "EmployeeExtraMoneyPerk", 0.1f);
productCheckoutWait = Config.Bind("General", "ProductCheckoutWait", 0.75f);
productItemPlaceWait = Config.Bind("General", "ProductItemPlaceWait", 0.5f);
employeeItemPlaceWait = Config.Bind("General", "EmployeeItemPlaceWait", 0.2f);
productCheckoutWait.SettingChanged += (sender, args) => {
Console.WriteLine($"ProductCheckoutWait changed to {productCheckoutWait.Value}");
productCheckoutWait.Value = Math.Max(productCheckoutWait.Value, 0.02f);
int n = 0;
for (var i = 0; i < NpcInfos.Count; i++) {
var npcInfo = GetNpcInfo(i);
if (npcInfo == null) {
NpcInfos.RemoveAt(i);
i--;
continue;
}
n++;
npcInfo.productCheckoutWait = productCheckoutWait.Value;
}
Console.WriteLine($"Updated {n} npc infos productCheckoutWait to {productCheckoutWait.Value}");
};
productItemPlaceWait.SettingChanged += (sender, args) => {
Console.WriteLine($"ProductItemPlaceWait changed to {productItemPlaceWait.Value}");
productItemPlaceWait.Value = Math.Max(productItemPlaceWait.Value, 0.02f);
int n = 0;
for (var i = 0; i < NpcInfos.Count; i++) {
var npcInfo = GetNpcInfo(i);
if (npcInfo == null) {
NpcInfos.RemoveAt(i);
i--;
continue;
}
n++;
npcInfo.productItemPlaceWait = productItemPlaceWait.Value;
}
Console.WriteLine($"Updated {n} npc infos productItemPlaceWait to {productItemPlaceWait.Value}");
};
employeeItemPlaceWait.SettingChanged += (sender, args) => {
Console.WriteLine($"EmployeeItemPlaceWait changed to {employeeItemPlaceWait.Value}");
employeeItemPlaceWait.Value = Math.Max(employeeItemPlaceWait.Value, 0.02f);
int n = 0;
for (var i = 0; i < NpcInfos.Count; i++) {
var npcInfo = GetNpcInfo(i);
if (npcInfo == null) {
NpcInfos.RemoveAt(i);
i--;
continue;
}
n++;
npcInfo.employeeItemPlaceWait = employeeItemPlaceWait.Value;
}
Console.WriteLine($"Updated {n} npc infos employeeItemPlaceWait to {employeeItemPlaceWait.Value}");
};
Logger.LogInfo("Cyka mod loaded");
HarmonyFileLog.Enabled = true;
@@ -26,6 +98,30 @@ namespace CykaMod {
var originalMethods = harmony.GetPatchedMethods();
Logger.LogInfo("Patched " + originalMethods.Count() + " methods");
}
private static NPC_Info GetNpcInfo(int index) {
if (index < 0 || index >= NpcInfos.Count)
return null;
NPC_Info npcInfo;
if (NpcInfos[index].TryGetTarget(out npcInfo)) {
return npcInfo;
}
return null;
}
}
[HarmonyPatch(typeof(NPC_Info), MethodType.Constructor)]
public static class NpcInfoConstructorPatch {
static void Postfix(NPC_Info __instance) {
Main.NpcInfos.Add(new WeakReference<NPC_Info>(__instance));
__instance.productItemPlaceWait = Main.productItemPlaceWait.Value;
__instance.productCheckoutWait = Main.productCheckoutWait.Value;
__instance.employeeItemPlaceWait = Main.employeeItemPlaceWait.Value;
Console.WriteLine(
$"Updated npc info with values: {__instance.productItemPlaceWait}, {__instance.productCheckoutWait}, {__instance.employeeItemPlaceWait}");
}
}
[HarmonyPatch(typeof(GameData), "UserCode_CmdOpenSupermarket")]
@@ -44,9 +140,44 @@ namespace CykaMod {
var codes = new List<CodeInstruction>(instructions);
for (int i = 0; i < codes.Count; i++) {
if (codes[i].opcode == OpCodes.Ldc_I4_1) {
Console.WriteLine("Found Ldc_I4_1");
codes[i].opcode = OpCodes.Ldc_I4_2;
var codeInstruction = codes[i];
// if (codeInstruction.operand != null) {
// Console.WriteLine($"'{codeInstruction.operand.ToString()}'");
// Console.WriteLine(codeInstruction.operand.ToString() == "NPC_Manager::extraEmployeeSpeedFactor");
// }
if (codeInstruction.opcode == OpCodes.Ldfld &&
codeInstruction.operand?.ToString() == "System.Int32 maxEmployees") {
Console.WriteLine($"Found {codeInstruction.operand}");
codes[i + 1].opcode = OpCodes.Nop;
codes.Insert(i + 2,
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(Main), "employeePerPerk")));
codes.Insert(i + 3,
new CodeInstruction(OpCodes.Call,
AccessTools.PropertyGetter(typeof(Main).GetField("employeePerPerk").FieldType, "Value")));
}
if (codeInstruction.opcode == OpCodes.Ldfld &&
codeInstruction.operand?.ToString() == "System.Single extraEmployeeSpeedFactor") {
Console.WriteLine($"Found {codeInstruction.operand}");
codes[i + 1].opcode = OpCodes.Nop;
codes.Insert(i + 2,
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(Main), "employeeSpeedPerk")));
codes.Insert(i + 3,
new CodeInstruction(OpCodes.Call,
AccessTools.PropertyGetter(typeof(Main).GetField("employeeSpeedPerk").FieldType, "Value")));
}
if (codeInstruction.opcode == OpCodes.Ldfld &&
codeInstruction.operand?.ToString() == "System.Single extraCheckoutMoney") {
Console.WriteLine($"Found {codeInstruction.operand}");
codes[i + 1].opcode = OpCodes.Nop;
codes.Insert(i + 2,
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(Main), "employeeExtraMoneyPerk")));
codes.Insert(i + 3,
new CodeInstruction(OpCodes.Call,
AccessTools.PropertyGetter(typeof(Main).GetField("employeeExtraMoneyPerk").FieldType,
"Value")));
}
}

View File

@@ -4,11 +4,11 @@ using System.Runtime.InteropServices;
// 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("Regiments")]
[assembly: AssemblyTitle("DavesPhatStore")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Regiments")]
[assembly: AssemblyProduct("DavesPhatStore")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

View File

@@ -10,8 +10,8 @@
<ProjectGuid>{DA9D274E-486F-4F82-84FF-CD9388CB0B09}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SupermarketTogether</RootNamespace>
<AssemblyName>SupermarketTogether</AssemblyName>
<RootNamespace>DavesPhatStore</RootNamespace>
<AssemblyName>DavesPhatStore</AssemblyName>
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
@@ -57,6 +57,9 @@
<Reference Include="UnityEngine.CoreModule">
<HintPath>$(GAME_MANAGED)/UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="Mirror">
<HintPath>$(GAME_MANAGED)/Mirror.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
</Project>

View File

@@ -1 +0,0 @@
for lib in $(cat libs.txt); do find 'C:\Program Files (x86)\Steam\steamapps\common\Mad Games Tycoon 2' -name "$lib" | sed 's|\\|/|g' | xargs -I% -- cp '%' .; done

View File

@@ -1,6 +0,0 @@
0Harmony.dll
Assembly-CSharp.dll
BepInEx.dll
ConfigurationManager.dll
UnityEngine.CoreModule.dll
UnityEngine.dll