mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 06:08:16 +08:00
Use a patch instead of manual check on every property
This commit is contained in:
parent
a90292f47f
commit
64193ff1b0
@ -30,8 +30,6 @@ namespace UnityExplorer.CacheObject
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
UnityCrashPrevention.CheckPropertyInfoEvaluation(this);
|
|
||||||
|
|
||||||
object ret;
|
object ret;
|
||||||
if (HasArguments)
|
if (HasArguments)
|
||||||
ret = PropertyInfo.GetValue(DeclaringInstance, this.Evaluator.TryParseArguments());
|
ret = PropertyInfo.GetValue(DeclaringInstance, this.Evaluator.TryParseArguments());
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using HarmonyLib;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -7,17 +8,31 @@ using UnityExplorer.CacheObject;
|
|||||||
|
|
||||||
namespace UnityExplorer.Runtime
|
namespace UnityExplorer.Runtime
|
||||||
{
|
{
|
||||||
public static class UnityCrashPrevention
|
internal static class UnityCrashPrevention
|
||||||
{
|
{
|
||||||
public static void CheckPropertyInfoEvaluation(CacheProperty cacheProp)
|
internal static void Init()
|
||||||
{
|
{
|
||||||
if (cacheProp.PropertyInfo.Name == "renderingDisplaySize"
|
try
|
||||||
&& cacheProp.Owner.Target is Canvas canvas
|
|
||||||
&& canvas.renderMode == RenderMode.WorldSpace
|
|
||||||
&& !canvas.worldCamera)
|
|
||||||
{
|
{
|
||||||
throw new Exception("Canvas is set to RenderMode.WorldSpace but has no worldCamera, cannot get value.");
|
ExplorerCore.Harmony.PatchAll(typeof(UnityCrashPrevention));
|
||||||
}
|
ExplorerCore.Log("Initialized UnityCrashPrevention.");
|
||||||
|
}
|
||||||
|
catch //(Exception ex)
|
||||||
|
{
|
||||||
|
//ExplorerCore.Log($"Exception setting up Canvas crash prevention patch: {ex}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// In Unity 2020 they introduced "Canvas.renderingDisplaySize".
|
||||||
|
// If you try to get the value on a Canvas which has a renderMode value of WorldSpace and no worldCamera set,
|
||||||
|
// the game will Crash when Unity tries to read from a null ptr (I think).
|
||||||
|
[HarmonyPatch(typeof(Canvas), "renderingDisplaySize", MethodType.Getter)]
|
||||||
|
[HarmonyPrefix]
|
||||||
|
internal static void Prefix(Canvas __instance)
|
||||||
|
{
|
||||||
|
if (__instance.renderMode == RenderMode.WorldSpace && !__instance.worldCamera)
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
"Canvas is set to RenderMode.WorldSpace but not worldCamera is set, cannot get renderingDisplaySize.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user