<?xml version="1.0" encoding="utf-8"?>
<CheatTable CheatEngineTableVersion="42">
  <CheatEntries>
    <CheatEntry>
      <ID>11</ID>
      <Description>"Enable (Enable Twice)"</Description>
      <Options moHideChildren="1"/>
      <VariableType>Auto Assembler Script</VariableType>
      <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end;if process==nil then ShowMessage('Process is not selected.')elseif readInteger(process)==0 then ShowMessage('Process cannot be opened.')else if monopipe~=nil and monopipe.ProcessID~=getOpenedProcessID()then monopipe.destroy()monopipe=nil end;if monopipe==nil then LaunchMonoDataCollector()end end
{$asm}
define(ItemSlotTryAddItemProc,"ItemSlot:TryAddItem")
define(ItemSlotRemoveItemsProc,"ItemSlot:RemoveItems")

registersymbol(ItemSlotTryAddItemProc)
registersymbol(ItemSlotRemoveItemsProc)
[DISABLE]
{$lua}
if syntaxcheck then return end
if not syntaxcheck and monopipe then monopipe = nil,monopipe.Destroy()end
{$asm}
unregistersymbol(*)
</AssemblerScript>
      <CheatEntries>
        <CheatEntry>
          <ID>7</ID>
          <Description>"Goods no decrease"</Description>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>{ Game   : Factory Town.exe
  Version:
  Date   : 2022-08-09
  Author : bbfox@ https://opencheattables.com
}
[ENABLE]

//aobscan(INJECT_GOODS,89 47 30 85 C0 7F) // should be unique
aobscanregion(INJECT_GOODS,ItemSlotRemoveItemsProc+10, ItemSlotRemoveItemsProc+30, 89 47 30 85 C0 7F)
alloc(newmem,$1000,INJECT_GOODS)

label(code)
label(return)

newmem:

code:
  cmp [rdi+20], 1
  jne _nothing
  // rdi+34: rawCapacity
  {
  cmp [rdi+34], #200
  jl _nothing
  cmp [rdi+34], #250
  je _next
  cmp [rdi+34], #400
  je _next
  cmp [rdi+34], #600
  je _next
  cmp [rdi+34], #800
  je _next
  cmp [rdi+34], #1000
  je _next
  cmp [rdi+34], #2000
  je _next
  cmp [rdi+34], #3000
  je _next
  cmp [rdi+34], #4000
  je _next
  cmp [rdi+34], #5000
  je _next
  cmp [rdi+34], #10000
  je _next
  jmp _nothing
  }
_next:

  add eax,[rbp-10]
  cmp eax, [rdi+34]
  jl _nothing

  vmovss xmm15, [vf_0_9]
  cvtsi2ss xmm14, [rdi+34]
  vmulss xmm14, xmm14, xmm15
  cvtss2si eax, xmm14
  //sub eax, 50

_nothing:
  mov [rdi+30],eax
  test eax,eax
  jmp return
align 10 cc
  vf_0_9:
  dd (float)0.9


INJECT_GOODS:
  jmp newmem
return:
registersymbol(INJECT_GOODS)

[DISABLE]

INJECT_GOODS:
  db 89 47 30 85 C0

unregistersymbol(INJECT_GOODS)
dealloc(newmem)

{
// ORIGINAL CODE - INJECTION POINT: ItemSlot:RemoveItems+1a

1E9E42B5C7C: 00 00                          - add [rax],al
1E9E42B5C7E: 00 00                          - add [rax],al
ItemSlotRemoveItemsProc: 55                             - push rbp
ItemSlot:RemoveItems+1: 48 8B EC                       - mov rbp,rsp
ItemSlot:RemoveItems+4: 48 83 EC 30                    - sub rsp,30
ItemSlot:RemoveItems+8: 48 89 7D F8                    - mov [rbp-08],rdi
ItemSlot:RemoveItems+c: 48 8B F9                       - mov rdi,rcx
ItemSlot:RemoveItems+f: 48 89 55 F0                    - mov [rbp-10],rdx
ItemSlot:RemoveItems+13: 48 63 47 30                    - movsxd  rax,dword ptr [rdi+30]
ItemSlot:RemoveItems+17: 2B 45 F0                       - sub eax,[rbp-10]
// ---------- INJECTING HERE ----------
ItemSlot:RemoveItems+1a: 89 47 30                       - mov [rdi+30],eax
// ---------- DONE INJECTING  ----------
ItemSlot:RemoveItems+1d: 85 C0                          - test eax,eax
ItemSlot:RemoveItems+1f: 7F 12                          - jg ItemSlot:RemoveItems+33
ItemSlot:RemoveItems+21: 48 8B CF                       - mov rcx,rdi
ItemSlot:RemoveItems+24: 33 D2                          - xor edx,edx
ItemSlot:RemoveItems+26: 49 BB D0 29 2B E4 E9 01 00 00  - mov r11,ItemSlot:SetFillTypeAndCapacity
ItemSlot:RemoveItems+30: 41 FF D3                       - call r11
ItemSlot:RemoveItems+33: 48 8B 7D F8                    - mov rdi,[rbp-08]
ItemSlot:RemoveItems+37: 48 8D 65 00                    - lea rsp,[rbp+00]
ItemSlot:RemoveItems+3b: 5D                             - pop rbp
ItemSlot:RemoveItems+3c: C3                             - ret
}
</AssemblerScript>
        </CheatEntry>
        <CheatEntry>
          <ID>10</ID>
          <Description>"Goods not flooding"</Description>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>{ Game   : Factory Town.exe
  Version:
  Date   : 2022-08-09
  Author : bbfox@ https://opencheattables.com
}
[ENABLE]

