2022-02-21 01:45:46 +11:00
|
|
|
|
using HarmonyLib;
|
|
|
|
|
using System;
|
2022-02-19 17:50:10 +11:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityExplorer.CacheObject;
|
|
|
|
|
|
|
|
|
|
namespace UnityExplorer.Runtime
|
|
|
|
|
{
|
2022-02-21 01:45:46 +11:00
|
|
|
|
internal static class UnityCrashPrevention
|
2022-02-19 17:50:10 +11:00
|
|
|
|
{
|
2022-02-21 01:45:46 +11:00
|
|
|
|
internal static void Init()
|
2022-02-19 17:50:10 +11:00
|
|
|
|
{
|
2022-02-21 01:45:46 +11:00
|
|
|
|
try
|
2022-02-19 17:50:10 +11:00
|
|
|
|
{
|
2022-02-21 01:45:46 +11:00
|
|
|
|
ExplorerCore.Harmony.PatchAll(typeof(UnityCrashPrevention));
|
|
|
|
|
ExplorerCore.Log("Initialized UnityCrashPrevention.");
|
2022-02-19 17:50:10 +11:00
|
|
|
|
}
|
2022-02-21 01:45:46 +11:00
|
|
|
|
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,
|
2022-02-24 19:26:01 +11:00
|
|
|
|
// the game will Crash (I think from Unity trying to read from null ptr).
|
2022-02-21 01:45:46 +11:00
|
|
|
|
[HarmonyPatch(typeof(Canvas), "renderingDisplaySize", MethodType.Getter)]
|
|
|
|
|
[HarmonyPrefix]
|
2022-02-24 19:26:01 +11:00
|
|
|
|
internal static void Prefix_Canvas_renderingDisplaySize(Canvas __instance)
|
2022-02-21 01:45:46 +11:00
|
|
|
|
{
|
|
|
|
|
if (__instance.renderMode == RenderMode.WorldSpace && !__instance.worldCamera)
|
|
|
|
|
throw new InvalidOperationException(
|
|
|
|
|
"Canvas is set to RenderMode.WorldSpace but not worldCamera is set, cannot get renderingDisplaySize.");
|
2022-02-19 17:50:10 +11:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|