source: oup/releases/0.11a/Unit1_main.pas@ 1149

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