Decompiled source of LetMePlay v1.5.0

LetMePlay.dll

Decompiled 4 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.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("LetMePlay")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LetMePlay")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("89ef3289-8b5a-4174-8b1e-a082ab4fe9be")]
[assembly: AssemblyFileVersion("1.5.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.5.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;
		}
	}
}
namespace LetMePlay
{
	[BepInPlugin("redseiko.valheim.letmeplay", "LetMePlay", "1.5.0")]
	public class LetMePlay : BaseUnityPlugin
	{
		public const string PluginGUID = "redseiko.valheim.letmeplay";

		public const string PluginName = "LetMePlay";

		public const string PluginVersion = "1.5.0";

		private Harmony _harmony;

		public void Awake()
		{
			PluginConfig.BindConfig(((BaseUnityPlugin)this).Config);
			_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "redseiko.valheim.letmeplay");
		}

		public void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	[HarmonyPatch(typeof(EnvMan))]
	public class EnvManPatch
	{
		[HarmonyTranspiler]
		[HarmonyPatch("SetEnv")]
		private static IEnumerable<CodeInstruction> SetEnvTranspiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0003: 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_0023: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[3]
			{
				new CodeMatch((OpCode?)OpCodes.Stfld, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldarg_1, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldfld, (object)typeof(EnvSetup).GetField("m_psystems"), (string)null)
			}).Advance(2).SetInstructionAndAdvance(Transpilers.EmitDelegate<Func<EnvSetup, bool>>((Func<EnvSetup, bool>)SetEnvDelegate))
				.InstructionEnumeration();
		}

		private static bool SetEnvDelegate(EnvSetup envSetup)
		{
			if (PluginConfig.IsModEnabled.Value)
			{
				if (PluginConfig.DisableWeatherSnowParticles.Value && (envSetup.m_name == "Snow" || envSetup.m_name == "SnowStorm" || envSetup.m_name == "Twilight_Snow" || envSetup.m_name == "Twilight_SnowStorm"))
				{
					return false;
				}
				if (PluginConfig.DisableWeatherAshParticles.Value && (envSetup.m_name == "Ashlands_ashrain" || envSetup.m_name == "Ashlands_storm"))
				{
					return false;
				}
			}
			return envSetup.m_psystems != null;
		}
	}
	[HarmonyPatch(typeof(GameCamera))]
	public class GameCameraPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("GetCameraBaseOffset")]
		private static void GetCameraBaseOffsetPostfix(ref Vector3 __result, Player player)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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)
			if (PluginConfig.IsModEnabled.Value && PluginConfig.DisableCameraSwayWhileSitting.Value)
			{
				__result = ((Component)((Character)player).m_eye).transform.position - ((Component)player).transform.position;
			}
		}
	}
	[HarmonyPatch(typeof(ItemData))]
	public class ItemDataPatch
	{
		private static readonly Dictionary<string, Sprite> SpriteCache = new Dictionary<string, Sprite>();

		private static Sprite GetSprite(string spriteName)
		{
			if (!SpriteCache.TryGetValue(spriteName, out var value))
			{
				value = ((IEnumerable<Sprite>)Resources.FindObjectsOfTypeAll<Sprite>()).FirstOrDefault((Func<Sprite, bool>)((Sprite obj) => ((Object)obj).name == spriteName));
				SpriteCache[spriteName] = value;
			}
			return value;
		}

		[HarmonyPrefix]
		[HarmonyPatch("GetIcon")]
		private static void ItemDataGetIcon(ref ItemData __instance)
		{
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			if (PluginConfig.IsModEnabled.Value && (__instance.m_variant < 0 || __instance.m_variant >= __instance.m_shared.m_icons.Length))
			{
				Array.Resize(ref __instance.m_shared.m_icons, __instance.m_variant + 1);
				__instance.m_shared.m_icons[__instance.m_variant] = GetSprite("hammer_icon_small");
				__instance.m_shared.m_name = ((Object)__instance.m_dropPrefab).name;
				__instance.m_shared.m_description = "Non-player item: " + ((Object)__instance.m_dropPrefab).name;
				__instance.m_shared.m_itemType = (ItemType)16;
				__instance.m_crafterID = 12345678L;
				__instance.m_crafterName = "redseiko.valheim.letmeplay";
			}
		}
	}
	[HarmonyPatch(typeof(Player))]
	public class PlayerPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("UpdatePlacementGhost")]
		private static void UpdatePlacementGhostPostfix(ref Player __instance)
		{
			if (Object.op_Implicit((Object)(object)__instance) && Object.op_Implicit((Object)(object)__instance.m_placementMarkerInstance) && __instance.m_placementMarkerInstance.activeSelf && PluginConfig.IsModEnabled.Value && PluginConfig.DisableBuildPlacementMarker.Value)
			{
				__instance.m_placementMarkerInstance.SetActive(false);
			}
		}
	}
	[HarmonyPatch(typeof(PrivateArea))]
	public class PrivateAreaPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("RPC_FlashShield")]
		private static bool PrivateAreaRpcFlashShield()
		{
			if (PluginConfig.IsModEnabled.Value && PluginConfig.DisableWardShieldFlash.Value)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(SpawnArea))]
	public class SpawnareaPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void AwakePostfix(ref SpawnArea __instance)
		{
			if (PluginConfig.IsModEnabled.Value)
			{
				__instance.m_prefabs?.RemoveAll((SpawnData spawnData) => !Object.op_Implicit((Object)(object)spawnData?.m_prefab));
			}
		}
	}
	public class PluginConfig
	{
		public static ConfigEntry<bool> IsModEnabled { get; private set; }

		public static ConfigEntry<bool> DisableWardShieldFlash { get; private set; }

		public static ConfigEntry<bool> DisableCameraSwayWhileSitting { get; private set; }

		public static ConfigEntry<bool> DisableBuildPlacementMarker { get; private set; }

		public static ConfigEntry<bool> DisableWeatherSnowParticles { get; private set; }

		public static ConfigEntry<bool> DisableWeatherAshParticles { get; private set; }

		public static void BindConfig(ConfigFile config)
		{
			IsModEnabled = config.Bind<bool>("_Global", "isModEnabled", true, "Globally enable or disable this mod.");
			DisableWardShieldFlash = config.Bind<bool>("Effects", "disableWardShieldFlash", false, "Disable wards from flashing their blue shield.");
			DisableCameraSwayWhileSitting = config.Bind<bool>("Camera", "disableCameraSwayWhileSitting", false, "Disables the camera sway while sitting.");
			DisableBuildPlacementMarker = config.Bind<bool>("Build", "disableBuildPlacementMarker", false, "Disables the yellow placement marker (and gizmo indicator) when building.");
			DisableWeatherSnowParticles = config.Bind<bool>("Weather", "disableWeatherSnowParticles", false, "Disables ALL snow particles during snow/snowstorm weather.");
			DisableWeatherAshParticles = config.Bind<bool>("Weather", "disableWeatherAshParticles", false, "Disables ALL ash particles during ash rain weather.");
		}
	}
}