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 


why can not i specify the "address"?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
cd&
Newbie cheater
Reputation: 0

Joined: 08 Apr 2023
Posts: 20

PostPosted: Mon Apr 17, 2023 9:12 am    Post subject: why can not i specify the "address"? Reply with quote

writeFloat("[game.exe+01016E44]+660",v_default[1]+text1.text/1000)
→it works as i intend
writeFloat("[game.exe+01016E44]+0x630+0x30",v_default[1]+text1.text/1000)
→it works as i intend
offset_1=0x630
writeFloat("[game.exe+01016E44]+offset_1+0x30",v_default[1]+text1.text/1000)
→it works as i intend

function f2(offset)
writeFloat("[game.exe+01016E44]+offset+0x30",v_default[1]+text1.text/1000)
end
offset_1=0x630
f2(offset_1)
→it doesn't work as i intend(with no error)

why is it happens?
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1069
Location: 0x90

PostPosted: Mon Apr 17, 2023 12:51 pm    Post subject: Reply with quote

I can't say for sure, but maybe scope has something to do with why it's not working.

Try this:
Code:

function f2(offset)
local o = offset
if o == nil then print('Invalid offset') end
if (type)o == 'number' then o:format('%X') end
writeFloat("game.exe+01016E44]+o+0x30",v_default[1]+text1.text/1000)
end

local offset_1=0x630
f2(offset_1)
Back to top
View user's profile Send private message
cd&
Newbie cheater
Reputation: 0

Joined: 08 Apr 2023
Posts: 20

PostPosted: Mon Apr 17, 2023 9:38 pm    Post subject: Reply with quote

thank you for your reply
do you mean below?:

function f2(offset)
local o = offset
if o == nil then print('Invalid offset') end
if type(o) == 'number' then o:format('%X') end
writeFloat("game.exe+01016E44]+o+0x30",v_default[1]+text1.text/1000)
end
local offset_1=0x630
f2(offset_1)

i try this code. and error: attempt to index a number value(local 'o')
maybe because of o:format('%X')

and i try below

function f2(offset)
local o = offset
writeFloat("game.exe+01016E44]+o.format('%X') +0x30",v_default[1]+text1.text/1000)
end
local offset_1=0x630
f2(offset_1)

it doesn't work as I intend(with no error)
[/b][/code]
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1069
Location: 0x90

PostPosted: Tue Apr 18, 2023 6:58 am    Post subject: Reply with quote

cd& wrote:
thank you for your reply
do you mean below?:

function f2(offset)
local o = offset
if o == nil then print('Invalid offset') end
if type(o) == 'number' then o:format('%X') end
writeFloat("game.exe+01016E44]+o+0x30",v_default[1]+text1.text/1000)
end

local offset_1=0x630
f2(offset_1)

i try this code. and error: attempt to index a number value(local 'o')
maybe because of o:format('%X')

and i try below

function f2(offset)
local o = offset
writeFloat("game.exe+01016E44]+o.format('%X') +0x30",v_default[1]+text1.text/1000)
end
local offset_1=0x630
f2(offset_1)

it doesn't work as I intend(with no error)
[/b][/code]


This is the whole code:
Code:

function f2(offset)
  local o = string.format('%X',offset)
  if o == nil then print('Invalid offset') end
  writeFloat("[game.exe+01016E44]+0x"..o.."+0x30",v_default[1]+text1.text/1000)
end

local offset_1=0x630
f2(offset_1)


It should work as intended.
Back to top
View user's profile Send private message
cd&
Newbie cheater
Reputation: 0

Joined: 08 Apr 2023
Posts: 20

PostPosted: Tue Apr 18, 2023 7:55 am    Post subject: Reply with quote

thank you for your code.
after my post, i struggle with this. and i found:

function f2(offset)
writeFloat("[game.exe+01016E44]+offset+0x30",v_default[1]+text1.text/1000)
end
offset_1=0x630
f2(offset_1)
→it doesn't work as i intend(with no error)
function f2(offset)
local o1=offset
writeFloat("[game.exe+01016E44]+o1+0x30",v_default[1]+text1.text/1000)
end
offset_1=0x630
f2(offset_1)
→it works as i intend

i think your code works because your idea is similar to mine
problem is solved. but why?
it is extraordinary strange!! why is it happened?!
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1069
Location: 0x90

PostPosted: Tue Apr 18, 2023 8:01 am    Post subject: Reply with quote

When you specify the address as a string, writeFloat expects it as such. 0x630 is a number value in hexadecimal format. If you test this code you will see why:
Code:

print(0x630)


It should print 1584, to the log. It's because it converts it to a number value. When writing to an address as a string it requires a literal string rather than a number so we must use the string.format function to format it as such.
Back to top
View user's profile Send private message
cd&
Newbie cheater
Reputation: 0

Joined: 08 Apr 2023
Posts: 20

PostPosted: Tue Apr 18, 2023 8:42 am    Post subject: Reply with quote

function f2(offset)

writeFloat("[game.exe+01016E44]+string.format('%X',offset)+0x30",v_default[1]+text1.text/1000)
end
offset_1=0x630
f2(offset_1)
→it doesn't work as i intend

