 |
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: 582
|
Posted: Sun Jul 02, 2023 10:35 am Post subject: Changing mass partial descriptions |
|
|
I've a lot of memory records that have a description of Defending followed by other descriptions for example Defending HP, Defending MP.
What I wish to accomplish is to change the partial description from Defening X
to Enemy X.
I have some code to print addresses and descriptions that doesn't work as a step towards finding the full descriptions to partial descriptions and changing those partial descriptions.
Code: |
AL = getAddressList();
for i = AL.Count-1,0 do
mrdesc = AL[i].Description
mraddr = AL[i].Address
--if mrdesc = "Defending" then
print (mraddr.. ", " .. mrdesc)
--end
end;
|
|
|
Back to top |
|
 |
YoucefHam Cheater
Reputation: 5
Joined: 19 Mar 2015 Posts: 39 Location: Algeria
|
Posted: Sun Jul 02, 2023 11:34 am Post subject: Re: Changing mass partial descriptions |
|
|
bknight2602 wrote: | I've a lot of memory records that have a description of Defending followed by other descriptions for example Defending HP, Defending MP.
What I wish to accomplish is to change the partial description from Defening X
to Enemy X.
.........
|
Use gsub() function
Code: | string.gsub('Defending HP','Defending (.*)','Enemy %1') |
https://www.tutorialspoint.com/lua/lua_strings.htm
http://lua-users.org/wiki/StringLibraryTutorial
|
|
Back to top |
|
 |
bknight2602 Grandmaster Cheater
Reputation: 0
Joined: 08 Oct 2012 Posts: 582
|
Posted: Sun Jul 02, 2023 12:33 pm Post subject: Re: Changing mass partial descriptions |
|
|
Thanks for the reply, but doesn't work in:
Code: |
AL = getAddressList();
for i = 0, AL.Count-1 do
mrdesc = AL[i].Description
mraddr = AL[i].Address
print(mrdesc)
string.gsub("Defending A Side","Defending","Enemy")
end;--for i = 1, AL.count do
|
Prints the description but doesn't change it. The example is the first of the set of descriptions required to be altered.
ETA I tried substituting mrdesc as the subject, but that didn't work either.
|
|
Back to top |
|
 |
LeFiXER Grandmaster Cheater Supreme
Reputation: 20
Joined: 02 Sep 2011 Posts: 1066 Location: 0x90
|
Posted: Sun Jul 02, 2023 2:11 pm Post subject: |
|
|
It really does help to read about how Lua works and try to understand it.
Code: |
for i = 0, AddressList.Count - 1 do
local d = AddressList.MemoryRecord[i].Description
AddressList.MemoryRecord[i].Description = d:gsub('Defending (.*)', 'Enemy %1')
end
|
|
|
Back to top |
|
 |
bknight2602 Grandmaster Cheater
Reputation: 0
Joined: 08 Oct 2012 Posts: 582
|
Posted: Sun Jul 02, 2023 3:29 pm Post subject: |
|
|
LeFiXER wrote: | It really does help to read about how Lua works and try to understand it.
Code: |
for i = 0, AddressList.Count - 1 do
local d = AddressList.MemoryRecord[i].Description
AddressList.MemoryRecord[i].Description = d:gsub('Defending (.*)', 'Enemy %1')
end
|
|
Well if you would kindly point out where in the in the guide it indicates (.*), as well as mrdesc:gsub to do the correcting?
the code does not function as I wished but:
Code: |
AL = getAddressList();
for i = 0, AL.Count-1 do
mrdesc = AL[i].Description
mraddr = AL[i].Address
print(mrdesc)
AL.MemoryRecord[i].Description = mrdesc:gsub('Defending', 'Enemy')
--This changes the whole description instead of a part
--AL.MemoryRecord[i].Description = mrdesc:gsub('Defending (.*)', 'Enemy')
end;--i = 0, AL.Count-1 do
|
Thanks for the direction of the hint.
|
|
Back to top |
|
 |
