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 


Cheat engine becomes unresponsive

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
axelsword
How do I cheat?
Reputation: 0

Joined: 06 Jul 2011
Posts: 9

PostPosted: Sat Apr 09, 2016 11:37 am    Post subject: Cheat engine becomes unresponsive Reply with quote

Hello!

Could someone (debug) resolve possible memory leaks in this piece of code?
The problem is that cheatengine becomes unresponsive sometime after or immediately when executing this under "table -> show cheat table lua script".
The cause could be the "getvalue" and "setvalue" bits
Code:
local rep=tonumber(memoryrecord_getValue(gg)) --line 25


Update: Cheat engine becomes unresponsive and makes the PC un-usable ONLY when freeze is left on for longer time. I'm running Win 8.1 64bit. Can't open task manager, and other apps like browser, notepad are stuck.

Reformatted for readability
Code:

local function traincheat()
   local addresslist=getAddressList()
   local starAdr="003AB83F"
   local description1="train slot "
   local doFreeze=true
   local endFreezeatSlot=20
   local freezeSlotCounter=addresslist.getCount()+endFreezeatSlot
   local x=addresslist.getCount()+endFreezeatSlot
   x=x-2
   local temp=tonumber("0x"..starAdr)
   local offset=16
   freezeSlotCounter=freezeSlotCounter-1
   local c=2

   for i=addresslist.getCount(),x do
      addresslist.createMemoryRecord()
      local gg=addresslist.getMemoryRecord(i)
      memoryrecord_setType(gg,"byte")
      temp=temp+offset
      local hx=string.format("%X",temp)
      memoryrecord_setAddress(gg,hx)
      memoryrecord_setDescription(gg,description1..c)
      --set the default item stack size to 5
      local rep=tonumber(memoryrecord_getValue(gg))
      if rep then
         if rep>0 and rep<5 then memoryrecord_setValue(gg,5)
         end
      end
      if doFreeze and i<freezeSlotCounter and tonumber(memoryrecord_getValue(gg))>0 then
memoryrecord_freeze(gg)
      end
      c=c+1
   end

end

traincheat()


Thank you!


Last edited by axelsword on Sat Apr 16, 2016 2:47 am; edited 17 times in total
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4700

PostPosted: Sat Apr 09, 2016 1:54 pm    Post subject: Reply with quote

  • Local variables are a thing that exist. Use them.
  • Assigning variables right after you initialize them is redundant.
  • Stop using deprecated functions. They're not in the documentation; you're just copying someone else's outdated work.
  • Correctly format your code. It helps everyone read it (including you).
  • The garbage collector will run on its own. There's no need for you to make it run.

Debugging it should be easy enough. Just start commenting out lines of code until executing the script doesn't hang anymore.

What exactly is this script suppose to do?

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
axelsword
How do I cheat?
Reputation: 0

Joined: 06 Jul 2011
Posts: 9

PostPosted: Sun Apr 10, 2016 12:41 am    Post subject: What the code does Reply with quote

This code automates the adding of addresses to cheat table.

After doing a search manually, this code takes that address and adds 13 addresses with offset of 10 (16 in hex).

This is to hack inventory slots that are 10 spaces apart in memory. So from a starting address of DA95C80 the desired effect is to replace manual process of highlighting the search result in cheat table, pressing Ctrl+B to open memory view, pressing down arrow, then the special key on the right side of keyboard that opens right-click menu, pressing up arrow three times to highlight option "add this address to the list", pressing Tab to switch to "edit description", entering description, hitting Enter to confirm, and repeating until all inventory slots (that can be up to 1000 slots) are added, then frozen. Also editing numeric values that are larger than 0 and less than 5 to be 5 by default.
As you'd imagine, that's a lot of work.

The addresses would be
DA95C90
DA95CA0
DA95CB0
DA95CC0

or (10 is decimal, so must use 90+10 to get next address)
DA95C80+10
DA95C80+20
DA95C80+30
DA95C80+40

