knah / Il2CppAssemblyUnhollower

A tool to generate Managed->IL2CPP proxy assemblies
GNU Lesser General Public License v3.0
503 stars 87 forks source link

Random garbage in IL2CPPStructArray<T> #86

Open Kein opened 2 years ago

Kein commented 2 years ago

For the first time (first scene load) everything works fine. When I change the scene, thing become weird, myInputs on my custom Component now has some weird garbage data, like Count/Length being a few million or throwing nullref when trying to request any value by index. The odd part is that this component isnt even transitioned through scene as DDOL or HideandDontSave, it is literally recreated as PlayerCharacter is being remade. WasCollected returns false for the given IL2cppStructArray (sine it is referenced on il2cpp side) Let me know if more information is needed.

Kein commented 2 years ago

Code:

ClassInjector.RegisterTypeInIl2Cpp<MyUtility>();
//------
public class MyUtility : BaseUtility // class from the unhollowed assembly, Monobehaviour
{
    public MyUtility(System.IntPtr ptr) : base(ptr)
    {
        myInputs = new INPUT[] { //whatever }; // implicit conversion to UnhollowerBaseLib.Il2CppStructArray<T>
    }

    public override void ActionEffect()
    {
        UnityEngine.Debug.Log("DONE");
    }

[HarmonyPatch(typeof(PlayerCharacter), "creature_Awake")]
static class PatchPlayerCharacterInit
{
    static void Postfix(PlayerCharacter __instance)
    {
        __instance.gameObject.AddComponent<MyUtility>();
        //Automatically gets added to IL2cppReferenceArray<BaseUtility>
        ///on character instance by original code
    }
}