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 


executing template

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting -> Lua Extensions
View previous topic :: View next topic  
Author Message
panraven
Grandmaster Cheater
Reputation: 26

Joined: 01 Oct 2008
Posts: 667

PostPosted: Wed Jul 19, 2017 9:50 pm    Post subject: executing template Reply with quote

It seem the original thread have been deleted by OP, so here a quick dirty make of an executing template.

It use etlua
which allow insert lua output string into AA during Prologue stage (registerAutoAssemblerPrologue, before AOB).

It change the tostring inside the etlua.lua to give hex number for number type for AA script usage, it should won't affect other part of Lua in CE.

Code:



------------ setup start ---------
local ToString = tostring
local _disp = function(e)
  local et = type(e)
  if et=='number' then
    return e<0 and string.format("-%X",-e) or string.format("%X",e)
  else
    return ToString(e)
  end
end

tostring = _disp -- use our hex number tostring
local etlua = require'etlua'
tostring = ToString -- restore

etluaSeeSource = true
etluaIsDebug = true
-- set false if not need to debug,
-- etlua only give its own parsing error,
-- likely with WRONG source line number, if any.
-- etlua error likely cause AA error, and ...
-- AA error (even etlua have no error) likely give
-- WRONG source line number too

local function etluaParser(s,sc)
  local trimL,trimR
  if s.Count>0 then
    trimL,trimR = s[0]:match"^%s*(////+)%s*[Ee][Tt][Ll][Uu][Aa]%s*%p*%s*(.-)$"
  end
  if trimL then
    s.Delete(0)
    s.Insert(0,table.concat{trimL,trimR})
    local code = s.Text
    local newcode,err = etlua.render(code,_G)
    if newcode then
      s.Text = newcode
      if etluaSeeSource then print(newcode)end
    elseif etluaIsDebug then
      print"*** etlua parsing error:"
      print(tostring(err))
    end
  end
end
if _regID then
  unregisterAutoAssemblerPrologue(_regID)
end
_regID = registerAutoAssemblerPrologue(etluaParser)

------------ setup end ---------
-- no need to run setup another time


--- test -- the [ENABLE] part

local script = [[
////etlua <-- IMPORTANCE: 1st line must begin with [////etlua] to get preprocesser to work

<%  --- begin multi-line lua
-- we need address1 defined before other etlua parsing
-- this autoAssemble not use etlua because not begin with  /////etlua

autoAssemble[=[
unregistersymbol(address1)
label(address1)
registersymbol(address1)

$process:
address1:

]=]

  %>    ///<--- end lua

unregistersymbol(address2)
label(address2)
registersymbol(address2)
<%  local choose = 2  -- lua chunks...  %>
<% if (choose == 1) then %>

address1+10:
address2:

<% elseif (choose==2) then%>

address1+20:
address2:

<% elseif (choose==3) then%>

address1+30:
address2:

<% elseif (choose==4) then%>

address1+40:
address2:

<% end %>


]]


print(tostring(autoAssemble(script)))




How to setup:
== local use:
1 copy and paste [setup start ~ setup end] into a lua file
2 save this file in your CE/autorun directory
3 download etlua.lua, save it in your CE directory (not autorun)

== embed in *.CT
1 same as 1, but give it a name, eg. etlua_aa.lua
2 download etlua.lua, save somewhere
3 in your *.CT load etlua_aa.lua and etlua.lua as table file, menu:table>add file, (!check if CE change the file name)
4 replace original lua 'require' with:
Code:


OriginalRequire = OriginalRequire or _G.require
function require (modulename)
  local m, pkl = modulename, package.loaded
  if pkl[m] then return pkl[m] end
  local tf = findTableFile(m) or findTableFile(m..'.lua')
  if tf then
    local ss = createStringStream()
    local ms = tf.Stream
    ss.Position,ms.Position=0,0
    ss.CopyFrom(ms,ms.Size)
    local src = ss.DataString
    ss.Destroy()
    local ok,ret = pcall(load,src,'-',nil,_ENV or _G)
    if ok then ok,ret = pcall(ret,m,[[_:\]]..m..'.lua')end
    if ok then
      pkl[m] = ret or true
      return pkl[m]
    end
  end
  return OriginalRequire(modulename)
end


then somewhere (lua script in MR for CT, or in lua engine in cetrainer)
require"etlua_aa" -- no ext ".lua"
eg. in an initializing MR :
Code:

{$lua}
if syntaxcheck then return end
[ENABLE]
OriginalRequire = OriginalRequire or G.require  -- paste modified require definition here
function require (modulename)
  ...
end

require"etlua_aa" -- load the executing templae, it should auto load the etlua.lua

etluaSeeSource = false
etluaIsDebug = false  -- turn off debug


[DISABLE]
_G.require = OriginalRequire  -- restore original require
-- could be just after previous require if no other module need to load.


check the filename in loaded table file, they have to be exact match, since table file name matching is case-sensitive.


--ADDED:
this two global in the script
etluaSeeSource = true
etluaIsDebug = true
is for limited debug.

set them true or false as need, add example in previous script

--ADDED:
Advice not execute timely action ,eg aobscan within etlua's lua execution since it must parse the script during syntaxcheck which may not have expected result worth the time waiting.

bye~

_________________
- Retarded.
dropbox
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 -> Lua Extensions 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