Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ItemDefinition): RecLuq to uint32 on Ep6_4 #58

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/Parsec/Common/Episode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

public enum Episode
{
Unknown,
EP4,
EP5,
EP6,
EP7,
EP8
Unknown = 0,

EP4 = 40,

EP5 = 50,

EP6 = 60,

EP6_4 = 64,

EP7 = 70,

EP8 = 80
}
5 changes: 5 additions & 0 deletions src/Parsec/Shaiya/Item/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
/// <returns><see cref="Item"/> instance</returns>
public static Item FromCsv(string csvPath, Episode episode, Encoding? encoding = null)
{
if (episode >= Episode.EP8)
{
throw new Exception("Item format is not supported for EP8 and above, use ItemData instead.");

Check warning on line 35 in src/Parsec/Shaiya/Item/Item.cs

View check run for this annotation

Codecov / codecov/patch

src/Parsec/Shaiya/Item/Item.cs#L35

Added line #L35 was not covered by tests
}

encoding ??= Encoding.ASCII;

// Read item definitions from csv
Expand Down
29 changes: 16 additions & 13 deletions src/Parsec/Shaiya/Item/ItemDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,10 @@ public sealed class ItemDefinition : ISerializable

public ushort ReqWis { get; set; }

public ushort ReqLuc { get; set; }
public uint ReqLuc { get; set; }

public ushort ReqVg { get; set; }

public ushort Unknown { get; set; }

public byte ReqOg { get; set; }

public byte ReqIg { get; set; }
Expand Down Expand Up @@ -185,18 +183,20 @@ public void Read(SBinaryReader binaryReader)
ReqRec = binaryReader.ReadUInt16();
ReqInt = binaryReader.ReadUInt16();
ReqWis = binaryReader.ReadUInt16();
ReqLuc = binaryReader.ReadUInt16();
ReqVg = binaryReader.ReadUInt16();

if (episode >= Episode.EP6)
if (episode >= Episode.EP6_4)
{
ReqLuc = binaryReader.ReadUInt32();
}
else
{
Unknown = binaryReader.ReadUInt16();
ReqLuc = binaryReader.ReadUInt16();
}

ReqVg = binaryReader.ReadUInt16();
ReqOg = binaryReader.ReadByte();
ReqIg = binaryReader.ReadByte();


if (episode <= Episode.EP5)
{
Range = binaryReader.ReadByte();
Expand Down Expand Up @@ -286,20 +286,23 @@ public void Write(SBinaryWriter binaryWriter)
binaryWriter.Write(ReqRec);
binaryWriter.Write(ReqInt);
binaryWriter.Write(ReqWis);
binaryWriter.Write(ReqLuc);
binaryWriter.Write(ReqVg);

if (episode >= Episode.EP6)
if (episode >= Episode.EP6_4)
{
binaryWriter.Write(Unknown);
binaryWriter.Write(ReqLuc);
}
else
{
binaryWriter.Write((ushort)ReqLuc);
}

binaryWriter.Write(ReqVg);
binaryWriter.Write(ReqOg);
binaryWriter.Write(ReqIg);

if (episode <= Episode.EP5)
{
binaryWriter.Write(Range);
binaryWriter.Write((byte)Range);
}
else
{
Expand Down
20 changes: 13 additions & 7 deletions tests/Parsec.Tests/Parsec.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

<IsPackable>false</IsPackable>

<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0"/>
<PackageReference Include="System.Text.Encoding.CodePages" Version="8.0.0"/>
<PackageReference Include="xunit" Version="2.6.6"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.0.2">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down Expand Up @@ -710,7 +710,7 @@
<None Update="Shaiya\Monster\Monster_1252.SData">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Shaiya\Item\ItemEp6_1251.SData">
<None Update="Shaiya\Item\ItemEp64_1251.SData">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Shaiya\TransformModel\DBTransformModelData.SData">
Expand Down Expand Up @@ -815,5 +815,11 @@
<None Update="Shaiya\Dg\R2_Dun1.dg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Shaiya\Item\Item_ES_ps0224.SData">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Shaiya\Item\Item_US_ps0216.SData">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
36 changes: 24 additions & 12 deletions tests/Parsec.Tests/Shaiya/Item/ItemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,40 @@ public void ItemEp5CsvTest()
}

[Fact]
public void ItemEp6CsvTest()
public void ItemEp5ReadWriteTest()
{
const string filePath = "Shaiya/Item/ItemEp6.SData";
const string csvPath = "Shaiya/Item/ItemEp6.SData.csv";
const string filePath = "Shaiya/Item/ItemEp5.SData";
const string outputPath = "Shaiya/Item/ItemEp5.written.SData";

var item = ParsecReader.FromFile<Parsec.Shaiya.Item.Item>(filePath, Episode.EP5, TestEncodings.Encoding1252);
item.WriteEncrypted(outputPath);

Assert.Equal(FileHash.Checksum(filePath), FileHash.Checksum(outputPath));
}

[Fact]
public void ItemEp64CsvTest()
{
const string filePath = "Shaiya/Item/Item_ES_ps0224.SData";
const string csvPath = "Shaiya/Item/Item_ES_ps0224.SData.csv";

var item = ParsecReader.FromFile<Parsec.Shaiya.Item.Item>(filePath, Episode.EP6);
var item = ParsecReader.FromFile<Parsec.Shaiya.Item.Item>(filePath, Episode.EP6_4, TestEncodings.Encoding1252);
item.WriteCsv(csvPath);
var itemFromCsv = Parsec.Shaiya.Item.Item.FromCsv(csvPath, Episode.EP6);
Assert.Equal(item.GetBytes(Episode.EP6), itemFromCsv.GetBytes(Episode.EP6));
var itemFromCsv = Parsec.Shaiya.Item.Item.FromCsv(csvPath, Episode.EP6_4, TestEncodings.Encoding1252);
Assert.Equal(item.GetBytes(Episode.EP6_4, TestEncodings.Encoding1252), itemFromCsv.GetBytes(Episode.EP6_4, TestEncodings.Encoding1252));
}

[Fact]
public void ItemEp6Csv_EncodingTest()
public void ItemEp64Csv_EncodingTest()
{
const string filePath = "Shaiya/Item/ItemEp6_1251.SData";
const string csvPath = "Shaiya/Item/ItemEp6_1252.SData.csv";
const string filePath = "Shaiya/Item/ItemEp64_1251.SData";
const string csvPath = "Shaiya/Item/ItemEp64_1251.SData.csv";

var encoding = TestEncodings.Encoding1251;
var item = ParsecReader.FromFile<Parsec.Shaiya.Item.Item>(filePath, Episode.EP6, encoding);
var item = ParsecReader.FromFile<Parsec.Shaiya.Item.Item>(filePath, Episode.EP6_4, encoding);
item.WriteCsv(csvPath, encoding);
var itemFromCsv = Parsec.Shaiya.Item.Item.FromCsv(csvPath, Episode.EP6, encoding);
Assert.Equal(item.GetBytes(Episode.EP6), itemFromCsv.GetBytes(Episode.EP6));
var itemFromCsv = Parsec.Shaiya.Item.Item.FromCsv(csvPath, Episode.EP6_4, encoding);
Assert.Equal(item.GetBytes(Episode.EP6_4), itemFromCsv.GetBytes(Episode.EP6_4));
}

[Fact]
Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/Parsec.Tests/Shaiya/SData/SDataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void SDataDecryptionTest()
const string encryptedOutputPath = "Shaiya/SData/ItemEp6.encrypted.SData";
const string decryptedOutputPath = "Shaiya/SData/ItemEp6.decrypted.SData";

var item = ParsecReader.FromFile<Parsec.Shaiya.Item.Item>(EncryptedSDataFilePath, Episode.EP6);
var item = ParsecReader.FromFile<Parsec.Shaiya.Item.Item>(EncryptedSDataFilePath, Episode.EP6_4);
item.WriteEncrypted(encryptedOutputPath);
item.WriteDecrypted(decryptedOutputPath);

Expand Down
Loading