Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
a8c37a8
Stop Multis preview flicker when switching entries
AsYlum- Nov 13, 2026
54fb3b6
Read and write UO Architect design files (.uoa and Designs.idx/bin)
AsYlum- Nov 14, 2026
b98aa4a
Import UOHE and WorldForge multi designs and export every importable …
AsYlum- Nov 14, 2026
97fc5d7
Resolve a plugin's dependencies from plugins\<plugin name>\
AsYlum- Nov 14, 2026
b6015cf
Keep plugin settings in the profile
AsYlum- Nov 14, 2026
b2cb961
Let plugins add to the Map tab's context menu with the clicked location
AsYlum- Nov 14, 2026
271a401
Add 1,697 tiles to the multi editor tile groups and a tile rotation t…
AsYlum- Nov 14, 2026
6a9746c
Replace the multi editor with an OpenGL editor, version 3.0.0
AsYlum- Nov 14, 2026
387d522
Turn multi pieces by their art and the client's house tables when rot…
AsYlum- Nov 14, 2026
58c764e
Import several multi files at once, or every multi in a folder
AsYlum- Nov 14, 2026
ecf7055
Read and write POL multiforge text in the multi editor
AsYlum- Nov 14, 2026
abdd8db
Add tab close buttons, wheel switching and Close all designs to the m…
AsYlum- Nov 14, 2026
575dfa8
Speed up the multi editor's hover hit test and add a performance box …
AsYlum- Nov 14, 2026
813c31e
Keep one work plane in the multi editor that follows the chosen floor…
AsYlum- Nov 14, 2026
aa83585
Keep multi editor designs centred and add Center design
AsYlum- Nov 14, 2026
1a0e61d
Tidy the multi editor toolbars
AsYlum- Nov 14, 2026
9503080
Put the compare views on nested tabs under one Compare tab
AsYlum- Nov 14, 2026
d785455
Update change log and version
AsYlum- Nov 14, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
424 changes: 423 additions & 1 deletion Ultima/MultiComponentList.cs

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion Ultima/Multis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ public enum ImportType
UOX3,
MULTICACHE,
UOADESIGN,
XML
XML,
UOH, // UO House Editor (UOHE) design
WORLDFORGE, // WorldForge tile export
MULTIFORGE // POL multiforge package text: id x y z hue [multi flag]
}

/// <summary>
Expand Down
241 changes: 241 additions & 0 deletions Ultima/UoaDesignFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
using System;
using System.Collections.Generic;
using System.IO;

