Hmm, it does seem like I'll have to rethink my approach to this. FF7 seems to look for some files using two names, presumably one is used for the lookup table, while the other is the actual filename from the TOC.
Unfortunately this means that some of the original information was lost in the conversion to lgp archives, since there's no way to figure out which name is actually used to access a file, save for the first two characters used in the lookup table (and even then you have a conflict between k/l and _/-).
Expect a new version up soon that will handle this properly. For now, don't try to repack magic.lgp (field, char, battle and menu should work fine, the others I have not tested)
Turns out my function for computing lookup values was still a bit off, numbers and periods were not handled properly. With that fixed, my previous theory about the lookup table still holds, the two first characters of the filename are used to find the file, nothing else. Unfortunately, that leaves the duplicate filenames mystery without a reasonable explanation. If only the filename is used to to find them, FF7 will simply open whichever file comes first in the TOC, leaving the other file inaccessible.
Good news everyone!TM
LGP files that do have subfolders provide a neat table of what goes where
Give me some time with this and soon enough these tools will be able to create/extract any kind of LGPs
Okay so it doesn't say exactly what goes where, it only specifies the folder name whenever there's a name conflict. Still, it's enough to (re)create a 1:1 copy of any existing LGP just from filesystem data.
Only magic.lgp has name conflicts and the unlgp tool can now handle that properly, while the lgp tool is still missing some things. I also kind-of figured out what the last unknown means (unknown 2 & 3 is the offset into the conflict table), it's only ever 11 or 14, where 11 means it's a text file and 14 means it's a binary file. The game does not care about this field however, so just setting it to 14 for everything is fine.