From 7315c3948f7428d29e467915456b0bd2bc1968a7 Mon Sep 17 00:00:00 2001 From: ZouJin Date: Fri, 22 Sep 2023 21:24:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E7=BB=9F=E8=AE=A1=E5=88=B0?= =?UTF-8?q?=E6=96=B0=E5=AD=98=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GameSave_v2.cs | 37 ++++++++++- .../IMainWindow.cs | 2 +- VPet-Simulator.Windows.Interface/Setting.cs | 10 +-- VPet-Simulator.Windows/MainWindow.cs | 65 ++++++++++--------- VPet-Simulator.Windows/MainWindow.xaml.cs | 26 ++++---- .../WinDesign/winGameSetting.xaml.cs | 24 +++---- 6 files changed, 99 insertions(+), 65 deletions(-) diff --git a/VPet-Simulator.Windows.Interface/GameSave_v2.cs b/VPet-Simulator.Windows.Interface/GameSave_v2.cs index c6af122..199d210 100644 --- a/VPet-Simulator.Windows.Interface/GameSave_v2.cs +++ b/VPet-Simulator.Windows.Interface/GameSave_v2.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Security.Policy; using System.Text; using System.Threading.Tasks; using VPet_Simulator.Core; @@ -33,14 +34,33 @@ namespace VPet_Simulator.Windows.Interface { Statistics = new Statistics(lps["statistics"].ToList()); } - if (lps.FindLine("vpet") != null) + ILine vpet = lps.FindLine("vpet"); + bool nohashcheck = true; + long hash; + if (vpet != null) { - GameSave = GameSave.Load(lps.FindLine("vpet")); + GameSave = GameSave.Load(vpet); + hash = vpet.GetInt64("hash"); + if (vpet.Remove("hash")) + { + HashCheck = vpet.GetLongHashCode() == hash; + nohashcheck = false; + } } else if (oldGameSave != null) { GameSave = oldGameSave; } + + if (nohashcheck) + { + hash = vpet.GetInt64("hash"); + if (lps.Remove("hash")) + { + HashCheck = vpet.GetLongHashCode() == hash; + } + } + if (olddata != null) Data.AddRange(olddata); Data.AddRange(lps); @@ -79,7 +99,7 @@ namespace VPet_Simulator.Windows.Interface /// public Statistics Statistics = null; - public ILPS Save() + public ILPS ToLPS() { var lps = new LPS_D(); lps.AddRange(Data); @@ -87,5 +107,16 @@ namespace VPet_Simulator.Windows.Interface lps.Add(new Line("statistics", "", Statistics.ToSubs())); return lps; } + /// + /// Hash检查 + /// + public bool HashCheck { get; private set; } + /// + /// + /// + public void HashCheckOff () + { + HashCheck = false; + } } } diff --git a/VPet-Simulator.Windows.Interface/IMainWindow.cs b/VPet-Simulator.Windows.Interface/IMainWindow.cs index 76fb24f..78cf172 100644 --- a/VPet-Simulator.Windows.Interface/IMainWindow.cs +++ b/VPet-Simulator.Windows.Interface/IMainWindow.cs @@ -139,7 +139,7 @@ namespace VPet_Simulator.Windows.Interface /// void HashCheckOff(); - GameSave_v2 GameSave_v2 { get; } + GameSave_v2 GameSavesData { get; } } } diff --git a/VPet-Simulator.Windows.Interface/Setting.cs b/VPet-Simulator.Windows.Interface/Setting.cs index 9976995..5acf2f7 100644 --- a/VPet-Simulator.Windows.Interface/Setting.cs +++ b/VPet-Simulator.Windows.Interface/Setting.cs @@ -33,19 +33,19 @@ namespace VPet_Simulator.Windows.Interface allowmove = !this["gameconfig"].GetBool("allowmove"); smartmove = this["gameconfig"].GetBool("smartmove"); enablefunction = !this["gameconfig"].GetBool("nofunction"); - Statistics = new Statistics(this["statistics"].ToList()); + Statistics_OLD = new Statistics(this["statistics"].ToList()); autobuy = this["gameconfig"].GetBool("autobuy"); autogift = this["gameconfig"].GetBool("autogift"); } public override string ToString() - { - this["statistics"] = new Line("statistics", "", "", Statistics.ToSubs().ToArray()); + {//留作备份,未来版本删了 + this["statistics"] = new Line("statistics", "", "", Statistics_OLD.ToSubs().ToArray()); return base.ToString(); } /// - /// 统计数据信息 + /// 统计数据信息(旧) /// - public Statistics Statistics; + public Statistics Statistics_OLD; //public Size WindowsSize //{ diff --git a/VPet-Simulator.Windows/MainWindow.cs b/VPet-Simulator.Windows/MainWindow.cs index 661aaba..2db62e2 100644 --- a/VPet-Simulator.Windows/MainWindow.cs +++ b/VPet-Simulator.Windows/MainWindow.cs @@ -62,7 +62,7 @@ namespace VPet_Simulator.Windows public List ClickTexts { get; set; } = new List(); - public GameSave_v2 GameSave_v2 { get; set; } + public GameSave_v2 GameSavesData { get; set; } /// /// 获得自动点击的文本 /// @@ -112,13 +112,16 @@ namespace VPet_Simulator.Windows /// public bool HashCheck { - get => hashCheck; + get => GameSavesData.HashCheck; set { - hashCheck = value; + if(!value) + { + GameSavesData.HashCheckOff(); + } Main?.Dispatcher.Invoke(() => { - if (hashCheck) + if (GameSavesData.HashCheck) { if (hashcheckimg == null) { @@ -166,14 +169,14 @@ namespace VPet_Simulator.Windows //游戏存档 if (Set != null) { - var st = Set.Statistics[(gint)"savetimes"]++; + var st = GameSavesData.Statistics[(gint)"savetimes"]++; if (Main != null) { Set.VoiceVolume = Main.PlayVoiceVolume; List list = new List(); Foods.FindAll(x => x.Star).ForEach(x => list.Add(x.Name)); Set["betterbuy"]["star"].info = string.Join(",", list); - //Set.Statistics[(gint)"stat_time"] = (int)(DateTime.Now - timecount).TotalMinutes; + //GameSavesData.Statistics[(gint)"stat_time"] = (int)(DateTime.Now - timecount).TotalMinutes; //timecount = DateTime.Now; } Set.StartRecordLastPoint = new Point(Dispatcher.Invoke(() => Left), Dispatcher.Invoke(() => Top)); @@ -200,7 +203,7 @@ namespace VPet_Simulator.Windows if (File.Exists(ExtensionValue.BaseDirectory + @"\Save.lps")) File.Move(ExtensionValue.BaseDirectory + @"\Save.lps", ExtensionValue.BaseDirectory + $"\\BackUP\\Save_{st}.lps"); - var l = Core.Save.ToLine(); + var l = GameSavesData.ToLPS(); if (HashCheck) { l[(gi64)"hash"] = new Line(l.ToString()).GetLongHashCode(); @@ -456,30 +459,30 @@ namespace VPet_Simulator.Windows Core.Save.Money -= item.Price; //统计 - Set.Statistics[(gint)("buy_" + item.Name)]++; - Set.Statistics[(gdbe)"stat_betterbuy"] += item.Price; + GameSavesData.Statistics[(gint)("buy_" + item.Name)]++; + GameSavesData.Statistics[(gdbe)"stat_betterbuy"] += item.Price; switch (item.Type) { case Food.FoodType.Food: - Set.Statistics[(gdbe)"stat_bb_food"] += item.Price; + GameSavesData.Statistics[(gdbe)"stat_bb_food"] += item.Price; break; case Food.FoodType.Drink: - Set.Statistics[(gdbe)"stat_bb_drink"] += item.Price; + GameSavesData.Statistics[(gdbe)"stat_bb_drink"] += item.Price; break; case Food.FoodType.Drug: - Set.Statistics[(gdbe)"stat_bb_drug"] += item.Price; + GameSavesData.Statistics[(gdbe)"stat_bb_drug"] += item.Price; break; case Food.FoodType.Snack: - Set.Statistics[(gdbe)"stat_bb_snack"] += item.Price; + GameSavesData.Statistics[(gdbe)"stat_bb_snack"] += item.Price; break; case Food.FoodType.Functional: - Set.Statistics[(gdbe)"stat_bb_functional"] += item.Price; + GameSavesData.Statistics[(gdbe)"stat_bb_functional"] += item.Price; break; case Food.FoodType.Meal: - Set.Statistics[(gdbe)"stat_bb_meal"] += item.Price; + GameSavesData.Statistics[(gdbe)"stat_bb_meal"] += item.Price; break; case Food.FoodType.Gift: - Set.Statistics[(gdbe)"stat_bb_gift"] += item.Price; + GameSavesData.Statistics[(gdbe)"stat_bb_gift"] += item.Price; break; } } @@ -533,7 +536,7 @@ namespace VPet_Simulator.Windows /// private void StatisticsCalHandle() { - var stat = Set.Statistics; + var stat = GameSavesData.Statistics; var save = Core.Save; stat["stat_money"] = save.Money; stat["stat_level"] = save.Level; @@ -588,23 +591,24 @@ namespace VPet_Simulator.Windows /// /// 加载游戏 /// - public bool GameLoad(ILine line) + public bool GameLoad(ILPS lps) { - if (line == null) + if (lps == null) return false; - if (string.IsNullOrWhiteSpace(line.ToString())) + if (string.IsNullOrWhiteSpace(lps.ToString())) return false; - - Core.Save = GameSave.Load(line); - - if (Core.Save.Money == 0 && Core.Save.Likability == 0 && Core.Save.Exp == 0 - && Core.Save.StrengthDrink == 0 && Core.Save.StrengthFood == 0)//数据全是0,可能是bug + GameSave_v2 tmp; + if (GameSavesData != null) + tmp = new GameSave_v2(lps, GameSavesData); + else + tmp = new GameSave_v2(lps, Set.Statistics_OLD); + if(tmp.GameSave == null) return false; - long hash = line.GetInt64("hash"); - if (line.Remove("hash")) - { - HashCheck = line.GetLongHashCode() == hash; - } + if (tmp.GameSave.Money == 0 && tmp.GameSave.Likability == 0 && tmp.GameSave.Exp == 0 + && tmp.GameSave.StrengthDrink == 0 && tmp.GameSave.StrengthFood == 0)//数据全是0,可能是bug + return false; + GameSavesData = tmp; + Core.Save = tmp.GameSave; return true; } private void Handle_Steam(Main obj) @@ -766,7 +770,6 @@ namespace VPet_Simulator.Windows public bool? CurrMusicType { get; private set; } int LastDiagnosisTime = 0; - private bool hashCheck = true; /// /// 上传遥测文件 diff --git a/VPet-Simulator.Windows/MainWindow.xaml.cs b/VPet-Simulator.Windows/MainWindow.xaml.cs index ca784e6..8f04f03 100644 --- a/VPet-Simulator.Windows/MainWindow.xaml.cs +++ b/VPet-Simulator.Windows/MainWindow.xaml.cs @@ -271,7 +271,7 @@ namespace VPet_Simulator.Windows { try { - if (GameLoad(new Line(File.ReadAllText(latestsave)))) + if (GameLoad(new LPS(File.ReadAllText(latestsave)))) return; MessageBoxX.Show("存档损毁,无法加载该存档\n可能是上次储存出错或Steam云同步导致的\n请在设置中加载备份还原存档", "存档损毁".Translate()); } @@ -412,7 +412,7 @@ namespace VPet_Simulator.Windows if (File.Exists(ExtensionValue.BaseDirectory + @"\Save.lps")) try { - if (!GameLoad(new LpsDocument(File.ReadAllText(ExtensionValue.BaseDirectory + @"\Save.lps")).First())) + if (!GameLoad(new LpsDocument(File.ReadAllText(ExtensionValue.BaseDirectory + @"\Save.lps")))) { //如果加载存档失败了,试试加载备份,如果没备份,就新建一个 LoadLatestSave(petloader.PetName); @@ -432,11 +432,11 @@ namespace VPet_Simulator.Windows AutoSaveTimer.Elapsed += AutoSaveTimer_Elapsed; - if (Set.Statistics[(gdbe)"stat_bb_food"] < 0 || Set.Statistics[(gdbe)"stat_bb_drink"] < 0 || Set.Statistics[(gdbe)"stat_bb_drug"] < 0 - || Set.Statistics[(gdbe)"stat_bb_snack"] < 0 || Set.Statistics[(gdbe)"stat_bb_functional"] < 0 || Set.Statistics[(gdbe)"stat_bb_meal"] < 0 - || Set.Statistics[(gdbe)"stat_bb_gift"] < 0) + if (GameSavesData.Statistics[(gdbe)"stat_bb_food"] < 0 || GameSavesData.Statistics[(gdbe)"stat_bb_drink"] < 0 || GameSavesData.Statistics[(gdbe)"stat_bb_drug"] < 0 + || GameSavesData.Statistics[(gdbe)"stat_bb_snack"] < 0 || GameSavesData.Statistics[(gdbe)"stat_bb_functional"] < 0 || GameSavesData.Statistics[(gdbe)"stat_bb_meal"] < 0 + || GameSavesData.Statistics[(gdbe)"stat_bb_gift"] < 0) { - hashCheck = false; + HashCheck = false; } if (Set.AutoSaveInterval > 0) @@ -465,7 +465,7 @@ namespace VPet_Simulator.Windows TranslateText = "关注 {0} 谢谢喵".Translate(SteamClient.Name) }); //Steam成就 - Set.Statistics.StatisticChanged += Statistics_StatisticChanged; + GameSavesData.Statistics.StatisticChanged += Statistics_StatisticChanged; //Steam通知 SteamFriends.SetRichPresence("username", Core.Save.Name); SteamFriends.SetRichPresence("mode", (Core.Save.Mode.ToString() + "ly").Translate()); @@ -720,13 +720,13 @@ namespace VPet_Simulator.Windows //成就和统计 - Set.Statistics[(gint)"stat_open_times"]++; + GameSavesData.Statistics[(gint)"stat_open_times"]++; Main.MoveTimer.Elapsed += MoveTimer_Elapsed; Main.OnSay += Main_OnSay; Main.Event_TouchHead += Main_Event_TouchHead; Main.Event_TouchBody += Main_Event_TouchBody; - HashCheck = hashCheck; + HashCheck = HashCheck; if (File.Exists(ExtensionValue.BaseDirectory + @"\Tutorial.html") && Set["SingleTips"].GetDateTime("tutorial") <= new DateTime(2023, 6, 20)) { @@ -798,22 +798,22 @@ namespace VPet_Simulator.Windows private void Main_Event_TouchBody() { - Set.Statistics[(gint)"stat_touch_body"]++; + GameSavesData.Statistics[(gint)"stat_touch_body"]++; } private void Main_Event_TouchHead() { - Set.Statistics[(gint)"stat_touch_head"]++; + GameSavesData.Statistics[(gint)"stat_touch_head"]++; } private void Main_OnSay(string obj) { - Set.Statistics[(gint)"stat_say_times"]++; + GameSavesData.Statistics[(gint)"stat_say_times"]++; } private void MoveTimer_Elapsed(object sender, ElapsedEventArgs e) { - Set.Statistics[(gint)"stat_move_length"] += (int)(Math.Abs(Main.MoveTimerPoint.X) + Math.Abs(Main.MoveTimerPoint.Y)); + GameSavesData.Statistics[(gint)"stat_move_length"] += (int)(Math.Abs(Main.MoveTimerPoint.X) + Math.Abs(Main.MoveTimerPoint.Y)); } private void AutoSaveTimer_Elapsed(object sender, ElapsedEventArgs e) diff --git a/VPet-Simulator.Windows/WinDesign/winGameSetting.xaml.cs b/VPet-Simulator.Windows/WinDesign/winGameSetting.xaml.cs index 2c154e1..bc18f58 100644 --- a/VPet-Simulator.Windows/WinDesign/winGameSetting.xaml.cs +++ b/VPet-Simulator.Windows/WinDesign/winGameSetting.xaml.cs @@ -857,12 +857,12 @@ namespace VPet_Simulator.Windows if (MessageBoxX.Show("该游戏随着开机启动该程序\r如需卸载游戏\r请关闭该选项".Translate() + "\n------\n" + "我已确认,并在卸载游戏前会关闭该功能".Translate(), "开机启动重要消息".Translate(), MessageBoxButton.YesNo, MessageBoxIcon.Warning) != MessageBoxResult.Yes) return; - //else - //{ - // mw.Set["SingleTips"][(gint)"open"] = 1; - // MessageBoxX.Show("游戏开机启动的实现方式是创建快捷方式,不是注册表,更健康,所以游戏卸了也不知道\n如果游戏打不开,可以去这里手动删除游戏开机启动快捷方式:\n%appdata%\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\".Translate() - // , "关于卸载不掉的问题是因为开启了开机启动".Translate(), MessageBoxIcon.Info); - //} + //else + //{ + // mw.Set["SingleTips"][(gint)"open"] = 1; + // MessageBoxX.Show("游戏开机启动的实现方式是创建快捷方式,不是注册表,更健康,所以游戏卸了也不知道\n如果游戏打不开,可以去这里手动删除游戏开机启动快捷方式:\n%appdata%\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\".Translate() + // , "关于卸载不掉的问题是因为开启了开机启动".Translate(), MessageBoxIcon.Info); + //} mw.Set.StartUPBoot = StartUpBox.IsChecked == true; GenStartUP(); @@ -1098,9 +1098,9 @@ namespace VPet_Simulator.Windows int reloadid = 0; private void CBSaveReLoad_MouseEnter(object sender, MouseEventArgs e) { - if (reloadid != mw.Set.Statistics[(gint)"savetimes"]) + if (reloadid != mw.GameSavesData.Statistics[(gint)"savetimes"]) { - reloadid = mw.Set.Statistics[(gint)"savetimes"]; + reloadid = mw.GameSavesData.Statistics[(gint)"savetimes"]; CBSaveReLoad.SelectedItem = null; CBSaveReLoad.Items.Clear(); if (Directory.Exists(ExtensionValue.BaseDirectory + @"\BackUP")) @@ -1128,10 +1128,10 @@ namespace VPet_Simulator.Windows { try { - var l = new Line(File.ReadAllText(path)); - GameSave gs = GameSave.Load(l); + var l = new LPS(File.ReadAllText(path)); + GameSave_v2 gs = new GameSave_v2(l); if (MessageBoxX.Show("存档名称:{0}\n存档等级:{1}\n存档金钱:{2}\n是否加载该备份存档? 当前游戏数据会丢失" - .Translate(gs.Name, gs.Level, gs.Money), "是否加载该备份存档? 当前游戏数据会丢失".Translate(), MessageBoxButton.YesNo, MessageBoxIcon.Info) == MessageBoxResult.Yes) + .Translate(gs.GameSave.Name, gs.GameSave.Level, gs.GameSave.Money), "是否加载该备份存档? 当前游戏数据会丢失".Translate(), MessageBoxButton.YesNo, MessageBoxIcon.Info) == MessageBoxResult.Yes) { try { @@ -1288,7 +1288,7 @@ namespace VPet_Simulator.Windows { mw.Core.Save = new GameSave(mw.Core.Save.Name); if (!mw.HashCheck) - mw.Set.Statistics = new Statistics(); + mw.GameSavesData.Statistics = new Statistics(); mw.HashCheck = true; CBSaveReLoad.IsEnabled = false; BtnSaveReload.IsEnabled = false;