I'm enjoying the feedback so far and am popping in as much as I can briefly.
As I've mentioned several times, I'm a bit too busy at the moment to work on the script. If anyone is interested in further improving this script, here are some hints as to what needs to be fixed. Please post new versions in this thread for people to use or post pieces of code that can be substituted.
The alpha layers (lighting layers that use Linear Dodge blending, type = 0, id > 65536) are messed up. If you look at Palmer's output you will see that some of the them have multiple files that come one after the other (only adding 1 to the filename), e.g. 65536 and then 65537 and 65538. If Palmer only adds 1 to the filename, these files are all considered to be a group, so they work together to make a single layer or image. When I outputted the images, I thought the baselayer (the 65536 one) could just be output as the composite of all the layers on top of one another (like you can do with the background). From what I've seen in game, this is wrong. You must cut the baselayer out like you must cut out other layers or it will actually shine through, causing the lighting artifacts. So, my cutting algorithm needs to simply be applied to the alpha baselayers in addition to the forelayers.
If that makes sense to anyone with some technical know-how, you can fix the problem in the meantime. If not, you guys will have to wait until I get a chunk of time on my hands, which will be weeks.