Skip to content

Commit 83c7302

Browse files
committed
Add loading of bitmap width and height
1 parent 90dd6a4 commit 83c7302

File tree

3 files changed

+82
-5
lines changed

3 files changed

+82
-5
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.IO.MemoryMappedFiles;
2+
using Duey.Abstractions;
3+
using Duey.Abstractions.Types;
4+
using Duey.Provider.WZ.Codecs;
5+
using Duey.Provider.WZ.Crypto;
6+
7+
namespace Duey.Provider.WZ.Files.Deferred;
8+
9+
public class WZPropertyCanvas : WZPropertyDeferred<DataBitmap>
10+
{
11+
public WZPropertyCanvas(
12+
MemoryMappedFile view,
13+
XORCipher cipher,
14+
int start,
15+
int offset,
16+
string name,
17+
IDataNode? parent = null
18+
) : base(view, cipher, start, offset, name, parent)
19+
{
20+
}
21+
22+
protected override DataBitmap Resolve(WZReader reader)
23+
{
24+
var width = reader.ReadCompressedInt();
25+
var height = reader.ReadCompressedInt();
26+
var format = reader.ReadCompressedInt();
27+
var scale = reader.ReadByte();
28+
29+
reader.BaseStream.Position += 4;
30+
31+
var length = reader.ReadInt32();
32+
33+
return new DataBitmap((ushort)width, (ushort)height, new byte[] {});
34+
}
35+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.IO.MemoryMappedFiles;
2+
using Duey.Abstractions;
3+
using Duey.Provider.WZ.Codecs;
4+
using Duey.Provider.WZ.Crypto;
5+
6+
namespace Duey.Provider.WZ.Files;
7+
8+
public abstract class WZPropertyDeferred<T> : WZPropertyFile, IDataProperty<T>
9+
{
10+
public WZPropertyDeferred(
11+
MemoryMappedFile view,
12+
XORCipher cipher,
13+
int start,
14+
int offset,
15+
string name,
16+
IDataNode? parent = null
17+
) : base(view, cipher, start, offset, name, parent)
18+
{
19+
}
20+
21+
public T Resolve()
22+
{
23+
do _ = Children.ToList();
24+
while (!_startDeferred.HasValue);
25+
26+
using var stream = _view.CreateViewStream(_offset, 0, MemoryMappedFileAccess.Read);
27+
using var reader = new WZReader(stream, _cipher, _startDeferred.Value);
28+
29+
return Resolve(reader);
30+
}
31+
32+
protected abstract T Resolve(WZReader reader);
33+
}

src/Duey.Provider.WZ/Files/WZPropertyFile.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
using Duey.Abstractions.Types;
44
using Duey.Provider.WZ.Codecs;
55
using Duey.Provider.WZ.Crypto;
6+
using Duey.Provider.WZ.Files.Deferred;
67
using Duey.Provider.WZ.Types;
78

89
namespace Duey.Provider.WZ.Files;
910

1011
public class WZPropertyFile : AbstractWZNode, IDataNode
1112
{
12-
private readonly MemoryMappedFile _view;
13-
private readonly XORCipher _cipher;
14-
private readonly int _start;
15-
private readonly int _offset;
13+
protected readonly MemoryMappedFile _view;
14+
protected readonly XORCipher _cipher;
15+
protected readonly int _start;
16+
protected readonly int _offset;
17+
18+
protected int? _startDeferred;
1619

1720
public WZPropertyFile(MemoryMappedFile view, XORCipher cipher, int start, int offset, string name, IDataNode? parent = null)
1821
{
@@ -35,7 +38,8 @@ public override IEnumerable<IDataNode> Children
3538
using var reader = new WZReader(stream, _cipher, _start);
3639

3740
reader.ReadBoolean();
38-
reader.ReadByte();
41+
if (reader.ReadBoolean())
42+
reader.BaseStream.Position += 2;
3943

4044
var count = reader.ReadCompressedInt();
4145

@@ -92,6 +96,9 @@ public override IEnumerable<IDataNode> Children
9296
case "Property":
9397
yield return new WZPropertyFile(_view, _cipher, (int)reader.BaseStream.Position, _offset, name, this);
9498
break;
99+
case "Canvas":
100+
yield return new WZPropertyCanvas(_view, _cipher, (int)reader.BaseStream.Position, _offset, name, this);
101+
break;
95102
case "Shape2D#Vector2D":
96103
yield return new WZPropertyData<DataVector>(name, this, new DataVector(
97104
reader.ReadCompressedInt(),
@@ -107,6 +114,8 @@ public override IEnumerable<IDataNode> Children
107114
throw new ArgumentOutOfRangeException();
108115
}
109116
}
117+
118+
_startDeferred = (int)reader.BaseStream.Position;
110119
}
111120
}
112121
}

0 commit comments

Comments
 (0)