Use file streams for non archive based writing. Allow giant file saving from opened streams.

This commit is contained in:
KillzXGaming 2019-08-06 17:35:18 -04:00
parent 23324a2233
commit e5bb9fa9d5
135 changed files with 1116 additions and 1007 deletions

Binary file not shown.

View file

@ -241,16 +241,13 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
var mem = new MemoryStream();
if (aampFileV1 != null)
aampFileV1.Save(mem);
aampFileV1.Save(stream);
else
aampFileV2.Save(mem);
return mem.ToArray();
aampFileV2.Save(stream);
}
}
}

View file

@ -64,9 +64,8 @@ namespace FirstPlugin
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public bool AddFile(ArchiveFileInfo archiveFileInfo)

View file

@ -162,7 +162,7 @@ namespace FirstPlugin
}
GC.Collect();
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
beaFile.FileList.Clear();
beaFile.FileDictionary.Clear();
@ -181,9 +181,7 @@ namespace FirstPlugin
beaFile.FileDictionary.Add(asset.FileName);
}
MemoryStream mem = new MemoryStream();
beaFile.Save(mem);
return mem.ToArray();
beaFile.Save(stream);
}

View file

@ -88,10 +88,9 @@ namespace FirstPlugin
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
var mem = new System.IO.MemoryStream();
using (var writer = new FileWriter(mem))
using (var writer = new FileWriter(stream, true))
{
writer.ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian;
@ -120,8 +119,6 @@ namespace FirstPlugin
writer.Write(files[i].FileData.Length);
*/
}
return mem.ToArray();
}
private void Align(FileWriter writer, int alignment)

View file

@ -108,15 +108,15 @@ namespace FirstPlugin
Read(new FileReader(stream));
}
public void Unload()
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
MemoryStream mem = new MemoryStream();
Write(new FileWriter(mem));
return mem.ToArray();
Write(new FileWriter(stream));
}
private void Save(object sender, EventArgs args)

View file

@ -265,9 +265,8 @@ namespace FirstPlugin.LuigisMansion.DarkMoon
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public bool AddFile(ArchiveFileInfo archiveFileInfo)

View file

@ -72,9 +72,8 @@ namespace FirstPlugin
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public bool AddFile(ArchiveFileInfo archiveFileInfo)

View file

@ -113,10 +113,9 @@ namespace FirstPlugin
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
var mem = new System.IO.MemoryStream();
using (var writer = new FileWriter(mem))
using (var writer = new FileWriter(stream, true))
{
if (IsSA01)
writer.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
@ -167,8 +166,6 @@ namespace FirstPlugin
writer.Seek(12, System.IO.SeekOrigin.Begin);
writer.Write(Offsets);
}
return mem.ToArray();
}
private void Align(FileWriter writer, int alignment)

View file

@ -88,9 +88,8 @@ namespace FirstPlugin
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public bool AddFile(ArchiveFileInfo archiveFileInfo)

View file

@ -175,9 +175,8 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
//EFE for REing format https://github.com/Gericom/EveryFileExplorer/blob/f9f00d193c9608d71c9a23d9f3ab7e752f4ada2a/NDS/NitroSystem/FND/NARC.cs

View file

@ -95,9 +95,8 @@ namespace FirstPlugin
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public bool AddFile(ArchiveFileInfo archiveFileInfo)

View file

@ -197,7 +197,7 @@ namespace FirstPlugin
//It's a good idea, and i don't want to deal with offset linking
private List<char> _exportStringTable;
private List<byte[]> _savedFileData;
public void SaveFile(FileWriter writer)
private void SaveFile(FileWriter writer)
{
_savedFiles.Clear();
_exportStringTable = new List<char>();
@ -444,11 +444,9 @@ namespace FirstPlugin
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
var mem = new System.IO.MemoryStream();
SaveFile(new FileWriter(mem));
return mem.ToArray();
SaveFile(new FileWriter(stream));
}
public bool AddFile(ArchiveFileInfo archiveFileInfo)

View file

@ -258,7 +258,7 @@ namespace FirstPlugin
return result;
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
sarcData.Files.Clear();
foreach (var file in files)
@ -290,7 +290,10 @@ namespace FirstPlugin
Tuple<int, byte[]> sarc = SARCExt.SARC.PackN(sarcData);
IFileInfo.Alignment = sarc.Item1;
return sarc.Item2;
using (var writer = new FileWriter(stream)) {
writer.Write(sarc.Item2);
}
}
public class SarcEntry : ArchiveFileInfo

View file

