Decompiled source of SacrificialStonesShifted v1.0.0

IronLabs.SacrificialStonesShifted.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("IronLabs.SacrificialStonesShifted")]
[assembly: AssemblyDescription("Moves Valheim's Sacrificial Stones away from the world center.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("IronLabs")]
[assembly: AssemblyProduct("IronLabs.SacrificialStonesShifted")]
[assembly: AssemblyCopyright("Copyright © 2026 End3rbyte")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("C698CE81-6F76-4320-A8C2-80E5273177E7")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace IronLabs.SacrificialStonesShifted;

internal static class ModLog
{
	private static ManualLogSource _logger;

	private static string _pluginName;

	internal static void Initialize(ManualLogSource logger, string pluginName)
	{
		_logger = logger;
		_pluginName = pluginName;
	}

	internal static void Clear()
	{
		_logger = null;
		_pluginName = null;
	}

	internal static void LogDebug(object message)
	{
		Write((LogLevel)32, message);
	}

	internal static void LogInfo(object message)
	{
		Write((LogLevel)16, message);
	}

	internal static void LogWarning(object message)
	{
		Write((LogLevel)4, message);
	}

	private static void Write(LogLevel level, object message)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		ManualLogSource logger = _logger;
		if (logger != null)
		{
			logger.Log(level, message);
		}
	}
}
[BepInPlugin("IronLabs.SacrificialStonesShifted", "IronLabs.SacrificialStonesShifted", "1.0.0")]
public sealed class SacrificialStonesShiftedPlugin : BaseUnityPlugin
{
	private const string PluginGuid = "IronLabs.SacrificialStonesShifted";

	private const string PluginName = "IronLabs.SacrificialStonesShifted";

	private const string PluginVersion = "1.0.0";

	private readonly Harmony _harmony = new Harmony("IronLabs.SacrificialStonesShifted");

	private static bool _patchesApplied;

	private void Awake()
	{
		ModLog.Initialize(((BaseUnityPlugin)this).Logger, "IronLabs.SacrificialStonesShifted");
		PatchOwnNamespace();
		ModLog.LogInfo("IronLabs.SacrificialStonesShifted 1.0.0 is loaded.");
	}

	private void PatchOwnNamespace()
	{
		if (_patchesApplied)
		{
			ModLog.LogDebug("Harmony patches are already active; skipping registration.");
			return;
		}
		string text = typeof(SacrificialStonesShiftedPlugin).Namespace;
		Type[] types = Assembly.GetExecutingAssembly().GetTypes();
		foreach (Type type in types)
		{
			if (type.Namespace == text)
			{
				_harmony.CreateClassProcessor(type).Patch();
			}
		}
		_patchesApplied = true;
		ModLog.LogDebug("Harmony patches were applied for the plugin namespace.");
	}

	private void OnDestroy()
	{
		if (_patchesApplied)
		{
			_harmony.UnpatchSelf();
			_patchesApplied = false;
		}
		ModLog.Clear();
	}
}
[HarmonyPatch(typeof(ZoneSystem), "GenerateLocations")]
internal static class ZoneSystemGenerateLocationsPatch
{
	private const string StartTemplePrefabName = "StartTemple";

	private const float MinimumDistance = 1500f;

	private const float MaximumDistance = 1600f;

	private static void Prefix(ZoneSystem __instance)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		ZoneLocation val = FindStartTemple(__instance);
		if (val == null)
		{
			ModLog.LogWarning("StartTemple was not found; its generation rules were not changed.");
			return;
		}
		val.m_biome = (Biome)1;
		val.m_minDistance = 1500f;
		val.m_maxDistance = 1600f;
		val.m_centerFirst = true;
		ModLog.LogDebug($"StartTemple generation constrained to Meadows between {1500f} and {1600f} metres.");
	}

	private static ZoneLocation FindStartTemple(ZoneSystem zoneSystem)
	{
		foreach (ZoneLocation location in zoneSystem.m_locations)
		{
			if (location.m_prefabName == "StartTemple")
			{
				return location;
			}
		}
		return null;
	}
}