Hex values code from this forum post is very helpful indeed.
forum.cheatengine.org/viewtopic.php?t=588506
(won't allow to post as url)
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4700

PostPosted: Sun Apr 10, 2016 10:32 am    Post subject: Reply with quote

I don't think you understand how hexadecimal numbers work, especially with memory records.

Hexadecimal refers to the base-16 number system, and decimal refers to the base-10 number system. So, 10 in hex is 16 in decimal- not the other way around. 10 in decimal is A in hex. 11 is B, 12 is C, and so on.

A memory record's address is a string that is suppose to represent a hexadecimal number in some manner. As such, you don't have to do something like +90+10, because that would just be +A0 (in hex).

Here's how I would go about doing it:
Code:
function addAddresses(startAddress, num, step, minValue, freezeNum)
  local al = getAddressList()
  local addy = startAddress or "0"
  if type(addy) ~= "string" then addy = string.format("%X", addy) end
  if type(num) ~= "number" then num = tonumber(num) end
  if type(step) == "string" then step = tonumber(step, 16) end
  if type(minValue) ~= "number" then minValue = tonumber(minValue) end
  if type(freezeNum) ~= "number" then freezeNum = tonumber(freezeNum) end
  if not step or step < 1 then step = 1 end

  local header = al.createMemoryRecord()
  header.Address = addy
  header.Type = vtString
  header.String.Size = 0
  header.Description = "Inventory Addresses"

  for i = 1, num or 10 do
    local r = al.createMemoryRecord()
    r.appendToEntry(header)
    r.Address = string.format("+%X", i * step)
    r.Type = vtByte
    r.Description = "train slot " .. i
  end

  -- workaround due to a bug
  local t = createTimer()
  t.Interval = 100
  t.OnTimer = function(timer)
    for i = 0, header.Count - 1 do
      local r = header[i]
      if freezeNum and i < freezeNum then
        r.Active = true
      end
      if minValue and (tonumber(r.Value) or minValue) < minValue then
        r.Value = tostring(minValue)
      end
    end
    timer.destroy()
  end
end

Now, if you type in addAddresses("1234ABCD", 1000, 0x10, 5, 100), it will add the addresses starting at 1234ABDD going to 1234EA4D (inclusive) to the address list under the header "Inventory Items", set them to 5 if they're below 5, and freeze the first 100 records it adds. It's done in a way that you can just change the address of the header and all the other addresses will automatically update. You can also right click on the header and go to "Group Config" for a couple ways to hide all the entries.

PS: you could also use tonumber(num, 16) instead of tonumber("0x"..num).

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
axelsword
How do I cheat?
Reputation: 0

Joined: 06 Jul 2011
Posts: 9

PostPosted: Sun Apr 10, 2016 3:03 pm    Post subject: Thanks for help Reply with quote

Thank you for the code!

I do understand hex counting. When I searched around, I couldn't find hex support for LUA. Your code does math in decimal and translates it to string. I was feeding addresses with offsets.

It would be nice to know where I could find the updated documentation so I could stop using depreached functions. I was going by the wiki
wiki.cheatengine.org/index.php?title=MemoryRecord

I modified your code to freeze records of values greater than 0. It's needed because some inventory slots are empty and freezing them causes game to crash.
Code:

  t.OnTimer = function(timer)
    for i = 0, header.Count - 1 do
      local r = header[i]
      if minValue and tonumber(r.Value) and freezeNum and i < freezeNum then
        local ft=tonumber(r.Value)
        if ft>0 and ft < minValue then
           r.Value = tostring(minValue)
           r.Active = true
        end
      end
    end
    timer.destroy()
  end


Update: Game keeps running fine, but cheat engine becomes non-responsive process. This happens only when freeze is used on memory records. That spreads to other apps, probably due to cpu load or memory overfill.
Haven't tested enough, but right now on CE version 6.4 it happens only when leaving addresses frozen for long time. I'm not sure if addresses added manually and frozen cause the same. For a while everything seems to work, but then I notice that freeze isn't working and at that moment cheat engine has hanged.


Last edited by axelsword on Sat Apr 16, 2016 2:52 am; edited 2 times in total
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4700

PostPosted: Sun Apr 10, 2016 3:35 pm    Post subject: Reply with quote

Look at main.lua in the main CE directory.

All you need to do is google "lua hex" and everything that pertains to hexadecimal numbers in Lua comes up. To sum it up, prepend a number with 0x to make it a hexadecimal number, use tonumber(num, 16) to turn a hexadecimal string into a number, and use string.format("%X",...) to turn a number into a hexadecimal string. If you have any questions, look through the reference manual.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
axelsword
How do I cheat?
Reputation: 0

Joined: 06 Jul 2011
Posts: 9

PostPosted: Fri Apr 15, 2016 7:39 am    Post subject: update - problem not fixed Reply with quote

bump

Last edited by axelsword on Sat Apr 16, 2016 2:59 am; edited 1 time in total
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4700

PostPosted: Fri Apr 15, 2016 8:54 am    Post subject: Reply with quote

How many addresses are you freezing? Try unfreezing everything and see if that has any noticeable effect.

It might be useful to look at task manager to see what's going on.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
axelsword
How do I cheat?
Reputation: 0

Joined: 06 Jul 2011
Posts: 9

PostPosted: Sat Apr 16, 2016 2:58 am    Post subject: Test results Reply with quote

I was using CE version 6.4

Now I have installed 6.5, but haven't tested the script yet.

Previously addresses left frozen that were added by script made cheat engine process unresponsive.

I'm using Windows 8.1 64-bit, 8gb RAM
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
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