- Fixed memory link checksums offsets and has to be calculated after encrypting.

- Randomize encryption seed for no data/BW import

Release: 2016619_15156
This commit is contained in:
suloku
2016-06-19 16:19:01 +02:00
parent 8bdeb025bb
commit f7db2f8dd5
3 changed files with 149 additions and 29 deletions

View File

@@ -41,6 +41,9 @@ namespace BW_tool
private System.Windows.Forms.CheckBox flag1;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button import_bw1;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
/// <summary>
/// Disposes resources used by the form.
@@ -90,6 +93,9 @@ namespace BW_tool
this.flag1 = new System.Windows.Forms.CheckBox();
this.label4 = new System.Windows.Forms.Label();
this.import_bw1 = new System.Windows.Forms.Button();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.sid)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.tid)).BeginInit();
@@ -117,7 +123,7 @@ namespace BW_tool
//
// b1_export
//
this.b1_export.Location = new System.Drawing.Point(16, 19);
this.b1_export.Location = new System.Drawing.Point(6, 19);
this.b1_export.Name = "b1_export";
this.b1_export.Size = new System.Drawing.Size(119, 37);
this.b1_export.TabIndex = 22;
@@ -127,7 +133,7 @@ namespace BW_tool
//
// b1m_export
//
this.b1m_export.Location = new System.Drawing.Point(16, 62);
this.b1m_export.Location = new System.Drawing.Point(6, 62);
this.b1m_export.Name = "b1m_export";
this.b1m_export.Size = new System.Drawing.Size(119, 37);
this.b1m_export.TabIndex = 23;
@@ -137,7 +143,7 @@ namespace BW_tool
//
// b2_export
//
this.b2_export.Location = new System.Drawing.Point(16, 105);
this.b2_export.Location = new System.Drawing.Point(6, 105);
this.b2_export.Name = "b2_export";
this.b2_export.Size = new System.Drawing.Size(119, 37);
this.b2_export.TabIndex = 24;
@@ -147,7 +153,7 @@ namespace BW_tool
//
// b2_import
//
this.b2_import.Location = new System.Drawing.Point(141, 105);
this.b2_import.Location = new System.Drawing.Point(131, 105);
this.b2_import.Name = "b2_import";
this.b2_import.Size = new System.Drawing.Size(119, 37);
this.b2_import.TabIndex = 27;
@@ -157,7 +163,7 @@ namespace BW_tool
//
// b1m_import
//
this.b1m_import.Location = new System.Drawing.Point(141, 62);
this.b1m_import.Location = new System.Drawing.Point(131, 62);
this.b1m_import.Name = "b1m_import";
this.b1m_import.Size = new System.Drawing.Size(119, 37);
this.b1m_import.TabIndex = 26;
@@ -167,7 +173,7 @@ namespace BW_tool
//
// b1_import
//
this.b1_import.Location = new System.Drawing.Point(141, 19);
this.b1_import.Location = new System.Drawing.Point(131, 19);
this.b1_import.Name = "b1_import";
this.b1_import.Size = new System.Drawing.Size(119, 37);
this.b1_import.TabIndex = 25;
@@ -203,9 +209,9 @@ namespace BW_tool
this.groupBox1.Controls.Add(this.b2_export);
this.groupBox1.Controls.Add(this.b1m_export);
this.groupBox1.Controls.Add(this.b1_export);
this.groupBox1.Location = new System.Drawing.Point(359, 149);
this.groupBox1.Location = new System.Drawing.Point(391, 149);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(288, 156);
this.groupBox1.Size = new System.Drawing.Size(256, 156);
this.groupBox1.TabIndex = 30;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Research Purposes";
@@ -270,7 +276,7 @@ namespace BW_tool
//
this.flag8.Location = new System.Drawing.Point(205, 247);
this.flag8.Name = "flag8";
this.flag8.Size = new System.Drawing.Size(125, 29);
this.flag8.Size = new System.Drawing.Size(164, 29);
this.flag8.TabIndex = 44;
this.flag8.Text = "flag 8";
this.flag8.UseVisualStyleBackColor = true;
@@ -342,9 +348,9 @@ namespace BW_tool
//
this.label4.Location = new System.Drawing.Point(12, 151);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(128, 19);
this.label4.Size = new System.Drawing.Size(306, 19);
this.label4.TabIndex = 45;
this.label4.Text = "Unlocked Memories:";
this.label4.Text = "Unlocked Memories: (still under research, better not to touch)";
this.label4.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
//
// import_bw1
@@ -357,11 +363,38 @@ namespace BW_tool
this.import_bw1.UseVisualStyleBackColor = true;
this.import_bw1.Click += new System.EventHandler(this.Import_bw1Click);
//
// label5
//
this.label5.Location = new System.Drawing.Point(398, 24);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(147, 37);
this.label5.TabIndex = 47;
this.label5.Text = "Will import:";
//
// label6
//
this.label6.Location = new System.Drawing.Point(465, 18);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(132, 23);
this.label6.TabIndex = 48;
this.label6.Text = "- Trainer name, TID, SID";
//
// label7
//
this.label7.Location = new System.Drawing.Point(465, 32);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(132, 23);
this.label7.TabIndex = 49;
this.label7.Text = "- Hall of Fame";
//
// MemoryLink
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(659, 317);
this.Controls.Add(this.label7);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.import_bw1);
this.Controls.Add(this.label4);
this.Controls.Add(this.flag8);

