Begin Formatting/Recommenting

This commit is contained in:
Michael 2021-02-06 18:09:13 -06:00
parent b9c57a8ae9
commit 6e865ca4af
11 changed files with 1857 additions and 1681 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
/.vs
/bin
/obj

View file

@ -3,14 +3,14 @@ using System.Resources;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security.Permissions; using System.Security.Permissions;
[assembly: AssemblyTitle("libWiiSharp_ModMii")] [assembly: AssemblyTitle("libWiiSharp_Modified")]
[assembly: AssemblyDescription("a wii related .NET library modified for ModMii")] [assembly: AssemblyDescription("a wii related .NET library modified to add features for othe programs.")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Leathl,SC reproductions")] [assembly: AssemblyCompany("Leathl,SC reproductions")]
[assembly: AssemblyProduct("libWiiSharp_ModMii")] [assembly: AssemblyProduct("libWiiSharp_Modified")]
[assembly: AssemblyCopyright("Copyright © Leathl 2011")] [assembly: AssemblyCopyright("Copyright © Leathl 2011, Copyright © Github Contributors 2020")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)] [assembly: ComVisible(true)]
[assembly: Guid("af701263-5875-4866-9c09-d7f62e9f0ff0")] [assembly: Guid("af701263-5875-4866-9c09-d7f62e9f0ff0")]
[assembly: AssemblyFileVersion("0.4.0.0")] [assembly: AssemblyFileVersion("0.4.0.0")]
[assembly: NeutralResourcesLanguage("en")] [assembly: NeutralResourcesLanguage("en")]

110
BNS.cs
View file

