Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remember injected types and reuse in GetIl2CppTypeFullName #103

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sir0x1
Copy link

@sir0x1 sir0x1 commented Aug 29, 2023

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

dlbuhtig4096 pushed a commit to dlbuhtig4096/Il2CppInterop that referenced this pull request Sep 28, 2023
@js6pak
Copy link
Member

js6pak commented Feb 25, 2024

What was the use case for this change?

@sir0x1
Copy link
Author

sir0x1 commented Feb 26, 2024

I forgott to fill the description sorry. Had a small discussion about this in the discord:
injecting a class derived from an existing generic class, with a virtual method using the generic type as parameter currently doesn't work because assembly.Name.Name is set to "InjectedMonoTypes" by ClassInjector. Is there an easy way to get the System.Type of an injected Type?
Il2CppClassPointerStore is only viable for System.Type -> ClassPtr at the moment.

The discrod link for reference:
https://discord.com/channels/623153565053222947/985596870229385256/1146049966444384336

@sir0x1 sir0x1 force-pushed the ClassInjectorSupportGenericBaseClassMethods branch from 36d079d to ad9b16f Compare February 26, 2024 20:17
@sir0x1
Copy link
Author

sir0x1 commented Feb 26, 2024

Updated the description

@ds5678
Copy link
Collaborator

ds5678 commented Dec 13, 2024

@sir0x1 can you rebase this pull request and verify that it still has your intended behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants