From 60f3fa84a32b53e069b594a6c90ffb357963c093 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 9 May 2020 09:39:35 -0700 Subject: [PATCH] Add more misc edits Closes #179 Not allowing people to import a jpeg. --- NHSE.Core/Save/Files/Personal.cs | 30 +++- NHSE.Core/Save/Offsets/PersonalOffsets.cs | 8 +- NHSE.Core/Save/Offsets/PersonalOffsets10.cs | 8 +- NHSE.Core/Save/Offsets/PersonalOffsets11.cs | 8 +- NHSE.Core/Save/Offsets/PersonalOffsets12.cs | 8 +- NHSE.Core/Structures/Misc/GSaveDate.cs | 13 +- NHSE.Core/Structures/Misc/GSaveDateMD.cs | 14 ++ NHSE.Tests/FancyMarshalTests.cs | 1 + .../Player/MiscPlayerEditor.Designer.cs | 130 ++++++++++++++++-- .../Subforms/Player/MiscPlayerEditor.cs | 8 +- 10 files changed, 209 insertions(+), 19 deletions(-) diff --git a/NHSE.Core/Save/Files/Personal.cs b/NHSE.Core/Save/Files/Personal.cs index 378f4f8..a54c002 100644 --- a/NHSE.Core/Save/Files/Personal.cs +++ b/NHSE.Core/Save/Files/Personal.cs @@ -130,9 +130,11 @@ public GSaveDateMD Birthday set => value.ToBytes().CopyTo(Data, Offsets.Birthday); } + #region Profile + public byte[] GetPhotoData() { - var offset = Offsets.Photo; + var offset = Offsets.ProfilePhoto; // Expect jpeg marker if (BitConverter.ToUInt16(Data, offset) != 0xD8FF) @@ -140,5 +142,31 @@ public byte[] GetPhotoData() var len = BitConverter.ToInt32(Data, offset - 4); return Data.Slice(offset, len); } + + public GSaveDateMD ProfileBirthday + { + get => Data.ToStructure(Offsets.ProfileBirthday, GSaveDateMD.SIZE); + set => value.ToBytes().CopyTo(Data, Offsets.ProfileBirthday); + } + + public ushort ProfileFruit + { + get => BitConverter.ToUInt16(Data, Offsets.ProfileFruit); + set => BitConverter.GetBytes(value).CopyTo(Data, Offsets.ProfileFruit); + } + + public GSaveDate ProfileTimestamp + { + get => Data.ToStructure(Offsets.ProfileTimestamp, GSaveDate.SIZE); + set => value.ToBytes().CopyTo(Data, Offsets.ProfileTimestamp); + } + + public bool ProfileIsMakeVillage + { + get => Data[Offsets.ProfileIsMakeVillage] != 0; + set => Data[Offsets.ProfileIsMakeVillage] = (byte)(value ? 1 : 0); + } + + #endregion } } \ No newline at end of file diff --git a/NHSE.Core/Save/Offsets/PersonalOffsets.cs b/NHSE.Core/Save/Offsets/PersonalOffsets.cs index 2241f40..8977e3b 100644 --- a/NHSE.Core/Save/Offsets/PersonalOffsets.cs +++ b/NHSE.Core/Save/Offsets/PersonalOffsets.cs @@ -14,7 +14,13 @@ public abstract class PersonalOffsets public abstract int NowPoint { get; } public abstract int TotalPoint { get; } public abstract int Birthday { get; } - public abstract int Photo { get; } + + public abstract int ProfileMain { get; } + public abstract int ProfilePhoto { get; } + public abstract int ProfileBirthday { get; } + public abstract int ProfileFruit { get; } + public abstract int ProfileTimestamp { get; } + public abstract int ProfileIsMakeVillage { get; } public abstract int Pockets1 { get; } public abstract int Pockets2 { get; } diff --git a/NHSE.Core/Save/Offsets/PersonalOffsets10.cs b/NHSE.Core/Save/Offsets/PersonalOffsets10.cs index 9a7e975..48d68df 100644 --- a/NHSE.Core/Save/Offsets/PersonalOffsets10.cs +++ b/NHSE.Core/Save/Offsets/PersonalOffsets10.cs @@ -17,8 +17,12 @@ public sealed class PersonalOffsets10 : PersonalOffsets public override int TotalPoint => NowPoint + 8; // Total Nook Miles Earned public override int Birthday => Player + 0x11478; - private const int GSaveNetPlayerProfile = Player + 0x11480; - public override int Photo => GSaveNetPlayerProfile + 0x24; + public override int ProfileMain => Player + 0x11488; + public override int ProfilePhoto => ProfileMain + 0x14; + public override int ProfileBirthday => ProfileMain + 0x23040; + public override int ProfileFruit => ProfileMain + 0x23044; + public override int ProfileTimestamp => ProfileMain + 0x230B4; + public override int ProfileIsMakeVillage => ProfileMain + 0x230B8; // end player diff --git a/NHSE.Core/Save/Offsets/PersonalOffsets11.cs b/NHSE.Core/Save/Offsets/PersonalOffsets11.cs index 3864918..19e6718 100644 --- a/NHSE.Core/Save/Offsets/PersonalOffsets11.cs +++ b/NHSE.Core/Save/Offsets/PersonalOffsets11.cs @@ -17,8 +17,12 @@ public sealed class PersonalOffsets11 : PersonalOffsets public override int TotalPoint => NowPoint + 8; // Total Nook Miles Earned public override int Birthday => Player + 0x11488; - private const int GSaveNetPlayerProfile = Player + 0x11490; - public override int Photo => GSaveNetPlayerProfile + 0x24; + public override int ProfileMain => Player + 0x114A0; + public override int ProfilePhoto => ProfileMain + 0x14; + public override int ProfileBirthday => ProfileMain + 0x23058; + public override int ProfileFruit => ProfileMain + 0x2305C; + public override int ProfileTimestamp => ProfileMain + 0x230CC; + public override int ProfileIsMakeVillage => ProfileMain + 0x230D0; // end player diff --git a/NHSE.Core/Save/Offsets/PersonalOffsets12.cs b/NHSE.Core/Save/Offsets/PersonalOffsets12.cs index 11b8bd7..21a29a2 100644 --- a/NHSE.Core/Save/Offsets/PersonalOffsets12.cs +++ b/NHSE.Core/Save/Offsets/PersonalOffsets12.cs @@ -17,8 +17,12 @@ public sealed class PersonalOffsets12 : PersonalOffsets public override int TotalPoint => NowPoint + 8; // Total Nook Miles Earned public override int Birthday => Player + 0x1168C; - private const int GSaveNetPlayerProfile = Player + 0x11690; - public override int Photo => GSaveNetPlayerProfile + 0x24; + public override int ProfileMain => Player + 0x116A0; + public override int ProfilePhoto => ProfileMain + 0x14; + public override int ProfileBirthday => ProfileMain + 0x23058; + public override int ProfileFruit => ProfileMain + 0x2305C; + public override int ProfileTimestamp => ProfileMain + 0x230CC; + public override int ProfileIsMakeVillage => ProfileMain + 0x230D0; // end player diff --git a/NHSE.Core/Structures/Misc/GSaveDate.cs b/NHSE.Core/Structures/Misc/GSaveDate.cs index 6e0b1ea..86e8447 100644 --- a/NHSE.Core/Structures/Misc/GSaveDate.cs +++ b/NHSE.Core/Structures/Misc/GSaveDate.cs @@ -1,4 +1,5 @@ -using System.ComponentModel; +using System; +using System.ComponentModel; using System.Runtime.InteropServices; #pragma warning disable CS8618, CA1815, CA1819, IDE1006 @@ -14,5 +15,15 @@ public struct GSaveDate public ushort Year { get; set; } public byte Month { get; set; } public byte Day { get; set; } + + private GSaveDate(int year, int month, int day) + { + Year = (ushort) year; + Month = (byte) month; + Day = (byte) day; + } + + public static implicit operator GSaveDate(DateTime dt) => new GSaveDate(dt.Year, dt.Month, dt.Day); + public static implicit operator DateTime(GSaveDate dt) => new DateTime(dt.Year, dt.Month, dt.Day); } } diff --git a/NHSE.Core/Structures/Misc/GSaveDateMD.cs b/NHSE.Core/Structures/Misc/GSaveDateMD.cs index 957a9a7..255b448 100644 --- a/NHSE.Core/Structures/Misc/GSaveDateMD.cs +++ b/NHSE.Core/Structures/Misc/GSaveDateMD.cs @@ -14,4 +14,18 @@ public struct GSaveDateMD public byte Month { get; set; } public byte Day { get; set; } } + + [StructLayout(LayoutKind.Sequential, Pack = 2)] + public struct GSavePlayerHandleName + { + public const int SIZE = 0xA; + + private ushort ModifierId { get; set; } + public byte ModifierLevel { get; set; } + + public ushort NounId { get; set; } + public byte NounLevel { get; set; } + public byte NounGenderType { get; set; } + public byte _fa0a936b { get; set; } + }; } diff --git a/NHSE.Tests/FancyMarshalTests.cs b/NHSE.Tests/FancyMarshalTests.cs index 42d5628..39914dc 100644 --- a/NHSE.Tests/FancyMarshalTests.cs +++ b/NHSE.Tests/FancyMarshalTests.cs @@ -19,6 +19,7 @@ public class FancyMarshalTests [Fact] public void MarshalGSaveRoomFloorWall() => MarshalBytesTestS(GSaveRoomFloorWall.SIZE); [Fact] public void MarshalGSaveManpu() => MarshalBytesTestS(GSavePlayerManpu.SIZE); + [Fact] public void MarshalGSavePlayerHandleName() => MarshalBytesTestS(GSavePlayerHandleName.SIZE); [Fact] public void MarshalGSaveFg() => MarshalBytesTest(GSaveFg.SIZE); private static void MarshalBytesTestS(int size) where T : struct diff --git a/NHSE.WinForms/Subforms/Player/MiscPlayerEditor.Designer.cs b/NHSE.WinForms/Subforms/Player/MiscPlayerEditor.Designer.cs index 2f4d8ab..15c1aad 100644 --- a/NHSE.WinForms/Subforms/Player/MiscPlayerEditor.Designer.cs +++ b/NHSE.WinForms/Subforms/Player/MiscPlayerEditor.Designer.cs @@ -33,14 +33,26 @@ private void InitializeComponent() this.L_Birthday = new System.Windows.Forms.Label(); this.NUD_BirthMonth = new System.Windows.Forms.NumericUpDown(); this.NUD_BirthDay = new System.Windows.Forms.NumericUpDown(); + this.tabControl1 = new System.Windows.Forms.TabControl(); + this.Tab_Misc = new System.Windows.Forms.TabPage(); + this.Tab_Profile = new System.Windows.Forms.TabPage(); + this.CAL_ProfileTimestamp = new System.Windows.Forms.DateTimePicker(); + this.CHK_ProfileMadeVillage = new System.Windows.Forms.CheckBox(); + this.L_ProfileSpecialtyFruit = new System.Windows.Forms.Label(); + this.NUD_ProfileFruit = new System.Windows.Forms.NumericUpDown(); + this.L_ProfileTimestamp = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.NUD_BirthMonth)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.NUD_BirthDay)).BeginInit(); + this.tabControl1.SuspendLayout(); + this.Tab_Misc.SuspendLayout(); + this.Tab_Profile.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_ProfileFruit)).BeginInit(); this.SuspendLayout(); // // B_Cancel // this.B_Cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.B_Cancel.Location = new System.Drawing.Point(272, 11); + this.B_Cancel.Location = new System.Drawing.Point(92, 156); this.B_Cancel.Name = "B_Cancel"; this.B_Cancel.Size = new System.Drawing.Size(72, 23); this.B_Cancel.TabIndex = 7; @@ -51,7 +63,7 @@ private void InitializeComponent() // B_Save // this.B_Save.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.B_Save.Location = new System.Drawing.Point(350, 11); + this.B_Save.Location = new System.Drawing.Point(170, 156); this.B_Save.Name = "B_Save"; this.B_Save.Size = new System.Drawing.Size(72, 23); this.B_Save.TabIndex = 6; @@ -61,7 +73,7 @@ private void InitializeComponent() // // L_Birthday // - this.L_Birthday.Location = new System.Drawing.Point(12, 9); + this.L_Birthday.Location = new System.Drawing.Point(6, 3); this.L_Birthday.Name = "L_Birthday"; this.L_Birthday.Size = new System.Drawing.Size(104, 23); this.L_Birthday.TabIndex = 8; @@ -71,7 +83,7 @@ private void InitializeComponent() // NUD_BirthMonth // this.NUD_BirthMonth.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.NUD_BirthMonth.Location = new System.Drawing.Point(122, 12); + this.NUD_BirthMonth.Location = new System.Drawing.Point(116, 6); this.NUD_BirthMonth.Name = "NUD_BirthMonth"; this.NUD_BirthMonth.Size = new System.Drawing.Size(37, 20); this.NUD_BirthMonth.TabIndex = 9; @@ -84,7 +96,7 @@ private void InitializeComponent() // NUD_BirthDay // this.NUD_BirthDay.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.NUD_BirthDay.Location = new System.Drawing.Point(165, 12); + this.NUD_BirthDay.Location = new System.Drawing.Point(159, 6); this.NUD_BirthDay.Name = "NUD_BirthDay"; this.NUD_BirthDay.Size = new System.Drawing.Size(37, 20); this.NUD_BirthDay.TabIndex = 10; @@ -94,16 +106,103 @@ private void InitializeComponent() 0, 0}); // + // tabControl1 + // + this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tabControl1.Controls.Add(this.Tab_Misc); + this.tabControl1.Controls.Add(this.Tab_Profile); + this.tabControl1.Location = new System.Drawing.Point(12, 12); + this.tabControl1.Name = "tabControl1"; + this.tabControl1.SelectedIndex = 0; + this.tabControl1.Size = new System.Drawing.Size(230, 138); + this.tabControl1.TabIndex = 12; + // + // Tab_Misc + // + this.Tab_Misc.Controls.Add(this.L_Birthday); + this.Tab_Misc.Controls.Add(this.NUD_BirthDay); + this.Tab_Misc.Controls.Add(this.NUD_BirthMonth); + this.Tab_Misc.Location = new System.Drawing.Point(4, 22); + this.Tab_Misc.Name = "Tab_Misc"; + this.Tab_Misc.Padding = new System.Windows.Forms.Padding(3); + this.Tab_Misc.Size = new System.Drawing.Size(222, 112); + this.Tab_Misc.TabIndex = 0; + this.Tab_Misc.Text = "Misc"; + this.Tab_Misc.UseVisualStyleBackColor = true; + // + // Tab_Profile + // + this.Tab_Profile.Controls.Add(this.CAL_ProfileTimestamp); + this.Tab_Profile.Controls.Add(this.CHK_ProfileMadeVillage); + this.Tab_Profile.Controls.Add(this.L_ProfileSpecialtyFruit); + this.Tab_Profile.Controls.Add(this.NUD_ProfileFruit); + this.Tab_Profile.Controls.Add(this.L_ProfileTimestamp); + this.Tab_Profile.Location = new System.Drawing.Point(4, 22); + this.Tab_Profile.Name = "Tab_Profile"; + this.Tab_Profile.Padding = new System.Windows.Forms.Padding(3); + this.Tab_Profile.Size = new System.Drawing.Size(222, 112); + this.Tab_Profile.TabIndex = 1; + this.Tab_Profile.Text = "Profile"; + this.Tab_Profile.UseVisualStyleBackColor = true; + // + // CAL_ProfileTimestamp + // + this.CAL_ProfileTimestamp.Location = new System.Drawing.Point(9, 22); + this.CAL_ProfileTimestamp.Name = "CAL_ProfileTimestamp"; + this.CAL_ProfileTimestamp.Size = new System.Drawing.Size(200, 20); + this.CAL_ProfileTimestamp.TabIndex = 16; + // + // CHK_ProfileMadeVillage + // + this.CHK_ProfileMadeVillage.AutoSize = true; + this.CHK_ProfileMadeVillage.Location = new System.Drawing.Point(9, 87); + this.CHK_ProfileMadeVillage.Name = "CHK_ProfileMadeVillage"; + this.CHK_ProfileMadeVillage.Size = new System.Drawing.Size(87, 17); + this.CHK_ProfileMadeVillage.TabIndex = 15; + this.CHK_ProfileMadeVillage.Text = "Made Village"; + this.CHK_ProfileMadeVillage.UseVisualStyleBackColor = true; + // + // L_ProfileSpecialtyFruit + // + this.L_ProfileSpecialtyFruit.AutoSize = true; + this.L_ProfileSpecialtyFruit.Location = new System.Drawing.Point(6, 45); + this.L_ProfileSpecialtyFruit.Name = "L_ProfileSpecialtyFruit"; + this.L_ProfileSpecialtyFruit.Size = new System.Drawing.Size(27, 13); + this.L_ProfileSpecialtyFruit.TabIndex = 14; + this.L_ProfileSpecialtyFruit.Text = "Fruit"; + // + // NUD_ProfileFruit + // + this.NUD_ProfileFruit.Location = new System.Drawing.Point(9, 61); + this.NUD_ProfileFruit.Maximum = new decimal(new int[] { + 65534, + 0, + 0, + 0}); + this.NUD_ProfileFruit.Name = "NUD_ProfileFruit"; + this.NUD_ProfileFruit.Size = new System.Drawing.Size(58, 20); + this.NUD_ProfileFruit.TabIndex = 13; + // + // L_ProfileTimestamp + // + this.L_ProfileTimestamp.AutoSize = true; + this.L_ProfileTimestamp.Location = new System.Drawing.Point(6, 6); + this.L_ProfileTimestamp.Name = "L_ProfileTimestamp"; + this.L_ProfileTimestamp.Size = new System.Drawing.Size(58, 13); + this.L_ProfileTimestamp.TabIndex = 12; + this.L_ProfileTimestamp.Text = "Timestamp"; + // // MiscPlayerEditor // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(434, 46); - this.Controls.Add(this.NUD_BirthDay); - this.Controls.Add(this.NUD_BirthMonth); - this.Controls.Add(this.L_Birthday); + this.ClientSize = new System.Drawing.Size(254, 191); + this.Controls.Add(this.tabControl1); this.Controls.Add(this.B_Cancel); this.Controls.Add(this.B_Save); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Icon = global::NHSE.WinForms.Properties.Resources.icon; this.MaximizeBox = false; this.MinimizeBox = false; @@ -112,6 +211,11 @@ private void InitializeComponent() this.Text = "Misc Player Detail Editor"; ((System.ComponentModel.ISupportInitialize)(this.NUD_BirthMonth)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.NUD_BirthDay)).EndInit(); + this.tabControl1.ResumeLayout(false); + this.Tab_Misc.ResumeLayout(false); + this.Tab_Profile.ResumeLayout(false); + this.Tab_Profile.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_ProfileFruit)).EndInit(); this.ResumeLayout(false); } @@ -123,5 +227,13 @@ private void InitializeComponent() private System.Windows.Forms.Label L_Birthday; private System.Windows.Forms.NumericUpDown NUD_BirthMonth; private System.Windows.Forms.NumericUpDown NUD_BirthDay; + private System.Windows.Forms.TabControl tabControl1; + private System.Windows.Forms.TabPage Tab_Misc; + private System.Windows.Forms.TabPage Tab_Profile; + private System.Windows.Forms.Label L_ProfileTimestamp; + private System.Windows.Forms.Label L_ProfileSpecialtyFruit; + private System.Windows.Forms.NumericUpDown NUD_ProfileFruit; + private System.Windows.Forms.CheckBox CHK_ProfileMadeVillage; + private System.Windows.Forms.DateTimePicker CAL_ProfileTimestamp; } } \ No newline at end of file diff --git a/NHSE.WinForms/Subforms/Player/MiscPlayerEditor.cs b/NHSE.WinForms/Subforms/Player/MiscPlayerEditor.cs index de4fe0a..ede8a6c 100644 --- a/NHSE.WinForms/Subforms/Player/MiscPlayerEditor.cs +++ b/NHSE.WinForms/Subforms/Player/MiscPlayerEditor.cs @@ -26,7 +26,9 @@ private void LoadPlayer() NUD_BirthDay.Value = bd.Day; NUD_BirthMonth.Value = bd.Month; - pers.Birthday = bd; + CHK_ProfileMadeVillage.Checked = pers.ProfileIsMakeVillage; + NUD_ProfileFruit.Value = pers.ProfileFruit; + CAL_ProfileTimestamp.Value = pers.ProfileTimestamp; } private void B_Cancel_Click(object sender, EventArgs e) => Close(); @@ -47,6 +49,10 @@ private void SavePlayer() bd.Month = (byte) NUD_BirthMonth.Value; pers.Birthday = bd; + pers.ProfileBirthday = bd; + pers.ProfileIsMakeVillage = CHK_ProfileMadeVillage.Checked; + pers.ProfileFruit = (ushort)NUD_ProfileFruit.Value; + pers.ProfileTimestamp = CAL_ProfileTimestamp.Value; } } }