ui基本完毕,修了一大把的bug

This commit is contained in:
FloatGaming
2026-07-13 02:28:39 +08:00
parent 1e20d73e90
commit fd22501f71
958 changed files with 378289 additions and 41038 deletions
@@ -12,7 +12,7 @@ public static class EquipmentConsumableLedgerStorage
private const string BackupFileName = ".eqc.bak";
private const string TempFileName = ".eqc.tmp";
private static string VaultDirectoryPath => Path.Combine(Application.persistentDataPath, VaultDirectoryName);
private static string VaultDirectoryPath => Path.Combine(SaveIdentityUtility.GetCanonicalPersistentRoot(), VaultDirectoryName);
private static string MainFilePath => Path.Combine(VaultDirectoryPath, MainFileName);
private static string BackupFilePath => Path.Combine(VaultDirectoryPath, BackupFileName);
private static string TempFilePath => Path.Combine(VaultDirectoryPath, TempFileName);
@@ -21,12 +21,18 @@ public static class EquipmentConsumableLedgerStorage
{
payload = CreateDefaultPayload();
if (TryReadPayload(MainFilePath, out payload))
if (TryReadPayloadFromVariants(MainFileName, out payload))
{
return true;
}
if (TryReadPayload(BackupFilePath, out payload))
if (TryReadPayloadFromVariants(BackupFileName, out payload))
{
TrySave(payload);
return true;
}
if (PlayerProgressBackupService.TryRestoreEquipmentConsumable(out payload))
{
TrySave(payload);
return true;
@@ -55,6 +61,7 @@ public static class EquipmentConsumableLedgerStorage
File.Copy(TempFilePath, MainFilePath, true);
TryHidePath(MainFilePath);
File.Delete(TempFilePath);
PlayerProgressBackupService.SaveEquipmentConsumable(payload);
return true;
}
catch (Exception ex)
@@ -91,17 +98,32 @@ public static class EquipmentConsumableLedgerStorage
return false;
}
var expectedSignature = ComputeSignature(envelope.payload);
if (!string.Equals(expectedSignature, envelope.signature, StringComparison.Ordinal))
if (!TryValidateSignature(envelope.payload, envelope.signature))
{
Debug.LogWarning("[EquipmentConsumableLedgerStorage] Save signature mismatch. Possible tampering detected.");
return false;
}
var encryptedBytes = Convert.FromBase64String(envelope.payload);
var plainBytes = XorTransform(encryptedBytes, BuildKeyBytes());
var payloadJson = Encoding.UTF8.GetString(plainBytes);
var loadedPayload = JsonUtility.FromJson<EquipmentConsumableLedgerPayload>(payloadJson);
EquipmentConsumableLedgerPayload loadedPayload = null;
var identifierVariants = SaveIdentityUtility.GetApplicationIdentifierVariants();
for (int i = 0; i < identifierVariants.Count; i++)
{
try
{
var plainBytes = XorTransform(encryptedBytes, BuildKeyBytes(identifierVariants[i]));
var payloadJson = Encoding.UTF8.GetString(plainBytes);
loadedPayload = JsonUtility.FromJson<EquipmentConsumableLedgerPayload>(payloadJson);
if (loadedPayload != null)
{
break;
}
}
catch
{
}
}
if (loadedPayload == null)
{
return false;
@@ -117,6 +139,21 @@ public static class EquipmentConsumableLedgerStorage
}
}
private static bool TryReadPayloadFromVariants(string fileName, out EquipmentConsumableLedgerPayload payload)
{
payload = CreateDefaultPayload();
var candidates = SaveIdentityUtility.GetVaultFilePathVariants(fileName);
for (int i = 0; i < candidates.Count; i++)
{
if (TryReadPayload(candidates[i], out payload))
{
return true;
}
}
return false;
}
private static string BuildEnvelopeJson(EquipmentConsumableLedgerPayload payload)
{
payload.lastUpdatedUtcTicks = DateTime.UtcNow.Ticks;
@@ -136,7 +173,7 @@ public static class EquipmentConsumableLedgerStorage
private static string ComputeSignature(string payloadBase64)
{
var signText = payloadBase64 + "|" + Application.identifier + "|" + SecretSeed + "|" + SystemInfo.deviceUniqueIdentifier;
var signText = payloadBase64 + "|" + SaveIdentityUtility.GetPrimaryApplicationIdentifier() + "|" + SecretSeed + "|" + SystemInfo.deviceUniqueIdentifier;
using (var sha = SHA256.Create())
{
var bytes = Encoding.UTF8.GetBytes(signText);
@@ -146,14 +183,45 @@ public static class EquipmentConsumableLedgerStorage
}
private static byte[] BuildKeyBytes()
{
return BuildKeyBytes(SaveIdentityUtility.GetPrimaryApplicationIdentifier());
}
private static byte[] BuildKeyBytes(string applicationIdentifier)
{
using (var sha = SHA256.Create())
{
var seed = Application.identifier + "|" + SystemInfo.deviceUniqueIdentifier + "|" + SecretSeed;
var seed = applicationIdentifier + "|" + SystemInfo.deviceUniqueIdentifier + "|" + SecretSeed;
return sha.ComputeHash(Encoding.UTF8.GetBytes(seed));
}
}
private static bool TryValidateSignature(string payloadBase64, string signature)
{
var identifierVariants = SaveIdentityUtility.GetApplicationIdentifierVariants();
for (int i = 0; i < identifierVariants.Count; i++)
{
var expectedSignature = ComputeSignature(payloadBase64, identifierVariants[i]);
if (string.Equals(expectedSignature, signature, StringComparison.Ordinal))
{
return true;
}
}
return false;
}
private static string ComputeSignature(string payloadBase64, string applicationIdentifier)
{
var signText = payloadBase64 + "|" + applicationIdentifier + "|" + SecretSeed + "|" + SystemInfo.deviceUniqueIdentifier;
using (var sha = SHA256.Create())
{
var bytes = Encoding.UTF8.GetBytes(signText);
var hash = sha.ComputeHash(bytes);
return Convert.ToBase64String(hash);
}
}
private static byte[] XorTransform(byte[] source, byte[] key)
{
var result = new byte[source.Length];