using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("VentureValheim.ServerSideMultiplayerTweaks")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VentureValheim.ServerSideMultiplayerTweaks")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("61B810D5-AA06-49F8-82D6-1DAC8E575266")]
[assembly: AssemblyFileVersion("0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace VentureValheim.ServerSideMultiplayerTweaks
{
[BepInPlugin("com.orianaventure.mod.ServerSideMultiplayerTweaks", "ServerSideMultiplayerTweaks", "0.1.0")]
public class ServerSideMultiplayerTweaksPlugin : BaseUnityPlugin
{
private const string ModName = "ServerSideMultiplayerTweaks";
private const string ModVersion = "0.1.0";
private const string Author = "com.orianaventure.mod";
private const string ModGUID = "com.orianaventure.mod.ServerSideMultiplayerTweaks";
private static string ConfigFileName = "com.orianaventure.mod.ServerSideMultiplayerTweaks.cfg";
private static string ConfigFileFullPath;
private readonly Harmony HarmonyInstance = new Harmony("com.orianaventure.mod.ServerSideMultiplayerTweaks");
public static readonly ManualLogSource ServerSideMultiplayerTweaksLogger;
internal static ConfigEntry<bool> CE_OverridePlayerMapPins;
internal static ConfigEntry<bool> CE_ForcePlayerMapPinsOn;
private DateTime _lastReloadTime;
private const long RELOAD_DELAY = 10000000L;
public static bool GetOverridePlayerMapPins()
{
return CE_OverridePlayerMapPins.Value;
}
public static bool GetForcePlayerMapPinsOn()
{
return CE_ForcePlayerMapPinsOn.Value;
}
private void AddConfig<T>(string key, string section, string description, T value, ref ConfigEntry<T> configEntry)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Expected O, but got Unknown
configEntry = ((BaseUnityPlugin)this).Config.Bind<T>(section, key, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()));
}
public void Awake()
{
AddConfig("OverridePlayerMapPositions", "General", "Override Player map pin position behavior for Minimap (boolean).", value: true, ref CE_OverridePlayerMapPins);
AddConfig("ForcePlayerMapPositionOn", "General", "True to always show Player position on Minimap, False to hide, when OverridePlayerMapPositions is True (boolean).", value: true, ref CE_ForcePlayerMapPinsOn);
ServerSideMultiplayerTweaksLogger.LogInfo((object)"Always has been.");
Assembly executingAssembly = Assembly.GetExecutingAssembly();
HarmonyInstance.PatchAll(executingAssembly);
SetupWatcher();
}
private void OnDestroy()
{
((BaseUnityPlugin)this).Config.Save();
}
private void SetupWatcher()
{
_lastReloadTime = DateTime.Now;
FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName);
fileSystemWatcher.Changed += ReadConfigValues;
fileSystemWatcher.Created += ReadConfigValues;
fileSystemWatcher.Renamed += ReadConfigValues;
fileSystemWatcher.IncludeSubdirectories = true;
fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
fileSystemWatcher.EnableRaisingEvents = true;
}
private void ReadConfigValues(object sender, FileSystemEventArgs e)
{
DateTime now = DateTime.Now;
long num = now.Ticks - _lastReloadTime.Ticks;
if (File.Exists(ConfigFileFullPath) && num >= 10000000)
{
try
{
ServerSideMultiplayerTweaksLogger.LogInfo((object)"Attempting to reload configuration...");
((BaseUnityPlugin)this).Config.Reload();
}
catch
{
ServerSideMultiplayerTweaksLogger.LogError((object)("There was an issue loading " + ConfigFileName));
return;
}
_lastReloadTime = now;
}
}
static ServerSideMultiplayerTweaksPlugin()
{
string configPath = Paths.ConfigPath;
char directorySeparatorChar = Path.DirectorySeparatorChar;
ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName;
ServerSideMultiplayerTweaksLogger = Logger.CreateLogSource("ServerSideMultiplayerTweaks");
CE_OverridePlayerMapPins = null;
CE_ForcePlayerMapPinsOn = null;
}
}
public class ServerSideMultiplayerTweaks
{
[HarmonyPatch(typeof(ZNet), "RPC_ServerSyncedPlayerData")]
private static class Patch_ZNet_RPC_ServerSyncedPlayerData
{
[HarmonyTranspiler]
internal static IEnumerable<CodeInstruction> RPCServerSyncedPlayerDataTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Expected O, but got Unknown
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Expected O, but got Unknown
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Expected O, but got Unknown
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Expected O, but got Unknown
return new CodeMatcher(instructions, generator).Start().MatchStartForward((CodeMatch[])(object)new CodeMatch[4]
{
new CodeMatch((OpCode?)OpCodes.Ldloc_0, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldarg_2, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(ZPackage), "ReadBool", (Type[])null, (Type[])null), (string)null),
new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(ZNetPeer), "m_publicRefPos"), (string)null)
}).ThrowIfInvalid("Could not patch ZNet.RPC_ServerSyncedPlayerData!")
.Advance(3)
.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
{
new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(ServerSideMultiplayerTweaks), "GetPositionVisibility", (Type[])null, (Type[])null))
})
.InstructionEnumeration();
}
}
public static bool GetPositionVisibility(bool publicPosition)
{
if (ServerSideMultiplayerTweaksPlugin.GetOverridePlayerMapPins())
{
return ServerSideMultiplayerTweaksPlugin.GetForcePlayerMapPinsOn();
}
return publicPosition;
}
}
}