IllusionMods / IllusionFixes

A collection of fixes for common issues found in games by Illusion
GNU General Public License v3.0
157 stars 29 forks source link

HS2 Steam NullChecks incompatibility #45

Open Perdition-117 opened 1 year ago

Perdition-117 commented 1 year ago

Hi,

I don't know whether the Steam version of Honey Select 2 is supported, but I was finally narrow down some issues I was having to NullChecks.

The Steam assembly seems to have an overload method for Illusion.Game.Utils.Bundle.LoadSprite, causing the patching to fail.

[Error  : Unity Log] AmbiguousMatchException: Ambiguous match found.
Stack trace:
System.RuntimeType.GetMethodImpl (System.String name, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Reflection.CallingConventions callConv, System.Type[] types, System.Reflection.ParameterModifier[] modifiers) (at <7ba07f088431485bb722f3b3373e87ee>:0)
System.Type.GetMethod (System.String name, System.Reflection.BindingFlags bindingAttr) (at <7ba07f088431485bb722f3b3373e87ee>:0)
HarmonyLib.AccessTools.DeclaredMethod (System.Type type, System.String name, System.Type[] parameters, System.Type[] generics) (at <474744d65d8e460fa08cd5fd82b5d65f>:0)
HarmonyLib.PatchTools.GetOriginalMethod (HarmonyLib.HarmonyMethod attr) (at <474744d65d8e460fa08cd5fd82b5d65f>:0)
Rethrow as HarmonyException: Ambiguous match for HarmonyMethod[(class=Illusion.Game.Utils+Bundle, methodname=LoadSprite, type=Normal, args=undefined)]
HarmonyLib.PatchClassProcessor.ReportException (System.Exception exception, System.Reflection.MethodBase original) (at <474744d65d8e460fa08cd5fd82b5d65f>:0)
HarmonyLib.PatchClassProcessor.Patch () (at <474744d65d8e460fa08cd5fd82b5d65f>:0)
HarmonyLib.Harmony.PatchAll (System.Type type) (at <474744d65d8e460fa08cd5fd82b5d65f>:0)
HarmonyLib.Harmony.CreateAndPatchAll (System.Type type, System.String harmonyInstanceId) (at <474744d65d8e460fa08cd5fd82b5d65f>:0)
IllusionFixes.NullChecks.Awake () (at <fc88d89c074943af8de50ae23464af22>:0)
UnityEngine.GameObject:AddComponent(Type)
BepInEx.Bootstrap.Chainloader:Start()
UnityEngine.AddressableAssets.Addressables:InstantiateAsync(Object, Transform, Boolean, Boolean)
GameSetup.Setup:InitializeBeforeSceneLoad()

I was able to get it working, but I don't know whether it's possible to patch the new overload without breaking JP compatibility.

[HarmonyFinalizer, HarmonyPatch(typeof(Illusion.Game.Utils.Bundle), nameof(Illusion.Game.Utils.Bundle.LoadSprite), typeof(string), typeof(string), typeof(UnityEngine.UI.Image), typeof(bool), typeof(string), typeof(string), typeof(string))]
private static Exception LoadSpriteNullRefEater(Exception __exception, string assetBundleName, string assetName)
{
    if (__exception != null)
    {
        Logger.LogError($"Caught a crash when trying to load sprite {assetBundleName} > {assetName}! \n{__exception}");
    }

    return null;
}

[HarmonyFinalizer, HarmonyPatch(typeof(Illusion.Game.Utils.Bundle), nameof(Illusion.Game.Utils.Bundle.LoadSprite), typeof(string), typeof(string), typeof(string))]
private static Exception LoadSpriteNullRefEater2(Exception __exception, string assetBundleName, string assetName)
{
    if (__exception != null)
    {
        Logger.LogError($"Caught a crash when trying to load sprite {assetBundleName} > {assetName}! \n{__exception}");
    }

    return null;
}
ManlyMarco commented 1 year ago

HS2 Steam isn't really supported since the recommendation is to convert it to a JP release. If you can submit a PR that adds compatibility without affecting other games then I'll happily merge it though.