@ -1,641 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Toolbox;
using System.Windows.Forms;
using SARCExt;
using Toolbox.Library;
using Toolbox.Library.IO;
using Toolbox.Library.Forms;
namespace FirstPlugin.Old
{
public class SARC : TreeNodeFile, IFileFormat
{
public FileType FileType { get; set; } = FileType.Archive;
public bool CanSave { get; set; }
public string[] Description { get; set; } = new string[] { "Sorted ARChive" };
public string[] Extension { get; set; } = new string[] { "*.pack", "*.sarc", "*.bgenv", "*.sblarc", "*.sbactorpack", ".arc" };
public string FileName { get; set; }
public string FilePath { get; set; }
public IFileInfo IFileInfo { get; set; }
public bool Identify(System.IO.Stream stream)
{
using (var reader = new Toolbox.Library.IO.FileReader(stream, true))
{
return reader.CheckSignature(4, "SARC");
}
}
public Type[] Types
{
get
{
List<Type> types = new List<Type>();
return types.ToArray();
}
}
public List<SarcEntry> Files = new List<SarcEntry>();
public Dictionary<string, byte[]> OpenedFiles = new Dictionary<string, byte[]>();
public SarcData sarcData;
public string SarcHash;
public void Load(System.IO.Stream stream)
{
CanSave = true;
IFileInfo.UseEditMenu = true;
var SzsFiles = SARCExt.SARC.UnpackRamN(stream);
sarcData = new SarcData();
sarcData.HashOnly = SzsFiles.HashOnly;
sarcData.Files = SzsFiles.Files;
sarcData.endianness = GetByteOrder(stream);
SarcHash = Utils.GenerateUniqueHashID();
FillTreeNodes(this, SzsFiles.Files, sarcData.HashOnly);
Text = FileName;
ContextMenuStrip = new STContextMenuStrip();
ContextMenuStrip.Items.Add(new STToolStipMenuItem("Save",null, Save, Keys.Control | Keys.S));
ContextMenuStrip.Items.Add(new STToolStipMenuItem("Rename Actor Files (Odyssey)", null, RenameActors, Keys.Control | Keys.S));
// ContextMenuStrip.Items.Add(new STToolStipMenuItem("Unpack to Folder", null, UnpackToFolder, Keys.Control | Keys.E));
// ContextMenuStrip.Items.Add(new STToolStipMenuItem("Pack From Folder", null, PackFromFolder, Keys.Control | Keys.R));
ContextMenuStrip.Items.Add(new STToolStripSeparator());
ContextMenuStrip.Items.Add(new STToolStipMenuItem("Batch Texture Editor", null, PreviewTextures, Keys.Control | Keys.P));
ContextMenuStrip.Items.Add(new STToolStripSeparator());
ContextMenuStrip.Items.Add(new STToolStipMenuItem("Sort Childern", null, SortChildern, Keys.Control | Keys.E));
CanDelete = true;
sarcData.Files.Clear();
}
private void RenameActors(object sender, EventArgs args)
{
string ActorName = Path.GetFileNameWithoutExtension(Text);
RenameDialog dialog = new RenameDialog();
dialog.SetString(ActorName);
if (dialog.ShowDialog() == DialogResult.OK)
{
string NewActorName = dialog.textBox1.Text;
Text = NewActorName + ".szs";
foreach (TreeNode node in Nodes)
{
string NodeName = Path.GetFileNameWithoutExtension(node.Text);
string ext = Utils.GetExtension(node.Text);
if (NodeName == ActorName)
{
node.Text = $"{NewActorName}{ext}";
}
else if (node.Text.Contains("Attribute.byml"))
{
node.Text = $"{NewActorName}Attribute.byml";
}
}
}
}
private void UnpackToFolder(object sender, EventArgs args)
{
}
private void PackFromFolder(object sender, EventArgs args)
{
}
private void Delete(object sender, EventArgs args) {
Unload();
var editor = LibraryGUI.GetObjectEditor();
if (editor != null)
editor.ResetControls();
}
private void SortChildern(object sender, EventArgs args)
{
TreeView.TreeViewNodeSorter = new TreeChildSorter();
TreeView.Sort();
}
public class FolderEntry : TreeNode, IContextMenuNode
{
public FolderEntry(string text, int imageIndex, int selectedImageIndex)
{
Text = text;
ImageIndex = imageIndex;
SelectedImageIndex = selectedImageIndex;
}
public ToolStripItem[] GetContextMenuItems()
{
List<ToolStripItem> Items = new List<ToolStripItem>();
Items.Add(new ToolStripMenuItem("Sort Childern", null, SortChildern, Keys.Control | Keys.W));
return Items.ToArray();
}
private void SortChildern(object sender, EventArgs args)
{
TreeView.TreeViewNodeSorter = new TreeChildSorter();
TreeView.Sort();
}
}
public Syroot.BinaryData.ByteOrder GetByteOrder(System.IO.Stream data)
{
using (FileReader reader = new FileReader(data))
{
reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
reader.Seek(6);
ushort bom = reader.ReadUInt16();
reader.Close();
reader.Dispose();
if (bom == 0xFFFE)
return Syroot.BinaryData.ByteOrder.LittleEndian;
else
return Syroot.BinaryData.ByteOrder.BigEndian;
}
}
public void Unload()
{
foreach (var file in Files)
file.FileData = null;
Files.Clear();
Nodes.Clear();
GC.SuppressFinalize(this);
}
IEnumerable<TreeNode> Collect(TreeNodeCollection nodes)
{
foreach (TreeNode node in nodes)
{
yield return node;
bool IsNodeFile = node is IFileFormat;
if (!IsNodeFile)
{
//We don't need to save the child of IFIleFormats
//If opened the file should save it's own children
foreach (var child in Collect(node.Nodes))
yield return child;
}
}
}
public byte[] Save()
{
Console.WriteLine("Saving sarc");
sarcData.Files.Clear();
foreach (TreeNode node in Collect(Nodes))
{
if (node is SarcEntry)
{
Console.WriteLine("Saving " + node);
SaveFileEntryData((SarcEntry)node);
}
else if (node is IFileFormat && node != this)
{
IFileFormat fileFormat = (IFileFormat)node;
if (fileFormat != null && ((IFileFormat)node).CanSave)
{
sarcData.Files.Add(SetSarcPath(node, this),
STLibraryCompression.CompressFile(fileFormat.Save(), fileFormat));
}
else
{
sarcData.Files.Add(SetSarcPath(node, this),
OpenedFiles[node.FullPath]);
}
}
}
Tuple<int, byte[]> sarc = SARCExt.SARC.PackN(sarcData);
IFileInfo.Alignment = sarc.Item1;
return sarc.Item2;
}
public static string SetSarcPath(TreeNode node, TreeNode sarcNode)
{
string nodePath = node.FullPath;
int startIndex = nodePath.IndexOf(sarcNode.Text);
if (startIndex > 0)
nodePath = nodePath.Substring(startIndex);
string slash = Path.DirectorySeparatorChar.ToString();
string slashAlt = Path.AltDirectorySeparatorChar.ToString();
string SetPath = nodePath.Replace(sarcNode.Text + slash, string.Empty).Replace(slash ?? "", slashAlt);
return !(SetPath == string.Empty) ? SetPath : node.Text;
}
private void SaveFileEntryData(SarcEntry sarc)
{
string dir = Path.GetDirectoryName(sarc.FileName);
if (!sarcData.HashOnly)
{
if (dir == string.Empty)
sarc.FileName = sarc.Text;
else
sarc.FileName = Path.Combine(dir, sarc.Text);
sarc.FileName = sarc.FileName.Replace(@"\", "/");
}
sarcData.Files.Add(sarc.FileName, sarc.FileData);
}
public static void ReplaceNode(TreeNode node, TreeNode replaceNode, TreeNode NewNode)
{
if (NewNode == null)
return;
int index = node.Nodes.IndexOf(replaceNode);
node.Nodes.RemoveAt(index);
node.Nodes.Insert(index, NewNode);
if (NewNode is TreeNodeFile)
((TreeNodeFile)NewNode).OnAfterAdded();
}
private void Save(object sender, EventArgs args)
{
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)
{
STFileSaver.SaveFileFormat(this, sfd.FileName);
}
}
public static bool SuppressFormDialog = false;
private void PreviewTextures(object sender, EventArgs args)
{
SuppressFormDialog = true;
List<IFileFormat> Formats = new List<IFileFormat>();
try
{
CallRecursive(TreeView, Formats);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
ArchiveListPreviewForm editor = new ArchiveListPreviewForm();
editor.LoadArchive(Formats);
editor.Show();
SuppressFormDialog = false;
}
private void CallRecursive(TreeView treeView, List<IFileFormat> Formats)
{
// Print each node recursively.
TreeNodeCollection nodes = treeView.Nodes;
foreach (TreeNode n in nodes)
{
GetNodeFileFormat(n, Formats);
}
}
private void GetNodeFileFormat(TreeNode treeNode, List<IFileFormat> Formats)
{
// Print the node.
if (treeNode is SarcEntry)
{
var format = ((SarcEntry)treeNode).OpenFile();
if (format != null)
Formats.Add(format);
}
// Print each node recursively.
foreach (TreeNode tn in treeNode.Nodes)
{
GetNodeFileFormat(tn, Formats);
}
}
public class SarcEntry : TreeNodeCustom, IContextMenuNode
{
public SARC sarc; //Sarc file the entry is located in
public byte[] FileData;
public string sarcHash;
public SarcEntry()
{
ImageKey = "fileBlank";
SelectedImageKey = "fileBlank";
}
public ToolStripItem[] GetContextMenuItems()
{
List<ToolStripItem> Items = new List<ToolStripItem>();
Items.Add(new STToolStipMenuItem("Export Raw Data", null, Export, Keys.Control | Keys.E));
Items.Add(new STToolStipMenuItem("Export Raw Data to File Location", null, ExportToFileLoc, Keys.Control | Keys.F));
Items.Add(new STToolStipMenuItem("Replace Raw Data", null, Replace, Keys.Control | Keys.R));
Items.Add(new STToolStripSeparator());
Items.Add(new STToolStipMenuItem("Open With Text Editor", null, OpenTextEditor, Keys.Control | Keys.T));
Items.Add(new STToolStripSeparator());
Items.Add(new STToolStipMenuItem("Remove", null, Remove, Keys.Control | Keys.Delete));
Items.Add(new STToolStipMenuItem("Rename", null, Rename, Keys.Control | Keys.N));
return Items.ToArray();
}
public override void OnClick(TreeView treeView)
{
UpdateHexView();
}
private void UpdateHexView()
{
HexEditor editor = (HexEditor)LibraryGUI.GetActiveContent(typeof(HexEditor));
if (editor == null)
{
editor = new HexEditor();
LibraryGUI.LoadEditor(editor);
}
editor.Text = Text;
editor.Dock = DockStyle.Fill;
editor.LoadData(FileData);
}
public IFileFormat OpenFile()
{
return STFileLoader.OpenFileFormat(FileName, FileData, false, true, this);
}
public override void OnDoubleMouseClick(TreeView treeView)
{
if (FileData.Length <= 0)
return;
IFileFormat file = OpenFile();
if (file == null) //File returns null if no supported format is found
return;
if (Utils.HasInterface(file.GetType(), typeof(IEditor<>)) && !SuppressFormDialog)
{
OpenFormDialog(file);
}
else if (file != null)
{
sarc.OpenedFiles.Add(FullPath, FileData);
ReplaceNode(this.Parent, this, (TreeNode)file);
}
}
private void OpenFormDialog(IFileFormat fileFormat)
{
UserControl form = GetEditorForm(fileFormat);
form.Text = (((IFileFormat)fileFormat).FileName);
var parentForm = LibraryGUI.GetActiveForm();
GenericEditorForm editorForm = new GenericEditorForm(true, form);
editorForm.Text = Text;
editorForm.FormClosing += (sender, e) => FormClosing(sender, e, fileFormat);
if (editorForm.ShowDialog() == DialogResult.OK)
{
if (fileFormat.CanSave)
{
FileData = fileFormat.Save();
UpdateHexView();
}
}
}
private void FormClosing(object sender, EventArgs args, IFileFormat fileFormat)
{
if (((Form)sender).DialogResult != DialogResult.OK)
return;
if (fileFormat.CanSave)
{
FileData = fileFormat.Save();
UpdateHexView();
}
}
private UserControl GetEditorForm(IFileFormat fileFormat)
{
Type objectType = fileFormat.GetType();
foreach (var inter in objectType.GetInterfaces())
{
if (inter.IsGenericType && inter.GetGenericTypeDefinition() == typeof(IEditor<>))
{
System.Reflection.MethodInfo method = objectType.GetMethod("OpenForm");
return (UserControl)method.Invoke(fileFormat, new object[0]);
}
}
return null;
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
TreeNode node = TreeView.SelectedNode;
// Determine by checking the Text property.
}
public string FileName;
private void Replace(object sender, EventArgs args)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.FileName = Text;
ofd.DefaultExt = Path.GetExtension(Text);
ofd.Filter = "Raw Data (*.*)|*.*";
if (ofd.ShowDialog() == DialogResult.OK)
{
FileData = File.ReadAllBytes(ofd.FileName);
}
}
private void ExportToFileLoc(object sender, EventArgs args)
{
Cursor.Current = Cursors.WaitCursor;
File.WriteAllBytes($"{Path.GetDirectoryName(sarc.FilePath)}/{Text}", FileData);
Cursor.Current = Cursors.Default;
}
private void Export(object sender, EventArgs args)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.FileName = Text;
sfd.DefaultExt = Path.GetExtension(Text);
sfd.Filter = "Raw Data (*.*)|*.*";
if (sfd.ShowDialog() == DialogResult.OK)
{
File.WriteAllBytes(sfd.FileName, FileData);
}
}
private void OpenTextEditor(object sender, EventArgs args)
{
TextEditor editor = (TextEditor)LibraryGUI.GetActiveContent(typeof(TextEditor));
if (editor == null)
{
editor = new TextEditor();
LibraryGUI.LoadEditor(editor);
}
editor.Text = Text;
editor.Dock = DockStyle.Fill;
editor.FillEditor(FileData);
}
private void Remove(object sender, EventArgs args)
{
DialogResult result = MessageBox.Show($"Are your sure you want to remove {Text}? This cannot be undone!", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
Parent.Nodes.Remove(this);
}
}
private void Rename(object sender, EventArgs args)
{
RenameDialog dialog = new RenameDialog();
dialog.SetString(Text);
if (dialog.ShowDialog() == DialogResult.OK)
{
Text = dialog.textBox1.Text;
}
}
}
void FillTreeNodes(TreeNode root, Dictionary<string, byte[]> files, bool HashOnly)
{
var rootText = root.Text;
var rootTextLength = rootText.Length;
var nodeStrings = files;
foreach (var node in nodeStrings)
{
string nodeString = node.Key;
if (HashOnly)
nodeString = SARCExt.SARC.TryGetNameFromHashTable(nodeString);
var roots = nodeString.Split(new char[] { '/' },
StringSplitOptions.RemoveEmptyEntries);
// The initial parent is the root node
var parentNode = root;
var sb = new StringBuilder(rootText, nodeString.Length + rootTextLength);
for (int rootIndex = 0; rootIndex < roots.Length; rootIndex++)
{
// Build the node name
var parentName = roots[rootIndex];
sb.Append("/");
sb.Append(parentName);
var nodeName = sb.ToString();
// Search for the node
var index = parentNode.Nodes.IndexOfKey(nodeName);
if (index == -1)
{
// Node was not found, add it
var folder = new FolderEntry(parentName, 0, 0);
if (rootIndex == roots.Length - 1)
{
var file = SetupFileEntry(node.Value, parentName, node.Key);
file.Name = nodeName;
parentNode.Nodes.Add(file);
parentNode = file;
}
else
{
folder.Name = nodeName;
parentNode.Nodes.Add(folder);
parentNode = folder;
}
}
else
{
// Node was found, set that as parent and continue
parentNode = parentNode.Nodes[index];
}
}
}
}
List<string> BuildFinalList(List<string> paths)
{
var finalList = new List<string>();
foreach (var path in paths)
{
bool found = false;
foreach (var item in finalList)
{
if (item.StartsWith(path, StringComparison.Ordinal))
{
found = true;
break;
}
}
if (!found)
{
finalList.Add(path);
}
}
return finalList;
}
public SarcEntry SetupFileEntry(byte[] data, string name, string fullName)
{
SarcEntry sarcEntry = new SarcEntry();
sarcEntry.FileName = fullName;
sarcEntry.Name = name;
sarcEntry.Text = name;
sarcEntry.sarc = this;
sarcEntry.FileData = data;
Files.Add(sarcEntry);
string ext = Path.GetExtension(name);
string SarcEx = SARCExt.SARC.GuessFileExtension(data);
if (SarcEx == ".bfres" || ext == ".sbfres")
{
sarcEntry.ImageKey = "bfres";
sarcEntry.SelectedImageKey = "bfres";
}
if (SarcEx == ".bntx")
{
sarcEntry.ImageKey = "bntx";
sarcEntry.SelectedImageKey = "bntx";
}
if (SarcEx == ".byaml")
{
sarcEntry.ImageKey = "byaml";
sarcEntry.SelectedImageKey = "byaml";
}
if (SarcEx == ".aamp")
{
sarcEntry.ImageKey = "aamp";
sarcEntry.SelectedImageKey = "aamp";
}
return sarcEntry;
}
}
}

