Ah OK, I have been out of the loop with WiiU stuff for a while, so I did not know any of that... well, that makes things difficult
WIT's DOLPATCH command can also be used to add new Text and Data sections to the dol, to add the codehandler and .gct file (which is what I used when making
this a while ago), rather than trying to overwrite unusued space already inside the dol.
And yeah, I discovered that the WSTRT tool inside of WIimm's SZS Toolset has an "--add-section" option to it's PATCH command, specifically for easily adding .gct files to .dol files only a few days ago, when I first researched solutions to OP's specific request here. So for this script, I just had to unpack the iso, use that feature in WSTRT then repack, which was much less work for me than using WIT's DOLPATCH command
So, in this case AFAIK, WSTRT adds the codehandler to the end of the .dol as a new Text section, to be loaded to RAM address 0x80001800, along with the .gct file as a Data section, then patches the .dol to hook the codehandler into the game. I think it uses the VI hooktype by default.
As for the that code, I tried
this code, made my MrBean35000vr. The Code is already a few compiled ASM routines, but in Gecko Ocarina Code form. I just had to omit the Gecko-specific stuff, recalculate a few Branch commands to point to where I placed the code in RAM, then add them as new sections to the .dol manually using WIT's DOLPATCH command. But loading it in dolphin failed wth a softlock; It looks like dolphin failed/refused to load this manually-patched .dol, since my memory viewer displaying all 00s in RAM where the dol should have been.
Thanks, and you too man, looking at the forums, I see you are still helping users here.
As for me, I sometimes lurk, but hardly log in, usually just too busy with life. But OP's rather interesting and specific request here really caught my attention