Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Library to manipulate AFS files

License

NotificationsYou must be signed in to change notification settings

MaikelChan/AFSLib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub release (latest SemVer)NugetGitHub commits since latest release (by SemVer)GitHub

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.

Usage examples

In order to use this examples, make sure you are using AFSLib.

usingAFSLib;

Create an AFS archive from scratch with some files

// 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 an AFS archive out of all the files inside a directory

// 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");}

Extract all the entries from an existing AFS archive

// 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");}

Change some entries properties and save them in another AFS archive

// 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");}

Advanced AFS creation

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");}

Get and print progress information

// 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}");}

[8]ページ先頭

©2009-2025 Movatter.jp