View file

@ -520,9 +520,9 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public class SDFTOC_Header

View file

@ -237,9 +237,8 @@ namespace FirstPlugin
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public bool AddFile(ArchiveFileInfo archiveFileInfo)

View file

@ -101,9 +101,9 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
}
}

View file

@ -342,10 +342,8 @@ namespace FirstPlugin
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
var mem = new System.IO.MemoryStream();
return mem.ToArray();
}

View file

@ -346,10 +346,8 @@ namespace FirstPlugin
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
var mem = new System.IO.MemoryStream();
return mem.ToArray();
}

View file

@ -482,10 +482,8 @@ namespace FirstPlugin
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
var mem = new System.IO.MemoryStream();
return mem.ToArray();
}

View file

@ -186,11 +186,10 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
var mem = new System.IO.MemoryStream();
SaveFile(new FileWriter(mem));
return mem.ToArray();
SaveFile(new FileWriter(stream));
}

View file

@ -152,6 +152,7 @@ namespace FirstPlugin
}
}
public void SaveFile(FileWriter writer)
{
long pos = writer.Position;
@ -219,11 +220,9 @@ namespace FirstPlugin
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
var mem = new System.IO.MemoryStream();
SaveFile(new FileWriter(mem));
return mem.ToArray();
SaveFile(new FileWriter(stream));
}
public bool AddFile(ArchiveFileInfo archiveFileInfo)

View file

@ -299,11 +299,10 @@ namespace FirstPlugin
STFileSaver.SaveFileFormat(this, sfd.FileName);
}
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
MemoryStream mem = new MemoryStream();
bars.Save(mem);
return mem.ToArray();
bars.Save(stream);
}
}
}

