2015-07-03 00:12:02 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.IO.Compression;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Mesen.GUI.Config;
|
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Forms.Cheats
|
|
|
|
|
{
|
|
|
|
|
public partial class frmCheat : BaseConfigForm
|
|
|
|
|
{
|
|
|
|
|
const int GGShortCodeLength = 6;
|
|
|
|
|
const int GGLongCodeLength = 8;
|
|
|
|
|
const int PARCodeLength = 8;
|
|
|
|
|
|
2016-06-17 20:53:05 -04:00
|
|
|
|
private string _gameCrc;
|
2015-07-03 00:12:02 -04:00
|
|
|
|
|
|
|
|
|
public frmCheat(CheatInfo cheat)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2015-07-05 19:05:33 -04:00
|
|
|
|
Entity = cheat;
|
|
|
|
|
|
2016-06-17 20:53:05 -04:00
|
|
|
|
_gameCrc = cheat.GameCrc;
|
2016-06-03 21:15:34 -04:00
|
|
|
|
|
|
|
|
|
if(string.IsNullOrWhiteSpace(cheat.GameName)) {
|
2016-06-17 20:53:05 -04:00
|
|
|
|
RomInfo romInfo = InteropEmu.GetRomInfo();
|
|
|
|
|
_gameCrc = romInfo.GetCrcString();
|
|
|
|
|
((CheatInfo)Entity).GameName = romInfo.GetRomName();
|
|
|
|
|
txtGameName.Text = ((CheatInfo)Entity).GameName;
|
2016-06-03 21:15:34 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-05 19:05:33 -04:00
|
|
|
|
radGameGenie.Tag = CheatType.GameGenie;
|
|
|
|
|
radProActionRocky.Tag = CheatType.ProActionRocky;
|
|
|
|
|
radCustom.Tag = CheatType.Custom;
|
|
|
|
|
radRelativeAddress.Tag = true;
|
|
|
|
|
radAbsoluteAddress.Tag = false;
|
|
|
|
|
|
|
|
|
|
AddBinding("Enabled", chkEnabled);
|
|
|
|
|
AddBinding("CheatName", txtCheatName);
|
|
|
|
|
AddBinding("GameName", txtGameName);
|
|
|
|
|
AddBinding("CheatType", radGameGenie.Parent);
|
|
|
|
|
AddBinding("GameGenieCode", txtGameGenie);
|
|
|
|
|
AddBinding("ProActionRockyCode", txtProActionRocky);
|
|
|
|
|
AddBinding("Address", txtAddress);
|
|
|
|
|
AddBinding("Value", txtValue);
|
2015-07-19 20:02:07 -04:00
|
|
|
|
AddBinding("UseCompareValue", chkCompareValue);
|
2015-07-05 19:05:33 -04:00
|
|
|
|
AddBinding("CompareValue", txtCompare);
|
|
|
|
|
AddBinding("IsRelativeAddress", radRelativeAddress.Parent);
|
2015-07-03 00:12:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-05 19:05:33 -04:00
|
|
|
|
protected override Type BindedType
|
|
|
|
|
{
|
|
|
|
|
get { return typeof(CheatInfo); }
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-03 00:12:02 -04:00
|
|
|
|
protected override bool ApplyChangesOnOK
|
|
|
|
|
{
|
|
|
|
|
get { return false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UpdateConfig()
|
|
|
|
|
{
|
2015-07-05 19:05:33 -04:00
|
|
|
|
UpdateObject();
|
2016-06-17 20:53:05 -04:00
|
|
|
|
((CheatInfo)Entity).GameCrc = _gameCrc;
|
2015-07-03 00:12:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-03 21:15:34 -04:00
|
|
|
|
private void LoadGame(string romPath)
|
|
|
|
|
{
|
2016-06-26 10:43:52 -04:00
|
|
|
|
int archiveFileIndex = -1;
|
|
|
|
|
if(frmSelectRom.SelectRom(romPath, ref archiveFileIndex)) {
|
2016-06-17 20:53:05 -04:00
|
|
|
|
RomInfo romInfo = InteropEmu.GetRomInfo(romPath, archiveFileIndex);
|
|
|
|
|
_gameCrc = romInfo.GetCrcString();
|
|
|
|
|
if(_gameCrc != null) {
|
|
|
|
|
((CheatInfo)Entity).GameName = Path.GetFileNameWithoutExtension(romInfo.RomName);
|
|
|
|
|
txtGameName.Text = ((CheatInfo)Entity).GameName;
|
|
|
|
|
}
|
2016-06-03 21:15:34 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-03 00:12:02 -04:00
|
|
|
|
private void btnBrowse_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
OpenFileDialog ofd = new OpenFileDialog();
|
2016-02-19 13:05:04 -05:00
|
|
|
|
ofd.Filter = ResourceHelper.GetMessage("FilterRom");
|
2015-07-03 00:12:02 -04:00
|
|
|
|
if(ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
|
2016-06-03 21:15:34 -04:00
|
|
|
|
LoadGame(ofd.FileName);
|
2015-07-03 00:12:02 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-05 19:05:33 -04:00
|
|
|
|
protected override bool ValidateInput()
|
2015-07-03 00:12:02 -04:00
|
|
|
|
{
|
2015-07-05 19:05:33 -04:00
|
|
|
|
UInt32 val;
|
2016-06-17 20:53:05 -04:00
|
|
|
|
if(_gameCrc == null) {
|
2015-07-03 00:12:02 -04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-05 19:05:33 -04:00
|
|
|
|
if(string.IsNullOrWhiteSpace(txtGameName.Text)) {
|
2015-07-03 00:12:02 -04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-05 19:05:33 -04:00
|
|
|
|
if(string.IsNullOrWhiteSpace(txtCheatName.Text)) {
|
2015-07-03 00:12:02 -04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-05 19:05:33 -04:00
|
|
|
|
if(radGameGenie.Checked) {
|
|
|
|
|
if(txtGameGenie.Text.Length != frmCheat.GGShortCodeLength && txtGameGenie.Text.Length != frmCheat.GGLongCodeLength) {
|
2015-07-03 00:12:02 -04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-07-05 19:05:33 -04:00
|
|
|
|
if(txtGameGenie.Text.Count(c => !"APZLGITYEOXUKSVN".Contains(c.ToString().ToUpper())) > 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else if(radProActionRocky.Checked) {
|
|
|
|
|
if(txtProActionRocky.Text.Length != frmCheat.PARCodeLength) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if(!UInt32.TryParse(txtProActionRocky.Text, System.Globalization.NumberStyles.AllowHexSpecifier, null, out val)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if(txtProActionRocky.Text.Count(c => !"1234567890ABCDEF".Contains(c.ToString().ToUpper())) > 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Byte byteVal;
|
|
|
|
|
if(!UInt32.TryParse(txtAddress.Text, System.Globalization.NumberStyles.AllowHexSpecifier, null, out val)) {
|
2015-07-03 00:12:02 -04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-05 19:05:33 -04:00
|
|
|
|
if(!Byte.TryParse(txtValue.Text, System.Globalization.NumberStyles.AllowHexSpecifier, null, out byteVal)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-07-03 00:12:02 -04:00
|
|
|
|
|
2015-07-05 19:05:33 -04:00
|
|
|
|
if(!Byte.TryParse(txtCompare.Text, System.Globalization.NumberStyles.AllowHexSpecifier, null, out byteVal)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-07-03 00:12:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-05 19:05:33 -04:00
|
|
|
|
return true;
|
2015-07-03 00:12:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtGameGenie_Enter(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
radGameGenie.Checked = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtProActionRocky_Enter(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
radProActionRocky.Checked = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void customField_Enter(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
radCustom.Checked = true;
|
|
|
|
|
}
|
2015-07-19 20:02:07 -04:00
|
|
|
|
|
|
|
|
|
private void chkCompareValue_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
txtCompare.Enabled = chkCompareValue.Checked;
|
|
|
|
|
}
|
2015-07-03 00:12:02 -04:00
|
|
|
|
}
|
|
|
|
|
}
|