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 read the value of a 3 byte address
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1249

PostPosted: Thu Mar 31, 2022 12:33 pm    Post subject: Reply with quote

Just take the length you want to change and replace it with the number you want.

Code:
local value = 0x024B1AF0, "+04" -- or address, "+4"
--value = 80 12 01 08 (134288000)
writeInteger(value,70000)
--value new= 70 11 01 00 (70000)

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Thu Mar 31, 2022 12:40 pm    Post subject: Reply with quote

Um I don't wish to replace the value I would want to add the value the one in the 3-byte address and the number chosen(70000). The number added could be anything I just chose 70000, it could be anything into the value defined by the 3-byte address. In this case 3e 92 03 + 70000., at the same address as the 3e 92 03 is/was in.
Back to top
View user's profile Send private message Yahoo Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1249

PostPosted: Thu Mar 31, 2022 2:07 pm    Post subject: Reply with quote

This is how the code is collected and changes with the new value if you want.

( Address and numbers are examples. )

Code:
addr=0x0B005490
newvalue=70000

value1=readInteger(addr) + tonumber(newvalue)
print(readInteger(addr)) -- 80 21 08 (532864)
print(value1) --(602864)

writeInteger(addr,tonumber(value1))
--value new= F0 32 09 (602864)


Or exemplify what you want to say in a short code.

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Thu Mar 31, 2022 2:39 pm    Post subject: Reply with quote

Code:

addr=0x54c0e4
newvalue=70000

value1=readInteger(addr) + tonumber(newvalue)
print(readInteger(addr))
print(value1)

writeInteger(addr,tonumber(value1))


Output
4093661172
4093731172

However the value at the address was increased by 70000, 20468 to 90468.
thanks.

ETA:
Code:

local al = getAddressList()
addexpvalue = 10000;--example
exp1addr = addresslist_getMemoryRecordByDescription(al, "Hero 1 Exp")
exp2addr = addresslist_getMemoryRecordByDescription(al, "Hero 2 Exp")
exp3addr = addresslist_getMemoryRecordByDescription(al, "Hero 2 Exp")
for x = 1, 3 do
local "value" .. x = readInteger("exp" .. x .. "addr")
writeInteger("exp" .. x .. "addr")+tonumber(addexpvalue)
end;

This has an error at local "value" .. x, but might have oters.
Back to top
View user's profile Send private message Yahoo Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1249

PostPosted: Thu Mar 31, 2022 5:17 pm    Post subject: Reply with quote

If the given example works, the running state of your code looks like this:

Code:
local al = getAddressList()
addexpvalue = 10000;--example
exp1addr = addresslist_getMemoryRecordByDescription(al, "Hero 1 Exp")
exp2addr = addresslist_getMemoryRecordByDescription(al, "Hero 2 Exp")
exp3addr = addresslist_getMemoryRecordByDescription(al, "Hero 2 Exp")
for x = 1, 3 do
local valueX = "exp" .. x .. "addr"
local valueX1 = readInteger(valueX) + tonumber(addexpvalue)
writeInteger(valueX, tonumber(valueX1))
end;


EDIT :
Assigning a new name ignores the previous name.
The code below works without naming.

Code:
local al = getAddressList()
addexpvalue = 10000;--example
for x = 1, 3 do
exp1addr = addresslist_getMemoryRecordByDescription(al, "Hero " .. x .. " Exp").Address

local valueX1 = readInteger(exp1addr) + tonumber(addexpvalue)
writeInteger(exp1addr, tonumber(valueX1))
end;

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Thu Mar 31, 2022 6:55 pm    Post subject: Reply with quote

Oh, I like that last one more efficient. I was having problems with the readInteger having any value. The address printed as well as the value, but the readInteger came up nil.

Thanks again.
Back to top
View user's profile Send private message Yahoo Messenger
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

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

PostPosted: Fri Apr 01, 2022 5:18 am    Post subject: Reply with quote

Just a note:
Code:

local al = getAddressList()                       
addexpvalue = 10000;--example
for x = 1, 3 do
exp1addr = addresslist_getMemoryRecordByDescription(al, "Hero " .. x .. " Exp").Address

local valueX1 = readInteger(exp1addr) + tonumber(addexpvalue)
writeInteger(exp1addr, tonumber(valueX1))
end;


Here local al = getAddressList() is not necessary because addresslist_getMemoryRecordByDescription is already accessing the global addresslist object. You are basically referrencing an object you are not using.

