Decompiled source of STRAFTAT Tweaks v1.3.3

StraftTweaks.dll

Decompiled a week 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 Steamworks;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: StraftatMod(true)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Koki")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d8adf90da0eaad24bf63b94004fe95fd7f9d472d")]
[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]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		SetJoinMessage.message = ((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> message;

	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Expected O, but got Unknown
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Expected O, but got Unknown
		MethodInfo methodInfo = AccessTools.Method(typeof(SetJoinMessage), "JoinMessage", (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)
		}).Advance(-1).RemoveInstructions(3)
			.Insert((CodeInstruction[])(object)new CodeInstruction[1]
			{
				new CodeInstruction(OpCodes.Call, (object)methodInfo)
			})
			.InstructionEnumeration();
	}

	private static string JoinMessage()
	{
		return message.Value.Replace("{USER}", SteamFriends.GetPersonaName());
	}
}
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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.inputActionReference.action.name == "ChangeWeapon")
			{
				string @string = PlayerPrefs.GetString("PlayerControls (UnityEngine.InputSystem.InputActionAsset):PlayerChangeWeapon1");
				if (Utility.IsNullOrWhiteSpace(@string))
				{
					InputActionSetupExtensions.AddBinding(InputManager.inputActions.asset.FindAction("ChangeWeapon", false), "<Mouse>/scroll", (string)null, (string)null, (string)null);
					((TMP_Text)__instance.rebindText).text = "Scroll";
					return;
				}
				TextMeshProUGUI rebindText = __instance.rebindText;
				string text = @string;
				int num = @string.IndexOf("/") + 1;
				((TMP_Text)rebindText).text = text.Substring(num, text.Length - num).ToUpper();
			}
		}
	}
	[HarmonyPatch(typeof(InputManager), "LoadBindingOverride")]
	internal static class ScrollJump
	{
		internal static ConfigEntry<bool> isEnabled;

		internal static void Postfix()
		{
			//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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: 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_0074: 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>();
			for (int i = 0; i < array.Length; i++)
			{
				Material[] sharedMaterials = array[i].sharedMaterials;
				foreach (Material val in sharedMaterials)
				{
					if (Object.op_Implicit((Object)(object)val) && ((Object)val.shader).GetInstanceID() == outlineShaderID)
					{
						val.SetColor(weaponOutline, weaponColor.Value);
					}
				}
			}
			Color val2 = ((!(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, val2);
			((TMP_Text)PauseManager.Instance.interactPopup).fontSharedMaterial.SetColor(textOutline, val2);
		}
	}
	[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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			Color val = Color.HSVToRGB(Time.time * ApplyRainbow.rainbowSpeed.Value % 1f, 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);
		}
	}
}