First of all, thanks for using my toolchain!
PangLib.IFF works like this:
Using the filename,
PangLib.IFF tries to figure out what data model to use. If it can’t find a model matching the filename, it will return “Unknown”. If you want to add a new model, you need to add it to the list of models in the
IFFFile.cs file as well.
- If the IFF file given is not a ZIP file (the root IFF file in Pangya
data/ is a ZIP file),
PangLib.IFF will proceed to read information like the record count, and record length (
record length = (file length - 8L) / record count)
- Now to the core, the
- First, we get sure that the type of the file is not “Unknown” and the file is not a ZIP file
- We then check for the magic number being in place (by now I’ve found out that this is the IFF file version)
- Now, we loop through all available records. Jumping to the starting position of a record using the
JumpToRecord method. Here we read
RecordLength bytes. Next thing we do is get an instance of the C# type of the data model our file matches to, for
Ball.iff we get the C# type
PangLib.IFF.DataModels.Ball (the Ball structure). Using C# marshalling, we then map the read bytes to the structure (basically a shorter way instead of setting everything manually). Once that is done, we put the filled-in data set into the
Entries property of the
If you want to add more IFF file types to get parsed, you need to do the following:
- Create a file with the name of the structure you want to add in
DataModels/ and follow the namespace convention of the other files. Inside that file, only define a structure for the model with the same name as the model file
public struct Ball.
- Once you added the file and added all the parseable fields to it, you need to add the name of the type to the “DataModels” list in the
IFFFile class, this ensures that if you create an instance of the IFF file using
IFFFile IFF = new IFFFile("Part.iff") the resulting type will not be “Unknown”.
- If everything was done properly, the file should be parsed and the entries should be found in the
Speaking of that, as I recently found out that the
int32 present at byte 4, which I previously assumed was just a “magic number” (a lot of people talked about it that way), is actually a version. This is prevalent when you try to parse a Pangya JP Season 8 file using
PangLib.IFF, which doesn’t work, because the common structure (the first few fields like name, level, etc.) have changed. So I need to add version specific IFF file structures to the whole library as well.
I also want to refactor the library as a whole and instead of having the library “guess” what type the file has, have the user specifically choose it, I imagined something like turning the library generic, so
IFFFile IFF = new IFFFile("Ball.iff");
would turn into something like
IFFFile<Ball> BallIFF = new IFFFile<Ball>("Ball.iff");
where the developer has to pass in the
DataModel, so unclear stuff like using the
List<object> Entries can use the actual type and developers don’t have to cast data before being able to use it properly.
Also, as noted in the README, you currently cannot save back IFF changes into files, but as part of the refactor, I’m working on this!