using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using MelonLoader;
using MelonLoader.Utils;
using Mono.Cecil;
using Mono.Collections.Generic;
using NoYesFusionBackdoor;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "NoYesFusionBackdoor", "1.0.0", "HAHOOS", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETFramework,Version=v4.7", FrameworkDisplayName = ".NET Framework 4.7")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace NoYesFusionBackdoor;
public class Core : MelonPlugin
{
public override void OnPreInitialization()
{
((MelonBase)this).LoggerInstance.Msg("Check for YesFusionBackdoor");
string[] files = Directory.GetFiles(MelonEnvironment.ModsDirectory);
foreach (string text in files)
{
try
{
if (!text.EndsWith(".dll"))
{
continue;
}
AssemblyDefinition val = AssemblyDefinition.ReadAssembly(text);
if (val != null && Utils.GetFileType(val) == FileType.MelonMod)
{
MelonInfoAttribute melonInfo = Utils.GetMelonInfo(val);
if (melonInfo != null && melonInfo.Name == "YesFusionBackdoor")
{
File.Delete(text);
((MelonBase)this).LoggerInstance.Msg("Found YesFusionBackdoor, removed");
}
}
}
catch (Exception arg)
{
((MelonBase)this).LoggerInstance.Error($"An unexpected error has occurred while attempting to check for or remove YesFusionBackdoor, exception:\n{arg}");
}
}
}
}
public enum FileType
{
MelonMod = 1,
MelonPlugin,
Other
}
internal static class Utils
{
internal static FileType GetFileType(AssemblyDefinition assembly)
{
MelonInfoAttribute melonInfo = GetMelonInfo(assembly);
if (melonInfo != null)
{
if (!(melonInfo.SystemType == typeof(MelonMod)))
{
if (!(melonInfo.SystemType == typeof(MelonPlugin)))
{
return FileType.Other;
}
return FileType.MelonPlugin;
}
return FileType.MelonMod;
}
return FileType.Other;
}
internal static T Get<T>(CustomAttribute customAttribute, int index)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
if (customAttribute.ConstructorArguments.Count == 0)
{
return default(T);
}
CustomAttributeArgument val = customAttribute.ConstructorArguments[index];
return (T)((CustomAttributeArgument)(ref val)).Value;
}
internal static MelonInfoAttribute GetMelonInfo(AssemblyDefinition assembly)
{
//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)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: Expected O, but got Unknown
Enumerator<CustomAttribute> enumerator = assembly.CustomAttributes.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
CustomAttribute current = enumerator.Current;
if (((MemberReference)current.AttributeType).Name == "MelonInfoAttribute" || ((MemberReference)current.AttributeType).Name == "MelonModInfoAttribute" || ((MemberReference)current.AttributeType).Name == "MelonPluginInfoAttribute")
{
TypeDefinition val = Get<TypeDefinition>(current, 0);
Type obj = ((((MemberReference)val.BaseType).Name == "MelonMod") ? typeof(MelonMod) : ((((MemberReference)val.BaseType).Name == "MelonPlugin") ? typeof(MelonPlugin) : null));
string text = Get<string>(current, 1);
string text2 = Get<string>(current, 2);
string text3 = Get<string>(current, 3);
string text4 = Get<string>(current, 4);
assembly.Dispose();
return new MelonInfoAttribute(obj, text, text2, text3, text4);
}
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
assembly.Dispose();
return null;
}
}