Decompiled source of LegacyZRoutedRpcCompat v1.0.1

BepInEx\patchers\AWLLegacyZRoutedRpcCompat.Patcher.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Mono.Cecil;
using Mono.Collections.Generic;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("AWLLegacyZRoutedRpcCompat.Patcher")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("AWLLegacyZRoutedRpcCompat.Patcher")]
[assembly: AssemblyTitle("AWLLegacyZRoutedRpcCompat.Patcher")]
[assembly: AssemblyVersion("1.0.1.0")]
public static class AWLLegacyZRoutedRpcCompatPatcher
{
	public static IEnumerable<string> TargetDLLs => new string[1] { "assembly_valheim.dll" };

	public static void Patch(AssemblyDefinition assembly)
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		TypeDefinition obj = assembly.MainModule.GetType("ZRoutedRpc") ?? throw new InvalidOperationException("ZRoutedRpc was not found in assembly_valheim.dll.");
		FieldDefinition val = null;
		Enumerator<FieldDefinition> enumerator = obj.Fields.GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				FieldDefinition current = enumerator.Current;
				if (((MemberReference)current).Name == "Everybody")
				{
					val = current;
					break;
				}
			}
		}
		finally
		{
			((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
		}
		if (val == null)
		{
			throw new InvalidOperationException("ZRoutedRpc.Everybody was not found.");
		}
		if (((MemberReference)((FieldReference)val).FieldType).FullName != "System.Int64" || !val.IsStatic)
		{
			throw new InvalidOperationException("ZRoutedRpc.Everybody has an unexpected signature.");
		}
		if (val.IsLiteral)
		{
			if (!val.HasConstant || Convert.ToInt64(val.Constant) != 0L)
			{
				throw new InvalidOperationException("ZRoutedRpc.Everybody no longer has the expected constant value 0.");
			}
			val.Constant = null;
			FieldDefinition obj2 = val;
			obj2.Attributes = (FieldAttributes)(obj2.Attributes & 0xFFBF);
			FieldDefinition obj3 = val;
			obj3.Attributes = (FieldAttributes)(obj3.Attributes & 0x7FFF);
			FieldDefinition obj4 = val;
			obj4.Attributes = (FieldAttributes)(obj4.Attributes | 0x10);
		}
	}
}

BepInEx\plugins\AWLLegacyZRoutedRpcCompat\AWLLegacyZRoutedRpcCompat.dll

Decompiled 3 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("AWLLegacyZRoutedRpcCompat")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("AWLLegacyZRoutedRpcCompat")]
[assembly: AssemblyTitle("AWLLegacyZRoutedRpcCompat")]
[assembly: AssemblyVersion("1.0.1.0")]
namespace AWLGaming.Valheim;

[BepInPlugin("net.awlgaming.valheim.legacyzroutedrpccompat", "AWL Legacy ZRoutedRpc Compatibility", "1.0.1")]
public sealed class LegacyZRoutedRpcCompatPlugin : BaseUnityPlugin
{
	private void Awake()
	{
		Type type = Type.GetType("ZRoutedRpc, assembly_valheim", throwOnError: false);
		FieldInfo fieldInfo = ((type == null) ? null : type.GetField("Everybody", BindingFlags.Static | BindingFlags.Public));
		if (fieldInfo == null || fieldInfo.FieldType != typeof(long) || fieldInfo.IsLiteral)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"ZRoutedRpc.Everybody compatibility field is not active.");
			return;
		}
		object value = fieldInfo.GetValue(null);
		if (!(value is long) || (long)value != 0L)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"ZRoutedRpc.Everybody compatibility field has an unexpected value.");
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Valheim 1.0 legacy ZRoutedRpc.Everybody compatibility is active.");
		}
	}
}