From 8e28ca8cf4ae1c31c060b94a79af36760a0b37a5 Mon Sep 17 00:00:00 2001 From: abcboy101 <16735361+abcboy101@users.noreply.github.com> Date: Fri, 3 Nov 2023 06:32:45 +0800 Subject: [PATCH] Fix Gen 7 map position (#4049) * Prevent UpdateOverworldCoordinates from corrupting FieldMoveModelSave * Fix Gen 7 player coordinates * Fix Gen 7 player rotation --- .../Substructures/Gen7/FieldMoveModelSave7.cs | 11 +++++++---- PKHeX.Core/Saves/Substructures/Gen7/Situation7.cs | 15 ++++++++++----- .../Subforms/Save Editors/Gen7/SAV_Trainer7.cs | 6 ++++-- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/PKHeX.Core/Saves/Substructures/Gen7/FieldMoveModelSave7.cs b/PKHeX.Core/Saves/Substructures/Gen7/FieldMoveModelSave7.cs index ee5f5af1e..8edb7edac 100644 --- a/PKHeX.Core/Saves/Substructures/Gen7/FieldMoveModelSave7.cs +++ b/PKHeX.Core/Saves/Substructures/Gen7/FieldMoveModelSave7.cs @@ -8,9 +8,12 @@ public sealed class FieldMoveModelSave7 : SaveBlock public FieldMoveModelSave7(SAV7SM sav, int offset) : base(sav) => Offset = offset; public FieldMoveModelSave7(SAV7USUM sav, int offset) : base(sav) => Offset = offset; - public int M { get => ReadUInt16LittleEndian(Data.AsSpan(Offset + 0x00)); set => WriteUInt16LittleEndian(Data.AsSpan(Offset + 0x00), (ushort)value); } + //public int Unknown { get => ReadUInt16LittleEndian(Data.AsSpan(Offset + 0x00)); set => WriteUInt16LittleEndian(Data.AsSpan(Offset + 0x00), (ushort)value); } // related to Ride Pokemon public float X { get => ReadSingleLittleEndian(Data.AsSpan(Offset + 0x08)); set => WriteSingleLittleEndian(Data.AsSpan(Offset + 0x08), value); } - public float Z { get => ReadSingleLittleEndian(Data.AsSpan(Offset + 0x10)); set => WriteSingleLittleEndian(Data.AsSpan(Offset + 0x10), value); } - public float Y { get => (int)ReadSingleLittleEndian(Data.AsSpan(Offset + 0x18)); set => WriteSingleLittleEndian(Data.AsSpan(Offset + 0x18), value); } - public float R { get => (int)ReadSingleLittleEndian(Data.AsSpan(Offset + 0x20)); set => WriteSingleLittleEndian(Data.AsSpan(Offset + 0x20), value); } + public float Z { get => ReadSingleLittleEndian(Data.AsSpan(Offset + 0x0C)); set => WriteSingleLittleEndian(Data.AsSpan(Offset + 0x0C), value); } + public float Y { get => ReadSingleLittleEndian(Data.AsSpan(Offset + 0x10)); set => WriteSingleLittleEndian(Data.AsSpan(Offset + 0x10), value); } + public float RX { get => ReadSingleLittleEndian(Data.AsSpan(Offset + 0x14)); set => WriteSingleLittleEndian(Data.AsSpan(Offset + 0x14), value); } + public float RZ { get => ReadSingleLittleEndian(Data.AsSpan(Offset + 0x18)); set => WriteSingleLittleEndian(Data.AsSpan(Offset + 0x18), value); } + public float RY { get => ReadSingleLittleEndian(Data.AsSpan(Offset + 0x1C)); set => WriteSingleLittleEndian(Data.AsSpan(Offset + 0x1C), value); } + public float RW { get => ReadSingleLittleEndian(Data.AsSpan(Offset + 0x20)); set => WriteSingleLittleEndian(Data.AsSpan(Offset + 0x20), value); } } diff --git a/PKHeX.Core/Saves/Substructures/Gen7/Situation7.cs b/PKHeX.Core/Saves/Substructures/Gen7/Situation7.cs index 1410f0464..490a354ee 100644 --- a/PKHeX.Core/Saves/Substructures/Gen7/Situation7.cs +++ b/PKHeX.Core/Saves/Substructures/Gen7/Situation7.cs @@ -10,18 +10,23 @@ public sealed class Situation7 : SaveBlock // "StartLocation" public int M { get => ReadUInt16LittleEndian(Data.AsSpan(Offset + 0x00)); set => WriteUInt16LittleEndian(Data.AsSpan(Offset + 0x00), (ushort)value); } public float X { get => ReadSingleLittleEndian(Data.AsSpan(Offset + 0x08)); set => WriteSingleLittleEndian(Data.AsSpan(Offset + 0x08), value); } - public float Z { get => ReadSingleLittleEndian(Data.AsSpan(Offset + 0x10)); set => WriteSingleLittleEndian(Data.AsSpan(Offset + 0x10), value); } - public float Y { get => (int)ReadSingleLittleEndian(Data.AsSpan(Offset + 0x18)); set => WriteSingleLittleEndian(Data.AsSpan(Offset + 0x18), value); } - public float R { get => (int)ReadSingleLittleEndian(Data.AsSpan(Offset + 0x20)); set => WriteSingleLittleEndian(Data.AsSpan(Offset + 0x20), value); } + public float Z { get => ReadSingleLittleEndian(Data.AsSpan(Offset + 0x0C)); set => WriteSingleLittleEndian(Data.AsSpan(Offset + 0x0C), value); } + public float Y { get => ReadSingleLittleEndian(Data.AsSpan(Offset + 0x10)); set => WriteSingleLittleEndian(Data.AsSpan(Offset + 0x10), value); } + public float RX { get => ReadSingleLittleEndian(Data.AsSpan(Offset + 0x14)); set => WriteSingleLittleEndian(Data.AsSpan(Offset + 0x14), value); } + public float RZ { get => ReadSingleLittleEndian(Data.AsSpan(Offset + 0x18)); set => WriteSingleLittleEndian(Data.AsSpan(Offset + 0x18), value); } + public float RY { get => ReadSingleLittleEndian(Data.AsSpan(Offset + 0x1C)); set => WriteSingleLittleEndian(Data.AsSpan(Offset + 0x1C), value); } + public float RW { get => ReadSingleLittleEndian(Data.AsSpan(Offset + 0x20)); set => WriteSingleLittleEndian(Data.AsSpan(Offset + 0x20), value); } public void UpdateOverworldCoordinates() { var o = SAV.Overworld; - o.M = M; o.X = X; o.Z = Z; o.Y = Y; - o.R = R; + o.RX = RX; + o.RZ = RZ; + o.RY = RY; + o.RW = RW; } public int SpecialLocation diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs index d3bb26ba0..6b76010f3 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs @@ -129,7 +129,7 @@ public partial class SAV_Trainer7 : Form NUD_X.Value = (decimal)SAV.Situation.X; NUD_Z.Value = (decimal)SAV.Situation.Z; NUD_Y.Value = (decimal)SAV.Situation.Y; - NUD_R.Value = (decimal)SAV.Situation.R; + NUD_R.Value = (decimal)(Math.Atan2(SAV.Situation.RZ, SAV.Situation.RW) * 360.0 / Math.PI); } // Sometimes the coordinates aren't really decimal/float coordinates? catch { GB_Map.Enabled = false; } @@ -343,7 +343,9 @@ public partial class SAV_Trainer7 : Form SAV.Situation.X = (float)NUD_X.Value; SAV.Situation.Z = (float)NUD_Z.Value; SAV.Situation.Y = (float)NUD_Y.Value; - SAV.Situation.R = (float)NUD_R.Value; + var angle = (double)NUD_R.Value * Math.PI / 360.0; + SAV.Situation.RZ = (float)Math.Sin(angle); + SAV.Situation.RW = (float)Math.Cos(angle); SAV.Situation.UpdateOverworldCoordinates(); }