LeFiXER Grandmaster Cheater Supreme
Reputation: 20
Joined: 02 Sep 2011 Posts: 1066 Location: 0x90
|
Posted: Sun Jul 02, 2023 3:46 pm Post subject: |
|
|
bknight2602 wrote: |
Well if you would kindly point out where in the in the guide it indicates (.*), as well as mrdesc:gsub to do the correcting?
the code does not function as I wished but:
Code: |
AL = getAddressList();
for i = 0, AL.Count-1 do
mrdesc = AL[i].Description
mraddr = AL[i].Address
print(mrdesc)
AL.MemoryRecord[i].Description = mrdesc:gsub('Defending', 'Enemy')
--This changes the whole description instead of a part
--AL.MemoryRecord[i].Description = mrdesc:gsub('Defending (.*)', 'Enemy')
end;--i = 0, AL.Count-1 do
|
Thanks for the direction of the hint. |
I just implemented YoucefHam's suggestion in a way that you can use it directly. There are copious resources on Lua although it takes time to read/try/understand it here are some links about Lua (some have already been mentioned):
https://www.tutorialspoint.com/lua/lua_strings.htm
http://lua-users.org/wiki/StringLibraryTutorial
https://www.lua.org/manual/5.4/
https://devhints.io/lua
You don't need me to teach you how to query a search engine for results you require.
In regards to your question where (.*) resides in the documentation, this falls under the pattern matching section in the official Lua documentation:
https://www.lua.org/manual/5.4/manual.html#6.4
Here you can see all character classes, what characters denote what within the pattern. If you are familiar with RegExp then you are already halfway to understanding how it works.
You have tried to combine code that is mismatched.
Code: |
AL = getAddressList();
for i = 0, AL.Count-1 do
mrdesc = AL[i].Description
mraddr = AL[i].Address
print(mrdesc)
AL.MemoryRecord[i].Description = mrdesc:gsub('Defending', 'Enemy')
--This changes the whole description instead of a part
--AL.MemoryRecord[i].Description = mrdesc:gsub('Defending (.*)', 'Enemy')
end;
|
Omit all the surplus code that is not required:
Code: |
for i = 0, AddressList.Count - 1 do
local description = AddressList.MemoryRecord[i].Description
AddressList.MemoryRecord[i].Description = description:gsub('Defending (.*)', 'Enemy %1')
end
|
Cheat Engine has built-in variables that you can use to access commonly used objects such as MainForm, AddressList etc.... There is no need to use getAddressList() unless you are using a much older version.
|
|
Back to top |
|
 |
bknight2602 Grandmaster Cheater
Reputation: 0
Joined: 08 Oct 2012 Posts: 582
|
Posted: Wed Jul 05, 2023 6:06 pm Post subject: |
|
|
LeFiXER wrote: | bknight2602 wrote: |
Well if you would kindly point out where in the in the guide it indicates (.*), as well as mrdesc:gsub to do the correcting?
the code does not function as I wished but:
Code: |
AL = getAddressList();
for i = 0, AL.Count-1 do
mrdesc = AL[i].Description
mraddr = AL[i].Address
print(mrdesc)
AL.MemoryRecord[i].Description = mrdesc:gsub('Defending', 'Enemy')
--This changes the whole description instead of a part
--AL.MemoryRecord[i].Description = mrdesc:gsub('Defending (.*)', 'Enemy')
end;--i = 0, AL.Count-1 do
|
Thanks for the direction of the hint. |
I just implemented YoucefHam's suggestion in a way that you can use it directly. There are copious resources on Lua although it takes time to read/try/understand it here are some links about Lua (some have already been mentioned):
https://www.tutorialspoint.com/lua/lua_strings.htm
http://lua-users.org/wiki/StringLibraryTutorial
https://www.lua.org/manual/5.4/
https://devhints.io/lua
You don't need me to teach you how to query a search engine for results you require.
In regards to your question where (.*) resides in the documentation, this falls under the pattern matching section in the official Lua documentation:
https://www.lua.org/manual/5.4/manual.html#6.4
Here you can see all character classes, what characters denote what within the pattern. If you are familiar with RegExp then you are already halfway to understanding how it works.
You have tried to combine code that is mismatched.
Code: |
AL = getAddressList();
for i = 0, AL.Count-1 do
mrdesc = AL[i].Description
mraddr = AL[i].Address
print(mrdesc)
AL.MemoryRecord[i].Description = mrdesc:gsub('Defending', 'Enemy')
--This changes the whole description instead of a part
--AL.MemoryRecord[i].Description = mrdesc:gsub('Defending (.*)', 'Enemy')
end;
|
Omit all the surplus code that is not required:
Code: |
for i = 0, AddressList.Count - 1 do
local description = AddressList.MemoryRecord[i].Description
AddressList.MemoryRecord[i].Description = description:gsub('Defending (.*)', 'Enemy %1')
end
|
Cheat Engine has built-in variables that you can use to access commonly used objects such as MainForm, AddressList etc.... There is no need to use getAddressList() unless you are using a much older version. |
I still not understanding for example if I wanted to find all records that had Sal in it I tried several, but not the correct one. The last one I tried:
Code: |
for i = 0, AddressList.Count - 1 do
local description = AddressList.MemoryRecord[i].Description
AddressList.MemoryRecord[i].Description = description:find('Sal (.*)')
print(description)
end |
What would e the correct syntax?
|
|
Back to top |
|
 |
