forked from Gota7/SM64DSe-Ultimate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CLPS_Form.cs
327 lines (297 loc) · 16.3 KB
/
CLPS_Form.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
323
324
325
326
327
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;
using SM64DSe.SM64DSFormats;
namespace SM64DSe
{
public partial class CLPS_Form : Form
{
enum Columns
{
TEXTURE = 0,
WATER,
VIEW_ID,
BEHAV_1,
CAM_BEHAV,
BEHAV_2,
CAM_THROUGH,
TOXIC,
UNK_26,
PAD_1,
WIND_ID,
PAD_2
}
struct ColStruct
{
public readonly string m_Name;
public readonly int m_Shift;
public readonly ulong m_And;
public readonly string[] m_TypeNames;
public ColStruct(string name, int shift, ulong and, string[] typeNames)
{
m_Name = name;
m_Shift = shift;
m_And = and;
m_TypeNames = typeNames;
}
public ulong GetFlag(ulong flags) { return flags >> m_Shift & m_And; }
public void SetFlag(ref ulong flags, ulong val)
{ flags = flags & ~(m_And << m_Shift) | (val & m_And) << m_Shift; }
}
ColStruct[] columns = new ColStruct[12]
{
new ColStruct ("Texture" , 0, 0x1fuL, new string[]{"Basic/Rocky ",
"Path-Textured ",
"Grassy ",
"Puddle ",
"Rocky ",
"Wooden ",
"Snowy ",
"Icy ",
"Sandy ",
"Flowery ",
"Rock (Merry Go-Round Music) ",
"Wood (Merry Go-Round Music) ",
"Grate-Meshed ",
"Weirdly Textured (No Sound) ",
"Weirdly Textured (No Sound) ",
"Weirdly Textured (No Sound) ",
"Echoed Basic/Rock ",
"Echoed Path ",
"Echoed Grass ",
"Echoed Puddle ",
"Echoed Rock ",
"Echoed Wood ",
"Echoed Snow ",
"Echoed Ice ",
"Echoed Sand ",
"Echoed Flowers ",
"Echoed Rock 2 ",
"Echoed Wood 2 ",
"Echoed Grate Mesh ",
"Weirdly Textured ",
"Weirdly Textured ",
"Weirdly Textured ",
"Weirdly Textured ",}),
new ColStruct ("Water" , 5, 0x01uL, new string[]{"",
"Water-Defining "}),
new ColStruct ("View ID" , 6, 0x3fuL, new string[]{}),
new ColStruct ("Traction" , 12, 0x07uL, new string[]{"Slippery, Crawlable ",
"Unslippable ",
"Unslippable, No Steep ",
"Slippery-Sloped ",
"Slippery ",
"Slide ",
"Slippery, Non-Crawlable ",
"Slippery, Non-Crawlable? "}),
new ColStruct ("Camera Type" , 15, 0x0fuL, new string[]{"Normal (Re-Adjusts Rotation) ",
"Go-Behind ",
"Zoom-Out-And-Go-Behind ",
"Go-Behind ",
"Go-Behind ",
"Weird ",
"Normal ",
"Go-Behind For Bosses ",
"Go-Behind ",
"8-Directional ",
"Non-Rotating ",
"Close-Up-And-Personal ",
"Go-Behind ",
"Go-Behind ",
"Go-Behind ",
"Go-Behind "}),
new ColStruct ("Behavior" , 19, 0x1fuL, new string[]{"Surface ",
"Lava ",
"Weird Surface ",
"Hanging Mesh ",
"Death Plane, Lose Life ",
"Death Plane, No Lose Life ",
"Jump-Limiting Surface ",
"Slow Half-Quicksand ",
"Slow Bottomless Quicksand ",
"Instant Quicksand ",
"Weird Surface ",
"Wind Animation/Sound ",
"Weird Surface ",
"Enter ? Switch ",
"No Stuck In Floor ",
"Start Line ",
"Finish Line (Star ID 2) ",
"Vanish-Luigi-Transparent Surface ",
"Get-Off-Of-Me Surface (Endless Stairs) ",
"Gust Plane (Up) ",
"Crawl Transparent ",
"Weird Surface ",
"Weird Surface ",
"Weird Surface ",
"Weird Surface ",
"Weird Surface ",
"Weird Surface ",
"Weird Surface ",
"Weird Surface ",
"Weird Surface ",
"Weird Surface ",
"Weird Surface "}),
new ColStruct ("Camera Through" , 24, 0x01uL, new string[]{"",
"Go-Through " }),
new ColStruct ("Toxic" , 25, 0x01uL, new string[]{"",
"Toxic "}),
new ColStruct ("Unk << 26" , 26, 0x01uL, new string[]{}),
new ColStruct ("Pad << 27" , 27, 0x1fuL, new string[]{}),
new ColStruct ("Wind Path ID", 32, 0xffuL, new string[]{}),
new ColStruct ("Pad << 40" , 40, 0xffffffuL, new string[]{}),
};
CLPS m_CLPS;
public CLPS_Form(CLPS CLPS)
{
InitializeComponent();
this.m_CLPS = CLPS;
for (int i = 0; i < 52; i++)
cbxLevels.Items.Add(i + " - " + Strings.LevelNames[i]);
LoadCLPSData();
}
private void LoadCLPSData()
{
txtNumEntries.Text = "" + m_CLPS.Count;
gridCLPSData.RowCount = m_CLPS.Count;
if (gridCLPSData.ColumnCount != columns.Length + 1)
{
gridCLPSData.ColumnCount = columns.Length;
// Set column widths
gridCLPSData.RowHeadersWidth = 54;
for (int i = 0; i < columns.Length; i++)
{
gridCLPSData.Columns[i].Width = 54;
gridCLPSData.Columns[i].HeaderText = columns[i].m_Name;
}
DataGridViewTextBoxColumn cmb = new DataGridViewTextBoxColumn();
cmb.HeaderText = "Type/Description";
cmb.ReadOnly = true;
cmb.Width = 500;
gridCLPSData.Columns.Add(cmb);
}
for (int i = 0; i < m_CLPS.Count; i++)
{
gridCLPSData.Rows[i].HeaderCell.Value = "" + i;
for (int j = 0; j < columns.Length; j++)
{
gridCLPSData.Rows[i].Cells[j].Value = columns[j].GetFlag(m_CLPS[i].flags);
}
// Fill in Type/Description column
gridCLPSData.Rows[i].Cells[columns.Length].Value =
columns[(int)Columns.WATER].m_TypeNames[m_CLPS[i].m_Water] +
columns[(int)Columns.TOXIC].m_TypeNames[m_CLPS[i].m_Toxic] +
(m_CLPS[i].m_WindID != 0xff ? "Windy " : "") +
columns[(int)Columns.TEXTURE].m_TypeNames[m_CLPS[i].m_Texture] +
columns[(int)Columns.BEHAV_1].m_TypeNames[m_CLPS[i].m_Traction] +
columns[(int)Columns.BEHAV_2].m_TypeNames[m_CLPS[i].m_Behav] +
"w/ " +
columns[(int)Columns.CAM_THROUGH].m_TypeNames[m_CLPS[i].m_CamThrough] +
columns[(int)Columns.CAM_BEHAV].m_TypeNames[m_CLPS[i].m_CamBehav] +
"Camera" +
(m_CLPS[i].m_ViewID != 0x3f ? ", View ID " + m_CLPS[i].m_ViewID.ToString() : "") +
(m_CLPS[i].m_WindID != 0xff ? ", Wind Path ID " + m_CLPS[i].m_WindID.ToString() : "");
}
}
void gridCLPSData_CellEndEdit(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
{
try
{
if (e.ColumnIndex != columns.Length)
{
ulong clps = m_CLPS[e.RowIndex].flags;
columns[e.ColumnIndex].SetFlag(ref clps,
ulong.Parse(gridCLPSData.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()));
CLPS.Entry temp = new CLPS.Entry();
temp.flags = clps;
m_CLPS[e.RowIndex] = temp;
}
else
{
return;
}
LoadCLPSData();
}
catch (Exception ex)
{
new ExceptionMessageBox(ex).ShowDialog();
return;
}
}
private void CopyCLPS(int sourceLevel)
{
NitroOverlay otherOVL = new NitroOverlay(Program.m_ROM, Program.m_ROM.GetLevelOverlayID(sourceLevel));
uint other_clps_addr = otherOVL.ReadPointer(0x60);
ushort other_clps_num = otherOVL.Read16(other_clps_addr + 0x06);
uint other_clps_size = (uint)(8 + (other_clps_num * 8));
m_CLPS = new CLPS();
for(int i = 0; i < other_clps_num; ++i)
{
ulong flags = otherOVL.Read32((uint)(other_clps_addr + 8 + 8 * i + 0));
flags |= (ulong)otherOVL.Read32((uint)(other_clps_addr + 8 + 8 * i + 4)) << 32;
CLPS.Entry clps = new CLPS.Entry();
clps.flags = flags;
m_CLPS.Add(clps);
}
LoadCLPSData();
}
private void btnCopy_Click(object sender, EventArgs e)
{
if (cbxLevels.SelectedIndex != -1)
CopyCLPS(cbxLevels.SelectedIndex);
}
private void btnAdd_Click(object sender, EventArgs e)
{
CLPS.Entry clps = new CLPS.Entry();
clps.flags = 0x000000ff00000fc0;
if (gridCLPSData.SelectedRows.Count == 0)
m_CLPS.Add(clps);
else
m_CLPS.m_Entries.Insert(gridCLPSData.SelectedRows[0].Index, clps);
// Reload data
LoadCLPSData();
}
private void btnRemove_Click(object sender, EventArgs e)
{
if (gridCLPSData.SelectedRows.Count == 0)
MessageBox.Show("Please select a row to delete.");
else
{
m_CLPS.m_Entries.RemoveAt(gridCLPSData.SelectedRows[0].Index);
// Reload data
LoadCLPSData();
}
}
private void btnShiftUp_Click(object sender, EventArgs e)
{
if (gridCLPSData.SelectedRows.Count == 0)
MessageBox.Show("Please select a row to move.");
else if (gridCLPSData.SelectedRows[0].Index != 0)
{
CLPS.Entry temp = m_CLPS[gridCLPSData.SelectedRows[0].Index];
m_CLPS[gridCLPSData.SelectedRows[0].Index] = m_CLPS[gridCLPSData.SelectedRows[0].Index - 1];
m_CLPS[gridCLPSData.SelectedRows[0].Index - 1] = temp;
}
LoadCLPSData();
}
private void btnShiftDown_Click(object sender, EventArgs e)
{
if (gridCLPSData.SelectedRows.Count == 0)
MessageBox.Show("Please select a row to move.");
else if (gridCLPSData.SelectedRows[0].Index != gridCLPSData.Rows.Count - 1)
{
CLPS.Entry temp = m_CLPS[gridCLPSData.SelectedRows[0].Index];
m_CLPS[gridCLPSData.SelectedRows[0].Index] = m_CLPS[gridCLPSData.SelectedRows[0].Index + 1];
m_CLPS[gridCLPSData.SelectedRows[0].Index + 1] = temp;
}
LoadCLPSData();
}
}
}