Skip to content

Commit

Permalink
修复老版本vpet(v1.4-)hashcheck失效的错误
Browse files Browse the repository at this point in the history
  • Loading branch information
LorisYounger committed Feb 7, 2024
1 parent 8673d05 commit 22745eb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
26 changes: 23 additions & 3 deletions VPet-Simulator.Windows.Interface/GameSave_v2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
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
{
Expand All @@ -31,7 +33,7 @@ protected void load(ILPS lps, Statistics oldStatistics = null, GameSave oldGameS
{
if (lps.FindLine("statistics") == null)
{//尝试从老存档加载
Statistics = oldStatistics;
Statistics = oldStatistics ?? new Statistics();
}
else
{
Expand All @@ -42,12 +44,30 @@ protected void load(ILPS lps, Statistics oldStatistics = null, GameSave oldGameS
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)
Expand Down
2 changes: 1 addition & 1 deletion VPet-Simulator.Windows.Interface/Setting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public int AutoSaveInterval
/// </summary>
public int BackupSaveMaxNum
{
get => Math.Max(GetInt("bakupsave", 30), 1);
get => Math.Max(GetInt("bakupsave", 50), 1);
set => SetInt("bakupsave", value);
}
/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions VPet-Simulator.Windows/VPet-Simulator.Windows.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@
<Resource Include="Res\remixicon.ttf" />
<Resource Include="vpeticon.ico" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VPet-Simulator.Core\VPet-Simulator.Core.csproj" />
<ProjectReference Include="..\VPet-Simulator.Windows.Interface\VPet-Simulator.Windows.Interface.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
Expand Down Expand Up @@ -242,4 +238,8 @@
<PackageReference Include="Panuon.WPF" Version="1.0.3" />
<PackageReference Include="Panuon.WPF.UI" Version="1.1.16.8" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VPet-Simulator.Core\VPet-Simulator.Core.csproj" />
<ProjectReference Include="..\VPet-Simulator.Windows.Interface\VPet-Simulator.Windows.Interface.csproj" />
</ItemGroup>
</Project>

0 comments on commit 22745eb

Please sign in to comment.