mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-22 04:23:09 +00:00
Add support for loading/saving .nkn csv files.
This commit is contained in:
parent
1ccc421eb9
commit
df1989236a
6 changed files with 204 additions and 1 deletions
|
@ -101,7 +101,7 @@ namespace FirstPlugin
|
|||
if (magic == "MCAN") ext = ".bccam";
|
||||
if (magic == "MANM") ext = ".bcskla";
|
||||
if (magic == "MSAS") ext = ".bmsas";
|
||||
if (magic == "MMDL") ext = ".mmdl"; //Original extension is bcmdl but use mmdl for noesis script
|
||||
if (magic == "MMDL") ext = ".bcmdl";
|
||||
if (magic == "MSUR") ext = ".bsmat";
|
||||
if (magic == "MNAV") ext = ".bmscd";
|
||||
if (magic.Contains(" Lua")) ext = ".lc";
|
||||
|
|
96
File_Format_Library/FileFormats/NKN.cs
Normal file
96
File_Format_Library/FileFormats/NKN.cs
Normal file
|
@ -0,0 +1,96 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using Toolbox;
|
||||
using System.Windows.Forms;
|
||||
using Toolbox.Library;
|
||||
using Toolbox.Library.IO;
|
||||
using Toolbox.Library.Forms;
|
||||
using Toolbox.Library.Security.Cryptography;
|
||||
|
||||
namespace FirstPlugin
|
||||
{
|
||||
public class NKN : IEditor<TextEditor>, IFileFormat, IConvertableTextFormat
|
||||
{
|
||||
private readonly string AES_KEY = "au3x5kBAnBbxqsqB";
|
||||
private readonly string AES_IV = "L8bdU63qcwpNYvR7";
|
||||
|
||||
public FileType FileType { get; set; } = FileType.Parameter;
|
||||
|
||||
public bool CanSave { get; set; } = true;
|
||||
public string[] Description { get; set; } = new string[] { "NKN Csv" };
|
||||
public string[] Extension { get; set; } = new string[] { "*.nkn" };
|
||||
public string FileName { get; set; }
|
||||
public string FilePath { get; set; }
|
||||
public IFileInfo IFileInfo { get; set; }
|
||||
|
||||
public bool Identify(System.IO.Stream stream) {
|
||||
return FileName.EndsWith(".nkn");
|
||||
}
|
||||
|
||||
public Type[] Types
|
||||
{
|
||||
get
|
||||
{
|
||||
List<Type> types = new List<Type>();
|
||||
return types.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
private string DecryptedContents;
|
||||
|
||||
public TextEditor OpenForm()
|
||||
{
|
||||
var textEditor = new TextEditor();
|
||||
return textEditor;
|
||||
}
|
||||
|
||||
public void FillEditor(UserControl control)
|
||||
{
|
||||
((TextEditor)control).FileFormat = this;
|
||||
((TextEditor)control).FillEditor(DecryptedContents);
|
||||
((TextEditor)control).TextEditorChanged += delegate
|
||||
{
|
||||
DecryptedContents = ((TextEditor)control).GetText();
|
||||
};
|
||||
}
|
||||
|
||||
#region Text Converter Interface
|
||||
public TextFileType TextFileType => TextFileType.Normal;
|
||||
public bool CanConvertBack => true;
|
||||
|
||||
public string ConvertToString() {
|
||||
return DecryptedContents;
|
||||
}
|
||||
|
||||
public void ConvertFromString(string text) {
|
||||
DecryptedContents = text;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void Load(System.IO.Stream stream)
|
||||
{
|
||||
using (var reader = new BinaryReader(stream)) {
|
||||
byte[] encodedContents = reader.ReadBytes((int)reader.BaseStream.Length);
|
||||
|
||||
AesEncryption.SetKey(AES_KEY);
|
||||
AesEncryption.SetIV(AES_IV);
|
||||
DecryptedContents = AesEncryption.AesDecrypt(encodedContents);
|
||||
}
|
||||
}
|
||||
|
||||
public void Save(System.IO.Stream stream)
|
||||
{
|
||||
using (var writer = new BinaryWriter(stream)) {
|
||||
writer.Write(AesEncryption.AesEncrypt(DecryptedContents));
|
||||
}
|
||||
}
|
||||
|
||||
public void Unload()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -318,6 +318,7 @@
|
|||
<Compile Include="FileFormats\MarioParty\HSF.cs" />
|
||||
<Compile Include="FileFormats\Message\MSYT.cs" />
|
||||
<Compile Include="FileFormats\MKAGPDX\LM2_ARCADE_Model.cs" />
|
||||
<Compile Include="FileFormats\NKN.cs" />
|
||||
<Compile Include="FileFormats\NLG\LM2\LM2_Material.cs" />
|
||||
<Compile Include="FileFormats\NLG\LM3\LM3_ChunkTable.cs" />
|
||||
<Compile Include="FileFormats\NLG\LM3\LM3_DICT.cs" />
|
||||
|
|
|
@ -454,6 +454,7 @@ namespace FirstPlugin
|
|||
Formats.Add(typeof(BNR));
|
||||
Formats.Add(typeof(PKG));
|
||||
Formats.Add(typeof(MTXT));
|
||||
Formats.Add(typeof(NKN));
|
||||
|
||||
|
||||
//Formats.Add(typeof(XLINK_FILE));
|
||||
|
|
104
Switch_Toolbox_Library/Security/Cryptography/AesEncryption.cs
Normal file
104
Switch_Toolbox_Library/Security/Cryptography/AesEncryption.cs
Normal file
|
@ -0,0 +1,104 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Toolbox.Library.Security.Cryptography
|
||||
{
|
||||
public static class AesEncryption
|
||||
{
|
||||
private static byte[] keyBytes;
|
||||
private static byte[] IvBytes;
|
||||
|
||||
static AesEncryption()
|
||||
{
|
||||
keyBytes = UTF8Encoding.UTF8.GetBytes("000000000");
|
||||
IvBytes = UTF8Encoding.UTF8.GetBytes("000000000");
|
||||
}
|
||||
|
||||
public static void SetKey(string key) {
|
||||
keyBytes = UTF8Encoding.UTF8.GetBytes(key);
|
||||
}
|
||||
|
||||
public static void SetIV(string key) {
|
||||
IvBytes = UTF8Encoding.UTF8.GetBytes(key);
|
||||
}
|
||||
|
||||
public static string ByteArrayToHexString(byte[] ba)
|
||||
{
|
||||
return BitConverter.ToString(ba).Replace("-", "");
|
||||
}
|
||||
|
||||
public static byte[] StringToByteArray(string hex)
|
||||
{
|
||||
return Enumerable.Range(0, hex.Length)
|
||||
.Where(x => x % 2 == 0)
|
||||
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public static string DecodeAndDecrypt(string cipherText)
|
||||
{
|
||||
string DecodeAndDecrypt = AesDecrypt(StringToByteArray(cipherText));
|
||||
return (DecodeAndDecrypt);
|
||||
}
|
||||
|
||||
public static string EncryptAndEncode(string plaintext)
|
||||
{
|
||||
return ByteArrayToHexString(AesEncrypt(plaintext));
|
||||
}
|
||||
|
||||
public static string AesDecrypt(Byte[] inputBytes)
|
||||
{
|
||||
Byte[] outputBytes = inputBytes;
|
||||
|
||||
string plaintext = string.Empty;
|
||||
|
||||
using (MemoryStream memoryStream = new MemoryStream(outputBytes))
|
||||
{
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, GetCryptoAlgorithm().CreateDecryptor(keyBytes, IvBytes), CryptoStreamMode.Read))
|
||||
{
|
||||
using (StreamReader srDecrypt = new StreamReader(cryptoStream))
|
||||
{
|
||||
plaintext = srDecrypt.ReadToEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return plaintext;
|
||||
}
|
||||
|
||||
public static byte[] AesEncrypt(string inputText)
|
||||
{
|
||||
byte[] inputBytes = UTF8Encoding.UTF8.GetBytes(inputText);//AbHLlc5uLone0D1q
|
||||
|
||||
byte[] result = null;
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
{
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, GetCryptoAlgorithm().CreateEncryptor(keyBytes, IvBytes), CryptoStreamMode.Write))
|
||||
{
|
||||
cryptoStream.Write(inputBytes, 0, inputBytes.Length);
|
||||
cryptoStream.FlushFinalBlock();
|
||||
|
||||
result = memoryStream.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private static RijndaelManaged GetCryptoAlgorithm()
|
||||
{
|
||||
RijndaelManaged algorithm = new RijndaelManaged();
|
||||
//set the mode, padding and block size
|
||||
algorithm.Padding = PaddingMode.PKCS7;
|
||||
algorithm.Mode = CipherMode.CBC;
|
||||
algorithm.KeySize = 128;
|
||||
algorithm.BlockSize = 128;
|
||||
return algorithm;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -448,6 +448,7 @@
|
|||
<Compile Include="Rendering\DrawableCircle.cs" />
|
||||
<Compile Include="Rendering\GenericModelRenderer\GenericModelRenderer.cs" />
|
||||
<Compile Include="Rendering\GenericModelRenderer\GenericRenderedObject.cs" />
|
||||
<Compile Include="Security\Cryptography\AesEncryption.cs" />
|
||||
<Compile Include="Security\Cryptography\crc32.cs" />
|
||||
<Compile Include="DrawableContainer.cs" />
|
||||
<Compile Include="Security\Cryptography\Crc64.cs" />
|
||||
|
|
Loading…
Reference in a new issue