Still a lot more to do but pushing WIP to not have it wasted if more commits come in from others. Also got rid of some global variables.
This is the code from the 'gimp-2.9' branch of the plug-in, integrated into GIMP's build system.