ASM patching with Event Assembler

Here’s an ugly macro that took forever to write:
#define BLRange(pointer) "(pointer - CURRENTOFFSET - 4)>>1"
#define BL(pointer) "SHORT (((BLRange(pointer)>>11)&0x7ff)|0xf000) ((BLRange(pointer)&0x7ff)|0xf800);"

And here’s how you use it:

ORG (hook location)
BL(Hack_start)
...
ORG (other hook location)
BL(Other_hack_start)
...
ORG (hack location)
Hack_start:
#incbin "myhack.dmp"
Other_hack_start:
#incbin "otherhack.dmp"

Also you need to edit \Language Raws\Raw code.txt - make a copy of the BYTE code and rename it CODE. This is because the later versions of EA broke the #incbin function.

No longer do you have to keep track of where each ASM hack starts and ends, or keep updating the bl calls every single time you add a few lines of code. I just made my life 100x easier with a single line :smiley:

what do you mean no one else has this problem?

2 Likes

Oh cool I was gonna delve into the actual C# code and fix it hardociding the use of the CODE function. Nice, this saves a craaaaaaaaapton of work and I’ll be sure to package it with any future release of EA Std Lib.

I assume it’ll toss an error if the hook is out of BL range?

I don’t know how to toss an error using macros, and even making a new command just seems to ignore the top bits if the number is too large. Maybe just outputting a MESSAGE?

I know there’s an ifthenelse macro but idk if that’s metaprogramming or just eventing.

Yeah if you could put a define inside a macro that would be great but sadly it doesn’t work.

No, I mean, you can put macros into macros. and there’s an ifelse macro somewhere I saw. But I’ll let you know when I look at it.