2016-06-20 04:22:43 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2019-02-02 07:08:03 +00:00
|
|
|
|
using System.Diagnostics;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
2017-01-08 07:54:09 +00:00
|
|
|
|
using PKHeX.Core;
|
2018-04-07 04:23:09 +00:00
|
|
|
|
using static PKHeX.Core.MessageStrings;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.WinForms
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2018-04-11 00:00:28 +00:00
|
|
|
|
public sealed partial class SAV_EventFlags : Form
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private readonly SaveFile Origin;
|
|
|
|
|
private readonly SaveFile SAV;
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public SAV_EventFlags(SaveFile sav)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2018-04-03 03:36:13 +00:00
|
|
|
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
|
|
|
|
SAV = (Origin = sav).Clone();
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
DragEnter += Main_DragEnter;
|
|
|
|
|
DragDrop += Main_DragDrop;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
flags = SAV.EventFlags;
|
|
|
|
|
Constants = SAV.EventConsts;
|
|
|
|
|
|
|
|
|
|
CB_Stats.Items.Clear();
|
|
|
|
|
for (int i = 0; i < Constants.Length; i++)
|
|
|
|
|
CB_Stats.Items.Add(i.ToString());
|
|
|
|
|
|
2016-07-24 22:04:04 +00:00
|
|
|
|
TLP_Flags.SuspendLayout();
|
|
|
|
|
TLP_Const.SuspendLayout();
|
2017-01-08 07:54:09 +00:00
|
|
|
|
TLP_Flags.Scroll += WinFormsUtil.PanelScroll;
|
|
|
|
|
TLP_Const.Scroll += WinFormsUtil.PanelScroll;
|
2016-07-31 03:57:45 +00:00
|
|
|
|
TLP_Flags.Controls.Clear();
|
2016-06-20 04:22:43 +00:00
|
|
|
|
TLP_Const.Controls.Clear();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
AddFlagList(GetStringList("flags"));
|
|
|
|
|
AddConstList(GetStringList("const"));
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2016-07-24 22:04:04 +00:00
|
|
|
|
TLP_Flags.ResumeLayout();
|
|
|
|
|
TLP_Const.ResumeLayout();
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
2016-11-14 13:31:33 +00:00
|
|
|
|
|
2018-04-07 04:23:09 +00:00
|
|
|
|
Text = $"{Text} ({gamePrefix.ToUpper()})";
|
2016-11-14 13:31:33 +00:00
|
|
|
|
|
2017-09-24 05:13:48 +00:00
|
|
|
|
if (CB_Stats.Items.Count > 0)
|
2018-08-04 17:06:06 +00:00
|
|
|
|
{
|
2017-09-24 05:13:48 +00:00
|
|
|
|
CB_Stats.SelectedIndex = 0;
|
2018-08-04 17:06:06 +00:00
|
|
|
|
}
|
2017-09-24 05:13:48 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
L_Stats.Visible = CB_Stats.Visible = MT_Stat.Visible = false;
|
|
|
|
|
tabControl1.TabPages.Remove(GB_Constants);
|
|
|
|
|
}
|
2016-12-30 00:24:01 +00:00
|
|
|
|
NUD_Flag.Maximum = flags.Length - 1;
|
|
|
|
|
NUD_Flag.Text = "0";
|
2017-09-24 05:13:48 +00:00
|
|
|
|
c_CustomFlag.Checked = flags[0];
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly bool[] flags;
|
|
|
|
|
private readonly ushort[] Constants;
|
|
|
|
|
private const string flagTag = "bool_";
|
|
|
|
|
private const string constTag = "const_";
|
2016-11-14 13:31:33 +00:00
|
|
|
|
private const string constCBTag = "cbconst_";
|
2016-06-20 04:22:43 +00:00
|
|
|
|
private const string flagLabelTag = "flag_";
|
|
|
|
|
private const string constLabelTag = "L_";
|
|
|
|
|
private bool editing;
|
|
|
|
|
private int constEntry = -1;
|
2016-11-12 20:08:50 +00:00
|
|
|
|
private string gamePrefix = "unk";
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2016-11-12 22:57:54 +00:00
|
|
|
|
private const ulong MagearnaConst = 0xCBE05F18356504AC;
|
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
private void B_Cancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
private void B_Save_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// Gather Updated Flags
|
2016-07-28 22:53:13 +00:00
|
|
|
|
foreach (CheckBox flag in TLP_Flags.Controls.OfType<CheckBox>())
|
2017-06-18 01:37:19 +00:00
|
|
|
|
flags[GetControlNum(flag)] = flag.Checked;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
SAV.EventFlags = flags;
|
|
|
|
|
|
2016-11-12 22:57:54 +00:00
|
|
|
|
HandleSpecialFlags();
|
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
// Copy back Constants
|
2019-02-02 18:19:41 +00:00
|
|
|
|
ChangeConstantIndex(null, EventArgs.Empty); // Trigger Saving
|
2016-06-20 04:22:43 +00:00
|
|
|
|
SAV.EventConsts = Constants;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
SAV.Data.CopyTo(Origin.Data, 0);
|
|
|
|
|
Origin.Edited = true;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-12 22:57:54 +00:00
|
|
|
|
private void HandleSpecialFlags()
|
|
|
|
|
{
|
|
|
|
|
if (SAV.SM) // Ensure magearna event flag has magic constant
|
|
|
|
|
{
|
2016-12-30 00:24:01 +00:00
|
|
|
|
BitConverter.GetBytes(flags[3100] ? MagearnaConst : 0).CopyTo(SAV.Data, ((SAV7)SAV).QRSaveData + 0x168);
|
2016-11-12 22:57:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private string[] GetStringList(string type)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2016-11-12 20:08:50 +00:00
|
|
|
|
switch (SAV.Version)
|
|
|
|
|
{
|
|
|
|
|
case GameVersion.X:
|
|
|
|
|
case GameVersion.Y:
|
|
|
|
|
gamePrefix = "xy";
|
|
|
|
|
break;
|
|
|
|
|
case GameVersion.OR:
|
|
|
|
|
case GameVersion.AS:
|
|
|
|
|
gamePrefix = "oras";
|
|
|
|
|
break;
|
|
|
|
|
case GameVersion.SN:
|
|
|
|
|
case GameVersion.MN:
|
|
|
|
|
gamePrefix = "sm";
|
|
|
|
|
break;
|
2017-11-10 23:08:20 +00:00
|
|
|
|
case GameVersion.US:
|
|
|
|
|
case GameVersion.UM:
|
|
|
|
|
gamePrefix = "usum";
|
|
|
|
|
break;
|
2017-05-13 01:15:04 +00:00
|
|
|
|
case GameVersion.DP:
|
|
|
|
|
gamePrefix = "dp";
|
|
|
|
|
break;
|
2017-06-10 13:12:51 +00:00
|
|
|
|
case GameVersion.Pt:
|
|
|
|
|
gamePrefix = "pt";
|
|
|
|
|
break;
|
2017-05-19 02:20:19 +00:00
|
|
|
|
case GameVersion.HGSS:
|
|
|
|
|
gamePrefix = "hgss";
|
|
|
|
|
break;
|
2017-05-26 09:05:58 +00:00
|
|
|
|
case GameVersion.BW:
|
|
|
|
|
gamePrefix = "bw";
|
|
|
|
|
break;
|
2017-06-02 15:43:08 +00:00
|
|
|
|
case GameVersion.B2W2:
|
|
|
|
|
gamePrefix = "b2w2";
|
|
|
|
|
break;
|
2017-07-14 06:05:56 +00:00
|
|
|
|
case GameVersion.R:
|
|
|
|
|
case GameVersion.S:
|
|
|
|
|
case GameVersion.RS:
|
|
|
|
|
gamePrefix = "rs";
|
|
|
|
|
break;
|
|
|
|
|
case GameVersion.E:
|
|
|
|
|
gamePrefix = "e";
|
|
|
|
|
break;
|
|
|
|
|
case GameVersion.FR:
|
|
|
|
|
case GameVersion.LG:
|
|
|
|
|
case GameVersion.FRLG:
|
2017-09-27 16:19:31 +00:00
|
|
|
|
gamePrefix = "frlg";
|
2017-07-14 06:05:56 +00:00
|
|
|
|
break;
|
2017-11-27 18:35:49 +00:00
|
|
|
|
case GameVersion.C:
|
|
|
|
|
gamePrefix = "c";
|
|
|
|
|
break;
|
2016-11-12 20:08:50 +00:00
|
|
|
|
default:
|
2019-02-02 07:08:03 +00:00
|
|
|
|
throw new ArgumentException(nameof(GameVersion));
|
2016-11-12 20:08:50 +00:00
|
|
|
|
}
|
2017-10-12 03:00:18 +00:00
|
|
|
|
return GameInfo.GetStrings(gamePrefix, GameInfo.CurrentLanguage, type);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void AddFlagList(string[] list)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
if (list == null || list.Length == 0)
|
|
|
|
|
{
|
2018-04-07 04:23:09 +00:00
|
|
|
|
TLP_Flags.Controls.Add(new Label { Text = MsgResearchRequired, Name = "TLP_Flags_Research", ForeColor = Color.Red, AutoSize = true }, 0, 0);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get list
|
|
|
|
|
List<int> num = new List<int>();
|
|
|
|
|
List<string> desc = new List<string>();
|
|
|
|
|
|
|
|
|
|
foreach (string[] split in list.Select(s => s.Split('\t')).Where(split => split.Length == 2))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2018-08-04 17:06:06 +00:00
|
|
|
|
var flagIndex = split[0];
|
|
|
|
|
int n = TryParseHexDec(flagIndex);
|
2017-07-14 06:05:56 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (num.Contains(n))
|
|
|
|
|
continue;
|
|
|
|
|
num.Add(n);
|
|
|
|
|
desc.Add(split[1]);
|
2018-08-04 17:06:06 +00:00
|
|
|
|
}
|
2019-02-02 07:08:03 +00:00
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// Ignore bad user values
|
|
|
|
|
Debug.WriteLine(string.Concat(split));
|
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
if (num.Count == 0)
|
|
|
|
|
{
|
2018-08-04 17:06:06 +00:00
|
|
|
|
TLP_Flags.Controls.Add(new Label { Text = MsgResearchRequired, Name = "TLP_Flags_Research", ForeColor = Color.Red, AutoSize = true }, 0, 0);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < num.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var lbl = new Label
|
|
|
|
|
{
|
|
|
|
|
Text = desc[i],
|
2016-11-12 20:08:50 +00:00
|
|
|
|
Name = gamePrefix + flagLabelTag + num[i].ToString("0000"),
|
2016-06-20 04:22:43 +00:00
|
|
|
|
Margin = Padding.Empty,
|
|
|
|
|
AutoSize = true
|
|
|
|
|
};
|
|
|
|
|
var chk = new CheckBox
|
|
|
|
|
{
|
|
|
|
|
Name = flagTag + num[i].ToString("0000"),
|
|
|
|
|
CheckAlign = ContentAlignment.MiddleLeft,
|
|
|
|
|
Margin = Padding.Empty,
|
|
|
|
|
Checked = flags[num[i]],
|
|
|
|
|
AutoSize = true
|
|
|
|
|
};
|
2017-06-18 01:37:19 +00:00
|
|
|
|
chk.CheckStateChanged += ToggleFlag;
|
2017-07-06 06:05:49 +00:00
|
|
|
|
lbl.Click += (sender, e) => chk.Checked ^= true;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
TLP_Flags.Controls.Add(chk, 0, i);
|
|
|
|
|
TLP_Flags.Controls.Add(lbl, 1, i);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
|
|
|
|
private static int TryParseHexDec(string flag)
|
|
|
|
|
{
|
|
|
|
|
if (!flag.StartsWith("0x"))
|
|
|
|
|
return Convert.ToInt16(flag);
|
|
|
|
|
flag = flag.Substring(2);
|
|
|
|
|
return Convert.ToInt16(flag, 16);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void AddConstList(string[] list)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
if (list == null || list.Length == 0)
|
|
|
|
|
{
|
2018-04-07 04:23:09 +00:00
|
|
|
|
TLP_Const.Controls.Add(new Label { Text = MsgResearchRequired, Name = "TLP_Const_Research", ForeColor = Color.Red, AutoSize = true }, 0, 0);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get list
|
|
|
|
|
List<int> num = new List<int>();
|
|
|
|
|
List<string> desc = new List<string>();
|
2016-11-14 13:31:33 +00:00
|
|
|
|
List<string> enums = new List<string>();
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2016-11-14 13:31:33 +00:00
|
|
|
|
foreach (string[] split in list.Select(s => s.Split('\t')).Where(split => split.Length == 2 || split.Length == 3))
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-07-14 06:05:56 +00:00
|
|
|
|
var c = split[0];
|
2018-08-04 17:06:06 +00:00
|
|
|
|
int n = TryParseHexDecConst(c);
|
2017-07-14 06:05:56 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (num.Contains(n))
|
|
|
|
|
continue;
|
|
|
|
|
num.Add(n);
|
|
|
|
|
desc.Add(split[1]);
|
2018-09-29 19:22:13 +00:00
|
|
|
|
enums.Add(split.Length == 3 ? split[2] : string.Empty);
|
2018-08-04 17:06:06 +00:00
|
|
|
|
}
|
2019-02-02 07:08:03 +00:00
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// Ignore bad user values
|
|
|
|
|
Debug.WriteLine(string.Concat(split));
|
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
if (num.Count == 0)
|
|
|
|
|
{
|
2018-04-07 04:23:09 +00:00
|
|
|
|
TLP_Const.Controls.Add(new Label { Text = MsgResearchRequired, Name = "TLP_Const_Research", ForeColor = Color.Red, AutoSize = true }, 0, 0);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < num.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var lbl = new Label
|
|
|
|
|
{
|
|
|
|
|
Text = desc[i],
|
2016-11-12 20:08:50 +00:00
|
|
|
|
Name = gamePrefix + constLabelTag + num[i].ToString("0000"),
|
2016-06-20 04:22:43 +00:00
|
|
|
|
Margin = Padding.Empty,
|
|
|
|
|
AutoSize = true
|
|
|
|
|
};
|
|
|
|
|
var mtb = new NumericUpDown
|
|
|
|
|
{
|
2016-08-25 00:46:24 +00:00
|
|
|
|
Maximum = ushort.MaxValue,
|
|
|
|
|
Minimum = ushort.MinValue,
|
2016-06-20 04:22:43 +00:00
|
|
|
|
Value = Constants[num[i]],
|
|
|
|
|
Name = constTag + num[i].ToString("0000"),
|
|
|
|
|
Margin = Padding.Empty,
|
2016-11-14 13:31:33 +00:00
|
|
|
|
Width = 50,
|
2016-06-20 04:22:43 +00:00
|
|
|
|
};
|
2016-11-14 13:31:33 +00:00
|
|
|
|
|
|
|
|
|
var map = new[] { new { Text = "Custom", Value = -1 } }.ToList();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(enums[i]))
|
|
|
|
|
{
|
|
|
|
|
foreach (var entry in enums[i].Split(','))
|
|
|
|
|
{
|
|
|
|
|
var spl = entry.Split(':');
|
2016-12-30 00:24:01 +00:00
|
|
|
|
map.Add(new { Text = spl[1], Value = Convert.ToInt32(spl[0])});
|
2016-11-14 13:31:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-30 00:24:01 +00:00
|
|
|
|
var cb = new ComboBox
|
2016-11-14 13:31:33 +00:00
|
|
|
|
{
|
|
|
|
|
Margin = Padding.Empty,
|
2017-07-09 21:54:10 +00:00
|
|
|
|
Width = 150,
|
2016-11-14 13:31:33 +00:00
|
|
|
|
Name = constCBTag + num[i].ToString("0000"),
|
|
|
|
|
DropDownStyle = ComboBoxStyle.DropDownList,
|
2017-07-09 21:54:10 +00:00
|
|
|
|
DropDownWidth = Width + 100
|
2016-11-14 13:31:33 +00:00
|
|
|
|
};
|
2019-02-12 06:04:47 +00:00
|
|
|
|
cb.InitializeBinding();
|
|
|
|
|
cb.DataSource = map;
|
|
|
|
|
cb.SelectedIndex = 0;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
cb.SelectedValueChanged += ToggleConst;
|
|
|
|
|
mtb.TextChanged += ToggleConst;
|
2016-11-14 13:31:33 +00:00
|
|
|
|
TLP_Const.Controls.Add(lbl, 0, i);
|
|
|
|
|
TLP_Const.Controls.Add(cb, 1, i);
|
|
|
|
|
TLP_Const.Controls.Add(mtb, 2, i);
|
2016-12-30 00:24:01 +00:00
|
|
|
|
if (map.Any(val => val.Value == Constants[num[i]]))
|
2016-11-14 13:31:33 +00:00
|
|
|
|
{
|
|
|
|
|
cb.SelectedValue = (int)Constants[num[i]];
|
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-04 17:06:06 +00:00
|
|
|
|
private static int TryParseHexDecConst(string c)
|
|
|
|
|
{
|
|
|
|
|
if (!c.StartsWith("0x40"))
|
|
|
|
|
return Convert.ToInt16(c);
|
|
|
|
|
c = c.Substring(4);
|
|
|
|
|
return Convert.ToInt16(c, 16);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static int GetControlNum(Control c)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2019-02-12 06:04:47 +00:00
|
|
|
|
string source = c.Name.Split('_')[1];
|
|
|
|
|
return int.TryParse(source, out var val) ? val : 0;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ChangeCustomBool(object sender, EventArgs e)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
if (editing)
|
|
|
|
|
return;
|
|
|
|
|
editing = true;
|
2016-12-30 00:24:01 +00:00
|
|
|
|
flags[(int)NUD_Flag.Value] = c_CustomFlag.Checked;
|
2018-05-13 02:07:32 +00:00
|
|
|
|
var name = flagTag + NUD_Flag.Value.ToString("0000");
|
|
|
|
|
if (TLP_Flags.Controls[name] is CheckBox c)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
c.Checked = c_CustomFlag.Checked;
|
|
|
|
|
editing = false;
|
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ChangeCustomFlag(object sender, EventArgs e)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2016-12-30 00:24:01 +00:00
|
|
|
|
int flag = (int)NUD_Flag.Value;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (flag >= flags.Length)
|
|
|
|
|
{
|
|
|
|
|
c_CustomFlag.Checked = false;
|
|
|
|
|
c_CustomFlag.Enabled = false;
|
2016-12-30 00:24:01 +00:00
|
|
|
|
NUD_Flag.BackColor = Color.Red;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
c_CustomFlag.Enabled = true;
|
2016-12-30 00:24:01 +00:00
|
|
|
|
NUD_Flag.ResetBackColor();
|
2016-06-20 04:22:43 +00:00
|
|
|
|
c_CustomFlag.Checked = flags[flag];
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ChangeCustomFlag(object sender, KeyEventArgs e)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
ChangeCustomFlag(null, (EventArgs)e);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ToggleFlag(object sender, EventArgs e)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
if (editing)
|
|
|
|
|
return;
|
|
|
|
|
editing = true;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int flagnum = GetControlNum((CheckBox) sender);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
flags[flagnum] = ((CheckBox)sender).Checked;
|
2016-12-30 00:24:01 +00:00
|
|
|
|
if (NUD_Flag.Value == flagnum)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
c_CustomFlag.Checked = flags[flagnum];
|
|
|
|
|
editing = false;
|
|
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ChangeCustomConst(object sender, EventArgs e)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
if (editing)
|
|
|
|
|
return;
|
|
|
|
|
editing = true;
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
Constants[CB_Stats.SelectedIndex] = (ushort)(Util.ToUInt32(((MaskedTextBox)sender).Text) & 0xFFFF);
|
2018-05-13 02:07:32 +00:00
|
|
|
|
var name = constTag + CB_Stats.SelectedIndex.ToString("0000");
|
|
|
|
|
if (TLP_Flags.Controls[name] is MaskedTextBox m)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
m.Text = MT_Stat.Text;
|
|
|
|
|
|
|
|
|
|
editing = false;
|
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ChangeConstantIndex(object sender, EventArgs e)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-09-24 05:13:48 +00:00
|
|
|
|
if (Constants.Length == 0)
|
|
|
|
|
return;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (constEntry > -1) // Set Entry
|
|
|
|
|
Constants[constEntry] = (ushort)Math.Min(Util.ToUInt32(MT_Stat.Text), 0xFFFF);
|
|
|
|
|
|
|
|
|
|
constEntry = CB_Stats.SelectedIndex; // Get Entry
|
|
|
|
|
MT_Stat.Text = Constants[constEntry].ToString();
|
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ToggleConst(object sender, EventArgs e)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
if (editing)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int constnum = GetControlNum((Control)sender);
|
2018-05-13 02:07:32 +00:00
|
|
|
|
if (sender is ComboBox cb)
|
2016-11-14 13:31:33 +00:00
|
|
|
|
{
|
2018-05-13 02:07:32 +00:00
|
|
|
|
var nud = (NumericUpDown)TLP_Const.GetControlFromPosition(2, TLP_Const.GetRow(cb));
|
|
|
|
|
var sel_val = (int)cb.SelectedValue;
|
2016-11-14 13:31:33 +00:00
|
|
|
|
editing = true;
|
|
|
|
|
nud.Enabled = sel_val == -1;
|
|
|
|
|
if (sel_val != -1)
|
|
|
|
|
nud.Value = (ushort)sel_val;
|
2018-05-13 02:07:32 +00:00
|
|
|
|
Constants[constnum] = (ushort)Util.ToUInt32(nud.Text);
|
2016-11-14 13:31:33 +00:00
|
|
|
|
editing = false;
|
|
|
|
|
}
|
2018-05-13 02:07:32 +00:00
|
|
|
|
else if (sender is NumericUpDown nud)
|
2016-11-14 13:31:33 +00:00
|
|
|
|
{
|
|
|
|
|
editing = true;
|
2018-05-13 02:07:32 +00:00
|
|
|
|
Constants[constnum] = (ushort)Util.ToUInt32(nud.Text);
|
2016-11-14 13:31:33 +00:00
|
|
|
|
if (constnum == CB_Stats.SelectedIndex)
|
|
|
|
|
MT_Stat.Text = Constants[constnum].ToString();
|
|
|
|
|
editing = false;
|
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ChangeSAV(object sender, EventArgs e)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
if (TB_NewSAV.Text.Length > 0 && TB_OldSAV.Text.Length > 0)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
DiffSaves();
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void OpenSAV(object sender, EventArgs e)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
OpenFileDialog ofd = new OpenFileDialog();
|
|
|
|
|
if (ofd.ShowDialog() == DialogResult.OK)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
LoadSAV(sender, ofd.FileName);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void LoadSAV(object sender, string path)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
if (sender == B_LoadOld)
|
|
|
|
|
TB_OldSAV.Text = path;
|
|
|
|
|
else
|
|
|
|
|
TB_NewSAV.Text = path;
|
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void DiffSaves()
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2018-04-07 04:23:09 +00:00
|
|
|
|
if (!File.Exists(TB_OldSAV.Text)) { WinFormsUtil.Alert(string.Format(MsgSaveNumberInvalid, 1)); return; }
|
|
|
|
|
if (!File.Exists(TB_NewSAV.Text)) { WinFormsUtil.Alert(string.Format(MsgSaveNumberInvalid, 2)); return; }
|
|
|
|
|
if (new FileInfo(TB_OldSAV.Text).Length > 0x100000) { WinFormsUtil.Alert(string.Format(MsgSaveNumberInvalid, 1)); return; }
|
|
|
|
|
if (new FileInfo(TB_NewSAV.Text).Length > 0x100000) { WinFormsUtil.Alert(string.Format(MsgSaveNumberInvalid, 2)); return; }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2018-09-29 19:22:13 +00:00
|
|
|
|
var s1 = SaveUtil.GetVariantSAV(TB_OldSAV.Text);
|
|
|
|
|
var s2 = SaveUtil.GetVariantSAV(TB_NewSAV.Text);
|
2018-04-07 04:23:09 +00:00
|
|
|
|
if (s1 == null) { WinFormsUtil.Alert(string.Format(MsgSaveNumberInvalid, 1)); return; }
|
|
|
|
|
if (s2 == null) { WinFormsUtil.Alert(string.Format(MsgSaveNumberInvalid, 2)); return; }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2018-04-07 04:23:09 +00:00
|
|
|
|
if (s1.GetType() != s2.GetType()) { WinFormsUtil.Alert(MsgSaveDifferentTypes, $"S1: {s1.GetType().Name}", $"S2: {s2.GetType().Name}"); return; }
|
|
|
|
|
if (s1.Version != s2.Version) { WinFormsUtil.Alert(MsgSaveDifferentVersions, $"S1: {s1.Version}", $"S2: {s2.Version}"); return; }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2018-09-29 19:22:13 +00:00
|
|
|
|
var tbIsSet = new List<int>();
|
|
|
|
|
var tbUnSet = new List<int>();
|
2019-02-07 07:28:02 +00:00
|
|
|
|
var result = new List<string>();
|
2018-09-29 19:22:13 +00:00
|
|
|
|
bool[] oldBits = s1.EventFlags;
|
|
|
|
|
bool[] newBits = s2.EventFlags;
|
|
|
|
|
var oldConst = s1.EventConsts;
|
|
|
|
|
var newConst = s2.EventConsts;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2018-09-29 19:22:13 +00:00
|
|
|
|
for (int i = 0; i < oldBits.Length; i++)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2018-09-29 19:22:13 +00:00
|
|
|
|
if (oldBits[i] != newBits[i])
|
|
|
|
|
(newBits[i] ? tbIsSet : tbUnSet).Add(i);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-29 19:22:13 +00:00
|
|
|
|
TB_IsSet.Text = string.Join(", ", tbIsSet.Select(z => $"{z:0000}"));
|
|
|
|
|
TB_UnSet.Text = string.Join(", ", tbUnSet.Select(z => $"{z:0000}"));
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2018-09-29 19:22:13 +00:00
|
|
|
|
for (int i = 0; i < newConst.Length; i++)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2018-09-29 19:22:13 +00:00
|
|
|
|
if (oldConst[i] != newConst[i])
|
2019-02-07 07:28:02 +00:00
|
|
|
|
result.Add($"{i}: {oldConst[i]}->{newConst[i]}");
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-07 07:28:02 +00:00
|
|
|
|
if (result.Count == 0)
|
2017-03-09 07:31:22 +00:00
|
|
|
|
{
|
|
|
|
|
WinFormsUtil.Alert("No Event Constant diff found.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-29 19:22:13 +00:00
|
|
|
|
if (DialogResult.Yes == WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Copy Event Constant diff to clipboard?"))
|
2019-02-07 07:28:02 +00:00
|
|
|
|
Clipboard.SetText(string.Join(Environment.NewLine, result));
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static void Main_DragEnter(object sender, DragEventArgs e)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2018-09-29 19:22:13 +00:00
|
|
|
|
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void Main_DragDrop(object sender, DragEventArgs e)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
2018-09-29 19:22:13 +00:00
|
|
|
|
var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, Name, "Yes: Old Save" + Environment.NewLine + "No: New Save");
|
|
|
|
|
var button = dr == DialogResult.Yes ? B_LoadOld : B_LoadNew;
|
|
|
|
|
LoadSAV(button, files[0]);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|