@ -1,8 +1,20 @@
// Decompiled with JetBrains decompiler /* This file is part of libWiiSharp
// Type: libWiiSharp.BNS * Copyright (C) 2009 Leathl
// Assembly: libWiiSharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null * Copyright (C) 2020 Github Contributors
// MVID: FBF36F3D-B5D6-481F-B5F5-1BD3C19E13B2 *
// Assembly location: C:\Users\theso\Downloads\NCPatcher\pack\libWiiSharp.dll * 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/>.
*/
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -13,6 +25,7 @@ namespace libWiiSharp
{ {
public class BNS : IDisposable public class BNS : IDisposable
{ {
private BNS_Header bnsHeader = new BNS_Header(); private BNS_Header bnsHeader = new BNS_Header();
private BNS_Info bnsInfo = new BNS_Info(); private BNS_Info bnsInfo = new BNS_Info();
private BNS_Data bnsData = new BNS_Data(); private BNS_Data bnsData = new BNS_Data();
@ -66,24 +79,37 @@ namespace libWiiSharp
private bool toMono; private bool toMono;
private bool isDisposed; private bool isDisposed;
/// <summary>
/// 0x00 (0) = No Loop, 0x01 (1) = Loop
/// </summary>
public bool HasLoop public bool HasLoop
{ {
get => this.bnsInfo.HasLoop == (byte) 1; get => this.bnsInfo.HasLoop == (byte) 1;
set => this.bnsInfo.HasLoop = value ? (byte) 1 : (byte) 0; set => this.bnsInfo.HasLoop = value ? (byte) 1 : (byte) 0;
} }
/// <summary>
/// The start sample of the Loop
/// </summary>
public uint LoopStart public uint LoopStart
{ {
get => this.bnsInfo.LoopStart; get => this.bnsInfo.LoopStart;
set => this.bnsInfo.LoopStart = value; set => this.bnsInfo.LoopStart = value;
} }
/// <summary>
/// The total number of samples in this file
/// </summary>
public uint TotalSampleCount public uint TotalSampleCount
{ {
get => this.bnsInfo.LoopEnd; get => this.bnsInfo.LoopEnd;
set => this.bnsInfo.LoopEnd = value; set => this.bnsInfo.LoopEnd = value;
} }
/// <summary>
/// If true and the input Wave file is stereo, the BNS will be converted to Mono.
/// Be sure to set this before you call Convert()!
/// </summary>
public bool StereoToMono public bool StereoToMono
{ {
get => this.toMono; get => this.toMono;
@ -94,6 +120,7 @@ namespace libWiiSharp
protected BNS() protected BNS()
{ {
} }
public BNS(string waveFile) => this.waveFile = File.ReadAllBytes(waveFile); public BNS(string waveFile) => this.waveFile = File.ReadAllBytes(waveFile);
@ -112,6 +139,8 @@ namespace libWiiSharp
this.loopFromWave = loopFromWave; this.loopFromWave = loopFromWave;
} }
#region IDisposable Members
~BNS() => this.Dispose(false); ~BNS() => this.Dispose(false);
public void Dispose() public void Dispose()
@ -135,19 +164,42 @@ namespace libWiiSharp
this.pHist2 = (int[]) null; this.pHist2 = (int[]) null;
this.waveFile = (byte[]) null; this.waveFile = (byte[]) null;
} }
this.isDisposed = true;
}
this.isDisposed = true;
}
#endregion
#region Public Functions
/// <summary>
/// Returns the length of the BNS audio file in seconds
/// </summary>
/// <param name="bnsFile"></param>
/// <returns></returns>
public static int GetBnsLength(byte[] bnsFile) public static int GetBnsLength(byte[] bnsFile)
{ {
uint num = (uint) Shared.Swap(BitConverter.ToUInt16(bnsFile, 44)); uint sampleRate = (uint) Shared.Swap(BitConverter.ToUInt16(bnsFile, 44));
return (int) (Shared.Swap(BitConverter.ToUInt32(bnsFile, 52)) / num); uint sampleCount = Shared.Swap(BitConverter.ToUInt32(bnsFile, 52));
return (int)(sampleCount / sampleRate);
} }
/// <summary>
/// Converts the Wave file to BNS
/// </summary>
public void Convert() => this.convert(this.waveFile, this.loopFromWave); public void Convert() => this.convert(this.waveFile, this.loopFromWave);
/// <summary>
/// Returns the BNS file as a Byte Array. If not already converted, it will be done first.
/// </summary>
/// <returns></returns>
public byte[] ToByteArray() => this.ToMemoryStream().ToArray(); public byte[] ToByteArray() => this.ToMemoryStream().ToArray();
/// <summary>
/// Returns the BNS file as a Memory Stream. If not already converted, it will be done first.
/// </summary>
/// <returns></returns>
public MemoryStream ToMemoryStream() public MemoryStream ToMemoryStream()
{ {
if (!this.converted) if (!this.converted)
@ -167,23 +219,35 @@ namespace libWiiSharp
} }
} }
public void Save(string destionationFile) /// <summary>
/// Saves the BNS file to the given path. If not already converted, it will be done first.
/// </summary>
/// <param name="destinationFile"></param>
public void Save(string destinationFile)
{ {
if (File.Exists(destionationFile)) if (File.Exists(destinationFile))
File.Delete(destionationFile); File.Delete(destinationFile);
using (FileStream fileStream = new FileStream(destionationFile, FileMode.Create)) using (FileStream fileStream = new FileStream(destinationFile, FileMode.Create))
{ {
byte[] array = this.ToMemoryStream().ToArray(); byte[] array = this.ToMemoryStream().ToArray();
fileStream.Write(array, 0, array.Length); fileStream.Write(array, 0, array.Length);
} }
} }
/// <summary>
/// Sets the Loop to the given Start Sample. Be sure that you call Convert() first!
/// </summary>
/// <param name="loopStartSample"></param>
public void SetLoop(int loopStartSample) public void SetLoop(int loopStartSample)
{ {
this.bnsInfo.HasLoop = (byte) 1; this.bnsInfo.HasLoop = (byte) 1;
this.bnsInfo.LoopStart = (uint) loopStartSample; this.bnsInfo.LoopStart = (uint) loopStartSample;
} }
#endregion
#region Private Functions
private void convert(byte[] waveFile, bool loopFromWave) private void convert(byte[] waveFile, bool loopFromWave)
{ {
Wave wave = new Wave(waveFile); Wave wave = new Wave(waveFile);
@ -269,7 +333,7 @@ namespace libWiiSharp
catch catch
{ {
} }
label_14: label_14:
for (int index2 = 0; index2 < 14; ++index2) for (int index2 = 0; index2 < 14; ++index2)
inputBuffer[index2] = array1[index1 * 14 + index2]; inputBuffer[index2] = array1[index1 * 14 + index2];
byte[] numArray2 = this.RepackAdpcm(0, this.defTbl, inputBuffer); byte[] numArray2 = this.RepackAdpcm(0, this.defTbl, inputBuffer);
@ -412,6 +476,18 @@ label_14:
progress(new object(), new ProgressChangedEventArgs(progressPercentage, new object())); progress(new object(), new ProgressChangedEventArgs(progressPercentage, new object()));
} }
#endregion
#region BNS to Wave
#region Public Functions
/// <summary>
/// Converts a BNS audio file to Wave format.
/// </summary>
/// <param name="inputFile"></param>
/// <param name="outputFile"></param>
/// <returns></returns>
public static Wave BnsToWave(Stream inputFile) public static Wave BnsToWave(Stream inputFile)
{ {
BNS bns = new BNS(); BNS bns = new BNS();
@ -446,6 +522,10 @@ label_14:
return wave; return wave;
} }
#endregion
#region Private Functions
private byte[] Read(Stream input) private byte[] Read(Stream input)
{ {
input.Seek(0L, SeekOrigin.Begin); input.Seek(0L, SeekOrigin.Begin);
@ -510,5 +590,7 @@ label_14:
this.pHist2[channel] = num4; this.pHist2[channel] = num4;
return numArray; return numArray;
} }
#endregion
#endregion
} }
} }

