using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using MelonLoader;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(BuildLimitMod), "Increase Build Limit", "1.1.0", "Grace", null)]
[assembly: MelonGame(null, null)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("BuildLimitMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BuildLimitMod")]
[assembly: AssemblyTitle("BuildLimitMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
public class BuildLimitMod : MelonMod
{
private bool _limitIncreased = false;
public override void OnInitializeMelon()
{
((MelonBase)this).LoggerInstance.Msg("Grace's Mod loaded!");
}
public override void OnUpdate()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
Scene activeScene = SceneManager.GetActiveScene();
if (((Scene)(ref activeScene)).name != "Main Mountain Scene" || _limitIncreased)
{
return;
}
try
{
Type type = FindTypeByShortName("LobbySettingsManager");
if (type == null)
{
return;
}
MethodInfo method = type.GetMethod("get_Instance", BindingFlags.Static | BindingFlags.Public);
if (method == null)
{
return;
}
object obj = method.Invoke(null, null);
if (obj == null)
{
return;
}
PropertyInfo property = type.GetProperty("IsServerStarted", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
bool flag = false;
if (property != null)
{
flag = (bool)property.GetValue(obj);
}
if (!flag)
{
return;
}
MethodInfo method2 = type.GetMethod("Server_UpdateMaxBuildableItems", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (method2 == null)
{
((MelonBase)this).LoggerInstance.Warning("Could not find Server_UpdateMaxBuildableItems");
return;
}
method2.Invoke(obj, new object[1] { 1000 });
MethodInfo method3 = type.GetMethod("GetLobbySettings", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (method3 != null)
{
object obj2 = method3.Invoke(obj, null);
if (obj2 != null)
{
Type type2 = obj2.GetType();
FieldInfo field = type2.GetField("maxBuildableItems", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (field != null)
{
field.SetValue(obj2, 1000);
}
else
{
PropertyInfo property2 = type2.GetProperty("maxBuildableItems", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (property2 != null && property2.CanWrite)
{
property2.SetValue(obj2, 1000);
}
}
}
}
_limitIncreased = true;
((MelonBase)this).LoggerInstance.Msg("Build limit increased to 1000!");
}
catch (Exception value)
{
((MelonBase)this).LoggerInstance.Error($"Failed to increase build limit: {value}");
}
}
private static Type FindTypeByShortName(string shortName)
{
try
{
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
Type[] types;
try
{
types = assembly.GetTypes();
}
catch
{
continue;
}
Type[] array = types;
foreach (Type type in array)
{
if (type != null && type.Name == shortName)
{
return type;
}
}
}
}
catch
{
}
return null;
}
}