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

    • Heroes vs. Hordes: Survivor v5.1.3 [ +11 Cheats ] Currency Max
      Modded/Hacked App: Heroes vs. Hordes: Survivor By Swift Games GmbH
      Bundle ID: com.swiftgames.roguelikesurvival
      iTunes Store Link: https://apps.apple.com/us/app/heroes-vs-hordes-survivor/id1608898173?uo=4

       
      Hack Features

      - Currency

      - Resource

      - Gold Unlimited [ Bonus Wave ]

      - Ch Unlocked [ Play All Off ]

      - Always Last Wave

      - Talents Cost 0

      - Hero DMG Only

      - HP & DMG [ Just Equip & Unequip ]

      - Enemy Freeze

      - Enemy ATK NO

       
      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/
        • Agree
        • Thanks
        • Winner
        • Like
      • 70 replies
    • Heroes vs. Hordes: Survivor v5.1.3 [ +11 Jailed ] Currency Max
      Modded/Hacked App: Heroes vs. Hordes: Survivor By Swift Games GmbH
      Bundle ID: com.swiftgames.roguelikesurvival
      iTunes Store Link: https://apps.apple.com/us/app/heroes-vs-hordes-survivor/id1608898173?uo=4

       

       

      Mod Requirements

      - Non-Jailbroken/Jailed or Jailbroken iPhone or iPad.
      - Sideloadly or alternatives.
      - Computer running Windows/macOS/Linux with iTunes installed.

       

      Hack Features

      - Currency

      - Resource

      - Gold Unlimited [ Bonus Wave ]

      - Ch Unlocked [ Play All Off ]

      - Always Last Wave

      - Talents Cost 0

      - Hero DMG Only

      - HP & DMG [ Just Equip & Unequip ]

      - Enemy Freeze

      - Enemy ATK NO


      Jailbreak required iOS hacks: https://iosgods.com/forum/5-game-cheats-hack-requests/
      Modded Android APKs: https://iosgods.com/forum/68-android-section/

       

      iOS Hack Download IPA Link


      Hidden Content

      Download via the iOSGods App
        • Agree
        • Thanks
        • Winner
        • Like
      • 85 replies
    • Merge & Blast: Dream Island v2.22.1 [ +2 Cheats ] Auto Win
      Modded/Hacked App: Merge & Blast: Dream Island By Dreamo, Inc.
      Bundle ID: com.dreamo.woodyblast
      iTunes Store Link: https://apps.apple.com/us/app/merge-blast-dream-island/id1668748189?uo=4


      🤩 Hack Features

      - Auto Win
      - Coin + Moves [ Disable After Get ]




      🍏 For Non-Jailbroken & No Jailbreak required hacks: https://iosgods.com/forum/79-no-jailbreak-section/
      🤖 Modded Android APKs: https://iosgods.com/forum/68-android-section/
        • Like
      • 13 replies
    • Merge & Blast: Dream Island v2.22.1 [ +2 Jailed ] Auto Win
      Modded/Hacked App: Merge & Blast: Dream Island By Dreamo, Inc.
      Bundle ID: com.dreamo.woodyblast
      iTunes Store Link: https://apps.apple.com/us/app/merge-blast-dream-island/id1668748189?uo=4

       

      🤩 Hack Features

      - Auto Win
      - Coin + Moves [ Disable After Get ]




      🍏 Jailbreak iOS hacks: https://iosgods.com/forum/5-game-cheats-hack-requests/
      🤖 Modded Android APKs: https://iosgods.com/forum/68-android-section/
      • 18 replies
    • Merge Cruise: Mystery Puzzle v0.36.360 [ +2 Cheats ] Currency Max
      Modded/Hacked App: Merge Cruise: Mystery Puzzle By STUDIO PEERPLAY GAMES LTD
      Bundle ID: com.peerplay.megamerge
      iTunes Store Link: https://apps.apple.com/us/app/merge-cruise-mystery-puzzle/id6459056553?uo=4
       

      🤩 Hack Features

      - Cash
      - Energy

        • Agree
        • Haha
        • Thanks
        • Like
      • 13 replies
    • Merge Cruise: Mystery Puzzle v0.36.360 [ +2 Jailed ] Currency Max
      Modded/Hacked App: Merge Cruise: Mystery Puzzle By STUDIO PEERPLAY GAMES LTD
      Bundle ID: com.peerplay.megamerge
      iTunes Store Link: https://apps.apple.com/us/app/merge-cruise-mystery-puzzle/id6459056553?uo=4
       

      🤩 Hack Features

      - Cash
      - Energy

        • Winner
        • Like
      • 17 replies
    • Pop Island v1.0.8 [ +1 Cheats ] Coins Max
      Modded/Hacked App: Pop Island By HISTAR INTERACTIVE PTE. LTD.
      Bundle ID: com.hmbdgames.match
      iTunes Store Link: https://apps.apple.com/us/app/pop-island/id6505047210?uo=4


      🤩 Hack Features

      - Coins [ Win Match Disable After Hack ]


        • Agree
        • Like
      • 13 replies
    • Pop Island v1.0.8 [ +1 Jailed ] Coins Max
      Modded/Hacked App: Pop Island By HISTAR INTERACTIVE PTE. LTD.
      Bundle ID: com.hmbdgames.match
      iTunes Store Link: https://apps.apple.com/us/app/pop-island/id6505047210?uo=4


      🤩 Hack Features

      - Coins [ Win Match Disable After Hack ]


        • Winner
        • Like
      • 12 replies
    • Survivor Kingdoms V3.23 [ +11 Cheats ] Easy Win
      Modded/Hacked App: Survivor Kingdoms By Gamee Joint Stock Company
      Bundle ID: com.gamee.kingdoms.survivor.io
      iTunes Store Link: https://apps.apple.com/us/app/survivor-kingdoms/id6444824577?uo=4


      Hack Features:
      - IAP Free [ Buy Anything ]

      - Health

      - Damage

      - Skill CD Slow

      - Skill CD Fast [ Maybe Game Slow ]

      - Skill Size Big

      - Shooting Speed Fast

      - Movement Speed

      - Auto Revive Unlimited [ Never Die ]

      - Ultimate Power CD

      - Avatar & Frame 


      Non-Jailbroken & No Jailbreak required hack(s): https://iosgods.com/forum/79-no-jailbreak-section/
      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
      • 41 replies
    • Survivor Kingdoms V3.23 [ +11 Jailed ] Easy Win
      Modded/Hacked App: Survivor Kingdoms By Gamee Joint Stock Company
      Bundle ID: com.gamee.kingdoms.survivor.io
      iTunes Store Link: https://apps.apple.com/us/app/survivor-kingdoms/id6444824577?uo=4

       

      🚀 Hack Features

      - IAP Free [ Buy Anything ]

      - Health

      - Damage

      - Skill CD Slow

      - Skill CD Fast [ Maybe Game Slow ]

      - Skill Size Big

      - Shooting Speed Fast

      - Movement Speed

      - Auto Revive Unlimited [ Never Die ]

      - Ultimate Power CD

      - Avatar & Frame 


      🍏 Jailbreak iOS hacks: https://iosgods.com/forum/5-game-cheats-hack-requests/
      🤖 Modded Android APKs: https://iosgods.com/forum/68-android-section/
        • Informative
        • Agree
        • Winner
        • Like
      • 26 replies
    • [ Seven Deadly Sins KR ] 일곱 개의 대죄: GRAND CROSS Cheats v8.6.71 +5
      Modded/Hacked App: 일곱 개의 대죄: GRAND CROSS By Netmarble Corporation
      Bundle ID: com.netmarble.nanakr
      iTunes Store Link: https://apps.apple.com/kr/app/%EC%9D%BC%EA%B3%B1-%EA%B0%9C%EC%9D%98-%EB%8C%80%EC%A3%84-grand-cross/id1449552940?uo=4


      Hack Features:
      - God Mode
      - One Hit Kill
      - Multiply Attack
      - Multiply Defense
      - Make Enemies God Mode for some quests


      iOS Hack Download Link: https://iosgods.com/topic/154899-seven-deadly-sins-kr-%EC%9D%BC%EA%B3%B1-%EA%B0%9C%EC%9D%98-%EB%8C%80%EC%A3%84-grand-cross-cheats-v750-5/
        • Informative
        • Agree
        • Haha
        • Thanks
        • Winner
        • Like
      • 174 replies
    • EverMerge: Merge & Match Game v1.62.3 +30 Jailed Cheats [ Cheat Menu ]
      Modded/Hacked App: EverMerge: Merge & Match Game By Big Fish Games, Inc
      Bundle ID: com.bigfishgames.mergetalesios
      iTunes Store Link: https://apps.apple.com/us/app/evermerge-merge-match-game/id1446344746?uo=4

       


      🚀 Hack Features

      - Cheat Menu -> Head into Settings and toggle the Support button.
        • Like
      • 5 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