Decompiled source of STRAFTAT Tweaks v1.3.4

StraftTweaks.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using ComputerysModdingUtilities;
using HarmonyLib;
using HoverInfo;
using ImprovedRebinds;
using Microsoft.CodeAnalysis;
using ModMenu.Api;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: StraftatMod(true)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Koki")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+09aca6c0062426c5a7ce14637d05de09feafdce2")]
[assembly: AssemblyProduct("StraftTweaks")]
[assembly: AssemblyTitle("StraftTweaks")]
[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;
		}
	}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.koki.tweaks", "STRAFTAT Tweaks", "1.3.3")]
public class STRAFTweakPlugin : BaseUnityPlugin
{
	internal static STRAFTweakPlugin Instance;

	private Harmony _harmony = new Harmony("com.koki.tweaks");

	private void Awake()
	{
		_harmony.PatchAll();
		Instance = this;
		((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
		InitConfig();
		if (Chainloader.PluginInfos.ContainsKey("kestrel.straftat.modmenu"))
		{
			STRAFTweakModMenuCompat.Start();
		}
	}

	private void InitConfig()
	{
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		SetJoinMessage.JoinMessageTemplate = ((BaseUnityPlugin)this).Config.Bind<string>("Custom Join Message", "Message", "{USER} has joined the lobby", "{USER} will be replaced with your username.");
		ScrollJump.isEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Binding", "Scroll to jump", false, (ConfigDescription)null);
		OutlineColor.weaponColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Outline Colors", "Weapon Outline Color", new Color(1f, 0.8196079f, 0.427451f), (ConfigDescription)null);
		OutlineColor.weaponTextColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Outline Colors", "Weapon Interact Text Color", OutlineColor.DefaultTextColor, (ConfigDescription)null);
		OutlineColor.weaponTextBrightness = ((BaseUnityPlugin)this).Config.Bind<float>("Outline Colors", "Weapon Interact Text Brightness", 1f, (ConfigDescription)null);
		ApplyRainbow.enable = ((BaseUnityPlugin)this).Config.Bind<bool>("Outline Colors", "Enable Rainbow Outlines", false, (ConfigDescription)null);
		ApplyRainbow.rainbowSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Outline Colors", "Rainbow Fluctuation Speed", 0.2f, "i have no idea what the unit is for this");
		WeaponInteractPrompt.enablePrompt = ((BaseUnityPlugin)this).Config.Bind<bool>("Text Popups", "Enable Weapon Interact Text", true, (ConfigDescription)null);
		DoorInteractPrompt.enablePrompt = ((BaseUnityPlugin)this).Config.Bind<bool>("Text Popups", "Enable Door Interact Text", true, (ConfigDescription)null);
		WeaponInteractPrompt.disableKey = ((BaseUnityPlugin)this).Config.Bind<bool>("Text Popups", "Disable Key Prompt", true, "Transform \"Handgun [F]\" into just \"Handgun\". Does the same for door interactions.");
		MinHUDPatch.hideFPS = ((BaseUnityPlugin)this).Config.Bind<bool>("HUD", "Hide FPS Display", true, (ConfigDescription)null);
		MinHUDPatch.hidePing = ((BaseUnityPlugin)this).Config.Bind<bool>("HUD", "Hide Ping Display", true, (ConfigDescription)null);
		OutlineColor.weaponColor.SettingChanged += OutlineColor.UpdateColorsFromConfig;
		OutlineColor.weaponTextColor.SettingChanged += OutlineColor.UpdateColorsFromConfig;
		OutlineColor.weaponTextBrightness.SettingChanged += OutlineColor.UpdateColorsFromConfig;
		ScrollJump.isEnabled.SettingChanged += delegate
		{
			ScrollJump.Postfix();
		};
		ApplyRainbow.enable.SettingChanged += OutlineColor.UpdateColorsFromConfig;
	}

	private void OnDestroy()
	{
		_harmony.UnpatchSelf();
		OutlineColor.weaponColor.SettingChanged -= OutlineColor.UpdateColorsFromConfig;
		OutlineColor.weaponTextColor.SettingChanged -= OutlineColor.UpdateColorsFromConfig;
		OutlineColor.weaponTextBrightness.SettingChanged -= OutlineColor.UpdateColorsFromConfig;
		ScrollJump.isEnabled.SettingChanged -= delegate
		{
			ScrollJump.Postfix();
		};
		ApplyRainbow.enable.SettingChanged -= OutlineColor.UpdateColorsFromConfig;
	}
}
internal static class STRAFTweakModMenuCompat
{
	internal static void Start()
	{
		try
		{
			ModMenuCustomisation.SetPluginDescription("Tweak things like weapon outline color or mouse wheel binds :D\n\nChanges are applied immediately.\n\n");
		}
		catch (InvalidOperationException)
		{
		}
	}

	private static void ConfigBuilder(OptionListContext c)
	{
	}
}
[HarmonyPatch(typeof(PlayerHealth), "Update")]
internal static class MinHUDPatch
{
	internal static ConfigEntry<bool> hidePing;

	internal static ConfigEntry<bool> hideFPS;

	private static void Postfix(PlayerHealth __instance)
	{
		if (hidePing.Value)
		{
			((TMP_Text)__instance.controller.pauseManager.minimalPingText).text = "";
		}
		if (hideFPS.Value)
		{
			((TMP_Text)__instance.controller.pauseManager.minimalFpsText).text = "";
		}
	}
}
[HarmonyPatch(typeof(ClientInstance), "OnStartClient")]
internal static class SetJoinMessage
{
	internal static ConfigEntry<string> JoinMessageTemplate;

	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Expected O, but got Unknown
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Expected O, but got Unknown
		MethodInfo methodInfo = AccessTools.Method(typeof(SetJoinMessage), "GetJoinMessage", (Type[])null, (Type[])null);
		return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((OpCode?)OpCodes.Ldstr, (object)" joined the lobby", (string)null)
		}).RemoveInstructions(2).Insert((CodeInstruction[])(object)new CodeInstruction[1]
		{
			new CodeInstruction(OpCodes.Call, (object)methodInfo)
		})
			.InstructionEnumeration();
	}

	private static string GetJoinMessage(string username)
	{
		return JoinMessageTemplate.Value.Replace("{USER}", username);
	}
}
namespace StraftTweaks
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.koki.tweaks";

		public const string PLUGIN_NAME = "STRAFTAT Tweaks";

		public const string PLUGIN_VERSION = "1.3.3";
	}
}
namespace ImprovedRebinds
{
	[HarmonyPatch(typeof(InputManager), "LoadBindingOverride")]
	internal static class AddKeyPressInput
	{
		private static void Prefix(string actionName)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			if (actionName != "ChangeWeapon")
			{
				return;
			}
			InputAction val = InputManager.inputActions.asset.FindAction(actionName, false);
			if (val.bindings.Count == 1)
			{
				BindingSyntax val2 = InputActionSetupExtensions.ChangeBinding(val, 0);
				((BindingSyntax)(ref val2)).Erase();
				CompositeSyntax val3 = InputActionSetupExtensions.AddCompositeBinding(val, "2DVector", (string)null, (string)null);
				((CompositeSyntax)(ref val3)).With("Up", "", (string)null, (string)null);
				if (Utility.IsNullOrWhiteSpace(PlayerPrefs.GetString("PlayerControls (UnityEngine.InputSystem.InputActionAsset):PlayerChangeWeapon1")))
				{
					InputActionSetupExtensions.AddBinding(val, "<Mouse>/scroll", (string)null, (string)null, (string)null);
				}
			}
		}
	}
	[HarmonyPatch(typeof(InputManager), "DoRebind")]
	internal static class OnBind
	{
		private static void Prefix(InputAction actionToRebind, ref bool allCompositeParts)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			if (actionToRebind.name == "ChangeWeapon")
			{
				if (actionToRebind.bindings.Count == 3)
				{
					BindingSyntax val = InputActionSetupExtensions.ChangeBinding(actionToRebind, 2);
					((BindingSyntax)(ref val)).Erase();
				}
				actionToRebind.expectedControlType = "Button";
				allCompositeParts = false;
			}
		}
	}
	[HarmonyPatch(typeof(ReBindUI), "UpdateUI")]
	internal static class UpdateBindUI
	{
		private static void Postfix(ReBindUI __instance)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			InputAction action = __instance.inputActionReference.action;
			if (action.name == "ChangeWeapon")
			{
				string text = PlayerPrefs.GetString("PlayerControls (UnityEngine.InputSystem.InputActionAsset):PlayerChangeWeapon1");
				if (Utility.IsNullOrWhiteSpace(text))
				{
					InputActionSetupExtensions.AddBinding(InputManager.inputActions.asset.FindAction("ChangeWeapon", false), "<Mouse>/scroll", (string)null, (string)null, (string)null);
					((TMP_Text)__instance.rebindText).text = "Scroll";
				}
				else
				{
					((TMP_Text)__instance.rebindText).text = text.Substring(text.IndexOf("/") + 1).ToUpper();
				}
			}
		}
	}
	[HarmonyPatch(typeof(InputManager), "LoadBindingOverride")]
	internal static class ScrollJump
	{
		internal static ConfigEntry<bool> isEnabled;

		internal static void Postfix()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			InputAction val = InputManager.inputActions.asset.FindAction("Jump", false);
			int num = val.bindings.IndexOf((Predicate<InputBinding>)((InputBinding b) => ((InputBinding)(ref b)).path == "<Mouse>/scroll"));
			if (isEnabled.Value)
			{
				if (num == -1)
				{
					InputActionSetupExtensions.AddBinding(val, "<Mouse>/scroll", (string)null, (string)null, "Keyboard&Mouse");
				}
			}
			else if (num != -1)
			{
				BindingSyntax val2 = InputActionSetupExtensions.ChangeBinding(val, num);
				((BindingSyntax)(ref val2)).Erase();
			}
		}
	}
}
namespace HoverInfo
{
	[HarmonyPatch(typeof(PauseManager), "Awake")]
	internal static class OutlineColor
	{
		internal static readonly Color DefaultTextColor = new Color(2f, 1.106f, 0f);

