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;
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("ValheimCartographyTableMapOnly")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ValheimCartographyTableMapOnly")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b4eb01f7-88ec-4f99-9060-c23449522afb")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ValheimCartographyTableMapOnly;
[HarmonyPatch(typeof(GameObject), "SetActive")]
internal class LargeMapOnActive
{
public static bool LargeMapCanBeActive;
[HarmonyPrefix]
public static bool OnSetActivePrefix(GameObject __instance, bool value)
{
if ((Object)(object)Program.mapInstance == (Object)null)
{
return true;
}
if ((Object)(object)__instance == (Object)(object)Program.mapInstance.m_smallRoot && value)
{
__instance.SetActive(false);
return false;
}
if ((Object)(object)__instance == (Object)(object)Program.mapInstance.m_largeRoot && value && !LargeMapCanBeActive)
{
__instance.SetActive(false);
return false;
}
return true;
}
}
[HarmonyPatch]
internal class MapTableUpdate
{
private static MethodBase TargetMethod()
{
return AccessTools.Method(typeof(MapTable), "OnRead", new Type[4]
{
typeof(Switch),
typeof(Humanoid),
typeof(ItemData),
typeof(bool)
}, (Type[])null);
}
[HarmonyPrefix]
public static void OnReadPrefix(ref Switch caller, ref Humanoid user, ref ItemData item, ref bool showMessage)
{
LargeMapOnActive.LargeMapCanBeActive = true;
Program.mapInstance.SetMapMode((MapMode)2);
MethodInfo method = ((object)Program.mapInstance).GetType().GetMethod("Update", BindingFlags.Instance | BindingFlags.NonPublic);
method.Invoke(Program.mapInstance, null);
}
[HarmonyPostfix]
public static void OnReadPostFix(ref Switch caller, ref Humanoid user, ref ItemData item, ref bool showMessage)
{
LargeMapOnActive.LargeMapCanBeActive = false;
}
}
[HarmonyPatch(typeof(Minimap), "Awake")]
internal class MinimapAwake
{
[HarmonyPostfix]
public static void AwakePostFix(Minimap __instance)
{
Program.mapInstance = __instance;
GameObject smallRoot = Program.mapInstance.m_smallRoot;
if (smallRoot != null)
{
smallRoot.SetActive(false);
}
}
}
public class Program
{
public static Minimap mapInstance;
}
[BepInPlugin("connorcacy.valheim.modcarttablemaponly", "Valheim Mod - no maps except on cartography table read", "1.0.0")]
[BepInProcess("valheim.exe")]
public class ModCartTableMapOnly : BaseUnityPlugin
{
private Harmony _harmony;
public static ManualLogSource StaticLogger;
public void Awake()
{
StaticLogger = ((BaseUnityPlugin)this).Logger;
_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "connorcacy.valheim.modcarttablemaponly");
}
}