View file

@ -1,8 +1,20 @@
// Decompiled with JetBrains decompiler /* This file is part of libWiiSharp
// Type: libWiiSharp.BNS_Data * Copyright (C) 2009 Leathl
// Assembly: libWiiSharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null * Copyright (C) 2020 Github Contributors
// MVID: FBF36F3D-B5D6-481F-B5F5-1BD3C19E13B2 *
// Assembly location: C:\Users\theso\Downloads\NCPatcher\pack\libWiiSharp.dll * 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/>.
*/
using System; using System;
using System.IO; using System.IO;

View file

@ -1,8 +1,20 @@
// Decompiled with JetBrains decompiler /* This file is part of libWiiSharp
// Type: libWiiSharp.BNS_Header * Copyright (C) 2009 Leathl
// Assembly: libWiiSharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null * Copyright (C) 2020 Github Contributors
// MVID: FBF36F3D-B5D6-481F-B5F5-1BD3C19E13B2 *
// Assembly location: C:\Users\theso\Downloads\NCPatcher\pack\libWiiSharp.dll * 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/>.
*/
using System; using System;
using System.IO; using System.IO;
@ -93,7 +105,7 @@ namespace libWiiSharp
{ {
binaryReader.BaseStream.Seek(28L, SeekOrigin.Current); binaryReader.BaseStream.Seek(28L, SeekOrigin.Current);
if (!Shared.CompareByteArrays(this.magic, binaryReader.ReadBytes(4))) if (!Shared.CompareByteArrays(this.magic, binaryReader.ReadBytes(4)))
throw new Exception("This is not a valid BNS audfo file!"); throw new Exception("This is not a valid BNS audio file!");
} }
this.flags = Shared.Swap(binaryReader.ReadUInt32()); this.flags = Shared.Swap(binaryReader.ReadUInt32());
this.fileSize = Shared.Swap(binaryReader.ReadUInt32()); this.fileSize = Shared.Swap(binaryReader.ReadUInt32());

View file

