Help! Hooking VOID multiplier function

DeeNastyle

Platinian
Original poster
Jul 27, 2022
8
2
3
33
France
Hi guys,

I took my first steps at modding a few days ago but I can't manage to make my function work.
I'm using LGL Model Menu template 3.2 to mod a unity libil2cpp game on android.

I want to do a damage multiplier function with a slider.
Here the offset I've found with dnSpy:

1659130421668.png



On Main.cpp I've tried the following:


1659130627555.png


1659130539485.png


1659130680334.png


1659130744483.png


1659130795700.png



Any clue how to make the function work ?

Thanks guys,
 

Attachments

Last edited:
  • Like
Reactions: Kaorin333

hienngocloveyou

Solid & Active Platinian
May 16, 2021
62
7
8
38
VN
Maybe the game server side so can not hack

but wait the method has more parameters you must add-in full of parameters.
 

NullCoder

Inactive Approved Modder
Jun 8, 2020
110
901
93
21
None
C++:
if (instance && DamageMultiplier > 1) {
    hpDamage *= DamageMultiplier;
    shieldDamage *= DamageMultiplier;
}
It must be so, you haven't provided all the necessary arguments to the ApplyAttackDamage method yet.

In the switch construction, value has an integer type, which means that it would be more correct to specify the type not float (real) but int (integer), It's certainly not a bug, but still.
 
  • Like
Reactions: DeeNastyle

DeeNastyle

Platinian
Original poster
Jul 27, 2022
8
2
3
33
France
It's an online game yes but battle calculation are client-sided, there is a lot of working mod menu out there with damage multiplier & defence multiplier functions..just trying to make my own :)

I will try to change the switch construction, thank you guys.
 

alsya

Solid & Active Platinian
Oct 21, 2021
80
19
8
unknown
if( instance != NULL && SliderValue > 1){
myfunction(instance, SliderValue);
}
 

Arch01

2/3 Games Approved
Sep 1, 2020
35
7
8
27
Cilegon Banten Indonesia
C++:
if (instance && DamageMultiplier > 1) {
    hpDamage *= DamageMultiplier;
    shieldDamage *= DamageMultiplier;
}
It must be so, you haven't provided all the necessary arguments to the ApplyAttackDamage method yet.

In the switch construction, value has an integer type, which means that it would be more correct to specify the type not float (real) but int (integer), It's certainly not a bug, but still.
try this
C++:
float DamageMultiplier;

void (*old_ApplyAttackDamage)(void *instance,int hpDamage,int shieldDamage,bool isCrit,BattleUnitController attacker,BattleUnitController target,UnitMoveType moveType,DamageTypeEnum damageType,bool showUiMessaging,bool canCounterAttack,[Optional] BattleEffectDO sourceEffect,bool fromDestroyModule);
void ApplyAttackDamage(void *instance,int hpDamage,int shieldDamage,bool isCrit,BattleUnitController attacker,BattleUnitController target,UnitMoveType moveType,DamageTypeEnum damageType,bool showUiMessaging,bool canCounterAttack,[Optional] BattleEffectDO sourceEffect,bool fromDestroyModule){
     if (instance != NULL && DamageMultiplier > 1){
          return old_ApplyAttackDamage(instance,int hpDamage * DamageMultiplier ,int shieldDamage * DamageMultiplier,bool isCrit,BattleUnitController attacker,BattleUnitController target,UnitMoveType moveType,DamageTypeEnum damageType,bool showUiMessaging,bool canCounterAttack,[Optional] BattleEffectDO sourceEffect,bool fromDestroyModule);
     }
     return old_ApplyAttackDamage(instance,int hpDamage,int shieldDamage,bool isCrit,BattleUnitController attacker,BattleUnitController target,UnitMoveType moveType,DamageTypeEnum damageType,bool showUiMessaging,bool canCounterAttack,[Optional] BattleEffectDO sourceEffect,bool fromDestroyModule);
}

HOOK("OFFSETS",ApplyAttackDamage,old_ApplyAttackDamage);


