Skip to content

Commit

Permalink
Fixed crucial data saving issue.
Browse files Browse the repository at this point in the history
• Fixed issue prevent you from saving data due to the player velocity being reset whilst still writing data.
• Fixed doubles not being writted or read accurately.
  • Loading branch information
Nestorboy committed Aug 29, 2022
1 parent eb3eae7 commit ffbd46d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Assets/Nessie/Udon/NUSaveState/Scripts/U#/NUSaveState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ public void _SetData() // Write data by doing float additions.
}
else
{
localPlayer.SetVelocity(Vector3.zero);
SendCustomEventDelayedFrames(nameof(_VerifyData), 10);
}
}
Expand Down Expand Up @@ -376,6 +375,7 @@ public void _VerifyData()
}

// Continue if write was successful.
localPlayer.SetVelocity(Vector3.zero); // Reset velocity before finishing or changing avatar.
if (dataByteIndex + avatarByteOffset < bufferByteCount)
{
dataProgress = (float)(dataByteIndex + avatarByteOffset) / bufferByteCount;
Expand Down Expand Up @@ -945,7 +945,7 @@ private double __ReadBufferDouble(byte[] buffer)
if (normal) exp -= 1023;
else exp = -1022;

double result = frac / (double)(2 << 51);
double result = frac / (double)(2UL << 51);
if (normal) result += 1.0;

result *= Math.Pow(2, exp);
Expand Down Expand Up @@ -1000,7 +1000,7 @@ private int __WriteBufferDouble(double value, byte[] buffer, int index)
else exp = 0;

tmp |= Convert.ToUInt64(exp << 52) & _DOUBLE_EXP_MASK;
tmp |= Convert.ToUInt64(value * (2 << 51)) & _DOUBLE_FRAC_MASK;
tmp |= Convert.ToUInt64(value * (2UL << 51)) & _DOUBLE_FRAC_MASK;
}

return __WriteBufferUnsignedLong(tmp, buffer, index);
Expand Down

0 comments on commit ffbd46d

Please sign in to comment.