Il2CppInterop icon indicating copy to clipboard operation
Il2CppInterop copied to clipboard

Remember injected types and reuse in GetIl2CppTypeFullName

Open sir0x1 opened this issue 10 months ago • 3 comments

Injecting a class derived from an existing generic class with a virtual method using the generic type as parameter currently doesn't work.

I had to fix some void* handling for this sample to work as well.

Can be reprodused with this sample plugin:

using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Il2CppInterop.Runtime.Injection;
using System;
using UnityEngine.InputSystem;

namespace Test;

[BepInPlugin("Test", "Test", "0.0.1")]
public class Plugin : BasePlugin
{
    internal static new ManualLogSource Log;

    public override void Load()
    {
        Log = base.Log;

        ClassInjector.RegisterTypeInIl2Cpp<Haptic>();
        ClassInjector.RegisterTypeInIl2Cpp<HapticControl>();

        Log.LogInfo($"Plugin 'Test' is loaded!");
    }

    public class Haptic : Il2CppSystem.Object
    {
        public Haptic()
            : base(ClassInjector.DerivedConstructorPointer<Haptic>()) { }

        public Haptic(IntPtr pointer)
            : base(pointer) { }

    }

    public class HapticControl : InputControl<Haptic>
    {
        public override unsafe Haptic ReadUnprocessedValueFromState(void* statePtr) => new Haptic();
        public override unsafe Il2CppSystem.Object ReadValueFromBufferAsObject(void* buffer, int bufferSize) => null;
        public override unsafe void ReadValueFromStateIntoBuffer(void* statePtr, void* bufferPtr, int bufferSize) { }
        public override unsafe Il2CppSystem.Object ReadValueFromStateAsObject(void* statePtr) => null;
        public override unsafe void WriteValueFromBufferIntoState(void* bufferPtr, int bufferSize, void* statePtr) { }
        public override unsafe void WriteValueFromObjectIntoState(Il2CppSystem.Object value, void* statePtr) { }
        public override unsafe bool CompareValue(void* firstStatePtr, void* secondStatePtr) => false;
        public override unsafe void WriteValueIntoState(Haptic value, void* statePtr) { }
    }
}

Before: grafik

After: grafik

sir0x1 avatar Aug 29 '23 16:08 sir0x1