Decompiled source of MoneyForKills v1.4.4

MoneyForKills.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LC_MoneyForKills.Patches;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MoneyForKills")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MoneyForKills")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("de022c53-3670-44b6-aebc-656df3c12537")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
public class Config
{
	private string prefix = "Credit reward for killing ";

	private string vanillaCategoryString = "Vanilla Values";

	private string moddedCategoryString = "Modded Values";

	private string miscCategoryString = "Miscellaneous Values";

	private string generalCategoryString = "General";

	public static ConfigEntry<int> cVal1;

	public static ConfigEntry<int> cVal2;

	public static ConfigEntry<int> cVal3;

	public static ConfigEntry<int> cVal4;

	public static ConfigEntry<int> cVal5;

	public static ConfigEntry<int> cVal6;

	public static ConfigEntry<int> cVal7;

	public static ConfigEntry<int> cVal8;

	public static ConfigEntry<int> cVal9;

	public static ConfigEntry<int> cVal10;

	public static ConfigEntry<int> cVal11;

	public static ConfigEntry<int> cVal12;

	public static ConfigEntry<int> cVal13;

	public static ConfigEntry<int> cVal14;

	public static ConfigEntry<int> cVal15;

	public static ConfigEntry<int> cVal16;

	public static ConfigEntry<int> cVal17;

	public static ConfigEntry<int> cVal18;

	public static ConfigEntry<int> cVal19;

	public static ConfigEntry<int> cValMod1;

	public static ConfigEntry<int> cValMod2;

	public static ConfigEntry<int> cValMod3;

	public static ConfigEntry<int> cValMod4;

	public static ConfigEntry<int> cValPlayer;

	public static ConfigEntry<bool> cNotification;

	public static ConfigEntry<bool> cPlayerNotification;

	public static ConfigEntry<bool> cQuota;

	public static ConfigEntry<bool> cBank;

	public Config(ConfigFile cfg)
	{
		cVal1 = cfg.Bind<int>(vanillaCategoryString, "SnareFlea Reward", 25, prefix + "Snare Flea");
		cVal2 = cfg.Bind<int>(vanillaCategoryString, "BunkerSpider Reward", 80, prefix + "Bunker Spider");
		cVal3 = cfg.Bind<int>(vanillaCategoryString, "HoardingBug Reward", 25, prefix + "Hoarding Bug");
		cVal4 = cfg.Bind<int>(vanillaCategoryString, "Bracken Reward", 150, prefix + "Bracken");
		cVal5 = cfg.Bind<int>(vanillaCategoryString, "Thumper Reward", 125, prefix + "Thumper");
		cVal6 = cfg.Bind<int>(vanillaCategoryString, "Nutcracker Reward", 100, prefix + "Nutcracker");
		cVal7 = cfg.Bind<int>(vanillaCategoryString, "Masked Reward", 75, prefix + "Masked");
		cVal8 = cfg.Bind<int>(vanillaCategoryString, "Butler Reward", 100, prefix + "Butler");
		cVal9 = cfg.Bind<int>(vanillaCategoryString, "EyelessDog Reward", 125, prefix + "Eyeless Dog");
		cVal10 = cfg.Bind<int>(vanillaCategoryString, "ForestKeeper Reward", 300, prefix + "Forest Keeper");
		cVal11 = cfg.Bind<int>(vanillaCategoryString, "BaboonHawk Reward", 25, prefix + "Baboon Hawk");
		cVal12 = cfg.Bind<int>(vanillaCategoryString, "Manticoil Reward", 10, prefix + "Manticoil");
		cVal13 = cfg.Bind<int>(vanillaCategoryString, "TulipSnake Reward", 15, prefix + "Tulip Snake");
		cVal14 = cfg.Bind<int>(vanillaCategoryString, "Maneater Reward", 300, prefix + "Maneater");
		cVal15 = cfg.Bind<int>(vanillaCategoryString, "Sapsucker Reward", 300, prefix + "Sapsucker");
		cVal16 = cfg.Bind<int>(vanillaCategoryString, "KidnapperFox Reward", 150, prefix + "Kidnapper Fox");
		cVal17 = cfg.Bind<int>(vanillaCategoryString, "BackwaterGunkfish Reward", 20, prefix + "Backwater Gunkfish");
		cVal18 = cfg.Bind<int>(vanillaCategoryString, "Feiopar Reward", 90, prefix + "Feiopar");
		cVal19 = cfg.Bind<int>(vanillaCategoryString, "CadaverBloom Reward", 275, prefix + "Cadaver Bloom");
		cValMod1 = cfg.Bind<int>(moddedCategoryString, "Modded Reward 0", 25, prefix + "any modded entity whose power level is >= 0 and < 1");
		cValMod2 = cfg.Bind<int>(moddedCategoryString, "Modded Reward 1", 75, prefix + "any modded entity whose power level is >= 1 and < 2");
		cValMod3 = cfg.Bind<int>(moddedCategoryString, "Modded Reward 2", 150, prefix + "any modded entity whose power level is >= 2 and < 3");
		cValMod4 = cfg.Bind<int>(moddedCategoryString, "Modded Reward 3", 250, prefix + "any modded entity whose power level is >= 3");
		cValPlayer = cfg.Bind<int>(miscCategoryString, "Player Reward", 0, "Credits received for player deaths");
		cNotification = cfg.Bind<bool>(generalCategoryString, "Play Notification", true, "Toggles notifications for killing an entity and the credits received, or deducted if negative. Visible to all players.");
		cPlayerNotification = cfg.Bind<bool>(generalCategoryString, "Play Player Death Notification", false, "Toggles notifications for player deaths/kills and credits received, or deducted if negative. Visible to all players.");
		cQuota = cfg.Bind<bool>(generalCategoryString, "Add To Quota", false, "Add credit reward towards the quota (May cause problems when exceeding current quota goal, Quota Rollover reccommended)");
		cBank = cfg.Bind<bool>(generalCategoryString, "Add To Bank", true, "Add credit reward towards the bank");
	}
}
namespace LC_MoneyForKills
{
	[BepInPlugin("Jack.MoneyForKills", "MoneyForKills", "1.4.4")]
	public class MFKBase : BaseUnityPlugin
	{
		private const string modGUID = "Jack.MoneyForKills";

