Help! Hook a void function with multiple arguments

  • Polarmods v2 is currently being developed. More information can be found on the Discord.

DeeNastyle

New member
Registered
Aug 2, 2022
1
0
1
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 64-bit game on android.

Here the function I want to hook:
- Lib class: BattleUnitController
- Offset: 0xD92288
C++:
public void ApplyAttackDamage(int hpDamage, int shieldDamage, bool isCrit, BattleUnitController attacker, BattleUnitController target, UnitMoveType moveType, DamageTypeEnum damageType, bool showUIMessaging = True, bool canCounterAttack = True, BattleEffectDO sourceEffect, bool fromDestroyModule = False) { }

My ultimate goal is to modify hpDamage & shieldDamage parameters inside the void function by using a slider.
Is calling only a few arguments of a void function possible ? How should I do it ? (I'm a begginer have hard time finding the right way to translate that in C+)

So far I have tested the following but not working:

C++:
int DamageMultiplier = 1;

//My function
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);

}

//Hooking armeabi-v7a
HOOK("0xd92288", ApplyAttackDamage, old_ApplyAttackDamage);

//Setting the slider
jobjectArray GetFeatureList(JNIEnv *env, jobject context) {
    jobjectArray ret;

    const char *features[] = {
            OBFUSCATE("10_SeekBar_Damage Multiplier_1_10000")
    };

//Switch cases
    switch (featNum) {
    
        case 10:
            if (value >= 1) {
                DamageMultiplier = value;
            }
            break;

I have seen some well working mod menus for my game out there so I'm pretty sure it's can be done.
I would take any wisedom/advise you could share :)
 

A random person

Poggers
Staff member
Junior Polar Modder
Apr 14, 2020
32
852
83
your moms house
Something like this should work
Don't forget to set a update offset
C++:
void (*ApplyAttackDamage)((void *instance,int hpDamage,int shieldDamage,bool isCrit,void* BattleUnitController,void* UnitMoveType,void* DamageTypeEnum,bool showUiMessaging,bool canCounterAttack,void* BattleEffectDO,bool fromDestroyModule));

void (*old_PlayerUpdate)(void *instance);
void PlayerUpdate(void *instance) {
    if (instance != nullptr && DamageMultiplier > 1) {
        ApplyAttackDamage(your params here);
    }

    old_PlayerBehaviourUpdate(instance);
}

//Put this where your hooks are
ApplyAttackDamage = (void (*)(void *instance,int hpDamage,int shieldDamage,bool isCrit,void* BattleUnitController,void* UnitMoveType,void* DamageTypeEnum,bool showUiMessaging,bool canCounterAttack,void* BattleEffectDO,bool fromDestroyModule))getAbsoluteAddress(targetLibName, 0xD92288);

HOOK("0x0", PlayerUpdate, old_PlayerUpdate);
 

About us

  • Welcome to Polarmods.com! We are an ever-expanding gaming community that loves to both help others, and make mods for everyone to enjoy! Although we're currently quite small, we can guarantee you that we offer the best game mods for the game that you're looking for! If you don't find what you're looking for please request it in the android mods request section. We're always trying to improve ourselves and to make you guys happy. We also want to help you out, that's why we offer tutorials on modding, and tools to help you out! So what are you waiting for? Join in on the fun! If you need anything, be sure to join our discord server, or contact us on one of your social medias below. We hope you have a great day :)

Quick Navigation

User Menu