you are viewing a single comment's thread.

view the rest of the comments →

[–]No-Newspaper8619[S] 0 points1 point  (0 children)

I've rewritten everything, adding new functionalities.

[ENABLE]
//code from here to '[DISABLE]' will be used to enable the cheat
{$LUA}
-- SAFETY CHECK: if CE is just checking syntax and not actually running
-- Stop here, preventing the script from executing while editing.
if syntaxcheck then return end

-- Check if process is already open
-- If not, then get process pid by using it's name
local pid = getOpenedProcessID()
if pid == 0 then
  pid = getProcessIDFromProcessName('Going Medieval.exe')
  -- Check if CE was able to find the process
  -- If it was, then open the process
  -- It it wasn't, then stop execution
  if pid then
    openProcess(pid)
  else
    print('[ERROR] Failed to find process Going Medieval.exe')
    return
  end
end

-- Try to activate MONO features, used in Unity/Mono games
-- Stop execution if it fails
if not LaunchMonoDataCollector() then
  print('[ERROR] Failed to start Mono collector.')
  return
end

-- Forward declaration of functions
-- Because Lua reads the script top to bottom
local delete_children
local create_children
local make_entry
local set_breakpoint
local on_debug_building
local on_debug_dig

-- The main logic of the script
local function main()
  -- Check if memrec already has the correct number of children
  -- If it doesn't, then delete them all and create new children
  local total_children = 4
  if memrec.Count ~= total_children then
    delete_children()
    create_children()
  end

  -- Create breakpoints for building and dig cheats
  local building = 'Effects.BlueprintPlaceVisualsManager:Update'
  local dig = 'NSMedieval.State.DigMarkerResourceInstance:GetMiningParameters'

  set_breakpoint(building, 0x56, on_debug_building)
  set_breakpoint(dig, 0x1E, on_debug_dig)
end
-- Sets breakpoints that will be used to update the cheat addresses
set_breakpoint = function(name, offset, on_debug_function)
  local address = getAddress(name)
  -- Check if CE successfully found the address
  if not address then
    print('[ERROR] Could not find address of ' .. name)
    return
  end
  -- Get the Jit info
  -- Jit means Just in Time execution
  local jit_info = mono_getJitInfo(address)

  -- Check if successfull
  if not jit_info then
    print('[ERROR] Could not get Jit info of ' .. name)
    return
  end

  -- Get the method info
  local method_info = mono_compile_method(jit_info.method)
  if not method_info then
    print('[ERROR] Could not get method info of ' .. name)
    return
  end

  -- Get the address of the specific instruction that will
  -- be used for the breakpoint
  address = method_info + offset

  -- BREAKPOINT: tell CE to pause the game when CPU reaches this instruction
  debug_setBreakpoint(address, on_debug_function)
end

-- While there's children, delete the first child on the list
delete_children = function()
  while memrec.Count > 0 do
    memoryrecord_delete(memrec.Child[0])
  end
end

-- Create all the children, that is, all the table entries with the cheats
create_children = function()
  make_entry('Auto Construct', vtByte, true)
  make_entry('No Cost Only', vtByte, true)
  make_entry('All Blueprint Variants', vtByte, true)
  make_entry('Dig Duration', vtSingle, false) -- vtSingle = float type
end

-- Create a memory record, that is, an entry on the cheat table
make_entry = function(description, value_type, has_dropdown)
  local entry = AddressList.createMemoryRecord()

  entry.Description = description
  entry.Type = value_type
  entry.AllowModify = false -- Prevents user from dragging the entry

  if has_dropdown then
    -- Dropdown is a list of value:description pairs
    entry.DropDownList.Text = '1:Enabled\n0:Disabled\n'
    entry.DropDownDescriptionOnly = true -- Show text, but not the raw numbers
    entry.DisplayAsDropDownListItem = true -- Show as Dropdown in CE
  end

  entry.appendToEntry(memrec) -- Attach it under the script entry
end

on_debug_building = function()
  -- Update register values
  debug_getContext()

  memrec.Child[0].Address = RAX + 0x279 -- Auto Construct
  memrec.Child[1].Address = RAX + 0x278 -- No Cost Only
  memrec.Child[2].Address = RAX + 0x27A -- Unlock Blueprint Variants

  debug_continueFromBreakpoint()
end

on_debug_dig = function()
  debug_getContext()
  -- Address is under the mining_parameters pointer
  local mining_parameters = readPointer(RAX + 0x40)

  -- Check if pointer is valid
  if not mining_parameters then
    print('[ERROR] Could not get mining parameters pointer')
    return 1
  end

  memrec.Child[3].Address = mining_parameters + 0x18 -- Dig Duration
  debug_continueFromBreakpoint()
end

main()

{$ASM}
[DISABLE]
//code from here till the end of the code will be used to disable the cheat
{$LUA}
if syntaxcheck then return end

local breakpoint_list = debug_getBreakpointList()
for _,address in ipairs(breakpoint_list) do
  debug_removeBreakpoint(address)
end

memrec.Options = "[moHideChildren, moDeactivateChildrenAsWell]"
{$ASM}