View file

@ -38,13 +38,14 @@ namespace FirstPlugin
public void Load(System.IO.Stream stream)
{
}
public void Unload()
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
}
}

View file

@ -50,13 +50,14 @@ namespace FirstPlugin
Nodes.Add("Group List");
Nodes.Add("Players List");
}
public void Unload()
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
private static uint FileSizeOffset;

View file

@ -62,13 +62,14 @@ namespace FirstPlugin
}
}
public void Unload()
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
}
}

View file

@ -59,13 +59,15 @@ namespace FirstPlugin
CanSave = true;
LoadAudio(stream, this);
}
public void Unload()
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return SaveAudio();
SaveAudio(stream);
}
}
}

View file

@ -59,13 +59,15 @@ namespace FirstPlugin
CanSave = true;
LoadAudio(stream, this);
}
public void Unload()
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return SaveAudio();
SaveAudio(stream);
}
}
}

View file

@ -76,9 +76,10 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return SaveAudio();
SaveAudio(stream);
}
}
}

View file

@ -62,9 +62,9 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return SaveAudio();
SaveAudio(stream);
}
}
}

View file

@ -59,13 +59,15 @@ namespace FirstPlugin
CanSave = true;
LoadAudio(stream, this);
}
public void Unload()
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return SaveAudio();
SaveAudio(stream);
}
}
}

View file

@ -62,9 +62,10 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return SaveAudio();
SaveAudio(stream);
}
}
}

View file

@ -59,13 +59,15 @@ namespace FirstPlugin
CanSave = true;
LoadAudio(stream, this);
}
public void Unload()
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return SaveAudio();
SaveAudio(stream);
}
}
}

View file

@ -59,13 +59,15 @@ namespace FirstPlugin
CanSave = true;
LoadAudio(stream, this);
}
public void Unload()
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return SaveAudio();
SaveAudio(stream);
}
}
}

View file

@ -75,13 +75,14 @@ namespace FirstPlugin
mp3Struct = CSCore.Tags.ID3.ID3v1.FromStream(stream);
}
public void Unload()
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
}
}

View file

@ -73,13 +73,14 @@ namespace FirstPlugin
waveSource = CodecFactory.Instance.GetCodec(stream, ".ogg");
}
public void Unload()
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
}
}

View file

@ -77,15 +77,18 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
var writer = new BCFstmWriter(NwTarget.Ctr);
writer.Configuration = new BxstmConfiguration()
var audioWriter = new BCFstmWriter(NwTarget.Ctr);
audioWriter.Configuration = new BxstmConfiguration()
{
Endianness = VGAudio.Utilities.Endianness.LittleEndian,
};
return writer.GetFile(audioData, writer.Configuration);
using (var writer = new Toolbox.Library.IO.FileWriter(stream, true))
{
writer.Write(audioWriter.GetFile(audioData, audioWriter.Configuration));
}
}
}
}

View file

@ -172,9 +172,9 @@ namespace FirstPlugin
{
ObjectEditor.RemoveContainer(DrawableContainer);
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
}
}

View file

@ -879,10 +879,8 @@ namespace FirstPlugin
GC.SuppressFinalize(this);
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
MemoryStream mem = new MemoryStream();
var Models = GetModels();
if (Models != null)
{
@ -897,11 +895,9 @@ namespace FirstPlugin
if (IsWiiU)
SaveWiiU(mem);
SaveWiiU(stream);
else
SaveSwitch(mem);
return mem.ToArray();
SaveSwitch(stream);
}
public TreeNodeCollection GetModels()
@ -1433,7 +1429,7 @@ namespace FirstPlugin
{
Unload();
}
private void SaveSwitch(MemoryStream mem)
private void SaveSwitch(Stream stream)
{
var resFile = BFRESRender.ResFileNode.resFile;
@ -1469,7 +1465,10 @@ namespace FirstPlugin
if (((BNTX)node).Textures.Count > 0)
{
resFile.ExternalFiles.Add(new ExternalFile() { Data = ((BNTX)node).Save() });
var mem = new System.IO.MemoryStream();
((BNTX)node).Save(mem);
resFile.ExternalFiles.Add(new ExternalFile() { Data = mem.ToArray() });
resFile.ExternalFileDict.Add("textures.bntx");
}
}
@ -1477,7 +1476,7 @@ namespace FirstPlugin
ErrorCheck();
resFile.Save(mem);
resFile.Save(stream);
}
private void RemoveUnusedTextures(BFRESGroupNode ftexGroup)
@ -1625,7 +1624,13 @@ namespace FirstPlugin
}
else if (ext is TreeNodeFile)
{
resFile.ExternalFiles.Add(new ExternalFile() { Data = ((IFileFormat)ext).Save() });
var mem = new System.IO.MemoryStream();
((IFileFormat)ext).Save(mem);
resFile.ExternalFiles.Add(new ExternalFile()
{
Data = mem.ToArray(),
});
resFile.ExternalFileDict.Add(((TreeNodeFile)ext).Text);
}
@ -1640,7 +1645,7 @@ namespace FirstPlugin
}
private void SaveWiiU(MemoryStream mem)
private void SaveWiiU(Stream mem)
{
var resFileU = BFRESRender.ResFileNode.resFileU;

View file

@ -85,7 +85,9 @@ namespace Bfres.Structs
{
if (fileFormat.CanSave)
{
ArchiveFileInfo.FileData = fileFormat.Save();
var mem = new System.IO.MemoryStream();
fileFormat.Save(mem);
ArchiveFileInfo.FileData = mem.ToArray();
UpdateEditor();
}
}

View file

@ -1121,9 +1121,17 @@ namespace FirstPlugin
{
ExternalFile ext = new ExternalFile();
if (node is BNTX)
ext.Data = ((BNTX)node).Save();
{
var mem = new System.IO.MemoryStream();
((BNTX)node).Save(mem);
ext.Data = mem.ToArray();
}
else if (node is IFileFormat && ((IFileFormat)node).CanSave)
ext.Data = ((IFileFormat)node).Save();
{
var mem = new System.IO.MemoryStream();
((IFileFormat)node).Save(mem);
ext.Data = mem.ToArray();
}
else
ext.Data = ((ExternalFileData)node).Data;

View file

@ -1074,7 +1074,11 @@ namespace FirstPlugin
{
ExternalFile ext = new ExternalFile();
if (node is BNTX)
ext.Data = ((BNTX)node).Save();
{
var mem = new System.IO.MemoryStream();
((BNTX)node).Save(mem);
ext.Data = mem.ToArray();
}
else
ext.Data = ((ExternalFileData)node).Data;

View file

@ -368,11 +368,9 @@ namespace FirstPlugin
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
var mem = new System.IO.MemoryStream();
BMDFile.ExportBMD(mem);
return mem.ToArray();
BMDFile.ExportBMD(stream);
}
}
}

View file

@ -120,9 +120,9 @@ namespace FirstPlugin.Turbo
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
}
}

View file

@ -189,18 +189,15 @@ namespace FirstPlugin
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
MemoryStream mem = new MemoryStream();
ByamlFile.SaveN(mem, new BymlFileData
ByamlFile.SaveN(stream, new BymlFileData
{
Version = data.Version,
byteOrder = data.byteOrder,
SupportPaths = data.SupportPaths,
RootNode = data.RootNode
});
return mem.ToArray();
}
}
}

View file

