mirror of
https://github.com/kwsch/pkNX.git
synced 2026-10-02 06:06:38 -05:00
Add TM editor
This commit is contained in:
45
pkNX.Game/Editors/TMEditorGG.cs
Normal file
45
pkNX.Game/Editors/TMEditorGG.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using pkNX.Containers;
|
||||
using pkNX.Structures;
|
||||
|
||||
namespace pkNX.Game
|
||||
{
|
||||
public class TMEditorGG
|
||||
{
|
||||
private readonly int Offset;
|
||||
private readonly NSO NSO;
|
||||
private readonly byte[] Data;
|
||||
|
||||
private const int count = 60;
|
||||
|
||||
public TMEditorGG(byte[] data)
|
||||
{
|
||||
NSO = new NSO(data);
|
||||
Data = NSO.DecompressedRO;
|
||||
|
||||
// tm list is stored immediately after TM item index list
|
||||
var pattern = CodePattern.TMHM_GG;
|
||||
Offset = CodePattern.IndexOfBytes(Data, pattern, 0x200_000);
|
||||
if (Valid)
|
||||
Offset += pattern.Length;
|
||||
}
|
||||
|
||||
public ushort[] GetMoves()
|
||||
{
|
||||
var moves = new ushort[count];
|
||||
for (int i = 0; i < moves.Length; i++)
|
||||
moves[i] = BitConverter.ToUInt16(Data, Offset + (2 * i));
|
||||
return moves;
|
||||
}
|
||||
|
||||
public void SetMoves(ushort[] finalMoves)
|
||||
{
|
||||
var result = finalMoves.SelectMany(BitConverter.GetBytes).ToArray();
|
||||
result.CopyTo(Data, Offset);
|
||||
}
|
||||
|
||||
public bool Valid => Offset > 0;
|
||||
public byte[] Write() => NSO.Write();
|
||||
}
|
||||
}
|
||||
@@ -168,12 +168,20 @@ public static int[] GetRandomItemList(GameVersion game)
|
||||
{080, new[] {760}}, // Slowbro @ Slowbronite
|
||||
};
|
||||
|
||||
public static int[] GetBannedMoves(GameVersion infoGame, IEnumerable<Move> moves)
|
||||
public static int[] GetBannedMoves(GameVersion infoGame, int moveCount)
|
||||
{
|
||||
if (!GameVersion.GG.Contains(infoGame))
|
||||
return Array.Empty<int>();
|
||||
|
||||
return Enumerable.Range(0, moves.Count()).Except(AllowedMovesGG).ToArray();
|
||||
return Enumerable.Range(0, moveCount).Except(AllowedMovesGG).ToArray();
|
||||
}
|
||||
|
||||
public static int[] GetAllowedMoves(GameVersion infoGame, int moveCount)
|
||||
{
|
||||
if (GameVersion.GG.Contains(infoGame))
|
||||
return AllowedMovesGG;
|
||||
|
||||
return Enumerable.Range(0, moveCount).ToArray();
|
||||
}
|
||||
|
||||
private static readonly int[] AllowedMovesGG =
|
||||
|
||||
@@ -243,5 +243,29 @@ public void EditShinyRate()
|
||||
nso.DecompressedText = shiny.Data;
|
||||
FileMitm.WriteAllBytes(path, nso.Write());
|
||||
}
|
||||
|
||||
public void EditTM()
|
||||
{
|
||||
var path = Path.Combine(ROM.PathExeFS, "main");
|
||||
var data = FileMitm.ReadAllBytes(path);
|
||||
var list = new TMEditorGG(data);
|
||||
if (!list.Valid)
|
||||
{
|
||||
WinFormsUtil.Alert("Not able to find tm data in exefs.");
|
||||
return;
|
||||
}
|
||||
|
||||
var moves = list.GetMoves();
|
||||
var allowed = Legal.GetAllowedMoves(ROM.Game, ROM.Data.MoveData.Length);
|
||||
var names = ROM.GetStrings(TextName.MoveNames);
|
||||
var editor = new TMList(moves, allowed, names);
|
||||
editor.ShowDialog();
|
||||
if (!editor.Modified)
|
||||
return;
|
||||
|
||||
list.SetMoves(editor.FinalMoves);
|
||||
data = list.Write();
|
||||
FileMitm.WriteAllBytes(path, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -535,7 +535,7 @@ private void B_Randomize_Click(object sender, EventArgs e)
|
||||
SaveEntry();
|
||||
var moves = Game.Data.MoveData.LoadAll();
|
||||
var rmove = new MoveRandomizer(Game.Info, moves, Personal);
|
||||
int[] banned = Legal.GetBannedMoves(Game.Info.Game, moves);
|
||||
int[] banned = Legal.GetBannedMoves(Game.Info.Game, moves.Length);
|
||||
rmove.Initialize((MovesetRandSettings)PG_Moves.SelectedObject, banned);
|
||||
var rspec = new SpeciesRandomizer(Game.Info, Personal);
|
||||
rspec.Initialize((SpeciesSettings)PG_Species.SelectedObject);
|
||||
|
||||
@@ -479,7 +479,7 @@ private void B_RandLearn_Click(object sender, EventArgs e)
|
||||
var settings = (LearnSettings)PG_Learn.SelectedObject;
|
||||
var rand = new LearnsetRandomizer(ROM.Info, Editor.Learn.LoadAll(), Editor.Personal);
|
||||
var moves = ROM.Data.MoveData.LoadAll();
|
||||
int[] banned = Legal.GetBannedMoves(ROM.Info.Game, moves);
|
||||
int[] banned = Legal.GetBannedMoves(ROM.Info.Game, moves.Length);
|
||||
rand.Initialize(moves, settings, EditUtil.Settings.Move, banned);
|
||||
rand.Execute();
|
||||
LoadIndex(CB_Species.SelectedIndex);
|
||||
|
||||
97
pkNX.WinForms/Subforms/TMList.Designer.cs
generated
Normal file
97
pkNX.WinForms/Subforms/TMList.Designer.cs
generated
Normal file
@@ -0,0 +1,97 @@
|
||||
namespace pkNX.WinForms
|
||||
{
|
||||
partial class TMList
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.B_Save = new System.Windows.Forms.Button();
|
||||
this.B_RTM = new System.Windows.Forms.Button();
|
||||
this.dgvTM = new System.Windows.Forms.DataGridView();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dgvTM)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// B_Save
|
||||
//
|
||||
this.B_Save.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.B_Save.Location = new System.Drawing.Point(185, 12);
|
||||
this.B_Save.Name = "B_Save";
|
||||
this.B_Save.Size = new System.Drawing.Size(60, 23);
|
||||
this.B_Save.TabIndex = 1;
|
||||
this.B_Save.Text = "Save";
|
||||
this.B_Save.UseVisualStyleBackColor = true;
|
||||
this.B_Save.Click += new System.EventHandler(this.B_Save_Click);
|
||||
//
|
||||
// B_RTM
|
||||
//
|
||||
this.B_RTM.Location = new System.Drawing.Point(12, 12);
|
||||
this.B_RTM.Name = "B_RTM";
|
||||
this.B_RTM.Size = new System.Drawing.Size(75, 23);
|
||||
this.B_RTM.TabIndex = 7;
|
||||
this.B_RTM.Text = "Randomize";
|
||||
this.B_RTM.UseVisualStyleBackColor = true;
|
||||
this.B_RTM.Click += new System.EventHandler(this.B_RTM_Click);
|
||||
//
|
||||
// dgvTM
|
||||
//
|
||||
this.dgvTM.AllowUserToAddRows = false;
|
||||
this.dgvTM.AllowUserToDeleteRows = false;
|
||||
this.dgvTM.AllowUserToResizeColumns = false;
|
||||
this.dgvTM.AllowUserToResizeRows = false;
|
||||
this.dgvTM.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.dgvTM.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dgvTM.Location = new System.Drawing.Point(12, 41);
|
||||
this.dgvTM.Name = "dgvTM";
|
||||
this.dgvTM.RowHeadersVisible = false;
|
||||
this.dgvTM.Size = new System.Drawing.Size(233, 333);
|
||||
this.dgvTM.TabIndex = 6;
|
||||
//
|
||||
// TMList
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(257, 386);
|
||||
this.Controls.Add(this.B_RTM);
|
||||
this.Controls.Add(this.dgvTM);
|
||||
this.Controls.Add(this.B_Save);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
|
||||
this.MaximizeBox = false;
|
||||
this.Name = "TMList";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||||
this.Text = "TM List";
|
||||
((System.ComponentModel.ISupportInitialize)(this.dgvTM)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
private System.Windows.Forms.Button B_Save;
|
||||
private System.Windows.Forms.Button B_RTM;
|
||||
private System.Windows.Forms.DataGridView dgvTM;
|
||||
}
|
||||
}
|
||||
97
pkNX.WinForms/Subforms/TMList.cs
Normal file
97
pkNX.WinForms/Subforms/TMList.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using pkNX.Game;
|
||||
using pkNX.Randomization;
|
||||
|
||||
namespace pkNX.WinForms
|
||||
{
|
||||
public sealed partial class TMList : Form
|
||||
{
|
||||
private readonly int[] AllowedMoves;
|
||||
private readonly string[] MoveNames;
|
||||
private readonly ushort[] OriginalMoves;
|
||||
|
||||
public TMList(ushort[] moves, int[] allowed, string[] movenames)
|
||||
{
|
||||
InitializeComponent();
|
||||
MoveNames = EditorUtil.SanitizeMoveList(movenames);
|
||||
AllowedMoves = allowed;
|
||||
SetupDGV(MoveNames);
|
||||
LoadMoves(moves);
|
||||
OriginalMoves = moves;
|
||||
}
|
||||
|
||||
public bool Modified { get; set; }
|
||||
public ushort[] FinalMoves { get; private set; }
|
||||
|
||||
private void SetupDGV(string[] list)
|
||||
{
|
||||
dgvTM.Columns.Clear();
|
||||
DataGridViewColumn dgvIndex = new DataGridViewTextBoxColumn();
|
||||
{
|
||||
dgvIndex.HeaderText = "Index";
|
||||
dgvIndex.DisplayIndex = 0;
|
||||
dgvIndex.Width = 45;
|
||||
dgvIndex.ReadOnly = true;
|
||||
dgvIndex.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
|
||||
dgvIndex.SortMode = DataGridViewColumnSortMode.NotSortable;
|
||||
}
|
||||
DataGridViewComboBoxColumn dgvMove = new DataGridViewComboBoxColumn();
|
||||
{
|
||||
dgvMove.HeaderText = "Move";
|
||||
dgvMove.DisplayIndex = 1;
|
||||
foreach (string t in list)
|
||||
dgvMove.Items.Add(t); // add only the Names
|
||||
|
||||
dgvMove.Width = 133;
|
||||
dgvMove.FlatStyle = FlatStyle.Flat;
|
||||
dgvIndex.SortMode = DataGridViewColumnSortMode.NotSortable;
|
||||
}
|
||||
dgvTM.Columns.Add(dgvIndex);
|
||||
dgvTM.Columns.Add(dgvMove);
|
||||
}
|
||||
|
||||
public void LoadMoves(ushort[] tmlist)
|
||||
{
|
||||
dgvTM.Rows.Clear();
|
||||
|
||||
for (int i = 0; i < tmlist.Length; i++)
|
||||
{
|
||||
dgvTM.Rows.Add();
|
||||
dgvTM.Rows[i].Cells[0].Value = (i + 1).ToString();
|
||||
dgvTM.Rows[i].Cells[1].Value = MoveNames[tmlist[i]];
|
||||
}
|
||||
}
|
||||
|
||||
public ushort[] SaveMoves()
|
||||
{
|
||||
ushort[] moves = new ushort[dgvTM.RowCount];
|
||||
for (int i = 0; i < moves.Length; i++)
|
||||
moves[i] = (ushort)Array.IndexOf(MoveNames, dgvTM.Rows[i].Cells[1].Value);
|
||||
|
||||
return moves;
|
||||
}
|
||||
|
||||
private void B_Save_Click(object sender, EventArgs e)
|
||||
{
|
||||
Modified = true;
|
||||
FinalMoves = SaveMoves();
|
||||
Close();
|
||||
}
|
||||
|
||||
private void B_RTM_Click(object sender, EventArgs e)
|
||||
{
|
||||
var moves = GetRandomMoves();
|
||||
LoadMoves(moves);
|
||||
System.Media.SystemSounds.Asterisk.Play();
|
||||
}
|
||||
|
||||
private ushort[] GetRandomMoves()
|
||||
{
|
||||
var allowed = AllowedMoves.Select(z => (ushort)z).Except(new ushort[] { 0 }).ToArray();
|
||||
var rand = new GenericRandomizer<ushort>(allowed);
|
||||
return rand.GetMany(OriginalMoves.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
120
pkNX.WinForms/Subforms/TMList.resx
Normal file
120
pkNX.WinForms/Subforms/TMList.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -89,6 +89,12 @@
|
||||
<Compile Include="Subforms\BTTE.designer.cs">
|
||||
<DependentUpon>BTTE.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Subforms\TMList.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Subforms\TMList.Designer.cs">
|
||||
<DependentUpon>TMList.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Subforms\ShinyRate.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
@@ -149,6 +155,9 @@
|
||||
<EmbeddedResource Include="Subforms\BTTE.resx">
|
||||
<DependentUpon>BTTE.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Subforms\TMList.resx">
|
||||
<DependentUpon>TMList.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Subforms\ShinyRate.resx">
|
||||
<DependentUpon>ShinyRate.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
||||
Reference in New Issue
Block a user