Decompiled source of ValheimPlusTurretFix v1.0.0

plugins\ValheimPlusTurretFix\ValheimPlusTurretFix.dll

Decompiled a month 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 HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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 Valheim1Mod
{
	[BepInPlugin("MrGay.ValheimPlusTurretFix", "Valheim Plus - Turret Fix", "1.0.0")]
	public class Valheim1ModPlugin : BaseUnityPlugin
	{
		private static readonly Harmony Harmony = new Harmony("MrGay.ValheimPlusTurretFix");

		internal static ManualLogSource Log;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Valheim Plus - Turret Fix loaded. Ballista spawn fix active.");
		}
	}
	[HarmonyPatch(typeof(Turret), "ShootProjectile")]
	public static class Turret_ShootProjectile_SpawnFix
	{
		private static readonly Dictionary<Turret, Vector3> OriginalEyePositions = new Dictionary<Turret, Vector3>();

		private const float SpawnOffsetForward = 1.25f;

		private const float SpawnOffsetUp = 0.75f;

		[HarmonyPrefix]
		public static void Prefix(Turret __instance)
		{
			//IL_002b: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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)
			if (!((Object)(object)__instance == (Object)null) && !((Object)(object)__instance.m_eye == (Object)null))
			{
				Transform transform = __instance.m_eye.transform;
				OriginalEyePositions[__instance] = transform.position;
				Vector3 val = ((Component)__instance).transform.forward * 1.25f + Vector3.up * 0.75f;
				transform.position = ((Component)__instance).transform.position + val;
			}
		}

		[HarmonyPostfix]
		public static void Postfix(Turret __instance)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance == (Object)null) && !((Object)(object)__instance.m_eye == (Object)null) && OriginalEyePositions.TryGetValue(__instance, out var value))
			{
				__instance.m_eye.transform.position = value;
				OriginalEyePositions.Remove(__instance);
			}
		}
	}
}