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

    • Dawn of Ages: Medieval Games v2.0.9 +5 Jailed Cheats [ Damage & Defence ]
      Modded/Hacked App: Dawn of Ages: total war battle By BoomBit, Inc.
      Bundle ID: com.stratospheregames.dawnofages
      App Store Link: https://apps.apple.com/us/app/dawn-of-ages-total-war-battle/id6477473268?uo=4

       


      🤩 Hack Features

      - Damage Multiplier
      - Defence Multiplier
      - God Mode
      - Dumb Enemy
      - Premium Enabled
        • Agree
        • Winner
        • Like
      • 13 replies
    • Dawn of Ages: Medieval Games v2.0.9 +5 Cheats [ Damage & Defence ]
      Modded/Hacked App: Dawn of Ages: total war battle By BoomBit, Inc.
      Bundle ID: com.stratospheregames.dawnofages
      App Store Link: https://apps.apple.com/us/app/dawn-of-ages-total-war-battle/id6477473268?uo=4

       

      📌 Mod Requirements

      - Jailbroken iPhone or iPad.
      - iGameGod / Filza / iMazing.
      - Cydia Substrate, ElleKit, Substitute or libhooker depending on your jailbreak (from Sileo, Cydia or Zebra).

       

      🤩 Hack Features

      - Damage Multiplier
      - Defence Multiplier
      - God Mode
      - Dumb Enemy
      - Premium Enabled

       

      ⬇️ iOS Hack Download Link


      Hidden Content

      Download Hack







       

      📖 iOS Installation Instructions

      STEP 1: Download the .deb hack file from the link above. Use Safari, Google Chrome or other iOS browsers to download.
      STEP 2: Once the file has downloaded, tap on it and then you will be prompted on whether you want to open the deb with iGameGod or copy it to Filza.
      STEP 3: If needed, tap on the downloaded file again, then select ‘Normal Install’ from the options on your screen.
      STEP 4: Let iGameGod/Filza finish the cheat installation. If it doesn’t install successfully, see the note below.
      STEP 5: Open the game, log in to your iOSGods account when asked, then toggle on the features you want and enjoy!

       

      NOTE: If you have any questions or problems, read our Jailbreak iOS Hack Troubleshooting & Frequently Asked Questions & Answers topic. If you still haven't found a solution, post your issue below and we'll do our best to help! If the hack does work for you, please post your feedback below and help out other fellow members that are encountering issues.

       

      🙌 Credits

      - @Puddin
      - @Laxus

       

      📷 Cheat Video/Screenshots

      N/A

       

      More iOS App Hacks
      If you’re looking for Non-Jailbroken & No Jailbreak required iOS IPA hacks, visit the iOS Game Cheats & Hacks or the iOSGods App for a variety of modded games and apps for non-jailbroken iOS devices.

      Modded Android APKs
      Need modded apps or games for Android? Check out the latest custom APK mods, cheats & more in our Android Section.
        • Agree
        • Thanks
        • Winner
        • Like
      • 22 replies
    • MONOPOLY: The Board Game v1.15.0 +1 Jailed Cheat [ Everything Owned ]
      Modded/Hacked App: MONOPOLY: The Board Game By Marmalade Game Studio Limited
      Bundle ID: com.marmalade.monopoly
      iTunes Store Link: https://apps.apple.com/us/app/monopoly-the-board-game/id1477966166?uo=4


      Hack Features:
      - Everything Owned -> All packs, themes, boards, tokens, all purchased and owned.


      Jailbreak required hack(s): https://iosgods.com/topic/169254-monopoly-classic-board-game-all-versions-1-cheat-everything-owned/
      Modded Android APK(s): https://iosgods.com/forum/68-android-section/
      For more fun, check out the Club(s): https://iosgods.com/clubs/
        • Informative
        • Agree
        • Haha
        • Thanks
        • Winner
        • Like
      • 413 replies
    • First Team Manager Season 2026 v1.0.0 +4 Jailed Cheats [ Unlimited Currencies ]
      Modded/Hacked App: First Team Manager Season 2026 By Go Play Games
      Bundle ID: com.GoPlayGames.FTM26
      iTunes Store Link: https://apps.apple.com/us/app/first-team-manager-season-2026/id6743993781

       
       

      🤩 Hack Features

      - Freeze Coins
      - Freeze Cash
      - Freeze Tokens
      - Free In-App Purchases
      • 0 replies
    • First Team Manager Season 2026 v1.0.0 +4 Cheats [ Unlimited Currencies ]
      Modded/Hacked App: First Team Manager Season 2026 By Go Play Games
      Bundle ID: com.GoPlayGames.FTM26
      iTunes Store Link: https://apps.apple.com/us/app/first-team-manager-season-2026/id6743993781

       
       

      🤩 Hack Features

      - Freeze Coins
      - Freeze Cash
      - Freeze Tokens
      - Free In-App Purchases
      • 0 replies
    • Red Bull Playgrounds v1.0.0 +1 Jailed Cheat [ Score Multiplier ]
      Modded/Hacked App: Red Bull Playgrounds By Red Bull Media House GmbH
      Bundle ID: com.red.bull.playgrounds
      App Store Link: https://apps.apple.com/us/app/red-bull-playgrounds/id6737554653?uo=4

       


      🤩 Hack Features

      - Score Multiplier
      • 3 replies
    • Red Bull Playgrounds v1.0.0 +1 Cheat [ Score Multiplier ]
      Modded/Hacked App: Red Bull Playgrounds By Red Bull Media House GmbH
      Bundle ID: com.red.bull.playgrounds
      App Store Link: https://apps.apple.com/us/app/red-bull-playgrounds/id6737554653?uo=4

       
       

      🤩 Hack Features

      - Score Multiplier
      • 4 replies
    • MONOPOLY: The Board Game v1.15.0 +1 Cheat [ Everything Owned ]
      Modded/Hacked App: MONOPOLY: The Board Game By Marmalade Game Studio Limited
      Bundle ID: com.marmalade.monopoly
      iTunes Store Link: https://apps.apple.com/us/app/monopoly-the-board-game/id1477966166?uo=4


      Hack Features:
      - Everything Owned -> All packs, themes, boards, tokens, all purchased and owned.


      Non-Jailbroken & No Jailbreak required hack(s): https://iosgods.com/topic/169256-monopoly-classic-board-game-v189-1-jailed-cheat-everything-owned/
      Modded Android APK(s): https://iosgods.com/forum/68-android-section/
      For more fun, check out the Club(s): https://iosgods.com/clubs/
        • Informative
        • Agree
        • Haha
        • Thanks
        • Winner
        • Like
      • 203 replies
    • Last War:Survival v1.0.301 [+1 Jailed Cheats]
      Modded/Hacked App: Last War:Survival By FUNFLY PTE. LTD.
      Bundle ID: com.lastwar.ios
      App Store Link: https://apps.apple.com/us/app/last-war-survival/id6448786147?uo=4



      Important


      Only work on Pve contents

      Enable on loading screen!

       

      🤩 Hack Features

      - Never Die
       
        • Informative
        • Agree
        • Thanks
        • Winner
        • Like
      • 25 replies
    • Last War:Survival v1.0.301 [+1 Cheats]
      Modded/Hacked App: Last War:Survival By FUNFLY PTE. LTD.
      Bundle ID: com.lastwar.ios
      App Store Link: https://apps.apple.com/us/app/last-war-survival/id6448786147?uo=4



      Important


      Only work on Pve contents

      Enable on loading screen!

       

       

      🤩 Hack Features

      - Never Die
       
        • Informative
        • Agree
        • Thanks
        • Winner
        • Like
      • 28 replies
    • Arcanterra: A Story Driven RPG v0.18.1 +2 Jailed Cheats [ Damage + More ]
      Modded/Hacked App: Arcanterra: A Story Driven RPG By Funventure P S A
      Bundle ID: eu.funventure.arcanterra
      iTunes Store Link: https://apps.apple.com/us/app/arcanterra-a-story-driven-rpg/id6744968165

       
       

      🤩 Hack Features

      - Damage Multiplier
      - God Mode
      • 2 replies
    • Arcanterra: A Story Driven RPG v0.18.1 +2 Cheats [ Damage + More ]
      Modded/Hacked App: Arcanterra: A Story Driven RPG By Funventure P S A
      Bundle ID: eu.funventure.arcanterra
      iTunes Store Link: https://apps.apple.com/us/app/arcanterra-a-story-driven-rpg/id6744968165

       


      🤩 Hack Features

      - Damage Multiplier
      - God Mode
      • 3 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