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 


pointerstring mistakes tester

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
mgr.inz.Player
I post too much
Reputation: 145

Joined: 07 Nov 2008
Posts: 4107
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sat May 13, 2017 4:16 pm    Post subject: pointerstring mistakes tester Reply with quote

This code will add additional check for all Lua functions which are using address as parameter.

It should catch those:
Code:

readInteger('[basePtr]+4F10]') - too many closing bracket ']'
readInteger('[basePtr+4F10')   - missing closing bracket ']'
readInteger('basePtr]+4F10')   - missing opening bracket ']'

readInteger, and the rest from this function family, will just return a nil value.

writeInteger, and the rest from this function family, will return a nil or false, false when errorOnLookupFailure is set to false.

readBytes - will throw "Error:Failure determining what ... means" exception and break Lua execution, or nil when errorOnLookupFailure is set to false.

writeBytes - will throw "Error:Failure determining what ... means" exception and break Lua execution, or 0 when errorOnLookupFailure is set to false.

getAddress - will throw "Error:Failure determining what ... means" exception and break Lua execution, or 0 when errorOnLookupFailure is set to false.



Of course, you might think those are easy to find mistakes. But, imagine you have many level5 or above pointers and your script has few hundreds lines.


With this Lua script you will get exact line number:
Code:
local function addressMistakeCheck(addressString)
  --debug
  --print(addressString)

  local counted_leftBracket,counted_rightBracket = 0,0

  addressString:gsub('%[',function (c) counted_leftBracket=counted_leftBracket+1 end)
  addressString:gsub(']',function (c) counted_rightBracket=counted_rightBracket+1 end)

  if ((counted_leftBracket>0) or (counted_rightBracket>0)) and
     (counted_leftBracket~=counted_rightBracket) then
    local dbgInf3 = debug.getinfo(3)
    local isAALuaCode = (stringToMD5String(dbgInf3.short_src)=='313cfbaaa930b9d4e2ed8108511db63a') or
                        (stringToMD5String(dbgInf3.short_src)=='cc1345622ea008b92ad7f1b6f4de8f49')
    local extraInfo = isAALuaCode and ' (counting starts from {$Lua} line)' or ''
    print('"address" parameter must have the same amount of "[" and "]"')
    print('line number: '..(dbgInf3.currentline + (isAALuaCode and -1 or 0))..extraInfo)
  end

end

registerSymbolLookupCallback( addressMistakeCheck, slNotInt)



Script is designed as additional tool for debugging huge tables with mulilevel pointers used in Lua script.

_________________
Back to top
View user's profile Send private message MSN Messenger
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