Decompiled source of ByokUnlock v1.0.1

patchers/ByokUnlock.dll

Decompiled a week 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.Cecil.Cil;
using Mono.Collections.Generic;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("ByokUnlock")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ByokUnlock")]
[assembly: AssemblyTitle("ByokUnlock")]
[assembly: AssemblyVersion("1.0.0.0")]
public static class ByokUnlock
{
	public static IEnumerable<string> TargetDLLs { get; } = new string[1] { "ScriptsAssDef.dll" };

	public static void Patch(AssemblyDefinition asm)
	{
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		TypeDefinition type = asm.MainModule.GetType("HostAiSettings");
		MethodDefinition val = ((((type != null) ? type.Properties : null) == null) ? null : FindGetter(type));
		if (val == null)
		{
			Console.WriteLine("[ByokUnlock] HostAiSettings.OpenRouterByokEnabled not found (game updated?)");
			return;
		}
		val.Body.Instructions.Clear();
		ILProcessor iLProcessor = val.Body.GetILProcessor();
		iLProcessor.Emit(OpCodes.Ldc_I4_1);
		iLProcessor.Emit(OpCodes.Ret);
		Console.WriteLine("[ByokUnlock] OpenRouter BYOK enabled");
	}

	private static MethodDefinition FindGetter(TypeDefinition t)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		Enumerator<PropertyDefinition> enumerator = t.Properties.GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				PropertyDefinition current = enumerator.Current;
				if (((MemberReference)current).Name == "OpenRouterByokEnabled")
				{
					return current.GetMethod;
				}
			}
		}
		finally
		{
			((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
		}
		return null;
	}
}