BG3ModManager icon indicating copy to clipboard operation
BG3ModManager copied to clipboard

[Question] How is the mod's meta data parsing done?

Open ManHinnn0509 opened this issue 2 years ago • 4 comments

Hi, first of all thank you for this amazing tools. I have a MacBook and I want to run the game on it but with mods too. I know that the mod manager only supports Windows so I have an idea of making a Python script for that.

I think I have a brief understanding of the progress, read all the .pak files in order, parse the meta.lsx or meta.lsf to get the mod's info, then write it to modsetting.xml

But how is the parsing meta.lsx or meta.lsf part done? I didn't learn C# so I couldn't really understand much from reading the source code (I looked at DivinityModDataLoader.cs)

Looking for a detailed explanation on that, thanks!

ManHinnn0509 avatar Aug 30 '23 13:08 ManHinnn0509

Hi. Basically the mod manager uses lslib to open/read the .pak file, then it looks for a meta.lsx file in the Mods folder within the pak. If that exists, it then parses it like an xml file (since it basically is), and looks to get the attributes out of root/children/ModuleInfo.

For a python script, the tricky part would be reading the pak so you can get to the meta.lsx, since the actual reading of the xml file itself is pretty straightforward.

You may want to ask over at the lslib repo, and here's some links to the related classes:

PackageReader.cs LSPKHeader16 BinUtils

BG3 uses this v16 package format.

LaughingLeader avatar Aug 31 '23 02:08 LaughingLeader

Thank you for the quick response, by "using lslib" do you mean using codes from it? Or calling it via CLI?

Because I have an idea where maybe I don't have to deal with reading .pak and parse them from binary, I can try to unpack a single file from them (meta.lsx) as temp file then get their data & info via CLI commands using divine.exe However I found CLI command might have some bugs and it doesnt work, currently waiting for the author's response

ManHinnn0509 avatar Aug 31 '23 14:08 ManHinnn0509

by "using lslib" do you mean using codes from it? Or calling it via CLI?

lslib is a C# .NET framework library, so the mod manager uses the code directly. Not sure if it would work on Mac. It definitely wouldn't work inherently at least, since .NET Framework isn't cross-platform, but I imagine the package-specific code could probably work in a Net 6/7 library with some tweaks, which would be cross-platform.

LaughingLeader avatar Aug 31 '23 18:08 LaughingLeader

I see, thank you info. I will try and see if lslib works on Linux/Mac. Worst case I might actually need to deal with the binaries and parse them into Python classes 😭 Something totally new to me and it sounds challenging, I will give it a try.

ManHinnn0509 avatar Sep 01 '23 07:09 ManHinnn0509