Skip to content

Commit 031f879

Browse files
committed
Add bitmap data decompression and loading
1 parent 83c7302 commit 031f879

File tree

15 files changed

+144
-50
lines changed

15 files changed

+144
-50
lines changed

Duey.sln

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Duey.Abstractions", "src\Du
1414
EndProject
1515
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Duey.Provider.WZ", "src\Duey.Provider.WZ\Duey.Provider.WZ.csproj", "{6EC8524D-B087-4003-B25C-253EDB42F615}"
1616
EndProject
17+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testing", "src\Testing\Testing.csproj", "{A183EF54-AC94-4C7F-8537-BA8243AC81CD}"
18+
EndProject
1719
Global
1820
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1921
Debug|Any CPU = Debug|Any CPU
@@ -63,10 +65,23 @@ Global
6365
{6EC8524D-B087-4003-B25C-253EDB42F615}.Release|x64.Build.0 = Release|Any CPU
6466
{6EC8524D-B087-4003-B25C-253EDB42F615}.Release|x86.ActiveCfg = Release|Any CPU
6567
{6EC8524D-B087-4003-B25C-253EDB42F615}.Release|x86.Build.0 = Release|Any CPU
68+
{A183EF54-AC94-4C7F-8537-BA8243AC81CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
69+
{A183EF54-AC94-4C7F-8537-BA8243AC81CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
70+
{A183EF54-AC94-4C7F-8537-BA8243AC81CD}.Debug|x64.ActiveCfg = Debug|Any CPU
71+
{A183EF54-AC94-4C7F-8537-BA8243AC81CD}.Debug|x64.Build.0 = Debug|Any CPU
72+
{A183EF54-AC94-4C7F-8537-BA8243AC81CD}.Debug|x86.ActiveCfg = Debug|Any CPU
73+
{A183EF54-AC94-4C7F-8537-BA8243AC81CD}.Debug|x86.Build.0 = Debug|Any CPU
74+
{A183EF54-AC94-4C7F-8537-BA8243AC81CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
75+
{A183EF54-AC94-4C7F-8537-BA8243AC81CD}.Release|Any CPU.Build.0 = Release|Any CPU
76+
{A183EF54-AC94-4C7F-8537-BA8243AC81CD}.Release|x64.ActiveCfg = Release|Any CPU
77+
{A183EF54-AC94-4C7F-8537-BA8243AC81CD}.Release|x64.Build.0 = Release|Any CPU
78+
{A183EF54-AC94-4C7F-8537-BA8243AC81CD}.Release|x86.ActiveCfg = Release|Any CPU
79+
{A183EF54-AC94-4C7F-8537-BA8243AC81CD}.Release|x86.Build.0 = Release|Any CPU
6680
EndGlobalSection
6781
GlobalSection(NestedProjects) = preSolution
6882
{CB853B65-1455-4A28-BF23-B903161DBEA5} = {19B8D1C2-E056-4BE2-98CE-59269DC3182B}
6983
{648311E4-DFF6-40D3-AB49-D85B7BE036A2} = {19B8D1C2-E056-4BE2-98CE-59269DC3182B}
7084
{6EC8524D-B087-4003-B25C-253EDB42F615} = {19B8D1C2-E056-4BE2-98CE-59269DC3182B}
85+
{A183EF54-AC94-4C7F-8537-BA8243AC81CD} = {19B8D1C2-E056-4BE2-98CE-59269DC3182B}
7186
EndGlobalSection
7287
EndGlobal

src/Duey.Abstractions/Duey.Abstractions.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
<Import Project="..\Source.targets" />
44

5+
<ItemGroup>
6+
<PackageReference Include="CommunityToolkit.HighPerformance" Version="8.4.0" />
7+
</ItemGroup>
8+
59
</Project>
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
namespace Duey.Abstractions.Types;
22

3-
public struct DataAudio
4-
{
5-
public DataAudio(byte[] data) => Data = data;
6-
7-
public byte[] Data { get; }
8-
}
3+
public record struct DataAudio(
4+
Memory<byte> Data
5+
);
Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
namespace Duey.Abstractions.Types;
22

3-
public struct DataBitmap
4-
{
5-
public DataBitmap(ushort width, ushort height, byte[] data)
6-
{
7-
Width = width;
8-
Height = height;
9-
Data = data;
10-
}
11-
12-
public ushort Width { get; }
13-
public ushort Height { get; }
14-
public byte[] Data { get; }
15-
}
3+
public record struct DataBitmap(
4+
ushort Width,
5+
ushort Height,
6+
DataBitmapFormat Format,
7+
Memory<byte> Data
8+
);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Duey.Abstractions.Types;
2+
3+
public enum DataBitmapFormat
4+
{
5+
Rgba16,
6+
Rgba32,
7+
Bgra32,
8+
Unknown
9+
}
Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
namespace Duey.Abstractions.Types;
22

3-
public struct DataVector
4-
{
5-
public DataVector(int x, int y)
6-
{
7-
X = x;
8-
Y = y;
9-
}
10-
11-
public int X { get; }
12-
public int Y { get; }
13-
}
3+
public record struct DataVector(
4+
int X,
5+
int Y
6+
);
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
{
22
"version": 1,
33
"dependencies": {
4-
".NETStandard,Version=v2.1": {}
4+
".NETStandard,Version=v2.1": {
5+
"CommunityToolkit.HighPerformance": {
6+
"type": "Direct",
7+
"requested": "[8.4.0, )",
8+
"resolved": "8.4.0",
9+
"contentHash": "flxspiBs0G/0GMp7IK2J2ijV9bTG6hEwFc/z6ekHqB6nwRJ4Ry2yLdx+TkbCUYFCl4XhABkAwomeKbT6zM2Zlg==",
10+
"dependencies": {
11+
"System.Runtime.CompilerServices.Unsafe": "6.1.0"
12+
}
13+
},
14+
"System.Runtime.CompilerServices.Unsafe": {
15+
"type": "Transitive",
16+
"resolved": "6.1.0",
17+
"contentHash": "5o/HZxx6RVqYlhKSq8/zronDkALJZUT2Vz0hx43f0gwe8mwlM0y2nYlqdBwLMzr262Bwvpikeb/yEwkAa5PADg=="
18+
}
19+
}
520
}
621
}

src/Duey.Provider.NX/NXPackage.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Collections;
22
using System.IO.MemoryMappedFiles;
3-
using System.Runtime.InteropServices;
43
using Duey.Abstractions;
54
using Duey.Provider.NX.Exceptions;
65
using Duey.Provider.NX.Headers;

src/Duey.Provider.NX/Tables/NXBitmapOffsetTable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ public override DataBitmap Get(NXPropertyBitmapHeader data)
2929
Package.Accessor.ReadArray(offset + 4, source, 0, sourceLength);
3030
LZ4Codec.Decode(source, target);
3131

32-
return new DataBitmap(data.Width, data.Height, target);
32+
return new DataBitmap(data.Width, data.Height, DataBitmapFormat.Bgra32, target);
3333
}
3434
}

src/Duey.Provider.NX/packages.lock.json

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,24 @@
1111
"System.Runtime.CompilerServices.Unsafe": "6.0.0"
1212
}
1313
},
14+
"CommunityToolkit.HighPerformance": {
15+
"type": "Transitive",
16+
"resolved": "8.4.0",
17+
"contentHash": "flxspiBs0G/0GMp7IK2J2ijV9bTG6hEwFc/z6ekHqB6nwRJ4Ry2yLdx+TkbCUYFCl4XhABkAwomeKbT6zM2Zlg==",
18+
"dependencies": {
19+
"System.Runtime.CompilerServices.Unsafe": "6.1.0"
20+
}
21+
},
1422
"System.Runtime.CompilerServices.Unsafe": {
1523
"type": "Transitive",
16-
"resolved": "6.0.0",
17-
"contentHash": "/iUeP3tq1S0XdNNoMz5C9twLSrM/TH+qElHkXWaPvuNOt+99G75NrV0OS2EqHx5wMN7popYjpc8oTjC1y16DLg=="
24+
"resolved": "6.1.0",
25+
"contentHash": "5o/HZxx6RVqYlhKSq8/zronDkALJZUT2Vz0hx43f0gwe8mwlM0y2nYlqdBwLMzr262Bwvpikeb/yEwkAa5PADg=="
1826
},
1927
"duey.abstractions": {
20-
"type": "Project"
28+
"type": "Project",
29+
"dependencies": {
30+
"CommunityToolkit.HighPerformance": "[8.4.0, )"
31+
}
2132
}
2233
}
2334
}

