1
0
mirror of synced 2024-12-13 00:01:13 +01:00
Switch-Toolbox/Switch_Toolbox_Library/IO/DWord.cs
KillzXGaming d1f03b161f Add files for the new one.
Rework UI from scratch with proper themes and custom controls. MDI windows are now used for workspaces, comparing docs, and multiple usages. Tabs organise multiple workspaces and you can keep mdi windows maximized if you want to only use tabs. Themes currently include dark and white theme but plan to have XML files with list of color and styles
Alot of things optimized. UI is very fast and snappy now
Dae rigging fixed.
Dae bones can be imported.
Dae with textures can be imported and exported to a folder
Custom sampler editor for sampler data.
Texture refs, shader options, params, render info, and basically all material data can be added/removed and edited
User data editor
Update opengl framework by JuPaHe64 to the newest. Includes an origintation cube, multiple models in a scene, and many improvements
Skeleton can be viewed
GFPAK with some fixes in saving
NUTEXB has proper mip map viewing
PTCL Editor (Wii U and Switch). Can edit colors ( Wii U) and view textures. Also EFFN files in smash ultimate can be previewed
Files can be associated with the program and opened with on clicking them
ASTC textures can be viewed
UVs can be viewed. Includes wrap modes and also translating and scaling for some basic edits
Textures use a new editor. It includes channel viewing and some new editing options
Fixed black textures on some wii u bfres
Fixed saving sarcs in sarcs
Shortcut keys have been added in. CTRL + S can save the active file in the currently used window
Fix more issues with bfres crashing
File - New includes BNTX for creating new bntx files from scatch
Raw shader binaries can be extracted from bnsh and bfsha. Yuzu and Ryujinx can decompile these
Sharc files can have source data previewed and shader programs in XML
Aamp v1 and v2 data can be previewed. v1 can be edited and saved atm, v2 will be at a later update
Byaml uses it's own editor instead of a seperate window for easy saving within sarcs
Archives have a hex viewer
Dae exporting greatly improved and can export rigged meshes
Scene, shader param, srt, color, and texture pattern animations can all be previewed (in a list)
Memory usage is greatly improved
Narc (Nitro Archives) can be viewed and extracted.
Fixed importing TGA images
Support importing ASTC textures for bntx
Added in PBR lighting for bfres from my implimentaion in forge
Added gradient background for viewport. This can be edited in the settings
Added skybox background option for viewport. Can load cubemaps
Added grid with customizable cells for viewport.
DDS decompression no longer requires Direct X tex.
Zlib decompression has been improved for opening files that use it
Rigid bones are properly ordered on importing a mesh. May fix some exploding issues.
Endianness for KCL can be toggled for saving. Will be set to what it was using orignally
Tangents can be filled with a constant value. Will allow them to not cause seams nor flat lighting however normal maps may not work as good
Vertex buffers can be added and removed. Also re encoded
Parameters now use drop down panels with values for easier editing
Reworked the bone editor. Everything for a bone can be fully edited now besides the index, billboard index and parent index  which get set automatically
Fixed animation scaling for skeletal animations finally!
Textures can be loaded in a tab now with thumbnail displaying for easy real time edits while previewing in the viewport

Fixed support for audio files to be big endian in BARS
Textures for switch now use their own folder. You can easily add textures to this and add textures to bfres that have no bntx. If there are no textures then the bfres will automatically not have one on save.
Animations are split into multiple sub sections for switch's material animation for easier access
Bfres for wii u has better binary exporting and is fully compatiable with Wexos Toolbox (to and from)
Every section can be added in as new for both wii u and switch.
Every section can be renamed properly and mostly everything can be edited. (Key frame editing and a more in depth curve editor later)
Added option to copy UV channel
Bone weights can be previewed
Tons of fixes for the switch bfres library with more games working. Splatoon 2 (more work now), BOTW, Kirby Star Allies, and more!
Fixed 3.3 Wii U bfres from not opening
Wii U Sharcfb files can have shader program data previewed (XML)

And possibly alot more things i missed! All this is still experimental but will improve over the next few weeks
2019-03-23 12:55:09 -04:00

