ByNameModding / BNM-Android

Modding il2cpp games by classes, methods, fields names on Android.
MIT License
210 stars 41 forks source link

There was a crash when adding a custom class component to a game object #45

Closed solomode0001 closed 3 months ago

solomode0001 commented 3 months ago

Logs:

AddComponent asking for "" which is not a Unity engine type.
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Version '2021.3.8f1 (b30333d56e81)', Build type 'Release', Scripting Backend 'il2cpp', CPU 'armeabi-v7a'
Build fingerprint: 'Asus/Asus/ASUS_I003DD:9/mv-dev103041042:user/release-keys'
Revision: '0'
ABI: 'arm'
Timestamp: 2024-07-05 18:44:22+0800
pid: 28032, tid: 28189, name: UnityMain  >>> com.AkhirPekan.GamingCafeLife <<<
uid: 10039
signal 4 (SIGILL), code 0 (SI_USER), fault addr --------
    r0  00000000  r1  00000000  r2  00000000  r3  e0000000
    r4  0bb011a0  r5  0bb011ac  r6  ba3a19a0  r7  00000000
    r8  0ba4e340  r9  0000000a  r10 0ba4ede1  r11 c557f7e8
    ip  cbcf2a00  sp  c557f790  lr  043bca11  pc  0ba6aacc

backtrace:
      #00 pc 0005aacc  /data/app/com.AkhirPekan.GamingCafeLife-E0sDAN8yCDxt3BT_JvQJEQ==/lib/arm/libMOD.so (BuildId: 8ab0fc47b63b326079edb66c7a5895a93147e12a)
      #01 pc 0005b248  /data/app/com.AkhirPekan.GamingCafeLife-E0sDAN8yCDxt3BT_JvQJEQ==/lib/arm/libMOD.so (BuildId: 8ab0fc47b63b326079edb66c7a5895a93147e12a)
      #02 pc 00068da4  /data/app/com.AkhirPekan.GamingCafeLife-E0sDAN8yCDxt3BT_JvQJEQ==/lib/arm/libMOD.so (BuildId: 8ab0fc47b63b326079edb66c7a5895a93147e12a)
      #03 pc 0007e65e  /system/lib/arm/nb/libtcb.so
Info/GameAnalytics: Event queue: 1 events sent.
other thread is trapped; signum = 4
FATAL EXCEPTION: UnityMain
Process: com.AkhirPekan.GamingCafeLife, PID: 28032
java.lang.Error: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Version '2021.3.8f1 (b30333d56e81)', Build type 'Release', Scripting Backend 'il2cpp', CPU 'armeabi-v7a'
Build fingerprint: 'Asus/Asus/ASUS_I003DD:9/mv-dev103041042:user/release-keys'
Revision: '0'
ABI: 'arm'
Timestamp: 2024-07-05 18:44:22+0800
pid: 28032, tid: 28189, name: UnityMain  >>> com.AkhirPekan.GamingCafeLife <<<
uid: 10039
signal 4 (SIGILL), code 0 (SI_USER), fault addr --------
    r0  00000000  r1  00000000  r2  00000000  r3  e0000000
    r4  0bb011a0  r5  0bb011ac  r6  ba3a19a0  r7  00000000
    r8  0ba4e340  r9  0000000a  r10 0ba4ede1  r11 c557f7e8
    ip  cbcf2a00  sp  c557f790  lr  043bca11  pc  0ba6aacc

backtrace:
      #00 pc 0005aacc  /data/app/com.AkhirPekan.GamingCafeLife-E0sDAN8yCDxt3BT_JvQJEQ==/lib/arm/libMOD.so (BuildId: 8ab0fc47b63b326079edb66c7a5895a93147e12a)
      #01 pc 0005b248  /data/app/com.AkhirPekan.GamingCafeLife-E0sDAN8yCDxt3BT_JvQJEQ==/lib/arm/libMOD.so (BuildId: 8ab0fc47b63b326079edb66c7a5895a93147e12a)
      #02 pc 00068da4  /data/app/com.AkhirPekan.GamingCafeLife-E0sDAN8yCDxt3BT_JvQJEQ==/lib/arm/libMOD.so (BuildId: 8ab0fc47b63b326079edb66c7a5895a93147e12a)
      #03 pc 0007e65e  /system/lib/arm/nb/libtcb.so

    at libMOD.0x5aacc(Native Method)
    at libMOD.0x5b248(Native Method)
    at libMOD.0x68da4(Native Method)
    at libtcb.0x7e65e(Native Method)
Error just lunched 
Try saving log
Done

Code:

struct MyClass : public BNM::UnityEngine::MonoBehaviour {
    BNM_CustomClass(MyClass, BNM::CompileTimeClassBuilder("","MyClass").Build(), BNM::CompileTimeClassBuilder("UnityEngine","MonoBehaviour").Build(), {});

    void Update() {
        LOGI("Call Update");
    }

    BNM_CustomMethod(Update, false, BNM::GetType<void>(), "Update");
};

BNM::Method<void*> addComponent;
BNM::Method<void> dontDestroyOnLoad;

void *AttachComponent() {
    auto gameObject = BNM::Class("UnityEngine", "GameObject").CreateNewObjectParameters();
    addComponent[gameObject](MyClass::BNMCustomClass.type);
    dontDestroyOnLoad(gameObject);
    return gameObject;
}

void OnLoad() {
    addComponent = BNM::Class("UnityEngine", "GameObject").GetMethod("AddComponent", {"componentType"});
    dontDestroyOnLoad = BNM::Class("UnityEngine", "Object").GetMethod("DontDestroyOnLoad");

    auto r = AttachComponent();
}
solomode0001 commented 3 months ago

Fixed...

yunli97 commented 2 months ago

I'm also experiencing this problem, how did you solve it?

yunli97 commented 2 months ago

imageSo that's the problem here. Here's the modification.

tomasky commented 2 months ago

this Code is not working now no errors report and game exit ! this line cause:

    auto gameObject = BNM::Class("UnityEngine", "GameObject").CreateNewObjectParameters();

:

struct MyClass : public BNM::UnityEngine::MonoBehaviour {
    BNM_CustomClass(MyClass, BNM::CompileTimeClassBuilder("","MyClass").Build(), BNM::CompileTimeClassBuilder("UnityEngine","MonoBehaviour").Build(), {});

    void Update() {
        LOGI("Call Update");
    }

    BNM_CustomMethod(Update, false, BNM::GetType<void>(), "Update");
};

BNM::Method<void*> addComponent;
BNM::Method<void> dontDestroyOnLoad;

void *AttachComponent() {
    auto gameObject = BNM::Class("UnityEngine", "GameObject").CreateNewObjectParameters();
    addComponent[gameObject](MyClass::BNMCustomClass.type);
    dontDestroyOnLoad(gameObject);
    return gameObject;
}

void OnLoad() {
    addComponent = BNM::Class("UnityEngine", "GameObject").GetMethod("AddComponent", {"componentType"});
    dontDestroyOnLoad = BNM::Class("UnityEngine", "Object").GetMethod("DontDestroyOnLoad");

    auto r = AttachComponent();
}
tomasky commented 2 months ago

@solomode0001 @yunli97 can you test the BNM lastest version with the example? ,