2021-02-06 18:09:13 -06:00
|
|
|
|
/* This file is part of libWiiSharp
|
|
|
|
|
* Copyright (C) 2009 Leathl
|
|
|
|
|
* Copyright (C) 2020 Github Contributors
|
|
|
|
|
*
|
|
|
|
|
* libWiiSharp is free software: you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License as published
|
|
|
|
|
* by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* libWiiSharp is distributed in the hope that it will be
|
|
|
|
|
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
|
|
|
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2020-12-28 22:28:44 -06:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace libWiiSharp
|
|
|
|
|
{
|
2021-02-06 18:09:13 -06:00
|
|
|
|
internal class BNS_Header
|
2020-12-28 22:28:44 -06:00
|
|
|
|
{
|
2021-02-06 22:53:40 -06:00
|
|
|
|
private readonly byte[] magic = new byte[4]
|
2021-02-06 18:09:13 -06:00
|
|
|
|
{
|
2021-02-06 22:53:40 -06:00
|
|
|
|
66,
|
|
|
|
|
78,
|
|
|
|
|
83,
|
|
|
|
|
32
|
2021-02-06 18:09:13 -06:00
|
|
|
|
};
|
|
|
|
|
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;
|
2020-12-28 22:28:44 -06:00
|
|
|
|
|
2021-02-06 18:09:13 -06:00
|
|
|
|
public uint DataOffset
|
|
|
|
|
{
|
2021-02-06 22:53:40 -06:00
|
|
|
|
get => dataOffset;
|
|
|
|
|
set => dataOffset = value;
|
2021-02-06 18:09:13 -06:00
|
|
|
|
}
|
2020-12-28 22:28:44 -06:00
|
|
|
|
|
2021-02-06 18:09:13 -06:00
|
|
|
|
public uint InfoLength
|
|
|
|
|
{
|
2021-02-06 22:53:40 -06:00
|
|
|
|
get => infoLength;
|
|
|
|
|
set => infoLength = value;
|
2021-02-06 18:09:13 -06:00
|
|
|
|
}
|
2020-12-28 22:28:44 -06:00
|
|
|
|
|
2021-02-06 18:09:13 -06:00
|
|
|
|
public ushort Size
|
|
|
|
|
{
|
2021-02-06 22:53:40 -06:00
|
|
|
|
get => size;
|
|
|
|
|
set => size = value;
|
2021-02-06 18:09:13 -06:00
|
|
|
|
}
|
2020-12-28 22:28:44 -06:00
|
|
|
|
|
2021-02-06 18:09:13 -06:00
|
|
|
|
public uint DataLength
|
|
|
|
|
{
|
2021-02-06 22:53:40 -06:00
|
|
|
|
get => dataLength;
|
|
|
|
|
set => dataLength = value;
|
2021-02-06 18:09:13 -06:00
|
|
|
|
}
|
2020-12-28 22:28:44 -06:00
|
|
|
|
|
2021-02-06 18:09:13 -06:00
|
|
|
|
public uint FileSize
|
|
|
|
|
{
|
2021-02-06 22:53:40 -06:00
|
|
|
|
get => fileSize;
|
|
|
|
|
set => fileSize = value;
|
2021-02-06 18:09:13 -06:00
|
|
|
|
}
|
2020-12-28 22:28:44 -06:00
|
|
|
|
|
2021-02-06 18:09:13 -06:00
|
|
|
|
public void Write(Stream outStream)
|
|
|
|
|
{
|
2021-02-06 22:53:40 -06:00
|
|
|
|
outStream.Write(magic, 0, magic.Length);
|
|
|
|
|
byte[] bytes1 = BitConverter.GetBytes(flags);
|
|
|
|
|
Array.Reverse(bytes1);
|
|
|
|
|
outStream.Write(bytes1, 0, bytes1.Length);
|
|
|
|
|
byte[] bytes2 = BitConverter.GetBytes(fileSize);
|
|
|
|
|
Array.Reverse(bytes2);
|
|
|
|
|
outStream.Write(bytes2, 0, bytes2.Length);
|
|
|
|
|
byte[] bytes3 = BitConverter.GetBytes(size);
|
|
|
|
|
Array.Reverse(bytes3);
|
|
|
|
|
outStream.Write(bytes3, 0, bytes3.Length);
|
|
|
|
|
byte[] bytes4 = BitConverter.GetBytes(chunkCount);
|
|
|
|
|
Array.Reverse(bytes4);
|
|
|
|
|
outStream.Write(bytes4, 0, bytes4.Length);
|
|
|
|
|
byte[] bytes5 = BitConverter.GetBytes(infoOffset);
|
|
|
|
|
Array.Reverse(bytes5);
|
|
|
|
|
outStream.Write(bytes5, 0, bytes5.Length);
|
|
|
|
|
byte[] bytes6 = BitConverter.GetBytes(infoLength);
|
|
|
|
|
Array.Reverse(bytes6);
|
|
|
|
|
outStream.Write(bytes6, 0, bytes6.Length);
|
|
|
|
|
byte[] bytes7 = BitConverter.GetBytes(dataOffset);
|
|
|
|
|
Array.Reverse(bytes7);
|
|
|
|
|
outStream.Write(bytes7, 0, bytes7.Length);
|
|
|
|
|
byte[] bytes8 = BitConverter.GetBytes(dataLength);
|
|
|
|
|
Array.Reverse(bytes8);
|
|
|
|
|
outStream.Write(bytes8, 0, bytes8.Length);
|
2021-02-06 18:09:13 -06:00
|
|
|
|
}
|
2020-12-28 22:28:44 -06:00
|
|
|
|
|
2021-02-06 18:09:13 -06:00
|
|
|
|
public void Read(Stream input)
|
|
|
|
|
{
|
|
|
|
|
BinaryReader binaryReader = new BinaryReader(input);
|
2021-02-06 22:53:40 -06:00
|
|
|
|
if (!Shared.CompareByteArrays(magic, binaryReader.ReadBytes(4)))
|
2021-02-06 18:09:13 -06:00
|
|
|
|
{
|
|
|
|
|
binaryReader.BaseStream.Seek(28L, SeekOrigin.Current);
|
2021-02-06 22:53:40 -06:00
|
|
|
|
if (!Shared.CompareByteArrays(magic, binaryReader.ReadBytes(4)))
|
|
|
|
|
{
|
2021-02-06 18:09:13 -06:00
|
|
|
|
throw new Exception("This is not a valid BNS audio file!");
|
2021-02-06 22:53:40 -06:00
|
|
|
|
}
|
2021-02-06 18:09:13 -06:00
|
|
|
|
}
|
2021-02-06 22:53:40 -06:00
|
|
|
|
flags = Shared.Swap(binaryReader.ReadUInt32());
|
|
|
|
|
fileSize = Shared.Swap(binaryReader.ReadUInt32());
|
|
|
|
|
size = Shared.Swap(binaryReader.ReadUInt16());
|
|
|
|
|
chunkCount = Shared.Swap(binaryReader.ReadUInt16());
|
|
|
|
|
infoOffset = Shared.Swap(binaryReader.ReadUInt32());
|
|
|
|
|
infoLength = Shared.Swap(binaryReader.ReadUInt32());
|
|
|
|
|
dataOffset = Shared.Swap(binaryReader.ReadUInt32());
|
|
|
|
|
dataLength = Shared.Swap(binaryReader.ReadUInt32());
|
2021-02-06 18:09:13 -06:00
|
|
|
|
}
|
2020-12-28 22:28:44 -06:00
|
|
|
|
}
|
|
|
|
|
}
|