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 


My module TrainerGen.lua

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Tutorials -> LUA Tutorials
View previous topic :: View next topic  
Author Message
GH*master
Expert Cheater
Reputation: 8

Joined: 10 Jan 2008
Posts: 159

PostPosted: Sun Jun 12, 2011 12:55 am    Post subject: My module TrainerGen.lua Reply with quote

This module can create your trainer as an example in the screenshot. There's just an example.

*.CETRAINER
Code:
<?xml version="1.0"?>
<CheatTable CheatEngineTableVersion="11">
  <CheatEntries/>
  <UserdefinedSymbols/>
  <LuaScript>
  require("TrainerGen")
function Initialize()
        bufScript = BeginGenerateAA("allocMem", "2048")
        bufScript = GenerateAAWithSignature(bufScript, "InfHealth1", "d9xxxxxxxxxx8bxxe8xxxxxxxx2bxx8bxxxx33xx2bxx83xxxx7dxx8axxxxxx84", "+X-C-W", 0, "mov [ebx+00000758],(float)100", true)
        bufScript = GenerateAAWithSignature(bufScript, "InfHealth2", "d9xxxxxxxxxx8bxxe8xxxxxxxx2bxx8bxxxx33xx2bxx83xxxx7dxx8axxxxxx84", "+X-C-W", 0, "mov [ebx+00000758],(float)100", true)
        bufScript = GenerateAAWithSignature(bufScript, "InfHealth3", "d9xxxxxxxxxx8bxxe8xxxxxxxx2bxx8bxxxx33xx2bxx83xxxx7dxx8axxxxxx84", "+X-C-W", 0, "mov [ebx+00000758],(float)100", true)
        bufScript = GenerateAAWithSignature(bufScript, "InfHealth4", "d9xxxxxxxxxx8bxxe8xxxxxxxx2bxx8bxxxx33xx2bxx83xxxx7dxx8axxxxxx84", "+X-C-W", 0, "mov [ebx+00000758],(float)100", true)
        bufScript = GenerateAAWithSignature(bufScript, "InfHealth5", "d9xxxxxxxxxx8bxxe8xxxxxxxx2bxx8bxxxx33xx2bxx83xxxx7dxx8axxxxxx84", "+X-C-W", 0, "mov [ebx+00000758],(float)100", true)
        bufScript = GenerateAAWithSignature(bufScript, "InfHealth6", "d9xxxxxxxxxx8bxxe8xxxxxxxx2bxx8bxxxx33xx2bxx83xxxx7dxx8axxxxxx84", "+X-C-W", 0, "mov [ebx+00000758],(float)100", true)
        bufScript = GenerateAAWithSignature(bufScript, "InfHealth7", "d9xxxxxxxxxx8bxxe8xxxxxxxx2bxx8bxxxx33xx2bxx83xxxx7dxx8axxxxxx84", "+X-C-W", 0, "mov [ebx+00000758],(float)100", true)
        bufScript = GenerateAAWithSignature(bufScript, "InfHealth8", "d9xxxxxxxxxx8bxxe8xxxxxxxx2bxx8bxxxx33xx2bxx83xxxx7dxx8axxxxxx84", "+X-C-W", 0, "mov [ebx+00000758],(float)100", true)
        bufScript = GenerateAAWithSignature(bufScript, "InfHealth9", "d9xxxxxxxxxx8bxxe8xxxxxxxx2bxx8bxxxx33xx2bxx83xxxx7dxx8axxxxxx84", "+X-C-W", 0, "mov [ebx+00000758],(float)100", true)
        EndGenerateAA(bufScript)
end

TrainerShow("F.E.A.R.XP Ttainer +9, v1.0, {MasterGH}", "FEARXP.exe", 290, 180, Initialize)</LuaScript>
</CheatTable>


Module TrainerGen.lua:
Code:
-- Version 1.0
-- Create by MasterGH

local frmTrainer = nil
local frmTrainerWidth = 0
local frmTrainerHeigth = 0
local messageLabel = nil

local _InitFunction