		private const string modName = "MoneyForKills";

		private const string modVersion = "1.4.4";

		private readonly Harmony harmony = new Harmony("Jack.MoneyForKills");

		private static MFKBase Instance;

		internal static ManualLogSource mls;

		public static Config myConfig { get; internal set; }

		private void Awake()
		{
			myConfig = new Config(((BaseUnityPlugin)this).Config);
			if (Instance == null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Jack.MoneyForKills");
			mls.LogInfo((object)("Successfully loaded " + "MoneyForKills v.1.4.4"));
			harmony.PatchAll(typeof(MFKBase));
			harmony.PatchAll(typeof(MoneyPatch));
		}
	}
}
namespace LC_MoneyForKills.Patches
{
	[HarmonyPatch]
	internal class MoneyPatch
	{
		private static Dictionary<string, int> enemyBounties = new Dictionary<string, int>
		{
			{
				"Centipede",
				Config.cVal1.Value
			},
			{
				"Bunker Spider",
				Config.cVal2.Value
			},
			{
				"Hoarding bug",
				Config.cVal3.Value
			},
			{
				"Flowerman",
				Config.cVal4.Value
			},
			{
				"Crawler",
				Config.cVal5.Value
			},
			{
				"Nutcracker",
				Config.cVal6.Value
			},
			{
				"Masked",
				Config.cVal7.Value
			},
			{
				"Butler",
				Config.cVal8.Value
			},
			{
				"MouthDog",
				Config.cVal9.Value
			},
			{
				"ForestGiant",
				Config.cVal10.Value
			},
			{
				"Baboon hawk",
				Config.cVal11.Value
			},
			{
				"Manticoil",
				Config.cVal12.Value
			},
			{
				"Tulip Snake",
				Config.cVal13.Value
			},
			{
				"Maneater",
				Config.cVal14.Value
			},
			{
				"GiantKiwi",
				Config.cVal15.Value
			},
			{
				"Bush Wolf",
				Config.cVal16.Value
			},
			{
				"Stingray",
				Config.cVal17.Value
			},
			{
				"Feiopar",
				Config.cVal18.Value
			},
			{
				"Cadaver Bloom",
				Config.cVal19.Value
			},
			{
				"PL0",
				Config.cValMod1.Value
			},
			{
				"PL1",
				Config.cValMod2.Value
			},
			{
				"PL2",
				Config.cValMod3.Value
			},
			{
				"PL3",
				Config.cValMod4.Value
			}
		};