View File

@@ -20,12 +20,14 @@ namespace BW_tool
public partial class MemoryLink : Form
{
MEMORIES ml;
Random rand;
public MemoryLink()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
rand = new Random(Guid.NewGuid().GetHashCode());
ml = new MEMORIES (MainForm.save.getData(MEMORIES.Offset, MEMORIES.Size));
@@ -43,6 +45,14 @@ namespace BW_tool
ml.block2.name = "PPorg";
ml.block2.TID = 25560;
ml.block2.SID = 13453;
UInt32 newseed = (UInt32)(rand.Next(0xFFFF+1)<<16);
ml.block1.crypt_seed = newseed;
ml.block1_mirror.crypt_seed = newseed;
//Needed so export memory doesn't export my own data (default_memories)
load_data();
set_data();
}
load_data();
@@ -202,6 +212,10 @@ namespace BW_tool
ml.block2.set_hof(bw1.Skip(0x23B00).Take(0x168).ToArray());
UInt32 newseed = (UInt32)(rand.Next(0xFFFF+1)<<16);
ml.block1.crypt_seed = newseed;
ml.block1_mirror.crypt_seed = newseed;
//Reload all data
load_data();
@@ -254,29 +268,94 @@ namespace BW_tool
public void set_blocks()
{
//Recalculate CRCs
ushort crc = SAV5.ccitt16(block1.Data.Skip(0xC).Take(0x368).ToArray());
block1.crc = crc;
ushort crc_mirror = SAV5.ccitt16(block1_mirror.Data.Skip(0xC).Take(0x368).ToArray());
block1_mirror.crc = crc_mirror;
ushort crc2 = SAV5.ccitt16(block2.Data.Skip(0xC).Take(0x214).ToArray());
block2.crc = crc2;
//Recrypt blocks
//Block 1
//Recrypt
byte[] encrypt1 = new byte[ML_BLOCK1.Size];
//byte[] encrypt2 = new byte[ML_BLOCK2.Size];
encrypt1 = SAV5.cryptoArray(block1.Data, 0xC, 0x364, 0x374-4);
//encrypt2 = SAV5.cryptoArray(block2.Data, ML_BLOCK1.Size), 0, 0x374-4, 0x374-4);
//Recalculate CRC
ushort crc = SAV5.ccitt16(encrypt1.Skip(0xC).Take(0x368).ToArray());
BitConverter.GetBytes(crc).CopyTo(encrypt1, 0x8);
//Set new data
setData(encrypt1, 0);
setData(encrypt1, 0x400); //Block 1 mirror, we'll edit just the not mirrored one
//setData(encrypt2, 0x400);
//Block 1 Mirror
//Just put block 1 for now as mirror
setData(encrypt1, 0x400);
/*
//Recrypt
byte[] encrypt_mirror = new byte[ML_BLOCK1.Size];
encrypt_mirror = SAV5.cryptoArray(block1_mirror.Data, 0xC, 0x364, 0x374-4);
//Recalculate CRC
ushort crc_mirror = SAV5.ccitt16(encrypt_mirror.Skip(0xC).Take(0x368).ToArray());
BitConverter.GetBytes(crc_mirror).CopyTo(encrypt_mirror, 0x8);
//Set new data
setData(encrypt_mirror, 0x400);
*/
//Block 2
//Recalculate CRC
ushort crc2 = SAV5.ccitt16(block2.Data.Skip(0xC).Take(0x214).ToArray());
block2.crc = crc2;
//Set new data
setData(block2.Data, 0x800);
}
public ushort block1_crc
{
get
{
return BitConverter.ToUInt16(Data, 0x8);
}
set
{
setData(BitConverter.GetBytes((UInt16)value), 0x8);
}
}
public UInt32 block1_crypt_seed
{
get
{
return BitConverter.ToUInt32(Data, 0x370);
}
set
{
setData(BitConverter.GetBytes((UInt32)value), 0x370);
}
}
public ushort block1_mirror_crc
{
get
{
return BitConverter.ToUInt16(Data, 0x400+0x8);
}
set
{
setData(BitConverter.GetBytes((UInt16)value), 0x400+0x8);
}
}
public UInt32 block1_mirror_crypt_seed
{
get
{
return BitConverter.ToUInt32(Data, 0x400+0x370);
}
set
{
setData(BitConverter.GetBytes((UInt32)value), 0x400+0x370);
}
}
public ushort block2_crc
{
get
{
return BitConverter.ToUInt16(Data, 0x800+0x8);
}
set
{
setData(BitConverter.GetBytes((UInt16)value), 0x800+0x8);
}
}
public class ML_BLOCK1
{
public static int Size = 0x374;
@@ -320,7 +399,7 @@ namespace BW_tool
}
public class ML_BLOCK2
{
public static int Size = 0x21F;
public static int Size = 0x2A0;
public byte[] Data;
public ML_BLOCK2(byte[] data = null)

View File

@@ -15,6 +15,7 @@ using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
namespace BW_tool
{
@@ -23,6 +24,13 @@ namespace BW_tool
/// </summary>
public partial class MainForm : Form
{
public string version()
{
var version = Assembly.GetExecutingAssembly().GetName().Version;
DateTime buildDate = new DateTime(2000, 1, 1).AddDays(version.Build).AddSeconds(version.Revision*2);
return "BUILD "+buildDate.Year.ToString()+buildDate.Month.ToString()+buildDate.Day.ToString()+"_"+buildDate.Hour.ToString()+buildDate.Minute.ToString()+buildDate.Second.ToString();
}
public MainForm()
{
//
@@ -180,7 +188,7 @@ namespace BW_tool
}
void AboutClick(object sender, EventArgs e)
{
MessageBox.Show("Pokémon Generation 5 save tool by suloku '16\n\nThanks to many people that I'm probably missing out now, but those who shall not be missed are BlackShark for many research and information and kaphotics for reference on pkhex source code and research at project pokemon forums.");
MessageBox.Show("Pokémon Generation 5 save tool by suloku '16\n\nThanks to many people that I'm probably missing out now, but those who shall not be missed are BlackShark for many research and information and kaphotics for reference on pkhex source code and research at project pokemon forums.\n\n"+version());
}
void Memory_butClick(object sender, EventArgs e)
{