local countObjectHotKeys = 0
local adrList = nil
local baseHotKey = "CTRL"

   local function CheatAction(indexCheat)
      local te = addresslist_getMemoryRecord(adrList, indexCheat-1)
      if (memoryrecord_isActive(te))   then
         memoryrecord_unfreeze(te)
      else
         memoryrecord_freeze(te, 0)
      end
      beep()
   end

   function onHotkey1(hotkey) CheatAction(1) end
   function onHotkey2(hotkey) CheatAction(2) end
   function onHotkey3(hotkey) CheatAction(3) end
   function onHotkey4(hotkey) CheatAction(4) end
   function onHotkey5(hotkey) CheatAction(5) end
   function onHotkey6(hotkey) CheatAction(6) end
   function onHotkey7(hotkey) CheatAction(7) end
   function onHotkey8(hotkey) CheatAction(8) end
   function onHotkey9(hotkey) CheatAction(9) end

   local arrayFunction = {}
   arrayFunction[1] = onHotkey1
   arrayFunction[2] = onHotkey2
   arrayFunction[3] = onHotkey3
   arrayFunction[4] = onHotkey4
   arrayFunction[5] = onHotkey5
   arrayFunction[6] = onHotkey6
   arrayFunction[7] = onHotkey7
   arrayFunction[8] = onHotkey8
   arrayFunction[9] = onHotkey9

   local function Trainer_Close(sender)         
      closeCE()
      return caFree
   end   
   local function Trainer_SendMessage(message)
      control_setCaption(messageLabel, message)
   end
   local function Trainer_FormCreate(nameTrainer)
     frmTrainer = createForm(true)
     setProperty(frmTrainer, "BorderStyle", "bsDialog")
     control_setSize(frmTrainer, frmTrainerWidth, frmTrainerHeigth)
     control_setCaption(frmTrainer, nameTrainer)
     form_centerScreen(frmTrainer)
     form_onClose(frmTrainer, Trainer_Close)
    
     messageLabel = createLabel(frmTrainer)
     control_setAlign(messageLabel, alBottom)
     Trainer_SendMessage("Trainer is not ready")
   end
   local function Trainer_CheatsCreateFromCETable()
      if (adrList == nil) then
         adrList = getAddressList()
      end
      
      countObjectHotKeys = addresslist_getCount(adrList)
      if (countObjectHotKeys < 1 or countObjectHotKeys > 9) then
         showMessage("Cheats group count can not be less than 1 or greater than 9. Trainer will be closed")
         Trainer_Close()
      end
      
      local x = 20
      local y = 10
      local yInc = 14
      
      CheatLbl = createLabel(frmTrainer)
      control_setPosition(CheatLbl, x, y)
      control_setCaption(CheatLbl, "Cheats:")
      x = x + 15
      
      for i = 1,countObjectHotKeys do
         local te = addresslist_getMemoryRecord(adrList, i-1)
         local description = memoryrecord_getDescription(te)
         local ObjectHotKeys =  createHotkey(arrayFunction[i], VK_CONTROL, VK_0 + i) --string.format("%s",i)
         generichotkey_setKeys(ObjectHotKeys, VK_CONTROL, VK_0 + i)
         generichotkey_onHotkey(ObjectHotKeys, arrayFunction[i])
         
         CheatLbl = createLabel(frmTrainer)
         control_setPosition(CheatLbl, x, (i + 1) * yInc)
         local stringHotKey = baseHotKey.."+"..i
         control_setCaption(CheatLbl, i..") "..description..": "..stringHotKey)
      end

      Trainer_SendMessage("Trainer is ready!")
      beep()
   end
   
   function onOpenProcess(processid)
      _InitFunction()
      Trainer_CheatsCreateFromCETable()   
   end
   
   local function ByteScan(signature, typeMem)             -- return address   
      Trainer_SendMessage("Scaning mode... Play in game and wait bell")
      local results = nil
      repeat
      results = AOBScan(signature, typeMem) -- typeMem = "+X-C-W" and any
      sleep(200)
       until (results ~= nil)

      local address = stringlist_getString(results, 0)
      object_destroy(results)
      return address
   end   
   local function GetInfoInjection(address)               -- return adressReturnHere, originalCodeString, nopsString
      local sumBytes = 0
      local originalCodeString = "  "

      repeat
         countBytes = getInstructionSize(address)
         extrafield, opcode, bytes, address = splitDisassembledString(disassemble(address))
         originalCodeString = originalCodeString.."\n  "..opcode
         sumBytes = sumBytes + countBytes
      until (sumBytes >= 5)
      adressReturnHere = string.format("%x", ("0x"..address) + countBytes)
            
      local nopsString = ""
      local nopsCount = sumBytes - 5
      if (nopsCount>0) then
          nopsString = "  db"
          for i = 1, nopsCount do
            nopsString = nopsString.." 90"
          end
      end
      
      return adressReturnHere, originalCodeString, nopsString
   end
   local function PreSubScript(script, patternWord, newWords)   -- return bufferString
      local index = string.find(script, patternWord)
      local newscript = string.sub(script, 1, index - 1)..newWords.."\n"..string.sub(script, index)
      return newscript
   end
    local function SetScriptInEntryCETable(cheatName, script)
      local teSlave = getTableEntry(cheatName)
      if (teSlave == nil) then
         teSlave = addresslist_createMemoryRecord(addresslist)
         memoryrecord_setDescription(teSlave, cheatName)
      end
      memoryrecord_setType(teSlave, vtAutoAssembler)
      memoryrecord_setScript(teSlave, script)   
   end

