Skip to content

Commit

Permalink
Just a tiny fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jianmingyong committed Aug 14, 2023
1 parent 6e6abc4 commit 9a24750
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
26 changes: 15 additions & 11 deletions TheDialgaTeam.FossilFighters.Assets/Header/DmgHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,25 @@

namespace TheDialgaTeam.FossilFighters.Assets.Header;

[JsonSerializable(typeof(DmgHeader))]
public readonly record struct DmgTextInfo(int TextId, string Text);

[JsonSerializable(typeof(DmgHeader), GenerationMode = JsonSourceGenerationMode.Serialization)]
public sealed partial class DmgHeaderContext : JsonSerializerContext
{
}

public readonly record struct DmgTextInfo(int TextId, string Text);

[PublicAPI]
public sealed class DmgHeader
{
public const int FileHeader = 0x00474D44;

public DmgTextInfo[] Texts { get; init; }

public DmgHeader(DmgTextInfo[] texts)
{
Texts = texts;
}

public static DmgHeader GetHeaderFromStream(Stream stream)
{
using var reader = new BinaryReader(stream, Encoding.UTF8, true);
Expand All @@ -42,7 +47,7 @@ public static DmgHeader GetHeaderFromStream(Stream stream)

var textCount = reader.ReadUInt32();
var texts = new DmgTextInfo[textCount];

stream.Seek(reader.ReadUInt32(), SeekOrigin.Begin);

var textOffsets = new uint[textCount];
Expand All @@ -51,26 +56,25 @@ public static DmgHeader GetHeaderFromStream(Stream stream)
{
textOffsets[i] = reader.ReadUInt32();
}

for (var i = 0; i < textCount; i++)
{
stream.Seek(textOffsets[i], SeekOrigin.Begin);

var textBuilder = new StringBuilder();
int id1, id2 = 0;
char nextChar;

id1 = reader.ReadInt32();
id2 = reader.ReadInt32();
var id = reader.ReadInt32();
_ = reader.ReadInt32();

while ((nextChar = reader.ReadChar()) != '\0')
{
textBuilder.Append(nextChar);
}

texts[i] = new DmgTextInfo(id1, textBuilder.ToString());
texts[i] = new DmgTextInfo(id, textBuilder.ToString());
}

return new DmgHeader { Texts = texts };
return new DmgHeader(texts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<Nullable>enable</Nullable>

<PublishSingleFile>true</PublishSingleFile>
<PublishRelease>true</PublishRelease>
<PublishTrimmed>true</PublishTrimmed>

<Version>1.7.0</Version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>

<PublishSingleFile>true</PublishSingleFile>
<PublishRelease>true</PublishRelease>
<PublishTrimmed>false</PublishTrimmed>

<Version>2.0.0</Version>
Expand Down

0 comments on commit 9a24750

Please sign in to comment.