 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Hayjamieoliver Newbie cheater
Reputation: 0
Joined: 29 Nov 2016 Posts: 16 Location: idk
|
Posted: Fri Aug 25, 2017 6:43 pm Post subject: How to set if statements to hotkeys? |
|
|
A hack I am currently making concerns a certain value from each of up to 23 AI, which can be either 1 or 2. Half of the AI will be one, the other half two (the last one depends on what the player is) I currently have a pointer for every single AI, with the difference in the final offset being 8 in decimal (so in hex it does 100, 108, 110, 118, 120, etc). I have a separate pointer that always points to the address of the player's number.
The issue is based around two things:
- I want to be able to have a hotkey that when pressed, takes the value of each and every address pointed to by their respective pointer, and compares it to the number of the player.
- IF it is not the same, it will change it to the same as that of the player
- Once a different hotkey (or the same one, doesn't matter) is pressed, ONLY the changed values revert back to what they once were. Otherwise I would just set a hotkey that changes all of them to either 1 or 2 depending on what key I press.
I have basic knowledge of LUA, but I find assembly a bit confusing to be honest, and I'm not sure how to write lua scripts that access pointers from one's cheat table, let alone change them.
I would look it up, but most videos involving lua scripting seem to involve making trainers which is not much use to me.
_________________
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4711
|
Posted: Fri Aug 25, 2017 10:30 pm Post subject: |
|
|
| Code: | local changedAddresses = {}
setAIHotkey = createHotkey(function(hk)
-- look for stuff to change
local baseAddr = getAddress('[[game.exe+12E4B7C]+1A4]') -- everything except last offset
local playerVal = readInteger('[[game.exe+12E5DC4]+E0]+1C')
for offs = 0x100, 0x120, 8 do -- range is inclusive
local aiAddr = baseAddr + offs
local aiVal = readInteger(aiAddr)
if aiVal ~= playerVal then
writeInteger(aiAddr, playerVal)
changedAddresses[#changedAddresses+1] = {addr = aiAddr, val = aiVal}
end
end
end, VK_MENU, VK_F4) -- change hotkey key codes here
resetAIHotkey = createHotkey(function(hk)
for i = #changedAddresses, 1, -1 do
writeInteger(changedAddresses[i].addr, changedAddresses[i].val)
changedAddresses[i] = nil
end
end, VK_MENU, VK_F5) -- change hotkey key codes here |
If you want to access the address list instead, look up examples using getMemoryRecordByDescription. If the records are under a header, you can enumerate the children of the header using the Count and Child[index] properties. See celua.txt for documentation.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
Hayjamieoliver Newbie cheater
Reputation: 0
Joined: 29 Nov 2016 Posts: 16 Location: idk
|
Posted: Fri Aug 25, 2017 11:02 pm Post subject: |
|
|
Thank you very much! I assume if the final address is not used it won't cause a crash? The reason I ask is because there are options to reduce the number of AI, and that quite often causes some addresses not to be used (I.e the one with offset 110, 118 and 128 are used, but 120 is not).
It's great that people here are so helpful
_________________
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4711
|
Posted: Fri Aug 25, 2017 11:14 pm Post subject: |
|
|
| Hayjamieoliver wrote: | | I assume if the final address is not used it won't cause a crash? The reason I ask is because there are options to reduce the number of AI, and that quite often causes some addresses not to be used (I.e the one with offset 110, 118 and 128 are used, but 120 is not). |
I dunno. If it isn't broken, don't fix it. If it is broken, look for a value that differentiates those that are in use from those that are not in use. If it isn't in use, then don't bother changing it.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
Hayjamieoliver Newbie cheater
Reputation: 0
Joined: 29 Nov 2016 Posts: 16 Location: idk
|
Posted: Sat Aug 26, 2017 2:59 am Post subject: |
|
|
Okay, so I have tried using the script, but it doesn't seem to have any effect, so I figure I should just list everywhere where I'm unsure:
1: This is used by going to Table->Show Cheat Table Lua script, correct?
2: The initial address used by the pointers has quotation marks around the name of the game, whilst your example does not. I'm not sure if this is needed.
3: It is not the last, but rather the second offset which changes by 8 in decimal. I tried to resolve this by adding the remaining offsets later as seen below.
4: The VK_F4 means the script is bound to F4 the key I assume, I'm not sure what VK_Menu means.
Here's my modification:
| Code: | local changedAddresses = {}
setAIHotkey = createHotkey(function(hk)
-- look for stuff to change
local baseAddr = getAddress('[["InsertName.exe"+address]+1stoffset]') -- everything except last offset
local playerVal = readInteger('[[[[[["InsertName.exe"+address]+1stoffset]+F8]+3rdoffset]+4thoffset]+5thoffset]')
for offs = 0x100, 0x1B0, 8 do -- range is inclusive
local aiAddr = baseAddr + offs + 0x3rdoffset + 0x4thoffset + 0x5thoffset
local aiVal = readInteger(aiAddr)
if aiVal ~= playerVal then
writeInteger(aiAddr, playerVal)
changedAddresses[#changedAddresses+1] = {addr = aiAddr, val = aiVal}
end
end
end, VK_MENU, VK_F4) -- change hotkey key codes here
resetAIHotkey = createHotkey(function(hk)
for i = #changedAddresses, 1, -1 do
writeInteger(changedAddresses[i].addr, changedAddresses[i].val)
changedAddresses[i] = nil
end
end, VK_MENU, VK_F5) -- change hotkey key codes here |
Sorry to be such a bother, it becomes quite hard to find info once you get into the later stages of cheat engine stuff.
_________________
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4711
|
Posted: Sat Aug 26, 2017 9:24 am Post subject: |
|
|
1: Yes. Click on "Execute" to execute the code. Make sure you destroy the previous hotkeys if you execute the script more than once. I.e. put this at the beginning:
| Code: | if setAIHotkey then setAIHotkey.destroy(); setAIHotkey=nil end
if resetAIHotkey then resetAIHotkey.destroy(); resetAIHotkey=nil end |
2: It shouldn't hurt.
3: That's not how you traverse a pointer path. If you don't know how, let CE do it for you.
| Code: | ...
for offs2 = 0x100, 0x1B0, 8 do -- range is inclusive
local aiAddr = getAddress(('[[[%08X+%X]+%X]+%X]+%X'):format(baseAddr, offs2, offs3, offs4, offs5))
local aiVal = readInteger(aiAddr)
if aiVal ~= playerVal then
writeInteger(aiAddr, playerVal)
changedAddresses[#changedAddresses+1] = {addr = aiAddr, val = aiVal}
end
end
... | (hint: the square brackets in a pointer path string tell CE to read the value at that address; read this for more information)
4: VK_MENU is the ALT key. Look in defines.lua for the other definitions CE provides, and look at MSDN for a full list.
(I bound those keys to the hotkey because I expect you to change them and not just copy and paste it)
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
Hayjamieoliver Newbie cheater
Reputation: 0
Joined: 29 Nov 2016 Posts: 16 Location: idk
|
Posted: Sat Aug 26, 2017 5:22 pm Post subject: |
|
|
| Code: | if setAIHotkey then setAIHotkey.destroy(); setAIHotkey=nil end
if resetAIHotkey then resetAIHotkey.destroy(); resetAIHotkey=nil end
local changedAddresses = {}
setAIHotkey = createHotkey(function(hk)
-- look for stuff to change
local baseAddr = getAddress('[[gamename.exe+202020]+aioffset1]')
local playerVal = readInteger('[[[[[[gamename.exe+02020202]+playeroffset1]+playeroffset2]]+playeroffset3]+playeroffset4]+playeroffset5)
for offs2 = 0x100, 0x1B0, 8 do -- range is inclusive
local aiAddr = getAddress(('[[[baseAddr+offs2]+aioffset3]+aioffset4]+aioffset5'):format(baseAddr, offs2, offs3, offs4, offs5))
local aiVal = readInteger(aiAddr)
if aiVal ~= playerVal then
writeInteger(aiAddr, playerVal)
changedAddresses[#changedAddresses+1] = {addr = aiAddr, val = aiVal}
end
end
end, VK_MENU, VK_F4) -- change hotkey key codes here
resetAIHotkey = createHotkey(function(hk)
for i = #changedAddresses, 1, -1 do
writeInteger(changedAddresses[i].addr, changedAddresses[i].val)
changedAddresses[i] = nil
end
end, VK_MENU, VK_F5) -- change hotkey key codes here |
I'm unsure as to what was the placeholder in the code you gave, whether it was X or % or both, but from the link you provided the syntax seemed to not require either? Of course that raises the question of how to use variables declared in the script without it trying to interpret it as hex, so I figure I must be missing something here.
I tried instead doing this: | Code: | | local aiAddr = getAddress(('[[[%08X+%X]+%X]+%X]+%X'):format(baseAddr, offs2, 0xB8, 0x658, 0x24)) |
But it didn't change anything, unfortunately.
I realise I'm making some really dumb or beginner mistake here, it's probably very frustrating for you, so I'm really sorry I'm having such trouble with such a simple thing :[
(The things that are written in their full length are representations, contracted words are as written, so offs2 is literally offs2 whilst aioffset3 is the third offset)
_________________
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4711
|
Posted: Sat Aug 26, 2017 5:57 pm Post subject: |
|
|
string.format uses the same format specifiers as ISO C sprintf.
You were correct in your second assessment (assuming those other offsets are correct). If it still doesn't work, debug the code. E.g. put print statements at certain places in the code that provide information as to what the script is doing.
P.S.: you still haven't changed the key codes.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
Hayjamieoliver Newbie cheater
Reputation: 0
Joined: 29 Nov 2016 Posts: 16 Location: idk
|
Posted: Sat Aug 26, 2017 6:11 pm Post subject: |
|
|
Oh okay, where would it output the printed text?
I have yet to change the key codes because I want it to work before I bother changing what key activates the code.
_________________
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4711
|
Posted: Sat Aug 26, 2017 6:19 pm Post subject: |
|
|
Output from print is shown in the Lua engine console. If any print statement is executed, that window is shown. If it isn't showing up, you aren't printing anything.
I highly doubt you're actually pressing alt + F4 to execute the hotkey. If you were, you should be having other problems. I made the script that way because I don't like people copying and pasting code without knowing what it does.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
Hayjamieoliver Newbie cheater
Reputation: 0
Joined: 29 Nov 2016 Posts: 16 Location: idk
|
Posted: Sat Aug 26, 2017 6:21 pm Post subject: |
|
|
welp uh
yeeeah I actually was pressing one or the other. I didn't realise it was alt AND f4 rather than alt or f4. My bad.
EDIT: okay, so I actually ran the script now, but I'm getting the following errors:
| Code: |
Error:[string "if setAIHotkey then setAIHotkey.destroy(); se..."]:11: bad argument #3 to 'format' (number expected, got nil)
Error:[string "local changedAddresses = {}..."]:8: bad argument #3 to 'format' (number expected, got nil)
|
The below one appears when I remove the stuff you suggested I add at the top, since it appears to be causing an issue.
Re-edit:
okay, I've rechecked all the code, found out one the the offsets was missing it's "0x". The issue is that it doesn't seem to be able to read the game's addresses inside the for loop?
Me trying as is:
Error:Failure determining what [[[02020202+100]+aioffset3]+aioffset4]+aioffset5 means
Me trying with the game's name put int first if that mattered.
Error:Failure determining what [[[InsertGame.exe+02020202+100]+aioffset3]+aioffset4]+aioffset5 means
Me adding an additional pair of square brackets
Error:Failure determining what [[[[InsertGame.exe+02020202]+100]+aioffset3]+aioffset4]+aioffset5 means
it's very odd to me, because it doesn't object to the address in the first instance, I even added a print that starts right after the for loop begins just to confirm that the first one is going through. I have the game open in cheat engine as well. I also checked whether the path itself was valid, manually making a pointer and using the modified address (shown as 02020202 above) as the initial value, and adding the offsets accordingly, and it DID lead me to the correct address.
_________________
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4711
|
Posted: Sat Aug 26, 2017 7:57 pm Post subject: |
|
|
Make sure you're using the code I said was correct.
| Code: | | local aiAddr = getAddress(('[[[%08X+%X]+%X]+%X]+%X'):format(baseAddr, offs2, 0xB8, 0x658, 0x24)) |
Putting a random string in place of an offset doesn't make any sense in a pointer path. CE knows how to resolve symbols (e.g. module names and registered user symbols), but it doesn't know what something like "aioffset3" is. That's why you should use string.format to insert the integer into the string in hexadecimal notation (CE parses offsets as hex).
If you can't figure it out yourself, copy and paste your entire unedited code (except for module names) and it will be much easier to point out what's wrong.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
Hayjamieoliver Newbie cheater
Reputation: 0
Joined: 29 Nov 2016 Posts: 16 Location: idk
|
Posted: Sat Aug 26, 2017 8:06 pm Post subject: |
|
|
| Code: | if setAIHotkey then setAIHotkey.destroy(); setAIHotkey=nil end
if resetAIHotkey then resetAIHotkey.destroy(); resetAIHotkey=nil end
local changedAddresses = {}
setAIHotkey = createHotkey(function(hk)
-- look for stuff to change
local baseAddr = getAddress('[Insertgame.exe+02B47F58]+50') -- everything except last offset
local playerVal = readInteger('[[[[[Insertgame.exe+02B5D718]+420]+450]+C0]+58]+24')
print (playerVal)
for offs2 = 0x100, 0x1B0, 8 do -- range is inclusive
print("getting ai addresses")
local aiAddr = getAddress(('[[[[%08X+%X]+%X]+%X]+%X'):format(baseAddr, offs2, 0xB8, 0x658, 0x24))
local aiVal = readInteger(aiAddr)
if aiVal ~= playerVal then
writeInteger(aiAddr, playerVal)
changedAddresses[#changedAddresses+1] = {addr = aiAddr, val = aiVal}
end
end
end, VK_MENU, VK_F3) --set to f3 since f4 closes game lol
resetAIHotkey = createHotkey(function(hk)
for i = #changedAddresses, 1, -1 do
writeInteger(changedAddresses[i].addr, changedAddresses[i].val)
changedAddresses[i] = nil
end
end, VK_MENU, VK_F5) -- chan |
error message:
Error:Failure determining what [[[[33795560+100]+B8]+658]+24 means <- this path leads to the correct address
_________________
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4711
|
Posted: Sat Aug 26, 2017 8:22 pm Post subject: |
|
|
Square brackets need to be balanced.
| Code: | | '[[[[%08X+%X]+%X]+%X]+%X' |
You have 4 opening square brackets and 3 closing square brackets. Remove one of the opening ones.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
Hayjamieoliver Newbie cheater
Reputation: 0
Joined: 29 Nov 2016 Posts: 16 Location: idk
|
Posted: Sat Aug 26, 2017 8:30 pm Post subject: |
|
|
Oh, that was just a remnant of when I added a bracket. The error message has not changed though. :/
_________________
|
|
| 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
|
|