<?xml version="1.0" encoding="utf-8" ?>
<EternityPatchFile name="LooseFiles" enabled="loose_files" comment="This file enables loose files to have higher priority than cpk files">

	<Patch name="LoadTocHook" type="hook" search_start="0x7255E" >
		<Instruction code="49 8B D2" comment="mov rdx, r10; buf" />
		<Instruction code="49 8B CB" comment="mov rcx, r11; unk param" />
		<Instruction code="E8 XX XX XX XX" comment="call LoadTable" />
		<Instruction code="48 89 07" comment="mov [rdi], rax" />
		<Instruction code="48 85 C0" comment="test rax, rax" />
		<Instruction code="75 05" comment="jnz +5" />
		<Instruction code="21 43 58" comment="and [rbx+58h], eax" />
		<Instruction code="EB E4" comment="jmp -1C" />
		<Instruction code="48 8B C8" comment="mov rcx, rax" />
		<Instruction code="E8 XX XX XX XX" comment="call XXXXXXXX" />
		
		<Hook type="call" inst_index="2" value="LoadToc" setup="LoadToc_Setup" />		
	</Patch>	
	
	<Patch name="DisableSort" type="write" search_start="0x70F91" comment="This patch makes CPK sorted flag always false. Without this, the previous patch would cause a mess on cpk with that feature enabled." >
		<Instruction code="4C 8D 05 XX XX XX XX" comment="lea r8, #sorted#" />
		<Instruction code="33 D2" comment="xor edx, edx" />
		<Instruction code="48 8B CF" comment="mov rcx, rdi" />
		<Instruction code="66 89 83 80 00 00 00" comment="mov [rbx+80h], ax" />
		<Instruction code="E8 XX XX XX XX" comment="call XXXXXXXX" />
		<Instruction code="4C 8D 05 XX XX XX XX" comment="lea r8, #eid#" />
		<Instruction code="66 89 83 82 00 00 00" comment="mov [rbx+82h], ax" />
		<Instruction code="33 D2" comment="xor edx, edx" />
		<Instruction code="48 8B CF" comment="mov rcx, rdi" />
		<Instruction code="E8 XX XX XX XX" comment="call XXXXXXXX" />
		<Instruction code="4C 8D 05 XX XX XX XX" comment="lea r8, #comment#" />
		<Instruction code="33 D2" comment="xor edx, edx" />
		<Instruction code="48 8B CF" comment="mov rcx, rdi" />
		<Instruction code="66 89 83 84 00 00 00" comment="mov [rbx+84h], ax" />
		<Instruction code="E8 XX XX XX XX" comment="call XXXXXXXX" />
				
		<Write inst_index="4" value="4831C0 90 90" comment="xor rax, rax; nop; nop" /> 
	</Patch>
	
	<Patch name="NotifyLFFunc1" type="notify" search_start="0x73288" >
		<Instruction code="48 8B C4" comment="mov rax, rsp"/>
		<Instruction code="48 89 58 08" comment="mov [rax+8], rbx" />
		<Instruction code="48 89 68 10" comment="mov [rax+10h], rbp" />
		<Instruction code="48 89 70 18" comment="mov [rax+18h], rsi" />
		<Instruction code="48 89 78 20" comment="mov [rax+20h], rdi" />
		<Instruction code="41 56" comment="push r14" />
		<Instruction code="48 83 EC 20" comment="sub rsp, 20h" />
		<Instruction code="33 DB" comment="xor ebx, ebx" />
		<Instruction code="49 8B F9" comment="mov rdi, r9" />
		<Instruction code="49 8B E8" comment="mov rbp, r8" />
		<Instruction code="48 8B F2" comment="mov  rsi, rdx" />
		
		<Notify value="NotifyLFFunc1" />
	</Patch>
	
	<Patch name="NotifyLFFunc2" type="notify" search_start="0x6A738" >
		<Instruction code="48 8B C4" comment="mov rax, rsp" />
		<Instruction code="48 89 58 08" comment="mov [rax+8], rbx" />
		<Instruction code="48 89 70 20" comment="mov [rax+20h], rsi" />
		<Instruction code="57 " comment="push rdi" />
		<Instruction code="48 83 EC 20" comment="sub rsp, 20h" />
		<Instruction code="48 83 60 10 00" comment="and qword ptr [rax+10h], 0" />
		<Instruction code="48 8B F9" comment="mov rdi, rcx" />
		<Instruction code="48 8D 48 10" comment="lea  rcx, [rax+10h]" />
		<Instruction code="48 83 CE FF" comment="or rsi, 0FFFFFFFFFFFFFFFFh" />
		<Instruction code="48 8B DA" comment="mov rbx, rdx" />
		<Instruction code="48 89 32" comment="mov [rdx], rsi" />
		
		<Notify value="NotifyLFFunc2" />
	</Patch>
	
	<Patch name="CpkGetFileInfoHook" type="hook" search_start="0x2C9D79" >
		<Instruction code="48 8B D0" comment="mov rdx, rax; path" />
		<Instruction code="4C 8D 4C 24 40" comment="lea r9, [rsp+040h]; result_ptr" />
		<Instruction code="4C 8D 44 24 68" comment="lea r8, [rsp+068h]; ret_entry" />
		<Instruction code="48 8B 4E 60" comment="mov  rcx, [rsi+60h]; cpk_object" />		
		<Instruction code="E8 XX XX XX XX" comment="call CpkGetFileInfo" />
		<Instruction code="85 C0" comment="test eax, eax" />
		<Instruction code="0F 85 99 00 00 00" comment="jnz +99" />
		<Instruction code="44 39 74 24 40" comment="cmp  [rsp+40h], r14d; result_ptr==0" />
		<Instruction code="0F 84 8E 00 00 00" comment="jz +8E" />
		<Instruction code="8B 84 24 88 00 00 00" comment="mov  eax, [rsp+88h]; eax = file_size" />
		<Instruction code="89 47 10" comment="mov [rdi+10h], eax; [rdi+10h] = file_size" />
		
		<Hook type="call" inst_index="4" value="CpkGetFileInfo_Patched" setup="CpkGetFileInfo_Setup" />
	</Patch>
	
	<Patch name="CpkGetFileInfoHook2" type="hook" search_start="0x2C9D79" >
		<Instruction code="48 8B 49 68" comment="mov rcx, [rcx+68h]; cpk_object" />
		<Instruction code="4C 8D 4C 24 20" comment="lea r9, [rsp+20h] result_ptr" />
		<Instruction code="4C 8D 44 24 28" comment="lea     r8, [rsp+28h]; ret_entry" />
		<Instruction code="E8 XX XX XX XX" comment="call CpkGetFileInfo" />
		<Instruction code="85 C0" comment="test  eax, eax" />
		<Instruction code="75 29" comment="jnz 29" />
		<Instruction code="39 44 24 20" comment="cmp [rsp+20h], eax" />
		<Instruction code="74 23" comment="jz +23" />
		<Instruction code="48 85 DB" comment="test  rbx, rbx" />
		<Instruction code="74 06" comment="jz +6" />
		<Instruction code="8B 44 24 48" comment="mov  eax, [rsp+48h]" />
		
		
		<Hook type="call" inst_index="3" value="CpkGetFileInfo_Patched" />
	</Patch>

</EternityPatchFile>