From fb4e3f8d001cd646818e6b369f61836693c1c995 Mon Sep 17 00:00:00 2001 From: HolographicHat Date: Thu, 21 Nov 2024 08:11:26 +0800 Subject: [PATCH] fix --- src/GlobalVars.cs | 2 +- src/Parsers/AchievementAllDataNotify.cs | 40 +++++++++++++++++-------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/GlobalVars.cs b/src/GlobalVars.cs index 0f734af..1b2343d 100644 --- a/src/GlobalVars.cs +++ b/src/GlobalVars.cs @@ -21,7 +21,7 @@ public static class GlobalVars { public static readonly string CachePath = Path.Combine(DataPath, "cache"); public static readonly string LibFilePath = Path.Combine(DataPath, "YaeAchievement.dll"); - public const uint AppVersionCode = 114; + public const uint AppVersionCode = 233; public const string AppVersionName = "5.2"; public const string PipeName = "YaeAchievementPipe"; diff --git a/src/Parsers/AchievementAllDataNotify.cs b/src/Parsers/AchievementAllDataNotify.cs index 8ed964c..da29e62 100644 --- a/src/Parsers/AchievementAllDataNotify.cs +++ b/src/Parsers/AchievementAllDataNotify.cs @@ -27,23 +27,37 @@ public class AchievementAllDataNotify { public static AchievementAllDataNotify ParseFrom(byte[] bytes) { using var stream = new CodedInputStream(bytes); - uint tag; var data = new List>(); - while ((tag = stream.ReadTag()) != 0) { - if ((tag & 7) == 2) { // is LengthDelimited - var dict = new Dictionary(); - using var eStream = new CodedInputStream(ReadRawBytes(stream, stream.ReadLength())); - while ((tag = eStream.ReadTag()) != 0) { - if ((tag & 7) != 0) { // not VarInt - dict = null; - break; + var errTimes = 0; + try { + uint tag; + while ((tag = stream.ReadTag()) != 0) { + if ((tag & 7) == 2) { // is LengthDelimited + var dict = new Dictionary(); + using var eStream = new CodedInputStream(ReadRawBytes(stream, stream.ReadLength())); + try { + while ((tag = eStream.ReadTag()) != 0) { + if ((tag & 7) != 0) { // not VarInt + dict = null; + break; + } + dict[tag >> 3] = eStream.ReadUInt32(); + } + if (dict != null) { + data.Add(dict); + } + } catch (InvalidProtocolBufferException) { + if (errTimes++ > 0) { // allows 1 fail on 'reward_taken_goal_id_list' + throw; + } } - dict[tag >> 3] = eStream.ReadUInt32(); - } - if (dict != null) { - data.Add(dict); } } + } catch (InvalidProtocolBufferException) { + // ReSharper disable once LocalizableElement + Console.WriteLine("Parse failed"); + File.WriteAllBytes("achievement_raw_data.bin", bytes); + Environment.Exit(0); } if (data.Count == 0) { return new AchievementAllDataNotify();