@ -1,8 +1,20 @@
// Decompiled with JetBrains decompiler /* This file is part of libWiiSharp
// Type: libWiiSharp.BNS_Info * Copyright (C) 2009 Leathl
// Assembly: libWiiSharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null * Copyright (C) 2020 Github Contributors
// MVID: FBF36F3D-B5D6-481F-B5F5-1BD3C19E13B2 *
// Assembly location: C:\Users\theso\Downloads\NCPatcher\pack\libWiiSharp.dll * 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/>.
*/
using System; using System;
using System.IO; using System.IO;
@ -11,6 +23,7 @@ namespace libWiiSharp
{ {
internal class BNS_Info internal class BNS_Info
{ {
//Private Variables
private byte[] magic = new byte[4] private byte[] magic = new byte[4]
{ {
(byte) 73, (byte) 73,
@ -26,7 +39,7 @@ namespace libWiiSharp
private ushort sampleRate = 44100; private ushort sampleRate = 44100;
private ushort pad0; private ushort pad0;
private uint loopStart; private uint loopStart;
private uint loopEnd; private uint loopEnd; //Or total sample count
private uint offsetToChannelStart = 24; private uint offsetToChannelStart = 24;
private uint pad1; private uint pad1;
private uint channel1StartOffset = 32; private uint channel1StartOffset = 32;
@ -56,6 +69,7 @@ namespace libWiiSharp
private ushort channel2LoopNextPreviousValue; private ushort channel2LoopNextPreviousValue;
private ushort channel2LoopPadding; private ushort channel2LoopPadding;
//Public Variables
public byte HasLoop public byte HasLoop
{ {
get => this.hasLoop; get => this.hasLoop;

View file

@ -1,8 +1,20 @@
// Decompiled with JetBrains decompiler /* This file is part of libWiiSharp
// Type: libWiiSharp.Brlan * Copyright (C) 2009 Leathl
// Assembly: libWiiSharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null * Copyright (C) 2020 Github Contributors
// MVID: FBF36F3D-B5D6-481F-B5F5-1BD3C19E13B2 *
// Assembly location: C:\Users\theso\Downloads\NCPatcher\pack\libWiiSharp.dll * 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/>.
*/
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;

View file

@ -1,8 +1,20 @@
// Decompiled with JetBrains decompiler /* This file is part of libWiiSharp
// Type: libWiiSharp.Brlyt * Copyright (C) 2009 Leathl
// Assembly: libWiiSharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null * Copyright (C) 2020 Github Contributors
// MVID: FBF36F3D-B5D6-481F-B5F5-1BD3C19E13B2 *
// Assembly location: C:\Users\theso\Downloads\NCPatcher\pack\libWiiSharp.dll * 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/>.
*/
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;

View file

@ -1,8 +1,20 @@
// Decompiled with JetBrains decompiler /* This file is part of libWiiSharp
// Type: libWiiSharp.CertificateChain * Copyright (C) 2009 Leathl
// Assembly: libWiiSharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null * Copyright (C) 2020 Github Contributors
// MVID: FBF36F3D-B5D6-481F-B5F5-1BD3C19E13B2 *
// Assembly location: C:\Users\theso\Downloads\NCPatcher\pack\libWiiSharp.dll * 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/>.
*/
using System; using System;
using System.IO; using System.IO;

View file

@ -1,8 +1,20 @@
// Decompiled with JetBrains decompiler /* This file is part of libWiiSharp
// Type: libWiiSharp.ColorIndexConverter * Copyright (C) 2009 Leathl
// Assembly: libWiiSharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null * Copyright (C) 2020 Github Contributors
// MVID: FBF36F3D-B5D6-481F-B5F5-1BD3C19E13B2 *
// Assembly location: C:\Users\theso\Downloads\NCPatcher\pack\libWiiSharp.dll * 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/>.
*/
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;

View file

@ -24,6 +24,7 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
<RegisterForComInterop>true</RegisterForComInterop>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
@ -34,6 +35,7 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
<RegisterForComInterop>false</RegisterForComInterop>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<SignAssembly>false</SignAssembly> <SignAssembly>false</SignAssembly>
@ -93,5 +95,8 @@
<Compile Include="zlibWrapper.cs" /> <Compile Include="zlibWrapper.cs" />
<Compile Include="AssemblyInfo.cs" /> <Compile Include="AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Include=".gitignore" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>