namespace Ultima
{
/// <summary>
/// One design in a UO Architect file: what its header says, and where its items are.
/// </summary>
public sealed class UoaDesign
{
public string Name { get; internal set; }

public string Category { get; internal set; }

public string Subsection { get; internal set; }

/// <summary>Size as UO Architect stored it; not always the extent of the items.</summary>
public int Width { get; internal set; }

public int Height { get; internal set; }

public int ItemCount { get; internal set; }

/// <summary>The .uoa file, or the .idx of an idx + bin design set.</summary>
public string FileName { get; internal set; }

/// <summary>Position of the design within its file, from 0.</summary>
public int Index { get; internal set; }

/// <summary>Where the item records start: in the .uoa itself, or in the .bin of a design set.</summary>
internal long ItemsPosition { get; set; }

internal bool InDesignSet { get; set; }
}

/// <summary>
/// Reads and writes UO Architect designs. Layouts as in UO Architect 2.7:
/// <list type="bullet">
/// <item>.uoa version 1: one design. Version 2: a count, then that many designs.</item>
/// <item>A design: name, category, subsection (each a flag byte, then a length-prefixed string
/// when the flag is 1), width, height, user width, user height, item count (int32 each), then
/// per item six int16: id, x, y, z, level, hue.</item>
/// <item>Design set (Designs.idx + Designs.bin): the idx holds a count, a version (0) and per
/// design the same header followed by the int64 position and int32 count of its records in
/// the bin; a bin record is int32 type (0 or 1), id, x, y, z, level, and hue when type is 1.</item>
/// </list>
/// A multi has no item hue or level, so reading drops them and writing stores 0.
/// </summary>
public static class UoaDesignFile
{
private const int _itemSize = 12;

/// <summary>
/// The designs a file holds, without reading their items. Takes a .uoa (either version) or
/// the .idx of a design set. An unreadable or foreign file gives an empty list.
/// </summary>
public static List<UoaDesign> ReadHeaders(string fileName)
{
var designs = new List<UoaDesign>();
try
{
using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
using (var reader = new BinaryReader(fs))
{
if (fileName.EndsWith(".idx", StringComparison.OrdinalIgnoreCase))
{
int count = reader.ReadInt32();
if (reader.ReadInt32() != 0 || count < 0)
{
return designs;
}

for (int i = 0; i < count; ++i)
{
UoaDesign design = ReadHeader(reader, fileName, i, countFollows: false);
design.ItemsPosition = reader.ReadInt64();
design.ItemCount = reader.ReadInt32();
design.InDesignSet = true;
designs.Add(design);
}

return designs;
}

short version = reader.ReadInt16();
int total = version == 1 ? 1 : version == 2 ? reader.ReadInt16() : 0;
for (int i = 0; i < total; ++i)
{
UoaDesign design = ReadHeader(reader, fileName, i, countFollows: true);
design.ItemsPosition = fs.Position;
fs.Seek((long)design.ItemCount * _itemSize, SeekOrigin.Current);
if (fs.Position > fs.Length)
{
break; // cut short: what was read so far stands
}

designs.Add(design);
}
}
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or ArgumentException)
{
// What was read before the file ran out is returned.
}

return designs;
}

private static UoaDesign ReadHeader(BinaryReader reader, string fileName, int index, bool countFollows)
{
var design = new UoaDesign
{
FileName = fileName,
Index = index,
Name = ReadString(reader),
Category = ReadString(reader),
Subsection = ReadString(reader),
Width = reader.ReadInt32(),
Height = reader.ReadInt32()
};
reader.ReadInt32(); // user width
reader.ReadInt32(); // user height
if (countFollows)
{
design.ItemCount = reader.ReadInt32();
if (design.ItemCount < 0)
{
throw new IOException("Negative item count");
}
}

return design;
}

/// <summary>The items of a design as a multi. Hue and level are dropped; Z is kept within a multi's range.</summary>
public static MultiComponentList Load(UoaDesign design)
{
var entries = new List<MultiComponentList.MultiTileEntry>(Math.Max(0, design.ItemCount));
string path = design.InDesignSet ? Path.ChangeExtension(design.FileName, ".bin") : design.FileName;
using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
using (var reader = new BinaryReader(fs))
{
fs.Seek(design.ItemsPosition, SeekOrigin.Begin);
for (int i = 0; i < design.ItemCount; ++i)
{
int id, x, y, z;
if (design.InDesignSet)
{
int type = reader.ReadInt32();
id = reader.ReadInt32();
x = reader.ReadInt32();
y = reader.ReadInt32();
z = reader.ReadInt32();
reader.ReadInt32(); // level
if (type == 1)
{
reader.ReadInt32(); // hue
}
}
else
{
id = (ushort)reader.ReadInt16();
x = reader.ReadInt16();
y = reader.ReadInt16();
z = reader.ReadInt16();
reader.ReadInt16(); // level
reader.ReadInt16(); // hue
}

entries.Add(new MultiComponentList.MultiTileEntry
{
ItemId = (ushort)id,
OffsetX = (short)x,
OffsetY = (short)y,
OffsetZ = (short)Math.Clamp(z, sbyte.MinValue, sbyte.MaxValue),
Flags = 1,
Unk1 = 0
});
}
}

return entries.Count == 0 ? MultiComponentList.Empty : new MultiComponentList(entries);
}

/// <summary>
/// Writes designs as a .uoa: version 1 for one design, version 2 (a batch) for several.
/// </summary>
public static void Write(string fileName, IReadOnlyList<(string Name, string Category, string Subsection, MultiComponentList Multi)> designs)
{
using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
using (var writer = new BinaryWriter(fs))
{
if (designs.Count == 1)
{
writer.Write((short)1);
}
else
{
writer.Write((short)2);
writer.Write((short)designs.Count);
}

foreach ((string name, string category, string subsection, MultiComponentList multi) in designs)
{
WriteString(writer, name);
WriteString(writer, category);
WriteString(writer, subsection);
writer.Write(multi.Width);
writer.Write(multi.Height);
writer.Write(multi.Width); // user width
writer.Write(multi.Height); // user height
writer.Write(multi.SortedTiles.Length);
foreach (MultiComponentList.MultiTileEntry tile in multi.SortedTiles)
{
writer.Write((short)tile.ItemId);
writer.Write(tile.OffsetX);
writer.Write(tile.OffsetY);
writer.Write(tile.OffsetZ);
writer.Write((short)0); // level
writer.Write((short)0); // hue
}
}
}
}

internal static string ReadString(BinaryReader reader)
{
return reader.ReadByte() == 0 ? null : reader.ReadString();
}

internal static void WriteString(BinaryWriter writer, string value)
{
writer.Write((byte)(value == null ? 0 : 1));
if (value != null)
{
writer.Write(value);
}
}
}
}
6 changes: 6 additions & 0 deletions UoFiddler.Controls/Classes/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public static class Options
/// </summary>
public static List<string> PluginsToLoad { get; set; } = new List<string>();

