| 1 |
UNIT Unit1_main; |
| 2 |
INTERFACE |
| 3 |
USES |
| 4 |
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
| 5 |
Dialogs, StdCtrls, StrUtils, Clipbrd, ExtCtrls, ComCtrls, Menus, |
| 6 |
Unit2_functions, Unit3_data, Unit5_preview, Unit7_txmpreplace; |
| 7 |
|
| 8 |
TYPE |
| 9 |
TForm1 = Class(TForm) |
| 10 |
panel_all: TPanel; |
| 11 |
panel_left: TPanel; |
| 12 |
Splitter1: TSplitter; |
| 13 |
panel_files: TPanel; |
| 14 |
btn_extractallconvert: TButton; |
| 15 |
btn_extract: TButton; |
| 16 |
btn_extractconvert: TButton; |
| 17 |
list_files: TListBox; |
| 18 |
btn_extractall: TButton; |
| 19 |
list_extensions: TListBox; |
| 20 |
Splitter2: TSplitter; |
| 21 |
panel_right: TPanel; |
| 22 |
edit_data: TMemo; |
| 23 |
list_names: TListBox; |
| 24 |
Splitter3: TSplitter; |
| 25 |
panel_info: TPanel; |
| 26 |
lbl_info: TLabel; |
| 27 |
btn_load: TButton; |
| 28 |
btn_hexcopy: TButton; |
| 29 |
fopen: TOpenDialog; |
| 30 |
lbl_fileinfo: TLabel; |
| 31 |
group_progress: TGroupBox; |
| 32 |
progress: TProgressBar; |
| 33 |
lbl_progress: TLabel; |
| 34 |
menu: TMainMenu; |
| 35 |
menu_main: TMenuItem; |
| 36 |
menu_exit: TMenuItem; |
| 37 |
menu_preview: TMenuItem; |
| 38 |
btn_extractcancel: TButton; |
| 39 |
menu_tools: TMenuItem; |
| 40 |
menu_txmpreplace: TMenuItem; |
| 41 |
procedure menu_txmpreplaceClick(Sender: TObject); |
| 42 |
procedure menu_exitClick(Sender: TObject); |
| 43 |
procedure btn_extractcancelClick(Sender: TObject); |
| 44 |
PROCEDURE menu_previewClick(Sender: TObject); |
| 45 |
PROCEDURE btn_extractallconvertClick(Sender: TObject); |
| 46 |
PROCEDURE Splitter2Moved(Sender: TObject); |
| 47 |
PROCEDURE Splitter1Moved(Sender: TObject); |
| 48 |
PROCEDURE FormClose(Sender: TObject; var Action: TCloseAction); |
| 49 |
PROCEDURE btn_hexcopyClick(Sender: TObject); |
| 50 |
PROCEDURE list_extensionsClick(Sender: TObject); |
| 51 |
PROCEDURE FormResize(Sender: TObject); |
| 52 |
PROCEDURE btn_extractconvertClick(Sender: TObject); |
| 53 |
PROCEDURE FormCreate(Sender: TObject); |
| 54 |
PROCEDURE list_filesDblClick(Sender: TObject); |
| 55 |
PROCEDURE btn_loadClick(Sender: TObject); |
| 56 |
PRIVATE |
| 57 |
PUBLIC |
| 58 |
END; |
| 59 |
|
| 60 |
VAR |
| 61 |
Form1: TForm1; |
| 62 |
|
| 63 |
IMPLEMENTATION |
| 64 |
{$R *.dfm} |
| 65 |
|
| 66 |
PROCEDURE DoAfterLoadOfADat; |
| 67 |
VAR |
| 68 |
i:LongWord; |
| 69 |
txt:Text; |
| 70 |
temp4:LongWord; |
| 71 |
temp2:Word; |
| 72 |
temp1:Byte; |
| 73 |
BEGIN |
| 74 |
IF NOT DirectoryExists(GetExtractPath) THEN |
| 75 |
CreateDir(GetExtractPath); |
| 76 |
AssignFile(txt,GetExtractPath+'\___TXMP-FILES___.TXT'); |
| 77 |
ReWrite(txt); |
| 78 |
FOR i:=0 TO dat_header.Extensions-1 DO BEGIN |
| 79 |
IF (dat_extensionsmap[i].Extension[3]='T') AND |
| 80 |
(dat_extensionsmap[i].Extension[2]='X') AND |
| 81 |
(dat_extensionsmap[i].Extension[1]='M') AND |
| 82 |
(dat_extensionsmap[i].Extension[0]='P') THEN BEGIN |
| 83 |
WriteLn(txt, FormatNumber(dat_extensionsmap[i].ExtCount,4,'0')+' TXMP-Files'); |
| 84 |
Break; |
| 85 |
END; |
| 86 |
END; |
| 87 |
WriteLn(txt,'FileName'+#9+'MipMap'+#9+'Depth'+#9+'ImgX'+#9+'ImgY'+#9+'StoreT'); |
| 88 |
FOR i:=0 TO dat_header.Files-1 DO BEGIN |
| 89 |
IF dat_files[i].Extension='TXMP' THEN BEGIN |
| 90 |
Write(txt,dat_files[i].FileName+#9); |
| 91 |
LoadDatFilePart(i,$88,1,@temp1); |
| 92 |
Write(txt,IntToHex(temp1,2)+#9); |
| 93 |
LoadDatFilePart(i,$89,1,@temp1); |
| 94 |
Write(txt,IntToHex(temp1,2)+#9); |
| 95 |
LoadDatFilePart(i,$8C,2,@temp2); |
| 96 |
Write(txt,IntToHex(temp2,4)+#9); |
| 97 |
LoadDatFilePart(i,$8E,2,@temp2); |
| 98 |
Write(txt,IntToHex(temp2,4)+#9); |
| 99 |
LoadDatFilePart(i,$90,1,@temp1); |
| 100 |
Write(txt,IntToHex(temp1,2)+#9); |
| 101 |
WriteLn(txt,''); |
| 102 |
END; |
| 103 |
END; |
| 104 |
CloseFile(txt); |
| 105 |
|
| 106 |
IF NOT DirectoryExists(GetExtractPath) THEN |
| 107 |
CreateDir(GetExtractPath); |
| 108 |
AssignFile(txt,GetExtractPath+'\___TXAN-FILES___.TXT'); |
| 109 |
ReWrite(txt); |
| 110 |
FOR i:=0 TO dat_header.Extensions-1 DO BEGIN |
| 111 |
IF (dat_extensionsmap[i].Extension[3]='T') AND |
| 112 |
(dat_extensionsmap[i].Extension[2]='X') AND |
| 113 |
(dat_extensionsmap[i].Extension[1]='A') AND |
| 114 |
(dat_extensionsmap[i].Extension[0]='N') THEN BEGIN |
| 115 |
WriteLn(txt, FormatNumber(dat_extensionsmap[i].ExtCount,4,'0')+' TXAN-Files'); |
| 116 |
Break; |
| 117 |
END; |
| 118 |
END; |
| 119 |
WriteLn(txt,'FileName'+#9+'Loopspeed'+#9+'Unknown'+#9+'Links'); |
| 120 |
FOR i:=0 TO dat_header.Files-1 DO BEGIN |
| 121 |
IF dat_files[i].Extension='TXAN' THEN BEGIN |
| 122 |
Write(txt,dat_files[i].FileName+#9); |
| 123 |
LoadDatFilePart(i,$14,2,@temp2); |
| 124 |
Write(txt,IntToHex(temp2,4)+#9); |
| 125 |
LoadDatFilePart(i,$16,2,@temp2); |
| 126 |
Write(txt,IntToHex(temp2,4)+#9); |
| 127 |
LoadDatFilePart(i,$1C,4,@temp4); |
| 128 |
Write(txt,IntToHex(temp4,8)+#9); |
| 129 |
WriteLn(txt,''); |
| 130 |
END; |
| 131 |
END; |
| 132 |
CloseFile(txt); |
| 133 |
END; |
| 134 |
|
| 135 |
PROCEDURE TForm1.btn_loadClick(Sender: TObject); |
| 136 |
VAR i:LongWord; |
| 137 |
BEGIN |
| 138 |
fopen.InitialDir:=AppSettings.DatPath; |
| 139 |
IF fopen.Execute THEN BEGIN |
| 140 |
Form1.Caption:='Oni Un/Packer '+version+' ('+ExtractFileName(fopen.FileName)+')'; |
| 141 |
AppSettings.DatPath:=ExtractFilepath(fopen.FileName); |
| 142 |
list_files.Items.Clear; |
| 143 |
list_extensions.Items.Clear; |
| 144 |
list_names.Items.Clear; |
| 145 |
IF LoadDatInfos(fopen.FileName) THEN BEGIN |
| 146 |
lbl_info.Caption:= |
| 147 |
'# of files: '+IntToStr(dat_header.Files)+CrLf+ |
| 148 |
'# of named files: '+IntToStr(dat_header.NamedFiles)+CrLf+ |
| 149 |
'# of extensions: '+IntToStr(dat_header.Extensions)+CrLf+ |
| 150 |
'Address of Body: 0x'+IntToHex(dat_header.DataAddr,8)+CrLf+ |
| 151 |
'Address of End: 0x'+IntToHex(dat_header.NamesAddr,8); |
| 152 |
list_extensions.Items.Add('_All files: '+FormatNumber(dat_header.Files,4,' ')); |
| 153 |
FOR i:=0 TO dat_header.Extensions-1 DO BEGIN |
| 154 |
WITH dat_extensionsmap[i] DO BEGIN |
| 155 |
list_extensions.Items.Add( |
| 156 |
Extension[3]+Extension[2]+Extension[1]+Extension[0]+': '+ |
| 157 |
FormatNumber(ExtCount,4,' '));{+' (Ident: 0x'+ |
| 158 |
IntToHex(Ident[7],2)+IntToHex(Ident[6],2)+IntToHex(Ident[5],2)+IntToHex(Ident[4],2)+IntToHex(Ident[3],2)+IntToHex(Ident[2],2)+IntToHex(Ident[1],2)+IntToHex(Ident[0],2)+')');} |
| 159 |
END; |
| 160 |
END; |
| 161 |
FOR i:=0 TO dat_header.namedFiles-1 DO BEGIN |
| 162 |
WITH dat_namedfilesmap[i] DO BEGIN |
| 163 |
list_names.Items.Add('0x'+IntToHex(filenumber,8)+': 0x'+IntToHex(blubb,8)); |
| 164 |
END; |
| 165 |
END; |
| 166 |
Form1.list_extensions.ItemIndex:=0; |
| 167 |
Form1.list_extensionsClick(Form1); |
| 168 |
Form1.list_files.ItemIndex:=0; |
| 169 |
Form1.list_filesDblClick(Form1); |
| 170 |
|
| 171 |
Form7.RecreateTXMPlist; |
| 172 |
|
| 173 |
DoAfterLoadOfADat; |
| 174 |
|
| 175 |
END ELSE BEGIN |
| 176 |
ShowMessage('Error while loading the file:'+CrLf+fopen.FileName+CrLf+'Perhaps not an Oni-.dat-file?'); |
| 177 |
END; |
| 178 |
END; |
| 179 |
END; |
| 180 |
|
| 181 |
PROCEDURE TForm1.list_filesDblClick(Sender: TObject); |
| 182 |
VAR |
| 183 |
id:LongWord; |
| 184 |
temp:Tdata; |
| 185 |
BEGIN |
| 186 |
id:=StrToInt(MidStr(list_files.Items.Strings[list_files.ItemIndex],1,5)); |
| 187 |
lbl_fileinfo.Caption:= |
| 188 |
'Filename: '+dat_files[id].FileName+CrLf+ |
| 189 |
'Size: '+FormatFileSize(dat_files[id].Size)+' ('+IntToStr(dat_files[id].Size)+' Bytes)'+CrLf+ |
| 190 |
'FileType: 0x'+IntToHex(dat_files[id].FileType,8)+CrLf+ |
| 191 |
'Address in .dat: 0x'+IntTohex(dat_files[id].DatAddr,8); |
| 192 |
IF (dat_files[id].FileType AND $02)=0 THEN BEGIN |
| 193 |
temp:=LoadDatFile(id); |
| 194 |
edit_data.Text:=CreateHexString(temp,False); |
| 195 |
btn_hexcopy.Visible:=True; |
| 196 |
IF menu_preview.Checked THEN Form5.ShowPreview(id); |
| 197 |
END ELSE BEGIN |
| 198 |
edit_data.Text:='Zero byte file.'+CrLf+'Oni will take the data for this file of level0_final.dat/raw'; |
| 199 |
btn_hexcopy.Visible:=False; |
| 200 |
END; |
| 201 |
END; |
| 202 |
|
| 203 |
PROCEDURE TForm1.FormCreate(Sender: TObject); |
| 204 |
BEGIN |
| 205 |
Form1.Caption:='Oni Un/Packer '+version; |
| 206 |
Form1.FormResize(Form1); |
| 207 |
|
| 208 |
panel_all.Align:=alClient; |
| 209 |
|
| 210 |
IF FileExists(ExtractFilepath(Application.EXEname)+'\oniunpacker.ini') THEN BEGIN |
| 211 |
AssignFile(AppSettingsFile,ExtractFilepath(Application.EXEname)+'\oniunpacker.ini'); |
| 212 |
Reset(AppSettingsFile); |
| 213 |
Read(AppSettingsFile,AppSettings); |
| 214 |
CloseFile(AppSettingsFile); |
| 215 |
END ELSE BEGIN |
| 216 |
AppSettings.DatPath:='D:\Spiele\Oni\GameDataFolder'; |
| 217 |
AppSettings.ExtractPath:='C:\Dokumente und Einstellungen\Administrator\Desktop'; |
| 218 |
END; |
| 219 |
|
| 220 |
//Form1.btn_loadClick(Form1); |
| 221 |
END; |
| 222 |
|
| 223 |
PROCEDURE TForm1.btn_extractconvertClick(Sender: TObject); |
| 224 |
VAR |
| 225 |
result:Integer; |
| 226 |
id:LongWord; |
| 227 |
BEGIN |
| 228 |
id:=StrToInt(MidStr(list_files.Items.Strings[list_files.ItemIndex],1,5)); |
| 229 |
IF TComponent(Sender).Name='btn_extract' THEN |
| 230 |
result:=ExportFile(id,False) |
| 231 |
ELSE |
| 232 |
result:=ExportFile(id,True); |
| 233 |
CASE result OF |
| 234 |
0{export_noerror}: IF 1=2 THEN BEGIN END; |
| 235 |
1{export_nohandler}: ShowMessage('No export-handler for files with extension '+dat_files[id].Extension+'.'); |
| 236 |
2{export_handlererror}: ShowMessage('Error while running data-handler for '+CrLf+dat_files[id].FileName); |
| 237 |
3{export_error}: ShowMessage('Error while exporting file '+CrLf+dat_files[id].FileName); |
| 238 |
ELSE ShowMessage('Couldn''t export file '+FormatNumber(id,5,'0')+CrLf+'(Unknown error)'); |
| 239 |
END; |
| 240 |
Form1.list_files.SetFocus; |
| 241 |
END; |
| 242 |
|
| 243 |
PROCEDURE TForm1.FormResize(Sender: TObject); |
| 244 |
CONST |
| 245 |
MinWidth:Integer=750; |
| 246 |
MinHeight:Integer=500; |
| 247 |
BEGIN |
| 248 |
IF NOT group_progress.Visible THEN BEGIN |
| 249 |
IF Form1.Width<MinWidth THEN Form1.Width:=MinWidth; |
| 250 |
IF Form1.Height<MinHeight THEN Form1.Height:=MinHeight; |
| 251 |
END; |
| 252 |
END; |
| 253 |
|
| 254 |
PROCEDURE TForm1.list_extensionsClick(Sender: TObject); |
| 255 |
VAR |
| 256 |
Extension:String[4]; |
| 257 |
i:LongWord; |
| 258 |
BEGIN |
| 259 |
Extension:=MidStr(list_extensions.Items.Strings[list_extensions.ItemIndex],1,4); |
| 260 |
list_files.Items.Clear; |
| 261 |
IF Extension='_All' THEN BEGIN |
| 262 |
FOR i:=0 TO dat_header.Files-1 DO |
| 263 |
list_files.Items.Add(dat_files[i].FileName); |
| 264 |
END ELSE BEGIN |
| 265 |
FOR i:=0 TO dat_header.Files-1 DO |
| 266 |
IF dat_files[i].Extension=Extension THEN |
| 267 |
list_files.Items.Add(dat_files[i].FileName); |
| 268 |
END; |
| 269 |
END; |
| 270 |
|
| 271 |
PROCEDURE TForm1.btn_hexcopyClick(Sender: TObject); |
| 272 |
VAR |
| 273 |
temp:Tdata; |
| 274 |
BEGIN |
| 275 |
temp:=LoadDatFile(StrToInt(MidStr(list_files.Items.Strings[list_files.ItemIndex],1,5))); |
| 276 |
Clipboard.SetTextBuf(PChar(CreateHexString(temp,True))); |
| 277 |
END; |
| 278 |
|
| 279 |
PROCEDURE TForm1.FormClose(Sender: TObject; var Action: TCloseAction); |
| 280 |
BEGIN |
| 281 |
AssignFile(AppSettingsFile,ExtractFilepath(Application.EXEname)+'\oniunpacker.ini'); |
| 282 |
IF FileExists(ExtractFilepath(Application.EXEname)+'\oniunpacker.ini') THEN |
| 283 |
Reset(AppSettingsFile) |
| 284 |
ELSE |
| 285 |
Rewrite(AppSettingsFile); |
| 286 |
Write(AppSettingsFile,AppSettings); |
| 287 |
CloseFile(AppSettingsFile); |
| 288 |
END; |
| 289 |
|
| 290 |
PROCEDURE TForm1.Splitter1Moved(Sender: TObject); |
| 291 |
BEGIN |
| 292 |
Form1.list_files.Height:=Form1.Splitter1.Top-32; |
| 293 |
Form1.btn_extractallconvert.Top:=Form1.Splitter1.Top-33; |
| 294 |
Form1.btn_extract.Top:=Form1.Splitter1.Top-33; |
| 295 |
Form1.btn_extractconvert.Top:=Form1.Splitter1.Top-33; |
| 296 |
Form1.btn_extractall.Top:=Form1.Splitter1.Top-33; |
| 297 |
END; |
| 298 |
|
| 299 |
PROCEDURE TForm1.Splitter2Moved(Sender: TObject); |
| 300 |
BEGIN |
| 301 |
Form1.btn_extractall.Left:=Form1.Splitter2.Left-146; |
| 302 |
Form1.btn_extractallconvert.Left:=Form1.Splitter2.Left-83; |
| 303 |
END; |
| 304 |
|
| 305 |
PROCEDURE TForm1.btn_extractallconvertClick(Sender: TObject); |
| 306 |
VAR |
| 307 |
convert:Boolean; |
| 308 |
i:LongWord; |
| 309 |
errors:LongWord; |
| 310 |
oldwidth,oldheight:Integer; |
| 311 |
oldstate:TWindowState; |
| 312 |
BEGIN |
| 313 |
panel_all.Visible:=False; |
| 314 |
panel_info.Visible:=False; |
| 315 |
group_progress.Visible:=True; |
| 316 |
menu.Items.Visible:=False; |
| 317 |
menu.Items.Enabled:=False; |
| 318 |
//FOR i:=0 TO menu.ComponentCount DO menu.Items.Items[i].Enabled:=False; |
| 319 |
oldwidth:=Form1.Width; |
| 320 |
oldheight:=Form1.Height; |
| 321 |
oldstate:=Form1.WindowState; |
| 322 |
Form1.WindowState:=wsNormal; |
| 323 |
Form1.Width:=400; |
| 324 |
Form1.Height:=103; |
| 325 |
group_progress.Left:=0; |
| 326 |
group_progress.Top:=0; |
| 327 |
group_progress.Width:=Form1.Width-8; |
| 328 |
progress.Width:=group_progress.Width-80; |
| 329 |
progress.Max:=dat_header.files; |
| 330 |
btn_extractcancel.Left:=group_progress.Width-65; |
| 331 |
btn_extractcancel.Caption:='Cancel'; |
| 332 |
btn_extractcancel.SetFocus; |
| 333 |
|
| 334 |
IF TComponent(Sender).Name='btn_extractall' THEN |
| 335 |
convert:=False |
| 336 |
ELSE |
| 337 |
convert:=True; |
| 338 |
errors:=0; |
| 339 |
FOR i:=0 TO High(dat_files) DO BEGIN |
| 340 |
IF ExportFile(i,convert)>0 THEN Inc(errors); |
| 341 |
IF (i MOD 25)=0 THEN BEGIN |
| 342 |
lbl_progress.Caption:=IntToStr(i)+'/'+IntToStr(dat_header.Files); |
| 343 |
progress.Position:=i; |
| 344 |
Application.ProcessMessages; |
| 345 |
IF btn_extractcancel.Caption='Cancel_' THEN BEGIN |
| 346 |
btn_extractcancel.Caption:='Cancel'; |
| 347 |
Break; |
| 348 |
END; |
| 349 |
END; |
| 350 |
END; |
| 351 |
IF errors>0 THEN |
| 352 |
ShowMessage(IntToStr(errors)+' errors encountered.'); |
| 353 |
|
| 354 |
Form1.Width:=oldwidth; |
| 355 |
Form1.Height:=oldheight; |
| 356 |
Form1.WindowState:=oldstate; |
| 357 |
//FOR i:=0 TO menu.ComponentCount DO menu.Items.Items[i].Enabled:=True; |
| 358 |
panel_all.Visible:=True; |
| 359 |
panel_info.Visible:=True; |
| 360 |
group_progress.Visible:=False; |
| 361 |
END; |
| 362 |
|
| 363 |
PROCEDURE TForm1.menu_previewClick(Sender: TObject); |
| 364 |
BEGIN |
| 365 |
Form5.Visible:=NOT Form5.Visible; |
| 366 |
END; |
| 367 |
|
| 368 |
PROCEDURE TForm1.btn_extractcancelClick(Sender: TObject); |
| 369 |
BEGIN |
| 370 |
btn_extractcancel.Caption:='Cancel_'; |
| 371 |
END; |
| 372 |
|
| 373 |
PROCEDURE TForm1.menu_exitClick(Sender: TObject); |
| 374 |
BEGIN |
| 375 |
Form1.Close; |
| 376 |
END; |
| 377 |
|
| 378 |
PROCEDURE TForm1.menu_txmpreplaceClick(Sender: TObject); |
| 379 |
BEGIN |
| 380 |
Form7.Visible:=NOT Form7.Visible; |
| 381 |
END; |
| 382 |
|
| 383 |
END. |