		private static readonly Dictionary<string, string> enemyNames = new Dictionary<string, string>
		{
			{ "Centipede", "Centipede" },
			{ "Bunker Spider", "Bunker Spider" },
			{ "Hoarding bug", "Hoarding Bug" },
			{ "Flowerman", "Bracken" },
			{ "Crawler", "Thumper" },
			{ "Nutcracker", "Nutcracker" },
			{ "Masked", "Masked" },
			{ "Butler", "Butler" },
			{ "MouthDog", "Eyeless Dog" },
			{ "ForestGiant", "Forest Giant" },
			{ "Baboon hawk", "Baboon Hawk" },
			{ "Manticoil", "Manticoil" },
			{ "Tulip Snake", "Tulip Snake" },
			{ "Maneater", "Maneater" },
			{ "GiantKiwi", "Giant Sapsucker" },
			{ "Bush Wolf", "Kidnapper Fox" },
			{ "Stingray", "Backwater Gunkfish" },
			{ "Feiopar", "Feiopar" },
			{ "Cadaver Bloom", "Cadaver Bloom" }
		};

		private static readonly List<string> vanillaList = new List<string>
		{
			"Red Locust Bees", "Manticoil", "Docile Locust Bees", "MouthDog", "ForestGiant", "Earth Leviathan", "RadMech", "Bush Wolf", "Tulip Snake", "Baboon hawk",
			"Centipede", "Bunker Spider", "Hoarding bug", "Flowerman", "Crawler", "Blob", "Girl", "Puffer", "Nutcracker", "Clay Surgeon",
			"Spring", "Jester", "Lasso", "Masked", "Butler", "Maneater", "GiantKiwi", "Stingray", "Feiopar", "Cadaver Bloom"
		};

		private static int getBounty(EnemyType obj)
		{
			if (enemyBounties.ContainsKey(obj.enemyName))
			{
				return enemyBounties[obj.enemyName];
			}
			MFKBase.mls.LogInfo((object)("Enemy " + obj.enemyName + " not found in vanilla enemy dictionary. Using enemy's power level of " + obj.PowerLevel));
			if (obj.PowerLevel >= 0f && obj.PowerLevel < 1f)
			{
				return enemyBounties["PL0"];
			}
			if (obj.PowerLevel >= 1f && obj.PowerLevel < 2f)
			{
				return enemyBounties["PL1"];
			}
			if (obj.PowerLevel >= 2f && obj.PowerLevel < 3f)
			{
				return enemyBounties["PL2"];
			}
			if (obj.PowerLevel >= 3f)
			{
				return enemyBounties["PL3"];
			}
			return 0;
		}

		private static string getName(EnemyType obj)
		{
			if (enemyNames.ContainsKey(obj.enemyName))
			{
				return enemyNames[obj.enemyName];
			}
			MFKBase.mls.LogInfo((object)("Enemy " + obj.enemyName + " not found in vanilla enemy dictionary. Returning internal name as common name..."));
			return obj.enemyName;
		}

