Help! Trying to hook timescale

nowhere_222

Just Crazy
Original poster
Jul 29, 2022
480
6,069
193
22
Inner Peace 🕊️
Hi, i'm wondering why my code didn't works on this hook..

C++:
//public void set_timeScale(float value) { } // class to hook

//the void *instance is a self-created variable.

void (*set_timeScale)(void *instance, float value);

float (*old_get_timeScale)(void *instance);
float get_timeScale(void *instance) {
    //Check if instance is NULL to prevent CRASH
    if (instance != NULL)
    {
        set_timeScale(instance, 9999); //Function Pointer mod
    }
    //return the original value (this code isn't really needed if you have a toggle/switch)
    return old_get_timeScale(instance);
}

MSHookFunction((void *) getAbsoluteAddress(targetLibName,
                                               string2Offset(OBFUSCATE_KEY("0x60e024", '?'))),
                   (void *)get_timeScale, (void **) &old_get_timeScale);

// Function pointer because we want to avoid crash when the il2cpp lib isn't loaded.

    set_timeScale = (void (*)(void *, float)) getAbsoluteAddress(targetLibName, 0x60e02c);
If someone can help me on this it would be great =))

nowhere222
 

Poison Modz

Approved Modder
Approved Modder
Aug 27, 2020
158
10,950
1,193
India
Try this

void (*old_get_timeScale)(void *instance);
void get_timeScale(void *instance) {
if (instance != NULL) {
if (TimeScale) {
set_timeScale(instance, 9999.0f);
}
}
return old_get_timeScale(instance);
}
 
  • Like
Reactions: nowhere_222

sobogamer_2020

Approved Modder
Approved Modder
Apr 6, 2022
375
14,532
1,193
23
Romania
Try this

void (*old_get_timeScale)(void *instance);
void get_timeScale(void *instance) {
if (instance != NULL) {
if (TimeScale) {
set_timeScale(instance, 9999.0f);
}
}
return old_get_timeScale(instance);
}
First, since its a void Offset (non-returnable), it wont work with return in the hook, and specifying the ".0f", at the end of the value, i don't think it helps too much, only if the game confuses the offset as a double one, its good to be safe, but it might not help with anything.
 
  • Like
Reactions: nowhere_222

shahzadk798

Rookie
Dec 23, 2022
1
0
1
34
Pakistan
How can i hook this Function..need help

public class Component : Object
[FreeFunctionAttribute] // RVA: 0x56101C Offset: 0x56101C VA: 0x56101C
// RVA: 0x1D955EC Offset: 0x1D955EC VA: 0x1D955EC
public Transform get_transform() { }

public class Transform : Component
// RVA: 0x2B4D720 Offset: 0x2B4D720 VA: 0x2B4D720
public void set_localScale(Vector3 value) { }
 

Poison Modz

Approved Modder
Approved Modder
Aug 27, 2020
158
10,950
1,193
India
#include "Includes/Vector3.hpp"

float isLocalPlayerSize;
void *(*get_transform)(void *component);
void (*Transform_set_localScale)(void *transform, Vector3);

void SetPlayerSize(void *transform, Vector3 scale) {
return Transform_set_localScale(get_transform(transform), scale);
}

void (*old_playersizeUpdate)(void *instance);
void playersizeUpdate(void *instance) {
if (instance != NULL) {
if(isLocalPlayerSize){
SetPlayerSize(instance, Vector3(isLocalPlayerSize, isLocalPlayerSize, isLocalPlayerSize));
}
}
old_playersizeUpdate(instance);
}

MSHookFunction((void *)getAbsoluteAddress("libil2cpp.so", Your Player Update Offset), (void *) playersizeUpdate, (void **) &old_playersizeUpdate);

get_transform = (void *(*)(void *))getAbsoluteAddress(targetLibName, 0x1D955EC);
Transform_set_localScale = (void (*)(void*, Vector3))getAbsoluteAddress(targetLibName, 0x2B4D720);

OBFUSCATE("SeekBar_Player Size_1_50"), //0 Case

