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 Forum Index
PostGo back to topic
mgr.inz.Player
I post too much
Reputation: 159
Joined: 07 Nov 2008
Posts: 4277
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sun Jun 12, 2011 8:02 am    Post subject: LUA Script used to make 'terraria materials spawner'.

Code:
-- SPAWN POINT PATTERN, left side
searchthis=[[
?? ?? ?? ?? 01 01 01 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??
?? ?? ?? ?? 00 01 00 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??
?? ?? ?? ?? 01 01 1E ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??
?? ?? ?? ?? 01 01 01 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??
?? ?? ?? ?? 01 01 1E ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??
?? ?? ?? ?? 00 01 00 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??
]]

searchthis=string.gsub(searchthis,"\n"," ")

ms = createMemScan()
FL = createFoundList(ms) 
memscanusedbefore=false

WorldHeight = 1200
spawnpoint_table = {}

function findSpawnpoints()

  control_setCaption(UDF1, "Terraria Materials Spawner. Searching...")

  if (memscanusedbefore==true) then foundlist_deinitialize(FL) end
  memscanusedbefore=true

  memscan_firstScan(ms, soExactValue, vtByteArray, rtRounded, searchthis,
                  "", 0x00000000, 0x7fffffff, "+W-X-C", fsmNotAligned, "",
                  true, false, false, false)


  memscan_waitTillDone(ms)
  foundlist_initialize(FL)

  spawnpoint_table = {}
 
  FlCount = foundlist_getCount(FL)
  if (FlCount == 0 ) then return end
 
  WorldHeight=(combobox_getItemIndex(CBworldSize)+2)*600

  for index=0,FlCount-1 do
      address = tonumber(foundlist_getAddress(FL,index),16)
      nextcolumncheck = readBytes(address+WorldHeight*24, 24*6, true)

      if (nextcolumncheck ~= nil) then

        if (nextcolumncheck[24*0+6]==1 and nextcolumncheck[24*1+6]==1 and nextcolumncheck[24*2+6]==1 and
            nextcolumncheck[24*3+6]==30 and nextcolumncheck[24*4+6]==30 and nextcolumncheck[24*5+6]==0) then

            table.insert(spawnpoint_table,address)
            end
      end
  end

end

function SpawnPointQuickCheck(spawnpointID)

    quickSpawnPointCheck_bytes = readBytes(spawnpoint_table[spawnpointID], 24*7, true)

    if (quickSpawnPointCheck_bytes == nil) then return false
    else
      if (quickSpawnPointCheck_bytes[24*0+6]==1 and quickSpawnPointCheck_bytes[24*1+6]==0 and
          quickSpawnPointCheck_bytes[24*2+6]==30 and quickSpawnPointCheck_bytes[24*3+6]==1 and
          quickSpawnPointCheck_bytes[24*4+6]==30 and quickSpawnPointCheck_bytes[24*5+6]==0) then
        return true end

      return false
    end

end

function button1click(secondtry)

  if (terrariaexeopened==false) then return end

  -- first time click check
  if ((# spawnpoint_table) == 0) then
    findSpawnpoints()
    if ((# spawnpoint_table) == 0) then
      control_setCaption(UDF1, "Terraria Materials Spawner. No trainer spawn points.")
      return false
    end
  end
  -- first time click check

  control_setCaption(UDF1, "Terraria Materials Spawner")

  material = combobox_getItemIndex(CBmaterial)+6

  spawnsuccess = false
  --lua tables starts from 1
  for index=1,(# spawnpoint_table) do
    if (SpawnPointQuickCheck(index) == true) then
      spawnsuccess=true
      writeBytes(spawnpoint_table[index]+2*24*WorldHeight+24*0,255,255,255,255,1,1,material)
      writeBytes(spawnpoint_table[index]+2*24*WorldHeight+24*1,255,255,255,255,1,1,material)
      writeBytes(spawnpoint_table[index]+2*24*WorldHeight+24*2,255,255,255,255,1,1,material)
      writeBytes(spawnpoint_table[index]+2*24*WorldHeight+24*3,255,255,255,255,1,1,material)
      writeBytes(spawnpoint_table[index]+2*24*WorldHeight+24*4,255,255,255,255,1,1,material)

      writeBytes(spawnpoint_table[index]+3*24*WorldHeight+24*0,255,255,255,255,1,1,material)
      writeBytes(spawnpoint_table[index]+3*24*WorldHeight+24*1,255,255,255,255,1,1,material)
      writeBytes(spawnpoint_table[index]+3*24*WorldHeight+24*2,255,255,255,255,1,1,material)
      writeBytes(spawnpoint_table[index]+3*24*WorldHeight+24*3,255,255,255,255,1,1,material)
      writeBytes(spawnpoint_table[index]+3*24*WorldHeight+24*4,255,255,255,255,1,1,material)
      end
  end
 
  if (spawnsuccess == true) then beep() end

  if ((spawnsuccess == false) and (secondtry~="secondtry")) then
                            spawnpoint_table = {}
                            button1click("secondtry")
                            end

end

function button2click()
  if (terrariaexeopened==false) then return end
 
  beep()
  spawnpoint_table = {}
  button1click()
end

terrariaexeopened=false

function onOpenProcess(processid)
  terrariaexeopened=true
end

addresslist=getAddressList()
memrec0 = addresslist_getMemoryRecordByID(addresslist, 0)
memrec0_hotkey0=memoryrecord_getHotkeyByID(memrec0,0)
memoryrecordhotkey_onHotkey(memrec0_hotkey0,button1click)

memrec1 = addresslist_getMemoryRecordByID(addresslist, 1)
memrec1_hotkey0=memoryrecord_getHotkeyByID(memrec1,0)
memoryrecordhotkey_onHotkey(memrec1_hotkey0,button2click)

strings_add(getAutoAttachList(), "terraria.exe")
form_show(UDF1)

function HelpButton1Click(sender)
  form_hide(UDF2)
end

function CEButton4Click(sender)
  form_show(UDF2)
end

CBmaterial=component_findComponentByName(UDF1, "TerrariaMaterialComboBox1")
CBworldSize=component_findComponentByName(UDF1, "worldSizeComboBox1")



function CloseClick()
  closeCE()
  return caFree --onClick doesn't care, but onClose would like a result
end

control_setCaption(UDF1, "Terraria Materials Spawner")

function CELabel1Click(sender)
  shellExecute('http://tnij.org/TMST_youtube')
end

function CELabel2Click(sender)
  shellExecute('http://tnij.org/TMST_forumthread')
end

_________________
Dark Souls II Item Swap and Item List
My Borderlands2 tables

Recent CheatEngine builds
Back to top
View user's profile Send private message MSN Messenger
Post reviews:   Approve 1
Author Review
GH*master
Review: Approve
Post reference:
ReviewPosted: Sun Jun 12, 2011 11:28 am

Good job!
Back to top
View user's profile Send private message
Display:  
Cheat Engine Forum Index


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites