From ac379a44892b8b04c86319bc9144b39d294e40b1 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Tue, 13 Oct 2020 20:28:25 -0500 Subject: [PATCH] Minor changes to the GameVersionEarly parser to make it slightly saner --- IPA.Injector/GameVersionEarly.cs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/IPA.Injector/GameVersionEarly.cs b/IPA.Injector/GameVersionEarly.cs index 6cbd7a7f..612a038d 100644 --- a/IPA.Injector/GameVersionEarly.cs +++ b/IPA.Injector/GameVersionEarly.cs @@ -40,25 +40,18 @@ namespace IPA.Injector if (stream.Position == stream.Length) // we went through the entire stream without finding the key throw new KeyNotFoundException("Could not find key '" + key + "' in " + mgr); - long startPos = 0; - long length = 0; while (stream.Position < stream.Length) { - char current = reader.ReadChar(); - if (startPos == 0 && current >= '0' && current <= '9') - startPos = stream.Position - 1; - else if (startPos > 0 && IllegalCharacters.Contains(current)) - { - length = stream.Position - startPos - 1; + var current = (char)reader.ReadByte(); + if (char.IsDigit(current)) break; - } } - if (startPos <= 0 || length <= 0) - throw new KeyNotFoundException("Could not parse version from " + mgr); - stream.Seek(startPos, SeekOrigin.Begin); + var rewind = -sizeof(int) - sizeof(byte); + stream.Seek(rewind, SeekOrigin.Current); // rewind to the string length - var strbytes = reader.ReadBytes((int)length); + var strlen = reader.ReadInt32(); + var strbytes = reader.ReadBytes(strlen); return Encoding.UTF8.GetString(strbytes); }