Decompiled source of SillyDuneTweaks v1.0.0

SillyDuneTweaks.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using CUCoreLib.Data;
using CUCoreLib.Helpers;
using CUCoreLib.Registries;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+f92451fcd00f17ad9020f070ad369054ff494436")]
[assembly: AssemblyProduct("Template description")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SillyDuneTweaks
{
	internal class SDTLoadedLanguage
	{
		[JsonProperty]
		internal Dictionary<string, string> other;

		[JsonProperty]
		internal Dictionary<string, List<string>>[] character;
	}
	internal class Assets
	{
		internal static SDTLoadedLanguage language;

		internal static void LoadStrings()
		{
			try
			{
				string text = AssetLoader.LoadEmbeddedText("DuneSpeak.json", (Assembly)null);
				language = JsonConvert.DeserializeObject<SDTLoadedLanguage>(text);
			}
			catch
			{
				Plugin.Logger.LogError((object)"Failed to load language file");
			}
		}
	}
	[HarmonyPatch(typeof(Locale), "LoadLanguage")]
	internal static class LanguagePatcher
	{
		[HarmonyPostfix]
		private static void AddCustomLines()
		{
			for (int i = 0; i < Assets.language.character.Length; i++)
			{
				foreach (KeyValuePair<string, List<string>> item in Assets.language.character[i])
				{
					Locale.currentLang.character[i].Add(item.Key, item.Value);
				}
			}
			foreach (KeyValuePair<string, string> item2 in Assets.language.other)
			{
				Locale.currentLang.other.Add(item2.Key, item2.Value);
			}
		}
	}
	[HarmonyPatch(typeof(Locale), "GetCharacter", new Type[]
	{
		typeof(string),
		typeof(int)
	})]
	internal static class SpeechPatcher
	{
		[HarmonyPrefix]
		private static void SmartifyDune(ref string str, ref int chr)
		{
			if (chr == 2 && ShouldDuneText())
			{
				string text = (str.Contains("sdt.") ? str.Replace("sdt.", "sdt.duned.") : ("sdt.duned." + str));
				if (Locale.currentLang.character[2].ContainsKey(text))
				{
					str = text;
				}
				else
				{
					Plugin.Logger.LogInfo((object)("Could not find duned variant for string " + str));
				}
			}
		}

		private static bool ShouldDuneText()
		{
			if (CustomSettings.DunedMode != DunedModes.BrainDamaged)
			{
				return CustomSettings.DunedMode == DunedModes.Always;
			}
			float num = 100f - Mathf.Clamp(PlayerCamera.main.body.brainHealth, 75f, 90f);
			float num2 = 1f - (25f - num) / 15f;
			return num2 > Random.value;
		}
	}
	[HarmonyPatch(typeof(Item), "SetupItems")]
	internal static class FoodPatcher
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Use <>9__0_1;

			public static Use <>9__0_2;

			public static Use <>9__0_0;

			internal void <ModifyItems>b__0_1(Body body, Item item)
			{
				if (body.charType == 2)
				{
					EatPDA(body, item);
				}
			}

			internal void <ModifyItems>b__0_2(Body body, Item item)
			{
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				if (body.charType == 2)
				{
					body.Eat(2.5f, 0f, 0);
					body.talker.EatGood();
					Sound.Play("eatCrunch", Vector2.op_Implicit(((Component)body).transform.position), false, true, (Transform)null, 1f, 1f, false, false);
				}
			}

			internal void <ModifyItems>b__0_0(Body body, Item item)
			{
				if (body.charType == 2)
				{
					ItemInfo item2 = Item.GetItem(item.id);
					BatteryInfo val = (BatteryInfo)(object)((item2 is BatteryInfo) ? item2 : null);
					if (body.skills.INT < ((ItemInfo)val).rec.min || !CustomSettings.SmartEating)
					{
						EatBattery(body, item, val.maxCharge);
					}
					else
					{
						body.talker.Talk(Locale.GetCharacter("sdt.smartRefuse", body.charType), (Limb)null, false, false);
					}
				}
				else
				{
					body.talker.Talk("...", (Limb)null, false, false);
				}
			}
		}

		[HarmonyPostfix]
		private static void ModifyItems()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			ItemInfo obj = Item.GlobalItems["epda"];
			Use useAction = obj.useAction;
			object obj2 = <>c.<>9__0_1;
			if (obj2 == null)
			{
				Use val = delegate(Body body, Item item)
				{
					if (body.charType == 2)
					{
						EatPDA(body, item);
					}
				};
				<>c.<>9__0_1 = val;
				obj2 = (object)val;
			}
			obj.useAction = (Use)Delegate.Combine((Delegate?)(object)useAction, (Delegate?)obj2);
			ItemInfo obj3 = Item.GlobalItems["blueprint"];
			Use useAction2 = obj3.useAction;
			object obj4 = <>c.<>9__0_2;
			if (obj4 == null)
			{
				Use val2 = delegate(Body body, Item item)
				{
					//IL_0038: Unknown result type (might be due to invalid IL or missing references)
					//IL_003d: Unknown result type (might be due to invalid IL or missing references)
					if (body.charType == 2)
					{
						body.Eat(2.5f, 0f, 0);
						body.talker.EatGood();
						Sound.Play("eatCrunch", Vector2.op_Implicit(((Component)body).transform.position), false, true, (Transform)null, 1f, 1f, false, false);
					}
				};
				<>c.<>9__0_2 = val2;
				obj4 = (object)val2;
			}
			obj3.useAction = (Use)Delegate.Combine((Delegate?)(object)useAction2, (Delegate?)obj4);
			object obj5 = <>c.<>9__0_0;
			if (obj5 == null)
			{
				Use val3 = delegate(Body body, Item item)
				{
					if (body.charType == 2)
					{
						ItemInfo item2 = Item.GetItem(item.id);
						BatteryInfo val7 = (BatteryInfo)(object)((item2 is BatteryInfo) ? item2 : null);
						if (body.skills.INT < ((ItemInfo)val7).rec.min || !CustomSettings.SmartEating)
						{
							EatBattery(body, item, val7.maxCharge);
						}
						else
						{
							body.talker.Talk(Locale.GetCharacter("sdt.smartRefuse", body.charType), (Limb)null, false, false);
						}
					}
					else
					{
						body.talker.Talk("...", (Limb)null, false, false);
					}
				};
				<>c.<>9__0_0 = val3;
				obj5 = (object)val3;
			}
			Use useAction3 = (Use)obj5;
			ItemInfo val4 = Item.GlobalItems["smallbattery"];
			val4.usable = true;
			val4.useAction = useAction3;
			ItemInfo val5 = Item.GlobalItems["mediumbattery"];
			val5.usable = true;
			val5.useAction = useAction3;
			ItemInfo val6 = Item.GlobalItems["largebattery"];
			val6.usable = true;
			val6.useAction = useAction3;
		}

		private static void EatPDA(Body body, Item item)
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			body.Eat(4f, 0f, 0);
			body.energy += 5f;
			body.caffeinated += 10f;
			body.internalBleeding += Random.Range(4f, 6f);
			Limb obj = body.limbs[2];
			obj.pain += 20f;
			body.skills.AddExp(2, 1f);
			Sound.Play("eatCrunch", Vector2.op_Implicit(((Component)body).transform.position), false, true, (Transform)null, 1f, 0.8f, false, false);
			Sound.Play("glass", Vector2.op_Implicit(((Component)body).transform.position), false, true, (Transform)null, 1f, 0.8f, false, false);
			body.talker.Talk(Locale.GetCharacter("sdt.eatPDA", body.charType), (Limb)null, false, false);
			if (item.battery.hasBattery)
			{
				EatBattery(body, item, item.battery.maxCharge);
			}
			Object.Destroy((Object)(object)((Component)item).gameObject);
		}

		private static void EatBattery(Body body, Item item, float maxCharge)
		{
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			float num = maxCharge / 100f;
			body.Eat(3f * num, 0f, 0);
			body.energy += 10f * num;
			body.caffeinated += 30f * num;
			body.internalBleeding += Random.Range(8f * num, 12f * num);
			Limb obj = body.limbs[2];
			obj.pain += 30f * num;
			Limb obj2 = body.limbs[2];
			obj2.muscleHealth -= Random.Range(18f, 22f) * num;
			body.temperature += num;
			body.brainHealth -= 2f * num;
			PlayerCamera.main.shaker.Shake(30f * num);
			if (num == 3f)
			{
				body.Ragdoll();
				Limb[] limbs = body.limbs;
				foreach (Limb val in limbs)
				{
					val.pain = Mathf.Max(val.pain, Random.Range(25f, 35f));
				}
			}
			float num2 = num * 0.1f;
			if (Random.value <= num2)
			{
				body.fibrillationProgress = 0f;
			}
			Sound.Play("eatCrunch", Vector2.op_Implicit(((Component)body).transform.position), false, true, (Transform)null, 1f, 0.8f, false, false);
			Sound.Play("zap", Vector2.op_Implicit(((Component)body).transform.position), false, true, (Transform)null, 0.3f + 0.15f * num, 1.4f, false, false);
			if (Object.op_Implicit((Object)(object)item))
			{
				Object.Destroy((Object)(object)((Component)item).gameObject);
			}
		}
	}
	internal class Patches
	{
		[HarmonyPatch(typeof(ConsoleScript))]
		internal static class ConsolePatch
		{
			[HarmonyPatch("Start")]
			[HarmonyPostfix]
			private static void StartPatch()
			{
				ConsoleScript.instance.LogToConsole("Loaded Silly Dune Tweaks (v1.0.0)");
			}
		}
	}
	[BepInPlugin("com.Egg.SillyDuneTweaks", "Silly Dune Tweaks", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string ModGUID = "com.Egg.SillyDuneTweaks";

		public const string ModName = "Silly Dune Tweaks";

		public const string ModVersion = "1.0.0";

		internal static ManualLogSource Logger;

		private readonly Harmony _harmony = new Harmony("com.Egg.SillyDuneTweaks");

		public static Plugin Instance { get; private set; }

		public void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Assets.LoadStrings();
			CustomSettings.RegisterSettings();
			_harmony.PatchAll();
			Logger.LogInfo((object)"Plugin Silly Dune Tweaks is loaded!");
		}
	}
	internal enum DunedModes
	{
		Never,
		BrainDamaged,
		Always
	}
	internal class CustomSettings
	{
		internal static DunedModes DunedMode;

		internal static bool SmartEating;

		internal static void RegisterSettings()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			ModOptionsRegistry.Register((ModOptionDefinition)(object)ModOptionDefinition.Dropdown("sdt.dunespeakmode", 1, (ModDropdownChoice[])(object)new ModDropdownChoice[3]
			{
				new ModDropdownChoice("never", "Never"),
				new ModDropdownChoice("brain", "Brain damage"),
				new ModDropdownChoice("always", "Always")
			}).WithCategory((SettingCategory)4).LocalOnly()
				.OnApply((Action<int>)delegate(int value)
				{
					DunedMode = (DunedModes)value;
				}));
			ModOptionsRegistry.Register((ModOptionDefinition)(object)ModOptionDefinition.Bool("sdt.smarteating", true).WithCategory((SettingCategory)2).OnApply((Action<bool>)delegate(bool value)
			{
				SmartEating = value;
			}));
		}
	}
	[HarmonyPatch(typeof(PlayerCamera), "HandleTradeMenu")]
	internal static class HugButtonInteractablePatcher
	{
		[HarmonyPostfix]
		private static void ReEnableButton(PlayerCamera __instance)
		{
			if (__instance.tradeMenu.activeSelf && Object.op_Implicit((Object)(object)__instance.currentTrader))
			{
				((Selectable)__instance.tradeHugButton).interactable = true;
			}
		}
	}
	[HarmonyPatch(typeof(PlayerCamera), "ToggleTradeMenu")]
	internal static class TradeMenuPatcher
	{
		[HarmonyPostfix]
		private static void ModifyButton(PlayerCamera __instance)
		{
			if (__instance.tradeMenu.activeSelf)
			{
				if (__instance.body.charType == 2)
				{
					((Component)((Component)__instance.tradeHugButton).transform.GetChild(0)).GetComponent<Image>().sprite = Resources.Load<Sprite>("Sprites/dunehaggle");
					UITooltip component = ((Component)__instance.tradeHugButton).GetComponent<UITooltip>();
					component.skipLocale = true;
					component.tipName = Locale.GetOther("sdt.requestbite");
					component.tipDesc = Locale.GetOther("sdt.requestbitedsc");
				}
				else
				{
					((Component)((Component)__instance.tradeHugButton).transform.GetChild(0)).GetComponent<Image>().sprite = Resources.Load<Sprite>("Sprites/hearticon");
					UITooltip component2 = ((Component)__instance.tradeHugButton).GetComponent<UITooltip>();
					component2.skipLocale = true;
					component2.tipName = Locale.GetOther("hug");
					component2.tipDesc = Locale.GetOther("hugdsc");
				}
			}
		}
	}
	[HarmonyPatch(typeof(TraderScript), "TryHug")]
	internal static class TraderHugPatcher
	{
		[HarmonyPrefix]
		private static bool DuneAltHug(TraderScript __instance)
		{
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.body.charType != 2)
			{
				return true;
			}
			int character = __instance.character;
			Body body = __instance.body;
			float num;
			float num2;
			switch (character)
			{
			case 1:
				num = 120f;
				num2 = 1.2f;
				break;
			case 2:
				num = 70f;
				num2 = -0.5f;
				break;
			default:
				num = 100f;
				num2 = 1f;
				break;
			}
			int num3 = Mathf.RoundToInt(8f * __instance.ValueMultiplier());
			if (__instance.reputation < num)
			{
				__instance.talker.Talk(Locale.GetCharacter("sdt.tradernomrefuse", character), (Limb)null, false, false);
				__instance.reputation -= Random.Range(10f, 14f);
			}
			else if (__instance.valueGiven < num3)
			{
				__instance.talker.Talk(Locale.GetCharacter("sdt.tradernomrefuse", character), (Limb)null, false, false);
				__instance.reputation -= Random.Range(10f, 14f);
			}
			else if (__instance.build.health < 750f)
			{
				__instance.talker.Talk(Locale.GetCharacter("sdt.tradernomtoolow", character), (Limb)null, false, false);
				__instance.reputation -= Random.Range(6f, 10f);
			}
			else
			{
				float num4 = Random.Range(0.8f, 1.2f);
				body.Eat(16f * num4, 1.2f, 1);
				body.happiness += 5f;
				body.talker.EatGood();
				Sound.Play("eatFlesh", Vector2.op_Implicit(((Component)body).transform.position), false, true, (Transform)null, 1f, 1f, false, false);
				BuildingEntity build = __instance.build;
				build.health -= 80f * num4;
				__instance.talker.Talk(Locale.GetCharacter("sdt.tradernomaccept", character), (Limb)null, false, false);
				__instance.reputation -= Random.Range(8f, 10f) * num2;
				__instance.valueGiven -= num3;
			}
			__instance.UpdateScreen();
			return false;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SillyDuneTweaks";

		public const string PLUGIN_NAME = "Template description";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}