-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
2123 lines (1914 loc) · 83.1 KB
/
main.js
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const electron = require('electron');
const path = require('path');
const url = require('url');
const checkDiskSpace = require('check-disk-space').default
const {app, BroswerWindow, dialog, BrowserView, BrowserWindow, ipcMain, Menu, Notification} = electron;
const fs = require('fs');
var ipc = require('electron').ipcRenderer;
var background = require('./data/background/background.json');
var preAttackAnimation = require('./data/attacks/preAttackAnimation.json')
var postAttackAnimation = require('./data/attacks/postAttackAnimation.json');
var attackData = require('./data/attacks/attacks.json');
let mainWindow;
let insertWindow
let preAnimationWindow;
let postAnimationWindow;
let freeSpaceFinderWindow;
let opacityWindow;
var rom = null;
var romType = null; //Either FireRed or Emerald
//Create main Browser window
function createWindow(){
mainWindow = new BrowserWindow({
width: 1100,
height: 800,
title:'Move Animation Creator 1.4.1',
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
},
})
//Load index.html
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file',
slashes: true
}));
//Build Menu from template
const mainMenu = Menu.buildFromTemplate(mainMenuTemplate);
Menu.setApplicationMenu(mainMenu);
mainWindow.on('closed', () => {
mainWindow = null;
})
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.setTitle("Move Animation Creator 1.4.1")
})
}
//Creates Insert Offset Animation Window
function createInsertWindow(){
insertWindow = new BrowserWindow({
parent:mainWindow,
modal: true,
show: false,
width: 290,
height: 270,
title:'Insert Animation',
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
},
});
insertWindow.loadURL(url.format({
pathname: path.join(__dirname, 'insertAnimationWindow.html'),
protocol: 'file:',
slashes:true
}));
insertWindow.setMenu(null);
// Handle garbage collection
insertWindow.on('close', function(){
insertWindow = null;
});
insertWindow.once('ready-to-show', () => {
insertWindow.show()
})
insertWindow.webContents.on('did-finish-load', () => {
insertWindow.setTitle("Insert Animation")
})
}
function createPostAnimationWindow(){
postAnimationWindow = new BrowserWindow({
modal: true,
show: false,
width: 600,
height: 350,
title:'Post Animation Images',
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
},
});
postAnimationWindow.loadURL(url.format({
pathname: path.join(__dirname, 'postAttackImages.html'),
protocol: 'file:',
slashes:true
}));
postAnimationWindow.setMenu(null);
// Handle garbage collection
postAnimationWindow.on('close', function(){
postAnimationWindow = null;
});
postAnimationWindow.once('ready-to-show', () => {
postAnimationWindow.show()
})
postAnimationWindow.webContents.on('did-finish-load', () => {
postAnimationWindow.setTitle("Post Animation")
})
}
function createPreAnimationWindow(){
preAnimationWindow = new BrowserWindow({
modal: true,
show: false,
width: 600,
height: 350,
title:'Pre Animation Images',
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
},
});
preAnimationWindow.loadURL(url.format({
pathname: path.join(__dirname, 'preAttackImages.html'),
protocol: 'file:',
slashes:true
}));
preAnimationWindow.setMenu(null);
// Handle garbage collection
preAnimationWindow.on('close', function(){
preAnimationWindow = null;
});
preAnimationWindow.once('ready-to-show', () => {
preAnimationWindow.show()
})
preAnimationWindow.webContents.on('did-finish-load', () => {
preAnimationWindow.setTitle("Pre Animation")
})
}
function createFreeSpaceFinderWindow(){
freeSpaceFinderWindow = new BrowserWindow({
parent:insertWindow,
modal: true,
show: false,
width: 350,
height: 300,
title:'Free Space Search',
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
},
});
freeSpaceFinderWindow.loadURL(url.format({
pathname: path.join(__dirname, 'searchFreeSpace.html'),
protocol: 'file:',
slashes:true
}));
freeSpaceFinderWindow.setMenu(null);
// Handle garbage collection
freeSpaceFinderWindow.on('close', function(){
freeSpaceFinderWindow = null;
});
freeSpaceFinderWindow.once('ready-to-show', () => {
freeSpaceFinderWindow.show()
})
freeSpaceFinderWindow.webContents.on('did-finish-load', () => {
freeSpaceFinderWindow.setTitle("Search Free Space")
})
}
function createOpacityMenu(){
opacityWindow = new BrowserWindow({
parent:insertWindow,
modal: true,
show: false,
width: 520,
height: 560,
title:'Opacity Levels',
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
},
});
opacityWindow.loadURL(url.format({
pathname: path.join(__dirname, 'opacityLevel.html'),
protocol: 'file:',
slashes:true
}));
opacityWindow.setMenu(null);
// Handle garbage collection
opacityWindow.on('close', function(){
opacityWindow = null;
});
opacityWindow.once('ready-to-show', () => {
opacityWindow.show()
})
opacityWindow.webContents.on('did-finish-load', () => {
opacityWindow.setTitle("Opacity Levels")
})
}
//Create Menu Template
const mainMenuTemplate = [
{
label: "File",
submenu:[
{
label: 'Load ROM',
accelerator: 'CmdOrCtrl+O',
click(){
openRom();
}
},
{
label: 'Quit',
click(){
app.quit();
}
}
],
}
]
mainMenuTemplate.push({
label: 'View',
submenu: [
{
label: 'Pre Attack Images',
click(item, focusedWindow){
createPreAnimationWindow();
}
},
{
label: 'Post Attack Images',
click(item, focusedWindow){
createPostAnimationWindow();
}
},
{
label: 'Opacity Levels',
click(item, focusedWindow){
createOpacityMenu();
}
},
]
})
//Add developer tools item if not in production
/*
if(process.env.Node_ENV !== 'production'){
mainMenuTemplate.push({
label: 'Developer Tools',
submenu: [
{
label: 'Toggle DevTools',
click(item, focusedWindow){
focusedWindow.toggleDevTools();
}
}
]
})
} */
//Run create window
app.whenReady().then(() => {
createWindow();
app.on('activate', function(){
if (BrowserWindow.getAllWindows().length === 0){
createWindow();
}
})
})
//Quit when all windows are closed
app.on('window-all-closed', () => {
//Check to see if user is on MAC
if(process.platform !== 'darwin') { //darwin = mac, win32 = windows
app.quit();
}
})
//Open ROM
async function openRom(){
const files = dialog.showOpenDialog(mainWindow, {
properties: ['openFile'],
filters: [
{name: 'ROM', extensions: ['gba']}
]
}).then((filepath) => {
rom = filepath.filePaths[0];
romType = determineRomType(rom);
mainWindow.webContents.send('romName', filepath.filePaths[0]);
});
}
//This function determines if the ROM is FireRed or Emerald
function determineRomType(rom){
var array = []
var romHex = fs.readFileSync(rom)
var startingOffsetDecimal = 172 //Location of the Header (in decimal) that tells you the type of game (Fire Red or Emerald)
for (var i=startingOffsetDecimal; i<176; i++){
array.push(romHex[i].toString('16'))
}
if(array[0] == "42" && array[1] == "50" && array[2] == "52" && array[3] == "45"){
return "Fire Red";
} else if (array[0] == "42" && array[1] == "50" && array[2] == "45" && array[3] == "45"){
return "Emerald";
} else {
mainWindow.webContents.send('errorMessage', "Error: ROM is neither Fire Red or Emerald.");
}
}
/////Ipc's
//Create Animation
ipcMain.on('form:submit', function(event, attackName, background, scrollType, scrollSpeed, removeBlink, attack1, attack2, attack3, attack4, attack1KeepBackground, attack2KeepBackground, attack3KeepBackground, attack4KeepBackground, postAnimation1, postAnimation2, postAnimation3, postAnimation4, preAnimation1, preAnimation2, preAnimation3, preAnimation4, customParticleColour1, customParticleColour2, customParticleColour3, customParticleColour4, particleColour1, particleColour2, particleColour3, particleColour4, particleOpacity1, particleOpacity2, particleOpacity3, particleOpacity4) {
var combinedAnimation;
var bytesNeeded;
var psychicBackgroundUsed = false;
var moveData1;
var moveData2;
var moveData3;
var moveData4;
//Check if ROM is open
if(rom != null){
//Case 1. User selects Default Background or No Background
if(background == 'Default' || background == "No Background"){
moveData1 = getMoveAnimationData(attack1);
moveData1.code = selectAnimationCodeToUse(moveData1);
if(background == "No Background" && moveData1.background == true && attack1KeepBackground == false){
moveData1.code = removeBackground(moveData1);
}
if(removeBlink == true){
moveData1.code = removeBlinkTemp(moveData1.code);
}
moveData1.code = trimTrailing08(moveData1.code);
moveData1.code = addPreAnimation(moveData1, preAnimation1);
moveData1.code = addPostAnimation(moveData1, postAnimation1);
if(customParticleColour1 == "Custom"){
moveData1.code = changeParticleColor(moveData1, particleColour1, particleOpacity1, preAnimation1);
}
if(attack2 != "---"){
moveData2 = getMoveAnimationData(attack2);
moveData2.code = selectAnimationCodeToUse(moveData2);
if(background == "No Background" && moveData2.background == true && attack2KeepBackground == false){
moveData2.code = removeBackground(moveData2);
}
if(removeBlink == true){
moveData2.code = removeBlinkTemp(moveData2.code);
}
moveData2.code = trimTrailing08(moveData2.code);
moveData2.code = addPreAnimation(moveData2, preAnimation2);
moveData2.code = addPostAnimation(moveData2, postAnimation2);
if(customParticleColour2 == "Custom"){
moveData2.code = changeParticleColor(moveData2, particleColour2, particleOpacity2, preAnimation2);
}
}
if(attack3 != "---"){
moveData3 = getMoveAnimationData(attack3);
moveData3.code = selectAnimationCodeToUse(moveData3);
if(background == "No Background" && moveData3.background == true && attack3KeepBackground == false){
moveData3.code = removeBackground(moveData3);
}
if(removeBlink == true){
moveData3.code = removeBlinkTemp(moveData3.code);
}
moveData3.code = trimTrailing08(moveData3.code);
moveData3.code = addPreAnimation(moveData3, preAnimation3);
moveData3.code = addPostAnimation(moveData3, postAnimation3);
if(customParticleColour3 == "Custom"){
moveData3.code = changeParticleColor(moveData3, particleColour3, particleOpacity3, preAnimation3);
}
}
if(attack4 != "---"){
moveData4 = getMoveAnimationData(attack4);
moveData4.code = selectAnimationCodeToUse(moveData4);
if(background == "No Background" && moveData4.background == true && attack4KeepBackground == false){
moveData4.code = removeBackground(moveData4);
}
if(removeBlink == true){
moveData4.code = removeBlinkTemp(moveData4.code);
}
moveData4.code = trimTrailing08(moveData4.code);
moveData4.code = addPreAnimation(moveData4, preAnimation4);
moveData4.code = addPostAnimation(moveData4, postAnimation4);
if(customParticleColour4 == "Custom"){
moveData4.code = changeParticleColor(moveData4, particleColour4, particleOpacity4, preAnimation4);
}
}
combinedAnimation = concatAnimation(moveData1, moveData2, moveData3, moveData4);
combinedAnimation = concat08(combinedAnimation);
bytesNeeded = getBytesNeeded(combinedAnimation)
createInsertWindow();
insertWindow.webContents.on('did-finish-load', function () {
insertWindow.webContents.send('setInsertWindowVariables', bytesNeeded, combinedAnimation);
});
}
//CASE 2 User selects a specific Background.
//There are LOTS of weird use cases when the user selects a background but then wants to Keep a PSYCHIC background for 1 or more of the moves.
//When a move has Keep Background checked, all the moves after it will use that background. For example -> Background: Dark; Moves: Absorb, tackle, Shadow Ball with Keep Background checked, Bite; Absorb and Tackle will use dark background, then Shadown Ball will use ghost background and then bite will use ghost background
else {
moveData1 = getMoveAnimationData(attack1);
moveData1.code = selectAnimationCodeToUse(moveData1);
if(moveData1.background == true && attack1KeepBackground == false){
moveData1.code = removeBackground(moveData1)
} else {
//Just remove the black fade out at the end. One will get added later and we don't want to have 2 spearate fade outs
moveData1.code = removeBackgroundEnding(moveData1.code);
//Keep track if a psychic background was used
if(moveData1.psychicBackground == true){
psychicBackgroundUsed = true;
}
}
moveData1.code = trimTrailing08(moveData1.code)
moveData1.code = addPreAnimation(moveData1, preAnimation1);
moveData1.code = addPostAnimation(moveData1, postAnimation1)
if(customParticleColour1 == "Custom"){
moveData1.code = changeParticleColor(moveData1, particleColour1, particleOpacity1, preAnimation1);
}
if(attack2 != "---"){
moveData2 = getMoveAnimationData(attack2);
moveData2.code = selectAnimationCodeToUse(moveData2);
if(moveData2.background == true && attack2KeepBackground == false){
moveData2.code = removeBackground(moveData2);
} else {
moveData2.code = removeBackgroundEnding(moveData2.code);
if(moveData2.psychicBackground == true){
psychicBackgroundUsed = true;
}
}
moveData2.code = trimTrailing08(moveData2.code);
moveData2.code = addPreAnimation(moveData2, preAnimation2);
moveData2.code = addPostAnimation(moveData2, postAnimation2)
if(customParticleColour2 == "Custom"){
moveData2.code = changeParticleColor(moveData2, particleColour2, particleOpacity2, preAnimation2);
}
}
if(attack3 != "---"){
moveData3 = getMoveAnimationData(attack3);
moveData3.code = selectAnimationCodeToUse(moveData3);
if(moveData3.background == true && attack3KeepBackground == false){
moveData3.code = removeBackground(moveData3);
} else {
moveData3.code = removeBackgroundEnding(moveData3.code);
if(moveData3.psychicBackground == true){
psychicBackgroundUsed = true;
}
}
moveData3.code = trimTrailing08(moveData3.code);
moveData3.code = addPreAnimation(moveData3, preAnimation3);
moveData3.code = addPostAnimation(moveData3, postAnimation3)
if(customParticleColour3 == "Custom"){
moveData3.code = changeParticleColor(moveData3, particleColour3, particleOpacity3, preAnimation3);
}
}
if(attack4 != "---"){
moveData4 = getMoveAnimationData(attack4);
moveData4.code = selectAnimationCodeToUse(moveData4);
if(moveData4.background == true && attack4KeepBackground == false){
moveData4.code = removeBackground(moveData4);
} else {
moveData4.code = removeBackgroundEnding(moveData4.code);
if(moveData4.psychicBackground == true){
psychicBackgroundUsed = true;
}
}
moveData4.code = trimTrailing08(moveData4.code);
moveData4.code = addPreAnimation(moveData4, preAnimation4);
moveData4.code = addPostAnimation(moveData4, postAnimation4);
if(customParticleColour4 == "Custom"){
moveData4.code = changeParticleColor(moveData4, particleColour4, particleOpacity4, preAnimation4);
}
}
combinedAnimation = concatAnimation(moveData1, moveData2, moveData3, moveData4);
combinedAnimation = addBackground(combinedAnimation, background, scrollType, scrollSpeed, psychicBackgroundUsed)
//If the background isn't Psychic, but a move with a psychic background was used and the user selected keep background, append the psychic closig to the end of the animation
if(psychicBackgroundUsed == true && background != "Psychic (03)"){
if(romType == "Fire Red"){
combinedAnimation = combinedAnimation.concat(" 0E C7 59 1D 08")
} else if(romType == "Emerald"){
combinedAnimation = combinedAnimation.concat(" 0E DD 7C 2D 08")
}
}
if (background != "Psychic (03)" && psychicBackgroundUsed == false && background != "Fissure (15)"
&& background != "Light Green" && background != "Deep Green" && background != "Light Red" && background != "Deep Red" && background != "Light Orange" && background != "Deep Orange"
&& background != "Light Blue" && background != "Deep Blue" && background != "Light Sky Blue" && background != "Deep Sky Blue" && background != "Light Pink" && background != "Deep Pink"
&& background != "Light Purple" && background != "Deep Purple" && background != "Light Black" && background != "Deep Black"
&& scrollType == "No Scroll")
{
combinedAnimation = combinedAnimation.concat(" 15 17");
}
combinedAnimation = concat08(combinedAnimation);
bytesNeeded = getBytesNeeded(combinedAnimation);
createInsertWindow();
insertWindow.webContents.on('did-finish-load', function () {
insertWindow.webContents.send('setInsertWindowVariables', bytesNeeded, combinedAnimation);
});
}
} else {
//ROM has not been loaded. Display error message
mainWindow.webContents.send('romNotLoaded');
}
});
ipcMain.on('backgroud:change', function(event, data) {
var id;
var vertical = false;
var horizontal = false;
mainWindow.webContents.send('backgroundImage', data);
background.backgrounds.map(function(backgroundData){
if(data == backgroundData.name){
vertical = backgroundData.vertical
horizontal = backgroundData.horizontal
}
})
loadBackgroundToUI(data);
setRadioButtonPermission(vertical, horizontal);
setCheckboxPermisssion(data)
});
ipcMain.on('postAttack:change', function(event, data) {
var obj = getPostAnimationObject(data);
postAnimationWindow.webContents.send('postAttackImage', data, obj);
// loadPostAttackImageToUI(data);
});
ipcMain.on('preAttack:change', function(event, data) {
var obj = getPreAnimationObject(data);
preAnimationWindow.webContents.send('preAttackImage', data, obj);
});
ipcMain.on('button:searchFreeSpace', function(event, bytesNeeded){
createFreeSpaceFinderWindow();
freeSpaceFinderWindow.webContents.on('did-finish-load', function () {
freeSpaceFinderWindow.webContents.send('setFreeSpaceWindowInitialParameters', bytesNeeded);
});
});
ipcMain.on('form:freeSpaceFinderInsertMemory', function(event, memoryOffset){
insertWindow.webContents.send('setInputMemoryOffset', memoryOffset)
freeSpaceFinderWindow.close();
});
ipcMain.on('form:searchForFreeSpace', function(event, startingOffset, bytesNeeded){
//Display loading symbol on Search Button
freeSpaceFinderWindow.webContents.send('setSearchLoadingSpinner', true);
//Make sure you don't look for free space in the header (the first 1040 bytes (0x410))
if(startingOffset < 1040){
startingOffset = 410;
}
//Increase the bytes needed in order to reduce the chances of you inserting a move animation in a block of FF that is actually used by something else
if(bytesNeeded < 20){
bytesNeeded = 20
}
var offset = findOffsetToInsert(startingOffset, bytesNeeded)
freeSpaceFinderWindow.webContents.send('setSearchLoadingSpinner', false);
//Make sure an offset was found
if(offset == "" || typeof(offset) == 'undefined'){
freeSpaceFinderWindow.webContents.send('errorMessage', "Error, could not find a valid offset.");
} else {
freeSpaceFinderWindow.webContents.send('setInsertMemoryOffset', offset.toString('16'));
}
})
//Insert Animation Clicked
ipcMain.on('form:insertAnimationSubmit', function(event, memoryOffset, hex){
//Animation code in Hex
var hexArray = convertStringToHexFormat(hex);
var memoryHex = "0x".concat(memoryOffset)
var success = isValidOffset(memoryHex);
if(success == true){
fs.open(rom, "r+", (err, fd) => {
if(!err) {
var position = parseInt(memoryHex)
const data = new Uint8Array(hexArray)
fs.write(fd, data, 0, data.length, position,
(err, bw, buf) => {
if(!err) {
// succesfully wrote byte to offset
insertWindow.close();
} else{
insertWindow.webContents.send('errorMessage', "Error writing to ROM");
}
}
);
} else{
mainWindow.webContents.send('errorMessage', "Error: Could not open ROM for writing");
}
});
}
else{
insertWindow.webContents.send('errorMessage', 'Error: Invalid offset.');
}
})
//Function displays the background the user to choose to the UI
async function loadBackgroundToUI(data){
mainWindow.webContents.on('did-finish-load', ()=>{
mainWindow.webContents.send('backgroundImage', data);
})
}
/*async function loadPostAttackImageToUI(data){
mainWindow.webContents.on('did-finish-load', ()=>{
mainWindow.webContents.send('postAttackImage', data);
})
} */
//Function enables/disables certain scroll radio buttons depending on background.
async function setRadioButtonPermission(vertical, horizontal){
mainWindow.webContents.send('scrollRadioButton', vertical, horizontal);
}
//Function enables/disables checkbox depending on which backgroud is chosen
async function setCheckboxPermisssion(backgroundName){
mainWindow.webContents.send('keepBackgroundCheckbox', backgroundName);
}
///HELPER FUNCTIONS
//Function recieves a move object and returns the animation code to use. (Either Fire Red or Emerald)
function selectAnimationCodeToUse(moveData){
if(romType == "Fire Red"){
return moveData.code;
} else if(romType == "Emerald"){
return moveData.emeraldCode;
}
}
//Function recieves a move name and returns its entire move object
function getMoveAnimationData(move){
var moveData;
attackData.attacks.map(function(attack){
if(move == attack.name){
moveData = JSON.parse(JSON.stringify(attack));
}
})
return moveData;
}
//Function receives Move Data Object and removes the background hex data from the animation code including the ending animation code
function removeBackground(moveData){
//CASE 1 Remove Colored Background (i.e absorb, Ice Beam).
if(moveData.coloredBackground == true && moveData.scroll == false){
//These moves can not have their colored backgrounds removed
if (moveData.name == "Calm Mind 1" || moveData.name == "Explosion" || moveData.name == "Flatter"){
return moveData.code;
}
else if (moveData.name == "Thunderbolt" || moveData.name == "Thundershock" || moveData.name == "Thunder Wave" || moveData.name == "Volt Tackle"){
return removeElectricBackground(moveData);
}
else if (moveData.name == "Glare" || moveData.name == "Hail" || moveData.name == "Rain Dance" || moveData.name == "Sky Attack Turn 1" || moveData.name == "Sunny Day"){
return removeFadePalette(moveData)
}
else {
return removeColoredBackground(moveData);
}
}
//CASE 2: Background is Psychic. No need to check for scroll as it doesn't work with Psychcic background
else if(moveData.psychicBackground == true){
return removePsychicBackground(moveData);
}
//CASE 3: Background is template like Ghost, Dark etc
else{
//If background isn't scrolling
if(moveData.scroll == false){
if (moveData.name == "Focus Punch" || moveData.name == "Hyper Fang" || moveData.name == "Mega Kick" || moveData.name == "Mega Punch"){
return removeChooseBGImpact(moveData);
}
else if (moveData.name == "Guillotine"){
return removeChooseBGGuillotine(moveData);
}
else if(moveData.name == "Destiny Bond" || moveData.name == "Grudge" || moveData.name == "Spite"){
return removeDestinyBondBackground(moveData);
}
else if(moveData.name == "Fissure"){
return removeFissureBackground(moveData);
}
else if(moveData.name == "Solarbeam Turn 2"){
return removeSolarbeamBackground(moveData)
}
else {
return removeStaticTemplateBackground(moveData);
}
}
//Else Background is scrolling vertically or horizontally
else {
if(moveData.name == "Aeroblast" || moveData.name == "Sky Attack Turn 2"){
return removeScrollFlyingBackground(moveData);
}
return removeScrollingTemplateBackground(moveData);
}
}
}
//Function recieves a move hex code and adds a background to it as well as the code to end the background at the end
function addBackground(hex, backgroundName, scrollType, scrollSpeed, psychicBackgroundUsed){
var backgroundObject = getBackgroundObject(backgroundName) //Gets ths background object i.e. (Dark (00), Ghost(02))
var backgroundStart;
var backgroundEnd;
var emeraldColourCodePointer = background.coloredBackground[0].startOfEmeraldCodePointer;
var fireRedColourCodePointer = background.coloredBackground[0].pointer;
//Background is static (not scrolling)
if(scrollType == "No Scroll"){
if(backgroundName == "Psychic (03)"){
if(romType == "Fire Red"){
backgroundStart = background.srollBackground[0].psychicCode;
hex = hex.concat(" 0E C7 59 1D 08");
} else if(romType == "Emerald") {
backgroundStart = background.srollBackground[0].psychicCodeEmerald;
hex = hex.concat(" 0E DD 7C 2D 08");
}
hex = hex.replace(/^/, backgroundStart + " ");
}
else if(backgroundName == "Solarbeam (18)"){
if(romType == "Fire Red"){
backgroundStart = background.staticBackground[0].solarbeamCode;
} else if(romType == "Emerald"){
backgroundStart = background.staticBackground[0].solarbeamCodeEmerald;
}
hex = hex.replace(/^/, backgroundStart + " ");
}
else if(backgroundName == "High Impact (04)"){
if(romType == "Fire Red"){
backgroundStart = background.staticBackground[0].highImpactCode;
} else if(romType == "Emerald"){
backgroundStart = background.staticBackground[0].highImpactCodeEmerald;
}
hex = hex.replace(/^/, backgroundStart + " ");
}
else if(backgroundName == "Guillotine (0C)"){
if(romType == "Fire Red"){
backgroundStart = background.staticBackground[0].guillotineCode;
} else if(romType == "Emerald"){
backgroundStart = background.staticBackground[0].guillotineCodeEmerald;
}
hex = hex.replace(/^/, backgroundStart + " ");
}
else if(backgroundName == "Fissure (15)"){
if(romType == "Fire Red"){
backgroundStart = background.staticBackground[0].fissureBackgroundCode;
} else if(romType == "Emerald"){
backgroundStart = background.staticBackground[0].fissureBackgroundEmerald;
}
backgroundEnd = background.staticBackground[0].fissureBackgroundEndCode;
hex = hex.replace(/^/, backgroundStart + " ");
hex = hex.concat(backgroundEnd);
}
else if(backgroundName == "Light Green"){
backgroundStart = background.coloredBackground[0].lightGreen;
var backgroundEnd = background.coloredBackground[0].lightGreenEnd;
hex = hex.replace(/^/, backgroundStart + " ");
hex = hex.concat(backgroundEnd);
if(romType == "Emerald"){
//Replace the start of Fire Red Colour background pointer with Emerald
hex = replaceCode(hex, fireRedColourCodePointer, emeraldColourCodePointer)
}
}
else if(backgroundName == "Deep Green"){
backgroundStart = background.coloredBackground[0].deepGreen;
var backgroundEnd = background.coloredBackground[0].deepGreenEnd;
hex = hex.replace(/^/, backgroundStart + " ");
hex = hex.concat(backgroundEnd);
if(romType == "Emerald"){
hex = replaceCode(hex, fireRedColourCodePointer, emeraldColourCodePointer)
}
}
else if(backgroundName == "Deep Green Slow"){
backgroundStart = background.coloredBackground[0].deepGreenSlow;
var backgroundEnd = background.coloredBackground[0].deepGreenSlowEnd;
hex = hex.replace(/^/, backgroundStart + " ");
hex = hex.concat(backgroundEnd);
if(romType == "Emerald"){
hex = replaceCode(hex, fireRedColourCodePointer, emeraldColourCodePointer)
}
}
else if(backgroundName == "Light Red"){
backgroundStart = background.coloredBackground[0].lightRed;
var backgroundEnd = background.coloredBackground[0].lightRedEnd;
hex = hex.replace(/^/, backgroundStart + " ");
hex = hex.concat(backgroundEnd);
if(romType == "Emerald"){
hex = replaceCode(hex, fireRedColourCodePointer, emeraldColourCodePointer)
}
}
else if(backgroundName == "Deep Red"){
backgroundStart = background.coloredBackground[0].deepRed;
var backgroundEnd = background.coloredBackground[0].deepRedEnd;
hex = hex.replace(/^/, backgroundStart + " ");
hex = hex.concat(backgroundEnd);
if(romType == "Emerald"){
hex = replaceCode(hex, fireRedColourCodePointer, emeraldColourCodePointer)
}
}
else if(backgroundName == "Deep Red Slow"){
backgroundStart = background.coloredBackground[0].deepRedSlow;
var backgroundEnd = background.coloredBackground[0].deepRedSlowEnd;
hex = hex.replace(/^/, backgroundStart + " ");
hex = hex.concat(backgroundEnd);
if(romType == "Emerald"){
hex = replaceCode(hex, fireRedColourCodePointer, emeraldColourCodePointer)
}
}
else if(backgroundName == "Light Orange"){
backgroundStart = background.coloredBackground[0].lightOrange;
var backgroundEnd = background.coloredBackground[0].lightOrangeEnd;
hex = hex.replace(/^/, backgroundStart + " ");
hex = hex.concat(backgroundEnd);
if(romType == "Emerald"){
hex = replaceCode(hex, fireRedColourCodePointer, emeraldColourCodePointer)
}
}
else if (backgroundName == "Deep Orange"){
backgroundStart = background.coloredBackground[0].deepOrange;
var backgroundEnd = background.coloredBackground[0].deepOrangeEnd;
hex = hex.replace(/^/, backgroundStart + " ");
hex = hex.concat(backgroundEnd);
if(romType == "Emerald"){
hex = replaceCode(hex, fireRedColourCodePointer, emeraldColourCodePointer)
}
}
else if (backgroundName == "Deep Orange Slow"){
backgroundStart = background.coloredBackground[0].deepOrangeSlow;
var backgroundEnd = background.coloredBackground[0].deepOrangeSlowEnd;
hex = hex.replace(/^/, backgroundStart + " ");
hex = hex.concat(backgroundEnd);
if(romType == "Emerald"){
hex = replaceCode(hex, fireRedColourCodePointer, emeraldColourCodePointer)
}
}
else if (backgroundName == "Light Blue"){
backgroundStart = background.coloredBackground[0].lightBlue;
var backgroundEnd = background.coloredBackground[0].lightBlueEnd;
hex = hex.replace(/^/, backgroundStart + " ");
hex = hex.concat(backgroundEnd);
if(romType == "Emerald"){
hex = replaceCode(hex, fireRedColourCodePointer, emeraldColourCodePointer)
}
}
else if (backgroundName == "Deep Blue"){
backgroundStart = background.coloredBackground[0].deepBlue;
var backgroundEnd = background.coloredBackground[0].deepBlueEnd;
hex = hex.replace(/^/, backgroundStart + " ");
hex = hex.concat(backgroundEnd);
if(romType == "Emerald"){
hex = replaceCode(hex, fireRedColourCodePointer, emeraldColourCodePointer)
}
}
else if(backgroundName == "Deep Blue Slow"){
backgroundStart = background.coloredBackground[0].deepBlueSlow;
var backgroundEnd = background.coloredBackground[0].deepBlueSlowEnd;
hex = hex.replace(/^/, backgroundStart + " ");
hex = hex.concat(backgroundEnd);
if(romType == "Emerald"){
hex = replaceCode(hex, fireRedColourCodePointer, emeraldColourCodePointer)
}
}
else if (backgroundName == "Light Sky Blue"){
backgroundStart = background.coloredBackground[0].lightSkyBlue;
var backgroundEnd = background.coloredBackground[0].lightSkyBlueEnd;
hex = hex.replace(/^/, backgroundStart + " ");
hex = hex.concat(backgroundEnd);
if(romType == "Emerald"){
hex = replaceCode(hex, fireRedColourCodePointer, emeraldColourCodePointer)
}
}
else if (backgroundName == "Deep Sky Blue"){
backgroundStart = background.coloredBackground[0].deepSkyBlue;
var backgroundEnd = background.coloredBackground[0].deepSkyBlueEnd;
hex = hex.replace(/^/, backgroundStart + " ");
hex = hex.concat(backgroundEnd);
if(romType == "Emerald"){
hex = replaceCode(hex, fireRedColourCodePointer, emeraldColourCodePointer)
}
}
else if(backgroundName == "Deep Sky Blue Slow"){
backgroundStart = background.coloredBackground[0].deepSkyBlueSlow;
var backgroundEnd = background.coloredBackground[0].deepSkyBlueSlowEnd;
hex = hex.replace(/^/, backgroundStart + " ");
hex = hex.concat(backgroundEnd);
if(romType == "Emerald"){
hex = replaceCode(hex, fireRedColourCodePointer, emeraldColourCodePointer)
}
}
else if (backgroundName == "Light Pink"){
backgroundStart = background.coloredBackground[0].lightPink;
var backgroundEnd = background.coloredBackground[0].lightPinkEnd;
hex = hex.replace(/^/, backgroundStart + " ");
hex = hex.concat(backgroundEnd);
if(romType == "Emerald"){
hex = replaceCode(hex, fireRedColourCodePointer, emeraldColourCodePointer)
}
}
else if (backgroundName == "Deep Pink"){
backgroundStart = background.coloredBackground[0].deepPink;
var backgroundEnd = background.coloredBackground[0].deepPinkEnd;
hex = hex.replace(/^/, backgroundStart + " ");
hex = hex.concat(backgroundEnd);
if(romType == "Emerald"){
hex = replaceCode(hex, fireRedColourCodePointer, emeraldColourCodePointer)
}
}
else if(backgroundName == "Deep Pink Slow"){
backgroundStart = background.coloredBackground[0].deepPinkSlow;
var backgroundEnd = background.coloredBackground[0].deepPinkSlowEnd;
hex = hex.replace(/^/, backgroundStart + " ");
hex = hex.concat(backgroundEnd);
if(romType == "Emerald"){
hex = replaceCode(hex, fireRedColourCodePointer, emeraldColourCodePointer)
}
}
else if (backgroundName == "Light Purple"){
backgroundStart = background.coloredBackground[0].lightPurple;
var backgroundEnd = background.coloredBackground[0].lightPurpleEnd;
hex = hex.replace(/^/, backgroundStart + " ");
hex = hex.concat(backgroundEnd);
if(romType == "Emerald"){
hex = replaceCode(hex, fireRedColourCodePointer, emeraldColourCodePointer)
}
}
else if (backgroundName == "Deep Purple"){
backgroundStart = background.coloredBackground[0].deepPurple;
var backgroundEnd = background.coloredBackground[0].deepPurpleEnd;
hex = hex.replace(/^/, backgroundStart + " ");
hex = hex.concat(backgroundEnd);
if(romType == "Emerald"){
hex = replaceCode(hex, fireRedColourCodePointer, emeraldColourCodePointer)
}
}
else if(backgroundName == "Deep Purple Slow"){
backgroundStart = background.coloredBackground[0].deepPurpleSlow;
var backgroundEnd = background.coloredBackground[0].deepPurpleSlowEnd;
hex = hex.replace(/^/, backgroundStart + " ");
hex = hex.concat(backgroundEnd);
if(romType == "Emerald"){
hex = replaceCode(hex, fireRedColourCodePointer, emeraldColourCodePointer)
}
}
else if (backgroundName == "Light Black"){
backgroundStart = background.coloredBackground[0].lightBlack;
var backgroundEnd = background.coloredBackground[0].lightBlackEnd;
hex = hex.replace(/^/, backgroundStart + " ");
hex = hex.concat(backgroundEnd);
if(romType == "Emerald"){