Help! Help in getting instance

HekaHeka709

Solid & Active Platinian
Original poster
Dec 29, 2021
56
6
8
19
Phillipines
Hello dear community,

I have this code

void *Inst;

void (*AddMoneyExample)(void *instance, int amount);
void _AddMoneyExample(void *instance, int amount) {
if (instance != NULL) {
Inst = instance;
}
AddMoneyExample(instance, amount);
}

It gets instance when AddMoney is called. It does work but can i get the address of instance so that function pointer works even addmoney is not called?

I'll wait for help thank you in advance
 

DigitalKnight

Approved Modder
Approved Modder
Jul 31, 2018
190
8,408
193
22
Within the Heart
If you are talking about a getting a constant address/offset like methods etc, then no. Instance/objects are dynamically allocated and each time their address will be entirely different.

You can still pass the inst pointer to your function pointer and it will work, but the original function have to be called at least once beforehand
 

HekaHeka709

Solid & Active Platinian
Original poster
Dec 29, 2021
56
6
8
19
Phillipines
If you are talking about a getting a constant address/offset like methods etc, then no. Instance/objects are dynamically allocated and each time their address will be entirely different.

You can still pass the inst pointer to your function pointer and it will work, but the original function have to be called at least once beforehand
[
If you are talking about a getting a constant address/offset like methods etc, then no. Instance/objects are dynamically allocated and each time their address will be entirely different.

You can still pass the inst pointer to your function pointer and it will work, but the original function have to be called at least once beforehand
Like what i just did? But i think it'll be useless but thank you
 

DigitalKnight

Approved Modder
Approved Modder
Jul 31, 2018
190
8,408
193
22
Within the Heart
This is your best bet
C++:
void* instptr;

void (*_addMoney)(void* instance, int amount);
void addMoney(void* instance, int amount){
  if(instance != NULL)
    instptr = instance;
    _addMoney(instance, amount);
   }
}

// A function pointer to addMoney function

void (*addMoneyPtr)(void* instance, int amount);

//Now you can call it anywhere, for example inside an update function like so

void (*_update)(void* instance);
void update(void* instance){
   if(instance != NULL && instptr != NULL){
    addMoneyPtr(instptr, <your amount>);
    }
    _update(instance);
}
 

HekaHeka709

Solid & Active Platinian
Original poster
Dec 29, 2021
56
6
8
19
Phillipines
Unfortunately i didnt find any update function i also tried finding a function that is called every time addmoney is called and i had bo luck. Is it possible that the instance cant be in the dump?
 

DigitalKnight

Approved Modder
Approved Modder
Jul 31, 2018
190
8,408
193
22
Within the Heart
Anyways, putting this particular function inside an update makes no sense. You wouldn't want the money getting increased on every frame.
The point was to help you understand about your particular question and how instance/this pointer works
 
  • Like
Reactions: jollong

HekaHeka709

Solid & Active Platinian
Original poster
Dec 29, 2021
56
6
8
19
Phillipines
Anyways, putting this particular function inside an update makes no sense. You wouldn't want the money getting increased on every frame.
The point was to help you understand about your particular question and how instance/this pointer works
It's fine now i found a function that is called every time something happens in the game in the same class as addMoney and the hook look like this

void *Inst;

AddMoneyExample(void *instance, int amount);

void (*ExampleFunction)(void *instance, int param); // FUNCTION THAT IS CALLED EVERYTIME
void _ExampleFunction(void *instance, int param) {
if (instance != NULL) {
LOGD("GETTING INSTANCE");
Inst = instance;
LOGD("DONE");
}
ExampleFunction(instance, param);
}

and i dont want that every time the function is called money will be added so i use function pointer in a button

case 115:
if (Inst != NULL) {
AddMoneyExample(Inst, 99999);
LOGD("MONEY IS ADDED");
}
break;

Works like a charm
 

Viktorovich31

Platinian
Sep 16, 2022
38
0
6
41
Russian
Теперь все в порядке, я нашел функцию, которая поднималась каждый раз, когда в игре что-то происходит в том же классе, что и addMoney, и хук выглядит так

недействующим *Inst;

AddMoneyExample(void *instance, целое количество);

void (*ExampleFunction)(void *instance, int param); // ФУНКЦИЯ, КОТОРАЯ ВЫЗЫВАЕТСЯ КАЖДЫЙ РАЗ
void _ExampleFunction (void * instance, int param) {
если (экземпляр != NULL) {
ЛОГД("ПОЛУЧЕНИЕ ЭКЗЕМПЛЯРА");
Инст = экземпляр;
ЛОГД("ГОТОВО");
}
ExampleFunction(экземпляр, параметр);
}

и я не хочу, чтобы каждый раз, когда функция подъема, деньги добавлялись, поэтому я рекомендую указывать функцию в учете

дело 115:
если (Inst != NULL) {
AddMoneyExample(Inst, 99999);
LOGD("ДЕНЬГИ ЗАЧИСЛЕНЫ");
}
ломать;

Работает как шарм
[/ЦИТИРОВАТЬ]
Здравствуйте! Может показать весь код (Main.cpp)
 

About us

  • Welcome to platinmods.com! We are proud to present you the place which let's dreams come true! Focusing on quality and trust we have spend much time to build a gaming community fitting to your wishes and needs. Actually we offer you the finest MODs and Games of the Android section and we slowly expand to the iOS section as well. But games, Android MODs & iOS MODs are not the only things we can offer you. We have tutorials, tools, a very friendly, active and solid community which will help you with any problem you have =) Your happiness is our goal. We hope you enjoy!

Forum statistics

Threads
52,795
Messages
1,787,423
Members
3,135,036
Latest member
malucki