UNIT Unit1_main; INTERFACE USES Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, StrUtils, Clipbrd, ExtCtrls, ComCtrls, Menus, Grids, MPHexEditor, ToolWin, ImgList, Tabs, Unit2_functions, Unit3_data, Unit9_data_structures, Unit10_leveldb, Unit4_exporters, Unit14_settings, Unit5_preview, Unit7_txmpreplace, Unit8_binedit, Unit11_extractor, Unit13_rawedit, Unit15_Classes, MDITab, TB2Item, TB2Dock, TB2Toolbar, TB2MDI; TYPE TForm1 = Class(TForm) saved: TSaveDialog; opend: TOpenDialog; statbar: TStatusBar; MenuImages: TImageList; MDITabPopUp: TPopupMenu; mdi_close: TMenuItem; DockTop: TTBDock; MainMenu: TTBToolbar; menu_main: TTBSubmenuItem; menu_loaddat: TTBItem; menu_lvldb: TTBItem; menu_CloseFileDB: TTBItem; menu_sep1: TTBSeparatorItem; menu_settings: TTBItem; menu_sep4: TTBSeparatorItem; menu_exit: TTBItem; menu_convert: TTBSubmenuItem; menu_createdb: TTBItem; menu_createlvl: TTBItem; menu_tools: TTBSubmenuItem; menu_preview: TTBItem; menu_binedit: TTBItem; menu_rawedit: TTBItem; menu_txmpreplace: TTBItem; menu_extractor: TTBItem; menu_filecompare: TTBItem; menu_levelstructedit: TTBItem; menu_windows: TTBSubmenuItem; menu_windows_cascade: TTBItem; menu_windows_tile: TTBItem; menu_windows_closeall: TTBItem; menu_sep3: TTBSeparatorItem; menu_windows_next: TTBItem; menu_windows_previous: TTBItem; menu_sep2: TTBSeparatorItem; menu_About: TTBItem; Toolbar: TTBToolbar; tbOpen: TTBItem; DockLeft: TTBDock; DockRight: TTBDock; DockBottom: TTBDock; MDIHandler: TTBMDIHandler; MDIToolbar: TTBToolbar; TBControlItem1: TTBControlItem; MDITab: TMDITab; menu_view: TTBSubmenuItem; menu_view_mdibar: TTBItem; menu_view_statusbar: TTBItem; menu_view_toolbar: TTBItem; toolbar_mdi: TTBToolbar; TBItem1: TTBItem; TBItem2: TTBItem; FUNCTION TryCloseAll:Boolean; procedure menu_AboutClick(Sender: TObject); PROCEDURE menu_settingsClick(Sender: TObject); PROCEDURE menu_CloseFileDBClick(Sender: TObject); PROCEDURE menu_filecompareClick(Sender: TObject); PROCEDURE menu_raweditClick(Sender: TObject); PROCEDURE menu_createlvlClick(Sender: TObject); PROCEDURE menu_extractorClick(Sender: TObject); PROCEDURE menu_lvldbClick(Sender: TObject); PROCEDURE menu_createdbClick(Sender: TObject); PROCEDURE close_window(window_name:String); PROCEDURE menu_windows_previousClick(Sender: TObject); PROCEDURE menu_windows_nextClick(Sender: TObject); PROCEDURE menu_windows_tileClick(Sender: TObject); FUNCTION open_child(window_context:String):Boolean; PROCEDURE menu_windows_closeallClick(Sender: TObject); PROCEDURE menu_windows_cascadeClick(Sender: TObject); PROCEDURE menu_window_entryClick(Sender: TObject); PROCEDURE menu_bineditClick(Sender: TObject); PROCEDURE menu_loaddatClick(Sender: TObject); PROCEDURE menu_txmpreplaceClick(Sender: TObject); PROCEDURE menu_exitClick(Sender: TObject); PROCEDURE menu_previewClick(Sender: TObject); PROCEDURE FormClose(Sender: TObject; var Action: TCloseAction); PROCEDURE FormResize(Sender: TObject); PROCEDURE FormCreate(Sender: TObject); PROCEDURE UpdateStatBar; procedure MDITabGetImageIndex(Sender: TObject; TabIndex: Integer; var ImageIndex: Integer); procedure MDIToolbarResize(Sender: TObject); procedure menu_view_mdibarClick(Sender: TObject); procedure menu_view_statusbarClick(Sender: TObject); procedure menu_view_toolbarClick(Sender: TObject); PRIVATE PUBLIC END; VAR Form1: TForm1; IMPLEMENTATION {$R *.dfm} PROCEDURE TForm1.FormCreate(Sender: TObject); BEGIN Form1.Caption:='Oni Un/Packer '+version; Form1.FormResize(Form1); IF FileExists(ExtractFilepath(Application.EXEname)+'\oniunpacker.ini') THEN BEGIN AssignFile(AppSettingsFile,ExtractFilepath(Application.EXEname)+'\oniunpacker.ini'); Reset(AppSettingsFile); Read(AppSettingsFile,AppSettings); CloseFile(AppSettingsFile); END ELSE BEGIN AppSettings.DatPath:='D:\Spiele\Oni\GameDataFolder'; AppSettings.ExtractPath:='C:\Dokumente und Einstellungen\Administrator\Desktop'; AppSettings.FilenumbersAsHex:=False; AppSettings.CharSet:=DEFAULT_CHARSET; AppSettings.HideUnusedData:=False; END; IF MidStr(ParamStr(1),1,3)='opf' THEN BEGIN ShowMessage('Load OPF-File: '+ParamStr(2)); END ELSE IF MidStr(ParamStr(1),1,4)='oldb' THEN BEGIN IF NOT CreateDataConnection(ParamStr(2), ODB_ADB) THEN ShowMessage('Error while loading the file:'+CrLf+ParamStr(2)+CrLf+'Perhaps not an OniUnPacker-LevelDatabase-file?'); END ELSE IF MidStr(ParamStr(1),1,3)='dat' THEN BEGIN IF NOT CreateDataConnection(ParamStr(2), ODB_Dat) THEN ShowMessage('Error while loading the file:'+CrLf+ParamStr(2)+CrLf+'Perhaps not an Oni-.dat-file?'); END; UpdateStatBar; END; PROCEDURE TForm1.FormResize(Sender: TObject); CONST MinWidth:Integer=750; MinHeight:Integer=500; BEGIN IF Form1.Width0 then // ImageIndex:=0 // else ImageIndex:=-1; end; procedure TForm1.MDIToolbarResize(Sender: TObject); begin { if MDIToolbar.Width>100 then MDITab.Width:=MDIToolbar.Width-10 else MDIToolbar.Width:=100; } end; PROCEDURE TForm1.FormClose(Sender: TObject; var Action: TCloseAction); BEGIN AssignFile(AppSettingsFile,ExtractFilepath(Application.EXEname)+'\oniunpacker.ini'); IF FileExists(ExtractFilepath(Application.EXEname)+'\oniunpacker.ini') THEN Reset(AppSettingsFile) ELSE Rewrite(AppSettingsFile); Write(AppSettingsFile,AppSettings); CloseFile(AppSettingsFile); Action:=caFree; END; PROCEDURE TForm1.UpdateStatBar; BEGIN IF Assigned(OniDataConnection) THEN BEGIN Form1.Caption:='Oni Un/Packer '+version+' ('+ExtractFileName(OniDataConnection.FileName)+')'; menu_tools.Enabled:=True; menu_convert.Enabled:=False; statbar.Panels.Items[1].Text:='Files: '+IntToStr(OniDataConnection.GetFilesCount); statbar.Panels.Items[2].Text:='Extensions: '+IntToStr(Length(OniDataConnection.GetExtensionsList)); CASE OniDataConnection.Backend OF ODB_Dat: BEGIN statbar.Panels.Items[0].Text:='.dat loaded: '+OniDataConnection.FileName; END; ODB_ADB: BEGIN statbar.Panels.Items[0].Text:='OLDB loaded: '+OniDataConnection.FileName; END; ELSE Form1.Caption:='Oni Un/Packer '+version; statbar.Panels.Items[0].Text:='Nothing loaded'; statbar.Panels.Items[1].Text:='Files: -'; statbar.Panels.Items[2].Text:='Extensions: -'; menu_tools.Enabled:=False; menu_convert.Enabled:=True; END; END ELSE BEGIN Form1.Caption:='Oni Un/Packer '+version; statbar.Panels.Items[0].Text:='Nothing loaded'; statbar.Panels.Items[1].Text:='Files: -'; statbar.Panels.Items[2].Text:='Extensions: -'; menu_tools.Enabled:=False; menu_convert.Enabled:=True; END; END; FUNCTION TForm1.TryCloseAll:Boolean; BEGIN menu_windows_closeallClick(Self); IF MDITab.MDIChildCount=0 THEN Result:=True ELSE Result:=False; END; {#################################} {##### Main-Menu-Handlers #####} {#################################} PROCEDURE TForm1.menu_loaddatClick(Sender: TObject); VAR i:LongWord; answer:Boolean; BEGIN IF TryCloseAll THEN BEGIN CloseDataConnection; opend.InitialDir:=AppSettings.DatPath; opend.Filter:='Oni-Dat-Files|*.dat'; IF opend.Execute THEN BEGIN IF NOT CreateDataConnection(opend.FileName, ODB_Dat) THEN ShowMessage('Error while loading the file:'+CrLf+opend.FileName+CrLf+'Perhaps not an Oni-.dat-file?'); AppSettings.DatPath:=ExtractFilepath(opend.FileName); END; END; UpdateStatBar; END; PROCEDURE TForm1.menu_lvldbClick(Sender: TObject); VAR answer:Boolean; BEGIN IF TryCloseAll THEN BEGIN CloseDataConnection; opend.InitialDir:=AppSettings.DatPath; opend.Filter:='OUP-Level-DB (*.oldb)|*.oldb'; IF opend.Execute THEN BEGIN IF NOT CreateDataConnection(opend.FileName, ODB_ADB) THEN ShowMessage('Error while loading the file:'+CrLf+opend.FileName+CrLf+'Perhaps not an OniUnPacker-LevelDatabase-file?'); AppSettings.DatPath:=ExtractFilepath(opend.FileName); END; END; UpdateStatBar; END; PROCEDURE TForm1.menu_CloseFileDBClick(Sender: TObject); BEGIN IF TryCloseAll THEN BEGIN CloseDataConnection; UpdateStatBar; END; END; PROCEDURE TForm1.menu_settingsClick(Sender: TObject); BEGIN Form14.Visible:=True; Self.Enabled:=False; END; PROCEDURE TForm1.menu_exitClick(Sender: TObject); BEGIN Form1.Close; END; {####################################} {##### Converters-Menu-Handlers #####} {####################################} PROCEDURE TForm1.menu_createdbClick(Sender: TObject); BEGIN opend.Filter:='Oni-Dat-Files|*.dat'; saved.Filter:='OUP-Level-DB (*.oldb)|*.oldb'; saved.DefaultExt:='oldb'; IF opend.Execute THEN BEGIN IF saved.Execute THEN BEGIN Form10.CreateDatabase(opend.FileName,saved.FileName); END; END; END; PROCEDURE TForm1.menu_createlvlClick(Sender: TObject); BEGIN opend.Filter:='OUP-Level-DB (*.oldb)|*.oldb'; saved.Filter:='Oni-Dat-Files|*.dat'; saved.DefaultExt:='dat'; IF opend.Execute THEN BEGIN IF saved.Execute THEN BEGIN Form10.CreateLevel(opend.FileName,saved.FileName); END; END; END; {#################################} {##### Tools-Menu-Handlers #####} {#################################} PROCEDURE TForm1.menu_previewClick(Sender: TObject); BEGIN open_child('preview'); END; PROCEDURE TForm1.menu_txmpreplaceClick(Sender: TObject); BEGIN open_child('txmpreplace'); END; PROCEDURE TForm1.menu_bineditClick(Sender: TObject); BEGIN open_child('binedit'); END; PROCEDURE TForm1.menu_raweditClick(Sender: TObject); BEGIN open_child('rawedit'); END; PROCEDURE TForm1.menu_extractorClick(Sender: TObject); BEGIN open_child('extractor'); END; PROCEDURE TForm1.menu_filecompareClick(Sender: TObject); BEGIN open_child('compare'); END; {#################################} {##### View-Menu-Handlers #####} {#################################} procedure TForm1.menu_view_mdibarClick(Sender: TObject); begin menu_view_mdibar.Checked := not menu_view_mdibar.Checked; mditoolbar.Visible := menu_view_mdibar.Checked; end; procedure TForm1.menu_view_statusbarClick(Sender: TObject); begin menu_view_statusbar.Checked := not menu_view_statusbar.Checked; statbar.Visible := menu_view_statusbar.Checked; end; procedure TForm1.menu_view_toolbarClick(Sender: TObject); begin menu_view_toolbar.Checked := not menu_view_toolbar.Checked; toolbar.Visible := menu_view_toolbar.Checked; end; {#################################} {##### Window-Menu-Handlers #####} {#################################} PROCEDURE TForm1.menu_windows_cascadeClick(Sender: TObject); BEGIN Form1.Cascade; END; PROCEDURE TForm1.menu_windows_tileClick(Sender: TObject); BEGIN Form1.TileMode:=tbHorizontal; Form1.Tile; END; PROCEDURE TForm1.menu_windows_closeallClick(Sender: TObject); VAR i:Byte; BEGIN MDITab.CloseAll; END; PROCEDURE TForm1.menu_windows_nextClick(Sender: TObject); VAR i:Byte; first_window:Byte; current_focus:String; BEGIN IF MDIChildCount>1 THEN BEGIN FOR i:=0 TO menu_windows.Count-1 DO BEGIN IF Pos('menu_window_',menu_windows.Items[i].Name)=1 THEN BEGIN first_window:=i; Break; END; END; current_focus:=ActiveMDIChild.Name; FOR i:=first_window TO menu_windows.Count-1 DO IF Pos(current_focus,menu_windows.Items[i].Name)>0 THEN Break; IF i=menu_windows.Count-1 THEN menu_windows.Items[first_window].Click ELSE menu_windows.Items[i+1].Click; END; END; PROCEDURE TForm1.menu_windows_previousClick(Sender: TObject); VAR i:Byte; first_window:Byte; current_focus:String; BEGIN IF MDIChildCount>1 THEN BEGIN FOR i:=0 TO menu_windows.Count-1 DO BEGIN IF Pos('menu_window_',menu_windows.Items[i].Name)=1 THEN BEGIN first_window:=i; Break; END; END; current_focus:=ActiveMDIChild.Name; FOR i:=first_window TO menu_windows.Count-1 DO IF Pos(current_focus,menu_windows.Items[i].Name)>0 THEN Break; IF i=first_window THEN menu_windows.Items[menu_windows.Count-1].Click ELSE menu_windows.Items[i-1].Click; END; END; PROCEDURE TForm1.menu_window_entryClick(Sender: TObject); VAR i:Byte; window_name:String; BEGIN window_name:=MidStr(TComponent(Sender).Name,Pos('window_',TComponent(Sender).Name)+7,Length(TComponent(Sender).Name)-Pos('window_',TComponent(Sender).Name)+7+1); FOR i:=0 TO MDIChildCount-1 DO BEGIN IF MDIChildren[i].Name=window_name THEN BEGIN MDIChildren[i].BringToFront; END; END; END; procedure TForm1.menu_AboutClick(Sender: TObject); begin ShowMessage('Will be implemented later ;)'); end; FUNCTION TForm1.open_child(window_context:String):Boolean; VAR rawEdit:TForm13; binEdit:TForm8; preview:TForm5; txmpreplacer:TForm7; extractor:TForm11; menu_button:TTBItem; used:Array[1..9] OF Boolean; i:Byte; caption:String; name:String; BEGIN Result:=True; FOR i:=1 TO 9 DO used[i]:=False; IF MDIChildCount>0 THEN FOR i:=0 TO MDIChildCount-1 DO IF Pos(window_context,Form1.MDIChildren[i].Name)=1 THEN used[StrToInt(RightStr(Form1.MDIChildren[i].Caption,1))]:=True; FOR i:=1 TO 10 DO IF i=10 THEN Break ELSE IF NOT used[i] THEN Break; IF i<10 THEN BEGIN name:=window_context+IntToStr(i); IF window_context='binedit' THEN caption:='Binary .dat-Editor '+IntToStr(i); IF window_context='rawedit' THEN caption:='Binary .raw-Editor '+IntToStr(i); IF window_context='preview' THEN caption:='Preview-Window '+IntToStr(i); IF window_context='txmpreplace' THEN caption:='TXMP Replacer '+IntToStr(i); IF window_context='extractor' THEN caption:='Extractor '+IntToStr(i); menu_button:=TTBItem.Create(menu_windows); menu_button.Caption:=caption; menu_button.Name:='menu_window_'+name; menu_button.OnClick:=Form1.menu_window_entryClick; menu_windows.Add(menu_button); IF window_context='binedit' THEN BEGIN binEdit:=TForm8.Create(Application); binEdit.Name:=name; binEdit.Caption:=caption; binEdit.Recreatelist; MDITab.AddTab(binEdit,-1); END; IF window_context='rawedit' THEN BEGIN rawEdit:=TForm13.Create(Application); rawEdit.Name:=name; rawEdit.Caption:=caption; rawEdit.Recreatelist; MDITab.AddTab(rawEdit,-1); END; IF window_context='preview' THEN BEGIN preview:=TForm5.Create(Application); preview.Name:=name; preview.Caption:=caption; preview.Recreatelist; MDITab.AddTab(preview,-1); END; IF window_context='txmpreplace' THEN BEGIN txmpreplacer:=TForm7.Create(Application); txmpreplacer.Name:=name; txmpreplacer.Caption:=caption; txmpreplacer.Recreatelist; MDITab.AddTab(txmpreplacer,-1); END; IF window_context='extractor' THEN BEGIN extractor:=TForm11.Create(Application); extractor.Name:=name; extractor.Caption:=caption; extractor.Recreatelist; MDITab.AddTab(extractor,-1); END; IF MDIChildCount=9 THEN menu_tools.Enabled:=False; END ELSE BEGIN Result:=False; END; END; PROCEDURE TForm1.close_window(window_name:String); VAR i,j:Byte; BEGIN FOR i:=0 TO menu_windows.Count-1 DO BEGIN IF menu_windows.Items[i].Name='menu_window_'+window_name THEN BEGIN menu_windows.Items[i].Free; Break; END; END; menu_tools.Enabled:=True; END; END.