支持存档Hash检查

This commit is contained in:
ZouJin 2023-08-06 12:00:03 +10:00
parent 20877c9843
commit a2ad158ea7
4 changed files with 29 additions and 13 deletions

View File

@ -98,6 +98,11 @@ namespace VPet_Simulator.Windows.Interface
/// 鼠标穿透
/// </summary>
bool MouseHitThrough { get; set; }
/// <summary>
/// 存档 Hash检查 是否通过
/// </summary>
bool HashCheck { get; }
}
}

View File

@ -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<LowText> LowFoodText { get; set; } = new List<LowText>();
public List<LowText> LowDrinkText { get; set; } = new List<LowText>();
/// <summary>
/// 存档 Hash检查 是否通过
/// </summary>
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;
}
}
}
}

View File

@ -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();

View File

@ -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);
}
}
}