Jump to content

How to return a value to a function with parameters?


Go to solution Solved by Ted2,

9 posts in this topic

Recommended Posts

Posted (edited)

Let's say I have this function in the dump.cs:

protected void ammo(int value, bool reload); // 0x289235

and I hooked it like this:

void(*old_ammo)(void *instance, int value, bool reload);
void ammo(void *instance, int value, bool reload)
{
if(instance != NULL)
{
// do something
}
return old_ammo(instance, value, reload);
}
MsHookFunction((void*)getAbsoluteAddress(0x289235), (void*)ammo, (void**)&old_ammo);

How would I set values to the parameters?

Would I do it like this:

void(*old_ammo)(void *instance, int value, bool reload);
void ammo(void *instance, int value, bool reload)
{
if(instance != NULL)
{
  return ammo(instance, 9999, false);
}
return old_ammo(instance, value, reload);
}
MsHookFunction((void*)getAbsoluteAddress(0x289235), (void*)ammo, (void**)&old_ammo);

or like this?

void(*old_ammo)(void *instance, int value, bool reload);
void ammo(void *instance, int value, bool reload)
{
if(instance != NULL)
{
  return 9999, false;
}
return old_ammo(instance, value, reload);
}
MsHookFunction((void*)getAbsoluteAddress(0x289235), (void*)ammo, (void**)&old_ammo);

Which one is correct?

 If none are correct, then how would I do it?

Updated by PixelYT
Added additional information
Posted
On 5/14/2021 at 11:09 PM, PixelYT said:

Would I do it like this:


void(*old_ammo)(void *instance, int value, bool reload);
void ammo(void *instance, int value, bool reload)
{
if(instance != NULL)
{
  return ammo(instance, 9999, false);
}
return old_ammo(instance, value, reload);
}
MsHookFunction((void*)getAbsoluteAddress(0x289235), (void*)ammo, (void**)&old_ammo);

This one is the one you need for setting the parameters.

  • Thanks 1
Posted
1 minute ago, Ted2 said:

Sorry, I just spotted a mistake. You should return old_ammo(instance, 9999,false); 

 

Not ammo(instance, 9999, false);

so we when we are setting values to parameters, we use the old_ammo but when there is no parameters we just use the ammo and inside of it return 99999 or whatever we want, right?

Posted

Hmm, sorry. I was checking the post on phone which sucks. I just checked on my laptop and...

 

The method you're hooking is a void, which means it doesn't return anything. Void methods are called to perform certain things rather than returning something. So this ammo method has two parameters: ammo and reload. You can make them always 9999 and false, but you do not return them.

A valid hook would look like this:

// This holds the original state of the method, some people prefer to call it "orig_ammo" instead because of that.
void(*old_ammo)(void *instance, int value, bool reload);

// This is the hooked method, where you can do whatever you want
void ammo(void *instance, int value, bool reload) {
  	// Just a note; I don't think instance will ever be NULL.
	if(instance != NULL) {
		// set ammo to 9999 and reload to false
		old_ammo(instance, 9999, false);
	}
	// Do what it normally does
	old_ammo(instance, value, reload);
}


MsHookFunction((void*)getAbsoluteAddress(0x289235), (void*)ammo, (void**)&old_ammo);

 

I've added some comments to the code, so I hope you understand better then.

  • Like 1
Posted (edited)
3 hours ago, Ted2 said:

Hmm, sorry. I was checking the post on phone which sucks. I just checked on my laptop and...

 

The method you're hooking is a void, which means it doesn't return anything. Void methods are called to perform certain things rather than returning something. So this ammo method has two parameters: ammo and reload. You can make them always 9999 and false, but you do not return them.

A valid hook would look like this:


// This holds the original state of the method, some people prefer to call it "orig_ammo" instead because of that.
void(*old_ammo)(void *instance, int value, bool reload);

// This is the hooked method, where you can do whatever you want
void ammo(void *instance, int value, bool reload) {
  	// Just a note; I don't think instance will ever be NULL.
	if(instance != NULL) {
		// set ammo to 9999 and reload to false
		old_ammo(instance, 9999, false);
	}
	// Do what it normally does
	old_ammo(instance, value, reload);
}


