Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


How to convert values to other numbers

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
ImmortalZypther
How do I cheat?
Reputation: 0

Joined: 28 Dec 2019
Posts: 7

PostPosted: Sat Dec 28, 2019 2:09 pm    Post subject: How to convert values to other numbers Reply with quote

I have a value that needs to be added to and then multiplied to get a different number that I can use.
Just as an example, let's say I have x as the value. I need to add y and then multiply by z to get z(x + y).
I don't want the value to actually change in game, I just need the value to change for the user.
Is there a way to get this to show in the value column of Cheat Engine? I have coding experience in other languages, but none in Lua or Assembly, so please give me additional instructions.

Additionally, is it possible to have this work in the opposite direction? So if I input z(x + y) into the value column, it'll push x back to the game.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4711

PostPosted: Sat Dec 28, 2019 3:49 pm    Post subject: Reply with quote

Use a custom value type. Right click the value type drop-down list and select "define new custom type" (AA or Lua). AA is better in general.

I can give an example if you give more information. What type of value you're looking at (i.e. integer or floating point), and do y or z ever change?

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
ImmortalZypther
How do I cheat?
Reputation: 0

Joined: 28 Dec 2019
Posts: 7

PostPosted: Sat Dec 28, 2019 4:29 pm    Post subject: Reply with quote

I found the new custom type menu, what should I type into there?

The value is a 2 byte integer, shouldn't be a float because there's no decimal
y and z never change, they're always the same value I need to add and then multiply by.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4711

PostPosted: Sat Dec 28, 2019 9:09 pm    Post subject: Reply with quote

This may work (haven't tested it):
Code:
alloc(ConvertRoutine,1024)
alloc(ConvertBackRoutine,1024)
alloc(TypeName,256)
alloc(ByteSize,4)
alloc(UsesFloat,1)
alloc(CallMethod,1)

// these are in hexadecimal
define(CONST_ADD,C)
define(CONST_MUL,7)

TypeName:
db '2 Byte Add Mul',0

ByteSize:
dd 2

UsesFloat:
db 0

CallMethod:
db 1

// cdecl int ConvertRoutine(unsigned char *input, PTR_UINT address);
ConvertRoutine:
[64-bit]
  movsx eax,word ptr[rcx]
[/64-bit]
[32-bit]
  mov eax,[esp+4]
  movsx eax,word ptr[eax]
[/32-bit]
  add eax,CONST_ADD
  imul eax,eax,CONST_MUL
  ret

// cdecl void ConvertBackRoutine(int i, PTR_UINT address, unsigned char *output);
ConvertBackRoutine:
[64-bit]
  mov eax,ecx
  mov r9d,CONST_MUL
  cdq
  idiv r9d
  sub eax,CONST_ADD
  mov word ptr[r8],ax
[/64-bit]
[32-bit]
  mov eax,[esp+4]
  mov ecx,CONST_MUL
  cdq
  idiv ecx
  mov ecx,[esp+C]
  sub eax,CONST_ADD
  mov word ptr[ecx],ax
[/32-bit]
  ret

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
ImmortalZypther
How do I cheat?
Reputation: 0

Joined: 28 Dec 2019
Posts: 7

PostPosted: Sun Dec 29, 2019 8:50 am    Post subject: Reply with quote

It works, many thanks to you!

I'm guessing you change these lines to see what to add and multiply by?
Code:
define(CONST_ADD,C)
define(CONST_MUL,7)
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4711

PostPosted: Sun Dec 29, 2019 11:19 am    Post subject: Reply with quote

Yes - change the text between the comma "," and closing parenthesis ")" to whatever hexadecimal integer you want.
_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25819
Location: The netherlands

PostPosted: Sun Dec 29, 2019 1:42 pm    Post subject: Reply with quote

You can also do it on a per memoryrecord item

e.g:
Code:

y=1
z=2

AddressList[0].OnGetDisplayValue=function(mr,currentvalue)
  local vi=tonumber(currentvalue)
  if vi then
    vi=vi+y*z
    return true,vi
  else
    return true,'What the fuck is this value?'
  end
end


This will set the first memory record to (value+y)*z , assuming it can be read and you can update y and z at runtime.

Just visual though (you could use the addresslist's OnValueChange method to override it)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
ImmortalZypther
How do I cheat?
Reputation: 0

Joined: 28 Dec 2019
Posts: 7

PostPosted: Mon Dec 30, 2019 6:47 am    Post subject: Reply with quote

Dark Byte wrote:
You can also do it on a per memoryrecord item

e.g:
Code:

y=1
z=2

AddressList[0].OnGetDisplayValue=function(mr,currentvalue)
  local vi=tonumber(currentvalue)
  if vi then
    vi=vi+y*z
    return true,vi
  else
    return true,'What the fuck is this value?'
  end
end


This will set the first memory record to (value+y)*z , assuming it can be read and you can update y and z at runtime.

Just visual though (you could use the addresslist's OnValueChange method to override it)


Sorry, I don't understand where to use this code. Do I right click the value type and make another custom value?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25819
Location: The netherlands

PostPosted: Mon Dec 30, 2019 6:53 am    Post subject: Reply with quote

it's lua code. Ctrl+shift+alt+L and paste and run
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites