mirror of
				https://github.com/hedge-dev/XenonRecomp.git
				synced 2025-11-04 06:47:09 +00:00 
			
		
		
		
	Add support for placing midasm hooks after instructions.
This commit is contained in:
		@@ -333,7 +333,8 @@ bool Recompiler::Recompile(
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    auto midAsmHook = config.midAsmHooks.find(base);
 | 
					    auto midAsmHook = config.midAsmHooks.find(base);
 | 
				
			||||||
    if (midAsmHook != config.midAsmHooks.end())
 | 
					
 | 
				
			||||||
 | 
					    auto printMidAsmHook = [&]()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            bool returnsBool = midAsmHook->second.returnOnFalse || midAsmHook->second.returnOnTrue ||
 | 
					            bool returnsBool = midAsmHook->second.returnOnFalse || midAsmHook->second.returnOnTrue ||
 | 
				
			||||||
                midAsmHook->second.jumpAddressOnFalse != NULL || midAsmHook->second.jumpAddressOnTrue != NULL;
 | 
					                midAsmHook->second.jumpAddressOnFalse != NULL || midAsmHook->second.jumpAddressOnTrue != NULL;
 | 
				
			||||||
@@ -410,7 +411,10 @@ bool Recompiler::Recompile(
 | 
				
			|||||||
                else if (midAsmHook->second.jumpAddress != NULL)
 | 
					                else if (midAsmHook->second.jumpAddress != NULL)
 | 
				
			||||||
                    println("\tgoto loc_{:X};", midAsmHook->second.jumpAddress);
 | 
					                    println("\tgoto loc_{:X};", midAsmHook->second.jumpAddress);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
    }
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (midAsmHook != config.midAsmHooks.end() && !midAsmHook->second.afterInstruction)
 | 
				
			||||||
 | 
					        printMidAsmHook();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int id = insn.opcode->id;
 | 
					    int id = insn.opcode->id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -2149,6 +2153,9 @@ bool Recompiler::Recompile(
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (midAsmHook != config.midAsmHooks.end() && midAsmHook->second.afterInstruction)
 | 
				
			||||||
 | 
					        printMidAsmHook();
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -118,6 +118,8 @@ void RecompilerConfig::Load(const std::string_view& configFilePath)
 | 
				
			|||||||
                fmt::println("{}: can't mix direct and conditional return/jump", midAsmHook.name);
 | 
					                fmt::println("{}: can't mix direct and conditional return/jump", midAsmHook.name);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            midAsmHook.afterInstruction = table["after_instruction"].value_or(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            midAsmHooks.emplace(*table["address"].value<uint32_t>(), std::move(midAsmHook));
 | 
					            midAsmHooks.emplace(*table["address"].value<uint32_t>(), std::move(midAsmHook));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,6 +18,8 @@ struct RecompilerMidAsmHook
 | 
				
			|||||||
    uint32_t jumpAddress = 0;
 | 
					    uint32_t jumpAddress = 0;
 | 
				
			||||||
    uint32_t jumpAddressOnTrue = 0;
 | 
					    uint32_t jumpAddressOnTrue = 0;
 | 
				
			||||||
    uint32_t jumpAddressOnFalse = 0;
 | 
					    uint32_t jumpAddressOnFalse = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    bool afterInstruction = false;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct RecompilerConfig
 | 
					struct RecompilerConfig
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user