-- SECTION 1
   function GenerateAAscriptPageMem_AndAddInCETable( cheatName, address, injectInstruction, originalcode )
      local addressInjection = address
      
      local adressReturnHere = 0
      local originalCodeString = ""
      local nopsString = ""
      adressReturnHere, originalCodeString, nopsString = GetInfoInjection(address)
      
     if (originalcode) then
      script =[[
   [ENABLE]
    alloc(newmem,2048)
    label(originalcode)
    label(returnhere)

    newmem:
      ]]..injectInstruction..[[

    originalcode:]]..originalCodeString.. [[

      jmp returnhere

    ]]..addressInjection..[[:
      jmp newmem
   ]]..nopsString..[[
    returnhere:

   [DISABLE]
    ]]..addressInjection..":"..originalCodeString.. [[


    dealloc(newmem)
   ]]
     else
      script =[[
   [ENABLE]
    alloc(newmem,2048)
    label(returnhere)

    newmem:
      ]]..injectInstruction..[[

      jmp returnhere

    ]]..addressInjection..[[:
      jmp newmem
   ]]..nopsString..[[
    returnhere:

   [DISABLE]
    ]]..addressInjection..":"..originalCodeString.. [[


    dealloc(newmem)
   ]]
     end
     SetScriptInEntryCETable(cheatName, script)
   end
   function FillnopsInstruction_AndAddInCETable(cheatName, address)
      adressReturnHere, originalCodeString, nopsString = GetInfoInjection(address)
      local scriptAddMainTable = "[ENABLE]\n-->>address1[DISABLE]\n-->>address2"

      local countBytes = getInstructionSize(address)
      local nopsString = "  db"
      for i = 1, countBytes do
         nopsString = nopsString.." 90"
      end

      scriptAddMainTable = PreSubScript(scriptAddMainTable,"-->>address1", address..":\n"..nopsString)
      scriptAddMainTable = PreSubScript(scriptAddMainTable,"-->>address2", address..":"..originalCodeString)
      scriptAddMainTable = string.gsub(scriptAddMainTable, "-->>address1", "")
      scriptAddMainTable = string.gsub(scriptAddMainTable, "-->>address2", "")
      SetScriptInEntryCETable(cheatName,scriptAddMainTable)
   end
   function FillnopsInstructionWithSignature_AndAddInCETable(cheatName, signature, typeMem, signatreOffset)
      local workAddress = ByteScan(signature, typeMem)
      if (signatureOffset ~=0) then
         workAddress = string.format("%x", ("0x"..workAddress) + signatureOffset)
      end
      FillnopsInstruction_AndAddInCETable(cheatName, workAddress)
   end

-- SECTION 2
   function BeginGenerateAA(newMemDescription, sizeMem)                                                       -- return bufferString
      return [[
   alloc(]]..newMemDescription..","..sizeMem..[[)
   registersymbol(]]..newMemDescription..[[)
   ->>label]]..newMemDescription..[[:

   ->>newCode
   ->>adressessInjected
   ]]
   end
   function GenerateAA(aggregateMem, cheatName, address, newCode, stateOriginalCode)                                  -- return bufferString 
      local addressInjection = address
      local adressReturnHere = 0
      local originalCodeString = ""
      local nopsString = ""
      adressReturnHere, originalCodeString, nopsString = GetInfoInjection(address)
      
      registerSymbol("returnHere_"..cheatName, adressReturnHere)
      
      local script = PreSubScript(aggregateMem,"->>label", "label("..cheatName..")")
      script = PreSubScript(script,"->>label", "registersymbol("..cheatName..")")
      
      if (stateOriginalCode) then
         script = PreSubScript(script,"->>label", "label(originalcode_"..cheatName..")")
         local buf = cheatName..":\n  "..newCode.."\noriginalcode_"..cheatName..":"..originalCodeString.."\n  jmp returnHere_"..cheatName
         script = PreSubScript(script,"->>newCode", buf)
      else
         script = PreSubScript(script,"->>newCode", cheatName..":\n"..newCode.."\n  jmp returnHere_"..cheatName)
      end
      
      local scriptAddMainTable = "[ENABLE]\n-->>address1[DISABLE]\n-->>address2"
      scriptAddMainTable = PreSubScript(scriptAddMainTable,"-->>address1", addressInjection..":\n  jmp "..cheatName.."\n"..nopsString)
      scriptAddMainTable = PreSubScript(scriptAddMainTable,"-->>address2", addressInjection..":"..originalCodeString)
      scriptAddMainTable = string.gsub(scriptAddMainTable, "-->>address1", "")
      scriptAddMainTable = string.gsub(scriptAddMainTable, "-->>address2", "")
      SetScriptInEntryCETable(cheatName,scriptAddMainTable)

      return script
   end
   function GenerateAAWithSignature(aggregateMem, cheatName, signature, typeMem, signatureOffset, newCode, stateOriginalCode )   -- return bufferString 
      local workAddress = ByteScan(signature, typeMem)
      if (signatureOffset ~=0) then
         workAddress = string.format("%x", ("0x"..workAddress) + signatureOffset)
      end
      return GenerateAA(aggregateMem, cheatName, workAddress, newCode, stateOriginalCode)
   end
   function AddRegistersymbols(aggregateMem, tableNewSymbols)
      local sizetable = table.getn(newSymbols)
      for i=1,sizetable do
         PreSubScript(aggregateMem,"->>label", "registersymbol("..tableNewSymbols[i]..")")
      end
   end
   function EndGenerateAA(aggregateMem)
      local endScript = string.gsub(aggregateMem, "->>label", "")
      endScript = string.gsub(endScript, "->>newCode", "")
      endScript = string.gsub(endScript, "->>adressessInjected", "")
      autoAssemble(endScript)
   end

