Skip to content

Commit 7f6275a

Browse files
authored
Merge pull request #3 from Sichii/master
mpf saving / improvements
2 parents d599aac + 68c16bf commit 7f6275a

22 files changed

+376
-151
lines changed

.github/workflows/dalib-build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
jobs:
1010
build:
11+
if: github.repository == 'eriscorp/dalib'
1112
runs-on: ubuntu-latest
1213
environment: deploy
1314
strategy:
@@ -28,5 +29,4 @@ jobs:
2829
- name: Install dependencies
2930
run: dotnet restore
3031
- name: Build
31-
run: dotnet build --configuration Release --no-restore
32-
k
32+
run: dotnet build --configuration Release --no-restore

DALib/DALib.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
<ItemGroup>
3131
<PackageReference Include="KGySoft.Drawing.SkiaSharp" Version="7.2.0"/>
3232
<PackageReference Include="SkiaSharp" Version="2.88.6"/>
33-
<PackageReference Include="zlib.net" Version="1.0.4"/>
3433
</ItemGroup>
3534
<ItemGroup>
3635
<SupportedPlatform Include="Linux"/>

DALib/Data/DataArchive.cs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public sealed class DataArchive() : KeyedCollection<string, DataArchiveEntry>(St
1515
private bool IsDisposed;
1616
internal Stream? DataStream { get; set; }
1717

18-
private DataArchive(Stream stream)
18+
private DataArchive(Stream stream, bool newFormat = false)
1919
: this()
2020
{
2121
DataStream = stream;
@@ -28,26 +28,30 @@ private DataArchive(Stream stream)
2828
{
2929
var startAddress = reader.ReadInt32();
3030

31-
var nameBytes = new byte[CONSTANTS.DATA_ARCHIVE_ENTRY_NAME_LENGTH];
32-
_ = reader.Read(nameBytes, 0, CONSTANTS.DATA_ARCHIVE_ENTRY_NAME_LENGTH);
31+
var nameLength = newFormat ? 12 : CONSTANTS.DATA_ARCHIVE_ENTRY_NAME_LENGTH;
32+
33+
var nameBytes = new byte[nameLength];
34+
_ = reader.Read(nameBytes, 0, nameLength);
3335

3436
var name = Encoding.ASCII.GetString(nameBytes);
3537
var nullChar = name.IndexOf('\0');
3638

3739
if (nullChar > -1)
3840
name = name[..nullChar];
3941

42+
if (newFormat)
43+
_ = reader.ReadBytes(20); //idk
44+
4045
var endAddress = reader.ReadInt32();
4146

4247
stream.Seek(-4, SeekOrigin.Current);
4348

44-
var entry = new DataArchiveEntry(
45-
this,
46-
name,
47-
startAddress,
48-
endAddress - startAddress);
49-
50-
Add(entry);
49+
Add(
50+
new DataArchiveEntry(
51+
this,
52+
name,
53+
startAddress,
54+
endAddress - startAddress));
5155
}
5256
}
5357

@@ -237,7 +241,7 @@ public static DataArchive FromDirectory(string dir)
237241
return archive;
238242
}
239243

240-
public static DataArchive FromFile(string path, bool cacheArchive = false)
244+
public static DataArchive FromFile(string path, bool cacheArchive = false, bool newformat = false)
241245
{
242246
//if we don't want to cache the archive
243247
//return an archive that reads using pointers from an open file handle
@@ -252,7 +256,8 @@ public static DataArchive FromFile(string path, bool cacheArchive = false)
252256
Options = FileOptions.RandomAccess,
253257
Share = FileShare.ReadWrite,
254258
BufferSize = 8192
255-
}));
259+
}),
260+
newformat);
256261

257262
//if we do want to cache the archive
258263
//copy the whole file into a memorystream and use that
@@ -273,7 +278,7 @@ public static DataArchive FromFile(string path, bool cacheArchive = false)
273278

274279
memory.Seek(0, SeekOrigin.Begin);
275280

276-
return new DataArchive(memory);
281+
return new DataArchive(memory, newformat);
277282
}
278283
#endregion
279284

DALib/Data/MetaFile.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ namespace DALib.Data;
1111

