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 


Cheating on HOMM3 / Paging heroes.
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Fri Feb 09, 2018 12:46 pm    Post subject: Reply with quote

Possibly BOM, though I wouldn't think so... regardless Smile

As for a dropdown list I think something like this would work, basically a script that allocates some memory for a nested memory record (which has the list setup), then generates the dropdown list (really only needs to happen once but) and sets a function that runs when it's value is displayed by CE to copy the value (if it's changed) to the address of the Hero record
Code:
<?xml version="1.0" encoding="utf-8"?>
<CheatTable>
  <CheatEntries>
    <CheatEntry>
      <ID>0</ID>
      <Description>"Generate list"</Description>
      <Options moHideChildren="1"/>
      <LastState Activated="1"/>
      <VariableType>Auto Assembler Script</VariableType>
      <AssemblerScript>[ENABLE]
globalalloc(heroesoffset,4)
{$lua}
local autoChange = false
local mr = memrec.Child[0]
local function getStructureIDByName(name)
  local lname = name:lower()
  local casematch = nil
  local count = getStructureCount()-1
  for i=0, count do
    local struct = getStructure(i)
    -- if there are two structs with the exact same name, not my problem if you get the wrong one!
    if struct.Name == name then return i
    elseif struct.Name:lower() == lname then
      if casematch == nil then casematch = i
        -- potentially misses case where exact match exists after two caseinsensitive matches
        -- ... can fix easily enough with two loops but... people probably shouldn't have that many
        -- structures with the same name right? right? I'll find out I guess lol
      else return nil, "more than one structure matches when ignoring case"
      end
    end
  end
  if casematch then return casematch else return nil, ("No structure with the name '%s' exists"):format(name) end
end

local function getStructureByName(name)
  local id, errmsg = getStructureIDByName(name)
  if not id then
    return nil, errmsg
  else
    return getStructure(id)
  end
end

local heroesStruct = getStructureByName('Heroes')

-- generate list
mr.DropDownList.Clear()
for i=0, heroesStruct.Count-1 do
  local element = heroesStruct.getElement(i)
  local new = ('%d:+Heroes.%s'):format(element.Offset, element.Name)
  mr.DropDownList.add(new)
end

-- setup function to automatically change base Hero offset
local lastValue = nil
mr.OnGetDisplayValue = function(mr,value)
  if lastValue == value then return end
  -- otherwise update
  lastValue = value
  local main = getAddressList().getMemoryRecordByDescription('Hero')
  -- try to assign back as +Heroes.Name (should always work since it was generated from structure but)
  local hero = heroesStruct.getElementByOffset(value)
  if hero then
    offset = '+Heroes.' .. hero.Name
  else
    -- default to hex string
    offset = ('+%X'):format(offset)
  end
  main.Address = offset
end

{$asm}
[DISABLE]
</AssemblerScript>
      <CheatEntries>
        <CheatEntry>
          <ID>1</ID>
          <Description>"Hero Selection"</Description>
          <DropDownList ReadOnly="1" DescriptionOnly="1" DisplayValueAsItem="1">0:+Heroes.Orrin
</DropDownList>
          <LastState Value="173160" RealAddress="05FF0000"/>
          <VariableType>4 Bytes</VariableType>
          <Address>heroesoffset</Address>
        </CheatEntry>
      </CheatEntries>
    </CheatEntry>
  </CheatEntries>
</CheatTable>
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
Goto page Previous  1, 2
Page 2 of 2

 
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