-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSQLBuilderControl.cs
322 lines (256 loc) · 12.4 KB
/
SQLBuilderControl.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
using PhatACCacheBinParser.ACE_Helpers;
using PhatACCacheBinParser.Common;
using PhatACCacheBinParser.Properties;
using PhatACCacheBinParser.Seg1_RegionDescExtendedData;
using PhatACCacheBinParser.Seg2_SpellTableExtendedData;
using PhatACCacheBinParser.Seg3_TreasureTable;
using PhatACCacheBinParser.Seg4_CraftTable;
using PhatACCacheBinParser.Seg5_HousingPortals;
using PhatACCacheBinParser.Seg6_LandBlockExtendedData;
using PhatACCacheBinParser.Seg8_QuestDefDB;
using PhatACCacheBinParser.Seg9_WeenieDefaults;
using PhatACCacheBinParser.SegA_MutationFilters;
using PhatACCacheBinParser.SegB_GameEventDefDB;
using PhatACCacheBinParser.SQLWriters;
namespace PhatACCacheBinParser
{
public partial class SQLBuilderControl : UserControl
{
public SQLBuilderControl()
{
InitializeComponent();
}
private readonly RegionDescExtendedData regionDescExtendedData = new RegionDescExtendedData();
private readonly SpellTableExtendedData spellTableExtendedData = new SpellTableExtendedData();
private readonly TreasureTable treasureTable = new TreasureTable();
private readonly CraftingTable craftingTable = new CraftingTable();
private readonly HousingPortalsTable housingPortalsTable = new HousingPortalsTable();
private readonly LandBlockData landBlockData = new LandBlockData();
// Segment 7
private readonly QuestDefDB questDefDB = new QuestDefDB();
private readonly WeenieDefaults weenieDefaults = new WeenieDefaults();
private readonly MutationFilters mutationFilters = new MutationFilters();
private readonly GameEventDefDB gameEventDefDB = new GameEventDefDB();
private readonly Dictionary<uint, string> weenieNames = new Dictionary<uint, string>();
private async void cmdParseAll_Click(object sender, EventArgs e)
{
cmdParseAll.Enabled = false;
progressParseSources.Style = ProgressBarStyle.Marquee;
// Read all the inputs here
await Task.Run(delegate
{
// Read all the inputs here
TryParseSegment((string)Settings.Default["_1SourceBin"], regionDescExtendedData);
TryParseSegment((string)Settings.Default["_2SourceBin"], spellTableExtendedData);
TryParseSegment((string)Settings.Default["_3SourceBin"], treasureTable);
TryParseSegment((string)Settings.Default["_4SourceBin"], craftingTable);
TryParseSegment((string)Settings.Default["_5SourceBin"], housingPortalsTable);
TryParseSegment((string)Settings.Default["_6SourceBin"], landBlockData);
// Segment 7
TryParseSegment((string)Settings.Default["_8SourceBin"], questDefDB);
TryParseSegment((string)Settings.Default["_9SourceBin"], weenieDefaults);
TryParseSegment((string)Settings.Default["_ASourceBin"], mutationFilters);
TryParseSegment((string)Settings.Default["_BSourceBin"], gameEventDefDB);
CollectWeenieNames();
});
progressParseSources.Style = ProgressBarStyle.Continuous;
progressParseSources.Value = 100;
// Now that we've parsed all of our input segments, we can enable outputs
foreach (Control control in Controls)
{
if (control is Button && control != sender)
control.Enabled = true;
}
}
private static bool TryParseSegment<T>(string sourceBin, T segment) where T : Segment
{
try
{
if (!File.Exists(sourceBin))
return false;
var data = File.ReadAllBytes(sourceBin);
// Parse the data
using (var memoryStream = new MemoryStream(data))
using (var binaryReader = new BinaryReader(memoryStream))
{
if (segment.Unpack(binaryReader))
return true;
}
}
catch
{
// ignored
}
return false;
}
private void CollectWeenieNames()
{
weenieNames.Clear();
foreach (var weenie in weenieDefaults.Weenies)
{
var name = weenie.Value.Description;
if (String.IsNullOrEmpty(name))
{
if (!WeenieClassNames.Values.TryGetValue(weenie.Value.WCID, out name))
name = "ace" + weenie.Value.WCID;
}
weenieNames.Add(weenie.Value.WCID, name);
}
}
private async void cmd1RegionsParse_Click(object sender, EventArgs e)
{
cmd1RegionsParse.Enabled = false;
progressBarRegions.Style = ProgressBarStyle.Marquee;
progressBarRegions.Value = 0;
await Task.Run(() =>
{
var aceEncounters = regionDescExtendedData.ConvertToACE(landBlockData);
RegionDescSQLWriter.WriteFiles(aceEncounters, Settings.Default["OutputFolder"] + "\\1 RegionDescExtendedData\\SQL\\", weenieNames);
});
progressBarRegions.Style = ProgressBarStyle.Continuous;
progressBarRegions.Value = 100;
cmd1RegionsParse.Enabled = true;
}
private async void cmd2SpellsParse_Click(object sender, EventArgs e)
{
cmd2SpellsParse.Enabled = false;
progressBarSpells.Style = ProgressBarStyle.Marquee;
progressBarSpells.Value = 0;
await Task.Run(() =>
{
var aceSpells = spellTableExtendedData.ConvertToACE();
SpellsSQLWriter.WriteFiles(aceSpells, Settings.Default["OutputFolder"] + "\\2 SpellTableExtendedData\\SQL\\", weenieNames);
});
progressBarSpells.Style = ProgressBarStyle.Continuous;
progressBarSpells.Value = 100;
cmd2SpellsParse.Enabled = true;
}
private async void cmd3TreasureParse_Click(object sender, EventArgs e)
{
cmd3TreasureParse.Enabled = false;
progressBarTreasure.Style = ProgressBarStyle.Marquee;
progressBarTreasure.Value = 0;
await Task.Run(() =>
{
var treasureDeath = treasureTable.DeathTreasure.ConvertToACE();
var treasureWielded = treasureTable.WieldedTreasure.ConvertToACE();
TreasureSQLWriter.WriteFiles(treasureDeath, Settings.Default["OutputFolder"] + "\\3 TreasureTable\\SQL\\Death\\");
TreasureSQLWriter.WriteFiles(treasureWielded, Settings.Default["OutputFolder"] + "\\3 TreasureTable\\SQL\\Wielded\\", weenieNames);
});
progressBarTreasure.Style = ProgressBarStyle.Continuous;
progressBarTreasure.Value = 100;
cmd3TreasureParse.Enabled = true;
}
private async void cmd4CraftingParse_Click(object sender, EventArgs e)
{
cmd4CraftingParse.Enabled = false;
progressBarCrafting.Style = ProgressBarStyle.Marquee;
progressBarCrafting.Value = 0;
await Task.Run(() =>
{
var aceCraftingTables = craftingTable.ConvertToACE();
CraftingSQLWriter.WriteFiles(aceCraftingTables, weenieNames, Settings.Default["OutputFolder"] + "\\4 CraftTable\\SQL\\");
});
progressBarCrafting.Style = ProgressBarStyle.Continuous;
progressBarCrafting.Value = 100;
cmd4CraftingParse.Enabled = true;
}
private async void cmd5HousingParse_Click(object sender, EventArgs e)
{
cmd5HousingParse.Enabled = false;
progressBarHousing.Style = ProgressBarStyle.Marquee;
progressBarHousing.Value = 0;
await Task.Run(() =>
{
var aceHouePortals = housingPortalsTable.ConvertToACE();
HouseSQLWriter.WriteFiles(aceHouePortals, Settings.Default["OutputFolder"] + "\\5 HousingPortals\\SQL\\");
});
progressBarHousing.Style = ProgressBarStyle.Continuous;
progressBarHousing.Value = 100;
cmd5HousingParse.Enabled = true;
}
private async void cmd6LandblocksParse_Click(object sender, EventArgs e)
{
cmd6LandblocksParse.Enabled = false;
progressBarLandblocks.Style = ProgressBarStyle.Marquee;
progressBarLandblocks.Value = 0;
await Task.Run(() =>
{
var landblockInstances = landBlockData.ConvertToACE();
LandblockSQLWriter.WriteFiles(landblockInstances, Settings.Default["OutputFolder"] + "\\6 LandBlockExtendedData\\SQL\\", weenieNames);
});
progressBarLandblocks.Style = ProgressBarStyle.Continuous;
progressBarLandblocks.Value = 100;
cmd6LandblocksParse.Enabled = true;
}
private async void cmd8QuestsParse_Click(object sender, EventArgs e)
{
cmd8QuestsParse.Enabled = false;
progressBarQuests.Style = ProgressBarStyle.Marquee;
progressBarQuests.Value = 0;
await Task.Run(() =>
{
var aceQuests = questDefDB.ConvertToACE();
QuestSQLWriter.WriteFiles(aceQuests, Settings.Default["OutputFolder"] + "\\8 QuestDefDB\\SQL\\");
});
progressBarQuests.Style = ProgressBarStyle.Continuous;
progressBarQuests.Value = 100;
cmd8QuestsParse.Enabled = true;
}
private async void cmd9WeeniesParse_Click(object sender, EventArgs e)
{
cmd9WeeniesParse.Enabled = false;
progressBarWeenies.Style = ProgressBarStyle.Marquee;
progressBarWeenies.Value = 0;
await Task.Run(() =>
{
// ClassId 30732 has -1 for an IID.. i think this was to make it so noone could wield
var aceWeenies = weenieDefaults.ConvertToACE();
var aceTreasureWielded = treasureTable.WieldedTreasure.ConvertToACE();
var aceTreasureDeath = treasureTable.DeathTreasure.ConvertToACE();
var weenies = new Dictionary<uint, ACE.Database.Models.World.Weenie>();
foreach (var item in aceWeenies)
{
if (!weenies.ContainsKey(item.ClassId))
weenies.Add(item.ClassId, item);
}
var treasureWielded = new Dictionary<uint, List<ACE.Database.Models.World.TreasureWielded>>();
foreach (var item in aceTreasureWielded)
{
if (!treasureWielded.ContainsKey(item.TreasureType))
treasureWielded.Add(item.TreasureType, new List<ACE.Database.Models.World.TreasureWielded>());
treasureWielded[item.TreasureType].Add(item);
}
var treasureDeath = new Dictionary<uint, ACE.Database.Models.World.TreasureDeath>();
foreach (var item in aceTreasureDeath)
{
if (!treasureDeath.ContainsKey(item.TreasureType))
treasureDeath.Add(item.TreasureType, item);
}
WeenieSQLWriter.WriteFiles(aceWeenies, Settings.Default["OutputFolder"] + "\\9 WeenieDefaults\\SQL\\", weenieNames, treasureWielded, treasureDeath, weenies);
});
progressBarWeenies.Style = ProgressBarStyle.Continuous;
progressBarWeenies.Value = 100;
cmd9WeeniesParse.Enabled = true;
}
private async void cmdBEventsParse_Click(object sender, EventArgs e)
{
cmdBEventsParse.Enabled = false;
progressBarEvents.Style = ProgressBarStyle.Marquee;
progressBarEvents.Value = 0;
await Task.Run(() =>
{
var aceEvents = gameEventDefDB.ConvertToACE();
EventSQLWriter.WriteFiles(aceEvents, Settings.Default["OutputFolder"] + "\\B GameEventDefDB\\SQL\\");
});
progressBarEvents.Style = ProgressBarStyle.Continuous;
progressBarEvents.Value = 100;
cmdBEventsParse.Enabled = true;
}
}
}