src/Duey.Provider.WZ/FSDirectory.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System.Collections;
2-
using System.IO.MemoryMappedFiles;
31
using Duey.Abstractions;
42
using Duey.Provider.WZ.Crypto;
53
using Duey.Provider.WZ.Files;
@@ -8,21 +6,16 @@ namespace Duey.Provider.WZ;
86

97
public class FSDirectory : AbstractWZNode, IDataNodeCached, IDataDirectory
108
{
11-
private readonly string _path;
12-
private readonly XORCipher? _cipher;
13-
149
public FSDirectory(string path, XORCipher? cipher = null, IDataNode? parent = null)
1510
{
16-
_path = path;
17-
_cipher = cipher;
1811
Name = Path.GetFileName(path);
1912
Parent = parent ?? this;
2013
Cached = Directory
21-
.GetDirectories(_path)
22-
.Select(d => new FSDirectory(d, _cipher, this))
14+
.GetDirectories(path)
15+
.Select(d => new FSDirectory(d, cipher, this))
2316
.Concat<IDataNode>(Directory
24-
.GetFiles(_path, "*.img")
25-
.Select(f => new WZImage(f, _cipher, this)))
17+
.GetFiles(path, "*.img")
18+
.Select(f => new WZImage(f, cipher, this)))
2619
.ToDictionary(n => n.Name, n => n);
2720
}
2821

