chore(m2): 保存功能验收及后续清理前检查点

This commit is contained in:
Liubing\LB
2026-10-10 20:40:27 +08:00
parent d3c5394a55
commit 144e7f739f
110 changed files with 12672 additions and 7514 deletions

View File

@@ -1,11 +1,9 @@
#if UNITY_EDITOR
#if UNITY_EDITOR
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using UnityEditor;
using UnityEngine;
@@ -19,11 +17,36 @@ public static class KVGameplayLoopSetup
public static async System.Threading.Tasks.Task<string> RunValidationAsync(string caseId)
{
if(caseId!="equipment-chain" && caseId!="fishing-consume" && caseId!="fishing-reward") throw new ArgumentException("Unknown fixed validation case.");
string methodName;
switch (caseId)
{
case "equipment-chain":
methodName = "VerifyEquipmentForEditorAsync";
break;
case "fishing-consume":
methodName = "VerifyFishingForEditorAsync";
break;
case "fishing-reward":
methodName = "VerifyFishingRewardForEditorAsync";
break;
case "fishing-original-reward":
methodName = "VerifyOriginalFishingRewardForEditorAsync";
break;
case "fishing-original-consume":
methodName = "VerifyOriginalFishingForEditorAsync";
break;
default:
throw new ArgumentException("Unknown fixed validation case.");
}
if(EditorApplication.isPlayingOrWillChangePlaymode || EditorApplication.isCompiling || EditorApplication.isUpdating)
{
throw new InvalidOperationException("Idle editor required.");
var method=Find("PlayerKVGameplayLoop").GetMethod(caseId=="equipment-chain"?"VerifyEquipmentForEditorAsync":caseId=="fishing-consume"?"VerifyFishingForEditorAsync":"VerifyFishingRewardForEditorAsync",BindingFlags.Static|BindingFlags.NonPublic);
if(method==null) throw new InvalidOperationException("Fixed equipment validation entry unavailable.");
}
var method = Find("PlayerKVGameplayLoop").GetMethod(methodName, BindingFlags.Static | BindingFlags.NonPublic);
if (method == null)
{
throw new InvalidOperationException("Fixed equipment validation entry unavailable.");
}
return await (System.Threading.Tasks.Task<string>)method.Invoke(null,null);
}
@@ -37,17 +60,6 @@ public static class KVGameplayLoopSetup
processMarkers=Directory.Exists(history)?Directory.GetFiles(history,"*.claimed").Select(Path.GetFileName).OrderBy(x=>x).ToArray():Array.Empty<string>()});
}
public static string ValidatePermit(string path)
{
var type=Find("PlayerKVLoopPermit");
try
{
var permit=type.GetMethod("Read",BindingFlags.Static|BindingFlags.NonPublic).Invoke(null,new object[]{Path.GetFullPath(path)});
return JsonConvert.SerializeObject(permit);
}
catch(TargetInvocationException e) { throw e.InnerException ?? e; }
}
public static string InspectPFBackup(string path)
{
if(EditorApplication.isPlayingOrWillChangePlaymode || EditorApplication.isCompiling || EditorApplication.isUpdating)
@@ -57,29 +69,6 @@ public static class KVGameplayLoopSetup
catch(TargetInvocationException e) { throw e.InnerException ?? e; }
}
public static string PreparePermit(string account,string backupPath,string[] allowedKeys)
=> PreparePermitCore(account,backupPath,allowedKeys,false);
public static string PrepareFishingPermit(string account,string backupPath,string[] allowedKeys)
=> PreparePermitCore(account,backupPath,allowedKeys,true);
public static string PrepareFishingRewardPermit(string account,string backupPath,string[] allowedKeys)
=> PreparePermitCore(account,backupPath,allowedKeys,true,true);
static string PreparePermitCore(string account,string backupPath,string[] allowedKeys,bool fishing,bool reward=false)
{
if(EditorApplication.isPlayingOrWillChangePlaymode || EditorApplication.isCompiling)
throw new InvalidOperationException("Stop play before preparing a new process run.");
backupPath=Path.GetFullPath(backupPath);
var bytes=File.ReadAllBytes(backupPath);
string hash;
using(var sha=SHA256.Create()) hash=BitConverter.ToString(sha.ComputeHash(bytes)).Replace("-","");
var candidate=Path.Combine(Root,"permit.candidate.json");
Directory.CreateDirectory(Root);
var json=JObject.FromObject(new{Version=reward?3:fishing?2:1,Enabled=true,PlayerId=account,
Api="http://s101.local:18080/",BackupPath=backupPath,BackupSha256=hash,AllowedKeys=allowedKeys});
if(fishing) json["Operation"]=reward?"fishing-reward-once":"fishing-consume-once";
File.WriteAllText(candidate,json.ToString(Formatting.Indented));
var validated=ValidatePermit(candidate); // Empty/mismatched backups cannot enable a run.
File.WriteAllText(Path.Combine(Root,"permit.json"),validated);
return State();
}
}
#endif