Add gen7 pickup editor

Thanks @Sciresm !
This commit is contained in:
Kurt
2017-04-12 21:30:49 -07:00
parent 86031d00da
commit 30770fbb20
6 changed files with 483 additions and 2 deletions

View File

@@ -117,6 +117,8 @@ public GARCReference getRelativeGARC(int offset, string name = "")
new GARCReference(155, "encounterstatic"),
new GARCReference(267, "pickup"),
new GARCReference(277, "maisonpkN"),
new GARCReference(278, "maisontrN"),
new GARCReference(279, "maisonpkS"),

View File

@@ -249,7 +249,7 @@ private void toggleSubEditors()
B_MoveTutor.Visible = Config.ORAS; // Default false unless loaded
break;
case 7:
romfs = new Control[] {B_GameText, B_StoryText, B_Personal, B_Evolution, B_LevelUp, B_Wild, B_MegaEvo, B_EggMove, B_Trainer, B_Item, B_Move, B_Maison, B_OWSE};
romfs = new Control[] {B_GameText, B_StoryText, B_Personal, B_Evolution, B_LevelUp, B_Wild, B_MegaEvo, B_EggMove, B_Trainer, B_Item, B_Move, B_Maison, B_Pickup, B_OWSE };
exefs = new Control[] {B_TMHM, B_TypeChart};
cro = new Control[] {B_Mart};
@@ -837,7 +837,16 @@ private void rebuildExeFS(object sender, EventArgs e)
private void B_Pickup_Click(object sender, EventArgs e)
{
if (threadActive()) return;
if (ExeFSPath != null) new PickupEditor6().Show();
switch (Config.Generation)
{
case 6:
if (ExeFSPath != null) new PickupEditor6().Show();
break;
case 7:
var pickup = Config.getlzGARCData("pickup");
Invoke((Action)(() => new PickupEditor7(pickup).ShowDialog()));
break;
}
}
private void B_TMHM_Click(object sender, EventArgs e)
{

View File

@@ -0,0 +1,137 @@
namespace pk3DS
{
partial class PickupEditor7
{
/// <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_Cancel = new System.Windows.Forms.Button();
this.B_Randomize = new System.Windows.Forms.Button();
this.dgvCommon = new System.Windows.Forms.DataGridView();
this.B_AddRow = new System.Windows.Forms.Button();
this.B_DeleteRow = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dgvCommon)).BeginInit();
this.SuspendLayout();
//
// 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(597, 331);
this.B_Save.Name = "B_Save";
this.B_Save.Size = new System.Drawing.Size(75, 23);
this.B_Save.TabIndex = 7;
this.B_Save.Text = "Save";
this.B_Save.UseVisualStyleBackColor = true;
this.B_Save.Click += new System.EventHandler(this.B_Save_Click);
//
// 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(516, 331);
this.B_Cancel.Name = "B_Cancel";
this.B_Cancel.Size = new System.Drawing.Size(75, 23);
this.B_Cancel.TabIndex = 8;
this.B_Cancel.Text = "Cancel";
this.B_Cancel.UseVisualStyleBackColor = true;
this.B_Cancel.Click += new System.EventHandler(this.B_Cancel_Click);
//
// B_Randomize
//
this.B_Randomize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.B_Randomize.Location = new System.Drawing.Point(9, 331);
this.B_Randomize.Name = "B_Randomize";
this.B_Randomize.Size = new System.Drawing.Size(75, 23);
this.B_Randomize.TabIndex = 9;
this.B_Randomize.Text = "Randomize";
this.B_Randomize.UseVisualStyleBackColor = true;
this.B_Randomize.Click += new System.EventHandler(this.B_Randomize_Click);
//
// dgvCommon
//
this.dgvCommon.AllowUserToResizeColumns = false;
this.dgvCommon.AllowUserToResizeRows = false;
this.dgvCommon.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.dgvCommon.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvCommon.Location = new System.Drawing.Point(12, 12);
this.dgvCommon.Name = "dgvCommon";
this.dgvCommon.Size = new System.Drawing.Size(656, 300);
this.dgvCommon.TabIndex = 10;
//
// B_AddRow
//
this.B_AddRow.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.B_AddRow.Location = new System.Drawing.Point(90, 331);
this.B_AddRow.Name = "B_AddRow";
this.B_AddRow.Size = new System.Drawing.Size(75, 23);
this.B_AddRow.TabIndex = 11;
this.B_AddRow.Text = "Add Row";
this.B_AddRow.UseVisualStyleBackColor = true;
this.B_AddRow.Click += new System.EventHandler(this.B_AddRow_Click);
//
// B_DeleteRow
//
this.B_DeleteRow.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.B_DeleteRow.Location = new System.Drawing.Point(171, 331);
this.B_DeleteRow.Name = "B_DeleteRow";
this.B_DeleteRow.Size = new System.Drawing.Size(75, 23);
this.B_DeleteRow.TabIndex = 12;
this.B_DeleteRow.Text = "Delete Row";
this.B_DeleteRow.UseVisualStyleBackColor = true;
this.B_DeleteRow.Click += new System.EventHandler(this.B_DeleteRow_Click);
//
// PickupEditor7
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(680, 361);
this.Controls.Add(this.B_DeleteRow);
this.Controls.Add(this.B_AddRow);
this.Controls.Add(this.dgvCommon);
this.Controls.Add(this.B_Randomize);
this.Controls.Add(this.B_Cancel);
this.Controls.Add(this.B_Save);
this.MaximizeBox = false;
this.MinimumSize = new System.Drawing.Size(600, 400);
this.Name = "PickupEditor7";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Pickup Editor";
((System.ComponentModel.ISupportInitialize)(this.dgvCommon)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button B_Save;
private System.Windows.Forms.Button B_Cancel;
private System.Windows.Forms.Button B_Randomize;
private System.Windows.Forms.DataGridView dgvCommon;
private System.Windows.Forms.Button B_AddRow;
private System.Windows.Forms.Button B_DeleteRow;
}
}

