-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathpatch_base_js.diff
More file actions
88 lines (85 loc) · 4.26 KB
/
patch_base_js.diff
File metadata and controls
88 lines (85 loc) · 4.26 KB
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
--- templates/base.html 2023-10-25 15:01:00.000000000 -0400
+++ templates/base.html 2023-10-25 15:02:00.000000000 -0400
@@ -321,14 +321,79 @@
$('#id_arguments').select2({ placeholder: 'Select arguments', allowClear: true });
+ let currentRollOptions = null;
+
+ async function calculateSHA256(file) {
+ const arrayBuffer = await file.arrayBuffer();
+ const hashBuffer = await crypto.subtle.digest('SHA-256', arrayBuffer);
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
+ const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
+ return hashHex.toUpperCase();
+ }
+
+ $('#rom-validation-submit').on('click', async function() {
+ const fileInput = document.getElementById('rom-validation-file');
+ const errorDiv = document.getElementById('rom-validation-error');
+ const rememberCheckbox = document.getElementById('remember-rom-validation');
+
+ if (!fileInput.files || fileInput.files.length === 0) {
+ errorDiv.innerText = "Please select a ROM file.";
+ errorDiv.style.display = 'block';
+ return;
+ }
+
+ const file = fileInput.files[0];
+ errorDiv.style.display = 'none';
+ $(this).prop('disabled', true).text('Validating...');
+
+ try {
+ const hash = await calculateSHA256(file);
+ const validHashes = [
+ '0F51B4FCA41B7FD509E4B8F9D543151F68EFA5E97B08493E4B2A0C06F5D8D5E2', // Unheadered
+ '60F6F506F928A6D3A6F1D0E43E5101E689C8F5B191B93F7159986326E1E909B1' // Headered
+ ];
+
+ if (validHashes.includes(hash)) {
+ if (rememberCheckbox.checked) {
+ localStorage.setItem('romValidated', 'true');
+ }
+ closeModal('rom-validation-modal');
+ if (currentRollOptions) {
+ initiateTaskAndPoll(currentRollOptions);
+ }
+ } else {
+ errorDiv.innerText = "Invalid ROM file. The sha256 value does not match the expected value.";
+ errorDiv.style.display = 'block';
+ }
+ } catch (error) {
+ errorDiv.innerText = "Error reading or validating the file. Please try again.";
+ errorDiv.style.display = 'block';
+ console.error("ROM validation error:", error);
+ } finally {
+ $(this).prop('disabled', false).text('Validate and Roll');
+ }
+ });
+
$(document).on('click', '.js-roll-seed-dispatcher', function() {
const button = $(this);
const randomLine = SILLY_THINGS.length > 0 ? SILLY_THINGS[Math.floor(Math.random() * SILLY_THINGS.length)] : "Rolling your seed...";
- initiateTaskAndPoll({
- dispatcherUrl: button.data('url'),
- statusUrlBase: button.data('status-url-base'),
- modalTitle: 'Rolling Seed...',
- modalMessage: randomLine.charAt(0).toUpperCase() + randomLine.slice(1),
- });
+ currentRollOptions = {
+ dispatcherUrl: button.data('url'),
+ statusUrlBase: button.data('status-url-base'),
+ modalTitle: 'Rolling Seed...',
+ modalMessage: randomLine.charAt(0).toUpperCase() + randomLine.slice(1),
+ };
+
+ const isValidated = localStorage.getItem('romValidated') === 'true';
+
+ if (isValidated) {
+ initiateTaskAndPoll(currentRollOptions);
+ } else {
+ // Reset the form
+ $('#rom-validation-file').val('');
+ $('#rom-validation-error').hide();
+ openModal('rom-validation-modal');
+ }
});
$(document).on('click', '.js-feature-btn', function() {