imnyang/BlockModLoader
Archived
Watch
2
0
Fork
You've already forked BlockModLoader
0

Initial commit

This commit is contained in:
암냥 2026-10-05 12:56:13 +09:00
commit d5d9fbf47c
3 changed files with 942 additions and 0 deletions

View file

@ -0,0 +1,18 @@
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)/$(MSBuildToolsVersion)/Microsoft.Common.props"/>
<PropertyGroup>
<OutputType>Exe</OutputType><AssemblyName>BlockMelonLoader.Tests</AssemblyName><TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<LangVersion>latest</LangVersion><OutputPath>bin/Release/</OutputPath>
<TargetFrameworkRootPath Condition="Exists('../packages/net48/build/.NETFramework/v4.8')">$(MSBuildProjectDirectory)/../packages/net48/build/</TargetFrameworkRootPath>
<FrameworkPathOverride Condition="Exists('../packages/net48/build/.NETFramework/v4.8')">$(MSBuildProjectDirectory)/../packages/net48/build/.NETFramework/v4.8</FrameworkPathOverride>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib"><Private>false</Private></Reference>
<Reference Include="System"><Private>false</Private></Reference>
<Reference Include="System.Core"><Private>false</Private></Reference>
<Compile Include="Program.cs"/>
<Compile Include="BlockMelonLoaderTests.cs"/>
<Compile Include="../LoaderGuard.cs" Link="LoaderGuard.cs"/>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)/Microsoft.CSharp.targets"/>
</Project>

View file

@ -0,0 +1,44 @@
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.");
}
}

19
Tests/Program.cs Normal file
View file

@ -0,0 +1,19 @@
using System;
internal static class Program
{
private static int Main()
{
try
{
BlockMelonLoaderTests.Run();
Console.WriteLine("BlockMelonLoader tests passed.");
return 0;
}
catch (Exception exception)
{
Console.Error.WriteLine(exception);
return 1;
}
}
}