Using the New Vegas Script Extender C++ API for Fallout New Vegas, I am able to write to the process' memory directly at runtime through a .dll plugin that's loaded by the NVSE injector. But it is not a debugger, like CheatEngine, so there's no automatic handling of inserting new code to an existing assembly function.
Beginning of the assembly function,
TryOpenPipboy, I want to inject code into: https://i.imgur.com/MQUrbXa.png
EquipPlayerPipboy() function I want to inject: https://i.imgur.com/IjmMRFU.png
The game has a loop called
MainUILoop which runs every frame, and when the player presses tab without holding it down,
TryOpenPipboy is called.
My guess is that I need to somehow create a new empty block of memory, edit a copy of the original
TryOpenPipboy function, then replace all
TryOpenPipboy calls with my modified variant. But that would make a hard incompatibility with any other NVSE plugins that also modify the MainUILoop in any way, as well as any that edit
Edit: Another possible way would be to change the jmp assembly to my C++ function, then call
TryOpenPipboy from my function. That would mean
TryOpenPipboy is still called, but is unmodified, increasing potential compatibility.
So how should I go about doing this?