		internal static ConfigEntry<Color> weaponColor;

		internal static ConfigEntry<Color> weaponTextColor;

		internal static ConfigEntry<float> weaponTextBrightness;

		private static bool HasRanOnStartup = false;

		internal static readonly int weaponOutline = Shader.PropertyToID("_Color_Outline");

		internal static readonly int textOutline = Shader.PropertyToID("_OutlineColor");

		internal static readonly int outlineShaderID = ((Object)Shader.Find("S_WeaponOutline_00")).GetInstanceID();

		private static Lazy<Material[]> _weaponMaterials = new Lazy<Material[]>(() => (from mat in Resources.FindObjectsOfTypeAll<Material>()
			where ((Object)mat.shader).GetInstanceID() == outlineShaderID
			select mat).ToArray());

		private static void Postfix()
		{
			if (!HasRanOnStartup)
			{
				UpdateColorsFromConfig();
				HasRanOnStartup = true;
			}
		}

		internal static void UpdateColorsFromConfig(object sender, EventArgs args)
		{
			UpdateColorsFromConfig();
		}

		internal static void UpdateColorsFromConfig()
		{
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			CollectionExtensions.Do<Material>((IEnumerable<Material>)_weaponMaterials.Value, (Action<Material>)delegate(Material mat)
			{
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				mat.SetColor(weaponOutline, weaponColor.Value);
			});
			Renderer[] array = Object.FindObjectsOfType<Renderer>();
			foreach (Renderer val in array)
			{
				Material[] sharedMaterials = val.sharedMaterials;
				foreach (Material val2 in sharedMaterials)
				{
					if (Object.op_Implicit((Object)(object)val2) && ((Object)val2.shader).GetInstanceID() == outlineShaderID)
					{
						val2.SetColor(weaponOutline, weaponColor.Value);
					}
				}
			}
			Color val3 = ((!(weaponTextColor.Value == new Color(1f, 1f, 0f)) && !(weaponTextColor.Value == DefaultTextColor)) ? (weaponTextColor.Value * Color.op_Implicit(Vector4.one) * weaponTextBrightness.Value) : DefaultTextColor);
			((TMP_Text)PauseManager.Instance.grabPopup).fontSharedMaterial.SetColor(textOutline, val3);
			((TMP_Text)PauseManager.Instance.interactPopup).fontSharedMaterial.SetColor(textOutline, val3);
		}
	}
	[HarmonyPatch(typeof(ItemBehaviour), "OnFocus")]
	internal static class WeaponInteractPrompt
	{
		internal static ConfigEntry<bool> enablePrompt;