LeFiXER Grandmaster Cheater Supreme
Reputation: 20
Joined: 02 Sep 2011 Posts: 1066 Location: 0x90
|
Posted: Thu Jul 06, 2023 6:23 am Post subject: |
|
|
bknight2602 wrote: |
I still not understanding for example if I wanted to find all records that had Sal in it I tried several, but not the correct one. The last one I tried:
Code: |
for i = 0, AddressList.Count - 1 do
local description = AddressList.MemoryRecord[i].Description
AddressList.MemoryRecord[i].Description = description:find('Sal (.*)')
print(description)
end |
What would e the correct syntax? |
The string.find function will return the index of the first and last index of the sub-string found within the string. For example, say you wanted to find 'code' in this string:
Code: |
local my_string = 'Coding is a great way to learn logic, but it will take time to learn to write great code.'
print(string.find(my_string, 'code'))
--> 85 88
|
Which prints '85 88 ' to console. Where index 85 is the character 'c' and index 88 is the character 'e'. Say you wanted to extract that word, you would use the
Code: |
local my_string = 'Coding is a great way to learn logic, but it will take many years to learn to write great code.'
local startIndex, endIndex = string.find(my_string, 'code')
local word = string.sub(my_string, startIndex, endIndex)
print(word)
--> code
|
Say you wanted to replace certain words within a string you would use the string.gsub function.
Code: |
local my_string = 'A wonderful example of the string.gsub function.'
local replacedString = string.gsub(my_string, 'wonderful', 'superb')
print(replacedString)
--> A superb example of the string.gsub function. 1
|
This replaces the occurrences of 'wonderful' with 'superb' within the passed string and returns how many replacements were made. To omit the occurrence count, simply encapsulate the whole string.gsub function within parentheses:
Code: |
local my_string = 'A wonderful example of the string.gsub function.'
local replacedStringNoCount = (string.gsub(my_string, 'wonderful', 'superb'))
print(replacedStringNoCount)
-->A superb example of the string.gsub function.
|
This will get you started. You can find out more information within the documentation linked in previous posts. If you struggle to understand things then you are free to ask questions.
|
|
Back to top |
|
 |
bknight2602 Grandmaster Cheater
Reputation: 0
Joined: 08 Oct 2012 Posts: 582
|
Posted: Sat Jul 08, 2023 11:53 am Post subject: |
|
|
LeFiXER wrote: | bknight2602 wrote: |
I still not understanding for example if I wanted to find all records that had Sal in it I tried several, but not the correct one. The last one I tried:
Code: |
for i = 0, AddressList.Count - 1 do
local description = AddressList.MemoryRecord[i].Description
AddressList.MemoryRecord[i].Description = description:find('Sal (.*)')
print(description)
end |
What would e the correct syntax? |
The string.find function will return the index of the first and last index of the sub-string found within the string. For example, say you wanted to find 'code' in this string:
Code: |
local my_string = 'Coding is a great way to learn logic, but it will take time to learn to write great code.'
print(string.find(my_string, 'code'))
--> 85 88
|
Which prints '85 88 ' to console. Where index 85 is the character 'c' and index 88 is the character 'e'. Say you wanted to extract that word, you would use the
Code: |
local my_string = 'Coding is a great way to learn logic, but it will take many years to learn to write great code.'
local startIndex, endIndex = string.find(my_string, 'code')
local word = string.sub(my_string, startIndex, endIndex)
print(word)
--> code
|
Say you wanted to replace certain words within a string you would use the string.gsub function.
Code: |
local my_string = 'A wonderful example of the string.gsub function.'
local replacedString = string.gsub(my_string, 'wonderful', 'superb')
print(replacedString)
--> A superb example of the string.gsub function. 1
|
This replaces the occurrences of 'wonderful' with 'superb' within the passed string and returns how many replacements were made. To omit the occurrence count, simply encapsulate the whole string.gsub function within parentheses:
Code: |
local my_string = 'A wonderful example of the string.gsub function.'
local replacedStringNoCount = (string.gsub(my_string, 'wonderful', 'superb'))
print(replacedStringNoCount)
-->A superb example of the string.gsub function.
|
This will get you started. You can find out more information within the documentation linked in previous posts. If you struggle to understand things then you are free to ask questions. |
You have given wonderful examples of finding/changing test with a text but find test within a set of memory records would be what I was seeking advice..
|
|
Back to top |
|
 |
