Jump to content

PixelYT

Member
  • Posts

    59
  • Joined

  • Last visited

Posts posted by PixelYT

  1. Let's say I have this method:

    private int AmmoAmount(){}; // 0xOFFSET

    And I wanted hook it and multiply or add my current ammo amount instead of returning an exact value. How would I do that? Is this how I would do it? Example:

    int (*old_AmmoAmount)(void *instance);
    int AmmoAmount(void *instance)
    {
    return old_AmmoAmount(instance) * 10; // Return whatever my current ammo is multiplied by 10
    }
    return old_AmmoAmount(instance); //Just return exact original value
    }
    // MSHOOKFUNCTION

    Would that work? Basically what I want to do is using arithmetic operators to change my ammo instead of returning an exact value in the hook like we do return 99999;

    @Ted2I am sorry for bothering you, but I hope you help me because you are the only one helping people and the android help section is very inactive

  2. @Ted2 I just have one more quick question, that i'll ask here, I already asked on another site, but didn't receive a good response. So there was one class called IAPManager or something like that, and inside it there were many useful functions that if called, would buy you whatever it is supposed to, but inside that class there was no Update/LateUpdate/FixedUpdate method (I know in some cases they can be renamed, but I looked and that wasn't the case), so would I hook Start or Awake and call those functions through a function pointer? Which one works, or does neither work?

  3. 8 hours ago, Ted2 said:

    No, in programming you have getters and setters;

    
    int getCoins() {
    	return coins
    }
    
    void setCoins(int newValue) {
    	coins = new_value
    }

    As you can see, to one of those functions you can pass a new value (SET). The other one just returns a variable (GET).

    Function pointers are not any different, because the function pointer is that function and so, they work the same.

     

    If for some reason you don't want to hook it, then I recommend opening the binary in IDA, go to the ReloadDuration method, and see which variable(s) is being used here (0x<some_value>. I assume this is an Unity game, so on top of the class ReloadDuration is in, you'll find a list of variables. See which one of them is inside ReloadDuration.

    You can then change these variables in the FixedUpdate method, like so:

    
    *(int*)((uint64_t)instance + 0x<variable_code> = 0;

     

    Okay, I don't have a problem with hooking, it's just that I wanted to know if it was possible to set a value to a function inside a hook, but other than that, I have no problem patching or hooking the function.

  4. Let's say I found this method and I wanna change the value to 0:

    private int ReloadDuration(); // 0x2347C82

    I would just do it by hooking it and returning 0 like this:

    int (*old_ReloadDuration)(void *instance);
    int ReloadDuration(void *instance)
    {
      if(instance != NULL)
      {
       return 0; 
      }
      return old_ReloadDuration(instance);
    }
    // MShookfunction whatever lol

     

    But can I do it by making a function pointer and changing the value of it inside a hook and how would I do it?

    Would I do it like this?

    int (*ReloadDuration)(void *instance) = (int (*)(void *))getAbsoluteAddress(targetLibName, 0xOFFSET); // Function pointer for int ReloadDuration
    
    void (*old_FixedUpdate)(void *instance);
    void FixedUpdate(void *instance)
    {
     if(instance != NULL)
     {
      int Reloadtime = ReloadDuration(instance); // Declare a variable to our function pointer and call it ReloadTime
       int ReloadTime = 0; // Set the value to 0
     }
      old_FixedUpdate(instance);
    }
    // MSHookfunction of Fixedupdate, whatever

     

    @Ted2 you or anyone can help me please?

  5. 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);

     

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