MsHookFunction((void*)getAbsoluteAddress(0x289235), (void*)ammo, (void**)&old_ammo);

 

I've added some comments to the code, so I hope you understand better then.

oh wow, now i understand. It's just like how when we hook an Update method and use function pointers on it, we don't use return because the Update method is a void which means it doesn't return anything. Thank you, now I understand, i just didn't know that when we hook a method that is a void but not the Update method, we just call the function and set it's parameters without return.

Updated by PixelYT
Added additional information
Posted (edited)
3 hours ago, Ted2 said:

Hmm, sorry. I was checking the post on phone which sucks. I just checked on my laptop and...

 

The method you're hooking is a void, which means it doesn't return anything. Void methods are called to perform certain things rather than returning something. So this ammo method has two parameters: ammo and reload. You can make them always 9999 and false, but you do not return them.

A valid hook would look like this:


// This holds the original state of the method, some people prefer to call it "orig_ammo" instead because of that.
void(*old_ammo)(void *instance, int value, bool reload);

// This is the hooked method, where you can do whatever you want
void ammo(void *instance, int value, bool reload) {
  	// Just a note; I don't think instance will ever be NULL.
	if(instance != NULL) {
		// set ammo to 9999 and reload to false
		old_ammo(instance, 9999, false);
	}
	// Do what it normally does
	old_ammo(instance, value, reload);
}


MsHookFunction((void*)getAbsoluteAddress(0x289235), (void*)ammo, (void**)&old_ammo);

 

I've added some comments to the code, so I hope you understand better then.

One more question: inside of the if(instance != NULL) statement, don't we use ammo to set parameters to whatever we like and then after it, we just put the old_ammo in case instance is NULL? Like this and not like the above one:

void(*old_ammo)(void *instance, int value, bool reload); // this holds the original value of the method
void ammo(void *instance, int value, bool reload) // this is the hooked method where we change the value to whatever we like
{
if(instance != NULL)
{
  ammo(instance, 9999, false); // Use the hooked method to change int value to 9999, and bool reload to false
}
 old_ammo(instance, value, reload); // in case instance is NULL, call the old_ammo which holds the original value
}
MsHookFunction((void*)getAbsoluteAddress(0x289235), (void*)ammo, (void**)&old_ammo);

 

Updated by PixelYT
Added additional information
  • Solution
Posted
7 hours ago, PixelYT said:

One more question: inside of the if(instance != NULL) statement, don't we use ammo to set parameters to whatever we like and then after it, we just put the old_ammo in case instance is NULL? Like this and not like the above one:


void(*old_ammo)(void *instance, int value, bool reload); // this holds the original value of the method
void ammo(void *instance, int value, bool reload) // this is the hooked method where we change the value to whatever we like
{
if(instance != NULL)
{
  ammo(instance, 9999, false); // Use the hooked method to change int value to 9999, and bool reload to false
}
 old_ammo(instance, value, reload); // in case instance is NULL, call the old_ammo which holds the original value
}
MsHookFunction((void*)getAbsoluteAddress(0x289235), (void*)ammo, (void**)&old_ammo);

 

Nope. As the void ammo(bla, bla, bla) {} is the replacement method of the original method (which you named old_ammo), here you write your own logic of the method. If you only need to change the parameter values, you can just call the original method (old_ammo) with your own values and that will be enough. You could also do: 

void ammo(void *instance, int value, bool reload) {
	value = 9999;
	reload = false;
	old_ammo(instance, value, reload);
}

