Skip to content

Commit

Permalink
TMX: save UserId, allow editing in UI
Browse files Browse the repository at this point in the history
AMD: fix 'Cannot open a closed file'
  • Loading branch information
Chris Weermann (TGE) committed Jun 18, 2020
1 parent 91989ef commit 0a38165
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 13 deletions.
Binary file not shown.
Binary file added Dependencies/Nuget/morelinq.2.10.0/.signature.p7s
Binary file not shown.
4 changes: 2 additions & 2 deletions Source/Amicitia/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.9.0.0")]
[assembly: AssemblyFileVersion("1.9.0.0")]
[assembly: AssemblyVersion("1.9.1.0")]
[assembly: AssemblyFileVersion("1.9.1.0")]
3 changes: 3 additions & 0 deletions Source/Amicitia/ResourceWrapperFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public static IResourceWrapper GetResourceWrapper(string text, Stream stream, in
{
if ( stream is FileStream fileStream )
{
if ( filePath == null )
filePath = fileStream.Name;

stream = fileStream.ToMemoryStream( leaveOpen: false );
}

Expand Down
3 changes: 1 addition & 2 deletions Source/Amicitia/ResourceWrappers/PAKFileSystemWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ protected override void Initialize()

RegisterFileExportAction(SupportedFileType.PakArchiveFile, ( res, path ) =>
{
res.Save().SaveToFile( leaveOpen: false, path );
res.Save( path );
} );
RegisterFileReplaceAction( SupportedFileType.PakArchiveFile, ( res, path ) =>
{
Expand Down
11 changes: 11 additions & 0 deletions Source/Amicitia/ResourceWrappers/ResourceWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public abstract partial class ResourceWrapper<TResource> : TreeNode, IResourceWr
private Dictionary<SupportedFileType, Action<string, ResourceWrapper<TResource>>> mFileAddActions;
private Func<ResourceWrapper<TResource>, TResource> mRebuildAction;
private List<ContextMenuAction> mCustomActions;
private Dictionary<Type, ContextMenuStrip> mContextMenuStripCache
= new Dictionary<Type, ContextMenuStrip>();

public event PropertyChangedEventHandler PropertyChanged;

Expand Down Expand Up @@ -574,6 +576,13 @@ private void PopulateViewFully()
/// </summary>
private void PopulateContextMenuStrip()
{
var type = GetType();
if (mContextMenuStripCache.TryGetValue( type, out var temp ) )
{
ContextMenuStrip = temp;
return;
}

ContextMenuStrip = new ContextMenuStrip();

if ( mCustomActions != null )
Expand Down Expand Up @@ -629,6 +638,8 @@ private void PopulateContextMenuStrip()
{
ContextMenuStrip.Items.Add(new ToolStripMenuItem("&Delete", null, DeleteEventHandler, Keys.Control | Keys.Delete));
}

mContextMenuStripCache[type] = ContextMenuStrip;
}

/// <summary>
Expand Down
23 changes: 23 additions & 0 deletions Source/Amicitia/ResourceWrappers/TMXFileWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ public class TmxFileWrapper : ResourceWrapper<TmxFile>
[OrderedProperty]
public byte MipMapCount => Resource.MipMapCount;

[Category( "Texture format" )]
[OrderedProperty]
public float MipMapKValue => Resource.MipMapKValue;

[Category( "Texture format" )]
[OrderedProperty]
public float MipMapLValue => Resource.MipMapLValue;

[Category("Texture wrapping modes")]
[OrderedProperty]
public TmxWrapMode HorizontalWrappingMode
Expand All @@ -53,6 +61,13 @@ public TmxWrapMode VerticalWrappingMode
set => SetProperty(Resource, value);
}

[Category("Texture metadata"), OrderedProperty]
public short UserId
{
get => Resource.UserId;
set => SetProperty(Resource, value);
}

[Category("Texture metadata")]
[OrderedProperty]
public int UserTextureId
Expand All @@ -77,6 +92,14 @@ public string UserComment
set => SetProperty(Resource, value);
}

[Category("Misc")]
[OrderedProperty]
public byte Reserved
{
get => Resource.Reserved;
set => SetProperty(Resource, value);
}

public TmxFileWrapper(string text, TmxFile resource) : base(text, resource)
{
}
Expand Down
3 changes: 2 additions & 1 deletion Source/AmicitiaLibrary/FileSystems/AMD/AMDFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using IO;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Utilities;

public class AmdFile : BinaryBase
Expand Down Expand Up @@ -65,7 +66,7 @@ public AmdFile(string path)
/// <param name="path">The path pointing to the the file to load.</param>
public AmdFile(Stream stream, bool leaveOpen = false)
{
using (BinaryReader reader = new BinaryReader(stream))
using (BinaryReader reader = new BinaryReader( stream, Encoding.Default, leaveOpen ) )
{
Read(reader);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public CvmExecutableListing(string path)
mRootDirectoryListing = new CvmDirectoryListing(reader, null);
}

public CvmExecutableListing(Stream stream)
public CvmExecutableListing(Stream stream, bool leaveOpen = false)
{
using (BinaryReader reader = new BinaryReader(stream, System.Text.Encoding.Default, true))
using (BinaryReader reader = new BinaryReader(stream, System.Text.Encoding.Default, leaveOpen ) )
mRootDirectoryListing = new CvmDirectoryListing(reader, null);
}

Expand Down
4 changes: 2 additions & 2 deletions Source/AmicitiaLibrary/Graphics/RenderWare/RMDNodeLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public RmdNodeLink(byte[] data)
{
}

public RmdNodeLink(Stream stream)
public RmdNodeLink(Stream stream, bool leaveOpen = false)
{
using (BinaryReader reader = new BinaryReader(stream))
using (BinaryReader reader = new BinaryReader(stream, System.Text.Encoding.Default, leaveOpen) )
{
Read(reader);
}
Expand Down
11 changes: 7 additions & 4 deletions Source/AmicitiaLibrary/Graphics/TMX/TMXFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ internal TmxFile(BinaryReader reader)
/********************/
/**** Properties ****/
/********************/
public short UserId { get; set; }

public byte PaletteCount { get; private set; }

Expand Down Expand Up @@ -139,6 +140,8 @@ public byte MipMapLValue
}
}

public byte Reserved { get; set; }

public TmxWrapMode HorizontalWrappingMode
{
get
Expand Down Expand Up @@ -289,7 +292,7 @@ internal override void Write(BinaryWriter writer)
writer.Write((byte)PixelFormat);
writer.Write(MipMapCount);
writer.Write(mMipKl);
writer.Write((byte)0);
writer.Write(Reserved);
writer.Write(mWrapModes);
writer.Write(UserTextureId);
writer.Write(UserClutId);
Expand All @@ -311,7 +314,7 @@ internal override void Write(BinaryWriter writer)
// Seek back to the chunk header and write it
writer.BaseStream.Seek(posFileStart, SeekOrigin.Begin);
writer.Write(FLAG);
writer.Write((short)0); // userID
writer.Write(UserId); // userID
writer.Write(length);
writer.WriteCString(TAG, 4);

Expand All @@ -323,7 +326,7 @@ private void Read(BinaryReader reader)
{
long posFileStart = reader.GetPosition();
short flag = reader.ReadInt16();
short userId = reader.ReadInt16();
UserId = reader.ReadInt16();
int length = reader.ReadInt32();
string tag = reader.ReadCString(4);
reader.AlignPosition(16);
Expand All @@ -340,7 +343,7 @@ private void Read(BinaryReader reader)
PixelFormat = (PS2PixelFormat)reader.ReadByte();
MipMapCount = reader.ReadByte();
mMipKl = reader.ReadUInt16();
byte reserved = reader.ReadByte();
Reserved = reader.ReadByte();
mWrapModes = reader.ReadByte();
UserTextureId = reader.ReadInt32();
UserClutId = reader.ReadInt32();
Expand Down

0 comments on commit 0a38165

Please sign in to comment.