This repository has been archived by the owner on Mar 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathMain.cs
217 lines (196 loc) · 8.05 KB
/
Main.cs
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
210
211
212
213
214
215
216
217
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
namespace NLSE
{
public partial class Main : Form
{
internal static string root;
internal static string[] itemNames = Data.getIndexStrings("item", "en");
internal static string[] buildingNames = Data.getIndexStrings("building", "en");
internal static string[] villagerNames = Data.getStrings("name", "en");
internal static List<cbItem> itemList = Data.getCBItems(itemNames);
internal static List<cbItem> vList = Data.getCBList(villagerNames, null);
internal static List<cbItem> buildingList = Data.getCBItems(buildingNames);
internal static ACNLVillager[] villagerList = Data.GetVillagers();
public Main()
{
// Set up.
InitializeComponent();
CB_Friend.Enabled = B_Exhibition.Enabled = B_Friend.Enabled = B_Garden.Enabled = false;
// Allow D&D
AllowDrop = true;
DragEnter += tabMain_DragEnter;
DragDrop += tabMain_DragDrop;
// Find the save files.
scanLoop();
// mine();
}
// Drag & Drop Events
private void tabMain_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
}
private void tabMain_DragDrop(object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if (Directory.Exists(files[0]))
{
findLoop = false;
root = files[0];
L_IO.Text = root;
return;
}
long len = new FileInfo(files[0]).Length;
if (len == 0x80000 || len == 0xC0000 || len == 0x121000 || len == 0x130000) // RAM
{
if (Util.Prompt(MessageBoxButtons.YesNo, "Edit RAM Dump?" + Environment.NewLine + files[0]) == DialogResult.Yes)
{
byte[] data = File.ReadAllBytes(files[0]);
SaveData = new byte[data.Length + 0x80]; // shift 0x80 bytes
Array.Copy(data, 0, SaveData, 0x80, SaveData.Length - 0x80);
new Garden().ShowDialog();
}
}
else // Try fix checksums?
{
foreach (string file in files)
{
try
{
byte[] data = File.ReadAllBytes(file);
byte[] data2 = (byte[])data.Clone();
Verification.fixChecksums(ref data);
if (!data.SequenceEqual(data2))
{
if (Util.Prompt(MessageBoxButtons.YesNo, "Update checksums?" + Environment.NewLine + file) == DialogResult.Yes)
{
File.WriteAllBytes(file, data);
Util.Alert("File checksums were updated:" + Environment.NewLine + file);
}
Util.Alert("File checksums were not updated (chose not to):" + Environment.NewLine + file);
}
else
{
Util.Alert("File checksums were not updated (already valid):" + Environment.NewLine + file, "If you were trying to load your save file, drop the folder that has garden.dat instead!");
}
}
catch (Exception ex) { Util.Error("File error:" + Environment.NewLine + file, ex.ToString()); }
}
}
}
// Find Files on Load Loop
private bool findLoop = true;
private void scanLoop(int ms = 400)
{
new Thread(() =>
{
while (findLoop && (root = Util.GetSDFLocation()) == null)
Thread.Sleep(ms);
// Trigger update
if (InvokeRequired)
Invoke((MethodInvoker)delegate { L_IO.Text = root; });
else L_IO.Text = root;
}).Start();
}
private void L_IO_Click(object sender, EventArgs e)
{
FolderBrowserDialog ofd = new FolderBrowserDialog();
if (ofd.ShowDialog() != DialogResult.OK)
return;
findLoop = false;
root = ofd.SelectedPath;
L_IO.Text = root;
}
private void updatePath(object sender, EventArgs e)
{
// Scan for files to enable.
string[] files = Directory.GetFiles(root);
B_Exhibition.Enabled = File.Exists(Path.Combine(root, "exhibition.dat"));
B_Garden.Enabled = File.Exists(Path.Combine(root, "garden.dat"));
CB_Friend.Items.Clear();
foreach (string file in files.Where(file => file.Contains("friend")))
CB_Friend.Items.Add(Path.GetFileName(file));
CB_Friend.Enabled = B_Friend.Enabled = CB_Friend.Items.Count > 0;
if (CB_Friend.Items.Count > 0)
CB_Friend.SelectedIndex = 0;
}
// Editing Windows
internal static byte[] SaveData;
private void clickExhibition(object sender, EventArgs e)
{
string dataPath = Path.Combine(root, "exhibition.dat");
if (!File.Exists(dataPath)) return;
// Load Data
try
{
SaveData = File.ReadAllBytes(dataPath);
// Open Form
new Exhibition().ShowDialog();
// Form closed, write data.
Verification.fixChecksums(ref SaveData);
File.WriteAllBytes(dataPath, SaveData);
}
catch (Exception ex)
{
// Error
Util.Error("Error:" + Environment.NewLine + ex);
}
}
private void clickGarden(object sender, EventArgs e)
{
string dataPath = Path.Combine(root, "garden.dat");
if (!File.Exists(dataPath)) return;
// Load Data
try
{
SaveData = File.ReadAllBytes(dataPath);
// Open Form
new Garden().ShowDialog();
// Form closed, write data.
Verification.fixChecksums(ref SaveData);
File.WriteAllBytes(dataPath, SaveData);
}
catch (Exception ex)
{
// Error
Util.Error("Error:" + Environment.NewLine + ex);
}
}
private void clickFriend(object sender, EventArgs e)
{
string dataPath = Path.Combine(root, CB_Friend.Text);
if (!File.Exists(dataPath)) return;
// Load Data
try
{
SaveData = File.ReadAllBytes(dataPath);
// Open Form
new Friend().ShowDialog();
// Form closed, write data.
Verification.fixChecksums(ref SaveData);
File.WriteAllBytes(dataPath, SaveData);
}
catch (Exception ex)
{
// Error
Util.Error("Error:" + Environment.NewLine + ex);
}
}
private void clickHelp(object sender, CancelEventArgs e)
{
Util.Alert(String.Format("NLSE - By Kaphotics{0}" +
"{0}" +
"To begin, drag the folder that contains your exported save file (garden.dat) onto the program window.{0}" +
"{0}" +
"Credits:{0}" +
"Big thanks to marc_max (ACNL Save Editor), NeoKamek (LeafTools), and the many other contributors to the scene!",
Environment.NewLine));
e.Cancel = true; // remove ? cursor
}
}
}