1212
public sealed class MetaFile : Collection<MetaFileEntry>, ISavable
1313
{
14-
public MetaFile(Stream stream, bool leaveOpen = false)
14+
public MetaFile() { }
15+
16+
private MetaFile(Stream stream)
1517
{
1618
var encoding = CodePagesEncodingProvider.Instance.GetEncoding(949)!;
17-
using var reader = new BinaryReader(stream, encoding, leaveOpen);
19+
using var reader = new BinaryReader(stream, encoding, true);
1820

1921
var entryCount = reader.ReadUInt16(true);
2022

DALib/Data/MetaFileEntry.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
using System.Collections.Generic;
2+
using System.Linq;
23

34
namespace DALib.Data;
45

5-
public sealed class MetaFileEntry
6+
public sealed class MetaFileEntry(string key, IEnumerable<string>? properties = null)
67
{
7-
public string Key { get; }
8-
public List<string> Properties { get; }
9-
10-
internal MetaFileEntry(string key, IEnumerable<string> properties)
11-
{
12-
Key = key;
13-
Properties = new List<string>(properties);
14-
}
8+
public string Key { get; } = key;
9+
public List<string> Properties { get; } = properties?.ToList() ?? new List<string>();
1510
}

DALib/Definitions/Enums.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,16 @@ public enum EfaBlendingType : byte
3939
/// like 3 effects. Other effects that try to use this option will not render at all.
4040
/// </summary>
4141
NotSure = 3
42+
}
43+
44+
public enum MpfHeaderType
45+
{
46+
Unknown = -1,
47+
None = 0
48+
}
49+
50+
public enum MpfFormatType
51+
{
52+
MultipleAttacks = -1,
53+
SingleAttack = 0
4254
}

DALib/Drawing/ColorTableEntry.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ namespace DALib.Drawing;
44

55
public sealed class ColorTableEntry
66
{
7-
public byte ColorIndex { get; init; }
8-
public required SKColor[] Colors { get; init; }
7+
public byte ColorIndex { get; set; }
8+
public required SKColor[] Colors { get; set; }
99
}

DALib/Drawing/EfaFile.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ public sealed class EfaFile : Collection<EfaFrame>, ISavable
1919
{
2020
public EfaBlendingType BlendingType { get; set; }
2121
public int FrameIntervalMs { get; set; }
22+
public int Unknown1 { get; set; }
2223
public byte[] Unknown2 { get; set; }
23-
public int Unknown1 { get; }
2424

25-
private EfaFile()
25+
public EfaFile()
2626
{
2727
Unknown1 = 0;
2828
BlendingType = EfaBlendingType.Luminance;
29-
FrameIntervalMs = 10000;
29+
FrameIntervalMs = 50;
3030
Unknown2 = new byte[51];
3131
}
3232

@@ -135,8 +135,9 @@ public static EfaFile FromFile(string path)
135135
public static EfaFile FromImages(params SKImage[] orderedFrames)
136136
{
137137
var efaFile = new EfaFile();
138-
var imageWidth = orderedFrames.Select(img => img.Width).Max();
139-
var imageHeight = orderedFrames.Select(img => img.Height).Max();
138+
139+
var imageWidth = orderedFrames.Max(img => img.Width);
140+
var imageHeight = orderedFrames.Max(img => img.Height);
140141

141142
for (var i = 0; i < orderedFrames.Length; i++)
142143
{
@@ -157,7 +158,8 @@ public static EfaFile FromImages(params SKImage[] orderedFrames)
157158
writer.WriteRgb565Color(color);
158159
}
159160

160-
rawBytes = writer.ToSpan().ToArray();
161+
rawBytes = writer.ToSpan()
162+
.ToArray();
161163
}
162164

163165
efaFile.Add(
@@ -198,7 +200,8 @@ private static void DecompressToFrame(Stream dataStream, EfaFrame frame)
198200

199201
decompressor.ReadAtLeast(decompressed, frame.RawSize);
200202

201-
decompressed[..frame.ByteCount].CopyTo(frame.Data);
203+
decompressed[..frame.ByteCount]
204+
.CopyTo(frame.Data);
202205

203206
/*
204207
//Not sure what these numbers are

DALib/Drawing/EfaFrame.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22

33
public sealed class EfaFrame
44
{
5-
public int ByteCount { get; init; }
6-
public int ByteWidth { get; init; }
7-
public required byte[] Data { get; init; }
8-
public short FrameHeight { get; init; }
9-
public short FrameWidth { get; init; }
10-
public short ImageHeight { get; init; }
11-
public short ImageWidth { get; init; }
5+
public int ByteCount { get; set; }
6+
public int ByteWidth { get; set; }
7+
public required byte[] Data { get; set; }
8+
public short FrameHeight { get; set; }
9+
public short FrameWidth { get; set; }
10+
public short ImageHeight { get; set; }
11+
public short ImageWidth { get; set; }
1212
public int Offset { get; set; }
13-
public int OriginFlags { get; init; }
13+
public int OriginFlags { get; set; }
1414
public short OriginX { get; set; }
1515
public short OriginY { get; set; }
16-
public int Pad1Flags { get; init; }
17-
public int Pad2Flags { get; init; }
18-
public int RawSize { get; init; }
16+
public int Pad1Flags { get; set; }
17+
public int Pad2Flags { get; set; }
18+
public int RawSize { get; set; }
1919
public int Size { get; set; }
20-
public int Unknown1 { get; init; }
21-
public int Unknown2 { get; init; }
22-
public int Unknown3 { get; init; }
23-
public int Unknown4 { get; init; }
24-
public int Unknown5 { get; init; }
20+
public int Unknown1 { get; set; }
21+
public int Unknown2 { get; set; }
22+
public int Unknown3 { get; set; }
23+
public int Unknown4 { get; set; }
24+
public int Unknown5 { get; set; }
2525
}

DALib/Drawing/EpfFile.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ namespace DALib.Drawing;
1414

1515
public sealed class EpfFile : Collection<EpfFrame>, ISavable
1616
{
17-
public short Height { get; }
18-
public byte[] UnknownBytes { get; }
19-
public short Width { get; }
17+
public short Height { get; set; }
18+
public byte[] UnknownBytes { get; set; }
19+
public short Width { get; set; }
2020

21-
private EpfFile(short width, short height)
21+
public EpfFile(short width, short height)
2222
{
2323
Height = height;
2424
Width = width;

0 commit comments

Comments
 (0)