src/Duey.Provider.WZ/Files/Deferred/WZPropertyCanvas.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.IO.Compression;
12
using System.IO.MemoryMappedFiles;
23
using Duey.Abstractions;
34
using Duey.Abstractions.Types;
@@ -23,13 +24,28 @@ protected override DataBitmap Resolve(WZReader reader)
2324
{
2425
var width = reader.ReadCompressedInt();
2526
var height = reader.ReadCompressedInt();
26-
var format = reader.ReadCompressedInt();
27+
var format = reader.ReadCompressedInt() switch
28+
{
29+
0x002 => DataBitmapFormat.Rgba32,
30+
0x201 => DataBitmapFormat.Rgba16,
31+
_ => DataBitmapFormat.Unknown
32+
};
2733
var scale = reader.ReadByte();
2834

2935
reader.BaseStream.Position += 4;
3036

3137
var length = reader.ReadInt32();
38+
var header = reader.ReadBytes(3);
39+
var data = reader.ReadBytes(length - 3);
3240

33-
return new DataBitmap((ushort)width, (ushort)height, new byte[] {});
41+
using var stream0 = new MemoryStream(data, false);
42+
using var stream1 = new DeflateStream(stream0, CompressionMode.Decompress);
43+
using var stream2 = new MemoryStream();
44+
45+
width >>= scale;
46+
height >>= scale;
47+
stream1.CopyTo(stream2);
48+
49+
return new DataBitmap((ushort)width, (ushort)height, format, stream2.ToArray());
3450
}
3551
}

src/Duey.Provider.WZ/packages.lock.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,24 @@
22
"version": 1,
33
"dependencies": {
44
".NETStandard,Version=v2.1": {
5+
"CommunityToolkit.HighPerformance": {
6+
"type": "Transitive",
7+
"resolved": "8.4.0",
8+
"contentHash": "flxspiBs0G/0GMp7IK2J2ijV9bTG6hEwFc/z6ekHqB6nwRJ4Ry2yLdx+TkbCUYFCl4XhABkAwomeKbT6zM2Zlg==",
9+
"dependencies": {
10+
"System.Runtime.CompilerServices.Unsafe": "6.1.0"
11+
}
12+
},
13+
"System.Runtime.CompilerServices.Unsafe": {
14+
"type": "Transitive",
15+
"resolved": "6.1.0",
16+
"contentHash": "5o/HZxx6RVqYlhKSq8/zronDkALJZUT2Vz0hx43f0gwe8mwlM0y2nYlqdBwLMzr262Bwvpikeb/yEwkAa5PADg=="
17+
},
518
"duey.abstractions": {
6-
"type": "Project"
19+
"type": "Project",
20+
"dependencies": {
21+
"CommunityToolkit.HighPerformance": "[8.4.0, )"
22+
}
723
}
824
}
925
}

src/Testing/Program.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Duey.Abstractions;
2+
using Duey.Provider.NX;
3+
using Duey.Provider.WZ;
4+
5+
var pkg = new WZPackage("/Users/keith/Workspace/Shared/MapleStory/UI.wz", "95");
6+
var node = pkg.ResolveBitmap("Logo.img/Nexon/2");
7+
var bitmap = node!.Value;
8+
9+
Console.WriteLine(bitmap);
10+
11+
var nx = new NXPackage("/Users/keith/Workspace/Shared/MapleStory/UI.nx");
12+
var nn = nx.ResolveBitmap("Logo.img/Nexon/2");
13+
14+
Console.WriteLine(nn.Value);

src/Testing/Testing.csproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\Duey.Provider.NX\Duey.Provider.NX.csproj" />
12+
<ProjectReference Include="..\Duey.Provider.WZ\Duey.Provider.WZ.csproj" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.6" />
17+
</ItemGroup>
18+
19+
</Project>

0 commit comments

Comments
 (0)