272 lines
10 KiB
C#

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace Switch_Toolbox.Library.IO
{
/// <summary>
/// Represents a 4-byte value which can hold differently typed data.
/// </summary>
[DebuggerDisplay("{" + nameof(Int32) + "} / {" + nameof(Single) + "}")]
[StructLayout(LayoutKind.Explicit)]
public struct DWord : IConvertible
{
// ---- FIELDS -------------------------------------------------------------------------------------------------
/// <summary>
/// The data as an <see cref="Int32"/>.
/// </summary>
[FieldOffset(0)]
public Int32 Int32;
/// <summary>
/// The data as a <see cref="Single"/>.
/// </summary>
[FieldOffset(0)]
public Single Single;
/// <summary>
/// The data as an <see cref="UInt32"/>.
/// </summary>
[FieldOffset(0)]
public UInt32 UInt32;
// ---- OPERATORS ----------------------------------------------------------------------------------------------
/// <summary>
/// Converts the given <paramref name="value"/> value to a <see cref="DWord"/> instance.
/// </summary>
/// <param name="value">The <see cref="Int32"/> value to represent in the new <see cref="DWord"/> instance.
/// </param>
public static implicit operator DWord(int value)
{
return new DWord() { Int32 = value };
}
/// <summary>
/// Converts the given <paramref name="value"/> value to a <see cref="DWord"/> instance.
/// </summary>
/// <param name="value">The <see cref="Single"/> value to represent in the new <see cref="DWord"/> instance.
/// </param>
public static implicit operator DWord(float value)
{
return new DWord() { Single = value };
}
/// <summary>
/// Converts the given <paramref name="value"/> value to a <see cref="DWord"/> instance.
/// </summary>
/// <param name="value">The <see cref="UInt32"/> value to represent in the new <see cref="DWord"/> instance.
/// </param>
public static implicit operator DWord(uint value)
{
return new DWord() { UInt32 = value };
}
/// <summary>
/// Converts the given <paramref name="value"/> value to an <see cref="Int32"/> instance.
/// </summary>
/// <param name="value">The <see cref="DWord"/> value to represent in the new <see cref="Int32"/> instance.
/// </param>
public static implicit operator int(DWord value)
{
return value.Int32;
}
/// <summary>
/// Converts the given <paramref name="value"/> value to a <see cref="Single"/> instance.
/// </summary>
/// <param name="value">The <see cref="DWord"/> value to represent in the new <see cref="Single"/> instance.
/// </param>
public static implicit operator float(DWord value)
{
return value.Single;
}
/// <summary>
/// Converts the given <paramref name="value"/> value to an <see cref="UInt32"/> instance.
/// </summary>
/// <param name="value">The <see cref="DWord"/> value to represent in the new <see cref="UInt32"/> instance.
/// </param>
public static implicit operator uint(DWord value)
{
return value.UInt32;
}
// ---- METHODS (PUBLIC) ---------------------------------------------------------------------------------------
/// <summary>
/// Returns the <see cref="TypeCode"/> for this instance.
/// </summary>
/// <returns>The enumerated constant that is the <see cref="TypeCode"/> of the class or value type that
/// implements this interface.</returns>
public TypeCode GetTypeCode()
{
// These are sadly not flags, so just return the value for Int32 at least.
return TypeCode.Int32;
}
/// <summary>
/// This operation is not supported.
/// </summary>
public bool ToBoolean(IFormatProvider provider)
{
throw new InvalidOperationException($"Cannot convert {nameof(DWord)} to type {typeof(bool)}.");
}
/// <summary>
/// This operation is not supported.
/// </summary>
public byte ToByte(IFormatProvider provider)
{
throw new InvalidOperationException($"Cannot convert {nameof(DWord)} to type {typeof(byte)}.");
}
/// <summary>
/// This operation is not supported.
/// </summary>
public char ToChar(IFormatProvider provider)
{
throw new InvalidOperationException($"Cannot convert {nameof(DWord)} to type {typeof(char)}.");
}
/// <summary>
/// This operation is not supported.
/// </summary>
public DateTime ToDateTime(IFormatProvider provider)
{
throw new InvalidOperationException($"Cannot convert {nameof(DWord)} to type {typeof(DateTime)}.");
}
/// <summary>
/// This operation is not supported.
/// </summary>
public decimal ToDecimal(IFormatProvider provider)
{
throw new InvalidOperationException($"Cannot convert {nameof(DWord)} to type {typeof(decimal)}.");
}
/// <summary>
/// Converts the value of this instance to an equivalent double-precision floating-point number using the
/// specified culture-specific formatting information.
/// </summary>
/// <param name="provider">An <see cref="IFormatProvider"/> interface implementation that supplies
/// culture-specific formatting information.</param>
/// <returns>A double-precision floating-point number equivalent to the value of this instance.</returns>
public double ToDouble(IFormatProvider provider)
{
return Single;
}
/// <summary>
/// This operation is not supported.
/// </summary>
public short ToInt16(IFormatProvider provider)
{
throw new InvalidOperationException($"Cannot convert {nameof(DWord)} to type {typeof(short)}.");
}
/// <summary>
/// Converts the value of this instance to an equivalent 32-bit signed integer using the specified
/// culture-specific formatting information.
/// </summary>
/// <param name="provider">An <see cref="IFormatProvider"/> interface implementation that supplies
/// culture-specific formatting information.</param>
/// <returns>An 32-bit signed integer equivalent to the value of this instance.</returns>
public int ToInt32(IFormatProvider provider)
{
return Int32;
}
/// <summary>
/// Converts the value of this instance to an equivalent 64-bit signed integer using the specified
/// culture-specific formatting information.
/// </summary>
/// <param name="provider">An <see cref="IFormatProvider"/> interface implementation that supplies
/// culture-specific formatting information.</param>
/// <returns>An 64-bit signed integer equivalent to the value of this instance.</returns>
public long ToInt64(IFormatProvider provider)
{
return Int32;
}
/// <summary>
/// This operation is not supported.
/// </summary>
public sbyte ToSByte(IFormatProvider provider)
{
throw new InvalidOperationException($"Cannot convert {nameof(DWord)} to type {nameof(String)}.");
}
/// <summary>
/// Converts the value of this instance to an equivalent single-precision floating-point number using the
/// specified culture-specific formatting information.
/// </summary>
/// <param name="provider">An <see cref="IFormatProvider"/> interface implementation that supplies
/// culture-specific formatting information.</param>
/// <returns>A single-precision floating-point number equivalent to the value of this instance.</returns>
public float ToSingle(IFormatProvider provider)
{
return Single;
}
/// <summary>
/// This operation is not supported.
/// </summary>
public string ToString(IFormatProvider provider)
{
throw new InvalidOperationException($"Cannot convert {nameof(DWord)} to type {nameof(String)}.");
}
/// <summary>
/// Converts the value of this instance to an <see cref="Object"/> of the specified <see cref="Type"/> that has
/// an equivalent value, using the specified culture-specific formatting information.
/// </summary>
/// <param name="conversionType">The <see cref="Type"/> to which the value of this instance is converted.
/// </param>
/// <param name="provider">An <see cref="IFormatProvider"/> interface implementation that supplies
/// culture-specific formatting information.</param>
/// <returns>An <see cref="Object"/> instance of type conversionType whose value is equivalent to the value of
/// this instance.</returns>
public object ToType(Type conversionType, IFormatProvider provider)
{
if (conversionType == typeof(Int32) || conversionType == typeof(Int64))
{
return Int32;
}
else if (conversionType == typeof(Single) || conversionType == typeof(Double))
{
return Single;
}
else
{
throw new ArgumentException($"Cannot convert {nameof(DWord)} to type {conversionType}.");
}
}
/// <summary>
/// This operation is not supported.
/// </summary>
public ushort ToUInt16(IFormatProvider provider)
{
throw new InvalidOperationException($"Cannot convert {nameof(DWord)} to type {nameof(UInt16)}.");
}
/// <summary>
/// This operation is not supported.
/// </summary>
public uint ToUInt32(IFormatProvider provider)
{
return UInt32;
}
/// <summary>
/// This operation is not supported.
/// </summary>
public ulong ToUInt64(IFormatProvider provider)
{
throw new InvalidOperationException($"Cannot convert {nameof(DWord)} to type {nameof(UInt64)}.");
}
}
}