/// <summary>
/// Settings plugins keep in the profile, by name. A plugin prefixes its names with its own
/// (e.g. "MultiEditor.Grid"); the values are saved and loaded with the profile as text.
/// </summary>
public static Dictionary<string, string> PluginSettings { get; set; } = new Dictionary<string, string>();

/// <summary>
/// Defines which muls are loaded
/// <para>
Expand Down
19 changes: 19 additions & 0 deletions UoFiddler.Controls/Plugin/PluginEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
*
***************************************************************************/

using System;
using System.Drawing;
using System.Windows.Forms;
using Ultima;

namespace UoFiddler.Controls.Plugin
{
Expand All @@ -30,5 +33,21 @@ public static void FireModifyItemShowContextMenuEvent(ContextMenuStrip contextme
{
ModifyItemsControlContextMenuEvent?.Invoke(contextmenu);
}

/// <summary>
/// OnLoad called in MapControl to modify its context menu. <paramref name="clickedAt"/> gives
/// the shown map and the map location of the right click that opened the menu.
/// </summary>
public delegate void ModifyMapControlContextMenuHandler(ContextMenuStrip contextmenu, Func<(Map Map, Point Location)> clickedAt);

/// <summary>
/// OnLoad called in MapControl to modify its context menu
/// </summary>
public static event ModifyMapControlContextMenuHandler ModifyMapControlContextMenuEvent;

public static void FireModifyMapControlContextMenuEvent(ContextMenuStrip contextmenu, Func<(Map Map, Point Location)> clickedAt)
{
ModifyMapControlContextMenuEvent?.Invoke(contextmenu, clickedAt);
}
}
}
55 changes: 55 additions & 0 deletions UoFiddler.Controls/Plugin/PluginServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Loader;
using Microsoft.Extensions.Logging;
using UoFiddler.Controls.Classes;
using UoFiddler.Controls.Plugin.Interfaces;
Expand Down Expand Up @@ -53,6 +55,8 @@ public void FindPlugins(string path)
return;
}

RegisterDependencyResolver(path);

foreach (string fileOn in Directory.GetFiles(path, "*.dll"))
{
try
Expand Down Expand Up @@ -86,6 +90,57 @@ public void ClosePlugins()
AvailablePlugins.Clear();
}

private static string _dependencyRoot;

/// <summary>
/// Lets a plugin ship third-party libraries in a subfolder of the plugin directory
/// (plugins\PluginName\). Files directly in the plugin directory are all loaded as plugins,
/// so dependencies cannot sit there.
/// </summary>
private static void RegisterDependencyResolver(string pluginDirectory)
{
bool first = _dependencyRoot == null;
_dependencyRoot = pluginDirectory;
if (!first)
{
return;
}

AssemblyLoadContext.Default.Resolving += (context, name) =>
{
string path = FindDependency(name.Name + ".dll");
return path == null ? null : context.LoadFromAssemblyPath(path);
};

AssemblyLoadContext.Default.ResolvingUnmanagedDll += (_, libraryName) =>
{
string path = FindDependency(libraryName)
?? (libraryName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)
? null
: FindDependency(libraryName + ".dll"));
return path != null && NativeLibrary.TryLoad(path, out IntPtr handle) ? handle : IntPtr.Zero;
};
}

private static string FindDependency(string fileName)
{
if (!Directory.Exists(_dependencyRoot))
{
return null;
}

foreach (string directory in Directory.GetDirectories(_dependencyRoot))
{
string candidate = Path.Combine(directory, fileName);
if (File.Exists(candidate))
{
return candidate;
}
}

return null;
}

private void AddPlugin(string fileName)
{
Assembly pluginAssembly = Assembly.LoadFrom(fileName);
Expand Down
1 change: 1 addition & 0 deletions UoFiddler.Controls/UserControls/MapControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ private void OnLoad(object sender, EventArgs e)
ControlEvents.MapNameChangeEvent += OnMapNameChangeEvent;
ControlEvents.MapSizeChangeEvent += OnMapSizeChangeEvent;
ControlEvents.FilePathChangeEvent += OnFilePathChangeEvent;
Plugin.PluginEvents.FireModifyMapControlContextMenuEvent(contextMenuStrip1, () => (CurrentMap, _currentPoint));
}
_loaded = true;
}
Expand Down
Loading