| View previous topic :: View next topic |
| Author |
Message |
lontongmalam Newbie cheater
Reputation: 0
Joined: 13 Apr 2022 Posts: 17
|
Posted: Mon Nov 20, 2023 7:16 am Post subject: Random Number In Range |
|
|
Hello everyone,
I need some help. I want to generate a random number between two given values.
Here are the details:
| Quote: |
[r14+000001FC] -> Contains min range
[r14+000001FE] -> Contains max range
|
The max value is 200. For example:
| Quote: |
[r14+000001FC] -> 78
[r14+000001FE] -> 192
|
I want to make it somehow like this:
| Quote: |
[r14+000001FC] -> 133
[r14+000001FE] -> 192
|
Thank you!
|
|
| Back to top |
|
 |
LeFiXER Grandmaster Cheater Supreme
Reputation: 20
Joined: 02 Sep 2011 Posts: 1069 Location: 0x90
|
Posted: Mon Nov 20, 2023 9:31 am Post subject: |
|
|
You can just simply use a register to set the value of [r14+1FC] like so:
| Code: |
...
push rbx // Store what's held in RBX
mov rbx,#133 // Move int 133 into RBX
mov [r14+1FC],rbx // Move the value held in RBX to [r14+1FC]
pop rbx // Restore value that was held in RBX before we used it
...
|
|
|
| Back to top |
|
 |
lontongmalam Newbie cheater
Reputation: 0
Joined: 13 Apr 2022 Posts: 17
|
Posted: Mon Nov 20, 2023 9:39 am Post subject: |
|
|
| LeFiXER wrote: | You can just simply use a register to set the value of [r14+1FC] like so:
| Code: |
...
push rbx // Store what's held in RBX
mov rbx,#133 // Move int 133 into RBX
mov [r14+1FC],rbx // Move the value held in RBX to [r14+1FC]
pop rbx // Restore value that was held in RBX before we used it
...
|
|
Thanks for the reply.
However, it is expected to be a randomly generated number between 78 and 192, rather than the fixed one. That above is my example of the result.
|
|
| Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1526
|
Posted: Mon Nov 20, 2023 11:55 am Post subject: |
|
|
Ridiculous or ordinary ..
There must be similar ideas ..
| Code: |
{$lua}
local num = math.random(78,192)
local res = "#"..tonumber(num)
{$asm}
push rbx // Store what's held in RBX
mov rbx,res // #133 Move int 133 into RBX
mov [r14+1FC],rbx // Move the value held in RBX to [r14+1FC]
pop rbx |
_________________
|
|
| Back to top |
|
 |
