<?xml version="1.0" encoding="utf-8"?>
<CheatTable CheatEngineTableVersion="45">
  <CheatEntries>
    <CheatEntry>
      <ID>1</ID>
      <Description>"Bio Menace - Smooth Edition by dRambone | v1.1"</Description>
      <LastState Value="" RealAddress="00000000"/>
      <Color>80CAE4</Color>
      <GroupHeader>1</GroupHeader>
    </CheatEntry>
    <CheatEntry>
      <ID>2</ID>
      <Description>"Press F1 to attach to game and open trainer"</Description>
      <LastState Value="" RealAddress="00000000"/>
      <Color>AFAFAF</Color>
      <GroupHeader>1</GroupHeader>
    </CheatEntry>
  </CheatEntries>
  <UserdefinedSymbols/>
  <LuaScript>-- BIO MENACE REMASTERED
-- Smooth Edition by dRambone

local scripts={
health=[==========[// BioMenace Remastered GOG, buildId 60154739544974006.
// Player damage: EXE+1A5FD0, health WORD at player+5C.
// Replace SUB AX,DX with TEST AX,AX: retain health and meaningful SF/ZF.
// Enemy damage (EXE+16B640), Infinite Jump and all data remain untouched.
// No allocation, hook, scan, debugger or persistent controller.
// Disable before process switch/restart; re-enable in the new process.

define(BMH_damage,"BioMenace Remastered.exe"+1A6036)

[ENABLE]
{$lua}
if syntaxcheck then return end
if not targetIs64Bit() or getOpenedProcessID()==0 then
  error('BMH: attach to the supported x64 game process first')
end
{$asm}
assert("BioMenace Remastered.exe"+1A5FD0,40 53 48 83 EC 20 80 3D 12 E4 78 00 00 48 8B D9 0F 85 E3 00 00 00)
assert(BMH_damage-4,0F B7 43 5C 66 2B C2 66 89 43 5C 79 07 66 44 89 43 5C EB 05 66 85 C0 7F 63)
BMH_damage:
  db 66 85 C0

[DISABLE]
assert("BioMenace Remastered.exe"+1A5FD0,40 53 48 83 EC 20 80 3D 12 E4 78 00 00 48 8B D9 0F 85 E3 00 00 00)
assert(BMH_damage-4,0F B7 43 5C 66 85 C0 66 89 43 5C 79 07 66 44 89 43 5C EB 05 66 85 C0 7F 63)
BMH_damage:
  db 66 2B C2
]==========],
keys=[==========[// BioMenace Remastered GOG buildId 60154739544974006.
// Golden doors work with any inventory count, including zero after level reset.
// Does NOT grant 99 keys or change the displayed inventory count.
// Colored/special keys, keycards, pickups and other door types are unchanged.
// No scan, breakpoint, cave, timer or allocation. Disable restores code only.
// Disable before process switch/restart, then re-enable in the new process.

define(BMK_check,"BioMenace Remastered.exe"+1A5BA1)
define(BMK_consume,"BioMenace Remastered.exe"+1A23DD)

[ENABLE]
{$lua}
if syntaxcheck then return end
if not targetIs64Bit() or getOpenedProcessID()==0 then
  error('BMK: attach to the supported x64 game process first')
end
{$asm}
// Door type 6 only: conditional success becomes unconditional success.
assert(BMK_check-D,83 FA 06 75 55 66 83 3D D5 E9 78 00 00 75 2D BA 02 00 00 00)
// Door action case 1 only: skip zero rejection AND DEC/store, retaining count.
assert(BMK_consume-A,0F B7 05 9C 21 79 00 66 85 C0 0F 84 10 02 00 00 66 FF C8 66 89 05 89 21 79 00 E9 94 00 00 00)
assert("BioMenace Remastered.exe"+1A2486,8B 05 54 21 79 00 48 89 5C 24 40)
BMK_consume:
  // JMP EXE+1A2486, plus one padding byte; fixed six-byte replacement.
  db E9 A4 00 00 00 90
BMK_check:
  // Keep the original +2D short displacement byte untouched.
  db EB

[DISABLE]
assert(BMK_check-D,83 FA 06 75 55 66 83 3D D5 E9 78 00 00 EB 2D BA 02 00 00 00)
assert(BMK_consume-A,0F B7 05 9C 21 79 00 66 85 C0 E9 A4 00 00 00 90 66 FF C8 66 89 05 89 21 79 00 E9 94 00 00 00)
assert("BioMenace Remastered.exe"+1A2486,8B 05 54 21 79 00 48 89 5C 24 40)
BMK_check:
  db 75
BMK_consume:
  db 0F 84 10 02 00 00
]==========],
jump=[==========[// Infinite Jump controller.
// First Enable installs the original 7-byte code hook, then enables the flag.
// Later Enable/Disable only toggle the activity byte. No breakpoints or scans.
// Disable NEVER removes the hook or frees memory. Process exit is the teardown.

{$lua}
if syntaxcheck then return end
local S = rawget(_G,'BMJCheckboxV2')
if S and S.version ~= 2 then error('BMJC: foreign controller namespace') end
S = S or {version=2, bindings={}, blocked={}}
-- Common Lua is evaluated again on later checkbox operations. Keep the same
-- session and attempt records; never reset a failed or in-progress install.
S.attempts = S.attempts or {}
local MODULE = 'BioMenace Remastered.exe'
local SIZE, ENTRY, FLAG = 0x1000, 0x100, 0x40
local function fail(s) error('BMJC: '..s,0) end
local function hex(n) return string.format('%X',n) end
local function bytes(s)
  local r={} for h in s:gmatch('%x%x') do r[#r+1]=tonumber(h,16) end return r
end
local ORIGINAL=bytes('0F BF 15 E3 06 79 00')
local PREFIX=bytes('40 53 48 83 EC 20')
local SUFFIX=bytes('48 8B D9 66 85 D2 74 7B')
local STARTER=bytes('40 53 48 83 EC 20 48 8B D9 B9 0B 00 00 00 E8 2D 1A FC FF C7 43 1E 00 00 D7 FF')
local function equal(a,b)
  if type(a)~='table' or #a~=#b then return false end
  for i=1,#b do if a[i]~=b[i] then return false end end return true
end
local function read(a,n)
  local b=readBytes(a,n,true)
  if type(b)~='table' or #b~=n then fail('unreadable memory at '..hex(a)) end
  return b
end
local function expect(a,b)
  if not equal(read(a,#b),b) then fail('unexpected bytes at '..hex(a)) end
end
local function put(t,n,count)
  for i=1,count do t[#t+1]=n &amp; 255; n=n &gt;&gt; 8 end
end
local function signed32(t,i)
  local n=t[i]+t[i+1]*256+t[i+2]*65536+t[i+3]*16777216
  return n&gt;=0x80000000 and n-0x100000000 or n
end
local function rel32(from,to)
  local d=to-(from+5)
  if d &lt; -0x80000000 or d &gt; 0x7fffffff then fail('rel32 out of range') end
  local r={0xE9}; put(r,d &amp; 0xffffffff,4); return r
end
local function current()
  if not targetIs64Bit() then fail('attach to the supported x64 game process') end
  local pid=getOpenedProcessID()
  local base=getAddressSafe(MODULE)
  if not pid or pid==0 or not base or base==0 then fail('target identity unavailable') end
  expect(base+0x1A3D30,PREFIX)
  expect(base+0x1A3D3D,SUFFIX)
  expect(base+0x1A6790,STARTER)
  return {pid=pid,base=base,hook=base+0x1A3D36}
end
local function still(c)
  if getOpenedProcessID()~=c.pid or getAddressSafe(MODULE)~=c.base then
    fail('target changed; no write permitted')
  end
end
-- Build with CE's single-instruction assembler, without executing target code.
-- Two bounded passes resolve local labels. Independently validate EVERY rel32
-- and RIP-relative operand; do not trust LONG to detect address truncation.
local function build(c,root)
  local entry=root+ENTRY
  local function addr(rva) return hex(c.base+rva) end
  local seq={}
  local function op(text,target,tail,kind)
    seq[#seq+1]={text=text,target=target,tail=tail or 0,kind=kind}
  end
  local function branch(m,label) seq[#seq+1]={branch=m,label=label} end
  local function label(name) seq[#seq+1]={mark=name} end
  op('cmp byte ptr ['..hex(root+FLAG)..'],1',root+FLAG,1)
  branch('jne','original')
  op('cmp rcx,['..addr(0x934500)..']',c.base+0x934500)
  branch('jne','original')
  op('cmp byte ptr ['..addr(0x9344F0)..'],0',c.base+0x9344F0,1)
  branch('je','original')
  op('cmp byte ptr ['..addr(0x934429)..'],0',c.base+0x934429,1)
  branch('jne','original')
  op('mov rax,[rcx+28]')
  op('lea rdx,['..addr(0x771B28)..']',c.base+0x771B28)
  op('cmp rax,rdx'); branch('je','jump')
  op('lea rdx,['..addr(0x771B60)..']',c.base+0x771B60)
  op('cmp rax,rdx'); branch('je','jump')
  op('lea rdx,['..addr(0x771B98)..']',c.base+0x771B98)
  op('cmp rax,rdx'); branch('jne','original')
  label('jump')
  op('push rcx'); op('sub rsp,28')
  op('mov ax,[rcx+1E]'); op('mov [rsp+20],ax')
  -- Accumulator MOV with [absolute] can select moffs instead of RIP-relative.
  -- Use a full 64-bit address in volatile R11 and keep the access WORD-sized.
  op('mov r11,'..addr(0x934410))
  op('mov ax,word ptr [r11]')
  op('mov [rsp+22],ax')
  op('call long '..addr(0x1A6790),c.base+0x1A6790,0,'call')
  op('mov rcx,[rsp+28]')
  op('mov ax,[rsp+20]'); op('mov [rcx+1E],ax')
  op('mov ax,[rsp+22]')
  -- The starter may clobber R11: reload the address after the CALL.
  op('mov r11,'..addr(0x934410))
  op('mov word ptr [r11],ax')
  op('add rsp,28'); op('pop rcx')
  label('original')
  op('movsx edx,word ptr ['..addr(0x934420)..']',c.base+0x934420)
  op('jmp long '..hex(c.hook+7),c.hook+7,0,'jmp')
  local labels,out,listing={},{},{}
  for pass=1,2 do
    local pc=entry; out={}; listing={}
    for _,s in ipairs(seq) do
      if s.mark then
        labels[s.mark]=pc
      else
        local target=s.target
        local text=s.text
        if s.branch then
          target=labels[s.label] or entry
          text=s.branch..' long '..hex(target)
        end
        local b=assemble(text,pc,2,false)
        if type(b)~='table' or #b==0 then fail('cannot assemble: '..text) end
        if s.branch and (#b~=6 or b[1]~=0x0F or
            b[2]~=(s.branch=='je' and 0x84 or 0x85)) then fail('unexpected Jcc encoding') end
        if s.kind and (#b~=5 or b[1]~=(s.kind=='call' and 0xE8 or 0xE9)) then
          fail('unexpected call/jump encoding')
        end
        if pass==1 then s.length=#b elseif s.length~=#b then fail('unstable assembler layout') end
        if pass==2 and target then
          local d=target-(pc+#b)
          if d &lt; -0x80000000 or d &gt; 0x7fffffff or #b&lt;5 or
              pc+#b+signed32(b,#b-3-(s.tail or 0))~=target then
            fail('truncated or non-relative operand: '..text)
          end
        end
        for _,v in ipairs(b) do out[#out+1]=v end
        listing[#listing+1]={address=pc,text=text,bytes=b}
        pc=pc+#b
      end
    end
  end
  if #out&gt;0x400 then fail('cave code exceeds reserved region') end
  return out,listing
end
local function header(c,root,n,cookie)
  local t={}
  for x in ('BMJC2_CHECKBOX!!'):gmatch('.') do t[#t+1]=x:byte() end
  -- Magic is padded to 16 bytes; metadata never overlaps the flag at +40.
  while #t&lt;16 do t[#t+1]=0 end
  put(t,c.base,8); put(t,c.pid,4); put(t,n,4)
  put(t,root,8); put(t,2,4); put(t,SIZE,4)
  for _,v in ipairs(cookie) do t[#t+1]=v end
  if #t~=0x40 then fail('invalid descriptor layout') end
  return t
end
local function probe(c)
  local b=read(c.hook,7)
  if equal(b,ORIGINAL) then return nil end
  if b[1]~=0xE9 or b[6]~=0x90 or b[7]~=0x90 then fail('foreign hook; no write') end
  local entry=c.hook+5+signed32(b,2)
  local root=entry-ENTRY
  if root&lt;0x10000 or root%0x1000~=0 then fail('foreign allocation alignment') end
  local h=read(root,0x40)
  local cookie={} for i=0x31,0x40 do cookie[#cookie+1]=h[i] end
  local code=build(c,root)
  expect(root,header(c,root,#code,cookie))
  expect(entry,code)
  local flag=read(root+FLAG,1)[1]
  if flag~=0 and flag~=1 then fail('invalid activity byte') end
  return {pid=c.pid,base=c.base,root=root,entry=entry,flag=root+FLAG,
    cookie=table.concat(cookie,','),value=flag}
end
local function same(a,b)
  return a and b and a.pid==b.pid and a.base==b.base and
    a.root==b.root and a.cookie==b.cookie
end
local function tohex(t)
  local r={} for i,v in ipairs(t) do r[i]=string.format('%02X',v) end
  return table.concat(r,' ')
end
local function writechecked(c,a,t)
  still(c)
  local ok=writeBytes(a,t)
  if ok==nil or ok==false then fail('write failed at '..hex(a)) end
  expect(a,t)
end
local function aa(c,text)
  still(c)
  local ok,err=autoAssemble(text,false)
  if not ok then fail('AA failed: '..tostring(err)..'; restart test process and CE, do not retry blindly') end
end
local function checkattempt(previous)
  if not previous or previous.phase=='INSTALLED' then return end
  if previous.phase=='FAILED' then
    fail('installation failed at '..previous.failedAt..'; retained allocation '..
      (previous.root and hex(previous.root) or '(none)')..'; first error: '..
      previous.error..'; restart test process and CE')
  end
  fail('installation already in progress at '..previous.phase..'; no second allocation')
end
local function install(c)
  still(c)
  expect(c.hook,ORIGINAL)
  local key=hex(c.pid)..':'..hex(c.base)
  local previous=S.attempts[key]
  checkattempt(previous)
  if previous then
    fail('installed hook disappeared; restart test process and CE')
  end
  -- An old boolean carries no completion/failure evidence. Do not erase it
  -- when updating a script in a CE session which already reserved memory.
  if S.blocked[key] then
    fail('legacy install attempt has unknown status; restart test process and CE')
  end
  local attempt={phase='ALLOCATING',pid=c.pid,base=c.base}
  S.attempts[key]=attempt
  local ok,result=xpcall(function()
    local root=allocateMemory(SIZE,c.hook,0x40)
    if not root or root==0 then fail('allocation failed; no hook written') end
    attempt.root=root
    attempt.phase='BUILDING'
    -- Even failed/unreachable installations are retained: no executable free.
    -- No print/UI callback in the unfinished installation path.
    local code=build(c,root)
    local jump=rel32(c.hook,root+ENTRY)
    jump[#jump+1]=0x90; jump[#jump+1]=0x90
    local cookie=bytes(stringToMD5String(hex(c.pid)..':'..hex(root)..':'..os.time()..':'..getTickCount()))
    attempt.phase='WRITING_CAVE'
    writechecked(c,root,header(c,root,#code,cookie))
    writechecked(c,root+FLAG,{0})
    aa(c,hex(root+ENTRY)..':\ndb '..tohex(code))
    expect(root+ENTRY,code)
    still(c); expect(c.hook,ORIGINAL)
    attempt.phase='PUBLISHING_HOOK'
    -- Install the hook after validating the expected original bytes.
    aa(c,'assert('..hex(c.hook)..','..tohex(ORIGINAL)..')\n'..
      hex(c.hook)..':\ndb '..tohex(jump))
    attempt.phase='VERIFYING_HOOK'
    local p=probe(c)
    if not p then fail('installation not visible') end
    attempt.phase='INSTALLED'
    return p
  end,function(err) return tostring(err) end)
  if not ok then
    attempt.failedAt=attempt.phase
    attempt.error=result
    attempt.phase='FAILED'
    fail('installation failed at '..attempt.failedAt..'; retained allocation '..
      (attempt.root and hex(attempt.root) or '(none)')..'; first error: '..
      attempt.error..'; restart test process and CE')
  end
  return result
end
local function recordid(record)
  if not record or type(record.ID)~='number' then fail('use one AA memory-record checkbox, not Execute') end
  return record.ID
end
local function flagwrite(c,p,value)
  local fresh=probe(current())
  if not same(p,fresh) then fail('installation/process changed; no flag write') end
  writechecked(c,p.flag,{value})
end
function S.enable(record)
  local id=recordid(record)
  local c=current()
  -- Gate even a readable hook: publication is not completion, and a failed
  -- post-publication verification must never silently become a new Enable.
  local key=hex(c.pid)..':'..hex(c.base)
  checkattempt(S.attempts[key])
  if S.blocked[key] then
    fail('legacy install attempt has unknown status; restart test process and CE')
  end
  local p=probe(c) or install(c)
  if S.owner and same(S.owner,p) and S.owner.id~=id then
    fail('another active memory record owns this installation; do not duplicate the checkbox')
  end
  -- Bind BEFORE flag write so a readback failure cannot lose ownership.
  S.bindings[id]=p
  local owner={} for k,v in pairs(p) do owner[k]=v end owner.id=id
  S.owner=owner
  flagwrite(c,p,1)
end
function S.disable(record)
  local id=recordid(record)
  local bound=S.bindings[id]
  if not bound then fail('missing record binding; re-adopt via Enable in the intended process') end
  local c=current()
  local p=probe(c)
  if not same(bound,p) then fail('record belongs to another process/installation; no write') end
  flagwrite(c,p,0)
  if S.owner and S.owner.id==id and same(S.owner,p) then S.owner=nil end
end
function S.status()
  local c=current()
  return probe(c) or {pid=c.pid,base=c.base,installed=false}
end
-- Read-only builder exposed for offline validation; never installs a hook.
S.build=build
_G.BMJCheckboxV2=S
{$asm}

[ENABLE]
{$lua}
if syntaxcheck then return end
BMJCheckboxV2.enable(memrec)
{$asm}

[DISABLE]
{$lua}
if syntaxcheck then return end
BMJCheckboxV2.disable(memrec)
{$asm}
]==========],
walk=[==========[// BioMenace Remastered GOG buildId 60154739544974006.
// Four normal player run-state speeds + player air cap/acceleration only.
// No cave, allocation, polling, scan, debugger or shared-enemy-function patch.
// Vertical velocity, gravity and Infinite Jump's horizontal restore unchanged.
// Initial step/jump impulses, friction and special-action states stay original.
// Disable restores tuning; existing airborne momentum settles via original code.

define(BMW_run0,"BioMenace Remastered.exe"+7718F8)
define(BMW_run1,"BioMenace Remastered.exe"+771930)
define(BMW_run2,"BioMenace Remastered.exe"+771968)
define(BMW_run3,"BioMenace Remastered.exe"+7719A0)
define(BMW_aircap,"BioMenace Remastered.exe"+1A3DF8)
define(BMW_airacc,"BioMenace Remastered.exe"+1A3E05)

[ENABLE]
{$lua}
local profiles={
  ['1']={24,'66 03 D2'},
  ['1.5']={36,'8D 14 52'},
  ['2']={48,'C1 E2 02'},
  ['3']={72,'6B D2 06'}
}
local p=profiles['2']
if not syntaxcheck then
  if not targetIs64Bit() or getOpenedProcessID()==0 then
    error('BMW: attach to the supported x64 game process first')
  end
  local pid,base=getOpenedProcessID(),getAddressSafe('BioMenace Remastered.exe')
  if not base then error('BMW: game module unavailable') end
  local value=inputQuery('BioMenace Walkspeed','Multiplier: 1 / 1.5 / 2 / 3','2')
  if not value then error('BMW: activation cancelled; no patch written') end
  value=value:gsub('%s',''):gsub(',','.')
  value=value:gsub('%.0$','')
  p=profiles[value]
  if not p then error('BMW: allowed multipliers are 1, 1.5, 2, 3') end
  if getOpenedProcessID()~=pid or getAddressSafe('BioMenace Remastered.exe')~=base then
    error('BMW: process changed while selecting speed; no patch written')
  end
end
return string.format('define(BMW_speed,%02X)\ndefine(BMW_accel,%s)',p[1],p[2])
{$asm}
assert(BMW_run0,10 00 0B 00 04 00 00 00 01 00 00 00 01 00 00 00 06 00 18 00 00 00 00 00)
assert(BMW_run1,11 00 0C 00 04 00 00 00 01 00 00 00 01 00 00 00 06 00 18 00 00 00 00 00)
assert(BMW_run2,12 00 0D 00 04 00 00 00 01 00 00 00 01 00 00 00 06 00 18 00 00 00 00 00)
assert(BMW_run3,13 00 0E 00 04 00 00 00 01 00 00 00 01 00 00 00 06 00 18 00 00 00 00 00)
assert(BMW_aircap,41 B8 18 00 00 00 0F B7 15 ED 06 79 00 66 03 D2 E8 E3 B8 FF FF)
BMW_run0+12:
  dw BMW_speed
BMW_run1+12:
  dw BMW_speed
BMW_run2+12:
  dw BMW_speed
BMW_run3+12:
  dw BMW_speed
BMW_aircap+2:
  dd BMW_speed
BMW_airacc:
  db BMW_accel

[DISABLE]
{$lua}
-- Infer the active profile, then assert ALL matching code/data before restore.
-- No saved absolute address or controller state is carried across game restarts.
local profiles={
  [24]='66 03 D2', [36]='8D 14 52',
  [48]='C1 E2 02', [72]='6B D2 06'
}
local speed=48
if not syntaxcheck then
  if not targetIs64Bit() or getOpenedProcessID()==0 then
    error('BMW: select the same test-copy process for Disable')
  end
  local base=getAddressSafe('BioMenace Remastered.exe')
  if not base then error('BMW: game module unavailable') end
  speed=readSmallInteger(base+0x77190A)
  if not profiles[speed] then error('BMW: foreign/unreadable speed; restore refused') end
end
return string.format('define(BMW_speed,%02X)\ndefine(BMW_accel,%s)',speed,profiles[speed])
{$asm}
assert(BMW_run0,10 00 0B 00 04 00 00 00 01 00 00 00 01 00 00 00 06 00 BMW_speed 00 00 00 00 00)
assert(BMW_run1,11 00 0C 00 04 00 00 00 01 00 00 00 01 00 00 00 06 00 BMW_speed 00 00 00 00 00)
assert(BMW_run2,12 00 0D 00 04 00 00 00 01 00 00 00 01 00 00 00 06 00 BMW_speed 00 00 00 00 00)
assert(BMW_run3,13 00 0E 00 04 00 00 00 01 00 00 00 01 00 00 00 06 00 BMW_speed 00 00 00 00 00)
assert(BMW_aircap,41 B8 BMW_speed 00 00 00 0F B7 15 ED 06 79 00 BMW_accel E8 E3 B8 FF FF)
BMW_run0+12:
  dw 18
BMW_run1+12:
  dw 18
BMW_run2+12:
  dw 18
BMW_run3+12:
  dw 18
BMW_aircap+2:
  dd 18
BMW_airacc:
  db 66 03 D2
]==========],
}

local prior=rawget(_G,'BMRSmooth')
if prior then
 if prior.version~=1 then error('A different trainer version is already loaded. Restart CE.') end
 if prior.busy then error('Trainer is busy. Retry loading after the current action.') end
 if prior.cleanup then
  if not prior.cleanup() then return end
 else

  prior.closed=true
  if prior.timer then prior.timer.destroy() end
  for _,h in ipairs(prior.hotkeys or {}) do h.destroy() end
  if prior.form then prior.form.destroy() end
 end
end
local S={version=1,selected=1,walkEnabled=false,held={},rows={},hotkeys={},busy=false}
if prior and prior.ready then
 for _,k in ipairs({'pid','base','handle','selected','walkEnabled','jump','jumpHook'}) do S[k]=prior[k] end
end
_G.BMRSmooth=S
local TRAINER_VERSION='v1.1'
local BRAND='Bio Menace - Smooth Edition by dRambone | '..TRAINER_VERSION
local entries={
 {'Infinite Health','Turn OFF when you fall in pits etc.'},
 {'Infinite Ammo',''}, {'Infinite Grenades',''}, {'Infinite Jumps',''},
 {'Infinite Keys','No keys needed to open doors'}, {'Walkspeed Multiplier',''}
}
local titles={}; for i,e in ipairs(entries) do titles[i]=e[1] end
local MODULE='BioMenace Remastered.exe'
local MD5='1930ea195cd02a137bf8b622ee439ff7'
local C={bg=0x202020,card=0x2C2C2C,gold=0x80CAE4,text=0xF0F0F0,muted=0xAFAFAF,off=0x777777,red=0x7777EE}
local function hx(n) return string.format('%X',n) end
local function bytes(s)
  local t={} for h in s:gmatch('%x%x') do t[#t+1]=tonumber(h,16) end return t
end
local function equal(a,b)
  if type(a)~='table' or #a~=#b then return false end
  for i=1,#b do if a[i]~=b[i] then return false end end return true
end
local function match(rva,hex)
  local b=bytes(hex)
  return S.base and equal(readBytes(S.base+rva,#b,true),b)
end
local function connected()
  return S.pid and getOpenedProcessID()==S.pid and getOpenedProcessHandle()==S.handle
    and getAddressSafe(MODULE)==S.base and match(0,'4D 5A')
end
local function requireTarget()
  if not connected() then error('Press F1 to attach to the game first.',0) end
end
local function aa(code)
  requireTarget()
  local ok,why=autoAssemble(code,false)
  if not ok then error('Patch failed: '..tostring(why or 'Cheat Engine rejected the script'),0) end
end
local function section(script,which)
  local global=script:match('^(.-)%[ENABLE%]') or ''
  local body=which=='ENABLE' and script:match('%[ENABLE%](.-)%[DISABLE%]')
    or script:match('%[DISABLE%](.*)')
  if not body then error('Missing embedded script section: '..which) end
  return global..body
end
local function plain(script)
  return (script:gsub('{%$lua}.-{%$asm}',''))
end

local ammo={
  {0x16BEAE,'40 2A C6','84 C0 90'},
  {0x16BF65,'80 C1 FF','84 C9 90'}
}
local grenades={{0x16D1F9,'FE C8','84 C0'}}
local health={{0x1A6036,'66 2B C2','66 85 C0'}}
local keys={{0x1A5BA1,'75','EB'},{0x1A23DD,'0F 84 10 02 00 00','E9 A4 00 00 00 90'}}
local function state(rows)
  local original,patched=true,true
  for _,r in ipairs(rows) do
    original=original and match(r[1],r[2])
    patched=patched and match(r[1],r[3])
  end
  if original then return false elseif patched then return true end
  return nil
end
local function patchRows(rows,on,extra)
  local text={extra or ''}
  for _,r in ipairs(rows) do text[#text+1]='assert('..hx(S.base+r[1])..','..(on and r[2] or r[3])..')' end
  for _,r in ipairs(rows) do text[#text+1]=hx(S.base+r[1])..':\ndb '..(on and r[3] or r[2]) end
  aa(table.concat(text,'\n'))
end
local speedProfiles={
  [1]={24,'66 03 D2'},[2]={48,'C1 E2 02'},[3]={72,'6B D2 06'},
  [4]={96,'6B D2 08'},[5]={120,'6B D2 0A'}
}
local run={0x77190A,0x771942,0x77197A,0x7719B2}
local function speedMatches(factor)
  local p=speedProfiles[factor]
  for _,rva in ipairs(run) do
    if readSmallInteger(S.base+rva)~=p[1] then return false end
  end
  return match(0x1A3DF8,'41 B8 '..string.format('%02X 00 00 00',p[1]))
    and match(0x1A3E05,p[2])
end
local function speedFactor()
  for i=1,5 do if speedMatches(i) then return i end end
end
local function speedCode(from,to)
  local old,new=speedProfiles[from],speedProfiles[to]
  local body=plain(section(scripts.walk,'DISABLE'))
  body=body:gsub('dw 18','dw '..hx(new[1])):gsub('dd 18','dd '..hx(new[1]))
    :gsub('db 66 03 D2','db '..new[2])
  return 'define(BMW_speed,'..hx(old[1])..')\ndefine(BMW_accel,'..old[2]..')\n'..body
end
local function primeJump()
  local core=scripts.jump:match('^(.-)%[ENABLE%]')
  aa(core) -- Defines the existing controller only. Does NOT enable/install.
  S.jump=BMJCheckboxV2.status()
  if S.jump.installed==false then S.jump=nil
  else S.jumpHook=readBytes(S.base+0x1A3D36,7,true) end
end
local function jumpState()
  if not S.jump then
    if match(0x1A3D36,'0F BF 15 E3 06 79 00') then return false end
    return nil
  end
  if not equal(readBytes(S.base+0x1A3D36,7,true),S.jumpHook) then return nil end
  local b=readBytes(S.jump.flag,1,true)
  if b and b[1]==0 then return false elseif b and b[1]==1 then return true end
end
function S.actual(i)
  if not connected() then return nil end
  if i==1 then return state(health)
  elseif i==2 then return state(ammo)
  elseif i==3 then return state(grenades)
  elseif i==4 then return jumpState()
  elseif i==5 then return state(keys)
  else
    local f=speedFactor()
    if not f then return nil end
    if f==1 then return S.walkEnabled end
    return true
  end
end
function S.refresh()
  local live=connected()
  S.connection.Caption=live and ('CONNECTED  /  PID '..S.pid) or 'NOT CONNECTED  /  PRESS F1'
  S.connection.Font.Color=live and C.gold or C.muted
  for i,row in ipairs(S.rows) do
    local ok,v=pcall(S.actual,i)
    if not ok then v=nil end
    row.Caption=not live and (S.pid and 'UNKNOWN' or 'OFF') or (v==nil and 'UNKNOWN' or (v and 'ON' or 'OFF'))
    row.Font.Color=(live and v==nil) and C.red or ((live and v) and C.gold or C.off)
  end
end
local function guarded(fn)
  if S.busy then return end
  S.busy=true
  local ok,err=xpcall(fn,function(e) return tostring(e) end)
  S.busy=false
  S.refresh()
  if not ok then showMessage('Trainer: '..err) end
end
function S.toggle(i)
  guarded(function()
    requireTarget()
    local actual=S.actual(i)
    if actual==nil then error('Unknown or changed cheat bytes. No patch applied.',0) end
    local on=not actual
    if i==1 then aa(section(scripts.health,on and 'ENABLE' or 'DISABLE'))
    elseif i==2 then
      patchRows(ammo,on,
        'assert('..hx(S.base+0x16BE8B)..',84 C0 0F 84 97 00 00 00 BE 01 00 00 00)\n'..
        'assert('..hx(S.base+0x16BEB1)..',88 01 0F 85 CA 00 00 00)\n'..
        'assert('..hx(S.base+0x16BF68)..',88 0D 2F 86 7C 00 EB 13)')
    elseif i==3 then
      patchRows(grenades,on,'assert('..hx(S.base+0x16D1EB)..',42 0F B6 44 05 50 84 C0 0F 8E C8 01 00 00)\n'..
        'assert('..hx(S.base+0x16D1FB)..',BA 03 00 00 00 42 88 44 05 50)')
    elseif i==4 then

      if on then BMJCheckboxV2.enable({ID=0x5F500005})
      else
        if not BMJCheckboxV2.bindings[0x5F500005] then
          BMJCheckboxV2.enable({ID=0x5F500005})
        end
        BMJCheckboxV2.disable({ID=0x5F500005})
      end
      S.jump=BMJCheckboxV2.status()
      S.jumpHook=readBytes(S.base+0x1A3D36,7,true)
    elseif i==5 then aa(section(scripts.keys,on and 'ENABLE' or 'DISABLE'))
    else
      local from=speedFactor()
      aa(speedCode(from,on and S.selected or 1))
      S.walkEnabled=on
    end
    if S.actual(i)~=on then error('The requested state could not be verified.',0) end
  end)
end
function S.changeSpeed()
  if S.settingSlider then return end
  local wanted=math.max(1,math.min(5,math.floor(S.slider.Position)))
  S.speedLabel.Caption=wanted..'x'
  local before=S.selected
  S.selected=wanted
  if not connected() then return end
  local active=S.actual(6)
  if active==true then
    guarded(function()
      aa(speedCode(speedFactor(),wanted))
      S.walkEnabled=true
      if not speedMatches(wanted) then error('Speed update could not be verified.',0) end
    end)
    if not speedMatches(wanted) then
      S.selected=before
      S.settingSlider=true; S.slider.Position=before; S.settingSlider=false
      S.speedLabel.Caption=before..'x'
    end
  elseif active==nil then
    S.refresh()
  end
end
function S.attach()
  guarded(function()
    local candidates={}
    for pid,name in pairs(getProcesslist()) do
      if tostring(name):lower()==MODULE:lower() then candidates[#candidates+1]=tonumber(pid) end
    end
    if #candidates==0 then error('Game not found. Start BioMenace Remastered, then press F1.',0) end
    if #candidates~=1 then error('More than one game process found. Close the extra instances.',0) end
    local pid=candidates[1]
    if connected() and S.pid==pid then S.form.show(); S.form.bringToFront(); return end

    if connected() then error('Another game session is still connected.',0) end
    openProcess(pid)
    if getOpenedProcessID()~=pid or not targetIs64Bit() then error('Could not attach to the x64 game.',0) end
    local path
    for _,m in ipairs(enumModules(pid)) do
      if tostring(m.Name):lower()==MODULE:lower() then path=m.PathToFile; break end
    end
    -- Resolve the executable location from the selected process.
    if not path or path=='' then
      error('Could not resolve the selected game executable.',0)
    end
    local f=io.open(path,'rb')
    if not f then error('Could not verify the selected game executable.',0) end
    local data=f:read('*a'); f:close()
    if not data or stringToMD5String(data):lower()~=MD5 then error('Unsupported game build.',0) end
    S.pid=pid; S.base=getAddressSafe(MODULE); S.handle=getOpenedProcessHandle()
    if not S.base or not connected() then error('Game module could not be verified.',0) end
    S.jump=nil; S.jumpHook=nil; S.walkEnabled=false
    primeJump()
    local actual=speedFactor()
    if actual and actual&gt;1 then
      S.walkEnabled=true; S.selected=actual
      S.settingSlider=true; S.slider.Position=actual; S.settingSlider=false
      S.speedLabel.Caption=actual..'x'
    end
    S.form.show(); S.form.bringToFront()
  end)
end

local configPath=[[F:\Modding-AI\Projects\Bio Menace\BioMenace.hotkeys.cfg]]
S.bindings={}; S.keyFields={}; S.generations={}
local function defaults()
 local t={}; for i=1,6 do t[i]={0x70+i,0} end; return t
end
local function valid(b)
 if type(b)~='table' then return false end
 local k,m=b[1],b[2]
 return type(k)=='number' and type(m)=='number' and m&gt;=0 and m&lt;=7 and m%1==0
  and ((k&gt;=0x41 and k&lt;=0x5A) or (k&gt;=0x30 and k&lt;=0x39)
  or (k&gt;=0x60 and k&lt;=0x6F) or (k&gt;=0x71 and k&lt;=0x87)) and k%1==0
  and not (m&amp;4~=0 and k==0x73) -- Alt+F4 closes the window
end
local function modifiers()
 return (isKeyPressed(0x11) and 1 or 0)+(isKeyPressed(0x10) and 2 or 0)+(isKeyPressed(0x12) and 4 or 0)
end
local function keyText(b)
 local k,m=b[1],b[2]; local s=''
 if m&amp;1~=0 then s=s..'Ctrl+' end
 if m&amp;2~=0 then s=s..'Shift+' end
 if m&amp;4~=0 then s=s..'Alt+' end
 if k&gt;=0x70 then return s..'F'..(k-0x6F) end
 if k&gt;=0x60 and k&lt;=0x69 then return s..'Num'..(k-0x60) end
 local names={[0x6A]='Num*',[0x6B]='Num+',[0x6C]='Separator',[0x6D]='Num-',[0x6E]='Num.',[0x6F]='Num/'}
 return s..(names[k] or string.char(k))
end
local function check(t)
 local seen={}
 for i=1,6 do
  if not valid(t[i]) then return false end
  local id=t[i][1]..':'..t[i][2]
  if seen[id] then return false end; seen[id]=true
 end
 return true
end
local function saveBindings()
 local ok,e=pcall(function()
  local file,err=io.open(configPath,'w'); if not file then error(err) end
  local lines={'BMR-HOTKEYS-1'}
  for i,b in ipairs(S.bindings) do lines[#lines+1]=i..'='..b[1]..','..b[2] end
  local wrote,err=file:write(table.concat(lines,'\n')..'\n')
  local closed,cerr=file:close()
  if not wrote or not closed then error(err or cerr or 'Write failed') end
 end)
 if not ok then showMessage('Hotkeys remain active but could not be saved: '..tostring(e)) end
end
local function loadBindings()
 local file=io.open(configPath,'r'); if not file then return defaults() end
 local t={}; local header=file:read('*l'); local good=header=='BMR-HOTKEYS-1'
 for line in file:lines() do
  local i,k,m=line:match('^(%d+)=(%d+),(%d+)$'); i=tonumber(i)
  if not i or i&lt;1 or i&gt;6 or t[i] then good=false
  else t[i]={tonumber(k),tonumber(m)} end
 end
 file:close()
 if good and check(t) then return t end
 showMessage('Invalid Bio Menace hotkey configuration. Defaults restored.')
 return defaults()
end
local function updateFields()
 for i,field in ipairs(S.keyFields) do field.Caption=keyText(S.bindings[i]) end
end
local function makeHotkey(i,b,generation)
 local keys={b[1]}
 if b[2]&amp;1~=0 then keys[#keys+1]=0x11 end
 if b[2]&amp;2~=0 then keys[#keys+1]=0x10 end
 if b[2]&amp;4~=0 then keys[#keys+1]=0x12 end
 local h=createHotkey(function()
  if S.closed or S.capture or S.blocked or S.generations[i]~=generation or modifiers()~=b[2] then return end
  local function action()
   if S.closed or S.capture or S.blocked or S.generations[i]~=generation or modifiers()~=b[2] then return end
   if S.held[b[1]] then return end; S.held[b[1]]=true; S.toggle(i)
  end
  if inMainThread() then action() else synchronize(action) end
 end,keys)
 if not h then error('Could not register hotkey') end
 h.DelayBetweenActivate=180; return h
end

local function replaceBindings(t)
 local fresh={}; local generations={}
 local ok,e=pcall(function()
  for i=1,6 do
   generations[i]=(S.generations[i] or 0)+1
   fresh[i]=makeHotkey(i,t[i],generations[i])
  end
 end)
 if not ok then
  for _,h in ipairs(fresh) do h.destroy() end
  showMessage('Hotkey registration failed; previous bindings retained: '..tostring(e)); return false
 end
 local previous=S.hotkeys
 S.generations=generations; S.hotkeys=fresh; S.bindings=t
 for _,h in ipairs(previous) do h.destroy() end
 updateFields(); return true
end
function S.cancelCapture()
 S.capture=nil; S.pending=nil; S.blocked=true
 if S.captureEdit then S.captureEdit.Visible=false end
 updateFields()
end
function S.beginCapture(i)
 S.cancelCapture(); S.capture=i
 S.keyFields[i].Caption='PRESS KEY'
 S.captureEdit.Text='PRESS KEY - Esc cancels'
 S.captureEdit.Visible=true; S.captureEdit.setFocus()
end
function S.captureDown(sender,key)
 if not S.capture then return 0 end
 if key==0x1B then S.cancelCapture(); return 0 end
 if key==0x10 or key==0x11 or key==0x12 or (key&gt;=0xA0 and key&lt;=0xA5) then return 0 end
 if S.pending then return 0 end
 local b={key,modifiers()}
 if not valid(b) then showMessage('Use letters, digits, numpad or F2-F24. F1 is reserved.'); return 0 end
 for i,other in ipairs(S.bindings) do
  if i~=S.capture and other[1]==b[1] and other[2]==b[2] then
   showMessage('This hotkey is already assigned to '..titles[i]..'.'); return 0
  end
 end
 S.pending=b; S.captureEdit.Text=keyText(b)..' - release key'
 return 0
end
function S.captureUp(sender,key)
 if not S.capture or not S.pending or key~=S.pending[1] then return 0 end
 local t={}; for i,b in ipairs(S.bindings) do t[i]={b[1],b[2]} end
 t[S.capture]=S.pending
 S.blocked=true
 if replaceBindings(t) then saveBindings() end
 S.cancelCapture(); return 0
end
function S.resetBindings()
 S.cancelCapture()
 if replaceBindings(defaults()) then saveBindings() end
end
S.bindings=loadBindings()


function S.cleanup()
 if S.closed then return true end
 if S.busy then showMessage('Trainer is busy; finish the current action first.'); return false end
 S.cancelCapture(); S.closed=true
 if S.timer then S.timer.destroy() end
 for _,h in ipairs(S.hotkeys) do h.destroy() end
 S.hotkeys={}
 if S.attachHotkey then S.attachHotkey.destroy() end
 if S.watermark then S.watermark.destroy() end
 if S.form then S.form.destroy() end
 if rawget(_G,'BMRSmooth')==S then _G.BMRSmooth=nil end
 return true
end
local function label(parent,text,x,y,w,h,size,color)
 local l=createLabel(parent); l.Parent=parent; l.AutoSize=false
 l.Left=x; l.Top=y; l.Width=w; l.Height=h; l.Caption=text
 l.Font.Name='Segoe UI'; l.Font.Size=size; l.Font.Color=color; return l
end
local rowsTop,rowStep=130,59
local sliderY=rowsTop+#entries*rowStep+39
local scaleY=sliderY+42
local connectionY=scaleY+26
local resetY=connectionY+32
local captureY=resetY+37
local f=createForm(false); S.form=f
f.Caption=BRAND; f.Color=C.bg; f.Font.Name='Segoe UI'
f.ClientWidth=600; f.ClientHeight=captureY+42; f.Position='poScreenCenter'; f.BorderStyle='bsSingle'
f.OnClose=function() S.cancelCapture(); return caHide end
f.OnDeactivate=function() if S.capture then S.cancelCapture() end end
label(f,'BIO MENACE',25,20,550,37,23,C.gold).Font.Style='[fsBold]'
label(f,'Smooth Edition by dRambone',27,62,460,25,11,C.text)
label(f,TRAINER_VERSION,515,62,60,25,11,C.gold)
label(f,'Click a hotkey to reassign it.',27,94,540,22,10,C.muted)
for i,e in ipairs(entries) do
 local index=i; local p=createPanel(f); p.Parent=f; p.Caption=''; p.Color=C.card; p.BevelOuter='bvNone'
 p.Left=25; p.Top=rowsTop+(i-1)*rowStep; p.Width=550; p.Height=50
 local field=createPanel(p); field.Parent=p; field.Left=8; field.Top=9; field.Width=155; field.Height=32
 field.BevelOuter='bvNone'; field.Color=C.bg; field.Font.Name='Segoe UI'; field.Font.Size=11; field.Font.Color=C.gold
 field.Cursor=-21; field.OnClick=function() S.beginCapture(index) end; S.keyFields[i]=field
 local name=label(p,e[1],173,e[2]~='' and 3 or 10,246,e[2]~='' and 24 or 28,12,C.text); name.WordWrap=true
 if e[2]~='' then label(p,e[2],173,29,246,18,9,C.muted) end
 local status=createPanel(p); status.Parent=p; status.Left=427; status.Top=9; status.Width=108; status.Height=32
 status.BevelOuter='bvNone'; status.Color=C.bg; status.Caption='OFF'; status.Font.Name='Segoe UI'; status.Font.Size=11; status.Font.Color=C.off
 status.Cursor=-21; status.OnClick=function() if not S.closed then S.toggle(index) end end; S.rows[i]=status
end
label(f,'WALKSPEED MULTIPLIER',27,sliderY-29,380,23,10,C.muted)
S.speedLabel=label(f,S.selected..'x',515,sliderY-31,60,27,14,C.gold)
S.slider=createTrackBar(f); S.slider.Parent=f; S.slider.Left=25; S.slider.Top=sliderY; S.slider.Width=550; S.slider.Height=40
S.slider.Color=C.bg; S.slider.Min=1; S.slider.Max=5; S.slider.Position=S.selected
setProperty(S.slider,'LineSize','1'); setProperty(S.slider,'PageSize','1'); S.slider.OnChange=S.changeSpeed
for i=1,5 do label(f,i..'x',30+(i-1)*132,scaleY,38,21,9,C.muted) end
S.connection=label(f,'NOT CONNECTED  /  PRESS F1',27,connectionY,548,24,10,C.muted)
S.captureEdit=createEdit(f); S.captureEdit.Parent=f; S.captureEdit.Left=25; S.captureEdit.Top=captureY; S.captureEdit.Width=550; S.captureEdit.Height=25
S.captureEdit.Font.Name='Segoe UI'; S.captureEdit.Font.Size=11; S.captureEdit.Font.Color=C.gold; S.captureEdit.Color=C.card
S.captureEdit.ReadOnly=true; S.captureEdit.Visible=false; S.captureEdit.OnKeyDown=S.captureDown; S.captureEdit.OnKeyUp=S.captureUp
local reset=createPanel(f); reset.Parent=f; reset.Width=260; reset.Left=math.floor((f.ClientWidth-reset.Width)/2); reset.Top=resetY; reset.Height=29
reset.Caption='RESET HOTKEYS'; reset.Color=C.card; reset.BevelOuter='bvNone'; reset.Font.Name='Segoe UI'; reset.Font.Size=10; reset.Font.Color=C.gold
reset.Cursor=-21; reset.OnClick=S.resetBindings
local main=getMainForm()
local w=createPanel(main); S.watermark=w; w.Parent=main; w.Align='alTop'; w.Height=26; w.Caption=''; w.Color=C.bg; w.BevelOuter='bvNone'
local wm=label(w,'Bio Menace | created by dRambone | '..TRAINER_VERSION,0,0,600,26,10,C.gold)
wm.Align='alClient'; wm.Alignment='taCenter'; wm.Layout='tlCenter'
if not replaceBindings(S.bindings) then S.cleanup(); return end
S.attachHotkey=createHotkey(function()
 if S.closed or S.capture or S.blocked then return end
 local function action()
  if S.closed or S.capture or S.blocked or S.held[0x70] then return end
  S.held[0x70]=true; S.attach()
 end
 if inMainThread() then action() else synchronize(action) end
end,0x70)
S.attachHotkey.DelayBetweenActivate=180
local ticks=0
S.timer=createTimer(nil,false); S.timer.Interval=20
S.timer.OnTimer=function()
 if S.closed or S.busy then return end
 if S.blocked and not S.capture then
  local down=false
  for vk=8,0xA5 do if isKeyPressed(vk) then down=true; break end end
  if not down then S.blocked=false end
 end
 for vk in pairs(S.held) do if not isKeyPressed(vk) then S.held[vk]=nil end end
 ticks=ticks+1
 if ticks%25==0 then S.refresh() end
end
S.timer.Enabled=true; S.refresh(); S.ready=true
</LuaScript>
</CheatTable>