Use one or the other.
Code:

local al = getAddressList()                       
addexpvalue = 10000;--example
for x = 1, 3 do
exp1addr = al.getMemoryRecordByDescription(al, "Hero " .. x .. " Exp").Address

local valueX1 = readInteger(exp1addr) + tonumber(addexpvalue)
writeInteger(exp1addr, tonumber(valueX1))
end;


or
Code:

addexpvalue = 10000;--example
for x = 1, 3 do
exp1addr = addresslist_getMemoryRecordByDescription(al, "Hero " .. x .. " Exp").Address

local valueX1 = readInteger(exp1addr) + tonumber(addexpvalue)
writeInteger(exp1addr, tonumber(valueX1))
end;
Back to top
View user's profile Send private message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Sat Apr 02, 2022 3:11 pm    Post subject: Reply with quote

Well, I have a small issue
Code:

local al = getAddressList()
               for x = 1, 4 do
                   exp1addr = addresslist_getMemoryRecordByDescription(al, "Hero " .. x .. " Exp").Address
print(exp1addr)
               end;

produces:
49f4a4
49f4a7
49f4aa
49f4ad
All are correct
Code:

local al = getAddressList()
               for x = 1, 4 do
                   exp1addr = addresslist_getMemoryRecordByDescription(al, "Hero " .. x .. " Exp").Value
print(exp1addr)
               end;

produces:
6870
6870
6870
6870
All are correct
Code:

local al = getAddressList()
               for x = 1, 4 do
                   exp1addr = addresslist_getMemoryRecordByDescription(al, "Hero " .. x .. " Exp").Address
                   local valueX1 = readInteger(exp1addr) + tonumber(addexpvalue)
print(valueX1)
               end;

produces:
3187679910
3187679910
3187679910
1459626662
I'm not sure of the last value, but remember.
Code:

addexpvalue = 1000
local al = getAddressList()
               for x = 1, 4 do
                   exp1addr = addresslist_getMemoryRecordByDescription(al, "Hero " .. x .. " Exp").Address
                   local valueX1 = readInteger(exp1addr) + tonumber(addexpvalue)
                   writeInteger(exp1addr, tonumber(valueX1))
               end;

produces
7870
7870
7870
7870
As one would expect.

After resetting game.
Entering 1000 into the edit box(addexp_value)
Code:

   self.add_exp = createButton(self.form);
   self.add_exp.Caption = 'Add Exp';
   self.add_exp.height = 35;
   self.add_exp.left = 5;
   self.add_exp.top = 370;
   self.add_exp.width = 70;
   self.add_exp.onClick =    function (sender)
                              local value = tonumber(self.addexp_value.Text);
                              if value then
                                 addexpvalue = tonumber(value);
                                 print("Add experience entered " .. addexpvalue);
                                 if addexpvalue then
                                    AddExp();
                                 end;
                              end;
                              self.addexp_value.Text = "";
                           end;
function AddExp()
         local al = getAddressList()
               for x = 1, 4 do
                   exp1addr = addresslist_getMemoryRecordByDescription(al, "Hero " .. x .. " Exp").Address
                   local valueX1 = readInteger(exp1addr) + tonumber(addexpvalue)
                   writeInteger(exp1addr, tonumber(valueX1))
               end;
               addexpvalue = 0;
end;

produces
7870
7870
7870
6870
How curious? remember the value I suggested remembering? What could be wrong?
Back to top
View user's profile Send private message Yahoo Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1249

PostPosted: Sat Apr 02, 2022 4:32 pm    Post subject: Reply with quote

This code works for me.

Code:
self={}
self.form=createForm()
self.addexp_value=createEdit(self.form)
addexpvalue=0


   self.add_exp = createButton(self.form);
   self.add_exp.Caption = 'Add Exp';
   self.add_exp.height = 35;
   self.add_exp.left = 5;
   self.add_exp.top = 170;
   self.add_exp.width = 70;
   self.add_exp.onClick =    function (sender)
                              local value = tonumber(self.addexp_value.Text);
                              if value then
                                 addexpvalue = tonumber(value);
                                 print("Add experience entered " .. addexpvalue);
                                 if addexpvalue then
                                    AddExp();
                                 end;
                              end;
                              self.addexp_value.Text = "";
                           end;
