using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Igor_Does_Nothing")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PublicSaves")]
[assembly: AssemblyTitle("PublicSaves")]
[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;
}
}
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}
namespace REPO.PublicSaves
{
[BepInPlugin("com.yourname.repo.publicsaves", "R.E.P.O Public Saves", "1.0.1")]
public class PublicSavesPlugin : BaseUnityPlugin
{
private void Awake()
{
Harmony.CreateAndPatchAll(typeof(PublicSavesPlugin), (string)null);
((BaseUnityPlugin)this).Logger.LogInfo((object)"R.E.P.O Public Saves loaded");
}
[HarmonyPrefix]
[HarmonyPatch(typeof(SemiFunc), "SaveFileSave")]
private static bool SemiFunc_SaveFileSave_Prefix()
{
if ((Object)(object)StatsManager.instance != (Object)null)
{
StatsManager.instance.SaveFileSave();
}
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(SemiFunc), "SaveFileDelete")]
private static bool SemiFunc_SaveFileDelete_Prefix(string saveFileName)
{
if (IsPublicLobbySafe())
{
return false;
}
return true;
}
private static bool IsPublicLobbySafe()
{
if (TryGetSingletonBool("GameManager", "instance", out var value, "connectRandom", "isConnectRandom", "quickJoin", "openLobby"))
{
return value;
}
if (TryGetStaticOrSingletonBool("NetworkConnect", out var value2, "connectRandom", "isConnectRandom"))
{
return value2;
}
if (TryGetStaticOrSingletonBool("NetworkController", out var value3, "connectRandom", "isConnectRandom"))
{
return value3;
}
return false;
}
private static bool TryGetSingletonBool(string typeName, string instanceMember, out bool value, params string[] candidates)
{
value = false;
Type type = AccessTools.TypeByName(typeName);
if (type == null)
{
return false;
}
object obj = null;
FieldInfo fieldInfo = AccessTools.Field(type, instanceMember);
if (fieldInfo != null)
{
obj = fieldInfo.GetValue(null);
}
if (obj == null)
{
PropertyInfo propertyInfo = AccessTools.Property(type, instanceMember);
if (propertyInfo != null)
{
obj = propertyInfo.GetValue(null, null);
}
}
if (obj == null)
{
return false;
}
foreach (string name in candidates)
{
if (TryGetBoolMember(obj, name, out value))
{
return true;
}
}
return false;
}
private static bool TryGetStaticOrSingletonBool(string typeName, out bool value, params string[] candidates)
{
value = false;
Type type = AccessTools.TypeByName(typeName);
if (type == null)
{
return false;
}
foreach (string name in candidates)
{
if (TryGetStaticBoolMember(type, name, out value))
{
return true;
}
}
string[] array = new string[3] { "Instance", "instance", "s_instance" };
foreach (string instanceMember in array)
{
if (TryGetSingletonBool(typeName, instanceMember, out value, candidates))
{
return true;
}
}
return false;
}
private static bool TryGetBoolMember(object obj, string name, out bool value)
{
value = false;
Type type = obj.GetType();
FieldInfo fieldInfo = AccessTools.Field(type, name);
if (fieldInfo != null && fieldInfo.FieldType == typeof(bool))
{
value = (bool)fieldInfo.GetValue(obj);
return true;
}
PropertyInfo propertyInfo = AccessTools.Property(type, name);
if (propertyInfo != null && propertyInfo.PropertyType == typeof(bool))
{
value = (bool)propertyInfo.GetValue(obj, null);
return true;
}
return false;
}
private static bool TryGetStaticBoolMember(Type t, string name, out bool value)
{
value = false;
FieldInfo fieldInfo = AccessTools.Field(t, name);
if (fieldInfo != null && fieldInfo.IsStatic && fieldInfo.FieldType == typeof(bool))
{
value = (bool)fieldInfo.GetValue(null);
return true;
}
PropertyInfo propertyInfo = AccessTools.Property(t, name);
if (propertyInfo != null && propertyInfo.GetMethod != null && propertyInfo.GetMethod.IsStatic && propertyInfo.PropertyType == typeof(bool))
{
value = (bool)propertyInfo.GetValue(null, null);
return true;
}
return false;
}
}
}