-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrmMain.cs
318 lines (286 loc) · 14.7 KB
/
FrmMain.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
using SavegameEditor.Forms;
using SavegameEditor.Objects;
using SavegameEditor.Reader;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace SavegameEditor
{
//-------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------
public partial class FrmMain : Form
{
internal SvFile fileData;
//-------------------------------------------------------------------------------------------------------------------------------
public FrmMain()
{
InitializeComponent();
}
//*===============================================================================================
//* MAIN MENU - FILE
//*===============================================================================================
private void MenuItemOpenFile_Click(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
OpenSaveFile(openFileDialog.FileName);
}
}
//-------------------------------------------------------------------------------------------------------------------------------
private void MenuItem_Save_Click(object sender, EventArgs e)
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
SvWriter_PC saveFile = new SvWriter_PC();
saveFile.WriteFile(saveFileDialog.FileName, fileData);
MessageBox.Show("File Saved Successfully!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
//-------------------------------------------------------------------------------------------------------------------------------
private void MenuItemExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
//*===============================================================================================
//* MAIN MENU - SETTINGS
//*===============================================================================================
private void MenuItemSettings_SetHashCodes_Click(object sender, EventArgs e)
{
if (openFileDialogHashCodes.ShowDialog() == DialogResult.OK)
{
Globals.HashCodesFilePath = openFileDialogHashCodes.FileName;
}
}
//*===============================================================================================
//* MAIN MENU - ABOUT
//*===============================================================================================
private void MenuItemHelp_About_Click(object sender, EventArgs e)
{
using (About frmAbout = new About())
{
frmAbout.ShowDialog();
}
}
//*===============================================================================================
//* FORM EVENTS
//*===============================================================================================
private void FrmMain_Load(object sender, EventArgs e)
{
//Read hashcodes
Dictionary<uint, string> fileSection = HashCodes.Read_Sound_h(Globals.HashCodesFilePath, "HT_File");
cbxLevelHashCode.BeginUpdate();
cbxLevelHashCode.Items.AddRange(fileSection.Values.ToArray());
if (cbxLevelHashCode.Items.Count > 0)
{
cbxLevelHashCode.SelectedIndex = 0;
}
cbxLevelHashCode.EndUpdate();
}
//-------------------------------------------------------------------------------------------------------------------------------
private void FrmMain_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Copy;
}
}
//-------------------------------------------------------------------------------------------------------------------------------
private void FrmMain_DragDrop(object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop, false);
//Open only the first file
if (files.Length > 0)
{
OpenSaveFile(files[0]);
}
}
//*===============================================================================================
//* HEADER DATA - CONTROL EVENTS
//*===============================================================================================
private void CbxLevelHashCode_SelectionChangeCommitted(object sender, EventArgs e)
{
//Get Level hashcode
Dictionary<uint, string> fileSection = HashCodes.Read_Sound_h(Globals.HashCodesFilePath, "HT_File");
uint myKey = fileSection.FirstOrDefault(x => x.Value.Equals(cbxLevelHashCode.SelectedItem)).Key;
//Update property
if (fileData != null)
{
fileData.headerData.cur_level_hashcode = myKey;
}
}
//-------------------------------------------------------------------------------------------------------------------------------
private void NumScarabs_MouseClick(object sender, MouseEventArgs e)
{
if (fileData != null)
{
fileData.headerData.scarabs = (ushort)numScarabs.Value;
}
}
//-------------------------------------------------------------------------------------------------------------------------------
private void NumCrowns_MouseClick(object sender, MouseEventArgs e)
{
if (fileData != null)
{
fileData.headerData.crowns = (ushort)numCrowns.Value;
}
}
//-------------------------------------------------------------------------------------------------------------------------------
private void NumLevelRestart_MouseClick(object sender, MouseEventArgs e)
{
if (fileData != null)
{
fileData.headerData.cur_level_restart_id = (uint)numLevelRestart.Value;
}
}
//-------------------------------------------------------------------------------------------------------------------------------
private void NumLevelEntrance_MouseClick(object sender, MouseEventArgs e)
{
if (fileData != null)
{
fileData.headerData.cur_level_entrance_id = (int)numLevelEntrance.Value;
}
}
//-------------------------------------------------------------------------------------------------------------------------------
private void NumHealthAnkhs_MouseClick(object sender, MouseEventArgs e)
{
if (fileData != null)
{
fileData.headerData.health_ankhs = (ushort)numHealthAnkhs.Value;
}
}
//*===============================================================================================
//* SECONDARY HEADER - FORM EVENTS
//*===============================================================================================
private void NudHealthThirds_MouseClick(object sender, MouseEventArgs e)
{
if (fileData != null)
{
fileData.health_thirds = (uint)nudHealthThirds.Value;
}
}
//-------------------------------------------------------------------------------------------------------------------------------
private void NudTotalHealthThirds_MouseClick(object sender, MouseEventArgs e)
{
if (fileData != null)
{
fileData.total_health_thirds = (uint)nudTotalHealthThirds.Value;
}
}
//*===============================================================================================
//* PRINT DATA METHODS
//*===============================================================================================
internal void PrintHeader(SvFile savegameData)
{
Dictionary<uint, string> HashTable = HashCodes.Read_Sound_h(Globals.HashCodesFilePath, "HT_File");
txtVersion.Text = "0x" + savegameData.headerData.version.ToString("X8");
txtbTag.Text = savegameData.headerData.save_name_tag;
numScarabs.Value = savegameData.headerData.scarabs;
numCrowns.Value = savegameData.headerData.crowns;
if (HashTable.ContainsKey(savegameData.headerData.cur_level_hashcode))
{
cbxLevelHashCode.SelectedItem = HashTable[savegameData.headerData.cur_level_hashcode];
}
numLevelRestart.Value = savegameData.headerData.cur_level_restart_id;
numLevelEntrance.Value = savegameData.headerData.cur_level_entrance_id;
numHealthAnkhs.Value = savegameData.headerData.health_ankhs;
//Game time
TimeSpan gameTime = TimeSpan.FromSeconds(savegameData.headerData.game_time_sec / 60);
txtGameTime.Text = string.Format("{0:00}:{1:00}:{2:00}", gameTime.Hours, gameTime.Minutes, gameTime.Seconds);
//Current Level Time
TimeSpan levelTime = TimeSpan.FromSeconds(savegameData.headerData.cur_level_timer / 60);
txtbLevelTime.Text = string.Format("{0:00}:{1:00}:{2:00}", levelTime.Hours, levelTime.Minutes, levelTime.Seconds);
}
//-------------------------------------------------------------------------------------------------------------------------------
private void TxtGameTime_Validated(object sender, EventArgs e)
{
if (TimeSpan.TryParse(txtGameTime.Text, out TimeSpan gameTime))
{
uint convertedTime = (uint)(gameTime.TotalSeconds * 60);
fileData.headerData.game_time_sec = convertedTime;
}
else
{
MessageBox.Show("Invalid format. Please enter a valid time in the format HH:MM:SS.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//-------------------------------------------------------------------------------------------------------------------------------
private void TxtbLevelTime_Validated(object sender, EventArgs e)
{
if (TimeSpan.TryParse(txtbLevelTime.Text, out TimeSpan levelTime))
{
int convertedTime = (int)(levelTime.TotalSeconds * 60);
fileData.headerData.cur_level_timer = convertedTime;
}
else
{
MessageBox.Show("Invalid format. Please enter a valid time in the format HH:MM:SS.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//-------------------------------------------------------------------------------------------------------------------------------
internal void PrintSecondaryHeader(SvFile savegameData)
{
nudHealthThirds.Value = savegameData.health_thirds;
nudTotalHealthThirds.Value = savegameData.total_health_thirds;
}
//-------------------------------------------------------------------------------------------------------------------------------
private void OpenSaveFile(string filePath)
{
if (!string.IsNullOrEmpty(Globals.HashCodesFilePath) && File.Exists(Globals.HashCodesFilePath))
{
//Read file
SvReader_PC fileReader = new SvReader_PC();
try
{
fileData = fileReader.ReadFile(filePath);
txtFilePath.Text = filePath;
//Show data
UserControl_Objectives.PrintObjectives(fileData);
PrintHeader(fileData);
PrintSecondaryHeader(fileData);
int sphinxItems = SphinxInventory.LoadInventory(fileData.sphinx_inventory);
StatusLabelSphinxItemsValue.Text = sphinxItems.ToString();
int mummyItems = MummyInventory.LoadInventory(fileData.mummy_inventory);
StatusLabelMummyItemsValue.Text = mummyItems.ToString();
UserControl_LevelTriggers.PrintLevelTriggers(fileData);
UserControl_OtherData.PrintCameraSettings(fileData);
UserControl_OtherData.PrintProgrammableButtons(fileData);
userControl_PlayerData1.PrintPlayerData(fileData);
UserControl_OtherData.PrintInventoryNotes(fileData);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
else
{
MessageBox.Show("Please specify the path to \"hashcodes.h\" before opening the file. This dependency is required for proper functionality.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
//*===============================================================================================
//* TEST BUTTONS
//*===============================================================================================
private void Button_Test_Click(object sender, EventArgs e)
{
OpenSaveFile(@"C:\Users\Jordi Martinez\Saved Games\Sphinx__bin_PC\DATA0");
SvWriter_PC saveFile = new SvWriter_PC();
saveFile.WriteFile(@"C:\Users\Jordi Martinez\Desktop\DATA0", fileData);
}
//-------------------------------------------------------------------------------------------------------------------------------
private void BtnAutoLOad_Click(object sender, EventArgs e)
{
OpenSaveFile(@"C:\Users\Jordi Martinez\Saved Games\Sphinx__bin_PC\DATA0.OLD-2023.07.23-15.44.18");
}
}
//-------------------------------------------------------------------------------------------------------------------------------
}