From 22745eb116ce5ad27d62a3e5325aeb4bf972f6ba Mon Sep 17 00:00:00 2001 From: ZouJin Date: Wed, 7 Feb 2024 16:46:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=80=81=E7=89=88=E6=9C=ACvp?= =?UTF-8?q?et(v1.4-)hashcheck=E5=A4=B1=E6=95=88=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GameSave_v2.cs | 26 ++++++++++++++++--- VPet-Simulator.Windows.Interface/Setting.cs | 2 +- .../VPet-Simulator.Windows.csproj | 8 +++--- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/VPet-Simulator.Windows.Interface/GameSave_v2.cs b/VPet-Simulator.Windows.Interface/GameSave_v2.cs index 58c8ad6..68fcba9 100644 --- a/VPet-Simulator.Windows.Interface/GameSave_v2.cs +++ b/VPet-Simulator.Windows.Interface/GameSave_v2.cs @@ -10,7 +10,9 @@ using System.Security.Cryptography; using System.Security.Policy; using System.Text; using System.Threading.Tasks; +using System.Xml.Linq; using VPet_Simulator.Core; +using static System.Net.Mime.MediaTypeNames; namespace VPet_Simulator.Windows.Interface { @@ -31,7 +33,7 @@ namespace VPet_Simulator.Windows.Interface { if (lps.FindLine("statistics") == null) {//尝试从老存档加载 - Statistics = oldStatistics; + Statistics = oldStatistics ?? new Statistics(); } else { @@ -42,12 +44,30 @@ namespace VPet_Simulator.Windows.Interface long hash; if (vpet != null) { - GameSave = GameSave.Load(vpet); + GameSave = GameSave.Load(vpet); hash = vpet.GetInt64("hash"); if (vpet.Remove("hash")) { - HashCheck = vpet.GetLongHashCode() == hash; nohashcheck = false; + try + { + using (MD5 md5 = MD5.Create()) + { + long hs = BitConverter.ToInt64(md5.ComputeHash(Encoding.UTF8.GetBytes(vpet.Name)), 0) + * 2 + BitConverter.ToInt64(md5.ComputeHash(Encoding.UTF8.GetBytes(vpet.info)), 0) + * 3 + BitConverter.ToInt64(md5.ComputeHash(Encoding.UTF8.GetBytes(vpet.text)), 0) * 4; + foreach (ISub su in vpet.ToList()) + { + hs += BitConverter.ToInt64(md5.ComputeHash(Encoding.UTF8.GetBytes(su.Name)), 0) * 2 + + BitConverter.ToInt64(md5.ComputeHash(Encoding.UTF8.GetBytes(su.Info)), 0) * 3; + } + HashCheck = hs == hash; + } + } + catch + { + nohashcheck = true; + } } } else if (oldGameSave != null) diff --git a/VPet-Simulator.Windows.Interface/Setting.cs b/VPet-Simulator.Windows.Interface/Setting.cs index 4a87c95..2f966d9 100644 --- a/VPet-Simulator.Windows.Interface/Setting.cs +++ b/VPet-Simulator.Windows.Interface/Setting.cs @@ -145,7 +145,7 @@ namespace VPet_Simulator.Windows.Interface /// public int BackupSaveMaxNum { - get => Math.Max(GetInt("bakupsave", 30), 1); + get => Math.Max(GetInt("bakupsave", 50), 1); set => SetInt("bakupsave", value); } /// diff --git a/VPet-Simulator.Windows/VPet-Simulator.Windows.csproj b/VPet-Simulator.Windows/VPet-Simulator.Windows.csproj index 9325579..1097547 100644 --- a/VPet-Simulator.Windows/VPet-Simulator.Windows.csproj +++ b/VPet-Simulator.Windows/VPet-Simulator.Windows.csproj @@ -125,10 +125,6 @@ - - - - True @@ -242,4 +238,8 @@ + + + + \ No newline at end of file