-- SECTION 3   
   function GroupAA(nameGRcheat, tableCheats)
      if (adrList == nil) then
         adrList = getAddressList()
      end   
      countObjectHotKeys = addresslist_getCount(adrList)
      mainGRScript = "[ENABLE]-->>marker1\n[DISABLE]\n-->>marker2"
      local delIndexes = {}
      local count_delIndexes = 0
      local zisetable = table.getn(tableCheats)
      local description = ""
      for i = 1,countObjectHotKeys do
         local te = addresslist_getMemoryRecord(adrList, i-1)
         description = memoryrecord_getDescription(te)
         for j=1,zisetable do
            if (tableCheats[j] == description) then
               local script = memoryrecord_getScript(te)
               local leftPos = 10
               local rigthPos = string.find(script, "%[DISABLE%]")
               mainGRScript = PreSubScript(mainGRScript,"-->>marker1",string.sub(script, leftPos, rigthPos-2))
               leftPos = rigthPos + 10 + 1
               rigthPos = string.len(script)      
               mainGRScript = PreSubScript(mainGRScript,"-->>marker2",string.sub(script, leftPos, rigthPos))
               count_delIndexes = count_delIndexes + 1
               delIndexes[count_delIndexes] = te
               break
            end
         end      
      end
      
      for i = 1,count_delIndexes do
         memoryrecord_delete(delIndexes[i])
      end

      mainGRScript = string.gsub(mainGRScript, "-->>marker1", "")
      mainGRScript = string.gsub(mainGRScript, "-->>marker2", "")
      SetScriptInEntryCETable(nameGRcheat,mainGRScript)
   end

-- SECTION 4   
   function TrainerShow(nameTrainer, processName, frmWidth, frmHeigth, initFunction)
      frmTrainerWidth = frmWidth
      frmTrainerHeigth = frmHeigth
      local aalist = getAutoAttachList()
      stringlist_add(aalist, processName);
      Trainer_FormCreate(nameTrainer)
      _InitFunction = initFunction
   end   


User functions:
1) TrainerShow(nameTrainer, processName, frmWidth, frmHeigth, initFunction)

2)
BeginGenerateAA(newMemDescription, sizeMem)
-----GenerateAA(aggregateMem, cheatName, address, newCode, stateOriginalCode)
-----GenerateAAWithSignature(aggregateMem, cheatName, signature, typeMem, signatureOffset, newCode, stateOriginalCode )
-----AddRegistersymbols(aggregateMem, tableNewSymbols)
EndGenerateAA(aggregateMem)

3)
FillnopsInstruction_AndAddInCETable(cheatName, address)
FillnopsInstructionWithSignature_AndAddInCETable(cheatName, signature, typeMem, signatreOffset)

4) GroupAA(nameGRcheat, tableCheats)

5) Function for quick tests of the console, LUA:
GenerateAAscriptPageMem_AndAddInCETable( cheatName, address, injectInstruction, originalcode )

Enjoy Razz


Last edited by GH*master on Sun Jun 12, 2011 11:12 am; edited 1 time in total
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

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

PostPosted: Sun Jun 12, 2011 8:27 am    Post subject: Reply with quote

Code:
repeat
results = AOBScan(signature, typeMem)
sleep(200)
until (results ~= nil)


I don't get it. Isn't 'aobscan' freeze active form?

_________________
Back to top
View user's profile Send private message MSN Messenger
GH*master
Expert Cheater
Reputation: 8

Joined: 10 Jan 2008
Posts: 159

PostPosted: Sun Jun 12, 2011 11:19 am    Post subject: Reply with quote

Unfortunately, yes.

I have not found a single way that would have been correct and fast than this my code.