View File

@@ -0,0 +1,204 @@
using System;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace pk3DS
{
public partial class PickupEditor7 : Form
{
public PickupEditor7(lzGARCFile pickup)
{
InitializeComponent();
g_pickup = pickup;
var itemlist = Main.getText(TextName.ItemNames);
itemlist[0] = "";
items = itemlist.Select((v, i) => $"{v} - {i:000}").ToArray();
setupFLP();
byte[] data = pickup.Files[0];
getList(data);
}
private readonly lzGARCFile g_pickup;
private readonly string[] items;
private const int Columns = 10;
private void setupFLP()
{
dgvCommon.Columns.Clear();
// Add DataGrid
var dgv = dgvCommon;
{
dgv.AllowUserToAddRows = false;
dgv.AllowUserToDeleteRows = false;
dgv.AllowUserToResizeRows = false;
dgv.AllowUserToResizeColumns = false;
dgv.RowHeadersVisible = false;
//dgv.ColumnHeadersVisible = false,
dgv.MultiSelect = false;
dgv.ShowEditingIcon = false;
dgv.EditMode = DataGridViewEditMode.EditOnEnter;
dgv.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dgv.SelectionMode = DataGridViewSelectionMode.CellSelect;
dgv.CellBorderStyle = DataGridViewCellBorderStyle.None;
}
int c = 0;
DataGridViewComboBoxColumn dgvItemVal = new DataGridViewComboBoxColumn
{
HeaderText = "Item",
DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing,
DisplayIndex = c++,
Width = 135,
FlatStyle = FlatStyle.Flat
};
dgv.Columns.Add(dgvItemVal);
for (int i = 0; i < Columns; i++)
{
string rate = $"{i*10 + 1}-{(i + 1)*10}";
DataGridViewColumn dgvIndex = new DataGridViewTextBoxColumn();
{
dgvIndex.HeaderText = rate;
dgvIndex.DisplayIndex = c++;
dgvIndex.Width = 45;
dgvIndex.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
((DataGridViewTextBoxColumn)dgvIndex).MaxInputLength = 2;
}
dgv.Columns.Add(dgvIndex);
}
var combo = dgv.Columns[0] as DataGridViewComboBoxColumn;
foreach (var i in items)
combo.Items.Add(i); // add only the Item Names
// disable sorting
dgv.Columns.Cast<DataGridViewColumn>().ToList().ForEach(f => f.SortMode = DataGridViewColumnSortMode.NotSortable);
dgv.CancelEdit();
}
private void getList(byte[] data)
{
// Fill Data
int rows = BitConverter.ToUInt16(data, 0) - 1; // nice editor gamefreak
dgvCommon.Rows.Add(rows);
for (int i = 0; i < rows; i++)
{
int offset = 4 + i * (Columns + 2);
int item = BitConverter.ToUInt16(data, offset);
var r = dgvCommon.Rows[i];
r.Cells[0].Value = items[item];
for (int j = 0; j < Columns; j++)
{
int rate = data[offset + 2 + j];
r.Cells[1 + j].Value = rate.ToString();
}
}
}
private byte[] setList()
{
int rows = dgvCommon.RowCount;
int[][] rates = new int[rows][];
for (int i = 0; i < rates.Length; i++)
rates[i] = new int[Columns];
for (int i = 0; i < Columns; i++)
{
// get column sum
int sum = 0;
for (int r = 0; r < rows; r++)
{
var cell = dgvCommon.Rows[r].Cells[i+1];
int val;
if (!int.TryParse(cell.Value.ToString(), out val))
{
cell.Value = 0.ToString();
continue;
}
if (val > 100 || val < 0)
{
val = 0;
cell.Value = 0.ToString();
}
rates[r][i] = val;
sum += val;
}
if (sum == 100) // good
continue;
Util.Alert($"Sum of Column {i+1} needs to equal 100.", $"Got {sum}.");
return null;
}
using (var ms = new MemoryStream())
using (var bw = new BinaryWriter(ms))
{
bw.Write(rates.Length + 1); // nice editor gamefreak
for (int i = 0; i < rows; i++)
{
var r = dgvCommon.Rows[i];
string item = r.Cells[0].Value.ToString();
int itemindex = Array.IndexOf(items, item);
bw.Write((ushort)itemindex);
foreach (var b in rates[i])
bw.Write((byte)b);
}
return ms.ToArray();
}
}
private void B_Save_Click(object sender, EventArgs e)
{
byte[] result = setList();
if (result == null)
return;
g_pickup[0] = result;
g_pickup.Save();
Close();
}
private void B_Cancel_Click(object sender, EventArgs e)
{
Close();
}
private void B_Randomize_Click(object sender, EventArgs e)
{
if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNoCancel, "Randomize pickup lists?"))
return;
int[] validItems = Randomizer.getRandomItemList();
int ctr = 0;
Util.Shuffle(validItems);
for (int r = 0; r < dgvCommon.RowCount; r++)
{
dgvCommon.Rows[r].Cells[0].Value = items[validItems[ctr++]];
if (ctr <= validItems.Length) continue;
Util.Shuffle(validItems); ctr = 0;
}
}
private void B_AddRow_Click(object sender, EventArgs e)
{
if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Add a row at the bottom?"))
return;
int row = dgvCommon.RowCount;
dgvCommon.Rows.Add();
dgvCommon.Rows[row].Cells[0].Value = items[0];
for (int i = 1; i < dgvCommon.ColumnCount; i++)
dgvCommon.Rows[row].Cells[i].Value = 0.ToString();
}
private void B_DeleteRow_Click(object sender, EventArgs e)
{
if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Delete the bottom row?"))
return;
dgvCommon.Rows.RemoveAt(dgvCommon.RowCount - 1);
}
}
}

View 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>

View File

@@ -191,6 +191,12 @@
<Compile Include="Subforms\Gen7\PersonalEditor7.Designer.cs">
<DependentUpon>PersonalEditor7.cs</DependentUpon>
</Compile>
<Compile Include="Subforms\Gen7\PickupEditor7.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Subforms\Gen7\PickupEditor7.Designer.cs">
<DependentUpon>PickupEditor7.cs</DependentUpon>
</Compile>
<Compile Include="Subforms\Gen7\SMTE.cs">
<SubType>Form</SubType>
</Compile>
@@ -447,6 +453,9 @@
<EmbeddedResource Include="Subforms\Gen7\PersonalEditor7.resx">
<DependentUpon>PersonalEditor7.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Subforms\Gen7\PickupEditor7.resx">
<DependentUpon>PickupEditor7.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Subforms\Gen7\SMTE.resx">
<DependentUpon>SMTE.cs</DependentUpon>
</EmbeddedResource>