		[HarmonyPatch(typeof(EnemyAI))]
		[HarmonyPatch("KillEnemy")]
		[HarmonyPostfix]
		private static void KillEnemyPatch(EnemyAI __instance)
		{
			EnemyType enemyType = __instance.enemyType;
			int bounty = getBounty(enemyType);
			string name = getName(enemyType);
			MFKBase.mls.LogInfo((object)("Enemy killed: " + name + " ... Enemy bounty: " + bounty));
			if (bounty == 0)
			{
				return;
			}
			if (Config.cNotification.Value)
			{
				if (!Config.cQuota.Value && Config.cBank.Value)
				{
					if (bounty > 0)
					{
						HUDManager.Instance.DisplayTip(name + " killed!", bounty + " credits have been added to your balance", false, false, "LC_Tip1");
					}
					else
					{
						HUDManager.Instance.DisplayTip(name + " killed.", Math.Abs(bounty) + " credits have been deducted from your balance", false, false, "LC_Tip1");
					}
				}
				else if (Config.cQuota.Value && !Config.cBank.Value)
				{
					if (bounty > 0)
					{
						HUDManager.Instance.DisplayTip(name + " killed!", bounty + " credits have been added towards the quota", false, false, "LC_Tip1");
					}
					else
					{
						HUDManager.Instance.DisplayTip(name + " killed.", Math.Abs(bounty) + " credits have been deducted from your quota", false, false, "LC_Tip1");
					}
				}
				else if (Config.cQuota.Value && Config.cBank.Value)
				{
					if (bounty > 0)
					{
						HUDManager.Instance.DisplayTip(name + " killed!", bounty + " credits have been added to your balance and quota", false, false, "LC_Tip1");
					}
					else
					{
						HUDManager.Instance.DisplayTip(name + " killed.", Math.Abs(bounty) + " credits have been deducted from your balance and quota", false, false, "LC_Tip1");
					}
				}
			}
			if (Config.cBank.Value)
			{
				Terminal val = Object.FindObjectOfType<Terminal>();
				int num = val.groupCredits + bounty;
				val.groupCredits = ((num >= 0) ? num : 0);
			}
			if (Config.cQuota.Value)
			{
				TimeOfDay instance = TimeOfDay.Instance;
				int num2 = instance.quotaFulfilled + bounty;
				instance.quotaFulfilled = ((num2 >= 0) ? num2 : 0);
				TimeOfDay.Instance.UpdateProfitQuotaCurrentTime();
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "KillPlayer")]
		[HarmonyPostfix]
		private static void KillPlayerPatch(PlayerControllerB __instance)
		{
			int value = Config.cValPlayer.Value;
			if (value != 0 && Config.cPlayerNotification.Value)
			{
				if (!Config.cQuota.Value && Config.cBank.Value)
				{
					if (value > 0)
					{
						HUDManager.Instance.DisplayTip("A player has died.", value + " credits have been added to your balance", false, false, "LC_Tip1");
					}
					else
					{
						HUDManager.Instance.DisplayTip("A player has died.", Math.Abs(value) + " credits have been deducted from your balance", false, false, "LC_Tip1");
					}
				}
				else if (Config.cQuota.Value && !Config.cBank.Value)
				{
					if (value > 0)
					{
						HUDManager.Instance.DisplayTip("A player has died.", value + " credits have been added to your quota", false, false, "LC_Tip1");
					}
					else
					{
						HUDManager.Instance.DisplayTip("A player has died.", Math.Abs(value) + " credits have been deducted from your quota", false, false, "LC_Tip1");
					}
				}
				else if (Config.cQuota.Value && Config.cBank.Value)
				{
					if (value > 0)
					{
						HUDManager.Instance.DisplayTip("A player has died.", value + " credits have been added to your balance and quota", false, false, "LC_Tip1");
					}
					else
					{
						HUDManager.Instance.DisplayTip("A player has died.", Math.Abs(value) + " credits have been deducted from your balance and quota", false, false, "LC_Tip1");
					}
				}
			}
			if (Config.cBank.Value)
			{
				Terminal val = Object.FindObjectOfType<Terminal>();
				int num = val.groupCredits + value;
				val.groupCredits = ((num >= 0) ? num : 0);
			}
			if (Config.cQuota.Value)
			{
				TimeOfDay instance = TimeOfDay.Instance;
				int num2 = instance.quotaFulfilled + value;
				instance.quotaFulfilled = ((num2 >= 0) ? num2 : 0);
				TimeOfDay.Instance.UpdateProfitQuotaCurrentTime();
			}
		}

		[HarmonyPatch(typeof(TimeOfDay), "SetNewProfitQuota")]
		[HarmonyPrefix]
		private static bool ResetQuota(ref int ___quotaFulfilled, ref int ___profitQuota, out int __state)
		{
			if (TimeOfDay.Instance.timeUntilDeadline <= 0f)
			{
				__state = ___quotaFulfilled - ___profitQuota;
				return true;
			}
			__state = ___quotaFulfilled;
			return false;
		}

		[HarmonyPatch(typeof(TimeOfDay), "SetNewProfitQuota")]
		[HarmonyPostfix]
		private static void SetQuotaFulfilledHost(ref int ___quotaFulfilled, int __state)
		{
			___quotaFulfilled = __state;
		}
	}
}