@ -151,10 +151,15 @@ namespace FirstPlugin
{
ObjectEditor.RemoveContainer(DrawableContainer);
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return data;
using (var writer = new FileWriter(stream))
{
writer.Write(data);
}
}
public enum GameSet : ushort
{
MarioOdyssey = 0x0,

View file

@ -10,7 +10,7 @@ using Toolbox.Library.IO;
namespace FirstPlugin
{
public class IGA_PAK : IArchiveFile, IFileFormat
public class IGA_PAK : IArchiveFile, IFileFormat, ISaveOpenedFileStream
{
public FileType FileType { get; set; } = FileType.Archive;
@ -109,8 +109,6 @@ namespace FirstPlugin
file.FileName = file.FileName.Replace("temporary/mack/data/win64/output/", string.Empty);
file.FileName = file.FileName.Replace("temporary/mack/data/nx/output/", string.Empty);
// if (file.FileOffset >= 0xff000000)
// file.FileOffset =
@ -206,11 +204,9 @@ namespace FirstPlugin
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
var mem = new System.IO.MemoryStream();
Write(new FileWriter(mem));
return mem.ToArray();
Write(new FileWriter(stream));
}
public bool AddFile(ArchiveFileInfo archiveFileInfo)
@ -335,7 +331,9 @@ namespace FirstPlugin
{
if (FileFormat != null && FileFormat.CanSave)
{
byte[] data = FileFormat.Save();
var mem = new System.IO.MemoryStream();
FileFormat.Save(mem);
byte[] data = mem.ToArray();
DecompressedFileSize = (uint)data.Length;
if (FileCompressionType != -1)

View file

@ -39,16 +39,16 @@ namespace FirstPlugin
{ 0x9D3B06CD, new FormatInfo(TEX_FORMAT.BC1_UNORM) },
{ 0xDA888839, new FormatInfo(TEX_FORMAT.BC3_UNORM) }, //PC
{ 0x78B94718, new FormatInfo(TEX_FORMAT.BC5_UNORM) }, //PC
{ 0x994608DE, new FormatInfo(TEX_FORMAT.R32G32B32_FLOAT) }, //PC
{ 0x994608DE, new FormatInfo(TEX_FORMAT.R8G8B8A8_UNORM) }, //PC
{ 0x1B282851, new FormatInfo(TEX_FORMAT.BC1_UNORM, Platform.Switch) },
{ 0x37456ECD, new FormatInfo(TEX_FORMAT.BC3_UNORM, Platform.Switch) },
{ 0xD0124568, new FormatInfo(TEX_FORMAT.BC3_UNORM, Platform.Switch) },
{ 0x8EBE8CF2, new FormatInfo(TEX_FORMAT.R32G32B32_FLOAT, Platform.Switch) },
{ 0x8EBE8CF2, new FormatInfo(TEX_FORMAT.R8G8B8A8_UNORM, Platform.Switch) },
{ 0xF8313483, new FormatInfo(TEX_FORMAT.BC1_UNORM, Platform.Ps4) },
{ 0xF0B976CF, new FormatInfo(TEX_FORMAT.BC3_UNORM, Platform.Ps4) },
{ 0x7D081E6A, new FormatInfo(TEX_FORMAT.BC5_UNORM, Platform.Ps4) },
{ 0x9B54FB48, new FormatInfo(TEX_FORMAT.R32G32B32_FLOAT, Platform.Ps4) },
{ 0xEDF22608, new FormatInfo(TEX_FORMAT.R32G32B32_FLOAT, Platform.Ps4) }, //Todo BGR32
{ 0x9B54FB48, new FormatInfo(TEX_FORMAT.R8G8B8A8_UNORM, Platform.Ps4) },
{ 0xEDF22608, new FormatInfo(TEX_FORMAT.B8G8R8A8_UNORM, Platform.Ps4) },
};
public class FormatInfo

View file

@ -78,7 +78,11 @@ namespace FirstPlugin
IGZStructure = new IGZ_Structure();
IGZStructure.Read(reader);
if (IGZStructure.TextureInfo == null) return;
if (IGZStructure.TextureInfo == null)
{
CanSave = false;
return;
}
//Set all the info from the parsed struct
var texInfo = IGZStructure.TextureInfo;
@ -97,6 +101,8 @@ namespace FirstPlugin
Text = IGZStructure.StringTable[0];
else
Text = FileName;
Parameters.FlipY = true;
}
}
@ -198,7 +204,8 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
//Apply the image info block from this image
IGZStructure.TextureInfo.Width = (ushort)this.Width;
@ -210,9 +217,7 @@ namespace FirstPlugin
IGZStructure.TextureInfo.FormatInfo.Platform = this.PlatformFormat;
IGZStructure.StringTable[0] = this.Text;
var mem = new System.IO.MemoryStream();
IGZStructure.Write(new FileWriter(mem));
return mem.ToArray();
IGZStructure.Write(new FileWriter(stream));
}
}
}

View file

@ -301,11 +301,9 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
MemoryStream mem = new MemoryStream();
using (System.IO.StreamWriter file = new System.IO.StreamWriter(mem))
using (System.IO.StreamWriter file = new System.IO.StreamWriter(stream))
{
foreach (STGenericObject obj in objects)
{
@ -342,9 +340,6 @@ namespace FirstPlugin
}
file.Close();
}
return mem.ToArray();
}
}
}

View file

@ -69,15 +69,15 @@ namespace FirstPlugin
EfcHeader = new Header();
EfcHeader.Read(new FileReader(stream));
}
public void Unload()
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
var mem = new System.IO.MemoryStream();
EfcHeader.Write(new FileWriter(mem));
return mem.ToArray();
EfcHeader.Write(new FileWriter(stream));
}
public class Header

View file

@ -50,13 +50,14 @@ namespace FirstPlugin
PTCL.Header Header = new PTCL.Header();
Header.Read(reader, pctl);
}
public void Unload()
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
}
}

View file

@ -105,17 +105,14 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
MemoryStream mem = new MemoryStream();
if (Is3DS)
header3DS.Write(new FileWriter(mem), this);
header3DS.Write(new FileWriter(stream), this);
else if (IsWiiU)
headerU.Write(new FileWriter(mem), this);
headerU.Write(new FileWriter(stream), this);
else
header.Write(new FileWriter(mem));
return mem.ToArray();
header.Write(new FileWriter(stream));
}
private void Save(object sender, EventArgs args)
{
@ -646,7 +643,9 @@ namespace FirstPlugin
SaveHeader(writer, header, BinaryDataBytes, 4096);
break;
case "GRTF":
SaveHeader(writer, header, ((BNTX)BinaryData).Save(), 4096);
var mem = new System.IO.MemoryStream();
((BNTX)BinaryData).Save(mem);
SaveHeader(writer, header, mem.ToArray(), 4096);
// SaveHeader(writer, header, BinaryDataBytes, 4096);
break;
case "PRIM":

View file

@ -112,11 +112,10 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
MemoryStream mem = new MemoryStream();
bffnt.Write(new FileWriter(mem));
return mem.ToArray();
bffnt.Write(new FileWriter(stream));
}
@ -852,7 +851,11 @@ namespace FirstPlugin
writer.Align(8192);
if (BinaryTextureFile != null)
SheetDataList[0] = BinaryTextureFile.Save();
{
var mem = new System.IO.MemoryStream();
BinaryTextureFile.Save(mem);
SheetDataList[0] = mem.ToArray();
}
long DataPosition = writer.Position;
using (writer.TemporarySeek(_ofsSheetBlocks, SeekOrigin.Begin))

View file

@ -129,9 +129,9 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
}
}

View file

@ -133,11 +133,9 @@ namespace FirstPlugin
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
var mem = new System.IO.MemoryStream();
header.Write(new FileWriter(mem));
return mem.ToArray();
header.Write(new FileWriter(stream));
}
//Todo replace tedius offset handling with a class to store necessary data and methods to execute

View file

@ -146,15 +146,15 @@ namespace FirstPlugin
}
}
}
public void Unload()
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
var mem = new System.IO.MemoryStream();
GMXHeader.Write(new FileWriter(mem));
return mem.ToArray();
GMXHeader.Write(new FileWriter(stream));
}
public class Header

View file

@ -363,9 +363,9 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public enum CMBVersion

View file

@ -53,9 +53,8 @@ namespace FirstPlugin
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public enum GameVersion

View file

@ -67,9 +67,8 @@ namespace FirstPlugin
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public class Header

