mirror of
https://github.com/kwsch/NHSE.git
synced 2026-07-02 00:11:55 -05:00
Fix identity swap when using span slices
Closes #684 Defensively allocate a copy so that the replacement does not overwrite the original sequence A=>B then continue doing B=>B swaps. Wasn't a problem before since properties fetched byte[] (allocated separate slice); changing to span introduced this regression -- now fixed.
This commit is contained in:
parent
ff4c77a06c
commit
db54e5ae1c
|
|
@ -77,6 +77,7 @@ public IEnumerable<FileHashRegion> GetInvalidHashes()
|
|||
|
||||
public void ChangeIdentity(ReadOnlySpan<byte> original, ReadOnlySpan<byte> updated)
|
||||
{
|
||||
original = original.ToArray(); // defensive allocation to ensure the sequence stays the same during replacement
|
||||
Main.Data.ReplaceOccurrences(original, updated);
|
||||
foreach (var pair in Players.SelectMany(z => z))
|
||||
pair.Data.ReplaceOccurrences(original, updated);
|
||||
|
|
|
|||
|
|
@ -40,14 +40,14 @@ public static void ChangeOrigins(this IVillagerOrigin visit, IVillagerOrigin hos
|
|||
private static void ChangeToHostTown(this IVillagerOrigin visit, IVillagerOrigin host, Span<byte> visitData)
|
||||
{
|
||||
var hostTown = host.GetTownIdentity();
|
||||
var visitTown = visit.GetTownIdentity();
|
||||
var visitTown = visit.GetTownIdentity().ToArray();
|
||||
visitData.ReplaceOccurrences(visitTown, hostTown);
|
||||
}
|
||||
|
||||
private static void ChangeToHostPlayer(this IVillagerOrigin visit, IVillagerOrigin host, Span<byte> visitData)
|
||||
{
|
||||
var hostPlayer = host.GetPlayerIdentity();
|
||||
var visitPlayer = visit.GetPlayerIdentity();
|
||||
var visitPlayer = visit.GetPlayerIdentity().ToArray();
|
||||
visitData.ReplaceOccurrences(visitPlayer, hostPlayer);
|
||||
}
|
||||
}
|
||||
|
|
@ -346,14 +346,14 @@ private void SavePlayer(int index)
|
|||
|
||||
if (pers.PlayerName != TB_Name.Text)
|
||||
{
|
||||
var orig = pers.GetPlayerIdentity();
|
||||
var orig = pers.GetPlayerIdentity().ToArray();
|
||||
pers.PlayerName = TB_Name.Text;
|
||||
var updated = pers.GetPlayerIdentity();
|
||||
SAV.ChangeIdentity(orig, updated);
|
||||
}
|
||||
if (pers.TownName != TB_TownName.Text)
|
||||
{
|
||||
var orig = pers.GetTownIdentity();
|
||||
var orig = pers.GetTownIdentity().ToArray();
|
||||
pers.TownName = TB_TownName.Text;
|
||||
var updated = pers.GetTownIdentity();
|
||||
SAV.ChangeIdentity(orig, updated);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user