Help! public void .ctor can be used as update method?

Master TK

Platinian
Original poster
Nov 11, 2019
30
7
8
26
Brasil
public void .ctor Can be used as update method for hook field?

public float maxFallSpeed; // 0x24
// Methods

// RVA: 0x46E418 Offset: 0x46E418 VA: 0x46E418
public void .ctor() { }
}
 

Master TK

Platinian
Original poster
Nov 11, 2019
30
7
8
26
Brasil

NepMods69

Inactive Approved Modder
Mar 6, 2022
122
5,075
193
Nepal
BTW, FOR YOUR INFORMATION .ctor is not defined method, its full form is constructor, it os automatically added by the Compiler, so i don't think .ctor can Be hooked

You can do Multi class Hooking,
Like:
class:

class a {
int money; // 0x3
}

class b {
public a UserMoney; // 0x10

//0x11111111
public void update()
}

So, Now:
Hooking:

void(_Update)(void *thiz);
void UPDATE(void *thiz) {
if(thiz != NULL) {
void *aClass = *(void**)((uint64_t)thiz + 0x3);
if(a != NULL) {
*(int *) ((uint64_t) aClass + 0x10) = 999;
}
}
}
HOOK_LIB("LIBNAME", "0x11111111", UPDATE, _Update);
 

Raebydett

Awesome Active Platinian
Jan 20, 2020
171
60
28
G
Tbh theres some games that i used ctor as update method, it does work but its a lil buggy. You need to try yourself, try and error is the key thats how u learn. Not just hoping ppl to spoonfeed you
 

Script4fun

Platinian
Jan 29, 2020
23
15
193
India
Yes .ctor can be used for hooking but the problem is most classes doesn't call it often and most of the time it only get called once when game start loading. Better look if another class is calling it or not if it does then access it from that class. If nothing is working you can try a dirty fix (not sure if it will work or not)
1. Hook .ctor and modify field.
2. Also create a function pointer for .ctor
[Ctor = (void(*)(void *))getAbsoluteAddress(targetLibName, 0x123456);]
3. Now call it from any update function.
 

NepMods69

Inactive Approved Modder
Mar 6, 2022
122
5,075
193
Nepal
Yes .ctor can be used for hooking but the problem is most classes doesn't call it often and most of the time it only get called once when game start loading. Better look if another class is calling it or not if it does then access it from that class. If nothing is working you can try a dirty fix (not sure if it will work or not)
1. Hook .ctor and modify field.
2. Also create a function pointer for .ctor
[Ctor = (void(*)(void *))getAbsoluteAddress(targetLibName, 0x123456);]
3. Now call it from any update function.
Checked By yourself Personally or not?
 

DigitalKnight

Approved Modder
Approved Modder
Jul 31, 2018
185
10,998
1,193
23
Within the Heart
Yes .ctor can be used for hooking but the problem is most classes doesn't call it often and most of the time it only get called once when game start loading. Better look if another class is calling it or not if it does then access it from that class. If nothing is working you can try a dirty fix (not sure if it will work or not)
1. Hook .ctor and modify field.
2. Also create a function pointer for .ctor
[Ctor = (void(*)(void *))getAbsoluteAddress(targetLibName, 0x123456);]
3. Now call it from any update function.
Well among other things, that would create a new object on every frame. That's a high toll on memory
Also, .ctor might use a completely different object than the one actually being used in the game. So i am not sure how that would actually help in modifying those fields :)
 
Last edited:

DigitalKnight

Approved Modder
Approved Modder
Jul 31, 2018
185
10,998
1,193
23
Within the Heart
Also not to mention, you probably cannot pass a "*this"/instance to .ctor by using function ptr, as the instance would refer to the object where the update function resides
 
  • Like
Reactions: Script4fun

DigitalKnight

Approved Modder
Approved Modder
Jul 31, 2018
185
10,998
1,193
23
Within the Heart
Yes checked by myself (1st & 2nd option) but 3rd one its totally an experimental :pepe001:

C++:
void* globalInstance;

void (*_ctor)(void* this);
void ctor(void* this){
  if(this != NULL){
     globalInstance = this;
    }
    _ctor(this);
}

void (*_update)(void* this);
void update(void* this){
    if(this != NULL && globalInstance != NULL){
      *(int *)((uint_64t)globalInstance + 0x24) = 0;
     }
     _update(this)
}

HOOK(.ctor//);
HOOK(update//);
Here is a code that might work. The only limitation is that the ctor must be called at least once lol. If it's called more than once, you will lose access to previous objects
 
Last edited:
  • Haha
Reactions: Script4fun

DigitalKnight

Approved Modder
Approved Modder
Jul 31, 2018
185
10,998
1,193
23
Within the Heart
Well among other things, that would create a new object on every frame. That's a high toll on memory
Also, .ctor might use a completely different object than the one actually being used in the game. So i am not sure how that would actually help in modifying those fields :)
Also discard this, it seems like .ctor is only responsible to run the code in the constructor. It's not responsible for the actual object creation in il2cpp. But the second point holds
 
  • Like
Reactions: Script4fun

Master TK

Platinian
Original poster
Nov 11, 2019
30
7
8
26
Brasil
C++:
void* globalInstance;

void (*_ctor)(void* this);
void ctor(void* this){
  if(este != NULL){
     globalInstance = this;
    }
    _ctor(este);
}

void (*_update)(void* this);
void update(void* this){
    if(this != NULL && globalInstance != NULL){
      *(int *)((uint_64t)globalInstance + 0x24) = 0;
     }
     _atualizar(este)
}

GANCHO(.ctor//);
HOOK(atualizar //);
Aqui está um código que pode funcionar. A única limitação é que o ctor deve ser chamado pelo menos uma vez rs. Se for chamado mais de uma vez, você perderá o acesso aos objetos anteriores
[/CITAR]
Bgood, try to use it but it didn't work, there was no change in the value
 

NepMods69

Inactive Approved Modder
Mar 6, 2022
122
5,075
193
Nepal
I think same, . ctor (Constructor) cant be used to hook. If the game calles it then it will work, else it wont.