		internal static ConfigEntry<bool> disableKey;

		private static void Postfix(ItemBehaviour __instance)
		{
			((Component)PauseManager.Instance.grabPopup).gameObject.SetActive(enablePrompt.Value);
			if (disableKey.Value)
			{
				((TMP_Text)PauseManager.Instance.grabPopup).text = __instance.weaponName.ToLower();
			}
		}
	}
	[HarmonyPatch(typeof(PhysicsProp), "OnFocus")]
	internal static class BarrelInteractPrompt
	{
		private static void Postfix(PhysicsProp __instance)
		{
			((Component)PauseManager.Instance.interactPopup).gameObject.SetActive(WeaponInteractPrompt.enablePrompt.Value);
			if (WeaponInteractPrompt.disableKey.Value)
			{
				((TMP_Text)PauseManager.Instance.interactPopup).text = (__instance.sync___get_value_grabbed() ? "drop" : "grab") + " " + ((InteractEnvironment)__instance).popupText.ToLower();
			}
		}
	}
	[HarmonyPatch(typeof(Door), "OnFocus")]
	internal static class DoorInteractPrompt
	{
		internal static ConfigEntry<bool> enablePrompt;

		private static void Postfix(Door __instance)
		{
			((Component)PauseManager.Instance.interactPopup).gameObject.SetActive(enablePrompt.Value);
			if (WeaponInteractPrompt.disableKey.Value)
			{
				((TMP_Text)PauseManager.Instance.interactPopup).text = (__instance.sync___get_value_isOpen() ? __instance.closeDoor.ToLower() : ((InteractEnvironment)__instance).popupText.ToLower());
			}
		}
	}
	[HarmonyPatch(typeof(ItemBehaviour), "OnFocus")]
	internal static class ApplyRainbow
	{
		internal static ConfigEntry<bool> enable;

