Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SnesPresetEditor.cs - github.com/ClusterM/hakchi2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5faebd89534df34409288fd90e27b94e28adef08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using com.clusterrr.hakchi_gui.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace com.clusterrr.hakchi_gui
{
    public partial class SnesPresetEditor : Form
    {
        SnesGame game;
        bool wasCompressed;
        SnesGame.SfromHeader2 header2;

        public SnesPresetEditor(SnesGame game)
        {
            InitializeComponent();
            try
            {
                wasCompressed = game.DecompressPossible().Count() > 0;
                if (wasCompressed)
                    game.Decompress();
                this.game = game;
                header2 = game.ReadSfromHeader2();
                textBoxPresetID.Text = string.Format("{0:X2}{1:X2}", header2.PresetID & 0xFF, (header2.PresetID >> 8) & 0xFF);
                textBoxExtra.Text = string.Format("{0:X2}", header2.Chip & 0xFF);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message + ex.StackTrace);
                MessageBox.Show(this, ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
            }
        }

        private void buttonOk_Click(object sender, EventArgs e)
        {
            try
            {
                var presetID = Convert.ToInt32(textBoxPresetID.Text, 16);
                presetID = ((presetID & 0xFF) << 8) | ((presetID >> 8) & 0xFF);
                var chip = Convert.ToInt32(textBoxExtra.Text, 16);
                header2.PresetID = (ushort)presetID;
                header2.Chip = (uint)chip;
                game.WriteSfromHeader2(header2);
                Close();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message + ex.StackTrace);
                MessageBox.Show(this, ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void SnesPresetEditor_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                if (wasCompressed)
                    game.Compress();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message + ex.StackTrace);
                MessageBox.Show(this, ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}