-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathForm1.cs
8619 lines (8361 loc) · 376 KB
/
Form1.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
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
// Decompiled with JetBrains decompiler
// Type: BanjoKazooieLevelEditor.Form1
// Assembly: BanjoKazooieLevelEditor, Version=2.0.19.0, Culture=neutral, PublicKeyToken=null
// MVID: 9E4E8A9F-6E2F-4B24-B56C-5C2BF24BF813
// Assembly location: F:\BanjosBackpack\BB.exe
using BKGlobalize;
using OpenTK;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;
using Tao.OpenGl;
namespace BanjoKazooieLevelEditor
{
public class Form1 : Form
{
private bool enableDebug;
private bool processControllerEvents;
private Color active = SystemColors.ControlDarkDark;
private Color inactive = SystemColors.ActiveBorder;
private RomBuilder romBuild = new RomBuilder();
private bool includeTriggers = true;
private List<LevelEntryPoint> entryPoints = new List<LevelEntryPoint>();
private List<LevelEntryPoint> levelEntries = new List<LevelEntryPoint>();
private List<TextFile> files = new List<TextFile>();
private bool unlockedEditSettings;
private List<int> usedJiggyFlags = new List<int>();
private bool multiselect;
private bool showStats = true;
private GECompression ge = new GECompression();
private bool drawLevelBoundary;
private bool hideUnknownBytes = true;
private string inRom = "";
private int jiggyCount;
private int honeyCombCount;
private int mumboTokenCount;
private int jiggyOffset;
private int honeyCombOffset;
private int mumboTokenOffset;
private byte[] rom;
private string path = Application.StartupPath;
public string tmpDir = Application.StartupPath + "\\tmp\\";
private OpenSetFileForm osff = new OpenSetFileForm();
private SetupFile selectedFile;
private SetupFileWritter sfw = new SetupFileWritter();
private List<WrittenFile> writtenFiles = new List<WrittenFile>();
private World world = new World();
private string setupfile = "";
private string outDir = Application.StartupPath + "\\out\\";
private string outTxtDir = Application.StartupPath + "\\text\\out\\";
private List<SetupFile> sfl = new List<SetupFile>();
private LevelStat ls = new LevelStat(0, 0, 0, 0, 0, 0, 0);
private ObjectData flagFound;
private int listDec;
private int newStart;
private bool zoomIn;
private bool zoomOut;
private bool left;
private bool right;
private bool moveUp;
private bool moveDown;
private GLCamera BBCamera = new GLCamera();
private int newMouseX;
private int newMouseY;
private int oldMouseX;
private int oldMouseY;
private bool sceneClick;
private bool RotateSceneClick;
private bool forceRedraw = true;
public string replacedModel = "";
public string replacedModelEx = "";
private bool rectSelectMode;
private bool rectSelect;
private Point startPoint = Point.Empty;
private Rectangle frameRect = Rectangle.Empty;
private bool selectMode = true;
private bool createMode;
private bool cameraMode;
private bool selectPathMode;
private bool createPathMode;
private bool nodeMoveMode;
private bool moveMode;
private bool scaleMode;
private bool rotateMode;
private bool duplicateMode;
private bool camMoveMode;
private bool yawMode;
private bool pitchMode;
private bool rollMode;
private bool movingObj;
private bool scalingObj;
private bool rotatingObj;
private bool movingNode;
private bool duplicatingObj;
private bool xToggle = true;
private bool yToggle = true;
private bool zToggle = true;
private bool camXToggle = true;
private bool camYToggle = true;
private bool camZToggle = true;
private int createPointX;
private int createPointY;
private int newEditX;
private int newEditY;
private int oldEditX;
private int oldEditY;
private bool running = true;
private bool allObjsErased;
private int DA2724_location;
private int E4D7FE_location;
private int F19250_location;
private int F361E3_location;
private int F37F90_location;
private int F9CAE0_location;
private int FA3FD0_location;
private int FA5D96_location;
private int FA5F50_location;
private int FA8CE6_location;
private int FA9150_location;
private int FAE27E_location;
private int FAE860_location;
private int FB1AEB_location;
private int FB24A0_location;
private int FB42D9_location;
private int FB44E0_location;
private int FB9610_location;
private int FB9A30_location;
private int FBE5E2_location;
private int FBEBE0_location;
private int FC3FEF_location;
private int FC4810_location;
private int FC6C0F_location;
private int FC6F20_location;
private int FC8AFC_location;
private int FC9150_location;
private int FCF150_location;
private int FCF698_location;
private int FD0420_location;
private int FD5A60_location;
private int FD6190_location;
private int FDA2FF_location;
private int FDAA10_location;
private int FDAA30_location;
private List<byte> F9CAE0 = new List<byte>();
private List<byte> F37F90 = new List<byte>();
private byte[] globalizedFCF698;
private int globalizedFCF698Location = 66440624;
private SetupFileReader sfr = new SetupFileReader();
private List<AnimationFile> everyAnimation = new List<AnimationFile>();
private bool loaded;
private IContainer components;
private OpenFileDialog SetupFileOpenDialog;
private MenuStrip menuStrip1;
private ToolStripMenuItem fileToolStripMenuItem;
private FolderBrowserDialog folderBrowserDialog1;
private ToolStripMenuItem save_tsmi;
private ToolStripMenuItem openSetupFileToolStripMenuItem;
private ImageList objectImages_il;
private GroupBox textUpdate_gb;
private TextBox updateScript_tb;
private TextBox updateRot_tb;
private TextBox updateSize_tb;
private TextBox updateZ_tb;
private TextBox updateY_tb;
private TextBox updateX_tb;
private TextBox updateName_tb;
private Label script_lbl;
private Label rotByte_lbl;
private Label size_lbl;
private Label label17;
private Label label18;
private Label label19;
private Label label22;
private Button changeLM_btn;
private OpenFileDialog changeLM_ofd;
private ContextMenuStrip objectMenu;
internal TrackBar CamSpeed_tb;
private System.Windows.Forms.Timer timer1;
private Label label2;
private TextBox baseLevel_tb;
private TextBox extraModel_tb;
private Label label3;
private Button replaceModelEx_btn;
private Button replaceModel_btn;
private Label label4;
private GroupBox replacemodel_gb;
private Button clear_btn;
private Label id_lbl;
private ToolStripMenuItem openRomToolStripMenuItem;
private OpenFileDialog openFileDialog1;
private OpenFileDialog openFileDialog2;
private ToolStripMenuItem toolsToolStripMenuItem;
private ToolStripMenuItem importObjToolStripMenuItem;
private ToolStripMenuItem helpToolStripMenuItem;
private Button warp_btn;
private TextBox warpTo_tb;
private Label warpTo_lbl;
private SaveFileDialog saveFileDialog;
private TextBox id_tb;
private Label label1;
private Label address_lbl;
private Label objID_lbl;
private ToolStripMenuItem aboutToolStripMenuItem;
private OpenFileDialog replaceSetup_ofd;
private ToolStripMenuItem saveSetupFileToolStripMenuItem;
private SaveFileDialog saveSetupFileDialog;
private ToolStripMenuItem loadSetupFileToolStripMenuItem;
private OpenFileDialog openSetupFileDialog;
private ToolStripMenuItem textEditorToolStripMenuItem;
private ToolStripMenuItem saveAsRomToolStripMenuItem;
private SaveFileDialog saveAsRomFileDialog;
private ToolStripMenuItem injectorInToolStripMenuItem;
private TextBox updateB13_tb;
private TextBox updateB18_tb;
private TextBox updateB11_tb;
private TextBox updateB10_tb;
private Label b11_lbl;
private Label b10_lbl;
private Label b13_lbl;
private Label b18_lbl;
private ToolStripMenuItem optionsToolStripMenuItem;
private ToolStripMenuItem knowAllMovesToolStripMenuItem;
private ToolStripMenuItem haveNoMovesToolStripMenuItem;
private FlowLayoutPanel flowLayoutPanel1;
private Button col_obj_details_btn;
private TableLayoutPanel tableLayoutPanel3;
private TableLayoutPanel tableLayoutPanel4;
private Button col_replacemodel_btn;
private Button col_levelbounds_btn;
private GroupBox bounds_gb;
private TableLayoutPanel tableLayoutPanel8;
private Label label21;
private Label label23;
private Label label24;
private TextBox minZ_Bounds_tb;
private TextBox minY_Bounds_tb;
private TextBox minX_Bounds_tb;
private Label label28;
private TableLayoutPanel tableLayoutPanel6;
private Label label6;
private Label label7;
private GroupBox groupBox1;
private TableLayoutPanel tableLayoutPanel7;
private Label label8;
private Label label20;
private Label label25;
private Label label26;
private Label label27;
private TextBox maxX_Bounds_tb;
private TextBox maxY_Bounds_tb;
private TextBox maxZ_Bounds_tb;
private Button updateBounds_btn;
private Label label29;
private Button col_levelentries_btn;
private GroupBox levelEntries_gb;
private Button button1;
private GroupBox groupBox2;
private Label label30;
private Button button2;
private TableLayoutPanel tableLayoutPanel9;
private Label label31;
private Label label32;
private DataGridView levelEntries_dgv;
private TextBox flag_tb;
private Label flag_lbl;
private GroupBox cam3_gb;
private TableLayoutPanel tableLayoutPanel10;
private Label label33;
private Label label34;
private TextBox camRoll_tb;
private Label label35;
private TextBox camYaw_tb;
private Label label36;
private TextBox camPitch_tb;
private Label label37;
private TextBox camZ_tb;
private Label label38;
private TextBox camY_tb;
private TextBox camX_tb;
private Label label39;
private TextBox camID_tb;
private Label label40;
private Label label43;
private Label label44;
private TextBox camHSpeed_tb;
private TextBox camVSpeed_tb;
private TableLayoutPanel tableLayoutPanel11;
private Label label41;
private Label label42;
private Label label45;
private Label label46;
private TextBox camRotation_tb;
private TextBox camAccel_tb;
private Label label47;
private Label label48;
private Label label49;
private TextBox cam3A5_tb;
private TextBox camCDist_tb;
private TextBox camFDist_tb;
private ContextMenuStrip cameraMenu;
private ToolStripMenuItem createCameraToolStripMenuItem;
private Button col_objects_btn;
private GroupBox objects_gb;
private DataGridView objects_dgv;
private ToolStripMenuItem includeCameraTriggersWhenSavingToolStripMenuItem;
private ToolStripMenuItem createGameplayCameraToolStripMenuItem;
private ToolStripMenuItem sNSEditorToolStripMenuItem;
private ToolStripMenuItem puzzleEditorToolStripMenuItem;
private TextBox updateRad_tb;
private Label rad_lbl;
private ToolStripMenuItem createGameplayTiggerToolStripMenuItem;
private ToolStripMenuItem removeNumbersFromNotedoorToolStripMenuItem;
private ToolStripMenuItem saveAsRomskillToolStripMenuItem;
private OpenFileDialog injectDialog;
private Button col_structs_btn;
private GroupBox structs_gb;
private DataGridView structs_dgv;
private Button col_selPath_btn;
private GroupBox path_gb;
private DataGridView path_dgv;
private TableLayoutPanel tableLayoutPanel14;
private Label label52;
private TextBox textBox1;
private TableLayoutPanel nodeProperties_lp;
private TextBox nodeZ_tb;
private Label label53;
private TextBox nodeX_tb;
private Label label54;
private Label label55;
private TextBox nodeY_tb;
private TextBox node18_tb;
private GroupBox pathObject_gb;
private TableLayoutPanel tableLayoutPanel16;
private Label label60;
private TextBox objectNode_tb;
private TableLayoutPanel tableLayoutPanel15;
private TextBox textBox2;
private Label label56;
private TextBox textBox3;
private GroupBox groupBox3;
private TextBox sNodeSpeed_tb;
private Label label61;
private TextBox sNodeF_tb;
private Label label62;
private Label label63;
private TextBox sNodeW1_tb;
private TextBox sNodeUNK3_tb;
private Label label67;
private TextBox updateB17_tb;
private TextBox updateB16_tb;
private Label b16_lbl;
private Label b17_lbl;
private Label animation_lbl;
private ComboBox animation_cb;
private TableLayoutPanel tableLayoutPanel13;
private Label label69;
private TextBox nodeID_tb;
private Label label70;
private TextBox pauseTime_tb;
private Label label57;
private ToolTip toolTip1;
private ToolStrip toolStrip1;
private ToolStripLabel mode_lbl;
private ToolStripComboBox mode_cb;
private ToolStripSeparator toolStripSeparator1;
private ToolStripButton obj_move_btn;
private ToolStripButton obj_rot_btn;
private ToolStripButton obj_scale_btn;
private ToolStripButton obj_duplicate_btn;
private ToolStripButton deselect_btn;
private ToolStripButton delete_btn;
private ToolStripButton cam_pitch_btn;
private ToolStripButton cam_yaw_btn;
private ToolStripButton cam_roll_btn;
private ToolStripSeparator toolStripSeparator3;
private ToolStripButton eraseAll_btn;
private Button button3;
private CheckBox bgA_cb;
private CheckBox bgB_btn;
private CheckBox objs_cb;
private Label label51;
private Label label59;
private Label label64;
private Label label65;
private CheckBox cameras_cb;
private ToolStripButton lockZ_btn;
private ToolStripButton lockY_btn;
private ToolStripButton lockX_btn;
private ToolStripLabel toolStripLabel2;
private ToolStripTextBox yOffset_tb;
private Panel nodeProperties_gb;
private Button button4;
private Panel sNode_gb;
private Button button5;
private TableLayoutPanel tableLayoutPanel1;
private TableLayoutPanel tableLayoutPanel2;
private Panel nodeID_gb;
private Button button6;
private CheckBox levelStats_cb;
private Label label14;
private FlowLayoutPanel flowLayoutPanel2;
private ToolStripButton assignObject_btn;
private ToolStripButton moveNode_btn;
private ToolStripButton linkMode_btn;
private ToolStripButton removeNode_btn;
private ToolStripButton deletePath_btn;
private ToolStripSeparator toolStripSeparator4;
private ToolStripButton rectSelect_btn;
private ToolStripMenuItem hideUnknownBytesToolStripMenuItem;
private Label label58;
private Label label66;
private CheckBox levelBound_cb;
private CheckBox camTrigger_cb;
private Label label71;
private CheckBox warpRadius_cb;
private CheckBox showFlagRadius_cb;
private Label label72;
private Label flagRadius_cb;
private CheckBox enemyRadius_cb;
private CheckBox unknownRadius_cb;
private Label label75;
private ToolStripButton endNode_btn;
private Button col_cam_btn;
private ToolStripButton startNewPath_btn;
private ToolStripButton addNode_btn;
private ToolStripButton addControllerNode_btn;
private ToolStripButton deselectPath_btn;
private ToolStripMenuItem midiToolToolStripMenuItem;
private ToolStripMenuItem modelEditorToolStripMenuItem;
private CheckBox levelBoundAlpha_cb;
private Label label5;
private TextBox pathID_tb;
private Label label9;
private CheckBox useAnimation_cb;
private CheckBox useSpeed_cb;
private CheckBox usePause_cb;
private Panel panel1;
private Panel panel2;
private Panel panel3;
private DataGridView pathControllers_dgv;
private Label label11;
private Label label10;
private CheckBox cc_failsafe_cb;
private Label failsafe_lbl;
private ToolStripMenuItem editToolStripMenuItem;
private ToolStripMenuItem undoToolStripMenuItem;
private ToolStripMenuItem redoToolStripMenuItem;
private ToolStripMenuItem historyToolStripMenuItem;
private TextBox drawDist_tb;
private Label label12;
private GLControl LevelViewer;
private ToolStripButton cam_moveToCurrent_btn;
private ToolStripMenuItem spriteManagerToolStripMenuItem;
private void initializeMenu()
{
try
{
XmlTextReader xmlTextReader = new XmlTextReader(".\\resources\\menu.xml");
ToolStripMenuItem toolStripMenuItem1 = new ToolStripMenuItem();
List<ToolStripMenuItem> toolStripMenuItemList = new List<ToolStripMenuItem>();
ToolStripMenuItem toolStripMenuItem2 = new ToolStripMenuItem();
List<int> intList = new List<int>();
bool flag = false;
int num1 = 0;
int index = -1;
int num2 = -1;
while (xmlTextReader.Read())
{
string name = xmlTextReader.Name;
if (xmlTextReader.NodeType == XmlNodeType.EndElement)
{
if (!(name == "submenu"))
{
if (name == "menu")
{
this.objectMenu.Items.Add((ToolStripItem) toolStripMenuItem1);
intList.Clear();
toolStripMenuItemList.Clear();
}
}
else
{
if (num1 > 1)
{
toolStripMenuItemList[index - 1].DropDownItems.Add((ToolStripItem) toolStripMenuItemList[index]);
toolStripMenuItemList.RemoveAt(index);
--index;
}
--num1;
if (num1 == 0)
{
flag = false;
toolStripMenuItem1.DropDownItems.Add((ToolStripItem) toolStripMenuItemList[index]);
}
}
}
if (xmlTextReader.NodeType != XmlNodeType.EndElement)
{
if (!(name == "menu"))
{
if (!(name == "submenu"))
{
if (name == "menuitem")
{
ToolStripMenuItem toolStripMenuItem3 = new ToolStripMenuItem();
toolStripMenuItem3.Name = xmlTextReader.GetAttribute("name").Replace(" ", "").Replace("'", "");
toolStripMenuItem3.Size = new Size(216, 22);
toolStripMenuItem3.Text = xmlTextReader.GetAttribute("name");
toolStripMenuItem3.Tag = xmlTextReader.GetAttribute("type") == null ? (object) "" : (object) xmlTextReader.GetAttribute("type");
toolStripMenuItem3.Click += new EventHandler(this.createItem_MouseClick);
if (index != -1 & flag)
{
toolStripMenuItemList[index].DropDownItems.Add((ToolStripItem) toolStripMenuItem3);
}
else
{
toolStripMenuItem1.DropDownItems.Add((ToolStripItem) toolStripMenuItem3);
++num2;
}
}
}
else
{
ToolStripMenuItem toolStripMenuItem4 = new ToolStripMenuItem();
toolStripMenuItem4.Name = xmlTextReader.GetAttribute("name").Replace(" ", "").Replace("'", "");
toolStripMenuItem4.Size = new Size(216, 22);
toolStripMenuItem4.Text = xmlTextReader.GetAttribute("name");
++index;
toolStripMenuItemList.Add(toolStripMenuItem4);
if (!flag || num1 == 0)
{
intList.Add(num2);
++num2;
}
flag = true;
++num1;
}
}
else
{
toolStripMenuItem1 = new ToolStripMenuItem();
toolStripMenuItem1.Name = xmlTextReader.GetAttribute("name").Replace(" ", "").Replace("'", "");
toolStripMenuItem1.Tag = (object) xmlTextReader.GetAttribute("name");
toolStripMenuItem1.Text = xmlTextReader.GetAttribute("name");
toolStripMenuItem1.Size = new Size(216, 22);
num2 = 0;
index = -1;
}
}
}
}
catch (Exception ex)
{
int num = (int) MessageBox.Show("Failed to load menu");
}
}
public Form1()
{
RomHandler.tmpDir = this.tmpDir;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
this.InitializeComponent();
if (!File.Exists(this.outDir + "rn64crc.exe"))
{
int num = (int) MessageBox.Show("Error: rn64crc NOT FOUND! " + Environment.NewLine + "You need to download rn64crc.exe and put it in ./out/ BB will now close");
this.Close();
}
if (!File.Exists(this.outDir + "gzip.exe"))
{
int num = (int) MessageBox.Show("Error: gzip NOT FOUND! " + Environment.NewLine + "You need to download gzip.exe and put it in ./out/ BB will now close");
this.Close();
}
this.initializeMenu();
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.BBCamera.MovementSpeed = (float) (this.CamSpeed_tb.Value * 2);
this.readINI();
this.ReadSetupsXML();
this.readAnimationsXML();
if (!(this.inRom != ""))
return;
this.locateEORFiles();
byte[] f = this.arrayCopy(this.F9CAE0_location, 1048576);
GECompression ge1 = this.ge;
byte[] Buffer1 = f;
int length1 = Buffer1.Length;
ge1.SetCompressedBuffer(Buffer1, length1);
int compressedSize = 0;
int fileSize1 = 0;
this.F9CAE0 = ((IEnumerable<byte>) this.ge.OutputDecompressedBuffer(ref fileSize1, ref compressedSize)).ToList<byte>();
this.arrayCopy(f, this.F37F90_location, 1048576);
GECompression ge2 = this.ge;
byte[] Buffer2 = f;
int length2 = Buffer2.Length;
ge2.SetCompressedBuffer(Buffer2, length2);
compressedSize = 0;
int fileSize2 = 0;
this.F37F90 = ((IEnumerable<byte>) this.ge.OutputDecompressedBuffer(ref fileSize2, ref compressedSize)).ToList<byte>();
this.globalizedFCF698 = new byte[9888];
this.arrayCopy(this.globalizedFCF698, this.globalizedFCF698Location, 9888);
this.world.getRomStats(this.F9CAE0);
this.getEntryPoints();
this.AssociateScenesWithLevels();
}
private void Form1_Load(object sender, EventArgs e) => this.mode_cb.SelectedIndex = 0;
private int getLevelID(int map)
{
for (int index = 33412; index < 34451; index += 8)
{
int num1 = (int) this.F9CAE0[index + 4] * 256 + (int) this.F9CAE0[index + 5];
int levelId = (int) this.F9CAE0[index + 6] * 256 + (int) this.F9CAE0[index + 7];
int num2 = map;
if (num1 == num2)
return levelId;
}
return 0;
}
public int getNextPointer(int pntr_)
{
int num = (int) this.rom[pntr_] * 16777216 + (int) this.rom[pntr_ + 1] * 65536 + (int) this.rom[pntr_ + 2] * 256 + (int) this.rom[pntr_ + 3];
int nextPointer = (int) this.rom[pntr_ + 8] * 16777216 + (int) this.rom[pntr_ + 1 + 8] * 65536 + (int) this.rom[pntr_ + 2 + 8] * 256 + (int) this.rom[pntr_ + 3 + 8];
while (num - nextPointer == 0)
{
nextPointer = (int) this.rom[pntr_ + 8] * 16777216 + (int) this.rom[pntr_ + 1 + 8] * 65536 + (int) this.rom[pntr_ + 2 + 8] * 256 + (int) this.rom[pntr_ + 3 + 8];
pntr_ += 8;
}
return nextPointer;
}
private int getCompressedFileSize(byte[] f, int l)
{
this.arrayCopy(f, l, 1048576);
this.ge.SetCompressedBuffer(f);
int compressedSize = 0;
int fileSize = 0;
this.ge.GetUncompressedSize(ref fileSize, ref compressedSize);
return compressedSize;
}
private void arrayCopy(byte[] f, int l, int length)
{
for (int index = 0; index < length && l < this.rom.Length; ++index)
{
f[index] = this.rom[l];
++l;
}
}
private byte[] arrayCopy(int l, int length)
{
byte[] numArray = new byte[length];
for (int index = 0; index < length && l < this.rom.Length; ++index)
{
numArray[index] = this.rom[l];
++l;
}
return numArray;
}
private byte[] arrayCopy(int l)
{
List<byte> byteList = new List<byte>();
for (; l < this.rom.Length; ++l)
byteList.Add(this.rom[l]);
return byteList.ToArray();
}
private void updateEORFiles(int diff)
{
this.F19250_location += diff;
this.F361E3_location += diff;
this.F37F90_location += diff;
this.F9CAE0_location += diff;
this.FA3FD0_location += diff;
this.FA5D96_location += diff;
this.FA5F50_location += diff;
this.FA8CE6_location += diff;
this.FA9150_location += diff;
this.FAE27E_location += diff;
this.FAE860_location += diff;
this.FB1AEB_location += diff;
this.FB24A0_location += diff;
this.FB42D9_location += diff;
this.FB44E0_location += diff;
this.FB9610_location += diff;
this.FB9A30_location += diff;
this.FBE5E2_location += diff;
this.FBEBE0_location += diff;
this.FC3FEF_location += diff;
this.FC4810_location += diff;
this.FC6C0F_location += diff;
this.FC6F20_location += diff;
this.FC8AFC_location += diff;
this.FC9150_location += diff;
this.FCF698_location += diff;
this.FD0420_location += diff;
this.FD5A60_location += diff;
this.FD6190_location += diff;
this.FDA2FF_location += diff;
this.FDAA10_location += diff;
this.FDAA30_location += diff;
}
private void locateEORFiles()
{
byte[] f = new byte[1048576];
this.F19250_location = this.toPNTR(4218, 4226);
this.F361E3_location = this.F19250_location + this.getCompressedFileSize(f, this.F19250_location);
this.F37F90_location = this.toPNTR(10234, 10274);
this.F9CAE0_location = this.F37F90_location + this.getCompressedFileSize(f, this.F37F90_location);
this.FA3FD0_location = this.toPNTR(10238, 10278);
this.FA5D96_location = this.FA3FD0_location + this.getCompressedFileSize(f, this.FA3FD0_location);
this.FA5F50_location = this.toPNTR(10254, 10294);
this.FA8CE6_location = this.FA5F50_location + this.getCompressedFileSize(f, this.FA5F50_location);
this.FA9150_location = this.toPNTR(10262, 10302);
this.FAE27E_location = this.FA9150_location + this.getCompressedFileSize(f, this.FA9150_location);
this.FAE860_location = this.toPNTR(10270, 10310);
this.FB1AEB_location = this.FAE860_location + this.getCompressedFileSize(f, this.FAE860_location);
this.FB24A0_location = this.toPNTR(10358, 10398);
this.FB42D9_location = this.FB24A0_location + this.getCompressedFileSize(f, this.FB24A0_location);
this.FB44E0_location = this.toPNTR(10366, 10406);
this.FB9610_location = this.FB44E0_location + this.getCompressedFileSize(f, this.FB44E0_location);
this.FB9A30_location = this.toPNTR(10374, 10414);
this.FBE5E2_location = this.FB9A30_location + this.getCompressedFileSize(f, this.FB9A30_location);
this.FBEBE0_location = this.toPNTR(10382, 10422);
this.FC3FEF_location = this.FBEBE0_location + this.getCompressedFileSize(f, this.FBEBE0_location);
this.FC4810_location = this.toPNTR(10390, 10430);
this.FC6C0F_location = this.FC4810_location + this.getCompressedFileSize(f, this.FC4810_location);
this.FC6F20_location = this.toPNTR(10486, 10526);
this.FC8AFC_location = this.FC6F20_location + this.getCompressedFileSize(f, this.FC6F20_location);
this.FC9150_location = this.toPNTR(10494, 10534);
this.FCF698_location = this.FC9150_location + this.getCompressedFileSize(f, this.FC9150_location);
this.FD0420_location = this.toPNTR(10502, 10542);
this.FD5A60_location = this.FD0420_location + this.getCompressedFileSize(f, this.FD0420_location);
this.FD6190_location = this.toPNTR(10474, 10514);
this.FDA2FF_location = this.FD6190_location + this.getCompressedFileSize(f, this.FD6190_location);
this.FDAA10_location = this.toPNTR(10242, 10282);
this.FDAA30_location = this.toPNTR(10246, 10286);
}
private int toPNTR(int u, int l) => (int) this.rom[u] * 16777216 + (int) this.rom[u + 1] * 65536 + (int) (short) ((int) this.rom[l] * 256 + (int) this.rom[l + 1]);
private void camera()
{
bool flag = false;
if (zoomIn | zoomOut | left | right | moveUp | moveDown)
{
BBCamera.PanUpdate(zoomIn, zoomOut, left, right, moveUp, moveDown);
flag = true;
}
Point mousePosition1 = Control.MousePosition;
this.newMouseX = mousePosition1.X;
mousePosition1 = Control.MousePosition;
this.newMouseY = mousePosition1.Y;
if (this.sceneClick)
flag = true;
if (this.forceRedraw)
{
flag = true;
this.forceRedraw = false;
}
if (this.RotateSceneClick)
{
flag = true;
this.BBCamera.MouseUpdate(this.newMouseX - this.oldMouseX, this.newMouseY - this.oldMouseY);
}
Point mousePosition2 = Control.MousePosition;
this.oldMouseX = mousePosition2.X;
mousePosition2 = Control.MousePosition;
this.oldMouseY = mousePosition2.Y;
if (!flag)
return;
this.world.core.ClearScreenAndLoadIdentity();
Gl.glPushMatrix();
Gl.glLoadMatrixf(this.BBCamera.GetWorldToViewMatrix());
this.world.Redraw(this.BBCamera);
Gl.glPopMatrix();
if (this.showStats)
{
BBUI.DrawStats(this.ls);
BBUI.DrawJinjos(this.LevelViewer.Width - 325, 2, this.world.jinjos);
this.world.core.SetView(this.LevelViewer.Height, this.LevelViewer.Width);
}
BBUI.DrawAxis(this.LevelViewer.Width - 90, this.LevelViewer.Height - 90, this.BBCamera);
this.world.core.SetView(this.LevelViewer.Height, this.LevelViewer.Width);
this.LevelViewer.SwapBuffers();
}
protected override void OnPaint(PaintEventArgs e) => base.OnPaint(e);
private void readINI()
{
try
{
StreamReader streamReader = new StreamReader(Application.StartupPath + "\\resources\\mw.ini");
string end = streamReader.ReadToEnd();
streamReader.Close();
if (Regex.IsMatch(end, "ROM:([^\\r\\n]*)"))
{
this.inRom = Regex.Match(end, "ROM:([^\\r\\n]*)").Groups[1].Value;
if (Regex.IsMatch(end, "DEBUG:ENABLED"))
this.enableDebug = true;
Regex.IsMatch(end, "DEBUG_TE:ENABLED");
if (Regex.IsMatch(end, "STACKSIZE:"))
{
Match match = Regex.Match(end, "STACKSIZE:(\\d.)");
try
{
this.world.setupStackSize = Convert.ToInt32(match.Groups[1].Value);
}
catch
{
}
}
try
{
BinaryReader binaryReader = new BinaryReader((Stream) File.Open(this.inRom, FileMode.Open));
long length = binaryReader.BaseStream.Length;
this.rom = new byte[length];
binaryReader.BaseStream.Read(this.rom, 0, (int) length);
binaryReader.Close();
this.enableMWFull();
this.romBuild.rom = this.rom;
RomHandler.Rom = this.rom;
this.romBuild.populateEORPointers();
}
catch (Exception ex)
{
int num = (int) MessageBox.Show("Banjo's Backpack Failed to open the rom " + ex.Message, "Unable to open rom");
this.openRom();
this.forceRedraw = true;
}
}
else
{
int num = (int) MessageBox.Show("Banjo's Backpack has detected that this is your first time using the program, please open a Banjo Kazooie Rom");
this.openRom();
}
}
catch (Exception ex)
{
int num = (int) MessageBox.Show("Banjo's Backpack has detected that this is your first time using the program, please open a Banjo Kazooie Rom");
this.openRom();
}
}
private void writeINI(string file)
{
try
{
if (!File.Exists(Application.StartupPath + "\\resources\\mw.ini"))
File.Create(Application.StartupPath + "\\resources\\mw.ini");
StreamReader streamReader = new StreamReader(Application.StartupPath + "\\resources\\mw.ini");
string end = streamReader.ReadToEnd();
streamReader.Close();
string str = !Regex.IsMatch(end, "ROM:([^\\r\\n]*)") ? end + "ROM:" + file + Environment.NewLine : Regex.Replace(end, "ROM:([^\\r\\n]*)", "ROM:" + file);
StreamWriter streamWriter = new StreamWriter(Application.StartupPath + "\\resources\\mw.ini");
streamWriter.Write(str);
streamWriter.Close();
}
catch (Exception ex1)
{
try
{
int num = (int) MessageBox.Show("Error: Could not open mw.ini");
if (MessageBox.Show("Do you want me to try to create the file?", "Attempt 2", MessageBoxButtons.YesNo) != DialogResult.Yes)
return;
File.Create(Application.StartupPath + "\\resources\\mw.ini");
StreamReader streamReader = new StreamReader(Application.StartupPath + "\\resources\\mw.ini");
string end = streamReader.ReadToEnd();
streamReader.Close();
string str = !Regex.IsMatch(end, "ROM:([^\\r\\n]*)") ? end + "ROM:" + file + Environment.NewLine : Regex.Replace(end, "ROM:([^\\r\\n]*)", "ROM:" + file);
StreamWriter streamWriter = new StreamWriter(Application.StartupPath + "\\resources\\mw.ini");
streamWriter.Write(str);
streamWriter.Close();
}
catch (Exception ex2)
{
int num = (int) MessageBox.Show("Error: General Failure");
}
}
}
private void KnowMoves(bool knowMoves)
{
byte[] numArray = this.arrayCopy(this.F37F90_location, 1048576);
GECompression ge = this.ge;
byte[] Buffer = numArray;
int length = Buffer.Length;
ge.SetCompressedBuffer(Buffer, length);
int compressedSize = 0;
int fileSize = 0;
this.F37F90 = ((IEnumerable<byte>) this.ge.OutputDecompressedBuffer(ref fileSize, ref compressedSize)).ToList<byte>();
if (!knowMoves)
{
this.F37F90[59470] = (byte) 195;
this.F37F90[59471] = (byte) 160;
}
else
{
this.F37F90[59470] = (byte) 15;
this.F37F90[59471] = (byte) 152;
}
FileStream output1 = File.Create(this.outDir + "F37F90.bin");
BinaryWriter binaryWriter1 = new BinaryWriter((Stream) output1);
binaryWriter1.Write(this.F37F90.ToArray(), 0, this.F37F90.Count);
binaryWriter1.Close();
output1.Close();
this.romBuild.rom = this.rom;
this.romBuild.populateEORPointers();
this.romBuild.outDir = this.outDir;
this.romBuild.insertDecompressedFile(this.outDir, "F37F90.bin", this.F37F90_location, this.F9CAE0_location - this.F37F90_location, true);
this.rom = this.romBuild.rom;
RomHandler.Rom = this.rom;
this.locateEORFiles();
FileStream output2 = File.Create(this.inRom);
BinaryWriter binaryWriter2 = new BinaryWriter((Stream) output2);
binaryWriter2.Write(this.romBuild.rom);
binaryWriter2.Close();
output2.Close();
this.reCRC();
int num = (int) MessageBox.Show(this.inRom + " has been updated");
}
private void reCRC()
{
string str = "rn64crc.exe";
Process process = new Process();
process.StartInfo.FileName = str;
process.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory() + "\\out\\";
process.StartInfo.Arguments = "-u \"" + this.inRom + "\"";
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.CreateNoWindow = true;
process.Start();
process.WaitForExit();
process.Close();
}
private void PrepRom()
{
int compressedSize = 0;
byte[] numArray = this.arrayCopy(this.F19250_location, this.F361E3_location - this.F19250_location);
GECompression geCompression = new GECompression();
byte[] Buffer = numArray;
geCompression.SetCompressedBuffer(Buffer, Buffer.Length);
int fileSize = 0;
byte[] buffer = geCompression.OutputDecompressedBuffer(ref fileSize, ref compressedSize);
buffer[68124] = (byte) 0;
buffer[68125] = (byte) 0;
buffer[68126] = (byte) 0;
buffer[68127] = (byte) 0;
buffer[68144] = (byte) 16;
buffer[68145] = (byte) 0;
buffer[395] = (byte) 145;
FileStream output1 = File.Create(this.outDir + "F19250.bin");
BinaryWriter binaryWriter1 = new BinaryWriter((Stream) output1);
binaryWriter1.Write(buffer, 0, fileSize);
binaryWriter1.Close();
output1.Close();
this.romBuild.rom = this.rom;
this.romBuild.populateEORPointers();
this.romBuild.outDir = this.outDir;
this.romBuild.insertDecompressedFile(this.outDir, "F19250.bin", this.F19250_location, compressedSize, true);
this.rom = this.romBuild.rom;
RomHandler.Rom = this.rom;
this.locateEORFiles();
uint num = 66060288;
byte[] f37f90;
byte[] assets;
new Globalizer(2151677952U, num, this.rom).BeginUpdating(out f37f90, out assets);
this.F37F90 = ((IEnumerable<byte>) f37f90).ToList<byte>();
this.insertF37F90();
this.romBuild.insertAsset(assets, (int) num);
this.rom = this.romBuild.rom;
RomHandler.Rom = this.rom;
this.locateEORFiles();
FileStream output2 = File.Create(this.inRom);
BinaryWriter binaryWriter2 = new BinaryWriter((Stream) output2);
binaryWriter2.Write(this.romBuild.rom);
binaryWriter2.Close();
output2.Close();
}
private void ReadSetupsXML()
{