libWiiSharp/BNS_Header.cs
Michael Malloy b9c57a8ae9 Add decompiled and edited files
I need to fix the formatting and rename some variables, but that's for another time. Licence, readme, and changelog are from the original libWiiSharp repo.
2020-12-28 22:28:44 -06:00

108 lines
3.4 KiB
C#

// Decompiled with JetBrains decompiler
// Type: libWiiSharp.BNS_Header
// Assembly: libWiiSharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null
// MVID: FBF36F3D-B5D6-481F-B5F5-1BD3C19E13B2
// Assembly location: C:\Users\theso\Downloads\NCPatcher\pack\libWiiSharp.dll
using System;
using System.IO;
namespace libWiiSharp
{
internal class BNS_Header
{
private byte[] magic = new byte[4]
{
(byte) 66,
(byte) 78,
(byte) 83,
(byte) 32
};
private uint flags = 4278124800;
private uint fileSize = 315584;
private ushort size = 32;
private ushort chunkCount = 2;
private uint infoOffset = 32;
private uint infoLength = 160;
private uint dataOffset = 192;
private uint dataLength = 315392;
public uint DataOffset
{
get => this.dataOffset;
set => this.dataOffset = value;
}
public uint InfoLength
{
get => this.infoLength;
set => this.infoLength = value;
}
public ushort Size
{
get => this.size;
set => this.size = value;
}
public uint DataLength
{
get => this.dataLength;
set => this.dataLength = value;
}
public uint FileSize
{
get => this.fileSize;
set => this.fileSize = value;
}
public void Write(Stream outStream)
{
outStream.Write(this.magic, 0, this.magic.Length);
byte[] bytes1 = BitConverter.GetBytes(this.flags);
Array.Reverse((Array) bytes1);
outStream.Write(bytes1, 0, bytes1.Length);
byte[] bytes2 = BitConverter.GetBytes(this.fileSize);
Array.Reverse((Array) bytes2);
outStream.Write(bytes2, 0, bytes2.Length);
byte[] bytes3 = BitConverter.GetBytes(this.size);
Array.Reverse((Array) bytes3);
outStream.Write(bytes3, 0, bytes3.Length);
byte[] bytes4 = BitConverter.GetBytes(this.chunkCount);
Array.Reverse((Array) bytes4);
outStream.Write(bytes4, 0, bytes4.Length);
byte[] bytes5 = BitConverter.GetBytes(this.infoOffset);
Array.Reverse((Array) bytes5);
outStream.Write(bytes5, 0, bytes5.Length);
byte[] bytes6 = BitConverter.GetBytes(this.infoLength);
Array.Reverse((Array) bytes6);
outStream.Write(bytes6, 0, bytes6.Length);
byte[] bytes7 = BitConverter.GetBytes(this.dataOffset);
Array.Reverse((Array) bytes7);
outStream.Write(bytes7, 0, bytes7.Length);
byte[] bytes8 = BitConverter.GetBytes(this.dataLength);
Array.Reverse((Array) bytes8);
outStream.Write(bytes8, 0, bytes8.Length);
}
public void Read(Stream input)
{
BinaryReader binaryReader = new BinaryReader(input);
if (!Shared.CompareByteArrays(this.magic, binaryReader.ReadBytes(4)))
{
binaryReader.BaseStream.Seek(28L, SeekOrigin.Current);
if (!Shared.CompareByteArrays(this.magic, binaryReader.ReadBytes(4)))
throw new Exception("This is not a valid BNS audfo file!");
}
this.flags = Shared.Swap(binaryReader.ReadUInt32());
this.fileSize = Shared.Swap(binaryReader.ReadUInt32());
this.size = Shared.Swap(binaryReader.ReadUInt16());
this.chunkCount = Shared.Swap(binaryReader.ReadUInt16());
this.infoOffset = Shared.Swap(binaryReader.ReadUInt32());
this.infoLength = Shared.Swap(binaryReader.ReadUInt32());
this.dataOffset = Shared.Swap(binaryReader.ReadUInt32());
this.dataLength = Shared.Swap(binaryReader.ReadUInt32());
}
}
}