imnyang/BlockModLoader
Archived
Watch
2
0
Fork
You've already forked BlockModLoader
0
This repository has been archived on 2026-10-08. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
BlockModLoader/Tests/BlockMelonLoaderTests.cs
2026-10-05 12:57:50 +09:00

44 lines
1.8 KiB
C#

using System;
using System.Reflection;
using System.Reflection.Emit;
using BlockMelonLoader;
internal static class BlockMelonLoaderTests
{
internal static void Run()
{
var alerts = 0;
var terminations = 0;
Action<string> alert = message =>
{
if (!message.Contains("SampleMod") || !message.Contains("Unity Mod Manager"))
throw new Exception("Missing mod name or installation guidance.");
alerts++;
};
Action<string> terminate = message =>
{
if (alerts == 0) throw new Exception("Termination preceded notification.");
terminations++;
};
var unrelated = AppDomain.CurrentDomain.DefineDynamicAssembly(
new AssemblyName("MelonLoader.Helper"), AssemblyBuilderAccess.Run);
LoaderGuard.EnsureAllowed("SampleMod", new[] { typeof(LoaderGuard).Assembly, unrelated }, alert, terminate);
if (alerts != 0 || terminations != 0) throw new Exception("Blocked an unrelated assembly.");
var loader = AppDomain.CurrentDomain.DefineDynamicAssembly(
new AssemblyName("melonloader"), AssemblyBuilderAccess.Run);
LoaderGuard.EnsureAllowed("SampleMod", new[] { loader }, alert, terminate);
if (alerts != 1 || terminations != 1) throw new Exception("MelonLoader was not blocked.");
try
{
LoaderGuard.EnsureAllowed("SampleMod", new[] { loader },
message => { throw new InvalidOperationException("Dialog unavailable."); },
message => terminations++);
throw new Exception("Expected the simulated dialog failure.");
}
catch (InvalidOperationException) { }
if (terminations != 2) throw new Exception("Dialog failure bypassed termination.");
}
}