using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("SlotMachineFix")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("SlotMachineFix")] [assembly: AssemblyTitle("SlotMachineFix")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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; } } } [BepInPlugin("avi.slotmachinefix", "SlotMachine RenderTexture Fix", "1.0.0")] public class SlotMachineFix : BaseUnityPlugin { internal static ManualLogSource L; private void Awake() { L = ((BaseUnityPlugin)this).Logger; Harmony.CreateAndPatchAll(typeof(Patch), (string)null); L.LogInfo((object)"SlotMachineFix loaded"); } } internal static class Patch { [HarmonyPostfix] [HarmonyPatch(typeof(GameInfo), "Awake")] private static void Postfix(GameInfo __instance) { try { FieldInfo fieldInfo = AccessTools.Field(typeof(GameInfo), "_slotMachineTexture"); if (fieldInfo == null) { SlotMachineFix.L.LogWarning((object)"field _slotMachineTexture not found"); return; } object? value = fieldInfo.GetValue(__instance); RenderTexture val = (RenderTexture)((value is RenderTexture) ? value : null); if ((Object)(object)val == (Object)null) { SlotMachineFix.L.LogWarning((object)"slot RT null"); return; } int maxTextureSize = SystemInfo.maxTextureSize; if (((Texture)val).width <= maxTextureSize && ((Texture)val).height <= maxTextureSize) { SlotMachineFix.L.LogInfo((object)$"slot RT {((Texture)val).width}x{((Texture)val).height} ok (max {maxTextureSize})"); return; } int width = ((Texture)val).width; int height = ((Texture)val).height; float num = Mathf.Min((float)maxTextureSize / (float)width, (float)maxTextureSize / (float)height); int num2 = Mathf.Max(1, Mathf.RoundToInt((float)width * num)); int num3 = Mathf.Max(1, Mathf.RoundToInt((float)height * num)); if (val.IsCreated()) { val.Release(); } ((Texture)val).width = num2; ((Texture)val).height = num3; bool flag = val.Create(); SlotMachineFix.L.LogWarning((object)$"Clamped slot RT {width}x{height} -> {num2}x{num3} (max {maxTextureSize}) Create={flag}"); string[] array = new string[2] { "_inventoryTexture", "_journalTexture" }; foreach (string text in array) { object? obj = AccessTools.Field(typeof(GameInfo), text)?.GetValue(__instance); RenderTexture val2 = (RenderTexture)((obj is RenderTexture) ? obj : null); if ((Object)(object)val2 != (Object)null) { SlotMachineFix.L.LogInfo((object)$"{text} {((Texture)val2).width}x{((Texture)val2).height} created={val2.IsCreated()}"); } } } catch (Exception ex) { SlotMachineFix.L.LogError((object)ex); } } }