Memscan class does not operate properly, and slowly over time. I have tried many methods ... The problem in the Cheat Engine source. I work in solving this problem.
Back to top
View user's profile Send private message
GH*master
Expert Cheater
Reputation: 8

Joined: 10 Jan 2008
Posts: 159

PostPosted: Sat Jun 25, 2011 1:00 pm    Post subject: Reply with quote

TrainerGen v1.1

example SpazGame.CETRAINER:

Code:
<?xml version="1.0"?>
<CheatTable CheatEngineTableVersion="12">
  <LuaScript>require("TrainerGen")

function Initialize()

      AddDataValue({
         {"_valueString", "db 39 39 39 39 39 39 00"},
         {"_StrCmp", "db 24 46 61 63 74 69 6F 6E 52 65 73 6F 75 72 63 65 73 50 69 72 61 74 65 00"}}) --_StrCmp = "$FactionResourcesPirate"
         
        CreateCheatsSign("RezResourse999999", "e8xxxxxxxxxxxxxxxxxxc2xxxx8bxxxxxxxxxx03xx8bxxxxxxxxxxxxxxxxe8", "+X-C-W", 0, [[
// [esp] or eax : pointer to str "$FactionResourcesPirate" (24 aymbols)
// [esp +4 ] or ebx : pointer to str rez value "00000"
 label(exit)
 pushfd
 pushad

 mov ecx,#23
 lea esi,[_StrCmp]
 mov edi,eax
 db f3 a6//repe cmpsb (bug CE 6.1)
 jnz short exit

 lea esi,[_valueString]
 mov edi,ebx//[esp+24]
 mov ecx,6
 rep movsb

exit:
 popad
 popfd]], true)
 
end


tableCheats = {"Rez Resourse: 999999"}
TrainerCreate("SpacePiratesAndZombies Ttainer +1, v1.0, {MasterGH}", "SpazGame.exe", 370, 100, tableCheats, Initialize)
</LuaScript>
</CheatTable>


TrainerGen v1.1 Source
Code:
local frmTrainer = nil      -- форма автоматически создаваемого трейнера
local frmTrainerWidth = 0
local frmTrainerHeigth = 0
local messageLabel = nil     -- объект лейбл со строкой информации в форме трейнера

local _InitFunction   = nil  -- указатель на пользовательскую функцию инициализации читов

local adrList = nil
local arrLabelsCtrls = {}   
local tableNamesCheats = {}
local lengthTableNamesCheats = 0

local baseHotKey = "CTRL"
local AAagregateMem = ""

   local function Trainer_Close(sender)   
      closeCE()
      return caFree
   end   
   local function Trainer_SendMessage(message)
      control_setCaption(messageLabel, message)
   end

   local function CriticalCondition(sizeCheats)
      if (sizeCheats < 1 or sizeCheats > 9) then
         showMessage("Cheats group count can not be less than 1 or greater than 9. Trainer will not be created")
         Trainer_Close(sender)
      end
   end
   local function Addresslist_getCount()
      if (adrList == nil) then
         adrList = getAddressList()
      end
      return (addresslist_getCount(adrList))
   end

   local function CheatAction(indexCheat)
      local te = addresslist_getMemoryRecord(adrList, indexCheat-1)
      if (memoryrecord_isActive(te))   then
         memoryrecord_unfreeze(te)
         --control_setColor(arrLabelsCtrls[indexCheat], "clGreen")
      else
         memoryrecord_freeze(te, 0)
         --control_setColor(arrLabelsCtrls[indexCheat], "clDefault")
      end
      beep()
   end

   function onHotkey1(hotkey) CheatAction(1) end
   function onHotkey2(hotkey) CheatAction(2) end
   function onHotkey3(hotkey) CheatAction(3) end
   function onHotkey4(hotkey) CheatAction(4) end
   function onHotkey5(hotkey) CheatAction(5) end
   function onHotkey6(hotkey) CheatAction(6) end
   function onHotkey7(hotkey) CheatAction(7) end
   function onHotkey8(hotkey) CheatAction(8) end
   function onHotkey9(hotkey) CheatAction(9) end

   local arrayFunction = {}
   arrayFunction[1] = onHotkey1
   arrayFunction[2] = onHotkey2
   arrayFunction[3] = onHotkey3
   arrayFunction[4] = onHotkey4
   arrayFunction[5] = onHotkey5
   arrayFunction[6] = onHotkey6
   arrayFunction[7] = onHotkey7
   arrayFunction[8] = onHotkey8
   arrayFunction[9] = onHotkey9

   
   local function ByteScan(signature, typeMem)             -- return address   
      Trainer_SendMessage("Scaning mode... Play in game and wait bell")
      local results = nil
      -- if (results == nil) then
      --  messageDialog("Ошибка. Не найден адрес внедрения.\n\rТрейнер будет закрыт!",1, 2)
      --  Trainer_Close()
      --  end      
      repeat
      results = AOBScan(signature, typeMem) -- typeMem = "+X-C-W" and any
      --   form_show(frmTrainer)
      sleep(200)
       until (results ~= nil)

      local address = stringlist_getString(results, 0)
      object_destroy(results);
      return address
   end   
   local function GetInfoInjection(address)               -- return adressReturnHere, originalCodeString, nopsString
      local sumBytes = 0
      local originalCodeString = "  "

      repeat
         countBytes = getInstructionSize(address)
         extrafield, opcode, bytes, address = splitDisassembledString(disassemble(address))
         originalCodeString = originalCodeString.."\n  "..opcode
         sumBytes = sumBytes + countBytes
      until (sumBytes >= 5)
      adressReturnHere = string.format("%x", ("0x"..address) + countBytes)
            
      local nopsString = ""
      local nopsCount = sumBytes - 5
      if (nopsCount>0) then
          nopsString = "  db"
          for i = 1, nopsCount do
            nopsString = nopsString.." 90"
          end
      end
      
      return adressReturnHere, originalCodeString, nopsString
   end
   local function PreSubScript(script, patternWord, newWords)   -- return bufferString
      local index = string.find(script, patternWord)
      local newscript = string.sub(script, 1, index - 1)..newWords.."\n"..string.sub(script, index)
      return newscript
   end
   local function DeleteEntryCETable(cheatName)
      local teSlave = getTableEntry(cheatName)
      if (teSlave == nil) then
         return
      end
      memoryrecord_delete(teSlave)
   end
   