function AddExp()
         local al = getAddressList()
               for x = 1, 4 do
                   exp1addr = addresslist_getMemoryRecordByDescription(al, "Hero " .. x .. " Exp").Address
                   local valueX1 = readInteger(exp1addr) + tonumber(addexpvalue)
                   writeInteger(exp1addr, tonumber(valueX1))
               end;
               addexpvalue = 0;
end;


To be sure (at the beginning of the form, if you don't express "addexpvalue" globally), do something like this;
Code:
                                 if addexpvalue then
                                    AddExp(addexpvalue);
                                 end;

function AddExp(newValue)
         local al = getAddressList()
               for x = 1, 4 do
                   exp1addr = addresslist_getMemoryRecordByDescription(al, "Hero " .. x .. " Exp").Address
                   local valueX1 = readInteger(exp1addr) + tonumber(newValue) --new value = addexpvalue
                   writeInteger(exp1addr, tonumber(valueX1))
               end;
               --newValue = 0;
end;

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Sat Apr 02, 2022 7:55 pm    Post subject: Reply with quote

I guess my question was why it worked 3 out of 4 times. Also that is why I went to the effort of all the print checks.
I tried AddExp(addexpvalue) and that gave the same results as before the last(4) was shy the value of addexpvalue.

This is the same game, same CE but different machine and op sys. I believe it worked on the other machine, but I'll have to check.
Back to top
View user's profile Send private message Yahoo Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1249

PostPosted: Sat Apr 02, 2022 8:41 pm    Post subject: Reply with quote

Do a different test and check the result.

Note1: Make sure the description of the 4th address is spelled correctly.

Note2: "addexpvalue = 0" may be reducing the value to zero before the change is complete. I disabled this in code.

Note3: Run the code below independently from the Trainer code and try it. For example, open a blank DT, select the DT's own action, search for 10000 and download the 5 results to the address list and change the descriptions (Hero 1 Exp). Copy and paste the code below into Lua Script, run and test.

Here is a code example:
Code:
self={}
self.form=createForm()
self.addexp_value=createEdit(self.form)
addexpvalue=0

   self.add_exp = createButton(self.form);
   self.add_exp.Caption = 'Add Exp';
   self.add_exp.height = 35;
   self.add_exp.left = 5;
   self.add_exp.top = 170;
   self.add_exp.width = 70;
   self.add_exp.onClick =    function (sender)
                              local value = tonumber(self.addexp_value.Text);
                              if value then
                                 addexpvalue = tonumber(value);
                                 print("Add experience entered " .. addexpvalue);
                                 if addexpvalue then
                                    AddExp(addexpvalue,4);
                                 end;
                              end;
                              self.addexp_value.Text = "";
                           end;
function AddExp(newValue,indx)
         local al = getAddressList()
               x=0
               pushT=createTimer()
               pushT.Interval=20
               pushT.OnTimer=function()
                   x=tonumber(x) + 1
                   exp1addr = addresslist_getMemoryRecordByDescription(al, "Hero " .. x .. " Exp").Address
                   local valueX1 = readInteger(exp1addr) + tonumber(addexpvalue)
                   writeInteger(exp1addr, tonumber(valueX1))
                   print(x)
                   if x==tonumber(indx) then pushT.Destroy() end
               end
               --addexpvalue = 0;
end;

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Sat Apr 02, 2022 9:35 pm    Post subject: Reply with quote

AylinCE wrote:
Do a different test and check the result.

Note1: Make sure the description of the 4th address is spelled correctly.

Note2: "addexpvalue = 0" may be reducing the value to zero before the change is complete. I disabled this in code.

Note3: Run the code below independently from the Trainer code and try it. For example, open a blank DT, select the DT's own action, search for 10000 and download the 5 results to the address list and change the descriptions (Hero 1 Exp). Copy and paste the code below into Lua Script, run and test.



What does DT stand for? I am unable to search for anything until the new table is attached. That being said, I ran your code in the new table and all 4 exp were increased, similar to what I believe in the other machine. The table on this machine is a copy from previous machine.
So what does that indicate to you? It doesn't indicate anything to me.
Back to top
View user's profile Send private message Yahoo Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1249

PostPosted: Sat Apr 02, 2022 10:06 pm    Post subject: Reply with quote

DT opss sorry! CE Cheat Engine ..

Try the last code as I said, on the device that is not working (Open a new CE)
As for your last question; This is not PC code or syntax, but Lua and CE syntax. For this reason, the difference may only be the CE version difference.

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Sun Apr 03, 2022 7:45 am    Post subject: Reply with quote

I have 7.4 installed on both machines. I am on the original machine and the same behavior noted yesterday exists with this machine. The fourth hero's exp was not increased.
The piece of the puzzle that does work. If I copy the code to the debug window and give it a fixed exp addexpvalue = ####. In this case all four addresses are adjusted. I guess after testing on this machine I ASSUMED the code worked and just copied from the debug window to the main code and never tested it. I tested the code deleting al = getAddressList() from the code. The fourth hero's exp was not changes.
I have spent an hour testing the last test commented out the for loop and hard coded hero 4 exp with some print statements.
Code:

function AddExp()
         local al = getAddressList()
         --exp4value = tonumber(addresslist_getMemoryRecordByDescription(al, "Hero 4 Exp").Value)
         --print(exp4value)
         --exp4addr = addresslist_getMemoryRecordByDescription(al, "Hero 4 Exp").Address
         --print(exp4addr)
               --for x = 1, 4 do
                   --exp1addr = addresslist_getMemoryRecordByDescription(al, "Hero " .. x .. " Exp").Address
                   --local valueX1 = readInteger(exp1addr) + tonumber(addexpvalue)
                   --writeInteger(exp1addr, tonumber(valueX1))
               --end;
               --if tonumber(addresslist_getMemoryRecordByDescription(al, "Hero 4 Exp").Value) == exp4value then
               print(addexpvalue)
               exp1addr = addresslist_getMemoryRecordByDescription(al, "Hero 4 Exp").Address
               print(exp1addr)
               local valueX1 = readInteger(exp1addr) + tonumber(addexpvalue)
               print(valueX1)
               writeInteger(exp1addr, tonumber(valueX1))
               --end
               --addexpvalue = 0;
end;

The result is nothing, its like the AddExp() doesn't exist or executed. I have even saved this shut down CE and restarted with the same result. Before you ask the pint statementn in the self.add_exp.onClick = function (sender) executes giving a global value to use in AddExp(). I tried AddExp(addexpvalue) also in the onClick function, no change.

ETA:
In an effort to force Hero 4 Exp to change I edited the code as follows:
Code:

function AddExp()
         local al = getAddressList()
               --The following bit of code should not be used in general, just this game
               local value4addr = addresslist_getMemoryRecordByDescription(al, "Hero 4 Exp")
               local value4 = tonumber(memoryrecord_getValue(value4addr))
               print(value4)
               memoryrecord_setValue(value4addr,value4 + addexpvalue)
               --End don't use code
               for x = 1, 4 do
                   exp1addr = addresslist_getMemoryRecordByDescription(al, "Hero " .. x .. " Exp").Address
                   local valueX1 = readInteger(exp1addr) + tonumber(addexpvalue)
                   writeInteger(exp1addr, tonumber(valueX1))
               end;
               --addexpvalue = 0;
end;

The code executed and changed 1-3, but 4 remained unchanged and obviously the print statements prior to the for statement weren't executed. I even deleted the for loop and still no change for Hero 4 Exp, no errors or print statements either.
Back to top
View user's profile Send private message Yahoo Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1249

PostPosted: Sun Apr 03, 2022 12:11 pm    Post subject: Reply with quote

Like a joke. A negative reference to the Lua syntax and outside the scope of CE. So an unlikely behavior!

1) After changing addresses 1,2,3,4, make sure that address 4 does not change back to its original state.

2) Just to test, try setting the "for" loop for 5 addresses instead of 4. (I wonder if the addresses 1,2,3,5 will still change)

Code:
for x = 1, 5 do


3) And only a code test specific to the current faulty address;

Code:
function AddExp()
         local al = getAddressList()
         local valueX1=0
         offaddr = addresslist_getMemoryRecordByDescription(al, "Hero 4 Exp").Address
               for x = 1, 4 do
                   exp1addr = addresslist_getMemoryRecordByDescription(al, "Hero " .. x .. " Exp").Address
                   valueX1 = readInteger(exp1addr) + tonumber(addexpvalue)
                   writeInteger(exp1addr, tonumber(valueX1))
               end;
                -- test
                newaddr=addresslist_getMemoryRecordByDescription(al, "Hero 4 Exp").Address
               if readInteger(newaddr)==readInteger(offaddr) then
                   writeInteger(newaddr, tonumber(valueX1))
               end
               addexpvalue = 0;
end;

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
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