<?xml version="1.0" encoding="utf-8" ?>
<EternityPatchFile name="UIPatches" comment="This file enables patches related with UI" >

	<!-- Addresses 1.08 unless stated otherwise -->	
	
	<!-- ui_enemy_portrait group -->
	<Patch name="PortraitEnemyForEMB" enabled="ui_enemy_portrait" type="write" search_start="0x216AAE" >
		<Instruction code="83 F9 01" comment="cmp ecx, 1" />
		<Instruction code="0F 85 91 00 00 00" comment="jnz +0x91" />
		<Instruction code="8B 45 04" comment="mov eax, [rbp+4]" />
		<Instruction code="85 C0" comment="test eax, eax" />
		<Instruction code="74 32" comment="jz +0x32" />
		<Instruction code="3B C1" comment="cmp eax, ecx" />
		<Instruction code="0F 84 8E 00 00 00" comment="jz +0x8E" />
		<Instruction code="83 F8 07" comment="cmp eax, 7" />
		<Instruction code="74 0F" comment="jz +0xF" />
		<Instruction code="83 C0 F7" comment="add eax, -9" />
		<Instruction code="83 F8 06" comment="cmp eax, 6" />
		<Instruction code="77 75" comment="ja +0x75" />
		
		<!-- Change jump of == 7 + change the other condition to !(>= 7 && <= 15) -->
		<Write inst_index="8" value="XX08 XXXXF9 XXXX08" />
	</Patch>
	
	<Patch name="PortraitEnemyForAutoGen" enabled="ui_enemy_portrait" type="write" search_start="0x216B36" >
		<Instruction code="83 F8 01" comment="cmp eax, 1"/>
		<Instruction code="74 19" comment="jz +0x19" />
		<Instruction code="83 F8 09" comment="cmp eax, 9"/>
		<Instruction code="74 14" comment="jz +0x14" />
		<Instruction code="83 C0 F2" comment="add eax, -0xE" />
		<Instruction code="83 F8 01" comment="cmp eax, 1" />
		<Instruction code="76 0C" comment="jbe +0xC" />
		
		<!-- Change condition to >= 7 && <= 15 -->
		<Write inst_index="4" value="XXXXF9 XXXX08" />
	</Patch>
	
	<Patch name="ShowTheRedRing" enabled="ui_enemy_portrait" type="notify" search_start="0x216781" >
		<Instruction code="4C 8D 0D XXXXXXXX" comment="lea r9, array" />
		<Instruction code="48 89 9C 24 90 00 00 00" comment="mov [rsp+90h], rbx" />
		<Instruction code="4C 89 AC 24 A8 00 00 00" comment="mov [rsp+A8h], r13" />
		<Instruction code="44 39 71 04" comment="cmp [rcx+4], r14d" />
		<Instruction code="74 26" comment="jz +0x26" />
		<Instruction code="4B 8B 0C F1" comment="mov rcx, [r9+r14*8]" />
		<Instruction code="4C 8B C5" comment="mov r8, rbp" />
		
		<Notify inst_index="0" inst_offset="3" value="ShowTheRedRing" />
	</Patch>
	<!-- end of ui_enemy_portrait group -->
	
	<!-- Note: a change in the signature of this patch may need an update on the dll part -->
	<Patch name="LocateToggleBattleUIPatch" enabled="hide_battle_ui" type="notify" search_start="0x20FD75" comment="signature 1.09.1" >
		<Instruction code="4C 8D 4D 90" comment="lea r9, [rbp-70h]" />
		<Instruction code="89 44 24 20" comment="mov [rsp+20h], eax" />
		<Instruction code="4C 8D 44 24 70" comment="lea r8, [rsp+70h]" />
		<Instruction code="49 8B D7" comment="mov rdx, r15" />
		<Instruction code="49 8B CE" comment="mov rcx, r14" />
		<Instruction code="E8 XXXXXXXX" comment="call battle_ui function" />
		<Instruction code="48 63 54 24 70" comment="movsxd edx, [rsp+70h]" />
		<Instruction code="83 FA FF" comment="cmp edx, -1" />
	
		<Notify inst_index="5" value="OnLocateToggleBattleUIPatch" />
	</Patch>
	
	<!-- Warning: signature of this is this big because too many functions start like this -->
	<Patch name="HookPopupPauseCtor" type="hook" search_start="0x591620" comment="address 1.09.1" > 
		<Instruction code="48 89 4C 24 08" comment="mov [rsp+8], rcx" />
		<Instruction code="57" comment="push rdi" />
		<Instruction code="48 83 EC 40" comment="sub rsp, 40h" />
		<Instruction code="48 C7 44 24 30 FE FF FF FF" comment="mov qword ptr[rsp+30h], -2" />
		<Instruction code="48 89 5C 24 58" comment="mov [rsp+58h], rbx" />
		<Instruction code="48 89 6C 24 60" comment="mov [rsp+60h], rbx" />
		<Instruction code="48 89 74 24 68" comment="mov [rsp+68h], rsi" />
		<Instruction code="48 8B F1" comment="mov rsi, rcx" />
		<Instruction code="BA 02 00 00 00" comment="mov edx, 2" />
		<Instruction code="44 8D 42 0C" comment="lea r8d, [rdx+0Ch]" />
		
		<Hook value="PopupPauseCtorHooked" setup="SetupPopupPauseCtor" />
	</Patch>
	
	<!-- Notice: the purpose of this patch is to gather the return address of the call to the popup pause ctor done in battle mode, to distinguish them from other pause menus -->
	<!-- So, the instruction returned is the one AFTER the call -->	
	<Patch name="LocatePopupPauseBattleRA" type="notify" search_start="0x1E8668" comment="address 1.09.1" >
		<Instruction code="48 8B C8" comment="mov rcx, rax" />
		<Instruction code="E8 XXXXXXXX" comment="call popup_pause_ctor" />
		<Instruction code="90" comment="nop" />
		<Instruction code="48 89 43 48" comment="mov [rbx+48h], rax" />
		<Instruction code="C6 05 XXXXXXXX 00" comment="mov XXXXXXXX, 0" />
		<Instruction code="48 8B 4B 68" comment="mov rcx, [rbx+68h]" />
		<Instruction code="48 85 C9" comment="test rcx, rcx" />
		<Instruction code="74 0A" comment="jz A" />
		<Instruction code="BA 59 00 00 00" comment="mov edx, 59h" />
		
		<Notify inst_index="2" value="OnPopupPauseBattleRALocated" />
	</Patch>
	
</EternityPatchFile>
	