In this example you alter the parameter values it was originally called with and then call the method itself with your new values.

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Our picks

    • Alien Survivor: Survival Arena v1.38.1 [ +7 Cheats ] Currency Max
      Modded/Hacked App: Alien Survivor: Survival Arena By IMPONILOX LIMITED
      Bundle ID: world.playme.x
      iTunes Store Link: https://apps.apple.com/us/app/alien-survivor-survival-arena/id1669761844?uo=4
       

      🚀 Hack Features

      - ADS NO [ Rewards Free ]

      - Gems [ Achievements Rewards Only One Get ]

      - Energy [ Just Buy ]

      - HP [ Just Equip & Unequip ]

      - ATK [ Just Equip & Unequip ]

      - DEF [ Just Equip & Unequip ]

      - Skill CD [ First Get Then Use ]


      🍏 For Non-Jailbroken & No Jailbreak required hacks: https://iosgods.com/forum/79-no-jailbreak-section/
      🤖 Modded Android APK(s): https://iosgods.com/forum/68-android-section/
      • 15 replies
    • Alien Survivor: Survival Arena v1.38.1 [ +7 Jailed ] Currency Max
      Modded/Hacked App: Alien Survivor: Survival Arena By IMPONILOX LIMITED
      Bundle ID: world.playme.x
      iTunes Store Link: https://apps.apple.com/us/app/alien-survivor-survival-arena/id1669761844?uo=4


      🚀 Hack Features

      - ADS NO [ Rewards Free ]

      - Gems [ Achievements Rewards Only One Get ]

      - Energy [ Just Buy ]

      - HP [ Just Equip & Unequip ]

      - ATK [ Just Equip & Unequip ]

      - DEF [ Just Equip & Unequip ]

      - Skill CD [ First Get Then Use ]


      🍏 Jailbreak iOS hacks: https://iosgods.com/forum/5-game-cheats-hack-requests/
      🤖 Modded Android APKs: https://iosgods.com/forum/68-android-section/
      • 26 replies
    • Legend of Survivors V1.2.8 [ +17 Jailed ] Currency Max
      Modded/Hacked App: Legend of Survivors By ABI GLOBAL LTD.
      Bundle ID: com.abi.legendofsurvivors
      iTunes Store Link: https://apps.apple.com/us/app/legend-of-survivors/id6489580730?uo=4


      Hack Features:

      - NO ADS

      - Gems 

      - Gold

      - Energy 

      - Material

      - Health Max [ Equip & Upgrade ]

      - Damage [ Equip & Upgrade ]

      - Skill Cooldown

      - EXP + Level [ Patrol Reward ]

      - Patrol Reward [ Claim Unlimited ]

      - Growth Pack Unlock

      - Growth Pack [ Claim Unlimited ]

      - Monthly card Pack Unlock

      - Monthly card Pack [ Claim Unlimited ]


      Jailbreak required hack(s): https://iosgods.com/forum/5-game-cheats-hack-requests/
      Modded Android APK(s): https://iosgods.com/forum/68-android-section/
      For more fun, check out the Club(s): https://iosgods.com/clubs/
      • 48 replies
    • Legend of Survivors V1.2.8 [ +17 Cheats ] Currency Max
      Modded/Hacked App: Legend of Survivors By ABI GLOBAL LTD.
      Bundle ID: com.abi.legendofsurvivors
      iTunes Store Link: https://apps.apple.com/us/app/legend-of-survivors/id6489580730?uo=4


      Hack Features:
      - IAP Free [ Buy Anything - Gems Gold Ads Premium Packs ]

      - NO ADS

      - Gems 

      - Gold

      - Energy 

      - Material

      - Health Max [ Equip & Upgrade ]

      - Damage [ Equip & Upgrade ]

      - Skill Cooldown

      - EXP + Level [ Patrol Reward ]

      - Patrol Reward [ Claim Unlimited ]

      - Growth Pack Unlock

      - Growth Pack [ Claim Unlimited ]

      - Monthly card Pack Unlock

      - Monthly card Pack [ Claim Unlimited ]
      • 132 replies
    • Kitchen Masters v15.0.0 [ +4 Cheats ] Currency Max
      Modded/Hacked App: Kitchen Masters By Bigger Oyun Yazilim ve Pazarlama Anonim Sirketi
      Bundle ID: com.bigger.kitchenmasters
      iTunes Store Link: https://apps.apple.com/ph/app/kitchen-masters/id6474870266?uo=4


      🤩 Hack Features

      - Coins

      - Cash

      - Lives

      - Tile Cost 0
      • 6 replies
    • Kitchen Masters v15.0.0 [ +4 Jailed ] Currency Max
      Modded/Hacked App: Kitchen Masters By Bigger Oyun Yazilim ve Pazarlama Anonim Sirketi
      Bundle ID: com.bigger.kitchenmasters
      iTunes Store Link: https://apps.apple.com/ph/app/kitchen-masters/id6474870266?uo=4
       

      🤩 Hack Features

      - Coins

      - Cash

      - Lives

      - Tile Cost 0
      • 10 replies
    • Score Masters v2.2 [ +7 Jailed ] Always Win
      Modded/Hacked App: Score Masters By SKYLOFT YAZILIM BILISIM VE TICARET ANONIM SIRKETI
      Bundle ID: com.bh.hypergoal
      iTunes Store Link: https://apps.apple.com/us/app/score-masters/id6473402760?uo=4


      🚀 Hack Features

      - Auto ADS Disable

      - Gems [ Mission Rewards ]

      - Coins [ Mission Rewards ]

      - Player Score 20 Max

      - Always Win Player

      - AI Score 0

      - AI Miss
      • 5 replies
    • Score Masters v2.2 [ +7 Cheats ] Always Win
      Modded/Hacked App: Score Masters By SKYLOFT YAZILIM BILISIM VE TICARET ANONIM SIRKETI
      Bundle ID: com.bh.hypergoal
      iTunes Store Link: https://apps.apple.com/us/app/score-masters/id6473402760?uo=4


      🚀 Hack Features

      - Auto ADS Disable

      - Gems [ Mission Rewards ]

      - Coins [ Mission Rewards ]

      - Player Score 20 Max

      - Always Win Player

      - AI Score 0

      - AI Miss
      • 8 replies
    • Adventure Bay - Farm Games v1.42.14 [ +4 Cheats ] Currency Max
      Modded/Hacked App: Adventure Bay - Farm Games By Gamegos Teknoloji A.S.
      Bundle ID: com.gamegos.adventure.bay.paradise.farm
      iTunes Store Link: https://apps.apple.com/us/app/adventure-bay-farm-games/id1578449819?uo=4
       

      🤩 Hack Features

      - Gems
      - Coins
      - Energy
      - Avatar Unlock
      • 19 replies
    • Adventure Bay - Farm Games v1.42.14 [ +4 Jailed ] Currency Max
      Modded/Hacked App: Adventure Bay - Farm Games By Gamegos Teknoloji A.S.
      Bundle ID: com.gamegos.adventure.bay.paradise.farm
      iTunes Store Link: https://apps.apple.com/us/app/adventure-bay-farm-games/id1578449819?uo=4


      🤩 Hack Features

      - Gems
      - Coins
      - Energy
      - Avatar Unlock
      • 25 replies
    • Disney Solitaire v1.3.0 [ +7 Cheats ] Auto Win
      Modded/Hacked App: Disney Solitaire By SuperPlay LTD
      Bundle ID: com.superplaystudios.disneysolitairedreams
      iTunes Store Link: https://apps.apple.com/ph/app/disney-solitaire/id6475757306?uo=4
       

      🤩 Hack Features

      - Coins [ Win Match ]

      - Task [ No Need Star ]

      - Stars

      - Undo

      - Wild Card

      - Free Ticket

      - Auto Win
      • 15 replies
    • Disney Solitaire v1.3.0 [ +7 Jailed ] Auto Win
      Modded/Hacked App: Disney Solitaire By SuperPlay LTD
      Bundle ID: com.superplaystudios.disneysolitairedreams
      iTunes Store Link: https://apps.apple.com/ph/app/disney-solitaire/id6475757306?uo=4


      🤩 Hack Features

      - Coins [ Win Match ]

      - Task [ No Need Star ]

      - Stars

      - Undo

      - Wild Card

      - Free Ticket

      - Auto Win
      • 21 replies
×
  • Create New...

Important Information

We would like to place cookies on your device to help make this website better. The website cannot give you the best user experience without cookies. You can accept or decline our cookies. You may also adjust your cookie settings. Privacy Policy - Guidelines