View file

@ -298,9 +298,8 @@ namespace FirstPlugin
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public bool AddFile(ArchiveFileInfo archiveFileInfo)

View file

@ -340,9 +340,8 @@ namespace FirstPlugin
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public class RoomSetup

View file

@ -42,13 +42,14 @@ namespace FirstPlugin
{
Read(new FileReader(stream));
}
public void Unload()
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public void Read(FileReader reader)

View file

@ -48,9 +48,8 @@ namespace FirstPlugin
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public List<STGenericTexture> IconTextureList

View file

@ -155,9 +155,8 @@ namespace FirstPlugin
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public bool AddFile(ArchiveFileInfo archiveFileInfo)

View file

@ -44,9 +44,9 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
}
}

View file

@ -45,9 +45,9 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public class Header

View file

@ -198,9 +198,9 @@ namespace FirstPlugin
Nodes.Clear();
header = null;
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
Viewport viewport

View file

@ -0,0 +1,436 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Toolbox.Library;
using Toolbox.Library.IO;
using Toolbox.Library.Rendering;
using Toolbox.Library.Forms;
using OpenTK;
using GL_EditorFramework.GL_Core;
using OpenTK.Graphics.OpenGL;
namespace FirstPlugin
{
class MOD : TreeNodeFile, IFileFormat
{
public FileType FileType { get; set; } = FileType.Model;
public bool CanSave { get; set; }
public string[] Description { get; set; } = new string[] { "Pikmin 1 Model Format" };
public string[] Extension { get; set; } = new string[] { "*.mod" };
public string FileName { get; set; }
public string FilePath { get; set; }
public IFileInfo IFileInfo { get; set; }
public bool Identify(System.IO.Stream stream)
{
return Utils.HasExtension(FileName, ".mod");
}
public Type[] Types
{
get
{
List<Type> types = new List<Type>();
return types.ToArray();
}
}
//Check for the viewport in the object editor
//This is attached to it to load multiple file formats within the object editor to the viewer
Viewport viewport
{
get
{
var editor = LibraryGUI.GetObjectEditor();
return editor.GetViewport();
}
set
{
var editor = LibraryGUI.GetObjectEditor();
editor.LoadViewport(value);
}
}
bool DrawablesLoaded = false;
public override void OnClick(TreeView treeView)
{
//Make sure opengl is enabled
if (Runtime.UseOpenGL)
{
//Open the viewport
if (viewport == null)
{
viewport = new Viewport(ObjectEditor.GetDrawableContainers());
viewport.Dock = DockStyle.Fill;
}
//Make sure to load the drawables only once so set it to true!
if (!DrawablesLoaded)
{
ObjectEditor.AddContainer(DrawableContainer);
DrawablesLoaded = true;
}
//Reload which drawable to display
viewport.ReloadDrawables(DrawableContainer);
LibraryGUI.LoadEditor(viewport);
viewport.Text = Text;
}
}
public MDL_Renderer Renderer;
public DrawableContainer DrawableContainer = new DrawableContainer();
private Vertex[] Vertices;
private Vertex[] VertexNormals;
private Vertex[] Colors;
private void SkipPadding(FileReader stream, int offset)
{
stream.Seek((~(offset - 1) & (stream.Position + offset - 1)) - stream.Position);
}
public void Load(System.IO.Stream stream)
{
CanSave = true;
Text = FileName;
//Set renderer
//Load it to a drawables list
Renderer = new MDL_Renderer();
DrawableContainer.Name = FileName;
DrawableContainer.Drawables.Add(Renderer);
using (var reader = new FileReader(stream))
{
reader.SetByteOrder(true);
while (reader.EndOfStream == false)
{
long chunkStart = reader.Position;
int opcode = reader.ReadInt32();
int lengthOfStruct = reader.ReadInt32();
// basic error checking
if ((chunkStart & 0x1F) != 0)
throw new Exception($"Chunk start ({chunkStart}) not on boundary!");
switch (opcode)
{
case 0x10: // VERTICES
int vertexCount = reader.ReadInt32();
Vertices = new Vertex[vertexCount];
SkipPadding(reader, 0x20);
for (int i = 0; i < vertexCount; i++)
{
float x = reader.ReadSingle();
float y = reader.ReadSingle();
float z = reader.ReadSingle();
Vertices[i] = new Vertex
{
pos = new Vector3(x, y, z)
};
}
SkipPadding(reader, 0x20);
break;
case 0x11:
int vertexNormalCount = reader.ReadInt32();
VertexNormals = new Vertex[vertexNormalCount];
SkipPadding(reader, 0x20);
for (int i = 0; i < vertexNormalCount; i++)
{
float x = reader.ReadSingle();
float y = reader.ReadSingle();
float z = reader.ReadSingle();
VertexNormals[i] = new Vertex
{
nrm = new Vector3(x, y, z)
};
}
SkipPadding(reader, 0x20);
break;
case 0x13: // COLOURS
int colorCount = reader.ReadInt32();
Colors = new Vertex[colorCount];
SkipPadding(reader, 0x20);
for (int i = 0; i < colorCount; i++)
{
byte x = reader.ReadByte();
byte y = reader.ReadByte();
byte z = reader.ReadByte();
byte w = reader.ReadByte();
Colors[i] = new Vertex
{
col = new Vector4(x, y, z, w)
};
}
SkipPadding(reader, 0x20);
break;
case 0x50:
int meshCount = reader.ReadInt32();
SkipPadding(reader, 0x20);
for (int i = 0; i < meshCount; i++)
{
//Create a renderable object for our mesh
var renderedMesh = new GenericRenderedObject
{
Checked = true,
ImageKey = "mesh",
SelectedImageKey = "mesh",
Text = $"Mesh {i}"
};
Nodes.Add(renderedMesh);
Renderer.Meshes.Add(renderedMesh);
STGenericPolygonGroup polyGroup = new STGenericPolygonGroup();
renderedMesh.PolygonGroups.Add(polyGroup);
reader.ReadInt32();
int vtxDescriptor = reader.ReadInt32();
int mtxGroupCount = reader.ReadInt32();
Console.WriteLine("mtxGroupCount " + mtxGroupCount);
for (int a = 0; a < mtxGroupCount; a++)
{
int unkCount = reader.ReadInt32();
for (int unkIter = 0; unkIter < unkCount; unkIter++)
reader.ReadInt16();
int dispListCount = reader.ReadInt32();
Console.WriteLine("dispListCount " + dispListCount);
for (int b = 0; b < dispListCount; b++)
{
reader.ReadInt32();
reader.ReadInt32();
int displacementSize = reader.ReadInt32();
SkipPadding(reader, 0x20);
long end_displist = reader.Position + displacementSize;
Console.WriteLine("end_displist " + end_displist);
Console.WriteLine("displacementSize " + displacementSize);
Console.WriteLine("reader.Position " + reader.Position);
while (reader.Position < end_displist)
{
byte faceOpCode = reader.ReadByte();
if (faceOpCode == 0x98 || faceOpCode == 0xA0)
{
short vCount = reader.ReadInt16();
int[] polys = new int[vCount];
for (int vc = 0; vc < vCount; vc++)
{
if ((vtxDescriptor & 0x1) == 0x1)
reader.ReadByte(); // Position Matrix
if ((vtxDescriptor & 0x2) == 0x2)
reader.ReadByte(); // tex1 matrix
ushort vtxPosIndex = reader.ReadUInt16();
uint normalID = 0;
if (VertexNormals.Length > 0)
normalID = reader.ReadUInt16();
uint colorID = 0;
if ((vtxDescriptor & 0x4) == 0x4)
colorID = reader.ReadUInt16();
int tmpVar = vtxDescriptor >> 3;
uint texCoordID = 0;
for (int c = 0; c < 8; c++)
{
if ((tmpVar & 0x1) == 0x1)
if (c == 0) texCoordID = reader.ReadUInt16();
tmpVar >>= 1;
}
Vertex vert = new Vertex
{
pos = Vertices[vtxPosIndex].pos,
nrm = VertexNormals[normalID].nrm,
//col = Colors[colorID].col
};
polys[vc] = renderedMesh.vertices.Count;
renderedMesh.vertices.Add(vert);
}
List<Triangle> curPolys = ToTris(polys, faceOpCode);
foreach (Triangle poly in curPolys)
{
Console.WriteLine($"{poly.A} {poly.B} {poly.C}");
polyGroup.faces.Add(poly.A);
polyGroup.faces.Add(poly.B);
polyGroup.faces.Add(poly.C);
}
}
}
}
}
Console.WriteLine("vertices " + renderedMesh.vertices.Count);
Console.WriteLine("faces " + renderedMesh.PolygonGroups[0].faces.Count);
Console.WriteLine("Vertices " + Vertices.Length);
}
break;
default:
reader.Seek(lengthOfStruct, System.IO.SeekOrigin.Current);
break;
}
}
}
}
private static List<Triangle> ToTris(int[] polys, byte opcode)
{
if (polys.Length == 3)
return new List<Triangle>()
{
new Triangle()
{ A = polys[0], B = polys[1], C = polys[2] }
};
var tris = new List<Triangle>();
if (opcode == 0x98)
{
int n = 2;
for (int x = 0; x < polys.Length - 2; x++)
{
int[] tri = new int[3];
bool isEven = (n % 2) == 0;
tri[0] = polys[n - 2];
tri[1] = isEven ? polys[n] : polys[n - 1];
tri[2] = isEven ? polys[n - 1] : polys[n];
if (tri[0] != tri[1] && tri[1] != tri[2] && tri[2] != tri[0])
tris.Add(new Triangle()
{
A = tri[0],
B = tri[1],
C = tri[2],
});
n++;
}
}
if (opcode == 0xA0)
{
for (int n = 1; n < polys.Length - 1; n++)
{
int[] tri = new int[3];
tri[0] = polys[n];
tri[1] = polys[n + 1];
tri[2] = polys[0];
if (tri[0] != tri[1] && tri[1] != tri[2] && tri[2] != tri[0])
tris.Add(new Triangle()
{
A = tri[0],
B = tri[1],
C = tri[2],
});
}
}
return tris;
}
public class Triangle
{
public int A;
public int B;
public int C;
}
public void Unload()
{
}
public void Save(System.IO.Stream stream)
{
}
public class MaterialTextureMap : STGenericMatTexture
{
//The index of a texture
//Some formats will map them by index, some by name, some by a hash, it's up to how the user handles it
public int TextureIndex { get; set; }
}
public class MDL_Renderer : GenericModelRenderer
{
//A list of textures to display on the model
public List<STGenericTexture> TextureList = new List<STGenericTexture>();
public override void OnRender(GLControl control)
{
//Here we can add things on each frame rendered
}
//Render data to display by per material and per mesh
public override void SetRenderData(STGenericMaterial mat, ShaderProgram shader, STGenericObject m)
{
}
//Custom bind texture method
public override int BindTexture(STGenericMatTexture tex, ShaderProgram shader)
{
//By default we bind to the default texture to use
//This will be used if no texture is found
GL.ActiveTexture(TextureUnit.Texture0 + tex.textureUnit + 1);
GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.RenderableTex.TexID);
string activeTex = tex.Name;
//We want to cast our custom texture map class to get any custom properties we may need
//If you don't need any custom way of mapping, you can just stick with the generic one
var matTexture = (MaterialTextureMap)tex;
//Go through our texture maps in the material and see if the index matches
foreach (var texture in TextureList)
{
if (TextureList.IndexOf(texture) == matTexture.TextureIndex)
{
BindGLTexture(tex, shader, TextureList[matTexture.TextureIndex]);
return tex.textureUnit + 1;
}
//You can also check if the names match
if (texture.Text == tex.Name)
{
BindGLTexture(tex, shader, TextureList[matTexture.TextureIndex]);
return tex.textureUnit + 1;
}
}
//Return our texture uint id.
return tex.textureUnit + 1;
}
}
}
}

