Closed hieupva closed 2 days ago
How did you come out with invokeConstructor
? Il2Cpp.Object
and Il2Cpp.Class
have no such method
Apologies, it seems the code/method above I sent was copied incorrectly and incomplete. So I edit the post. The code above was copied from other method. I only changed the name and pasted it again. It work with below method.
I thought the methods were similar, so the approach would be the same. But that is not the case.
// CommonLibs, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// FileModule.LMN.FileUtil
using Il2CppDummyDll;
[Token(Token = "0x601A4CF")]
[Address(RVA = "0x2B52F64", Offset = "0x2B52F64", VA = "0xC0A3CF64")]
[Attribute(Name = "IDTagAttribute", RVA = "0xC8BCA0", Offset = "0xC8BCA0")]
public static byte[] ReadAllBytesByPath(PathType inPathType, string inPath, bool inUseHashIfShould, bool tryGetFromStreammingAssetsPath)
{
return null;
}
Code
const FileUtil = Il2Cpp.domain.assembly("CommonLibs").image.class("FileModule.LMN.FileUtil");
const ReadAllBytesByPathB = FileUtil.method("ReadAllBytesByPath", 4);
ReadAllBytesByPathB.implementation = function(pathType, inPath, useHash, tryStream) {
const result = ReadAllBytesByPathB.invoke(pathType, inPath, useHash, tryStream);
console.log(`[ReadAllBytesByPathB] Type: ${pathType}, Path: ${inPath}\nuseHash: ${useHash} `);
return result;
};
FileUtil::ReadAllBytesByPath
is static, whereas UnityWebRequest::.ctor
is not. Whithin your implementation, this
is a Il2Cpp.Class
if the method is static, or Il2Cpp.Object
if it isn't.
Here you are invoking an instance method, but you are not providing the instance:
const result = UnityWebRequestB.invoke(url, method, downloadHandler, uploadHandler);
So, this is how you should do it:
const result = this.method(".ctor", 4).invoke(url, method, downloadHandler, uploadHandler);
And it works for static methods as well:
const result = this.method("ReadAllBytesByPath", 4).invoke(pathType, inPath, useHash, tryStream);
Ah, I understand. I didn’t notice that UnityWebRequest doesn’t have a static method. And it really works. Thank you for taking the time to help me.
I want to hook this method, but only for url and method. It keeps throwing an error and duplicate. How can I fix it?
My Hooking Code:
Error Message i got after loading script