mirror of
https://github.com/TheShadowEevee/libWiiSharp.git
synced 2025-01-11 15:38:51 -06:00
Begin Formatting/Recommenting
This commit is contained in:
parent
b9c57a8ae9
commit
6e865ca4af
11 changed files with 1857 additions and 1681 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
/.vs
|
||||
/bin
|
||||
/obj
|
|
@ -3,14 +3,14 @@ using System.Resources;
|
|||
using System.Runtime.InteropServices;
|
||||
using System.Security.Permissions;
|
||||
|
||||
[assembly: AssemblyTitle("libWiiSharp_ModMii")]
|
||||
[assembly: AssemblyDescription("a wii related .NET library modified for ModMii")]
|
||||
[assembly: AssemblyTitle("libWiiSharp_Modified")]
|
||||
[assembly: AssemblyDescription("a wii related .NET library modified to add features for othe programs.")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Leathl,SC reproductions")]
|
||||
[assembly: AssemblyProduct("libWiiSharp_ModMii")]
|
||||
[assembly: AssemblyCopyright("Copyright © Leathl 2011")]
|
||||
[assembly: AssemblyProduct("libWiiSharp_Modified")]
|
||||
[assembly: AssemblyCopyright("Copyright © Leathl 2011, Copyright © Github Contributors 2020")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: ComVisible(true)]
|
||||
[assembly: Guid("af701263-5875-4866-9c09-d7f62e9f0ff0")]
|
||||
[assembly: AssemblyFileVersion("0.4.0.0")]
|
||||
[assembly: NeutralResourcesLanguage("en")]
|
||||
|
|
110
BNS.cs
110
BNS.cs
|
@ -1,8 +1,20 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: libWiiSharp.BNS
|
||||
// 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
|
||||
/* 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/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -13,6 +25,7 @@ namespace libWiiSharp
|
|||
{
|
||||
public class BNS : IDisposable
|
||||
{
|
||||
|
||||
private BNS_Header bnsHeader = new BNS_Header();
|
||||
private BNS_Info bnsInfo = new BNS_Info();
|
||||
private BNS_Data bnsData = new BNS_Data();
|
||||
|
@ -66,24 +79,37 @@ namespace libWiiSharp
|
|||
private bool toMono;
|
||||
private bool isDisposed;
|
||||
|
||||
/// <summary>
|
||||
/// 0x00 (0) = No Loop, 0x01 (1) = Loop
|
||||
/// </summary>
|
||||
public bool HasLoop
|
||||
{
|
||||
get => this.bnsInfo.HasLoop == (byte) 1;
|
||||
set => this.bnsInfo.HasLoop = value ? (byte) 1 : (byte) 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The start sample of the Loop
|
||||
/// </summary>
|
||||
public uint LoopStart
|
||||
{
|
||||
get => this.bnsInfo.LoopStart;
|
||||
set => this.bnsInfo.LoopStart = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The total number of samples in this file
|
||||
/// </summary>
|
||||
public uint TotalSampleCount
|
||||
{
|
||||
get => this.bnsInfo.LoopEnd;
|
||||
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
|
||||
{
|
||||
get => this.toMono;
|
||||
|
@ -94,6 +120,7 @@ namespace libWiiSharp
|
|||
|
||||
protected BNS()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public BNS(string waveFile) => this.waveFile = File.ReadAllBytes(waveFile);
|
||||
|
@ -112,6 +139,8 @@ namespace libWiiSharp
|
|||
this.loopFromWave = loopFromWave;
|
||||
}
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
~BNS() => this.Dispose(false);
|
||||
|
||||
public void Dispose()
|
||||
|
@ -135,19 +164,42 @@ namespace libWiiSharp
|
|||
this.pHist2 = (int[]) 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)
|
||||
{
|
||||
uint num = (uint) Shared.Swap(BitConverter.ToUInt16(bnsFile, 44));
|
||||
return (int) (Shared.Swap(BitConverter.ToUInt32(bnsFile, 52)) / num);
|
||||
uint sampleRate = (uint) Shared.Swap(BitConverter.ToUInt16(bnsFile, 44));
|
||||
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);
|
||||
|
||||
/// <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();
|
||||
|
||||
/// <summary>
|
||||
/// Returns the BNS file as a Memory Stream. If not already converted, it will be done first.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public MemoryStream ToMemoryStream()
|
||||
{
|
||||
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))
|
||||
File.Delete(destionationFile);
|
||||
using (FileStream fileStream = new FileStream(destionationFile, FileMode.Create))
|
||||
if (File.Exists(destinationFile))
|
||||
File.Delete(destinationFile);
|
||||
using (FileStream fileStream = new FileStream(destinationFile, FileMode.Create))
|
||||
{
|
||||
byte[] array = this.ToMemoryStream().ToArray();
|
||||
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)
|
||||
{
|
||||
this.bnsInfo.HasLoop = (byte) 1;
|
||||
this.bnsInfo.LoopStart = (uint) loopStartSample;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Functions
|
||||
|
||||
private void convert(byte[] waveFile, bool loopFromWave)
|
||||
{
|
||||
Wave wave = new Wave(waveFile);
|
||||
|
@ -269,7 +333,7 @@ namespace libWiiSharp
|
|||
catch
|
||||
{
|
||||
}
|
||||
label_14:
|
||||
label_14:
|
||||
for (int index2 = 0; index2 < 14; ++index2)
|
||||
inputBuffer[index2] = array1[index1 * 14 + index2];
|
||||
byte[] numArray2 = this.RepackAdpcm(0, this.defTbl, inputBuffer);
|
||||
|
@ -412,6 +476,18 @@ label_14:
|
|||
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)
|
||||
{
|
||||
BNS bns = new BNS();
|
||||
|
@ -446,6 +522,10 @@ label_14:
|
|||
return wave;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Functions
|
||||
|
||||
private byte[] Read(Stream input)
|
||||
{
|
||||
input.Seek(0L, SeekOrigin.Begin);
|
||||
|
@ -510,5 +590,7 @@ label_14:
|
|||
this.pHist2[channel] = num4;
|
||||
return numArray;
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
}
|
22
BNS_Data.cs
22
BNS_Data.cs
|
@ -1,8 +1,20 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: libWiiSharp.BNS_Data
|
||||
// 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
|
||||
/* 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/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
|
|
@ -1,8 +1,20 @@
|
|||
// 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
|
||||
/* 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/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
@ -93,7 +105,7 @@ namespace libWiiSharp
|
|||
{
|
||||
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!");
|
||||
throw new Exception("This is not a valid BNS audio file!");
|
||||
}
|
||||
this.flags = Shared.Swap(binaryReader.ReadUInt32());
|
||||
this.fileSize = Shared.Swap(binaryReader.ReadUInt32());
|
||||
|
|
26
BNS_Info.cs
26
BNS_Info.cs
|
@ -1,8 +1,20 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: libWiiSharp.BNS_Info
|
||||
// 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
|
||||
/* 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/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
@ -11,6 +23,7 @@ namespace libWiiSharp
|
|||
{
|
||||
internal class BNS_Info
|
||||
{
|
||||
//Private Variables
|
||||
private byte[] magic = new byte[4]
|
||||
{
|
||||
(byte) 73,
|
||||
|
@ -26,7 +39,7 @@ namespace libWiiSharp
|
|||
private ushort sampleRate = 44100;
|
||||
private ushort pad0;
|
||||
private uint loopStart;
|
||||
private uint loopEnd;
|
||||
private uint loopEnd; //Or total sample count
|
||||
private uint offsetToChannelStart = 24;
|
||||
private uint pad1;
|
||||
private uint channel1StartOffset = 32;
|
||||
|
@ -56,6 +69,7 @@ namespace libWiiSharp
|
|||
private ushort channel2LoopNextPreviousValue;
|
||||
private ushort channel2LoopPadding;
|
||||
|
||||
//Public Variables
|
||||
public byte HasLoop
|
||||
{
|
||||
get => this.hasLoop;
|
||||
|
|
22
Brlan.cs
22
Brlan.cs
|
@ -1,8 +1,20 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: libWiiSharp.Brlan
|
||||
// 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
|
||||
/* 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/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
22
Brlyt.cs
22
Brlyt.cs
|
@ -1,8 +1,20 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: libWiiSharp.Brlyt
|
||||
// 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
|
||||
/* 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/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
|
@ -1,8 +1,20 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: libWiiSharp.CertificateChain
|
||||
// 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
|
||||
/* 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/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
|
|
@ -1,8 +1,20 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: libWiiSharp.ColorIndexConverter
|
||||
// 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
|
||||
/* 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/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
<RegisterForComInterop>true</RegisterForComInterop>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
|
@ -34,6 +35,7 @@
|
|||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
<RegisterForComInterop>false</RegisterForComInterop>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>false</SignAssembly>
|
||||
|
@ -93,5 +95,8 @@
|
|||
<Compile Include="zlibWrapper.cs" />
|
||||
<Compile Include="AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include=".gitignore" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
Loading…
Reference in a new issue