View file

@ -68,11 +68,9 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
MemoryStream mem = new MemoryStream();
header.Write(new FileWriter(mem));
return mem.ToArray();
header.Write(new FileWriter(stream));
}
public class Header

View file

@ -66,11 +66,10 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
MemoryStream mem = new MemoryStream();
header.Write(new FileWriter(mem));
return mem.ToArray();
header.Write(new FileWriter(stream));
}
public class Header

View file

@ -86,9 +86,8 @@ namespace FirstPlugin
}
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public void Unload()

View file

@ -10,7 +10,7 @@ using LibHac;
namespace FirstPlugin
{
public class GCDisk : IArchiveFile, IFileFormat
public class GCDisk : IArchiveFile, IFileFormat, ISaveOpenedFileStream
{
public FileType FileType { get; set; } = FileType.Rom;
@ -52,6 +52,8 @@ namespace FirstPlugin
public void Load(System.IO.Stream stream)
{
CanSave = false;
using (var reader = new FileReader(stream))
{
Header = new DiskHeader();
@ -100,6 +102,21 @@ namespace FirstPlugin
FileTable = new FileSystemTable();
FileTable.Read(reader, disk.files, disk.FilePath);
}
public void Write(FileWriter writer, GCDisk disk)
{
writer.Write(GameCode);
writer.Write(DiskID);
writer.Write(Version);
writer.Write(AudioStreaming);
writer.Write(StreamBufferSize);
writer.Seek(0x12);
writer.Write(1033843650);
FileTable.Write(writer, disk.files);
}
}
public class FileSystemTable
@ -170,6 +187,41 @@ namespace FirstPlugin
return currentIndex;
}
public void Write(FileWriter writer, List<FileEntry> Files)
{
long pos = writer.Position;
//reserve space
for (int i = 0; i < Files.Count; i++)
{
writer.Write(uint.MaxValue);
writer.Write(uint.MaxValue);
writer.Write(uint.MaxValue);
}
for (int i = 0; i < Files.Count; i++)
{
writer.WriteUint32Offset(pos + (i * 12));
writer.Write(Files[i].FileName);
}
for (int i = 0; i < Files.Count; i++)
{
writer.WriteUint32Offset(pos + (i * 12) + 4);
//More simple to get the size this way than getting file data over and over
//Also we don't need to store the bytes in memory
// long _fileStart = writer.Position;
writer.Write(Files[i].FileData);
// long _fileEnd = writer.Position;
/* using (writer.TemporarySeek(pos + (i * 12) + 8, System.IO.SeekOrigin.Begin))
{
writer.Write((uint)(_fileEnd - _fileStart));
}*/
}
}
}
@ -178,9 +230,10 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
Header.Write(new FileWriter(stream), this);
}
public bool AddFile(ArchiveFileInfo archiveFileInfo)

View file

@ -55,9 +55,9 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public bool AddFile(ArchiveFileInfo archiveFileInfo)

View file

@ -66,9 +66,9 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public bool AddFile(ArchiveFileInfo archiveFileInfo)

View file

@ -91,9 +91,9 @@ namespace FirstPlugin
Control = null;
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public bool AddFile(ArchiveFileInfo archiveFileInfo)

View file

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Toolbox.Library;
using Toolbox.Library.IO;
namespace FirstPlugin
{
@ -39,9 +40,9 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
}
}

View file

@ -91,9 +91,9 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public bool CheckWiiU(FileReader reader)

View file

@ -50,9 +50,9 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public class Header

View file

@ -80,13 +80,14 @@ namespace FirstPlugin
}
}
}
public void Unload()
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public class ShaderProgram : TreeNodeCustom

View file

@ -45,13 +45,14 @@ namespace FirstPlugin
}
}
public void Unload()
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
}
}

View file

@ -61,13 +61,14 @@ namespace FirstPlugin
Nodes[1].Nodes.Add(item);
}
}
public void Unload()
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
//Docs https://github.com/Kinnay/Wii-U-File-Formats/wiki/SHARCFB-File-Format

