Decompiled source of FollowDistance v1.0.1

FollowDistance.dll

Decompiled 6 months ago
using System.Collections.Generic;
using System.Diagnostics;
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;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("FollowDistance")]
[assembly: AssemblyDescription("https://valheim.thunderstore.io/package/blacks7ar/FollowDistance/")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("blacks7ar")]
[assembly: AssemblyProduct("FollowDistance")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("BA359044-5757-4046-95EE-0F036AB44726")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
namespace FollowDistance;

[BepInPlugin("blacks7ar.FollowDistance", "FollowDistance", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
	[HarmonyPatch]
	public static class Patches
	{
		[HarmonyTranspiler]
		[HarmonyPatch(typeof(BaseAI), "Follow")]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			foreach (CodeInstruction instruction in instructions)
			{
				if (CodeInstructionExtensions.Is(instruction, OpCodes.Ldc_R4, (object)3f))
				{
					instruction.operand = _distance.Value;
				}
			}
			return instructions;
		}
	}

	private const string modGUID = "blacks7ar.FollowDistance";

	public const string modName = "FollowDistance";

	public const string modAuthor = "blacks7ar";

	public const string modVersion = "1.0.1";

	public const string modLink = "https://valheim.thunderstore.io/package/blacks7ar/FollowDistance/";

	private static readonly Harmony _harmony = new Harmony("blacks7ar.FollowDistance");

	private static ConfigEntry<float> _distance;

	public void Awake()
	{
		((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
		_distance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Distance", 9f, "Players distance before your tames follows you.\nNeeds a Restart to take effect.");
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		_harmony.PatchAll(executingAssembly);
	}
}