switch(featNum):
case 10:
          if (value >= 1){
               DamageMultiplier = value;
          }
break;
 
  • Like
Reactions: DeeNastyle

DeeNastyle

Platinian
Original poster
Jul 27, 2022
8
2
3
33
France
Thank you for the answers.

try this
C++:
float DamageMultiplier;

void (*old_ApplyAttackDamage)(void *instance,int hpDamage,int shieldDamage,bool isCrit,BattleUnitController attacker,BattleUnitController target,UnitMoveType moveType,DamageTypeEnum damageType,bool showUiMessaging,bool canCounterAttack,[Optional] BattleEffectDO sourceEffect,bool fromDestroyModule);
void ApplyAttackDamage(void *instance,int hpDamage,int shieldDamage,bool isCrit,BattleUnitController attacker,BattleUnitController target,UnitMoveType moveType,DamageTypeEnum damageType,bool showUiMessaging,bool canCounterAttack,[Optional] BattleEffectDO sourceEffect,bool fromDestroyModule){
     if (instance != NULL && DamageMultiplier > 1){
          return old_ApplyAttackDamage(instance,int hpDamage * DamageMultiplier ,int shieldDamage * DamageMultiplier,bool isCrit,BattleUnitController attacker,BattleUnitController target,UnitMoveType moveType,DamageTypeEnum damageType,bool showUiMessaging,bool canCounterAttack,[Optional] BattleEffectDO sourceEffect,bool fromDestroyModule);
     }
     return old_ApplyAttackDamage(instance,int hpDamage,int shieldDamage,bool isCrit,BattleUnitController attacker,BattleUnitController target,UnitMoveType moveType,DamageTypeEnum damageType,bool showUiMessaging,bool canCounterAttack,[Optional] BattleEffectDO sourceEffect,bool fromDestroyModule);
}

HOOK("OFFSETS",ApplyAttackDamage,old_ApplyAttackDamage);


switch(featNum):
case 10:
          if (value >= 1){
               DamageMultiplier = value;
          }
break;
I can't even build LGL Mod Menu with this code, it does not understand "BattleUnitController", "attacker", "UnitMoveType", "moveType" etc.
"BattleUnitController" and so on are lib classes
"attacker" and so on are lib parameters

C++:
if (instance && DamageMultiplier > 1) {
    hpDamage *= DamageMultiplier;
    shieldDamage *= DamageMultiplier;
}
It must be so, you haven't provided all the necessary arguments to the ApplyAttackDamage method yet.

In the switch construction, value has an integer type, which means that it would be more correct to specify the type not float (real) but int (integer), It's certainly not a bug, but still.
It didn't worked neither but I guess it also about void calling..

So I've tryied the following:

C++:
int DamageMultiplier = 1;

void (*old_ApplyAttackDamage)(void *instance,int hpDamage,int shieldDamage,bool isCrit,void* BattleUnitController,void* UnitMoveType,void* DamageTypeEnum,bool showUiMessaging,bool canCounterAttack,void* BattleEffectDO,bool fromDestroyModule);
void ApplyAttackDamage(void *instance,int hpDamage,int shieldDamage,bool isCrit,void* BattleUnitController,void* UnitMoveType,void* DamageTypeEnum,bool showUiMessaging,bool canCounterAttack,void* BattleEffectDO,bool fromDestroyModule)
 {
    if (instance != NULL && DamageMultiplier > 1)
    {
        return old_ApplyAttackDamage(instance, hpDamage * DamageMultiplier , shieldDamage * DamageMultiplier, isCrit, BattleUnitController, UnitMoveType, DamageTypeEnum, showUiMessaging, canCounterAttack, BattleEffectDO, fromDestroyModule);
    }
    return old_ApplyAttackDamage(instance, hpDamage, shieldDamage, isCrit, BattleUnitController, UnitMoveType, DamageTypeEnum, showUiMessaging, canCounterAttack, BattleEffectDO, fromDestroyModule);

 }

