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

    • Modern Ops: Online Shooter FPS v9.53 +6 Jailed Cheats [ No Recoil + More ]
      Modded/Hacked App: Modern Ops: Online Shooter FPS By Edkon Games GmbH
      Bundle ID: com.edkongames.mobs
      App Store Link: https://apps.apple.com/us/app/modern-ops-online-shooter-fps/id1415791453?uo=4

       


      🤩 Hack Features

      - No Recoil
      - No Spread
      - No Flashbang Effect
      - No Smoke Effect
      - Red Crosshair
      - Field of View Modifier
      • 0 replies
    • FIFA Rivals - Mobile Football v1.0.2 +2 Jailed Cheats [ Auto Win ]
      Modded/Hacked App: FIFA Rivals - Mobile Football By Mythical Games
      Bundle ID: com.mythical.fifarivals
      iTunes Store Link:https://apps.apple.com/us/app/fifa-rivals-mobile-football/id6746578704

       
       

      🤩 Hack Features

      - Auto Win -> Linked to yourself & opponent. Every goal scored will result in a win.
      - Season Pass Unlocked -> Will let you claim all rewards from all passes.
        • Agree
        • Winner
        • Like
      • 9 replies
    • FIFA Rivals - Mobile Football v1.0.2 +2 Cheats [ Auto Win ]
      Modded/Hacked App: FIFA Rivals - Mobile Football By Mythical Games
      Bundle ID: com.mythical.fifarivals
      iTunes Store Link:https://apps.apple.com/us/app/fifa-rivals-mobile-football/id6746578704

       
       

      🤩 Hack Features

      - Auto Win -> Linked to yourself & opponent. Every goal scored will result in a win.
      - Season Pass Unlocked -> Will let you claim all rewards from all passes.
        • Winner
        • Like
      • 19 replies
    • Modern Ops: Online Shooter FPS v9.53 +6 Cheats [ No Recoil + More ]
      Modded/Hacked App: Modern Ops: Online Shooter FPS By Edkon Games GmbH
      Bundle ID: com.edkongames.mobs
      App Store Link: https://apps.apple.com/us/app/modern-ops-online-shooter-fps/id1415791453?uo=4

       
       

      🤩 Hack Features

      - No Recoil
      - No Spread
      - No Flashbang Effect
      - No Smoke Effect
      - Red Crosshairs
      - Field of View Modifier
        • Like
      • 1 reply
    • Hanuman & Fighters Versus Evil v1.1 [+3 Jailed Cheats]
      Modded/Hacked App: Hanuman & Fighters Versus Evil By VOJOY GAMES PRIVATE LIMITED
      Bundle ID: com.vojoygames.hanumangame.ios
      App Store Link: https://apps.apple.com/us/app/hanuman-fighters-versus-evil/id6737682082?uo=4

       

      🤩 Hack Features

      - Enemy Can't Attack
      - Unlimited Gold
      - Unlock All Levels
        • Winner
      • 1 reply
    • Hanuman & Fighters Versus Evil v1.1 [+3 Cheats]
      Modded/Hacked App: Hanuman & Fighters Versus Evil By VOJOY GAMES PRIVATE LIMITED
      Bundle ID: com.vojoygames.hanumangame.ios
      App Store Link: https://apps.apple.com/us/app/hanuman-fighters-versus-evil/id6737682082?uo=4



      🤩 Hack Features

      - Enemy Can't Attack
      - Unlimited Gold
      - Unlock All Levels
       
        • Winner
      • 1 reply
    • Idle Army: Trading Weapons v1.12.2 [+5 Jailed Cheats]
      Modded/Hacked App: Idle Army: Trading Weapons By UNIMOB VIET NAM COMPANY LIMITED
      Bundle ID: com.unimob.idle.army
      App Store Link: https://apps.apple.com/us/app/idle-army-trading-weapons/id6670773625?uo=4



      🤩 Hack Features

      - Always Enough Resources (Gem, Skip Ads etc.)
      - Max Gold (Enable inside game)
      - 2x Game Speed (Enable inside game)
      - Kill Monster (Enable inside game)
      - Add All Pet

        • Winner
        • Like
      • 1 reply
    • Idle Army: Trading Weapons v1.12.2 [+5 Cheats]
      Modded/Hacked App: Idle Army: Trading Weapons By UNIMOB VIET NAM COMPANY LIMITED
      Bundle ID: com.unimob.idle.army
      App Store Link: https://apps.apple.com/us/app/idle-army-trading-weapons/id6670773625?uo=4

       

      🤩 Hack Features

      - Always Enough Resources (Gem, Skip Ads etc.)
      - Max Gold (Enable inside game)
      - 2x Game Speed (Enable inside game)
      - Kill Monster (Enable inside game)
      - Add All Pet

        • Winner
      • 2 replies
    • Margonem Adventures v1.16.2 [+3 Jailed Cheats]
      Modded/Hacked App: Margonem Adventures By GARMORY sp. z o.o. sp. k.
      Bundle ID: pl.Garmory.MargonemAdventures
      iTunes Store Link: https://apps.apple.com/us/app/margonem-adventures/id6444410609?uo=4

       

      🤩 Hack Features

      - Enemy Can't Move
      - Enemy Can't Attack
      - Unlimited Mana
        • Like
      • 18 replies
    • Margonem Adventures v1.16.2 [+3 Cheats]
      Modded/Hacked App: Margonem Adventures By GARMORY sp. z o.o. sp. k.
      Bundle ID: pl.Garmory.MargonemAdventures
      iTunes Store Link: https://apps.apple.com/us/app/margonem-adventures/id6444410609?uo=4



      🤩 Hack Features

      - Enemy Can't Move
      - Enemy Can't Attack
      - Unlimited Mana
        • Agree
        • Winner
        • Like
      • 11 replies
    • XP Hero v9.0.0 [+3 Cheats]
      Modded/Hacked App: XP Hero By Supercent Inc.
      Bundle ID: io.supercent.weaponrpg
      iTunes Store Link: https://apps.apple.com/us/app/xp-hero/id6740618570?uo=4



      🤩 Hack Features

      - Add Currency (Enable and You'll Recieve All Currency)
      - Add Xp
      - Enemy Can't Attack
       
        • Winner
        • Like
      • 7 replies
    • XP Hero v9.0.0 [+3 Jailed Cheats]
      Modded/Hacked App: XP Hero By Supercent Inc.
      Bundle ID: io.supercent.weaponrpg
      iTunes Store Link: https://apps.apple.com/us/app/xp-hero/id6740618570?uo=4



      🤩 Hack Features

      - Add Currency (Enable and You'll Recieve All Currency)
      - Add Xp
      - Enemy Can't Attack
        • Agree
        • Thanks
        • Winner
        • Like
      • 6 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