		internal static ConfigEntry<float> rainbowSpeed;

		private static void Postfix(ItemBehaviour __instance)
		{
			if (enable.Value && !Object.op_Implicit((Object)(object)((Component)__instance).gameObject.GetComponent<RainbowOutline>()))
			{
				((Component)__instance).gameObject.AddComponent<RainbowOutline>().mats = __instance.hoveredObjectMat;
			}
		}
	}
	[HarmonyPatch(typeof(ItemBehaviour), "OnLoseFocus")]
	internal static class RemoveRainbow
	{
		private static void Postfix(ItemBehaviour __instance)
		{
			if (Object.op_Implicit((Object)(object)((Component)__instance).gameObject.GetComponent<RainbowOutline>()))
			{
				Object.Destroy((Object)(object)((Component)__instance).gameObject.GetComponent<RainbowOutline>());
			}
		}
	}
	internal class RainbowOutline : MonoBehaviour
	{
		internal List<Material> mats;

		private void Update()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			float num = Time.time * ApplyRainbow.rainbowSpeed.Value % 1f;
			Color val = Color.HSVToRGB(num, 1f, 1f);
			foreach (Material mat in mats)
			{
				mat.SetColor(OutlineColor.weaponOutline, val);
			}
			Color val2 = val * Color.op_Implicit(Vector4.one) * OutlineColor.weaponTextBrightness.Value;
			((TMP_Text)PauseManager.Instance.grabPopup).fontSharedMaterial.SetColor(OutlineColor.textOutline, val2);
			((TMP_Text)PauseManager.Instance.interactPopup).fontSharedMaterial.SetColor(OutlineColor.textOutline, val2);
		}
	}
}