1
1
#include " gui/EmulatedUSBDevices/EmulatedUSBDeviceFrame.h"
2
2
3
3
#include < algorithm>
4
- #include < random>
5
4
6
5
#include " config/CemuConfig.h"
7
6
#include " gui/helpers/wxHelpers.h"
8
7
#include " gui/wxHelper.h"
9
8
#include " util/helpers/helpers.h"
10
9
11
10
#include " Cafe/OS/libs/nsyshid/nsyshid.h"
12
- #include " Cafe/OS/libs/nsyshid/Skylander.h"
13
11
14
12
#include " Common/FileStream.h"
15
13
@@ -75,7 +73,7 @@ wxPanel* EmulatedUSBDeviceFrame::AddSkylanderPage(wxNotebook* notebook)
75
73
});
76
74
row->Add (m_emulatePortal, 1 , wxEXPAND | wxALL, 2 );
77
75
boxSizer->Add (row, 1 , wxEXPAND | wxALL, 2 );
78
- for (int i = 0 ; i < 16 ; i++)
76
+ for (int i = 0 ; i < nsyshid::MAX_SKYLANDERS ; i++)
79
77
{
80
78
boxSizer->Add (AddSkylanderRow (i, box), 1 , wxEXPAND | wxALL, 2 );
81
79
}
@@ -153,7 +151,7 @@ void EmulatedUSBDeviceFrame::LoadSkylanderPath(uint8 slot, wxString path)
153
151
uint16 skyVar = uint16 (fileData[0x1D ]) << 8 | uint16 (fileData[0x1C ]);
154
152
155
153
uint8 portalSlot = nsyshid::g_skyportal.LoadSkylander (fileData.data (),
156
- std::move (skyFile));
154
+ std::move (skyFile));
157
155
m_skySlots[slot] = std::tuple (portalSlot, skyId, skyVar);
158
156
UpdateSkylanderEdits ();
159
157
}
@@ -189,11 +187,11 @@ CreateSkylanderDialog::CreateSkylanderDialog(wxWindow* parent, uint8 slot)
189
187
auto * comboBox = new wxComboBox (this , wxID_ANY);
190
188
comboBox->Append (" ---Select---" , reinterpret_cast <void *>(0xFFFFFFFF ));
191
189
wxArrayString filterlist;
192
- for (auto it = nsyshid::listSkylanders. begin (); it != nsyshid::listSkylanders. end (); it++ )
190
+ for (const auto & it : nsyshid::g_skyportal. GetListSkylanders () )
193
191
{
194
- const uint32 variant = uint32 (uint32 (it-> first .first ) << 16 ) | uint32 (it-> first .second );
195
- comboBox->Append (it-> second , reinterpret_cast <void *>(variant));
196
- filterlist.Add (it-> second );
192
+ const uint32 variant = uint32 (uint32 (it. first .first ) << 16 ) | uint32 (it. first .second );
193
+ comboBox->Append (it. second , reinterpret_cast <void *>(variant));
194
+ filterlist.Add (it. second );
197
195
}
198
196
comboBox->SetSelection (0 );
199
197
bool enabled = comboBox->AutoComplete (filterlist);
@@ -233,16 +231,7 @@ CreateSkylanderDialog::CreateSkylanderDialog(wxWindow* parent, uint8 slot)
233
231
}
234
232
uint16 skyId = longSkyId & 0xFFFF ;
235
233
uint16 skyVar = longSkyVar & 0xFFFF ;
236
- const auto foundSky = nsyshid::listSkylanders.find (std::make_pair (skyId, skyVar));
237
- wxString predefName;
238
- if (foundSky != nsyshid::listSkylanders.end ())
239
- {
240
- predefName = foundSky->second + " .sky" ;
241
- }
242
- else
243
- {
244
- predefName = wxString::Format (_ (" Unknown(%i %i).sky" ), skyId, skyVar);
245
- }
234
+ wxString predefName = nsyshid::g_skyportal.FindSkylander (skyId, skyVar) + " .sky" ;
246
235
wxFileDialog
247
236
saveFileDialog (this , _ (" Create Skylander file" ), " " , predefName,
248
237
" SKY files (*.sky)|*.sky" , wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
@@ -251,46 +240,15 @@ CreateSkylanderDialog::CreateSkylanderDialog(wxWindow* parent, uint8 slot)
251
240
return ;
252
241
253
242
m_filePath = saveFileDialog.GetPath ();
254
-
255
- wxFileOutputStream output_stream (saveFileDialog.GetPath ());
256
- if (!output_stream.IsOk ())
243
+
244
+ if (!nsyshid::g_skyportal.CreateSkylander (_utf8ToPath (m_filePath.utf8_string ()), skyId, skyVar))
257
245
{
258
- wxMessageDialog saveError (this , " Error Creating Skylander File" );
246
+ wxMessageDialog errorMessage (this , " Failed to create file" );
247
+ errorMessage.ShowModal ();
248
+ this ->EndModal (0 );
259
249
return ;
260
250
}
261
251
262
- std::array<uint8, 0x40 * 0x10 > data{};
263
-
264
- uint32 first_block = 0x690F0F0F ;
265
- uint32 other_blocks = 0x69080F7F ;
266
- memcpy (&data[0x36 ], &first_block, sizeof (first_block));
267
- for (size_t index = 1 ; index < 0x10 ; index++)
268
- {
269
- memcpy (&data[(index * 0x40 ) + 0x36 ], &other_blocks, sizeof (other_blocks));
270
- }
271
- std::random_device rd;
272
- std::mt19937 mt (rd ());
273
- std::uniform_int_distribution<int > dist (0 , 255 );
274
- data[0 ] = dist (mt);
275
- data[1 ] = dist (mt);
276
- data[2 ] = dist (mt);
277
- data[3 ] = dist (mt);
278
- data[4 ] = data[0 ] ^ data[1 ] ^ data[2 ] ^ data[3 ];
279
- data[5 ] = 0x81 ;
280
- data[6 ] = 0x01 ;
281
- data[7 ] = 0x0F ;
282
-
283
- memcpy (&data[0x10 ], &skyId, sizeof (skyId));
284
- memcpy (&data[0x1C ], &skyVar, sizeof (skyVar));
285
-
286
- uint16 crc = nsyshid::g_skyportal.SkylanderCRC16 (0xFFFF , data.data (), 0x1E );
287
-
288
- memcpy (&data[0x1E ], &crc, sizeof (crc));
289
-
290
- output_stream.SeekO (0 );
291
- output_stream.WriteAll (data.data (), data.size ());
292
- output_stream.Close ();
293
-
294
252
this ->EndModal (1 );
295
253
});
296
254
auto * cancelButton = new wxButton (this , wxID_ANY, _ (" Cancel" ));
@@ -328,21 +286,13 @@ wxString CreateSkylanderDialog::GetFilePath() const
328
286
329
287
void EmulatedUSBDeviceFrame::UpdateSkylanderEdits ()
330
288
{
331
- for (auto i = 0 ; i < 16 ; i++)
289
+ for (auto i = 0 ; i < nsyshid::MAX_SKYLANDERS ; i++)
332
290
{
333
291
std::string displayString;
334
292
if (auto sd = m_skySlots[i])
335
293
{
336
294
auto [portalSlot, skyId, skyVar] = sd.value ();
337
- auto foundSky = nsyshid::listSkylanders.find (std::make_pair (skyId, skyVar));
338
- if (foundSky != nsyshid::listSkylanders.end ())
339
- {
340
- displayString = foundSky->second ;
341
- }
342
- else
343
- {
344
- displayString = fmt::format (" Unknown (Id:{} Var:{})" , skyId, skyVar);
345
- }
295
+ displayString = nsyshid::g_skyportal.FindSkylander (skyId, skyVar);
346
296
}
347
297
else
348
298
{
0 commit comments