Files
SPT-Server-Build/Libraries/SPTarkov.Server.Core/Migration/Migrations/HideoutSeed.cs
T
Jesse 533a7356fd Add new service to handle profile migrations (#468)
* Add new service to handle profile migrations

* Handle various null checks

* Remove unecessary assignments

* Further works on this:

- Loads profiles as JObject's initally, so migration can take place on profiles that don't have proper compatability
- Adds prerequisite migrations, and sorts them after one another

* Throw exception if profile can't be deserialized after migration

* Cleanup & use profile version

* Further migrations work, support 3.10 & 3.11 profiles upgrading to 4.0

* Update parameter name
2025-07-11 13:11:02 +01:00

61 lines
1.7 KiB
C#

using System.Security.Cryptography;
using System.Text.Json.Nodes;
using SPTarkov.DI.Annotations;
using Range = SemanticVersioning.Range;
namespace SPTarkov.Server.Core.Migration.Migrations
{
/// <summary>
/// In 0.16.1.3.35312 BSG changed this to from an int to a hex64 encoded value.
/// </summary>
[Injectable]
public class HideoutSeed : AbstractProfileMigration
{
public override string FromVersion
{
get { return "~3.10"; }
}
public override string ToVersion
{
get { return "3.11"; }
}
public override string MigrationName
{
get { return "HideoutSeed311-SPTSharp"; }
}
public override IEnumerable<Type> PrerequisiteMigrations
{
get { return []; }
}
public override bool CanMigrate(
JsonObject profile,
IEnumerable<IProfileMigration> previouslyRanMigrations
)
{
var profileVersion = GetProfileVersion(profile);
var fromRange = Range.Parse(FromVersion);
var versionMatches = fromRange.IsSatisfied(profileVersion);
var seedNode = profile["characters"]?["pmc"]?["Hideout"]?["Seed"];
var seedIsNumeric =
seedNode is JsonValue seedValue && seedValue.TryGetValue<long>(out _);
return versionMatches && seedIsNumeric;
}
public override JsonObject? Migrate(JsonObject profile)
{
profile["characters"]!["pmc"]!["Hideout"]!["Seed"] = Convert.ToHexStringLower(
RandomNumberGenerator.GetBytes(16)
);
return profile;
}
}
}