Skip to content

Commit

Permalink
Merge branch 'gmd_rework'
Browse files Browse the repository at this point in the history
  • Loading branch information
Fusion86 committed Sep 13, 2018
2 parents 20d90f0 + 6c02e72 commit c6a05ef
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 223 deletions.
37 changes: 25 additions & 12 deletions Cirilla.Core.Test/Tests/GMDTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;
using Cirilla.Core.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand Down Expand Up @@ -27,7 +28,6 @@ public void Load__item_eng()
[TestMethod]
public void Load__armor_eng()
{
// StringCount > actual number of strings
GMD gmd = new GMD(Utility.GetFullPath(@"chunk0/common/text/steam/armor_eng.gmd"));
}

Expand All @@ -37,7 +37,7 @@ public void Load__action_trial_eng()
// Uses skipInvalidMessages
GMD gmd = new GMD(Utility.GetFullPath(@"chunk0/common/text/action_trial_eng.gmd"));

Assert.AreEqual(gmd.Strings[3], "©CAPCOM CO., LTD. ALL RIGHTS RESERVED.");
//Assert.AreEqual(gmd.Entries[3].Value, "©CAPCOM CO., LTD. ALL RIGHTS RESERVED.");
}

[TestMethod]
Expand All @@ -46,7 +46,19 @@ public void Load__action_trial_ara()
// Uses skipInvalidMessages and weird workaround (see Models/GMD.cs)
GMD gmd = new GMD(Utility.GetFullPath(@"chunk0/common/text/action_trial_ara.gmd"));

Assert.AreEqual(gmd.Strings[3], "©CAPCOM CO., LTD. ALL RIGHTS RESERVED.");
//Assert.AreEqual(gmd.Entries[3].Value, "©CAPCOM CO., LTD. ALL RIGHTS RESERVED.");
}

[TestMethod]
public void Load__cm_facility_eng()
{
GMD gmd = new GMD(Utility.GetFullPath(@"chunk0/common/text/cm_facility_eng.gmd"));
}

[TestMethod]
public void Load__cm_facility_kor()
{
GMD gmd = new GMD(Utility.GetFullPath(@"chunk0/common/text/cm_facility_kor.gmd"));
}

[TestMethod]
Expand All @@ -66,7 +78,7 @@ public void Rebuild__em_names_eng()
public void Rebuild__q00503_eng()
{
string origPath = Utility.GetFullPath(@"chunk0/common/text/quest/q00503_eng.gmd");
string rebuildPath = "rebuild__q00503_eng";
string rebuildPath = "rebuild__q00503_eng.gmd";

GMD gmd = new GMD(origPath);
gmd.Save(rebuildPath);
Expand Down Expand Up @@ -98,8 +110,8 @@ public void Rebuild__action_trial_eng()
GMD gmd = new GMD(origPath);
gmd.Save(rebuildPath);

//if (!Utility.CheckFilesAreSame(origPath, rebuildPath))
// Assert.Fail("Hash doesn't match!");
if (!Utility.CheckFilesAreSame(origPath, rebuildPath))
Assert.Fail("Hash doesn't match!");
}

[TestMethod]
Expand All @@ -111,8 +123,8 @@ public void Rebuild__wep_series_eng()
GMD gmd = new GMD(origPath);
gmd.Save(rebuildPath);

//if (!Utility.CheckFilesAreSame(origPath, rebuildPath))
// Assert.Fail("Hash doesn't match!");
if (!Utility.CheckFilesAreSame(origPath, rebuildPath))
Assert.Fail("Hash doesn't match!");
}

[TestMethod]
Expand Down Expand Up @@ -144,24 +156,25 @@ public void AddString__q00503_eng()
Assert.IsTrue(oldGmd.Header.KeyBlockSize < newGmd.Header.KeyBlockSize);
Assert.IsTrue(oldGmd.Header.StringCount < newGmd.Header.StringCount);
Assert.IsTrue(oldGmd.Header.StringBlockSize < newGmd.Header.StringBlockSize);
Assert.IsTrue(newGmd.Strings.Contains("New string text...."));
Assert.IsNotNull(newGmd.Entries.FirstOrDefault(x => x.Value == "New string text...."));
}

[TestMethod]
public void RemoveString__w_sword_eng()
public void ReaddString__w_sword_eng()
{
// This won't display correctly in game, because the string order DOES matter

string origPath = Utility.GetFullPath(@"chunk0/common/text/steam/w_sword_eng.gmd");
string newPath = "removestring__w_sword_eng.gmd";
string readdPath = "readdstring__w_sword_eng.gmd";

GMD gmd = new GMD(origPath);
int idx = gmd.Keys.IndexOf("WP_WSWD_044_NAME");
gmd.RemoveString("WP_WSWD_044_NAME");
gmd.Save(newPath);

GMD newGmd = new GMD(newPath);

newGmd.AddString("WP_WSWD_044_NAME", "My new string", idx);
newGmd.AddString("WP_WSWD_044_NAME", "My new string");
newGmd.Save(readdPath);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Cirilla.Core/Cirilla.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>0.0.4.1</Version>
<Version>0.0.5</Version>
<Authors>Fusion86</Authors>
<Company />
</PropertyGroup>
Expand Down
6 changes: 2 additions & 4 deletions Cirilla.Core/Enums/EmLanguage.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;

namespace Cirilla.Core.Enums
namespace Cirilla.Core.Enums
{
public enum EmLanguage : UInt32
public enum EmLanguage : int
{
Japanese = 0,
English = 1,
Expand Down
19 changes: 4 additions & 15 deletions Cirilla.Core/Extensions/BinaryReaderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ public static T ReadStruct<T>(this BinaryReader br)
}

/// <summary>
/// Read zero terminated string (skips zeros in front of it)
/// Read zero terminated string (skips zeros in front of it).
/// Leaves BaseStream.Position += stringLength + 1 (for szString terminator)
/// </summary>
/// <param name="br"></param>
/// <param name="encoding"></param>
/// <returns></returns>
public static string ReadStringZero(this BinaryReader br, Encoding encoding)
{
byte b;
int skippedZeros = 0;
List<byte> szBytes = new List<byte>();

while (br.BaseStream.Position != br.BaseStream.Length)
Expand All @@ -42,26 +42,15 @@ public static string ReadStringZero(this BinaryReader br, Encoding encoding)

if (b == 0)
{
// Stop if we found a \0 **AND** we already have read some text.
// This is because a string could have empty space in front of it.
// While this is 'undocumented behaviour' it works in-game.
if (szBytes.Count > 0)
break;
else
skippedZeros++;
break;
}
else
{
szBytes.Add(b);
}
}

string str = encoding.GetString(szBytes.ToArray());

if (skippedZeros != 0)
Logger.Warn($"Skipped {skippedZeros} zeros in front of string '{str}'");

return str;
return encoding.GetString(szBytes.ToArray());
}
}
}
Loading

0 comments on commit c6a05ef

Please sign in to comment.