-- SECTION 1
   function FillnopsInstruction_AndAddInCETable(cheatName,address)
      adressReturnHere, originalCodeString, nopsString = GetInfoInjection(address)
      local scriptAddMainTable = "[ENABLE]\n-->>address1[DISABLE]\n-->>address2"

      local countBytes = getInstructionSize(address)
      local nopsString = "  db"
      for i = 1, countBytes do
         nopsString = nopsString.." 90"
      end

      scriptAddMainTable = PreSubScript(scriptAddMainTable,"-->>address1", address..":\n"..nopsString)
      scriptAddMainTable = PreSubScript(scriptAddMainTable,"-->>address2", address..":"..originalCodeString)
      scriptAddMainTable = string.gsub(scriptAddMainTable, "-->>address1", "")
      scriptAddMainTable = string.gsub(scriptAddMainTable, "-->>address2", "")
      SetScriptInEntryCETable(cheatName,scriptAddMainTable)
   end
   function FillnopsInstructionWithSignature_AndAddInCETable(cheatName,signature, typeMem, signatreOffset)
      local workAddress = ByteScan(signature, typeMem)
      if (signatureOffset ~=0) then
         workAddress = string.format("%x", ("0x"..workAddress) + signatureOffset)
      end
      FillnopsInstruction_AndAddInCETable(cheatName, workAddress)
   end
   function CreateThread(cheatName, callLabel)
      local bufscript = "%[ENABLE%]\n% createthread("..callLabel..")\n[DISABLE%]"
      SetScriptInEntryCETable(cheatName,bufscript)      
   end
    function SetScriptInEntryCETable(cheatName, script)
      local teSlave = getTableEntry(cheatName)
      if (teSlave == nil) then
         teSlave = addresslist_createMemoryRecord(addresslist)
         memoryrecord_setDescription(teSlave, cheatName)
      end
      memoryrecord_setType(teSlave, vtAutoAssembler)
      memoryrecord_setScript(teSlave, script)   
   end
   function DeleteTableEntryes(tableCEEntryesName)
      local sizetable = table.getn(tableCheatsName)
      for i=1,sizetable do
         DeleteEntryCETable(tableCheatsName[i])
      end   
   end   
   function GroupAA(nameGRcheat, tableCheats, stateDeleteTableCheats)
      if (adrList == nil) then
         adrList = getAddressList()
      end   
      local countObjectHotKeys = addresslist_getCount(adrList)
      mainGRScript = "[ENABLE]-->>marker1\n[DISABLE]\n-->>marker2"
      local delIndexes = {}
      local count_delIndexes = 0
      local zisetable = table.getn(tableCheats)
      local description = ""
      for i = 1,countObjectHotKeys do
         local te = addresslist_getMemoryRecord(adrList, i-1)
         description = memoryrecord_getDescription(te)
         for j=1,zisetable do
            if (tableCheats[j] == description) then
               local script = memoryrecord_getScript(te)
               local leftPos = 10 -- длина "[ENABLE]\n" 9 символов и плюс переход +1
               local rigthPos = string.find(script, "%[DISABLE%]")
               mainGRScript = PreSubScript(mainGRScript,"-->>marker1",string.sub(script, leftPos, rigthPos-2))
               leftPos = rigthPos + 10 + 1
               rigthPos = string.len(script)      
               mainGRScript = PreSubScript(mainGRScript,"-->>marker2",string.sub(script, leftPos, rigthPos))
               count_delIndexes = count_delIndexes + 1
               delIndexes[count_delIndexes] = te
               break
            end
         end      
      end
      
      if (stateDeleteTableCheats) then
         for i = 1,count_delIndexes do
            memoryrecord_delete(delIndexes[i])
         end
      end

      mainGRScript = string.gsub(mainGRScript, "-->>marker1", "")
      mainGRScript = string.gsub(mainGRScript, "-->>marker2", "")
      SetScriptInEntryCETable(nameGRcheat,mainGRScript)
   end
