This is the AMP version of this page.
If you want to load the real page instead, click this text.

Solved How to hook static bool(string)

Status
Not open for further replies.

Shawn_Ares

Platinian
Code:
    // RVA: 0x135F8F4 Offset: 0x135F8F4 VA: 0x135F8F4
    public static bool JoinRoom(string RoomName) { }

As you can see, I'd like to hook this func, the bool represents whether you successfully entered a room,I have tried but it doesn't work.

This is my code:
Code:
bool JoinRoom;
bool (*old_JoinRoom)(monoString * Name);
bool OnJoinRoom(monoString * Name ) {
    if (JoinRoom) {
        old_JoinRoom(String_CreateString(get_StringInstance,RoomName));
        JoinRoom = false;
        return 1;
    }
    return old_JoinRoom(Name);
}

Code:
MSHookFunction((void *) getAbsoluteAddress("libil2cpp.so", 0x135F8F4), (void *) &OnJoinRoom, (void **) &old_JoinRoom);

Plz come to help me with this :( !
 
Hello, I think the signature of your OnJoinRoom function does not match the signature of the JoinRoom function you are trying to hook. The JoinRoom function takes a string parameter, not a monoString* parameter.
Here is a revised version of your code:

Code:
cpp
#include <string> // Include necessary headers

bool JoinRoomSuccess; // Declare a flag to track successful room joining
bool (*old_JoinRoom)(std::string RoomName); // Define the function pointer

bool OnJoinRoom(std::string RoomName) {
    if (JoinRoomSuccess) {
        // Call the original JoinRoom function with the provided RoomName
        old_JoinRoom(RoomName);
        JoinRoomSuccess = false;
        return true; // Indicate successful room joining
    }
    // Call the original JoinRoom function with the provided RoomName
    return old_JoinRoom(RoomName);
}

// Hooking function
MSHookFunction((void *)getAbsoluteAddress("libil2cpp.so", 0x135F8F4), (void *)&OnJoinRoom, (void **)&old_JoinRoom);
In this revised version, the OnJoinRoom function takes a std::string parameter RoomName to match the signature of JoinRoom. This function then calls the original function old_JoinRoom with the provided RoomName. Remember to adjust any other parts of your code accordingly to ensure consistency and compatibility with the rest of your implementation.
 
Could you give me a few examples?


You have static methods like these. Static methods is already in a class, meaning you don't have to create an additional parameter by creating an "instance". You can call any static methods without those objects/instance. Static is shared across all INSTANCES. You can call it ANYWHERE from ANY CLASS by creating the function pointer for it. set_timeScale is from the class Time. You can call that in any classes like Player, Weapons, ETC because it's "static".
 
You cannot use std::string, but only able to convert the std::string into using Il2cpp's string method. Unity uses it's own implementation for strings with .NET Framework. std::string differents from C++. You can either use std::string to and convert it for C-Style or just use monoString to make it easier.
 
i have function:
// RVA: 0x527F868 Offset: 0x527F868 VA: 0x527F868
public bool ImmuneDamage(ref HurtDataInfo hurt) { }
and struct HurtDataInfo like this:

public struct HurtDataInfo // TypeDefIndex: 13245
{
// Fields
public PoolObjHandle<LActorRoot> atker; // 0x0
public PoolObjHandle<LActorRoot> orignalAtker; // 0x10
public PoolObjHandle<LActorRoot> target; // 0x20
public PoolObjHandle<LActorRoot> triggerActor; // 0x30
public string atkerName; // 0x40
public HurtAttackerInfo attackInfo; // 0x48
public SkillSlotType atkSlot; // 0x9C
public HurtTypeDef hurtType; // 0xA0
public ExtraHurtTypeDef extraHurtType; // 0xA4
public int hurtValue; // 0xA8
.......................
// RVA: 0x31B8560 Offset: 0x31B8560 VA: 0x31B8560
public void Init() { }

}
. I don't know how to take string atkerName, Could you help me?
 
Thread will be set to "solved" and closed.
When you're not happy with that just send me a message and i will re-open the thread for you.

Thanks.
 
Status
Not open for further replies.