From a2ad158ea77913fbfe246cd33c2f3920297e2529 Mon Sep 17 00:00:00 2001 From: ZouJin Date: Sun, 6 Aug 2023 12:00:03 +1000 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=AD=98=E6=A1=A3Hash?= =?UTF-8?q?=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IMainWindow.cs | 5 +++++ VPet-Simulator.Windows/MainWindow.cs | 21 ++++++++++++++++--- VPet-Simulator.Windows/MainWindow.xaml.cs | 10 ++------- .../WinDesign/winGameSetting.xaml.cs | 6 ++++-- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/VPet-Simulator.Windows.Interface/IMainWindow.cs b/VPet-Simulator.Windows.Interface/IMainWindow.cs index 58b8dbf..a5d69c8 100644 --- a/VPet-Simulator.Windows.Interface/IMainWindow.cs +++ b/VPet-Simulator.Windows.Interface/IMainWindow.cs @@ -98,6 +98,11 @@ namespace VPet_Simulator.Windows.Interface /// 鼠标穿透 /// bool MouseHitThrough { get; set; } + + /// + /// 存档 Hash检查 是否通过 + /// + bool HashCheck { get; } } } diff --git a/VPet-Simulator.Windows/MainWindow.cs b/VPet-Simulator.Windows/MainWindow.cs index 41e03aa..e1ad669 100644 --- a/VPet-Simulator.Windows/MainWindow.cs +++ b/VPet-Simulator.Windows/MainWindow.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Reflection; using System.Threading.Tasks; using System.Windows; using VPet_Simulator.Core; @@ -45,7 +46,10 @@ namespace VPet_Simulator.Windows public List LowFoodText { get; set; } = new List(); public List LowDrinkText { get; set; } = new List(); - + /// + /// 存档 Hash检查 是否通过 + /// + public bool HashCheck { get; set; } = true; public void SetZoomLevel(double zl) { Set.ZoomLevel = zl; @@ -97,7 +101,10 @@ namespace VPet_Simulator.Windows if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"\Save.lps")) File.Move(AppDomain.CurrentDomain.BaseDirectory + @"\Save.lps", AppDomain.CurrentDomain.BaseDirectory + $"\\UserData\\Save_{st}.lps"); - File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"\Save.lps", Core.Save.ToLine().ToString()); + var l = Core.Save.ToLine(); + int hs = l.GetHashCode(); + l[(gint)"hash"] = hs; + File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"\Save.lps", l.ToString()); } if (CGPTClient != null) File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"\ChatGPTSetting.json", CGPTClient.Save()); @@ -372,6 +379,14 @@ namespace VPet_Simulator.Windows Task.Run(Steamworks.SteamUserStats.StoreStats); } } - + public void GameLoad(ILine line) + { + Core.Save = GameSave.Load(line); + int hash = line.GetInt("hash"); + if (line.Remove("hash")) + { + HashCheck = line.GetHashCode() == hash; + } + } } } diff --git a/VPet-Simulator.Windows/MainWindow.xaml.cs b/VPet-Simulator.Windows/MainWindow.xaml.cs index e47d3b5..bbe93b9 100644 --- a/VPet-Simulator.Windows/MainWindow.xaml.cs +++ b/VPet-Simulator.Windows/MainWindow.xaml.cs @@ -18,20 +18,14 @@ using ChatGPT.API.Framework; using static VPet_Simulator.Core.GraphCore; using Panuon.WPF.UI; using VPet_Simulator.Windows.Interface; -using static VPet_Simulator.Core.IGraph; using System.Windows.Controls; -using System.Windows.Media.Imaging; -using System.Windows.Media; using System.Linq; using LinePutScript.Localization.WPF; using System.Runtime.InteropServices; using System.Windows.Interop; using static VPet_Simulator.Windows.PerformanceDesktopTransparentWindow; -using System.Windows.Shapes; using Line = LinePutScript.Line; using static VPet_Simulator.Core.GraphInfo; -using LinePutScript.Converter; -using System.Windows.Markup; namespace VPet_Simulator.Windows { @@ -171,7 +165,7 @@ namespace VPet_Simulator.Windows .GetFiles("*.lps").OrderByDescending(x => x.LastWriteTime).FirstOrDefault(); if (latestsave != null) { - Core.Save = GameSave.Load(new Line(File.ReadAllText(latestsave.FullName))); + GameLoad(new Line(File.ReadAllText(latestsave.FullName))); return; } } @@ -240,7 +234,7 @@ namespace VPet_Simulator.Windows //加载游戏内容 Core.Controller = new MWController(this); if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"\Save.lps")) - Core.Save = GameSave.Load(new LpsDocument(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"\Save.lps")).First()); + GameLoad(new LpsDocument(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"\Save.lps")).First()); else//如果加载存档失败了,试试加载备份,如果没备份,就新建一个 LoadLatestSave(); diff --git a/VPet-Simulator.Windows/WinDesign/winGameSetting.xaml.cs b/VPet-Simulator.Windows/WinDesign/winGameSetting.xaml.cs index b247b04..34c115f 100644 --- a/VPet-Simulator.Windows/WinDesign/winGameSetting.xaml.cs +++ b/VPet-Simulator.Windows/WinDesign/winGameSetting.xaml.cs @@ -762,6 +762,7 @@ namespace VPet_Simulator.Windows if (!AllowChange) return; mw.Set["CGPT"].SetBool("enable", RBCGPTUseLB.IsChecked == false); + mw.Set["CGPT"].SetBool("enable", RBCGPTUseLB.IsChecked == false); if (mw.Set["CGPT"][(gbol)"enable"]) { BtnCGPTReSet.Content = "打开 ChatGPT API 设置".Translate(); @@ -895,11 +896,12 @@ namespace VPet_Simulator.Windows string path = AppDomain.CurrentDomain.BaseDirectory + @"\UserData\" + txt + ".lps"; if (File.Exists(path)) { - GameSave gs = GameSave.Load(new Line(File.ReadAllText(path))); + var l = new Line(File.ReadAllText(path)); + GameSave gs = GameSave.Load(l); if (MessageBoxX.Show("存档名称:{0}\n存档等级:{1}\n存档金钱:{2}\n是否加载该备份存档? 当前游戏数据会丢失" .Translate(gs.Name, gs.Level, gs.Money), "是否加载该备份存档? 当前游戏数据会丢失".Translate(), MessageBoxButton.YesNo, MessageBoxIcon.Info) == MessageBoxResult.Yes) { - mw.Core.Save = gs; + mw.GameLoad(l); } } }