-- SECTION 2
   function NewVirtualMem(newMemDescription, sizeMem)
      AAagregateMem = [[
   alloc(]]..newMemDescription..","..sizeMem..[[)
   registersymbol(]]..newMemDescription..[[)
   
   ->>label]]..newMemDescription..[[:

   ->>newCode
   ->>adressessInjected
   ]]
   end
   function EndGenerateAA()
      AAagregateMem = string.gsub(AAagregateMem, "->>label", "\n")
      AAagregateMem = string.gsub(AAagregateMem, "->>newCode", "")
      AAagregateMem = string.gsub(AAagregateMem, "->>adressessInjected", "")
      showMessage(AAagregateMem)
      autoAssemble(AAagregateMem)
   end
   function CreateCheats(cheatName, address, newCode, stateOriginalCode)
      local addressInjection = address
      local adressReturnHere = 0
      local originalCodeString = ""
      local nopsString = ""
      adressReturnHere, originalCodeString, nopsString = GetInfoInjection(address)
      
      registerSymbol("returnHere_"..cheatName, adressReturnHere)
      
      AAagregateMem = PreSubScript(AAagregateMem,"->>label", "label("..cheatName..")")
      AAagregateMem = PreSubScript(AAagregateMem,"->>label", "registersymbol("..cheatName..")")
      
      if (stateOriginalCode) then
         AAagregateMem = PreSubScript(AAagregateMem,"->>label", "label(originalcode_"..cheatName..")")
         local buf = cheatName..":\n  "..newCode.."\noriginalcode_"..cheatName..":"..originalCodeString.."\n  jmp returnHere_"..cheatName
         AAagregateMem = PreSubScript(AAagregateMem,"->>newCode", buf)
      else
         AAagregateMem = PreSubScript(AAagregateMem,"->>newCode", cheatName..":\n"..newCode.."\n  jmp returnHere_"..cheatName)
      end
      
      local scriptAddMainTable = "[ENABLE]\n-->>address1[DISABLE]\n-->>address2"
      scriptAddMainTable = PreSubScript(scriptAddMainTable,"-->>address1", addressInjection..":\n  jmp "..cheatName.."\n"..nopsString)
      scriptAddMainTable = PreSubScript(scriptAddMainTable,"-->>address2", addressInjection..":"..originalCodeString)
      scriptAddMainTable = string.gsub(scriptAddMainTable, "-->>address1", "")
      scriptAddMainTable = string.gsub(scriptAddMainTable, "-->>address2", "")
      SetScriptInEntryCETable(cheatName,scriptAddMainTable)
   end
   function CreateCheatsSign(cheatName, signature, typeMem, signatureOffset, newCode, stateOriginalCode )
      local workAddress = ByteScan(signature, typeMem)
      if (signatureOffset ~=0) then
         workAddress = string.format("%x", ("0x"..workAddress) + signatureOffset)
      end
      CreateCheats(cheatName, workAddress, newCode, stateOriginalCode)
   end
   function AddCodeThread(cheatName, AAcode)
      AAagregateMem = PreSubScript(AAagregateMem,"->>label", "label("..cheatName..")")
      AAagregateMem = PreSubScript(AAagregateMem,"->>label", "registersymbol("..cheatName..")")
      AAagregateMem = PreSubScript(AAagregateMem,"->>newCode", AAcode)
      
      local bufscript = "%[ENABLE%]\n% createthread("..cheatName..")\n[DISABLE%]"
      SetScriptInEntryCETable(cheatName, bufscript)      
   end   
   function AddRegisterSymbols(tableNewSymbols)
      local sizetable = table.getn(newSymbols)
      for i=1,sizetable do
         PreSubScript(AAagregateMem,"->>label", "label("..tableNewSymbols[i]..")")
         PreSubScript(AAagregateMem,"->>label", "registersymbol("..tableNewSymbols[i]..")")
      end
   end
   function AddLabels(tableNewSymbols)
      local sizetable = table.getn(newSymbols)
      for i=1,sizetable do
         PreSubScript(AAagregateMem,"->>label", "label("..tableNewSymbols[i]..")")
      end
   end
   function AddZeroValue(tableTableSymbols) --tableTableSymbols = { {"pId", 4}, {"pRES", 4} }
      local sizetable1 = table.getn(tableTableSymbols)
      for i=1,sizetable1 do
         local inTable = tableTableSymbols[i]
         local sizetable2 = table.getn(inTable)
         for j=1,sizetable2 do
            local regName = inTable[1]
            local sizeRegName = inTable[1]      
            local template = regName..":\n".."db "
            for j=1,sizeRegName do   
               template = sizeRegName.."00"
            end
            AAagregateMem = PreSubScript(AAagregateMem,"->>label", "label("..regName..")")
            AAagregateMem = PreSubScript(AAagregateMem,"->>label", "registersymbol("..regName..")")
            AAagregateMem = PreSubScript(AAagregateMem,"->>adressessInjected", template)
         end   
      end
   end
   function AddDataValue(tableTableSymbols) --tableTableSymbols = { {"pId", "data string"}, {"pRES", data string} }
      local sizetable1 = table.getn(tableTableSymbols)
      local template = ""
      for i=1,sizetable1 do
         local inTable = tableTableSymbols[i]
         local sizetable2 = table.getn(inTable)
         template = ""
         local regName = inTable[1]
         local template = inTable[2]      
         template = regName..":\n"..template

         AAagregateMem = PreSubScript(AAagregateMem,"->>label", "label("..regName..")")
         AAagregateMem = PreSubScript(AAagregateMem,"->>label", "registersymbol("..regName..")")
         AAagregateMem = PreSubScript(AAagregateMem,"->>adressessInjected", template)
      end
   end   
   function AddCode(newRegSymbols, AAcode)
      AAagregateMem = PreSubScript(AAagregateMem,"->>label", "label("..newRegSymbols..")")
      AAagregateMem = PreSubScript(AAagregateMem,"->>label", "registersymbol("..newRegSymbols..")")
      AAagregateMem = PreSubScript(AAagregateMem,"->>newCode", AAcode)
   end

   function onOpenProcess(processid)
      NewVirtualMem("newCheatsMem","2048")   
      _InitFunction()
      -- В таблице должно быть не более 9-ти записей включительно       
      local count = Addresslist_getCount()
      CriticalCondition(Addresslist_getCount())
      EndGenerateAA()
      
      for i=1,count do      
         local ObjectHotKeys =  createHotkey(arrayFunction[i], VK_CONTROL, VK_0 + i) --string.format("%s",i)
         generichotkey_setKeys(ObjectHotKeys, VK_CONTROL, VK_0 + i)
         generichotkey_onHotkey(ObjectHotKeys, arrayFunction[i])
         setProperty(arrLabelsCtrls[i], "Enabled", "true")
      end   
         
      Trainer_SendMessage("Trainer is ready!")
      beep()      
   end   
