1
0
mirror of synced 2024-11-12 10:10:50 +01:00
Switch-Toolbox/Switch_Toolbox_Library/Util/Util.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

190 lines
6.5 KiB
C#

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Drawing;
using OpenTK;
namespace Switch_Toolbox.Library
{
public class Utils
{
public static bool IsInDesignMode()
{
if (System.Diagnostics.Process.GetCurrentProcess().ProcessName == "devenv")
return true;
return false;
}
public static string ColorToHex(Color color)
{
return color.R.ToString("X2") +
color.G.ToString("X2") +
color.B.ToString("X2") +
color.A.ToString("X2");
}
public static int FloatToIntClamp(float r)
{
return Clamp((int)(r * 255), 0, 255);
}
public static T Clamp<T>(T val, T min, T max) where T : IComparable<T>
{
if (val.CompareTo(min) < 0) return min;
else if (val.CompareTo(max) > 0) return max;
else return val;
}
public static string AddQuotesIfRequired(string path)
{
return !string.IsNullOrWhiteSpace(path) ?
path.Contains(" ") && (!path.StartsWith("\"") && !path.EndsWith("\"")) ?
"\"" + path + "\"" : path :
string.Empty;
}
public static string GetExtension(string FileName)
{
return Path.GetExtension(FileName).ToLower();
}
public static bool HasExtension(string FileName, string Extension)
{
return FileName.EndsWith(Extension, StringComparison.Ordinal);
}
public static Vector2 ToVec2(float[] v)
{
return new Vector2(v[0], v[1]);
}
public static Vector3 ToVec3(float[] v)
{
return new Vector3(v[0], v[1], v[2]);
}
public static Vector4 ToVec4(float[] v)
{
return new Vector4(v[0], v[1], v[2], v[3]);
}
public static Vector2 ToVec2(Syroot.Maths.Vector2F v)
{
return new Vector2(v.X, v.Y);
}
public static Vector3 ToVec3(Syroot.Maths.Vector3F v)
{
return new Vector3(v.X, v.Y, v.Z);
}
public static Vector4 ToVec4(Syroot.Maths.Vector4F v)
{
return new Vector4(v.X, v.Y, v.Z, v.W);
}
public static byte[] CombineByteArray(params byte[][] arrays)
{
byte[] rv = new byte[arrays.Sum(a => a.Length)];
int offset = 0;
foreach (byte[] array in arrays)
{
System.Buffer.BlockCopy(array, 0, rv, offset, array.Length);
offset += array.Length;
}
return rv;
}
public static byte[] SubArray(byte[] data, uint offset, uint length)
{
return data.Skip((int)offset).Take((int)length).ToArray();
}
static int i = 0;
public static string RenameDuplicateString(List<string> strings, string oldString)
{
i = 0;
foreach (string s in strings)
{
if (strings.Contains(oldString))
{
oldString += i.ToString();
if (strings.Contains(oldString))
RenameDuplicateString(strings, oldString);
else
return oldString;
}
}
return oldString;
}
public static T DeepCopy<T>(T other)
{
using (MemoryStream ms = new MemoryStream())
{
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(ms, other);
ms.Position = 0;
return (T)formatter.Deserialize(ms);
}
}
public static Matrix4 TransformValues(Vector3 translation, Vector3 rotation, float scale)
{
return TransformValues(translation, rotation, new Vector3(scale));
}
public static Matrix4 TransformValues(Vector3 translation, Vector3 rotation, Vector3 scale)
{
Matrix4 positionMat = Matrix4.CreateTranslation(translation);
Matrix4 rotXMat = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(rotation.X));
Matrix4 rotYMat = Matrix4.CreateRotationY(MathHelper.DegreesToRadians(rotation.Y));
Matrix4 rotZMat = Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(rotation.Z));
Matrix4 scaleMat = Matrix4.CreateScale(scale);
return scaleMat * (rotXMat * rotYMat * rotZMat) * positionMat;
}
public static string GenerateUniqueHashID()
{
return Guid.NewGuid().ToString();
}
public static string GetAllFilters(IFileFormat format)
{
List<IFileFormat> f = new List<IFileFormat>();
f.Add(format);
return GetAllFilters(f);
}
public static string GetAllFilters(IEnumerable<IFileFormat> format)
{
var alltypes = format;
string Filter = "All Supported Files|";
List<string> FilterEach = new List<string>();
foreach (IFileFormat f in format)
{
for (int i = 0; i < f.Extension.Length; i++)
{
Filter += $"{f.Extension[i]};";
FilterEach.Add($"{f.Description[0]} ({f.Extension[i]}) |{f.Extension[i]}|");
}
}
Filter += $"{"*.z"};";
Filter += $"{"*.cmp"};";
Filter += $"{"*.yaz0"};";
Filter += $"{"*.zstb"};";
Filter += $"{"*.lz4"};";
Filter += $"{"*.gz"};";
Filter += $"{"*.szs"};";
Filter += $"{"*.yaz0"};";
FilterEach.Add($"{"Compressed File"} ({"*.cmp"}) |{"*.cmp"}|");
FilterEach.Add($"{"Zlib Compressed"} ({"*.z"}) |{"*.z"}|");
FilterEach.Add($"{"Yaz0 Compressed"} ({"*.yaz0"}) |{"*.yaz0"}|");
FilterEach.Add($"{"Zstb Compressed"} ({"*.zstb"}) |{"*.zstb"}|");
FilterEach.Add($"{"Lz4 Compressed"} ({"*.lz4"}) |{"*.lz4"}|");
FilterEach.Add($"{"GZIP Compressed"} ({"*.gz"}) |{"*.gz"}|");
FilterEach.Add($"{"SZS Yaz0 Compressed"} ({"*.szs"}) |{"*.szs"}|");
FilterEach.Add($"{"Yaz0 Compressed"} ({"*.yaz0"}) |{"*.yaz0"}|");
Filter += "|";
Filter += string.Join("", FilterEach.ToArray());
Filter += "All files(*.*)|*.*";
return Filter;
}
}
}