HOOK("0xd92288", ApplyAttackDamage, old_ApplyAttackDamage);

    switch (featNum) {
        
        case 11:
            if (value >= 1) {
                DamageMultiplier = value;
            }
            break;
I can build the Mod Menu and recompile the apk with this one but it's not working, any other clue ?
 

·҉ dollaz·҉. .

Approved iModder
Approved iModder
Mar 26, 2021
159
1,824
193
Somewhere
Thank you for the answers.



I can't even build LGL Mod Menu with this code, it does not understand "BattleUnitController", "attacker", "UnitMoveType", "moveType" etc.
"BattleUnitController" and so on are lib classes
"attacker" and so on are lib parameters



It didn't worked neither but I guess it also about void calling..

So I've tryied the following:

C++:
int DamageMultiplier = 1;

void (*old_ApplyAttackDamage)(void *instance,int hpDamage,int shieldDamage,bool isCrit,void* BattleUnitController,void* UnitMoveType,void* DamageTypeEnum,bool showUiMessaging,bool canCounterAttack,void* BattleEffectDO,bool fromDestroyModule);
void ApplyAttackDamage(void *instance,int hpDamage,int shieldDamage,bool isCrit,void* BattleUnitController,void* UnitMoveType,void* DamageTypeEnum,bool showUiMessaging,bool canCounterAttack,void* BattleEffectDO,bool fromDestroyModule)
{
    if (instance != NULL && DamageMultiplier > 1)
    {
        return old_ApplyAttackDamage(instance, hpDamage * DamageMultiplier , shieldDamage * DamageMultiplier, isCrit, BattleUnitController, UnitMoveType, DamageTypeEnum, showUiMessaging, canCounterAttack, BattleEffectDO, fromDestroyModule);
    }
    return old_ApplyAttackDamage(instance, hpDamage, shieldDamage, isCrit, BattleUnitController, UnitMoveType, DamageTypeEnum, showUiMessaging, canCounterAttack, BattleEffectDO, fromDestroyModule);

}

HOOK("0xd92288", ApplyAttackDamage, old_ApplyAttackDamage);

    switch (featNum) {
       
        case 11:
            if (value >= 1) {
                DamageMultiplier = value;
            }
            break;
I can build the Mod Menu and recompile the apk with this one but it's not working, any other clue ?
you need to make a function pointer
 

alsya

Solid & Active Platinian
Oct 21, 2021
80
19
8
unknown
try this
C++:
float DamageMultiplier;

void (*old_ApplyAttackDamage)(void *instance,int hpDamage,int shieldDamage,bool isCrit,BattleUnitController attacker,BattleUnitController target,UnitMoveType moveType,DamageTypeEnum damageType,bool showUiMessaging,bool canCounterAttack,[Optional] BattleEffectDO sourceEffect,bool fromDestroyModule);
void ApplyAttackDamage(void *instance,int hpDamage,int shieldDamage,bool isCrit,BattleUnitController attacker,BattleUnitController target,UnitMoveType moveType,DamageTypeEnum damageType,bool showUiMessaging,bool canCounterAttack,[Optional] BattleEffectDO sourceEffect,bool fromDestroyModule){
     if (instance != NULL && DamageMultiplier > 1){
          return old_ApplyAttackDamage(instance,int hpDamage * DamageMultiplier ,int shieldDamage * DamageMultiplier,bool isCrit,BattleUnitController attacker,BattleUnitController target,UnitMoveType moveType,DamageTypeEnum damageType,bool showUiMessaging,bool canCounterAttack,[Optional] BattleEffectDO sourceEffect,bool fromDestroyModule);
     }
     return old_ApplyAttackDamage(instance,int hpDamage,int shieldDamage,bool isCrit,BattleUnitController attacker,BattleUnitController target,UnitMoveType moveType,DamageTypeEnum damageType,bool showUiMessaging,bool canCounterAttack,[Optional] BattleEffectDO sourceEffect,bool fromDestroyModule);
}

HOOK("OFFSETS",ApplyAttackDamage,old_ApplyAttackDamage);


switch(featNum):
case 10:
          if (value >= 1){
               DamageMultiplier = value;
          }
break;
this is not recommended
 

Raebydett

Awesome Active Platinian
Jan 20, 2020
176
62
28
G
You say its not recomended , but it works for me so i dont care , :face09:
He said that bcs the sample u give wont be able to compile it is bcs this
C++:
BattleUnitController attacker,BattleUnitController target,UnitMoveType moveType,DamageTypeEnum damageType
Enum is usually Int, If u not sure just put void
 

Arch01

2/3 Games Approved
Sep 1, 2020
35
7
8
27
Cilegon Banten Indonesia
He said that bcs the sample u give wont be able to compile it is bcs this
C++:
BattleUnitController attacker,BattleUnitController target,UnitMoveType moveType,DamageTypeEnum damageType
Enum is usually Int, If u not sure just put void
yea i mean , its work for me because most of my mod was have somethink like that in the dump , so yea need to cast all the think into hook variable
 

Arch01

2/3 Games Approved
Sep 1, 2020
35
7
8
27
Cilegon Banten Indonesia
try this , this is was improved version
C++:
float DamageMultiplier;

void (*old_ApplyAttackDamage)(void *instance,int hpDamage,int shieldDamage,bool isCrit,void* attacker,void* target,void* moveType,int damageType,bool showUiMessaging,bool canCounterAttack,[Optional] void* sourceEffect,bool fromDestroyModule);
void ApplyAttackDamage(void *instance,int hpDamage,int shieldDamage,bool isCrit,void* attacker,void* target,void* moveType,int damageType,bool showUiMessaging,bool canCounterAttack,[Optional] void* sourceEffect,bool fromDestroyModule){
     if (instance != NULL && DamageMultiplier > 1){
          return old_ApplyAttackDamage(instance,int hpDamage * DamageMultiplier ,int shieldDamage * DamageMultiplier,isCrit,attacker,target,damageType,showUiMessaging,canCounterAttack,[Optional] sourceEffect,fromDestroyModule);
     }
     return old_ApplyAttackDamage(instance,hpDamage,shieldDamage,isCrit,attacker,target,moveType,damageType,showUiMessaging,canCounterAttack,[Optional] sourceEffect,fromDestroyModule);
}

HOOK("OFFSETS",ApplyAttackDamage,old_ApplyAttackDamage);


switch(featNum):
case 10:
          if (value >= 1){
               DamageMultiplier = value;
          }
break;
[/QUOTE]
 

alsya

Solid & Active Platinian
Oct 21, 2021
80
19
8
unknown
try this , this is was improved version
C++:
float DamageMultiplier;

void (*old_ApplyAttackDamage)(void *instance,int hpDamage,int shieldDamage,bool isCrit,void* attacker,void* target,void* moveType,int damageType,bool showUiMessaging,bool canCounterAttack,[Optional] void* sourceEffect,bool fromDestroyModule);
void ApplyAttackDamage(void *instance,int hpDamage,int shieldDamage,bool isCrit,void* attacker,void* target,void* moveType,int damageType,bool showUiMessaging,bool canCounterAttack,[Optional] void* sourceEffect,bool fromDestroyModule){
     if (instance != NULL && DamageMultiplier > 1){
          return old_ApplyAttackDamage(instance,int hpDamage * DamageMultiplier ,int shieldDamage * DamageMultiplier,isCrit,attacker,target,damageType,showUiMessaging,canCounterAttack,[Optional] sourceEffect,fromDestroyModule);
     }
     return old_ApplyAttackDamage(instance,hpDamage,shieldDamage,isCrit,attacker,target,moveType,damageType,showUiMessaging,canCounterAttack,[Optional] sourceEffect,fromDestroyModule);
}

HOOK("OFFSETS",ApplyAttackDamage,old_ApplyAttackDamage);


switch(featNum):
case 10:
          if (value >= 1){
               DamageMultiplier = value;
          }
break;
[/QUOTE]
this is not recommended, why should type void return? and consuming too much space should be easy, just replace the parameter with a damagemultiplier.