From 4ce324d8221efa033a8877c96f53eb48328f5f5e Mon Sep 17 00:00:00 2001 From: Miguel Terol Espino Date: Sat, 4 May 2024 20:50:29 +0200 Subject: [PATCH] Initiate Moves. Fix DPPt bug for ENcounters tab. --- DS_Map/DSPRE.csproj | 7 ++ DS_Map/Main Window.cs | 3 + DS_Map/MoveEditor.Designer.cs | 34 +++++++ DS_Map/MoveEditor.cs | 17 ++++ DS_Map/Properties/AssemblyInfo.cs | 8 +- DS_Map/ROMFiles/MoveFile.cs | 145 ++++++++++++++++++++++++++++++ 6 files changed, 210 insertions(+), 4 deletions(-) create mode 100644 DS_Map/MoveEditor.Designer.cs create mode 100644 DS_Map/MoveEditor.cs create mode 100644 DS_Map/ROMFiles/MoveFile.cs diff --git a/DS_Map/DSPRE.csproj b/DS_Map/DSPRE.csproj index 86d7dd3..8452f29 100644 --- a/DS_Map/DSPRE.csproj +++ b/DS_Map/DSPRE.csproj @@ -179,6 +179,12 @@ LearnsetEditor.cs + + Form + + + MoveEditor.cs + Form @@ -232,6 +238,7 @@ + diff --git a/DS_Map/Main Window.cs b/DS_Map/Main Window.cs index 1cfcaef..1fc2c45 100644 --- a/DS_Map/Main Window.cs +++ b/DS_Map/Main Window.cs @@ -692,6 +692,9 @@ namespace DSPRE { monEditorToolStripMenuItem.Enabled = true; scriptCommandsButton.Enabled = true; + if (!RomInfo.gameFamily.Equals(GameFamilies.HGSS)) { + mainTabControl.TabPages.Remove(tabPageEncountersEditor); + } Helpers.statusLabelMessage(); this.Text += " - " + RomInfo.fileName; } diff --git a/DS_Map/MoveEditor.Designer.cs b/DS_Map/MoveEditor.Designer.cs new file mode 100644 index 0000000..e859e04 --- /dev/null +++ b/DS_Map/MoveEditor.Designer.cs @@ -0,0 +1,34 @@ +namespace DSPRE { + partial class MoveEditor { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) { + if (disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "MoveEditor"; + } + + #endregion + } +} \ No newline at end of file diff --git a/DS_Map/MoveEditor.cs b/DS_Map/MoveEditor.cs new file mode 100644 index 0000000..451ea9c --- /dev/null +++ b/DS_Map/MoveEditor.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace DSPRE { + public partial class MoveEditor : Form { + public MoveEditor() { + InitializeComponent(); + } + } +} diff --git a/DS_Map/Properties/AssemblyInfo.cs b/DS_Map/Properties/AssemblyInfo.cs index c1ff88d..7b045be 100644 --- a/DS_Map/Properties/AssemblyInfo.cs +++ b/DS_Map/Properties/AssemblyInfo.cs @@ -4,11 +4,11 @@ using System.Runtime.InteropServices; // Le informazioni generali relative a un assembly sono controllate dal seguente // set di attributi. Modificare i valori di questi attributi per modificare le informazioni // associate a un assembly. -[assembly: AssemblyTitle("DSPRE Reloaded 1.12.2")] +[assembly: AssemblyTitle("DSPRE Reloaded 1.12.3")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("DSPRE Reloaded 1.12.2")] +[assembly: AssemblyProduct("DSPRE Reloaded 1.12.3")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -31,5 +31,5 @@ using System.Runtime.InteropServices; // È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build // usando l'asterisco '*' come illustrato di seguito: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.12.2")] -[assembly: AssemblyFileVersion("1.12.2")] +[assembly: AssemblyVersion("1.12.3")] +[assembly: AssemblyFileVersion("1.12.3")] diff --git a/DS_Map/ROMFiles/MoveFile.cs b/DS_Map/ROMFiles/MoveFile.cs new file mode 100644 index 0000000..f681eaf --- /dev/null +++ b/DS_Map/ROMFiles/MoveFile.cs @@ -0,0 +1,145 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DSPRE.ROMFiles { + + public enum MoveTypes : short { + Normal, + Fighting, + Flying, + Poison, + Ground, + Rock, + Bug, + Ghost, + Steel, + Unknown, + Fire, + Water, + Grass, + Electric, + Psychic, + Ice, + Dragon, + Dark + } + + public enum MoveCategory { + Physical, + Special, + Status + } + + public enum ContestCategories { + One = 1, + Two = 2, + Three = 3, + Four = 4, + Five = 5, + Six = 6, + Seven = 7, + Eight = 8, + Nine = 9, + Ten = 10, + Eleven = 11, + Twelve = 12 + } + + [Flags] + public enum MoveTargets { + OneOpponent = 1, + Automatic = 2, + Random = 4, + BothOpponents = 16, + BothOpponentsAndAlly = 8, + User = 32, + UsersSideOfField = 64, + EntireField = 128, + OpponentsSideOfField = 256, + AutomaticWithAlly = 512, + UserOrAlly = 1024, + OneOpponentFailsIfTargetFaints = 2048 + } + + + public struct MoveData { + public ushort Effect; // u16 + public byte Category; // u8 + public byte Power; // u8 + + public byte Type; // u8 + public byte Accuracy; // u8 + public byte PP; // u8 + public byte EffectChance; // u8 + + public ushort Target; // u16 + public sbyte Priority; // s8 + public bool[] Flags; // u8 + + public byte ContestEffect; // u8 + public byte ContestType; // u8 + } + + public class MoveFile : RomFile{ + + public MoveData moveData; + + public MoveFile(Stream stream) { + moveData = new MoveData(); + using (BinaryReader reader = new BinaryReader(stream)) { + moveData.Effect = reader.ReadUInt16(); + moveData.Category = reader.ReadByte(); + moveData.Power = reader.ReadByte(); + moveData.Type = reader.ReadByte(); + moveData.Accuracy = reader.ReadByte(); + moveData.PP = reader.ReadByte(); + moveData.EffectChance = reader.ReadByte(); + moveData.Target = reader.ReadUInt16(); + moveData.Priority = reader.ReadSByte(); + + // Reading flags + byte flagsByte = reader.ReadByte(); + moveData.Flags = new bool[8]; + for (int i = 0; i < 8; i++) { + moveData.Flags[i] = (flagsByte & (1 << i)) != 0; + } + + moveData.ContestEffect = reader.ReadByte(); + moveData.ContestType = reader.ReadByte(); + } + } + + public override byte[] ToByteArray() { + using (MemoryStream stream = new MemoryStream()) { + using (BinaryWriter writer = new BinaryWriter(stream)) { + writer.Write(moveData.Effect); + writer.Write(moveData.Category); + writer.Write(moveData.Power); + writer.Write(moveData.Type); + writer.Write(moveData.Accuracy); + writer.Write(moveData.PP); + writer.Write(moveData.EffectChance); + writer.Write(moveData.Target); + writer.Write(moveData.Priority); + + // Writing flags + byte flagsByte = 0; + for (int i = 0; i < 8; i++) { + if (moveData.Flags[i]) + flagsByte |= (byte)(1 << i); + } + writer.Write(flagsByte); + + writer.Write(moveData.ContestEffect); + writer.Write(moveData.ContestType); + } + + return stream.ToArray(); + } + } + } +}