//aobscan(INJECT_GOODS_INC,41 89 47 30 49 63 47 28) // should be unique
aobscanregion(INJECT_GOODS_INC,ItemSlotTryAddItemProc+130, ItemSlotTryAddItemProc+160, 41 89 47 30 49 63 47 28)
alloc(newmem,$1000,INJECT_GOODS_INC)

label(code)
label(return)

newmem:

code:
  cmp [r15+20], 1
  jne _nothing
  {
  cmp [r15+34], #200
  jl _nothing
  cmp [r15+34], #250
  je _next
  cmp [r15+34], #400
  je _next
  cmp [r15+34], #600
  je _next
  cmp [r15+34], #800
  je _next
  cmp [r15+34], #900
  je _next
  cmp [r15+34], #1000
  je _next
  cmp [r15+34], #2000
  je _next
  cmp [r15+34], #3000
  je _next
  cmp [r15+34], #4000
  je _next
  cmp [r15+34], #5000
  je _next
  cmp [r15+34], #10000
  je _next
  jmp _nothing
  }
_next:
  push rbx
  mov ebx, [r15+34]
  sub ebx, 49
  cmp eax, ebx
  pop rbx
  jl @F

  cvtsi2ss xmm15, [r15+34]
  vmovss xmm14, [vf_0_9]
  vmulss xmm15, xmm15, xmm14
  cvtss2si eax, xmm15

  cmp eax, 9
  jbe @F
  add eax, 1


  //mov eax, [r15+34]
  //sub eax, 49


_nothing:
  mov [r15+30],eax
  movsxd  rax,dword ptr [r15+28]
  jmp return
align 10 cc
  vf_0_9:
  dd (float)0.9

INJECT_GOODS_INC:
  jmp newmem
  nop 3
return:
registersymbol(INJECT_GOODS_INC)

[DISABLE]

INJECT_GOODS_INC:
  db 41 89 47 30 49 63 47 28

unregistersymbol(INJECT_GOODS_INC)
dealloc(newmem)

{
// ORIGINAL CODE - INJECTION POINT: ItemSlot:TryAddItem+150

ItemSlot:TryAddItem+12d: 74 06                          - je ItemSlot:TryAddItem+135
ItemSlot:TryAddItem+12f: 41 BC 01 00 00 00              - mov r12d,00000001
ItemSlot:TryAddItem+135: 48 63 45 B0                    - movsxd  rax,dword ptr [rbp-50]
ItemSlot:TryAddItem+139: 48 8B D8                       - mov rbx,rax
ItemSlot:TryAddItem+13c: 41 3B DC                       - cmp ebx,r12d
ItemSlot:TryAddItem+13f: 41 0F 4F DC                    - cmovg ebx,r12d
ItemSlot:TryAddItem+143: 49 63 47 30                    - movsxd  rax,dword ptr [r15+30]
ItemSlot:TryAddItem+147: 48 8B CB                       - mov rcx,rbx
ItemSlot:TryAddItem+14a: 41 0F AF CD                    - imul ecx,r13d
ItemSlot:TryAddItem+14e: 03 C1                          - add eax,ecx
// ---------- INJECTING HERE ----------
ItemSlot:TryAddItem+150: 41 89 47 30                    - mov [r15+30],eax
// ---------- DONE INJECTING  ----------
ItemSlot:TryAddItem+154: 49 63 47 28                    - movsxd  rax,dword ptr [r15+28]
ItemSlot:TryAddItem+158: 41 3B C6                       - cmp eax,r14d
ItemSlot:TryAddItem+15b: 74 16                          - je ItemSlot:TryAddItem+173
ItemSlot:TryAddItem+15d: 49 8B CF                       - mov rcx,r15
ItemSlot:TryAddItem+160: 49 8B D6                       - mov rdx,r14
ItemSlot:TryAddItem+163: 66 66 90                       - nop 3
ItemSlot:TryAddItem+166: 49 BB D0 29 2B E4 E9 01 00 00  - mov r11,ItemSlot:SetFillTypeAndCapacity
ItemSlot:TryAddItem+170: 41 FF D3                       - call r11
ItemSlot:TryAddItem+173: 85 DB                          - test ebx,ebx
ItemSlot:TryAddItem+175: 0F 8E 4E 00 00 00              - jng ItemSlot:TryAddItem+1c9
}
</AssemblerScript>
        </CheatEntry>
      </CheatEntries>
    </CheatEntry>
    <CheatEntry>
      <ID>12</ID>
      <Description>"Factory Town 2.1  /  https://opencheattables.com  /  CE 7.4+"</Description>
      <Color>400080</Color>
      <GroupHeader>1</GroupHeader>
    </CheatEntry>
  </CheatEntries>
  <UserdefinedSymbols/>
</CheatTable>
