From 821b0302131eb135fed54553e167251df824929c Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Thu, 24 Nov 2022 16:10:27 +0100 Subject: [PATCH] add fileheader entry class for detecting odyssey --- EDPlayerJournal/Entries/CommanderEntry.cs | 8 +--- EDPlayerJournal/Entries/Entry.cs | 1 + EDPlayerJournal/Entries/Events.cs | 1 + EDPlayerJournal/Entries/FileHeaderEntry.cs | 37 ++++++++++++++++ EDPlayerJournalTests/FileHeaderTest.cs | 50 ++++++++++++++++++++++ 5 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 EDPlayerJournal/Entries/FileHeaderEntry.cs create mode 100644 EDPlayerJournalTests/FileHeaderTest.cs diff --git a/EDPlayerJournal/Entries/CommanderEntry.cs b/EDPlayerJournal/Entries/CommanderEntry.cs index 9d6e0da..8ab4c11 100644 --- a/EDPlayerJournal/Entries/CommanderEntry.cs +++ b/EDPlayerJournal/Entries/CommanderEntry.cs @@ -1,13 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +namespace EDPlayerJournal.Entries; -namespace EDPlayerJournal.Entries; public class CommanderEntry : Entry { public string? Name { get; set; } public string? FID { get; set; } + protected override void Initialise() { Name = JSON.Value("Name") ?? ""; FID = JSON.Value("FID") ?? ""; diff --git a/EDPlayerJournal/Entries/Entry.cs b/EDPlayerJournal/Entries/Entry.cs index a7367b4..c122891 100644 --- a/EDPlayerJournal/Entries/Entry.cs +++ b/EDPlayerJournal/Entries/Entry.cs @@ -17,6 +17,7 @@ public class Entry { { Events.CommitCrime, typeof(CommitCrimeEntry) }, { Events.Died, typeof(DiedEntry) }, { Events.Docked, typeof(DockedEntry) }, + { Events.FileHeader, typeof(FileHeaderEntry) }, { Events.FactionKillBond, typeof(FactionKillBondEntry) }, { Events.FSDJump, typeof(FSDJumpEntry) }, { Events.HullDamage, typeof(HullDamageEntry) }, diff --git a/EDPlayerJournal/Entries/Events.cs b/EDPlayerJournal/Entries/Events.cs index 34a0c7a..62ad8ec 100644 --- a/EDPlayerJournal/Entries/Events.cs +++ b/EDPlayerJournal/Entries/Events.cs @@ -8,6 +8,7 @@ public class Events { public static readonly string Docked = "Docked"; public static readonly string FactionKillBond = "FactionKillBond"; public static readonly string FighterDestroyed = "FighterDestroyed"; + public static readonly string FileHeader = "Fileheader"; public static readonly string FSDJump = "FSDJump"; public static readonly string HullDamage = "HullDamage"; public static readonly string LoadGame = "LoadGame"; diff --git a/EDPlayerJournal/Entries/FileHeaderEntry.cs b/EDPlayerJournal/Entries/FileHeaderEntry.cs new file mode 100644 index 0000000..2ce393c --- /dev/null +++ b/EDPlayerJournal/Entries/FileHeaderEntry.cs @@ -0,0 +1,37 @@ +namespace EDPlayerJournal.Entries; + +public class FileHeaderEntry : Entry { + /// + /// File part. + /// + public ulong Part { get; set; } = 1; + + /// + /// Local language of the file. + /// + public string? Language { get; set; } + + /// + /// Whether the file is for an Odyssey version + /// + public bool Odyssey { get; set; } = false; + + /// + /// Game version in question (3.8 or 4.0) + /// + public string GameVersion { get; set; } = "3.8"; + + /// + /// Build version (SVN revision number). + /// + public string? Build { get; set; } + + protected override void Initialise() { + Part = JSON.Value("part") ?? 1; + Language = JSON.Value("language") ?? string.Empty; + // If this entry is not there then its a legacy entry + Odyssey = JSON.Value("Odyssey") ?? false; + GameVersion = JSON.Value("gameversion") ?? "3.8"; + Build = JSON.Value("build"); + } +} diff --git a/EDPlayerJournalTests/FileHeaderTest.cs b/EDPlayerJournalTests/FileHeaderTest.cs new file mode 100644 index 0000000..93d1669 --- /dev/null +++ b/EDPlayerJournalTests/FileHeaderTest.cs @@ -0,0 +1,50 @@ +using EDPlayerJournal.Entries; + +namespace EDPlayerJournalTests; + +[TestClass] +public class FileHeaderTest { + [TestMethod] + public void OdysseyFileHeader() { + string fileheader = /*lang=json,strict*/ """{ "timestamp":"2022-11-21T15:04:36Z", "event":"Fileheader", "part":1, "language":"English/UK", "Odyssey":true, "gameversion":"4.0.0.1450", "build":"r286858/r0 " }"""; + + Entry? entry = Entry.Parse(fileheader); + + Assert.IsNotNull(entry); + Assert.IsInstanceOfType(entry, typeof(FileHeaderEntry)); + + FileHeaderEntry? header = entry as FileHeaderEntry; + + Assert.IsNotNull(header); + + Assert.AreEqual(header.Part, 1UL); + Assert.AreEqual(header.Language, "English/UK"); + Assert.AreEqual(header.Odyssey, true); + Assert.AreEqual(header.GameVersion, "4.0.0.1450"); + // Someone at FDev messed up string building there. + Assert.AreEqual(header.Build, "r286858/r0 "); + } + + [TestMethod] + public void LegacyFileHeader() { + // This is the oldest file header I could find. + string fileheader = /*lang=json,strict*/ """{ "timestamp":"2020-01-02T23:45:23Z", "event":"Fileheader", "part":1, "language":"English\\UK", "gameversion":"3.5.3.400 EDH", "build":"r213094/r0 " }"""; + + Entry? entry = Entry.Parse(fileheader); + + Assert.IsNotNull(entry); + Assert.IsInstanceOfType(entry, typeof(FileHeaderEntry)); + + FileHeaderEntry? header = entry as FileHeaderEntry; + + Assert.IsNotNull(header); + + Assert.AreEqual(header.Part, 1UL); + // At some point they switche to a forward slash. Curious. + Assert.AreEqual(header.Language, """English\UK"""); + Assert.AreEqual(header.Odyssey, false); + Assert.AreEqual(header.GameVersion, "3.5.3.400 EDH"); + // ~73k commits in two years. Not bad. + Assert.AreEqual(header.Build, "r213094/r0 "); + } +}