ByNameModding / BNM-Android

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

Overloaded Method #23

Closed ArifRios1st closed 7 months ago

ArifRios1st commented 8 months ago

how to hook method that have same name and params count but different type ?

// RVA: 0x8BD0E0 Offset: 0x8BD0E0 VA: 0x8BD0E0 Slot: 17 public void TargetMove(float speed, Transform targetTransform, float range, Action endCallBack) { }

// RVA: 0x8BD1E0 Offset: 0x8BD1E0 VA: 0x8BD1E0 public void TargetMove(float speed, Vector3 position, float range, Action endCallBack) { }

ArifRios1st commented 8 months ago

ah i don't know there is GetMethodByName by paramName and paramType sorry

ArifRios1st commented 8 months ago

how to hook something like this ? image i want to hook both can you give example, because it same params count and params name @BNM-Dev

BNM-Dev commented 8 months ago

I don't know all paths to classes, so you will need add them. But code should work. (At least for AddRate with float)

auto cls = LoadClass("", ""); // Class with AddRate methods
auto calcStep = LoadClass("", "SkillCalcTemplate").GetInnerClass("CalcStep");
auto floatType = BNM::GetType<float>();
auto funcCls = LoadClass("", "Func`1"); // Idk full path to Func class
auto  funcFloatCls = funcCls.GetGeneric({floatType}); // Func<float>

auto met1 = cls.GetMethodByName("AddRate", {calcStep, funcFloatCls}); // AddRate with Func<float>
auto met2 = cls.GetMethodByName("AddRate", {calcStep, floatType}); // AddRate with float
ArifRios1st commented 7 months ago

Thanks, work like charm !!

dvgmdvgm commented 7 months ago

@BNM-Dev @ArifRios1st hello Looks strange for me. I have two methods which is completely same except the args type:

Screen-074

Trying to hook second one (byte[]) by this snippet: auto bytesType = GetType<byte[]>(); auto met_ctor = MyClass.GetMethodByName(".ctor", {bytesType});

Also trying GetType();

and get following log output: Method: [NameSpace]::[Classs].[.ctor], 1 - not found; using parameter types.

ArifRios1st commented 7 months ago

@BNM-Dev @ArifRios1st hello Looks strange for me. I have two methods which is completely same except the args type:

Screen-074

Trying to hook second one (byte[]) by this snippet: auto bytesType = GetType<byte[]>(); auto met_ctor = MyClass.GetMethodByName(".ctor", {bytesType});

Also trying GetType();

and get following log output: Method: [NameSpace]::[Classs].[.ctor], 1 - not found; using parameter types.

i think it should be like auto arrayOfByte = BNM::GetType<uint8_t>(RuntimeTypeGetter::RuntimeModifier::Array); then auto met_ctor = MyClass.GetMethodByName(".ctor", {arrayOfByte});

dvgmdvgm commented 7 months ago

@BNM-Dev @ArifRios1st hello Looks strange for me. I have two methods which is completely same except the args type: Screen-074 Trying to hook second one (byte[]) by this snippet: auto bytesType = GetType<byte[]>(); auto met_ctor = MyClass.GetMethodByName(".ctor", {bytesType}); Also trying GetType(); and get following log output: Method: [NameSpace]::[Classs].[.ctor], 1 - not found; using parameter types.

i think it should be like auto arrayOfByte = BNM::GetType<uint8_t>(RuntimeTypeGetter::RuntimeModifier::Array); then auto met_ctor = MyClass.GetMethodByName(".ctor", {arrayOfByte});

working perfectly.