- Notifications
You must be signed in to change notification settings - Fork4
Library to manipulate AFS files
License
MaikelChan/AFSLib
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
AFSLib is a library that can extract, create and manipulate AFS files. The AFS format is used in many games from companies like Sega. Even though it's a simple format, there are lots of quirks and edge cases in many games that require implementing specific fixes or workarounds for the library to work with them. If you encounter any issue with a specific game, don't hesitate to report it.
For a usage example, you can checkAFSPacker, a simple command line tool that uses AFSLib to extract and create AFS files.
In order to use this examples, make sure you are using AFSLib.
usingAFSLib;
// Create a new AFS object.using(AFSafs=newAFS()){// Add two files. The first parameter is the path to the file.// By default, an entry will be created with the same name as the file.// But you can also set a different entry name with the second parameter.afs.AddEntryFromFile(@"C:\Data\Files\MyTextFile.txt");afs.AddEntryFromFile(@"C:\Data\Files\MyImageFile.png","Title.png");// Finally save the AFS archive to the specified file.afs.SaveToFile(@"C:\Data\MyArchive.afs");}
// Create a new AFS object.using(AFSafs=newAFS()){// Add all the files located in the directory C:\Data\Files.afs.AddEntriesFromDirectory(@"C:\Data\Files");// Finally save the AFS archive to the specified file.afs.SaveToFile(@"C:\Data\MyArchive.afs");}
// Create an AFS object out of an existing AFS archive.using(AFSafs=newAFS(@"C:\Data\MyArchive.afs")){// Extract all the entries to the specified directory.afs.ExtractAllEntriesToDirectory(@"C:\Data\Files");}
// Create an AFS object out of an existing AFS archive.using(AFSafs=newAFS(@"C:\Data\MyArchive.afs")){// To change some properties, first we need to be sure that we// are trying to change an entry with data, and not a null entry.// So cast to DataEntry, which is the parent class of all entries// that can contain data.DataEntrydataEntry=afs.Entries[0]asDataEntry;if(dataEntry!=null){// It seems that it's indeed an entry with data,// so let's change some stuff.dataEntry.Name="NewFileName.txt";dataEntry.LastWriteTime=DateTime.Now;}// Save again with a different name.afs.SaveToFile(@"C:\Data\MyNewArchive.afs");}
There are many variants of the AFS format found in many games. Some of those games may require to have a specific variant of AFS archive. There are several modifiable properties that allow to customize the archive so it matches what the game needs. To know what values are needed, read them from one of the AFS archives found in the game.
// Some variables to store the propertiesHeaderMagicTypeheader;AttributesInfoTypeattributesInfo;uintentryBlockAlignment;// Create an AFS object out of an existing AFS archive.using(AFSafs=newAFS(@"C:\Data\MyArchive.afs")){// Read and store some propertiesheader=afs.HeaderMagicType;attributesInfo=afs.AttributesInfoType;entryBlockAlignment=afs.EntryBlockAlignment;}// Create a new AFS object.using(AFSafs=newAFS()){// Set the same properties to the new fileafs.HeaderMagicType=header;afs.AttributesInfoType=attributesInfo;afs.EntryBlockAlignment=entryBlockAlignment;// Add some filesafs.AddEntriesFromDirectory(@"C:\Data\Files");// Finally save the AFS archive to the specified file.afs.SaveToFile(@"C:\Data\MyArchive.afs");}
// Create an AFS object out of an existing AFS archive.using(AFSafs=newAFS(@"C:\Data\MyArchive.afs")){// Subscribe to the event so the extraction process will send info about its progress// and can be printed with the method Afs_NotifyProgress.afs.NotifyProgress+=Afs_NotifyProgress;// Extract all the entries to the specified directory.afs.ExtractAllEntriesToDirectory(@"C:\Data\Files");}staticvoidAfs_NotifyProgress(NotificationTypetype,stringmessage){Console.WriteLine($"[{type}] -{message}");}
About
Library to manipulate AFS files