|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
++METHOS I post too much Reputation: 92
Joined: 29 Oct 2010 Posts: 4197
|
Posted: Wed Jan 26, 2022 11:07 am Post subject: Stack Overflow Error |
|
|
I have this segment of code in my script:
Code: | if (isKeyPressed(22535)) or (isKeyPressed(38)) then
writeBytes('higher_input', 1); |
Sometimes, CE is unable to determine was 'higher_input' is, and I receive a stack overflow error that spams CE to the point that I cannot do anything else and have to force end process.
Is there a way to check if 'higher_input' is nil or similar to avoid this error?
This is the entire lua:
Code: | [ENABLE]
{$lua}
_G._hotkeyTimer = createTimer();
_G._hotkeyTimer.Interval = 10;
_G._hotkeyTimer.OnTimer = function (t)
if (isKeyPressed(22535)) or (isKeyPressed(38)) then
writeBytes('higher_input', 1);
else
writeBytes('higher_input', 0);
end
if (isKeyPressed(22534)) or (isKeyPressed(40)) then
writeBytes('lower_input', 1);
else
writeBytes('lower_input', 0);
end
if (isKeyPressed(22560)) or (isKeyPressed(87)) then
writeBytes('north_input', 1);
else
writeBytes('north_input', 0);
end
if (isKeyPressed(22561)) or (isKeyPressed(83)) then
writeBytes('south_input', 1);
else
writeBytes('south_input', 0);
end
if (isKeyPressed(22562)) or (isKeyPressed(68)) then
writeBytes('east_input', 1);
else
writeBytes('east_input', 0);
end
if (isKeyPressed(22563)) or (isKeyPressed(65)) then
writeBytes('west_input', 1);
else
writeBytes('west_input', 0);
end
end
{$asm} |
Code: | [DISABLE]
{$lua}
if (_G._hotkeyTimer ~= nil) then
_G._hotkeyTimer.destroy();
_G._hotkeyTimer = nil;
end
{$asm} |
Thanks.
Description: |
|
Filesize: |
15.91 KB |
Viewed: |
1700 Time(s) |
|
Description: |
|
Filesize: |
42.49 KB |
Viewed: |
1700 Time(s) |
|
|
|
Back to top |
|
|
LeFiXER Grandmaster Cheater Supreme Reputation: 20
Joined: 02 Sep 2011 Posts: 1053 Location: 0x90
|
Posted: Wed Jan 26, 2022 11:13 am Post subject: |
|
|
Something like this.
Code: |
if getAddress('higher_input') ~= nil then
writeBytes('higher_input', 1);
end
|
|
|
Back to top |
|
|
panraven Grandmaster Cheater Reputation: 54
Joined: 01 Oct 2008 Posts: 941
|
Posted: Wed Jan 26, 2022 11:57 am Post subject: |
|
|
<Never mind, please ignore. I missed read again, sorry>
The logic of the series 'if key1 or key2 then else end' to writing the same address is tricky.
No matter what previous key is checked, the end result will only be the last 'if then else end'
May be you what a single check that if any of the said key pressed set to 1, else set to 0?
Not sure the cause of the stack overflow, but if it is cause by writing unreadable memory, then if can be avoid by checking if readable first,ie.
Code: |
local readable = readSmallInteger'higher_input' -- may be readBytes work better, but older version readBytes will spawn error instead of return nil
if readable then
if key1Pressed or key2Pressed or key3Pressed or key4Pressed or ... then
write('higher_input',1)
else
write('higher_input',0)
end
end
|
_________________
- Retarded. |
|
Back to top |
|
|
++METHOS I post too much Reputation: 92
Joined: 29 Oct 2010 Posts: 4197
|
Posted: Wed Jan 26, 2022 12:27 pm Post subject: |
|
|
LeFiXER wrote: | Something like this.
Code: |
if getAddress('higher_input') ~= nil then
writeBytes('higher_input', 1);
end
|
| -Thanks. However, this did not solve the problem.
panraven wrote: |
Code: |
local readable = readSmallInteger'higher_input' -- may be readBytes work better, but older version readBytes will spawn error instead of return nil
if readable then
if key1Pressed or key2Pressed or key3Pressed or key4Pressed or ... then
write('higher_input',1)
else
write('higher_input',0)
end
end
|
| -So far, this seems to be working. Thanks.
I really appreciate everyone's help.
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 138
Joined: 06 Jul 2014 Posts: 4275
|
Posted: Wed Jan 26, 2022 1:27 pm Post subject: |
|
|
The easiest way to solve this is to use errorOnLookupFailure. e.g. run this before createTimer:
Code: | errorOnLookupFailure(false) |
getAddress will give an error on symbol lookup failure the same way as writeBytes. getAddressSafe won't.
I'd use getAddressSafe and use the return value from that. And put that duplicated code in a function.
Code: | local function writeBoolOnKeysPressed(address, ...)
local a = getAddressSafe(address)
if not a then return false end
for _,v in ipairs{...} do
if isKeyPressed(v) then
return writeBytes(a, 1) == 1
end
end
return writeBytes(a, 0) == 1
end
_G._hotkeyTimer.OnTimer = function (t)
writeBoolOnKeysPressed('higher_input', 22535, 38)
writeBoolOnKeysPressed('lower_input', 22534, 40)
writeBoolOnKeysPressed('north_input', 22560, 87)
writeBoolOnKeysPressed('south_input', 22561, 83)
writeBoolOnKeysPressed('east_input', 22562, 68)
writeBoolOnKeysPressed('west_input', 22563, 65)
end
|
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
++METHOS I post too much Reputation: 92
Joined: 29 Oct 2010 Posts: 4197
|
Posted: Wed Jan 26, 2022 1:34 pm Post subject: |
|
|
ParkourPenguin wrote: | I'd use getAddressSafe | -Thanks. I will revisit this if I experience any more errors. So far, so good. I appreciate your help.
|
|
Back to top |
|
|
Frouk Master Cheater Reputation: 5
Joined: 22 Jun 2021 Posts: 489 Location: mov dword ptr [Ukraine]
|
Posted: Thu Jan 27, 2022 3:36 am Post subject: |
|
|
I had this issue because i haven't known lua yet
One more solution is check if opened process id equals to existing one
Code: | function IsAttached() --returns true if attached to game process else it will return false
return getOpenedProcessID() == getProcessIDFromProcessName("game.exe")
end
--[[
--Another function tho it might be used
function IsGameProcessExists()
return getProcessIDFromProcessName("game.exe") ~= nil
end
--]] |
In timer insert line in first line of timer function
Code: | if not IsAttached() then return end |
it might give some errors tho
_________________
void(__cdecl *Haxing)(HWND hGameWindow) |
|
Back to top |
|
|
++METHOS I post too much Reputation: 92
Joined: 29 Oct 2010 Posts: 4197
|
Posted: Thu Jan 27, 2022 3:53 am Post subject: |
|
|
Frouk wrote: | One more solution | -Thanks. I will try all other suggestions if I have any more problems. So far, panraven's solution is thankfully working without issues.
Thanks.
|
|
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
|
|