View file

@ -91,13 +91,14 @@ namespace FirstPlugin
}
}
}
public void Unload()
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
//Docs https://github.com/Kinnay/Wii-U-File-Formats/wiki/SHARCFB-File-Format

View file

@ -426,10 +426,9 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
MemoryStream mem = new MemoryStream();
using (var writer = new FileWriter(mem))
using (var writer = new FileWriter(stream, true))
{
writer.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
@ -444,7 +443,6 @@ namespace FirstPlugin
writer.Seek(headerPos + 0x0C, SeekOrigin.Begin);
writer.Write((uint)writer.BaseStream.Length);
}
return mem.ToArray();
}
public class Header

View file

@ -602,10 +602,10 @@ namespace FirstPlugin
{
form.Dispose();
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
MemoryStream mem = new MemoryStream();
using (var writer = new FileWriter(mem))
using (var writer = new FileWriter(stream, true))
{
writer.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
@ -620,7 +620,6 @@ namespace FirstPlugin
writer.Seek(headerPos + 0x0C, SeekOrigin.Begin);
writer.Write((uint)writer.BaseStream.Length);
}
return mem.ToArray();
}
public class Header

View file

@ -269,16 +269,18 @@ namespace FirstPlugin
IsLoadingArray = false;
}
private static void SaveBNTXArray(MemoryStream mem, List<BNTX> Containers)
private static void SaveBNTXArray(Stream stream, List<BNTX> Containers)
{
IsSavingArray = true;
int Alignment = 4096;
using (var saver = new FileWriter(mem))
using (var saver = new FileWriter(stream, true))
{
foreach (var container in Containers)
{
saver.Write(container.Save());
var mem = new System.IO.MemoryStream();
container.Save(mem);
saver.Write(mem.ToArray());
saver.Align(Alignment);
}
}
@ -892,13 +894,12 @@ namespace FirstPlugin
private void SortTextures(object sender, EventArgs args)
{
}
public byte[] Save()
{
MemoryStream mem = new MemoryStream();
public void Save(System.IO.Stream stream)
{
if (ContainerArray.Count > 0 && !IsSavingArray)
{
SaveBNTXArray(mem, ContainerArray);
SaveBNTXArray(stream, ContainerArray);
}
else
{
@ -923,10 +924,8 @@ namespace FirstPlugin
BinaryTexFile.TextureDict.Add(tex.Text);
}
BinaryTexFile.Save(mem);
BinaryTexFile.Save(stream);
}
return mem.ToArray();
}
public class PropertieGridData

View file

@ -108,9 +108,8 @@ namespace FirstPlugin
}
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public void Unload()

View file

@ -45,9 +45,9 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}
public class Header

View file

@ -159,16 +159,12 @@ namespace FirstPlugin
public void Unload()
{
}
public byte[] Save()
{
//Get each block type for saving except alignment
// var TextureInfoBlocks = blocks.Where(i => i.BlockType == BlockType.ImageInfo);
// var TextureDataBlocks = blocks.Where(i => i.BlockType == BlockType.ImageData);
// var TextureMipDataBlocks = blocks.Where(i => i.BlockType == BlockType.MipData);
System.IO.MemoryStream mem = new System.IO.MemoryStream();
using (FileWriter writer = new FileWriter(mem))
}
public void Save(System.IO.Stream stream)
{
using (FileWriter writer = new FileWriter(stream, true))
{
writer.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
header.Write(writer);
@ -246,7 +242,6 @@ namespace FirstPlugin
}
}
}
return mem.ToArray();
}
private static uint GetAlignBlockSize(uint DataOffset, uint Alignment)

View file

@ -62,11 +62,11 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
var mem = new System.IO.MemoryStream();
NutHeader.Write(new FileWriter(mem));
return mem.ToArray();
NutHeader.Write(new FileWriter(stream));
}
public class Header

View file

@ -626,11 +626,10 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
System.IO.MemoryStream mem = new System.IO.MemoryStream();
Write(new FileWriter(mem));
return mem.ToArray();
Write(new FileWriter(stream));
}
}
}

View file

@ -121,10 +121,9 @@ namespace FirstPlugin
}
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
MemoryStream mem = new MemoryStream();
using (var writer = new FileWriter(mem))
using (var writer = new FileWriter(stream, true))
{
writer.Write(Width);
writer.Write(Height);
@ -136,9 +135,6 @@ namespace FirstPlugin
writer.Position = 0x80;
writer.Write(ImageData);
}
return mem.ToArray();
}
public override void SetImageData(System.Drawing.Bitmap bitmap, int ArrayLevel)

View file

@ -298,10 +298,8 @@ namespace FirstPlugin
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
MemoryStream mem = new MemoryStream();
return mem.ToArray();
}
}
}

View file

@ -68,11 +68,9 @@ namespace FirstPlugin
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
MemoryStream mem = new MemoryStream();
SaveFile(new FileWriter(mem));
return mem.ToArray();
SaveFile(new FileWriter(stream, true));
}
public class XTXFormats

View file

@ -55,16 +55,15 @@ namespace FirstPlugin.Turbo
Read(new FileReader(stream));
}
public void Unload()
{
}
public byte[] Save()
{
MemoryStream mem = new MemoryStream();
Write(new FileWriter(mem));
return mem.ToArray();
public void Save(System.IO.Stream stream)
{
Write(new FileWriter(stream));
}
public CameraData cameraData;

View file

@ -70,9 +70,9 @@ namespace FirstPlugin
{
}
public byte[] Save()
public void Save(System.IO.Stream stream)
{
return null;
}

View file

@ -86,6 +86,7 @@
</Reference>
<Reference Include="Gl_EditorFramework">
<HintPath>..\Toolbox\Gl_EditorFramework.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="KCLExt">
<HintPath>..\Toolbox\Lib\KCLExt.dll</HintPath>
@ -223,7 +224,6 @@
<Compile Include="FileFormats\Archives\NXARC.cs" />
<Compile Include="FileFormats\Archives\Sonic Forces\PACx30XL.cs" />
<Compile Include="FileFormats\Archives\RARC.cs" />
<Compile Include="FileFormats\Archives\SARC_OLD.cs" />
<Compile Include="FileFormats\Archives\Sonic Racing\GameDataToc.cs" />
<Compile Include="FileFormats\Archives\Sonic Racing\SPC.cs" />
<Compile Include="FileFormats\Archives\Sonic Racing\SWU.cs" />
@ -277,6 +277,7 @@
<Compile Include="FileFormats\HyruleWarriors\G1M.cs" />
<Compile Include="FileFormats\Message\MSBP.cs" />
<Compile Include="FileFormats\CrashBandicoot\IGZ_TEX.cs" />
<Compile Include="FileFormats\MOD.cs" />
<Compile Include="FileFormats\Pikmin\TXE.cs" />
<Compile Include="FileFormats\Texture\CTPK.cs" />
<Compile Include="FileFormats\Grezzo\CTXB.cs" />

View file

@ -106,7 +106,7 @@ namespace FirstPlugin.Forms
SaveFileDialog sav = new SaveFileDialog() { FileName = AampFile.FileName, Filter = "Parameter Archive | *.aamp" };
if (sav.ShowDialog() == DialogResult.OK)
{
File.WriteAllBytes(sav.FileName, AampFile.Save());
Toolbox.Library.IO.STFileSaver.SaveFileFormat(AampFile, sav.FileName);
}
}

View file

@ -206,7 +206,7 @@ namespace FirstPlugin.Forms
SaveFileDialog sfd = new SaveFileDialog();
if (sfd.ShowDialog() == DialogResult.OK)
{
File.WriteAllBytes(sfd.FileName, CameraFile.Save());
STFileSaver.SaveFileFormat(CameraFile, sfd.FileName);
}
}
}

Some files were not shown because too many files have changed in this diff Show more