├── .gitignore ├── BARSReaderGUI.sln ├── BARSReaderGUI ├── AMTA.cs ├── AudioAsset.cs ├── BARSReaderGUI.csproj ├── Form1.Designer.cs ├── Form1.cs ├── Form1.resx ├── IDeobfuscator.cs ├── NativeReader.cs ├── Program.cs ├── Res │ └── BARSIcon.ico └── ZstdUtils.cs └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | -------------------------------------------------------------------------------- /BARSReaderGUI.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.4.33110.190 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BARSReaderGUI", "BARSReaderGUI\BARSReaderGUI.csproj", "{191770B1-32E7-444F-ADA0-D55A5BDFB9B5}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {191770B1-32E7-444F-ADA0-D55A5BDFB9B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {191770B1-32E7-444F-ADA0-D55A5BDFB9B5}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {191770B1-32E7-444F-ADA0-D55A5BDFB9B5}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {191770B1-32E7-444F-ADA0-D55A5BDFB9B5}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {C7F8259B-B350-4184-9CDD-DDDA3882104B} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /BARSReaderGUI/AMTA.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace BARSReaderGUI 8 | { 9 | public enum AMTAVersion : ushort 10 | { 11 | V1 = 0x0100, 12 | V3 = 0x0300, 13 | V4 = 0x0400, 14 | V5 = 0x0500 15 | } 16 | public class AMTA //Audio Metadata 17 | { 18 | public string magic; 19 | public ushort endian; 20 | public ushort version; 21 | public int size; 22 | public byte channelCount; 23 | public string assetName; 24 | public AMTADATAV4 amtaDataV4 = new AMTADATAV4(); 25 | public AMTAMARKV4 amtaMarkV4 = new AMTAMARKV4(); 26 | public AMTAEXTV4 amtaExtV4 = new AMTAEXTV4(); 27 | public AMTASTRGV4 amtaStrgV4 = new AMTASTRGV4(); 28 | 29 | public void ReadAMTA(long startPosition, NativeReader reader) 30 | { 31 | reader.Position = startPosition; 32 | magic = reader.ReadSizedString(4); 33 | endian = reader.ReadUShort(); 34 | version = reader.ReadUShort(); 35 | size = reader.ReadInt(); 36 | 37 | switch ((AMTAVersion)version) 38 | { 39 | case AMTAVersion.V4: 40 | { 41 | ReadAMTAV4(startPosition, reader); 42 | } 43 | break; 44 | case AMTAVersion.V5: 45 | { 46 | ReadAMTAV5(reader.Position, reader); 47 | } 48 | break; 49 | default: 50 | MessageBox.Show("Unsupported AMTA version."); 51 | return; 52 | } 53 | } 54 | 55 | #region V4 56 | #region Classes 57 | public class AMTADATAV4 58 | { 59 | public string identifer; 60 | public uint sectionsize; 61 | public uint nameoffset; 62 | public uint unk1; 63 | public byte type; 64 | public byte channelcount; 65 | public byte usedstreamcount; 66 | public byte flags; //xxAx xBCC || A = 0 = BFWAV/BFSTP, 1 = BWAV || B = looping || C = Unknown, 2 for stream, 3 for prefetch stream 67 | public float volume; 68 | public uint samplerate; 69 | 70 | public AMTALoopInfo loopInfo = new AMTALoopInfo(); 71 | public class AMTALoopInfo 72 | { 73 | public uint loopstartsample; 74 | public uint loopendsample; 75 | } 76 | public float loudness; 77 | 78 | public List streamTracks = new List(); 79 | public class AMTAStreamTrack //theres 8 of these i think? 80 | { 81 | public uint channelcount; 82 | public float volume; 83 | } 84 | public float peakamplitude; 85 | public string name; 86 | } 87 | public class AMTAMARKV4 88 | { 89 | public string identifier; 90 | public uint sectionsize; 91 | public uint entrycount; 92 | 93 | public List markers = new List(); 94 | public class AMTAMarker 95 | { 96 | public uint id; 97 | public uint nameoffset; 98 | public uint startpos; 99 | public uint length; //one doc page says this is unknown 100 | public string name; 101 | } 102 | } 103 | public class AMTAEXTV4 104 | { 105 | public string identifier; 106 | public uint sectionsize; 107 | public uint entrycount; 108 | public List extentries = new List(); 109 | public class AMTAEXTEntry 110 | { 111 | public uint unk1; //one doc page says this is a string offset 112 | public uint unk2; 113 | } 114 | } 115 | public class AMTASTRGV4 116 | { 117 | public string identifier; 118 | public uint sectionsize; 119 | //null terminated strings, all entries are linked to via offsets that are relative to the end of the section header(strgoffset +8) 120 | } 121 | #endregion 122 | public void ReadAMTAV4(long startPosition, NativeReader reader) 123 | { 124 | uint dataoffset = reader.ReadUInt(); 125 | uint markoffset = reader.ReadUInt(); 126 | uint extoffset = reader.ReadUInt(); 127 | uint strgoffset = reader.ReadUInt(); 128 | ReadAMTADATAV4(startPosition, dataoffset, strgoffset, reader); 129 | ReadAMTAMARKV4(startPosition, markoffset, strgoffset, reader); 130 | ReadAMTAEXTV4(startPosition, extoffset, reader); 131 | //ReadAMTASTRGV4(startPosition, strgoffset, reader); 132 | assetName = amtaDataV4.name; 133 | } 134 | public void ReadAMTADATAV4(long startPosition, long dataoffset, uint strgoffset, NativeReader reader) 135 | { 136 | reader.Position = startPosition + dataoffset; 137 | amtaDataV4.identifer = reader.ReadSizedString(4); 138 | amtaDataV4.sectionsize = reader.ReadUInt(); 139 | amtaDataV4.nameoffset = reader.ReadUInt(); 140 | amtaDataV4.unk1 = reader.ReadUInt(); 141 | amtaDataV4.type = reader.ReadByte(); 142 | amtaDataV4.channelcount = reader.ReadByte(); 143 | amtaDataV4.usedstreamcount = reader.ReadByte(); 144 | amtaDataV4.flags = reader.ReadByte(); 145 | amtaDataV4.volume = reader.ReadFloat(); 146 | amtaDataV4.samplerate = reader.ReadUInt(); 147 | amtaDataV4.loopInfo.loopstartsample = reader.ReadUInt(); 148 | amtaDataV4.loopInfo.loopendsample = reader.ReadUInt(); 149 | amtaDataV4.loudness = reader.ReadFloat(); 150 | for (int i = 0; i < 7; i++) 151 | { 152 | amtaDataV4.streamTracks.Add(new AMTADATAV4.AMTAStreamTrack()); 153 | amtaDataV4.streamTracks[i].channelcount = reader.ReadUInt(); 154 | amtaDataV4.streamTracks[i].volume = reader.ReadFloat(); 155 | } 156 | 157 | amtaDataV4.peakamplitude = reader.ReadFloat(); 158 | reader.Position = startPosition + strgoffset + 8; 159 | amtaDataV4.name = reader.ReadNullTerminatedString(); 160 | } 161 | 162 | public void ReadAMTAMARKV4(long startPosition, long markoffset, uint strgoffset, NativeReader reader) 163 | { 164 | reader.Position = startPosition + markoffset; 165 | long returnpos; 166 | amtaMarkV4.identifier = reader.ReadSizedString(4); 167 | amtaMarkV4.sectionsize = reader.ReadUInt(); 168 | amtaMarkV4.entrycount = reader.ReadUInt(); 169 | for (int i = 0; i < amtaMarkV4.entrycount; i++) 170 | { 171 | amtaMarkV4.markers.Add(new AMTAMARKV4.AMTAMarker()); 172 | amtaMarkV4.markers[i].id = reader.ReadUInt(); 173 | amtaMarkV4.markers[i].nameoffset = reader.ReadUInt(); 174 | amtaMarkV4.markers[i].startpos = reader.ReadUInt(); 175 | amtaMarkV4.markers[i].length = reader.ReadUInt(); 176 | returnpos = reader.Position; 177 | reader.Position = startPosition + strgoffset + 8 + amtaMarkV4.markers[i].nameoffset; 178 | amtaMarkV4.markers[i].name = reader.ReadNullTerminatedString(); 179 | reader.Position = returnpos; 180 | } 181 | } 182 | 183 | public void ReadAMTAEXTV4(long startPosition, long extoffset, NativeReader reader) 184 | { 185 | reader.Position = startPosition + extoffset; 186 | amtaExtV4.identifier = reader.ReadSizedString(4); 187 | amtaExtV4.sectionsize = reader.ReadUInt(); 188 | amtaExtV4.entrycount = reader.ReadUInt(); 189 | for (int i = 0; i < amtaExtV4.entrycount; i++) 190 | { 191 | amtaExtV4.extentries.Add(new AMTAEXTV4.AMTAEXTEntry()); 192 | amtaExtV4.extentries[i].unk1 = reader.ReadUInt(); 193 | amtaExtV4.extentries[i].unk2 = reader.ReadUInt(); 194 | } 195 | } 196 | 197 | public void ReadAMTASTRGV4(long startPosition, long strgoffset, NativeReader reader) 198 | { 199 | reader.Position = startPosition + strgoffset; 200 | reader.ReadSizedString(4); 201 | } 202 | #endregion 203 | 204 | #region V5 205 | public void ReadAMTAV5(long startPosition, NativeReader reader) 206 | { 207 | uint unk1 = reader.ReadUInt(); 208 | uint unk2 = reader.ReadUInt(); //observed 0x34 or 0x38 209 | uint unk3 = reader.ReadUInt(); 210 | uint unk4 = reader.ReadUInt(); 211 | uint unk5 = reader.ReadUInt(); 212 | uint unk6 = reader.ReadUInt(); 213 | ReadAMTADATAV5(reader.Position, reader); 214 | assetName = reader.ReadNullTerminatedString(); 215 | } 216 | public void ReadAMTADATAV5(long startPosition, NativeReader reader) 217 | { 218 | uint datasize = reader.ReadUInt(); 219 | uint namehash = reader.ReadUInt(); //same as asset name hash 220 | uint unk1 = reader.ReadUInt(); 221 | byte unk2 = reader.ReadByte(); 222 | channelCount = reader.ReadByte(); 223 | reader.Position = startPosition + datasize; //return to start pos and use the size to skip over the rest of the section 224 | } 225 | 226 | //public class MINF //Music Info 227 | //{ 228 | // public string magic; //always MINF 229 | // public ushort endian; 230 | // public ushort version; 231 | // public uint size; 232 | //} 233 | } 234 | #endregion 235 | } 236 | -------------------------------------------------------------------------------- /BARSReaderGUI/AudioAsset.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace BARSReaderGUI 8 | { 9 | public class AudioAsset 10 | { 11 | public uint crcHash; 12 | public uint amtaOffset; 13 | public uint assetOffset; 14 | public string assetName; 15 | public string assetType; 16 | public bool isPrefetch = false; 17 | public byte[] assetData; 18 | public byte[] amtaAssetData; 19 | public AMTA amtaData = new AMTA(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /BARSReaderGUI/BARSReaderGUI.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | WinExe 5 | net6.0-windows 6 | enable 7 | true 8 | enable 9 | True 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | ..\lib\ZstdNet.dll 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /BARSReaderGUI/Form1.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace BARSReaderGUI 2 | { 3 | partial class Form1 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); 32 | menuStrip1 = new MenuStrip(); 33 | fileToolStripMenuItem = new ToolStripMenuItem(); 34 | openToolStripMenuItem = new ToolStripMenuItem(); 35 | groupBox1 = new GroupBox(); 36 | AssetListBox = new ListBox(); 37 | groupBox2 = new GroupBox(); 38 | extractAllButton = new Button(); 39 | AudioAssetIsPrefetchLabel = new Label(); 40 | label5 = new Label(); 41 | extractMetaButton = new Button(); 42 | extractAudioButton = new Button(); 43 | AudioAssetBwavOffsetLabel = new Label(); 44 | label4 = new Label(); 45 | AudioAssetAmtaOffsetLabel = new Label(); 46 | label3 = new Label(); 47 | AudioAssetCrc32HashLabel = new Label(); 48 | label2 = new Label(); 49 | AudioAssetNameLabel = new Label(); 50 | label1 = new Label(); 51 | batchExtractToolStripMenuItem = new ToolStripMenuItem(); 52 | menuStrip1.SuspendLayout(); 53 | groupBox1.SuspendLayout(); 54 | groupBox2.SuspendLayout(); 55 | SuspendLayout(); 56 | // 57 | // menuStrip1 58 | // 59 | menuStrip1.ImageScalingSize = new Size(32, 32); 60 | menuStrip1.Items.AddRange(new ToolStripItem[] { fileToolStripMenuItem }); 61 | menuStrip1.Location = new Point(0, 0); 62 | menuStrip1.Name = "menuStrip1"; 63 | menuStrip1.Padding = new Padding(3, 1, 0, 1); 64 | menuStrip1.Size = new Size(605, 26); 65 | menuStrip1.TabIndex = 0; 66 | menuStrip1.Text = "menuStrip1"; 67 | // 68 | // fileToolStripMenuItem 69 | // 70 | fileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { openToolStripMenuItem, batchExtractToolStripMenuItem }); 71 | fileToolStripMenuItem.Name = "fileToolStripMenuItem"; 72 | fileToolStripMenuItem.Size = new Size(46, 24); 73 | fileToolStripMenuItem.Text = "File"; 74 | // 75 | // openToolStripMenuItem 76 | // 77 | openToolStripMenuItem.Name = "openToolStripMenuItem"; 78 | openToolStripMenuItem.Size = new Size(224, 26); 79 | openToolStripMenuItem.Text = "Open..."; 80 | openToolStripMenuItem.Click += openToolStripMenuItem_Click; 81 | // 82 | // groupBox1 83 | // 84 | groupBox1.Controls.Add(AssetListBox); 85 | groupBox1.Dock = DockStyle.Left; 86 | groupBox1.Location = new Point(0, 26); 87 | groupBox1.Margin = new Padding(2, 1, 2, 1); 88 | groupBox1.Name = "groupBox1"; 89 | groupBox1.Padding = new Padding(2, 1, 2, 1); 90 | groupBox1.Size = new Size(354, 402); 91 | groupBox1.TabIndex = 1; 92 | groupBox1.TabStop = false; 93 | groupBox1.Text = "Assets"; 94 | // 95 | // AssetListBox 96 | // 97 | AssetListBox.Dock = DockStyle.Fill; 98 | AssetListBox.FormattingEnabled = true; 99 | AssetListBox.ItemHeight = 20; 100 | AssetListBox.Location = new Point(2, 21); 101 | AssetListBox.Margin = new Padding(2, 1, 2, 1); 102 | AssetListBox.Name = "AssetListBox"; 103 | AssetListBox.Size = new Size(350, 380); 104 | AssetListBox.TabIndex = 0; 105 | AssetListBox.SelectedIndexChanged += AssetListBox_SelectedIndexChanged; 106 | // 107 | // groupBox2 108 | // 109 | groupBox2.Controls.Add(extractAllButton); 110 | groupBox2.Controls.Add(AudioAssetIsPrefetchLabel); 111 | groupBox2.Controls.Add(label5); 112 | groupBox2.Controls.Add(extractMetaButton); 113 | groupBox2.Controls.Add(extractAudioButton); 114 | groupBox2.Controls.Add(AudioAssetBwavOffsetLabel); 115 | groupBox2.Controls.Add(label4); 116 | groupBox2.Controls.Add(AudioAssetAmtaOffsetLabel); 117 | groupBox2.Controls.Add(label3); 118 | groupBox2.Controls.Add(AudioAssetCrc32HashLabel); 119 | groupBox2.Controls.Add(label2); 120 | groupBox2.Controls.Add(AudioAssetNameLabel); 121 | groupBox2.Controls.Add(label1); 122 | groupBox2.Dock = DockStyle.Right; 123 | groupBox2.Location = new Point(359, 26); 124 | groupBox2.Margin = new Padding(2, 1, 2, 1); 125 | groupBox2.Name = "groupBox2"; 126 | groupBox2.Padding = new Padding(2, 1, 2, 1); 127 | groupBox2.Size = new Size(246, 402); 128 | groupBox2.TabIndex = 2; 129 | groupBox2.TabStop = false; 130 | groupBox2.Text = "Asset Info"; 131 | // 132 | // extractAllButton 133 | // 134 | extractAllButton.Enabled = false; 135 | extractAllButton.Location = new Point(5, 352); 136 | extractAllButton.Margin = new Padding(2, 1, 2, 1); 137 | extractAllButton.Name = "extractAllButton"; 138 | extractAllButton.Size = new Size(237, 29); 139 | extractAllButton.TabIndex = 12; 140 | extractAllButton.Text = "Extract All Audio"; 141 | extractAllButton.UseVisualStyleBackColor = true; 142 | extractAllButton.Click += extractAllButton_Click; 143 | // 144 | // AudioAssetIsPrefetchLabel 145 | // 146 | AudioAssetIsPrefetchLabel.AutoSize = true; 147 | AudioAssetIsPrefetchLabel.Location = new Point(3, 201); 148 | AudioAssetIsPrefetchLabel.Name = "AudioAssetIsPrefetchLabel"; 149 | AudioAssetIsPrefetchLabel.Size = new Size(74, 20); 150 | AudioAssetIsPrefetchLabel.TabIndex = 11; 151 | AudioAssetIsPrefetchLabel.Text = "isprefetch"; 152 | // 153 | // label5 154 | // 155 | label5.AutoSize = true; 156 | label5.Location = new Point(3, 181); 157 | label5.Name = "label5"; 158 | label5.Size = new Size(73, 20); 159 | label5.TabIndex = 10; 160 | label5.Text = "IsPrefetch"; 161 | // 162 | // extractMetaButton 163 | // 164 | extractMetaButton.Enabled = false; 165 | extractMetaButton.Location = new Point(5, 288); 166 | extractMetaButton.Margin = new Padding(2, 1, 2, 1); 167 | extractMetaButton.Name = "extractMetaButton"; 168 | extractMetaButton.Size = new Size(237, 29); 169 | extractMetaButton.TabIndex = 9; 170 | extractMetaButton.Text = "Extract Meta"; 171 | extractMetaButton.UseVisualStyleBackColor = true; 172 | extractMetaButton.Click += extractMetaButton_Click; 173 | // 174 | // extractAudioButton 175 | // 176 | extractAudioButton.Enabled = false; 177 | extractAudioButton.Location = new Point(5, 320); 178 | extractAudioButton.Margin = new Padding(2, 1, 2, 1); 179 | extractAudioButton.Name = "extractAudioButton"; 180 | extractAudioButton.Size = new Size(237, 29); 181 | extractAudioButton.TabIndex = 8; 182 | extractAudioButton.Text = "Extract Audio"; 183 | extractAudioButton.UseVisualStyleBackColor = true; 184 | extractAudioButton.Click += extractAudioButton_Click; 185 | // 186 | // AudioAssetBwavOffsetLabel 187 | // 188 | AudioAssetBwavOffsetLabel.AutoSize = true; 189 | AudioAssetBwavOffsetLabel.Location = new Point(3, 161); 190 | AudioAssetBwavOffsetLabel.Margin = new Padding(2, 0, 2, 0); 191 | AudioAssetBwavOffsetLabel.Name = "AudioAssetBwavOffsetLabel"; 192 | AudioAssetBwavOffsetLabel.Size = new Size(82, 20); 193 | AudioAssetBwavOffsetLabel.TabIndex = 7; 194 | AudioAssetBwavOffsetLabel.Text = "assetOffset"; 195 | // 196 | // label4 197 | // 198 | label4.AutoSize = true; 199 | label4.Location = new Point(3, 141); 200 | label4.Margin = new Padding(2, 0, 2, 0); 201 | label4.Name = "label4"; 202 | label4.Size = new Size(88, 20); 203 | label4.TabIndex = 6; 204 | label4.Text = "Asset Offset"; 205 | // 206 | // AudioAssetAmtaOffsetLabel 207 | // 208 | AudioAssetAmtaOffsetLabel.AutoSize = true; 209 | AudioAssetAmtaOffsetLabel.Location = new Point(3, 121); 210 | AudioAssetAmtaOffsetLabel.Margin = new Padding(2, 0, 2, 0); 211 | AudioAssetAmtaOffsetLabel.Name = "AudioAssetAmtaOffsetLabel"; 212 | AudioAssetAmtaOffsetLabel.Size = new Size(83, 20); 213 | AudioAssetAmtaOffsetLabel.TabIndex = 5; 214 | AudioAssetAmtaOffsetLabel.Text = "amtaOffset"; 215 | // 216 | // label3 217 | // 218 | label3.AutoSize = true; 219 | label3.Location = new Point(3, 101); 220 | label3.Margin = new Padding(2, 0, 2, 0); 221 | label3.Name = "label3"; 222 | label3.Size = new Size(87, 20); 223 | label3.TabIndex = 4; 224 | label3.Text = "Meta Offset"; 225 | // 226 | // AudioAssetCrc32HashLabel 227 | // 228 | AudioAssetCrc32HashLabel.AutoSize = true; 229 | AudioAssetCrc32HashLabel.Location = new Point(3, 81); 230 | AudioAssetCrc32HashLabel.Margin = new Padding(2, 0, 2, 0); 231 | AudioAssetCrc32HashLabel.Name = "AudioAssetCrc32HashLabel"; 232 | AudioAssetCrc32HashLabel.Size = new Size(61, 20); 233 | AudioAssetCrc32HashLabel.TabIndex = 3; 234 | AudioAssetCrc32HashLabel.Text = "crcHash"; 235 | // 236 | // label2 237 | // 238 | label2.AutoSize = true; 239 | label2.Location = new Point(3, 61); 240 | label2.Margin = new Padding(2, 0, 2, 0); 241 | label2.Name = "label2"; 242 | label2.Size = new Size(86, 20); 243 | label2.TabIndex = 2; 244 | label2.Text = "Name Hash"; 245 | // 246 | // AudioAssetNameLabel 247 | // 248 | AudioAssetNameLabel.AutoSize = true; 249 | AudioAssetNameLabel.Location = new Point(3, 41); 250 | AudioAssetNameLabel.Margin = new Padding(2, 0, 2, 0); 251 | AudioAssetNameLabel.Name = "AudioAssetNameLabel"; 252 | AudioAssetNameLabel.Size = new Size(79, 20); 253 | AudioAssetNameLabel.TabIndex = 1; 254 | AudioAssetNameLabel.Text = "assetname"; 255 | // 256 | // label1 257 | // 258 | label1.AutoSize = true; 259 | label1.Location = new Point(3, 21); 260 | label1.Margin = new Padding(2, 0, 2, 0); 261 | label1.Name = "label1"; 262 | label1.Size = new Size(49, 20); 263 | label1.TabIndex = 0; 264 | label1.Text = "Name"; 265 | // 266 | // batchExtractToolStripMenuItem 267 | // 268 | batchExtractToolStripMenuItem.Name = "batchExtractToolStripMenuItem"; 269 | batchExtractToolStripMenuItem.Size = new Size(224, 26); 270 | batchExtractToolStripMenuItem.Text = "Batch Extract..."; 271 | batchExtractToolStripMenuItem.Click += BatchExtract_Click; 272 | // 273 | // Form1 274 | // 275 | AutoScaleDimensions = new SizeF(8F, 20F); 276 | AutoScaleMode = AutoScaleMode.Font; 277 | BackColor = SystemColors.Control; 278 | ClientSize = new Size(605, 428); 279 | Controls.Add(groupBox2); 280 | Controls.Add(groupBox1); 281 | Controls.Add(menuStrip1); 282 | FormBorderStyle = FormBorderStyle.FixedSingle; 283 | Icon = (Icon)resources.GetObject("$this.Icon"); 284 | MainMenuStrip = menuStrip1; 285 | Margin = new Padding(2, 1, 2, 1); 286 | MaximizeBox = false; 287 | Name = "Form1"; 288 | Text = "BARSReaderGUI"; 289 | menuStrip1.ResumeLayout(false); 290 | menuStrip1.PerformLayout(); 291 | groupBox1.ResumeLayout(false); 292 | groupBox2.ResumeLayout(false); 293 | groupBox2.PerformLayout(); 294 | ResumeLayout(false); 295 | PerformLayout(); 296 | } 297 | 298 | #endregion 299 | 300 | private MenuStrip menuStrip1; 301 | private ToolStripMenuItem fileToolStripMenuItem; 302 | private ToolStripMenuItem openToolStripMenuItem; 303 | private GroupBox groupBox1; 304 | private ListBox AssetListBox; 305 | private GroupBox groupBox2; 306 | private Label label2; 307 | private Label AudioAssetNameLabel; 308 | private Label label1; 309 | private Label AudioAssetCrc32HashLabel; 310 | private Label AudioAssetBwavOffsetLabel; 311 | private Label label4; 312 | private Label AudioAssetAmtaOffsetLabel; 313 | private Label label3; 314 | private Button extractAudioButton; 315 | private Button extractMetaButton; 316 | private Label AudioAssetIsPrefetchLabel; 317 | private Label label5; 318 | private Button extractAllButton; 319 | private ToolStripMenuItem batchExtractToolStripMenuItem; 320 | } 321 | } -------------------------------------------------------------------------------- /BARSReaderGUI/Form1.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Windows.Forms; 3 | 4 | namespace BARSReaderGUI 5 | { 6 | public partial class Form1 : Form 7 | { 8 | List audioAssets = new List(); 9 | // stores all of the names of the BWAVs in a BARS file 10 | // used when sorting to get the index of the actual sound 11 | List audioNames = new List(); 12 | 13 | public Form1() 14 | { 15 | InitializeComponent(); 16 | } 17 | 18 | private void openToolStripMenuItem_Click(object sender, EventArgs e) 19 | { 20 | OpenFileDialog fileDialog = new OpenFileDialog(); 21 | fileDialog.Filter = "BARS files (*.bars, *.bars.zs)|*.bars;*.bars.zs"; 22 | 23 | if (fileDialog.ShowDialog() == DialogResult.OK) 24 | { 25 | OpenFile(fileDialog.FileName); 26 | } 27 | } 28 | 29 | private void OpenFile(string inputFile, bool showMessages = true) 30 | { 31 | Stream fileStream; 32 | 33 | audioAssets.Clear(); 34 | audioNames.Clear(); 35 | AssetListBox.Items.Clear(); 36 | 37 | // Check for compression first. 38 | using (NativeReader reader = new(new FileStream(inputFile, FileMode.Open))) 39 | { 40 | if (reader.ReadUInt() == 0xFD2FB528) 41 | { 42 | ZstdUtils zstdUtils = new ZstdUtils(); 43 | reader.Position -= 4; 44 | fileStream = zstdUtils.Decompress(reader.BaseStream); // Stores decompressed data into stream 45 | } 46 | else 47 | { 48 | reader.Position -= 4; 49 | fileStream = new MemoryStream(reader.BaseStream.ToArray()); // If no compression is found, we store the original file data in the stream. 50 | } 51 | } 52 | 53 | // Read the file stored in the stream. 54 | using (NativeReader reader = new NativeReader(fileStream)) 55 | { 56 | // Check file magic. 57 | string magic = reader.ReadSizedString(4); 58 | if (magic != "BARS") 59 | { 60 | if (showMessages) 61 | MessageBox.Show("Not a BARS file."); 62 | return; 63 | } 64 | 65 | // Read file size. 66 | uint size = reader.ReadUInt(); 67 | 68 | // Read endianness from file. 69 | ushort endian = reader.ReadUShort(); 70 | if (endian != 0xFEFF) 71 | { 72 | if (showMessages) 73 | MessageBox.Show("Unsupported endian!"); 74 | return; 75 | } 76 | 77 | // Read version from the file. 78 | ushort version = reader.ReadUShort(); 79 | if (version != 0x0102 && version != 0x0101) 80 | { 81 | if (showMessages) 82 | MessageBox.Show("This version of BARS is unsupported at this time."); //throw this error on trying to read anything other than v1.1/1.2 83 | return; 84 | } 85 | 86 | uint assetcount = reader.ReadUInt(); 87 | //assets = new KeyValuePair[assetcount]; 88 | 89 | // Create audioAssets and tie crcHashes to them. 90 | for (int i = 0; i < assetcount; i++) 91 | { 92 | audioAssets.Add(new AudioAsset()); 93 | audioAssets[i].crcHash = reader.ReadUInt(); 94 | } 95 | 96 | // Pair ATMA/BWAV offsets with asset 97 | for (int i = 0; i < assetcount; i++) 98 | { 99 | audioAssets[i].amtaOffset = reader.ReadUInt(); 100 | audioAssets[i].assetOffset = reader.ReadUInt(); 101 | } 102 | 103 | // Read asset's amta data. 104 | for (int i = 0; i < assetcount; i++) 105 | { 106 | audioAssets[i].amtaData = new AMTA(); 107 | audioAssets[i].amtaData.ReadAMTA(audioAssets[i].amtaOffset, reader); 108 | } 109 | 110 | for (int i = 0; i < assetcount; i++) 111 | { 112 | reader.Position = audioAssets[i].amtaOffset; 113 | audioAssets[i].amtaAssetData = reader.ReadBytes(audioAssets[i].amtaData.size); 114 | } 115 | 116 | // Sort assets. 117 | audioAssets = SortAudioAssets(); 118 | 119 | // Reads audio assets. 120 | // TODO: Explain this particular section better. 121 | for (int i = 0; i < audioAssets.Count; i++) 122 | { 123 | reader.Position = audioAssets[i].assetOffset; 124 | 125 | audioAssets[i].assetType = reader.ReadSizedString(4); 126 | reader.Position -= 4; 127 | 128 | 129 | if (audioAssets[i].assetType != "BWAV") 130 | { 131 | //FSTPs are prefetch assets. 132 | if (audioAssets[i].assetType == "FSTP") 133 | audioAssets[i].isPrefetch = true; 134 | reader.Position += 0xC; 135 | int assetSize = reader.ReadInt(); 136 | reader.Position -= 0x10; 137 | 138 | audioAssets[i].assetData = reader.ReadBytes(assetSize); 139 | } 140 | else 141 | { 142 | //check if BWAV is a prefetch or not. 143 | reader.Position += 0xC; 144 | if (reader.ReadUShort() == 1) 145 | audioAssets[i].isPrefetch = true; 146 | reader.Position -= 0xE; 147 | 148 | // For BWAV assets, read data of the size of the next assset offset minus the current asset offset. 149 | if (i != audioAssets.Count - 1) 150 | audioAssets[i].assetData = reader.ReadBytes(Convert.ToInt32(audioAssets[i + 1].assetOffset - audioAssets[i].assetOffset)); 151 | else 152 | audioAssets[i].assetData = reader.ReadBytes(Convert.ToInt32(size - audioAssets[i].assetOffset)); 153 | } 154 | } 155 | 156 | 157 | // Adds all of the audio asset names to the main list box. 158 | if (showMessages) 159 | { 160 | for (int i = 0; i < audioAssets.Count; i++) 161 | { 162 | AssetListBox.Items.Add(audioAssets[i].amtaData.assetName); 163 | audioNames.Add(audioAssets[i].amtaData.assetName); 164 | } 165 | this.Text = $"BARSReaderGUI - {Path.GetFileName(inputFile)} - {assetcount} Assets"; 166 | MessageBox.Show("Successfully read " + assetcount + " assets."); 167 | extractAllButton.Enabled = true; 168 | } 169 | } 170 | } 171 | 172 | private void AssetListBox_SelectedIndexChanged(object sender, EventArgs e) 173 | { 174 | try 175 | { 176 | extractAudioButton.Enabled = true; 177 | extractMetaButton.Enabled = true; 178 | String sortedAssetName = AssetListBox.Items[AssetListBox.SelectedIndex].ToString() ?? audioAssets[0].amtaData.assetName; 179 | int index = audioNames.FindIndex(s => s.Contains(sortedAssetName)); 180 | AudioAssetNameLabel.Text = audioAssets[index].amtaData.assetName; 181 | AudioAssetCrc32HashLabel.Text = audioAssets[index].crcHash.ToString("X"); 182 | AudioAssetAmtaOffsetLabel.Text = audioAssets[index].amtaOffset.ToString("X"); 183 | AudioAssetBwavOffsetLabel.Text = audioAssets[index].assetOffset.ToString("X"); 184 | AudioAssetIsPrefetchLabel.Text = audioAssets[index].isPrefetch.ToString(); 185 | 186 | } 187 | catch (Exception ex) 188 | { 189 | extractAudioButton.Enabled = false; 190 | extractMetaButton.Enabled = false; 191 | extractAllButton.Enabled = false; 192 | } 193 | } 194 | 195 | private void extractAudioButton_Click(object sender, EventArgs e) 196 | { 197 | int index = AssetListBox.SelectedIndex; 198 | SaveFileDialog saveFileDialog = new SaveFileDialog(); 199 | 200 | switch (audioAssets[index].assetType) 201 | { 202 | case "BWAV": 203 | saveFileDialog.Filter = "BWAV files (*.bwav)|*.bwav"; 204 | break; 205 | case "FWAV": 206 | saveFileDialog.Filter = "BFWAV files (*.bfwav)|*.bfwav"; 207 | break; 208 | case "FSTP": 209 | saveFileDialog.Filter = "BFSTP files (*.bfstp)|*.bfstp"; 210 | break; 211 | default: 212 | break; 213 | }// Change this later to handle other audio formats 214 | 215 | saveFileDialog.Title = "Extract Audio"; 216 | saveFileDialog.FileName = audioAssets[AssetListBox.SelectedIndex].amtaData.assetName; 217 | saveFileDialog.RestoreDirectory = true; 218 | 219 | if (saveFileDialog.ShowDialog() == DialogResult.OK) 220 | { 221 | using var writer = new BinaryWriter(File.Create(saveFileDialog.FileName)); 222 | writer.Write(audioAssets[index].assetData); 223 | MessageBox.Show(audioAssets[index].amtaData.assetName + " extracted successfully."); 224 | } 225 | } 226 | 227 | private void extractMetaButton_Click(object sender, EventArgs e) 228 | { 229 | int index = AssetListBox.SelectedIndex; 230 | SaveFileDialog saveFileDialog = new SaveFileDialog(); 231 | saveFileDialog.Filter = "BAMETA files (*.bameta)|*.bameta"; 232 | saveFileDialog.Title = "Extract Meta"; 233 | saveFileDialog.FileName = audioAssets[AssetListBox.SelectedIndex].amtaData.assetName; 234 | saveFileDialog.RestoreDirectory = true; 235 | 236 | if (saveFileDialog.ShowDialog() == DialogResult.OK) 237 | { 238 | using var writer = new BinaryWriter(File.Create(saveFileDialog.FileName)); 239 | writer.Write(audioAssets[index].amtaAssetData); 240 | MessageBox.Show(audioAssets[index].amtaData.assetName + " extracted successfully."); 241 | } 242 | } 243 | 244 | // Sorts audio asssets by their asset offsets. 245 | private List SortAudioAssets() 246 | { 247 | List sortedAssets = new List(); 248 | // Iterate through all assets 249 | int oldAssetCount = audioAssets.Count; 250 | for (int i = 0; i < oldAssetCount; i++) 251 | { 252 | int lowestToSave = 0; 253 | 254 | for (int j = 0; j < audioAssets.Count; j++) 255 | { 256 | // Check if we reached the end. 257 | if (j == audioAssets.Count - 1) 258 | { 259 | // Make the saved index j if it is smaller than the current saved one. 260 | if (audioAssets[lowestToSave].assetOffset > audioAssets[j].assetOffset) 261 | lowestToSave = j; 262 | 263 | break; 264 | } 265 | 266 | // Check if the currently saved index is greater than at j + 1. Change the saved index to this if true. 267 | if (audioAssets[lowestToSave].assetOffset > audioAssets[j + 1].assetOffset) 268 | { 269 | lowestToSave = j + 1; 270 | } 271 | } 272 | 273 | // Add the currently saved index to the sorted list and remove it from the main list so we don't run into it again on future iterations. 274 | sortedAssets.Add(audioAssets[lowestToSave]); 275 | audioAssets.RemoveAt(lowestToSave); 276 | } 277 | return sortedAssets; 278 | } 279 | 280 | private void extractAllButton_Click(object sender, EventArgs e) 281 | { 282 | // Select export folder 283 | FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog(); 284 | folderBrowserDialog.RootFolder = Environment.SpecialFolder.Personal; 285 | 286 | if (folderBrowserDialog.ShowDialog() == DialogResult.OK) 287 | { 288 | int assetcount = 0; 289 | // Iterate through each entry and export. 290 | audioAssets.ForEach(asset => 291 | { 292 | String fileName = folderBrowserDialog.SelectedPath + "\\" + asset.amtaData.assetName + "." + asset.assetType; 293 | using var writer = new BinaryWriter(File.Create(fileName)); 294 | writer.Write(asset.assetData); 295 | assetcount++; 296 | }); 297 | 298 | MessageBox.Show("Successfully extracted " + assetcount + " sounds."); 299 | } 300 | } 301 | 302 | private void BatchExtract_Click(object sender, EventArgs e) 303 | { 304 | // Select import folder 305 | FolderBrowserDialog inputFolderBrowser = new FolderBrowserDialog(); 306 | inputFolderBrowser.Description = "Choose input folder"; 307 | inputFolderBrowser.UseDescriptionForTitle = true; 308 | inputFolderBrowser.RootFolder = Environment.SpecialFolder.Personal; 309 | 310 | // Select output folder 311 | FolderBrowserDialog outputFolderBrowser = new FolderBrowserDialog(); 312 | outputFolderBrowser.Description = "Choose output folder"; 313 | outputFolderBrowser.UseDescriptionForTitle = true; 314 | outputFolderBrowser.RootFolder = Environment.SpecialFolder.Personal; 315 | 316 | if (inputFolderBrowser.ShowDialog() == DialogResult.OK && outputFolderBrowser.ShowDialog() == DialogResult.OK) 317 | { 318 | int assetcount = 0; 319 | foreach (var file in Directory.GetFiles(inputFolderBrowser.SelectedPath, "*", 320 | SearchOption.AllDirectories).Where(x => x.ToLower().EndsWith("bars") || x.ToLower().EndsWith("bars.zs"))) 321 | { 322 | OpenFile(file, false); 323 | assetcount++; 324 | 325 | // Iterate through each entry and import. 326 | audioAssets.ForEach(asset => 327 | { 328 | string outDir = Path.Combine(outputFolderBrowser.SelectedPath, Path.GetFileNameWithoutExtension(file)); 329 | Directory.CreateDirectory(outDir); 330 | String fileName = outDir + "\\" + asset.amtaData.assetName + "." + asset.assetType; 331 | using var writer = new BinaryWriter(File.Create(fileName)); 332 | writer.Write(asset.assetData); 333 | }); 334 | } 335 | 336 | MessageBox.Show("Successfully extracted " + assetcount + " files."); 337 | } 338 | } 339 | } 340 | } -------------------------------------------------------------------------------- /BARSReaderGUI/Form1.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 17, 17 122 | 123 | 124 | 125 | 126 | AAABAAEAICAAAAEAIACoEAAAFgAAACgAAAAgAAAAQAAAAAEAIAAAAAAAABAAABMLAAATCwAAAAAAAAAA 127 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 128 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 129 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 130 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 131 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAA 195 | AAAAAAAAAAAAAAAAAAAAAAAA////////////////wAAA/4AAAH+AAAB/gAAAf4fgeA+HwBgHhAAIB4AA 196 | CAeAEAAHgBAAB4AQAAeAEAAHgAAIB4QACAeHwBgHh+B4B4AAAAeAAAAHgAAAB8AAAIf4AAAH+AAAB/gA 197 | AAf8AAAP//////////////////////////8= 198 | 199 | 200 | -------------------------------------------------------------------------------- /BARSReaderGUI/IDeobfuscator.cs: -------------------------------------------------------------------------------- 1 | namespace BARSReaderGUI 2 | { 3 | public interface IDeobfuscator 4 | { 5 | long Initialize(NativeReader reader); 6 | bool AdjustPosition(NativeReader reader, long newPosition); 7 | void Deobfuscate(byte[] buffer, long position, int offset, int numBytes); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /BARSReaderGUI/NativeReader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text; 4 | 5 | namespace BARSReaderGUI 6 | { 7 | public enum Endian 8 | { 9 | Little, 10 | Big 11 | } 12 | 13 | public class NativeReader : IDisposable 14 | { 15 | public Stream BaseStream => stream; 16 | 17 | public virtual long Position 18 | { 19 | get => stream?.Position ?? 0; 20 | set 21 | { 22 | if (deobfuscator == null || !deobfuscator.AdjustPosition(this, value)) 23 | stream.Position = value; 24 | } 25 | } 26 | public virtual long Length => streamLength; 27 | 28 | protected Stream stream; 29 | protected IDeobfuscator deobfuscator; 30 | protected byte[] buffer; 31 | protected char[] charBuffer; 32 | protected long streamLength; 33 | protected Encoding wideDecoder; 34 | 35 | public NativeReader(Stream inStream) 36 | { 37 | stream = inStream; 38 | if (stream != null) 39 | streamLength = stream.Length; 40 | 41 | wideDecoder = new UnicodeEncoding(); 42 | buffer = new byte[20]; 43 | charBuffer = new char[2]; 44 | } 45 | 46 | public NativeReader(Stream inStream, IDeobfuscator inDeobfuscator) 47 | : this(inStream) 48 | { 49 | deobfuscator = inDeobfuscator; 50 | if (deobfuscator != null && stream != null) 51 | { 52 | long newLength = deobfuscator.Initialize(this); 53 | if (newLength != -1) 54 | streamLength = newLength; 55 | } 56 | } 57 | 58 | public static byte[] ReadInStream(Stream inStream) 59 | { 60 | using (NativeReader reader = new NativeReader(inStream)) 61 | return reader.ReadToEnd(); 62 | } 63 | 64 | #region -- Basic Types -- 65 | 66 | public char ReadWideChar() 67 | { 68 | FillBuffer(2); 69 | wideDecoder.GetChars(buffer, 0, 2, charBuffer, 0); 70 | return charBuffer[0]; 71 | } 72 | 73 | public bool ReadBoolean() => ReadByte() == 1; 74 | 75 | public byte ReadByte() 76 | { 77 | FillBuffer(1); 78 | return buffer[0]; 79 | } 80 | 81 | public sbyte ReadSByte() 82 | { 83 | FillBuffer(1); 84 | return (sbyte)buffer[0]; 85 | } 86 | 87 | public short ReadShort(Endian inEndian = Endian.Little) 88 | { 89 | FillBuffer(2); 90 | if (inEndian == Endian.Little) 91 | return (short)(buffer[0] | buffer[1] << 8); 92 | return (short)(buffer[1] | buffer[0] << 8); 93 | } 94 | 95 | public ushort ReadUShort(Endian inEndian = Endian.Little) 96 | { 97 | FillBuffer(2); 98 | if (inEndian == Endian.Little) 99 | return (ushort)(buffer[0] | buffer[1] << 8); 100 | return (ushort)(buffer[1] | buffer[0] << 8); 101 | } 102 | 103 | public int ReadInt(Endian inEndian = Endian.Little) 104 | { 105 | FillBuffer(4); 106 | if (inEndian == Endian.Little) 107 | return (int)(buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer[3] << 24); 108 | return (int)(buffer[3] | buffer[2] << 8 | buffer[1] << 16 | buffer[0] << 24); 109 | } 110 | 111 | public uint ReadUInt(Endian inEndian = Endian.Little) 112 | { 113 | FillBuffer(4); 114 | if (inEndian == Endian.Little) 115 | return (uint)(buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer[3] << 24); 116 | return (uint)(buffer[3] | buffer[2] << 8 | buffer[1] << 16 | buffer[0] << 24); 117 | } 118 | 119 | public long ReadLong(Endian inEndian = Endian.Little) 120 | { 121 | FillBuffer(8); 122 | if (inEndian == Endian.Little) 123 | return (long)(uint)(buffer[4] | buffer[5] << 8 | buffer[6] << 16 | buffer[7] << 24) << 32 | 124 | (long)(uint)(buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer[3] << 24); 125 | return (long)(uint)(buffer[3] | buffer[2] << 8 | buffer[1] << 16 | buffer[0] << 24) << 32 | 126 | (long)(uint)(buffer[7] | buffer[6] << 8 | buffer[5] << 16 | buffer[4] << 24); 127 | } 128 | 129 | public ulong ReadULong(Endian inEndian = Endian.Little) 130 | { 131 | FillBuffer(8); 132 | if (inEndian == Endian.Little) 133 | return (ulong)(uint)(buffer[4] | buffer[5] << 8 | buffer[6] << 16 | buffer[7] << 24) << 32 | 134 | (ulong)(uint)(buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer[3] << 24); 135 | return (ulong)(uint)(buffer[3] | buffer[2] << 8 | buffer[1] << 16 | buffer[0] << 24) << 32 | 136 | (ulong)(uint)(buffer[7] | buffer[6] << 8 | buffer[5] << 16 | buffer[4] << 24); 137 | } 138 | 139 | public unsafe float ReadFloat(Endian inEndian = Endian.Little) 140 | { 141 | FillBuffer(4); 142 | 143 | uint tmpBuffer = 0; 144 | if (inEndian == Endian.Little) 145 | tmpBuffer = (uint)(buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer[3] << 24); 146 | else 147 | tmpBuffer = (uint)(buffer[3] | buffer[2] << 8 | buffer[1] << 16 | buffer[0] << 24); 148 | 149 | return *((float*)&tmpBuffer); 150 | } 151 | 152 | public unsafe double ReadDouble(Endian inEndian = Endian.Little) 153 | { 154 | FillBuffer(8); 155 | 156 | uint lo = 0; 157 | uint hi = 0; 158 | 159 | if (inEndian == Endian.Little) 160 | { 161 | lo = (uint)(buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer[3] << 24); 162 | hi = (uint)(buffer[4] | buffer[5] << 8 | buffer[6] << 16 | buffer[7] << 24); 163 | } 164 | else 165 | { 166 | lo = (uint)(buffer[3] | buffer[2] << 8 | buffer[1] << 16 | buffer[0] << 24); 167 | hi = (uint)(buffer[7] | buffer[6] << 8 | buffer[5] << 16 | buffer[4] << 24); 168 | } 169 | 170 | ulong tmpBuffer = ((ulong)hi) << 32 | lo; 171 | return *((double*)&tmpBuffer); 172 | } 173 | 174 | #endregion 175 | 176 | #region -- Special Types -- 177 | 178 | public Guid ReadGuid(Endian endian = Endian.Little) 179 | { 180 | FillBuffer(16); 181 | if (endian == Endian.Little) 182 | return new Guid(new byte[] { 183 | buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7], 184 | buffer[8], buffer[9], buffer[10], buffer[11], buffer[12], buffer[13], buffer[14], buffer[15] 185 | }); 186 | 187 | return new Guid(new byte[] { 188 | buffer[3], buffer[2], buffer[1], buffer[0], buffer[5], buffer[4], buffer[7], buffer[6], 189 | buffer[8], buffer[9], buffer[10], buffer[11], buffer[12], buffer[13], buffer[14], buffer[15] 190 | }); 191 | } 192 | 193 | public int Read7BitEncodedInt() 194 | { 195 | int result = 0; 196 | int i = 0; 197 | 198 | while (true) 199 | { 200 | int b = ReadByte(); 201 | result |= (b & 127) << i; 202 | 203 | if (b >> 7 == 0) 204 | return result; 205 | 206 | i += 7; 207 | } 208 | } 209 | 210 | public long Read7BitEncodedLong() 211 | { 212 | long result = 0; 213 | int i = 0; 214 | 215 | while (true) 216 | { 217 | int b = ReadByte(); 218 | result |= (long)((b & 127) << i); 219 | 220 | if (b >> 7 == 0) 221 | return result; 222 | 223 | i += 7; 224 | } 225 | } 226 | 227 | #endregion 228 | 229 | #region -- String Types -- 230 | 231 | public string ReadNullTerminatedString() 232 | { 233 | StringBuilder sb = new StringBuilder(); 234 | while (true) 235 | { 236 | char c = (char)ReadByte(); 237 | if (c == 0x00) 238 | return sb.ToString(); 239 | 240 | sb.Append(c); 241 | } 242 | } 243 | 244 | public string ReadNullTerminatedWideString() 245 | { 246 | StringBuilder sb = new StringBuilder(); 247 | while (true) 248 | { 249 | char c = ReadWideChar(); 250 | if (c == 0x0000) 251 | return sb.ToString(); 252 | 253 | sb.Append(c); 254 | } 255 | } 256 | 257 | public string ReadSizedString(int strLen) 258 | { 259 | StringBuilder sb = new StringBuilder(); 260 | for (int i = 0; i < strLen; i++) 261 | { 262 | char c = (char)ReadByte(); 263 | if (c != 0x00) 264 | sb.Append(c); 265 | } 266 | return sb.ToString(); 267 | } 268 | 269 | public string ReadLine() 270 | { 271 | StringBuilder sb = new StringBuilder(); 272 | byte c = 0x00; 273 | 274 | while (c != 0x0d && c != 0x0a) 275 | { 276 | c = ReadByte(); 277 | sb.Append((char)c); 278 | if (c == 0x0a || c == 0x0d || Position >= Length) 279 | break; 280 | } 281 | 282 | if (c == 0x0d) 283 | ReadByte(); 284 | 285 | return sb.ToString().Trim('\r', '\n'); 286 | } 287 | 288 | public string ReadWideLine() 289 | { 290 | StringBuilder sb = new StringBuilder(); 291 | char c = (char)0x00; 292 | 293 | while (c != 0x0d && c != 0x0a) 294 | { 295 | c = ReadWideChar(); 296 | sb.Append(c); 297 | if (c == 0x0a || c == 0x0d || Position >= Length) 298 | break; 299 | } 300 | 301 | if (c == 0x0d) 302 | ReadWideChar(); 303 | 304 | return sb.ToString().Trim('\r', '\n'); 305 | } 306 | 307 | public void Pad(int alignment) 308 | { 309 | if (alignment == 0) 310 | { 311 | return; 312 | } 313 | 314 | while (Position % alignment != 0) 315 | { 316 | Position++; 317 | } 318 | } 319 | 320 | #endregion 321 | 322 | public byte[] ReadToEnd() 323 | { 324 | long totalSize = Length - Position; 325 | if (totalSize < int.MaxValue) 326 | return ReadBytes((int)totalSize); 327 | 328 | byte[] outBuffer = new byte[totalSize]; 329 | while(totalSize > 0) 330 | { 331 | int bufferSize = (totalSize > int.MaxValue) ? int.MaxValue : (int)totalSize; 332 | byte[] tmpBuffer = new byte[bufferSize]; 333 | 334 | int count = Read(tmpBuffer, 0, bufferSize); 335 | totalSize -= bufferSize; 336 | 337 | Buffer.BlockCopy(tmpBuffer, 0, outBuffer, count, bufferSize); 338 | } 339 | 340 | return outBuffer; 341 | } 342 | 343 | public byte[] ReadBytes(int count) 344 | { 345 | byte[] outBuffer = new byte[count]; 346 | int totalNumBytesRead = 0; 347 | 348 | do 349 | { 350 | int numBytesRead = Read(outBuffer, totalNumBytesRead, count); 351 | if (numBytesRead == 0) 352 | break; 353 | 354 | totalNumBytesRead += numBytesRead; 355 | count -= numBytesRead; 356 | 357 | } while (count > 0); 358 | 359 | return outBuffer; 360 | } 361 | 362 | public virtual int Read(byte[] inBuffer, int offset, int numBytes) 363 | { 364 | int count = stream.Read(inBuffer, offset, numBytes); 365 | deobfuscator?.Deobfuscate(inBuffer, Position, offset, numBytes); 366 | return count; 367 | } 368 | 369 | public Stream CreateViewStream(long offset, long size) 370 | { 371 | Position = offset; 372 | return new MemoryStream(ReadBytes((int)size)); 373 | } 374 | 375 | public void Dispose() => Dispose(true); 376 | 377 | protected virtual void FillBuffer(int numBytes) 378 | { 379 | stream.Read(buffer, 0, numBytes); 380 | deobfuscator?.Deobfuscate(buffer, Position, 0, numBytes); 381 | } 382 | 383 | protected virtual void Dispose(bool disposing) 384 | { 385 | if (disposing) 386 | { 387 | Stream copyOfStream = stream; 388 | stream = null; 389 | 390 | copyOfStream?.Close(); 391 | } 392 | 393 | stream = null; 394 | buffer = null; 395 | } 396 | } 397 | 398 | } 399 | -------------------------------------------------------------------------------- /BARSReaderGUI/Program.cs: -------------------------------------------------------------------------------- 1 | namespace BARSReaderGUI 2 | { 3 | internal static class Program 4 | { 5 | /// 6 | /// The main entry point for the application. 7 | /// 8 | [STAThread] 9 | static void Main() 10 | { 11 | // To customize application configuration such as set high DPI settings or default font, 12 | // see https://aka.ms/applicationconfiguration. 13 | ApplicationConfiguration.Initialize(); 14 | Application.Run(new Form1()); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /BARSReaderGUI/Res/BARSIcon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/natv1337/BARSReaderGUI/800058a100e76cc82611a6b5f9bed931dcc02ed5/BARSReaderGUI/Res/BARSIcon.ico -------------------------------------------------------------------------------- /BARSReaderGUI/ZstdUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace BARSReaderGUI 8 | { 9 | public class ZstdUtils 10 | { 11 | public Stream Decompress(Stream stream) 12 | { 13 | return new MemoryStream(Decompressor(stream.ToArray())); 14 | } 15 | 16 | public static byte[] Decompressor(byte[] b) 17 | { 18 | using (var decompressor = new ZstdNet.Decompressor()) 19 | { 20 | return decompressor.Unwrap(b); 21 | } 22 | } 23 | } 24 | public static class StreamExtensions 25 | { 26 | public static byte[] ToArray(this Stream stream) 27 | { 28 | using (var memoryStream = new MemoryStream()) 29 | { 30 | stream.CopyTo(memoryStream); 31 | 32 | return memoryStream.ToArray(); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BARSReaderGUI 2 | 3 | Basic program for reading and exporting data from Nintendo's BARS file format. 4 | 5 | ## Usage 6 | Select "File" at the top, then "Open..." then select the BARS you wish to read. 7 | ![image](https://user-images.githubusercontent.com/33284629/222014613-de53a59f-5115-428c-8f9c-73b2ae16694d.png) 8 | 9 | You can extract the sound or meta with the two buttons on the bottom right after selecting an asset from the list on the left. 10 | 11 | ## Compatibility 12 | This has been tested with: 13 | - Super Mario Bros. Wonder 14 | - The Legend of Zelda: Tears of the Kingdom 15 | - Splatoon 3 16 | - Animal Crossing New Horizons 17 | - Splatoon 2 18 | - Mario Kart 8 Deluxe 19 | 20 | The above games definitely work, but any little endian BARS file of version 1.1 or 1.2 should work just fine as well. 21 | 22 | ## Credits 23 | 24 | NativeReader class from [FrostyToolSuite](https://github.com/CadeEvs/FrostyToolsuite) 25 | 26 | Zstd compressed files support provided by [ZstdNet](https://github.com/skbkontur/ZstdNet) 27 | 28 | Lastly, the awesome [Nintendo-File-Formats 29 | wiki](https://github.com/kinnay/Nintendo-File-Formats/wiki) for it's documentation on the BARS and AMTA formats 30 | --------------------------------------------------------------------------------