Skip to content

Commit

Permalink
Fix duped objects pointing to original obj
Browse files Browse the repository at this point in the history
  • Loading branch information
ihatecompvir committed Jan 10, 2025
1 parent e92befd commit ce8c55d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
13 changes: 12 additions & 1 deletion MiloEditor/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,22 @@ private void DuplicateAsset(TreeNode node)
if (entry.typeRecognized)
{
newEntry = new DirectoryMeta.Entry(entry.type, entry.name, entry.obj);

var updatedBytes = entry.objBytes.ToArray().Concat(new byte[] { 0xAD, 0xDE, 0xAD, 0xDE }).ToArray();

// hack to clone an obj without making them clonable or writing a Copy method
// dont like this but :shrug:
using (MemoryStream ms = new MemoryStream(updatedBytes))
{
EndianReader reader = new EndianReader(ms, currentMiloScene.endian);
directoryEntry.ReadEntry(reader, entry);
}
}
else
{
// create a dirty entry
newEntry = Entry.CreateDirtyAssetFromBytes(entry.type.value, entry.name.value, entry.objBytes);
newEntry = Entry.CreateDirtyAssetFromBytes(entry.type, entry.name, entry.objBytes);

}

// bring up a dialog to get the new name
Expand Down
6 changes: 6 additions & 0 deletions MiloLib/MiloFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public enum Type : uint
/// </summary>
public DirectoryMeta dirMeta;

/// <summary>
/// The endianness of the body. Header is always little endian.
/// </summary>
public Endian endian = Endian.BigEndian;

/// <summary>
/// Loads a Milo file from a file path.
/// </summary>
Expand Down Expand Up @@ -292,6 +297,7 @@ public MiloFile(DirectoryMeta meta)
/// <param name="bodyEndian">The endianness of the body. Certain games require little endian bodies, such as GH2.</param>
public void Save(string? path, Type? type, uint startingOffset = 0x810, Endian headerEndian = Endian.LittleEndian, Endian bodyEndian = Endian.BigEndian)
{
endian = bodyEndian;
if (path == null)
{
path = filePath;
Expand Down

0 comments on commit ce8c55d

Please sign in to comment.