Decompiled source of OpenWorldVessel v1.0.0

OpenWorldVessel.dll

Decompiled 2 hours ago
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 MioGame;
using MioModLoader;
using MioModdingApi;
using On.MioGame;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]
[assembly: AssemblyCompany("OpenWorldVessel")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+aa8567bc143b7aa6a31309ab20194c7aa0373771")]
[assembly: AssemblyProduct("OpenWorldVessel")]
[assembly: AssemblyTitle("OpenWorldVessel")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace OpenWorldVessel;

public class OpenWorldVessel : Mod
{
	private static ModMenuPage? modPage;

	private static ButtonOption? activate;

	private int startDelay = 20;

	public override void Initialize()
	{
		Hooks();
		ConnectMenus();
	}

	public static List<string> GetData()
	{
		List<string> list = new List<string>();
		using StreamReader streamReader = File.OpenText(".\\mods\\OpenWorldVessel\\shortcuts.dat");
		string[] array = streamReader.ReadToEnd().Split("\n");
		foreach (string text in array)
		{
			if (!string.IsNullOrEmpty(text))
			{
				list.Add(text);
			}
		}
		return list;
	}

	public void ConnectMenus()
	{
		modPage = ModMenu.RegisterMod((Mod)(object)this, "OpenWorldVessel", "");
		activate = modPage.RegisterButton("activate", "Activate", (Action)Hooks, (string)null);
	}

	private void Hooks()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		fixed_update.Prefix += new orig_fixed_update(Fixed_update_Prefix);
	}

	private unsafe void Fixed_update_Prefix(Game* self)
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Expected O, but got Unknown
		if (startDelay > 1)
		{
			startDelay--;
		}
		Unsafe.AsRef<Game>((void*)self);
		ref Save reference = ref ((Game)self).save;
		List<String> list = new List<String>();
		foreach (string datum in GetData())
		{
			list.Add(Util.StringToMioString(datum));
		}
		Span<String> span;
		if (startDelay >= 1)
		{
			span = CollectionsMarshal.AsSpan(list);
			fixed (String* ptr = span)
			{
				for (int i = 0; i < list.Count; i++)
				{
					try
					{
						((Save)(ref reference)).acquire((String*)((byte*)ptr + (nint)i * (nint)Unsafe.SizeOf<String>()));
					}
					catch (Exception ex)
					{
						((Mod)this).LogMessage("[OWV] Could not give shortcut: " + ex);
					}
				}
			}
			startDelay--;
			return;
		}
		span = CollectionsMarshal.AsSpan(list);
		fixed (String* ptr2 = span)
		{
			for (int j = 0; j < list.Count; j++)
			{
				Unsafe.AsRef<Save_entry>((void*)((Save)(ref reference)).peek((String*)((byte*)ptr2 + (nint)j * (nint)Unsafe.SizeOf<String>()))).count = 1;
			}
		}
		fixed_update.Prefix -= new orig_fixed_update(Fixed_update_Prefix);
	}
}