lontongmalam Newbie cheater
Reputation: 0
Joined: 13 Apr 2022 Posts: 17
|
Posted: Mon Nov 20, 2023 12:25 pm Post subject: |
|
|
| AylinCE wrote: | Ridiculous or ordinary ..
There must be similar ideas ..
| Code: |
{$lua}
local num = math.random(78,192)
local res = "#"..tonumber(num)
{$asm}
push rbx // Store what's held in RBX
mov rbx,res // #133 Move int 133 into RBX
mov [r14+1FC],rbx // Move the value held in RBX to [r14+1FC]
pop rbx |
|
I can do that in lua, but I need assembly codes as it would run faster.
Also, you need to get the min, max value from r14.
I think I found a topic similiar like this, but I have no idea how to change that into my request.
cheatengine*org/forum/viewtopic.php?p=5638667&sid=f4105b9b0798d0924764843446ddfef2
Last edited by lontongmalam on Mon Nov 20, 2023 12:29 pm; edited 1 time in total |
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4706
|
Posted: Mon Nov 20, 2023 12:28 pm Post subject: |
|
|
| lontongmalam wrote: | The max value is 200. For example:
| Quote: | [r14+000001FC] -> 78
[r14+000001FE] -> 192 |
| Where's the 200?
| lontongmalam wrote: | | Quote: |
[r14+000001FC] -> Contains min range
[r14+000001FE] -> Contains max range
|
...
I want to make it somehow like this:
| Quote: | [r14+000001FC] -> 133
[r14+000001FE] -> 192 |
| You want to change the minimum value to be a random value? That's just going to converge to the max value every iteration.
Give more information regarding what you want to do.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
lontongmalam Newbie cheater
Reputation: 0
Joined: 13 Apr 2022 Posts: 17
|
Posted: Mon Nov 20, 2023 12:33 pm Post subject: |
|
|
| ParkourPenguin wrote: | | lontongmalam wrote: | The max value is 200. For example:
| Quote: | [r14+000001FC] -> 78
[r14+000001FE] -> 192 |
| Where's the 200?
| lontongmalam wrote: | | Quote: |
[r14+000001FC] -> Contains min range
[r14+000001FE] -> Contains max range
|
...
I want to make it somehow like this:
| Quote: | [r14+000001FC] -> 133
[r14+000001FE] -> 192 |
| You want to change the minimum value to be a random value? That's just going to converge to the max value every iteration.
Give more information regarding what you want to do. |
Yes, I want give a new value to [r14+1FC] based on what number between [r14+1FC] and [r14+1FE]. And it should be not greater than [r14+1FE].
Like this:
| Code: |
{$lua}
local a = readByte(num+0x1FC)
local b = readByte(num+0x1FE)
writeByte(num+0x1FC, math.random(a,b))
{$asm}
mov [num],r14
num:
dq 0
|
But it really slowdown the process, that's why I want these codes in asm, like fully asm.
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4706
|
Posted: Mon Nov 20, 2023 1:07 pm Post subject: |
|
|
| lontongmalam wrote: | | Yes, I want give a new value to [r14+1FC] based on what number between [r14+1FC] and [r14+1FE]. And it should be not greater than [r14+1FE]. | That's just going to converge to the maximum value. There would no longer be any randomness after a few iterations.
| Code: | low - high -> rand_val
1: 10 - 100 -> 69
2: 69 - 100 -> 88
3: 88 - 100 -> 98
4: 98 - 100 -> 100
5: 100 - 100 -> 100
6: 100 - 100 -> 100
... |
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1526
|
Posted: Mon Nov 20, 2023 1:23 pm Post subject: |
|
|
| ParkourPenguin wrote: | | [quote=That's just going to converge to the maximum value. There would no longer be any randomness after a few iterations. |
The "[r14+1FC] and [r14+1FE]" values may be constantly changing during the game.
In other words, arbitrary value assignment is only possible if the script is enabled, if it is not tied to a timer.
And if not disabled it may be getting fixed to random value.
_________________
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4706
|
Posted: Mon Nov 20, 2023 1:42 pm Post subject: |
|
|
Alright.
There's probably some `int rand(void)` function exported by some dll; try to use that.
| Code: | [ENABLE]
...
{$c}
extern int rand(void);
int randbetween(int low, int high) {
return rand() % (high - low + 1) + low;
}
{$asm}
...
newmem:
{$ccode ptr=r12}
char *data = (char *)ptr;
const short *minp = (short *)(data + 0x1FC);
const short *maxp = (short *)(data + 0x1FE);
*minp = randbetween(*minp, *maxp);
{$asm}
...
[DISABLE]
...
| {$ccode} is probably fast enough. It's basically assembly.
If not, go implement your own random number genrator.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
lontongmalam Newbie cheater
Reputation: 0
Joined: 13 Apr 2022 Posts: 17
|
Posted: Mon Nov 20, 2023 2:10 pm Post subject: |
|
|
| ParkourPenguin wrote: | Alright.
There's probably some `int rand(void)` function exported by some dll; try to use that.
| Code: | [ENABLE]
...
{$c}
extern int rand(void);
int randbetween(int low, int high) {
return rand() % (high - low + 1) + low;
}
{$asm}
...
newmem:
{$ccode ptr=r12}
char *data = (char *)ptr;
const short *minp = (short *)(data + 0x1FC);
const short *maxp = (short *)(data + 0x1FE);
*minp = randbetween(*minp, *maxp);
{$asm}
...
[DISABLE]
...
| {$ccode} is probably fast enough. It's basically assembly.
If not, go implement your own random number genrator. |
Thanks, I tried to make it like this, I think it similiar:
| Code: |
push rax
push rdx
push rbx
push r10
xor r10,r10
xor rbx,rbx
rdtsc
xor edx,edx
mov bl,[r14+1FE]
mov r10b,[r14+1FC]
sub bl,r10b
inc bl
div ebx // edx is the remainder
add dl,r10b
mov byte ptr [r14+1FC],dl
pop r10
pop rbx
pop rdx
pop rax
|
|
|
| Back to top |
|
 |
|