Decompiled source of Sea Sailer v1.0.1

Mods/SeaSailer.dll

Decompiled 3 weeks ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Threading.Tasks;
using BoneLib;
using BoneLib.BoneMenu;
using BoneLib.Notifications;
using HarmonyLib;
using Il2CppCysharp.Threading.Tasks;
using Il2CppSLZ.Marrow.Utilities;
using MelonLoader;
using MelonLoader.InternalUtils;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using SeaSailer;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(global::SeaSailer.SeaSailer), "SeaSailer", "1.0.0", "Bhijn", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: MelonAuthorColor(255, 198, 119, 230)]
[assembly: MelonAdditionalDependencies(new string[] { "BoneLib" })]
[assembly: AssemblyDescription("Allows toggling Bonelab's anti-piracy features at runtime")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("SeaSailer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SeaSailer")]
[assembly: AssemblyTitle("SeaSailer")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 SeaSailer
{
	public class SeaSailer : MelonMod
	{
		[HarmonyPatch(typeof(MarrowEntitlement), "CheckEntitlementAsync")]
		public static class EntitlementCheck
		{
			private static void Postfix(ref UniTask<bool> __result)
			{
				if (__result.result && !GenuinelyPassedCheck)
				{
					AllowPiracy();
				}
				if (GameInitialized && GenuinelyPassedCheck)
				{
					__result.result = !SailingSeas;
				}
			}
		}

		internal static Instance Logger;

		public static MelonPreferences_Category SailorCategory;

		public static MelonPreferences_Entry<bool> MelonSailingSeas;

		public static Page SailorPage;

		public static BoolElement BonedSailingSeas;

		public static bool SailingSeas;

		public static bool ProperlyInitialized;

		public static bool GenuinelyPassedCheck;

		public static bool CheckFailureWarned;

		public static bool GameInitialized;

		public static bool PotentiallyPirated;

		public override void OnInitializeMelon()
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			SailorCategory = MelonPreferences.CreateCategory("SeaSailer");
			MelonSailingSeas = SailorCategory.CreateEntry<bool>("SailingSeas", false, "Anti-piracy measures enabled?", (string)null, false, false, (ValueValidator)null, (string)null);
			SailingSeas = MelonSailingSeas.Value;
			Logger = ((MelonBase)this).LoggerInstance;
			SailorPage = Page.Root.CreatePage("Sea Sailer", Color.white, 0, false);
			BonedSailingSeas = SailorPage.CreateBool("Sail the seven seas?", Color.white, SailingSeas, (Action<bool>)YarrMatey);
			Hooking.OnMarrowGameStarted += HoistSail;
			Hooking.OnLevelLoaded += SanityCheck;
			if (!HelperMethods.IsAndroid() && MelonEnvironment.GameExecutableName == "BONELAB_Steam_Windows64")
			{
				string gameVersion = UnityInformationHandler.GameVersion;
				if (gameVersion == "1.744.58126")
				{
					MD5 mD = MD5.Create();
					FileStream fileStream = File.OpenRead(MelonEnvironment.GameExecutablePath);
					FileStream fileStream2 = File.OpenRead(MelonEnvironment.UnityGameDataDirectory + "\\Plugins\\x86_64\\steam_api64.dll");
					byte[] array = mD.ComputeHash(fileStream);
					byte[] array2 = mD.ComputeHash(fileStream2);
					long num = BitConverter.ToInt64(array) - BitConverter.ToInt64(array, 8) + BitConverter.ToInt64(array2) - BitConverter.ToInt64(array2, 8);
					fileStream.Dispose();
					fileStream2.Dispose();
					if (num != 768354071345851907L)
					{
						PotentiallyPirated = true;
					}
				}
				else if (gameVersion == "1.702.57346")
				{
					PotentiallyPirated = true;
				}
			}
			ProperlyInitialized = true;
		}

		public override void OnPreferencesLoaded()
		{
			if (ProperlyInitialized)
			{
				SailingSeas = MelonSailingSeas.Value;
				BonedSailingSeas.Value = SailingSeas;
			}
		}

		public static void YarrMatey(bool value)
		{
			SailingSeas = value;
			MelonSailingSeas.Value = value;
			SailorCategory.SaveToFile(false);
		}

		public static void HoistSail()
		{
			GameInitialized = true;
			if (PotentiallyPirated)
			{
				Task.Run(async delegate
				{
					await Task.Delay(1800000);
					Notifier.Send(new Notification
					{
						Title = NotificationText.op_Implicit("Notice"),
						Message = NotificationText.op_Implicit("You seem to enjoy this game!\nYou should support the developers, and buy it."),
						ShowTitleOnPopup = true,
						PopupLength = 30f,
						Type = (NotificationType)0
					});
				});
			}
		}

		public static void SanityCheck(LevelInfo info)
		{
			if (GenuinelyPassedCheck || CheckFailureWarned)
			{
				return;
			}
			Task.Run(async delegate
			{
				await Task.Delay(5000);
				if (!GenuinelyPassedCheck && !CheckFailureWarned)
				{
					Logger.Msg("Entitlement check failed or is inactive this session.");
					Logger.Msg("Sea Sailer will be inactive until restart or check passes.");
					Notifier.Send(new Notification
					{
						Title = NotificationText.op_Implicit("Sea Sailer"),
						Message = NotificationText.op_Implicit("Entitlement check failed or is bugged this session.\nSea Sailer will be inactive until restart or check passes."),
						ShowTitleOnPopup = true,
						PopupLength = 10f,
						Type = (NotificationType)1
					});
					CheckFailureWarned = true;
				}
			});
		}

		public static void AllowPiracy()
		{
			GenuinelyPassedCheck = true;
			Page.Root.CreatePageLink(SailorPage);
		}
	}
}