using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using Microsoft.CodeAnalysis; using Mono.Cecil; using Mono.Cecil.Cil; [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("ArgusMagnus")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("ArgusMagnus")] [assembly: AssemblyFileVersion("1.99.8.0")] [assembly: AssemblyInformationalVersion("1.99.8-beta+328851184cc278c858ffbc70e717af9f9d7b6973")] [assembly: AssemblyProduct("ServersideQoL.Patchers")] [assembly: AssemblyTitle("ServersideQoL.Patchers")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/ArgusMagnus/ValheimServersideQoL")] [assembly: AssemblyVersion("1.99.8.0")] [module: RefSafetyRules(11)] [CompilerGenerated] internal sealed class <>z__ReadOnlySingleElementList : IEnumerable, ICollection, IList, IEnumerable, IReadOnlyCollection, IReadOnlyList, ICollection, IList { private sealed class Enumerator : IDisposable, IEnumerator, IEnumerator { object IEnumerator.Current => _item; T IEnumerator.Current => _item; public Enumerator(T item) { _item = item; } bool IEnumerator.MoveNext() { if (!_moveNextCalled) { return _moveNextCalled = true; } return false; } void IEnumerator.Reset() { _moveNextCalled = false; } void IDisposable.Dispose() { } } int ICollection.Count => 1; bool ICollection.IsSynchronized => false; object ICollection.SyncRoot => this; object IList.this[int index] { get { if (index != 0) { throw new IndexOutOfRangeException(); } return _item; } set { throw new NotSupportedException(); } } bool IList.IsFixedSize => true; bool IList.IsReadOnly => true; int IReadOnlyCollection.Count => 1; T IReadOnlyList.this[int index] { get { if (index != 0) { throw new IndexOutOfRangeException(); } return _item; } } int ICollection.Count => 1; bool ICollection.IsReadOnly => true; T IList.this[int index] { get { if (index != 0) { throw new IndexOutOfRangeException(); } return _item; } set { throw new NotSupportedException(); } } public <>z__ReadOnlySingleElementList(T item) { _item = item; } IEnumerator IEnumerable.GetEnumerator() { return new Enumerator(_item); } void ICollection.CopyTo(Array array, int index) { array.SetValue(_item, index); } int IList.Add(object value) { throw new NotSupportedException(); } void IList.Clear() { throw new NotSupportedException(); } bool IList.Contains(object value) { return EqualityComparer.Default.Equals(_item, (T)value); } int IList.IndexOf(object value) { if (!EqualityComparer.Default.Equals(_item, (T)value)) { return -1; } return 0; } void IList.Insert(int index, object value) { throw new NotSupportedException(); } void IList.Remove(object value) { throw new NotSupportedException(); } void IList.RemoveAt(int index) { throw new NotSupportedException(); } IEnumerator IEnumerable.GetEnumerator() { return new Enumerator(_item); } void ICollection.Add(T item) { throw new NotSupportedException(); } void ICollection.Clear() { throw new NotSupportedException(); } bool ICollection.Contains(T item) { return EqualityComparer.Default.Equals(_item, item); } void ICollection.CopyTo(T[] array, int arrayIndex) { array[arrayIndex] = _item; } bool ICollection.Remove(T item) { throw new NotSupportedException(); } int IList.IndexOf(T item) { if (!EqualityComparer.Default.Equals(_item, item)) { return -1; } return 0; } void IList.Insert(int index, T item) { throw new NotSupportedException(); } void IList.RemoveAt(int index) { throw new NotSupportedException(); } } namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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] [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; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ServersideQoL.Patchers { internal static class Patcher { private const string AssemblyName = "assembly_valheim.dll"; public static IEnumerable TargetDLLs => new <>z__ReadOnlySingleElementList("assembly_valheim.dll"); public static void Patch(AssemblyDefinition assembly) { AddProperty(assembly, "ZDO", "ServersideQoL", "ServersideQoLZDO", "ServersideQoLZDO"); AddProperty(assembly, "ZNetPeer", "ServersideQoL", "Peer", "ServersideQoLPeer"); static void AddProperty(AssemblyDefinition val, string typeToExtendName, string propertyTypeNamespace, string propertyTypeName, string propertyName) { //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected O, but got Unknown //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Expected O, but got Unknown //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Expected O, but got Unknown //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Expected O, but got Unknown //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Expected O, but got Unknown //IL_00df: 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_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Expected O, but got Unknown //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Expected O, but got Unknown //IL_01c5: Expected O, but got Unknown //IL_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_01f7: Unknown result type (might be due to invalid IL or missing references) //IL_020e: Unknown result type (might be due to invalid IL or missing references) ModuleDefinition mainModule = val.MainModule; TypeDefinition val2 = mainModule.GetType(typeToExtendName) ?? throw new Exception("Type " + typeToExtendName + " not found"); AssemblyNameReference val3 = new AssemblyNameReference("ServersideQoL.Patchers".Replace(".Patchers", ""), new Version("1.99.8")); mainModule.AssemblyReferences.Add(val3); TypeReference val4 = mainModule.ImportReference(new TypeReference(propertyTypeNamespace, propertyTypeName, mainModule, (IMetadataScope)(object)val3)); TypeReference val5 = mainModule.ImportReference(new TypeReference("System.Runtime.CompilerServices", "NullableAttribute", mainModule, mainModule.TypeSystem.CoreLibrary)); FieldDefinition val6 = new FieldDefinition("<" + propertyName + ">k__BackingField", (FieldAttributes)33, val4); val2.Fields.Add(val6); MethodDefinition val7 = new MethodDefinition("get_" + propertyName, (MethodAttributes)2182, val4); ILProcessor iLProcessor = val7.Body.GetILProcessor(); iLProcessor.Append(iLProcessor.Create(OpCodes.Ldarg_0)); iLProcessor.Append(iLProcessor.Create(OpCodes.Ldfld, (FieldReference)(object)val6)); iLProcessor.Append(iLProcessor.Create(OpCodes.Ret)); val2.Methods.Add(val7); PropertyDefinition val8 = new PropertyDefinition(propertyName, (PropertyAttributes)0, val4) { GetMethod = val7 }; val2.Properties.Add(val8); MethodDefinition val9 = ((IEnumerable)val2.Methods).Single((MethodDefinition m) => m.IsConstructor && !m.IsStatic); iLProcessor = val9.Body.GetILProcessor(); Instruction val10 = val9.Body.Instructions[0]; MethodReference val11 = new MethodReference(".ctor", mainModule.TypeSystem.Void, val4) { HasThis = true }; val11.Parameters.Add(new ParameterDefinition((TypeReference)(object)val2)); MethodReference val12 = mainModule.ImportReference(val11); iLProcessor.InsertBefore(val10, iLProcessor.Create(OpCodes.Ldarg_0)); iLProcessor.InsertBefore(val10, iLProcessor.Create(OpCodes.Ldarg_0)); iLProcessor.InsertBefore(val10, iLProcessor.Create(OpCodes.Newobj, val12)); iLProcessor.InsertBefore(val10, iLProcessor.Create(OpCodes.Stfld, (FieldReference)(object)val6)); } } } public sealed class PatchersPlugin { public const string Author = "ArgusMagnus"; public const string PluginName = "ServersideQoL.Patchers"; public const string PluginGuid = "ArgusMagnus.ServersideQoL.Patchers"; public const string PluginVersion = "1.99.8"; public const string PluginInformationalVersion = "1.99.8-beta"; private DateTimeOffset BuildTimestamp { get; } = new DateTimeOffset(639215507592029843L, default(TimeSpan)); } }