function f2(offset)
local o1=offset
writeFloat("[game.exe+01016E44]+o1+0x30",v_default[1]+text1.text/1000)
end
offset_1=0x630
f2(offset_1)
→it works as i intend

why does my code work as i intend? if your reply is right, o1 should be not 0x630 but 1584.
but it is compiled to 0x630
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1069
Location: 0x90

PostPosted: Tue Apr 18, 2023 9:15 am    Post subject: Reply with quote

To explain here:
Code:

function f2(offset)

writeFloat("game.exe+01016E44]+string.format('%X',offset)+0x30",v_default[1]+text1.text/1000)
end
offset_1=0x630
f2(offset_1)
→it doesn't work as i intend


The first argument passed to the writeFloat function is a literal string:
Code:

"game.exe+01016E44]+string.format('%X',offset)+0x30"


You are asking Cheat Engine to write a float to the address
"game.exe+01016E44]+string.format('%X',offset)+0x30"

You are also missing the opening square bracket "[" at the beginning of your string.
Back to top
View user's profile Send private message
cd&
Newbie cheater
Reputation: 0

Joined: 08 Apr 2023
Posts: 20

PostPosted: Tue Apr 18, 2023 12:50 pm    Post subject: Reply with quote

not the main point, I didn't miss the opening square bracket "[" at the beginning of your string.maybe you miss-copied.

I understand string.format→literal. so,"game.exe+01016E44]+string.format('%X',offset)+0x30" means "number+string+number"
thank you


function f2(offset)
writeFloat("[game.exe+01016E44]+offset+0x30",v_default[1]+text1.text/1000)
end
offset_1=0x630
f2(offset_1)
→it doesn't work as i intend(with no error)
does it mean variable offset become literal?

function f2(offset)
local o1=offset
writeFloat("[game.exe+01016E44]+o1+0x30",v_default[1]+text1.text/1000)
end
offset_1=0x630
f2(offset_1)
→it works as i intend
why doesn't variable o1 become literal?
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1069
Location: 0x90

PostPosted: Tue Apr 18, 2023 1:12 pm    Post subject: Reply with quote

Perhaps there is a mistranslation somewhere. The parameters required by the function:
Code:

writeFloat(address, new_value)


Where address can either be a number or a string:
Code:

Number: 0x00040000
String: "[game.exe]+10"


If you must include numbers within the string within Lua you must concatenate the values by using double-period like so:
Code:

local my_value = 100
"[[game.exe]+10]+" .. string.format("%X", my_value)


But to answer your question. o1 is not a literal string value because you haven't cast it as such in the function you defined. For this you must use string.format to convert a number to a string value. I would highly suggest you do some reading on Lua to better understand how it works.
Back to top
View user's profile Send private message
cd&
Newbie cheater
Reputation: 0

Joined: 08 Apr 2023
Posts: 20

PostPosted: Tue Apr 18, 2023 11:12 pm    Post subject: Reply with quote

ah-ha.i'm starting to understand little by little.
(I understand string.format→....."number+string+number") is totally wrong.
i wrote writeFloat(string,new_value).because of that, numerical calculation is not possible.
but just for "[game.exe]+number" writeFloat can calculate(because writeFloat is for hacking the game).
so,
"[game.exe+01016E44]+660"
"[game.exe+01016E44]+0x630+0x30"
offset_1=0x630 "[game.exe+01016E44]+offset_1+0x30"
is ok. and nevertheless type(offset)==number,
function f2(offset)
writeFloat("[game.exe+01016E44]+offset+0x30",v_default[1]+text1.text/1000)
end
offset_1=0x630
f2(offset_1)
→it doesn't work as i intend(with no error)
is bad.

is it right?
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4707

PostPosted: Tue Apr 18, 2023 11:24 pm    Post subject: Reply with quote

I'm shook this works:
Code:
foo = 5
print(getAddress'0+foo')
-- output:
-- 5
Kind of weird it only works with globals.

Anyway, here, `offset` is a local:
Code:
-- does NOT work: `offset` is not a global
function f2(offset)
  writeFloat("[game.exe+01016E44]+offset+0x30",v_default[1]+text1.text/1000)
end

Do the pointer arithmetic manually:
Code:
function f2(offset)
  writeFloat(readPointer"game.exe+01016E44"+offset+0x30,v_default[1]+text1.text/1000)
end
`readPointer` returns a number. Numbers can be safely added with other numbers. If `offset` is not a number, convert it to a number first with `tonumber(...)`
_________________
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
cd&
Newbie cheater
Reputation: 0

Joined: 08 Apr 2023
Posts: 20

PostPosted: Wed Apr 19, 2023 4:31 am    Post subject: Reply with quote

>Kind of weird it only works with globals.
I'm getting to feel weird too.

function f2(offset) writeFloat(readPointer("game.exe+01016E44")+offset+0x30,v_default[1]+text1.text/1000)
end
your code is most readable and simple i 've ever seen. Let me adopt your code.
thank you
Back to top
View user's profile Send private message
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