1
0
mirror of synced 2025-02-20 12:41:10 +01:00

Alot of clean up.

This commit is contained in:
KillzXGaming 2018-12-02 17:30:46 -05:00
parent 785f5657b2
commit 307a8832c5
45 changed files with 1517 additions and 1601 deletions

View File

@ -20,7 +20,6 @@ namespace FirstPlugin
public CompressionType CompressionType { get; set; } = CompressionType.None;
public byte[] Data { get; set; }
public string FileName { get; set; }
public TreeNodeFile EditorRoot { get; set; }
public bool IsActive { get; set; } = false;
public bool UseEditMenu { get; set; } = false;
public int Alignment { get; set; } = 0;

View File

@ -16,7 +16,7 @@ using NAudio.Wave;
namespace FirstPlugin
{
public class BARS : IFileFormat
public class BARS : TreeNodeFile, IFileFormat
{
public bool CanSave { get; set; } = false;
public bool FileIsEdited { get; set; } = false;
@ -27,7 +27,6 @@ namespace FirstPlugin
public CompressionType CompressionType { get; set; } = CompressionType.None;
public byte[] Data { get; set; }
public string FileName { get; set; }
public TreeNodeFile EditorRoot { get; set; }
public bool IsActive { get; set; } = false;
public bool UseEditMenu { get; set; } = false;
public int Alignment { get; set; } = 0;
@ -165,15 +164,16 @@ namespace FirstPlugin
IsActive = true;
CanSave = true;
Text = FileName;
bars = new BarsLib.BARS(new MemoryStream(Data));
EditorRoot = new TreeNodeFile(FileName, this);
EditorRoot.Nodes.Add("AMTA");
EditorRoot.Nodes.Add("Audio");
Nodes.Add("AMTA");
Nodes.Add("Audio");
for (int i = 0; i < bars.AmtaList.Count; i++)
{
string audioName = bars.AmtaList[i].Name;
EditorRoot.Nodes[0].Nodes.Add(audioName + ".amta");
Nodes[0].Nodes.Add(audioName + ".amta");
BARSAudioFile audio = bars.audioList[i];
AudioEntry node = new AudioEntry();
@ -188,7 +188,7 @@ namespace FirstPlugin
else
node.Text = audioName + ".UNKOWN";
EditorRoot.Nodes[1].Nodes.Add(node);
Nodes[1].Nodes.Add(node);
}
}
public void Unload()
@ -199,7 +199,7 @@ namespace FirstPlugin
{
MemoryStream mem = new MemoryStream();
foreach (TreeNode node in EditorRoot.Nodes[1].Nodes)
foreach (TreeNode node in Nodes[1].Nodes)
{
for (int i = 0; i < bars.AmtaList.Count; i++)
{

View File

@ -14,7 +14,7 @@ using Switch_Toolbox.Library.Forms;
namespace FirstPlugin
{
public class BEA : IFileFormat
public class BEA : TreeNode, IFileFormat
{
public bool CanSave { get; set; } = false;
public bool FileIsEdited { get; set; } = false;
@ -25,7 +25,6 @@ namespace FirstPlugin
public CompressionType CompressionType { get; set; } = CompressionType.None;
public byte[] Data { get; set; }
public string FileName { get; set; }
public TreeNodeFile EditorRoot { get; set; }
public bool IsActive { get; set; } = false;
public bool UseEditMenu { get; set; } = false;
public int Alignment { get; set; } = 0;
@ -115,14 +114,13 @@ namespace FirstPlugin
public void Load()
{
Text = FileName;
IsActive = true;
CanSave = true;
beaFile = new BezelEngineArchive(new MemoryStream(Data));
EditorRoot = new RootNode(Path.GetFileName(FileName), this);
TreeNode root = EditorRoot;
FillTreeNodes(root, beaFile.FileList);
FillTreeNodes(this, beaFile.FileList);
}
public void Unload()
{
@ -141,7 +139,7 @@ namespace FirstPlugin
}
public byte[] Save()
{
foreach (TreeNode node in Collect(EditorRoot.Nodes))
foreach (TreeNode node in Collect(Nodes))
{
if (node is FileEntry)
{
@ -165,7 +163,6 @@ namespace FirstPlugin
public RootNode(string n, IFileFormat format)
{
Text = n;
FileHandler = format;
ContextMenu = new ContextMenu();
MenuItem previewFiles = new MenuItem("Preview Window");
@ -313,11 +310,13 @@ namespace FirstPlugin
format.Load();
format.FilePath = FileName;
if (format.EditorRoot != null)
if (format is TreeNode)
{
format.EditorRoot.Text = Text;
format.EditorRoot.ImageKey = ImageKey;
format.EditorRoot.SelectedImageKey = SelectedImageKey;
((TreeNode)format).Text = Text;
((TreeNode)format).ImageKey = ImageKey;
((TreeNode)format).SelectedImageKey = SelectedImageKey;
Nodes.Add(((TreeNode)format));
}
}
if (format.Magic == String.Empty) //Load by extension if magic isn't defined
@ -447,13 +446,13 @@ namespace FirstPlugin
format.Load();
format.FilePath = FileName;
if (format.EditorRoot != null)
if (format is TreeNode)
{
format.EditorRoot.Text = Text;
format.EditorRoot.ImageKey = ImageKey;
format.EditorRoot.SelectedImageKey = SelectedImageKey;
((TreeNode)format).Text = Text;
((TreeNode)format).ImageKey = ImageKey;
((TreeNode)format).SelectedImageKey = SelectedImageKey;
Nodes.Add(format.EditorRoot);
Nodes.Add(((TreeNode)format));
}
}
if (format.Magic == String.Empty) //Load by extension if magic isn't defined

View File

@ -11,7 +11,7 @@ using Switch_Toolbox.Library.IO;
namespace FirstPlugin
{
public class BFFNT : IFileFormat
public class BFFNT : TreeNode, IFileFormat
{
public bool CanSave { get; set; } = false;
public bool FileIsEdited { get; set; } = false;
@ -22,7 +22,6 @@ namespace FirstPlugin
public CompressionType CompressionType { get; set; } = CompressionType.None;
public byte[] Data { get; set; }
public string FileName { get; set; }
public TreeNodeFile EditorRoot { get; set; }
public bool IsActive { get; set; } = false;
public bool UseEditMenu { get; set; } = false;
public int Alignment { get; set; } = 0;
@ -46,16 +45,12 @@ namespace FirstPlugin
TGLP tglp = bffnt.finf.tglp;
EditorRoot = new TreeNodeFile(FileName, this);
int i = 0;
foreach (byte[] texture in tglp.SheetDataList)
{
SheetEntry sheet = new SheetEntry();
sheet.data = texture;
sheet.Text = "Sheet" + i++;
EditorRoot.Nodes.Add(sheet);
}
}
public void Unload()

View File

@ -20,7 +20,6 @@ namespace FirstPlugin
public CompressionType CompressionType { get; set; } = CompressionType.None;
public byte[] Data { get; set; }
public string FileName { get; set; }
public TreeNodeFile EditorRoot { get; set; }
public bool IsActive { get; set; } = false;
public bool UseEditMenu { get; set; } = false;
public int Alignment { get; set; } = 0;

View File

@ -20,7 +20,6 @@ namespace FirstPlugin
public CompressionType CompressionType { get; set; } = CompressionType.None;
public byte[] Data { get; set; }
public string FileName { get; set; }
public TreeNodeFile EditorRoot { get; set; }
public bool IsActive { get; set; } = false;
public bool UseEditMenu { get; set; } = false;
public int Alignment { get; set; } = 0;

View File

@ -9,11 +9,16 @@ using Switch_Toolbox.Library;
using Switch_Toolbox.Library.Forms;
using Switch_Toolbox.Library.IO;
using Bfres.Structs;
using ResU = Syroot.NintenTools.Bfres;
using Syroot.NintenTools.NSW.Bfres;
namespace FirstPlugin
{
public class BFRES : IFileFormat
public class BFRES : TreeNodeFile, IFileFormat
{
private static BFRES _instance;
public static BFRES Instance { get { return _instance == null ? _instance = new BFRES() : _instance; } }
public bool CanSave { get; set; } = false;
public bool FileIsEdited { get; set; } = false;
public bool FileIsCompressed { get; set; } = false;
@ -34,19 +39,274 @@ namespace FirstPlugin
}
}
private TreeNodeFile eitorRoot;
public TreeNodeFile EditorRoot
public bool IsActive { get; set; } = false;
public bool UseEditMenu { get; set; } = false;
public int Alignment { get; set; } = 0;
public string FilePath { get; set; }
private bool isWiiU;
public bool IsWiiU
{
get
{
return eitorRoot;
}
set
{
this.eitorRoot = value;
if (Data == null)
return false;
if (isWiiU)
return true;
using (FileReader reader = new FileReader(new MemoryStream(Data)))
{
reader.Seek(4);
if (reader.ReadInt32() != 0x20202020)
{
return true;
}
else
return false;
}
}
}
public void SaveFile()
public BFRESRender BFRESRender;
public void Load()
{
IsActive = true;
CanSave = true;
ImageKey = "bfres";
SelectedImageKey = "bfres";
ContextMenu = new ContextMenu();
MenuItem save = new MenuItem("Save");
ContextMenu.MenuItems.Add(save);
save.Click += Save;
MenuItem newMenu = new MenuItem("New");
MenuItem import = new MenuItem("Import");
// ContextMenu.MenuItems.Add(newMenu);
// ContextMenu.MenuItems.Add(import);
MenuItem rename = new MenuItem("Rename");
ContextMenu.MenuItems.Add(rename);
rename.Click += Rename;
MenuItem remove = new MenuItem("Remove");
ContextMenu.MenuItems.Add(remove);
remove.Click += Remove;
if (Parent == null)
remove.Enabled = false;
if (IsWiiU)
{
}
else
{
MenuItem model = new MenuItem("Model");
MenuItem fska = new MenuItem("Skeletal Animation");
MenuItem fmaa = new MenuItem("Material Animation");
MenuItem bonevis = new MenuItem("Bone Visual Animation");
MenuItem shape = new MenuItem("Shape Animation");
MenuItem scene = new MenuItem("Scene Animation");
MenuItem embedded = new MenuItem("Embedded File");
MenuItem texture = new MenuItem("Texture File");
texture.Click += NewTextureFile;
newMenu.MenuItems.Add(model);
newMenu.MenuItems.Add(fska);
newMenu.MenuItems.Add(fmaa);
newMenu.MenuItems.Add(bonevis);
newMenu.MenuItems.Add(shape);
newMenu.MenuItems.Add(scene);
newMenu.MenuItems.Add(embedded);
newMenu.MenuItems.Add(texture);
MenuItem importmodel = new MenuItem("Model");
MenuItem importfska = new MenuItem("Skeletal Animation");
MenuItem importfmaa = new MenuItem("Material Animation");
MenuItem importbonevis = new MenuItem("Bone Visual Animation");
MenuItem importshape = new MenuItem("Shape Animation");
MenuItem importscene = new MenuItem("Scene Animation");
MenuItem importembedded = new MenuItem("Embedded File");
MenuItem importtexture = new MenuItem("Texture File");
import.MenuItems.Add(importmodel);
import.MenuItems.Add(importfska);
import.MenuItems.Add(importfmaa);
import.MenuItems.Add(importbonevis);
import.MenuItems.Add(importshape);
import.MenuItems.Add(importscene);
import.MenuItems.Add(importembedded);
import.MenuItems.Add(importtexture);
}
BFRESRender = new BFRESRender();
BFRESRender.ResFileNode = this;
if (IsWiiU)
{
BFRESRender.LoadFile(new Syroot.NintenTools.Bfres.ResFile(new System.IO.MemoryStream(Data)));
}
else
{
BFRESRender.LoadFile(new Syroot.NintenTools.NSW.Bfres.ResFile(new System.IO.MemoryStream(Data)));
}
Runtime.abstractGlDrawables.Add(BFRESRender);
}
public void Unload()
{
BFRESRender.Destroy();
BFRESRender.ResFileNode.Nodes.Clear();
}
public byte[] Save()
{
MemoryStream mem = new MemoryStream();
if (IsWiiU)
SaveWiiU(mem);
else
SaveSwitch(mem);
return mem.ToArray();
}
public ResFile resFile = null;
public ResU.ResFile resFileU = null;
public TreeNode TextureFolder = new TreeNode("Textures");
public override void OnClick(TreeView treeView)
{
//If has models
if (Nodes.ContainsKey("FMDL"))
{
LibraryGUI.Instance.LoadViewport(Viewport.Instance);
Viewport.Instance.gL_ControlModern1.MainDrawable = BFRESRender;
BFRESRender.UpdateVertexData();
}
}
public void Load(ResU.ResFile res)
{
resFileU = res;
Text = resFileU.Name;
if (resFileU.Models.Count > 0)
Nodes.Add(new FmdlFolder());
if (resFileU.Textures.Count > 0)
AddFTEXTextures(resFileU);
if (resFileU.SkeletalAnims.Count > 0)
AddSkeletonAnims(resFileU);
if (resFileU.ShaderParamAnims.Count > 0)
Nodes.Add(new FshuFolder());
if (resFileU.ColorAnims.Count > 0)
Nodes.Add(new FshuColorFolder());
if (resFileU.TexSrtAnims.Count > 0)
Nodes.Add(new TexSrtFolder());
if (resFileU.TexPatternAnims.Count > 0)
Nodes.Add(new TexPatFolder());
if (resFileU.ShapeAnims.Count > 0)
Nodes.Add(new FshpaFolder());
if (resFileU.BoneVisibilityAnims.Count > 0)
Nodes.Add(new FbnvFolder());
if (resFileU.SceneAnims.Count > 0)
Nodes.Add(new FscnFolder());
if (resFileU.ExternalFiles.Count > 0)
Nodes.Add(new EmbeddedFilesFolder());
foreach (var anim in resFileU.ShaderParamAnims)
Nodes["FSHA"].Nodes.Add(anim.Key);
foreach (var anim in resFileU.ColorAnims)
Nodes["FSHAColor"].Nodes.Add(anim.Key);
foreach (var anim in resFileU.TexSrtAnims)
Nodes["TEXSRT"].Nodes.Add(anim.Key);
foreach (var anim in resFileU.TexPatternAnims)
Nodes["TEXPAT"].Nodes.Add(anim.Key);
int ext = 0;
foreach (var extfile in resFileU.ExternalFiles)
{
string Name = extfile.Key;
FileReader f = new FileReader(extfile.Value.Data);
string Magic = f.ReadMagic(0, 4);
if (Magic == "FSHA")
{
Nodes["EXT"].Nodes.Add(new BfshaFileData(extfile.Value.Data, Name));
}
else
Nodes["EXT"].Nodes.Add(new ExternalFileData(extfile.Value.Data, Name));
f.Dispose();
f.Close();
ext++;
}
}
public void Load(ResFile res)
{
resFile = res;
Text = resFile.Name;
UpdateTree(resFile);
foreach (ShapeAnim anim in resFile.ShapeAnims)
Nodes["FSHPA"].Nodes.Add(anim.Name);
foreach (VisibilityAnim anim in resFile.BoneVisibilityAnims)
Nodes["FBNV"].Nodes.Add(anim.Name);
int ext = 0;
foreach (ExternalFile extfile in resFile.ExternalFiles)
{
string Name = resFile.ExternalFileDict.GetKey(ext);
FileReader f = new FileReader(extfile.Data);
string Magic = f.ReadMagic(0, 4);
if (Magic == "BNTX")
{
BNTX bntx = new BNTX();
bntx.Data = extfile.Data;
bntx.FileName = Name;
bntx.Load();
bntx.IFileInfo.InArchive = true;
Nodes["EXT"].Nodes.Add(bntx);
}
else if (Magic == "FSHA")
{
Nodes["EXT"].Nodes.Add(new BfshaFileData(extfile.Data, Name));
}
else
Nodes["EXT"].Nodes.Add(new ExternalFileData(extfile.Data, Name));
f.Dispose();
f.Close();
ext++;
}
}
private void NewTextureFile(object sender, EventArgs args)
{
string Name = "textures";
for (int i = 0; i < resFile.ExternalFiles.Count; i++)
{
if (resFile.ExternalFileDict.GetKey(i) == Name)
Name = Name + i;
}
if (!Nodes.ContainsKey("EXT"))
{
Nodes.Add(new EmbeddedFilesFolder());
}
BNTX bntx = new BNTX();
bntx.Data = new byte[0];
bntx.FileName = "textures";
Nodes["EXT"].Nodes.Add(bntx);
}
private void NewEmbeddedFile(object sender, EventArgs args)
{
}
private void Save(object sender, EventArgs args)
{
List<IFileFormat> formats = new List<IFileFormat>();
formats.Add(this);
@ -61,6 +321,127 @@ namespace FirstPlugin
SaveCompressFile(Save(), sfd.FileName, Alignment);
}
}
private void Rename(object sender, EventArgs args)
{
RenameDialog dialog = new RenameDialog();
dialog.SetString(Text);
if (dialog.ShowDialog() == DialogResult.OK)
{
Text = dialog.textBox1.Text;
}
}
private void Remove(object sender, EventArgs args)
{
BFRESRender.DisposeFile();
}
private void UpdateTree(ResFile resFile)
{
if (resFile.Models.Count > 0)
Nodes.Add(new FmdlFolder());
if (resFile.SkeletalAnims.Count > 0)
AddSkeletonAnims(resFile);
if (resFile.MaterialAnims.Count > 0)
AddMaterialAnims(resFile);
if (resFile.ShapeAnims.Count > 0)
AddShapeAnims(resFile);
if (resFile.BoneVisibilityAnims.Count > 0)
AddBoneVisAnims(resFile);
if (resFile.SceneAnims.Count > 0)
AddSceneAnims(resFile);
if (resFile.ExternalFiles.Count > 0)
Nodes.Add(new EmbeddedFilesFolder());
}
private void AddFTEXTextures(ResU.ResFile resFile)
{
FTEXContainer ftexContainer = new FTEXContainer();
Nodes.Add(ftexContainer);
foreach (ResU.Texture tex in resFile.Textures.Values)
{
string TextureName = tex.Name;
FTEX texture = new FTEX();
texture.Read(tex);
ftexContainer.Nodes.Add(texture);
ftexContainer.Textures.Add(texture.Text, texture);
}
PluginRuntime.ftexContainers.Add(ftexContainer);
}
private void AddSkeletonAnims(ResU.ResFile resFile)
{
FskaFolder fksaFolder = new FskaFolder();
Nodes.Add(fksaFolder);
foreach (ResU.SkeletalAnim ska in resFile.SkeletalAnims.Values)
{
BfresSkeletonAnim skeletonAnim = new BfresSkeletonAnim(ska.Name);
skeletonAnim.Read(ska, resFile);
fksaFolder.Nodes.Add(skeletonAnim);
}
}
private void AddSkeletonAnims(ResFile resFile)
{
FskaFolder fksaFolder = new FskaFolder();
Nodes.Add(fksaFolder);
foreach (SkeletalAnim ska in resFile.SkeletalAnims)
{
BfresSkeletonAnim skeletonAnim = new BfresSkeletonAnim(ska.Name);
skeletonAnim.Read(ska, resFile);
fksaFolder.Nodes.Add(skeletonAnim);
}
}
private void AddSceneAnims(ResU.ResFile resFile)
{
FscnFolder FSCN = new FscnFolder();
Nodes.Add(FSCN);
}
private void AddSceneAnims(ResFile resFile)
{
FscnFolder fscnFolder = new FscnFolder();
Nodes.Add(fscnFolder);
foreach (var scn in resFile.SceneAnims)
{
FSCN sceneAnim = new FSCN();
sceneAnim.Text = scn.Name;
sceneAnim.Read(scn);
fscnFolder.Nodes.Add(sceneAnim);
}
}
private void AddMaterialAnims(ResFile resFile)
{
FmaaFolder fmaaFolder = new FmaaFolder();
Nodes.Add(fmaaFolder);
foreach (var fmaa in resFile.MaterialAnims)
{
FMAA materialAnim = new FMAA();
materialAnim.Text = fmaa.Name;
materialAnim.BFRESRender = BFRESRender;
materialAnim.Read(fmaa);
fmaaFolder.Nodes.Add(materialAnim);
}
}
private void AddShapeAnims(ResFile resFile)
{
FshpaFolder fshaFolder = new FshpaFolder();
Nodes.Add(fshaFolder);
foreach (var fsha in resFile.ShapeAnims)
{
FSHA shapeAnim = new FSHA();
shapeAnim.Text = fsha.Name;
shapeAnim.Read(fsha);
fshaFolder.Nodes.Add(shapeAnim);
}
}
private void AddBoneVisAnims(ResFile resFile)
{
FbnvFolder fbnvFolder = new FbnvFolder();
Nodes.Add(fbnvFolder);
foreach (var fbnv in resFile.BoneVisibilityAnims)
{
FBNV boneVis = new FBNV();
boneVis.Text = fbnv.Name;
boneVis.Read(fbnv);
fbnvFolder.Nodes.Add(boneVis);
}
}
private void SaveCompressFile(byte[] data, string FileName, int Alignment = 0, bool EnableDialog = true)
{
if (EnableDialog && CompressionType != CompressionType.None)
@ -87,65 +468,9 @@ namespace FirstPlugin
Cursor.Current = Cursors.Default;
}
public bool IsActive { get; set; } = false;
public bool UseEditMenu { get; set; } = false;
public int Alignment { get; set; } = 0;
public string FilePath { get; set; }
public static bool IsWiiU = false;
BFRESRender bfres;
public void Load()
{
IsActive = true;
CanSave = true;
using (FileReader reader = new FileReader(new MemoryStream(Data)))
{
reader.Seek(4);
if (reader.ReadInt32() != 0x20202020)
{
IsWiiU = true;
}
reader.Close();
}
bfres = new BFRESRender();
bfres.ResFileNode = new ResourceFile(this);
bfres.ResFileNode.BFRESRender = bfres;
EditorRoot = bfres.ResFileNode;
if (IsWiiU)
{
bfres.LoadFile(new Syroot.NintenTools.Bfres.ResFile(new System.IO.MemoryStream(Data)));
}
else
{
bfres.LoadFile(new Syroot.NintenTools.NSW.Bfres.ResFile(new System.IO.MemoryStream(Data)));
}
Runtime.abstractGlDrawables.Add(bfres);
}
public void Unload()
{
bfres.Destroy();
bfres.ResFileNode.Nodes.Clear();
}
public byte[] Save()
{
MemoryStream mem = new MemoryStream();
if (IsWiiU)
SaveWiiU(mem);
else
SaveSwitch(mem);
return mem.ToArray();
}
private void SaveSwitch(MemoryStream mem)
{
var resFile = bfres.ResFileNode.resFile;
var resFile = BFRESRender.ResFileNode.resFile;
resFile.Models.Clear();
resFile.SkeletalAnims.Clear();
@ -162,45 +487,45 @@ namespace FirstPlugin
int CurMdl = 0;
if (EditorRoot.Nodes.ContainsKey("FMDL"))
if (Nodes.ContainsKey("FMDL"))
{
foreach (FMDL model in EditorRoot.Nodes["FMDL"].Nodes)
foreach (FMDL model in Nodes["FMDL"].Nodes)
resFile.Models.Add(BfresSwitch.SetModel(model));
}
if (EditorRoot.Nodes.ContainsKey("FSKA"))
if (Nodes.ContainsKey("FSKA"))
{
foreach (BfresSkeletonAnim ska in EditorRoot.Nodes["FSKA"].Nodes)
foreach (BfresSkeletonAnim ska in Nodes["FSKA"].Nodes)
resFile.SkeletalAnims.Add(ska.SkeletalAnim);
}
if (EditorRoot.Nodes.ContainsKey("FMAA"))
if (Nodes.ContainsKey("FMAA"))
{
foreach (FMAA fmaa in EditorRoot.Nodes["FMAA"].Nodes)
foreach (FMAA fmaa in Nodes["FMAA"].Nodes)
resFile.MaterialAnims.Add(fmaa.MaterialAnim);
}
if (EditorRoot.Nodes.ContainsKey("FBNV"))
if (Nodes.ContainsKey("FBNV"))
{
foreach (FBNV fbnv in EditorRoot.Nodes["FBNV"].Nodes)
foreach (FBNV fbnv in Nodes["FBNV"].Nodes)
resFile.BoneVisibilityAnims.Add(fbnv.VisibilityAnim);
}
if (EditorRoot.Nodes.ContainsKey("FSHPA"))
if (Nodes.ContainsKey("FSHPA"))
{
foreach (FSHA fsha in EditorRoot.Nodes["FSHPA"].Nodes)
foreach (FSHA fsha in Nodes["FSHPA"].Nodes)
resFile.ShapeAnims.Add(fsha.ShapeAnim);
}
if (EditorRoot.Nodes.ContainsKey("FSCN"))
if (Nodes.ContainsKey("FSCN"))
{
foreach (FSCN fscn in EditorRoot.Nodes["FSCN"].Nodes)
foreach (FSCN fscn in Nodes["FSCN"].Nodes)
resFile.SceneAnims.Add(fscn.SceneAnim);
}
ErrorCheck();
BfresSwitch.WriteExternalFiles(resFile, EditorRoot);
BfresSwitch.WriteExternalFiles(resFile, this);
resFile.Save(mem);
}
private void SaveWiiU(MemoryStream mem)
{
var resFileU = bfres.ResFileNode.resFileU;
var resFileU = BFRESRender.ResFileNode.resFileU;
resFileU.Models.Clear();
// resFileU.SkeletalAnims.Clear();
// resFileU.SceneAnims.Clear();
@ -210,9 +535,9 @@ namespace FirstPlugin
int CurMdl = 0;
if (EditorRoot.Nodes.ContainsKey("FMDL"))
if (Nodes.ContainsKey("FMDL"))
{
foreach (FMDL model in EditorRoot.Nodes["FMDL"].Nodes)
foreach (FMDL model in Nodes["FMDL"].Nodes)
resFileU.Models.Add(model.Text, BfresWiiU.SetModel(model));
}
ErrorCheck();
@ -252,7 +577,7 @@ namespace FirstPlugin
public static void CheckMissingTextures(FSHP shape)
{
bool ImportMissingTextures = false;
foreach (BinaryTextureContainer bntx in PluginRuntime.bntxContainers)
foreach (BNTX bntx in PluginRuntime.bntxContainers)
{
foreach (MatTexture tex in shape.GetMaterial().textures)
{
@ -281,10 +606,10 @@ namespace FirstPlugin
public void ErrorCheck()
{
if (bfres != null)
if (BFRESRender != null)
{
List<Errors> Errors = new List<Errors>();
foreach (FMDL model in bfres.models)
foreach (FMDL model in BFRESRender.models)
{
foreach (FSHP shp in model.shapes)
{

View File

@ -39,9 +39,9 @@ namespace Bfres.Structs
{
foreach (var ext in Nodes)
{
if (ext is BinaryTextureContainer)
if (ext is BNTX)
{
PluginRuntime.bntxContainers.Remove((BinaryTextureContainer)ext);
PluginRuntime.bntxContainers.Remove((BNTX)ext);
}
}

View File

@ -75,7 +75,7 @@ namespace Bfres.Structs
public ResFile GetResFile()
{
return ((ResourceFile)Parent.Parent).resFile;
return ((BFRES)Parent.Parent).resFile;
}
private void Export(object sender, EventArgs args)

View File

@ -75,7 +75,7 @@ namespace Bfres.Structs
public ResFile GetResFile()
{
return ((ResourceFile)Parent.Parent).resFile;
return ((BFRES)Parent.Parent).resFile;
}
public void Read(MaterialAnim anim)
{

View File

@ -95,7 +95,7 @@ namespace Bfres.Structs
public void UpdateTextureMaps()
{
((ResourceFile)Parent.Parent.Parent.Parent).BFRESRender.UpdateSingleMaterialTextureMaps(this);
((BFRES)Parent.Parent.Parent.Parent).BFRESRender.UpdateSingleMaterialTextureMaps(this);
}
public void SetActiveGame()
@ -143,7 +143,7 @@ namespace Bfres.Structs
if (sfd.ShowDialog() == DialogResult.OK)
{
if (BFRES.IsWiiU)
if (BFRES.Instance.IsWiiU)
MaterialU.Export(sfd.FileName, GetResFileU());
else
Material.Export(sfd.FileName, GetResFile());
@ -156,7 +156,7 @@ namespace Bfres.Structs
if (ofd.ShowDialog() == DialogResult.OK)
{
if (BFRES.IsWiiU)
if (BFRES.Instance.IsWiiU)
{
MaterialU.Import(ofd.FileName, GetResFileU());
MaterialU.Name = Text;

View File

@ -46,8 +46,8 @@ namespace Bfres.Structs
if (dialogResult == DialogResult.Yes)
{
Nodes.Clear();
((ResourceFile)Parent).BFRESRender.models.Clear();
((ResourceFile)Parent).BFRESRender.UpdateVertexData();
((BFRES)Parent).BFRESRender.models.Clear();
((BFRES)Parent).BFRESRender.UpdateVertexData();
}
}
public override void OnClick(TreeView treeView)
@ -66,19 +66,19 @@ namespace Bfres.Structs
public ResFile GetResFile()
{
//ResourceFile -> FMDL -> Material Folder -> this
return ((ResourceFile)Parent.Parent).resFile;
return ((BFRES)Parent.Parent).resFile;
}
public ResU.ResFile GetResFileU()
{
return ((ResourceFile)Parent.Parent).resFileU;
return ((BFRES)Parent.Parent).resFileU;
}
public void UpdateVertexData()
{
((ResourceFile)Parent.Parent).BFRESRender.UpdateVertexData();
((BFRES)Parent.Parent).BFRESRender.UpdateVertexData();
}
public List<FMDL> GetModelList()
{
return ((ResourceFile)Parent.Parent).BFRESRender.models;
return ((BFRES)Parent.Parent).BFRESRender.models;
}
@ -472,7 +472,7 @@ namespace Bfres.Structs
}
Cursor.Current = Cursors.WaitCursor;
if (!BFRES.IsWiiU && Replace)
if (!BFRES.Instance.IsWiiU && Replace)
{
materials.Clear();
Nodes["FmatFolder"].Nodes.Clear();
@ -483,7 +483,7 @@ namespace Bfres.Structs
FMAT fmat = new FMAT();
if (settings.ExternalMaterialPath != string.Empty)
{
if (!BFRES.IsWiiU)
if (!BFRES.Instance.IsWiiU)
{
fmat.Material = new Material();
fmat.Material.Import(settings.ExternalMaterialPath);
@ -544,9 +544,9 @@ namespace Bfres.Structs
{
foreach (var node in Parent.Parent.Nodes["EXT"].Nodes)
{
if (node is BinaryTextureContainer)
if (node is BNTX)
{
var bntx = (BinaryTextureContainer)node;
var bntx = (BNTX)node;
bntx.ImportBasicTextures("Basic_Alb");
bntx.ImportBasicTextures("Basic_Nrm");
@ -583,7 +583,7 @@ namespace Bfres.Structs
materials.Add(fmat.Text, fmat);
Nodes["FmatFolder"].Nodes.Add(fmat);
if (BFRES.IsWiiU)
if (BFRES.Instance.IsWiiU)
{
fmat.MaterialU.Name = Text;
fmat.SetMaterial(fmat.MaterialU);

View File

@ -75,7 +75,7 @@ namespace Bfres.Structs
public ResFile GetResFile()
{
return ((ResourceFile)Parent.Parent).resFile;
return ((BFRES)Parent.Parent).resFile;
}
private void Export(object sender, EventArgs args)

View File

@ -74,7 +74,7 @@ namespace Bfres.Structs
public ResFile GetResFile()
{
return ((ResourceFile)Parent.Parent).resFile;
return ((BFRES)Parent.Parent).resFile;
}
private void Export(object sender, EventArgs args)

View File

@ -658,7 +658,7 @@ namespace Bfres.Structs
}
public void SaveShape()
{
if (!BFRES.IsWiiU)
if (!BFRES.Instance.IsWiiU)
Shape = BfresSwitch.SaveShape(this);
else
ShapeU = BfresWiiU.SaveShape(this);
@ -685,7 +685,7 @@ namespace Bfres.Structs
}
public void SaveVertexBuffer()
{
if (BFRES.IsWiiU)
if (BFRES.Instance.IsWiiU)
{
BfresWiiU.SaveVertexBuffer(this);
return;

View File

@ -101,7 +101,7 @@ namespace Bfres.Structs
public ResFile GetResFile()
{
//ResourceFile -> FMDL -> Material Folder -> this
return ((ResourceFile)Parent.Parent).resFile;
return ((BFRES)Parent.Parent).resFile;
}
private void Export(object sender, EventArgs args)
{

View File

@ -10,9 +10,6 @@ using Switch_Toolbox.Library.Rendering;
using WeifenLuo.WinFormsUI.Docking;
using Switch_Toolbox.Library.IO;
using Switch_Toolbox.Library.Forms;
using ResU = Syroot.NintenTools.Bfres;
using ResUGX2 = Syroot.NintenTools.Bfres.GX2;
using ResGFX = Syroot.NintenTools.NSW.Bfres.GFX;
using FirstPlugin;
namespace Bfres.Structs
@ -26,339 +23,4 @@ namespace Bfres.Structs
"Common_Scroll01._13827715"
});
}
public class ResourceFile : TreeNodeFile
{
public BFRESRender BFRESRender;
public ResFile resFile = null;
public ResU.ResFile resFileU = null;
public TreeNode TextureFolder = new TreeNode("Textures");
public ResourceFile(IFileFormat handler)
{
ImageKey = "bfres";
SelectedImageKey = "bfres";
FileHandler = handler;
ContextMenu = new ContextMenu();
MenuItem save = new MenuItem("Save");
ContextMenu.MenuItems.Add(save);
save.Click += Save;
MenuItem newMenu = new MenuItem("New");
MenuItem import = new MenuItem("Import");
// ContextMenu.MenuItems.Add(newMenu);
// ContextMenu.MenuItems.Add(import);
MenuItem rename = new MenuItem("Rename");
ContextMenu.MenuItems.Add(rename);
rename.Click += Rename;
MenuItem remove = new MenuItem("Remove");
ContextMenu.MenuItems.Add(remove);
remove.Click += Remove;
if (Parent == null)
remove.Enabled = false;
if (BFRES.IsWiiU)
{
}
else
{
MenuItem model = new MenuItem("Model");
MenuItem fska = new MenuItem("Skeletal Animation");
MenuItem fmaa = new MenuItem("Material Animation");
MenuItem bonevis = new MenuItem("Bone Visual Animation");
MenuItem shape = new MenuItem("Shape Animation");
MenuItem scene = new MenuItem("Scene Animation");
MenuItem embedded = new MenuItem("Embedded File");
MenuItem texture = new MenuItem("Texture File");
texture.Click += NewTextureFile;
newMenu.MenuItems.Add(model);
newMenu .MenuItems.Add(fska);
newMenu.MenuItems.Add(fmaa);
newMenu.MenuItems.Add(bonevis);
newMenu.MenuItems.Add(shape);
newMenu.MenuItems.Add(scene);
newMenu.MenuItems.Add(embedded);
newMenu.MenuItems.Add(texture);
MenuItem importmodel = new MenuItem("Model");
MenuItem importfska = new MenuItem("Skeletal Animation");
MenuItem importfmaa = new MenuItem("Material Animation");
MenuItem importbonevis = new MenuItem("Bone Visual Animation");
MenuItem importshape = new MenuItem("Shape Animation");
MenuItem importscene = new MenuItem("Scene Animation");
MenuItem importembedded = new MenuItem("Embedded File");
MenuItem importtexture = new MenuItem("Texture File");
import.MenuItems.Add(importmodel);
import.MenuItems.Add(importfska);
import.MenuItems.Add(importfmaa);
import.MenuItems.Add(importbonevis);
import.MenuItems.Add(importshape);
import.MenuItems.Add(importscene);
import.MenuItems.Add(importembedded);
import.MenuItems.Add(importtexture);
}
}
public override void OnClick(TreeView treeView)
{
//If has models
if (Nodes.ContainsKey("FMDL"))
{
LibraryGUI.Instance.LoadViewport(Viewport.Instance);
Viewport.Instance.gL_ControlModern1.MainDrawable = BFRESRender;
BFRESRender.UpdateVertexData();
}
}
public void Load(ResU.ResFile res)
{
resFileU = res;
Text = resFileU.Name;
if (resFileU.Models.Count > 0)
Nodes.Add(new FmdlFolder());
if (resFileU.Textures.Count > 0)
AddFTEXTextures(resFileU);
if (resFileU.SkeletalAnims.Count > 0)
AddSkeletonAnims(resFileU);
if (resFileU.ShaderParamAnims.Count > 0)
Nodes.Add(new FshuFolder());
if (resFileU.ColorAnims.Count > 0)
Nodes.Add(new FshuColorFolder());
if (resFileU.TexSrtAnims.Count > 0)
Nodes.Add(new TexSrtFolder());
if (resFileU.TexPatternAnims.Count > 0)
Nodes.Add(new TexPatFolder());
if (resFileU.ShapeAnims.Count > 0)
Nodes.Add(new FshpaFolder());
if (resFileU.BoneVisibilityAnims.Count > 0)
Nodes.Add(new FbnvFolder());
if (resFileU.SceneAnims.Count > 0)
Nodes.Add(new FscnFolder());
if (resFileU.ExternalFiles.Count > 0)
Nodes.Add(new EmbeddedFilesFolder());
foreach (var anim in resFileU.ShaderParamAnims)
Nodes["FSHA"].Nodes.Add(anim.Key);
foreach (var anim in resFileU.ColorAnims)
Nodes["FSHAColor"].Nodes.Add(anim.Key);
foreach (var anim in resFileU.TexSrtAnims)
Nodes["TEXSRT"].Nodes.Add(anim.Key);
foreach (var anim in resFileU.TexPatternAnims)
Nodes["TEXPAT"].Nodes.Add(anim.Key);
int ext = 0;
foreach (var extfile in resFileU.ExternalFiles)
{
string Name = extfile.Key;
FileReader f = new FileReader(extfile.Value.Data);
string Magic = f.ReadMagic(0, 4);
if (Magic == "FSHA")
{
Nodes["EXT"].Nodes.Add(new BfshaFileData(extfile.Value.Data, Name));
}
else
Nodes["EXT"].Nodes.Add(new ExternalFileData(extfile.Value.Data, Name));
f.Dispose();
f.Close();
ext++;
}
}
public void Load(ResFile res)
{
resFile = res;
Text = resFile.Name;
UpdateTree(resFile);
foreach (ShapeAnim anim in resFile.ShapeAnims)
Nodes["FSHPA"].Nodes.Add(anim.Name);
foreach (VisibilityAnim anim in resFile.BoneVisibilityAnims)
Nodes["FBNV"].Nodes.Add(anim.Name);
int ext = 0;
foreach (ExternalFile extfile in resFile.ExternalFiles)
{
string Name = resFile.ExternalFileDict.GetKey(ext);
FileReader f = new FileReader(extfile.Data);
string Magic = f.ReadMagic(0, 4);
if (Magic == "BNTX")
{
BNTX bntx = new BNTX();
bntx.Data = extfile.Data;
bntx.FileName = Name;
bntx.Load();
bntx.IFileInfo.InArchive = true;
Nodes["EXT"].Nodes.Add(bntx.EditorRoot);
}
else if (Magic == "FSHA")
{
Nodes["EXT"].Nodes.Add(new BfshaFileData(extfile.Data, Name));
}
else
Nodes["EXT"].Nodes.Add(new ExternalFileData(extfile.Data, Name));
f.Dispose();
f.Close();
ext++;
}
}
private void NewTextureFile(object sender, EventArgs args)
{
string Name = "textures";
for (int i = 0; i < resFile.ExternalFiles.Count; i++)
{
if (resFile.ExternalFileDict.GetKey(i) == Name)
Name = Name + i;
}
if (!Nodes.ContainsKey("EXT"))
{
Nodes.Add(new EmbeddedFilesFolder());
}
BNTX bntx = new BNTX();
bntx.Data = new byte[0];
BinaryTextureContainer bntxTreeNode = new BinaryTextureContainer(new byte[0], "textures", resFile.Name);
Nodes["EXT"].Nodes.Add(bntxTreeNode);
}
private void NewEmbeddedFile(object sender, EventArgs args)
{
}
private void Save(object sender, EventArgs args)
{
((BFRES)FileHandler).SaveFile();
}
private void Rename(object sender, EventArgs args)
{
RenameDialog dialog = new RenameDialog();
dialog.SetString(Text);
if (dialog.ShowDialog() == DialogResult.OK)
{
Text = dialog.textBox1.Text;
}
}
private void Remove(object sender, EventArgs args)
{
BFRESRender.DisposeFile();
}
private void UpdateTree(ResFile resFile)
{
if (resFile.Models.Count > 0)
Nodes.Add(new FmdlFolder());
if (resFile.SkeletalAnims.Count > 0)
AddSkeletonAnims(resFile);
if (resFile.MaterialAnims.Count > 0)
AddMaterialAnims(resFile);
if (resFile.ShapeAnims.Count > 0)
AddShapeAnims(resFile);
if (resFile.BoneVisibilityAnims.Count > 0)
AddBoneVisAnims(resFile);
if (resFile.SceneAnims.Count > 0)
AddSceneAnims(resFile);
if (resFile.ExternalFiles.Count > 0)
Nodes.Add(new EmbeddedFilesFolder());
}
private void AddFTEXTextures(ResU.ResFile resFile)
{
FTEXContainer ftexContainer = new FTEXContainer();
Nodes.Add(ftexContainer);
foreach (ResU.Texture tex in resFile.Textures.Values)
{
string TextureName = tex.Name;
FTEX texture = new FTEX();
texture.Read(tex);
ftexContainer.Nodes.Add(texture);
ftexContainer.Textures.Add(texture.Text, texture);
}
PluginRuntime.ftexContainers.Add(ftexContainer);
}
private void AddSkeletonAnims(ResU.ResFile resFile)
{
FskaFolder fksaFolder = new FskaFolder();
Nodes.Add(fksaFolder);
foreach (ResU.SkeletalAnim ska in resFile.SkeletalAnims.Values)
{
BfresSkeletonAnim skeletonAnim = new BfresSkeletonAnim(ska.Name);
skeletonAnim.Read(ska, resFile);
fksaFolder.Nodes.Add(skeletonAnim);
}
}
private void AddSkeletonAnims(ResFile resFile)
{
FskaFolder fksaFolder = new FskaFolder();
Nodes.Add(fksaFolder);
foreach (SkeletalAnim ska in resFile.SkeletalAnims)
{
BfresSkeletonAnim skeletonAnim = new BfresSkeletonAnim(ska.Name);
skeletonAnim.Read(ska, resFile);
fksaFolder.Nodes.Add(skeletonAnim);
}
}
private void AddSceneAnims(ResU.ResFile resFile)
{
FscnFolder FSCN = new FscnFolder();
Nodes.Add(FSCN);
}
private void AddSceneAnims(ResFile resFile)
{
FscnFolder fscnFolder = new FscnFolder();
Nodes.Add(fscnFolder);
foreach (var scn in resFile.SceneAnims)
{
FSCN sceneAnim = new FSCN();
sceneAnim.Text = scn.Name;
sceneAnim.Read(scn);
fscnFolder.Nodes.Add(sceneAnim);
}
}
private void AddMaterialAnims(ResFile resFile)
{
FmaaFolder fmaaFolder = new FmaaFolder();
Nodes.Add(fmaaFolder);
foreach (var fmaa in resFile.MaterialAnims)
{
FMAA materialAnim = new FMAA();
materialAnim.Text = fmaa.Name;
materialAnim.BFRESRender = BFRESRender;
materialAnim.Read(fmaa);
fmaaFolder.Nodes.Add(materialAnim);
}
}
private void AddShapeAnims(ResFile resFile)
{
FshpaFolder fshaFolder = new FshpaFolder();
Nodes.Add(fshaFolder);
foreach (var fsha in resFile.ShapeAnims)
{
FSHA shapeAnim = new FSHA();
shapeAnim.Text = fsha.Name;
shapeAnim.Read(fsha);
fshaFolder.Nodes.Add(shapeAnim);
}
}
private void AddBoneVisAnims(ResFile resFile)
{
FbnvFolder fbnvFolder = new FbnvFolder();
Nodes.Add(fbnvFolder);
foreach (var fbnv in resFile.BoneVisibilityAnims)
{
FBNV boneVis = new FBNV();
boneVis.Text = fbnv.Name;
boneVis.Read(fbnv);
fbnvFolder.Nodes.Add(boneVis);
}
}
}
}

View File

@ -974,19 +974,13 @@ namespace FirstPlugin
foreach (TreeNode node in EditorRoot.Nodes["EXT"].Nodes)
{
ExternalFile ext = new ExternalFile();
if (node is BinaryTextureContainer)
{
BinaryTextureContainer bntx = (BinaryTextureContainer)node;
ext.Data = bntx.Save();
}
if (node is BNTX)
ext.Data = ((BNTX)node).Save();
else if (node is BfshaFileData)
{
ext.Data = ((BfshaFileData)node).Data;
}
else
{
ext.Data = ((ExternalFileData)node).Data;
}
resFile.ExternalFiles.Add(ext);
}
}

View File

@ -897,19 +897,13 @@ namespace FirstPlugin
foreach (TreeNode node in EditorRoot.Nodes["EXT"].Nodes)
{
ExternalFile ext = new ExternalFile();
if (node is BinaryTextureContainer)
{
BinaryTextureContainer bntx = (BinaryTextureContainer)node;
ext.Data = bntx.Save();
}
if (node is BNTX)
ext.Data = ((BNTX)node).Save();
else if (node is BfshaFileData)
{
ext.Data = ((BfshaFileData)node).Data;
}
else
{
ext.Data = ((ExternalFileData)node).Data;
}
resFile.ExternalFiles.Add(node.Text, ext);
}
}

View File

@ -10,7 +10,7 @@ using Switch_Toolbox.Library.IO;
namespace FirstPlugin
{
public class BFSAR : IFileFormat
public class BFSAR : TreeNodeFile, IFileFormat
{
public bool CanSave { get; set; } = false;
public bool FileIsEdited { get; set; } = false;
@ -21,7 +21,6 @@ namespace FirstPlugin
public CompressionType CompressionType { get; set; } = CompressionType.None;
public byte[] Data { get; set; }
public string FileName { get; set; }
public TreeNodeFile EditorRoot { get; set; }
public bool IsActive { get; set; } = false;
public bool UseEditMenu { get; set; } = false;
public int Alignment { get; set; } = 0;
@ -43,13 +42,12 @@ namespace FirstPlugin
FSAR bfsar = new FSAR();
bfsar.Read(new FileReader(new MemoryStream(Data)));
EditorRoot = new TreeNodeFile(FileName, this);
EditorRoot.Nodes.Add("Audio List");
EditorRoot.Nodes.Add("Audio Set List");
EditorRoot.Nodes.Add("Bank List");
EditorRoot.Nodes.Add("Group List");
EditorRoot.Nodes.Add("Players List");
Text = FileName;
Nodes.Add("Audio List");
Nodes.Add("Audio Set List");
Nodes.Add("Bank List");
Nodes.Add("Group List");
Nodes.Add("Players List");
}
public void Unload()
{

View File

@ -12,7 +12,7 @@ using WeifenLuo.WinFormsUI.Docking;
namespace FirstPlugin
{
public class BYAML : IFileFormat
public class BYAML : TreeNodeFile, IFileFormat
{
public bool CanSave { get; set; } = false;
public bool FileIsEdited { get; set; } = false;
@ -23,7 +23,6 @@ namespace FirstPlugin
public CompressionType CompressionType { get; set; } = CompressionType.None;
public byte[] Data { get; set; }
public string FileName { get; set; }
public TreeNodeFile EditorRoot { get; set; }
public bool IsActive { get; set; } = false;
public bool UseEditMenu { get; set; } = false;
public string FilePath { get; set; }
@ -70,7 +69,6 @@ namespace FirstPlugin
ByamlViewer.OpenByml(mem, FileName);
// BymlFileData byamlFile = ByamlFile.LoadN(new System.IO.MemoryStream(Data), false, Syroot.BinaryData.ByteOrder.LittleEndian);
// EditorRoot = LoadByamlNodes(byamlFile.RootNode);
// LoadDockedEditor(byamlFile);
}
@ -79,8 +77,6 @@ namespace FirstPlugin
}
ByamlEditor ByamlEditor;
public TreeNode LoadByamlNodes(dynamic root)
{
TreeNode node = new TreeNode();

View File

@ -21,7 +21,6 @@ namespace FirstPlugin
public CompressionType CompressionType { get; set; } = CompressionType.None;
public byte[] Data { get; set; }
public string FileName { get; set; }
public TreeNodeFile EditorRoot { get; set; }
public bool IsActive { get; set; } = false;
public bool UseEditMenu { get; set; } = false;
public string FilePath { get; set; }

View File

@ -11,7 +11,7 @@ using Switch_Toolbox.Library.IO;
namespace FirstPlugin
{
public class GFPAK : IFileFormat
public class GFPAK : TreeNodeFile, IFileFormat
{
public bool CanSave { get; set; } = false;
public bool FileIsEdited { get; set; } = false;
@ -22,7 +22,6 @@ namespace FirstPlugin
public CompressionType CompressionType { get; set; } = CompressionType.None;
public byte[] Data { get; set; }
public string FileName { get; set; }
public TreeNodeFile EditorRoot { get; set; }
public bool IsActive { get; set; } = false;
public bool UseEditMenu { get; set; } = false;
public int Alignment { get; set; } = 0;
@ -40,31 +39,11 @@ namespace FirstPlugin
public void Load()
{
IsActive = true;
EditorRoot = new GFLXPACK(FileName, this);
IFileInfo = new IFileInfo();
((GFLXPACK)EditorRoot).Read(new FileReader(new MemoryStream(Data)), EditorRoot);
Read(new FileReader(new MemoryStream(Data)));
}
public void Unload()
{
}
public byte[] Save()
{
MemoryStream mem = new MemoryStream();
((GFLXPACK)EditorRoot).Write(new FileWriter(mem));
return mem.ToArray();
}
}
public class GFLXPACK : TreeNodeFile
{
public GFLXPACK(string text, IFileFormat format)
{
Text = text;
FileHandler = format;
Text = FileName;
ContextMenu = new ContextMenu();
MenuItem save = new MenuItem("Save");
@ -74,19 +53,29 @@ namespace FirstPlugin
ContextMenu.MenuItems.Add(previewFiles);
previewFiles.Click += PreviewWindow;
}
public void Unload()
{
}
public byte[] Save()
{
MemoryStream mem = new MemoryStream();
Write(new FileWriter(mem));
return mem.ToArray();
}
private void Save(object sender, EventArgs args)
{
List<IFileFormat> formats = new List<IFileFormat>();
formats.Add(FileHandler);
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = Utils.GetAllFilters(formats);
sfd.FileName = FileHandler.FileName;
sfd.FileName = FileName;
if (sfd.ShowDialog() == DialogResult.OK)
{
Cursor.Current = Cursors.WaitCursor;
SaveCompressFile(FileHandler.Save(), sfd.FileName, FileHandler.IFileInfo.Alignment);
SaveCompressFile(Save(), sfd.FileName, IFileInfo.Alignment);
}
}
private void SaveCompressFile(byte[] data, string FileName, int Alignment = 0, bool EnableDialog = true)
@ -154,7 +143,7 @@ namespace FirstPlugin
public int version;
public int FolderCount;
public void Read(FileReader reader, TreeNode root)
public void Read(FileReader reader)
{
string Signature = reader.ReadString(8, Encoding.ASCII);
if (Signature != "GFLXPACK")
@ -188,7 +177,7 @@ namespace FirstPlugin
FileEntry fileEntry = new FileEntry();
fileEntry.Read(reader);
fileEntry.Text = hashes[i].ToString();
root.Nodes.Add(fileEntry);
Nodes.Add(fileEntry);
files.Add(fileEntry);
}
}
@ -380,14 +369,14 @@ namespace FirstPlugin
fileFormat.FilePath = FileName;
fileFormat.IFileInfo = new IFileInfo();
fileFormat.IFileInfo.InArchive = true;
if (fileFormat.EditorRoot == null)
return null;
fileFormat.EditorRoot.ImageKey = fileEntry.ImageKey;
fileFormat.EditorRoot.SelectedImageKey = fileEntry.SelectedImageKey;
fileFormat.EditorRoot.Text = fileEntry.Text;
fileEntry.FileHandler = fileFormat;
return fileFormat.EditorRoot;
if (fileFormat is TreeNode)
{
((TreeNode)fileFormat).Text = fileEntry.Text;
((TreeNode)fileFormat).ImageKey = fileEntry.ImageKey;
((TreeNode)fileFormat).SelectedImageKey = fileEntry.SelectedImageKey;
return (TreeNode)fileFormat;
}
}
if (fileFormat.Magic == string.Empty)
{
@ -401,14 +390,14 @@ namespace FirstPlugin
fileFormat.FilePath = FileName;
fileFormat.IFileInfo = new IFileInfo();
fileFormat.IFileInfo.InArchive = true;
if (fileFormat.EditorRoot == null)
return null;
fileFormat.EditorRoot.ImageKey = fileEntry.ImageKey;
fileFormat.EditorRoot.SelectedImageKey = fileEntry.SelectedImageKey;
fileFormat.EditorRoot.Text = fileEntry.Text;
fileEntry.FileHandler = fileFormat;
return fileFormat.EditorRoot;
if (fileFormat is TreeNode)
{
((TreeNode)fileFormat).Text = fileEntry.Text;
((TreeNode)fileFormat).ImageKey = fileEntry.ImageKey;
((TreeNode)fileFormat).SelectedImageKey = fileEntry.SelectedImageKey;
return (TreeNode)fileFormat;
}
}
}
}
@ -425,26 +414,4 @@ namespace FirstPlugin
node.Nodes.Insert(index, NewNode);
}
}
public class FileUnk
{
public uint Size;
public uint Type;
public uint Width;
public uint Height;
public uint Ascend;
public uint LineFeed;
public uint AlterCharIndex;
public uint DefaultLeftWidth;
public uint DefaultGlyphWidth;
public uint DefaultCharWidth;
public uint CharEncoding;
public TGLP tglp;
public void Read(FileReader reader)
{
}
}
}

View File

@ -16,7 +16,7 @@ using Switch_Toolbox.Library.IO;
namespace FirstPlugin
{
public class KCL : IFileFormat
public class KCL : TreeNodeFile, IFileFormat
{
public bool CanSave { get; set; } = false;
public bool FileIsEdited { get; set; } = false;
@ -27,7 +27,6 @@ namespace FirstPlugin
public CompressionType CompressionType { get; set; } = CompressionType.None;
public byte[] Data { get; set; }
public string FileName { get; set; }
public TreeNodeFile EditorRoot { get; set; }
public bool IsActive { get; set; } = false;
public bool UseEditMenu { get; set; } = false;
public string FilePath { get; set; }
@ -45,8 +44,22 @@ namespace FirstPlugin
public void Load()
{
IsActive = true;
EditorRoot = new KCLRoot(FileName, this);
IFileInfo = new IFileInfo();
Text = FileName;
Renderer = new KCLRendering();
Read(Data);
ContextMenu = new ContextMenu();
MenuItem save = new MenuItem("Save");
ContextMenu.MenuItems.Add(save);
save.Click += Save;
MenuItem export = new MenuItem("Export");
ContextMenu.MenuItems.Add(export);
export.Click += Export;
MenuItem replace = new MenuItem("Replace");
ContextMenu.MenuItems.Add(replace);
replace.Click += Replace;
}
public void Unload()
{
@ -143,156 +156,135 @@ namespace FirstPlugin
BoostTrick = 8202,
}
public class KCLRoot : TreeNodeFile
public void Save(object sender, EventArgs args)
{
public KCLRoot(string Name, IFileFormat handler)
{
Text = Name;
FileHandler = handler;
Renderer = new KCLRendering();
Read(handler.Data);
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Supported Formats|*.kcl";
sfd.FileName = Text;
sfd.DefaultExt = ".kcl";
ContextMenu = new ContextMenu();
MenuItem save = new MenuItem("Save");
ContextMenu.MenuItems.Add(save);
save.Click += Save;
MenuItem export = new MenuItem("Export");
ContextMenu.MenuItems.Add(export);
export.Click += Export;
MenuItem replace = new MenuItem("Replace");
ContextMenu.MenuItems.Add(replace);
replace.Click += Replace;
if (sfd.ShowDialog() == DialogResult.OK)
{
int Alignment = IFileInfo.Alignment;
SaveCompressFile(Save(), sfd.FileName, CompressionType, Alignment);
}
public void Save(object sender, EventArgs args)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Supported Formats|*.kcl";
sfd.FileName = Text;
sfd.DefaultExt = ".kcl";
}
public void Export(object sender, EventArgs args)
{
if (kcl == null)
return;
if (sfd.ShowDialog() == DialogResult.OK)
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Supported Formats|*.obj";
sfd.FileName = Text;
sfd.DefaultExt = ".obj";
if (sfd.ShowDialog() == DialogResult.OK)
{
kcl.ToOBJ().toWritableObj().WriteObj(sfd.FileName + ".obj");
}
}
public void Replace(object sender, EventArgs args)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Supported Formats|*.obj";
if (ofd.ShowDialog() == DialogResult.OK)
{
var mod = EditorCore.Common.OBJ.Read(new MemoryStream(File.ReadAllBytes(ofd.FileName)), null);
if (mod.Faces.Count > 65535)
{
int Alignment = FileHandler.IFileInfo.Alignment;
SaveCompressFile(FileHandler.Save(), sfd.FileName, FileHandler.CompressionType, Alignment);
}
}
public void Export(object sender, EventArgs args)
{
if (kcl == null)
MessageBox.Show("this model has too many faces, only models with less than 65535 triangles can be converted");
return;
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Supported Formats|*.obj";
sfd.FileName = Text;
sfd.DefaultExt = ".obj";
if (sfd.ShowDialog() == DialogResult.OK)
{
kcl.ToOBJ().toWritableObj().WriteObj(sfd.FileName + ".obj");
}
kcl = MarioKart.MK7.KCL.FromOBJ(mod);
Data = kcl.Write(Syroot.BinaryData.ByteOrder.LittleEndian);
Read(Data);
}
public void Replace(object sender, EventArgs args)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Supported Formats|*.obj";
}
if (ofd.ShowDialog() == DialogResult.OK)
{
var mod = EditorCore.Common.OBJ.Read(new MemoryStream(File.ReadAllBytes(ofd.FileName)), null);
if (mod.Faces.Count > 65535)
{
MessageBox.Show("this model has too many faces, only models with less than 65535 triangles can be converted");
return;
}
kcl = MarioKart.MK7.KCL.FromOBJ(mod);
FileHandler.Data = kcl.Write(Syroot.BinaryData.ByteOrder.LittleEndian);
Read(FileHandler.Data);
}
KCLRendering Renderer;
public override void OnClick(TreeView treeView)
{
LibraryGUI.Instance.LoadViewport(Viewport.Instance);
Viewport.Instance.gL_ControlModern1.MainDrawable = Renderer;
Renderer.UpdateVertexData();
}
public MarioKart.MK7.KCL kcl = null;
public void Read(byte[] file_data)
{
try
{
kcl = new MarioKart.MK7.KCL(file_data, Syroot.BinaryData.ByteOrder.LittleEndian);
}
KCLRendering Renderer;
public override void OnClick(TreeView treeView)
catch
{
LibraryGUI.Instance.LoadViewport(Viewport.Instance);
Viewport.Instance.gL_ControlModern1.MainDrawable = Renderer;
Renderer.UpdateVertexData();
kcl = new MarioKart.MK7.KCL(file_data, Syroot.BinaryData.ByteOrder.BigEndian);
}
Read(kcl);
Renderer.UpdateVertexData();
}
public void Read(MarioKart.MK7.KCL kcl)
{
Nodes.Clear();
Renderer.models.Clear();
public MarioKart.MK7.KCL kcl = null;
public void Read(byte[] file_data)
int CurModelIndx = 0;
foreach (MarioKart.MK7.KCL.KCLModel mdl in kcl.Models)
{
try
KCLModel kclmodel = new KCLModel();
kclmodel.Text = "Model " + CurModelIndx;
int ft = 0;
foreach (var plane in mdl.Planes)
{
kcl = new MarioKart.MK7.KCL(file_data, Syroot.BinaryData.ByteOrder.LittleEndian);
var triangle = mdl.GetTriangle(plane);
var normal = triangle.Normal;
var pointA = triangle.PointA;
var pointB = triangle.PointB;
var pointC = triangle.PointC;
Vertex vtx = new Vertex();
Vertex vtx2 = new Vertex();
Vertex vtx3 = new Vertex();
vtx.pos = new Vector3(Vec3D_To_Vec3(pointA));
vtx2.pos = new Vector3(Vec3D_To_Vec3(pointB));
vtx3.pos = new Vector3(Vec3D_To_Vec3(pointC));
vtx.nrm = new Vector3(Vec3D_To_Vec3(normal));
vtx2.nrm = new Vector3(Vec3D_To_Vec3(normal));
vtx3.nrm = new Vector3(Vec3D_To_Vec3(normal));
KCLModel.Face face = new KCLModel.Face();
face.Text = triangle.Collision.ToString();
face.MaterialFlag = triangle.Collision;
var col = MarioKart.MK7.KCLColors.GetMaterialColor(plane.CollisionType);
Vector3 ColorSet = new Vector3(col.R, col.G, col.B);
vtx.col = new Vector4(ColorSet, 1);
vtx2.col = new Vector4(ColorSet, 1);
vtx3.col = new Vector4(ColorSet, 1);
kclmodel.faces.Add(ft);
kclmodel.faces.Add(ft + 1);
kclmodel.faces.Add(ft + 2);
ft += 3;
kclmodel.vertices.Add(vtx);
kclmodel.vertices.Add(vtx2);
kclmodel.vertices.Add(vtx3);
}
catch
{
kcl = new MarioKart.MK7.KCL(file_data, Syroot.BinaryData.ByteOrder.BigEndian);
}
Read(kcl);
Renderer.UpdateVertexData();
}
public void Read(MarioKart.MK7.KCL kcl)
{
Nodes.Clear();
Renderer.models.Clear();
int CurModelIndx = 0;
foreach (MarioKart.MK7.KCL.KCLModel mdl in kcl.Models)
{
KCLModel kclmodel = new KCLModel();
Renderer.models.Add(kclmodel);
Nodes.Add(kclmodel);
kclmodel.Text = "Model " + CurModelIndx;
int ft = 0;
foreach (var plane in mdl.Planes)
{
var triangle = mdl.GetTriangle(plane);
var normal = triangle.Normal;
var pointA = triangle.PointA;
var pointB = triangle.PointB;
var pointC = triangle.PointC;
Vertex vtx = new Vertex();
Vertex vtx2 = new Vertex();
Vertex vtx3 = new Vertex();
vtx.pos = new Vector3(Vec3D_To_Vec3(pointA));
vtx2.pos = new Vector3(Vec3D_To_Vec3(pointB));
vtx3.pos = new Vector3(Vec3D_To_Vec3(pointC));
vtx.nrm = new Vector3(Vec3D_To_Vec3(normal));
vtx2.nrm = new Vector3(Vec3D_To_Vec3(normal));
vtx3.nrm = new Vector3(Vec3D_To_Vec3(normal));
KCLModel.Face face = new KCLModel.Face();
face.Text = triangle.Collision.ToString();
face.MaterialFlag = triangle.Collision;
var col = MarioKart.MK7.KCLColors.GetMaterialColor(plane.CollisionType);
Vector3 ColorSet = new Vector3(col.R, col.G, col.B);
vtx.col = new Vector4(ColorSet, 1);
vtx2.col = new Vector4(ColorSet, 1);
vtx3.col = new Vector4(ColorSet, 1);
kclmodel.faces.Add(ft);
kclmodel.faces.Add(ft + 1);
kclmodel.faces.Add(ft + 2);
ft += 3;
kclmodel.vertices.Add(vtx);
kclmodel.vertices.Add(vtx2);
kclmodel.vertices.Add(vtx3);
}
Renderer.models.Add(kclmodel);
Nodes.Add(kclmodel);
CurModelIndx++;
}
CurModelIndx++;
}
}

View File

@ -20,7 +20,6 @@ namespace FirstPlugin
public CompressionType CompressionType { get; set; } = CompressionType.None;
public byte[] Data { get; set; }
public string FileName { get; set; }
public TreeNodeFile EditorRoot { get; set; }
public bool IsActive { get; set; } = false;
public bool UseEditMenu { get; set; } = false;
public int Alignment { get; set; } = 0;

View File

@ -11,7 +11,7 @@ using Switch_Toolbox.Library.Forms;
namespace FirstPlugin
{
public class SARC : IFileFormat
public class SARC : TreeNodeFile, IFileFormat
{
public bool CanSave { get; set; } = false;
public bool FileIsEdited { get; set; } = false;
@ -22,7 +22,6 @@ namespace FirstPlugin
public CompressionType CompressionType { get; set; } = CompressionType.None;
public byte[] Data { get; set; }
public string FileName { get; set; }
public TreeNodeFile EditorRoot { get; set; }
public bool IsActive { get; set; } = false;
public bool UseEditMenu { get; set; } = false;
public string FilePath { get; set; }
@ -40,7 +39,6 @@ namespace FirstPlugin
public string SarcHash;
public void Load()
{
EditorRoot = new RootNode(Path.GetFileName(FileName), this);
IsActive = true;
CanSave = true;
UseEditMenu = true;
@ -53,8 +51,14 @@ namespace FirstPlugin
SarcHash = Utils.GenerateUniqueHashID();
IFileInfo = new IFileInfo();
FillTreeNodes(this, SzsFiles.Files, SarcHash);
FillTreeNodes(EditorRoot, SzsFiles.Files, SarcHash);
Text = FileName;
ContextMenu = new ContextMenu();
MenuItem save = new MenuItem("Save");
ContextMenu.MenuItems.Add(save);
save.Click += Save;
sarcData.Files.Clear();
}
@ -77,7 +81,7 @@ namespace FirstPlugin
public void Unload()
{
EditorRoot.Nodes.Clear();
Nodes.Clear();
}
IEnumerable<TreeNode> Collect(TreeNodeCollection nodes)
@ -95,19 +99,20 @@ namespace FirstPlugin
Console.WriteLine("Saving sarc");
sarcData.Files.Clear();
foreach (TreeNode node in Collect(EditorRoot.Nodes))
foreach (TreeNode node in Collect(Nodes))
{
if (node is SarcEntry)
{
Console.WriteLine("Saving " + node);
SaveFileEntryData((SarcEntry)node);
}
if (node is TreeNodeFile && node != EditorRoot)
if (node is TreeNodeFile && node != this)
{
TreeNodeFile treeNodeFile = (TreeNodeFile)node;
if (treeNodeFile.FileHandler != null && treeNodeFile.FileHandler.IFileInfo.ArchiveHash == SarcHash)
IFileFormat fileFormat = (IFileFormat)node;
if (fileFormat != null && fileFormat.IFileInfo.ArchiveHash == SarcHash)
{
sarcData.Files.Add(SARC.SetSarcPath(node, (TreeNode)this.EditorRoot), STLibraryCompression.CompressFile(treeNodeFile.FileHandler.Save(), treeNodeFile.FileHandler));
sarcData.Files.Add(SetSarcPath(node, this),
STLibraryCompression.CompressFile(fileFormat.Save(), fileFormat));
}
}
}
@ -152,77 +157,62 @@ namespace FirstPlugin
node.Nodes.Insert(index, NewNode);
}
public class RootNode : TreeNodeFile
private void Save(object sender, EventArgs args)
{
SARC sarc;
public RootNode(string n, SARC s)
List<IFileFormat> formats = new List<IFileFormat>();
formats.Add(this);
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = Utils.GetAllFilters(formats);
sfd.FileName = FileName;
if (sfd.ShowDialog() == DialogResult.OK)
{
Text = n;
sarc = s;
ContextMenu = new ContextMenu();
MenuItem save = new MenuItem("Save");
ContextMenu.MenuItems.Add(save);
save.Click += Save;
}
private void Save(object sender, EventArgs args)
{
List<IFileFormat> formats = new List<IFileFormat>();
formats.Add(sarc);
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = Utils.GetAllFilters(formats);
sfd.FileName = sarc.FileName;
if (sfd.ShowDialog() == DialogResult.OK)
{
Cursor.Current = Cursors.WaitCursor;
SaveCompressFile(sarc.Save(), sfd.FileName, sarc.IFileInfo.Alignment);
}
}
private void SaveCompressFile(byte[] data, string FileName, int Alignment = 0, bool EnableDialog = true)
{
if (EnableDialog)
{
DialogResult save = MessageBox.Show("Compress file?", "File Save", MessageBoxButtons.YesNo);
if (save == DialogResult.Yes)
data = EveryFileExplorer.YAZ0.Compress(data, 3, (uint)Alignment);
}
File.WriteAllBytes(FileName, data);
MessageBox.Show($"File has been saved to {FileName}");
Cursor.Current = Cursors.Default;
}
private void CallRecursive(TreeView treeView)
{
// Print each node recursively.
TreeNodeCollection nodes = treeView.Nodes;
foreach (TreeNode n in nodes)
{
PrintRecursive(n);
}
}
private void PrintRecursive(TreeNode treeNode)
{
// Print the node.
if (treeNode is SarcEntry)
{
((SarcEntry)treeNode).OnClick(treeNode.TreeView);
}
if (treeNode is IFileFormat)
{
}
// Print each node recursively.
foreach (TreeNode tn in treeNode.Nodes)
{
PrintRecursive(tn);
}
Cursor.Current = Cursors.WaitCursor;
SaveCompressFile(Save(), sfd.FileName, IFileInfo.Alignment);
}
}
private void SaveCompressFile(byte[] data, string FileName, int Alignment = 0, bool EnableDialog = true)
{
if (EnableDialog)
{
DialogResult save = MessageBox.Show("Compress file?", "File Save", MessageBoxButtons.YesNo);
if (save == DialogResult.Yes)
data = EveryFileExplorer.YAZ0.Compress(data, 3, (uint)Alignment);
}
File.WriteAllBytes(FileName, data);
MessageBox.Show($"File has been saved to {FileName}");
Cursor.Current = Cursors.Default;
}
private void CallRecursive(TreeView treeView)
{
// Print each node recursively.
TreeNodeCollection nodes = treeView.Nodes;
foreach (TreeNode n in nodes)
{
PrintRecursive(n);
}
}
private void PrintRecursive(TreeNode treeNode)
{
// Print the node.
if (treeNode is SarcEntry)
{
((SarcEntry)treeNode).OnClick(treeNode.TreeView);
}
if (treeNode is IFileFormat)
{
}
// Print each node recursively.
foreach (TreeNode tn in treeNode.Nodes)
{
PrintRecursive(tn);
}
}
public class SarcEntry : TreeNodeCustom
{
public SARC sarc; //Sarc file the entry is located in
@ -409,13 +399,14 @@ namespace FirstPlugin
fileFormat.IFileInfo = new IFileInfo();
fileFormat.IFileInfo.ArchiveHash = sarcEntry.sarcHash;
fileFormat.IFileInfo.InArchive = true;
if (fileFormat.EditorRoot == null)
return null;
fileFormat.EditorRoot.ImageKey = sarcEntry.ImageKey;
fileFormat.EditorRoot.SelectedImageKey = sarcEntry.SelectedImageKey;
fileFormat.EditorRoot.Text = sarcEntry.Text;
return fileFormat.EditorRoot;
if (fileFormat is TreeNode)
{
((TreeNode)fileFormat).Text = sarcEntry.Text;
((TreeNode)fileFormat).ImageKey = sarcEntry.ImageKey;
((TreeNode)fileFormat).SelectedImageKey = sarcEntry.SelectedImageKey;
return (TreeNode)fileFormat;
}
}
if (fileFormat.Magic == string.Empty)
{
@ -430,12 +421,14 @@ namespace FirstPlugin
fileFormat.IFileInfo = new IFileInfo();
fileFormat.IFileInfo.ArchiveHash = sarcEntry.sarcHash;
fileFormat.IFileInfo.InArchive = true;
if (fileFormat.EditorRoot == null)
return null;
fileFormat.EditorRoot.ImageKey = sarcEntry.ImageKey;
fileFormat.EditorRoot.SelectedImageKey = sarcEntry.SelectedImageKey;
fileFormat.EditorRoot.Text = sarcEntry.Text;
return fileFormat.EditorRoot;
if (fileFormat is TreeNode)
{
((TreeNode)fileFormat).Text = sarcEntry.Text;
((TreeNode)fileFormat).ImageKey = sarcEntry.ImageKey;
((TreeNode)fileFormat).SelectedImageKey = sarcEntry.SelectedImageKey;
return (TreeNode)fileFormat;
}
}
}
}

View File

@ -117,7 +117,7 @@ namespace FirstPlugin
}
}
public class BNTX : IFileFormat
public class BNTX : TreeNodeFile, IFileFormat
{
public bool CanSave { get; set; } = false;
public bool FileIsEdited { get; set; } = false;
@ -128,7 +128,6 @@ namespace FirstPlugin
public CompressionType CompressionType { get; set; } = CompressionType.None;
public byte[] Data { get; set; }
public string FileName { get; set; }
public TreeNodeFile EditorRoot { get; set; }
public bool IsActive { get; set; } = false;
public bool UseEditMenu { get; set; } = false;
public int Alignment { get; set; } = 0;
@ -183,86 +182,9 @@ namespace FirstPlugin
}
}
}
/*
byte[] ByteBuffer = File.ReadAllBytes(ofd.FileName);
byte[] StringBytes = Encoding.UTF8.GetBytes("BNTX");
try
{
while (true)
{
byte byt = reader.ReadByte();
if (byt == 0x42)
{
reader.Seek(-1, SeekOrigin.Current);
int TryRdMagic = reader.ReadInt32();
if (TryRdMagic == 0x424E5458)
{
reader.ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian;
long BNTXpos = reader.Position - 4;
Console.WriteLine("String was found at offset {0}", reader.Position);
reader.Seek(BNTXpos + 16, SeekOrigin.Begin);
int offsetName = reader.ReadInt32();
reader.Seek(BNTXpos + offsetName, SeekOrigin.Begin);
string Name = reader.ReadString();
reader.Seek(BNTXpos + 28, SeekOrigin.Begin);
int size = reader.ReadInt32();
reader.Seek(BNTXpos, SeekOrigin.Begin);
File.WriteAllBytes(Name + ".bntx", reader.ReadBytes(size));
reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
}
}
}
}
catch
{
}
}
}*/
BinaryTextureContainer bntx;
public void Load()
{
IFileInfo = new IFileInfo();
IsActive = true;
UseEditMenu = true;
CanSave = true;
bntx = new BinaryTextureContainer(Data, FileName, "", this);
EditorRoot = bntx;
}
public void Unload()
{
foreach (TextureData tex in bntx.Textures.Values)
{
tex.mipmaps.Clear();
tex.renderedGLTex = null;
}
bntx.Textures.Clear();
bntx.Nodes.Clear();
}
public byte[] Save()
{
return bntx.Save();
}
}
public class BinaryTextureContainer : TreeNodeFile
{
public Dictionary<string, TextureData> Textures;
public byte[] Data;
public PropertieGridData prop;
public BntxFile BinaryTexFile;
public string FileNameText;
@ -297,24 +219,26 @@ namespace FirstPlugin
}
}
public BinaryTextureContainer()
public void Load()
{
ImageKey = "bntx";
SelectedImageKey = "bntx";
}
public BinaryTextureContainer(byte[] data, string Name = "", string FileName = "", IFileFormat handler = null)
{
if (data.Length == 0)
data = CreateNewBNTX(Name);
IFileInfo = new IFileInfo();
IsActive = true;
UseEditMenu = true;
CanSave = true;
ImageKey = "bntx";
SelectedImageKey = "bntx";
FileNameText = FileName;
LoadFile(data, Name);
if (Data.Length == 0)
Data = CreateNewBNTX(Name);
LoadFile(Data, Name);
PluginRuntime.bntxContainers.Add(this);
FileHandler = handler;
//Check if bntx is parented to determine if an archive is used
bool checkParent = HasParent;
@ -327,19 +251,31 @@ namespace FirstPlugin
ContextMenu.MenuItems.Add(exportAll);
ContextMenu.MenuItems.Add(clear);
save.Click += Save;
replace.Click += Import;
rename.Click += Rename;
save.Click += Save;
replace.Click += Import;
rename.Click += Rename;
importTex.Click += ImportTexture;
exportAll.Click += ExportAll;
clear.Click += Clear;
clear.Click += Clear;
}
public void Unload()
{
foreach (TextureData tex in Textures.Values)
{
tex.mipmaps.Clear();
tex.renderedGLTex = null;
}
Textures.Clear();
Nodes.Clear();
}
private byte[] CreateNewBNTX(string Name)
{
MemoryStream mem = new MemoryStream();
BntxFile bntx = new BntxFile();
bntx.Target = new char[] { 'N', 'X', ' ', ' '};
bntx.Target = new char[] { 'N', 'X', ' ', ' ' };
bntx.Name = Name;
bntx.Alignment = 0xC;
bntx.TargetAddressSize = 0x40;
@ -390,7 +326,7 @@ namespace FirstPlugin
foreach (Texture tex in BinaryTexFile.Textures)
{
TextureData texData = new TextureData(tex, BinaryTexFile);
// texData.LoadOpenGLTexture();
// texData.LoadOpenGLTexture();
Nodes.Add(texData);
Textures.Add(tex.Name, texData);
@ -483,7 +419,7 @@ namespace FirstPlugin
}
}
}
settings.Clear();
GC.Collect();
Cursor.Current = Cursors.Default;
@ -656,7 +592,7 @@ namespace FirstPlugin
else if (form.Index == 5)
tex.SaveBitMap(folderPath + '\\' + tex.Text + ".tiff");
}
}
}
}
}
public byte[] Save()
@ -747,11 +683,11 @@ namespace FirstPlugin
SaveFileDialog sfd = new SaveFileDialog();
sfd.DefaultExt = "bntx";
sfd.Filter = "Supported Formats|*.bntx;";
sfd.FileName = FileHandler.FileName;
sfd.FileName = FileName;
if (sfd.ShowDialog() == DialogResult.OK)
{
File.WriteAllBytes(sfd.FileName, FileHandler.Save());
File.WriteAllBytes(sfd.FileName, Save());
}
}
}
@ -1111,7 +1047,7 @@ namespace FirstPlugin
}
private void Remove(object sender, EventArgs args)
{
((BinaryTextureContainer)Parent).RemoveTexture(this);
((BNTX)Parent).RemoveTexture(this);
}
private void Rename(object sender, EventArgs args)
{
@ -1120,10 +1056,10 @@ namespace FirstPlugin
if (dialog.ShowDialog() == DialogResult.OK)
{
((BinaryTextureContainer)Parent).Textures.Remove(Text);
((BNTX)Parent).Textures.Remove(Text);
Text = dialog.textBox1.Text;
((BinaryTextureContainer)Parent).Textures.Add(Text, this);
((BNTX)Parent).Textures.Add(Text, this);
}
}
private void Replace(object sender, EventArgs args)
@ -1162,7 +1098,7 @@ namespace FirstPlugin
break;
default:
setting.LoadBitMap(FileName, bntxFile);
importer.LoadSetting(setting, (BinaryTextureContainer)Parent);
importer.LoadSetting(setting, (BNTX)Parent);
break;
}

View File

@ -2,6 +2,9 @@
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using Switch_Toolbox.Library;
using Switch_Toolbox.Library.IO;
using System.Windows.Forms;
namespace FirstPlugin
{
@ -18,7 +21,65 @@ namespace FirstPlugin
GeometryShaderProgram = 0x09,
}
/* public class GTXHeader
public class GTXFile : TreeNode, IFileFormat
{
public bool CanSave { get; set; } = false;
public bool FileIsEdited { get; set; } = false;
public bool FileIsCompressed { get; set; } = false;
public string[] Description { get; set; } = new string[] { "GTX" };
public string[] Extension { get; set; } = new string[] { "*.gtx" };
public string Magic { get; set; } = "Gfx2 ";
public CompressionType CompressionType { get; set; } = CompressionType.None;
public byte[] Data { get; set; }
public string FileName { get; set; }
public bool IsActive { get; set; } = false;
public bool UseEditMenu { get; set; } = false;
public string FilePath { get; set; }
public IFileInfo IFileInfo { get; set; }
public Type[] Types
{
get
{
List<Type> types = new List<Type>();
return types.ToArray();
}
}
private GTXHeader header;
private GTXDataBlock block;
public void Load()
{
CanSave = true;
ReadGx2(new FileReader(Data));
ContextMenu = new ContextMenu();
MenuItem save = new MenuItem("Save");
ContextMenu.MenuItems.Add(save);
save.Click += Save;
}
private void Save(object sender, EventArgs args)
{
Save();
}
private void ReadGx2(FileReader reader)
{
header = new GTXHeader();
header.Read(reader);
}
public void Unload()
{
}
public byte[] Save()
{
System.IO.MemoryStream mem = new System.IO.MemoryStream();
return mem.ToArray();
}
public class GTXHeader
{
public uint MajorVersion;
public uint MinorVersion;
@ -36,39 +97,70 @@ namespace FirstPlugin
MinorVersion = reader.ReadUInt32();
GpuVersion = reader.ReadUInt32();
AlignMode = reader.ReadUInt32();
uint Reserved = reader.ReadUInt32();
uint Reserved2 = reader.ReadUInt32();
}
public void Write(FileWriter reader)
public void Write(FileWriter writer)
{
writer.WriteSignature("Gfx2");
writer.Write(MajorVersion);
writer.Write(MinorVersion);
writer.Write(GpuVersion);
writer.Write(AlignMode);
}
}
public class GTXDataBlock
{
public uint HeaderSize;
public uint MajorVersion;
public uint MinorVersion;
public BlockType BlockType;
public uint Identifier;
public uint index;
public uint DataSize;
public void Read(FileReader reader, GTXHeader header)
{
string Signature = reader.ReadString(4, Encoding.ASCII);
if (Signature != "BLK")
throw new Exception($"Invalid signature {Signature}! Expected BLK.");
uint HeaderSize = reader.ReadUInt32();
HeaderSize = reader.ReadUInt32();
MajorVersion = reader.ReadUInt32(); //Must be 0x01 for 6.x.x
MinorVersion = reader.ReadUInt32(); //Must be 0x00 for 6.x.x
BlockType = reader.ReadEnum<BlockType>(false);
uint DataSize = reader.ReadUInt32();
DataSize = reader.ReadUInt32();
Identifier = reader.ReadUInt32();
index = reader.ReadUInt32();
}
}*/
public void Write(FileWriter writer)
{
writer.WriteSignature("BLK");
writer.Write(HeaderSize);
writer.Write(MajorVersion);
writer.Write(MinorVersion);
writer.Write(BlockType, true);
writer.Write(DataSize);
writer.Write(Identifier);
writer.Write(index);
}
}
public class TextureInfo
{
public void Read(FileReader reader)
{
}
public void Write(FileWriter writer)
{
}
}
}
public class GTX
{
//From https://github.com/jam1garner/Smash-Forge/blob/master/Smash%20Forge/Filetypes/Textures/GTX.cs
//Some enums and parts from https://github.com/jam1garner/Smash-Forge/blob/master/Smash%20Forge/Filetypes/Textures/GTX.cs
//Todo. Add swizzling back
public struct GX2Surface
{

View File

@ -11,7 +11,7 @@ using Switch_Toolbox.Library.Forms;
namespace FirstPlugin
{
public class NUTEXB : IFileFormat
public class NUTEXB : TreeNodeFile, IFileFormat
{
public bool CanSave { get; set; } = false;
public bool FileIsEdited { get; set; } = false;
@ -136,7 +136,7 @@ namespace FirstPlugin
{
foreach (string file in ofd.FileNames)
{
NuTex texture = new NuTex();
NUTEXB texture = new NUTEXB();
texture.Read(new FileReader(file));
Console.WriteLine(texture.Format.ToString("x") + " " + file + " " + texture.Text);
@ -154,7 +154,7 @@ namespace FirstPlugin
}
catch
{
Console.WriteLine("Somethign went wrong??");
Console.WriteLine("Something went wrong??");
}
texture.blocksCompressed.Clear();
texture.mipmaps.Clear();
@ -166,427 +166,418 @@ namespace FirstPlugin
}
}
}
public class NuTex : TreeNodeFile
public bool BadSwizzle;
public uint Width;
public uint Height;
public uint unk;
public int unk2;
public int unk3;
public NUTEXImageFormat Format;
public List<uint[]> mipSizes = new List<uint[]>();
public int Alignment;
public List<List<byte[]>> mipmaps = new List<List<byte[]>>();
public List<List<byte[]>> blocksCompressed = new List<List<byte[]>>();
bool IsSwizzled = true;
public string ArcOffset; //Temp for exporting in batch
private void Replace(object sender, EventArgs args)
{
public bool BadSwizzle;
public uint Width;
public uint Height;
public uint unk;
public int unk2;
public int unk3;
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Supported Formats|*.dds; *.png;*.tga;*.jpg;*.tiff|" +
"Microsoft DDS |*.dds|" +
"Portable Network Graphics |*.png|" +
"Joint Photographic Experts Group |*.jpg|" +
"Bitmap Image |*.bmp|" +
"Tagged Image File Format |*.tiff|" +
"All files(*.*)|*.*";
public NUTEXImageFormat Format;
public List<uint[]> mipSizes = new List<uint[]>();
public int Alignment;
public List<List<byte[]>> mipmaps = new List<List<byte[]>>();
public List<List<byte[]>> blocksCompressed = new List<List<byte[]>>();
bool IsSwizzled = true;
public string ArcOffset; //Temp for exporting in batch
MenuItem save = new MenuItem("Save");
MenuItem export = new MenuItem("Export");
MenuItem replace = new MenuItem("Replace");
public NuTex()
ofd.Multiselect = false;
if (ofd.ShowDialog() == DialogResult.OK)
{
ImageKey = "Texture";
SelectedImageKey = "Texture";
throw new Exception("Saving is not supported yet!");
ContextMenu = new ContextMenu();
ContextMenu.MenuItems.Add(save);
ContextMenu.MenuItems.Add(export);
ContextMenu.MenuItems.Add(replace);
var bntxFile = new BNTX();
var tex = new TextureData();
tex.Replace(ofd.FileName);
blocksCompressed = tex.Texture.TextureData;
mipmaps = tex.mipmaps;
Width = tex.Texture.Width;
Height = tex.Texture.Height;
save.Click += Save;
replace.Click += Replace;
export.Click += Export;
}
private void Replace(object sender, EventArgs args)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Supported Formats|*.dds; *.png;*.tga;*.jpg;*.tiff|" +
"Microsoft DDS |*.dds|" +
"Portable Network Graphics |*.png|" +
"Joint Photographic Experts Group |*.jpg|" +
"Bitmap Image |*.bmp|" +
"Tagged Image File Format |*.tiff|" +
"All files(*.*)|*.*";
ofd.Multiselect = false;
if (ofd.ShowDialog() == DialogResult.OK)
{
throw new Exception("Not finished yet!");
var bntxFile = new BinaryTextureContainer();
var tex = new TextureData();
tex.Replace(ofd.FileName);
blocksCompressed = tex.Texture.TextureData;
mipmaps = tex.mipmaps;
Width = tex.Texture.Width;
Height = tex.Texture.Height;
UpdateEditor();
}
}
private void Export(object sender, EventArgs args)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.FileName = Text;
sfd.DefaultExt = "png";
sfd.Filter = "Supported Formats|*.dds; *.png;*.tga;*.jpg;*.tiff|" +
"Microsoft DDS |*.dds|" +
"Portable Network Graphics |*.png|" +
"Joint Photographic Experts Group |*.jpg|" +
"Bitmap Image |*.bmp|" +
"Tagged Image File Format |*.tiff|" +
"All files(*.*)|*.*";
if (sfd.ShowDialog() == DialogResult.OK)
{
Export(sfd.FileName);
}
}
private void Save(object sender, EventArgs args)
{
List<IFileFormat> formats = new List<IFileFormat>();
formats.Add(FileHandler);
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = Utils.GetAllFilters(formats);
sfd.FileName = FileHandler.FileName;
if (sfd.ShowDialog() == DialogResult.OK)
{
Cursor.Current = Cursors.WaitCursor;
System.IO.File.WriteAllBytes(sfd.FileName, FileHandler.Save());
}
}
public void Export(string FileName, bool ExportSurfaceLevel = false,
bool ExportMipMapLevel = false, int SurfaceLevel = 0, int MipLevel = 0)
{
string ext = System.IO.Path.GetExtension(FileName);
ext = ext.ToLower();
switch (ext)
{
case ".dds":
SaveDDS(FileName);
break;
default:
SaveBitMap(FileName);
break;
}
}
internal void SaveBitMap(string FileName, int SurfaceLevel = 0, int MipLevel = 0)
{
Bitmap bitMap = DisplayTexture(SurfaceLevel, MipLevel);
bitMap.Save(FileName);
}
internal void SaveDDS(string FileName)
{
DDS dds = new DDS();
dds.header = new DDS.Header();
dds.header.width = Width;
dds.header.height = Height;
dds.header.mipmapCount = (uint)mipmaps.Count;
dds.header.pitchOrLinearSize = (uint)mipmaps[0][0].Length;
if (IsCompressedFormat((NUTEXImageFormat)Format))
dds.SetFlags(GetCompressedDXGI_FORMAT((NUTEXImageFormat)Format));
else
dds.SetFlags(GetUncompressedDXGI_FORMAT((NUTEXImageFormat)Format));
dds.Save(dds, FileName, mipmaps);
}
public void Read(FileReader reader)
{
ImageKey = "Texture";
SelectedImageKey = "Texture";
long pos = reader.BaseStream.Length;
string magic = reader.ReadMagic((int)pos - 7, 3);//Check magic first!
if (magic != "XET")
throw new Exception($"Invalid magic! Expected XET but got {magic}");
reader.Seek(pos - 112, System.IO.SeekOrigin.Begin); //Subtract size where the name occurs
byte padding = reader.ReadByte();
Text = reader.ReadString(Syroot.BinaryData.BinaryStringFormat.ZeroTerminated);
reader.Seek(pos - 48, System.IO.SeekOrigin.Begin); //Subtract size of header
uint padding2 = reader.ReadUInt32();
Width = reader.ReadUInt32();
Height = reader.ReadUInt32();
unk3 = reader.ReadInt32();
Format = reader.ReadEnum<NUTEXImageFormat>(true);
unk = reader.ReadByte(); //Related to pixel size??
ushort padding3 = reader.ReadUInt16();
unk2 = reader.ReadInt32();
uint mipCount = reader.ReadUInt32();
Alignment = reader.ReadInt32();
uint ArrayCount = reader.ReadUInt32(); //6 for cubemaps
int imagesize = reader.ReadInt32();
reader.Seek(imagesize, System.IO.SeekOrigin.Begin); //Get mipmap sizes
for (int arrayLevel = 0; arrayLevel < ArrayCount; arrayLevel++)
{
long mipPos = reader.Position;
uint[] mips = reader.ReadUInt32s((int)mipCount);
mipSizes.Add(mips);
//Each mip section is 0x40 size for each array
//Seek to next one
reader.Seek(mipPos + 0x40, System.IO.SeekOrigin.Begin);
}
reader.Seek(0, System.IO.SeekOrigin.Begin);
for (int arrayLevel = 1; arrayLevel < ArrayCount + 1; arrayLevel++)
{
List<byte[]> mipmaps = new List<byte[]>();
for (int mipLevel = 0; mipLevel < mipCount; mipLevel++)
{
//Get the size from the size array
int size = (int)mipSizes[arrayLevel - 1][mipLevel];
//Align the size
if (mipLevel == 0)
if (size % Alignment != 0) size = size + (Alignment - (size % Alignment));
mipmaps.Add(reader.ReadBytes(imagesize));
break;
}
blocksCompressed.Add(mipmaps);
//Seek the next array
reader.Seek(imagesize / (int)ArrayCount, System.IO.SeekOrigin.Begin);
}
LoadTexture();
}
public void Write(FileWriter writer)
{
int arrayCount = blocksCompressed.Count;
foreach (var array in blocksCompressed)
{
writer.Write(array[0]); //Write textue block first
}
long headerStart = writer.Position;
foreach (var mips in mipSizes)
{
long MipStart = writer.Position;
writer.Write(mips); //Write textue block first
writer.Seek(MipStart + 0x40, System.IO.SeekOrigin.Begin);
}
long stringPos = writer.Position;
writer.Write((byte)0x20);
writer.WriteString(Text);
writer.Seek(stringPos + 0x40, System.IO.SeekOrigin.Begin);
writer.Seek(4); //padding
writer.Write(Width);
writer.Write(Height);
writer.Write(unk3);
writer.Write((byte)Format);
writer.Write((byte)unk);
writer.Seek(2); //padding
writer.Write(unk2);
writer.Write(blocksCompressed[0].Count);
writer.Write(Alignment);
writer.Write(arrayCount);
writer.Write(blocksCompressed[0][0].Length * arrayCount);
writer.WriteSignature(" XET");
writer.Write(131073);
}
public override void OnClick(TreeView treeView)
{
UpdateEditor();
}
}
private void Export(object sender, EventArgs args)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.FileName = Text;
sfd.DefaultExt = "png";
sfd.Filter = "Supported Formats|*.dds; *.png;*.tga;*.jpg;*.tiff|" +
"Microsoft DDS |*.dds|" +
"Portable Network Graphics |*.png|" +
"Joint Photographic Experts Group |*.jpg|" +
"Bitmap Image |*.bmp|" +
"Tagged Image File Format |*.tiff|" +
"All files(*.*)|*.*";
public Bitmap DisplayTexture(int ArrayIndex = 0, int DisplayMipIndex = 0)
if (sfd.ShowDialog() == DialogResult.OK)
{
if (BadSwizzle)
return BitmapExtension.GetBitmap(Properties.Resources.Black, 32, 32);
if (IsSwizzled)
LoadTexture();
else
mipmaps.Add(blocksCompressed[ArrayIndex]);
if (mipmaps[0].Count <= 0)
{
return BitmapExtension.GetBitmap(Properties.Resources.Black, 32, 32);
}
Console.WriteLine(ArrayIndex);
uint width = (uint)Math.Max(1, Width >> DisplayMipIndex);
uint height = (uint)Math.Max(1, Height >> DisplayMipIndex);
byte[] data = mipmaps[ArrayIndex][DisplayMipIndex];
return DecodeBlock(data, width, height, (NUTEXImageFormat)Format);
}
public static Bitmap DecodeBlock(byte[] data, uint Width, uint Height, NUTEXImageFormat Format)
{
Bitmap decomp;
Console.WriteLine(Format);
if (Format == NUTEXImageFormat.BC5_SNORM)
return DDSCompressor.DecompressBC5(data, (int)Width, (int)Height, true);
byte[] d = null;
if (IsCompressedFormat(Format))
d = DDSCompressor.DecompressBlock(data, (int)Width, (int)Height, GetCompressedDXGI_FORMAT(Format));
else
d = DDSCompressor.DecodePixelBlock(data, (int)Width, (int)Height, GetUncompressedDXGI_FORMAT(Format));
if (d != null)
{
decomp = BitmapExtension.GetBitmap(d, (int)Width, (int)Height);
return TextureData.SwapBlueRedChannels(decomp);
}
return null;
}
private static DDS.DXGI_FORMAT GetUncompressedDXGI_FORMAT(NUTEXImageFormat Format)
{
switch (Format)
{
case NUTEXImageFormat.R32G32B32A32_FLOAT: return DDS.DXGI_FORMAT.DXGI_FORMAT_R32G32B32A32_FLOAT;
case NUTEXImageFormat.R8G8B8A8_UNORM: return DDS.DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM;
case NUTEXImageFormat.R8G8B8A8_SRGB: return DDS.DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM;
case NUTEXImageFormat.B8G8R8A8_UNORM: return DDS.DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_UNORM;
case NUTEXImageFormat.B8G8R8A8_SRGB: return DDS.DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_UNORM;
default:
throw new Exception($"Cannot convert format {Format}");
}
}
private static DDS.DXGI_FORMAT GetCompressedDXGI_FORMAT(NUTEXImageFormat Format)
{
//This uses UNORM instead of SRGB due to decod
switch (Format)
{
case NUTEXImageFormat.BC1_UNORM: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC1_UNORM;
case NUTEXImageFormat.BC1_SRGB: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC1_UNORM;
case NUTEXImageFormat.BC2_UNORM: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC2_UNORM;
case NUTEXImageFormat.BC2_SRGB: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC2_UNORM;
case NUTEXImageFormat.BC3_UNORM: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC3_UNORM;
case NUTEXImageFormat.BC3_SRGB: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC3_UNORM;
case NUTEXImageFormat.BC4_UNORM: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC4_UNORM;
case NUTEXImageFormat.BC4_SNORM: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC4_SNORM;
case NUTEXImageFormat.BC5_UNORM: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC5_UNORM;
case NUTEXImageFormat.BC5_SNORM: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC5_SNORM;
case NUTEXImageFormat.BC6_UFLOAT: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC6H_UF16;
case NUTEXImageFormat.BC7_UNORM: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC7_UNORM;
case NUTEXImageFormat.BC7_SRGB: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC7_UNORM;
default:
throw new Exception($"Cannot convert format {Format}");
}
}
private static bool IsCompressedFormat(NUTEXImageFormat Format)
{
switch (Format)
{
case NUTEXImageFormat.BC1_UNORM:
case NUTEXImageFormat.BC1_SRGB:
case NUTEXImageFormat.BC2_UNORM:
case NUTEXImageFormat.BC2_SRGB:
case NUTEXImageFormat.BC3_UNORM:
case NUTEXImageFormat.BC3_SRGB:
case NUTEXImageFormat.BC4_UNORM:
case NUTEXImageFormat.BC4_SNORM:
case NUTEXImageFormat.BC5_UNORM:
case NUTEXImageFormat.BC5_SNORM:
case NUTEXImageFormat.BC6_UFLOAT:
case NUTEXImageFormat.BC7_UNORM:
case NUTEXImageFormat.BC7_SRGB:
return true;
default:
return false;
}
}
public void LoadTexture(int target = 1)
{
mipmaps.Clear();
uint blk_dim = blk_dims((byte)Format);
uint blkWidth = blk_dim >> 4;
uint blkHeight = blk_dim & 0xF;
uint blockHeight = TegraX1Swizzle.GetBlockHeight(TegraX1Swizzle.DIV_ROUND_UP(Height, blkHeight));
uint BlockHeightLog2 = (uint)Convert.ToString(blockHeight, 2).Length - 1;
uint tileMode = 0;
int linesPerBlockHeight = (1 << (int)BlockHeightLog2) * 8;
uint bpp = bpps((byte)Format);
for (int arrayLevel = 0; arrayLevel < blocksCompressed.Count; arrayLevel++)
{
int blockHeightShift = 0;
List<byte[]> mips = new List<byte[]>();
for (int mipLevel = 0; mipLevel < blocksCompressed[arrayLevel].Count; mipLevel++)
{
uint width = (uint)Math.Max(1, Width >> mipLevel);
uint height = (uint)Math.Max(1, Height >> mipLevel);
uint size = TegraX1Swizzle.DIV_ROUND_UP(width, blkWidth) * TegraX1Swizzle.DIV_ROUND_UP(height, blkHeight) * bpp;
if (TegraX1Swizzle.pow2_round_up(TegraX1Swizzle.DIV_ROUND_UP(height, blkWidth)) < linesPerBlockHeight)
blockHeightShift += 1;
Console.WriteLine($"{blk_dim.ToString("x")} {bpp} {width} {height} {linesPerBlockHeight} {blkWidth} {blkHeight} {size} { blocksCompressed[arrayLevel][mipLevel].Length}");
try
{
byte[] result = TegraX1Swizzle.deswizzle(width, height, blkWidth, blkHeight, target, bpp, tileMode, (int)Math.Max(0, BlockHeightLog2 - blockHeightShift), blocksCompressed[arrayLevel][mipLevel]);
//Create a copy and use that to remove uneeded data
byte[] result_ = new byte[size];
Array.Copy(result, 0, result_, 0, size);
mips.Add(result_);
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show($"Failed to swizzle texture {Text}!");
Console.WriteLine(e);
BadSwizzle = true;
break;
}
}
mipmaps.Add(mips);
}
}
public void UpdateEditor()
{
if (Viewport.Instance.gL_ControlModern1.Visible == false)
PluginRuntime.FSHPDockState = WeifenLuo.WinFormsUI.Docking.DockState.Document;
NuTexEditor docked = (NuTexEditor)LibraryGUI.Instance.GetContentDocked(new NuTexEditor());
if (docked == null)
{
docked = new NuTexEditor();
LibraryGUI.Instance.LoadDockContent(docked, PluginRuntime.FSHPDockState);
}
docked.Text = Text;
docked.Dock = DockStyle.Fill;
docked.LoadProperty(this);
Export(sfd.FileName);
}
}
private void Save(object sender, EventArgs args)
{
List<IFileFormat> formats = new List<IFileFormat>();
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = Utils.GetAllFilters(formats);
sfd.FileName = FileName;
if (sfd.ShowDialog() == DialogResult.OK)
{
Cursor.Current = Cursors.WaitCursor;
System.IO.File.WriteAllBytes(sfd.FileName, Save());
}
}
public void Export(string FileName, bool ExportSurfaceLevel = false,
bool ExportMipMapLevel = false, int SurfaceLevel = 0, int MipLevel = 0)
{
string ext = System.IO.Path.GetExtension(FileName);
ext = ext.ToLower();
switch (ext)
{
case ".dds":
SaveDDS(FileName);
break;
default:
SaveBitMap(FileName);
break;
}
}
internal void SaveBitMap(string FileName, int SurfaceLevel = 0, int MipLevel = 0)
{
Bitmap bitMap = DisplayTexture(SurfaceLevel, MipLevel);
bitMap.Save(FileName);
}
internal void SaveDDS(string FileName)
{
DDS dds = new DDS();
dds.header = new DDS.Header();
dds.header.width = Width;
dds.header.height = Height;
dds.header.mipmapCount = (uint)mipmaps.Count;
dds.header.pitchOrLinearSize = (uint)mipmaps[0][0].Length;
if (IsCompressedFormat((NUTEXImageFormat)Format))
dds.SetFlags(GetCompressedDXGI_FORMAT((NUTEXImageFormat)Format));
else
dds.SetFlags(GetUncompressedDXGI_FORMAT((NUTEXImageFormat)Format));
dds.Save(dds, FileName, mipmaps);
}
public void Read(FileReader reader)
{
ImageKey = "Texture";
SelectedImageKey = "Texture";
long pos = reader.BaseStream.Length;
string magic = reader.ReadMagic((int)pos - 7, 3);//Check magic first!
if (magic != "XET")
throw new Exception($"Invalid magic! Expected XET but got {magic}");
reader.Seek(pos - 112, System.IO.SeekOrigin.Begin); //Subtract size where the name occurs
byte padding = reader.ReadByte();
Text = reader.ReadString(Syroot.BinaryData.BinaryStringFormat.ZeroTerminated);
reader.Seek(pos - 48, System.IO.SeekOrigin.Begin); //Subtract size of header
uint padding2 = reader.ReadUInt32();
Width = reader.ReadUInt32();
Height = reader.ReadUInt32();
unk3 = reader.ReadInt32();
Format = reader.ReadEnum<NUTEXImageFormat>(true);
unk = reader.ReadByte(); //Related to pixel size??
ushort padding3 = reader.ReadUInt16();
unk2 = reader.ReadInt32();
uint mipCount = reader.ReadUInt32();
Alignment = reader.ReadInt32();
uint ArrayCount = reader.ReadUInt32(); //6 for cubemaps
int imagesize = reader.ReadInt32();
reader.Seek(imagesize, System.IO.SeekOrigin.Begin); //Get mipmap sizes
for (int arrayLevel = 0; arrayLevel < ArrayCount; arrayLevel++)
{
long mipPos = reader.Position;
uint[] mips = reader.ReadUInt32s((int)mipCount);
mipSizes.Add(mips);
//Each mip section is 0x40 size for each array
//Seek to next one
reader.Seek(mipPos + 0x40, System.IO.SeekOrigin.Begin);
}
reader.Seek(0, System.IO.SeekOrigin.Begin);
for (int arrayLevel = 1; arrayLevel < ArrayCount + 1; arrayLevel++)
{
List<byte[]> mipmaps = new List<byte[]>();
for (int mipLevel = 0; mipLevel < mipCount; mipLevel++)
{
//Get the size from the size array
int size = (int)mipSizes[arrayLevel - 1][mipLevel];
//Align the size
if (mipLevel == 0)
if (size % Alignment != 0) size = size + (Alignment - (size % Alignment));
mipmaps.Add(reader.ReadBytes(imagesize));
break;
}
blocksCompressed.Add(mipmaps);
//Seek the next array
reader.Seek(imagesize / (int)ArrayCount, System.IO.SeekOrigin.Begin);
}
LoadTexture();
}
public void Write(FileWriter writer)
{
int arrayCount = blocksCompressed.Count;
foreach (var array in blocksCompressed)
{
writer.Write(array[0]); //Write textue block first
}
long headerStart = writer.Position;
foreach (var mips in mipSizes)
{
long MipStart = writer.Position;
writer.Write(mips); //Write textue block first
writer.Seek(MipStart + 0x40, System.IO.SeekOrigin.Begin);
}
long stringPos = writer.Position;
writer.Write((byte)0x20);
writer.WriteString(Text);
writer.Seek(stringPos + 0x40, System.IO.SeekOrigin.Begin);
writer.Seek(4); //padding
writer.Write(Width);
writer.Write(Height);
writer.Write(unk3);
writer.Write((byte)Format);
writer.Write((byte)unk);
writer.Seek(2); //padding
writer.Write(unk2);
writer.Write(blocksCompressed[0].Count);
writer.Write(Alignment);
writer.Write(arrayCount);
writer.Write(blocksCompressed[0][0].Length * arrayCount);
writer.WriteSignature(" XET");
writer.Write(131073);
}
public override void OnClick(TreeView treeView)
{
UpdateEditor();
}
public Bitmap DisplayTexture(int ArrayIndex = 0, int DisplayMipIndex = 0)
{
if (BadSwizzle)
return BitmapExtension.GetBitmap(Properties.Resources.Black, 32, 32);
if (IsSwizzled)
LoadTexture();
else
mipmaps.Add(blocksCompressed[ArrayIndex]);
if (mipmaps[0].Count <= 0)
{
return BitmapExtension.GetBitmap(Properties.Resources.Black, 32, 32);
}
Console.WriteLine(ArrayIndex);
uint width = (uint)Math.Max(1, Width >> DisplayMipIndex);
uint height = (uint)Math.Max(1, Height >> DisplayMipIndex);
byte[] data = mipmaps[ArrayIndex][DisplayMipIndex];
return DecodeBlock(data, width, height, (NUTEXImageFormat)Format);
}
public static Bitmap DecodeBlock(byte[] data, uint Width, uint Height, NUTEXImageFormat Format)
{
Bitmap decomp;
Console.WriteLine(Format);
if (Format == NUTEXImageFormat.BC5_SNORM)
return DDSCompressor.DecompressBC5(data, (int)Width, (int)Height, true);
byte[] d = null;
if (IsCompressedFormat(Format))
d = DDSCompressor.DecompressBlock(data, (int)Width, (int)Height, GetCompressedDXGI_FORMAT(Format));
else
d = DDSCompressor.DecodePixelBlock(data, (int)Width, (int)Height, GetUncompressedDXGI_FORMAT(Format));
if (d != null)
{
decomp = BitmapExtension.GetBitmap(d, (int)Width, (int)Height);
return TextureData.SwapBlueRedChannels(decomp);
}
return null;
}
private static DDS.DXGI_FORMAT GetUncompressedDXGI_FORMAT(NUTEXImageFormat Format)
{
switch (Format)
{
case NUTEXImageFormat.R32G32B32A32_FLOAT: return DDS.DXGI_FORMAT.DXGI_FORMAT_R32G32B32A32_FLOAT;
case NUTEXImageFormat.R8G8B8A8_UNORM: return DDS.DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM;
case NUTEXImageFormat.R8G8B8A8_SRGB: return DDS.DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM;
case NUTEXImageFormat.B8G8R8A8_UNORM: return DDS.DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_UNORM;
case NUTEXImageFormat.B8G8R8A8_SRGB: return DDS.DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_UNORM;
default:
throw new Exception($"Cannot convert format {Format}");
}
}
private static DDS.DXGI_FORMAT GetCompressedDXGI_FORMAT(NUTEXImageFormat Format)
{
//This uses UNORM instead of SRGB due to decod
switch (Format)
{
case NUTEXImageFormat.BC1_UNORM: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC1_UNORM;
case NUTEXImageFormat.BC1_SRGB: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC1_UNORM;
case NUTEXImageFormat.BC2_UNORM: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC2_UNORM;
case NUTEXImageFormat.BC2_SRGB: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC2_UNORM;
case NUTEXImageFormat.BC3_UNORM: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC3_UNORM;
case NUTEXImageFormat.BC3_SRGB: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC3_UNORM;
case NUTEXImageFormat.BC4_UNORM: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC4_UNORM;
case NUTEXImageFormat.BC4_SNORM: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC4_SNORM;
case NUTEXImageFormat.BC5_UNORM: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC5_UNORM;
case NUTEXImageFormat.BC5_SNORM: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC5_SNORM;
case NUTEXImageFormat.BC6_UFLOAT: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC6H_UF16;
case NUTEXImageFormat.BC7_UNORM: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC7_UNORM;
case NUTEXImageFormat.BC7_SRGB: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC7_UNORM;
default:
throw new Exception($"Cannot convert format {Format}");
}
}
private static bool IsCompressedFormat(NUTEXImageFormat Format)
{
switch (Format)
{
case NUTEXImageFormat.BC1_UNORM:
case NUTEXImageFormat.BC1_SRGB:
case NUTEXImageFormat.BC2_UNORM:
case NUTEXImageFormat.BC2_SRGB:
case NUTEXImageFormat.BC3_UNORM:
case NUTEXImageFormat.BC3_SRGB:
case NUTEXImageFormat.BC4_UNORM:
case NUTEXImageFormat.BC4_SNORM:
case NUTEXImageFormat.BC5_UNORM:
case NUTEXImageFormat.BC5_SNORM:
case NUTEXImageFormat.BC6_UFLOAT:
case NUTEXImageFormat.BC7_UNORM:
case NUTEXImageFormat.BC7_SRGB:
return true;
default:
return false;
}
}
public void LoadTexture(int target = 1)
{
mipmaps.Clear();
uint blk_dim = blk_dims((byte)Format);
uint blkWidth = blk_dim >> 4;
uint blkHeight = blk_dim & 0xF;
uint blockHeight = TegraX1Swizzle.GetBlockHeight(TegraX1Swizzle.DIV_ROUND_UP(Height, blkHeight));
uint BlockHeightLog2 = (uint)Convert.ToString(blockHeight, 2).Length - 1;
uint tileMode = 0;
int linesPerBlockHeight = (1 << (int)BlockHeightLog2) * 8;
uint bpp = bpps((byte)Format);
for (int arrayLevel = 0; arrayLevel < blocksCompressed.Count; arrayLevel++)
{
int blockHeightShift = 0;
List<byte[]> mips = new List<byte[]>();
for (int mipLevel = 0; mipLevel < blocksCompressed[arrayLevel].Count; mipLevel++)
{
uint width = (uint)Math.Max(1, Width >> mipLevel);
uint height = (uint)Math.Max(1, Height >> mipLevel);
uint size = TegraX1Swizzle.DIV_ROUND_UP(width, blkWidth) * TegraX1Swizzle.DIV_ROUND_UP(height, blkHeight) * bpp;
if (TegraX1Swizzle.pow2_round_up(TegraX1Swizzle.DIV_ROUND_UP(height, blkWidth)) < linesPerBlockHeight)
blockHeightShift += 1;
Console.WriteLine($"{blk_dim.ToString("x")} {bpp} {width} {height} {linesPerBlockHeight} {blkWidth} {blkHeight} {size} { blocksCompressed[arrayLevel][mipLevel].Length}");
try
{
byte[] result = TegraX1Swizzle.deswizzle(width, height, blkWidth, blkHeight, target, bpp, tileMode, (int)Math.Max(0, BlockHeightLog2 - blockHeightShift), blocksCompressed[arrayLevel][mipLevel]);
//Create a copy and use that to remove uneeded data
byte[] result_ = new byte[size];
Array.Copy(result, 0, result_, 0, size);
mips.Add(result_);
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show($"Failed to swizzle texture {Text}!");
Console.WriteLine(e);
BadSwizzle = true;
break;
}
}
mipmaps.Add(mips);
}
}
public void UpdateEditor()
{
if (Viewport.Instance.gL_ControlModern1.Visible == false)
PluginRuntime.FSHPDockState = WeifenLuo.WinFormsUI.Docking.DockState.Document;
NuTexEditor docked = (NuTexEditor)LibraryGUI.Instance.GetContentDocked(new NuTexEditor());
if (docked == null)
{
docked = new NuTexEditor();
LibraryGUI.Instance.LoadDockContent(docked, PluginRuntime.FSHPDockState);
}
docked.Text = Text;
docked.Dock = DockStyle.Fill;
docked.LoadProperty(this);
}
MenuItem save = new MenuItem("Save");
MenuItem export = new MenuItem("Export");
MenuItem replace = new MenuItem("Replace");
public void Load()
{
IsActive = true;
EditorRoot = new NuTex();
((NuTex)EditorRoot).FileHandler = this;
((NuTex)EditorRoot).ArcOffset = System.IO.Path.GetFileNameWithoutExtension(FileName);
((NuTex)EditorRoot).Read(new FileReader(Data));
Text = FileName;
Read(new FileReader(Data));
ImageKey = "Texture";
SelectedImageKey = "Texture";
ContextMenu = new ContextMenu();
ContextMenu.MenuItems.Add(save);
ContextMenu.MenuItems.Add(export);
ContextMenu.MenuItems.Add(replace);
save.Click += Save;
replace.Click += Replace;
export.Click += Export;
}
public void Unload()
{
@ -595,7 +586,7 @@ namespace FirstPlugin
public byte[] Save()
{
System.IO.MemoryStream mem = new System.IO.MemoryStream();
((NuTex)EditorRoot).Write(new FileWriter(mem));
Write(new FileWriter(mem));
return mem.ToArray();
}
}

View File

@ -11,7 +11,7 @@ using Switch_Toolbox.Library.IO;
namespace FirstPlugin
{
public class XTX : IFileFormat
public class XTX : TreeNodeFile, IFileFormat
{
public bool CanSave { get; set; } = false;
public bool FileIsEdited { get; set; } = false;
@ -22,7 +22,6 @@ namespace FirstPlugin
public CompressionType CompressionType { get; set; } = CompressionType.None;
public byte[] Data { get; set; }
public string FileName { get; set; }
public TreeNodeFile EditorRoot { get; set; }
public bool IsActive { get; set; } = false;
public bool UseEditMenu { get; set; } = false;
public string FilePath { get; set; }
@ -40,10 +39,8 @@ namespace FirstPlugin
public void Load()
{
IsActive = true;
EditorRoot = new XTXFile();
((XTXFile)EditorRoot).FileHandler = this;
((XTXFile)EditorRoot).Text = FileName;
((XTXFile)EditorRoot).LoadFile(Data);
Text = FileName;
LoadFile(Data);
}
public void Unload()
{
@ -126,265 +123,261 @@ namespace FirstPlugin
}
}
public class XTXFile : TreeNodeFile
public uint HeaderSize { get; set; }
public uint MajorVersion { get; set; }
public uint MinorVersion { get; set; }
public BlockHeader blockHeader { get; set; }
private const int texHeadBlkType = 2;
private const int dataBlkType = 3;
public void LoadFile(byte[] data)
{
public uint HeaderSize { get; set; }
public uint MajorVersion { get; set; }
public uint MinorVersion { get; set; }
public BlockHeader blockHeader { get; set; }
private const int texHeadBlkType = 2;
private const int dataBlkType = 3;
FileReader reader = new FileReader(new MemoryStream(data));
string Signature = reader.ReadString(4, Encoding.ASCII);
if (Signature != "DFvN")
throw new Exception($"Invalid signature {Signature}! Expected DFvN.");
public void LoadFile(byte[] data)
HeaderSize = reader.ReadUInt32();
MajorVersion = reader.ReadUInt32();
MinorVersion = reader.ReadUInt32();
blockHeader = new BlockHeader();
blockHeader.Read(reader);
}
public override void OnClick(TreeView treeview)
{
UpdateEditor();
}
public void UpdateEditor()
{
if (Viewport.Instance.gL_ControlModern1.Visible == false)
PluginRuntime.FSHPDockState = WeifenLuo.WinFormsUI.Docking.DockState.Document;
XTXEditor docked = (XTXEditor)LibraryGUI.Instance.GetContentDocked(new XTXEditor());
if (docked == null)
{
docked = new XTXEditor();
LibraryGUI.Instance.LoadDockContent(docked, PluginRuntime.FSHPDockState);
}
docked.Text = Text;
docked.Dock = DockStyle.Fill;
docked.LoadProperty(blockHeader.textureInfo);
}
public class BlockHeader
{
public uint BlockSize { get; set; }
public UInt64 DataSize { get; set; }
public uint BlockType { get; set; }
public uint GlobalBlockIndex { get; set; }
public uint IncBlockTypeIndex { get; set; }
public TextureInfo textureInfo { get; set; }
public long DataOffset;
public void Read(FileReader reader)
{
FileReader reader = new FileReader(new MemoryStream(data));
string Signature = reader.ReadString(4, Encoding.ASCII);
if (Signature != "DFvN")
throw new Exception($"Invalid signature {Signature}! Expected DFvN.");
if (Signature != "HBvN")
throw new Exception($"Invalid signature {Signature}! Expected HBvN.");
HeaderSize = reader.ReadUInt32();
MajorVersion = reader.ReadUInt32();
MinorVersion = reader.ReadUInt32();
BlockSize = reader.ReadUInt32();
DataSize = reader.ReadUInt64();
DataOffset = reader.ReadInt64();
BlockType = reader.ReadUInt32();
GlobalBlockIndex = reader.ReadUInt32();
IncBlockTypeIndex = reader.ReadUInt32();
blockHeader = new BlockHeader();
blockHeader.Read(reader);
if (BlockType == texHeadBlkType)
{
textureInfo = new TextureInfo();
textureInfo.Read(reader);
}
if (BlockType == dataBlkType)
{
}
}
}
public class TextureInfo : TreeNodeFile
{
public UInt64 DataSize { get; set; }
public uint Alignment { get; set; }
public uint Width { get; set; }
public uint Height { get; set; }
public uint Depth { get; set; }
public uint Target { get; set; }
public XTXFormats.XTXImageFormat Format { get; set; }
public uint MipCount { get; set; }
public uint SliceSize { get; set; }
public uint[] MipOffsets { get; set; }
public BlockHeader DataBlockHeader { get; set; }
public List<byte[]> mipmaps = new List<byte[]>();
public List<byte[]> compressedBlocks = new List<byte[]>();
public override void OnClick(TreeView treeview)
public void Read(FileReader reader)
{
UpdateEditor();
DataSize = reader.ReadUInt64();
Alignment = reader.ReadUInt32();
Width = reader.ReadUInt32();
Height = reader.ReadUInt32();
Depth = reader.ReadUInt32();
Target = reader.ReadUInt32();
Format = reader.ReadEnum<XTXFormats.XTXImageFormat>(true);
MipCount = reader.ReadUInt32();
SliceSize = reader.ReadUInt32();
long offPos = reader.Position;
MipOffsets = reader.ReadUInt32s((int)MipCount);
reader.Seek(offPos + 68, SeekOrigin.Begin);
byte[] Layout = reader.ReadBytes(8);
byte Sparse = reader.ReadByte();
reader.Seek(3);
long DataBlockOff = reader.Position;
DataBlockHeader = new BlockHeader();
DataBlockHeader.Read(reader);
reader.Seek(DataBlockOff + DataBlockHeader.DataOffset, SeekOrigin.Begin);
// data = reader.ReadBytes((int)DataBlockHeader.DataSize);
long datastart = reader.Position;
Console.WriteLine(DataBlockHeader.DataSize);
for (int i = 0; i < MipCount; i++)
{
int size = (int)((int)DataBlockHeader.DataSize - MipOffsets[i]);
Console.WriteLine(size);
using (reader.TemporarySeek(datastart + MipOffsets[i], System.IO.SeekOrigin.Begin))
{
compressedBlocks.Add(reader.ReadBytes(size));
}
if (compressedBlocks[i].Length == 0)
throw new System.Exception("Empty mip size!");
break; //Only first mip level works?
}
reader.Seek(DataBlockOff + DataBlockHeader.DataOffset + (long)DataBlockHeader.DataSize, SeekOrigin.Begin);
BlockHeader EndBlockHeader = new BlockHeader();
EndBlockHeader.Read(reader);
}
public void UpdateEditor()
public Bitmap DisplayImage(int mipLevel = 0, int arrayLevel = 0)
{
if (Viewport.Instance.gL_ControlModern1.Visible == false)
PluginRuntime.FSHPDockState = WeifenLuo.WinFormsUI.Docking.DockState.Document;
LoadTexture();
XTXEditor docked = (XTXEditor)LibraryGUI.Instance.GetContentDocked(new XTXEditor());
if (docked == null)
Bitmap decomp;
if (Format == XTXFormats.XTXImageFormat.BC5S)
return DDSCompressor.DecompressBC5(mipmaps[0], (int)Width, (int)Height, true);
byte[] d = null;
if (IsCompressedFormat(Format))
d = DDSCompressor.DecompressBlock(mipmaps[0], (int)Width, (int)Height, GetCompressedDXGI_FORMAT(Format));
else
d = DDSCompressor.DecodePixelBlock(mipmaps[0], (int)Width, (int)Height, GetUncompressedDXGI_FORMAT(Format));
if (d != null)
{
docked = new XTXEditor();
LibraryGUI.Instance.LoadDockContent(docked, PluginRuntime.FSHPDockState);
decomp = BitmapExtension.GetBitmap(d, (int)Width, (int)Height);
return TextureData.SwapBlueRedChannels(decomp);
}
docked.Text = Text;
docked.Dock = DockStyle.Fill;
docked.LoadProperty(blockHeader.textureInfo);
return null;
}
public class BlockHeader
private static DDS.DXGI_FORMAT GetCompressedDXGI_FORMAT(XTXFormats.XTXImageFormat Format)
{
public uint BlockSize { get; set; }
public UInt64 DataSize { get; set; }
public uint BlockType { get; set; }
public uint GlobalBlockIndex { get; set; }
public uint IncBlockTypeIndex { get; set; }
public TextureInfo textureInfo { get; set; }
public long DataOffset;
public void Read(FileReader reader)
switch (Format)
{
string Signature = reader.ReadString(4, Encoding.ASCII);
if (Signature != "HBvN")
throw new Exception($"Invalid signature {Signature}! Expected HBvN.");
BlockSize = reader.ReadUInt32();
DataSize = reader.ReadUInt64();
DataOffset = reader.ReadInt64();
BlockType = reader.ReadUInt32();
GlobalBlockIndex = reader.ReadUInt32();
IncBlockTypeIndex = reader.ReadUInt32();
if (BlockType == texHeadBlkType)
{
textureInfo = new TextureInfo();
textureInfo.Read(reader);
}
if (BlockType == dataBlkType)
{
}
case XTXFormats.XTXImageFormat.DXT1: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC1_UNORM;
case XTXFormats.XTXImageFormat.DXT3: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC2_UNORM;
case XTXFormats.XTXImageFormat.DXT5: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC3_UNORM;
case XTXFormats.XTXImageFormat.BC4U: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC4_UNORM;
case XTXFormats.XTXImageFormat.BC4S: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC4_SNORM;
case XTXFormats.XTXImageFormat.BC5U: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC5_UNORM;
case XTXFormats.XTXImageFormat.BC5S: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC5_SNORM;
default:
throw new Exception($"Cannot convert format {Format}");
}
}
public class TextureInfo : TreeNodeFile
private static bool IsCompressedFormat(XTXFormats.XTXImageFormat Format)
{
public UInt64 DataSize { get; set; }
public uint Alignment { get; set; }
public uint Width { get; set; }
public uint Height { get; set; }
public uint Depth { get; set; }
public uint Target { get; set; }
public XTXFormats.XTXImageFormat Format { get; set; }
public uint MipCount { get; set; }
public uint SliceSize { get; set; }
public uint[] MipOffsets { get; set; }
public BlockHeader DataBlockHeader { get; set; }
public List<byte[]> mipmaps = new List<byte[]>();
public List<byte[]> compressedBlocks = new List<byte[]>();
public void Read(FileReader reader)
switch (Format)
{
DataSize = reader.ReadUInt64();
Alignment = reader.ReadUInt32();
Width = reader.ReadUInt32();
Height = reader.ReadUInt32();
Depth = reader.ReadUInt32();
Target = reader.ReadUInt32();
Format = reader.ReadEnum<XTXFormats.XTXImageFormat>(true);
MipCount = reader.ReadUInt32();
SliceSize = reader.ReadUInt32();
long offPos = reader.Position;
MipOffsets = reader.ReadUInt32s((int)MipCount);
reader.Seek(offPos + 68, SeekOrigin.Begin);
byte[] Layout = reader.ReadBytes(8);
byte Sparse = reader.ReadByte();
reader.Seek(3);
long DataBlockOff = reader.Position;
DataBlockHeader = new BlockHeader();
DataBlockHeader.Read(reader);
reader.Seek(DataBlockOff + DataBlockHeader.DataOffset, SeekOrigin.Begin);
// data = reader.ReadBytes((int)DataBlockHeader.DataSize);
long datastart = reader.Position;
Console.WriteLine(DataBlockHeader.DataSize);
for (int i = 0; i < MipCount; i++)
{
int size = (int)((int)DataBlockHeader.DataSize - MipOffsets[i]);
Console.WriteLine(size);
using (reader.TemporarySeek(datastart + MipOffsets[i], System.IO.SeekOrigin.Begin))
{
compressedBlocks.Add(reader.ReadBytes(size));
}
if (compressedBlocks[i].Length == 0)
throw new System.Exception("Empty mip size!");
break; //Only first mip level works?
}
reader.Seek(DataBlockOff + DataBlockHeader.DataOffset + (long)DataBlockHeader.DataSize, SeekOrigin.Begin);
BlockHeader EndBlockHeader = new BlockHeader();
EndBlockHeader.Read(reader);
case XTXFormats.XTXImageFormat.DXT1:
case XTXFormats.XTXImageFormat.DXT3:
case XTXFormats.XTXImageFormat.DXT5:
case XTXFormats.XTXImageFormat.BC4U:
case XTXFormats.XTXImageFormat.BC4S:
case XTXFormats.XTXImageFormat.BC5U:
case XTXFormats.XTXImageFormat.BC5S:
return true;
default:
return false;
}
public Bitmap DisplayImage(int mipLevel = 0, int arrayLevel = 0)
}
private static DDS.DXGI_FORMAT GetUncompressedDXGI_FORMAT(XTXFormats.XTXImageFormat Format)
{
switch (Format)
{
LoadTexture();
Bitmap decomp;
if (Format == XTXFormats.XTXImageFormat.BC5S)
return DDSCompressor.DecompressBC5(mipmaps[0], (int)Width, (int)Height, true);
byte[] d = null;
if (IsCompressedFormat(Format))
d = DDSCompressor.DecompressBlock(mipmaps[0], (int)Width, (int)Height, GetCompressedDXGI_FORMAT(Format));
else
d = DDSCompressor.DecodePixelBlock(mipmaps[0], (int)Width, (int)Height, GetUncompressedDXGI_FORMAT(Format));
if (d != null)
{
decomp = BitmapExtension.GetBitmap(d, (int)Width, (int)Height);
return TextureData.SwapBlueRedChannels(decomp);
}
return null;
}
private static DDS.DXGI_FORMAT GetCompressedDXGI_FORMAT(XTXFormats.XTXImageFormat Format)
{
switch (Format)
{
case XTXFormats.XTXImageFormat.DXT1: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC1_UNORM;
case XTXFormats.XTXImageFormat.DXT3: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC2_UNORM;
case XTXFormats.XTXImageFormat.DXT5: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC3_UNORM;
case XTXFormats.XTXImageFormat.BC4U: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC4_UNORM;
case XTXFormats.XTXImageFormat.BC4S: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC4_SNORM;
case XTXFormats.XTXImageFormat.BC5U: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC5_UNORM;
case XTXFormats.XTXImageFormat.BC5S: return DDS.DXGI_FORMAT.DXGI_FORMAT_BC5_SNORM;
default:
throw new Exception($"Cannot convert format {Format}");
}
}
private static bool IsCompressedFormat(XTXFormats.XTXImageFormat Format)
{
switch (Format)
{
case XTXFormats.XTXImageFormat.DXT1:
case XTXFormats.XTXImageFormat.DXT3:
case XTXFormats.XTXImageFormat.DXT5:
case XTXFormats.XTXImageFormat.BC4U:
case XTXFormats.XTXImageFormat.BC4S:
case XTXFormats.XTXImageFormat.BC5U:
case XTXFormats.XTXImageFormat.BC5S:
return true;
default:
return false;
}
}
private static DDS.DXGI_FORMAT GetUncompressedDXGI_FORMAT(XTXFormats.XTXImageFormat Format)
{
switch (Format)
{
case XTXFormats.XTXImageFormat.NVN_FORMAT_R8: return DDS.DXGI_FORMAT.DXGI_FORMAT_R8_UNORM;
case XTXFormats.XTXImageFormat.NVN_FORMAT_RG8: return DDS.DXGI_FORMAT.DXGI_FORMAT_R8G8_UNORM;
case XTXFormats.XTXImageFormat.NVN_FORMAT_RGB10A2: return DDS.DXGI_FORMAT.DXGI_FORMAT_R10G10B10A2_UNORM;
case XTXFormats.XTXImageFormat.NVN_FORMAT_RGB565: return DDS.DXGI_FORMAT.DXGI_FORMAT_B5G6R5_UNORM;
case XTXFormats.XTXImageFormat.NVN_FORMAT_RGB5A1: return DDS.DXGI_FORMAT.DXGI_FORMAT_B5G5R5A1_UNORM;
case XTXFormats.XTXImageFormat.NVN_FORMAT_RGBA4: return DDS.DXGI_FORMAT.DXGI_FORMAT_B4G4R4A4_UNORM;
case XTXFormats.XTXImageFormat.NVN_FORMAT_RGBA8: return DDS.DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM;
case XTXFormats.XTXImageFormat.NVN_FORMAT_RGBA8_SRGB: return DDS.DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
default:
throw new Exception($"Cannot convert format {Format}");
}
}
public void LoadTexture()
{
mipmaps.Clear();
Console.WriteLine(Format);
uint blk_dim = XTXFormats.blk_dims((uint)((int)Format >> 8));
uint blkWidth = blk_dim >> 4;
uint blkHeight = blk_dim & 0xF;
uint blockHeight = TegraX1Swizzle.GetBlockHeight(TegraX1Swizzle.DIV_ROUND_UP(Height, blkHeight));
uint BlockHeightLog2 = (uint)Convert.ToString(blockHeight, 2).Length - 1;
int linesPerBlockHeight = (1 << (int)BlockHeightLog2) * 8;
int TileMode = 0;
uint bpp = XTXFormats.bpps((uint)Format);
int blockHeightShift = 0;
for (int mipLevel = 0; mipLevel < compressedBlocks.Count; mipLevel++)
{
uint width = (uint)Math.Max(1, Width >> mipLevel);
uint height = (uint)Math.Max(1, Height >> mipLevel);
// uint size = width * height * bpp;
uint size = TegraX1Swizzle.DIV_ROUND_UP(width, blkWidth) * TegraX1Swizzle.DIV_ROUND_UP(height, blkHeight) * bpp;
Console.WriteLine(mipLevel + " " + size);
if (TegraX1Swizzle.pow2_round_up(TegraX1Swizzle.DIV_ROUND_UP(height, blkWidth)) < linesPerBlockHeight)
blockHeightShift += 1;
byte[] result = TegraX1Swizzle.deswizzle(width, height, blkWidth, blkHeight, (int)Target, bpp, (uint)TileMode, (int)Math.Max(0, BlockHeightLog2 - blockHeightShift), compressedBlocks[mipLevel]);
//Create a copy and use that to remove uneeded data
byte[] result_ = new byte[size];
Array.Copy(result, 0, result_, 0, size);
mipmaps.Add(result_);
Console.WriteLine("bpp " + bpp);
Console.WriteLine("result_ " + size);
Console.WriteLine("width " + width);
Console.WriteLine("height " + height);
}
case XTXFormats.XTXImageFormat.NVN_FORMAT_R8: return DDS.DXGI_FORMAT.DXGI_FORMAT_R8_UNORM;
case XTXFormats.XTXImageFormat.NVN_FORMAT_RG8: return DDS.DXGI_FORMAT.DXGI_FORMAT_R8G8_UNORM;
case XTXFormats.XTXImageFormat.NVN_FORMAT_RGB10A2: return DDS.DXGI_FORMAT.DXGI_FORMAT_R10G10B10A2_UNORM;
case XTXFormats.XTXImageFormat.NVN_FORMAT_RGB565: return DDS.DXGI_FORMAT.DXGI_FORMAT_B5G6R5_UNORM;
case XTXFormats.XTXImageFormat.NVN_FORMAT_RGB5A1: return DDS.DXGI_FORMAT.DXGI_FORMAT_B5G5R5A1_UNORM;
case XTXFormats.XTXImageFormat.NVN_FORMAT_RGBA4: return DDS.DXGI_FORMAT.DXGI_FORMAT_B4G4R4A4_UNORM;
case XTXFormats.XTXImageFormat.NVN_FORMAT_RGBA8: return DDS.DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM;
case XTXFormats.XTXImageFormat.NVN_FORMAT_RGBA8_SRGB: return DDS.DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
default:
throw new Exception($"Cannot convert format {Format}");
}
}
public void LoadTexture()
{
mipmaps.Clear();
Console.WriteLine(Format);
uint blk_dim = XTXFormats.blk_dims((uint)((int)Format >> 8));
uint blkWidth = blk_dim >> 4;
uint blkHeight = blk_dim & 0xF;
uint blockHeight = TegraX1Swizzle.GetBlockHeight(TegraX1Swizzle.DIV_ROUND_UP(Height, blkHeight));
uint BlockHeightLog2 = (uint)Convert.ToString(blockHeight, 2).Length - 1;
int linesPerBlockHeight = (1 << (int)BlockHeightLog2) * 8;
int TileMode = 0;
uint bpp = XTXFormats.bpps((uint)Format);
int blockHeightShift = 0;
for (int mipLevel = 0; mipLevel < compressedBlocks.Count; mipLevel++)
{
uint width = (uint)Math.Max(1, Width >> mipLevel);
uint height = (uint)Math.Max(1, Height >> mipLevel);
// uint size = width * height * bpp;
uint size = TegraX1Swizzle.DIV_ROUND_UP(width, blkWidth) * TegraX1Swizzle.DIV_ROUND_UP(height, blkHeight) * bpp;
Console.WriteLine(mipLevel + " " + size);
if (TegraX1Swizzle.pow2_round_up(TegraX1Swizzle.DIV_ROUND_UP(height, blkWidth)) < linesPerBlockHeight)
blockHeightShift += 1;
byte[] result = TegraX1Swizzle.deswizzle(width, height, blkWidth, blkHeight, (int)Target, bpp, (uint)TileMode, (int)Math.Max(0, BlockHeightLog2 - blockHeightShift), compressedBlocks[mipLevel]);
//Create a copy and use that to remove uneeded data
byte[] result_ = new byte[size];
Array.Copy(result, 0, result_, 0, size);
mipmaps.Add(result_);
Console.WriteLine("bpp " + bpp);
Console.WriteLine("result_ " + size);
Console.WriteLine("width " + width);
Console.WriteLine("height " + height);
}
}
}
}
}

View File

@ -31,7 +31,7 @@ namespace FirstPlugin
public Shader shader = null;
public List<FMDL> models = new List<FMDL>();
public ResourceFile ResFileNode;
public BFRES ResFileNode;
public BFRESRender()
{
@ -303,7 +303,7 @@ namespace FirstPlugin
GL.ActiveTexture(TextureUnit.Texture0 + tex.hash + 1);
GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.Id);
if (BFRES.IsWiiU)
if (BFRES.Instance.IsWiiU)
{
foreach (var ftexContainer in PluginRuntime.ftexContainers)
{
@ -450,7 +450,7 @@ namespace FirstPlugin
if (OpenTKSharedResources.SetupStatus == OpenTKSharedResources.SharedResourceStatus.Unitialized)
return;
foreach (BinaryTextureContainer bntx in PluginRuntime.bntxContainers)
foreach (BNTX bntx in PluginRuntime.bntxContainers)
{
foreach (var t in mat.textures)
{
@ -469,7 +469,7 @@ namespace FirstPlugin
if (OpenTKSharedResources.SetupStatus == OpenTKSharedResources.SharedResourceStatus.Unitialized)
return;
foreach (BinaryTextureContainer bntx in PluginRuntime.bntxContainers)
foreach (BNTX bntx in PluginRuntime.bntxContainers)
{
if (!bntx.AllGLInitialized)
{

View File

@ -40,7 +40,7 @@ namespace FirstPlugin
textureListView.FullRowSelect = true;
int CurTex = 0;
foreach (BinaryTextureContainer bntx in PluginRuntime.bntxContainers)
foreach (BNTX bntx in PluginRuntime.bntxContainers)
{
foreach (TextureData item in bntx.Textures.Values)
{
@ -73,7 +73,7 @@ namespace FirstPlugin
private void textureListView_DoubleClick(object sender, EventArgs e)
{
foreach (BinaryTextureContainer bntx in PluginRuntime.bntxContainers)
foreach (BNTX bntx in PluginRuntime.bntxContainers)
{
if (bntx.Textures.ContainsKey(textureListView.SelectedItems[0].Text))
{
@ -110,7 +110,7 @@ namespace FirstPlugin
{
case MouseButtons.Right:
{
foreach (BinaryTextureContainer bntx in PluginRuntime.bntxContainers)
foreach (BNTX bntx in PluginRuntime.bntxContainers)
{
if (bntx.Textures.ContainsKey(textureListView.SelectedItems[0].Text))
{

View File

@ -195,7 +195,7 @@ namespace FirstPlugin
bool FoundTexture = false;
foreach (ListViewItem item in textureRefListView.Items)
{
foreach (BinaryTextureContainer bntx in PluginRuntime.bntxContainers)
foreach (BNTX bntx in PluginRuntime.bntxContainers)
{
if (bntx.Textures.ContainsKey(item.Text))
{

View File

@ -59,9 +59,9 @@ namespace FirstPlugin
bonesCB.SelectedIndex = 0;
textBoxVertexSkinCount.Text = shape.VertexSkinCount.ToString();
if (BFRES.IsWiiU)
if (BFRES.Instance.IsWiiU)
{
}
else
{

View File

@ -16,14 +16,14 @@ namespace FirstPlugin
{
InitializeComponent();
foreach (BinaryTextureContainer bntx in PluginRuntime.bntxContainers)
foreach (BNTX bntx in PluginRuntime.bntxContainers)
{
listView1.Items.Add(bntx.Text);
}
}
public BinaryTextureContainer GetBNTX()
public BNTX GetBNTX()
{
foreach (BinaryTextureContainer bntx in PluginRuntime.bntxContainers)
foreach (BNTX bntx in PluginRuntime.bntxContainers)
{
if (bntx.Text == listView1.SelectedItems[0].Text)
return bntx;

View File

@ -20,7 +20,7 @@ namespace FirstPlugin
public void LoadTexture()
{
if (BFRES.IsWiiU)
if (BFRES.Instance.IsWiiU)
{
foreach (FTEXContainer ftexcont in PluginRuntime.ftexContainers)
{
@ -30,7 +30,7 @@ namespace FirstPlugin
}
else
{
foreach (BinaryTextureContainer bntx in PluginRuntime.bntxContainers)
foreach (BNTX bntx in PluginRuntime.bntxContainers)
{
foreach (TextureData tex in bntx.Textures.Values)
listView1.Items.Add(tex.Text);
@ -54,7 +54,7 @@ namespace FirstPlugin
if (listView1.SelectedItems.Count > 0)
{
string TexName = listView1.SelectedItems[0].Text;
if (BFRES.IsWiiU)
if (BFRES.Instance.IsWiiU)
{
foreach (FTEXContainer ftexcont in PluginRuntime.ftexContainers)
{
@ -64,7 +64,7 @@ namespace FirstPlugin
}
else
{
foreach (BinaryTextureContainer bntx in PluginRuntime.bntxContainers)
foreach (BNTX bntx in PluginRuntime.bntxContainers)
{
if (bntx.Textures.ContainsKey(TexName))
DisplayTexture(bntx.Textures[TexName]);
@ -121,7 +121,7 @@ namespace FirstPlugin
AddTexture((PluginRuntime.bntxContainers[0]));
}
}
private void AddTexture(BinaryTextureContainer bntx)
private void AddTexture(BNTX bntx)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Supported Formats|*.bftex;*.dds; *.png;*.tga;*.jpg;*.tiff|" +
@ -150,7 +150,7 @@ namespace FirstPlugin
if (listView1.SelectedItems.Count > 0)
{
string TexName = listView1.SelectedItems[0].Text;
foreach (BinaryTextureContainer bntx in PluginRuntime.bntxContainers)
foreach (BNTX bntx in PluginRuntime.bntxContainers)
{
if (bntx.Textures.ContainsKey(TexName))
{

View File

@ -68,10 +68,10 @@ namespace FirstPlugin
formatComboBox.SelectedItem = SurfaceFormat.BC1_SRGB;
}
TextureImporterSettings SelectedTexSettings;
BinaryTextureContainer bntx;
BNTX bntx;
List<TextureImporterSettings> settings = new List<TextureImporterSettings>();
public void LoadSettings(List<TextureImporterSettings> s, BinaryTextureContainer b)
public void LoadSettings(List<TextureImporterSettings> s, BNTX b)
{
settings = s;
bntx = b;
@ -83,7 +83,7 @@ namespace FirstPlugin
listViewCustom1.Items[0].Selected = true;
listViewCustom1.Select();
}
public void LoadSetting(TextureImporterSettings setting, BinaryTextureContainer b)
public void LoadSetting(TextureImporterSettings setting, BNTX b)
{
settings = new List<TextureImporterSettings>();
settings.Add(setting);

View File

@ -29,7 +29,7 @@ namespace FirstPlugin
UpdateBackgroundImage();
}
NUTEXB.NuTex textureData;
NUTEXB textureData;
int CurMipDisplayLevel = 0;
int CurArrayDisplayLevel = 0;
@ -43,7 +43,7 @@ namespace FirstPlugin
public uint MipCount { get; set; }
public uint ArrayCount { get; set; }
}
public void LoadProperty(NUTEXB.NuTex tex)
public void LoadProperty(NUTEXB tex)
{
pictureBoxCustom1.Image = Imaging.GetLoadingImage();
LoadImage();

View File

@ -29,7 +29,7 @@ namespace FirstPlugin
UpdateBackgroundImage();
}
XTX.XTXFile.TextureInfo textureData;
XTX.TextureInfo textureData;
int CurMipDisplayLevel = 0;
int CurArrayDisplayLevel = 0;
@ -43,7 +43,7 @@ namespace FirstPlugin
public uint MipCount { get; set; }
public uint ArrayCount { get; set; }
}
public void LoadProperty(XTX.XTXFile.TextureInfo tex)
public void LoadProperty(XTX.TextureInfo tex)
{
pictureBoxCustom1.Image = Imaging.GetLoadingImage();
LoadImage();

View File

@ -124,6 +124,7 @@ namespace FirstPlugin
Formats.Add(typeof(CsvModel));
Formats.Add(typeof(GFPAK));
Formats.Add(typeof(NUTEXB));
Formats.Add(typeof(GTXFile));
return Formats.ToArray();
}

View File

@ -9,7 +9,7 @@ namespace FirstPlugin
{
public class PluginRuntime
{
public static List<BinaryTextureContainer> bntxContainers = new List<BinaryTextureContainer>();
public static List<BNTX> bntxContainers = new List<BNTX>();
public static List<FTEXContainer> ftexContainers = new List<FTEXContainer>();
public static DockState FSHPDockState = DockState.DockRight;
public static string ExternalFMATPath = "";

View File

@ -30,7 +30,7 @@
<ProjectGuid>{755AB64B-16B4-4C90-AA3B-BFF448E5A21E}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>DirectXTex</RootNamespace>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">

View File

@ -278,9 +278,9 @@ namespace Switch_Toolbox
format.Load();
format.FilePath = FileName;
if (format.EditorRoot != null)
if (format is TreeNode)
{
objectList.treeView1.Nodes.Add(format.EditorRoot);
objectList.treeView1.Nodes.Add((TreeNode)format);
}
if (format.CanSave)
@ -308,9 +308,9 @@ namespace Switch_Toolbox
format.FilePath = FileName;
format.Load();
if (format.EditorRoot != null)
if (format is TreeNode)
{
objectList.treeView1.Nodes.Add(format.EditorRoot);
objectList.treeView1.Nodes.Add((TreeNode)format);
}
if (format.CanSave)

View File

@ -22,19 +22,13 @@ namespace Switch_Toolbox.Library
}
public class TreeNodeFile : TreeNodeCustom
{
public IFileFormat FileHandler;
public TreeNodeFile()
{
}
public TreeNodeFile(IFileFormat handler)
{
}
public TreeNodeFile(string text, IFileFormat handler)
public TreeNodeFile(string text)
{
Text = text;
FileHandler = handler;
}
}
public class TreeViewCustom : TreeView

View File

@ -22,7 +22,6 @@ namespace Switch_Toolbox.Library
byte[] Data { get; set; }
string FileName { get; set; }
string FilePath { get; set; }
TreeNodeFile EditorRoot { get; set; }
void Load();
void Unload();
byte[] Save();