case 0:
if (value >= 1) {
isLocalPlayerSize = value;
}
break;
 
  • Like
Reactions: ecoda and Jeff232

ryus

Platinian
Dec 9, 2018
9
6
3
28
mexico
Try this

void (*old_get_timeScale)(void *instance);
void get_timeScale(void *instance) {
if (instance != NULL) {
if (TimeScale) {
set_timeScale(instance, 9999.0f);
}
}
return old_get_timeScale(instance);
}
how can includ this timescale on the lgl patch mod method? any advice? i already know how create the lgl mod floating
 

sukiop

Solid & Active Platinian
Jul 2, 2020
84
18
53
19
iphone
#include "Includes/Vector3.hpp"

float isLocalPlayerSize;
void *(*get_transform)(void *component);
void (*Transform_set_localScale)(void *transform, Vector3);

void SetPlayerSize(void *transform, Vector3 scale) {
return Transform_set_localScale(get_transform(transform), scale);
}

void (*old_playersizeUpdate)(void *instance);
void playersizeUpdate(void *instance) {
if (instance != NULL) {
if(isLocalPlayerSize){
SetPlayerSize(instance, Vector3(isLocalPlayerSize, isLocalPlayerSize, isLocalPlayerSize));
}
}
old_playersizeUpdate(instance);
}

MSHookFunction((void *)getAbsoluteAddress("libil2cpp.so", Your Player Update Offset), (void *) playersizeUpdate, (void **) &old_playersizeUpdate);

get_transform = (void *(*)(void *))getAbsoluteAddress(targetLibName, 0x1D955EC);
Transform_set_localScale = (void (*)(void*, Vector3))getAbsoluteAddress(targetLibName, 0x2B4D720);

OBFUSCATE("SeekBar_Player Size_1_50"), //0 Case

case 0:
if (value >= 1) {
isLocalPlayerSize = value;
}
break;
Is ios okay?I tried it on ios, but it crashed
 

A7xk7y

Platinian
Mar 25, 2020
8
0
1
38
Belgium
I'm guessing you're trying to make speed hack with this. If you're modding an il2cpp unity game then there is a universally used function called timeScale that controls the game speed. It's static which means it doesn't have an instance. If it doesn't work then, in the same class, try deltaTime and FixedDeltaTime.


If you're not modding a unity game and your code didn't work then it could be that this isn't the method that controls the game speed or there are protections put in place or many other reasons, including: not the correct addresses, error with the function calling method, try an update method. Or an error with the inputted targetLibName.
 

nowhere_222

Just Crazy
Original poster
Jul 29, 2022
480
6,069
193
22
Inner Peace 🕊️
I'm guessing you're trying to make speed hack with this. If you're modding an il2cpp unity game then there is a universally used function called timeScale that controls the game speed. It's static which means it doesn't have an instance. If it doesn't work then, in the same class, try deltaTime and FixedDeltaTime.


If you're not modding a unity game and your code didn't work then it could be that this isn't the method that controls the game speed or there are protections put in place or many other reasons, including: not the correct addresses, error with the function calling method, try an update method. Or an error with the inputted targetLibName.
yes get_deltaTime from Time Unity class can make some sort of speedhack, called time hack, but i wanted to make it with timescale but couldn't, anyway i find another way to make speedhack and this is fast way
thanks for the help
 

SmilingSword

Platinian
Feb 17, 2018
38
17
8
31
yes get_deltaTime from Time Unity class can make some sort of speedhack, called time hack, but i wanted to make it with timescale but couldn't, anyway i find another way to make speedhack and this is fast way
thanks for the help
not all game using same class function, for example get_deltaTime, or time.timescale. sometime they hide it in another
 
  • Like
Reactions: nowhere_222

Davidenco

Rookie
Oct 9, 2020
1
0
1
23
Italy
yes get_deltaTime from Time Unity class can make some sort of speedhack, called time hack, but i wanted to make it with timescale but couldn't, anyway i find another way to make speedhack and this is fast way
thanks for the help
What's the other way you found pls i need it too