Skip to content
Merged
8 changes: 4 additions & 4 deletions .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
fetch-depth: 0

- name: Install .NET Core
uses: actions/setup-dotnet@v4.3.0
uses: actions/setup-dotnet@v4.3.1
with:
dotnet-version: 8.0.x

Expand All @@ -45,7 +45,7 @@ jobs:
Configuration: ${{ matrix.configuration }}

- name: Upload build artifacts
uses: actions/upload-artifact@v4.6.1
uses: actions/upload-artifact@v4.6.2
with:
name: ${{ env.Asset_Name }}.zip
path: ./UOFiddler/bin/Release/
Expand All @@ -65,7 +65,7 @@ jobs:

steps:
- name: Download artifacts
uses: actions/download-artifact@v4.1.8
uses: actions/download-artifact@v4.3.0
with:
name: ${{ env.Asset_Name }}.zip
path: ./${{ env.Asset_Name }}/
Expand All @@ -74,7 +74,7 @@ jobs:
run: 7z a -tzip ${{ env.Asset_Name }}.zip './${{ env.Asset_Name }}'

- name: Create release
uses: softprops/action-gh-release@v2.2.1
uses: softprops/action-gh-release@v2.2.2
with:
name: UOFiddler ${{ github.ref_name }}
generate_release_notes: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
fetch-depth: 1

- name: Install .NET Core
uses: actions/setup-dotnet@v4.3.0
uses: actions/setup-dotnet@v4.3.1
with:
dotnet-version: 8.0.x

Expand Down
17 changes: 14 additions & 3 deletions Ultima/FileIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public Stream Seek(int index, out int length, out int extra, out bool patched)

IEntry e = FileAccessor.GetEntry(index);

if (e.Lookup < 0)
if (e.Lookup < 0 || (e.Lookup > 0 && e.Length == -1))
{
length = extra = 0;
patched = false;
Expand Down Expand Up @@ -274,40 +274,47 @@ public Stream Seek(int index, out int length, out int extra, out bool patched)
return FileAccessor.Stream;
}

public Stream Seek(int index, ref IEntry entry)
public Stream Seek(int index, ref IEntry entry, out bool patched)
{
if (FileAccessor is null)
{
patched = false;
return null;
}

if (index < 0 || index >= FileAccessor.IndexLength)
{
patched = false;
return null;
}

IEntry e = FileAccessor.GetEntry(index);

if (e.Lookup < 0)
{
patched = false;
return null;
}

if (e.Length < 0)
var length = e.Length & 0x7FFFFFFF;
if (length < 0)
{
patched = false;
return null;
}

entry = e;

if ((e.Length & (1 << 31)) != 0)
{
patched = true;
Verdata.Seek(e.Lookup);
return Verdata.Stream;
}

if (e.Length < 0)
{
patched = false;
return null;
}

Expand All @@ -318,14 +325,18 @@ public Stream Seek(int index, ref IEntry entry)

if (FileAccessor.Stream == null)
{
patched = false;
return null;
}

if (FileAccessor.Stream.Length < e.Lookup)
{
patched = false;
return null;
}

patched = false;

FileAccessor.Stream.Seek(e.Lookup, SeekOrigin.Begin);
return FileAccessor.Stream;
}
Expand Down
36 changes: 27 additions & 9 deletions Ultima/Gumps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static byte[] GetRawGump(int index, out int width, out int height)
height = -1;

IEntry entry = null;
Stream stream = _fileIndex.Seek(index, ref entry);
Stream stream = _fileIndex.Seek(index, ref entry, out bool patched);
if (stream == null || entry == null)
{
return null;
Expand All @@ -147,6 +147,11 @@ public static byte[] GetRawGump(int index, out int width, out int height)
// Compressed UOPs
if (entry.Flag >= CompressionFlag.Zlib)
{
if (patched)
{
throw new InvalidOperationException("Verdata.mul is not supported for compressed UOP");
}

if (_streamBuffer == null || _streamBuffer.Length < entry.Length)
{
_streamBuffer = new byte[entry.Length];
Expand Down Expand Up @@ -193,8 +198,14 @@ public static byte[] GetRawGump(int index, out int width, out int height)
return _streamBuffer;
}

var buffer = new byte[entry.Length];
stream.Read(buffer, 0, entry.Length);
var length = entry.Length;
if (patched)
{
length = entry.Length & 0x7FFFFFFF;
}

var buffer = new byte[length];
stream.ReadExactly(buffer, 0, length);
stream.Close();

return buffer;
Expand All @@ -208,6 +219,7 @@ public static byte[] GetRawGump(int index, out int width, out int height)
/// <param name="onlyHueGrayPixels"></param>
/// <param name="patched"></param>
/// <returns></returns>
// TODO: Currently unused and may be broken because of recent UOP changes. Needs verdata `patched` checks and compression handling
public static unsafe Bitmap GetGump(int index, Hue hue, bool onlyHueGrayPixels, out bool patched)
{
Stream stream = _fileIndex.Seek(index, out int length, out int extra, out patched);
Expand Down Expand Up @@ -405,7 +417,7 @@ public static unsafe Bitmap GetGump(int index, out bool patched)
}

IEntry entry = null;
Stream stream = _fileIndex.Seek(index, ref entry);
Stream stream = _fileIndex.Seek(index, ref entry, out patched);
if (stream == null || entry == null)
{
return null;
Expand All @@ -422,12 +434,18 @@ public static unsafe Bitmap GetGump(int index, out bool patched)
_patched[index] = true;
}

if (_streamBuffer == null || _streamBuffer.Length < entry.Length)
var length = entry.Length;
if (patched)
{
length = entry.Length & 0x7FFFFFFF;
}

if (_streamBuffer == null || _streamBuffer.Length < length)
{
_streamBuffer = new byte[entry.Length];
_streamBuffer = new byte[length];
}

stream.Read(_streamBuffer, 0, entry.Length);
stream.Read(_streamBuffer, 0, length);

uint width = (uint)entry.Extra1;
uint height = (uint)entry.Extra2;
Expand Down Expand Up @@ -544,8 +562,8 @@ public static unsafe void Save(string path)
if ((bmp == null) || (_removed[index]))
{
binidx.Write(-1); // lookup
binidx.Write(-1); // length
binidx.Write(-1); // extra
binidx.Write(0); // length
binidx.Write(0); // extra
}
else
{
Expand Down
Loading