using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Reptile;
using TMPro;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("PhotoStorage")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PhotoStorage")]
[assembly: AssemblyTitle("PhotoStorage")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace PhotoStorage
{
[BepInPlugin("com.LazyDuchess.BRC.PhotoStorage", "PhotoStorage", "1.1.1")]
internal class PhotoStoragePlugin : BaseUnityPlugin
{
private static ConfigEntry<int> _maxPhotos;
private static ConfigEntry<bool> _disableCloud;
private const string GUID = "com.LazyDuchess.BRC.PhotoStorage";
private const string Name = "PhotoStorage";
private const string Version = "1.1.1";
public static bool DisableCloud => false;
public static int MaxPhotos => _maxPhotos.Value;
private void Awake()
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
try
{
Configure();
new Harmony("com.LazyDuchess.BRC.PhotoStorage").PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin PhotoStorage 1.1.1 is loaded!");
}
catch (Exception arg)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("Plugin {0} {1} failed to load! {2}", "PhotoStorage", "1.1.1", arg));
}
}
private void Configure()
{
_maxPhotos = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MaxPhotos", 1000, "Maximum amount of photos.");
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "PhotoStorage";
public const string PLUGIN_NAME = "PhotoStorage";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace PhotoStorage.Patches
{
[HarmonyPatch(typeof(AFileTransaction))]
internal static class AFileTransactionPatch
{
[HarmonyPrefix]
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
private static bool IsLocal_Prefix(ref bool __result)
{
if (PhotoStoragePlugin.DisableCloud)
{
__result = true;
return false;
}
return true;
}
}
[HarmonyPatch(typeof(PhotosAlbumMenu))]
internal static class PhotosAlbumMenuPatch
{
[HarmonyPrefix]
[HarmonyPatch("RefreshTotalPhotoCountDisplayText")]
private static bool RefreshTotalPhotoCountDisplayText_Prefix(PhotosAlbumMenu __instance, int updatedPhotoCount)
{
((TMP_Text)__instance.photoCountDisplayText).text = $"{updatedPhotoCount}/{PhotoStoragePlugin.MaxPhotos}";
return false;
}
}
[HarmonyPatch(typeof(PhotosManager))]
internal static class PhotosManagerPatch
{
private static MethodInfo MaxPhotosGet = AccessTools.PropertyGetter(typeof(PhotoStoragePlugin), "MaxPhotos");
[HarmonyPrefix]
[HarmonyPatch("IsPhotoStorageFull")]
private static bool IsPhotoStorageFull_Prefix(ref bool __result, PhotosManager __instance)
{
__result = __instance.availablePhotosCount >= PhotoStoragePlugin.MaxPhotos;
return false;
}
[HarmonyTranspiler]
[HarmonyPatch("SavePhoto")]
private static IEnumerable<CodeInstruction> SavePhoto_Transpiler(IEnumerable<CodeInstruction> instructions)
{
foreach (CodeInstruction instruction in instructions)
{
if (CodeInstructionExtensions.LoadsConstant(instruction, 50L))
{
yield return new CodeInstruction(OpCodes.Call, (object)MaxPhotosGet);
}
else
{
yield return instruction;
}
}
}
}
}