fix crashes, temp disable reflection caching, possibly reduce optimization in some areas, likely break 1.5

This commit is contained in:
localavaster
2026-04-14 00:12:50 -06:00
parent 9821c68999
commit 35187cf2d2
20 changed files with 275 additions and 107 deletions
@@ -0,0 +1,50 @@
// Copyright (c) 2023 bradson
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
namespace PerformanceFish.Rendering;
public sealed class TextureAtlasPatches : ClassWithFishPatches
{
public sealed class StaticTextureAtlas_ApplyTextureCompression : FishPatch
{
public override string? Description { get; }
= "Routes texture atlas compression through the GPU path when compute shaders are available, "
+ "regardless of the VRAM threshold check in UnityData.ComputeShadersSupported. Prevents native "
+ "crashes in debug Mono builds.";
public override MethodBase TargetMethodInfo
=> AccessTools.DeclaredMethod(typeof(StaticTextureAtlas), "ApplyTextureCompression");
public static bool Prefix(StaticTextureAtlas __instance, bool noGpuCompressionSupport)
{
if (!noGpuCompressionSupport || !SystemInfo.supportsComputeShaders)
return true;
if (__instance.ColorTexture != null)
{
var name = __instance.ColorTexture.name;
var compressed = StaticTextureAtlas.FastCompressDXT(__instance.ColorTexture, deleteOriginal: true);
compressed.name = name;
_colorTextureField.SetValue(__instance, compressed);
}
if (__instance.MaskTexture != null)
{
var name = __instance.MaskTexture.name;
var compressed = StaticTextureAtlas.FastCompressDXT(__instance.MaskTexture, deleteOriginal: true);
compressed.name = name;
_maskTextureField.SetValue(__instance, compressed);
}
return false;
}
private static readonly FieldInfo _colorTextureField
= AccessTools.DeclaredField(typeof(StaticTextureAtlas), "colorTexture");
private static readonly FieldInfo _maskTextureField
= AccessTools.DeclaredField(typeof(StaticTextureAtlas), "maskTexture");
}
}
@@ -93,9 +93,9 @@ public sealed class TextureLoadingPatches : ClassWithFishPrepatches
var data = file.ReadAllBytes();
texture2D = new(2, 2, TextureFormat.Alpha8, true);
texture2D.LoadImage(data);
FixMipMapsIfNeeded(texture2D, data, file);
FixMipMapsIfNeeded(ref texture2D, data, file);
}
if (!isDds && Prefs.TextureCompression)
texture2D.Compress(true);
@@ -120,11 +120,11 @@ public sealed class TextureLoadingPatches : ClassWithFishPrepatches
var texture2D = new Texture2D(2, 2, TextureFormat.Alpha8, true);
texture2D.LoadImage(data);
FixMipMapsIfNeeded(texture2D, data, file);
FixMipMapsIfNeeded(ref texture2D, data, file);
return texture2D;
}
public static void FixMipMapsIfNeeded(Texture2D texture2D, byte[] data, VirtualFile file)
public static void FixMipMapsIfNeeded(ref Texture2D texture2D, byte[] data, VirtualFile file)
{
if (((texture2D.width & 3) == 0) & ((texture2D.height & 3) == 0))
return;