LeFiXER Grandmaster Cheater Supreme
Reputation: 20
Joined: 02 Sep 2011 Posts: 1066 Location: 0x90
|
Posted: Sat Jul 08, 2023 12:10 pm Post subject: |
|
|
bknight2602 wrote: |
You have given wonderful examples of finding/changing test with a text but find test within a set of memory records would be what I was seeking advice.. |
This is practically spoonfeeding at this point. You already know how to get the description of the memory record, including how to loop through the address list:
Code: |
for i = 0, AddressList.Count - 1 do
local memory_record = AddressList.MemoryRecord[i]
-- Here you have access to every property of the memory record class, see link below
memory_record.description = string.gsub(memory_record.description, 'text_to_replace', 'text_to_replace_with')
end
|
This will search the description of the memory record for the text 'text_to_replace' and replace it with 'text_to_replace_with' (providing the gsub function finds it), and set the description of the memory record accordingly.
celua.txt/memory_record
Now, I really, really, really, really, REALLY suggest you do read through the Lua documentation. Test the code, see what it does, try to understand it and if you don't you can always ask questions here on this forum under the appropriate section. It is the only way you will ever get where you want to be without people giving you the answers all the time.
|
|
Back to top |
|
 |
bknight2602 Grandmaster Cheater
Reputation: 0
Joined: 08 Oct 2012 Posts: 582
|
Posted: Sat Jul 08, 2023 9:08 pm Post subject: |
|
|
LeFiXER wrote: | bknight2602 wrote: |
You have given wonderful examples of finding/changing test with a text but find test within a set of memory records would be what I was seeking advice.. |
This is practically spoonfeeding at this point. You already know how to get the description of the memory record, including how to loop through the address list:
Code: |
for i = 0, AddressList.Count - 1 do
local memory_record = AddressList.MemoryRecord[i]
-- Here you have access to every property of the memory record class, see link below
memory_record.description = string.gsub(memory_record.description, 'text_to_replace', 'text_to_replace_with')
end
|
This will search the description of the memory record for the text 'text_to_replace' and replace it with 'text_to_replace_with' (providing the gsub function finds it), and set the description of the memory record accordingly.
celua.txt/memory_record
Now, I really, really, really, really, REALLY suggest you do read through the Lua documentation. Test the code, see what it does, try to understand it and if you don't you can always ask questions here on this forum under the appropriate section. It is the only way you will ever get where you want to be without people giving you the answers all the time. |
Well the Lua documentation does not give an example of searching a set of memory records, just text within a string as you presented. Yes it may be spoon feeding but never the less I asked the question because I did not understand. Ypu may be the type of leaner that can read a manual and directly transfer that information to your task at hand, but not all of us are wired that way.
I thank you for your time and help.
|
|
Back to top |
|
 |
LeFiXER Grandmaster Cheater Supreme
Reputation: 20
Joined: 02 Sep 2011 Posts: 1066 Location: 0x90
|
Posted: Sun Jul 09, 2023 12:53 pm Post subject: |
|
|
bknight2602 wrote: |
Well the Lua documentation does not give an example of searching a set of memory records, just text within a string as you presented. Yes it may be spoon feeding but never the less I asked the question because I did not understand. Ypu may be the type of leaner that can read a manual and directly transfer that information to your task at hand, but not all of us are wired that way.
I thank you for your time and help. |
You're quite right that the Lua documentation does not give explicit examples on how to obtain memory records within Cheat Engine. I have seen several threads of yours demonstrating your ability to access certain properties of the memory records. Think of it this way in a similar way of fixing a car, no two cars are the same yet they both have an engine, they both have certain components which make the car drive and when things go wrong fixing it becomes a matter of principle in the sense that the technique is the same but will differ slightly from car to car. Programming is very much the same, the techniques are the same.
It very much sounds like you lack understanding of functions (or methods, whichever you prefer) and parameters (or arguments, whichever you prefer). Let me give an example:
Code: |
local function my_function(a,b)
return a + b
end
|
Here we have a locally declared function which takes two parameters, a and b. The function will add both values together and return that value to whomever called it.
Code: |
local my_added_value = my_function(5,10)
|
Here 'my_added_value' will total 15 in this example. You are declaring a local variable which stores the return value of the function. It's the same technique used to set the description of the memory record. You are retrieving the object which contains the property 'description' and setting it based on the return value of the function string.gsub. Maybe this doesn't make sense, maybe it does (I can only hope it does).
I'm not questioning one's ability to learn, the documentation is there to help you understand how the functions are used. It's then your own thoughts that decide what to do with those functions. Anyway, I'm just waffling at this point. I hope you understand what I mean and can take something from this. I never commented in a bid to knock your confidence, ability or even upset you in any way. I just try to encourage those to really practice and try on their own backs because it's far more gratifying doing something without aid. You're more than welcome for the assistance; if you have any further questions do feel free to ask.
|
|
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
|
|