-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRandomDropTableEditor.cs
More file actions
209 lines (164 loc) · 6.7 KB
/
RandomDropTableEditor.cs
File metadata and controls
209 lines (164 loc) · 6.7 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
namespace CustomActorToolkit
{
public partial class RandomDropTableEditor : Form
{
String OldFileName = "";
Boolean isrom = false, isztable = false;
Dictionary<byte,string> SceneNames;
public int RandomDropTableOffset = 0;
public DropTable[] DropTables = new DropTable[16];
ComboBox[] items;
NumericUpDown[] amounts;
public string ROMpath = "";
public int previd = 0;
public RandomDropTableEditor(int a, string b)
{
RandomDropTableOffset = a;
ROMpath = b;
InitializeComponent();
items = new []{ Item0, Item1, Item2, Item3, Item4, Item5, Item6, Item7, Item8, Item9, Item10, Item11, Item12, Item13, Item14, Item15 };
amounts = new []{ Amount0, Amount1, Amount2, Amount3, Amount4, Amount5, Amount6, Amount7, Amount8, Amount9, Amount10, Amount11, Amount12, Amount13, Amount14, Amount15 };
InitializeForm();
}
private void Close_MouseClick(object sender, MouseEventArgs e)
{
this.Close();
}
private void InitializeForm()
{
for(int i = 0; i < 16; i++)
{
items[i].Items.AddRange(XMLreader.getXMLItems("ItemDrops", "Item"));
}
List<byte> ROM = new List<byte>(File.ReadAllBytes(ROMpath));
int offset = (int)RandomDropTableOffset;
int cnt = 0;
while (cnt != 15)
{
DropTables[cnt] = new DropTable();
for (int i = 0; i < 16; i++)
{
DropTables[cnt].ItemVal[i] = ROM[offset + i];
DropTables[cnt].ItemAmount[i] = ROM[offset + i + 0xF0];
}
offset += 0x10;
cnt++;
}
ChangeTable(false);
}
private void saveROMToolStripMenuItem_Click(object sender, EventArgs e)
{
if (IsFileLocked(ROMpath))
MessageBox.Show("File is in use... try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
{
BinaryWriter BWS = new BinaryWriter(File.OpenWrite(ROMpath));
int offset = (int)RandomDropTableOffset;
BWS.Seek(offset, SeekOrigin.Begin);
ChangeTable(true);
List<Byte> Output = new List<byte>();
List<Byte> Output2 = new List<byte>();
for (int i = 0; i < 15; i++)
{
for (int y = 0; y < 16; y++)
{
Output.Add(DropTables[i].ItemVal[y]);
Output2.Add(DropTables[i].ItemAmount[y]);
}
}
Output.AddRange(Output2);
BWS.Write(Output.ToArray());
BWS.Close();
MessageBox.Show("Done!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void exportBinaryToolStripMenuItem_Click(object sender, EventArgs e)
{
saveFileDialog1.CheckFileExists = false;
// saveFileDialog1.FileName = Path.GetFileName(OldFileName) + "_new";
saveFileDialog1.Filter = "Save file binary (*.bin)|*.bin|All Files (*.*)|*.*";
saveFileDialog1.CreatePrompt = true;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if (IsFileLocked(saveFileDialog1.FileName))
MessageBox.Show("File is in use... try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
{
ChangeTable(true);
List<Byte> Output = new List<byte>();
List<Byte> Output2 = new List<byte>();
for (int i = 0; i < 15; i++)
{
for (int y = 0; y < 16; y++)
{
Output.Add(DropTables[i].ItemVal[y]);
Output2.Add(DropTables[i].ItemAmount[y]);
}
}
Output.AddRange(Output2);
File.WriteAllBytes(saveFileDialog1.FileName, Output.ToArray());
MessageBox.Show("Done! File Size: " + Output.Count.ToString("X") + " bytes", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
private void DropTableID_ValueChanged(object sender, EventArgs e)
{
ChangeTable(true);
}
private void ChangeTable(bool change = false)
{
if (change)
{
for (int y = 0; y < 16; y++)
{
DropTables[previd].ItemVal[y] = (byte)Convert.ToByte((items[y].SelectedItem as SongItem).Value);
DropTables[previd].ItemAmount[y] = (byte) amounts[y].Value;
}
}
for(int i=0; i < 16; i++)
{
items[i].SelectedIndex = MainForm.FindSongComboItemValue(items[i].Items, DropTables[(int)DropTableID.Value].ItemVal[i]);
amounts[i].Value = DropTables[(int) DropTableID.Value].ItemAmount[i];
}
previd = (int)DropTableID.Value;
}
private bool IsFileLocked(string file)
{
FileStream stream = null;
try
{
stream = File.OpenWrite(file);
}
catch (IOException)
{
return true;
}
finally
{
if (stream != null)
stream.Close();
}
return false;
}
private void linkLabel1_Click(object sender, EventArgs e)
{
linkLabel1.LinkVisited = true;
System.Diagnostics.Process.Start(linkLabel1.Text);
}
public class DropTable
{
public byte[] ItemVal = new byte[16];
public byte[] ItemAmount = new byte[16];
}
}
}