using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Digitalroot.Valheim.Common;
using Digitalroot.Valheim.Common.Json;
using HarmonyLib;
using JetBrains.Annotations;
using Jotunn.Utils;
using SimpleJson;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Digitalroot.Valheim.MaxDungeonRooms")]
[assembly: AssemblyDescription("Digitalroot Max Dungeon Rooms")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Digitalroot Technologies")]
[assembly: AssemblyProduct("Digitalroot Valheim Mods")]
[assembly: AssemblyCopyright("Copyright © Digitalroot Technologies 2021 - 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3ccc4dc1-5b17-47c1-b996-ca03b8639a61")]
[assembly: AssemblyFileVersion("2.0.37")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.37.0")]
[module: UnverifiableCode]
namespace Digitalroot.Valheim.MaxDungeonRooms
{
[BepInPlugin("digitalroot.mods.maxdungeonrooms", "Digitalroot Max Dungeon Rooms", "2.0.37")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
public class Main : BaseUnityPlugin, ITraceableLogging
{
private Harmony _harmony;
public static Main Instance;
public static ConfigEntry<int> NexusId;
public ConfigEntry<int> MinRooms;
public ConfigEntry<int> MaxRooms;
public ConfigEntry<bool> EnableForestCryptOverride;
public ConfigEntry<int> ForestCryptOverrideMinRooms;
public ConfigEntry<int> ForestCryptOverrideMaxRooms;
public ConfigEntry<bool> EnableSunkenCryptOverride;
public ConfigEntry<int> SunkenCryptOverrideMinRooms;
public ConfigEntry<int> SunkenCryptOverrideMaxRooms;
public ConfigEntry<bool> EnableCaveOverride;
public ConfigEntry<int> CaveOverrideMinRooms;
public ConfigEntry<int> CaveOverrideMaxRooms;
public ConfigEntry<bool> EnableDvergrTownOverride;
public ConfigEntry<int> DvergrTownOverrideMinRooms;
public ConfigEntry<int> DvergrTownOverrideMaxRooms;
public const string Version = "2.0.37";
public const string Name = "Digitalroot Max Dungeon Rooms";
public const string Guid = "digitalroot.mods.maxdungeonrooms";
public const string Namespace = "Digitalroot.Valheim.MaxDungeonRooms";
public string Source => "Digitalroot.Valheim.MaxDungeonRooms";
public bool EnableTrace { get; }
public Main()
{
//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_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Expected O, but got Unknown
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Expected O, but got Unknown
try
{
EnableTrace = false;
Instance = this;
NexusId = ((BaseUnityPlugin)this).Config.Bind<int>("1. General", "NexusID", 1665, new ConfigDescription("Nexus mod ID for updates", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
{
Browsable = false,
ReadOnly = true
} }));
Log.RegisterSource(Instance);
Log.Trace(Instance, ((object)this).GetType().Namespace + "." + ((object)this).GetType().Name + "." + MethodBase.GetCurrentMethod()?.Name + "()");
}
catch (Exception ex)
{
ZLog.LogError((object)ex);
}
}
[UsedImplicitly]
private void Awake()
{
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Expected O, but got Unknown
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Expected O, but got Unknown
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_0101: Expected O, but got Unknown
//IL_0101: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Expected O, but got Unknown
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_0148: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_0162: Expected O, but got Unknown
//IL_0162: Unknown result type (might be due to invalid IL or missing references)
//IL_016c: Expected O, but got Unknown
//IL_019a: Unknown result type (might be due to invalid IL or missing references)
//IL_019f: Unknown result type (might be due to invalid IL or missing references)
//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
//IL_01be: Unknown result type (might be due to invalid IL or missing references)
//IL_01cb: Expected O, but got Unknown
//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
//IL_01d5: Expected O, but got Unknown
//IL_0206: Unknown result type (might be due to invalid IL or missing references)
//IL_020b: Unknown result type (might be due to invalid IL or missing references)
//IL_0212: Unknown result type (might be due to invalid IL or missing references)
//IL_021e: Unknown result type (might be due to invalid IL or missing references)
//IL_022a: Unknown result type (might be due to invalid IL or missing references)
//IL_0237: Expected O, but got Unknown
//IL_0237: Unknown result type (might be due to invalid IL or missing references)
//IL_0241: Expected O, but got Unknown
//IL_0266: Unknown result type (might be due to invalid IL or missing references)
//IL_026b: Unknown result type (might be due to invalid IL or missing references)
//IL_0272: Unknown result type (might be due to invalid IL or missing references)
//IL_027e: Unknown result type (might be due to invalid IL or missing references)
//IL_028b: Unknown result type (might be due to invalid IL or missing references)
//IL_0298: Expected O, but got Unknown
//IL_0298: Unknown result type (might be due to invalid IL or missing references)
//IL_02a2: Expected O, but got Unknown
//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
//IL_0301: Expected O, but got Unknown
//IL_0301: Unknown result type (might be due to invalid IL or missing references)
//IL_030b: Expected O, but got Unknown
//IL_033c: Unknown result type (might be due to invalid IL or missing references)
//IL_0341: Unknown result type (might be due to invalid IL or missing references)
//IL_0348: Unknown result type (might be due to invalid IL or missing references)
//IL_0354: Unknown result type (might be due to invalid IL or missing references)
//IL_0360: Unknown result type (might be due to invalid IL or missing references)
//IL_036d: Expected O, but got Unknown
//IL_036d: Unknown result type (might be due to invalid IL or missing references)
//IL_0377: Expected O, but got Unknown
//IL_039c: Unknown result type (might be due to invalid IL or missing references)
//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
//IL_03ce: Expected O, but got Unknown
//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
//IL_03d8: Expected O, but got Unknown
//IL_0406: Unknown result type (might be due to invalid IL or missing references)
//IL_040b: Unknown result type (might be due to invalid IL or missing references)
//IL_0412: Unknown result type (might be due to invalid IL or missing references)
//IL_041e: Unknown result type (might be due to invalid IL or missing references)
//IL_042a: Unknown result type (might be due to invalid IL or missing references)
//IL_0437: Expected O, but got Unknown
//IL_0437: Unknown result type (might be due to invalid IL or missing references)
//IL_0441: Expected O, but got Unknown
//IL_0472: Unknown result type (might be due to invalid IL or missing references)
//IL_0477: Unknown result type (might be due to invalid IL or missing references)
//IL_047e: Unknown result type (might be due to invalid IL or missing references)
//IL_048a: Unknown result type (might be due to invalid IL or missing references)
//IL_0496: Unknown result type (might be due to invalid IL or missing references)
//IL_04a3: Expected O, but got Unknown
//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
//IL_04ad: Expected O, but got Unknown
//IL_04d2: Unknown result type (might be due to invalid IL or missing references)
//IL_04d7: Unknown result type (might be due to invalid IL or missing references)
//IL_04de: Unknown result type (might be due to invalid IL or missing references)
//IL_04ea: Unknown result type (might be due to invalid IL or missing references)
//IL_04f7: Unknown result type (might be due to invalid IL or missing references)
//IL_0504: Expected O, but got Unknown
//IL_0504: Unknown result type (might be due to invalid IL or missing references)
//IL_050e: Expected O, but got Unknown
//IL_053c: Unknown result type (might be due to invalid IL or missing references)
//IL_0541: Unknown result type (might be due to invalid IL or missing references)
//IL_0548: Unknown result type (might be due to invalid IL or missing references)
//IL_0554: Unknown result type (might be due to invalid IL or missing references)
//IL_0560: Unknown result type (might be due to invalid IL or missing references)
//IL_056d: Expected O, but got Unknown
//IL_056d: Unknown result type (might be due to invalid IL or missing references)
//IL_0577: Expected O, but got Unknown
//IL_05a8: Unknown result type (might be due to invalid IL or missing references)
//IL_05ad: Unknown result type (might be due to invalid IL or missing references)
//IL_05b4: Unknown result type (might be due to invalid IL or missing references)
//IL_05c0: Unknown result type (might be due to invalid IL or missing references)
//IL_05cc: Unknown result type (might be due to invalid IL or missing references)
//IL_05d9: Expected O, but got Unknown
//IL_05d9: Unknown result type (might be due to invalid IL or missing references)
//IL_05e3: Expected O, but got Unknown
try
{
Log.Trace(Instance, "Digitalroot.Valheim.MaxDungeonRooms." + MethodBase.GetCurrentMethod()?.DeclaringType?.Name + "." + MethodBase.GetCurrentMethod()?.Name);
((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
MinRooms = ((BaseUnityPlugin)this).Config.Bind<int>("1. General", "Min Rooms", 20, new ConfigDescription("Min number of rooms in a dungeon.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 120), new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true,
Browsable = true,
Order = 1
} }));
MaxRooms = ((BaseUnityPlugin)this).Config.Bind<int>("1. General", "Max Rooms", 40, new ConfigDescription("Max number of rooms in a dungeon.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 1000), new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true,
Browsable = true,
Order = 0
} }));
EnableForestCryptOverride = ((BaseUnityPlugin)this).Config.Bind<bool>("2. Forest Crypt Overrides", "Enable Forest Crypt Override", false, new ConfigDescription("Min number of rooms in a Forest Crypt dungeon.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true,
Browsable = true,
Order = 100,
IsAdvanced = true
} }));
ForestCryptOverrideMinRooms = ((BaseUnityPlugin)this).Config.Bind<int>("2. Forest Crypt Overrides", "Forest Crypt Min Rooms", 20, new ConfigDescription("Min number of rooms in a Forest Crypt dungeon.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 120), new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true,
Browsable = true,
Order = 1,
IsAdvanced = true
} }));
ForestCryptOverrideMaxRooms = ((BaseUnityPlugin)this).Config.Bind<int>("2. Forest Crypt Overrides", "Forest Crypt Max Rooms", 40, new ConfigDescription("Max number of rooms in a Forest Crypt dungeon.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 1000), new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true,
Browsable = true,
Order = 0,
IsAdvanced = true
} }));
EnableSunkenCryptOverride = ((BaseUnityPlugin)this).Config.Bind<bool>("3. Sunken Crypt Overrides", "Enable Sunken Crypt Override", false, new ConfigDescription("Min number of rooms in a Sunken Crypt dungeon.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true,
Browsable = true,
Order = 100,
IsAdvanced = true
} }));
SunkenCryptOverrideMinRooms = ((BaseUnityPlugin)this).Config.Bind<int>("3. Sunken Crypt Overrides", "Sunken Crypt Min Rooms", 20, new ConfigDescription("Min number of rooms in a Sunken Crypt dungeon.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 120), new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true,
Browsable = true,
Order = 1,
IsAdvanced = true
} }));
SunkenCryptOverrideMaxRooms = ((BaseUnityPlugin)this).Config.Bind<int>("3. Sunken Crypt Overrides", "Sunken Crypt Max Rooms", 30, new ConfigDescription("Max number of rooms in a Sunken Crypt dungeon.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 1000), new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true,
Browsable = true,
Order = 0,
IsAdvanced = true
} }));
EnableCaveOverride = ((BaseUnityPlugin)this).Config.Bind<bool>("4. Cave Overrides", "Enable Cave Override", false, new ConfigDescription("Min number of rooms in a Cave dungeon.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true,
Browsable = true,
Order = 100,
IsAdvanced = true
} }));
CaveOverrideMinRooms = ((BaseUnityPlugin)this).Config.Bind<int>("4. Cave Overrides", "Cave Min Rooms", 20, new ConfigDescription("Min number of rooms in a Cave dungeon.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 120), new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true,
Browsable = true,
Order = 1,
IsAdvanced = true
} }));
CaveOverrideMaxRooms = ((BaseUnityPlugin)this).Config.Bind<int>("4. Cave Overrides", "Cave Max Rooms", 40, new ConfigDescription("Max number of rooms in a Cave dungeon.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 1000), new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true,
Browsable = true,
Order = 0,
IsAdvanced = true
} }));
EnableDvergrTownOverride = ((BaseUnityPlugin)this).Config.Bind<bool>("5. Dvergr Town Overrides", "Enable Dvergr Town Override", false, new ConfigDescription("Min number of rooms in a Dvergr Town dungeon.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true,
Browsable = true,
Order = 100,
IsAdvanced = true
} }));
DvergrTownOverrideMinRooms = ((BaseUnityPlugin)this).Config.Bind<int>("5. Dvergr Town Overrides", "Dvergr Town Min Rooms", 20, new ConfigDescription("Min number of rooms in a Dvergr Town dungeon.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 120), new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true,
Browsable = true,
Order = 1,
IsAdvanced = true
} }));
DvergrTownOverrideMaxRooms = ((BaseUnityPlugin)this).Config.Bind<int>("5. Dvergr Town Overrides", "Dvergr Town Max Rooms", 40, new ConfigDescription("Max number of rooms in a Dvergr Town dungeon.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 1000), new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true,
Browsable = true,
Order = 0,
IsAdvanced = true
} }));
_harmony = Harmony.CreateAndPatchAll(typeof(Main).Assembly, "digitalroot.mods.maxdungeonrooms");
}
catch (Exception e)
{
Log.Error(Instance, e);
}
}
[UsedImplicitly]
private void OnDestroy()
{
try
{
Log.Trace(Instance, "Digitalroot.Valheim.MaxDungeonRooms." + MethodBase.GetCurrentMethod()?.DeclaringType?.Name + "." + MethodBase.GetCurrentMethod()?.Name);
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
catch (Exception e)
{
Log.Error(Instance, e);
}
}
}
[UsedImplicitly]
public class Patch
{
[UsedImplicitly]
[HarmonyPatch(typeof(DungeonGenerator))]
public class PatchDungeonGeneratorPlaceRooms
{
[HarmonyPrefix]
[HarmonyPriority(400)]
[HarmonyPatch(typeof(DungeonGenerator), "PlaceRooms")]
public static bool Prefix([NotNull] ref DungeonGenerator __instance, SpawnMode mode)
{
//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
//IL_039f: Unknown result type (might be due to invalid IL or missing references)
try
{
Log.Trace(Main.Instance, "Digitalroot.Valheim.MaxDungeonRooms." + MethodBase.GetCurrentMethod()?.DeclaringType?.Name + "." + MethodBase.GetCurrentMethod()?.Name);
Log.Trace(Main.Instance, "[" + MethodBase.GetCurrentMethod()?.DeclaringType?.Name + "] " + ((Object)((Component)__instance).gameObject).name);
int value = Main.Instance.MinRooms.Value;
int value2 = Main.Instance.MaxRooms.Value;
bool flag = true;
switch (((Object)((Component)__instance).gameObject).name)
{
case "DG_ForestCrypt(Clone)":
if (Main.Instance.EnableForestCryptOverride.Value)
{
value = Main.Instance.ForestCryptOverrideMinRooms.Value;
value2 = Main.Instance.ForestCryptOverrideMaxRooms.Value;
}
break;
case "DG_SunkenCrypt(Clone)":
if (Main.Instance.EnableSunkenCryptOverride.Value)
{
value = Main.Instance.SunkenCryptOverrideMinRooms.Value;
value2 = Main.Instance.SunkenCryptOverrideMaxRooms.Value;
}
break;
case "DG_Cave(Clone)":
if (Main.Instance.EnableCaveOverride.Value)
{
value = Main.Instance.CaveOverrideMinRooms.Value;
value2 = Main.Instance.CaveOverrideMaxRooms.Value;
}
break;
case "DG_DvergrTown(Clone)":
if (Main.Instance.EnableDvergrTownOverride.Value)
{
value = Main.Instance.DvergrTownOverrideMinRooms.Value;
value2 = Main.Instance.DvergrTownOverrideMaxRooms.Value;
}
break;
default:
flag = false;
break;
}
if (flag)
{
__instance.m_minRooms = value;
__instance.m_maxRooms = value2;
}
int i;
for (i = 0; i < __instance.m_maxRooms; i++)
{
__instance.PlaceOneRoom(mode);
if (__instance.CheckRequiredRooms() && DungeonGenerator.m_placedRooms.Count > __instance.m_minRooms)
{
ZLog.Log((object)"All required rooms have been placed, stopping generation");
break;
}
if (i + 1 > __instance.m_maxRooms)
{
Log.Trace(Main.Instance, $"i : {i}, DungeonGenerator.m_placedRooms.Count : {DungeonGenerator.m_placedRooms.Count}");
Log.Trace(Main.Instance, $"__instance.CheckRequiredRooms() : {__instance.CheckRequiredRooms()}");
Log.Trace(Main.Instance, $"DungeonGenerator.m_placedRooms.Count > __instance.m_minRooms : {DungeonGenerator.m_placedRooms.Count > __instance.m_minRooms}");
Log.Trace(Main.Instance, $"i+1 < __instance.m_maxRooms : {i + 1 < __instance.m_maxRooms}");
}
}
Log.Debug(Main.Instance, "All required rooms have been placed, stopping generation");
Log.Debug(Main.Instance, "[" + MethodBase.GetCurrentMethod()?.DeclaringType?.Name + "] __instance.gameObject.name : " + ((Object)((Component)__instance).gameObject).name);
Log.Debug(Main.Instance, $"[{MethodBase.GetCurrentMethod()?.DeclaringType?.Name}] DungeonGenerator.m_placedRooms.Count : {DungeonGenerator.m_placedRooms.Count}");
Log.Debug(Main.Instance, $"[{MethodBase.GetCurrentMethod()?.DeclaringType?.Name}] Loc: {((Component)__instance).gameObject.transform.position}");
Log.Debug(Main.Instance, $"Total attempts {i} of {__instance.m_minRooms}/{__instance.m_maxRooms}");
}
catch (Exception e)
{
Log.Error(Main.Instance, e);
}
return false;
}
}
}
}
namespace Digitalroot.Valheim.Common
{
internal interface ITraceableLogging
{
string Source { get; }
bool EnableTrace { get; }
}
internal sealed class Log
{
private static readonly Dictionary<string, TraceLogger> TraceLoggers;
[UsedImplicitly]
private static Log Instance { get; }
static Log()
{
TraceLoggers = new Dictionary<string, TraceLogger>();
Instance = new Log();
}
private Log()
{
TraceLoggers.Add("Digitalroot", new TraceLogger("Digitalroot", enableTrace: false));
}
public static void RegisterSource(ITraceableLogging sender)
{
if ((!TraceLoggers.ContainsKey(sender.Source) || TraceLoggers[sender.Source].IsTraceEnabled != sender.EnableTrace) && (!TraceLoggers.ContainsKey(sender.Source) || sender.EnableTrace))
{
if (TraceLoggers.ContainsKey(sender.Source) && sender.EnableTrace)
{
TraceLoggers[sender.Source].EnableTrace();
}
else
{
TraceLoggers.Add(sender.Source, new TraceLogger(sender.Source, sender.EnableTrace));
}
}
}
private static TraceLogger GetTraceLogger(ITraceableLogging sender)
{
if (!TraceLoggers.ContainsKey(sender.Source))
{
return TraceLoggers["Digitalroot"];
}
return TraceLoggers[sender.Source];
}
[UsedImplicitly]
public static void SetEnableTrace(ITraceableLogging sender, bool value)
{
if (value)
{
GetTraceLogger(sender).EnableTrace();
}
else
{
GetTraceLogger(sender).DisableTrace();
}
}
[UsedImplicitly]
public static void SetEnableTraceForAllLoggers(bool value)
{
foreach (TraceLogger value2 in TraceLoggers.Values)
{
if (value)
{
value2.EnableTrace();
}
else
{
value2.DisableTrace();
}
}
}
[UsedImplicitly]
public static void Debug(ITraceableLogging sender, object value)
{
GetTraceLogger(sender).LoggerRef.LogDebug(value);
}
[UsedImplicitly]
public static void Error(ITraceableLogging sender, Exception e, int i = 1)
{
Error(sender, "Message: " + e.Message);
Error(sender, $"TargetSite: {e.TargetSite}");
Error(sender, "StackTrace: " + e.StackTrace);
Error(sender, "Source: " + e.Source);
if (e.Data.Count > 0)
{
foreach (object key in e.Data.Keys)
{
Error(sender, $"key: {key}, value: {e.Data[key]}");
}
}
if (e.InnerException != null)
{
Error(sender, $"--- InnerException [{i}][Start] ---");
Error(sender, e.InnerException, ++i);
}
}
[UsedImplicitly]
public static void Error(ITraceableLogging sender, object value)
{
GetTraceLogger(sender).LoggerRef.LogError(value);
}
[UsedImplicitly]
public static void Info(ITraceableLogging sender, object value)
{
GetTraceLogger(sender).LoggerRef.LogInfo(value);
}
[UsedImplicitly]
public static void Fatal(ITraceableLogging sender, Exception e, int i = 1)
{
Fatal(sender, "Message: " + e.Message);
Fatal(sender, $"TargetSite: {e.TargetSite}");
Fatal(sender, "StackTrace: " + e.StackTrace);
Fatal(sender, "Source: " + e.Source);
if (e.Data.Count > 0)
{
foreach (object key in e.Data.Keys)
{
Fatal(sender, $"key: {key}, value: {e.Data[key]}");
}
}
if (e.InnerException != null)
{
Fatal(sender, $"--- InnerException [{i}][Start] ---");
Fatal(sender, e.InnerException, ++i);
}
}
[UsedImplicitly]
public static void Fatal(ITraceableLogging sender, object value)
{
GetTraceLogger(sender).LoggerRef.LogFatal(value);
}
[UsedImplicitly]
public static void Message(ITraceableLogging sender, object value)
{
GetTraceLogger(sender).LoggerRef.LogMessage(value);
}
[UsedImplicitly]
public static void Trace(ITraceableLogging sender, object value)
{
if (GetTraceLogger(sender).IsTraceEnabled || sender.EnableTrace)
{
GetTraceLogger(sender).LoggerRef.Log((LogLevel)63, value);
}
}
[UsedImplicitly]
public static void Warning(ITraceableLogging sender, object value)
{
GetTraceLogger(sender).LoggerRef.LogWarning(value);
}
}
internal class TraceLogger
{
internal readonly ManualLogSource LoggerRef;
private readonly string _source;
private readonly FileInfo _traceFileInfo;
public bool IsTraceEnabled { get; private set; }
private DirectoryInfo AssemblyDirectory => new FileInfo(Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path)).Directory;
public TraceLogger(string source, bool enableTrace)
{
_source = source;
IsTraceEnabled = enableTrace;
LoggerRef = Logger.CreateLogSource(_source);
_traceFileInfo = new FileInfo(Path.Combine(Paths.BepInExRootPath ?? AssemblyDirectory.FullName, "logs", _source + ".Trace.log"));
if (_traceFileInfo.DirectoryName != null)
{
Directory.CreateDirectory(_traceFileInfo.DirectoryName);
}
if (_traceFileInfo.Exists)
{
_traceFileInfo.Delete();
_traceFileInfo.Refresh();
}
LoggerRef.LogEvent += OnLogEvent;
}
public void EnableTrace()
{
IsTraceEnabled = true;
}
public void DisableTrace()
{
IsTraceEnabled = false;
}
[UsedImplicitly]
public void StopTrace()
{
LoggerRef.LogEvent -= OnLogEvent;
}
private void OnLogEvent(object sender, LogEventArgs e)
{
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
if (e.Source.SourceName != _source || !IsTraceEnabled)
{
return;
}
using Mutex mutex = new Mutex(initiallyOwned: false, "Digitalroot.Valheim.Common.TraceLogger." + _source);
mutex.WaitOne();
try
{
if (e.Data is string)
{
string contents = $"[{e.Level,-7}:{e.Source.SourceName,10}] {e.Data}{Environment.NewLine}";
File.AppendAllText(_traceFileInfo.FullName, contents, Encoding.UTF8);
}
else
{
string contents2 = $"[{e.Level,-7}:{e.Source.SourceName,10}] {JsonSerializationProvider.Serialize(e.Data)}{Environment.NewLine}";
File.AppendAllText(_traceFileInfo.FullName, contents2, Encoding.UTF8);
}
}
finally
{
mutex.ReleaseMutex();
}
}
}
}
namespace Digitalroot.Valheim.Common.Json
{
[UsedImplicitly]
internal static class JsonSerializationProvider
{
[Obsolete("Use Deserialize<T>()")]
public static T FromJson<T>(string json)
{
return Deserialize<T>(json);
}
public static T Deserialize<T>(string json)
{
return SimpleJson.DeserializeObject<T>(json, (IJsonSerializerStrategy)(object)new DigitalrootJsonSerializerStrategy());
}
[Obsolete("Use Serialize()")]
public static string ToJson(object obj, bool pretty = false)
{
return Serialize(obj);
}
public static string Serialize(object obj)
{
return SimpleJson.SerializeObject(obj, (IJsonSerializerStrategy)(object)new DigitalrootJsonSerializerStrategy());
}
}
internal class DigitalrootJsonSerializerStrategy : PocoJsonSerializerStrategy
{
public override bool TrySerializeNonPrimitiveObject(object input, out object output)
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: 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_0062: 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)
if (!(input is Vector3 val))
{
if (input is Quaternion val2)
{
output = new float[4] { val2.x, val2.y, val2.z, val2.w };
return true;
}
return ((PocoJsonSerializerStrategy)this).TrySerializeNonPrimitiveObject(input, ref output);
}
output = new float[3] { val.x, val.y, val.z };
return true;
}
public override object DeserializeObject(object value, Type type)
{
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
if (type == null)
{
throw new ArgumentNullException("type");
}
if (value == null)
{
throw new ArgumentNullException("value");
}
if (value is string value2)
{
if (string.IsNullOrWhiteSpace(value2))
{
throw new ArgumentNullException("value");
}
if (type == typeof(Vector3))
{
if (!(((PocoJsonSerializerStrategy)this).DeserializeObject(value, typeof(float[])) is float[] array) || (array != null && array.Length != 3))
{
throw new ArgumentException(string.Format("The value '{0}' can be converted to a {1}.", value, "Vector3"), "value");
}
return (object)new Vector3(array[0], array[1], array[2]);
}
if (type == typeof(Quaternion))
{
if (!(((PocoJsonSerializerStrategy)this).DeserializeObject(value, typeof(float[])) is float[] array2) || (array2 != null && array2.Length != 4))
{
throw new ArgumentException(string.Format("The value '{0}' can be converted to a {1}.", value, "Quaternion"), "value");
}
return (object)new Quaternion(array2[0], array2[1], array2[2], array2[3]);
}
return ((PocoJsonSerializerStrategy)this).DeserializeObject(value, type);
}
throw new ArgumentException($"The value '{value}' can be converted to a {type.Name}.", "value");
}
}
}
internal class DigitalrootValheimMaxDungeonRooms_ProcessedByFody
{
internal const string FodyVersion = "6.6.0.0";
internal const string ILMerge = "1.22.0.0";
}