|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
bknight2602 Grandmaster Cheater Reputation: 0
Joined: 08 Oct 2012 Posts: 577
|
Posted: Sat Nov 08, 2014 9:03 pm Post subject: How to make address caption dependant on the value of addrss |
|
|
I have some addresses the show the profession of a hero. ie.
Description Address Value
Hero 1 Profession 07115C98 7
Hero 4 Profession 07115C9B 1
The value of 7 is a Ninja, 1 Solder etc.
How can I code the description to read Hero 1 Profession is Ninja when the value is 7?
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 457
Joined: 09 May 2003 Posts: 25262 Location: The netherlands
|
Posted: Sat Nov 08, 2014 10:23 pm Post subject: |
|
|
Code: |
value=readInteger(0x07115c98)
if value==1 then
description='Soldier'
end
if value==7 then
description='Ninja'
end
descriptionofhero1label.caption=description
|
you can easily adapt this to hero 4 as well
If this isn't a lua question but just an addresslist question, then look into the dropdown list
_________________
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 |
|
|
bknight2602 Grandmaster Cheater Reputation: 0
Joined: 08 Oct 2012 Posts: 577
|
Posted: Sun Nov 09, 2014 12:21 am Post subject: |
|
|
That would work, if the addresses were static, but they change every time the game opens. I have a recalculation function in the CE panel I have.
I was thinking a for loop after Code: |
prof1address = addresslist_getMemoryRecordByDescription(addresslist, "Hero 1 Profession")
prof1 = memoryrecord_getValue(prof1address)
prof2address = addresslist_getMemoryRecordByDescription(addresslist, "Hero 2 Profession")
prof2 = memoryrecord_getValue(prof2address)
...
prof20address = addresslist_getMemoryRecordByDescription(addresslist, "Hero 20 Profession")
prof20 = memoryrecord_getValue(prof20address)
for x = 1, 20 do
whichprof = "prof"..x
if whichprof == 1 then
memoryrecord_setDescription(prof1address, "Soldier")
elseif whichprof == 2 then
memoryrecord_setDescription(prof1address, "Knight")
etc.
end
end |
My obstacle is how to code in the hero number with the specific profession
|
|
Back to top |
|
|
panraven Grandmaster Cheater Reputation: 54
Joined: 01 Oct 2008 Posts: 941
|
Posted: Sun Nov 09, 2014 6:08 am Post subject: |
|
|
Hi, I've generalized the idea with these function:
Code: | local conv_rules = {
-- numeric key
class={[1]="witch",[2]="knight",[0xf]="monomaneshi"},
-- string key, case matter, key name follow lua variable naming rule,ie. no space etc.
name={john="John Lennon", paul="Paul McCartney", george="George Harrison", yoko="Yoko Ono"}
}
local convert = function (mr,d)
local desc = mr.Description
for k,v in pairs(d) do
local mkey = '@'..k..':' -- adapt for your header format
local head = string.sub(desc, 1, #mkey)
if mkey == head then
local val = v[tonumber(mr.Value)] or v[tostring(mr.Value)]
if val ~= nil then
mr.Description = mkey..val
else
mr.Description = mkey..'???' -- adapt for your unknown value identifier
end
break
end
end
end
local updateAddrList = function(d)
local d = d or conv_rules
local al = getAddressList()
for i=0,al.Count-1 do convert(al[i],d) end
end
updateAddrList()
|
Customize the 'conv_rule' then manually set the description 'header' to let the function know which type (class or name in above example) the memory record should set.
Attach the 'updateAddrList' to a timer function event may let it update automatically.
|
|
Back to top |
|
|
bknight2602 Grandmaster Cheater Reputation: 0
Joined: 08 Oct 2012 Posts: 577
|
Posted: Sun Nov 09, 2014 12:10 pm Post subject: |
|
|
Many questions
First:
class={[1]="witch",[2]="knight",[0xf]="monomaneshi"}, Why the 0xf? why the comma at the end?
Second:
local convert = function (mr,d) What is d and when, how is it enabled?
Third:
local desc = mr.Description Which memory record does this refer?
Fourth:
local mkey = '@'..k..':' -- adapt for your header format Why the @ char. and why the : char. k I assume would be the class (name does not fit the general game as names are not constant)
Fifth:
local head = string.sub(desc, 1, #mkey) Where does the # mean?
Sixth:
local d = d or conv_rules I don't understand this statement. Please explain your process.
Seventh:
local updateAddrList = function(d) Same question where does d come from in the code
I tried a snippet of your code:
Code: | local conv_rules = {
-- numeric key
class={[1]="Soldier",[2]="Knight",[3]="Berzerker",[4]="Unknown",[5]="Unknown",[6]="Unkown",[7]="Ninja",[8]="Beast Master",[9]="Unknown"}--[0xf]="monomaneshi"},
}
local convert = function (mr,d)
local desc = mr.Description
print(desc)
for k,v in pairs(d) do
local mkey = '@'..k..':' -- adapt for your header format
print(mkey)
local head = string.sub(desc, 1, #mkey)
print(head)
if mkey == head then
local val = v[tonumber(mr.Value)]
if val ~= nil then
mr.Description = mkey..val
else
mr.Description = mkey..'???' -- adapt for your unknown value identifier
end
break
end
end
end
local updateAddrList = function(d)
local d = d or conv_rules
print(d)
local al = getAddressList()
--for i=0,al.Count-1 do convert(al[i],d) end
end |
Nothing happens
|
|
Back to top |
|
|
panraven Grandmaster Cheater Reputation: 54
Joined: 01 Oct 2008 Posts: 941
|
Posted: Sun Nov 09, 2014 2:11 pm Post subject: |
|
|
I'm not English Speaking native, and not good at explaining, I answer briefly. It is better have a look at official Lua for basic of Lua, ce use ver 5.1, so check here
Quote: | First:
class={[1]="witch",[2]="knight",[0xf]="monomaneshi"}, Why the 0xf? why the comma at the end? |
'0xf' is hexadecimal representation of number 15, just for an example of numeric key usage. The comma is used to separate different key-value pairs, it is a lua syntax.
Quote: | Second:
local convert = function (mr,d) What is d and when, how is it enabled? |
It is a parameter for the function. You supply the parameter when calling the function.
Quote: | Third:
local desc = mr.Description Which memory record does this refer? |
This function will be call for every memory record on the address list, by specifying the mr as 1st parameter of the function, so every memory record.
Quote: | Fourth:
local mkey = '@'..k..':' -- adapt for your header format Why the @ char. and why the : char. k I assume would be the class (name does not fit the general game as names are not constant) |
It is just a format to let the function know which conv_rules should be use on the memory record.
Quote: | Fifth:
local head = string.sub(desc, 1, #mkey) Where does the # mean? |
It is the number of byte of the string the variable mkey holding, in this case same as number of characters in the string.
Quote: | Sixth:
local d = d or conv_rules I don't understand this statement. Please explain your process. |
You can supply no parameter (d) for the updateAddrList function, in this case, it use a default d, as conv_rules.
Quote: | Seventh:
local updateAddrList = function(d) Same question where does d come from in the code |
It is an optional function parameter, see previous.
Quote: | I tried a snippet of your code: --snip-- |
Check img
[img=http://forum.cheatengine.org/files/convdesc_115.jpg][/img]
Here steps on using the function:
1. paste the functions on lua script editor by tool/'show cheat table lua script'
2. customize the conv_rules
3. setup your address list, this part you have to do it your self on your game target
4. manually change the description by double click the column. That's, if the address entry's value represent a weapon, and the description name should follow the 'weapon' conv_rules, set the 1st few characters of the description as "@weapon:".
5. execute the script.
Description: |
|
Filesize: |
148.85 KB |
Viewed: |
16950 Time(s) |
|
|
|
Back to top |
|
|
bknight2602 Grandmaster Cheater Reputation: 0
Joined: 08 Oct 2012 Posts: 577
|
Posted: Sun Nov 09, 2014 7:21 pm Post subject: |
|
|
panraven wrote: | I'm not English Speaking native, and not good at explaining, I answer briefly. It is better have a look at official Lua for basic of Lua, ce use ver 5.1, so check here
Quote: | First:
class={[1]="witch",[2]="knight",[0xf]="monomaneshi"}, Why the 0xf? why the comma at the end? |
'0xf' is hexadecimal representation of number 15, just for an example of numeric key usage. The comma is used to separate different key-value pairs, it is a lua syntax.OK, but the name function won't work for the general case as the names change every time the game starts
Quote: | Second:
local convert = function (mr,d) What is d and when, how is it enabled? |
It is a parameter for the function. You supply the parameter when calling the function.
Quote: | Third:
local desc = mr.Description Which memory record does this refer? |
This function will be call for every memory record on the address list, by specifying the mr as 1st parameter of the function, so every memory record.
Quote: | Fourth:
local mkey = '@'..k..':' -- adapt for your header format Why the @ char. and why the : char. k I assume would be the class (name does not fit the general game as names are not constant) |
It is just a format to let the function know which conv_rules should be use on the memory record.
Quote: | Fifth:
local head = string.sub(desc, 1, #mkey) Where does the # mean? |
It is the number of byte of the string the variable mkey holding, in this case same as number of characters in the string.
Quote: | Sixth:
local d = d or conv_rules I don't understand this statement. Please explain your process. |
You can supply no parameter (d) for the updateAddrList function, in this case, it use a default d, as conv_rules.
Quote: | Seventh:
local updateAddrList = function(d) Same question where does d come from in the code |
It is an optional function parameter, see previous.
Quote: | I tried a snippet of your code: --snip-- |
Check img
[img=http://forum.cheatengine.org/files/convdesc_115.jpg][/img]
Here steps on using the function:
1. paste the functions on lua script editor by tool/'show cheat table lua script'
2. customize the conv_rules
3. setup your address list, this part you have to do it your self on your game target
4. manually change the description by double click the column. That's, if the address entry's value represent a weapon, and the description name should follow the 'weapon' conv_rules, set the 1st few characters of the description as "@weapon:".
5. execute the script. |
You did very well with English, far better than I with your language.
I copied the entire code you presented (plus some print statements) except updateAddrList(), then entered updateAddrList() in the debug window and got
Error:[string "updateAddrList()..."]:1: attempt to call global 'updateAddrList' (a nil value)
|
|
Back to top |
|
|
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Sun Nov 09, 2014 7:38 pm Post subject: |
|
|
updateAddrList is defined locally.
delete the 'local'.
_________________
|
|
Back to top |
|
|
panraven Grandmaster Cheater Reputation: 54
Joined: 01 Oct 2008 Posts: 941
|
Posted: Sun Nov 09, 2014 8:31 pm Post subject: |
|
|
Yes, as DaSpamer said.
Quote: | ... OK, but the name function won't work for the general case as the names change every time the game starts |
You mean the ADDRESS of the value representing 'name' change?
If it is the 'name' change, or the relationship between the 'name' and the value representing 'name' change every game start, yes, it won't work.
For example, the value of an address is the item_index, and you know from game playing that the item_index represent an item having an in-game name item_name, the relationship between list of item_index and item_name should normally not change every game start.
Otherwise you cannot customize the conv_rules.
If it is the Address of the item_idx change, then it is up to you to setup the CE AddressList. I cannot do anything without further knowledge of the game and your exact goal want to achieve.
|
|
Back to top |
|
|
bknight2602 Grandmaster Cheater Reputation: 0
Joined: 08 Oct 2012 Posts: 577
|
Posted: Sun Nov 09, 2014 11:12 pm Post subject: |
|
|
DaSpamer wrote: | updateAddrList is defined locally.
delete the 'local'. |
Still have the same error message
panraven wrote: | Yes, as DaSpamer said.
Quote: | ... OK, but the name function won't work for the general case as the names change every time the game starts |
You mean the ADDRESS of the value representing 'name' change? The addresses all change every time the game opens, I have a recalculation function to get table addresses in synch with the game.
If it is the 'name' change, or the relationship between the 'name' and the value representing 'name' change every game start, yes, it won't work.The names change every time the game initiates, but after that the names remain the same
For example, the value of an address is the item_index, and you know from game playing that the item_index represent an item having an in-game name item_name, the relationship between list of item_index and item_name should normally not change every game start.
Otherwise you cannot customize the conv_rules.The values are probably in the game data, but values always mean the same profession 1 for Soldier, 2 for Knight et.c
If it is the Address of the item_idx change, then it is up to you to setup the CE AddressList. I cannot do anything without further knowledge of the game and your exact goal want to achieve. |
|
|
Back to top |
|
|
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Mon Nov 10, 2014 8:43 am Post subject: |
|
|
Quote: | local conv_rules = {
-- numeric key
class={[1]="Soldier",[2]="Knight",[3]="Berzerker",[4]="Unknown",[5]="Unknown",[6]="Unkown",[7]="Ninja",[8]="Beast Master",[9]="Unknown"}--[0xf]="monomaneshi"},
}
local convert = function (mr,d)
local desc = mr.Description
print(desc)
for k,v in pairs(d) do
local mkey = '@'..k..':' -- adapt for your header format
print(mkey)
local head = string.sub(desc, 1, #mkey)
print(head)
if mkey == head then
local val = v[tonumber(mr.Value)]
if val ~= nil then
mr.Description = mkey..val
else
mr.Description = mkey..'???' -- adapt for your unknown value identifier
end
break
end
end
end
--local updateAddrList = function(d)
updateAddrList = function(d)
local d = d or conv_rules
print(d)
local al = getAddressList()
--for i=0,al.Count-1 do convert(al[i],d) end
end |
_________________
|
|
Back to top |
|
|
bknight2602 Grandmaster Cheater Reputation: 0
Joined: 08 Oct 2012 Posts: 577
|
Posted: Mon Nov 10, 2014 9:54 am Post subject: |
|
|
That is what I did, still have the same error.
Code: | updateAddrList = function(d)
local d = d or conv_rules
local al = getAddressList()
for i=0,al.Count-1 do convert(al[i],d) end
end
--updateAddrList() |
|
|
Back to top |
|
|
bknight2602 Grandmaster Cheater Reputation: 0
Joined: 08 Oct 2012 Posts: 577
|
Posted: Sat Nov 15, 2014 1:42 pm Post subject: |
|
|
Finished the coding with long if statements, but it does work.
For the code to work all the time I need one more step.
Here is a bit of the code with questionable steps commented out currently: Code: |
self.form.show();
--self.form.close(CloseCET)
--self.profession.Enabled = false | Shut down the timer used to re-write professions within the trainer so self = trainer Code: |
--function CloseCET(sender)
--local addresslist = getAddressList()
--memoryrecord_setDescription(prof1address,"Hero 1 Profession")
--memoryrecord_setDescription(prof2address,"Hero 2 Profession")
--memoryrecord_setDescription(prof3address,"Hero 3 Profession")
--memoryrecord_setDescription(prof4address,"Hero 4 Profession")
--memoryrecord_setDescription(prof5address,"Hero 5 Profession")
--memoryrecord_setDescription(prof6address,"Hero 6 Profession")
--memoryrecord_setDescription(prof7address,"Hero 7 Profession")
--memoryrecord_setDescription(prof8address,"Hero 8 Profession")
--memoryrecord_setDescription(prof9address,"Hero 9 Profession")
--memoryrecord_setDescription(prof10address,"Hero 10 Profession")
--memoryrecord_setDescription(prof11address,"Hero 11 Profession")
--memoryrecord_setDescription(prof12address,"Hero 12 Profession")
--memoryrecord_setDescription(prof13address,"Hero 13 Profession")
--memoryrecord_setDescription(prof14address,"Hero 14 Profession")
--memoryrecord_setDescription(prof15address,"Hero 15 Profession")
--memoryrecord_setDescription(prof16address,"Hero 16 Profession")
--memoryrecord_setDescription(prof17address,"Hero 17 Profession")
--memoryrecord_setDescription(prof18address,"Hero 18 Profession")
--memoryrecord_setDescription(prof19address,"Hero 19 Profession")
--memoryrecord_setDescription(prof20address,"Hero 20 Profession")
--end--function CloseCET(sender)
|
What I'm attempting is to re-set the professions back to the original when CE is shut down. There should be one more step in the code:
To Save The Table.
Is this the correct syntax and what would be the correct saving code?
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 457
Joined: 09 May 2003 Posts: 25262 Location: The netherlands
|
Posted: Sat Nov 15, 2014 7:36 pm Post subject: |
|
|
Perhaps it might be easier to just build the cheat table with the lua script and on save delete all entries so only the lua script remains ? (or just don't save at all)
_________________
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 |
|
|
panraven Grandmaster Cheater Reputation: 54
Joined: 01 Oct 2008 Posts: 941
|
Posted: Wed Nov 19, 2014 2:57 am Post subject: |
|
|
Hi,
I've made a tutorial on response to "save the table" here
Copy the necessary function and get the menuitem 'save', use as the usage after where the table/address is just updated .
|
|
Back to top |
|
|
|
|
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
|
|