-- SECTION 3   
   function TrainerCreate(nameTrainer, processName, frmWidth, frmHeigth, tableCheats, initFunction)
      tableNamesCheats = tableCheats
      lengthTableNamesCheats = table.getn(tableNamesCheats)
      frmTrainerWidth = frmWidth
      frmTrainerHeigth = frmHeigth
      _InitFunction = initFunction
      
      frmTrainer = createForm(true)
      form_centerScreen(frmTrainer)
      setProperty(frmTrainer, "BorderStyle", "bsDialog")
      control_setSize(frmTrainer, frmTrainerWidth, frmTrainerHeigth)
      control_setCaption(frmTrainer, nameTrainer)
      form_onClose(frmTrainer, Trainer_Close)

      messageLabel = createLabel(frmTrainer)
      control_setAlign(messageLabel, alBottom)
      Trainer_SendMessage("Trainer is not ready")
   
      local x = 20
      local y = 10
      local yInc = 16
      
      local cheatLbl = createLabel(frmTrainer)
      control_setPosition(cheatLbl, x, y)
      control_setCaption(cheatLbl, "Cheats:")
      
      x = x + 60
      
      for i=1,lengthTableNamesCheats do      
         cheatLbl = createLabel(frmTrainer)
         setProperty(cheatLbl, "Enabled", "False")
         control_setPosition(cheatLbl, x, (i * yInc) + 7)
         local stringHotKey = baseHotKey.."+"..i
         control_setCaption(cheatLbl, i..". "..tableCheats[i].."  : ........ "..stringHotKey)
         arrLabelsCtrls[i] = cheatLbl
      end

      local aalist = getAutoAttachList()
      stringlist_add(aalist, processName);   
   end   


If you'll run the trainer and to activate hot-key, then change the Rez resources in the game and you see the "999 999". Other cheats are not ready.
Twisted Evil (Mua-ha-ha)
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 Tutorials -> LUA Tutorials 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 cannot download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites