Skip to content

Commit

Permalink
fixes:
Browse files Browse the repository at this point in the history
- fixed mangling with the time on save
added:
- seen enemies editing
refactorings:
- renamed variables
- added more typehints
- using .count instead of the dedicated count variable
  • Loading branch information
tolik518 committed Feb 21, 2024
1 parent e4c20e2 commit 46e34f6
Show file tree
Hide file tree
Showing 13 changed files with 396 additions and 266 deletions.
2 changes: 1 addition & 1 deletion SoG_SGreader.Test/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void TestTextOutput()

Assert.Contains("Filesize: 4494", output);
Assert.Contains("Birthday: 24.6.1081", output);
Assert.Contains("ItemsMetCount: 124", output);
Assert.Contains("ItemsSeenCount: 124", output);
Assert.Contains("KilledEnemiesCount: 58", output);
}

Expand Down
82 changes: 41 additions & 41 deletions SoG_SGreader/DataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,6 @@ public static Player ReadFromFile(string fileName, ITextBoxWrapper txtConsole)
playerObject.PetHidden = readBinary.ReadByte();


// | //
// | //
// new stuff //
// we're not editing //
// yet //

playerObject.QuestsCount = readBinary.ReadUInt16();
txtConsole.AppendText("\r\n" + "> QuestsCount Position: " + readBinary.BaseStream.Position.ToString("X"));

Expand All @@ -243,18 +237,24 @@ public static Player ReadFromFile(string fileName, ITextBoxWrapper txtConsole)
}
txtConsole.AppendText("\r\n" + "QuestsCount: " + playerObject.QuestsCount);

txtConsole.AppendText("\r\n" + "> EnemiesMetCount Position: " + readBinary.BaseStream.Position.ToString("X"));
playerObject.EnemiesMetCount = readBinary.ReadUInt16();
playerObject.Enemies = new List<Enemy>(playerObject.EnemiesMetCount);
for (int i = 0; i != playerObject.EnemiesMetCount; i++)
txtConsole.AppendText("\r\n" + "> EnemiesSeenCount Position: " + readBinary.BaseStream.Position.ToString("X"));
playerObject.EnemiesSeenCount = readBinary.ReadUInt16();
playerObject.EnemiesSeen = new List<Enemy>(playerObject.EnemiesSeenCount);
for (int i = 0; i != playerObject.EnemiesSeenCount; i++)
{
playerObject.Enemies.Add(new Enemy
playerObject.EnemiesSeen.Add(new Enemy
{
EnemyID = readBinary.ReadInt32()
EnemyID = (SogEnemy) readBinary.ReadInt32()
});
}
txtConsole.AppendText("\r\n" + "EnemiesMetCount: " + playerObject.EnemiesMetCount);
txtConsole.AppendText("\r\n" + "> EnemiesMetCount Position: " + readBinary.BaseStream.Position.ToString("X"));
txtConsole.AppendText("\r\n" + "EnemiesSeenCount: " + playerObject.EnemiesSeenCount);
txtConsole.AppendText("\r\n" + "> EnemiesSeenCount Position: " + readBinary.BaseStream.Position.ToString("X"));

// | //
// | //
// new stuff //
// we're not editing //
// yet //

playerObject.UnknownVariable02Count = (UInt16)(readBinary.ReadUInt16() * 16); // there are X sequences, each 10 bytes long
txtConsole.AppendText("\r\n" + "UnknownVariable02Count: " + playerObject.UnknownVariable02Count);
Expand All @@ -275,26 +275,26 @@ public static Player ReadFromFile(string fileName, ITextBoxWrapper txtConsole)
txtConsole.AppendText("\r\n" + "RobinBowHighscore: " + playerObject.RobinBowHighscore);
txtConsole.AppendText("\r\n" + "> RobinBowHighscore Position: " + readBinary.BaseStream.Position.ToString("X"));

playerObject.UnknownVariable03Count = (UInt16)(readBinary.ReadUInt16());
playerObject.UnknownVariables03 = new List<UnknownVariable03>(playerObject.UnknownVariable03Count);
for (int i = 0; i != playerObject.UnknownVariable03Count; i++)
playerObject.TrophiesCount = (UInt16)(readBinary.ReadUInt16());
playerObject.Trophies = new List<Trophy>(playerObject.TrophiesCount);
for (int i = 0; i != playerObject.TrophiesCount; i++)
{
playerObject.UnknownVariables03.Add(new UnknownVariable03
playerObject.Trophies.Add(new Trophy
{
UnknownVariable = readBinary.ReadUInt16()
TrophyID = readBinary.ReadUInt16()
});
}
txtConsole.AppendText("\r\n" + "UnknownVariable03Count: " + playerObject.UnknownVariable03Count);
txtConsole.AppendText("\r\n" + "> UnknownVariable03Count Position: " + readBinary.BaseStream.Position.ToString("X"));
txtConsole.AppendText("\r\n" + "TrophiesCount: " + playerObject.TrophiesCount);
txtConsole.AppendText("\r\n" + "> TrophiesCount Position: " + readBinary.BaseStream.Position.ToString("X"));

playerObject.ItemsMetCount = (UInt16)(readBinary.ReadUInt16());
txtConsole.AppendText("\r\n" + "ItemsMetCount: " + playerObject.ItemsMetCount);
txtConsole.AppendText("\r\n" + "> ItemsMetCount Position: " + readBinary.BaseStream.Position.ToString("X"));
playerObject.ItemsSeenCount = (UInt16)(readBinary.ReadUInt16());
txtConsole.AppendText("\r\n" + "ItemsSeenCount: " + playerObject.ItemsSeenCount);
txtConsole.AppendText("\r\n" + "> ItemsSeenCount Position: " + readBinary.BaseStream.Position.ToString("X"));

playerObject.ItemsMet = new List<ItemsSeen>(playerObject.ItemsMetCount);
for (int i = 0; i != playerObject.ItemsMetCount; i++)
playerObject.ItemsSeen = new List<ItemsSeen>(playerObject.ItemsSeenCount);
for (int i = 0; i != playerObject.ItemsSeenCount; i++)
{
playerObject.ItemsMet.Add(new ItemsSeen
playerObject.ItemsSeen.Add(new ItemsSeen
{
ItemID = (SogItem)readBinary.ReadInt32()
});
Expand Down Expand Up @@ -367,23 +367,23 @@ public static Player ReadFromFile(string fileName, ITextBoxWrapper txtConsole)
playerObject.UniquePlayerId = readBinary.ReadUInt32();
txtConsole.AppendText("\r\n" + "UniquePlayerId: " + playerObject.UniquePlayerId);
txtConsole.AppendText("\r\n" + "> UniquePlayerId Position: " + readBinary.BaseStream.Position.ToString("X"));
playerObject.UnknownVariable04 = readBinary.ReadInt32();
playerObject.UnknownVariable05 = readBinary.ReadInt32();
playerObject.LastAutosave = readBinary.ReadInt32();
playerObject.SaveUnknown = readBinary.ReadInt32();
playerObject.PlayTimeTotal = readBinary.ReadInt32();
txtConsole.AppendText("\r\n" + "PlayTimeTotal: " + playerObject.PlayTimeTotal);
txtConsole.AppendText("\r\n" + "> PlayTimeTotal Position: " + readBinary.BaseStream.Position.ToString("X"));
txtConsole.AppendText("\r\nPlayTimeTotal: " + Math.Round((double)playerObject.PlayTimeTotal / 60 / 60 / 60, 2) + " hours");
playerObject.UnknownVariable06 = readBinary.ReadByte();
playerObject.PhaseShiftStuff = readBinary.ReadByte();

playerObject.UnknownVariable07Count = readBinary.ReadInt16();
playerObject.UnknownVariables07 = new List<UnknownVariable07>(playerObject.UnknownVariable07Count);
for (int i = 0; i != playerObject.UnknownVariable07Count; i++)
playerObject.CharacterFlagCount = readBinary.ReadInt16();
playerObject.CharacterFlags = new List<CharacterFlags>(playerObject.CharacterFlagCount);
for (int i = 0; i != playerObject.CharacterFlagCount; i++)
{
string unknownString = readBinary.ReadString();
playerObject.UnknownVariables07.Add(new UnknownVariable07
playerObject.CharacterFlags.Add(new CharacterFlags
{
UnknownString = unknownString,
UnknownFloat = readBinary.ReadSingle()
Name = unknownString,
Value = readBinary.ReadSingle()
});

txtConsole.AppendText("\r\nUnknownstring: " + unknownString);
Expand All @@ -401,7 +401,7 @@ public static Player ReadFromFile(string fileName, ITextBoxWrapper txtConsole)
txtConsole.AppendText("\r\nFlagsCount: " + playerObject.FlagsCount);

playerObject.HouseStylesCount = readBinary.ReadByte();
playerObject.Houses = new List<HouseStyle>(playerObject.HouseStylesCount);
playerObject.HouseStyles = new List<HouseStyle>(playerObject.HouseStylesCount);
for (int i = 0; i != playerObject.HouseStylesCount; i++)
{
byte styleNumber = readBinary.ReadByte();
Expand All @@ -413,11 +413,11 @@ public static Player ReadFromFile(string fileName, ITextBoxWrapper txtConsole)
styleBytes[j] = readBinary.ReadByte();
}
// add the housestyle to the list
playerObject.Houses.Add(new HouseStyle
playerObject.HouseStyles.Add(new HouseStyle
{
HouseStyleNumber = styleNumber,
HouseStyleLength = styleLength,
HouseStyleBytes = styleBytes
Number = styleNumber,
Length = styleLength,
Bytes = styleBytes
});
}

Expand Down
87 changes: 44 additions & 43 deletions SoG_SGreader/DataWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,19 @@ public void WriteToFile(string fileName)
writeBinary.Write((byte) style.Sex);
writeBinary.Write(playerObject.Nickname);

writeBinary.Write(playerObject.ItemsCount);
writeBinary.Write((int) playerObject.ItemsCount);
for (var i = 0; i != playerObject.ItemsCount; i++)
{
writeBinary.Write((int) playerObject.Inventory[i].ItemID);
writeBinary.Write(playerObject.Inventory[i].ItemCount);
writeBinary.Write((int) playerObject.Inventory[i].ItemPos);
}

// Inventory.DisplayItem.PickupNumberPool???
writeBinary.Write(playerObject.UnknownVariable0);

writeBinary.Write(playerObject.MerchantItemsCount);
for (var i = 0; i != playerObject.MerchantItemsCount; i++)
writeBinary.Write((int) playerObject.MerchantItems.Count);
for (var i = 0; i != playerObject.MerchantItems.Count; i++)
{
writeBinary.Write((int) playerObject.MerchantItems[i].ItemID);
writeBinary.Write(playerObject.MerchantItems[i].ItemCount);
Expand All @@ -88,22 +89,22 @@ public void WriteToFile(string fileName)
writeBinary.Write((int) playerObject.Cards[i].CardID);
}

writeBinary.Write(playerObject.TreasureMapsCount);
for (var i = 0; i != playerObject.TreasureMapsCount; i++)
writeBinary.Write((int) playerObject.TreasureMaps.Count);
for (var i = 0; i != playerObject.TreasureMaps.Count; i++)
{
writeBinary.Write(playerObject.TreasureMaps[i].TreasureMapID);
}

writeBinary.Write(playerObject.UnknownVariable01Count);
for (var i = 0; i != playerObject.UnknownVariable01Count; i++)
writeBinary.Write((int) playerObject.UnknownVariables01.Count);
for (var i = 0; i != playerObject.UnknownVariables01.Count; i++)
{
writeBinary.Write(playerObject.UnknownVariables01[i].UnknownVariable01ID);
}

writeBinary.Write(playerObject.SkillsCount);
for (var i = 0; i != playerObject.SkillsCount; i++)
writeBinary.Write((int) playerObject.Skills.Count);
for (var i = 0; i != playerObject.Skills.Count; i++)
{
writeBinary.Write((short) playerObject.Skills[i].SkillID);
writeBinary.Write((ushort) playerObject.Skills[i].SkillID);
writeBinary.Write(playerObject.Skills[i].SkillLevel);
}

Expand Down Expand Up @@ -149,48 +150,48 @@ public void WriteToFile(string fileName)
writeBinary.Write((ushort) playerObject.Quests[i].QuestID);
}

writeBinary.Write(playerObject.EnemiesMetCount);
for (int i = 0; i != playerObject.EnemiesMetCount; i++)
writeBinary.Write((ushort) playerObject.EnemiesSeen.Count);
for (int i = 0; i != playerObject.EnemiesSeen.Count; i++)
{
writeBinary.Write((uint) playerObject.Enemies[i].EnemyID);
writeBinary.Write((int) playerObject.EnemiesSeen[i].EnemyID);
}

writeBinary.Write((ushort) (playerObject.UnknownVariable02Count / 16));
for (int i = 0; i != playerObject.UnknownVariable02Count; i++)
writeBinary.Write((ushort) (playerObject.UnknownVariables02.Count / 16));
for (int i = 0; i != playerObject.UnknownVariables02.Count; i++)
{
writeBinary.Write(playerObject.UnknownVariables02[i].UnknownByte);
}

writeBinary.Write(playerObject.RobinBowHighscore);

writeBinary.Write(playerObject.UnknownVariable03Count);
for (int i = 0; i != playerObject.UnknownVariable03Count; i++)
writeBinary.Write((ushort) playerObject.Trophies.Count);
for (int i = 0; i != playerObject.Trophies.Count; i++)
{
writeBinary.Write(playerObject.UnknownVariables03[i].UnknownVariable);
writeBinary.Write(playerObject.Trophies[i].TrophyID);
}

writeBinary.Write(playerObject.ItemsMetCount);
for (int i = 0; i != playerObject.ItemsMetCount; i++)
writeBinary.Write((ushort)playerObject.ItemsSeen.Count);
for (int i = 0; i != playerObject.ItemsSeen.Count; i++)
{
writeBinary.Write((int) playerObject.ItemsMet[i].ItemID);
writeBinary.Write((int) playerObject.ItemsSeen[i].ItemID);
}

writeBinary.Write(playerObject.ItemsCraftedCount);
for (int i = 0; i != playerObject.ItemsCraftedCount; i++)
writeBinary.Write((ushort) playerObject.ItemsCrafted.Count);
for (int i = 0; i != playerObject.ItemsCrafted.Count; i++)
{
writeBinary.Write((int) playerObject.ItemsCrafted[i].ItemID);
}

writeBinary.Write(playerObject.FishiesCaughtCount);
for (int i = 0; i != playerObject.FishiesCaughtCount; i++)
writeBinary.Write((ushort) playerObject.FishiesCaught.Count);
for (int i = 0; i != playerObject.FishiesCaught.Count; i++)
{
writeBinary.Write((int) playerObject.FishiesCaught[i].FishID);
}

writeBinary.Write(playerObject.KilledEnemiesCount);
for (int i = 0; i != playerObject.KilledEnemiesCount; i++)
writeBinary.Write((ushort) playerObject.KilledEnemies.Count);
for (int i = 0; i != playerObject.KilledEnemies.Count; i++)
{
writeBinary.Write(playerObject.KilledEnemies[i].EnemyID);
writeBinary.Write((int)playerObject.KilledEnemies[i].EnemyID);
writeBinary.Write(playerObject.KilledEnemies[i].KillCount);
}

Expand All @@ -199,38 +200,38 @@ public void WriteToFile(string fileName)

for (int i = 0; i != playerObject.PotionsEquipped; i++)
{
writeBinary.Write(playerObject.Potions[i].PotionID);
writeBinary.Write((int) playerObject.Potions[i].PotionID);
}

writeBinary.Write(playerObject.BirthdayMonth);
writeBinary.Write(playerObject.BirthdayDay);
writeBinary.Write((int) playerObject.UniquePlayerId);
writeBinary.Write(playerObject.UnknownVariable04);
writeBinary.Write(playerObject.UnknownVariable05);
writeBinary.Write(playerObject.LastAutosave);
writeBinary.Write(playerObject.SaveUnknown);

writeBinary.Write(playerObject.PlayTimeTotal); // check for overflow

writeBinary.Write((byte)playerObject.UnknownVariable06);
writeBinary.Write((byte )playerObject.PhaseShiftStuff);

writeBinary.Write((ushort) playerObject.UnknownVariable07Count);
for (int i = 0; i != playerObject.UnknownVariable07Count; i++)
writeBinary.Write((ushort) playerObject.CharacterFlags.Count);
for (int i = 0; i != playerObject.CharacterFlags.Count; i++)
{
writeBinary.Write(playerObject.UnknownVariables07[i].UnknownString);
writeBinary.Write(playerObject.UnknownVariables07[i].UnknownFloat);
writeBinary.Write(playerObject.CharacterFlags[i].Name);
writeBinary.Write(playerObject.CharacterFlags[i].Value);
}

writeBinary.Write((ushort) playerObject.FlagsCount);
for (int i = 0; i != playerObject.FlagsCount; i++)
writeBinary.Write((ushort) playerObject.Flags.Count);
for (int i = 0; i != playerObject.Flags.Count; i++)
{
writeBinary.Write(playerObject.Flags[i].FlagID);
}

writeBinary.Write(playerObject.HouseStylesCount);
for (int i = 0; i != playerObject.HouseStylesCount; i++)
writeBinary.Write((byte) playerObject.HouseStyles.Count);
for (int i = 0; i != playerObject.HouseStyles.Count; i++)
{
writeBinary.Write(playerObject.Houses[i].HouseStyleNumber);
writeBinary.Write(playerObject.Houses[i].HouseStyleLength);
writeBinary.Write(playerObject.Houses[i].HouseStyleBytes);
writeBinary.Write(playerObject.HouseStyles[i].Number);
writeBinary.Write(playerObject.HouseStyles[i].Length);
writeBinary.Write(playerObject.HouseStyles[i].Bytes);
}

writeBinary.Close();
Expand Down
Loading

0 comments on commit 46e34f6

Please sign in to comment.