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
2 minutes ago, PixelYT said:

Thanks sir! :))

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

 

Not ammo(instance, 9999, false);

  • Like 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

    • Powerlust - Action RPG Offline v1.67.09 +2 Jailed Cheats [ Damage ]
      Modded/Hacked App: Powerlust - Action RPG offline By Bartlomiej Mamzer
      Bundle ID: bartmamzer.powerlust.actionrpg.roguelike
      App Store Link: https://apps.apple.com/us/app/powerlust-action-rpg-offline/id1439088319?uo=4

       


      🤩 Hack Features

      - God Mode
      - Damage Multiplier
      • 0 replies
    • Powerlust - Action RPG Offline v1.67.09 +2 Cheats [ Damage ]
      Modded/Hacked App: Powerlust - Action RPG offline By Bartlomiej Mamzer
      Bundle ID: bartmamzer.powerlust.actionrpg.roguelike
      App Store Link: https://apps.apple.com/us/app/powerlust-action-rpg-offline/id1439088319?uo=4

       
       

      🤩 Hack Features

      - God Mode
      - Damage Multiplier
      • 0 replies
    • NETHER DUNGEONS v1.18 [+3 Cheats]
      Modded/Hacked App: NETHER DUNGEONS By ARAKUMA STUDIO S.A.
      Bundle ID: com.ArakumaStudio.NetherDungeons
      iTunes Store Link: https://apps.apple.com/us/app/nether-dungeons/id6737908225?uo=4



      🤩 Hack Features

      - Never Die
      - Activate Vip Mode
      - Add Currency
       
      • 4 replies
    • NETHER DUNGEONS v1.18 [+3 Jailed Cheats]
      Modded/Hacked App: NETHER DUNGEONS By ARAKUMA STUDIO S.A.
      Bundle ID: com.ArakumaStudio.NetherDungeons
      iTunes Store Link: https://apps.apple.com/us/app/nether-dungeons/id6737908225?uo=4

       

      🤩 Hack Features

      - Never Die
      - Activate Vip Mode
      - Add Currency
      • 3 replies
    • Kiwoyong: Raise Your Dragon ( 키워용: 도굴라이프 ) v1.5.16 +2 Cheats [ Damage ]
      Modded/Hacked App: 키워용: 도굴라이프 By Co., Ltd. NGELGAMES
      Bundle ID: kr.ngelgames.dragon
      App Store Link: https://apps.apple.com/kr/app/%ED%82%A4%EC%9B%8C%EC%9A%A9-%EB%8F%84%EA%B5%B4%EB%9D%BC%EC%9D%B4%ED%94%84/id6618145893?uo=4

       
       

      🤩 Hack Features

      - God Mode
      - Damage Multiplier
      • 2 replies
    • Hungry Shark World v6.7.7 +5 Jailed Cheats [ Unlimited Currencies ]
      Modded/Hacked App: Hungry Shark World By Ubisoft
      Bundle ID: com.ubisoft.hungrysharkworld
      iTunes Store Link: https://apps.apple.com/us/app/hungry-shark-world/id1046846443?uo=4


      Mod Requirements:
      - Non-Jailbroken/Jailed or Jailbroken iPhone/iPad/iPod Touch.
      - Sideloadly / Cydia Impactor or alternatives.
      - A Computer Running Windows/macOS/Linux with iTunes installed.


      Hack Features:
      - Unlimited Coins
      - Unlimited Gems
      - Unlimited Pearls
      - Unlimited Boost
      - Season Pass Unlocked


      Jailbreak required hack(s): [Mod Menu Hack] Hungry Shark World v5.9.1 +5 Cheats [ Unlimited Currencies ] - Free Jailbroken Cydia Cheats - iOSGods
      Modded Android APK(s): https://iosgods.com/forum/68-android-section/
      For more fun, check out the Club(s): https://iosgods.com/clubs/
        • Informative
        • Thanks
        • Winner
        • Like
      • 228 replies
    • Hungry Shark World v6.7.7 +5 Cheats [ Unlimited Currencies ]
      Modded/Hacked App: Hungry Shark World By Ubisoft
      Bundle ID: com.ubisoft.hungrysharkworld
      iTunes Store Link: https://apps.apple.com/us/app/hungry-shark-world/id1046846443?uo=4


      Hack Features:
      - Unlimited Coins
      - Unlimited Gems
      - Unlimited Pearls
      - Unlimited Boost
      - Season Pass Unlocked


      Non-Jailbroken & No Jailbreak required hack(s): [Non-Jailbroken Hack] Hungry Shark World v5.9.1 +4 Jailed Cheats [ Unlimited Currencies ] - Free Non-Jailbroken IPA Cheats - iOSGods
      Modded Android APK(s): https://iosgods.com/forum/68-android-section/
      For more fun, check out the Club(s): https://iosgods.com/clubs/
        • Thanks
        • Like
      • 92 replies
    • Run! Goddess v1.0.10 [+3 Jailed Cheats]
      Modded/Hacked App: Run! Goddess By TOP GAMES INC.
      Bundle ID: com.topgamesinc.rg
      iTunes Store Link: https://apps.apple.com/us/app/run-goddess/id6667111749?uo=4



      🤩 Hack Features

      - No Skill Cooldown
      - Slow Enemy
      - Enemy Can't Attack (Enemy Can't Do Damage)
      • 31 replies
    • Run! Goddess v1.0.10 [+3 Cheats]
      Modded/Hacked App: Run! Goddess By TOP GAMES INC.
      Bundle ID: com.topgamesinc.rg
      iTunes Store Link: https://apps.apple.com/us/app/run-goddess/id6667111749?uo=4

       

      🤩 Hack Features

      - No Skill Cooldown
      - Slow Enemy
      - Enemy Can't Attack (Enemy Can't Do Damage)
       
      • 26 replies
    • Sword Master Story Cheats v4.107.556 +5
      Modded/Hacked App: Sword Master Story By SuperPlanet corp.
      Bundle ID: com.superplanet.swordmaster
      iTunes Store Link: https://apps.apple.com/us/app/sword-master-story/id1521447065?uo=4


      Hack Features:
      - Custom Player Stats
      - Weak Enemies
      - One Hit Kill
      - & More

      Press & Hold to read feature description


      iOS Hack Download Link: https://iosgods.com/topic/146819-sword-master-story-cheats-v42294-3/
        • Informative
        • Agree
        • Thanks
        • Winner
        • Like
      • 1,445 replies
    • Subway Surfers v3.45.0 +22 Jailed Cheats [ Currencies + More ]
      Modded/Hacked App: Subway Surfers By Sybo Games ApS
      Bundle ID: com.kiloo.subwaysurfers
      iTunes Store Link: https://apps.apple.com/us/app/subway-surfers/id512939461?uo=4


      Hack Features:
      - Unlimited Currencies
      - Freeze Currencies
      - Free In-App Purchases
      - All Characters Unlocked
      - All Boards Unlocked
      - God Mode
      - No Stumble
      - Score Multiplier
      - Speed Multiplier
      - Gravity Multiplier
      - Jump Height Multiplier
      - Air Jump Height Multiplier
      - Unlimited Jumps
      - Unlimited Powers
      - Instant Lane Change
      - Freeze Trains
      - No Clip
      - Disable All Pickup
      - No Revive Cost
      - Unlimited Jetpack Time
      - Camera Stops
      - Camera Follows


      Jailbreak required hack(s): [Mod Menu Hack] Subway Surfers v3.40.0 +20 Cheats [ Currencies + More ] - ViP Cheats - iOSGods
      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
      • 36 replies
    • Subway Surfers v3.45.0 +22 Cheats [ Currencies + More ]
      Modded/Hacked App: Subway Surfers By Sybo Games ApS
      Bundle ID: com.kiloo.subwaysurfers
      iTunes Store Link: https://apps.apple.com/us/app/subway-surfers/id512939461?uo=4


      Hack Features:
      - Unlimited Currencies
      - Freeze Currencies
      - Free In-App Purchases
      - All Characters Unlocked
      - All Boards Unlocked
      - God Mode
      - No Stumble
      - Score Multiplier
      - Speed Multiplier
      - Gravity Multiplier
      - Jump Height Multiplier
      - Air Jump Height Multiplier
      - Unlimited Jumps
      - Unlimited Powers
      - Instant Lane Change
      - Freeze Trains
      - No Clip
      - Disable All Pickup
      - No Revive Cost
      - Unlimited Jetpack Time
      - Camera Stops
      - Camera Follows


      Non-Jailbroken & No Jailbreak required hack(s): [IPA Mod Menu] Subway Surfers v3.40.0 +20 Jailed Cheats [ Currencies + More ] - ViP Non-Jailbroken Hacks & Cheats - iOSGods
      Modded Android APK(s): https://iosgods.com/forum/68-android-section/
      For more fun, check out the Club(s): https://iosgods.com/clubs/
        • Agree
        • Haha
        • Thanks
        • Like
      • 40 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