Index: oup/current/Code_DataStructures.pas
===================================================================
--- oup/current/Code_DataStructures.pas	(revision 43)
+++ oup/current/Code_DataStructures.pas	(revision 43)
@@ -0,0 +1,604 @@
+unit Code_DataStructures;
+
+interface
+
+uses SysUtils, Classes, Data, Dialogs, StrUtils;
+
+type
+  Tstructure_entry = record
+    Name:     String;
+    offset:   LongWord;
+    datatype: Word;  // 1..4  : Integer[1..4] dec
+    // 5..8  : Integer[1..4] hex
+    // 9     : float
+    // 10    : bitset
+    // 11    : raw-addr
+    // 12    : dat-file-ID
+    // 13..16: Signed Integer[1..4]
+    // 17    : level-ID
+    // 100..300: dat-file-name[0..200]
+    // 1000..9999: Unused data[0-8999]
+    // 10000+: string[0+]
+    description: String;
+  end;
+
+  TStructDefSub = record
+    SubName: String;
+    SubDesc: String;
+    Entries: array of TStructure_entry;
+  end;
+
+  TStructDef = record
+    Data:   Boolean;
+    Global: array of TStructure_entry;
+    Subs:   array of TStructDefSub;
+  end;
+  THandler = function(fileid: LongWord): TRawList;
+
+  TRawListHandlers = record
+    Ext:     String[4];
+    needed:  Boolean;
+    Handler: THandler;
+  end;
+
+var
+  RawListHandlers: array of TRawListHandlers;
+  Raws: String;
+
+
+function LoadStructureDefinition(fileid: LongWord): TStructDef;
+function GetDataType(typeid: Word): String;
+function GetTypeDataLength(datatype: Word): Word;
+
+implementation
+
+uses Code_Functions, Code_OniDataClass, Forms;
+
+
+
+
+function GetTypeDataLength(datatype: Word): Word;
+begin
+  case datatype of
+    1..4:
+      Result := datatype;
+    5..8:
+      Result := datatype - 4;
+    9:
+      Result := 4;
+    10:
+      Result := 1;
+    11:
+      Result := 4;
+    12:
+      Result := 4;
+    13..16:
+      Result := datatype - 12;
+    17:
+      Result := 4;
+    100..300:
+      Result := datatype - 100;
+    1000..9999:
+      Result := datatype - 1000;
+    10000..65535:
+      Result := datatype - 10000;
+  end;
+end;
+
+
+
+
+function GetDataType(typeid: Word): String;
+begin
+  case typeid of
+    1..4:
+      Result := 'Int' + IntToStr(typeid * 8);
+    5..8:
+      Result := 'Int' + IntToStr((typeid - 4) * 8);
+    9:
+      Result := 'Float';
+    10:
+      Result := 'BitSet';
+    11:
+      Result := 'Raw-Address';
+    12:
+      Result := '.dat-file-ID';
+    13..16:
+      Result := 'SignedInt' + IntToStr((typeid - 12) * 8);
+    17:
+      Result := 'LevelID';
+    100..300:
+      Result := '.dat-file-name(' + IntToStr(typeid - 100) + ')';
+    1000..9999:
+      Result := 'Unused(' + IntToStr(typeid - 1000) + ')';
+    10000..65535:
+      Result := 'String(' + IntToStr(typeid - 10000) + ')';
+  end;
+end;
+
+
+
+
+function AGDB(fileid: LongWord): TRawList;
+var
+  link:  LongWord;
+  links: LongWord;
+  i:     LongWord;
+begin
+  if not OniDataConnection.OSisMac then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @links);
+    links := links * 2;
+    SetLength(Result, links);
+    for i := 0 to links - 1 do
+    begin
+      Result[i].src_offset := $20 + i * 4;
+      OniDataConnection.LoadDatFilePart(fileid, $20 + i * 4, 4, @link);
+      Result[i].raw_addr := link;
+      Result[i].raw_size := 0{????????????????????????????????};
+      Result[i].loc_sep  := False;
+    end;
+  end;
+end;
+
+
+
+
+function AKVA(fileid: LongWord): TRawList;
+var
+  link:  LongWord;
+  links: LongWord;
+  i:     LongWord;
+begin
+  if not OniDataConnection.OSisMac then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @links);
+    SetLength(Result, links);
+    for i := 0 to links - 1 do
+    begin
+      Result[i].src_offset := $20 + i * $74 + $24;
+      OniDataConnection.LoadDatFilePart(fileid, $20 + i * $74 + $24, 4, @link);
+      Result[i].raw_addr := link;
+      OniDataConnection.LoadDatFilePart(fileid, $20 + i * $74 + $28, 4, @link);
+      Result[i].raw_size := link;
+      Result[i].loc_sep  := False;
+    end;
+  end;
+end;
+
+
+
+
+function BINA(fileid: LongWord): TRawList;
+var
+  link:     LongWord;
+  datasize: LongWord;
+begin
+  OniDataConnection.LoadDatFilePart(fileid, $0C, 4, @link);
+  OniDataConnection.LoadDatFilePart(fileid, $08, 4, @datasize);
+  SetLength(Result, 1);
+  Result[0].src_offset := $0C;
+  Result[0].raw_addr   := link;
+  Result[0].raw_size   := datasize;
+  Result[0].loc_sep    := OniDataConnection.OSisMac;
+end;
+
+
+
+
+function OSBD(fileid: LongWord): TRawList;
+var
+  link:     LongWord;
+  datasize: LongWord;
+begin
+  OniDataConnection.LoadDatFilePart(fileid, $08, 4, @datasize);
+  OniDataConnection.LoadDatFilePart(fileid, $0C, 4, @link);
+  SetLength(Result, 1);
+  Result[0].src_offset := $0C;
+  Result[0].raw_addr   := link;
+  Result[0].raw_size   := datasize;
+  Result[0].loc_sep    := OniDataConnection.OSisMac;
+end;
+
+
+
+
+function SNDD(fileid: LongWord): TRawList;
+var
+  link:     LongWord;
+  datasize: LongWord;
+begin
+  SetLength(Result, 1);
+  if not OniDataConnection.OSisMac then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $40, 4, @datasize);
+    OniDataConnection.LoadDatFilePart(fileid, $44, 4, @link);
+    Result[0].src_offset := $44;
+  end
+  else
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $10, 4, @datasize);
+    OniDataConnection.LoadDatFilePart(fileid, $14, 4, @link);
+    Result[0].src_offset := $14;
+  end;
+  Result[0].raw_addr := link;
+  Result[0].raw_size := datasize;
+  Result[0].loc_sep  := False;
+end;
+
+
+
+
+function SUBT(fileid: LongWord): TRawList;
+var
+  baselink, lastlink: LongWord;
+  links: LongWord;
+  j, k:  LongWord;
+  Data:  Tdata;
+begin
+  OniDataConnection.LoadDatFilePart(fileid, $18, 4, @baselink);
+  OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @links);
+  if links > 0 then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $20 + (links - 1) * 4, 4, @lastlink);
+    SetLength(Data, lastlink + 1024);
+    TOniDataDat(OniDataConnection).LoadRawOffset(False,
+      baselink, lastlink + 1024, Data);
+    //      OniDataConnection.LoadRawFile(fileid,$1C,baselink,lastlink+1024,False,@data[0]);
+    k := 0;
+    for j := 0 to 1024 do
+    begin
+      if (Data[lastlink + j] = $00) or (j = 1024) then
+      begin
+        if j < 1024 then
+        begin
+          if k = 0 then
+          begin
+            k := 1;
+          end
+          else
+          begin
+            SetLength(Result, 1);
+            Result[0].src_offset := $18;
+            Result[0].raw_addr   := baselink;
+            Result[0].raw_size   := lastlink + j;
+            Break;
+          end;
+        end;
+      end;
+    end;
+  end;
+end;
+
+
+
+
+function TRAM(fileid: LongWord): TRawList;
+var
+  i:      Integer;
+  link:   LongWord;
+  frames: Word;
+  tempb:  Byte;
+  tempw:  Word;
+  templ:  LongWord;
+  Data:   Tdata;
+  offset: Word;
+  frame_count: Byte;
+begin
+  SetLength(Result, 13);
+  OniDataConnection.LoadDatFilePart(fileid, $16C, 2, @frames);
+  {y-pos}
+  OniDataConnection.LoadDatFilePart(fileid, $0C, 4, @link);
+  Result[0].src_offset := $0C;
+  Result[0].raw_addr   := link;
+  Result[0].raw_size   := frames * 4;
+  {x-z-pos}
+  OniDataConnection.LoadDatFilePart(fileid, $10, 4, @link);
+  Result[1].src_offset := $10;
+  Result[1].raw_addr   := link;
+  Result[1].raw_size   := frames * 8;
+  {attacks}
+  OniDataConnection.LoadDatFilePart(fileid, $182, 1, @tempb);
+  OniDataConnection.LoadDatFilePart(fileid, $14, 4, @link);
+  Result[2].src_offset := $14;
+  Result[2].raw_addr   := link;
+  Result[2].raw_size   := tempb * 32;
+  {damage}
+  OniDataConnection.LoadDatFilePart(fileid, $183, 1, @tempb);
+  OniDataConnection.LoadDatFilePart(fileid, $18, 4, @link);
+  Result[3].src_offset := $18;
+  Result[3].raw_addr   := link;
+  Result[3].raw_size   := tempb * 8;
+  {motionblur}
+  OniDataConnection.LoadDatFilePart(fileid, $184, 1, @tempb);
+  OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @link);
+  Result[4].src_offset := $1C;
+  Result[4].raw_addr   := link;
+  Result[4].raw_size   := tempb * 8;
+  {shortcut}
+  OniDataConnection.LoadDatFilePart(fileid, $185, 1, @tempb);
+  OniDataConnection.LoadDatFilePart(fileid, $20, 4, @link);
+  Result[5].src_offset := $20;
+  Result[5].raw_addr   := link;
+  Result[5].raw_size   := tempb * 8;
+  {throw}
+  OniDataConnection.LoadDatFilePart(fileid, $24, 4, @link);
+  Result[6].src_offset := $24;
+  Result[6].raw_addr   := link;
+  if link > 0 then
+    Result[6].raw_size := 24
+  else
+    Result[6].raw_size := 0;
+  {footstep}
+  OniDataConnection.LoadDatFilePart(fileid, $186, 1, @tempb);
+  OniDataConnection.LoadDatFilePart(fileid, $28, 4, @link);
+  Result[7].src_offset := $28;
+  Result[7].raw_addr   := link;
+  Result[7].raw_size   := tempb * 4;
+  {particle}
+  OniDataConnection.LoadDatFilePart(fileid, $187, 1, @tempb);
+  OniDataConnection.LoadDatFilePart(fileid, $2C, 4, @link);
+  Result[8].src_offset := $2C;
+  Result[8].raw_addr   := link;
+  Result[8].raw_size   := tempb * 24;
+  {position}
+  OniDataConnection.LoadDatFilePart(fileid, $30, 4, @link);
+  Result[9].src_offset := $30;
+  Result[9].raw_addr   := link;
+  Result[9].raw_size   := frames * 8;
+  {particle}
+  OniDataConnection.LoadDatFilePart(fileid, $154, 2, @tempw);
+  OniDataConnection.LoadDatFilePart(fileid, $38, 4, @link);
+  Result[11].src_offset := $38;
+  Result[11].raw_addr   := link;
+  Result[11].raw_size   := tempw * 34;
+  {extent}
+  OniDataConnection.LoadDatFilePart(fileid, $138, 4, @templ);
+  OniDataConnection.LoadDatFilePart(fileid, $13C, 4, @link);
+  Result[12].src_offset := $13C;
+  Result[12].raw_addr   := link;
+  Result[12].raw_size   := templ * 12;
+
+  OniDataConnection.LoadDatFilePart(fileid, $34, 4, @link);
+  if link > 0 then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $160, 2, @tempw);
+    frame_count := 0;
+    i := 0;
+    SetLength(Data, $FFFF);
+    TOniDataDat(OniDataConnection).LoadRawOffset(False, link, $FFFF, Data);
+    offset := Data[$24] + Data[$25] * 256;
+    while (offset + i < Length(Data)) and (frame_count < frames - 1) do
+    begin
+      Inc(i, tempw);
+      frame_count := frame_count + Data[offset + i];
+      Inc(i);
+    end;
+    if offset + i < Length(Data) then
+    begin
+      Inc(i, tempw);
+      Result[10].raw_size := offset + i;
+    end
+    else
+    begin
+      Result[10].raw_size := 0;
+    end;
+  end;
+  Result[10].src_offset := $34;
+  Result[10].raw_addr   := link;
+end;
+
+
+
+
+function TXMP(fileid: LongWord): TRawList;
+var
+  link_pc:   LongWord;
+  link_mac:  LongWord;
+  x, y:      Word;
+  storetype: Byte;
+  datasize:  LongWord;
+begin
+  OniDataConnection.LoadDatFilePart(fileid, $8C, SizeOf(x), @x);
+  OniDataConnection.LoadDatFilePart(fileid, $8E, SizeOf(y), @y);
+  OniDataConnection.LoadDatFilePart(fileid, $90, SizeOf(storetype), @storetype);
+  OniDataConnection.LoadDatFilePart(fileid, $9C, 4, @link_pc);
+  OniDataConnection.LoadDatFilePart(fileid, $A0, 4, @link_mac);
+  case storetype of
+    0, 1, 2:
+      datasize := x * y * 2;
+    8:
+      datasize := x * y * 4;
+    9:
+      datasize := x * y div 2;
+  end;
+  SetLength(Result, 1);
+  if not OniDataConnection.OSisMac then
+  begin
+    Result[0].src_offset := $9C;
+    Result[0].raw_addr   := link_pc;
+  end
+  else
+  begin
+    Result[0].src_offset := $A0;
+    Result[0].raw_addr   := link_mac;
+  end;
+  Result[0].raw_size := datasize;
+  Result[0].loc_sep  := OniDataConnection.OSisMac;
+end;
+
+
+
+
+procedure InsertRawListHandler(ext: String; needed: Boolean; handler: THandler);
+begin
+  SetLength(RawListHandlers, Length(RawListHandlers) + 1);
+  RawListHandlers[High(RawListHandlers)].Ext := ext;
+  RawListHandlers[High(RawListHandlers)].needed := needed;
+  RawListHandlers[High(RawListHandlers)].handler := handler;
+  Raws := Raws + ext;
+end;
+
+
+
+
+function LoadStructureDefinition(fileid: LongWord): TStructDef;
+var
+  i:      LongWord;
+  current_type: Byte; //0: Global, 1: Undynamic, 2: Dynamic
+  current_base, current_package, current_package_size: LongWord;
+  packages: LongWord;
+  deffile: Text;
+  structentry: TStructure_Entry;
+  fields: TStringArray;
+  filename: String;
+  ext:    String[4];
+  temps:  String;
+  Data:   TData;
+begin
+  SetLength(Result.Global, 0);
+  SetLength(Result.Subs, 0);
+  Result.Data := False;
+  ext      := OniDataConnection.GetFileInfo(fileid).Extension;
+  filename := ExtractFilePath(Application.ExeName) + '\StructDefs\' + ext + '.txt';
+  if FileExists(filename) then
+  begin
+    Data := OniDataConnection.LoadDatFile(fileid);
+    AssignFile(deffile, filename);
+    Reset(deffile);
+    current_type := 0;
+    Result.Data  := True;
+    if not EOF(deffile) then
+    begin
+      ReadLn(deffile, temps);
+      while not EOF(deffile) do
+      begin
+        ReadLn(deffile, temps);
+        if (Length(temps) > 0) and (temps[1] <> '#') then
+        begin
+          if temps[1] = '*' then
+          begin
+            fields := Explode(temps, #9);
+            case Length(fields) of
+              1..2:
+              begin
+                current_type := 1;
+                current_base := 0;
+                SetLength(Result.Subs, Length(Result.Subs) + 1);
+                Result.Subs[High(Result.Subs)].SubName :=
+                  MidStr(fields[0], 2, Length(fields[0]) - 1);
+                if Length(fields) = 2 then
+                  Result.Subs[High(Result.Subs)].SubDesc := fields[1];
+              end;
+              3:
+              begin
+                current_type := 1;
+                current_base := HexToLong(fields[2]);
+                SetLength(Result.Subs, Length(Result.Subs) + 1);
+                Result.Subs[High(Result.Subs)].SubName :=
+                  MidStr(fields[0], 2, Length(fields[0]) - 1);
+                Result.Subs[High(Result.Subs)].SubDesc := fields[1];
+              end;
+              6:
+              begin
+                current_type    := 2;
+                current_base    := HexToLong(fields[2]);
+                current_package := 0;
+                current_package_size := StrToInt(fields[5]);
+                if fields[4][1] <> '$' then
+                begin
+                  case StrToInt(fields[4]) of
+                    1:
+                      packages := Data[HexToLong(fields[3])];
+                    2:
+                      packages := Data[HexToLong(fields[3])] + Data[HexToLong(fields[3]) + 1] * 256;
+                    4:
+                      packages := Data[HexToLong(fields[3])] + Data[HexToLong(fields[3]) + 1] *
+                        256 + Data[HexToLong(fields[3]) + 2] * 256 * 256 + Data[HexToLong(fields[3]) + 3] * 256 * 256 * 256;
+                  end;
+                end
+                else
+                begin
+                  packages := HexToLong(fields[4]);
+                end;
+                SetLength(Result.Subs, Length(Result.Subs) + packages);
+                for current_package := 0 to packages - 1 do
+                begin
+                  Result.Subs[High(Result.Subs) - packages +
+                    current_package + 1].SubName :=
+                    MidStr(fields[0], 2, Length(fields[0]) - 1) +
+                    '[' + IntToStr(current_package) + ']' + '#' +
+                    IntToHex(current_base + current_package * current_package_size, 8) +
+                    '#' + IntToHex(current_package_size, 8);
+                  Result.Subs[High(Result.Subs) - packages +
+                    current_package + 1].SubDesc :=
+                    fields[1];
+                end;
+              end;
+            end;
+          end
+          else
+          begin
+            fields := Explode(temps, #9);
+            if (Length(fields) = 3) or (Length(fields) = 4) then
+            begin
+              if not AppSettings.HideUnusedData or
+                ((StrToInt(fields[2]) < 1000) or (StrToInt(fields[2]) > 9999)) then
+              begin
+                structentry.Name     := fields[0];
+                structentry.datatype := StrToInt(fields[2]);
+                if Length(fields) = 4 then
+                  structentry.description := fields[3]
+                else
+                  structentry.description := '';
+                if current_type in [0, 1] then
+                begin
+                  structentry.offset := HexToLong(fields[1]) + current_base;
+                  if Length(Result.Subs) = 0 then
+                  begin
+                    SetLength(Result.Global, Length(Result.Global) + 1);
+                    Result.Global[High(Result.Global)] := structentry;
+                  end
+                  else
+                  begin
+                    SetLength(Result.Subs[High(Result.Subs)].Entries,
+                      Length(Result.Subs[High(Result.Subs)].Entries) + 1);
+                    Result.Subs[High(Result.Subs)].Entries[High(
+                      Result.Subs[High(Result.Subs)].Entries)] := structentry;
+                  end;
+                end
+                else
+                begin
+                  for current_package := 0 to packages - 1 do
+                  begin
+                    structentry.offset :=
+                      current_base + current_package * current_package_size + HexToLong(fields[1]);
+                    with Result.Subs[High(Result.Subs) - packages + current_package + 1] do
+                    begin
+                      SetLength(Entries, Length(Entries) + 1);
+                      Entries[High(Entries)] := structentry;
+                    end;
+                  end;
+                end;
+              end;
+            end;
+          end;
+        end;
+      end;
+    end;
+    CloseFile(deffile);
+  end;
+end;
+
+
+begin
+  Raws := '';
+  //  InsertRawListHandler('AGDB',True,AGDB);
+  InsertRawListHandler('AKVA', True, AKVA);
+  InsertRawListHandler('BINA', True, BINA);
+  InsertRawListHandler('OSBD', True, OSBD);
+  InsertRawListHandler('SNDD', True, SNDD);
+  InsertRawListHandler('SUBT', True, SUBT);
+  InsertRawListHandler('TRAM', True, TRAM);
+  InsertRawListHandler('TXMP', True, TXMP);
+end.
Index: oup/current/Code_Exporters.pas
===================================================================
--- oup/current/Code_Exporters.pas	(revision 43)
+++ oup/current/Code_Exporters.pas	(revision 43)
@@ -0,0 +1,256 @@
+unit Code_Exporters;
+
+interface
+
+uses Classes, Dialogs, StrUtils, SysUtils, Math, Data, Code_OniImgClass;
+
+procedure ExportDatFile(fileid: LongWord; filename: String);
+procedure ExportRawFile(fileid: LongWord; dat_offset: LongWord; filename: String);
+
+function ExportSNDD(fileid: LongWord; filename: String; convert: Boolean): Integer;
+function ExportTRAC(fileid: LongWord; filename: String; convert: Boolean): Integer;
+function ExportTXAN(fileid: LongWord; filename: String; convert: Boolean): Integer;
+function ExportTXMB(fileid: LongWord; filename: String; convert: Boolean): Integer;
+function ExportTXMP(fileid: LongWord; filename: String; convert: Boolean): Integer;
+
+var
+  ExportHandlers: array[1..1] of TExportHandlers = (
+    //    (Ext:'ABNA'; needed:False),
+    //(Ext:'AGDB'; needed:False),
+    (Ext: 'SNDD'; needed: True; Handler: ExportSNDD)
+{    (Ext:'TRAC'; needed:True; Handler:ExportTRAC),
+    (Ext:'TXAN'; needed:True; Handler:ExportTXAN),
+    (Ext:'TXMB'; needed:True; Handler:ExportTXMB),
+    (Ext:'TXMP'; needed:True; Handler:ExportTXMP)
+});
+
+
+
+implementation
+
+uses Code_Functions, Code_DataStructures, Code_OniDataClass;
+
+
+
+
+procedure ExportDatFile(fileid: LongWord; filename: String);
+var
+  filestream: TFileStream;
+  Data: Tdata;
+begin
+  Data := OniDataConnection.LoadDatFile(fileid);
+  if FileExists(filename) then
+  begin
+    filestream := TFileStream.Create(filename, fmOpenReadWrite);
+    filestream.Seek(0, soFromEnd);
+  end
+  else
+  begin
+    filestream := TFileStream.Create(filename, fmCreate);
+  end;
+  filestream.Write(Data[0], Length(Data));
+  filestream.Free;
+end;
+
+
+
+
+procedure ExportRawFile(fileid: LongWord; dat_offset: LongWord; filename: String);
+var
+  filestream: TFileStream;
+  Data: Tdata;
+begin
+  SetLength(Data, OniDataConnection.GetRawInfo(fileid, dat_offset).raw_size);
+  OniDataConnection.LoadRawFile(fileid, dat_offset, @Data[0]);
+  if FileExists(filename + '.raw0x' + IntToHex(dat_offset, 8)) then
+  begin
+    filestream := TFileStream.Create(filename + '.raw0x' + IntToHex(
+      dat_offset, 8), fmOpenReadWrite);
+    filestream.Seek(0, soFromEnd);
+  end
+  else
+  begin
+    filestream := TFileStream.Create(filename + '.raw0x' + IntToHex(dat_offset, 8), fmCreate);
+  end;
+  filestream.Write(Data[0], Length(Data));
+  filestream.Free;
+end;
+
+
+
+
+function ExportSNDD;
+{  CONST
+    WAVheader:Array[0..0] OF Byte=(
+        Ord('R'),Ord('I'),Ord('F'),Ord('F'),0,0,0,0,Ord('W'),Ord('A'),Ord('V'),Ord('E'),
+        Ord('f'),Ord('m'),Ord('t'),Ord(' '),24,0,0,0,
+      );
+}  type
+  TDatData = record
+    {0x00}
+    _fileid:   LongWord;
+    level:     LongWord;
+    Flag:      LongWord;
+    FormatTag: Word;
+    ChanNo:    Word;
+    {0x10}
+    SampleRate: LongWord;
+    BytesPSec: LongWord;
+    BPSample:  LongWord;
+    BitsPS:    LongWord;
+    {0x20}
+    Unknown:   array[1..7] of LongWord;
+    Unknown2:  Word;
+    {0x40}
+    RawSize:   LongWord;
+    RawPos:    LongWord;
+  end;
+var
+  filestream: TFileStream;
+
+  DatData:     TDatData;
+  //Wave Header Stuff
+  ASCII_Group: LongWord; //"RIFF"
+  WAV_Len:     LongWord;
+  ASCII_WAV:   LongWord; //"WAVE"
+  ASCII_FMT:   LongWord; //"fmt "
+  WAV_FMT_Len: LongWord;
+  ASCII_DATA:  LongWord; //"data"
+  WAV_FolLen:  LongWord;
+
+  Data: Tdata;
+begin
+  Result := export_noerror;
+  OniDataConnection.LoadDatFilePart(fileid, 0, SizeOf(DatData), @DatData);
+  with DatData do
+  begin
+    //Initializing Header vars
+    ASCII_Group := 1179011410; // 'RIFF'
+    WAV_Len     := RAWSize + 70;
+    ASCII_WAV   := 1163280727;  // 'WAVE'
+    ASCII_FMT   := 544501094;   // 'fmt '
+    WAV_FMT_Len := 50;          // 50 bytes
+    ASCII_DATA  := 1635017060;  // 'data'
+    WAV_FolLen  := RAWSize;
+    SetLength(Data, RAWSize);
+    OniDataConnection.LoadRawFile(fileid, $44, Data);
+
+    filestream := TFileStream.Create(filename + '.raw', fmCreate);
+    filestream.Write(Data[0], Length(Data));
+    filestream.Free;
+
+    if convert then
+    begin
+      //Now start packing this into a neat wave...
+      filestream := TFileStream.Create(filename + '.wav', fmCreate);
+      filestream.Write(ASCII_Group, SizeOf(ASCII_Group));
+      filestream.Write(WAV_Len, SizeOf(WAV_Len));
+      filestream.Write(ASCII_WAV, SizeOf(ASCII_WAV));
+      filestream.Write(ASCII_FMT, SizeOf(ASCII_FMT));
+      filestream.Write(WAV_FMT_Len, SizeOf(WAV_FMT_Len));
+      filestream.Write(ChanNo, SizeOf(ChanNo));
+      filestream.Write(Samplerate, SizeOf(Samplerate));
+      filestream.Write(BytesPSec, SizeOf(BytesPSec));
+      filestream.Write(BPSample, SizeOf(BPSample));
+      filestream.Write(BitsPS, SizeOf(BitsPS));
+      filestream.Write(Unknown[1], SizeOf(Unknown));
+      filestream.Write(Unknown2, SizeOf(Unknown2));
+      filestream.Write(ASCII_DATA, SizeOf(ASCII_DATA));
+      filestream.Write(WAV_FolLen, SizeOf(WAV_FolLen));
+      filestream.Write(Data[0], Length(Data));
+      filestream.Free;
+    end;
+  end;
+end;
+
+
+
+
+function ExportTRAC;
+var
+  link: LongWord;
+  linkcount: Word;
+  i: LongWord;
+begin
+  Result := export_noerror;
+
+  OniDataConnection.LoadDatFilePart(fileid, $18, SizeOf(link), @link);
+  link := link div 256;
+
+  OniDataConnection.LoadDatFilePart(fileid, $1E, SizeOf(linkcount), @linkcount);
+  for i := 1 to linkcount do
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $20 + (i - 1) * 12 + 8, SizeOf(link), @link);
+    link := link div 256;
+  end;
+end;
+
+
+
+
+function ExportTXAN;
+var
+  loop_speed, unknown: Word;
+  linkcount: LongWord;
+  link: LongWord;
+  i: Byte;
+begin
+  Result := export_noerror;
+
+  OniDataConnection.LoadDatFilePart(fileid, $14, SizeOf(loop_speed), @loop_speed);
+  OniDataConnection.LoadDatFilePart(fileid, $16, SizeOf(unknown), @unknown);
+
+  OniDataConnection.LoadDatFilePart(fileid, $1C, SizeOf(linkcount), @linkcount);
+  for i := 0 to linkcount - 1 do
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $20 + i * 4, SizeOf(link), @link);
+    link := link div 256;
+    if link = 0 then
+      link := fileid - 1;
+  end;
+end;
+
+
+
+
+function ExportTXMB;
+var
+  filestream: TFileStream;
+  //    img:TImgPackage;
+  Data: Tdata;
+begin
+  Result := export_noerror;
+  if convert then
+  begin
+{      img:=LoadTXMBconnected(fileid);
+      data:=ImgdataToBmp(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
+      filestream:=TFileStream.Create(filename+'.bmp',fmCreate);
+      filestream.Write(data[0],Length(data));
+      filestream.Free;
+}    end;
+end;
+
+
+
+
+function ExportTXMP;
+var
+  filestream: TFileStream;
+  //    img:TImgPackage;
+begin
+  Result := export_noerror;
+{    img:=LoadImgData(fileid);
+
+    filestream:=TFileStream.Create(filename+'.raw',fmCreate);
+    filestream.Write(img.imgdata[0],Length(img.imgdata));
+    filestream.Free;
+
+    IF convert THEN BEGIN
+      img.imgdata:=ImgdataToBMP(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
+      filestream:=TFileStream.Create(filename+'.bmp',fmCreate);
+      filestream.Write(img.imgdata[0],Length(img.imgdata));
+      filestream.Free;
+    END;
+}  end;
+
+end.
Index: oup/current/Code_Functions.pas
===================================================================
--- oup/current/Code_Functions.pas	(revision 43)
+++ oup/current/Code_Functions.pas	(revision 43)
@@ -0,0 +1,401 @@
+unit Code_Functions;
+
+interface
+
+uses Classes, Dialogs, SysUtils, StrUtils, Math, Data;
+
+type
+  TExportSet = set of (DO_dat, DO_raw, DO_convert, DO_toone);
+
+function BoolToStr(bool: Boolean): String;
+function HexToLong(hex: String): LongWord;
+function Decode_Int(buffer: Tdata): LongWord;
+function Encode_Int(input: LongWord): Tdata;
+function Decode_Float(buffer: Tdata): Single;
+function Encode_Float(input: Single): Tdata;
+function DataToBin(Data: Tdata): String;
+function BinToInt(bin: String): Byte;
+
+function ExportFile(fileid: LongWord; filename: String; settings: TExportSet;
+  path: String): Integer;
+
+function StringSmaller(string1, string2: String): Boolean;
+
+function FormatNumber(Value: LongWord; Width: Byte; leadingzeros: Char): String;
+function FormatFileSize(size: LongWord): String;
+function CreateHexString(Data: Tdata; HexOnly: Boolean): String;
+function DecodeHexString(hex: String): Tdata;
+function GetWinFileName(Name: String): String;
+function GetExtractPath: String;
+
+function Explode(_string: String; delimiter: Char): TStringArray;
+
+
+implementation
+
+uses Code_Exporters, Code_OniDataClass;
+
+type
+  TValueSwitcher = record
+    case IsFloat: Boolean of
+      True: (ValueFloat: Single);
+      False: (ValueInt: LongWord);
+  end;
+
+
+
+
+function BoolToStr(bool: Boolean): String;
+begin
+  if bool then
+    Result := 'true'
+  else
+    Result := 'false';
+end;
+
+
+
+
+function HexToLong(hex: String): LongWord;
+
+
+
+
+  function NormalizeHexString(var hex: String): Boolean;
+  var
+    i: Byte;
+  begin
+    if hex[1] = '$' then
+    begin
+      for i := 1 to Length(hex) - 1 do
+      begin
+        hex[i] := hex[i + 1];
+      end;
+      SetLength(hex, Length(hex) - 1);
+    end;
+    if (hex[1] = '0') and (UpCase(hex[2]) = 'X') then
+    begin
+      for i := 1 to Length(hex) - 2 do
+      begin
+        hex[i] := hex[i + 2];
+      end;
+      SetLength(hex, Length(hex) - 2);
+    end;
+    if Length(hex) = 0 then
+      Result := False
+    else
+      Result := True;
+  end;
+
+var
+  i: Byte;
+begin
+  if NormalizeHexString(hex) then
+  begin
+    hex    := UpperCase(hex);
+    Result := 0;
+    for i := 1 to Length(hex) do
+    begin
+      Result := Result shl 4;
+      case hex[i] of
+        '0'..'9':
+          Result := Result + Ord(hex[i]) - 48;
+        'A'..'F':
+          Result := Result + Ord(hex[i]) - 55;
+        else
+          Result := 0;
+          Exit;
+      end;
+    end;
+  end
+  else
+  begin
+    Result := 0;
+  end;
+end;
+
+
+
+
+function Decode_Int(buffer: Tdata): LongWord;
+begin
+  Result := buffer[0] + buffer[1] * 256 + buffer[2] * 256 * 256 + buffer[3] * 256 * 256 * 256;
+end;
+
+
+
+
+function Encode_Int(input: LongWord): Tdata;
+begin
+  SetLength(Result, 4);
+  Result[0] := input mod 256;
+  input     := input div 256;
+  Result[1] := input mod 256;
+  input     := input div 256;
+  Result[2] := input mod 256;
+  input     := input div 256;
+  Result[3] := input mod 256;
+end;
+
+
+
+
+function Decode_Float(buffer: Tdata): Single;
+var
+  _valueswitcher: TValueSwitcher;
+begin
+  _valueswitcher.ValueInt := Decode_Int(buffer);
+  Result := _valueswitcher.ValueFloat;
+  if IsNAN(Result) then
+    Result := 0.0;
+end;
+
+
+
+
+function Encode_Float(input: Single): Tdata;
+var
+  _valueswitcher: TValueSwitcher;
+begin
+  _valueswitcher.ValueFloat := input;
+  Result := Encode_Int(_valueswitcher.ValueInt);
+end;
+
+
+
+
+function DataToBin(Data: Tdata): String;
+var
+  i, j:     Byte;
+  singlebyte: Byte;
+  bytepart: String;
+begin
+  SetLength(bytepart, 8);
+  Result := '';
+  for i := 0 to High(Data) do
+  begin
+    singlebyte := Data[i];
+    for j := 7 downto 0 do
+    begin
+      bytepart[j + 1] := Char((singlebyte and $01) + 48);
+      singlebyte      := singlebyte shr 1;
+    end;
+    Result := Result + bytepart + ' ';
+  end;
+end;
+
+
+
+
+function BinToInt(bin: String): Byte;
+var
+  Add: Integer;
+  i:   Byte;
+begin
+  Result := 0;
+  if Length(bin) <> 8 then
+    Exit;
+  Add := 1;
+  for i := 8 downto 1 do
+  begin
+    if not (bin[i] in ['0', '1']) then
+      Exit;
+    if bin[i] = '1' then
+      Inc(Result, Add);
+    Add := Add shl 1;
+  end;
+end;
+
+
+
+
+function FormatNumber(Value: LongWord; Width: Byte; leadingzeros: Char): String;
+begin
+  Result := AnsiReplaceStr(Format('%' + IntToStr(Width) + 'u', [Value]), ' ', leadingzeros);
+end;
+
+
+
+
+function FormatFileSize(size: LongWord): String;
+begin
+  if size >= 1000 * 1024 * 1024 then
+  begin
+    Result := FloatToStrF(size / 1024 / 1024 / 1024, ffFixed, 5, 1) + ' GB';
+  end
+  else
+  begin
+    if size >= 1000 * 1024 then
+    begin
+      Result := FloatToStrF(size / 1024 / 1024, ffFixed, 5, 1) + ' MB';
+    end
+    else
+    begin
+      if size >= 1000 then
+      begin
+        Result := FloatToStrF(size / 1024, ffFixed, 5, 1) + ' KB';
+      end
+      else
+      begin
+        Result := IntToStr(size) + ' B';
+      end;
+    end;
+  end;
+end;
+
+
+
+
+function CreateHexString(Data: Tdata; HexOnly: Boolean): String;
+var
+  string_build, ascii_version: String;
+  i: LongWord;
+begin
+  string_build  := '';
+  ascii_version := '';
+  for i := 0 to High(Data) do
+  begin
+    if not HexOnly then
+      if (i mod 16) = 0 then
+        string_build := string_build + '0x' + IntToHex(i, 6) + '  ';
+    string_build := string_build + IntToHex(Data[i], 2);
+    if not HexOnly then
+    begin
+      if Data[i] >= 32 then
+        ascii_version := ascii_version + Chr(Data[i])
+      else
+        ascii_version := ascii_version + '.';
+      if ((i + 1) mod 2) = 0 then
+        string_build := string_build + #32;
+      if ((i + 1) mod 16) = 0 then
+      begin
+        string_build  := string_build + #32 + ascii_version + CrLf;
+        ascii_version := '';
+      end;
+    end;
+  end;
+  Result := string_build;
+end;
+
+
+
+
+function DecodeHexString(hex: String): Tdata;
+var
+  i: LongWord;
+begin
+  SetLength(Result, Length(hex) div 2);
+  for i := 0 to Length(Result) do
+  begin
+    Result[i] := 0;
+    case UpCase(hex[1 + i * 2]) of
+      '0'..'9':
+        Result[i] := (Ord(UpCase(hex[1 + i * 2])) - 48) * 16;
+      'A'..'F':
+        Result[i] := (Ord(UpCase(hex[1 + i * 2])) - 55) * 16;
+    end;
+    case UpCase(hex[1 + i * 2 + 1]) of
+      '0'..'9':
+        Result[i] := Result[i] + (Ord(UpCase(hex[1 + i * 2 + 1])) - 48);
+      'A'..'F':
+        Result[i] := Result[i] + (Ord(UpCase(hex[1 + i * 2 + 1])) - 55);
+    end;
+  end;
+end;
+
+
+
+
+function StringSmaller(string1, string2: String): Boolean;
+var
+  i:   Integer;
+  len: Integer;
+begin
+  len := Min(Length(string1), Length(string2));
+  for i := 1 to len do
+    if Ord(string1[i]) <> Ord(string2[i]) then
+    begin
+      Result := Ord(string1[i]) < Ord(string2[i]);
+      Exit;
+    end;
+  Result := Length(string1) < Length(string2);
+end;
+
+
+
+
+function ExportFile(fileid: LongWord; filename: String; settings: TExportSet;
+  path: String): Integer;
+var
+  i: Byte;
+  extension: String;
+  rawlist: TRawList;
+begin
+  Result    := export_noerror;
+  extension := RightStr(filename, 4);
+  if DO_toone in settings then
+  begin
+    ExportDatFile(fileid, path + '\' + GetWinFileName(filename));
+  end
+  else
+  begin
+    if DO_dat in settings then
+      ExportDatFile(fileid, path + '\' + GetWinFileName(filename));
+    if DO_raw in settings then
+    begin
+      rawlist := OniDataConnection.GetRawList(fileid);
+      if Length(rawlist) > 0 then
+      begin
+        for i := 0 to High(rawlist) do
+        begin
+          ExportRawFile(fileid, rawlist[i].src_offset, path + '\' +
+            GetWinFileName(filename));
+        end;
+      end;
+    end;
+  end;
+end;
+
+
+
+
+function Explode(_string: String; delimiter: Char): TStringArray;
+var
+  start, len: Word;
+begin
+  SetLength(Result, 0);
+  start := 1;
+  while PosEx(delimiter, _string, start) > 0 do
+  begin
+    len := PosEx(delimiter, _string, start) - start;
+    SetLength(Result, Length(Result) + 1);
+    Result[High(Result)] := MidStr(_string, start, len);
+    start := start + len + 1;
+  end;
+  SetLength(Result, Length(Result) + 1);
+  Result[High(Result)] := MidStr(_string, start, Length(_string) - start + 1);
+end;
+
+
+
+
+function GetWinFileName(Name: String): String;
+begin
+  Result := Name;
+  Result := AnsiReplaceStr(Result, '\', '__');
+  Result := AnsiReplaceStr(Result, '/', '__');
+  Result := AnsiReplaceStr(Result, '>', '__');
+  Result := AnsiReplaceStr(Result, '<', '__');
+end;
+
+
+
+
+function GetExtractPath: String;
+begin
+  Result := ExtractFilePath(OniDataConnection.FileName) + '\extracted_' +
+    ExtractFileName(OniDataConnection.Filename);
+end;
+
+
+end.
Index: oup/current/Code_OniDataClass.pas
===================================================================
--- oup/current/Code_OniDataClass.pas	(revision 43)
+++ oup/current/Code_OniDataClass.pas	(revision 43)
@@ -0,0 +1,1321 @@
+unit Code_OniDataClass;
+
+interface
+
+uses Data, Code_DataStructures, Classes, SysUtils, StrUtils,
+  Dialogs, ABSDecUtil, ABSMain, DB;
+
+type
+  TOniData = class
+  private
+    FFileName:  String;
+    FLevelInfo: TLevelInfo;
+    FBackend:   Integer;
+    Fos_mac:    Boolean;
+  protected
+  public
+    property FileName: String Read FFileName Write FFileName;
+    property Backend: Integer Read FBackend Write FBackend;
+    property OSisMac: Boolean Read Fos_mac Write Fos_mac;
+    property LevelInfo: TLevelinfo Read FLevelInfo Write FLevelInfo;
+
+    constructor Create(filename: String; var Result: Boolean); virtual; abstract;
+    procedure Close; virtual; abstract;
+
+    function GetFileInfo(fileid: LongWord): TFileInfo; virtual; abstract;
+    function GetFilesList(ext: String; pattern: String;
+      NoEmptyFiles: Boolean): TStringArray; virtual; abstract;
+    function GetFilesCount: LongWord; virtual; abstract;
+    function GetExtensionsList: TStringArray; virtual; abstract;
+    function GetExtendedExtensionsList: TExtensionsMap; virtual; abstract;
+    function ExtractFileID(Name: String): Integer;
+    function GetFileIDByName(Name: String): Integer;
+
+    function LoadDatFile(fileid: LongWord): Tdata; virtual; abstract;
+    procedure UpdateDatFile(fileid: LongWord; Data: Tdata); virtual; abstract;
+    procedure LoadDatFilePart(fileid, offset, size: LongWord; target: Pointer);
+      virtual; abstract;
+    procedure UpdateDatFilePart(fileid, offset, size: LongWord; target: Pointer);
+      virtual; abstract;
+
+    function GetRawList(fileid: LongWord): TRawList; virtual; abstract;
+    function GetRawInfo(fileid, dat_offset: LongWord): TRawInfo;
+    procedure LoadRawFile(fileid, dat_offset: LongWord; target: Pointer);
+      virtual; abstract;
+    procedure UpdateRawFile(fileid, dat_offset: LongWord; size: LongWord; target: Pointer);
+      virtual; abstract;
+    procedure LoadRawFilePart(fileid, dat_offset: LongWord;
+      offset, size: LongWord; target: Pointer); virtual; abstract;
+    procedure UpdateRawFilePart(fileid, dat_offset: LongWord;
+      offset, size: LongWord; target: Pointer); virtual; abstract;
+    function AppendRawFile(loc_sep: Boolean; size: LongWord; target: Pointer): LongWord;
+      virtual; abstract;//Returns new Address
+  published
+  end;
+
+  TOniDataDat = class(TOniData)
+  private
+    Fdat_file:     TFileStream;
+    Fraw_file:     TFileStream;
+    Fsep_file:     TFileStream;
+    Fdat_header:   THeader;
+    Fdat_filesmap: TFilesMap;
+    Fdat_files:    TFiles;
+    Fdat_namedfilesmap: TNamedFilesMap;
+    Fdat_extensionsmap: TExtensionsMap;
+    FUnloadWhenUnused: Boolean;
+    FDatOpened:    Boolean;
+    FRawOpened:    Boolean;
+    FSepOpened:    Boolean;
+  protected
+  public
+    property UnloadWhenUnused: Boolean Read FUnloadWhenUnused Write FUnloadWhenUnused;
+
+    constructor Create(DatFilename: String; var Result: Boolean); override;
+    procedure Close; override;
+
+    function GetFileInfo(fileid: LongWord): TFileInfo; override;
+    function GetFilesList(ext: String; pattern: String;
+      NoEmptyFiles: Boolean): TStringArray; override;
+    function GetFilesCount: LongWord; override;
+    function GetExtensionsList: TStringArray; override;
+    function GetExtendedExtensionsList: TExtensionsMap; override;
+
+    function LoadDatFile(fileid: LongWord): Tdata; override;
+    procedure UpdateDatFile(fileid: LongWord; Data: Tdata); override;
+    procedure LoadDatFilePart(fileid, offset, size: LongWord; target: Pointer); override;
+    procedure UpdateDatFilePart(fileid, offset, size: LongWord; target: Pointer); override;
+
+    procedure LoadRawOffset(loc_sep: Boolean; raw_addr, size: LongWord; target: Pointer);
+    function GetRawList(fileid: LongWord): TRawList; override;
+    procedure LoadRawFile(fileid, dat_offset: LongWord; target: Pointer); override;
+    procedure UpdateRawFile(fileid, dat_offset: LongWord; size: LongWord;
+      target: Pointer); override;
+    procedure LoadRawFilePart(fileid, dat_offset: LongWord;
+      offset, size: LongWord; target: Pointer); override;
+    procedure UpdateRawFilePart(fileid, dat_offset: LongWord;
+      offset, size: LongWord; target: Pointer); override;
+    function AppendRawFile(loc_sep: Boolean; size: LongWord; target: Pointer): LongWord;
+      override;//Returns new Address
+  published
+  end;
+
+  TOniDataADB = class(TOniData)
+  private
+    FDatabase: TABSDatabase;
+    FQuery:    TABSQuery;
+  protected
+  public
+    constructor Create(OLDBFilename: String; var Result: Boolean); override;
+    procedure Close; override;
+
+    //      function GetDatLinks(srcid:LongWord):TDatLinks;
+    function GetFileInfo(fileid: LongWord): TFileInfo; override;
+    function GetFilesList(ext: String; pattern: String;
+      NoEmptyFiles: Boolean): TStringArray; override;
+    function GetFilesCount: LongWord; override;
+    function GetExtensionsList: TStringArray; override;
+    function GetExtendedExtensionsList: TExtensionsMap; override;
+    function GetNamedFilesMap: TNamedFilesMap;
+
+    function LoadDatFile(fileid: LongWord): Tdata; override;
+    procedure UpdateDatFile(fileid: LongWord; Data: Tdata); override;
+    procedure LoadDatFilePart(fileid, offset, size: LongWord; target: Pointer); override;
+    procedure UpdateDatFilePart(fileid, offset, size: LongWord; target: Pointer); override;
+
+    function GetRawList(fileid: LongWord): TRawList; override;
+    procedure LoadRawFile(fileid, dat_offset: LongWord; target: Pointer); override;
+    procedure UpdateRawFile(fileid, dat_offset: LongWord; size: LongWord;
+      target: Pointer); override;
+    procedure LoadRawFilePart(fileid, dat_offset: LongWord;
+      offset, size: LongWord; target: Pointer); override;
+    procedure UpdateRawFilePart(fileid, dat_offset: LongWord;
+      offset, size: LongWord; target: Pointer); override;
+  published
+  end;
+
+
+const
+  ODB_None = -1;
+  ODB_Dat  = 0;
+  ODB_ADB  = 1;
+
+var
+  OniDataConnection: TOniData;
+
+function CreateDataConnection(filename: String; backend: Integer): Boolean;
+procedure CloseDataConnection;
+
+
+
+
+implementation
+
+uses Code_Functions;
+
+
+
+(*
+  Implementation of  TOniData
+*)
+
+function TOniData.GetFileIDByName(Name: String): Integer;
+var
+  files: TStringArray;
+  i:     Integer;
+begin
+  Result := -1;
+  files  := Self.GetFilesList('', Name, False);
+  if Length(files) > 0 then
+    for i := 0 to High(files) do
+      if Pos(Name, files[i]) = Pos('-', files[i]) + 1 then
+      begin
+        //        if MidStr(files[i],Pos('-',files[i])+1,Length(files[i])-Pos('-',files[i])-5)=name then begin
+        Result := Self.ExtractFileID(files[i]);
+        Break;
+      end;
+end;
+
+
+
+
+function TOniData.ExtractFileID(Name: String): Integer;
+begin
+  if Name[5] = '-' then
+    Result := HexToLong(MidStr(Name, 1, 4))
+  else
+    Result := StrToInt(MidStr(Name, 1, 5));
+end;
+
+
+
+
+function TOniData.GetRawInfo(fileid, dat_offset: LongWord): TRawInfo;
+var
+  i: LongWord;
+  raw_list: TRawList;
+begin
+  raw_list      := Self.GetRawList(fileid);
+  Result.src_id := 0;
+  Result.src_offset := 0;
+  Result.raw_addr := 0;
+  Result.raw_size := 0;
+  for i := 0 to High(raw_list) do
+  begin
+    if raw_list[i].src_offset = dat_offset then
+    begin
+      Result.src_id     := fileid;
+      Result.src_offset := raw_list[i].src_offset;
+      Result.raw_addr   := raw_list[i].raw_addr;
+      Result.raw_size   := raw_list[i].raw_size;
+      Result.loc_sep    := raw_list[i].loc_sep;
+      Break;
+    end;
+  end;
+end;
+
+
+
+
+
+
+
+(*
+================================================================================
+                      Implementation of  TOniDataDat
+*)
+
+constructor TOniDataDat.Create(DatFilename: String; var Result: Boolean);
+const
+  header_ident1_pc: array[0..$13] of Byte =
+    ($1F, $27, $DC, $33, $DF, $BC, $03, $00, $31, $33, $52, $56, $40, $00,
+    $14, $00, $10, $00, $08, $00);
+  header_ident1_mac: array[0..$13] of Byte =
+    ($61, $30, $C1, $23, $DF, $BC, $03, $00, $31, $33, $52, $56, $40, $00,
+    $14, $00, $10, $00, $08, $00);
+  header_ident1_macbeta: array[0..$13] of Byte =
+    ($81, $11, $8D, $23, $DF, $BC, $03, $00, $31, $33, $52, $56, $40, $00,
+    $14, $00, $10, $00, $08, $00);
+  header_ident2: array[0..$F] of Byte =
+    ($99, $CF, $40, $00, $90, $4F, $63, $00, $F4, $55, $5F, $00, $90, $4F, $63, $00);
+var
+  i: LongWord;
+  header_pc, header_mac: Boolean;
+begin
+  FUnloadWhenUnused := True;
+  FDatOpened := False;
+  FRawOpened := False;
+  if not FileExists(DatFilename) then
+  begin
+    ShowMessage('File doesn''t exist!!!');
+    Result := False;
+    Exit;
+  end;
+  FFileName := DatFilename;
+  Fdat_file := TFileStream.Create(FFileName, fmOpenRead);
+  Fdat_file.Read(Fdat_header, SizeOf(Fdat_header));
+  header_pc  := True;
+  header_mac := True;
+  for i := 0 to High(Fdat_header.Ident) do
+  begin
+    FLevelInfo.Ident[i] := Fdat_header.Ident[i];
+    if Fdat_header.Ident[i] <> header_ident1_pc[i] then
+      header_pc := False;
+    if Fdat_header.Ident[i] <> header_ident1_mac[i] then
+      header_mac := False;
+  end;
+  if not (header_pc xor header_mac) then
+  begin
+    Result := False;
+    Exit;
+  end
+  else
+  begin
+    if (header_pc and not header_mac) then
+      Fos_mac := False
+    else
+      Fos_mac := True;
+  end;
+  SetLength(Fdat_filesmap, Fdat_header.Files);
+  SetLength(Fdat_files, Fdat_header.Files);
+  for i := 0 to Fdat_header.Files - 1 do
+    Fdat_file.Read(Fdat_filesmap[i], SizeOf(Fdat_filesmap[i]));
+  for i := 0 to Fdat_header.Files - 1 do
+  begin
+    Fdat_files[i].Extension := Fdat_filesmap[i].Extension;
+    Fdat_files[i].Extension := ReverseString(Fdat_files[i].Extension);
+    Fdat_files[i].Size      := Fdat_filesmap[i].FileSize;
+    Fdat_files[i].FileType  := Fdat_filesmap[i].FileType;
+    Fdat_files[i].DatAddr   := Fdat_filesmap[i].DataAddr - 8 + Fdat_header.DataAddr;
+    if (Fdat_filesmap[i].FileType and $01) = 0 then
+    begin
+      Fdat_file.Seek(Fdat_filesmap[i].NameAddr + Fdat_header.NamesAddr, soFromBeginning);
+      SetLength(Fdat_files[i].Name, 100);
+      Fdat_file.Read(Fdat_files[i].Name[1], 100);
+      Fdat_files[i].Name := MidStr(Fdat_files[i].Name, 1 + 4, Pos(
+        #0, Fdat_files[i].Name) - 1 - 4);
+    end
+    else
+    begin
+      Fdat_files[i].Name := '';
+    end;
+    Fdat_files[i].FileName    :=
+      FormatNumber(i, 5, '0') + '-' + Fdat_files[i].Name + '.' + Fdat_files[i].Extension;
+    Fdat_files[i].FileNameHex :=
+      IntToHex(i, 4) + '-' + Fdat_files[i].Name + '.' + Fdat_files[i].Extension;
+  end;
+  Fdat_file.Seek($40 + Fdat_header.Files * $14, soFromBeginning);
+  SetLength(Fdat_namedfilesmap, Fdat_header.NamedFiles);
+  for i := 0 to Fdat_header.NamedFiles - 1 do
+    Fdat_file.Read(Fdat_namedfilesmap[i], SizeOf(Fdat_namedfilesmap[i]));
+
+  Fdat_file.Seek($40 + Fdat_header.Files * $14 + Fdat_header.NamedFiles * $8, soFromBeginning);
+  SetLength(Fdat_extensionsmap, Fdat_header.Extensions);
+  for i := 0 to Fdat_header.Extensions - 1 do
+    Fdat_file.Read(Fdat_extensionsmap[i], SizeOf(Fdat_extensionsmap[i]));
+
+  Fdat_file.Seek(Fdat_files[0].DatAddr + 7, soFromBeginning);
+  Fdat_file.Read(FLevelInfo.LevelNumber, 1);
+  FLevelInfo.LevelNumber := FLevelInfo.LevelNumber div 2;
+
+  Fdat_file.Free;
+
+  Result   := True;
+  FBackend := ODB_Dat;
+end;
+
+
+
+
+procedure TOniDataDat.Close;
+begin
+  if not FUnloadWhenUnused and FDatOpened then
+    Fdat_file.Free;
+  if not FUnloadWhenUnused and FRawOpened then
+    Fraw_file.Free;
+  if not FUnloadWhenUnused and FSepOpened then
+    Fsep_file.Free;
+  Self.Free;
+end;
+
+
+
+
+function TOniDataDat.GetFileInfo(fileid: LongWord): TFileInfo;
+begin
+  if fileid < Self.GetFilesCount then
+    Result    := Fdat_files[fileid]
+  else
+    Result.ID := -1;
+end;
+
+
+
+
+function TOniDataDat.GetFilesList(ext: String; pattern: String;
+  NoEmptyFiles: Boolean): TStringArray;
+var
+  i: LongWord;
+begin
+  SetLength(Result, 0);
+  for i := 0 to Fdat_header.Files - 1 do
+  begin
+    if ((Length(ext) = 0) or (Pos(Fdat_files[i].Extension, ext) > 0)) and
+      ((Length(pattern) = 0) or
+      (Pos(UpperCase(pattern), UpperCase(Fdat_files[i].Name)) > 0)) then
+    begin
+      if (NoEmptyFiles = False) or ((Fdat_files[i].FileType and $02) = 0) then
+      begin
+        SetLength(Result, Length(Result) + 1);
+        if AppSettings.FilenumbersAsHex then
+          Result[High(Result)] := Fdat_files[i].FileNameHex
+        else
+          Result[High(Result)] := Fdat_files[i].FileName;
+      end;
+    end;
+  end;
+end;
+
+
+
+
+function TOniDataDat.GetFilesCount: LongWord;
+begin
+  Result := Fdat_header.Files;
+end;
+
+
+
+
+function TOniDataDat.GetExtensionsList: TStringArray;
+var
+  i: LongWord;
+begin
+  SetLength(Result, Fdat_header.Extensions);
+  for i := 0 to Fdat_header.Extensions - 1 do
+  begin
+    with Fdat_extensionsmap[i] do
+    begin
+      Result[i] := Extension[3] + Extension[2] + Extension[1] + Extension[0] +
+        ' (' + IntToStr(ExtCount) + ')';
+    end;
+  end;
+end;
+
+
+
+
+function TOniDataDat.GetExtendedExtensionsList: TExtensionsMap;
+var
+  i: LongWord;
+begin
+  SetLength(Result, Fdat_header.Extensions);
+  for i := 0 to Fdat_header.Extensions - 1 do
+  begin
+    Result[i] := Fdat_extensionsmap[i];
+  end;
+end;
+
+
+
+
+function TOniDataDat.LoadDatFile(fileid: LongWord): Tdata;
+begin
+  if fileid < Self.GetFilesCount then
+  begin
+    if FUnloadWhenUnused or not FDatOpened then
+      Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
+    Fdat_file.Seek(Fdat_files[fileid].DatAddr, soFromBeginning);
+    SetLength(Result, Fdat_files[fileid].Size);
+    Fdat_file.Read(Result[0], Fdat_files[fileid].Size);
+    if UnloadWhenUnused then
+      Fdat_file.Free
+    else
+      FDatOpened := True;
+  end;
+end;
+
+
+
+
+procedure TOniDataDat.UpdateDatFile(fileid: LongWord; Data: Tdata);
+begin
+  if fileid < Self.GetFilesCount then
+  begin
+    if FUnloadWhenUnused or not FDatOpened then
+      Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
+    Fdat_file.Seek(Fdat_files[fileid].DatAddr, soFromBeginning);
+    Fdat_file.Write(Data[0], Length(Data));
+    if UnloadWhenUnused then
+      Fdat_file.Free
+    else
+      FDatOpened := True;
+  end;
+end;
+
+
+
+
+procedure TOniDataDat.LoadDatFilePart(fileid, offset, size: LongWord; target: Pointer);
+begin
+  if fileid < Self.GetFilesCount then
+  begin
+    if FUnloadWhenUnused or not FDatOpened then
+      Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
+    Fdat_file.Seek(Fdat_files[fileid].DatAddr + offset, soFromBeginning);
+    Fdat_file.Read(target^, size);
+    if UnloadWhenUnused then
+      Fdat_file.Free
+    else
+      FDatOpened := True;
+  end;
+end;
+
+
+
+
+procedure TOniDataDat.UpdateDatFilePart(fileid, offset, size: LongWord; target: Pointer);
+begin
+  if fileid < Self.GetFilesCount then
+  begin
+    if FUnloadWhenUnused or not FDatOpened then
+      Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
+    Fdat_file.Seek(Fdat_files[fileid].DatAddr + offset, soFromBeginning);
+    Fdat_file.Write(target^, size);
+    if UnloadWhenUnused then
+      Fdat_file.Free
+    else
+      FDatOpened := True;
+  end;
+end;
+
+
+
+
+function TOniDataDat.GetRawList(fileid: LongWord): TRawList;
+var
+  i: LongWord;
+begin
+  SetLength(Result, 0);
+  for i := 0 to High(RawListHandlers) do
+    if UpperCase(RawListHandlers[i].Ext) = UpperCase(Fdat_files[fileid].extension) then
+      if RawListHandlers[i].needed then
+      begin
+        Result := RawListHandlers[i].Handler(fileid);
+        Break;
+      end
+      else
+        Break;
+end;
+
+
+
+
+procedure TOniDataDat.LoadRawOffset(loc_sep: Boolean; raw_addr, size: LongWord;
+  target: Pointer);
+begin
+  if not loc_sep then
+  begin
+    if FUnloadWhenUnused or not FRawOpened then
+      Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
+        fmOpenReadWrite);
+    if raw_addr <= Fraw_file.Size then
+    begin
+      Fraw_file.Seek(raw_addr, soFromBeginning);
+      Fraw_file.Read(target^, size);
+    end;
+    if UnloadWhenUnused then
+      Fraw_file.Free
+    else
+      FRawOpened := True;
+  end
+  else
+  begin
+    if FUnloadWhenUnused or not FSepOpened then
+      Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
+        fmOpenReadWrite);
+    if raw_addr <= Fsep_file.Size then
+    begin
+      Fsep_file.Seek(raw_addr, soFromBeginning);
+      Fsep_file.Read(target^, size);
+    end;
+    if UnloadWhenUnused then
+      Fsep_file.Free
+    else
+      FSepOpened := True;
+  end;
+end;
+
+
+
+
+procedure TOniDataDat.LoadRawFile(fileid, dat_offset: LongWord; target: Pointer);
+var
+  raw_info: TRawInfo;
+begin
+  if fileid < Self.GetFilesCount then
+  begin
+    raw_info := Self.GetRawInfo(fileid, dat_offset);
+    if not raw_info.loc_sep then
+    begin
+      if FUnloadWhenUnused or not FRawOpened then
+        Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
+          fmOpenReadWrite);
+      Fraw_file.Seek(raw_info.raw_addr, soFromBeginning);
+      Fraw_file.Read(target^, raw_info.raw_size);
+      if UnloadWhenUnused then
+        Fraw_file.Free
+      else
+        FRawOpened := True;
+    end
+    else
+    begin
+      if FUnloadWhenUnused or not FSepOpened then
+        Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
+          fmOpenReadWrite);
+      Fsep_file.Seek(raw_info.raw_addr, soFromBeginning);
+      Fsep_file.Read(target^, raw_info.raw_size);
+      if UnloadWhenUnused then
+        Fsep_file.Free
+      else
+        FSepOpened := True;
+    end;
+  end;
+end;
+
+
+
+
+procedure TOniDataDat.UpdateRawFile(fileid, dat_offset: LongWord;
+  size: LongWord; target: Pointer);
+var
+  raw_info: TRawInfo;
+begin
+  if fileid < Self.GetFilesCount then
+  begin
+    raw_info := Self.GetRawInfo(fileid, dat_offset);
+    if not raw_info.loc_sep then
+    begin
+      if FUnloadWhenUnused or not FRawOpened then
+        Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
+          fmOpenReadWrite);
+      Fraw_file.Seek(raw_info.raw_addr, soFromBeginning);
+      Fraw_file.Write(target^, raw_info.raw_size);
+      if UnloadWhenUnused then
+        Fraw_file.Free
+      else
+        FRawOpened := True;
+    end
+    else
+    begin
+      if FUnloadWhenUnused or not FSepOpened then
+        Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
+          fmOpenReadWrite);
+      Fsep_file.Seek(raw_info.raw_addr, soFromBeginning);
+      Fsep_file.Write(target^, raw_info.raw_size);
+      if UnloadWhenUnused then
+        Fsep_file.Free
+      else
+        FSepOpened := True;
+    end;
+  end;
+end;
+
+
+
+
+procedure TOniDataDat.LoadRawFilePart(fileid, dat_offset: LongWord;
+  offset, size: LongWord; target: Pointer);
+var
+  raw_info: TRawInfo;
+  Data:     Tdata;
+  mem:      TMemoryStream;
+begin
+  if fileid < Self.GetFilesCount then
+  begin
+    raw_info := Self.GetRawInfo(fileid, dat_offset);
+    SetLength(Data, raw_info.raw_size);
+    Self.LoadRawFile(fileid, dat_offset, @Data[0]);
+    mem := TMemoryStream.Create;
+    mem.Write(Data[offset], size);
+    mem.Read(target^, size);
+    mem.Free;
+  end;
+end;
+
+
+
+
+procedure TOniDataDat.UpdateRawFilePart(fileid, dat_offset: LongWord;
+  offset, size: LongWord; target: Pointer);
+var
+  raw_info: TRawInfo;
+begin
+  if fileid < Self.GetFilesCount then
+  begin
+    raw_info := Self.GetRawInfo(fileid, dat_offset);
+    if not raw_info.loc_sep then
+    begin
+      if FUnloadWhenUnused or not FRawOpened then
+        Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
+          fmOpenReadWrite);
+      Fraw_file.Seek(raw_info.raw_addr + offset, soFromBeginning);
+      Fraw_file.Write(target^, raw_info.raw_size);
+      if UnloadWhenUnused then
+        Fraw_file.Free
+      else
+        FRawOpened := True;
+    end
+    else
+    begin
+      if FUnloadWhenUnused or not FSepOpened then
+        Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
+          fmOpenReadWrite);
+      Fsep_file.Seek(raw_info.raw_addr + offset, soFromBeginning);
+      Fsep_file.Write(target^, raw_info.raw_size);
+      if UnloadWhenUnused then
+        Fsep_file.Free
+      else
+        FSepOpened := True;
+    end;
+  end;
+end;
+
+
+
+
+function TOniDataDat.AppendRawFile(loc_sep: Boolean; size: LongWord;
+  target: Pointer): LongWord; //Returns new Address
+begin
+  if not loc_sep then
+  begin
+    if FUnloadWhenUnused or not FRawOpened then
+      Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
+        fmOpenReadWrite);
+    Result := Fraw_file.Size;
+    Fraw_file.Seek(0, soFromEnd);
+    Fraw_file.Write(target^, size);
+    if UnloadWhenUnused then
+      Fraw_file.Free
+    else
+      FRawOpened := True;
+  end
+  else
+  begin
+    if FUnloadWhenUnused or not FSepOpened then
+      Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
+        fmOpenReadWrite);
+    Result := Fsep_file.Size;
+    Fsep_file.Seek(0, soFromEnd);
+    Fsep_file.Write(target^, size);
+    if UnloadWhenUnused then
+      Fsep_file.Free
+    else
+      FSepOpened := True;
+  end;
+end;
+
+
+
+
+
+
+
+
+
+
+
+(*
+================================================================================
+                     Implementation of  TOniDataADB
+*)
+
+constructor TOniDataADB.Create(OLDBFilename: String; var Result: Boolean);
+var
+  i, j:  Byte;
+  temps: String;
+begin
+  if not FileExists(OLDBFilename) then
+  begin
+    ShowMessage('File doesn''t exist!!!');
+    Result := False;
+    Exit;
+  end;
+  FFileName := OLDBFilename;
+  FDatabase := TABSDatabase.Create(nil);
+  FDatabase.DatabaseName := 'OLDBcon';
+  FDatabase.DatabaseFileName := OLDBFilename;
+  FDatabase.Open;
+  FQuery := TABSQuery.Create(FDatabase);
+  FQuery.DatabaseName := 'OLDBcon';
+  FQuery.SQL.Text := 'SELECT [name],[value] FROM globals ORDER BY [name] ASC';
+  FQuery.Open;
+  FQuery.First;
+  repeat
+    if FQuery.FieldByName('name').AsString = 'dbversion' then
+    begin
+      if FQuery.FieldByName('value').AsString <> DBversion then
+      begin
+        ShowMessage('Database-file ' + #13 + #10 +
+          '"' + OLDBFilename + '"' + #13 + #10 +
+          'has wrong version. (Required: ' + DBversion + '; found: ' +
+          FQuery.FieldByName('value').AsString + ')');
+        FQuery.Close;
+        Result := False;
+        Exit;
+      end;
+    end;
+    if FQuery.FieldByName('name').AsString = 'lvl' then
+    begin
+      FLevelInfo.LevelNumber := StrToInt(FQuery.FieldByName('value').AsString);
+    end;
+    if FQuery.FieldByName('name').AsString = 'ident' then
+    begin
+      temps := FQuery.FieldByName('value').AsString;
+      for i := 0 to High(FLevelInfo.Ident) do
+      begin
+        j := i * 2 + 1;
+        case temps[j] of
+          '0'..'9':
+            FLevelInfo.Ident[i] := Ord(temps[j]) - 48;
+          'A'..'F':
+            FLevelInfo.Ident[i] := Ord(temps[j]) - 55;
+        end;
+        FLevelInfo.Ident[i] := FLevelInfo.Ident[i] * 16;
+        case temps[j + 1] of
+          '0'..'9':
+            FLevelInfo.Ident[i] := FLevelInfo.Ident[i] + Ord(temps[j + 1]) - 48;
+          'A'..'F':
+            FLevelInfo.Ident[i] := FLevelInfo.Ident[i] + Ord(temps[j + 1]) - 55;
+        end;
+      end;
+    end;
+    if FQuery.FieldByName('name').AsString = 'ident' then
+    begin
+      temps   := FQuery.FieldByName('value').AsString;
+      Fos_mac := temps = 'MAC';
+    end;
+    FQuery.Next;
+  until FQuery.EOF;
+  FQuery.Close;
+
+  Result   := True;
+  FBackend := ODB_ADB;
+end;
+
+
+
+
+procedure TOniDataADB.Close;
+begin
+  FDatabase.Close;
+  FDatabase.Free;
+  Self.Free;
+end;
+
+
+
+
+function TOniDataADB.GetFileInfo(fileid: LongWord): TFileInfo;
+begin
+  if fileid < Self.GetFilesCount then
+  begin
+    FQuery.SQL.Text := 'SELECT * FROM datfiles WHERE id=' + IntToStr(
+      fileid) + ' ORDER BY id ASC;';
+    FQuery.Open;
+    if FQuery.RecordCount = 1 then
+    begin
+      FQuery.First;
+      Result.ID      := FQuery.FieldByName('id').AsInteger;
+      Result.Name    := FQuery.FieldByName('name').AsString;
+      Result.Extension := FQuery.FieldByName('extension').AsString;
+      Result.FileName := FormatNumber(Result.ID, 5, '0') + '-' + Result.Name + '.' +
+        Result.Extension;
+      Result.Size    := FQuery.FieldByName('size').AsInteger;
+      Result.FileType := HexToLong(FQuery.FieldByName('contenttype').AsString);
+      Result.DatAddr := 0;
+      Result.opened  := False;
+    end;
+    FQuery.Close;
+  end
+  else
+  begin
+    Result.ID := -1;
+  end;
+end;
+
+
+
+
+function TOniDataADB.GetFilesList(ext: String; pattern: String;
+  NoEmptyFiles: Boolean): TStringArray;
+var
+  i:     LongWord;
+  where: String;
+  where_ext: String;
+begin
+  where := '';
+  if Length(ext) > 0 then
+  begin
+    if Length(where) > 0 then
+      where := where + ' AND ';
+    if Pos(',', ext) > 0 then
+    begin
+      i := 1;
+      where_ext := '';
+      while i < Length(ext) do
+      begin
+        if Length(where_ext) > 0 then
+          where_ext := where_ext + ' OR ';
+        where_ext := where_ext + '(extension="' + MidStr(ext, i, 4) + '")';
+        i := i + 5;
+      end;
+      where := where + '(' + where_ext + ')';
+    end
+    else
+    begin
+      where := where + '(extension="' + ext + '")';
+    end;
+  end;
+  if Length(pattern) > 0 then
+  begin
+    if Length(where) > 0 then
+      where := where + ' AND ';
+    where := where + '(name LIKE "%' + pattern + '%")';
+  end;
+  if NoEmptyFiles then
+  begin
+    if Length(where) > 0 then
+      where := where + ' AND ';
+    where := where + '(contenttype<>2)';
+  end;
+  if Length(where) > 0 then
+    where := ' WHERE ' + where;
+  FQuery.SQL.Text := 'SELECT id,name,extension FROM datfiles' + where + ' ORDER BY id ASC;';
+  FQuery.Open;
+  if FQuery.RecordCount > 0 then
+  begin
+    FQuery.First;
+    SetLength(Result, FQuery.RecordCount);
+    i := 0;
+    repeat
+      Result[i] := FormatNumber(FQuery.FieldByName('id').AsInteger, 5, '0') + '-' +
+        FQuery.FieldByName('name').AsString + '.' + FQuery.FieldByName('extension').AsString;
+      Inc(i);
+      FQuery.Next;
+    until FQuery.EOF;
+  end;
+  FQuery.Close;
+end;
+
+
+
+
+function TOniDataADB.GetFilesCount: LongWord;
+begin
+  FQuery.SQL.Text := 'SELECT Count(*) AS cnumber FROM datfiles;';
+  FQuery.Open;
+  if FQuery.RecordCount > 0 then
+  begin
+    FQuery.First;
+    Result := FQuery.FieldByName('cnumber').AsInteger;
+  end
+  else
+    Result := 0;
+  FQuery.Close;
+end;
+
+
+
+
+function TOniDataADB.GetExtensionsList: TStringArray;
+var
+  i: LongWord;
+begin
+  SetLength(Result, 0);
+  FQuery.SQL.Text :=
+    'SELECT extension,count(extension) AS x FROM datfiles GROUP BY extension ORDER BY extension ASC;';
+  FQuery.Open;
+  if FQuery.RecordCount > 0 then
+  begin
+    SetLength(Result, FQuery.RecordCount);
+    i := 0;
+    repeat
+      Result[i] := FQuery.FieldByName('extension').AsString + ' (' +
+        IntToStr(FQuery.FieldByName('x').AsInteger) + ')';
+      Inc(i);
+      FQuery.Next;
+    until FQuery.EOF;
+  end;
+  FQuery.Close;
+end;
+
+
+
+
+function TOniDataADB.GetExtendedExtensionsList: TExtensionsMap;
+var
+  i, j:  LongWord;
+  temps: String;
+  Data:  Tdata;
+begin
+  SetLength(Result, 0);
+  FQuery.SQL.Text := 'SELECT ext,ident FROM extlist ORDER BY ext ASC;';
+  FQuery.Open;
+  if FQuery.RecordCount > 0 then
+  begin
+    SetLength(Result, FQuery.RecordCount);
+    i := 0;
+    repeat
+      temps := FQuery.FieldByName('ext').AsString;
+      for j := 0 to 3 do
+        Result[i].Extension[j] := temps[4 - j];
+      Data := DecodeHexString(FQuery.FieldByName('ident').AsString);
+      for j := 0 to 7 do
+        Result[i].Ident[j] := Data[j];
+      Inc(i);
+      FQuery.Next;
+    until FQuery.EOF;
+  end;
+  FQuery.Close;
+end;
+
+
+
+
+function TOniDataADB.GetNamedFilesMap: TNamedFilesMap;
+var
+  i:     LongWord;
+  temp:  Integer;
+  temps: String;
+  temparray: array of record
+    id: Integer;
+    fullname: String[50];
+  end;
+begin
+  SetLength(temparray, 0);
+  FQuery.SQL.Text :=
+    'SELECT id,(extension+name) AS xname FROM datfiles WHERE Length(name)>0 ORDER BY extension,name ASC;';
+  FQuery.Open;
+  if FQuery.RecordCount > 0 then
+  begin
+    repeat
+      temp  := FQuery.FieldByName('id').AsInteger;
+      temps := FQuery.FieldByName('xname').AsString;
+
+      SetLength(temparray, Length(temparray) + 1);
+      if Length(temparray) > 1 then
+      begin
+        for i := High(temparray) - 1 downto 0 do
+        begin
+          if StringSmaller(temps, temparray[i].fullname) then
+          begin
+            temparray[i + 1] := temparray[i];
+            if i = 0 then
+            begin
+              temparray[i].id := temp;
+              temparray[i].fullname := temps;
+            end;
+          end
+          else
+          begin
+            temparray[i + 1].id := temp;
+            temparray[i + 1].fullname := temps;
+            Break;
+          end;
+        end;
+      end
+      else
+      begin
+        temparray[0].id := temp;
+        temparray[0].fullname := temps;
+      end;
+      FQuery.Next;
+    until FQuery.EOF;
+  end;
+  FQuery.Close;
+  SetLength(Result, Length(temparray));
+  for i := 0 to High(temparray) do
+  begin
+    Result[i].FileNumber := temparray[i].id;
+    Result[i].blubb      := 0;
+  end;
+end;
+
+
+
+
+function TOniDataADB.LoadDatFile(fileid: LongWord): Tdata;
+var
+  mem: TStream;
+begin
+  if fileid < Self.GetFilesCount then
+  begin
+    FQuery.SQL.Text := 'SELECT data FROM datfiles WHERE id=' + IntToStr(fileid) + ';';
+    FQuery.Open;
+    if FQuery.RecordCount > 0 then
+    begin
+      mem := FQuery.CreateBlobStream(FQuery.FieldByName('data'), bmRead);
+      SetLength(Result, mem.Size);
+      mem.Seek(0, soFromBeginning);
+      mem.Read(Result[0], mem.Size);
+      mem.Free;
+    end;
+    FQuery.Close;
+  end;
+end;
+
+
+
+
+procedure TOniDataADB.UpdateDatFile(fileid: LongWord; Data: Tdata);
+var
+  MimeCoder: TStringFormat_MIME64;
+  mem: TMemoryStream;
+begin
+  if fileid < Self.GetFilesCount then
+  begin
+    mimecoder := TStringFormat_MIME64.Create;
+    mem := TMemoryStream.Create;
+    mem.Write(Data[0], Length(Data));
+    mem.Seek(0, soFromBeginning);
+    FQuery.SQL.Text := 'UPDATE datfiles SET data=MimeToBin("' +
+      MimeCoder.StrTo(mem.Memory, mem.Size) + '") WHERE id=' + IntToStr(fileid) + ';';
+    FQuery.ExecSQL;
+    mem.Free;
+    mimecoder.Free;
+  end;
+end;
+
+
+
+
+procedure TOniDataADB.LoadDatFilePart(fileid, offset, size: LongWord; target: Pointer);
+var
+  mem: TStream;
+begin
+  if fileid < Self.GetFilesCount then
+  begin
+    FQuery.SQL.Text := 'SELECT data FROM datfiles WHERE id=' + IntToStr(fileid) + ';';
+    FQuery.Open;
+    if FQuery.RecordCount > 0 then
+    begin
+      mem := FQuery.CreateBlobStream(FQuery.FieldByName('data'), bmRead);
+      mem.Seek(offset, soFromBeginning);
+      mem.Read(target^, size);
+      mem.Free;
+    end;
+    FQuery.Close;
+  end;
+end;
+
+
+
+
+procedure TOniDataADB.UpdateDatFilePart(fileid, offset, size: LongWord; target: Pointer);
+var
+  MimeCoder: TStringFormat_MIME64;
+  mem:  TMemoryStream;
+  Data: Tdata;
+begin
+  if fileid < Self.GetFilesCount then
+  begin
+    Data := Self.LoadDatFile(fileid);
+    mimecoder := TStringFormat_MIME64.Create;
+    mem := TMemoryStream.Create;
+    mem.Write(Data[0], Length(Data));
+    mem.Seek(offset, soFromBeginning);
+    mem.Write(target^, size);
+    mem.Seek(0, soFromBeginning);
+    FQuery.SQL.Text := 'UPDATE datfiles SET data=MimeToBin("' +
+      MimeCoder.StrTo(mem.Memory, mem.Size) + '") WHERE id=' + IntToStr(fileid) + ';';
+    FQuery.ExecSQL;
+    mem.Free;
+    mimecoder.Free;
+  end;
+end;
+
+
+
+
+function TOniDataADB.GetRawList(fileid: LongWord): TRawList;
+var
+  i: LongWord;
+begin
+  SetLength(Result, 0);
+  FQuery.SQL.Text := 'SELECT [src_link_offset],[size],[sep] FROM rawmap WHERE [src_id]=' +
+    IntToStr(fileid) + ' ORDER BY src_link_offset ASC;';
+  FQuery.Open;
+  if FQuery.RecordCount > 0 then
+  begin
+    FQuery.First;
+    SetLength(Result, FQuery.RecordCount);
+    i := 0;
+    repeat
+      Result[i].src_id     := fileid;
+      Result[i].src_offset := FQuery.FieldByName('src_link_offset').AsInteger;
+      Result[i].raw_addr   := 0;
+      Result[i].raw_size   := FQuery.FieldByName('size').AsInteger;
+      Result[i].loc_sep    := FQuery.FieldByName('sep').AsBoolean;
+      Inc(i);
+      FQuery.Next;
+    until FQuery.EOF;
+  end;
+  FQuery.Close;
+end;
+
+
+
+
+procedure TOniDataADB.LoadRawFile(fileid, dat_offset: LongWord; target: Pointer);
+var
+  mem: TStream;
+begin
+  if fileid < Self.GetFilesCount then
+  begin
+    FQuery.SQL.Text := 'SELECT data FROM rawmap WHERE (src_id=' +
+      IntToStr(fileid) + ') AND (src_link_offset=' + IntToStr(dat_offset) + ');';
+    FQuery.Open;
+    if FQuery.RecordCount > 0 then
+    begin
+      mem := FQuery.CreateBlobStream(FQuery.FieldByName('data'), bmRead);
+      mem.Seek(0, soFromBeginning);
+      mem.Read(target^, mem.size);
+      mem.Free;
+    end;
+    FQuery.Close;
+  end;
+end;
+
+
+
+
+procedure TOniDataADB.UpdateRawFile(fileid, dat_offset: LongWord;
+  size: LongWord; target: Pointer);
+var
+  MimeCoder: TStringFormat_MIME64;
+  mem: TMemoryStream;
+begin
+  if fileid < Self.GetFilesCount then
+  begin
+    mimecoder := TStringFormat_MIME64.Create;
+    mem := TMemoryStream.Create;
+    mem.Write(target^, size);
+    mem.Seek(0, soFromBeginning);
+    FQuery.SQL.Text := 'UPDATE rawmap SET data=MimeToBin("' + MimeCoder.StrTo(
+      mem.Memory, mem.Size) + '") WHERE (src_id=' + IntToStr(fileid) +
+      ') AND (src_link_offset=' + IntToStr(dat_offset) + ');';
+    FQuery.ExecSQL;
+    mem.Free;
+    mimecoder.Free;
+  end;
+end;
+
+
+
+
+procedure TOniDataADB.LoadRawFilePart(fileid, dat_offset: LongWord;
+  offset, size: LongWord; target: Pointer);
+var
+  Data: Tdata;
+  mem:  TMemoryStream;
+begin
+  if fileid < Self.GetFilesCount then
+  begin
+    SetLength(Data, Self.GetRawInfo(fileid, dat_offset).raw_size);
+    Self.LoadRawFile(fileid, dat_offset, @Data[0]);
+    mem := TMemoryStream.Create;
+    mem.Write(Data[offset], size);
+    mem.Read(target^, size);
+    mem.Free;
+  end;
+end;
+
+
+
+
+procedure TOniDataADB.UpdateRawFilePart(fileid, dat_offset: LongWord;
+  offset, size: LongWord; target: Pointer);
+var
+  MimeCoder: TStringFormat_MIME64;
+  mem:  TMemoryStream;
+  Data: Tdata;
+begin
+  if fileid < Self.GetFilesCount then
+  begin
+    SetLength(Data, Self.GetRawInfo(fileid, offset).raw_size);
+    Self.LoadRawFile(fileid, offset, @Data[0]);
+    mimecoder := TStringFormat_MIME64.Create;
+    mem := TMemoryStream.Create;
+    mem.Write(Data[0], Length(Data));
+    mem.Seek(offset, soFromBeginning);
+    mem.Write(target^, size);
+    mem.Seek(0, soFromBeginning);
+    FQuery.SQL.Text := 'UPDATE rawmap SET data=MimeToBin("' + MimeCoder.StrTo(
+      mem.Memory, mem.Size) + '") WHERE (src_id=' + IntToStr(fileid) +
+      ') AND (src_link_offset=' + IntToStr(dat_offset) + ');';
+    FQuery.ExecSQL;
+    mem.Free;
+    mimecoder.Free;
+  end;
+end;
+
+
+
+
+
+
+
+
+
+
+
+function CreateDataConnection(filename: String; backend: Integer): Boolean;
+var
+  answer: Boolean;
+begin
+  if Assigned(OniDataConnection) then
+  begin
+    OniDataConnection.Close;
+    OniDataConnection.Free;
+    OniDataConnection := nil;
+  end;
+  case backend of
+    ODB_Dat:
+      OniDataConnection := TOniDataDat.Create(filename, answer);
+    ODB_ADB:
+      OniDataConnection := TOniDataADB.Create(filename, answer);
+    else
+      ShowMessage('Unknown Backend');
+      Result := False;
+      Exit;
+  end;
+
+  if answer then
+  begin
+    //      ShowMessage('file loaded');
+    //      ShowMessage('Files: '+IntToStr(OniDataConnection.GetFilesCount));
+    Result := True;
+  end
+  else
+  begin
+    ShowMessage('File not loaded');
+    OniDataConnection.Close;
+    OniDataConnection.Free;
+    Result := False;
+  end;
+end;
+
+
+
+
+procedure CloseDataConnection;
+begin
+  if Assigned(OniDataConnection) then
+  begin
+    OniDataConnection.Close;
+    OniDataConnection := nil;
+  end;
+end;
+
+end.
Index: oup/current/Code_OniImgClass.pas
===================================================================
--- oup/current/Code_OniImgClass.pas	(revision 43)
+++ oup/current/Code_OniImgClass.pas	(revision 43)
@@ -0,0 +1,827 @@
+unit Code_OniImgClass;
+
+interface
+
+uses Math, Dialogs, Types, SysUtils, Classes, Data, Code_OniDataClass;
+
+type
+  TImgDataType = set of (DT_OniReverted, DT_Oni, DT_Decoded32);
+
+type
+  TOniImage = class
+  private
+    FLoaded:    Boolean;
+    FDataType:  TImgDataType;
+    FData:      Tdata;
+    FWidth, FHeight: Word;
+    FDepth:     Byte;
+    FStoreType: Byte;
+
+    function ResizeImage(oldx, oldy: LongWord; img: Tdata): Tdata;
+    procedure RevertImage;
+    procedure DecodeImage;
+    procedure DecompressImage;
+  protected
+  public
+    property Loaded: Boolean Read FLoaded Write FLoaded;
+    property DataType: TImgDataType Read FDataType Write FDataType;
+    property Width: Word Read FWidth Write FWidth;
+    property Height: Word Read FHeight Write FHeight;
+    property Depth: Byte Read FDepth Write FDepth;
+    property StoreType: Byte Read FStoreType Write FStoreType;
+    property Data: Tdata Read FData Write FData;
+
+    constructor Create;
+    function Load(fileid: LongWord): Boolean;
+    function LoadFromPSpc(fileid: LongWord): Boolean;
+    function LoadFromTXMP(fileid: LongWord): Boolean;
+    function LoadFromTXMB(fileid: LongWord): Boolean;
+    function GetImageDataSize(fading: Boolean): LongWord;
+
+    function GetAsData: Tdata;
+    function GetAs32bit: Tdata;
+    function GetAsBMP: Tdata;
+    function LoadFromBMP(filename: String): Boolean;
+    function WriteToBMP(filename: String): Boolean;
+    function GetMipMappedImage(var faded: Tdata): Boolean;
+  published
+  end;
+
+
+implementation
+
+uses Code_Functions;
+
+
+
+
+constructor TOniImage.Create;
+begin
+  Self.FLoaded   := False;
+  Self.FDataType := [];
+  SetLength(Self.FData, 0);
+  Self.FWidth     := 0;
+  Self.FHeight    := 0;
+  Self.FDepth     := 0;
+  Self.FStoreType := 0;
+end;
+
+
+
+
+function TOniImage.ResizeImage(oldx, oldy: LongWord; img: Tdata): Tdata;
+var
+  i, j: LongWord;
+  col, row, row_orig: LongWord;
+begin
+  SetLength(Result, (oldx div 2) * (oldy div 2) * (Self.FDepth div 8));
+  row_orig := 0;
+  row      := 0;
+  col      := 0;
+  for i := 0 to (oldx * oldy) - 1 do
+  begin
+    if ((i mod oldx) = 0) and (i > 0) then
+    begin
+      Inc(row_orig);
+      if (row_orig mod 2) = 0 then
+      begin
+        Inc(row);
+        col := 0;
+      end;
+    end;
+    if (row_orig mod 2) = 0 then
+    begin
+      if (i mod 2) = 0 then
+      begin
+        for j := 0 to (Self.FDepth div 8) - 1 do
+          Result[((row * (oldx div 2)) + col) * (Self.FDepth div 8) + j] :=
+            img[(i * (Self.FDepth div 8)) + j];
+        Inc(col);
+      end;
+    end;
+  end;
+end;
+
+
+
+
+procedure TOniImage.RevertImage;
+var
+  x, y, i: LongWord;
+  tempd:   Tdata;
+begin
+  SetLength(tempd, Self.FWidth * Self.FHeight * (Self.FDepth div 8));
+  for y := 0 to Self.FHeight - 1 do
+    for x := 0 to Self.FWidth - 1 do
+      for i := 0 to (Self.FDepth div 8) - 1 do
+        tempd[((Self.FWidth * (Self.FHeight - 1 - y) + x) * (Self.FDepth div 8)) + i] :=
+          Self.FData[(Self.FWidth * y + x) * (Self.FDepth div 8) + i];
+  for x := 0 to High(tempd) do
+    Self.FData[x] := tempd[x];
+  if DT_OniReverted in Self.FDataType then
+    Self.FDataType := Self.FDataType - [DT_OniReverted]
+  else
+    Self.FDataType := Self.FDataType + [DT_OniReverted];
+end;
+
+
+
+
+procedure TOniImage.DecodeImage;
+var
+  x, y:  LongWord;
+  tempd: Tdata;
+begin
+  if not (DT_Decoded32 in Self.FDataType) then
+  begin
+    SetLength(tempd, Self.FWidth * Self.FHeight * 4);
+    case Self.FStoreType of
+      0:
+      begin
+        for y := 0 to Self.FHeight - 1 do
+        begin
+          for x := 0 to Self.FWidth - 1 do
+          begin
+            tempd[((Self.FWidth * y + x) * 4) + 0] :=
+              Floor(((Self.FData[(Self.FWidth * y + x) * 2] + Self.FData[(Self.FWidth * y + x) * 2 + 1] * 256) and
+              $000F) / $000F * 255);
+            tempd[((Self.FWidth * y + x) * 4) + 1] :=
+              Floor(((Self.FData[(Self.FWidth * y + x) * 2] + Self.FData[(Self.FWidth * y + x) * 2 + 1] * 256) and
+              $00F0) / $00F0 * 255);
+            tempd[((Self.FWidth * y + x) * 4) + 2] :=
+              Floor(((Self.FData[(Self.FWidth * y + x) * 2] + Self.FData[(Self.FWidth * y + x) * 2 + 1] * 256) and
+              $0F00) / $0F00 * 255);
+            tempd[((Self.FWidth * y + x) * 4) + 3] := 0;
+          end;
+        end;
+      end;
+      1, 2:
+      begin
+        for y := 0 to Self.FHeight - 1 do
+        begin
+          for x := 0 to Self.FWidth - 1 do
+          begin
+            tempd[((Self.FWidth * y + x) * 4) + 0] :=
+              Floor(((Self.FData[(Self.FWidth * y + x) * 2] + Self.FData[(Self.FWidth * y + x) * 2 + 1] * 256) and
+              $001F) / $001F * 255);
+            tempd[((Self.FWidth * y + x) * 4) + 1] :=
+              Floor(((Self.FData[(Self.FWidth * y + x) * 2] + Self.FData[(Self.FWidth * y + x) * 2 + 1] * 256) and
+              $03E0) / $03E0 * 255);
+            tempd[((Self.FWidth * y + x) * 4) + 2] :=
+              Floor(((Self.FData[(Self.FWidth * y + x) * 2] + Self.FData[(Self.FWidth * y + x) * 2 + 1] * 256) and
+              $7C00) / $7C00 * 255);
+            tempd[((Self.FWidth * y + x) * 4) + 3] := 0;
+          end;
+        end;
+      end;
+      9:
+      begin
+        DecompressImage;
+      end;
+    end;
+    Self.FDepth := 32;
+    if (Self.FStoreType <> 9) and (Self.FStoreType <> 8) then
+    begin
+      SetLength(Self.FData, Length(tempd));
+      for x := 0 to High(tempd) do
+        Self.FData[x] := tempd[x];
+    end;
+    Self.FStoreType := 8;
+    if DT_Oni in Self.FDataType then
+      Self.FDataType := Self.FDataType - [DT_Oni];
+    Self.FDataType := Self.FDataType + [DT_Decoded32];
+  end;
+  if DT_OniReverted in Self.FDataType then
+    Self.RevertImage;
+end;
+
+
+
+
+procedure TOniImage.DecompressImage;
+type
+  Tcolor = record
+    RGBb: Byte;
+    RGBg: Byte;
+    RGBr: Byte;
+    RGBa: Byte;
+  end;
+var
+  i, j, x, y: LongWord;
+  color:      array[1..4] of Tcolor;
+  pixel:      array[1..16] of Byte;
+  tempd:      Tdata;
+begin
+  x := 0;
+  y := 0;
+  SetLength(tempd, Self.FWidth * Self.FHeight * 4);
+  for i := 0 to ((Self.FWidth * Self.FHeight) div 16) - 1 do
+  begin
+    Color[1].RGBb := Floor(((Self.FData[(i * 8) + 0] + Self.FData[(i * 8) + 1] * 256) and $001F) /
+      $001F * 255);
+    Color[1].RGBg := Floor(((Self.FData[(i * 8) + 0] + Self.FData[(i * 8) + 1] * 256) and $07E0) /
+      $07E0 * 255);
+    Color[1].RGBr := Floor(((Self.FData[(i * 8) + 0] + Self.FData[(i * 8) + 1] * 256) and $F800) /
+      $F800 * 255);
+    Color[1].RGBa := 255;
+    Color[2].RGBb := Floor(((Self.FData[(i * 8) + 2] + Self.FData[(i * 8) + 3] * 256) and $001F) /
+      $001F * 255);
+    Color[2].RGBg := Floor(((Self.FData[(i * 8) + 2] + Self.FData[(i * 8) + 3] * 256) and $07E0) /
+      $07E0 * 255);
+    Color[2].RGBr := Floor(((Self.FData[(i * 8) + 2] + Self.FData[(i * 8) + 3] * 256) and $F800) /
+      $F800 * 255);
+    Color[2].RGBa := 255;
+    Color[3].RGBb := Floor(Color[1].RGBb / 3 * 2 + Color[2].RGBb / 3);
+    Color[3].RGBg := Floor(Color[1].RGBg / 3 * 2 + Color[2].RGBg / 3);
+    Color[3].RGBr := Floor(Color[1].RGBr / 3 * 2 + Color[2].RGBr / 3);
+    Color[3].RGBa := 255;
+    Color[4].RGBb := Floor(Color[1].RGBb / 3 + Color[2].RGBb / 3 * 2);
+    Color[4].RGBg := Floor(Color[1].RGBg / 3 + Color[2].RGBg / 3 * 2);
+    Color[4].RGBr := Floor(Color[1].RGBr / 3 + Color[2].RGBr / 3 * 2);
+    Color[4].RGBa := 255;
+    Pixel[1]      := Floor((Self.FData[(i * 8) + 4] and $C0) / $40 + 1);
+    Pixel[2]      := Floor((Self.FData[(i * 8) + 4] and $30) / $10 + 1);
+    Pixel[3]      := Floor((Self.FData[(i * 8) + 4] and $0C) / $04 + 1);
+    Pixel[4]      := Floor((Self.FData[(i * 8) + 4] and $03) + 1);
+    Pixel[5]      := Floor((Self.FData[(i * 8) + 5] and $C0) / $40 + 1);
+    Pixel[6]      := Floor((Self.FData[(i * 8) + 5] and $30) / $10 + 1);
+    Pixel[7]      := Floor((Self.FData[(i * 8) + 5] and $0C) / $04 + 1);
+    Pixel[8]      := Floor((Self.FData[(i * 8) + 5] and $03) + 1);
+    Pixel[9]      := Floor((Self.FData[(i * 8) + 6] and $C0) / $40 + 1);
+    Pixel[10]     := Floor((Self.FData[(i * 8) + 6] and $30) / $10 + 1);
+    Pixel[11]     := Floor((Self.FData[(i * 8) + 6] and $0C) / $04 + 1);
+    Pixel[12]     := Floor((Self.FData[(i * 8) + 6] and $03) + 1);
+    Pixel[13]     := Floor((Self.FData[(i * 8) + 7] and $C0) / $40 + 1);
+    Pixel[14]     := Floor((Self.FData[(i * 8) + 7] and $30) / $10 + 1);
+    Pixel[15]     := Floor((Self.FData[(i * 8) + 7] and $0C) / $04 + 1);
+    Pixel[16]     := Floor((Self.FData[(i * 8) + 7] and $03) + 1);
+    for j := 0 to 3 do
+    begin
+      tempd[((y + 3) * Self.FWidth + x + j) * 4 + 0] := Color[Pixel[16 - j]].RGBb;
+      tempd[((y + 3) * Self.FWidth + x + j) * 4 + 1] := Color[Pixel[16 - j]].RGBg;
+      tempd[((y + 3) * Self.FWidth + x + j) * 4 + 2] := Color[Pixel[16 - j]].RGBr;
+      tempd[((y + 3) * Self.FWidth + x + j) * 4 + 3] := 0;
+    end;
+    for j := 0 to 3 do
+    begin
+      tempd[((y + 2) * Self.FWidth + x + j) * 4 + 0] := Color[Pixel[12 - j]].RGBb;
+      tempd[((y + 2) * Self.FWidth + x + j) * 4 + 1] := Color[Pixel[12 - j]].RGBg;
+      tempd[((y + 2) * Self.FWidth + x + j) * 4 + 2] := Color[Pixel[12 - j]].RGBr;
+      tempd[((y + 2) * Self.FWidth + x + j) * 4 + 3] := 0;
+    end;
+    for j := 0 to 3 do
+    begin
+      tempd[((y + 1) * Self.FWidth + x + j) * 4 + 0] := Color[Pixel[8 - j]].RGBb;
+      tempd[((y + 1) * Self.FWidth + x + j) * 4 + 1] := Color[Pixel[8 - j]].RGBg;
+      tempd[((y + 1) * Self.FWidth + x + j) * 4 + 2] := Color[Pixel[8 - j]].RGBr;
+      tempd[((y + 1) * Self.FWidth + x + j) * 4 + 3] := 0;
+    end;
+    for j := 0 to 3 do
+    begin
+      tempd[((y + 0) * Self.FWidth + x + j) * 4 + 0] := Color[Pixel[4 - j]].RGBb;
+      tempd[((y + 0) * Self.FWidth + x + j) * 4 + 1] := Color[Pixel[4 - j]].RGBg;
+      tempd[((y + 0) * Self.FWidth + x + j) * 4 + 2] := Color[Pixel[4 - j]].RGBr;
+      tempd[((y + 0) * Self.FWidth + x + j) * 4 + 3] := 0;
+    end;
+    x := x + 4;
+    if x = Self.FWidth then
+    begin
+      y := y + 4;
+      x := 0;
+    end;
+  end;
+  SetLength(Self.FData, Length(tempd));
+  for i := 0 to High(tempd) do
+    Self.FData[i] := tempd[i];
+  Self.FStoreType := 8;
+  Self.FDepth    := 32;
+  Self.FDataType := Self.FDataType - [DT_Oni] + [DT_Decoded32];
+end;
+
+
+
+
+
+function TOniImage.Load(fileid: LongWord): Boolean;
+var
+  FileInfo: TFileInfo;
+  ext:      String;
+begin
+  FileInfo := OniDataConnection.GetFileInfo(fileid);
+  if FileInfo.Extension = 'PSpc' then
+    Result := LoadFromPSpc(fileid)
+  else if FileInfo.Extension = 'TXMB' then
+    Result := LoadFromTXMB(fileid)
+  else if FileInfo.Extension = 'TXMP' then
+    Result := LoadFromTXMP(fileid)
+  else
+    Result := False;
+end;
+
+
+
+
+function TOniImage.LoadFromPSpc(fileid: LongWord): Boolean;
+type
+  TPoint = packed record
+    X, Y: Word;
+  end;
+
+  TPSpc = packed record
+    p1:   array[0..8] of TPoint;
+    p2:   array[0..8] of TPoint;
+    TXMP: LongWord;
+  end;
+
+  TPart = packed record
+    x_txmp, y_txmp: Word;
+    x_pspc, y_pspc: Word;
+    w, h:    Word;
+    imgdata: Tdata;
+    used:    Boolean;
+  end;
+const
+  PartMatch: array[0..8] of Byte = (0, 3, 6, 1, 4, 7, 2, 5, 8);
+var
+  x, y, pixel: Word;
+  i: Integer;
+
+  PSpc:     TPSpc;
+  txmpimg:  TOniImage;
+  txmpdata: Tdata;
+
+  parts:    array[0..8] of TPart;
+  part:     Byte;
+  cols:     array[0..2] of Word;
+  rows:     array[0..2] of Word;
+  col, row: Byte;
+begin
+  OniDataConnection.LoadDatFilePart(fileid, $08, SizeOf(PSpc), @PSpc);
+  PSpc.TXMP := PSpc.TXMP div 256;
+  if PSpc.TXMP = 0 then
+  begin
+    Result := False;
+    Exit;
+  end;
+  txmpimg := TOniImage.Create;
+  txmpimg.LoadFromTXMP(PSpc.TXMP);
+  txmpimg.DecodeImage;
+  txmpimg.WriteToBMP('C:\file.bmp');
+  txmpdata := txmpimg.GetAs32bit;
+{    ShowMessage(IntToStr(txmpimg.Width)+'x'+IntToStr(txmpimg.Height));
+    for i:=0 to High(txmpdata) do
+      txmpimg.Data[i]:=txmpdata[i];
+    txmpimg.WriteToBMP('D:\file2.bmp');
+}
+  with PSpc do
+  begin
+    for i := 0 to 2 do
+    begin
+      cols[i] := 0;
+      rows[i] := 0;
+    end;
+    for i := 0 to 8 do
+    begin
+      part := PartMatch[i];
+      col  := i div 3;
+      row  := i mod 3;
+      if (p2[i].X > 0) or (p2[i].Y > 0) then
+      begin
+        parts[part].x_txmp := p1[i].X - 1;
+        parts[part].y_txmp := p1[i].Y - 1;
+        parts[part].x_pspc := 0;
+        if col > 0 then
+          for x := 0 to col - 1 do
+            Inc(parts[part].x_pspc, cols[x]);
+        parts[part].y_pspc := 0;
+        if row > 0 then
+          for y := 0 to row - 1 do
+            Inc(parts[part].y_pspc, rows[y]);
+        parts[part].w := p2[i].X - p1[i].X + 1;
+        parts[part].h := p2[i].Y - p1[i].Y + 1;
+        parts[part].used := True;
+        cols[col] := parts[part].w;
+        rows[row] := parts[part].h;
+        SetLength(parts[part].imgdata, parts[part].w * parts[part].h * 4);
+        for y := 0 to parts[part].h - 1 do
+        begin
+          for x := 0 to parts[part].w - 1 do
+          begin
+            for pixel := 0 to 3 do
+            begin
+              parts[part].imgdata[(y * parts[part].w + x) * 4 + pixel] :=
+                txmpdata[((parts[part].y_txmp + y) * txmpimg.Width +
+                parts[part].x_txmp + x) * 4 + pixel];
+            end;
+          end;
+        end;
+      end
+      else
+      begin
+        parts[part].used := False;
+      end;
+    end;
+
+  end;
+
+  txmpimg.Free;
+  txmpimg := TOniImage.Create;
+  for i := 0 to 8 do
+  begin
+    if parts[i].used then
+    begin
+      SetLength(txmpimg.FData, Length(parts[i].imgdata));
+      for pixel := 0 to High(parts[i].imgdata) do
+        txmpimg.Data[pixel] := parts[i].imgdata[pixel];
+      txmpimg.Width := parts[i].w;
+      txmpimg.Height    := parts[i].h;
+      txmpimg.StoreType := 8;
+      txmpimg.DataType  := [DT_Decoded32];
+      txmpimg.Depth     := 32;
+      txmpimg.WriteToBMP('D:\' + IntToStr(i) + '.bmp');
+    end;
+  end;
+  txmpimg.Free;
+
+  Self.FWidth  := 0;
+  Self.FHeight := 0;
+  for i := 0 to 2 do
+  begin
+    Inc(Self.FWidth, cols[i]);
+    Inc(Self.FHeight, rows[i]);
+  end;
+  SetLength(Self.FData, Self.FWidth * Self.FHeight * 4);
+
+  //Combine data parts
+
+  Self.FDepth     := 32;
+  Self.FStoreType := 8;
+  Self.FDataType  := [DT_Decoded32];
+  //    Self.RevertImage;
+end;
+
+
+
+
+function TOniImage.LoadFromTXMP(fileid: LongWord): Boolean;
+var
+  img_addr: LongWord;
+begin
+  Result := True;
+  OniDataConnection.LoadDatFilePart(fileid, $8C, SizeOf(Self.FWidth), @Self.FWidth);
+  OniDataConnection.LoadDatFilePart(fileid, $8E, SizeOf(Self.FHeight), @Self.FHeight);
+  OniDataConnection.LoadDatFilePart(fileid, $90, SizeOf(Self.FStoreType),
+    @Self.FStoreType);
+  if not OniDataConnection.OSisMac then
+    OniDataConnection.LoadDatFilePart(fileid, $9C, SizeOf(img_addr), @img_addr)
+  else
+    OniDataConnection.LoadDatFilePart(fileid, $A0, SizeOf(img_addr), @img_addr);
+
+  case Self.FStoreType of
+    0, 1, 2:
+    begin
+      SetLength(Self.FData, Self.FWidth * Self.FHeight * 2);
+      Self.FDepth := 16;
+    end;
+    8:
+    begin
+      SetLength(Self.FData, Self.FWidth * Self.FHeight * 4);
+      Self.FDepth := 32;
+    end;
+    9:
+    begin
+      SetLength(Self.FData, Self.FWidth * Self.FHeight div 2);
+      Self.FDepth := 16;
+    end;
+    else
+      Result := False;
+      Exit;
+  end;
+
+  if not OniDataConnection.OSisMac then
+    OniDataConnection.LoadRawFile(fileid, $9C, @Self.FData[0])
+  else
+    OniDataConnection.LoadRawFile(fileid, $A0, @Self.FData[0]);
+
+  Self.FDataType := [DT_OniReverted, DT_Oni];
+end;
+
+
+
+
+function TOniImage.LoadFromTXMB(fileid: LongWord): Boolean;
+var
+  i, x, y, x2, y2, pixelid, imgid: LongWord;
+  rows, cols: Word;
+  linkcount: LongWord;
+  link: LongWord;
+  images_decoded: array of TOniImage;
+  x_start, y_start: LongWord;
+begin
+  OniDataConnection.LoadDatFilePart(fileid, $10, SizeOf(Self.FWidth), @Self.FWidth);
+  OniDataConnection.LoadDatFilePart(fileid, $12, SizeOf(Self.FHeight), @Self.FHeight);
+  OniDataConnection.LoadDatFilePart(fileid, $18, SizeOf(cols), @cols);
+  OniDataConnection.LoadDatFilePart(fileid, $1A, SizeOf(rows), @rows);
+  OniDataConnection.LoadDatFilePart(fileid, $1C, SizeOf(linkcount), @linkcount);
+  SetLength(images_decoded, linkcount);
+  for i := 0 to linkcount - 1 do
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $20 + i * 4, SizeOf(link), @link);
+    link := link div 256;
+    images_decoded[i] := TOniImage.Create;
+    images_decoded[i].LoadFromTXMP(link);
+    images_decoded[i].DecodeImage;
+    images_decoded[i].RevertImage;
+  end;
+  SetLength(Self.FData, Self.FWidth * Self.FHeight * 4);
+  for y := 0 to rows - 1 do
+  begin
+    for x := 0 to cols - 1 do
+    begin
+      imgid   := y * cols + x;
+      x_start := 0;
+      y_start := 0;
+      for i := 0 to x do
+        if i < x then
+          x_start := x_start + images_decoded[i].Width;
+      for i := 0 to y do
+        if i < y then
+          y_start := y_start + images_decoded[i].Height;
+      for y2 := 0 to images_decoded[imgid].Height - 1 do
+      begin
+        for x2 := 0 to images_decoded[imgid].Width - 1 do
+        begin
+          if ((x_start + x2) < Self.FWidth) and ((y_start + y2) < Self.FHeight) then
+          begin
+            pixelid := y_start * Self.FWidth + x_start + y2 * Self.FWidth + x2;
+            Self.FData[pixelid * 4 + 0] :=
+              images_decoded[imgid].Data[(y2 * images_decoded[imgid].Width + x2) * 4 + 0];
+            Self.FData[pixelid * 4 + 1] :=
+              images_decoded[imgid].Data[(y2 * images_decoded[imgid].Width + x2) * 4 + 1];
+            Self.FData[pixelid * 4 + 2] :=
+              images_decoded[imgid].Data[(y2 * images_decoded[imgid].Width + x2) * 4 + 2];
+            Self.FData[pixelid * 4 + 3] :=
+              images_decoded[imgid].Data[(y2 * images_decoded[imgid].Width + x2) * 4 + 3];
+          end;
+        end;
+      end;
+    end;
+  end;
+  for i := 0 to linkcount - 1 do
+    images_decoded[i].Free;
+  Self.FDepth     := 32;
+  Self.FStoreType := 8;
+  Self.FDataType  := [DT_Decoded32];
+  Self.RevertImage;
+end;
+
+
+
+
+function TOniImage.GetImageDataSize(fading: Boolean): LongWord;
+var
+  size: LongWord;
+  x, y: Word;
+  bpp:  Byte;
+begin
+  case Self.FStoreType of
+    9:
+      bpp := 8;
+    0, 1, 2:
+      bpp := 16;
+    8:
+      bpp := 32;
+    else
+      Result := 0;
+      Exit;
+  end;
+
+  x    := Self.FWidth;
+  y    := Self.FHeight;
+  size := x * y * bpp div 8;
+  if fading then
+  begin
+    repeat
+      x    := x div 2;
+      y    := y div 2;
+      size := size + x * y * bpp div 8;
+    until (x = 1) or (y = 1);
+  end;
+  Result := size;
+end;
+
+
+
+
+function TOniImage.GetAsData: Tdata;
+var
+  i:      Integer;
+  revert: Boolean;
+begin
+  //    if not (DT_Decoded32 in Self.FDataType) then
+  //      Self.DecodeImage;
+  if not (DT_OniReverted in Self.FDataType) then
+  begin
+    revert := True;
+    Self.RevertImage;
+  end
+  else
+    revert := False;
+  SetLength(Result, Length(Self.FData));
+  for i := 0 to High(Result) do
+    Result[i] := Self.FData[i];
+  if revert then
+    Self.RevertImage;
+end;
+
+
+
+
+function TOniImage.GetAs32bit: Tdata;
+var
+  i: Integer;
+begin
+  if not (DT_Decoded32 in Self.FDataType) then
+    Self.DecodeImage;
+  SetLength(Result, Length(Self.FData));
+  for i := 0 to High(Result) do
+    Result[i] := Self.FData[i];
+end;
+
+
+
+
+function TOniImage.GetAsBMP: Tdata;
+const
+  BMPheader: array[0..53] of Byte =
+    ($42, $4D, 0, 0, 0, 0, 0, 0, 0, 0, 54, 0, 0, 0,
+    40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, $18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+var
+  i, x, y: LongWord;
+begin
+  if not (DT_Decoded32 in Self.FDataType) then
+    Self.DecodeImage;
+
+  SetLength(Result, Self.FWidth * Self.FHeight * 3 + 54);
+  for y := 0 to Self.FHeight - 1 do
+  begin
+    for x := 0 to Self.FWidth - 1 do
+    begin
+      Result[((Self.FWidth * y + x) * 3) + 0 + 54] := Self.FData[(Self.FWidth * y + x) * 4 + 0];
+      Result[((Self.FWidth * y + x) * 3) + 1 + 54] := Self.FData[(Self.FWidth * y + x) * 4 + 1];
+      Result[((Self.FWidth * y + x) * 3) + 2 + 54] := Self.FData[(Self.FWidth * y + x) * 4 + 2];
+    end;
+  end;
+
+  for i := 0 to High(BMPheader) do
+    Result[i] := BMPheader[i];
+  Result[2] := ((Self.FWidth * Self.FHeight * 3 + 54) and $000000FF) div $1;
+  Result[3]  := ((Self.FWidth * Self.FHeight * 3 + 54) and $0000FF00) div $100;
+  Result[4]  := ((Self.FWidth * Self.FHeight * 3 + 54) and $00FF0000) div $10000;
+  Result[5]  := ((Self.FWidth * Self.FHeight * 3 + 54) and $FF000000) div $1000000;
+  Result[18] := (Self.FWidth and $000000FF) div $1;
+  Result[19] := (Self.FWidth and $0000FF00) div $100;
+  Result[20] := (Self.FWidth and $00FF0000) div $10000;
+  Result[21] := (Self.FWidth and $FF000000) div $1000000;
+  Result[22] := (Self.FHeight and $000000FF) div $1;
+  Result[23] := (Self.FHeight and $0000FF00) div $100;
+  Result[24] := (Self.FHeight and $00FF0000) div $10000;
+  Result[25] := (Self.FHeight and $FF000000) div $1000000;
+  Result[34] := ((Self.FWidth * Self.FHeight * 3) and $000000FF) div $1;
+  Result[35] := ((Self.FWidth * Self.FHeight * 3) and $0000FF00) div $100;
+  Result[36] := ((Self.FWidth * Self.FHeight * 3) and $00FF0000) div $10000;
+  Result[37] := ((Self.FWidth * Self.FHeight * 3) and $FF000000) div $1000000;
+end;
+
+
+
+
+function TOniImage.LoadFromBMP(filename: String): Boolean;
+var
+  filestream: TFileStream;
+  tempd:      Tdata;
+
+  x, y: LongWord;
+begin
+  filestream := TFileStream.Create(filename, fmOpenRead);
+  SetLength(tempd, filestream.Size);
+  filestream.Read(tempd[0], filestream.Size);
+  filestream.Free;
+
+  if not ((tempd[00] = $42) and (tempd[01] = $4D)) then
+  begin
+    Result := False;
+    ShowMessage('Not a standard 24bit bitmap');
+    Exit;
+  end;
+  if not (tempd[10] = 54) then
+  begin
+    Result := False;
+    ShowMessage('Imagedata has to start at 0x54');
+    Exit;
+  end;
+  if not (tempd[14] = 40) then
+  begin
+    Result := False;
+    ShowMessage('Second bitmap header has to have 40 bytes');
+    Exit;
+  end;
+  if not (tempd[28] = 24) then
+  begin
+    Result := False;
+    ShowMessage('Bitmap has to have 24bits');
+    Exit;
+  end;
+  if not (tempd[30] = 0) then
+  begin
+    Result := False;
+    ShowMessage('Bitmap has to be uncompressed');
+    Exit;
+  end;
+
+  Self.FWidth     := tempd[18] + tempd[19] * 256 + tempd[20] * 256 * 256 + tempd[21] * 256 * 256 * 256;
+  Self.FHeight    := tempd[22] + tempd[23] * 256 + tempd[24] * 256 * 256 + tempd[25] * 256 * 256 * 256;
+  Self.FDepth     := 32;
+  Self.FStoreType := 8;
+
+  SetLength(Self.FData, Self.FWidth * Self.FHeight * Self.FDepth div 8);
+  for y := 0 to Self.FHeight - 1 do
+  begin
+    for x := 0 to Self.FWidth - 1 do
+    begin
+      Self.FData[((Self.FWidth * y + x) * 4) + 0] := tempd[54 + (Self.FWidth * y + x) * 3 + 0];
+      Self.FData[((Self.FWidth * y + x) * 4) + 1] := tempd[54 + (Self.FWidth * y + x) * 3 + 1];
+      Self.FData[((Self.FWidth * y + x) * 4) + 2] := tempd[54 + (Self.FWidth * y + x) * 3 + 2];
+      Self.FData[((Self.FWidth * y + x) * 4) + 3] := 0;
+    end;
+  end;
+
+  Self.FDataType := [DT_Decoded32];
+end;
+
+
+
+
+function TOniImage.WriteToBMP(filename: String): Boolean;
+var
+  filestream: TFileStream;
+  tempd:      Tdata;
+begin
+  tempd      := Self.GetAsBMP;
+  filestream := TFileStream.Create(filename, fmCreate);
+  filestream.Write(tempd[0], Length(tempd));
+  filestream.Free;
+end;
+
+
+
+
+function TOniImage.GetMipMappedImage(var faded: Tdata): Boolean;
+var
+  i:      LongWord;
+  x, y:   Word;
+  fadelvldata: Tdata;
+  revert: Boolean;
+begin
+  Result := False;
+
+  //    if not (DT_Decoded32 in Self.FDataType) then
+  //      Self.DecodeImage;
+  if Self.FStoreType = 9 then
+    Self.DecompressImage;
+  if not (DT_OniReverted in Self.FDataType) then
+  begin
+    revert := True;
+    Self.RevertImage;
+  end
+  else
+    revert := False;
+
+  x := Self.FWidth;
+  y := Self.FHeight;
+  SetLength(faded, x * y * Self.FDepth div 8);
+  SetLength(fadelvldata, x * y * Self.FDepth div 8);
+  for i := 0 to Length(faded) - 1 do
+  begin
+    faded[i] := Self.FData[i];
+    fadelvldata[i] := Self.FData[i];
+  end;
+  repeat
+    fadelvldata := Self.ResizeImage(x, y, fadelvldata);
+    x := x div 2;
+    y := y div 2;
+    SetLength(faded, Length(faded) + x * y * Self.FDepth div 8);
+    for i := 0 to Length(fadelvldata) - 1 do
+      faded[Length(faded) - x * y * Self.FDepth div 8 + i] := fadelvldata[i];
+  until (x = 1) or (y = 1) or ((x mod 2) = 1) or ((y mod 2) = 1);
+  if (x > 1) and (y > 1) then
+    Exit;
+  Result := True;
+
+  if revert then
+    Self.RevertImage;
+end;
+
+
+end.
Index: oup/current/Data.pas
===================================================================
--- oup/current/Data.pas	(revision 43)
+++ oup/current/Data.pas	(revision 43)
@@ -0,0 +1,133 @@
+unit Data;
+
+interface
+
+uses Classes, Graphics;
+
+const
+  Version: String   = 'v0.33a';
+  DBVersion: String = '0.3';
+  CrLf: String[2]   = #13 + #10;
+
+type
+  TData = array of Byte;
+
+  THeader = packed record
+    Ident:      array[0..$13] of Byte;
+    Files:      LongWord;
+    NamedFiles: LongWord;
+    Extensions: LongWord;
+    DataAddr:   LongWord;
+    DataSize:   LongWord;
+    NamesAddr:  LongWord;
+    NamesSize:  LongWord;
+    Ident2:     array[0..$F] of Byte;
+  end;
+  TFilesMap = array of packed record
+    Extension: array[0..$3] of Char;
+    DataAddr:  LongWord;
+    NameAddr:  LongWord;
+    FileSize:  LongWord;
+    FileType:  LongWord;
+  end;
+
+  TFileInfo = packed record
+    ID:      Integer;
+    FileName: String;
+    FileNameHex: String;
+    Extension: String[4];
+    Name:    String;
+    Size:    LongWord;
+    FileType: LongWord;
+    DatAddr: LongWord;
+    opened:  Boolean;
+  end;
+  TFiles = array of TFileInfo;
+
+  TNamedFilesMap = array of packed record
+    FileNumber: LongWord;
+    blubb:      LongWord;
+  end;
+  TExtensionsMap = array of packed record
+    Ident:     array[0..$7] of Byte;
+    Extension: array[0..$3] of Char;
+    ExtCount:  LongWord;
+  end;
+
+  TLevelInfo = record
+    Ident: array[0..$13] of Byte;
+    LevelNumber: Byte;
+  end;
+
+  TAppSettings = record
+    DatPath:     String[250];
+    ExtractPath: String[250];
+    FilenumbersAsHex: Boolean;
+    CharSet:     TFontCharSet;
+    HideUnusedData: Boolean;
+  end;
+
+  TExportHandlers = record
+    Ext:     String[4];
+    needed:  Boolean;
+    Handler: function(fileid: LongWord; filename: String; convert: Boolean): Integer;
+  end;
+
+  TStringArray = array of String;
+  TExtList     = array of record
+    Ext:   String;
+    Count: LongWord;
+  end;
+
+  TRawInfo = record
+    src_id:     LongWord;
+    src_offset: LongWord;
+    raw_addr:   LongWord;
+    raw_size:   LongWord;
+    loc_sep:    Boolean;
+  end;
+  TRawList = array of TRawInfo;
+
+  TDatLinks = array of record
+    Src_Offset: LongWord;
+    Target:     LongWord;
+  end;
+
+var
+{
+  opened_state:Byte=0;
+  dat_filename:String='';
+  raw_filename:String='';
+  dat_os_mac:Boolean=False;
+  dat_header:Theader;
+  dat_filesmap:Tfilesmap;
+  dat_files:Tfiles;
+  dat_namedfilesmap:Tnamedfilesmap;
+  dat_extensionsmap:Textensionsmap;
+}
+  AppSettings:     TAppSettings;
+  AppSettingsFile: file of TAppSettings;
+{
+  database_level:LongWord;
+  database_ident:Array[0..$13] of Byte;
+}
+const
+{  header_ident1_pc:Array[0..$13] of Byte=
+      ($1F,$27,$DC,$33,$DF,$BC,$03,$00,$31,$33,$52,$56,$40,$00,$14,$00,$10,$00,$08,$00);
+  header_ident1_mac:Array[0..$13] of Byte=
+      ($61,$30,$C1,$23,$DF,$BC,$03,$00,$31,$33,$52,$56,$40,$00,$14,$00,$10,$00,$08,$00);
+  header_ident2:Array[0..$F] of Byte=
+      ($99,$CF,$40,$00,$90,$4F,$63,$00,$F4,$55,$5F,$00,$90,$4F,$63,$00);
+}
+  export_noerror: Integer = 0;
+  export_nohandler: Integer = 1;
+  export_handlererror: Integer = 2;
+  export_error: Integer = 3;
+{
+  opened_nothing:Byte=0;
+  opened_dat:Byte=1;
+  opened_db:Byte=2;
+}
+implementation
+
+end.
Index: oup/current/Helper_LevelDB.dfm
===================================================================
--- oup/current/Helper_LevelDB.dfm	(revision 43)
+++ oup/current/Helper_LevelDB.dfm	(revision 43)
@@ -0,0 +1,61 @@
+object Form_LevelDB: TForm_LevelDB
+  Left = 0
+  Top = 0
+  BorderStyle = bsNone
+  Caption = 'Creating DB'
+  ClientHeight = 89
+  ClientWidth = 400
+  Color = clBtnFace
+  Font.Charset = DEFAULT_CHARSET
+  Font.Color = clWindowText
+  Font.Height = -11
+  Font.Name = 'Tahoma'
+  Font.Style = []
+  OldCreateOrder = False
+  Position = poScreenCenter
+  PixelsPerInch = 96
+  TextHeight = 13
+  object group_progress: TGroupBox
+    Left = 0
+    Top = 0
+    Width = 400
+    Height = 89
+    Caption = 'Progress ...'
+    TabOrder = 0
+    object lbl_progress: TLabel
+      Left = 2
+      Top = 32
+      Width = 396
+      Height = 17
+      Align = alTop
+      AutoSize = False
+    end
+    object lbl_estimation: TLabel
+      Left = 2
+      Top = 49
+      Width = 396
+      Height = 17
+      Align = alTop
+      AutoSize = False
+      Caption = 'Estimated finishing time:'
+    end
+    object progress: TProgressBar
+      Left = 2
+      Top = 15
+      Width = 396
+      Height = 17
+      Align = alTop
+      Smooth = True
+      TabOrder = 0
+    end
+    object btn_abortok: TButton
+      Left = 3
+      Top = 64
+      Width = 60
+      Height = 22
+      Caption = 'Abort...'
+      TabOrder = 1
+      OnClick = btn_abortokClick
+    end
+  end
+end
Index: oup/current/Helper_LevelDB.pas
===================================================================
--- oup/current/Helper_LevelDB.pas	(revision 43)
+++ oup/current/Helper_LevelDB.pas	(revision 43)
@@ -0,0 +1,1740 @@
+unit Helper_LevelDB;
+
+interface
+
+uses
+  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
+  Dialogs, ComCtrls, StdCtrls, StrUtils;
+
+type
+  TForm_LevelDB = class(TForm)
+    group_progress: TGroupBox;
+    progress:     TProgressBar;
+    lbl_progress: TLabel;
+    btn_abortok:  TButton;
+    lbl_estimation: TLabel;
+    procedure btn_abortokClick(Sender: TObject);
+  private
+    procedure HandleFile(ext: String; fileid: LongWord; dir_dat2db: Boolean);
+    procedure stop_convert;
+  public
+    procedure CreateDatabase(Source, target: String);
+    procedure CreateLevel(Source, target: String);
+  end;
+
+
+var
+  Form_LevelDB: TForm_LevelDB;
+
+implementation
+
+{$R *.dfm}
+
+uses ABSMain, ABSDecUtil, Main, Code_Functions, Data,
+  Code_OniImgClass, Code_DataStructures, Code_OniDataClass;
+
+type
+  THandler = procedure(fileid: LongWord; dir_dat2db: Boolean);
+
+  TConvertHandlers = record
+    Ext:     String[4];
+    needed:  Boolean;
+    Handler: THandler;
+  end;
+
+var
+  ConvertHandlers: array of TConvertHandlers;
+  loaded_filename: String;
+  converting: Boolean = False;
+  abort:     Boolean = False;
+  DataBase:  TABSDatabase;
+  Query:     TABSQuery;
+  MimeCoder: TStringFormat_MIME64;
+
+var
+  DatHeader:   THeader;
+  FilesHeader: TFilesMap;
+  NamedFilesHeader: TNamedFilesMap;
+  ExtensionsHeader: TExtensionsMap;
+  Stream_Body, Stream_Names: TMemoryStream;
+  Stream_Dat, Stream_Raw, Stream_Sep: TFileStream;
+
+
+
+
+procedure TForm_LevelDB.CreateLevel(Source, target: String);
+var
+  files: LongWord;
+
+  i, j:     LongWord;
+  temps, temps2: String;
+  Data, rawdata: Tdata;
+  absolutebegintime, begintime: Double;
+  step:     Byte;
+  rawlist:  TRawList;
+  extlist:  TExtensionsMap;
+  fileinfo: TFileInfo;
+  datlinks: TDatLinks;
+  OniImage: TOniImage;
+  levelid:  LongWord;
+const
+  steps: Byte = 3;
+
+
+
+
+  procedure DoStep(stepname: String);
+  begin
+    Inc(step);
+    if stepname <> 'FIN' then
+      group_progress.Caption :=
+        'Creating Dat (Step ' + IntToStr(step) + '/' + IntToStr(steps) + ': ' + stepname + ')'
+    else
+      group_progress.Caption := 'Creating Dat (FINISHED)';
+  end;
+
+begin
+
+  //
+  // FILE EXISTS CHECK FÜR DAT/RAW/SEP!!!
+  //
+
+  if not CreateDataConnection(Source, ODB_ADB) then
+  begin
+    ShowMessage('Could not connect to .oldb-file');
+    Exit;
+  end;
+  levelid  := OniDataConnection.LevelInfo.LevelNumber;
+  levelid  := (levelid * 2) * 256 * 256 * 256 + $01;
+  OniImage := TOniImage.Create;
+
+  absolutebegintime := Time;
+
+  Self.Visible := True;
+  Form_Main.Visible := False;
+  step  := 0;
+  converting := True;
+  abort := False;
+  btn_abortok.Caption := '&Abort...';
+  btn_abortok.Default := False;
+  absolutebegintime := Time;
+
+  Stream_Body  := TMemoryStream.Create;
+  Stream_Names := TMemoryStream.Create;
+  Stream_Dat   := TFileStream.Create(target, fmCreate);
+  Stream_Raw   := TFileStream.Create(AnsiReplaceStr(target, '.dat', '.raw'), fmCreate);
+  if OniDataConnection.OSisMac then
+    Stream_Sep := TFileStream.Create(AnsiReplaceStr(target, '.dat', '.sep'), fmCreate);
+
+  DoStep('Creating header');
+  progress.Position      := 0;
+  lbl_progress.Caption   := '';
+  lbl_estimation.Caption := 'Estimated finishing time: unknown';
+  Application.ProcessMessages;
+
+  NamedFilesHeader := TOniDataADB(OniDataConnection).GetNamedFilesMap;
+  extlist := OniDataConnection.GetExtendedExtensionsList;
+  for i := 0 to High(DatHeader.Ident) do
+    DatHeader.Ident[i] := OniDataConnection.LevelInfo.Ident[i];
+  DatHeader.Files := OniDataConnection.GetFilesCount;
+  DatHeader.NamedFiles := Length(NamedFilesHeader);
+  DatHeader.Extensions := Length(extlist);
+  DatHeader.DataAddr   := 0;
+  DatHeader.DataSize   := 0;
+  DatHeader.NamesAddr  := 0;
+  DatHeader.NamesSize  := 0;
+  for i := 0 to High(DatHeader.Ident2) do
+    DatHeader.Ident2[i] := 0;
+  SetLength(FilesHeader, DatHeader.Files);
+  SetLength(ExtensionsHeader, DatHeader.Extensions);
+
+  DoStep('Writing extensions-header');
+  progress.Max := Length(OniDataConnection.GetExtensionsList);
+  Application.ProcessMessages;
+
+  for i := 0 to High(ExtensionsHeader) do
+  begin
+    ExtensionsHeader[i].Ident     := extlist[i].Ident;
+    ExtensionsHeader[i].Extension := extlist[i].Extension;
+    SetLength(temps, 4);
+    for j := 0 to 3 do
+      temps[j + 1] := ExtensionsHeader[i].Extension[3 - j];
+    ExtensionsHeader[i].ExtCount :=
+      Length(OniDataConnection.GetFilesList(temps, '', False));
+    progress.Position    := i + 1;
+    lbl_progress.Caption := 'Extensions done: ' + IntToStr(i + 1) + '/' +
+      IntToStr(Length(extlist));
+    Application.ProcessMessages;
+  end;
+
+  DoStep('Storing files-data');
+  progress.Position := 0;
+  progress.Max      := DatHeader.Files;
+  lbl_progress.Caption := '';
+  lbl_estimation.Caption := 'Estimated finishing time: unknown';
+  Application.ProcessMessages;
+
+  begintime := Time;
+  for i := 0 to DatHeader.Files - 1 do
+  begin
+    fileinfo := OniDataConnection.GetFileInfo(i);
+    for j := 0 to 3 do
+      FilesHeader[i].Extension[j] := fileinfo.Extension[4 - j];
+    if fileinfo.Size > 0 then
+    begin
+      //        DatLinks:=;
+      FilesHeader[i].DataAddr := Stream_Body.Size + 8;
+      Data    := OniDataConnection.LoadDatFile(i);
+      Data[4] := (levelid) and $FF;
+      Data[5] := (levelid shr 8) and $FF;
+      Data[6] := (levelid shr 16) and $FF;
+      Data[7] := (levelid shr 24) and $FF;
+
+      if (Pos(UpperCase(fileinfo.Extension), UpperCase(raws)) mod 4) = 1 then
+      begin
+        rawlist := OniDataConnection.GetRawList(i);
+        if Length(rawlist) > 0 then
+        begin
+          for j := 0 to High(rawlist) do
+          begin
+            if rawlist[j].raw_size > 0 then
+            begin
+              if (UpperCase(fileinfo.Extension) = 'TXMP') and
+                ((Data[$88] and $01) > 0) then
+              begin
+                OniImage.LoadFromTXMP(i);
+                OniImage.GetMipMappedImage(rawdata);
+                rawlist[j].raw_size := OniImage.GetImageDataSize(True);
+                Data[$90] := $08;
+                Data[$89] := 32;
+{                  if data[$90]<>OniImage.StoreType then begin
+                    data[$90]:=OniImage.StoreType;
+                    data[$89]:=(data[$89] and $CF) or $20;
+                  end;
+}                end
+              else
+              begin
+                SetLength(rawdata, rawlist[j].raw_size);
+                OniDataConnection.LoadRawFile(i, rawlist[j].src_offset, @rawdata[0]);
+              end;
+              //                data[$88]:=data[$88] and $FE;
+
+              if rawlist[j].loc_sep then
+              begin
+                rawlist[j].raw_addr := Stream_Sep.Size;
+                Stream_Sep.Write(rawdata[0], Length(rawdata));
+              end
+              else
+              begin
+                rawlist[j].raw_addr := Stream_Raw.Size;
+                Stream_Raw.Write(rawdata[0], Length(rawdata));
+              end;
+            end
+            else
+              rawlist[j].raw_addr := 0;
+            Data[rawlist[j].src_offset + 0] := (rawlist[j].raw_addr) and $FF;
+            Data[rawlist[j].src_offset + 1] := (rawlist[j].raw_addr shr 8) and $FF;
+            Data[rawlist[j].src_offset + 2] := (rawlist[j].raw_addr shr 16) and $FF;
+            Data[rawlist[j].src_offset + 3] := (rawlist[j].raw_addr shr 24) and $FF;
+          end;
+        end;
+      end;
+
+      Stream_Body.Write(Data[0], Length(Data));
+      //
+    end
+    else
+      FilesHeader[i].DataAddr := 0;
+    if Length(fileinfo.Name) > 0 then
+    begin
+      FilesHeader[i].NameAddr := Stream_Names.Size;
+      temps := fileinfo.Extension + fileinfo.Name + Chr(0);
+      Stream_Names.Write(temps[1], Length(temps));
+    end
+    else
+      FilesHeader[i].NameAddr := 0;
+    FilesHeader[i].FileSize := fileinfo.Size;
+    FilesHeader[i].FileType := fileinfo.FileType;
+
+    if ((i mod 25) = 0) and (i >= 100) then
+      lbl_estimation.Caption := 'Estimated finishing time: ' + TimeToStr(
+        (Time - begintime) / i * progress.Max + begintime);
+    progress.Position := i + 1;
+    lbl_progress.Caption := 'Files done: ' + IntToStr(i + 1) + '/' + IntToStr(progress.Max);
+    Application.ProcessMessages;
+  end;
+
+  Stream_Dat.Write(DatHeader, SizeOf(DatHeader));
+  for i := 0 to High(FilesHeader) do
+    Stream_Dat.Write(FilesHeader[i], SizeOf(FilesHeader[i]));
+  for i := 0 to High(NamedFilesHeader) do
+    Stream_Dat.Write(NamedFilesHeader[i], SizeOf(NamedFilesHeader[i]));
+  for i := 0 to High(ExtensionsHeader) do
+    Stream_Dat.Write(ExtensionsHeader[i], SizeOf(ExtensionsHeader[i]));
+
+  DatHeader.DataSize  := Stream_Body.Size;
+  DatHeader.NamesSize := Stream_Names.Size;
+  DatHeader.DataAddr  := Stream_Dat.Size;
+  Stream_Body.Seek(0, soFromBeginning);
+  Stream_Dat.CopyFrom(Stream_Body, Stream_Body.Size);
+  DatHeader.NamesAddr := Stream_Dat.Size;
+  Stream_Names.Seek(0, soFromBeginning);
+  Stream_Dat.CopyFrom(Stream_Names, Stream_Names.Size);
+
+  Stream_Dat.Seek(0, soFromBeginning);
+  Stream_Dat.Write(DatHeader, SizeOf(DatHeader));
+
+  Stream_Dat.Free;
+  Stream_Body.Free;
+  Stream_Names.Free;
+  Stream_Raw.Free;
+  if OniDataConnection.OSisMac then
+    Stream_Sep.Free;
+
+  progress.Position      := progress.Max;
+  lbl_progress.Caption   := 'Files done: ' + IntToStr(progress.Max) + '/' +
+    IntToStr(progress.Max);
+  lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - absolutebegintime) + ')';
+
+  DoStep('FIN');
+  btn_abortok.Caption := '&OK';
+  btn_abortok.Default := True;
+
+  OniImage.Free;
+
+  converting := False;
+
+  CloseDataConnection;
+end;
+
+
+
+
+procedure TForm_LevelDB.HandleFile;
+var
+  i: Byte;
+begin
+  for i := 1 to Length(ConvertHandlers) do
+    if UpperCase(ConvertHandlers[i].Ext) = UpperCase(ext) then
+      if ConvertHandlers[i].needed then
+      begin
+        ConvertHandlers[i].Handler(fileid, dir_dat2db);
+        Break;
+      end
+      else
+        Break;
+end;
+
+
+
+
+procedure TForm_LevelDB.CreateDatabase(Source, target: String);
+var
+  i, j:     LongWord;
+  temps, temps2: String;
+  Data:     Tdata;
+  absolutebegintime, begintime: Double;
+  step:     Byte;
+  rawlist:  TRawList;
+  extlist:  TExtensionsMap;
+  fileinfo: TFileInfo;
+const
+  steps: Byte = 4;
+
+
+
+
+  procedure DoStep(stepname: String);
+  begin
+    Inc(step);
+    if stepname <> 'FIN' then
+      group_progress.Caption :=
+        'Creating DB (Step ' + IntToStr(step) + '/' + IntToStr(steps) + ': ' + stepname + ')'
+    else
+      group_progress.Caption := 'Creating DB (FINISHED)';
+  end;
+
+begin
+  if not CreateDataConnection(Source, ODB_Dat) then
+  begin
+    ShowMessage('Could not connect to .dat-file');
+    Exit;
+  end
+  else
+  begin
+    TOniDataDat(OniDataConnection).UnloadWhenUnused := False;
+  end;
+
+  Self.Visible := True;
+  Form_Main.Visible := False;
+  step  := 0;
+  converting := True;
+  abort := False;
+  btn_abortok.Caption := '&Abort...';
+  btn_abortok.Default := False;
+  loaded_filename := target;
+
+  absolutebegintime := Time;
+
+  DataBase := TABSDatabase.Create(Self);
+  DataBase.DatabaseName := 'OLDB';
+  DataBase.DatabaseFileName := target;
+  DataBase.CreateDatabase;
+
+  DoStep('Creating tables');
+  progress.Position      := 0;
+  lbl_progress.Caption   := '';
+  lbl_estimation.Caption := 'Estimated finishing time: unknown';
+  Application.ProcessMessages;
+
+  Query := TABSQuery.Create(Self);
+  Query.DatabaseName := 'OLDB';
+  Query.SQL.Text :=
+    'CREATE TABLE globals  ( id AUTOINC PRIMARY KEY, name STRING(128), value STRING(128) );';
+  Query.ExecSQL;
+  Query.SQL.Text :=
+    'CREATE TABLE linkmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, target_id INTEGER );';
+  Query.ExecSQL;
+  Query.SQL.Text :=
+    'CREATE TABLE rawmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, sep BOOLEAN, size INTEGER, data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib );';
+  //    Query.SQL.Text:='CREATE TABLE rawmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
+  Query.ExecSQL;
+  Query.SQL.Text :=
+    'CREATE TABLE datfiles  ( id INTEGER PRIMARY KEY, extension CHAR(4), name STRING(128), contenttype INTEGER, size INTEGER, data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib );';
+  //    Query.SQL.Text:='CREATE TABLE datfiles  ( id INTEGER PRIMARY KEY, extension CHAR(4), name STRING(128), contenttype INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
+  Query.ExecSQL;
+  Query.SQL.Text :=
+    'CREATE TABLE extlist  ( id AUTOINC PRIMARY KEY, ext CHAR(4), ident CHAR(16) );';
+  Query.ExecSQL;
+
+  Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("dbversion","' +
+    dbversion + '");';
+  Query.ExecSQL;
+  SetLength(Data, Length(OniDataConnection.LevelInfo.Ident));
+  for i := 0 to High(OniDataConnection.LevelInfo.Ident) do
+    Data[i] := OniDataConnection.LevelInfo.Ident[i];
+  temps := CreateHexString(Data, True);
+  Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("ident","' + temps + '");';
+  Query.ExecSQL;
+  Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("lvl","' +
+    IntToStr(OniDataConnection.LevelInfo.LevelNumber) + '");';
+  Query.ExecSQL;
+  if OniDataConnection.OSisMAC then
+    Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("os","MAC");'
+  else
+    Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("os","PC");';
+  Query.ExecSQL;
+
+  DoStep('Writing extensionslist');
+  progress.Max := Length(OniDataConnection.GetExtensionsList);
+  Application.ProcessMessages;
+
+  extlist := OniDataConnection.GetExtendedExtensionsList;
+  for i := 0 to High(extlist) do
+  begin
+    SetLength(Data, Length(extlist[i].Ident));
+    for j := 0 to High(extlist[i].Ident) do
+      Data[j] := extlist[i].Ident[j];
+    temps := CreateHexString(Data, True);
+    temps2 := extlist[i].Extension[3] + extlist[i].Extension[2] +
+      extlist[i].Extension[1] + extlist[i].Extension[0];
+    Query.SQL.Text := 'INSERT INTO extlist (ext,ident) VALUES ("' +
+      temps2 + '","' + temps + '");';
+    Query.ExecSQL;
+    progress.Position    := i;
+    lbl_progress.Caption := 'Extensions done: ' + IntToStr(i) + '/' +
+      IntToStr(Length(extlist));
+    Application.ProcessMessages;
+    if abort then
+    begin
+      stop_convert;
+      Exit;
+    end;
+  end;
+  lbl_progress.Caption := '';
+
+  progress.Position      := 0;
+  lbl_progress.Caption   := 'Files done: ' + IntToStr(0) + '/' + IntToStr(
+    OniDataConnection.GetFilesCount);
+  lbl_estimation.Caption := 'Estimated finishing time: unknown';
+
+  DoStep('Loading .dat into memory');
+  Application.ProcessMessages;
+
+  progress.Max := OniDataConnection.GetFilesCount;
+  begintime    := Time;
+  DoStep('Writing .dat-fileslist');
+  Application.ProcessMessages;
+
+  Database.StartTransaction;
+  for i := 0 to OniDataConnection.GetFilesCount - 1 do
+  begin
+    fileinfo := OniDataConnection.GetFileInfo(i);
+    if (fileinfo.FileType and $02) = 0 then
+    begin
+      mimecoder := TStringFormat_MIME64.Create;
+      Data      := OniDataConnection.LoadDatFile(i);
+      Query.SQL.Text :=
+        'INSERT INTO datfiles (id,extension,name,contenttype,size,data) VALUES (' +
+        IntToStr(i) + ',"' + fileinfo.Extension + '","' + fileinfo.Name + '","' + IntToHex(
+        fileinfo.FileType, 8) + '",' + IntToStr(fileinfo.Size) + ',MimeToBin("' +
+        MimeCoder.StrTo(@Data[0], Length(Data)) + '") );';
+      Query.ExecSQL;
+      mimecoder.Free;
+
+      rawlist := OniDataConnection.GetRawList(i);
+      if Length(rawlist) > 0 then
+      begin
+        for j := 0 to High(rawlist) do
+        begin
+          if rawlist[j].raw_size > 0 then
+          begin
+            SetLength(Data, rawlist[j].raw_size);
+            OniDataConnection.LoadRawFile(i, rawlist[j].src_offset, Data);
+            mimecoder      := TStringFormat_MIME64.Create;
+            Query.SQL.Text :=
+              'INSERT INTO rawmap (src_id,src_link_offset,sep,size,data) VALUES (' +
+              IntToStr(i) + ',' + IntToStr(rawlist[j].src_offset) + ',' + BoolToStr(
+              rawlist[j].loc_sep) + ',' + IntToStr(rawlist[j].raw_size) + ',MimeToBin("' +
+              MimeCoder.StrTo(@Data[0], rawlist[j].raw_size) + '") );';
+            Query.ExecSQL;
+            mimecoder.Free;
+          end
+          else
+          begin
+            Query.SQL.Text :=
+              'INSERT INTO rawmap (src_id,src_link_offset,sep,size) VALUES (' +
+              IntToStr(i) + ',' + IntToStr(rawlist[j].src_offset) + ',' + BoolToStr(rawlist[j].loc_sep) + ',0);';
+            Query.ExecSQL;
+          end;
+        end;
+      end;
+
+      HandleFile(fileinfo.Extension, i, True);
+    end
+    else
+    begin
+      Query.SQL.Text :=
+        'INSERT INTO datfiles (id,extension,name,contenttype,size) VALUES (' +
+        IntToStr(i) + ',"' + fileinfo.Extension + '","' + fileinfo.Name + '","' + IntToHex(
+        fileinfo.FileType, 8) + '",0);';
+      Query.ExecSQL;
+    end;
+    if ((i mod 100) = 0) and (i > 0) then
+    begin
+      Database.Commit(False);
+      Database.StartTransaction;
+    end;
+    if ((i mod 25) = 0) and (i >= 100) then
+      lbl_estimation.Caption := 'Estimated finishing time: ' + TimeToStr(
+        (Time - begintime) / i * progress.Max + begintime);
+    progress.Position := i;
+    lbl_progress.Caption := 'Files done: ' + IntToStr(i) + '/' + IntToStr(progress.Max);
+    Application.ProcessMessages;
+    if abort then
+    begin
+      stop_convert;
+      Exit;
+    end;
+  end;
+  Database.Commit(False);
+  progress.Position      := progress.Max;
+  lbl_progress.Caption   := 'Files done: ' + IntToStr(progress.Max) + '/' +
+    IntToStr(progress.Max);
+  lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - absolutebegintime) + ')';
+
+  DoStep('FIN');
+  btn_abortok.Caption := '&OK';
+  btn_abortok.Default := True;
+
+  converting := False;
+
+  database.Close;
+  database.Free;
+
+  CloseDataConnection;
+end;
+
+
+
+
+procedure TForm_LevelDB.stop_convert;
+begin
+  btn_abortok.Caption := '&Close';
+  btn_abortok.Default := True;
+  converting := False;
+  lbl_estimation.Caption := 'ABORTED';
+  group_progress.Caption := 'Creating DB (ABORTED)';
+  DataBase.Close;
+  if MessageBox(Self.Handle, PChar('Delete the unfinished DB-file?'),
+    PChar('Delete file?'), MB_YESNO) = idYes then
+  begin
+    DeleteFile(loaded_filename);
+  end;
+end;
+
+
+
+
+procedure TForm_LevelDB.btn_abortokClick(Sender: TObject);
+begin
+  if converting then
+  begin
+    if MessageBox(Self.Handle,
+      PChar('Do you really want to cancel the convert-progress?'),
+      PChar('Warning: Converting'), MB_YESNO) = idYes then
+      abort := True;
+  end
+  else
+  begin
+    Self.Visible := False;
+    Form_Main.Visible  := True;
+  end;
+end;
+
+
+
+
+procedure InsertDatLinkToDB(fileid: LongWord; offset: LongWord);
+var
+  link: LongWord;
+begin
+  OniDataConnection.LoadDatFilePart(fileid, offset, 4, @link);
+  if link = 0 then
+    link := $FFFFFFFF
+  else
+    link := link div 256;
+  Query.SQL.Text := 'INSERT INTO linkmap (src_id,src_link_offset,target_id) VALUES (' +
+    IntToStr(fileid) + ',' + IntToStr(offset) + ',' + IntToStr(link) + ');';
+  Query.ExecSQL;
+end;
+
+
+
+
+procedure AISA(fileid: LongWord; dir_dat2db: Boolean);
+var
+  packages: Word;
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
+    if packages > 0 then
+    begin
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * $160 + $28);
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * $160 + $150);
+    end;
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure AKEV(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    for i := 0 to 16 do
+      InsertDatLinkToDB(fileid, $8 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure AKOT(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    for i := 0 to 4 do
+      InsertDatLinkToDB(fileid, $8 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure CBPI(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    for i := 0 to 56 do
+      InsertDatLinkToDB(fileid, $8 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure CBPM(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    for i := 0 to 18 do
+      InsertDatLinkToDB(fileid, $8 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure CONS(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    for i := 0 to 1 do
+      InsertDatLinkToDB(fileid, $24 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure CRSA(fileid: LongWord; dir_dat2db: Boolean);
+var
+  packages: LongWord;
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $14, 4, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 1100 + $A0);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure DOOR(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $08);
+    InsertDatLinkToDB(fileid, $10);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure DPGE(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $40);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure HPGE(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $0C);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure IGHH(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $24);
+    InsertDatLinkToDB(fileid, $28);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure IGPA(fileid: LongWord; dir_dat2db: Boolean);
+var
+  links: LongWord;
+  i:     LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @links);
+    if links > 0 then
+      for i := 0 to links - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure IGPG(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    for i := 0 to 1 do
+      InsertDatLinkToDB(fileid, $1C + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure IGSA(fileid: LongWord; dir_dat2db: Boolean);
+var
+  links: LongWord;
+  i:     LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @links);
+    if links > 0 then
+      for i := 0 to links - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure IMPT(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $10);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure IPGE(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $0C);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure KEYI(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    for i := 0 to 9 do
+      InsertDatLinkToDB(fileid, $08 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure M3GA(fileid: LongWord; dir_dat2db: Boolean);
+var
+  links: LongWord;
+  i:     LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @links);
+    if links > 0 then
+      for i := 0 to links - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure M3GM(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    for i := 0 to 6 do
+      InsertDatLinkToDB(fileid, $0C + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure MTRL(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $10);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure OBDC(fileid: LongWord; dir_dat2db: Boolean);
+var
+  packages: Word;
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * $18 + $4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure OBOA(fileid: LongWord; dir_dat2db: Boolean);
+var
+  packages: Word;
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+      begin
+        InsertDatLinkToDB(fileid, $20 + i * 240 + $0);
+        InsertDatLinkToDB(fileid, $20 + i * 240 + $4);
+        InsertDatLinkToDB(fileid, $20 + i * 240 + $8);
+      end;
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure OFGA(fileid: LongWord; dir_dat2db: Boolean);
+var
+  packages: LongWord;
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 12 + $04);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure ONCC(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $28);
+    InsertDatLinkToDB(fileid, $434);
+    InsertDatLinkToDB(fileid, $438);
+    InsertDatLinkToDB(fileid, $43C);
+    InsertDatLinkToDB(fileid, $C3C);
+    InsertDatLinkToDB(fileid, $C40);
+    InsertDatLinkToDB(fileid, $C44);
+    InsertDatLinkToDB(fileid, $C48);
+    InsertDatLinkToDB(fileid, $C88);
+    InsertDatLinkToDB(fileid, $C8C);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure ONCV(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $08);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure ONLV(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    for i := 0 to 5 do
+      InsertDatLinkToDB(fileid, $48 + i * 4);
+    for i := 0 to 5 do
+      InsertDatLinkToDB(fileid, $64 + i * 4);
+    InsertDatLinkToDB(fileid, $300);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure ONOA(fileid: LongWord; dir_dat2db: Boolean);
+var
+  packages: LongWord;
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 8 + $04);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure ONSK(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $08);
+    InsertDatLinkToDB(fileid, $0C);
+    InsertDatLinkToDB(fileid, $10);
+    InsertDatLinkToDB(fileid, $14);
+    InsertDatLinkToDB(fileid, $18);
+    InsertDatLinkToDB(fileid, $20);
+    InsertDatLinkToDB(fileid, $44);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure ONVL(fileid: LongWord; dir_dat2db: Boolean);
+var
+  packages: LongWord;
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure ONWC(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $28);
+    InsertDatLinkToDB(fileid, $34);
+    InsertDatLinkToDB(fileid, $40);
+    InsertDatLinkToDB(fileid, $54);
+    InsertDatLinkToDB(fileid, $58);
+    InsertDatLinkToDB(fileid, $5C);
+    InsertDatLinkToDB(fileid, $60);
+    InsertDatLinkToDB(fileid, $6FC);
+    InsertDatLinkToDB(fileid, $700);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure OPGE(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $0C);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure PSPC(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $50);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure PSPL(fileid: LongWord; dir_dat2db: Boolean);
+var
+  packages: LongWord;
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 8 + $4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure PSUI(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    for i := 0 to 43 do
+      InsertDatLinkToDB(fileid, $08 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure STNA(fileid: LongWord; dir_dat2db: Boolean);
+var
+  packages: Word;
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TRAC(fileid: LongWord; dir_dat2db: Boolean);
+var
+  packages: Word;
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $18);
+    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 12 + 8);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TRAM(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $40);
+    InsertDatLinkToDB(fileid, $44);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TRAS(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $08);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TRBS(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    for i := 0 to 4 do
+      InsertDatLinkToDB(fileid, $08 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TRCM(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    for i := 0 to 2 do
+      InsertDatLinkToDB(fileid, $5C + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TRGA(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+  packages: Word;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TRGE(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $20);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TRIG(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $18);
+    InsertDatLinkToDB(fileid, $24);
+    InsertDatLinkToDB(fileid, $28);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TRMA(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+  packages: Word;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TRSC(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+  packages: Word;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TSFF(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+  packages: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TSFT(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $1C);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TURR(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $60);
+    InsertDatLinkToDB(fileid, $6C);
+    InsertDatLinkToDB(fileid, $74);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TXAN(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+  packages: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TXMA(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+  packages: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TXMB(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+  packages: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TXMP(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $94);
+    InsertDatLinkToDB(fileid, $98);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TXTC(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $08);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure WMCL(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+  packages: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 8 + $4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure WMDD(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+  packages: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $11C, 4, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $120 + i * $124 + $114);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure WMMB(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+  packages: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure WPGE(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $08);
+    InsertDatLinkToDB(fileid, $0C);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure InsertHandler(ext: String; needed: Boolean; handler: THandler);
+begin
+  SetLength(ConvertHandlers, Length(ConvertHandlers) + 1);
+  ConvertHandlers[High(ConvertHandlers)].Ext     := ext;
+  ConvertHandlers[High(ConvertHandlers)].needed  := needed;
+  ConvertHandlers[High(ConvertHandlers)].handler := handler;
+end;
+
+begin
+  InsertHandler('ABNA', False, nil);
+  //  InsertHandler('AGDB',True,AGDB);
+  InsertHandler('AGDB', False, nil);
+  InsertHandler('AGQC', False, nil);
+  InsertHandler('AGQG', False, nil);
+  InsertHandler('AGQR', False, nil);
+  InsertHandler('AISA', True, AISA);
+  InsertHandler('AITR', False, nil);
+  InsertHandler('AKAA', False, nil);
+  InsertHandler('AKBA', False, nil);
+  InsertHandler('AKBP', False, nil);
+  InsertHandler('AKDA', False, nil);
+  InsertHandler('AKEV', True, AKEV);
+  InsertHandler('AKOT', True, AKOT);
+  InsertHandler('AKVA', False, nil);
+  InsertHandler('BINA', False, nil);
+  InsertHandler('CBPI', True, CBPI);
+  InsertHandler('CBPM', True, CBPM);
+  InsertHandler('CONS', True, CONS);
+  InsertHandler('CRSA', True, CRSA);
+  InsertHandler('DOOR', True, DOOR);
+  InsertHandler('DPGE', True, DPGE);
+  InsertHandler('ENVP', False, nil);
+  InsertHandler('FILM', False, nil);
+  InsertHandler('HPGE', True, HPGE);
+  InsertHandler('IDXA', False, nil);
+  InsertHandler('IGHH', True, IGHH);
+  InsertHandler('IGPA', True, IGPA);
+  InsertHandler('IGPG', True, IGPG);
+  InsertHandler('IGSA', True, IGSA);
+  InsertHandler('IMPT', True, IMPT);
+  InsertHandler('IPGE', True, IPGE);
+  InsertHandler('KEYI', True, KEYI);
+  InsertHandler('M3GA', True, M3GA);
+  InsertHandler('M3GM', True, M3GM);
+  InsertHandler('MTRL', True, MTRL);
+  InsertHandler('OBAN', False, nil);
+  InsertHandler('OBDC', True, OBDC);
+  InsertHandler('OBOA', True, OBOA);
+  InsertHandler('OFGA', True, OFGA);
+  InsertHandler('ONCC', True, ONCC);
+  InsertHandler('ONCP', False, nil);
+  InsertHandler('ONCV', True, ONCV);
+  InsertHandler('ONFA', False, nil);
+  InsertHandler('ONGS', False, nil);
+  InsertHandler('ONIA', False, nil);
+  InsertHandler('ONLD', False, nil);
+  InsertHandler('ONLV', True, ONLV);
+  InsertHandler('ONMA', False, nil);
+  InsertHandler('ONOA', True, ONOA);
+  InsertHandler('ONSA', False, nil);
+  InsertHandler('ONSK', True, ONSK);
+  InsertHandler('ONTA', False, nil);
+  InsertHandler('ONVL', True, ONVL);
+  InsertHandler('ONWC', True, ONWC);
+  InsertHandler('OPGE', True, OPGE);
+  InsertHandler('OSBD', False, nil);
+  InsertHandler('OTIT', False, nil);
+  InsertHandler('OTLF', False, nil);
+  InsertHandler('PLEA', False, nil);
+  InsertHandler('PNTA', False, nil);
+  InsertHandler('PSPC', True, PSPC);
+  InsertHandler('PSPL', True, PSPL);
+  InsertHandler('PSUI', True, PSUI);
+  InsertHandler('QTNA', False, nil);
+  InsertHandler('SNDD', False, nil);
+  InsertHandler('STNA', True, STNA);
+  InsertHandler('SUBT', False, nil);
+  InsertHandler('TRAC', True, TRAC);
+  InsertHandler('TRAM', True, TRAM);
+  InsertHandler('TRAS', True, TRAS);
+  InsertHandler('TRBS', True, TRBS);
+  InsertHandler('TRCM', True, TRCM);
+  InsertHandler('TRGA', True, TRGA);
+  InsertHandler('TRGE', True, TRGE);
+  InsertHandler('TRIA', False, nil);
+  InsertHandler('TRIG', True, TRIG);
+  InsertHandler('TRMA', True, TRMA);
+  InsertHandler('TRSC', True, TRSC);
+  InsertHandler('TRTA', False, nil);
+  InsertHandler('TSFF', True, TSFF);
+  InsertHandler('TSFL', False, nil);
+  InsertHandler('TSFT', True, TSFT);
+  InsertHandler('TSGA', False, nil);
+  InsertHandler('TSTR', False, nil);
+  InsertHandler('TURR', True, TURR);
+  InsertHandler('TXAN', True, TXAN);
+  InsertHandler('TXCA', False, nil);
+  InsertHandler('TXMA', True, TXMA);
+  InsertHandler('TXMB', True, TXMB);
+  InsertHandler('TXMP', True, TXMP);
+  InsertHandler('TXTC', True, TXTC);
+  InsertHandler('VCRA', False, nil);
+  InsertHandler('WMCL', True, WMCL);
+  InsertHandler('WMDD', True, WMDD);
+  InsertHandler('WMM_', False, nil);
+  InsertHandler('WMMB', True, WMMB);
+  InsertHandler('WPGE', True, WPGE);
+end.
Index: oup/current/Helper_ValueEdit.dfm
===================================================================
--- oup/current/Helper_ValueEdit.dfm	(revision 43)
+++ oup/current/Helper_ValueEdit.dfm	(revision 43)
@@ -0,0 +1,123 @@
+object Form_ValueEdit: TForm_ValueEdit
+  Left = 0
+  Top = 0
+  BorderStyle = bsNone
+  BorderWidth = 1
+  Caption = 'Value Edit'
+  ClientHeight = 145
+  ClientWidth = 298
+  Color = clBtnFace
+  Constraints.MaxHeight = 147
+  Constraints.MaxWidth = 700
+  Constraints.MinHeight = 147
+  Constraints.MinWidth = 300
+  Font.Charset = DEFAULT_CHARSET
+  Font.Color = clWindowText
+  Font.Height = -11
+  Font.Name = 'Tahoma'
+  Font.Style = []
+  OldCreateOrder = False
+  Position = poMainFormCenter
+  OnCreate = FormCreate
+  PixelsPerInch = 96
+  TextHeight = 13
+  object group: TGroupBox
+    Left = 0
+    Top = 0
+    Width = 298
+    Height = 145
+    Align = alClient
+    Caption = '---'
+    TabOrder = 0
+    DesignSize = (
+      298
+      145)
+    object lbl_current: TLabel
+      Left = 8
+      Top = 64
+      Width = 73
+      Height = 17
+      AutoSize = False
+      Caption = 'Current value:'
+    end
+    object lbl_new: TLabel
+      Left = 8
+      Top = 88
+      Width = 73
+      Height = 17
+      AutoSize = False
+      Caption = 'New value:'
+    end
+    object lbl_offset: TLabel
+      Left = 8
+      Top = 16
+      Width = 73
+      Height = 17
+      AutoSize = False
+      Caption = 'Offset:'
+    end
+    object lbl_datatype: TLabel
+      Left = 8
+      Top = 40
+      Width = 73
+      Height = 17
+      AutoSize = False
+      Caption = 'Datatype:'
+    end
+    object btn_ok: TButton
+      Left = 153
+      Top = 112
+      Width = 65
+      Height = 25
+      Anchors = [akTop, akRight]
+      Caption = 'OK'
+      Default = True
+      TabOrder = 0
+      OnClick = btn_okClick
+    end
+    object btn_cancel: TButton
+      Left = 225
+      Top = 112
+      Width = 65
+      Height = 25
+      Anchors = [akTop, akRight]
+      Cancel = True
+      Caption = 'Cancel'
+      TabOrder = 1
+      OnClick = btn_cancelClick
+    end
+    object edit_current: TEdit
+      Left = 88
+      Top = 64
+      Width = 203
+      Height = 18
+      Anchors = [akLeft, akTop, akRight]
+      AutoSize = False
+      Color = clInfoBk
+      ReadOnly = True
+      TabOrder = 2
+    end
+    object edit_offset: TEdit
+      Left = 87
+      Top = 16
+      Width = 203
+      Height = 18
+      Anchors = [akLeft, akTop, akRight]
+      AutoSize = False
+      Color = clInfoBk
+      ReadOnly = True
+      TabOrder = 3
+    end
+    object edit_datatype: TEdit
+      Left = 87
+      Top = 40
+      Width = 203
+      Height = 18
+      Anchors = [akLeft, akTop, akRight]
+      AutoSize = False
+      Color = clInfoBk
+      ReadOnly = True
+      TabOrder = 4
+    end
+  end
+end
Index: oup/current/Helper_ValueEdit.pas
===================================================================
--- oup/current/Helper_ValueEdit.pas	(revision 43)
+++ oup/current/Helper_ValueEdit.pas	(revision 43)
@@ -0,0 +1,186 @@
+unit Helper_ValueEdit;
+
+interface
+
+uses
+  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
+  Dialogs, StdCtrls, CrossEdit, Math;
+
+type
+  TForm_ValueEdit = class(TForm)
+    group:      TGroupBox;
+    btn_ok:     TButton;
+    btn_cancel: TButton;
+    lbl_current: TLabel;
+    edit_current: TEdit;
+    lbl_new:    TLabel;
+    lbl_offset: TLabel;
+    lbl_datatype: TLabel;
+    edit_offset: TEdit;
+    edit_datatype: TEdit;
+    procedure btn_cancelClick(Sender: TObject);
+    procedure btn_okClick(Sender: TObject);
+    procedure MakeVarInput(objectname: String; offset: LongWord;
+      datatype: Word; current: String; caller: TObject);
+    procedure FormCreate(Sender: TObject);
+  private
+  public
+    edit_new:   TCrossEdit;
+  end;
+
+var
+  Form_ValueEdit: TForm_ValueEdit;
+
+
+implementation
+
+uses Tool_BinEdit, Tool_RawEdit, Code_DataStructures, Main;
+
+{$R *.dfm}
+
+var
+  caller_win_dat: TForm_BinEdit;
+  caller_win_raw: TForm_RawEdit;
+  _datatype: Word;
+  _offset: LongWord;
+
+
+
+
+procedure TForm_ValueEdit.MakeVarInput(objectname: String; offset: LongWord;
+  datatype: Word; current: String; caller: TObject);
+begin
+  caller_win_dat := nil;
+  caller_win_raw := nil;
+  if Pos('rawedit', TComponent(caller).Name) > 0 then
+    caller_win_raw := TForm_RawEdit(caller)
+  else
+    caller_win_dat := TForm_BinEdit(caller);
+  Form_Main.Enabled := False;
+  Self.Visible := True;
+  group.Caption := 'Edit value';
+  _datatype := datatype;
+  _offset := offset;
+  if Length(objectname) > 0 then
+    group.Caption := group.Caption + ' for ' + objectname;
+  edit_offset.Text := '0x' + IntToHex(offset, 8);
+  edit_datatype.Text := GetDataType(datatype);
+  edit_current.Text := current;
+  edit_new.EditType := etString;
+  edit_new.Text := '';
+  edit_new.LimitCheck := False;
+  edit_new.MaxLength := 0;
+  edit_new.Max := 0;
+  edit_new.BorderStyle := bsSingle;
+  Self.Width := 300;
+  case datatype of
+    1..4:
+    begin
+      edit_new.EditType := etUnsignedInt;
+      edit_new.LimitCheck := True;
+      edit_new.Max := Int(Power(256, datatype)) - 1;
+    end;
+    5..8:
+    begin
+      edit_new.MaxLength := 2 * (datatype - 4);
+      edit_new.EditType  := etHex;
+    end;
+    9:
+    begin
+      edit_new.EditType   := etFloat;
+      edit_new.LimitCheck := False;
+    end;
+    10:
+    begin
+      edit_new.EditType   := etBinary;
+      edit_new.LimitCheck := False;
+      edit_new.MaxLength  := 8;
+    end;
+    13..16:
+    begin
+      Exit;
+      edit_new.EditType := etInteger;
+      edit_new.LimitCheck := True;
+      edit_new.Max := Int((Power(256, datatype - 13)) / 2) - 1;
+      edit_new.Min := 1 - Int((Power(256, datatype - 13)) / 2) - 1;
+    end;
+    10000..65535:
+    begin
+      edit_new.EditType := etString;
+      edit_new.LimitCheck := False;
+      edit_new.MaxLength := datatype - 10000;
+      Self.Width := 700;
+    end;
+  end;
+  edit_new.SetFocus;
+  edit_new.SelectAll;
+end;
+
+
+
+
+procedure TForm_ValueEdit.btn_okClick(Sender: TObject);
+begin
+  if not edit_new.NoValidValue then
+  begin
+    Form_Main.Enabled := True;
+    Self.Visible  := False;
+    if caller_win_dat = nil then
+      caller_win_raw.SetNewValue(_datatype, _offset, edit_new.Text)
+    else
+      caller_win_dat.SetNewValue(_datatype, _offset, edit_new.Text);
+  end;
+end;
+
+
+
+
+procedure TForm_ValueEdit.FormCreate(Sender: TObject);
+begin
+  edit_new := TCrossEdit.Create(Self);
+  with edit_new do
+  begin
+    Left := 88;
+    Top := 88;
+    Width := 203;
+    Height := 18;
+    Anchors := [akLeft, akTop, akRight];
+    AutoSize := False;
+    BorderStyle := bsNone;
+    Color := clWhite;
+    Font.Charset := DEFAULT_CHARSET;
+    Font.Color := clWindowText;
+    Font.Height := -11;
+    Font.Name := 'Tahoma';
+    Font.Style := [];
+    HideSelection := False;
+    ParentFont := False;
+    TabOrder := 5;
+    Text := '0000';
+    FocusAlignment := taLeftJustify;
+    NoFocusAlignment := taLeftJustify;
+    Precision := 15;
+    Decimals := 4;
+    FocusWidthInc := 0;
+    EditType := etHex;
+    NextDialogOnEnter := True;
+    DialogOnCursorKeys := True;
+    NextPriorStep := 1;
+    AutoFocus := False;
+    LimitCheck := True;
+    Max := 2147483647.000000000000000000;
+    FocusColor := clWhite;
+    NoFocusColor := clWhite;
+    ErrorColor := clRed;
+    StringCharSet := scFull;
+  end;
+  Self.InsertControl(edit_new);
+end;
+
+procedure TForm_ValueEdit.btn_cancelClick(Sender: TObject);
+begin
+  Form_Main.Enabled := True;
+  Self.Visible  := False;
+end;
+
+end.
Index: oup/current/Main.dfm
===================================================================
--- oup/current/Main.dfm	(revision 43)
+++ oup/current/Main.dfm	(revision 43)
@@ -0,0 +1,444 @@
+object Form_Main: TForm_Main
+  Left = 0
+  Top = 0
+  HorzScrollBar.Visible = False
+  VertScrollBar.Visible = False
+  Caption = 'Form_Main'
+  ClientHeight = 571
+  ClientWidth = 577
+  Color = clBtnFace
+  Font.Charset = DEFAULT_CHARSET
+  Font.Color = clWindowText
+  Font.Height = -11
+  Font.Name = 'Tahoma'
+  Font.Style = []
+  FormStyle = fsMDIForm
+  OldCreateOrder = False
+  WindowState = wsMaximized
+  OnClose = FormClose
+  OnCreate = FormCreate
+  OnResize = FormResize
+  PixelsPerInch = 96
+  TextHeight = 13
+  object statbar: TStatusBar
+    Left = 0
+    Top = 554
+    Width = 577
+    Height = 17
+    BiDiMode = bdLeftToRight
+    Panels = <
+      item
+        Text = 'Nothing loaded'
+        Width = 500
+      end
+      item
+        Text = 'Files: -'
+        Width = 90
+      end
+      item
+        Text = 'Extensions: -'
+        Width = 100
+      end>
+    ParentBiDiMode = False
+  end
+  object DockTop: TTBDock
+    Left = 0
+    Top = 0
+    Width = 577
+    Height = 75
+    object MainMenu: TTBToolbar
+      Left = 0
+      Top = 0
+      Caption = 'MainMenu'
+      CloseButton = False
+      FullSize = True
+      Images = MenuImages
+      MenuBar = True
+      ProcessShortCuts = True
+      ShrinkMode = tbsmWrap
+      TabOrder = 0
+      object menu_main: TTBSubmenuItem
+        Caption = '&Main'
+        object menu_loadfile: TTBItem
+          Caption = '&Open level-file ...'
+          ImageIndex = 1
+          ShortCut = 16463
+          OnClick = menu_loadfileClick
+        end
+        object menu_sep1: TTBSeparatorItem
+        end
+        object menu_settings: TTBItem
+          Caption = 'Se&ttings...'
+          OnClick = menu_settingsClick
+        end
+        object menu_sep4: TTBSeparatorItem
+        end
+        object menu_exit: TTBItem
+          Caption = '&Exit'
+          OnClick = menu_exitClick
+        end
+      end
+      object menu_convert: TTBSubmenuItem
+        Caption = '&Convert'
+        object menu_createdb: TTBItem
+          Caption = 'Create level-database ...'
+          OnClick = menu_createdbClick
+        end
+        object menu_createlvl: TTBItem
+          Caption = 'Create level-files ...'
+          OnClick = menu_createlvlClick
+        end
+      end
+      object menu_tools: TTBSubmenuItem
+        Caption = '&Tools'
+        Enabled = False
+        object menu_preview: TTBItem
+          Caption = '&Preview Window ...'
+          ShortCut = 16464
+          OnClick = menu_previewClick
+        end
+        object menu_binedit: TTBItem
+          Caption = '&Binary .dat editor ...'
+          ShortCut = 16450
+          OnClick = menu_bineditClick
+        end
+        object menu_rawedit: TTBItem
+          Caption = 'Binary .&raw editor ...'
+          ShortCut = 16466
+          OnClick = menu_raweditClick
+        end
+        object menu_txmpreplace: TTBItem
+          Caption = '&TXMP replacer ...'
+          ShortCut = 16468
+          OnClick = menu_txmpreplaceClick
+        end
+        object menu_extractor: TTBItem
+          Caption = 'File &extractor ...'
+          ShortCut = 16453
+          OnClick = menu_extractorClick
+        end
+        object menu_filecompare: TTBItem
+          Caption = '&File compare ...'
+          Enabled = False
+          ShortCut = 16454
+          OnClick = menu_filecompareClick
+        end
+        object menu_levelstructedit: TTBItem
+          Caption = 'Levelfile structure editor ...'
+          Enabled = False
+          ShortCut = 16460
+        end
+      end
+      object menu_windows: TTBSubmenuItem
+        Caption = '&Windows'
+        object menu_windows_cascade: TTBItem
+          Caption = 'Cascade'
+          OnClick = menu_windows_cascadeClick
+        end
+        object menu_windows_tile: TTBItem
+          Caption = 'Tile'
+          OnClick = menu_windows_tileClick
+        end
+        object menu_windows_closeall: TTBItem
+          Caption = '&Close all'
+          OnClick = menu_windows_closeallClick
+        end
+        object menu_sep3: TTBSeparatorItem
+        end
+        object menu_windows_next: TTBItem
+          Caption = 'Next window'
+          ShortCut = 16417
+          OnClick = menu_windows_nextClick
+        end
+        object menu_windows_previous: TTBItem
+          Caption = 'Previous window'
+          ShortCut = 16418
+          OnClick = menu_windows_previousClick
+        end
+        object menu_sep2: TTBSeparatorItem
+        end
+        object menu_view: TTBSubmenuItem
+          Caption = '&View'
+          object menu_view_toolbar: TTBItem
+            Caption = '&Toolbar'
+            Checked = True
+            OnClick = menu_view_toolbarClick
+          end
+          object menu_view_statusbar: TTBItem
+            Caption = '&Status bar'
+            Checked = True
+            OnClick = menu_view_statusbarClick
+          end
+          object menu_view_mdibar: TTBItem
+            Caption = '&Window list'
+            Checked = True
+            OnClick = menu_view_mdibarClick
+          end
+        end
+      end
+      object menu_About: TTBItem
+        Caption = '&About'
+        OnClick = menu_AboutClick
+      end
+    end
+    object Toolbar: TTBToolbar
+      Left = 0
+      Top = 23
+      Caption = 'Toolbar'
+      Images = MenuImages
+      TabOrder = 1
+      object tbOpen: TTBItem
+        Caption = 'Open file'
+        DisplayMode = nbdmImageAndText
+        ImageIndex = 1
+        OnClick = menu_loadfileClick
+      end
+      object tb_separator1: TTBSeparatorItem
+      end
+      object tb_preview: TTBItem
+        Caption = 'Preview'
+        Enabled = False
+        OnClick = menu_previewClick
+      end
+      object tb_datedit: TTBItem
+        Caption = 'DatEditor'
+        Enabled = False
+        OnClick = menu_bineditClick
+      end
+      object tb_rawedit: TTBItem
+        Caption = 'RawEditor'
+        Enabled = False
+        OnClick = menu_raweditClick
+      end
+      object tb_txmpreplacer: TTBItem
+        Caption = 'TXMP Replacer'
+        Enabled = False
+        OnClick = menu_txmpreplaceClick
+      end
+      object tb_extractor: TTBItem
+        Caption = 'File extractor'
+        Enabled = False
+        OnClick = menu_extractorClick
+      end
+      object tb_compare: TTBItem
+        Caption = 'File compare'
+        Enabled = False
+        OnClick = menu_filecompareClick
+      end
+      object tb_structure: TTBItem
+        Caption = 'Level structure'
+        Enabled = False
+      end
+    end
+    object MDIToolbar: TTBToolbar
+      Left = 0
+      Top = 49
+      Caption = 'MDIToolbar'
+      DockableTo = [dpTop, dpBottom]
+      DockMode = dmCannotFloat
+      DockPos = 0
+      DockRow = 2
+      TabOrder = 2
+      object TBControlItem1: TTBControlItem
+        Control = MDITab
+      end
+      object MDITab: TMDITab
+        Left = 0
+        Top = 0
+        Width = 300
+        Height = 22
+        Cursor = crHandPoint
+        About = 'MDI Tab Control 1.4 - Copyright '#169' 1999,2002 MichaL MutL'
+        Align = alTop
+        DragKind = dkDock
+        HotTrack = True
+        Images = MenuImages
+        OwnerDraw = True
+        Style = tsFlatButtons
+        OnDrawTab = MDITabDrawTab
+        ParentShowHint = False
+        ShowHint = True
+        ShowOnChange = True
+        TabOrder = 0
+        OnMouseUp = MDITabMouseUp
+      end
+    end
+  end
+  object DockLeft: TTBDock
+    Left = 0
+    Top = 75
+    Width = 9
+    Height = 470
+    Position = dpLeft
+  end
+  object DockRight: TTBDock
+    Left = 568
+    Top = 75
+    Width = 9
+    Height = 470
+    Position = dpRight
+  end
+  object DockBottom: TTBDock
+    Left = 0
+    Top = 545
+    Width = 577
+    Height = 9
+    Position = dpBottom
+  end
+  object opend: TOpenDialog
+    Filter = 
+      'Compatible level files|*.dat;*.oldb|Oni level (*.dat)|*.dat|OUP ' +
+      'level database (*.oldb)|*.oldb|Any (*.*)|*'
+    Options = [ofPathMustExist, ofFileMustExist, ofEnableSizing]
+    Left = 32
+    Top = 64
+  end
+  object saved: TSaveDialog
+    Options = [ofOverwritePrompt, ofPathMustExist, ofEnableSizing]
+    Left = 32
+    Top = 88
+  end
+  object MenuImages: TImageList
+    Left = 168
+    Top = 112
+    Bitmap = {
+      494C010102000400040010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
+      0000000000003600000028000000400000001000000001002000000000000010
+      00000000000000000000000000000000000000000000EEB40000EEB40000EEB4
+      0000EEB40000EEB40000EEB40000EEB40000EEB40000EEB40000EEB40000EEB4
+      0000EEB40000EEB40000EEB400000000000000000000EEB40000EEB40000EEB4
+      0000EEB40000EEB40000EEB40000EEB40000EEB40000EEB40000EEB40000EEB4
+      0000EEB40000EEB40000EEB40000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      00000000000000000000000000000000000000000000A4A4A400A4A4A400A4A4
+      A400A4A4A40000000000EEB40000EEB40000EEB40000EEB4000000000000A4A4
+      A400A4A4A400A4A4A400A4A4A400EEB4000000000000A4A4A400A4A4A400A4A4
+      A400A4A4A40000000000EEB40000EEB40000EEB40000EEB4000000000000A4A4
+      A400A4A4A400A4A4A400A4A4A400EEB400000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      000000000000000000000000000000000000000000004A4A4A004A4A4A004A4A
+      4A00A4A4A40014007F00944131009441310094413100EEB400000E0E0E004A4A
+      4A004A4A4A004A4A4A00A4A4A400EEB40000000000004A4A4A004A4A4A004A4A
+      4A00A4A4A40018800000944131009441310094413100EEB400000E0E0E004A4A
+      4A004A4A4A004A4A4A00A4A4A400EEB400000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      000000000000000000000000000000000000000000004A4A4A004A4A4A004A4A
+      4A00A4A4A40018009400944131009441310094413100EEB40000180094004A4A
+      4A004A4A4A004A4A4A00A4A4A400EEB40000000000004A4A4A004A4A4A004A4A
+      4A00A4A4A40018920000944131009441310094413100EEB40000189200004A4A
+      4A004A4A4A004A4A4A00A4A4A400EEB400000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      000000000000000000000000000000000000000000004A4A4A00000000000000
+      0000A4A4A40000000000944131000000000000000000EEB40000020202004A4A
+      4A000000000000000000A4A4A400EEB40000000000004A4A4A00000000000000
+      0000A4A4A40000000000944131000000000000000000EEB40000020202004A4A
+      4A000000000000000000A4A4A400EEB400000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      00000000000000000000000000000000000000000000A4A4A4004A4A4A00A4A4
+      A400A4A4A40000000000EEB4000094413100EEB40000EEB4000000000000A4A4
+      A4004A4A4A00A4A4A400A4A4A400EEB4000000000000A4A4A4004A4A4A00A4A4
+      A400A4A4A40000000000EEB4000094413100EEB40000EEB4000000000000A4A4
+      A4004A4A4A00A4A4A400A4A4A400EEB400000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      000000000000000000000000000000000000000000000000000014007F000000
+      0000000000000000000000000000180094000000000014007F00000000000000
+      000014007F0014007F0000000000EEB40000000000000000000014007F000000
+      0000000000000000000000000000180094000000000000000000000000000000
+      000014007F001880000000000000EEB400000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000014007F0014007F000000
+      00000000000000000000180094000000000014007F0014007F00000000000000
+      0000000000001800940000000000EEB400000000000018800000188000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000001892000000000000EEB400000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000014007F0014007F000000
+      00000000000000000000000000001800940014007F0000000000000000000000
+      0000000000001800940000000000EEB400000000000018800000188000000000
+      0000000000000000000018920000189200000000000000000000000000000000
+      0000000000001892000000000000EEB400000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000014007F0014007F000000
+      0000000000000000000014007F0014007F001800940000000000000000000000
+      0000000000001800940000000000EEB400000000000018800000188000000000
+      0000000000000000000000000000000000001892000000000000000000000000
+      0000000000001892000000000000EEB400000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000014007F00180094000000
+      00000000000014007F0014007F00180094000000000018009400000000000000
+      000014007F001800940000000000EEB400000000000018800000189200000000
+      0000000000000000000000000000180094000000000018920000000000000000
+      0000188000001892000000000000EEB400000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      000000000000000000000000000000000000000000000E0E0E00180094000202
+      0200000000000000000000000000A4A4A4000000000000000000000000000000
+      000014007F0014007F0000000000EEB40000000000000E0E0E00189200000202
+      0200000000000000000000000000A4A4A4000000000000000000000000000000
+      0000188000001880000000000000EEB400000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      00000000000000000000000000000000000000000000A4A4A400A4A4A400A4A4
+      A400A4A4A400A4A4A400A4A4A40094413100A4A4A400A4A4A400A4A4A400A4A4
+      A400A4A4A400A4A4A400EEB40000EEB4000000000000A4A4A400A4A4A400A4A4
+      A400A4A4A400A4A4A400A4A4A40094413100A4A4A400A4A4A400A4A4A400A4A4
+      A400A4A4A400A4A4A400EEB40000EEB400000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      00000000000000000000000000000000000000000000EEB40000EEB40000EEB4
+      0000EEB40000EEB40000EEB40000EEB40000EEB40000EEB40000EEB40000EEB4
+      0000EEB40000EEB40000EEB40000EEB4000000000000EEB40000EEB40000EEB4
+      0000EEB40000EEB40000EEB40000EEB40000EEB40000EEB40000EEB40000EEB4
+      0000EEB40000EEB40000EEB40000EEB400000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      00000000000014007F001800940018009400180094001800940014007F000000
+      0000000000000000000000000000EEB400000000000000000000000000000000
+      0000000000001880000018920000189200001892000018920000188000000000
+      0000000000000000000000000000EEB400000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      000000000000000000000000000000000000EEB4000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      000000000000000000000000000000000000EEB4000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      000000000000000000000000000000000000424D3E000000000000003E000000
+      2800000040000000100000000100010000000000800000000000000000000000
+      000000000000000000000000FFFFFF0080018001000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000000000000000000000000000000000000000000000000
+      0000000000000000000100010000000000000000000000000000000000000000
+      000000000000}
+  end
+end
Index: oup/current/Main.pas
===================================================================
--- oup/current/Main.pas	(revision 43)
+++ oup/current/Main.pas	(revision 43)
@@ -0,0 +1,572 @@
+unit Main;
+
+interface
+
+uses
+  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
+  Dialogs, StdCtrls, StrUtils, Clipbrd, ExtCtrls, ComCtrls, Menus, Grids,
+  MPHexEditor, ToolWin, ImgList, Tabs,
+  Code_Functions, Data, Code_DataStructures,
+  Helper_LevelDB, Code_Exporters, Settings,
+  Tool_Preview, Tool_TxmpReplace, Tool_BinEdit, Tool_Extractor, Tool_RawEdit,
+  Code_OniDataClass, MDITab, TB2Item, TB2Dock, TB2Toolbar, TB2MDI;
+
+type
+  TForm_Main = class(TForm)
+    saved:      TSaveDialog;
+    opend:      TOpenDialog;
+    statbar:    TStatusBar;
+    MenuImages: TImageList;
+    DockTop:    TTBDock;
+    MainMenu:   TTBToolbar;
+    menu_main:  TTBSubmenuItem;
+    menu_loadfile: 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;
+    MDIToolbar: TTBToolbar;
+    TBControlItem1: TTBControlItem;
+    MDITab:     TMDITab;
+    menu_view:  TTBSubmenuItem;
+    menu_view_mdibar: TTBItem;
+    menu_view_statusbar: TTBItem;
+    menu_view_toolbar: TTBItem;
+    tb_separator1: TTBSeparatorItem;
+    tb_preview: TTBItem;
+    tb_structure: TTBItem;
+    tb_compare: TTBItem;
+    tb_extractor: TTBItem;
+    tb_txmpreplacer: TTBItem;
+    tb_rawedit: TTBItem;
+    tb_datedit: TTBItem;
+    function TryCloseAll: Boolean;
+    procedure menu_AboutClick(Sender: TObject);
+    procedure menu_settingsClick(Sender: TObject);
+    procedure menu_filecompareClick(Sender: TObject);
+    procedure menu_raweditClick(Sender: TObject);
+    procedure menu_createlvlClick(Sender: TObject);
+    procedure menu_extractorClick(Sender: TObject);
+    procedure menu_createdbClick(Sender: TObject);
+    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_bineditClick(Sender: TObject);
+    procedure menu_loadfileClick(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 menu_view_mdibarClick(Sender: TObject);
+    procedure menu_view_statusbarClick(Sender: TObject);
+    procedure menu_view_toolbarClick(Sender: TObject);
+    procedure MDITabDrawTab(Control: TCustomTabControl; TabIndex: Integer;
+      const Rect: TRect; Active: Boolean);
+    procedure ActivateTools(active: Boolean);
+    procedure MDITabMouseUp(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+  private
+  public
+  end;
+
+var
+  Form_Main: TForm_Main;
+
+implementation
+
+{$R *.dfm}
+
+
+
+procedure TForm_Main.FormCreate(Sender: TObject);
+begin
+  Self.Caption := 'Oni Un/Packer ' + version;
+  Self.FormResize(Self);
+
+  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 TForm_Main.FormResize(Sender: TObject);
+const
+  MinWidth: Integer  = 750;
+  MinHeight: Integer = 500;
+begin
+  if Self.Width < MinWidth then
+    Self.Width := MinWidth;
+  if Self.Height < MinHeight then
+    Self.Height := MinHeight;
+  statbar.Panels.Items[0].Width := Self.Width - 200;
+  MDITab.Width := Self.Width - 20;
+end;
+
+
+
+
+procedure TForm_Main.MDITabDrawTab(Control: TCustomTabControl;
+  TabIndex: Integer; const Rect: TRect; Active: Boolean);
+var
+  x, y: Integer;
+  iconindex: Integer;
+  caption: String;
+begin
+  iconindex := TMDITab(Control).Glyphs[TabIndex];
+  caption := TMDITab(Control).Captions[TabIndex];
+  if active then
+  begin
+    Control.Canvas.Font.Style := Control.Canvas.Font.Style + [fsItalic];
+    y := Rect.Top + 1;
+  end else
+    y := Rect.Top;
+  if iconindex >= 0 then
+  begin
+    TMDITab(Control).Images.Draw(Control.Canvas, Rect.Left + 4, y, iconindex);
+    x := Rect.Left + 26;
+  end else
+    x := Rect.Left + 4;
+  Control.Canvas.TextOut(x, y + 2, caption);
+end;
+
+
+
+
+
+
+procedure TForm_Main.MDITabMouseUp(Sender: TObject; Button: TMouseButton;
+  Shift: TShiftState; X, Y: Integer);
+var
+  pt: TPoint;
+  index: Integer;
+begin
+  pt.X := X;
+  pt.Y := Y;
+  index := MDITab.GetTabAtPos(pt);
+  if (Button = mbRight) and (index >= 0) then
+    MDITab.MDIChildren[index].Close;
+end;
+
+procedure TForm_Main.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 TForm_Main.ActivateTools(active: Boolean);
+begin
+  menu_tools.Enabled := active;
+  tb_preview.Enabled := active;
+  tb_datedit.Enabled := active;
+  tb_rawedit.Enabled := active;
+  tb_txmpreplacer.Enabled := active;
+  tb_extractor.Enabled := active;
+//  tb_compare.Enabled := active;
+//  tb_structure.Enabled := active;
+end;
+
+procedure TForm_Main.UpdateStatBar;
+begin
+  if Assigned(OniDataConnection) then
+  begin
+    Self.Caption      := 'Oni Un/Packer ' + version + ' (' + ExtractFileName(
+      OniDataConnection.FileName) + ')';
+    ActivateTools(True);
+    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
+      Self.Caption      := 'Oni Un/Packer ' + version;
+      statbar.Panels.Items[0].Text := 'Nothing loaded';
+      statbar.Panels.Items[1].Text := 'Files: -';
+      statbar.Panels.Items[2].Text := 'Extensions: -';
+      ActivateTools(False);
+    end;
+  end
+  else
+  begin
+    Self.Caption      := 'Oni Un/Packer ' + version;
+    statbar.Panels.Items[0].Text := 'Nothing loaded';
+    statbar.Panels.Items[1].Text := 'Files: -';
+    statbar.Panels.Items[2].Text := 'Extensions: -';
+    ActivateTools(False);
+  end;
+end;
+
+
+
+
+function TForm_Main.TryCloseAll: Boolean;
+begin
+  menu_windows_closeallClick(Self);
+  Application.ProcessMessages;
+  if MDITab.MDIChildCount = 0 then
+    Result := True
+  else
+    Result := False;
+end;
+
+
+ {#################################}
+ {##### Main-Menu-Handlers    #####}
+ {#################################}
+procedure TForm_Main.menu_loadfileClick(Sender: TObject);
+var
+  ext: String;
+begin
+  if TryCloseAll then
+  begin
+    CloseDataConnection;
+    opend.InitialDir := AppSettings.DatPath;
+    opend.Filter     := 'Compatible level files|*.dat;*.oldb|Oni level (*.dat)|*.dat|OUP level database (*.oldb)|*.oldb|Any (*.*)|*';
+    if opend.Execute then
+    begin
+      ext := ExtractFileExt(opend.FileName);
+      if ext = '.dat' then
+        if not CreateDataConnection(opend.FileName, ODB_Dat) then
+          ShowMessage('Error while loading the file:' + CrLf + opend.FileName +
+            CrLf + 'Perhaps not an Oni-.dat-file?')
+      else if ext = '.oldb' then
+        if not CreateDataConnection(opend.FileName, ODB_ADB) then
+          ShowMessage('Error while loading the file:' + CrLf + opend.FileName +
+            CrLf + 'Perhaps not an OniUnPacker-LevelDatabase-file?')
+      else
+        ShowMessage('Incompatible file');
+      AppSettings.DatPath := ExtractFilepath(opend.FileName);
+    end;
+  end;
+  UpdateStatBar;
+end;
+
+
+
+
+procedure TForm_Main.menu_settingsClick(Sender: TObject);
+begin
+  Form_Settings.Visible := True;
+  Self.Enabled   := False;
+end;
+
+
+
+
+procedure TForm_Main.menu_exitClick(Sender: TObject);
+begin
+  Self.Close;
+end;
+
+ {####################################}
+ {##### Converters-Menu-Handlers #####}
+ {####################################}
+procedure TForm_Main.menu_createdbClick(Sender: TObject);
+begin
+  if Assigned(OniDataConnection) then
+    if MessageBox(Self.Handle, PChar('You have currently opened a level-file. ' +
+          'Do you want to close it to continue?'), PChar('Close file?'),
+          MB_YESNO + MB_ICONQUESTION) = ID_NO then
+      Exit
+    else begin
+      if TryCloseAll then
+      begin
+        CloseDataConnection;
+        UpdateStatBar;
+      end else
+        Exit;
+    end;
+  opend.Filter     := 'Oni-Dat-Files|*.dat';
+  saved.Filter     := 'OUP-Level-DB (*.oldb)|*.oldb';
+  saved.DefaultExt := 'oldb';
+  if opend.Execute then
+    if saved.Execute then
+      Form_LevelDB.CreateDatabase(opend.FileName, saved.FileName);
+end;
+
+
+
+
+procedure TForm_Main.menu_createlvlClick(Sender: TObject);
+begin
+  if Assigned(OniDataConnection) then
+    if MessageBox(Self.Handle, PChar('You have currently opened a level-file. ' +
+          'Do you want to close it to continue?'), PChar('Close file?'),
+          MB_YESNO + MB_ICONQUESTION) = ID_NO then
+      Exit
+    else begin
+      if TryCloseAll then
+      begin
+        CloseDataConnection;
+        UpdateStatBar;
+      end else
+        Exit;
+    end;
+  opend.Filter     := 'OUP-Level-DB (*.oldb)|*.oldb';
+  saved.Filter     := 'Oni-Dat-Files|*.dat';
+  saved.DefaultExt := 'dat';
+  if opend.Execute then
+    if saved.Execute then
+      Form_LevelDB.CreateLevel(opend.FileName, saved.FileName);
+end;
+
+ {#################################}
+ {##### Tools-Menu-Handlers   #####}
+ {#################################}
+procedure TForm_Main.menu_previewClick(Sender: TObject);
+begin
+  open_child('preview');
+end;
+
+
+procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject);
+begin
+  open_child('txmpreplace');
+end;
+
+
+procedure TForm_Main.menu_bineditClick(Sender: TObject);
+begin
+  open_child('binedit');
+end;
+
+
+procedure TForm_Main.menu_raweditClick(Sender: TObject);
+begin
+  open_child('rawedit');
+end;
+
+
+procedure TForm_Main.menu_extractorClick(Sender: TObject);
+begin
+  open_child('extractor');
+end;
+
+
+procedure TForm_Main.menu_filecompareClick(Sender: TObject);
+begin
+  open_child('compare');
+end;
+
+
+ {#################################}
+ {#####   View-Menu-Handlers  #####}
+ {#################################}
+procedure TForm_Main.menu_view_mdibarClick(Sender: TObject);
+begin
+  menu_view_mdibar.Checked := not menu_view_mdibar.Checked;
+  mditoolbar.Visible := menu_view_mdibar.Checked;
+end;
+
+
+
+
+procedure TForm_Main.menu_view_statusbarClick(Sender: TObject);
+begin
+  menu_view_statusbar.Checked := not menu_view_statusbar.Checked;
+  statbar.Visible := menu_view_statusbar.Checked;
+end;
+
+
+
+
+procedure TForm_Main.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 TForm_Main.menu_windows_cascadeClick(Sender: TObject);
+begin
+  Self.Cascade;
+end;
+
+
+
+procedure TForm_Main.menu_windows_tileClick(Sender: TObject);
+begin
+  Self.TileMode := tbHorizontal;
+  Self.Tile;
+end;
+
+
+
+procedure TForm_Main.menu_windows_closeallClick(Sender: TObject);
+begin
+  MDITab.CloseAll;
+end;
+
+
+
+procedure TForm_Main.menu_windows_nextClick(Sender: TObject);
+begin
+  if MDIChildCount > 1 then
+    if MDITab.TabIndex = MDITab.MDIChildCount - 1 then
+      MDITab.MDIChildren[0].BringToFront
+    else
+      MDITab.MDIChildren[MDITab.TabIndex + 1].BringToFront;
+end;
+
+
+
+procedure TForm_Main.menu_windows_previousClick(Sender: TObject);
+begin
+  if MDIChildCount > 1 then
+    if MDITab.TabIndex = 0 then
+      MDITab.MDIChildren[MDITab.MDIChildCount - 1].BringToFront
+    else
+      MDITab.MDIChildren[MDITab.TabIndex - 1].BringToFront;
+end;
+
+
+
+
+
+
+procedure TForm_Main.menu_AboutClick(Sender: TObject);
+begin
+  ShowMessage('Will be implemented later ;)');
+end;
+
+
+
+
+function TForm_Main.open_child(window_context: String): Boolean;
+var
+  form:    TCustomForm;
+  i:       Integer;
+  tag:     Integer;
+  iconindex: Integer;
+begin
+  Result := True;
+
+  tag := 1;
+  if MDIChildCount > 0 then
+    for i := 0 to MDIChildCount - 1 do
+      if MDIChildren[i].Tag >= tag then
+        tag := MDIChildren[i].Tag + 1;
+
+  iconindex := -1;
+
+  if window_context = 'binedit' then
+  begin
+    form      := TForm_BinEdit.Create(Application);
+    TForm_BinEdit(form).Recreatelist;
+    form.Caption := 'Binary .dat-Editor ' + IntToStr(tag);
+    iconindex := 0;
+  end;
+  if window_context = 'rawedit' then
+  begin
+    form      := TForm_RawEdit.Create(Application);
+    TForm_RawEdit(form).Recreatelist;
+    form.Caption := 'Binary .raw-Editor ' + IntToStr(tag);
+  end;
+  if window_context = 'preview' then
+  begin
+    form      := TForm_Preview.Create(Application);
+    TForm_Preview(form).Recreatelist;
+    form.Caption := 'Preview-Window ' + IntToStr(tag);
+  end;
+  if window_context = 'txmpreplace' then
+  begin
+    form      := TForm_TxmpReplace.Create(Application);
+    TForm_TxmpReplace(form).Recreatelist;
+    form.Caption := 'TXMP Replacer ' + IntToStr(tag);
+  end;
+  if window_context = 'extractor' then
+  begin
+    form      := TForm_Extractor.Create(Application);
+    TForm_Extractor(form).Recreatelist;
+    form.Caption := 'Extractor ' + IntToStr(tag);
+  end;
+
+  form.Name := window_context + IntToStr(tag);
+  form.Tag  := tag;
+
+  MDITab.AddTab(TForm(form), iconindex);
+end;
+
+end.
Index: oup/current/OniUnPacker.dpr
===================================================================
--- oup/current/OniUnPacker.dpr	(revision 40)
+++ oup/current/OniUnPacker.dpr	(revision 43)
@@ -1,32 +1,33 @@
-PROGRAM OniUnPacker;
+program OniUnPacker;
+
 uses
   Forms,
-  Unit1_main in 'Unit1_main.pas' {Form1},
-  Unit2_functions in 'Unit2_functions.pas',
-  Unit3_data in 'Unit3_data.pas',
-  Unit4_Exporters in 'Unit4_Exporters.pas',
-  Unit5_preview in 'Unit5_preview.pas' {Form5},
-  Unit6_imgfuncs in 'Unit6_imgfuncs.pas',
-  Unit7_txmpreplace in 'Unit7_txmpreplace.pas' {Form7},
-  Unit8_binedit in 'Unit8_binedit.pas' {Form8},
-  Unit9_data_structures in 'Unit9_data_structures.pas',
-  Unit10_leveldb in 'Unit10_leveldb.pas' {Form10},
-  Unit11_extractor in 'Unit11_extractor.pas' {Form11},
-  Unit12_ValueEdit in 'Unit12_ValueEdit.pas' {Form12},
-  Unit13_rawedit in 'Unit13_rawedit.pas' {Form13},
-  Unit14_settings in 'Unit14_settings.pas' {Form14},
+  Main in 'Main.pas' {Form_Main},
+  Code_Functions in 'Code_Functions.pas',
+  Data in 'Data.pas',
+  Code_Exporters in 'Code_Exporters.pas',
+  Tool_Preview in 'Tool_Preview.pas' {Form_Preview},
+  Code_OniImgClass in 'Code_OniImgClass.pas',
+  Tool_TxmpReplace in 'Tool_TxmpReplace.pas' {Form_TxmpReplace},
+  Tool_BinEdit in 'Tool_BinEdit.pas' {Form_BinEdit},
+  Code_DataStructures in 'Code_DataStructures.pas',
+  Helper_LevelDB in 'Helper_LevelDB.pas' {Form_LevelDB},
+  Tool_Extractor in 'Tool_Extractor.pas' {Form_Extractor},
+  Helper_ValueEdit in 'Helper_ValueEdit.pas' {Form_ValueEdit},
+  Tool_RawEdit in 'Tool_RawEdit.pas' {Form_RawEdit},
+  Settings in 'Settings.pas' {Form_Settings},
   ftypesAPI in 'TFileTypeRegistration\ftypesAPI.pas',
-  Unit15_Classes in 'Unit15_Classes.pas';
+  Code_OniDataClass in 'Code_OniDataClass.pas';
 
 {$R *.res}
 {$R icon2.res}
 
-BEGIN
+begin
   Application.Initialize;
-  Application.Title:='Oni Un/Packer';
-  Application.CreateForm(TForm1, Form1);
-  Application.CreateForm(TForm10, Form10);
-  Application.CreateForm(TForm12, Form12);
-  Application.CreateForm(TForm14, Form14);
+  Application.Title := 'Oni Un/Packer';
+  Application.CreateForm(TForm_Main, Form_Main);
+  Application.CreateForm(TForm_LevelDB, Form_LevelDB);
+  Application.CreateForm(TForm_ValueEdit, Form_ValueEdit);
+  Application.CreateForm(TForm_Settings, Form_Settings);
   Application.Run;
-END.
+end.
Index: oup/current/Settings.dfm
===================================================================
--- oup/current/Settings.dfm	(revision 43)
+++ oup/current/Settings.dfm	(revision 43)
@@ -0,0 +1,113 @@
+object Form_Settings: TForm_Settings
+  Left = 0
+  Top = 0
+  BorderStyle = bsToolWindow
+  Caption = 'Settings'
+  ClientHeight = 357
+  ClientWidth = 321
+  Color = clBtnFace
+  Font.Charset = DEFAULT_CHARSET
+  Font.Color = clWindowText
+  Font.Height = -11
+  Font.Name = 'Tahoma'
+  Font.Style = []
+  OldCreateOrder = False
+  Position = poMainFormCenter
+  OnCloseQuery = FormCloseQuery
+  OnShow = FormShow
+  PixelsPerInch = 96
+  TextHeight = 13
+  object label_charset: TLabel
+    Left = 8
+    Top = 39
+    Width = 145
+    Height = 26
+    AutoSize = False
+    Caption = 'CharSet for displaying strings in ValueViewer/StructViewer:'
+    WordWrap = True
+  end
+  object check_filesashex: TCheckBox
+    Left = 8
+    Top = 8
+    Width = 145
+    Height = 17
+    Caption = 'Show filenumbers as Hex'
+    TabOrder = 0
+  end
+  object btn_ok: TButton
+    Left = 8
+    Top = 319
+    Width = 57
+    Height = 23
+    Caption = 'OK'
+    Default = True
+    TabOrder = 1
+    OnClick = btn_okClick
+  end
+  object btn_cancel: TButton
+    Left = 120
+    Top = 319
+    Width = 57
+    Height = 23
+    Cancel = True
+    Caption = 'Cancel'
+    TabOrder = 2
+    OnClick = btn_cancelClick
+  end
+  object btn_register_oldb: TButton
+    Left = 8
+    Top = 184
+    Width = 169
+    Height = 25
+    Caption = 'Register .oldb files with OUP'
+    TabOrder = 3
+    OnClick = btn_register_oldbClick
+  end
+  object btn_register_opf: TButton
+    Left = 8
+    Top = 215
+    Width = 169
+    Height = 25
+    Caption = 'Register .opf files with OUP'
+    TabOrder = 4
+    OnClick = btn_register_opfClick
+  end
+  object btn_register_dat: TButton
+    Left = 8
+    Top = 153
+    Width = 169
+    Height = 25
+    Caption = 'Register .dat files with OUP'
+    TabOrder = 5
+    OnClick = btn_register_datClick
+  end
+  object combo_charset: TComboBox
+    Left = 160
+    Top = 40
+    Width = 156
+    Height = 21
+    Style = csDropDownList
+    ItemHeight = 13
+    ItemIndex = 0
+    TabOrder = 6
+    Text = 'default - 1'
+    Items.Strings = (
+      'default - 1'
+      'Arabic - 178'
+      'Baltic - 186'
+      'ChineseBig5 - 136'
+      'EastEurope - 238'
+      'Greek - 161'
+      'Russian - 204'
+      'Thai - 222'
+      'Turkish - 162')
+  end
+  object check_hideunused: TCheckBox
+    Left = 8
+    Top = 79
+    Width = 209
+    Height = 17
+    Caption = 'Hide "Unused" data in StructureViewer'
+    TabOrder = 7
+  end
+end
Index: oup/current/Settings.pas
===================================================================
--- oup/current/Settings.pas	(revision 43)
+++ oup/current/Settings.pas	(revision 43)
@@ -0,0 +1,220 @@
+unit Settings;
+
+interface
+
+uses
+  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
+  Dialogs, StdCtrls, StrUtils, Grids, Wrapgrid;
+
+type
+  TForm_Settings = class(TForm)
+    check_filesashex: TCheckBox;
+    btn_ok:     TButton;
+    btn_cancel: TButton;
+    btn_register_oldb: TButton;
+    btn_register_opf: TButton;
+    btn_register_dat: TButton;
+    label_charset: TLabel;
+    combo_charset: TComboBox;
+    check_hideunused: TCheckBox;
+    procedure btn_register_opfClick(Sender: TObject);
+    procedure btn_register_oldbClick(Sender: TObject);
+    procedure btn_register_datClick(Sender: TObject);
+    procedure btn_cancelClick(Sender: TObject);
+    procedure btn_okClick(Sender: TObject);
+    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
+    procedure FormShow(Sender: TObject);
+    function RegisterExtension(ext: String): Integer;
+  private
+  public
+  end;
+
+var
+  Form_Settings: TForm_Settings;
+
+implementation
+
+{$R *.dfm}
+
+uses
+  Main, Data, ftypesAPI;
+
+
+
+
+function ExtensionRegistered(ext: String; var RegisteredAs: String): Boolean;
+var
+  ftr: TFileTypeRegistration;
+begin
+  ftr := TFileTypeRegistration.Create;
+  if (ftr <> nil) then
+  begin
+    try
+      RegisteredAs := ftr.GetInternalKey(ext);
+      if RegisteredAs <> '' then
+        Result := True
+      else
+        Result := False;
+    finally
+      ftr.Free;
+    end;
+  end;
+end;
+
+
+
+
+function TForm_Settings.RegisterExtension(ext: String): Integer;
+var
+  ftr:     TFileTypeRegistration;
+  temps:   String;
+  warnmsg: String;
+begin
+  Result := -1;
+  if ExtensionRegistered(ext, temps) then
+  begin
+    if temps <> 'ONI' + ext then
+    begin
+      warnmsg := ext + '-files are not registered to OUP but as "' +
+        temps + '"-files.' + #13 + #10 + 'Do you really want to unregister' +
+        ext + '-files?';
+      if MessageBox(Self.Handle, PChar(warnmsg), PChar('Warning'), MB_YESNO) = ID_NO then
+        Exit;
+    end;
+    ftr := TFileTypeRegistration.Create;
+    if ftr <> nil then
+      try
+        if not ftr.UnregisterExtension(ext) then
+          ShowMessage('Could not unregister ' + ext + '-files')
+        else
+          Result := 2;
+      finally
+        ftr.Free;
+      end;
+  end
+  else
+  begin
+    ftr := TFileTypeRegistration.Create;
+    if ftr <> nil then
+    begin
+      try
+        if ftr.RegisterType(ext, 'ONI' + ext, 'ONI ' + ext + '-file',
+          Application.EXEname + ',1') then
+        begin
+          ftr.AddHandler('open', '"' + Application.EXEname + '" ' + MidStr(
+            ext, 2, Length(ext) - 1) + ' "%1"');
+          ftr.SetDefaultHandler;
+          Result := 1;
+        end;
+      finally
+        ftr.Free;
+      end;
+    end;
+  end;
+end;
+
+
+
+
+procedure TForm_Settings.btn_cancelClick(Sender: TObject);
+begin
+  Self.Close;
+end;
+
+
+
+
+procedure TForm_Settings.btn_okClick(Sender: TObject);
+begin
+  AppSettings.FilenumbersAsHex := check_filesashex.Checked;
+  AppSettings.CharSet := StrToInt(
+    MidStr(combo_charset.Items.Strings[combo_charset.ItemIndex], Pos(
+    ' ', combo_charset.Items.Strings[combo_charset.ItemIndex]) + 3, Length(
+    combo_charset.Items.Strings[combo_charset.ItemIndex]) - Pos(
+    ' ', combo_charset.Items.Strings[combo_charset.ItemIndex]) - 2));
+  AppSettings.HideUnusedData := check_hideunused.Checked;
+
+  Self.Close;
+end;
+
+
+
+
+procedure TForm_Settings.btn_register_datClick(Sender: TObject);
+begin
+  case RegisterExtension('.dat') of
+    2:
+      btn_register_dat.Caption := 'Register .dat files with OUP';
+    1:
+      btn_register_dat.Caption := 'Unregister .dat files';
+  end;
+end;
+
+
+
+
+procedure TForm_Settings.btn_register_oldbClick(Sender: TObject);
+begin
+  case RegisterExtension('.oldb') of
+    2:
+      btn_register_oldb.Caption := 'Register .oldb files with OUP';
+    1:
+      btn_register_oldb.Caption := 'Unregister .oldb files';
+  end;
+end;
+
+
+
+
+procedure TForm_Settings.btn_register_opfClick(Sender: TObject);
+begin
+  case RegisterExtension('.opf') of
+    2:
+      btn_register_opf.Caption := 'Register .opf files with OUP';
+    1:
+      btn_register_opf.Caption := 'Unregister .opf files';
+  end;
+end;
+
+
+
+
+procedure TForm_Settings.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
+begin
+  CanClose      := False;
+  Self.Visible  := False;
+  Form_Main.Enabled := True;
+  Form_Main.SetFocus;
+end;
+
+
+
+
+procedure TForm_Settings.FormShow(Sender: TObject);
+var
+  temps: String;
+  i:     Byte;
+begin
+  if ExtensionRegistered('.dat', temps) then
+    btn_register_dat.Caption := 'Unregister .dat files'
+  else
+    btn_register_dat.Caption := 'Register .dat files with OUP';
+  if ExtensionRegistered('.oldb', temps) then
+    btn_register_oldb.Caption := 'Unregister .oldb files'
+  else
+    btn_register_oldb.Caption := 'Register .oldb files with OUP';
+  if ExtensionRegistered('.opf', temps) then
+    btn_register_opf.Caption := 'Unregister .opf files'
+  else
+    btn_register_opf.Caption := 'Register .opf files with OUP';
+  check_filesashex.Checked := AppSettings.FilenumbersAsHex;
+  check_hideunused.Checked := AppSettings.HideUnusedData;
+
+  for i := 0 to combo_charset.Items.Count - 1 do
+    if StrToInt(MidStr(combo_charset.Items.Strings[i], Pos(
+      ' ', combo_charset.Items.Strings[i]) + 3, Length(combo_charset.Items.Strings[i]) -
+      Pos(' ', combo_charset.Items.Strings[i]) - 2)) = AppSettings.CharSet then
+      combo_charset.ItemIndex := i;
+end;
+
+end.
Index: oup/current/Tool_BinEdit.dfm
===================================================================
--- oup/current/Tool_BinEdit.dfm	(revision 43)
+++ oup/current/Tool_BinEdit.dfm	(revision 43)
@@ -0,0 +1,389 @@
+object Form_BinEdit: TForm_BinEdit
+  Left = 0
+  Top = 0
+  BorderIcons = [biSystemMenu, biMaximize]
+  Caption = 'Binary .dat-Editor'
+  ClientHeight = 555
+  ClientWidth = 642
+  Color = clBtnFace
+  Font.Charset = DEFAULT_CHARSET
+  Font.Color = clWindowText
+  Font.Height = -11
+  Font.Name = 'Tahoma'
+  Font.Style = []
+  FormStyle = fsMDIChild
+  KeyPreview = True
+  OldCreateOrder = False
+  Visible = True
+  WindowState = wsMaximized
+  OnClose = FormClose
+  OnCloseQuery = FormCloseQuery
+  OnCreate = FormCreate
+  OnKeyUp = FormKeyUp
+  OnResize = FormResize
+  PixelsPerInch = 96
+  TextHeight = 13
+  object Splitter1: TSplitter
+    Left = 200
+    Top = 0
+    Width = 9
+    Height = 555
+    AutoSnap = False
+    Beveled = True
+    MinSize = 150
+    ExplicitLeft = 150
+    ExplicitHeight = 423
+  end
+  object panel_data: TPanel
+    Left = 209
+    Top = 0
+    Width = 433
+    Height = 555
+    Align = alClient
+    BevelOuter = bvNone
+    TabOrder = 0
+    object Splitter2: TSplitter
+      Left = 0
+      Top = 209
+      Width = 433
+      Height = 9
+      Cursor = crVSplit
+      Align = alTop
+      AutoSnap = False
+      Beveled = True
+      MinSize = 40
+      ExplicitWidth = 483
+    end
+    object Splitter3: TSplitter
+      Left = 0
+      Top = 450
+      Width = 433
+      Height = 8
+      Cursor = crVSplit
+      Align = alBottom
+      AutoSnap = False
+      Beveled = True
+      MinSize = 40
+      ExplicitTop = 375
+      ExplicitWidth = 483
+    end
+    object hex: TMPHexEditor
+      Left = 0
+      Top = 0
+      Width = 433
+      Height = 209
+      Cursor = crIBeam
+      Align = alTop
+      Font.Charset = DEFAULT_CHARSET
+      Font.Color = clWindowText
+      Font.Height = -16
+      Font.Name = 'Courier'
+      Font.Style = []
+      OnKeyUp = hexKeyUp
+      ParentFont = False
+      TabOrder = 0
+      BytesPerRow = 16
+      Translation = tkASCII
+      OffsetFormat = '6!10:0x|'
+      Colors.Background = clWindow
+      Colors.ChangedBackground = clWindow
+      Colors.ChangedText = clRed
+      Colors.CursorFrame = clNavy
+      Colors.Offset = clBlack
+      Colors.OddColumn = clBlue
+      Colors.EvenColumn = clNavy
+      Colors.CurrentOffsetBackground = clBtnShadow
+      Colors.OffsetBackGround = clBtnFace
+      Colors.CurrentOffset = clBtnHighlight
+      Colors.Grid = clBtnFace
+      Colors.NonFocusCursorFrame = clAqua
+      Colors.ActiveFieldBackground = clWindow
+      FocusFrame = True
+      NoSizeChange = True
+      AllowInsertMode = False
+      DrawGridLines = False
+      Version = 'May 23, 2005; '#169' markus stephany, vcl[at]mirkes[dot]de'
+      OnChange = hexChange
+      ShowPositionIfNotFocused = True
+      OnSelectionChanged = hexSelectionChanged
+    end
+    object value_viewer: TWrapGrid
+      Left = 0
+      Top = 218
+      Width = 433
+      Height = 232
+      Align = alClient
+      ColCount = 1
+      DefaultColWidth = 80
+      DefaultRowHeight = 18
+      FixedCols = 0
+      RowCount = 8
+      FixedRows = 0
+      Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goColSizing]
+      PopupMenu = value_viewer_context
+      TabOrder = 1
+      OnDblClick = value_viewerDblClick
+      OnMouseDown = value_viewerMouseDown
+    end
+    object VST: TVirtualStringTree
+      Left = 0
+      Top = 458
+      Width = 433
+      Height = 97
+      Align = alBottom
+      AnimationDuration = 0
+      AutoExpandDelay = 300
+      BiDiMode = bdLeftToRight
+      Colors.UnfocusedSelectionColor = clGradientActiveCaption
+      Colors.UnfocusedSelectionBorderColor = clGradientActiveCaption
+      Ctl3D = True
+      DragOperations = []
+      DrawSelectionMode = smBlendedRectangle
+      EditDelay = 200
+      Font.Charset = DEFAULT_CHARSET
+      Font.Color = clWindowText
+      Font.Height = -11
+      Font.Name = 'Tahoma'
+      Font.Style = []
+      Header.AutoSizeIndex = 0
+      Header.Font.Charset = DEFAULT_CHARSET
+      Header.Font.Color = clWindowText
+      Header.Font.Height = -11
+      Header.Font.Name = 'Tahoma'
+      Header.Font.Style = []
+      Header.Options = [hoColumnResize, hoDblClickResize, hoDrag, hoVisible]
+      Header.PopupMenu = VTHPopup
+      Header.Style = hsFlatButtons
+      HintAnimation = hatNone
+      HintMode = hmTooltip
+      Indent = 14
+      ParentBiDiMode = False
+      ParentCtl3D = False
+      ParentFont = False
+      ParentShowHint = False
+      ShowHint = True
+      TabOrder = 2
+      TreeOptions.MiscOptions = [toAcceptOLEDrop, toCheckSupport, toFullRepaintOnResize, toInitOnSave, toToggleOnDblClick, toWheelPanning]
+      TreeOptions.PaintOptions = [toShowButtons, toShowDropmark, toShowHorzGridLines, toShowRoot, toShowTreeLines, toShowVertGridLines, toUseBlendedImages]
+      TreeOptions.SelectionOptions = [toExtendedFocus, toFullRowSelect, toRightClickSelect]
+      OnDblClick = VSTDblClick
+      OnFocusChanged = VSTFocusChanged
+      OnGetText = VSTGetText
+      OnHeaderDragged = VSTHeaderDragged
+      Columns = <
+        item
+          MaxWidth = 300
+          MinWidth = 100
+          Options = [coEnabled, coParentBidiMode, coParentColor, coResizable, coShowDropMark, coVisible]
+          Position = 0
+          Spacing = 20
+          Width = 150
+          WideText = 'Name'
+          WideHint = 'Name of the item.'
+        end
+        item
+          MaxWidth = 110
+          MinWidth = 80
+          Options = [coDraggable, coEnabled, coParentBidiMode, coParentColor, coResizable, coShowDropMark, coVisible]
+          Position = 1
+          Spacing = 20
+          Width = 85
+          WideText = 'Offset'
+          WideHint = 'Offset of the data-item.'
+        end
+        item
+          MaxWidth = 110
+          MinWidth = 75
+          Options = [coDraggable, coEnabled, coParentBidiMode, coParentColor, coResizable, coShowDropMark, coVisible]
+          Position = 2
+          Width = 75
+          WideText = 'Type'
+          WideHint = 'Data type of the item.'
+        end
+        item
+          MaxWidth = 250
+          MinWidth = 80
+          Options = [coDraggable, coEnabled, coParentBidiMode, coParentColor, coResizable, coShowDropMark, coVisible]
+          Position = 3
+          Width = 100
+          WideText = 'Value'
+          WideHint = 'Value of the item.'
+        end
+        item
+          MaxWidth = 400
+          MinWidth = 80
+          Options = [coDraggable, coEnabled, coParentBidiMode, coParentColor, coResizable, coShowDropMark, coVisible]
+          Position = 4
+          Width = 400
+          WideText = 'Description'
+        end>
+      WideDefaultText = ''
+    end
+  end
+  object panel_files: TPanel
+    Left = 0
+    Top = 0
+    Width = 200
+    Height = 555
+    Align = alLeft
+    BevelOuter = bvNone
+    TabOrder = 1
+    object Bevel1: TBevel
+      Left = 0
+      Top = 491
+      Width = 200
+      Height = 6
+      Align = alBottom
+      Style = bsRaised
+      ExplicitTop = 359
+      ExplicitWidth = 150
+    end
+    object list: TListBox
+      Left = 0
+      Top = 0
+      Width = 200
+      Height = 388
+      Align = alClient
+      ItemHeight = 13
+      TabOrder = 0
+      OnClick = listClick
+      OnMouseDown = listMouseDown
+    end
+    object panel_extension: TPanel
+      Left = 0
+      Top = 388
+      Width = 200
+      Height = 103
+      Align = alBottom
+      BevelOuter = bvNone
+      TabOrder = 1
+      OnResize = panel_extensionResize
+      object lbl_filter: TLabel
+        Left = 2
+        Top = 62
+        Width = 100
+        Height = 17
+        AutoSize = False
+        Caption = 'Filter by &extension:'
+        FocusControl = combo_extension
+      end
+      object combo_extension: TComboBox
+        Left = 2
+        Top = 76
+        Width = 145
+        Height = 21
+        Style = csDropDownList
+        DropDownCount = 12
+        Font.Charset = DEFAULT_CHARSET
+        Font.Color = clWindowText
+        Font.Height = -11
+        Font.Name = 'Tahoma'
+        Font.Style = []
+        ItemHeight = 13
+        ParentFont = False
+        Sorted = True
+        TabOrder = 3
+        OnClick = combo_extensionClick
+      end
+      object check_zerobyte: TCheckBox
+        Left = 2
+        Top = 44
+        Width = 130
+        Height = 13
+        Caption = 'Show &zero-byte files'
+        TabOrder = 2
+        OnClick = check_zerobyteClick
+      end
+      object edit_filtername: TEdit
+        Left = 2
+        Top = 20
+        Width = 145
+        Height = 18
+        AutoSize = False
+        TabOrder = 1
+      end
+      object check_filtername: TCheckBox
+        Left = 2
+        Top = 5
+        Width = 130
+        Height = 15
+        Caption = 'Filter by file&name:'
+        TabOrder = 0
+        OnClick = check_filternameClick
+      end
+    end
+    object panel_imexport: TPanel
+      Left = 0
+      Top = 497
+      Width = 200
+      Height = 58
+      Align = alBottom
+      BevelOuter = bvNone
+      TabOrder = 2
+      OnResize = panel_imexportResize
+      object btn_export: TButton
+        Left = 4
+        Top = 4
+        Width = 142
+        Height = 25
+        Caption = 'Export to file...'
+        TabOrder = 0
+        OnClick = btn_exportClick
+      end
+      object btn_import: TButton
+        Left = 4
+        Top = 32
+        Width = 142
+        Height = 25
+        Caption = 'Import from file...'
+        TabOrder = 1
+        OnClick = btn_importClick
+      end
+    end
+  end
+  object opend: TOpenDialog
+    Options = [ofPathMustExist, ofFileMustExist, ofEnableSizing]
+    Left = 120
+    Top = 392
+  end
+  object saved: TSaveDialog
+    Options = [ofOverwritePrompt, ofPathMustExist, ofEnableSizing]
+    Left = 120
+    Top = 368
+  end
+  object value_viewer_context: TPopupMenu
+    AutoHotkeys = maManual
+    OnPopup = value_viewer_contextPopup
+    Left = 240
+    Top = 248
+    object value_viewer_context_copy: TMenuItem
+      Caption = 'Copy to &clipboard'
+      OnClick = value_viewer_context_copyClick
+    end
+    object value_viewer_context_copyasdec: TMenuItem
+      Caption = 'Copy to clipboard (as &dec)'
+      OnClick = value_viewer_context_copyClick
+    end
+    object value_viewer_context_copyasfloat: TMenuItem
+      Caption = 'Copy to clipboard (as &float)'
+      OnClick = value_viewer_context_copyClick
+    end
+    object value_viewer_context_copyasbitset: TMenuItem
+      Caption = 'Copy to clipboard (as &bitset)'
+      OnClick = value_viewer_context_copyClick
+    end
+    object value_viewer_context_copyasstring: TMenuItem
+      Caption = 'Copy to clipboard (as &string)'
+      OnClick = value_viewer_context_copyClick
+    end
+    object value_viewer_context_copyashex: TMenuItem
+      Caption = 'Copy to clipboard (as &hex)'
+      OnClick = value_viewer_context_copyClick
+    end
+  end
+  object VTHPopup: TVTHeaderPopupMenu
+    OnColumnChange = VTHPopupColumnChange
+    Left = 200
+    Top = 496
+  end
+end
Index: oup/current/Tool_BinEdit.pas
===================================================================
--- oup/current/Tool_BinEdit.pas	(revision 43)
+++ oup/current/Tool_BinEdit.pas	(revision 43)
@@ -0,0 +1,1198 @@
+unit Tool_BinEdit;
+
+interface
+
+uses
+  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
+  Dialogs, Wrapgrid, StdCtrls, Grids, StrUtils, MPHexEditor, ExtCtrls, Clipbrd,
+  Data, Code_Functions, Code_DataStructures, Code_Exporters, Code_OniDataClass,
+  Menus, Math, VirtualTrees, VTHeaderPopup;
+
+type
+  TForm_BinEdit = class(TForm)
+    Splitter1: TSplitter;
+    panel_data: TPanel;
+    hex:      TMPHexEditor;
+    Splitter2: TSplitter;
+    panel_files: TPanel;
+    list:     TListBox;
+    panel_extension: TPanel;
+    lbl_filter: TLabel;
+    combo_extension: TComboBox;
+    Bevel1:   TBevel;
+    panel_imexport: TPanel;
+    btn_export: TButton;
+    btn_import: TButton;
+    opend:    TOpenDialog;
+    saved:    TSaveDialog;
+    value_viewer: TWrapGrid;
+    Splitter3: TSplitter;
+    value_viewer_context: TPopupMenu;
+    value_viewer_context_copy: TMenuItem;
+    value_viewer_context_copyashex: TMenuItem;
+    value_viewer_context_copyasdec: TMenuItem;
+    value_viewer_context_copyasfloat: TMenuItem;
+    value_viewer_context_copyasbitset: TMenuItem;
+    value_viewer_context_copyasstring: TMenuItem;
+    check_zerobyte: TCheckBox;
+    edit_filtername: TEdit;
+    check_filtername: TCheckBox;
+    VST:      TVirtualStringTree;
+    VTHPopup: TVTHeaderPopupMenu;
+    procedure VSTFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode;
+      Column: TColumnIndex);
+    procedure VSTDblClick(Sender: TObject);
+    procedure VTHPopupColumnChange(const Sender: TBaseVirtualTree;
+      const Column: TColumnIndex; Visible: Boolean);
+    procedure VSTHeaderDragged(Sender: TVTHeader; Column: TColumnIndex;
+      OldPosition: Integer);
+    procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
+      Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
+    procedure hexKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
+    procedure LoadDat(_fileid: LongWord);
+    procedure LoadFileNames;
+    procedure check_filternameClick(Sender: TObject);
+    procedure check_zerobyteClick(Sender: TObject);
+    procedure combo_extensionClick(Sender: TObject);
+    procedure panel_extensionResize(Sender: TObject);
+    procedure listClick(Sender: TObject);
+    procedure Recreatelist;
+
+    procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
+    procedure value_viewerDblClick(Sender: TObject);
+    procedure value_viewer_context_copyClick(Sender: TObject);
+    procedure value_viewerMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure value_viewer_contextPopup(Sender: TObject);
+    procedure btn_importClick(Sender: TObject);
+    procedure btn_exportClick(Sender: TObject);
+    procedure panel_imexportResize(Sender: TObject);
+    function Save: Boolean;
+    procedure FormClose(Sender: TObject; var Action: TCloseAction);
+    function GetValue(datatype: Word; offset: LongWord): String;
+    procedure WriteStructureInfos; //(structinfoid:Integer);
+    procedure hexSelectionChanged(Sender: TObject);
+    procedure hexChange(Sender: TObject);
+    procedure FormResize(Sender: TObject);
+    procedure ClearStructViewer;
+    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
+    procedure FormCreate(Sender: TObject);
+    procedure ClearValues;
+    procedure WriteValues;
+    procedure SetNewValue(datatype: Word; offset: LongWord; Value: String);
+    procedure listMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+  private
+    fileid: LongWord;
+  public
+  end;
+
+var
+  Form_BinEdit: TForm_BinEdit;
+
+implementation
+
+{$R *.dfm}
+
+uses Main, Helper_ValueEdit, Tool_Rawedit;
+
+type
+  PNodeData = ^TNodeData;
+
+  TNodeData = record
+    Caption:  String;
+    Offset:   LongInt;
+    DataType: Word;
+    Value:    String;
+    Description: String;
+  end;
+
+
+
+
+function AddVSTEntry(AVST: TCustomVirtualStringTree; ANode: PVirtualNode;
+  ARecord: TNodeData): PVirtualNode;
+var
+  Data: PNodeData;
+begin
+  Result := AVST.AddChild(ANode);
+  Data   := AVST.GetNodeData(Result);
+  AVST.ValidateNode(Result, False);
+  Data^ := ARecord;
+end;
+
+
+
+
+procedure TForm_BinEdit.LoadDat(_fileid: LongWord);
+var
+  i:    LongWord;
+  mem:  TMemoryStream;
+  Data: Tdata;
+begin
+  if hex.Modified then
+  begin
+    if not Save then
+    begin
+      for i := 0 to list.Count - 1 do
+      begin
+        if OniDataConnection.ExtractFileID(list.Items.Strings[i]) = fileid then
+        begin
+          list.ItemIndex := i;
+          Exit;
+        end;
+      end;
+    end;
+  end;
+  fileid := _fileid;
+  for i := 0 to list.Count - 1 do
+    if OniDataConnection.ExtractFileID(list.Items.Strings[i]) = fileid then
+    begin
+      list.ItemIndex := i;
+      Break;
+    end;
+  Self.ClearStructViewer;
+  Data := OniDataConnection.LoadDatFile(fileid);
+  if Length(Data) > 0 then
+  begin
+    mem := TMemoryStream.Create;
+    mem.Write(Data[0], Length(Data));
+    mem.Seek(0, soFromBeginning);
+    hex.LoadFromStream(mem);
+    mem.Free;
+    WriteStructureInfos;
+  end
+  else
+  begin
+    ClearValues;
+    hex.DataSize := 0;
+  end;
+end;
+
+
+
+
+procedure TForm_BinEdit.Recreatelist;
+var
+  i:    LongWord;
+  exts: TStringArray;
+begin
+  combo_extension.Items.Clear;
+  combo_extension.Items.Add('_All files_ (' + IntToStr(
+    OniDataConnection.GetFilesCount) + ')');
+  exts := OniDataConnection.GetExtensionsList;
+  for i := 0 to High(exts) do
+    combo_extension.Items.Add(exts[i]);
+  combo_extension.ItemIndex := 0;
+  combo_extensionClick(Self);
+end;
+
+
+
+
+procedure TForm_BinEdit.LoadFileNames;
+var
+  Extension: String[4];
+  no_zero_bytes: Boolean;
+  pattern: String;
+  files: TStringArray;
+  i: LongWord;
+begin
+  Extension := MidStr(combo_extension.Items.Strings[combo_extension.ItemIndex], 1, 4);
+  no_zero_bytes := not check_zerobyte.Checked;
+  pattern := '';
+  if check_filtername.Checked then
+    pattern := edit_filtername.Text;
+  if Extension = '_All' then
+    Extension := '';
+
+  files := OniDataConnection.GetFilesList(extension, pattern, no_zero_bytes);
+  list.Items.Clear;
+  if Length(files) > 0 then
+    for i := 0 to High(files) do
+      list.Items.Add(files[i]);
+end;
+
+
+
+
+procedure TForm_BinEdit.panel_extensionResize(Sender: TObject);
+begin
+  combo_extension.Width := panel_extension.Width - 5;
+  edit_filtername.Width := panel_extension.Width - 5;
+end;
+
+
+
+
+procedure TForm_BinEdit.combo_extensionClick(Sender: TObject);
+begin
+  LoadFileNames;
+end;
+
+
+
+
+procedure TForm_BinEdit.check_zerobyteClick(Sender: TObject);
+begin
+  LoadFileNames;
+end;
+
+
+
+
+procedure TForm_BinEdit.check_filternameClick(Sender: TObject);
+begin
+  edit_filtername.Enabled := not check_filtername.Checked;
+  LoadFileNames;
+end;
+
+
+
+
+procedure TForm_BinEdit.listClick(Sender: TObject);
+begin
+  LoadDat(OniDataConnection.ExtractFileID(list.Items.Strings[list.ItemIndex]));
+end;
+
+
+
+
+procedure TForm_BinEdit.listMouseDown(Sender: TObject; Button: TMouseButton;
+  Shift: TShiftState; X, Y: Integer);
+var
+  pt: TPoint;
+begin
+  pt.X := x;
+  pt.Y := y;
+  list.ItemIndex := list.ItemAtPos(pt, true);
+  if list.ItemIndex > -1 then
+    Self.listClick(Self);
+end;
+
+function IntToBin(Value: Byte): String;
+var
+  i: Byte;
+begin
+  Result := '';
+  for i := 7 downto 0 do
+  begin
+    Result := Result + IntToStr((Value shr i) and $01);
+  end;
+end;
+
+
+
+
+function TForm_BinEdit.GetValue(datatype: Word; offset: LongWord): String;
+var
+  Data: Tdata;
+  i:    Word;
+begin
+  case datatype of
+    1:
+      Result := IntToStr(hex.Data[offset]);
+    2:
+      Result := IntToStr(hex.Data[offset] + hex.Data[offset + 1] * 256);
+    3:
+      Result := IntToStr(hex.Data[offset] + hex.Data[offset + 1] * 256 + hex.Data[offset + 2] * 256 * 256);
+    4:
+      Result := IntToStr(hex.Data[offset] + hex.Data[offset + 1] * 256 + hex.Data[offset + 2] *
+        256 * 256 + hex.Data[offset + 3] * 256 * 256 * 256);
+    5:
+      Result := '0x' + IntToHex(hex.Data[offset], 2);
+    6:
+      Result := '0x' + IntToHex(hex.Data[offset] + hex.Data[offset + 1] * 256, 4);
+    7:
+      Result := '0x' + IntToHex(hex.Data[offset] + hex.Data[offset + 1] * 256 +
+        hex.Data[offset + 2] * 256 * 256, 6);
+    8:
+      Result := '0x' + IntToHex(hex.Data[offset] + hex.Data[offset + 1] * 256 +
+        hex.Data[offset + 2] * 256 * 256 + hex.Data[offset + 3] * 256 * 256 * 256, 8);
+    9:
+    begin
+      SetLength(Data, 4);
+      Data[0] := hex.Data[offset];
+      Data[1] := hex.Data[offset + 1];
+      Data[2] := hex.Data[offset + 2];
+      Data[3] := hex.Data[offset + 3];
+      Result  := FloatToStr(Decode_Float(Data));
+    end;
+    10:
+      Result := IntToBin(hex.Data[offset]);
+    11:
+      Result := '0x' + IntToHex(OniDataConnection.GetRawInfo(fileid, offset).raw_addr, 8);
+    12:
+      Result := FormatNumber(hex.Data[offset + 1] + hex.Data[offset + 2] * 256 +
+        hex.Data[offset + 3] * 256 * 256, 5, '0');
+    13:
+      Result := IntToStr(hex.Data[offset]);
+    14:
+      Result := IntToStr(hex.Data[offset] + hex.Data[offset + 1] * 256);
+    15:
+      Result := IntToStr(hex.Data[offset] + hex.Data[offset + 1] * 256 + hex.Data[offset + 2] * 256 * 256);
+    16:
+      Result := IntToStr(hex.Data[offset] + hex.Data[offset + 1] * 256 + hex.Data[offset + 2] *
+        256 * 256 + hex.Data[offset + 3] * 256 * 256 * 256);
+    17:
+      Result := IntToStr((hex.Data[offset + 3]) div 2);
+    100..300:
+    begin
+      Result := '';
+      for i := 1 to datatype - 100 do
+      begin
+        if hex.Data[offset + i - 1] >= 32 then
+          Result := Result + Chr(hex.Data[offset + i - 1])
+        else
+          Break;
+      end;
+    end;
+    1000..9999:
+    begin
+      Result := '';
+      for i := 1 to datatype - 1000 do
+      begin
+        if hex.Data[offset + i - 1] >= 32 then
+          Result := Result + Chr(hex.Data[offset + i - 1])
+        else
+          Result := Result + '.';
+      end;
+    end;
+    10000..65535:
+    begin
+      Result := '';
+      for i := 1 to datatype - 10000 do
+      begin
+        if hex.Data[offset + i - 1] >= 32 then
+          Result := Result + Chr(hex.Data[offset + i - 1])
+        else
+          Result := Result + '.';
+      end;
+    end;
+  end;
+end;
+
+
+
+
+procedure TForm_BinEdit.WriteStructureInfos;
+var
+  i, j:    LongWord;
+  pdata:   PNodeData;
+  Data:    TNodeData;
+  node:    PVirtualNode;
+  structs: TStructDef;
+begin
+  VST.BeginUpdate;
+  if VST.RootNodeCount = 0 then
+  begin
+    structs := LoadStructureDefinition(fileid);
+    if structs.Data then
+    begin
+      if Length(structs.Global) > 0 then
+      begin
+        for i := 0 to High(structs.Global) do
+        begin
+          Data.Caption  := structs.Global[i].Name;
+          Data.Offset   := structs.Global[i].offset;
+          Data.DataType := structs.Global[i].datatype;
+          Data.Value    := GetValue(structs.Global[i].datatype, structs.Global[i].offset);
+          Data.Description := structs.Global[i].description;
+          AddVSTEntry(VST, nil, Data);
+        end;
+      end;
+      if Length(structs.Subs) > 0 then
+      begin
+        for i := 0 to High(structs.Subs) do
+        begin
+          with structs.Subs[i] do
+          begin
+            if Length(Entries) > 0 then
+            begin
+              if Pos('#', SubName) > 0 then
+              begin
+                Data.Offset  := HexToLong(MidStr(SubName, Pos('#', SubName) + 1, 8));
+                Data.Value   :=
+                  MidStr(SubName, PosEx('#', SubName, Pos('#', SubName) + 1) + 1, 8);
+                Data.Caption := MidStr(SubName, 1, Pos('#', SubName) - 1);
+                Data.Description := SubDesc;
+              end
+              else
+              begin
+                Data.Caption := SubName;
+                Data.Description := SubDesc;
+                Data.Offset := 0;
+                Data.Value := '';
+              end;
+              Data.DataType := 0;
+              node := AddVSTEntry(VST, nil, Data);
+              Data.Description := '';
+              for j := 0 to High(Entries) do
+              begin
+                Data.Caption  := Entries[j].Name;
+                Data.Offset   := Entries[j].offset;
+                Data.DataType := Entries[j].datatype;
+                Data.Value    := GetValue(Entries[j].datatype, Entries[j].offset);
+                Data.Description := Entries[j].description;
+                AddVSTEntry(VST, node, Data);
+              end;
+            end;
+          end;
+        end;
+      end;
+    end;
+    if VST.RootNodeCount > 0 then
+      VST.FocusedNode := VST.GetFirst;
+  end
+  else
+  begin
+    Node := VST.GetFirst;
+    while Assigned(Node) do
+    begin
+      pdata := VST.GetNodeData(Node);
+      if pdata.DataType > 0 then
+        pdata.Value := GetValue(pdata.Datatype, pdata.Offset);
+      Node := VST.GetNext(Node);
+    end;
+  end;
+  VST.EndUpdate;
+end;
+
+
+
+
+procedure TForm_BinEdit.ClearValues;
+var
+  i: Byte;
+begin
+  for i := 1 to value_viewer.RowCount - 1 do
+  begin
+    value_viewer.Cells[1, i] := '';
+  end;
+end;
+
+
+
+
+procedure TForm_BinEdit.WriteValues;
+var
+  i, j:  Byte;
+  Data:  Tdata;
+  str:   String;
+  Value: LongWord;
+begin
+  for i := 1 to value_viewer.RowCount - 1 do
+  begin
+    if value_viewer.Cells[0, i] = '1 byte, unsigned' then
+    begin
+      if ((hex.SelCount = 1) or (hex.SelCount = 0)) and not
+        ((hex.SelStart + 1) > hex.DataSize) then
+      begin
+        Value := hex.Data[hex.SelStart];
+        value_viewer.Cells[1, i] := IntToStr(Value) + ' / 0x' + IntToHex(Value, 2);
+      end
+      else
+        value_viewer.Cells[1, i] := '';
+    end;
+    if value_viewer.Cells[0, i] = '2 bytes, unsigned' then
+    begin
+      if ((hex.SelCount = 2) or (hex.SelCount = 0)) and not
+        ((hex.SelStart + 2) > hex.DataSize) then
+      begin
+        Value := hex.Data[hex.SelStart] + hex.Data[hex.SelStart + 1] * 256;
+        value_viewer.Cells[1, i] := IntToStr(Value) + ' / 0x' + IntToHex(Value, 4);
+      end
+      else
+        value_viewer.Cells[1, i] := '';
+    end;
+    if value_viewer.Cells[0, i] = '4 bytes, unsigned' then
+    begin
+      if ((hex.SelCount = 4) or (hex.SelCount = 0)) and not
+        ((hex.SelStart + 4) > hex.DataSize) then
+      begin
+        Value := hex.Data[hex.SelStart] + hex.Data[hex.SelStart + 1] * 256 +
+          hex.Data[hex.SelStart + 2] * 256 * 256 + hex.Data[hex.SelStart + 3] * 256 * 256 * 256;
+        value_viewer.Cells[1, i] := IntToStr(Value) + ' / 0x' + IntToHex(Value, 8);
+      end
+      else
+        value_viewer.Cells[1, i] := '';
+    end;
+    if value_viewer.Cells[0, i] = 'Bitset' then
+    begin
+      if (hex.SelCount <= 8) then
+      begin
+        if hex.SelCount = 0 then
+        begin
+          SetLength(Data, 1);
+          Data[0] := hex.Data[hex.SelStart];
+        end
+        else
+        begin
+          SetLength(Data, hex.SelCount);
+          for j := 0 to hex.SelCount - 1 do
+            Data[j] := hex.Data[hex.SelStart + j];
+        end;
+        value_viewer.Cells[1, i] := DataToBin(Data);
+      end
+      else
+        value_viewer.Cells[1, i] := '';
+    end;
+    if value_viewer.Cells[0, i] = 'Float' then
+    begin
+      if ((hex.SelCount = 4) or (hex.SelCount = 0)) and not
+        ((hex.SelStart + 4) > hex.DataSize) then
+      begin
+        SetLength(Data, 4);
+        for j := 0 to 3 do
+          Data[j] := hex.Data[hex.SelStart + j];
+        value_viewer.Cells[1, i] := FloatToStr(Decode_Float(Data));
+      end
+      else
+        value_viewer.Cells[1, i] := '';
+    end;
+    if value_viewer.Cells[0, i] = 'Selected length' then
+    begin
+      value_viewer.Cells[1, i] := IntToStr(hex.SelCount) + ' bytes';
+    end;
+    if value_viewer.Cells[0, i] = 'String' then
+    begin
+      j   := 0;
+      str := '';
+      if hex.SelCount = 0 then
+      begin
+        while (hex.Data[hex.SelStart + j] > 0) and ((hex.SelStart + j) < hex.DataSize) do
+        begin
+          if hex.Data[hex.selstart + j] >= 32 then
+            str := str + Char(hex.Data[hex.SelStart + j])
+          else
+            str := str + '.';
+          Inc(j);
+        end;
+      end
+      else
+      begin
+        for j := 0 to hex.SelCount - 1 do
+          if hex.Data[hex.selstart + j] >= 32 then
+            str := str + Char(hex.Data[hex.SelStart + j])
+          else if hex.Data[hex.selstart + j] > 0 then
+            str := str + '.'
+          else
+            Break;
+      end;
+      value_viewer.Cells[1, i] := str;
+    end;
+  end;
+end;
+
+
+
+
+procedure TForm_BinEdit.FormCreate(Sender: TObject);
+begin
+  Self.Caption := '';
+  fileid     := 0;
+  VST.NodeDataSize := SizeOf(TNodeData);
+  value_viewer.ColCount := 2;
+  value_viewer.RowCount := 8;
+  value_viewer.FixedRows := 1;
+  value_viewer.Cells[0, 0] := 'Type';
+  value_viewer.Cells[1, 0] := 'Value';
+  value_viewer.Cells[0, 1] := '1 byte, unsigned';
+  value_viewer.Cells[0, 2] := '2 bytes, unsigned';
+  value_viewer.Cells[0, 3] := '4 bytes, unsigned';
+  value_viewer.Cells[0, 4] := 'Bitset';
+  value_viewer.Cells[0, 5] := 'Float';
+  value_viewer.Cells[0, 6] := 'String';
+  value_viewer.Cells[0, 7] := 'Selected length';
+  value_viewer.ColWidths[0] := 100;
+  value_viewer.ColWidths[1] := value_viewer.Width - 150;
+  hex.Height := panel_data.Height - 215;
+  //
+  value_viewer.Font.Charset := AppSettings.CharSet;
+  VST.Font.Charset := AppSettings.CharSet;
+  hex.Translation := tkAsIs;
+  hex.Font.Charset := AppSettings.CharSet;
+  //
+end;
+
+
+
+
+function TForm_BinEdit.Save: Boolean;
+var
+  mem:  TMemoryStream;
+  Data: Tdata;
+  i:    LongWord;
+begin
+  case MessageBox(Self.Handle, PChar('Save changes to file ' +
+      OniDataConnection.GetFileInfo(fileid).FileName + '?'), PChar('Data changed...'),
+      MB_YESNOCANCEL) of
+    idYes:
+    begin
+      mem := TMemoryStream.Create;
+      hex.SaveToStream(mem);
+      mem.Seek(0, soFromBeginning);
+      SetLength(Data, mem.Size);
+      mem.Read(Data[0], mem.Size);
+      mem.Free;
+      OniDataConnection.UpdateDatFile(fileid, Data);
+      hex.Modified := False;
+      for i := 0 to hex.Datasize - 1 do
+        hex.ByteChanged[i] := False;
+      Result := True;
+    end;
+    idNo:
+      Result := True;
+    idCancel:
+    begin
+      Result := False;
+    end;
+  end;
+end;
+
+
+
+
+procedure TForm_BinEdit.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
+begin
+  if hex.Modified then
+  begin
+    if not Save then
+      CanClose := False;
+  end;
+end;
+
+
+
+
+procedure TForm_BinEdit.ClearStructViewer;
+begin
+  VST.Clear;
+end;
+
+
+
+
+procedure TForm_BinEdit.FormResize(Sender: TObject);
+begin
+  if Self.Width >= 650 then
+  begin
+  end
+  else
+    Self.Width := 650;
+  if Self.Height >= 450 then
+  begin
+  end
+  else
+    Self.Height := 450;
+end;
+
+
+
+
+procedure TForm_BinEdit.hexChange(Sender: TObject);
+begin
+  ClearValues;
+  if hex.DataSize > 0 then
+  begin
+    WriteStructureInfos;
+    WriteValues;
+  end;
+end;
+
+
+
+
+procedure TForm_BinEdit.hexKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
+var
+  temps: String;
+begin
+  if (Shift = [ssCtrl]) and (Key = Ord('C')) then
+  begin
+    if hex.SelCount > 0 then
+    begin
+      if hex.InCharField then
+        Clipboard.AsText := hex.SelectionAsText
+      else
+        Clipboard.AsText := hex.SelectionAsHex;
+    end;
+  end;
+  if (Shift = [ssCtrl]) and (Key = Ord('V')) then
+  begin
+{      temps:=Clipboard.AsText;
+      IF hex.SelStart+Length(temps)>hex.DataSize THEN
+        SetLength(temps, hex.DataSize-hex.SelStart);
+      hex.Sel
+      hex.SelCount:=Length(temps);
+      hex.ReplaceSelection(temps,Length(temps));
+}    end;
+end;
+
+
+
+
+procedure TForm_BinEdit.hexSelectionChanged(Sender: TObject);
+var
+  selstart: Integer;
+  node:     PVirtualNode;
+  pdata:    PNodeData;
+begin
+  if hex.DataSize > 0 then
+  begin
+    WriteValues;
+    selstart := hex.SelStart;
+    if VST.RootNodeCount > 0 then
+    begin
+      Node := VST.GetFirst;
+      while Assigned(Node) do
+      begin
+        pdata := VST.GetNodeData(Node);
+        if pdata.DataType > 0 then
+        begin
+          if ((selstart - pdata.Offset) < GetTypeDataLength(pdata.DataType)) and
+            ((selstart - pdata.Offset) >= 0) then
+          begin
+            VST.FocusedNode    := Node;
+            VST.Selected[Node] := True;
+            Break;
+          end;
+        end;
+        Node := VST.GetNext(Node);
+      end;
+    end;
+  end;
+end;
+
+
+
+
+procedure TForm_BinEdit.FormClose(Sender: TObject; var Action: TCloseAction);
+begin
+  Action := caFree;
+end;
+
+
+
+
+procedure TForm_BinEdit.panel_imexportResize(Sender: TObject);
+begin
+  btn_import.Width := panel_imexport.Width - 8;
+  btn_export.Width := panel_imexport.Width - 8;
+end;
+
+
+
+
+procedure TForm_BinEdit.btn_exportClick(Sender: TObject);
+begin
+  saved.Filter     := 'Files of matching extension (*.' + OniDataConnection.GetFileInfo(
+    fileid).Extension + ')|*.' + OniDataConnection.GetFileInfo(fileid).Extension +
+    '|All files|*.*';
+  saved.DefaultExt := OniDataConnection.GetFileInfo(fileid).Extension;
+  if saved.Execute then
+  begin
+    ExportDatFile(fileid, saved.FileName);
+  end;
+end;
+
+
+
+
+procedure TForm_BinEdit.btn_importClick(Sender: TObject);
+var
+  fs: TFileStream;
+begin
+  opend.Filter := 'Files of matching extension (*.' + OniDataConnection.GetFileInfo(
+    fileid).Extension + ')|*.' + OniDataConnection.GetFileInfo(fileid).Extension +
+    '|All files|*.*';
+  if opend.Execute then
+  begin
+    fs := TFileStream.Create(opend.FileName, fmOpenRead);
+    if fs.Size <> hex.DataSize then
+    begin
+      ShowMessage('Can''t import ' + ExtractFilename(opend.FileName) +
+        ', file has to have same size as file in .dat.' + CrLf +
+        'Size of file in .dat: ' + FormatFileSize(hex.datasize) + CrLf +
+        'Size of chosen file: ' + FormatFileSize(fs.Size));
+    end
+    else
+    begin
+      hex.LoadFromStream(fs);
+      hex.Modified := True;
+    end;
+    fs.Free;
+  end;
+end;
+
+
+
+
+procedure TForm_BinEdit.value_viewer_contextPopup(Sender: TObject);
+var
+  i: Byte;
+begin
+  for i := 0 to value_viewer_context.Items.Count - 1 do
+    value_viewer_context.Items.Items[i].Visible := False;
+  with value_viewer do
+  begin
+    if (Col = 1) and (Row > 0) and (Length(Cells[Col, Row]) > 0) then
+    begin
+      if Pos(' byte', Cells[0, Row]) = 2 then
+      begin
+        value_viewer_context.Items.Find('Copy to &clipboard').Visible := True;
+        value_viewer_context.Items.Find('Copy to clipboard (as &dec)').Visible := True;
+        value_viewer_context.Items.Find('Copy to clipboard (as &hex)').Visible := True;
+      end;
+      if Pos('Float', Cells[0, Row]) = 1 then
+        value_viewer_context.Items.Find('Copy to clipboard (as &float)').Visible := True;
+      if Pos('Bitset', Cells[0, Row]) = 1 then
+        value_viewer_context.Items.Find(
+          'Copy to clipboard (as &bitset)').Visible := True;
+      if Pos('String', Cells[0, Row]) = 1 then
+        value_viewer_context.Items.Find(
+          'Copy to clipboard (as &string)').Visible := True;
+      if Pos('Selected length', Cells[0, Row]) = 1 then
+        value_viewer_context.Items.Find('Copy to &clipboard').Visible := True;
+    end;
+  end;
+end;
+
+
+
+
+procedure TForm_BinEdit.value_viewerMouseDown(Sender: TObject; Button: TMouseButton;
+  Shift: TShiftState; X, Y: Integer);
+var
+  ACol, ARow: Integer;
+begin
+  if Button = mbRight then
+  begin
+    value_viewer.MouseToCell(x, y, ACol, ARow);
+    if ARow > 0 then
+    begin
+      value_viewer.Col := ACol;
+      value_viewer.Row := ARow;
+    end;
+  end;
+end;
+
+
+
+
+procedure TForm_BinEdit.value_viewer_context_copyClick(Sender: TObject);
+var
+  Name:  String;
+  Value: LongWord;
+begin
+  Name := TMenuItem(Sender).Name;
+  if Pos('asstring', Name) > 0 then
+  begin
+    Clipboard.AsText := value_viewer.Cells[value_viewer.Col, value_viewer.Row];
+  end
+  else if Pos('asfloat', Name) > 0 then
+  begin
+    Clipboard.AsText := value_viewer.Cells[value_viewer.Col, value_viewer.Row];
+  end
+  else if Pos('asbitset', Name) > 0 then
+  begin
+    Clipboard.AsText := value_viewer.Cells[value_viewer.Col, value_viewer.Row];
+  end
+  else if (Pos('ashex', Name) > 0) or (Pos('asdec', Name) > 0) then
+  begin
+    if value_viewer.Cells[0, value_viewer.Row] = '1 byte, unsigned' then
+    begin
+      if ((hex.SelCount = 1) or (hex.SelCount = 0)) and not
+        ((hex.SelStart + 1) > hex.DataSize) then
+        Value := hex.Data[hex.SelStart];
+    end;
+    if value_viewer.Cells[0, value_viewer.Row] = '2 bytes, unsigned' then
+    begin
+      if ((hex.SelCount = 2) or (hex.SelCount = 0)) and not
+        ((hex.SelStart + 2) > hex.DataSize) then
+        Value := hex.Data[hex.SelStart] + hex.Data[hex.SelStart + 1] * 256;
+    end;
+    if value_viewer.Cells[0, value_viewer.Row] = '4 bytes, unsigned' then
+    begin
+      if ((hex.SelCount = 4) or (hex.SelCount = 0)) and not
+        ((hex.SelStart + 4) > hex.DataSize) then
+        Value := hex.Data[hex.SelStart] + hex.Data[hex.SelStart + 1] * 256 +
+          hex.Data[hex.SelStart + 2] * 256 * 256 + hex.Data[hex.SelStart + 3] * 256 * 256 * 256;
+    end;
+    if Pos('asdec', Name) > 0 then
+    begin
+      Clipboard.AsText := IntToStr(Value);
+    end
+    else
+    begin
+      if value_viewer.Cells[0, value_viewer.Row] = '1 byte, unsigned' then
+        Clipboard.AsText := '0x' + IntToHex(Value, 2);
+      if value_viewer.Cells[0, value_viewer.Row] = '2 bytes, unsigned' then
+        Clipboard.AsText := '0x' + IntToHex(Value, 4);
+      if value_viewer.Cells[0, value_viewer.Row] = '4 bytes, unsigned' then
+        Clipboard.AsText := '0x' + IntToHex(Value, 8);
+    end;
+  end
+  else
+  begin
+    Clipboard.AsText := value_viewer.Cells[value_viewer.Col, value_viewer.Row];
+  end;
+end;
+
+
+
+
+procedure TForm_BinEdit.VSTDblClick(Sender: TObject);
+var
+  node: PVirtualNode;
+  nodedata: PNodeData;
+  id: Integer;
+begin
+  if VST.FocusedColumn = 3 then
+  begin
+    node     := VST.FocusedNode;
+    nodedata := VST.GetNodeData(node);
+
+    if not (nodedata.datatype in [11, 12]) and
+      ((nodedata.DataType < 100) or (nodedata.DataType > 300)) then
+    begin
+      Form_ValueEdit.MakeVarInput(nodedata.Caption, nodedata.offset,
+        nodedata.datatype, nodedata.Value, Self);
+    end
+    else
+    begin
+      if nodedata.DataType = 11 then
+      begin
+        if OniDataConnection.GetRawInfo(fileid, nodedata.offset).raw_size > 0 then
+        begin
+          if Form_Main.open_child('rawedit') then
+          begin
+            TForm_RawEdit(Form_Main.ActiveMDIChild).LoadRaw(
+              OniDataConnection.GetRawInfo(fileid, nodedata.offset));
+          end;
+        end;
+      end;
+      if nodedata.DataType = 12 then
+      begin
+        if (StrToInt(nodedata.Value) < OniDataConnection.GetFilesCount) and
+          (StrToInt(nodedata.Value) > 0) and
+          (StrToInt(nodedata.Value) <> fileid) then
+        begin
+          if OniDataConnection.GetFileInfo(StrToInt(nodedata.Value)).Size > 0 then
+          begin
+            if Form_Main.open_child('binedit') then
+            begin
+              TForm_BinEdit(Form_Main.ActiveMDIChild).LoadDat(StrToInt(nodedata.Value));
+            end;
+          end
+          else
+          begin
+            ShowMessage('Linked filed is a zero-byte-file');
+          end;
+        end;
+      end;
+      if (nodedata.DataType >= 100) and (nodedata.DataType <= 300) then
+      begin
+        if Form_Main.open_child('binedit') then
+        begin
+          TForm_BinEdit(Form_Main.ActiveMDIChild).edit_filtername.Text := nodedata.Value;
+          TForm_BinEdit(Form_Main.ActiveMDIChild).check_filtername.Checked := True;
+          TForm_BinEdit(Form_Main.ActiveMDIChild).check_filternameClick(Self);
+        end;
+      end;
+    end;
+
+  end;
+end;
+
+
+
+
+procedure TForm_BinEdit.VSTFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode;
+  Column: TColumnIndex);
+var
+  Data: PNodeData;
+begin
+  Data := VST.GetNodeData(node);
+  if Data.DataType > 0 then
+  begin
+    hex.SelStart := Data.Offset;
+    hex.SelEnd   := Data.Offset + GetTypeDataLength(Data.DataType) - 1;
+  end
+  else
+  begin
+    hex.SelStart := Data.Offset;
+    hex.SelEnd   := Data.Offset + HexToLong(Data.Value) - 1;
+  end;
+end;
+
+
+
+
+procedure TForm_BinEdit.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
+  Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
+var
+  Data: PNodeData;
+begin
+  Data     := Sender.GetNodeData(Node);
+  CellText := '';
+  if TextType = ttNormal then
+  begin
+    case Column of
+      0:
+        CellText := Data.Caption;
+      1:
+        if Data.DataType > 0 then
+          CellText := '0x' + IntToHex(Data.Offset, 8)
+        else if Data.Offset > 0 then
+          CellText := '0x' + IntToHex(Data.Offset, 8);
+      2:
+        if Data.DataType > 0 then
+          CellText := GetDataType(Data.DataType);
+      3:
+        if Data.DataType > 0 then
+          CellText := Data.Value //GetValue(data.DataType, data.Offset)
+        else if Length(Data.Value) > 0 then
+          CellText := IntToStr(HexToLong(Data.Value)) + ' Bytes';
+      4:
+        CellText := Data.Description;
+    end;
+  end;
+end;
+
+
+
+
+procedure TForm_BinEdit.VSTHeaderDragged(Sender: TVTHeader; Column: TColumnIndex;
+  OldPosition: Integer);
+begin
+  if Sender.Columns.Items[column].Position < 1 then
+    Sender.Columns.Items[column].Position := OldPosition;
+end;
+
+
+
+
+procedure TForm_BinEdit.VTHPopupColumnChange(const Sender: TBaseVirtualTree;
+  const Column: TColumnIndex; Visible: Boolean);
+begin
+  if column = 0 then
+    TVirtualStringTree(Sender).Header.Columns.Items[column].Options :=
+      TVirtualStringTree(Sender).Header.Columns.Items[column].Options + [coVisible];
+end;
+
+
+
+
+procedure TForm_BinEdit.SetNewValue(datatype: Word; offset: LongWord; Value: String);
+var
+  Data: Tdata;
+  value_int: LongWord;
+  value_float: Single;
+  i: Word;
+begin
+  case datatype of
+    1..4:
+    begin
+      value_int := StrToInt(Value);
+      SetLength(Data, datatype);
+      for i := 0 to datatype - 1 do
+      begin
+        Data[i]   := value_int mod 256;
+        value_int := value_int div 256;
+      end;
+    end;
+    5..8:
+    begin
+      value_int := StrToInt('$' + Value);
+      SetLength(Data, datatype - 4);
+      for i := 0 to datatype - 5 do
+      begin
+        Data[i]   := value_int mod 256;
+        value_int := value_int div 256;
+      end;
+    end;
+    9:
+    begin
+      value_float := StrToFloat(Value);
+      Data := Encode_Float(value_float);
+    end;
+    10:
+    begin
+      value_int := BinToInt(Value);
+      SetLength(Data, 1);
+      Data[0] := value_int;
+    end;
+    10000..65535:
+    begin
+      SetLength(Data, datatype - 10000);
+      for i := 1 to datatype - 10000 do
+      begin
+        if i <= Length(Value) then
+          Data[i - 1] := Ord(Value[i])
+        else
+          Data[i - 1] := 0;
+      end;
+    end;
+  end;
+  for i := 0 to High(Data) do
+  begin
+    if hex.Data[offset + i] <> Data[i] then
+      hex.ByteChanged[offset + i] := True;
+    hex.Data[offset + i] := Data[i];
+  end;
+  hex.Modified := True;
+  hexChange(Self);
+  hex.Repaint;
+end;
+
+
+
+
+procedure TForm_BinEdit.value_viewerDblClick(Sender: TObject);
+var
+  offset:     LongWord;
+  datatype:   Word;
+  objectname: String;
+  Value:      String;
+begin
+  if (value_viewer.Col = 1) and (Length(value_viewer.Cells[1, value_viewer.Row]) > 0) then
+  begin
+    offset := hex.SelStart;
+    if value_viewer.Cells[0, value_viewer.Row] = '1 byte, unsigned' then
+      datatype := 1;
+    if value_viewer.Cells[0, value_viewer.Row] = '2 bytes, unsigned' then
+      datatype := 2;
+    if value_viewer.Cells[0, value_viewer.Row] = '4 bytes, unsigned' then
+      datatype := 4;
+    if value_viewer.Cells[0, value_viewer.Row] = 'Bitset' then
+      datatype := 10;
+    if value_viewer.Cells[0, value_viewer.Row] = 'Float' then
+      datatype := 9;
+    if value_viewer.Cells[0, value_viewer.Row] = 'Selected length' then
+      Exit;
+    if value_viewer.Cells[0, value_viewer.Row] = 'String' then
+    begin
+      if hex.SelCount > 0 then
+        datatype := 10000 + hex.SelCount
+      else
+        datatype := 10000 + Length(value_viewer.Cells[1, value_viewer.Row]);
+    end;
+    objectname := '';
+    Value      := GetValue(datatype, offset);
+    Form_ValueEdit.MakeVarInput(objectname, offset, datatype, Value, Self);
+  end;
+end;
+
+
+
+
+procedure TForm_BinEdit.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
+begin
+  if (Shift = [ssCtrl]) and (Key = 83) then
+    if hex.Modified then
+      if not Save then
+        Exit;
+end;
+
+
+end.
Index: oup/current/Tool_Extractor.dfm
===================================================================
--- oup/current/Tool_Extractor.dfm	(revision 43)
+++ oup/current/Tool_Extractor.dfm	(revision 43)
@@ -0,0 +1,261 @@
+object Form_Extractor: TForm_Extractor
+  Left = 0
+  Top = 0
+  Caption = 'Extractor'
+  ClientHeight = 398
+  ClientWidth = 526
+  Color = clBtnFace
+  Font.Charset = DEFAULT_CHARSET
+  Font.Color = clWindowText
+  Font.Height = -11
+  Font.Name = 'Tahoma'
+  Font.Style = []
+  FormStyle = fsMDIChild
+  OldCreateOrder = False
+  Visible = True
+  WindowState = wsMaximized
+  OnClose = FormClose
+  OnCreate = FormCreate
+  OnResize = FormResize
+  PixelsPerInch = 96
+  TextHeight = 13
+  object group_select: TGroupBox
+    Left = 0
+    Top = 0
+    Width = 230
+    Height = 398
+    Align = alClient
+    Caption = '1. Select file(s)'
+    TabOrder = 0
+    ExplicitWidth = 191
+    object panel_extension: TPanel
+      Left = 2
+      Top = 293
+      Width = 226
+      Height = 103
+      Align = alBottom
+      BevelOuter = bvNone
+      TabOrder = 0
+      OnResize = panel_extensionResize
+      ExplicitWidth = 187
+      object lbl_filter: TLabel
+        Left = 2
+        Top = 62
+        Width = 100
+        Height = 17
+        AutoSize = False
+        Caption = 'Filter by &extension:'
+        FocusControl = combo_extension
+      end
+      object combo_extension: TComboBox
+        Left = 2
+        Top = 76
+        Width = 145
+        Height = 21
+        Style = csDropDownList
+        DropDownCount = 12
+        Font.Charset = DEFAULT_CHARSET
+        Font.Color = clWindowText
+        Font.Height = -11
+        Font.Name = 'Tahoma'
+        Font.Style = []
+        ItemHeight = 13
+        ParentFont = False
+        Sorted = True
+        TabOrder = 3
+        OnClick = combo_extensionClick
+      end
+      object check_zerobyte: TCheckBox
+        Left = 2
+        Top = 44
+        Width = 130
+        Height = 13
+        Caption = 'Show &zero-byte files'
+        TabOrder = 2
+        OnClick = check_zerobyteClick
+      end
+      object edit_filtername: TEdit
+        Left = 2
+        Top = 20
+        Width = 145
+        Height = 18
+        AutoSize = False
+        TabOrder = 1
+      end
+      object check_filtername: TCheckBox
+        Left = 2
+        Top = 5
+        Width = 130
+        Height = 15
+        Caption = 'Filter by file&name:'
+        TabOrder = 0
+        OnClick = check_filternameClick
+      end
+    end
+    object list: TListBox
+      Left = 2
+      Top = 15
+      Width = 226
+      Height = 278
+      Align = alClient
+      ItemHeight = 13
+      MultiSelect = True
+      TabOrder = 1
+      ExplicitWidth = 187
+    end
+  end
+  object group_extract: TGroupBox
+    Left = 230
+    Top = 0
+    Width = 296
+    Height = 398
+    Align = alRight
+    Caption = '2. Select extract-method'
+    TabOrder = 1
+    ExplicitLeft = 191
+    object group_singlefiles: TGroupBox
+      Left = 8
+      Top = 16
+      Width = 281
+      Height = 185
+      Caption = 'Write data into single files'
+      TabOrder = 0
+      object btn_sel_dat: TButton
+        Left = 8
+        Top = 16
+        Width = 129
+        Height = 49
+        Caption = 'Selected files (dat contents only)'
+        TabOrder = 0
+        WordWrap = True
+        OnClick = Extract
+      end
+      object btn_sel_datraw: TButton
+        Left = 8
+        Top = 72
+        Width = 129
+        Height = 49
+        Caption = 'Selected files (dat+raw)'
+        TabOrder = 1
+        WordWrap = True
+        OnClick = Extract
+      end
+      object btn_sel_datraw_convert: TButton
+        Left = 8
+        Top = 128
+        Width = 129
+        Height = 49
+        Caption = 'Selected files (dat+raw) (with convert if possible)'
+        TabOrder = 2
+        WordWrap = True
+        OnClick = Extract
+      end
+      object btn_all_dat: TButton
+        Left = 144
+        Top = 16
+        Width = 129
+        Height = 49
+        Caption = 'All files in list (dat contents only)'
+        TabOrder = 3
+        WordWrap = True
+        OnClick = Extract
+      end
+      object btn_all_datraw: TButton
+        Left = 144
+        Top = 72
+        Width = 129
+        Height = 49
+        Caption = 'All files in list (dat+raw)'
+        TabOrder = 4
+        WordWrap = True
+        OnClick = Extract
+      end
+      object btn_all_datraw_convert: TButton
+        Left = 144
+        Top = 128
+        Width = 129
+        Height = 49
+        BiDiMode = bdLeftToRight
+        Caption = 'All files in list (dat+raw) (with convert if possible)'
+        ParentBiDiMode = False
+        TabOrder = 5
+        WordWrap = True
+        OnClick = Extract
+      end
+    end
+    object group_onefile: TGroupBox
+      Left = 8
+      Top = 208
+      Width = 281
+      Height = 73
+      Caption = 'Write data into one file'
+      TabOrder = 1
+      object btn_sel_files_toone: TButton
+        Left = 8
+        Top = 16
+        Width = 129
+        Height = 49
+        Caption = 'Selected files (dat contents only)'
+        TabOrder = 0
+        WordWrap = True
+        OnClick = Extract
+      end
+      object btn_all_files_toone: TButton
+        Left = 144
+        Top = 16
+        Width = 129
+        Height = 49
+        Caption = 'All files in list (dat contents only)'
+        TabOrder = 1
+        WordWrap = True
+        OnClick = Extract
+      end
+    end
+    object group_progress: TGroupBox
+      Left = 8
+      Top = 288
+      Width = 281
+      Height = 105
+      Caption = 'Progress ...'
+      TabOrder = 2
+      Visible = False
+      object lbl_progress: TLabel
+        Left = 8
+        Top = 40
+        Width = 265
+        Height = 17
+        AutoSize = False
+        Caption = 'Files done: 0/0'
+      end
+      object lbl_estimated: TLabel
+        Left = 8
+        Top = 56
+        Width = 265
+        Height = 17
+        AutoSize = False
+        Caption = 'Estimated finishing time: 00:00:00'
+      end
+      object progress: TProgressBar
+        Left = 8
+        Top = 16
+        Width = 265
+        Height = 17
+        Smooth = True
+        TabOrder = 0
+      end
+      object btn_abort: TButton
+        Left = 8
+        Top = 72
+        Width = 97
+        Height = 23
+        Caption = 'Abort'
+        Enabled = False
+        TabOrder = 1
+      end
+    end
+  end
+  object saved: TSaveDialog
+    Left = 448
+    Top = 328
+  end
+end
Index: oup/current/Tool_Extractor.pas
===================================================================
--- oup/current/Tool_Extractor.pas	(revision 43)
+++ oup/current/Tool_Extractor.pas	(revision 43)
@@ -0,0 +1,312 @@
+unit Tool_Extractor;
+
+interface
+
+uses
+  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
+  Dialogs, StdCtrls, ExtCtrls, StrUtils, ComCtrls;
+
+type
+  TForm_Extractor = class(TForm)
+    group_select: TGroupBox;
+    group_extract: TGroupBox;
+    group_singlefiles: TGroupBox;
+    btn_sel_dat: TButton;
+    btn_sel_datraw: TButton;
+    btn_sel_datraw_convert: TButton;
+    btn_all_dat: TButton;
+    btn_all_datraw: TButton;
+    btn_all_datraw_convert: TButton;
+    group_onefile: TGroupBox;
+    btn_sel_files_toone: TButton;
+    btn_all_files_toone: TButton;
+    group_progress: TGroupBox;
+    progress: TProgressBar;
+    lbl_progress: TLabel;
+    lbl_estimated: TLabel;
+    btn_abort: TButton;
+    saved: TSaveDialog;
+    panel_extension: TPanel;
+    lbl_filter: TLabel;
+    combo_extension: TComboBox;
+    check_zerobyte: TCheckBox;
+    edit_filtername: TEdit;
+    check_filtername: TCheckBox;
+    list: TListBox;
+    procedure LoadFileNames;
+    procedure check_filternameClick(Sender: TObject);
+    procedure check_zerobyteClick(Sender: TObject);
+    procedure combo_extensionClick(Sender: TObject);
+    procedure panel_extensionResize(Sender: TObject);
+    procedure Recreatelist;
+
+    procedure FormCreate(Sender: TObject);
+    procedure FormClose(Sender: TObject; var Action: TCloseAction);
+    procedure FormResize(Sender: TObject);
+    procedure Extract(Sender: TObject);
+  private
+  public
+  end;
+
+var
+  Form_Extractor: TForm_Extractor;
+
+implementation
+
+{$R *.dfm}
+
+uses Main, Code_Functions, Data, Code_OniDataClass;
+
+
+
+
+procedure TForm_Extractor.Recreatelist;
+var
+  i:    LongWord;
+  exts: TStringArray;
+begin
+  combo_extension.Items.Clear;
+  combo_extension.Items.Add('_All files_ (' + IntToStr(
+    OniDataConnection.GetFilesCount) + ')');
+  exts := OniDataConnection.GetExtensionsList;
+  for i := 0 to High(exts) do
+    combo_extension.Items.Add(exts[i]);
+  combo_extension.ItemIndex := 0;
+  combo_extensionClick(Self);
+end;
+
+
+
+
+procedure TForm_Extractor.LoadFileNames;
+var
+  Extension: String[4];
+  no_zero_bytes: Boolean;
+  pattern: String;
+  files: TStringArray;
+  i: LongWord;
+begin
+  Extension := MidStr(combo_extension.Items.Strings[combo_extension.ItemIndex], 1, 4);
+  no_zero_bytes := not check_zerobyte.Checked;
+  pattern := '';
+  if check_filtername.Checked then
+    pattern := edit_filtername.Text;
+  if Extension = '_All' then
+    Extension := '';
+
+  files := OniDataConnection.GetFilesList(extension, pattern, no_zero_bytes);
+  list.Items.Clear;
+  if Length(files) > 0 then
+    for i := 0 to High(files) do
+      list.Items.Add(files[i]);
+end;
+
+
+
+
+procedure TForm_Extractor.panel_extensionResize(Sender: TObject);
+begin
+  combo_extension.Width := panel_extension.Width - 5;
+  edit_filtername.Width := panel_extension.Width - 5;
+end;
+
+
+
+
+procedure TForm_Extractor.combo_extensionClick(Sender: TObject);
+begin
+  LoadFileNames;
+end;
+
+
+
+
+procedure TForm_Extractor.check_zerobyteClick(Sender: TObject);
+var
+  i: Byte;
+begin
+  LoadFileNames;
+end;
+
+
+
+
+procedure TForm_Extractor.check_filternameClick(Sender: TObject);
+begin
+  edit_filtername.Enabled := not check_filtername.Checked;
+  LoadFileNames;
+end;
+
+
+
+
+procedure TForm_Extractor.FormResize(Sender: TObject);
+begin
+  if Self.Width >= 450 then
+  begin
+  end
+  else
+    Self.Width := 450;
+  if Self.Height >= 400 then
+  begin
+    group_progress.Height := group_extract.Height - 293;
+  end
+  else
+    Self.Height := 400;
+end;
+
+
+
+
+procedure TForm_Extractor.FormClose(Sender: TObject; var Action: TCloseAction);
+begin
+  Action := caFree;
+end;
+
+
+
+
+procedure TForm_Extractor.FormCreate(Sender: TObject);
+begin
+  btn_sel_dat.Caption    := 'Selected files' + CrLf + '(dat contents only)';
+  btn_sel_datraw.Caption := 'Selected files' + CrLf + '(dat+raw contents)';
+  btn_sel_datraw_convert.Caption :=
+    'Selected files' + CrLf + '(dat+raw contents)' + CrLf + '(with convert if possible)';
+  btn_all_dat.Caption    := 'All files in list' + CrLf + '(dat contents only)';
+  btn_all_datraw.Caption := 'All files in list' + CrLf + '(dat+raw contents)';
+  btn_all_datraw_convert.Caption :=
+    'All files in list' + CrLf + '(dat+raw contents)' + CrLf + '(with convert if possible)';
+  btn_sel_files_toone.Caption := 'Selected files' + CrLf + '(dat contents only)';
+  btn_all_files_toone.Caption := 'All files in list' + CrLf + '(dat contents only)';
+end;
+
+
+
+
+procedure TForm_Extractor.Extract(Sender: TObject);
+var
+  sel_only:  Boolean;
+  dat_only:  Boolean;
+  convert:   Boolean;
+  one_file:  Boolean;
+  settings:  TExportSet;
+  files:     LongWord;
+  i, done:   LongWord;
+  begintime: Double;
+begin
+  sel_only := Pos('sel', TButton(Sender).Name) > 0;
+  dat_only := not (Pos('datraw', TButton(Sender).Name) > 0);
+  convert  := Pos('convert', TButton(Sender).Name) > 0;
+  one_file := Pos('toone', TButton(Sender).Name) > 0;
+  if dat_only then
+    settings := [DO_dat]
+  else
+    settings := [DO_dat, DO_raw];
+  if convert then
+    settings := settings + [DO_convert];
+  if one_file then
+    settings := settings + [DO_toone];
+  progress.Position := 0;
+
+  if saved.Execute then
+  begin
+    begintime := Time;
+    group_progress.Visible := True;
+    group_select.Enabled := False;
+    group_singlefiles.Enabled := False;
+    group_onefile.Enabled := False;
+    lbl_estimated.Caption := 'Estimated finishing time: unknown';
+    if one_file then
+    begin
+      if FileExists(saved.FileName) then
+      begin
+        if MessageBox(Self.Handle, PChar(
+          'File already exists. Do you want to overwrite it?'), PChar('Warning!'), MB_YESNO) =
+          ID_YES then
+        begin
+          DeleteFile(saved.FileName);
+        end
+        else
+        begin
+          group_progress.Visible    := False;
+          group_select.Enabled      := True;
+          group_singlefiles.Enabled := True;
+          group_onefile.Enabled     := True;
+          Exit;
+        end;
+      end;
+      i := FileCreate(saved.FileName);
+      FileClose(i);
+      i := 0;
+    end;
+    if sel_only then
+    begin
+      files := list.SelCount;
+      lbl_progress.Caption := 'Files done: 0/' + IntToStr(files);
+      progress.Max := files;
+      done  := 0;
+      for i := 0 to list.Count - 1 do
+      begin
+        if list.Selected[i] then
+        begin
+          if one_file then
+          begin
+            ExportFile(OniDataConnection.ExtractFileID(
+              list.Items.Strings[list.ItemIndex]), ExtractFileName(saved.FileName),
+              settings, ExtractFileDir(saved.FileName));
+          end
+          else
+          begin
+            ExportFile(OniDataConnection.ExtractFileID(
+              list.Items.Strings[list.ItemIndex]), list.Items.Strings[i], settings, 'D:');
+          end;
+          Inc(done);
+        end;
+        if ((done mod 10) = 0) and (done >= 50) then
+          lbl_estimated.Caption := 'Estimated finishing time: ' + TimeToStr(
+            (Time - begintime) / done * files + begintime);
+        if (i mod 10) = 0 then
+        begin
+          progress.Position    := done;
+          lbl_progress.Caption := 'Files done: ' + IntToStr(done) + '/' + IntToStr(files);
+          Application.ProcessMessages;
+        end;
+      end;
+    end
+    else
+    begin
+      files := list.Count;
+      lbl_progress.Caption := 'Files done: 0/' + IntToStr(files);
+      progress.Max := files;
+      for i := 0 to list.Count - 1 do
+      begin
+        if one_file then
+        begin
+          ExportFile(OniDataConnection.ExtractFileID(
+            list.Items.Strings[list.ItemIndex]), ExtractFileName(saved.FileName),
+            settings, ExtractFileDir(saved.FileName));
+        end
+        else
+        begin
+          ExportFile(OniDataConnection.ExtractFileID(
+            list.Items.Strings[list.ItemIndex]), list.Items.Strings[i], settings, 'D:');
+        end;
+        if ((i mod 10) = 0) and (i >= 50) then
+          lbl_estimated.Caption := 'Estimated finishing time: ' + TimeToStr(
+            (Time - begintime) / i * files + begintime);
+        if (i mod 5) = 0 then
+        begin
+          progress.Position    := i;
+          lbl_progress.Caption := 'Files done: ' + IntToStr(i) + '/' + IntToStr(files);
+          Application.ProcessMessages;
+        end;
+      end;
+    end;
+    group_progress.Visible    := False;
+    group_select.Enabled      := True;
+    group_singlefiles.Enabled := True;
+    group_onefile.Enabled     := True;
+  end;
+end;
+
+end.
Index: oup/current/Tool_Preview.dfm
===================================================================
--- oup/current/Tool_Preview.dfm	(revision 43)
+++ oup/current/Tool_Preview.dfm	(revision 43)
@@ -0,0 +1,193 @@
+object Form_Preview: TForm_Preview
+  Left = 0
+  Top = 0
+  Caption = 'Preview'
+  ClientHeight = 473
+  ClientWidth = 472
+  Color = clBtnFace
+  Font.Charset = DEFAULT_CHARSET
+  Font.Color = clWindowText
+  Font.Height = -11
+  Font.Name = 'Tahoma'
+  Font.Style = []
+  FormStyle = fsMDIChild
+  OldCreateOrder = False
+  Visible = True
+  WindowState = wsMaximized
+  OnClose = FormClose
+  OnCreate = FormCreate
+  OnResize = FormResize
+  PixelsPerInch = 96
+  TextHeight = 13
+  object Splitter1: TSplitter
+    Left = 200
+    Top = 0
+    Width = 9
+    Height = 473
+    AutoSnap = False
+    Beveled = True
+    MinSize = 150
+  end
+  object panel_preview: TPanel
+    Left = 209
+    Top = 0
+    Width = 263
+    Height = 473
+    Align = alClient
+    BevelOuter = bvNone
+    TabOrder = 0
+    object img: TImage
+      Left = 0
+      Top = 20
+      Width = 263
+      Height = 453
+      Align = alClient
+      ExplicitWidth = 313
+    end
+    object lbl_notpossible: TLabel
+      Left = 16
+      Top = 56
+      Width = 97
+      Height = 65
+      AutoSize = False
+      Caption = 'No preview possible for this filetype'
+      Font.Charset = DEFAULT_CHARSET
+      Font.Color = clWindowText
+      Font.Height = -16
+      Font.Name = 'Tahoma'
+      Font.Style = []
+      ParentFont = False
+      Visible = False
+      WordWrap = True
+    end
+    object panel_buttons: TPanel
+      Left = 0
+      Top = 0
+      Width = 263
+      Height = 20
+      Align = alTop
+      BevelOuter = bvNone
+      TabOrder = 0
+      Visible = False
+      OnResize = panel_buttonsResize
+      object btn_dec: TButton
+        Left = 0
+        Top = 0
+        Width = 20
+        Height = 20
+        Caption = '-'
+        Enabled = False
+        TabOrder = 0
+        OnClick = btn_decClick
+      end
+      object btn_startstop: TButton
+        Left = 21
+        Top = 0
+        Width = 80
+        Height = 20
+        Caption = 'Stop automatic'
+        TabOrder = 1
+        OnClick = btn_startstopClick
+      end
+      object btn_inc: TButton
+        Left = 102
+        Top = 0
+        Width = 20
+        Height = 20
+        Caption = '+'
+        Enabled = False
+        TabOrder = 2
+        OnClick = btn_incClick
+      end
+    end
+  end
+  object panel_files: TPanel
+    Left = 0
+    Top = 0
+    Width = 200
+    Height = 473
+    Align = alLeft
+    BevelOuter = bvNone
+    TabOrder = 1
+    object list: TListBox
+      Left = 0
+      Top = 0
+      Width = 200
+      Height = 370
+      Align = alClient
+      ItemHeight = 13
+      TabOrder = 0
+      OnClick = listClick
+      OnMouseDown = listMouseDown
+    end
+    object panel_extension: TPanel
+      Left = 0
+      Top = 370
+      Width = 200
+      Height = 103
+      Align = alBottom
+      BevelOuter = bvNone
+      TabOrder = 1
+      OnResize = panel_extensionResize
+      object lbl_filter: TLabel
+        Left = 2
+        Top = 62
+        Width = 100
+        Height = 17
+        AutoSize = False
+        Caption = 'Filter by &extension:'
+        FocusControl = combo_extension
+      end
+      object combo_extension: TComboBox
+        Left = 2
+        Top = 76
+        Width = 145
+        Height = 21
+        Style = csDropDownList
+        DropDownCount = 12
+        Font.Charset = DEFAULT_CHARSET
+        Font.Color = clWindowText
+        Font.Height = -11
+        Font.Name = 'Tahoma'
+        Font.Style = []
+        ItemHeight = 13
+        ParentFont = False
+        Sorted = True
+        TabOrder = 3
+        OnClick = combo_extensionClick
+      end
+      object check_zerobyte: TCheckBox
+        Left = 2
+        Top = 44
+        Width = 130
+        Height = 13
+        Caption = 'Show &zero-byte files'
+        TabOrder = 2
+        OnClick = check_zerobyteClick
+      end
+      object edit_filtername: TEdit
+        Left = 2
+        Top = 20
+        Width = 145
+        Height = 18
+        AutoSize = False
+        TabOrder = 1
+      end
+      object check_filtername: TCheckBox
+        Left = 2
+        Top = 5
+        Width = 130
+        Height = 15
+        Caption = 'Filter by file&name:'
+        TabOrder = 0
+        OnClick = check_filternameClick
+      end
+    end
+  end
+  object timer: TTimer
+    Enabled = False
+    OnTimer = timerTimer
+    Left = 144
+    Top = 24
+  end
+end
Index: oup/current/Tool_Preview.pas
===================================================================
--- oup/current/Tool_Preview.pas	(revision 43)
+++ oup/current/Tool_Preview.pas	(revision 43)
@@ -0,0 +1,364 @@
+unit Tool_Preview;
+
+interface
+
+uses
+  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
+  Dialogs, Math, ExtCtrls, StdCtrls, StrUtils, Menus,
+  Code_Functions, Data, Code_Exporters, Code_OniImgClass, Code_OniDataClass;
+
+type
+  TForm_Preview = class(TForm)
+    timer:   TTimer;
+    panel_preview: TPanel;
+    img:     TImage;
+    panel_buttons: TPanel;
+    btn_dec: TButton;
+    btn_startstop: TButton;
+    btn_inc: TButton;
+    Splitter1: TSplitter;
+    lbl_notpossible: TLabel;
+    panel_files: TPanel;
+    list:    TListBox;
+    panel_extension: TPanel;
+    lbl_filter: TLabel;
+    combo_extension: TComboBox;
+    check_zerobyte: TCheckBox;
+    edit_filtername: TEdit;
+    check_filtername: TCheckBox;
+    procedure LoadFileNames;
+    procedure check_filternameClick(Sender: TObject);
+    procedure check_zerobyteClick(Sender: TObject);
+    procedure combo_extensionClick(Sender: TObject);
+    procedure panel_extensionResize(Sender: TObject);
+    procedure listClick(Sender: TObject);
+    procedure Recreatelist;
+
+    procedure PreviewImage;
+    procedure PreviewTXAN;
+    procedure btn_incClick(Sender: TObject);
+    procedure btn_decClick(Sender: TObject);
+    procedure FormResize(Sender: TObject);
+    procedure btn_startstopClick(Sender: TObject);
+    procedure panel_buttonsResize(Sender: TObject);
+    procedure timerTimer(Sender: TObject);
+    procedure FormCreate(Sender: TObject);
+    procedure FormClose(Sender: TObject; var Action: TCloseAction);
+
+    procedure DrawImage(index: Integer);
+    procedure SetBitmapCount(Count: Integer);
+    procedure LoadImage(fileid, index: Integer);
+    procedure listMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+  private
+    bitmaps:   array of TBitmap;
+    actualimg: Byte;
+    _fileid:   LongWord;
+  public
+  end;
+
+var
+  Form_Preview: TForm_Preview;
+
+implementation
+
+{$R *.dfm}
+
+uses Main;
+
+
+
+
+procedure TForm_Preview.Recreatelist;
+var
+  i:    LongWord;
+  exts: TStringArray;
+begin
+  combo_extension.Items.Clear;
+  combo_extension.Items.Add('_All files_ (' +
+    IntToStr(OniDataConnection.GetFilesCount) + ')');
+  exts := OniDataConnection.GetExtensionsList;
+  for i := 0 to High(exts) do
+    combo_extension.Items.Add(exts[i]);
+  combo_extension.ItemIndex := 0;
+  combo_extensionClick(Self);
+end;
+
+
+
+
+procedure TForm_Preview.LoadFileNames;
+var
+  Extension: String[4];
+  no_zero_bytes: Boolean;
+  pattern: String;
+  files: TStringArray;
+  i: LongWord;
+begin
+  Extension := MidStr(combo_extension.Items.Strings[combo_extension.ItemIndex], 1, 4);
+  no_zero_bytes := not check_zerobyte.Checked;
+  pattern := '';
+  if check_filtername.Checked then
+    pattern := edit_filtername.Text;
+  if Extension = '_All' then
+    Extension := '';
+
+  files := OniDataConnection.GetFilesList(extension, pattern, no_zero_bytes);
+  list.Items.Clear;
+  if Length(files) > 0 then
+    for i := 0 to High(files) do
+      list.Items.Add(files[i]);
+end;
+
+
+
+
+procedure TForm_Preview.LoadImage(fileid, index: Integer);
+var
+  Data:      Tdata;
+  memstream: TMemoryStream;
+  OniImage:  TOniImage;
+
+begin
+  OniImage := TOniImage.Create;
+  OniImage.Load(fileid);
+  Data := OniImage.GetAsBMP;
+  OniImage.Free;
+
+  memstream := TMemoryStream.Create;
+  memstream.Write(Data[0], Length(Data));
+  memstream.Seek(0, soFromBeginning);
+  bitmaps[index].LoadFromStream(memstream);
+  memstream.Free;
+end;
+
+
+
+
+procedure TForm_Preview.combo_extensionClick(Sender: TObject);
+begin
+  LoadFileNames;
+end;
+
+
+
+procedure TForm_Preview.DrawImage(index: Integer);
+begin
+  BitBlt(img.Canvas.Handle, 0, 0, img.Width, img.Height,
+    bitmaps[index].Canvas.Handle, 0, 0, WHITENESS);
+  BitBlt(img.Canvas.Handle, 0, 0, bitmaps[index].Width, bitmaps[index].Height,
+    bitmaps[index].Canvas.Handle, 0, 0, SRCCOPY);
+  img.Invalidate;
+end;
+
+
+
+
+procedure TForm_Preview.SetBitmapCount(Count: Integer);
+var
+  i: Integer;
+begin
+  if Length(bitmaps) > Count then
+  begin
+    for i := Count to High(bitmaps) do
+      bitmaps[i].Free;
+    SetLength(bitmaps, Count);
+  end;
+  if Length(bitmaps) < Count then
+  begin
+    i := Length(bitmaps);
+    SetLength(bitmaps, Count);
+    for i := i to High(bitmaps) do
+      bitmaps[i] := TBitmap.Create;
+  end;
+end;
+
+
+
+
+procedure TForm_Preview.check_zerobyteClick(Sender: TObject);
+begin
+  LoadFileNames;
+end;
+
+
+
+
+procedure TForm_Preview.check_filternameClick(Sender: TObject);
+begin
+  edit_filtername.Enabled := not check_filtername.Checked;
+  LoadFileNames;
+end;
+
+
+
+
+procedure TForm_Preview.listClick(Sender: TObject);
+var
+  ext: String;
+begin
+  _fileid := OniDataConnection.ExtractFileID(list.Items.Strings[list.ItemIndex]);
+  lbl_notpossible.Visible := False;
+  Self.img.Visible := True;
+  Self.timer.Enabled := False;
+  Self.panel_buttons.Visible := False;
+  ext     := RightStr(list.Items.Strings[list.ItemIndex], 4);
+  if (ext = 'PSpc') or (ext = 'TXMB') or (ext = 'TXMP') then
+    PreviewImage
+  else if ext = 'TXAN' then
+    PreviewTXAN
+  else
+  begin
+    Self.lbl_notpossible.Visible := True;
+    Self.img.Visible := False;
+  end;
+end;
+
+
+
+
+procedure TForm_Preview.listMouseDown(Sender: TObject; Button: TMouseButton;
+  Shift: TShiftState; X, Y: Integer);
+var
+  pt: TPoint;
+begin
+  pt.X := x;
+  pt.Y := y;
+  list.ItemIndex := list.ItemAtPos(pt, true);
+  if list.ItemIndex > -1 then
+    Self.listClick(Self);
+end;
+
+procedure TForm_Preview.PreviewImage;
+begin
+  SetBitmapCount(1);
+  LoadImage(_fileid, 0);
+  DrawImage(0);
+end;
+
+
+
+
+procedure TForm_Preview.PreviewTXAN;
+var
+  loop_speed: Word;
+  linkcount: LongWord;
+  link: LongWord;
+  i:    Byte;
+begin
+  OniDataConnection.LoadDatFilePart(_fileid, $14, SizeOf(loop_speed), @loop_speed);
+  OniDataConnection.LoadDatFilePart(_fileid, $1C, SizeOf(linkcount), @linkcount);
+  SetBitmapCount(linkcount);
+  for i := 0 to linkcount - 1 do
+  begin
+    OniDataConnection.LoadDatFilePart(_fileid, $20 + i * 4, SizeOf(link), @link);
+    link := link div 256;
+    if link = 0 then
+      link := _fileid - 1;
+    LoadImage(link, i);
+  end;
+  actualimg := 254;
+  Self.timer.Interval := Floor(loop_speed * (1 / 60) * 1000);
+  Self.timer.Enabled := False;
+  Self.btn_startstopClick(Self);
+  Self.panel_buttons.Visible := True;
+end;
+
+
+
+
+procedure TForm_Preview.timerTimer(Sender: TObject);
+begin
+  btn_incClick(Self);
+end;
+
+
+
+
+procedure TForm_Preview.btn_startstopClick(Sender: TObject);
+begin
+  Self.timer.Enabled   := not Self.timer.Enabled;
+  Self.btn_dec.Enabled := not Self.timer.Enabled;
+  Self.btn_inc.Enabled := not Self.timer.Enabled;
+  if Self.timer.Enabled then
+    Self.btn_startstop.Caption := 'Stop automatic'
+  else
+    Self.btn_startstop.Caption := 'Start automatic';
+end;
+
+
+
+
+procedure TForm_Preview.btn_decClick(Sender: TObject);
+begin
+  if actualimg > 0 then
+    Dec(actualimg)
+  else
+    actualimg := High(bitmaps);
+  Self.Caption := 'Preview ' + OniDataConnection.GetFileInfo(_fileid).FileName +
+    ' (' + IntToStr(actualimg + 1) + '/' + IntToStr(Length(bitmaps)) + ')';
+  DrawImage(actualimg);
+end;
+
+
+
+
+procedure TForm_Preview.btn_incClick(Sender: TObject);
+begin
+  if actualimg < High(bitmaps) then
+    Inc(actualimg)
+  else
+    actualimg := 0;
+  Self.Caption := 'Preview ' + OniDataConnection.GetFileInfo(_fileid).FileName +
+    ' (' + IntToStr(actualimg + 1) + '/' + IntToStr(Length(bitmaps)) + ')';
+  DrawImage(actualimg);
+end;
+
+
+
+
+procedure TForm_Preview.panel_buttonsResize(Sender: TObject);
+begin
+  btn_startstop.Width := panel_buttons.Width - 45;
+  btn_inc.Left := panel_buttons.Width - 23;
+end;
+
+
+
+
+procedure TForm_Preview.panel_extensionResize(Sender: TObject);
+begin
+  combo_extension.Width := panel_extension.Width - 5;
+  edit_filtername.Width := panel_extension.Width - 5;
+end;
+
+
+
+
+procedure TForm_Preview.FormResize(Sender: TObject);
+begin
+  if Self.Width < 300 then
+    Self.Width := 300;
+  if Self.Height < 200 then
+    Self.Height := 200;
+end;
+
+
+
+
+procedure TForm_Preview.FormCreate(Sender: TObject);
+begin
+  SetLength(bitmaps, 0);
+  Self.Width  := 260;
+  Self.Height := 300;
+end;
+
+
+
+
+procedure TForm_Preview.FormClose(Sender: TObject; var Action: TCloseAction);
+begin
+  Action := caFree;
+end;
+
+end.
Index: oup/current/Tool_RawEdit.dfm
===================================================================
--- oup/current/Tool_RawEdit.dfm	(revision 43)
+++ oup/current/Tool_RawEdit.dfm	(revision 43)
@@ -0,0 +1,305 @@
+object Form_RawEdit: TForm_RawEdit
+  Left = 0
+  Top = 0
+  BorderIcons = [biSystemMenu, biMaximize]
+  Caption = 'Binary .raw-Editor'
+  ClientHeight = 640
+  ClientWidth = 642
+  Color = clBtnFace
+  Font.Charset = DEFAULT_CHARSET
+  Font.Color = clWindowText
+  Font.Height = -11
+  Font.Name = 'Tahoma'
+  Font.Style = []
+  FormStyle = fsMDIChild
+  KeyPreview = True
+  OldCreateOrder = False
+  Visible = True
+  WindowState = wsMaximized
+  OnClose = FormClose
+  OnCloseQuery = FormCloseQuery
+  OnCreate = FormCreate
+  OnKeyUp = FormKeyUp
+  OnResize = FormResize
+  PixelsPerInch = 96
+  TextHeight = 13
+  object Splitter1: TSplitter
+    Left = 200
+    Top = 0
+    Width = 9
+    Height = 640
+    AutoSnap = False
+    Beveled = True
+    MinSize = 150
+    ExplicitLeft = 150
+  end
+  object panel_data: TPanel
+    Left = 209
+    Top = 0
+    Width = 433
+    Height = 640
+    Align = alClient
+    BevelOuter = bvNone
+    TabOrder = 0
+    OnResize = panel_dataResize
+    object Splitter2: TSplitter
+      Left = 0
+      Top = 450
+      Width = 433
+      Height = 9
+      Cursor = crVSplit
+      Align = alTop
+      AutoSnap = False
+      Beveled = True
+      MinSize = 40
+      ExplicitTop = 209
+      ExplicitWidth = 483
+    end
+    object hex: TMPHexEditor
+      Left = 0
+      Top = 0
+      Width = 433
+      Height = 450
+      Cursor = crIBeam
+      Align = alTop
+      Font.Charset = DEFAULT_CHARSET
+      Font.Color = clWindowText
+      Font.Height = -16
+      Font.Name = 'Courier'
+      Font.Style = []
+      OnKeyUp = hexKeyUp
+      ParentFont = False
+      TabOrder = 0
+      BytesPerRow = 16
+      Translation = tkAsIs
+      OffsetFormat = '6!10:0x|'
+      Colors.Background = clWindow
+      Colors.ChangedBackground = clWindow
+      Colors.ChangedText = clRed
+      Colors.CursorFrame = clNavy
+      Colors.Offset = clBlack
+      Colors.OddColumn = clBlue
+      Colors.EvenColumn = clNavy
+      Colors.CurrentOffsetBackground = clBtnShadow
+      Colors.OffsetBackGround = clBtnFace
+      Colors.CurrentOffset = clBtnHighlight
+      Colors.Grid = clBtnFace
+      Colors.NonFocusCursorFrame = clAqua
+      Colors.ActiveFieldBackground = clWindow
+      FocusFrame = True
+      NoSizeChange = True
+      AllowInsertMode = False
+      DrawGridLines = False
+      Version = 'May 23, 2005; '#169' markus stephany, vcl[at]mirkes[dot]de'
+      OnChange = hexChange
+      ShowPositionIfNotFocused = True
+      OnSelectionChanged = hexSelectionChanged
+    end
+    object value_viewer: TWrapGrid
+      Left = 0
+      Top = 459
+      Width = 433
+      Height = 181
+      Align = alClient
+      ColCount = 1
+      DefaultColWidth = 80
+      DefaultRowHeight = 18
+      FixedCols = 0
+      RowCount = 8
+      FixedRows = 0
+      Font.Charset = DEFAULT_CHARSET
+      Font.Color = clWindowText
+      Font.Height = -11
+      Font.Name = 'Tahoma'
+      Font.Style = []
+      Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goColSizing]
+      ParentFont = False
+      PopupMenu = value_viewer_context
+      TabOrder = 1
+      OnDblClick = value_viewerDblClick
+      OnMouseDown = value_viewerMouseDown
+    end
+  end
+  object panel_files: TPanel
+    Left = 0
+    Top = 0
+    Width = 200
+    Height = 640
+    Align = alLeft
+    BevelOuter = bvNone
+    TabOrder = 1
+    object Splitter4: TSplitter
+      Left = 0
+      Top = 442
+      Width = 200
+      Height = 9
+      Cursor = crVSplit
+      Align = alBottom
+      AutoSnap = False
+      Beveled = True
+      MinSize = 150
+      ExplicitWidth = 150
+    end
+    object panel_imexport: TPanel
+      Left = 0
+      Top = 580
+      Width = 200
+      Height = 60
+      Align = alBottom
+      BevelOuter = bvNone
+      TabOrder = 0
+      OnResize = panel_imexportResize
+      object btn_export: TButton
+        Left = 4
+        Top = 4
+        Width = 142
+        Height = 25
+        Caption = 'Export to file...'
+        TabOrder = 0
+        OnClick = btn_exportClick
+      end
+      object btn_import: TButton
+        Left = 4
+        Top = 32
+        Width = 142
+        Height = 25
+        Caption = 'Import from file...'
+        TabOrder = 1
+        OnClick = btn_importClick
+      end
+    end
+    object group_file: TGroupBox
+      Left = 0
+      Top = 0
+      Width = 200
+      Height = 442
+      Align = alClient
+      Caption = '1. Select file'
+      TabOrder = 1
+      object list: TListBox
+        Left = 2
+        Top = 15
+        Width = 196
+        Height = 337
+        Align = alClient
+        ItemHeight = 13
+        TabOrder = 0
+        OnClick = listClick
+        OnMouseDown = listMouseDown
+      end
+      object panel_extension: TPanel
+        Left = 2
+        Top = 352
+        Width = 196
+        Height = 88
+        Align = alBottom
+        BevelOuter = bvNone
+        TabOrder = 1
+        OnResize = panel_extensionResize
+        object lbl_filter: TLabel
+          Left = 2
+          Top = 46
+          Width = 100
+          Height = 17
+          AutoSize = False
+          Caption = 'Filter by &extension:'
+          FocusControl = combo_extension
+        end
+        object combo_extension: TComboBox
+          Left = 2
+          Top = 60
+          Width = 145
+          Height = 21
+          Style = csDropDownList
+          DropDownCount = 12
+          Font.Charset = DEFAULT_CHARSET
+          Font.Color = clWindowText
+          Font.Height = -11
+          Font.Name = 'Tahoma'
+          Font.Style = []
+          ItemHeight = 13
+          ParentFont = False
+          Sorted = True
+          TabOrder = 2
+          OnClick = combo_extensionClick
+        end
+        object edit_filtername: TEdit
+          Left = 2
+          Top = 20
+          Width = 145
+          Height = 18
+          AutoSize = False
+          TabOrder = 1
+        end
+        object check_filtername: TCheckBox
+          Left = 2
+          Top = 5
+          Width = 130
+          Height = 15
+          Caption = 'Filter by file&name:'
+          TabOrder = 0
+          OnClick = check_filternameClick
+        end
+      end
+    end
+    object GroupBox1: TGroupBox
+      Left = 0
+      Top = 451
+      Width = 200
+      Height = 129
+      Align = alBottom
+      Caption = '2. Select .dat-link-offset'
+      TabOrder = 2
+      object list_offset: TListBox
+        Left = 2
+        Top = 15
+        Width = 196
+        Height = 112
+        Align = alClient
+        ItemHeight = 13
+        TabOrder = 0
+        OnClick = list_offsetClick
+      end
+    end
+  end
+  object value_viewer_context: TPopupMenu
+    AutoHotkeys = maManual
+    OnPopup = value_viewer_contextPopup
+    Left = 368
+    Top = 264
+    object value_viewer_context_copy: TMenuItem
+      Caption = 'Copy to &clipboard'
+      OnClick = value_viewer_context_copyClick
+    end
+    object value_viewer_context_copyasdec: TMenuItem
+      Caption = 'Copy to clipboard (as &dec)'
+      OnClick = value_viewer_context_copyClick
+    end
+    object value_viewer_context_copyasfloat: TMenuItem
+      Caption = 'Copy to clipboard (as &float)'
+      OnClick = value_viewer_context_copyClick
+    end
+    object value_viewer_context_copyasbitset: TMenuItem
+      Caption = 'Copy to clipboard (as &bitset)'
+      OnClick = value_viewer_context_copyClick
+    end
+    object value_viewer_context_copyasstring: TMenuItem
+      Caption = 'Copy to clipboard (as &string)'
+      OnClick = value_viewer_context_copyClick
+    end
+    object value_viewer_context_copyashex: TMenuItem
+      Caption = 'Copy to clipboard (as &hex)'
+      OnClick = value_viewer_context_copyClick
+    end
+  end
+  object opend: TOpenDialog
+    Options = [ofPathMustExist, ofFileMustExist, ofEnableSizing]
+    Left = 120
+    Top = 584
+  end
+  object saved: TSaveDialog
+    Options = [ofOverwritePrompt, ofPathMustExist, ofEnableSizing]
+    Left = 120
+    Top = 608
+  end
+end
Index: oup/current/Tool_RawEdit.pas
===================================================================
--- oup/current/Tool_RawEdit.pas	(revision 43)
+++ oup/current/Tool_RawEdit.pas	(revision 43)
@@ -0,0 +1,968 @@
+unit Tool_RawEdit;
+
+interface
+
+uses
+  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
+  Dialogs, Wrapgrid, StdCtrls, Grids, StrUtils, MPHexEditor, ExtCtrls, Clipbrd,
+  Data, Code_Functions, Code_DataStructures, Code_Exporters, Code_OniDataClass,
+  Menus, Math;
+
+type
+  TForm_RawEdit = class(TForm)
+    Splitter1: TSplitter;
+    panel_data: TPanel;
+    hex:   TMPHexEditor;
+    Splitter2: TSplitter;
+    value_viewer: TWrapGrid;
+    value_viewer_context: TPopupMenu;
+    value_viewer_context_copy: TMenuItem;
+    value_viewer_context_copyashex: TMenuItem;
+    value_viewer_context_copyasdec: TMenuItem;
+    value_viewer_context_copyasfloat: TMenuItem;
+    value_viewer_context_copyasbitset: TMenuItem;
+    value_viewer_context_copyasstring: TMenuItem;
+    panel_files: TPanel;
+    opend: TOpenDialog;
+    saved: TSaveDialog;
+    panel_imexport: TPanel;
+    btn_export: TButton;
+    btn_import: TButton;
+    group_file: TGroupBox;
+    list:  TListBox;
+    panel_extension: TPanel;
+    lbl_filter: TLabel;
+    combo_extension: TComboBox;
+    edit_filtername: TEdit;
+    check_filtername: TCheckBox;
+    GroupBox1: TGroupBox;
+    list_offset: TListBox;
+    Splitter4: TSplitter;
+    procedure hexKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
+    procedure list_offsetClick(Sender: TObject);
+    procedure LoadRaw(raw_info: TRawInfo);
+    procedure LoadFileNames;
+    procedure check_filternameClick(Sender: TObject);
+    procedure combo_extensionClick(Sender: TObject);
+    procedure panel_extensionResize(Sender: TObject);
+    procedure listClick(Sender: TObject);
+    procedure Recreatelist;
+
+    procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
+    procedure value_viewerDblClick(Sender: TObject);
+    procedure value_viewer_context_copyClick(Sender: TObject);
+    procedure value_viewerMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure value_viewer_contextPopup(Sender: TObject);
+    procedure btn_importClick(Sender: TObject);
+    procedure btn_exportClick(Sender: TObject);
+    procedure panel_imexportResize(Sender: TObject);
+    function Save: Boolean;
+    procedure FormClose(Sender: TObject; var Action: TCloseAction);
+    function GetValue(datatype: Word; offset: LongWord): String;
+    procedure hexSelectionChanged(Sender: TObject);
+    procedure hexChange(Sender: TObject);
+    procedure panel_dataResize(Sender: TObject);
+    procedure FormResize(Sender: TObject);
+    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
+    procedure FormCreate(Sender: TObject);
+    procedure ClearValues;
+    procedure WriteValues;
+    procedure SetNewValue(datatype: Word; offset: LongWord; Value: String);
+    procedure listMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+  private
+    fileid:     LongWord;
+    dat_offset: LongWord;
+    fileid_opened, dat_offset_opened: LongWord;
+  public
+  end;
+
+var
+  Form_RawEdit: TForm_RawEdit;
+
+implementation
+
+{$R *.dfm}
+
+uses Main, Helper_ValueEdit;
+
+
+
+
+procedure TForm_RawEdit.LoadRaw(raw_info: TRawInfo);
+var
+  i:    LongWord;
+  Data: Tdata;
+  mem:  TMemoryStream;
+begin
+  if hex.Modified then
+  begin
+    if not Save then
+    begin
+      Exit;
+    end;
+  end;
+  if list_offset.Count = 0 then
+  begin
+    for i := 0 to list.Count - 1 do
+    begin
+      if OniDataConnection.ExtractFileID(list.Items.Strings[i]) = raw_info.src_id then
+      begin
+        list.ItemIndex := i;
+        listClick(Self);
+        Break;
+      end;
+    end;
+    for i := 0 to list_offset.Count - 1 do
+    begin
+      if MidStr(list_offset.Items.Strings[i], 3, 8) = IntToHex(raw_info.src_offset, 8) then
+      begin
+        list_offset.ItemIndex := i;
+        Break;
+      end;
+    end;
+  end;
+  SetLength(Data, raw_info.raw_size);
+  OniDataConnection.LoadRawFile(raw_info.src_id, raw_info.src_offset, @Data[0]);
+  if Length(Data) > 0 then
+  begin
+    hex.DataSize := 0;
+    hex.DataSize := raw_info.raw_size;
+    for i := 0 to High(Data) do
+      hex.Data[i] := Data[i];
+    //WriteStructureInfos(GetStructureInfoId(GetFileInfo(fileid).Extension));
+    //      structs.Height:=structs.RowCount*20;
+    //      IF structs.Height>120 THEN structs.Height:=120;
+    hexSelectionChanged(Self);
+    fileid_opened     := raw_info.src_id;
+    dat_offset_opened := raw_info.src_offset;
+    hex.Modified      := False;
+  end
+  else
+  begin
+    ClearValues;
+    hex.DataSize := 0;
+  end;
+end;
+
+
+
+
+procedure TForm_RawEdit.Recreatelist;
+var
+  i:     LongWord;
+  exts:  TStringArray;
+  Count: LongWord;
+begin
+  combo_extension.Items.Clear;
+  combo_extension.Items.Add('_All files_ ('{+IntToStr(dat_header.Files)} + ')');
+  exts := OniDataConnection.GetExtensionsList;
+  for i := 0 to High(RawListHandlers) do
+  begin
+    Count := Length(OniDataConnection.GetFilesList(RawListHandlers[i].Ext, '', True));
+    combo_extension.Items.Add(RawListHandlers[i].ext + ' (' + IntToStr(Count) + ')');
+  end;
+  //    FOR i:=0 TO High(exts) DO
+  //      combo_extension.Items.Add(exts[i]);
+  combo_extension.ItemIndex := 0;
+  combo_extensionClick(Self);
+end;
+
+
+
+
+procedure TForm_RawEdit.LoadFileNames;
+var
+  Extension: String;
+  no_zero_bytes: Boolean;
+  pattern: String;
+  files: TStringArray;
+  i: LongWord;
+begin
+  Extension := MidStr(combo_extension.Items.Strings[combo_extension.ItemIndex], 1, 4);
+  pattern   := '';
+  if check_filtername.Checked then
+    pattern := edit_filtername.Text;
+  if Extension = '_All' then
+  begin
+    Extension := '';
+    for i := 0 to High(RawListHandlers) do
+    begin
+      if Length(Extension) > 0 then
+        Extension := Extension + ',';
+      Extension := Extension + RawListHandlers[i].Ext;
+    end;
+  end;
+
+  files := OniDataConnection.GetFilesList(extension, pattern, True);
+  list.Items.Clear;
+  if Length(files) > 0 then
+    for i := 0 to High(files) do
+      list.Items.Add(files[i]);
+  list_offset.Items.Clear;
+end;
+
+
+
+
+procedure TForm_RawEdit.panel_extensionResize(Sender: TObject);
+begin
+  combo_extension.Width := panel_extension.Width - 5;
+  edit_filtername.Width := panel_extension.Width - 5;
+end;
+
+
+
+
+procedure TForm_RawEdit.combo_extensionClick(Sender: TObject);
+begin
+  LoadFileNames;
+end;
+
+
+
+
+procedure TForm_RawEdit.check_filternameClick(Sender: TObject);
+begin
+  edit_filtername.Enabled := not check_filtername.Checked;
+  LoadFileNames;
+end;
+
+
+
+
+procedure TForm_RawEdit.listClick(Sender: TObject);
+var
+  mem:  TMemoryStream;
+  Data: Tdata;
+  i:    LongWord;
+  offsets: TRawList;
+begin
+  if hex.Modified then
+  begin
+    if not Save then
+    begin
+      Exit;
+    end;
+  end;
+  ClearValues;
+  hex.DataSize := 0;
+  fileid := OniDataConnection.ExtractFileID(list.Items.Strings[list.ItemIndex]);
+  list_offset.Enabled := True;
+  if OniDataConnection.GetFileInfo(fileid).size > 0 then
+  begin
+    offsets := OniDataConnection.GetRawList(fileid);
+    list_offset.Items.Clear;
+    if Length(offsets) > 0 then
+    begin
+      for i := 0 to High(offsets) do
+      begin
+        list_offset.Items.Add('0x' + IntToHex(offsets[i].src_offset, 8) +
+          ', ' + IntToStr(offsets[i].raw_size) + ' bytes');
+      end;
+    end
+    else
+    begin
+      list_offset.Enabled := False;
+    end;
+  end
+  else
+  begin
+    list_offset.Enabled := False;
+  end;
+end;
+
+
+
+
+procedure TForm_RawEdit.listMouseDown(Sender: TObject; Button: TMouseButton;
+  Shift: TShiftState; X, Y: Integer);
+var
+  pt: TPoint;
+begin
+  pt.X := x;
+  pt.Y := y;
+  list.ItemIndex := list.ItemAtPos(pt, true);
+  if list.ItemIndex > -1 then
+    Self.listClick(Self);
+end;
+
+procedure TForm_RawEdit.list_offsetClick(Sender: TObject);
+var
+  i: LongWord;
+  raw_info: TRawInfo;
+begin
+  ClearValues;
+  dat_offset := StrToInt('$' + MidStr(
+    list_offset.Items.Strings[list_offset.ItemIndex], 3, 8));
+  LoadRaw(OniDataConnection.GetRawInfo(fileid, dat_offset));
+end;
+
+
+
+
+function IntToBin(Value: Byte): String;
+var
+  i: Byte;
+begin
+  Result := '';
+  for i := 7 downto 0 do
+  begin
+    Result := Result + IntToStr((Value shr i) and $01);
+  end;
+end;
+
+
+
+
+function TForm_RawEdit.GetValue(datatype: Word; offset: LongWord): String;
+var
+  Data: Tdata;
+  i:    Word;
+begin
+  case datatype of
+    1:
+      Result := IntToStr(hex.Data[offset]);
+    2:
+      Result := IntToStr(hex.Data[offset] + hex.Data[offset + 1] * 256);
+    3:
+      Result := IntToStr(hex.Data[offset] + hex.Data[offset + 1] * 256 + hex.Data[offset + 2] * 256 * 256);
+    4:
+      Result := IntToStr(hex.Data[offset] + hex.Data[offset + 1] * 256 + hex.Data[offset + 2] *
+        256 * 256 + hex.Data[offset + 3] * 256 * 256 * 256);
+    5:
+      Result := '0x' + IntToHex(hex.Data[offset], 2);
+    6:
+      Result := '0x' + IntToHex(hex.Data[offset] + hex.Data[offset + 1] * 256, 4);
+    7:
+      Result := '0x' + IntToHex(hex.Data[offset] + hex.Data[offset + 1] * 256 +
+        hex.Data[offset + 2] * 256 * 256, 6);
+    8:
+      Result := '0x' + IntToHex(hex.Data[offset] + hex.Data[offset + 1] * 256 +
+        hex.Data[offset + 2] * 256 * 256 + hex.Data[offset + 3] * 256 * 256 * 256, 8);
+    9:
+    begin
+      SetLength(Data, 4);
+      Data[0] := hex.Data[offset];
+      Data[1] := hex.Data[offset + 1];
+      Data[2] := hex.Data[offset + 2];
+      Data[3] := hex.Data[offset + 3];
+      Result  := FloatToStr(Decode_Float(Data));
+    end;
+    10:
+      Result := IntToBin(hex.Data[offset]);
+    11:
+      Result := '0x' + IntToHex(hex.Data[offset] + hex.Data[offset + 1] * 256 +
+        hex.Data[offset + 2] * 256 * 256 + hex.Data[offset + 3] * 256 * 256 * 256, 8);
+    10000..65535:
+    begin
+      Result := '';
+      for i := 1 to datatype - 10000 do
+      begin
+        if hex.Data[offset + i - 1] >= 32 then
+          Result := Result + Chr(hex.Data[offset + i - 1])
+        else
+          Result := Result + '.';
+      end;
+    end;
+  end;
+end;
+
+
+
+
+procedure TForm_RawEdit.ClearValues;
+var
+  i: Byte;
+begin
+  for i := 1 to value_viewer.RowCount - 1 do
+  begin
+    value_viewer.Cells[1, i] := '';
+  end;
+end;
+
+
+
+
+procedure TForm_RawEdit.WriteValues;
+var
+  i, j:  Byte;
+  Data:  Tdata;
+  str:   String;
+  Value: LongWord;
+begin
+  for i := 1 to value_viewer.RowCount - 1 do
+  begin
+    if value_viewer.Cells[0, i] = '1 byte, unsigned' then
+    begin
+      if ((hex.SelCount = 1) or (hex.SelCount = 0)) and not
+        ((hex.SelStart + 1) > hex.DataSize) then
+      begin
+        Value := hex.Data[hex.SelStart];
+        value_viewer.Cells[1, i] := IntToStr(Value) + ' / 0x' + IntToHex(Value, 2);
+      end
+      else
+        value_viewer.Cells[1, i] := '';
+    end;
+    if value_viewer.Cells[0, i] = '2 bytes, unsigned' then
+    begin
+      if ((hex.SelCount = 2) or (hex.SelCount = 0)) and not
+        ((hex.SelStart + 2) > hex.DataSize) then
+      begin
+        Value := hex.Data[hex.SelStart] + hex.Data[hex.SelStart + 1] * 256;
+        value_viewer.Cells[1, i] := IntToStr(Value) + ' / 0x' + IntToHex(Value, 4);
+      end
+      else
+        value_viewer.Cells[1, i] := '';
+    end;
+    if value_viewer.Cells[0, i] = '4 bytes, unsigned' then
+    begin
+      if ((hex.SelCount = 4) or (hex.SelCount = 0)) and not
+        ((hex.SelStart + 4) > hex.DataSize) then
+      begin
+        Value := hex.Data[hex.SelStart] + hex.Data[hex.SelStart + 1] * 256 +
+          hex.Data[hex.SelStart + 2] * 256 * 256 + hex.Data[hex.SelStart + 3] * 256 * 256 * 256;
+        value_viewer.Cells[1, i] := IntToStr(Value) + ' / 0x' + IntToHex(Value, 8);
+      end
+      else
+        value_viewer.Cells[1, i] := '';
+    end;
+    if value_viewer.Cells[0, i] = 'Bitset' then
+    begin
+      if (hex.SelCount <= 8) then
+      begin
+        if hex.SelCount = 0 then
+        begin
+          SetLength(Data, 1);
+          Data[0] := hex.Data[hex.SelStart];
+        end
+        else
+        begin
+          SetLength(Data, hex.SelCount);
+          for j := 0 to hex.SelCount - 1 do
+            Data[j] := hex.Data[hex.SelStart + j];
+        end;
+        value_viewer.Cells[1, i] := DataToBin(Data);
+      end
+      else
+        value_viewer.Cells[1, i] := '';
+    end;
+    if value_viewer.Cells[0, i] = 'Float' then
+    begin
+      if ((hex.SelCount = 4) or (hex.SelCount = 0)) and not
+        ((hex.SelStart + 4) > hex.DataSize) then
+      begin
+        SetLength(Data, 4);
+        for j := 0 to 3 do
+          Data[j] := hex.Data[hex.SelStart + j];
+        value_viewer.Cells[1, i] := FloatToStr(Decode_Float(Data));
+      end
+      else
+        value_viewer.Cells[1, i] := '';
+    end;
+    if value_viewer.Cells[0, i] = 'Selected length' then
+    begin
+      value_viewer.Cells[1, i] := IntToStr(hex.SelCount) + ' bytes';
+    end;
+    if value_viewer.Cells[0, i] = 'String' then
+    begin
+      j   := 0;
+      str := '';
+      if hex.SelCount = 0 then
+      begin
+        while (hex.Data[hex.SelStart + j] > 0) and ((hex.SelStart + j) < hex.DataSize) do
+        begin
+          if hex.Data[hex.selstart + j] >= 32 then
+            str := str + Char(hex.Data[hex.SelStart + j])
+          else
+            str := str + '.';
+          Inc(j);
+        end;
+      end
+      else
+      begin
+        for j := 0 to hex.SelCount - 1 do
+          if hex.Data[hex.selstart + j] >= 32 then
+            str := str + Char(hex.Data[hex.SelStart + j])
+          else if hex.Data[hex.selstart + j] > 0 then
+            str := str + '.'
+          else
+            Break;
+      end;
+      value_viewer.Cells[1, i] := str;
+    end;
+  end;
+end;
+
+
+
+
+procedure TForm_RawEdit.FormCreate(Sender: TObject);
+begin
+  Self.Caption := '';
+  fileid     := 0;
+  value_viewer.ColCount := 2;
+  value_viewer.RowCount := 8;
+  value_viewer.FixedRows := 1;
+  value_viewer.Cells[0, 0] := 'Type';
+  value_viewer.Cells[1, 0] := 'Value';
+  value_viewer.Cells[0, 1] := '1 byte, unsigned';
+  value_viewer.Cells[0, 2] := '2 bytes, unsigned';
+  value_viewer.Cells[0, 3] := '4 bytes, unsigned';
+  value_viewer.Cells[0, 4] := 'Bitset';
+  value_viewer.Cells[0, 5] := 'Float';
+  value_viewer.Cells[0, 6] := 'String';
+  value_viewer.Cells[0, 7] := 'Selected length';
+  value_viewer.ColWidths[0] := 100;
+  hex.Height := panel_data.Height - 190;
+  Self.panel_dataResize(Self);
+  //
+  value_viewer.Font.Charset := AppSettings.CharSet;
+  //
+end;
+
+
+
+
+function TForm_RawEdit.Save: Boolean;
+var
+  mem:  TMemoryStream;
+  Data: Tdata;
+  i:    LongWord;
+begin
+  case MessageBox(Self.Handle, PChar('Save changes to .raw-part of file ' +
+      OniDataConnection.GetFileInfo(fileid).FileName + '?'), PChar('Data changed...'),
+      MB_YESNOCANCEL) of
+    idYes:
+    begin
+      mem := TMemoryStream.Create;
+      hex.SaveToStream(mem);
+      mem.Seek(0, soFromBeginning);
+      SetLength(Data, mem.Size);
+      mem.Read(Data[0], mem.Size);
+      mem.Free;
+      OniDataConnection.UpdateRawFile(fileid_opened, dat_offset_opened,
+        Length(Data), @Data[0]);
+      hex.Modified := False;
+      for i := 0 to hex.Datasize - 1 do
+        hex.ByteChanged[i] := False;
+      Result := True;
+    end;
+    idNo:
+      Result := True;
+    idCancel:
+    begin
+      Result := False;
+    end;
+  end;
+end;
+
+
+
+
+procedure TForm_RawEdit.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
+begin
+  if hex.Modified then
+  begin
+    if not Save then
+      CanClose := False;
+  end;
+end;
+
+
+
+
+procedure TForm_RawEdit.FormResize(Sender: TObject);
+begin
+  if Self.Width >= 650 then
+  begin
+  end
+  else
+    Self.Width := 650;
+  if Self.Height >= 450 then
+  begin
+  end
+  else
+    Self.Height := 450;
+end;
+
+
+
+
+procedure TForm_RawEdit.panel_dataResize(Sender: TObject);
+begin
+  value_viewer.ColWidths[1] := value_viewer.Width - value_viewer.ColWidths[0] - 28;
+end;
+
+
+
+
+procedure TForm_RawEdit.hexChange(Sender: TObject);
+begin
+  ClearValues;
+  if hex.DataSize > 0 then
+  begin
+{      WriteStructureInfos(GetStructureInfoId(GetFileInfo(fileid).Extension));
+      WriteValues;
+}    end;
+end;
+
+
+
+
+procedure TForm_RawEdit.hexKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
+var
+  temps: String;
+begin
+  if (Shift = [ssCtrl]) and (Key = Ord('C')) then
+  begin
+    if hex.SelCount > 0 then
+    begin
+      if hex.InCharField then
+        Clipboard.AsText := hex.SelectionAsText
+      else
+        Clipboard.AsText := hex.SelectionAsHex;
+    end;
+  end;
+  if (Shift = [ssCtrl]) and (Key = Ord('V')) then
+  begin
+{      temps:=Clipboard.AsText;
+      IF hex.SelStart+Length(temps)>hex.DataSize THEN
+        SetLength(temps, hex.DataSize-hex.SelStart);
+      hex.Sel
+      hex.SelCount:=Length(temps);
+      hex.ReplaceSelection(temps,Length(temps));
+}    end;
+end;
+
+
+
+
+procedure TForm_RawEdit.hexSelectionChanged(Sender: TObject);
+var
+  selstart: Integer;
+  i, j:     Word;
+begin
+{    FOR i:=1 TO structs.RowCount-1 DO BEGIN
+      FOR j:=0 TO structs.ColCount-1 DO BEGIN
+        structs.CellColors[j,i]:=clWhite;
+        structs.CellFontColors[j,i]:=clBlack;
+      END;
+    END;
+}    if hex.DataSize > 0 then
+  begin
+{      selstart:=hex.SelStart;
+      IF GetStructureInfoId(GetFileInfo(fileid).Extension)>=0 THEN BEGIN
+        WITH structure_infos[GetStructureInfoId(GetFileInfo(fileid).Extension)] DO BEGIN
+          FOR i:=0 TO High(entries) DO BEGIN
+            IF ((selstart-entries[i].offset)<GetTypeDataLength(entries[i].datatype)) AND ((selstart-entries[i].offset)>=0) THEN BEGIN
+              FOR j:=0 TO structs.ColCount-1 DO BEGIN
+                structs.CellColors[j,i+1]:=clBlue;
+                structs.CellFontColors[j,i+1]:=clWhite;
+              END;
+              structs.Row:=i+1;
+            END;
+          END;
+        END;
+      END;
+}      WriteValues;
+  end;
+end;
+
+
+
+
+procedure TForm_RawEdit.FormClose(Sender: TObject; var Action: TCloseAction);
+begin
+  Action := caFree;
+end;
+
+
+
+
+procedure TForm_RawEdit.panel_imexportResize(Sender: TObject);
+begin
+  btn_import.Width := panel_imexport.Width - 8;
+  btn_export.Width := panel_imexport.Width - 8;
+end;
+
+
+
+
+procedure TForm_RawEdit.btn_exportClick(Sender: TObject);
+var
+  fs: TFileStream;
+begin
+  saved.Filter     := 'Files of matching extension (*.' + OniDataConnection.GetFileInfo(
+    fileid).Extension + ')|*.' + OniDataConnection.GetFileInfo(fileid).Extension +
+    '|All files|*.*';
+  saved.DefaultExt := OniDataConnection.GetFileInfo(fileid).Extension;
+  if saved.Execute then
+  begin
+    fs := TFileStream.Create(saved.FileName, fmCreate);
+    hex.SaveToStream(fs);
+    fs.Free;
+  end;
+end;
+
+
+
+
+procedure TForm_RawEdit.btn_importClick(Sender: TObject);
+var
+  Data: Tdata;
+  fs:   TFileStream;
+begin
+  opend.Filter := 'Files of matching extension (*.' + OniDataConnection.GetFileInfo(
+    fileid).Extension + ')|*.' + OniDataConnection.GetFileInfo(fileid).Extension +
+    '|All files|*.*';
+  if opend.Execute then
+  begin
+    fs := TFileStream.Create(opend.FileName, fmOpenRead);
+    if fs.Size <> hex.DataSize then
+    begin
+      ShowMessage('Can''t import ' + ExtractFilename(opend.FileName) +
+        ', file has to have same size as file in .dat.' + CrLf +
+        'Size of file in .dat: ' + FormatFileSize(hex.datasize) + CrLf +
+        'Size of chosen file: ' + FormatFileSize(fs.Size));
+    end
+    else
+    begin
+      hex.LoadFromStream(fs);
+      hex.Modified := True;
+    end;
+    fs.Free;
+  end;
+end;
+
+
+
+
+procedure TForm_RawEdit.value_viewer_contextPopup(Sender: TObject);
+var
+  i: Byte;
+begin
+  for i := 0 to value_viewer_context.Items.Count - 1 do
+    value_viewer_context.Items.Items[i].Visible := False;
+  with value_viewer do
+  begin
+    if (Col = 1) and (Row > 0) and (Length(Cells[Col, Row]) > 0) then
+    begin
+      if Pos(' byte', Cells[0, Row]) = 2 then
+      begin
+        value_viewer_context.Items.Find('Copy to &clipboard').Visible := True;
+        value_viewer_context.Items.Find('Copy to clipboard (as &dec)').Visible := True;
+        value_viewer_context.Items.Find('Copy to clipboard (as &hex)').Visible := True;
+      end;
+      if Pos('Float', Cells[0, Row]) = 1 then
+        value_viewer_context.Items.Find('Copy to clipboard (as &float)').Visible := True;
+      if Pos('Bitset', Cells[0, Row]) = 1 then
+        value_viewer_context.Items.Find(
+          'Copy to clipboard (as &bitset)').Visible := True;
+      if Pos('String', Cells[0, Row]) = 1 then
+        value_viewer_context.Items.Find(
+          'Copy to clipboard (as &string)').Visible := True;
+      if Pos('Selected length', Cells[0, Row]) = 1 then
+        value_viewer_context.Items.Find('Copy to &clipboard').Visible := True;
+    end;
+  end;
+end;
+
+
+
+
+procedure TForm_RawEdit.value_viewerMouseDown(Sender: TObject; Button: TMouseButton;
+  Shift: TShiftState; X, Y: Integer);
+var
+  ACol, ARow: Integer;
+begin
+  if Button = mbRight then
+  begin
+    value_viewer.MouseToCell(x, y, ACol, ARow);
+    if ARow > 0 then
+    begin
+      value_viewer.Col := ACol;
+      value_viewer.Row := ARow;
+    end;
+  end;
+end;
+
+
+
+
+procedure TForm_RawEdit.value_viewer_context_copyClick(Sender: TObject);
+var
+  i:     Byte;
+  Name:  String;
+  Value: LongWord;
+begin
+  Name := TMenuItem(Sender).Name;
+  if Pos('asstring', Name) > 0 then
+  begin
+    Clipboard.AsText := value_viewer.Cells[value_viewer.Col, value_viewer.Row];
+  end
+  else if Pos('asfloat', Name) > 0 then
+  begin
+    Clipboard.AsText := value_viewer.Cells[value_viewer.Col, value_viewer.Row];
+  end
+  else if Pos('asbitset', Name) > 0 then
+  begin
+    Clipboard.AsText := value_viewer.Cells[value_viewer.Col, value_viewer.Row];
+  end
+  else if (Pos('ashex', Name) > 0) or (Pos('asdec', Name) > 0) then
+  begin
+    if value_viewer.Cells[0, value_viewer.Row] = '1 byte, unsigned' then
+    begin
+      if ((hex.SelCount = 1) or (hex.SelCount = 0)) and not
+        ((hex.SelStart + 1) > hex.DataSize) then
+        Value := hex.Data[hex.SelStart];
+    end;
+    if value_viewer.Cells[0, value_viewer.Row] = '2 bytes, unsigned' then
+    begin
+      if ((hex.SelCount = 2) or (hex.SelCount = 0)) and not
+        ((hex.SelStart + 2) > hex.DataSize) then
+        Value := hex.Data[hex.SelStart] + hex.Data[hex.SelStart + 1] * 256;
+    end;
+    if value_viewer.Cells[0, value_viewer.Row] = '4 bytes, unsigned' then
+    begin
+      if ((hex.SelCount = 4) or (hex.SelCount = 0)) and not
+        ((hex.SelStart + 4) > hex.DataSize) then
+        Value := hex.Data[hex.SelStart] + hex.Data[hex.SelStart + 1] * 256 +
+          hex.Data[hex.SelStart + 2] * 256 * 256 + hex.Data[hex.SelStart + 3] * 256 * 256 * 256;
+    end;
+    if Pos('asdec', Name) > 0 then
+    begin
+      Clipboard.AsText := IntToStr(Value);
+    end
+    else
+    begin
+      if value_viewer.Cells[0, value_viewer.Row] = '1 byte, unsigned' then
+        Clipboard.AsText := '0x' + IntToHex(Value, 2);
+      if value_viewer.Cells[0, value_viewer.Row] = '2 bytes, unsigned' then
+        Clipboard.AsText := '0x' + IntToHex(Value, 4);
+      if value_viewer.Cells[0, value_viewer.Row] = '4 bytes, unsigned' then
+        Clipboard.AsText := '0x' + IntToHex(Value, 8);
+    end;
+  end
+  else
+  begin
+    Clipboard.AsText := value_viewer.Cells[value_viewer.Col, value_viewer.Row];
+  end;
+end;
+
+
+
+
+procedure TForm_RawEdit.SetNewValue(datatype: Word; offset: LongWord; Value: String);
+var
+  Data: Tdata;
+  value_int: LongWord;
+  value_float: Single;
+  i: Word;
+begin
+  case datatype of
+    1..4:
+    begin
+      value_int := StrToInt(Value);
+      SetLength(Data, datatype);
+      for i := 0 to datatype - 1 do
+      begin
+        Data[i]   := value_int mod 256;
+        value_int := value_int div 256;
+      end;
+    end;
+    5..8:
+    begin
+      value_int := StrToInt('$' + Value);
+      SetLength(Data, datatype - 4);
+      for i := 0 to datatype - 5 do
+      begin
+        Data[i]   := value_int mod 256;
+        value_int := value_int div 256;
+      end;
+    end;
+    9:
+    begin
+      value_float := StrToFloat(Value);
+      Data := Encode_Float(value_float);
+    end;
+    10:
+    begin
+      value_int := BinToInt(Value);
+      SetLength(Data, 1);
+      Data[0] := value_int;
+    end;
+    10000..65535:
+    begin
+      SetLength(Data, datatype - 10000);
+      for i := 1 to datatype - 10000 do
+      begin
+        if i <= Length(Value) then
+          Data[i - 1] := Ord(Value[i])
+        else
+          Data[i - 1] := 0;
+      end;
+    end;
+  end;
+  for i := 0 to High(Data) do
+  begin
+    if hex.Data[offset + i] <> Data[i] then
+      hex.ByteChanged[offset + i] := True;
+    hex.Data[offset + i] := Data[i];
+  end;
+  hex.Modified := True;
+  hexChange(Self);
+  hex.Repaint;
+end;
+
+
+
+
+procedure TForm_RawEdit.value_viewerDblClick(Sender: TObject);
+var
+  offset:     LongWord;
+  datatype:   Word;
+  objectname: String;
+  Value:      String;
+begin
+  if (value_viewer.Col = 1) and (Length(value_viewer.Cells[1, value_viewer.Row]) > 0) then
+  begin
+    offset := hex.SelStart;
+    if value_viewer.Cells[0, value_viewer.Row] = '1 byte, unsigned' then
+      datatype := 1;
+    if value_viewer.Cells[0, value_viewer.Row] = '2 bytes, unsigned' then
+      datatype := 2;
+    if value_viewer.Cells[0, value_viewer.Row] = '4 bytes, unsigned' then
+      datatype := 4;
+    if value_viewer.Cells[0, value_viewer.Row] = 'Bitset' then
+      datatype := 10;
+    if value_viewer.Cells[0, value_viewer.Row] = 'Float' then
+      datatype := 9;
+    if value_viewer.Cells[0, value_viewer.Row] = 'Selected length' then
+      Exit;
+    if value_viewer.Cells[0, value_viewer.Row] = 'String' then
+    begin
+      if hex.SelCount > 0 then
+        datatype := 10000 + hex.SelCount
+      else
+        datatype := 10000 + Length(value_viewer.Cells[1, value_viewer.Row]);
+    end;
+    objectname := '';
+    Value      := GetValue(datatype, offset);
+    Form_ValueEdit.MakeVarInput(objectname, offset, datatype, Value, Self);
+  end;
+end;
+
+
+
+
+procedure TForm_RawEdit.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
+begin
+  if (Shift = [ssCtrl]) and (Key = 83) then
+    if hex.Modified then
+      if not Save then
+        Exit;
+end;
+
+end.
Index: oup/current/Tool_TxmpReplace.dfm
===================================================================
--- oup/current/Tool_TxmpReplace.dfm	(revision 43)
+++ oup/current/Tool_TxmpReplace.dfm	(revision 43)
@@ -0,0 +1,183 @@
+object Form_TxmpReplace: TForm_TxmpReplace
+  Left = 0
+  Top = 0
+  BorderStyle = bsSingle
+  Caption = 'TXMP Replacer'
+  ClientHeight = 428
+  ClientWidth = 394
+  Color = clBtnFace
+  Font.Charset = DEFAULT_CHARSET
+  Font.Color = clWindowText
+  Font.Height = -11
+  Font.Name = 'Tahoma'
+  Font.Style = []
+  FormStyle = fsMDIChild
+  OldCreateOrder = False
+  Visible = True
+  WindowState = wsMaximized
+  OnClose = FormClose
+  OnCreate = FormCreate
+  PixelsPerInch = 96
+  TextHeight = 13
+  object panel_12: TPanel
+    Left = 0
+    Top = 0
+    Width = 394
+    Height = 349
+    Align = alClient
+    BevelOuter = bvNone
+    TabOrder = 0
+    object Splitter1: TSplitter
+      Left = 280
+      Top = 0
+      Width = 8
+      Height = 349
+      AutoSnap = False
+      Beveled = True
+      MinSize = 150
+      ExplicitLeft = 200
+    end
+    object group_txmpselect: TGroupBox
+      Left = 0
+      Top = 0
+      Width = 280
+      Height = 349
+      Align = alLeft
+      Caption = '1. Select TXMP to replace'
+      TabOrder = 0
+      object splitter_txmp: TSplitter
+        Left = 2
+        Top = 190
+        Width = 276
+        Height = 8
+        Cursor = crVSplit
+        Align = alTop
+        AutoSnap = False
+        Beveled = True
+        MinSize = 60
+        ExplicitWidth = 196
+      end
+      object image_txmppreview: TImage
+        Left = 2
+        Top = 198
+        Width = 276
+        Height = 119
+        Align = alClient
+        ExplicitWidth = 196
+      end
+      object list_txmp: TListBox
+        Left = 2
+        Top = 15
+        Width = 276
+        Height = 175
+        Align = alTop
+        ItemHeight = 13
+        TabOrder = 0
+        OnClick = list_txmpClick
+        OnMouseDown = list_txmpMouseDown
+      end
+      object panel_txmppreview: TPanel
+        Left = 2
+        Top = 317
+        Width = 276
+        Height = 30
+        Align = alBottom
+        BevelOuter = bvNone
+        TabOrder = 1
+        object btn_save: TButton
+          Left = 2
+          Top = 2
+          Width = 111
+          Height = 25
+          Caption = 'Save TXMP-Picture'
+          TabOrder = 0
+          OnClick = btn_saveClick
+        end
+      end
+    end
+    object group_bmpselect: TGroupBox
+      Left = 288
+      Top = 0
+      Width = 106
+      Height = 349
+      Align = alClient
+      Caption = '2. Open BMP to replace with'
+      Enabled = False
+      TabOrder = 1
+      object image_bmppreview: TImage
+        Left = 2
+        Top = 45
+        Width = 102
+        Height = 302
+        Align = alClient
+        ExplicitWidth = 182
+      end
+      object panel_load: TPanel
+        Left = 2
+        Top = 15
+        Width = 102
+        Height = 30
+        Align = alTop
+        BevelOuter = bvNone
+        TabOrder = 0
+        object btn_load: TButton
+          Left = 2
+          Top = 2
+          Width = 121
+          Height = 25
+          Caption = 'Load BMP ...'
+          TabOrder = 0
+          OnClick = btn_loadClick
+        end
+      end
+    end
+  end
+  object group_options: TGroupBox
+    Left = 0
+    Top = 349
+    Width = 394
+    Height = 79
+    Align = alBottom
+    Caption = '3. Options && Replace'
+    Enabled = False
+    TabOrder = 1
+    object btn_replace: TButton
+      Left = 4
+      Top = 50
+      Width = 157
+      Height = 25
+      Caption = 'Replace'
+      TabOrder = 0
+      OnClick = btn_replaceClick
+    end
+    object check_transparency: TCheckBox
+      Left = 8
+      Top = 16
+      Width = 105
+      Height = 17
+      Caption = 'Transparency'
+      TabOrder = 1
+    end
+    object check_fading: TCheckBox
+      Left = 8
+      Top = 32
+      Width = 105
+      Height = 17
+      Caption = 'MIP Mapping'
+      TabOrder = 2
+    end
+  end
+  object opend: TOpenDialog
+    Filter = '24bit Bitmap (*.bmp)|*.bmp'
+    Options = [ofPathMustExist, ofFileMustExist, ofEnableSizing]
+    Left = 352
+    Top = 16
+  end
+  object saved: TSaveDialog
+    DefaultExt = 'bmp'
+    Filter = 'Windows Bitmap (*.bmp)|*.bmp'
+    Options = [ofOverwritePrompt, ofHideReadOnly, ofPathMustExist, ofEnableSizing]
+    Left = 104
+    Top = 320
+  end
+end
Index: oup/current/Tool_TxmpReplace.pas
===================================================================
--- oup/current/Tool_TxmpReplace.pas	(revision 43)
+++ oup/current/Tool_TxmpReplace.pas	(revision 43)
@@ -0,0 +1,244 @@
+unit Tool_TxmpReplace;
+
+interface
+
+uses
+  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
+  Dialogs, ExtCtrls, StdCtrls, StrUtils, Code_Functions, Data, Code_OniImgClass;
+
+type
+  TForm_TxmpReplace = class(TForm)
+    panel_12: TPanel;
+    group_txmpselect: TGroupBox;
+    splitter_txmp: TSplitter;
+    list_txmp: TListBox;
+    Splitter1: TSplitter;
+    group_bmpselect: TGroupBox;
+    panel_load: TPanel;
+    btn_load: TButton;
+    image_bmppreview: TImage;
+    opend:    TOpenDialog;
+    group_options: TGroupBox;
+    btn_replace: TButton;
+    check_transparency: TCheckBox;
+    check_fading: TCheckBox;
+    panel_txmppreview: TPanel;
+    btn_save: TButton;
+    image_txmppreview: TImage;
+    saved:    TSaveDialog;
+    procedure FormCreate(Sender: TObject);
+    procedure btn_saveClick(Sender: TObject);
+    procedure FormClose(Sender: TObject; var Action: TCloseAction);
+    procedure btn_replaceClick(Sender: TObject);
+    procedure btn_loadClick(Sender: TObject);
+    procedure list_txmpClick(Sender: TObject);
+    procedure Recreatelist;
+    procedure list_txmpMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+  private
+    OniImage_Old: TOniImage;
+    OniImage_New: TOniImage;
+  public
+  end;
+
+var
+  Form_TxmpReplace: TForm_TxmpReplace;
+
+implementation
+
+uses Main, Code_OniDataClass;
+
+{$R *.dfm}
+
+
+
+procedure TForm_TxmpReplace.Recreatelist;
+var
+  files: TStringArray;
+  i:     LongWord;
+begin
+  list_txmp.Items.Clear;
+  files := OniDataConnection.GetFilesList('TXMP', '', True);
+  if Length(files) > 0 then
+    for i := 0 to High(files) do
+      list_txmp.Items.Add(files[i]);
+  group_bmpselect.Enabled := False;
+  check_transparency.Checked := False;
+  check_fading.Checked := False;
+end;
+
+
+
+
+procedure TForm_TxmpReplace.list_txmpClick(Sender: TObject);
+var
+  id:   LongWord;
+  Data: Tdata;
+  mem:  TMemoryStream;
+  fadingbyte, depthbyte, storebyte: Byte;
+begin
+  id := OniDataConnection.ExtractFileID(list_txmp.Items.Strings[list_txmp.ItemIndex]);
+  OniDataConnection.LoadDatFilePart(id, $88, SizeOf(fadingbyte), @fadingbyte);
+  OniDataConnection.LoadDatFilePart(id, $89, SizeOf(depthbyte), @depthbyte);
+  OniDataConnection.LoadDatFilePart(id, $90, SizeOf(storebyte), @storebyte);
+  check_fading.Checked := (fadingbyte and $01) > 0;
+  check_transparency.Checked := (depthbyte and $04) > 0;
+
+  OniImage_Old.LoadFromTXMP(id);
+  Data := OniImage_Old.GetAsBMP;
+  mem  := TMemoryStream.Create;
+  mem.Write(Data[0], Length(Data));
+  mem.Seek(0, soFromBeginning);
+  image_txmppreview.Picture.Bitmap.LoadFromStream(mem);
+  mem.Free;
+
+  group_bmpselect.Enabled := True;
+end;
+
+
+
+
+procedure TForm_TxmpReplace.list_txmpMouseDown(Sender: TObject;
+  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+var
+  pt: TPoint;
+begin
+  pt.X := x;
+  pt.Y := y;
+  list_txmp.ItemIndex := list_txmp.ItemAtPos(pt, true);
+  if list_txmp.ItemIndex > -1 then
+    Self.list_txmpClick(Self);
+end;
+
+procedure TForm_TxmpReplace.btn_loadClick(Sender: TObject);
+var
+  mem:   TMemoryStream;
+  tempd: Tdata;
+begin
+  if opend.Execute then
+  begin
+    OniImage_New.LoadFromBMP(opend.FileName);
+    tempd := OniImage_New.GetAsBMP;
+    mem   := TMemoryStream.Create;
+    mem.Write(tempd[0], Length(tempd));
+    mem.Seek(0, soFromBeginning);
+    image_bmppreview.Picture.Bitmap.LoadFromStream(mem);
+    mem.Free;
+    group_options.Enabled := True;
+  end;
+end;
+
+
+
+
+procedure TForm_TxmpReplace.btn_replaceClick(Sender: TObject);
+var
+  id: LongWord;
+
+  oldsize, newsize: LongWord;
+  old_rawaddr, new_rawaddr: LongWord;
+  oldfading: Byte;
+  tempd:     Tdata;
+
+  datbyte: Word;
+begin
+  if list_txmp.ItemIndex >= 0 then
+  begin
+    id := OniDataConnection.ExtractFileID(list_txmp.Items.Strings[list_txmp.ItemIndex]);
+    OniDataConnection.LoadDatFilePart(id, $88, 1, @oldfading);
+    if OniDataConnection.OSisMac then
+      OniDataConnection.UpdateDatFilePart(id, $A0, 4, @old_rawaddr)
+    else
+      OniDataConnection.LoadDatFilePart(id, $9C, 4, @old_rawaddr);
+
+    if (OniImage_Old.Width <> OniImage_New.Width) or
+      (OniImage_Old.Height <> OniImage_New.Height) then
+    begin
+      if MessageBox(Self.Handle, PChar(
+        'Current image and new image have different size' + CrLf +
+        '(Current: ' + IntToStr(OniImage_Old.Width) +
+        'x' + IntToStr(OniImage_Old.Height) + ' - New: ' +
+        IntToStr(OniImage_New.Width) + 'x' + IntToStr(OniImage_New.Height) + ')' + CrLf +
+        'Replace anyways?'),
+        PChar(list_txmp.Items.Strings[list_txmp.ItemIndex]),
+        MB_YESNO) = idNo then
+        Exit;
+    end;
+
+    oldsize := OniImage_Old.GetImageDataSize((oldfading and $01) > 0);
+
+    if check_fading.Checked then
+      if not OniImage_New.GetMipMappedImage(tempd) then
+        if MessageBox(Self.Handle,
+          PChar('Can not create a MipMapped-image (probably because of a wrong dimension).' +
+          #13 + #10 + 'Do you want to continue without MipMapping?'), PChar('Warning'),
+          MB_YESNO) = ID_YES then
+          check_fading.Checked := False
+        else
+          Exit;
+
+    if not check_fading.Checked then
+      tempd := OniImage_New.GetAsData;
+
+    newsize := OniImage_New.GetImageDataSize(check_fading.Checked);
+    ShowMessage(IntToStr(newsize));
+
+    if (newsize > oldsize) and (OniDataConnection.Backend = ODB_Dat) then
+      new_rawaddr := OniDataConnection.AppendRawFile(
+        OniDataConnection.OSisMac, Length(tempd), tempd)
+    else
+    begin
+      new_rawaddr := old_rawaddr;
+      OniDataConnection.UpdateRawFile(id, $9C, Length(tempd), tempd);
+    end;
+
+    datbyte := $00;
+    if check_fading.Checked then
+      datbyte := datbyte or $01;
+    OniDataConnection.UpdateDatFilePart(id, $88, 1, @datbyte);
+    datbyte := $10;
+    if check_transparency.Checked then
+      datbyte := datbyte or $04;
+    OniDataConnection.UpdateDatFilePart(id, $89, 1, @datbyte);
+    OniDataConnection.UpdateDatFilePart(id, $8C, 2, @OniImage_New.Width);
+    OniDataConnection.UpdateDatFilePart(id, $8E, 2, @OniImage_New.Height);
+    datbyte := $08;
+    OniDataConnection.UpdateDatFilePart(id, $90, 1, @datbyte);
+    if OniDataConnection.OSisMac then
+      OniDataConnection.UpdateDatFilePart(id, $A0, 4, @new_rawaddr)
+    else
+      OniDataConnection.UpdateDatFilePart(id, $9C, 4, @new_rawaddr);
+
+    ShowMessage('TXMP-image replaced');
+  end;
+end;
+
+
+
+
+procedure TForm_TxmpReplace.FormClose(Sender: TObject; var Action: TCloseAction);
+begin
+  OniImage_Old.Free;
+  OniImage_New.Free;
+  Action := caFree;
+end;
+
+
+
+
+procedure TForm_TxmpReplace.FormCreate(Sender: TObject);
+begin
+  OniImage_Old := TOniImage.Create;
+  OniImage_New := TOniImage.Create;
+end;
+
+
+
+
+procedure TForm_TxmpReplace.btn_saveClick(Sender: TObject);
+begin
+  if saved.Execute then
+    OniImage_Old.WriteToBMP(saved.FileName);
+end;
+
+end.
Index: oup/current/Unit10_leveldb.dfm
===================================================================
--- oup/current/Unit10_leveldb.dfm	(revision 40)
+++ 	(revision )
@@ -1,61 +1,0 @@
-object Form10: TForm10
-  Left = 0
-  Top = 0
-  BorderStyle = bsNone
-  Caption = 'Creating DB'
-  ClientHeight = 89
-  ClientWidth = 400
-  Color = clBtnFace
-  Font.Charset = DEFAULT_CHARSET
-  Font.Color = clWindowText
-  Font.Height = -11
-  Font.Name = 'Tahoma'
-  Font.Style = []
-  OldCreateOrder = False
-  Position = poScreenCenter
-  PixelsPerInch = 96
-  TextHeight = 13
-  object group_progress: TGroupBox
-    Left = 0
-    Top = 0
-    Width = 400
-    Height = 89
-    Caption = 'Progress ...'
-    TabOrder = 0
-    object lbl_progress: TLabel
-      Left = 2
-      Top = 32
-      Width = 396
-      Height = 17
-      Align = alTop
-      AutoSize = False
-    end
-    object lbl_estimation: TLabel
-      Left = 2
-      Top = 49
-      Width = 396
-      Height = 17
-      Align = alTop
-      AutoSize = False
-      Caption = 'Estimated finishing time:'
-    end
-    object progress: TProgressBar
-      Left = 2
-      Top = 15
-      Width = 396
-      Height = 17
-      Align = alTop
-      Smooth = True
-      TabOrder = 0
-    end
-    object btn_abortok: TButton
-      Left = 3
-      Top = 64
-      Width = 60
-      Height = 22
-      Caption = 'Abort...'
-      TabOrder = 1
-      OnClick = btn_abortokClick
-    end
-  end
-end
Index: oup/current/Unit10_leveldb.pas
===================================================================
--- oup/current/Unit10_leveldb.pas	(revision 40)
+++ 	(revision )
@@ -1,1185 +1,0 @@
-UNIT Unit10_leveldb;
-INTERFACE
-USES
-  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
-  Dialogs, ComCtrls, StdCtrls, StrUtils;
-
-TYPE
-  TForm10 = Class(TForm)
-    group_progress: TGroupBox;
-    progress: TProgressBar;
-    lbl_progress: TLabel;
-    btn_abortok: TButton;
-    lbl_estimation: TLabel;
-    PROCEDURE btn_abortokClick(Sender: TObject);
-  PRIVATE
-    PROCEDURE HandleFile(ext:String; fileid:LongWord; dir_dat2db:Boolean);
-    PROCEDURE stop_convert;
-  PUBLIC
-    PROCEDURE CreateDatabase(source,target:String);
-    PROCEDURE CreateLevel(source,target:String);
-  END;
-
-
-VAR
-  Form10: TForm10;
-
-IMPLEMENTATION
-{$R *.dfm}
-USES ABSMain, ABSDecUtil, Unit1_main, Unit2_functions, Unit3_data, Unit6_imgfuncs, Unit9_data_structures, Unit15_Classes;
-
-TYPE
-  THandler=PROCEDURE(fileid:LongWord; dir_dat2db:Boolean);
-  TConvertHandlers=RECORD
-    Ext:String[4];
-    needed:Boolean;
-    Handler:THandler;
-  END;
-VAR
-  ConvertHandlers:Array OF TConvertHandlers;
-  loaded_filename:String;
-  converting:Boolean=False;
-  abort:Boolean=False;
-  DataBase:TABSDatabase;
-  Query:TABSQuery;
-  MimeCoder: TStringFormat_MIME64;
-VAR
-  DatHeader:THeader;
-  FilesHeader:TFilesMap;
-  NamedFilesHeader:TNamedFilesMap;
-  ExtensionsHeader:TExtensionsMap;
-  Stream_Body,Stream_Names:TMemoryStream;
-  Stream_Dat,Stream_Raw,Stream_Sep:TFileStream;
-
-PROCEDURE TForm10.CreateLevel(source,target:String);
-  VAR
-    files:LongWord;
-    
-    i,j:LongWord;
-    temps,temps2:String;
-    data,rawdata:Tdata;
-    absolutebegintime,begintime:Double;
-    step:Byte;
-    rawlist:TRawList;
-    extlist:TExtensionsMap;
-    fileinfo:TFileInfo;
-    datlinks:TDatLinks;
-    OniImage:TOniImage;
-    levelid:LongWord;
-  CONST
-    steps:Byte=3;
-  PROCEDURE DoStep(stepname:String);
-    BEGIN
-      Inc(step);
-      IF stepname<>'FIN' THEN
-        group_progress.Caption:='Creating Dat (Step '+IntToStr(step)+'/'+IntToStr(steps)+': '+stepname+')'
-      ELSE
-        group_progress.Caption:='Creating Dat (FINISHED)';
-    END;
-  BEGIN
-
-//
-// FILE EXISTS CHECK FÜR DAT/RAW/SEP!!!
-//
-
-    IF NOT CreateDataConnection(source,ODB_ADB) THEN BEGIN
-      ShowMessage('Could not connect to .oldb-file');
-      Exit;
-    END;
-    levelid:=OniDataConnection.LevelInfo.LevelNumber;
-    levelid:=(levelid*2)*256*256*256 + $01;
-    OniImage:=TOniImage.Create;
-
-    absolutebegintime:=Time;
-
-    Form10.Visible:=True;
-    Form1.Visible:=False;
-    step:=0;
-    converting:=True;
-    abort:=False;
-    btn_abortok.Caption:='&Abort...';
-    btn_abortok.Default:=False;
-    absolutebegintime:=Time;
-
-    Stream_Body:=TMemoryStream.Create;
-    Stream_Names:=TMemoryStream.Create;
-    Stream_Dat:=TFileStream.Create(target,fmCreate);
-    Stream_Raw:=TFileStream.Create(AnsiReplaceStr(target,'.dat','.raw'),fmCreate);
-    IF OniDataConnection.OSisMac THEN
-      Stream_Sep:=TFileStream.Create(AnsiReplaceStr(target,'.dat','.sep'),fmCreate);
-
-    DoStep('Creating header');
-    progress.Position:=0;
-    lbl_progress.Caption:='';
-    lbl_estimation.Caption:='Estimated finishing time: unknown';
-    Application.ProcessMessages;
-
-    NamedFilesHeader:=TOniDataADB(OniDataConnection).GetNamedFilesMap;
-    extlist:=OniDataConnection.GetExtendedExtensionsList;
-    FOR i:=0 TO High(DatHeader.Ident) DO
-      DatHeader.Ident[i]:=OniDataConnection.LevelInfo.Ident[i];
-    DatHeader.Files:=OniDataConnection.GetFilesCount;
-    DatHeader.NamedFiles:=Length(NamedFilesHeader);
-    DatHeader.Extensions:=Length(extlist);
-    DatHeader.DataAddr:=0;
-    DatHeader.DataSize:=0;
-    DatHeader.NamesAddr:=0;
-    DatHeader.NamesSize:=0;
-    FOR i:=0 TO High(DatHeader.Ident2) DO
-      DatHeader.Ident2[i]:=0;
-    SetLength(FilesHeader, DatHeader.Files);
-    SetLength(ExtensionsHeader, DatHeader.Extensions);
-
-    DoStep('Writing extensions-header');
-    progress.Max:=Length(OniDataConnection.GetExtensionsList);
-    Application.ProcessMessages;
-
-    FOR i:=0 TO High(ExtensionsHeader) DO BEGIN
-      ExtensionsHeader[i].Ident:=extlist[i].Ident;
-      ExtensionsHeader[i].Extension:=extlist[i].Extension;
-      SetLength(temps,4);
-      FOR j:=0 TO 3 DO
-        temps[j+1]:=ExtensionsHeader[i].Extension[3-j];
-      ExtensionsHeader[i].ExtCount:=Length(OniDataConnection.GetFilesList(temps,'',False));
-      progress.Position:=i+1;
-      lbl_progress.Caption:='Extensions done: '+IntToStr(i+1)+'/'+IntToStr(Length(extlist));
-      Application.ProcessMessages;
-    END;
-
-    DoStep('Storing files-data');
-    progress.Position:=0;
-    progress.Max:=DatHeader.Files;
-    lbl_progress.Caption:='';
-    lbl_estimation.Caption:='Estimated finishing time: unknown';
-    Application.ProcessMessages;
-
-    begintime:=Time;
-    FOR i:=0 TO DatHeader.Files-1 DO BEGIN
-      fileinfo:=OniDataConnection.GetFileInfo(i);
-      FOR j:=0 TO 3 DO
-        FilesHeader[i].Extension[j]:=fileinfo.Extension[4-j];
-      IF fileinfo.Size>0 THEN BEGIN
-//        DatLinks:=;
-        FilesHeader[i].DataAddr:=Stream_Body.Size+8;
-        data:=OniDataConnection.LoadDatFile(i);
-        data[4]:=(levelid       ) AND $FF;
-        data[5]:=(levelid SHR  8) AND $FF;
-        data[6]:=(levelid SHR 16) AND $FF;
-        data[7]:=(levelid SHR 24) AND $FF;     
-
-        IF (Pos(UpperCase(fileinfo.Extension),UpperCase(raws)) MOD 4)=1 THEN BEGIN
-          rawlist:=OniDataConnection.GetRawList(i);
-          IF Length(rawlist)>0 THEN BEGIN
-            FOR j:=0 TO High(rawlist) DO BEGIN
-              IF rawlist[j].raw_size>0 THEN BEGIN
-                IF (UpperCase(fileinfo.Extension)='TXMP') AND ((data[$88] AND $01)>0) THEN BEGIN
-                  OniImage.LoadFromTXMP(i);
-                  OniImage.GetMipMappedImage(rawdata);
-                  rawlist[j].raw_size:=OniImage.GetImageDataSize(true);
-                  data[$90]:=$08;
-                  data[$89]:=32;
-{                  if data[$90]<>OniImage.StoreType then begin
-                    data[$90]:=OniImage.StoreType;
-                    data[$89]:=(data[$89] and $CF) or $20;
-                  end;
-}                END ELSE BEGIN
-                  SetLength(rawdata,rawlist[j].raw_size);
-                  OniDataConnection.LoadRawFile(i,rawlist[j].src_offset,@rawdata[0]);
-                END;
-//                data[$88]:=data[$88] and $FE;
-
-                IF rawlist[j].loc_sep THEN BEGIN
-                  rawlist[j].raw_addr:=Stream_Sep.Size;
-                  Stream_Sep.Write(rawdata[0],Length(rawdata));
-                END ELSE BEGIN
-                  rawlist[j].raw_addr:=Stream_Raw.Size;
-                  Stream_Raw.Write(rawdata[0],Length(rawdata));
-                END;
-              END ELSE rawlist[j].raw_addr:=0;
-              data[rawlist[j].src_offset+0]:=(rawlist[j].raw_addr       ) AND $FF;
-              data[rawlist[j].src_offset+1]:=(rawlist[j].raw_addr SHR  8) AND $FF;
-              data[rawlist[j].src_offset+2]:=(rawlist[j].raw_addr SHR 16) AND $FF;
-              data[rawlist[j].src_offset+3]:=(rawlist[j].raw_addr SHR 24) AND $FF;
-            END;
-          END;
-        END;
-
-        Stream_Body.Write(data[0],Length(data));
-//
-      END ELSE
-        FilesHeader[i].DataAddr:=0;
-      IF Length(fileinfo.Name)>0 THEN BEGIN
-        FilesHeader[i].NameAddr:=Stream_Names.Size;
-        temps:=fileinfo.Extension+fileinfo.Name+Chr(0);
-        Stream_Names.Write(temps[1],Length(temps)); 
-      END ELSE
-        FilesHeader[i].NameAddr:=0;
-      FilesHeader[i].FileSize:=fileinfo.Size;
-      FilesHeader[i].FileType:=fileinfo.FileType;
-
-      IF ( (i MOD 25)=0 ) AND (i>=100) THEN
-        lbl_estimation.Caption:='Estimated finishing time: '+TimeToStr((Time-begintime)/i*progress.Max+begintime);
-      progress.Position:=i+1;
-      lbl_progress.Caption:='Files done: '+IntToStr(i+1)+'/'+IntToStr(progress.Max);
-      Application.ProcessMessages;
-    END;
-
-    Stream_Dat.Write(DatHeader,SizeOf(DatHeader));
-    FOR i:=0 TO High(FilesHeader) DO
-      Stream_Dat.Write(FilesHeader[i],SizeOf(FilesHeader[i]));
-    FOR i:=0 TO High(NamedFilesHeader) DO
-      Stream_Dat.Write(NamedFilesHeader[i],SizeOf(NamedFilesHeader[i]));
-    FOR i:=0 TO High(ExtensionsHeader) DO
-      Stream_Dat.Write(ExtensionsHeader[i],SizeOf(ExtensionsHeader[i]));
-
-    DatHeader.DataSize:=Stream_Body.Size;
-    DatHeader.NamesSize:=Stream_Names.Size;
-    DatHeader.DataAddr:=Stream_Dat.Size;
-    Stream_Body.Seek(0,soFromBeginning);
-    Stream_Dat.CopyFrom(Stream_Body,Stream_Body.Size);
-    DatHeader.NamesAddr:=Stream_Dat.Size;
-    Stream_Names.Seek(0,soFromBeginning);
-    Stream_Dat.CopyFrom(Stream_Names,Stream_Names.Size);
-
-    Stream_Dat.Seek(0,soFromBeginning);
-    Stream_Dat.Write(DatHeader,SizeOf(DatHeader)); 
-
-    Stream_Dat.Free;
-    Stream_Body.Free;
-    Stream_Names.Free;
-    Stream_Raw.Free;
-    IF OniDataConnection.OSisMac THEN
-      Stream_Sep.Free;
-
-    progress.Position:=progress.Max;
-    lbl_progress.Caption:='Files done: '+IntToStr(progress.Max)+'/'+IntToStr(progress.Max);
-    lbl_estimation.Caption:='FINISHED (duration: '+TimeToStr(Time-absolutebegintime)+')';
-
-    DoStep('FIN');
-    btn_abortok.Caption:='&OK';
-    btn_abortok.Default:=True;
-
-    OniImage.Free;
-
-    converting:=False;
-
-    CloseDataConnection;
-  END;
-
-PROCEDURE TForm10.HandleFile;
-  VAR
-    i:Byte;
-  BEGIN
-    FOR i:=1 TO Length(ConvertHandlers) DO
-      IF UpperCase(ConvertHandlers[i].Ext)=UpperCase(ext) THEN
-        IF ConvertHandlers[i].needed THEN BEGIN
-          ConvertHandlers[i].Handler(fileid, dir_dat2db);
-          Break;
-        END ELSE
-          Break;
-  END;
-
-PROCEDURE TForm10.CreateDatabase(source,target:String);
-  VAR
-    i,j:LongWord;
-    temps,temps2:String;
-    data:Tdata;
-    absolutebegintime,begintime:Double;
-    step:Byte;
-    rawlist:TRawList;
-    extlist:TExtensionsMap;
-    fileinfo:TFileInfo;
-  CONST
-    steps:Byte=4;
-  PROCEDURE DoStep(stepname:String);
-    BEGIN
-      Inc(step);
-      IF stepname<>'FIN' THEN
-        group_progress.Caption:='Creating DB (Step '+IntToStr(step)+'/'+IntToStr(steps)+': '+stepname+')'
-      ELSE
-        group_progress.Caption:='Creating DB (FINISHED)';
-    END;
-  BEGIN
-    IF NOT CreateDataConnection(source,ODB_Dat) THEN BEGIN
-      ShowMessage('Could not connect to .dat-file');
-      Exit;
-    END ELSE BEGIN
-      TOniDataDat(OniDataConnection).UnloadWhenUnused:=False;
-    END;
-
-    Form10.Visible:=True;
-    Form1.Visible:=False;
-    step:=0;
-    converting:=True;
-    abort:=False;
-    btn_abortok.Caption:='&Abort...';
-    btn_abortok.Default:=False;
-    loaded_filename:=target;
-
-    absolutebegintime:=Time;
-
-    DataBase:=TABSDatabase.Create(Self);
-    DataBase.DatabaseName:='OLDB';
-    DataBase.DatabaseFileName:=target;
-    DataBase.CreateDatabase;
-
-    DoStep('Creating tables');
-    progress.Position:=0;
-    lbl_progress.Caption:='';
-    lbl_estimation.Caption:='Estimated finishing time: unknown';
-    Application.ProcessMessages;
-
-    Query:=TABSQuery.Create(Self);
-    Query.DatabaseName:='OLDB';
-    Query.SQL.Text:='CREATE TABLE globals  ( id AUTOINC PRIMARY KEY, name STRING(128), value STRING(128) );';
-    Query.ExecSQL;
-    Query.SQL.Text:='CREATE TABLE linkmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, target_id INTEGER );';
-    Query.ExecSQL;
-    Query.SQL.Text:='CREATE TABLE rawmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, sep BOOLEAN, size INTEGER, data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib );';
-//    Query.SQL.Text:='CREATE TABLE rawmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
-    Query.ExecSQL;
-    Query.SQL.Text:='CREATE TABLE datfiles  ( id INTEGER PRIMARY KEY, extension CHAR(4), name STRING(128), contenttype INTEGER, size INTEGER, data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib );';
-//    Query.SQL.Text:='CREATE TABLE datfiles  ( id INTEGER PRIMARY KEY, extension CHAR(4), name STRING(128), contenttype INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
-    Query.ExecSQL;
-    Query.SQL.Text:='CREATE TABLE extlist  ( id AUTOINC PRIMARY KEY, ext CHAR(4), ident CHAR(16) );';
-    Query.ExecSQL;
-
-    Query.SQL.Text:='INSERT INTO globals (name,value) VALUES ("dbversion","'+dbversion+'");';
-    Query.ExecSQL;
-    SetLength(data,Length(OniDataConnection.LevelInfo.Ident));
-    FOR i:=0 TO High(OniDataConnection.LevelInfo.Ident) DO data[i]:=OniDataConnection.LevelInfo.Ident[i];
-    temps:=CreateHexString(data,True);
-    Query.SQL.Text:='INSERT INTO globals (name,value) VALUES ("ident","'+temps+'");';
-    Query.ExecSQL;
-    Query.SQL.Text:='INSERT INTO globals (name,value) VALUES ("lvl","'+IntToStr(OniDataConnection.LevelInfo.LevelNumber)+'");';
-    Query.ExecSQL;
-    IF OniDataConnection.OSisMAC THEN
-      Query.SQL.Text:='INSERT INTO globals (name,value) VALUES ("os","MAC");'
-    ELSE
-      Query.SQL.Text:='INSERT INTO globals (name,value) VALUES ("os","PC");';
-    Query.ExecSQL;
-
-    DoStep('Writing extensionslist');
-    progress.Max:=Length(OniDataConnection.GetExtensionsList);
-    Application.ProcessMessages;
-
-    extlist:=OniDataConnection.GetExtendedExtensionsList;
-    FOR i:=0 TO High(extlist) DO BEGIN
-      SetLength(data,Length(extlist[i].Ident));
-      FOR j:=0 TO High(extlist[i].Ident) DO data[j]:=extlist[i].Ident[j];
-      temps:=CreateHexString(data,True);
-      temps2:=extlist[i].Extension[3]+extlist[i].Extension[2]+extlist[i].Extension[1]+extlist[i].Extension[0];
-      Query.SQL.Text:='INSERT INTO extlist (ext,ident) VALUES ("'+temps2+'","'+temps+'");';
-      Query.ExecSQL;
-      progress.Position:=i;
-      lbl_progress.Caption:='Extensions done: '+IntToStr(i)+'/'+IntToStr(Length(extlist));
-      Application.ProcessMessages;
-      IF abort THEN BEGIN
-        stop_convert;
-        Exit;
-      END;
-    END;
-    lbl_progress.Caption:='';
-
-    progress.Position:=0;
-    lbl_progress.Caption:='Files done: '+IntToStr(0)+'/'+IntToStr(OniDataConnection.GetFilesCount);
-    lbl_estimation.Caption:='Estimated finishing time: unknown';
-
-    DoStep('Loading .dat into memory');
-    Application.ProcessMessages;
-
-    progress.Max:=OniDataConnection.GetFilesCount;
-    begintime:=Time;
-    DoStep('Writing .dat-fileslist');
-    Application.ProcessMessages;
-
-    Database.StartTransaction;
-    FOR i:=0 TO OniDataConnection.GetFilesCount-1 DO BEGIN
-      fileinfo:=OniDataConnection.GetFileInfo(i);
-      IF (fileinfo.FileType AND $02)=0 THEN BEGIN
-        mimecoder:=TStringFormat_MIME64.Create;
-        data:=OniDataConnection.LoadDatFile(i);
-        Query.SQL.Text:='INSERT INTO datfiles (id,extension,name,contenttype,size,data) VALUES ('+IntToStr(i)+',"'+fileinfo.Extension+'","'+fileinfo.Name+'","'+IntToHex(fileinfo.FileType,8)+'",'+IntToStr(fileinfo.Size)+',MimeToBin("'+MimeCoder.StrTo(@data[0], Length(data))+'") );';
-        Query.ExecSQL;
-        mimecoder.Free;
-
-        rawlist:=OniDataConnection.GetRawList(i);
-        IF Length(rawlist)>0 THEN BEGIN
-          FOR j:=0 TO High(rawlist) DO BEGIN
-            IF rawlist[j].raw_size>0 THEN BEGIN
-              SetLength(data, rawlist[j].raw_size);
-              OniDataConnection.LoadRawFile(i,rawlist[j].src_offset,data);
-              mimecoder:=TStringFormat_MIME64.Create;
-              Query.SQL.Text:='INSERT INTO rawmap (src_id,src_link_offset,sep,size,data) VALUES ('+IntToStr(i)+','+IntToStr(rawlist[j].src_offset)+','+BoolToStr(rawlist[j].loc_sep)+','+IntToStr(rawlist[j].raw_size)+',MimeToBin("'+MimeCoder.StrTo(@data[0], rawlist[j].raw_size)+'") );';
-              Query.ExecSQL;
-              mimecoder.Free;
-            END ELSE BEGIN
-              Query.SQL.Text:='INSERT INTO rawmap (src_id,src_link_offset,sep,size) VALUES ('+IntToStr(i)+','+IntToStr(rawlist[j].src_offset)+','+BoolToStr(rawlist[j].loc_sep)+',0);';
-              Query.ExecSQL;
-            END;
-          END;
-        END;
-
-        HandleFile(fileinfo.Extension,i,True);
-      END ELSE BEGIN
-        Query.SQL.Text:='INSERT INTO datfiles (id,extension,name,contenttype,size) VALUES ('+IntToStr(i)+',"'+fileinfo.Extension+'","'+fileinfo.Name+'","'+IntToHex(fileinfo.FileType,8)+'",0);';
-        Query.ExecSQL;
-      END;
-      IF ( (i MOD 100)=0 ) AND (i>0) THEN BEGIN
-        Database.Commit(False);
-        Database.StartTransaction;
-      END;
-      IF ( (i MOD 25)=0 ) AND (i>=100) THEN
-        lbl_estimation.Caption:='Estimated finishing time: '+TimeToStr((Time-begintime)/i*progress.Max+begintime);
-      progress.Position:=i;
-      lbl_progress.Caption:='Files done: '+IntToStr(i)+'/'+IntToStr(progress.Max);
-      Application.ProcessMessages;
-      IF abort THEN BEGIN
-        stop_convert;
-        Exit;
-      END;
-    END;
-    Database.Commit(False);
-    progress.Position:=progress.Max;
-    lbl_progress.Caption:='Files done: '+IntToStr(progress.Max)+'/'+IntToStr(progress.Max);
-    lbl_estimation.Caption:='FINISHED (duration: '+TimeToStr(Time-absolutebegintime)+')';
-
-    DoStep('FIN');
-    btn_abortok.Caption:='&OK';
-    btn_abortok.Default:=True;
-
-    converting:=False;
-
-    database.Close;
-    database.Free;
-
-    CloseDataConnection;
-  END;
-
-PROCEDURE TForm10.stop_convert;
-  BEGIN
-    btn_abortok.Caption:='&Close';
-    btn_abortok.Default:=True;
-    converting:=False;
-    lbl_estimation.Caption:='ABORTED';
-    group_progress.Caption:='Creating DB (ABORTED)';
-    DataBase.Close;
-    IF MessageBox(Self.Handle, PChar('Delete the unfinished DB-file?'), PChar('Delete file?'), MB_YESNO)=IDYES THEN BEGIN
-      DeleteFile(loaded_filename);
-    END;
-  END;
-
-PROCEDURE TForm10.btn_abortokClick(Sender: TObject);
-  BEGIN
-    IF converting THEN BEGIN
-      IF MessageBox(Self.Handle, PChar('Do you really want to cancel the convert-progress?'), PChar('Warning: Converting'), MB_YESNO)=IDYES THEN
-        abort:=True;
-    END ELSE BEGIN
-      Form10.Visible:=False;
-      Form1.Visible:=True;
-    END;
-  END;
-
-PROCEDURE InsertDatLinkToDB(fileid:LongWord; offset:LongWord);
-  VAR
-    link:LongWord;
-  BEGIN
-    OniDataConnection.LoadDatFilePart(fileid,offset,4,@link);
-    IF link=0 THEN
-      link:=$FFFFFFFF
-    ELSE
-      link:=link DIV 256;
-    Query.SQL.Text:='INSERT INTO linkmap (src_id,src_link_offset,target_id) VALUES ('+IntToStr(fileid)+','+IntToStr(offset)+','+IntToStr(link)+');';
-    Query.ExecSQL;
-  END;
-
-PROCEDURE AISA(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    packages:Word;
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$1E,2,@packages);
-      IF packages>0 THEN BEGIN
-        FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*$160+$28);
-        FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*$160+$150);
-      END;
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE AKEV(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      FOR i:=0 TO 16 DO InsertDatLinkToDB(fileid,$8+i*4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE AKOT(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      FOR i:=0 TO 4 DO InsertDatLinkToDB(fileid,$8+i*4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE CBPI(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      FOR i:=0 TO 56 DO InsertDatLinkToDB(fileid,$8+i*4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE CBPM(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      FOR i:=0 TO 18 DO InsertDatLinkToDB(fileid,$8+i*4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE CONS(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      FOR i:=0 TO 1 DO InsertDatLinkToDB(fileid,$24+i*4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE CRSA(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    packages:LongWord;
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$14,4,@packages);
-      IF packages>0 THEN
-        FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*1100+$A0);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE DOOR(fileid:LongWord; dir_dat2db:Boolean);
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      InsertDatLinkToDB(fileid,$08);
-      InsertDatLinkToDB(fileid,$10);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE DPGE(fileid:LongWord; dir_dat2db:Boolean);
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      InsertDatLinkToDB(fileid,$40);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE HPGE(fileid:LongWord; dir_dat2db:Boolean);
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      InsertDatLinkToDB(fileid,$0C);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE IGHH(fileid:LongWord; dir_dat2db:Boolean);
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      InsertDatLinkToDB(fileid,$24);
-      InsertDatLinkToDB(fileid,$28);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE IGPA(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    links:LongWord;
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$1C,4,@links);
-      IF links>0 THEN
-        FOR i:=0 TO links-1 DO InsertDatLinkToDB(fileid,$20+i*4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE IGPG(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      FOR i:=0 TO 1 DO InsertDatLinkToDB(fileid,$1C+i*4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE IGSA(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    links:LongWord;
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$1C,4,@links);
-      IF links>0 THEN
-        FOR i:=0 TO links-1 DO InsertDatLinkToDB(fileid,$20+i*4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE IMPT(fileid:LongWord; dir_dat2db:Boolean);
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      InsertDatLinkToDB(fileid,$10);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE IPGE(fileid:LongWord; dir_dat2db:Boolean);
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      InsertDatLinkToDB(fileid,$0C);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE KEYI(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      FOR i:=0 TO 9 DO InsertDatLinkToDB(fileid,$08+i*4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE M3GA(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    links:LongWord;
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$1C,4,@links);
-      IF links>0 THEN
-        FOR i:=0 TO links-1 DO InsertDatLinkToDB(fileid,$20+i*4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE M3GM(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      FOR i:=0 TO 6 DO InsertDatLinkToDB(fileid,$0C+i*4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE MTRL(fileid:LongWord; dir_dat2db:Boolean);
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      InsertDatLinkToDB(fileid,$10);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE OBDC(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    packages:Word;
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$1E,2,@packages);
-      IF packages>0 THEN
-        FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*$18+$4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE OBOA(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    packages:Word;
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$1E,2,@packages);
-      IF packages>0 THEN
-        FOR i:=0 TO packages-1 DO BEGIN
-          InsertDatLinkToDB(fileid,$20+i*240+$0);
-          InsertDatLinkToDB(fileid,$20+i*240+$4);
-          InsertDatLinkToDB(fileid,$20+i*240+$8);
-        END;
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE OFGA(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    packages:LongWord;
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$1C,4,@packages);
-      IF packages>0 THEN
-        FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*12+$04);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE ONCC(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      InsertDatLinkToDB(fileid,$28);
-      InsertDatLinkToDB(fileid,$434);
-      InsertDatLinkToDB(fileid,$438);
-      InsertDatLinkToDB(fileid,$43C);
-      InsertDatLinkToDB(fileid,$C3C);
-      InsertDatLinkToDB(fileid,$C40);
-      InsertDatLinkToDB(fileid,$C44);
-      InsertDatLinkToDB(fileid,$C48);
-      InsertDatLinkToDB(fileid,$C88);
-      InsertDatLinkToDB(fileid,$C8C);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE ONCV(fileid:LongWord; dir_dat2db:Boolean);
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      InsertDatLinkToDB(fileid,$08);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE ONLV(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      FOR i:=0 TO 5 DO InsertDatLinkToDB(fileid,$48+i*4);
-      FOR i:=0 TO 5 DO InsertDatLinkToDB(fileid,$64+i*4);
-      InsertDatLinkToDB(fileid,$300);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE ONOA(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    packages:LongWord;
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$1C,4,@packages);
-      IF packages>0 THEN
-        FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*8+$04);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE ONSK(fileid:LongWord; dir_dat2db:Boolean);
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      InsertDatLinkToDB(fileid,$08);
-      InsertDatLinkToDB(fileid,$0C);
-      InsertDatLinkToDB(fileid,$10);
-      InsertDatLinkToDB(fileid,$14);
-      InsertDatLinkToDB(fileid,$18);
-      InsertDatLinkToDB(fileid,$20);
-      InsertDatLinkToDB(fileid,$44);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE ONVL(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    packages:LongWord;
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$1C,4,@packages);
-      IF packages>0 THEN
-        FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE ONWC(fileid:LongWord; dir_dat2db:Boolean);
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      InsertDatLinkToDB(fileid,$28);
-      InsertDatLinkToDB(fileid,$34);
-      InsertDatLinkToDB(fileid,$40);
-      InsertDatLinkToDB(fileid,$54);
-      InsertDatLinkToDB(fileid,$58);
-      InsertDatLinkToDB(fileid,$5C);
-      InsertDatLinkToDB(fileid,$60);
-      InsertDatLinkToDB(fileid,$6FC);
-      InsertDatLinkToDB(fileid,$700);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE OPGE(fileid:LongWord; dir_dat2db:Boolean);
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      InsertDatLinkToDB(fileid,$0C);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE PSPC(fileid:LongWord; dir_dat2db:Boolean);
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      InsertDatLinkToDB(fileid,$50);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE PSPL(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    packages:LongWord;
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$1C,4,@packages);
-      IF packages>0 THEN
-        FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*8+$4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE PSUI(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      FOR i:=0 TO 43 DO InsertDatLinkToDB(fileid,$08+i*4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE STNA(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    packages:Word;
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$1E,2,@packages);
-      IF packages>0 THEN
-        FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE TRAC(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    packages:Word;
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      InsertDatLinkToDB(fileid,$18);
-      OniDataConnection.LoadDatFilePart(fileid,$1E,2,@packages);
-      IF packages>0 THEN
-        FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*12+8);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE TRAM(fileid:LongWord; dir_dat2db:Boolean);
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      InsertDatLinkToDB(fileid,$40);
-      InsertDatLinkToDB(fileid,$44);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE TRAS(fileid:LongWord; dir_dat2db:Boolean);
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      InsertDatLinkToDB(fileid,$08);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE TRBS(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      FOR i:=0 TO 4 DO InsertDatLinkToDB(fileid,$08+i*4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE TRCM(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    i:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      FOR i:=0 TO 2 DO InsertDatLinkToDB(fileid,$5C+i*4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE TRGA(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    i:LongWord;
-    packages:Word;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$1E,2,@packages);
-      IF packages>0 THEN
-        FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE TRGE(fileid:LongWord; dir_dat2db:Boolean);
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      InsertDatLinkToDB(fileid,$20);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE TRIG(fileid:LongWord; dir_dat2db:Boolean);
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      InsertDatLinkToDB(fileid,$18);
-      InsertDatLinkToDB(fileid,$24);
-      InsertDatLinkToDB(fileid,$28);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE TRMA(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    i:LongWord;
-    packages:Word;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$1E,2,@packages);
-      IF packages>0 THEN
-        FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE TRSC(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    i:LongWord;
-    packages:Word;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$1E,2,@packages);
-      IF packages>0 THEN
-        FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE TSFF(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    i:LongWord;
-    packages:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$1C,4,@packages);
-      IF packages>0 THEN
-        FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE TSFT(fileid:LongWord; dir_dat2db:Boolean);
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      InsertDatLinkToDB(fileid,$1C);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE TURR(fileid:LongWord; dir_dat2db:Boolean);
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      InsertDatLinkToDB(fileid,$60);
-      InsertDatLinkToDB(fileid,$6C);
-      InsertDatLinkToDB(fileid,$74);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE TXAN(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    i:LongWord;
-    packages:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$1C,4,@packages);
-      IF packages>0 THEN
-        FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE TXMA(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    i:LongWord;
-    packages:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$1C,4,@packages);
-      IF packages>0 THEN
-        FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE TXMB(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    i:LongWord;
-    packages:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$1C,4,@packages);
-      IF packages>0 THEN
-        FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE TXMP(fileid:LongWord; dir_dat2db:Boolean);
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      InsertDatLinkToDB(fileid,$94);
-      InsertDatLinkToDB(fileid,$98);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE TXTC(fileid:LongWord; dir_dat2db:Boolean);
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      InsertDatLinkToDB(fileid,$08);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE WMCL(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    i:LongWord;
-    packages:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$1C,4,@packages);
-      IF packages>0 THEN
-        FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*8+$4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE WMDD(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    i:LongWord;
-    packages:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$11C,4,@packages);
-      IF packages>0 THEN
-        FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$120+i*$124+$114);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE WMMB(fileid:LongWord; dir_dat2db:Boolean);
-  VAR
-    i:LongWord;
-    packages:LongWord;
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$1C,4,@packages);
-      IF packages>0 THEN
-        FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
-    END ELSE BEGIN
-    END;
-  END;
-PROCEDURE WPGE(fileid:LongWord; dir_dat2db:Boolean);
-  BEGIN
-    IF dir_dat2db THEN BEGIN
-      InsertDatLinkToDB(fileid,$08);
-      InsertDatLinkToDB(fileid,$0C);
-    END ELSE BEGIN
-    END;
-  END;
-
-PROCEDURE InsertHandler(ext:String; needed:Boolean; handler:THandler);
-  BEGIN
-    SetLength(ConvertHandlers,Length(ConvertHandlers)+1);
-    ConvertHandlers[High(ConvertHandlers)].Ext:=ext;
-    ConvertHandlers[High(ConvertHandlers)].needed:=needed;
-    ConvertHandlers[High(ConvertHandlers)].handler:=handler;
-  END;
-
-BEGIN
-  InsertHandler('ABNA',False,NIL);
-//  InsertHandler('AGDB',True,AGDB);
-  InsertHandler('AGDB',False,NIL);
-  InsertHandler('AGQC',False,NIL);
-  InsertHandler('AGQG',False,NIL);
-  InsertHandler('AGQR',False,NIL);
-  InsertHandler('AISA',True,AISA);
-  InsertHandler('AITR',False,NIL);
-  InsertHandler('AKAA',False,NIL);
-  InsertHandler('AKBA',False,NIL);
-  InsertHandler('AKBP',False,NIL);
-  InsertHandler('AKDA',False,NIL);
-  InsertHandler('AKEV',True,AKEV);
-  InsertHandler('AKOT',True,AKOT);
-  InsertHandler('AKVA',False,NIL);
-  InsertHandler('BINA',False,NIL);
-  InsertHandler('CBPI',True,CBPI);
-  InsertHandler('CBPM',True,CBPM);
-  InsertHandler('CONS',True,CONS);
-  InsertHandler('CRSA',True,CRSA);
-  InsertHandler('DOOR',True,DOOR);
-  InsertHandler('DPGE',True,DPGE);
-  InsertHandler('ENVP',False,NIL);
-  InsertHandler('FILM',False,NIL);
-  InsertHandler('HPGE',True,HPGE);
-  InsertHandler('IDXA',False,NIL);
-  InsertHandler('IGHH',True,IGHH);
-  InsertHandler('IGPA',True,IGPA);
-  InsertHandler('IGPG',True,IGPG);
-  InsertHandler('IGSA',True,IGSA);
-  InsertHandler('IMPT',True,IMPT);
-  InsertHandler('IPGE',True,IPGE);
-  InsertHandler('KEYI',True,KEYI);
-  InsertHandler('M3GA',True,M3GA);
-  InsertHandler('M3GM',True,M3GM);
-  InsertHandler('MTRL',True,MTRL);
-  InsertHandler('OBAN',False,NIL);
-  InsertHandler('OBDC',True,OBDC);
-  InsertHandler('OBOA',True,OBOA);
-  InsertHandler('OFGA',True,OFGA);
-  InsertHandler('ONCC',True,ONCC);
-  InsertHandler('ONCP',False,NIL);
-  InsertHandler('ONCV',True,ONCV);
-  InsertHandler('ONFA',False,NIL);
-  InsertHandler('ONGS',False,NIL);
-  InsertHandler('ONIA',False,NIL);
-  InsertHandler('ONLD',False,NIL);
-  InsertHandler('ONLV',True,ONLV);
-  InsertHandler('ONMA',False,NIL);
-  InsertHandler('ONOA',True,ONOA);
-  InsertHandler('ONSA',False,NIL);
-  InsertHandler('ONSK',True,ONSK);
-  InsertHandler('ONTA',False,NIL);
-  InsertHandler('ONVL',True,ONVL);
-  InsertHandler('ONWC',True,ONWC);
-  InsertHandler('OPGE',True,OPGE);
-  InsertHandler('OSBD',False,NIL);
-  InsertHandler('OTIT',False,NIL);
-  InsertHandler('OTLF',False,NIL);
-  InsertHandler('PLEA',False,NIL);
-  InsertHandler('PNTA',False,NIL);
-  InsertHandler('PSPC',True,PSPC);
-  InsertHandler('PSPL',True,PSPL);
-  InsertHandler('PSUI',True,PSUI);
-  InsertHandler('QTNA',False,NIL);
-  InsertHandler('SNDD',False,NIL);
-  InsertHandler('STNA',True,STNA);
-  InsertHandler('SUBT',False,NIL);
-  InsertHandler('TRAC',True,TRAC);
-  InsertHandler('TRAM',True,TRAM);
-  InsertHandler('TRAS',True,TRAS);
-  InsertHandler('TRBS',True,TRBS);
-  InsertHandler('TRCM',True,TRCM);
-  InsertHandler('TRGA',True,TRGA);
-  InsertHandler('TRGE',True,TRGE);
-  InsertHandler('TRIA',False,NIL);
-  InsertHandler('TRIG',True,TRIG);
-  InsertHandler('TRMA',True,TRMA);
-  InsertHandler('TRSC',True,TRSC);
-  InsertHandler('TRTA',False,NIL);
-  InsertHandler('TSFF',True,TSFF);
-  InsertHandler('TSFL',False,NIL);
-  InsertHandler('TSFT',True,TSFT);
-  InsertHandler('TSGA',False,NIL);
-  InsertHandler('TSTR',False,NIL);
-  InsertHandler('TURR',True,TURR);
-  InsertHandler('TXAN',True,TXAN);
-  InsertHandler('TXCA',False,NIL);
-  InsertHandler('TXMA',True,TXMA);
-  InsertHandler('TXMB',True,TXMB);
-  InsertHandler('TXMP',True,TXMP);
-  InsertHandler('TXTC',True,TXTC);
-  InsertHandler('VCRA',False,NIL);
-  InsertHandler('WMCL',True,WMCL);
-  InsertHandler('WMDD',True,WMDD);
-  InsertHandler('WMM_',False,NIL);
-  InsertHandler('WMMB',True,WMMB);
-  InsertHandler('WPGE',True,WPGE);   
-END.
Index: oup/current/Unit11_extractor.dfm
===================================================================
--- oup/current/Unit11_extractor.dfm	(revision 40)
+++ 	(revision )
@@ -1,257 +1,0 @@
-object Form11: TForm11
-  Left = 0
-  Top = 0
-  Caption = 'Extractor'
-  ClientHeight = 398
-  ClientWidth = 487
-  Color = clBtnFace
-  Font.Charset = DEFAULT_CHARSET
-  Font.Color = clWindowText
-  Font.Height = -11
-  Font.Name = 'Tahoma'
-  Font.Style = []
-  FormStyle = fsMDIChild
-  OldCreateOrder = False
-  Visible = True
-  WindowState = wsMaximized
-  OnClose = FormClose
-  OnCreate = FormCreate
-  OnResize = FormResize
-  PixelsPerInch = 96
-  TextHeight = 13
-  object group_select: TGroupBox
-    Left = 0
-    Top = 0
-    Width = 191
-    Height = 398
-    Align = alClient
-    Caption = '1. Select file(s)'
-    TabOrder = 0
-    object panel_extension: TPanel
-      Left = 2
-      Top = 293
-      Width = 187
-      Height = 103
-      Align = alBottom
-      BevelOuter = bvNone
-      TabOrder = 0
-      OnResize = panel_extensionResize
-      object lbl_filter: TLabel
-        Left = 2
-        Top = 62
-        Width = 100
-        Height = 17
-        AutoSize = False
-        Caption = 'Filter by &extension:'
-        FocusControl = combo_extension
-      end
-      object combo_extension: TComboBox
-        Left = 2
-        Top = 76
-        Width = 145
-        Height = 21
-        Style = csDropDownList
-        DropDownCount = 12
-        Font.Charset = DEFAULT_CHARSET
-        Font.Color = clWindowText
-        Font.Height = -11
-        Font.Name = 'Tahoma'
-        Font.Style = []
-        ItemHeight = 13
-        ParentFont = False
-        Sorted = True
-        TabOrder = 3
-        OnClick = combo_extensionClick
-      end
-      object check_zerobyte: TCheckBox
-        Left = 2
-        Top = 44
-        Width = 130
-        Height = 13
-        Caption = 'Show &zero-byte files'
-        TabOrder = 2
-        OnClick = check_zerobyteClick
-      end
-      object edit_filtername: TEdit
-        Left = 2
-        Top = 20
-        Width = 145
-        Height = 18
-        AutoSize = False
-        TabOrder = 1
-      end
-      object check_filtername: TCheckBox
-        Left = 2
-        Top = 5
-        Width = 130
-        Height = 15
-        Caption = 'Filter by file&name:'
-        TabOrder = 0
-        OnClick = check_filternameClick
-      end
-    end
-    object list: TListBox
-      Left = 2
-      Top = 15
-      Width = 187
-      Height = 278
-      Align = alClient
-      ItemHeight = 13
-      MultiSelect = True
-      TabOrder = 1
-    end
-  end
-  object group_extract: TGroupBox
-    Left = 191
-    Top = 0
-    Width = 296
-    Height = 398
-    Align = alRight
-    Caption = '2. Select extract-method'
-    TabOrder = 1
-    object group_singlefiles: TGroupBox
-      Left = 8
-      Top = 16
-      Width = 281
-      Height = 185
-      Caption = 'Write data into single files'
-      TabOrder = 0
-      object btn_sel_dat: TButton
-        Left = 8
-        Top = 16
-        Width = 129
-        Height = 49
-        Caption = 'Selected files (dat contents only)'
-        TabOrder = 0
-        WordWrap = True
-        OnClick = Extract
-      end
-      object btn_sel_datraw: TButton
-        Left = 8
-        Top = 72
-        Width = 129
-        Height = 49
-        Caption = 'Selected files (dat+raw)'
-        TabOrder = 1
-        WordWrap = True
-        OnClick = Extract
-      end
-      object btn_sel_datraw_convert: TButton
-        Left = 8
-        Top = 128
-        Width = 129
-        Height = 49
-        Caption = 'Selected files (dat+raw) (with convert if possible)'
-        TabOrder = 2
-        WordWrap = True
-        OnClick = Extract
-      end
-      object btn_all_dat: TButton
-        Left = 144
-        Top = 16
-        Width = 129
-        Height = 49
-        Caption = 'All files in list (dat contents only)'
-        TabOrder = 3
-        WordWrap = True
-        OnClick = Extract
-      end
-      object btn_all_datraw: TButton
-        Left = 144
-        Top = 72
-        Width = 129
-        Height = 49
-        Caption = 'All files in list (dat+raw)'
-        TabOrder = 4
-        WordWrap = True
-        OnClick = Extract
-      end
-      object btn_all_datraw_convert: TButton
-        Left = 144
-        Top = 128
-        Width = 129
-        Height = 49
-        BiDiMode = bdLeftToRight
-        Caption = 'All files in list (dat+raw) (with convert if possible)'
-        ParentBiDiMode = False
-        TabOrder = 5
-        WordWrap = True
-        OnClick = Extract
-      end
-    end
-    object group_onefile: TGroupBox
-      Left = 8
-      Top = 208
-      Width = 281
-      Height = 73
-      Caption = 'Write data into one file'
-      TabOrder = 1
-      object btn_sel_files_toone: TButton
-        Left = 8
-        Top = 16
-        Width = 129
-        Height = 49
-        Caption = 'Selected files (dat contents only)'
-        TabOrder = 0
-        WordWrap = True
-        OnClick = Extract
-      end
-      object btn_all_files_toone: TButton
-        Left = 144
-        Top = 16
-        Width = 129
-        Height = 49
-        Caption = 'All files in list (dat contents only)'
-        TabOrder = 1
-        WordWrap = True
-        OnClick = Extract
-      end
-    end
-    object group_progress: TGroupBox
-      Left = 8
-      Top = 288
-      Width = 281
-      Height = 105
-      Caption = 'Progress ...'
-      TabOrder = 2
-      Visible = False
-      object lbl_progress: TLabel
-        Left = 8
-        Top = 40
-        Width = 265
-        Height = 17
-        AutoSize = False
-        Caption = 'Files done: 0/0'
-      end
-      object lbl_estimated: TLabel
-        Left = 8
-        Top = 56
-        Width = 265
-        Height = 17
-        AutoSize = False
-        Caption = 'Estimated finishing time: 00:00:00'
-      end
-      object progress: TProgressBar
-        Left = 8
-        Top = 16
-        Width = 265
-        Height = 17
-        Smooth = True
-        TabOrder = 0
-      end
-      object btn_abort: TButton
-        Left = 8
-        Top = 72
-        Width = 97
-        Height = 23
-        Caption = 'Abort'
-        Enabled = False
-        TabOrder = 1
-      end
-    end
-  end
-  object saved: TSaveDialog
-    Left = 448
-    Top = 328
-  end
-end
Index: oup/current/Unit11_extractor.pas
===================================================================
--- oup/current/Unit11_extractor.pas	(revision 40)
+++ 	(revision )
@@ -1,235 +1,0 @@
-UNIT Unit11_extractor;
-INTERFACE
-USES
-  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
-  Dialogs, StdCtrls, ExtCtrls, StrUtils, ComCtrls;
-TYPE
-  TForm11 = Class(TForm)
-    group_select: TGroupBox;
-    group_extract: TGroupBox;
-    group_singlefiles: TGroupBox;
-    btn_sel_dat: TButton;
-    btn_sel_datraw: TButton;
-    btn_sel_datraw_convert: TButton;
-    btn_all_dat: TButton;
-    btn_all_datraw: TButton;
-    btn_all_datraw_convert: TButton;
-    group_onefile: TGroupBox;
-    btn_sel_files_toone: TButton;
-    btn_all_files_toone: TButton;
-    group_progress: TGroupBox;
-    progress: TProgressBar;
-    lbl_progress: TLabel;
-    lbl_estimated: TLabel;
-    btn_abort: TButton;
-    saved: TSaveDialog;
-    panel_extension: TPanel;
-    lbl_filter: TLabel;
-    combo_extension: TComboBox;
-    check_zerobyte: TCheckBox;
-    edit_filtername: TEdit;
-    check_filtername: TCheckBox;
-    list: TListBox;
-    PROCEDURE LoadFileNames;
-    PROCEDURE check_filternameClick(Sender: TObject);
-    PROCEDURE check_zerobyteClick(Sender: TObject);
-    PROCEDURE combo_extensionClick(Sender: TObject);
-    PROCEDURE panel_extensionResize(Sender: TObject);
-    PROCEDURE Recreatelist;
-
-    PROCEDURE FormCreate(Sender: TObject);
-    PROCEDURE FormClose(Sender: TObject; var Action: TCloseAction);
-    PROCEDURE FormResize(Sender: TObject);
-    PROCEDURE Extract(Sender: TObject);
-  PRIVATE
-  PUBLIC
-  END;
-
-VAR
-  Form11: TForm11;
-
-IMPLEMENTATION
-{$R *.dfm}
-USES Unit1_main, Unit2_functions, Unit3_data, Unit15_Classes;
-
-
-PROCEDURE TForm11.Recreatelist;
-  VAR
-    i:LongWord;
-    exts:TStringArray;
-  BEGIN
-    combo_extension.Items.Clear;
-    combo_extension.Items.Add('_All files_ ('+IntToStr(OniDataConnection.GetFilesCount)+')');
-    exts:=OniDataConnection.GetExtensionsList;
-    FOR i:=0 TO High(exts) DO
-      combo_extension.Items.Add(exts[i]);
-    combo_extension.ItemIndex:=0;
-    combo_extensionClick(Self);
-  END;
-
-PROCEDURE TForm11.LoadFileNames;
-  VAR
-    Extension:String[4];
-    no_zero_bytes:Boolean;
-    pattern:String;
-    files:TStringArray;
-    i:LongWord;
-  BEGIN
-    Extension:=MidStr(combo_extension.Items.Strings[combo_extension.ItemIndex],1,4);
-    no_zero_bytes:=NOT check_zerobyte.Checked;
-    pattern:='';
-    IF check_filtername.Checked THEN pattern:=edit_filtername.Text;
-    IF Extension='_All' THEN Extension:='';
-
-    files:=OniDataConnection.GetFilesList(extension,pattern,no_zero_bytes);
-    list.Items.Clear;
-    IF Length(files)>0 THEN
-      FOR i:=0 TO High(files) DO
-        list.Items.Add(files[i]);
-  END;
-
-PROCEDURE TForm11.panel_extensionResize(Sender: TObject);
-  BEGIN
-    combo_extension.Width:=panel_extension.Width-5;
-    edit_filtername.Width:=panel_extension.Width-5;
-  END;
-
-PROCEDURE TForm11.combo_extensionClick(Sender: TObject);
-  BEGIN
-    LoadFileNames;
-  END;
-
-PROCEDURE TForm11.check_zerobyteClick(Sender: TObject);
-  VAR
-    i:Byte;
-  BEGIN
-    LoadFileNames;
-  END;
-
-PROCEDURE TForm11.check_filternameClick(Sender: TObject);
-  BEGIN
-    edit_filtername.Enabled:=NOT check_filtername.Checked;
-    LoadFileNames;
-  END;
-
-
-
-PROCEDURE TForm11.FormResize(Sender: TObject);
-  BEGIN
-    IF Self.Width>=450 THEN BEGIN
-    END ELSE Self.Width:=450;
-    IF Self.Height>=400 THEN BEGIN
-      group_progress.Height:=group_extract.Height-293;
-    END ELSE Self.Height:=400;
-  END;
-
-PROCEDURE TForm11.FormClose(Sender: TObject; var Action: TCloseAction);
-  BEGIN
-    Action:=caFree;
-  END;
-
-PROCEDURE TForm11.FormCreate(Sender: TObject);
-  BEGIN
-    btn_sel_dat.Caption:=           'Selected files'+CrLf+'(dat contents only)';
-    btn_sel_datraw.Caption:=        'Selected files'+CrLf+'(dat+raw contents)';
-    btn_sel_datraw_convert.Caption:='Selected files'+CrLf+'(dat+raw contents)'+CrLf+'(with convert if possible)';
-    btn_all_dat.Caption:=           'All files in list'+CrLf+'(dat contents only)';
-    btn_all_datraw.Caption:=        'All files in list'+CrLf+'(dat+raw contents)';
-    btn_all_datraw_convert.Caption:='All files in list'+CrLf+'(dat+raw contents)'+CrLf+'(with convert if possible)';
-    btn_sel_files_toone.Caption:=   'Selected files'+CrLf+'(dat contents only)';
-    btn_all_files_toone.Caption:=   'All files in list'+CrLf+'(dat contents only)';
-  END;
-
-PROCEDURE TForm11.Extract(Sender: TObject);
-  VAR
-    sel_only:Boolean;
-    dat_only:Boolean;
-    convert:Boolean;
-    one_file:Boolean;
-    settings:TExportSet;
-    files:LongWord;
-    i,done:LongWord;
-    begintime:Double;
-  BEGIN
-    sel_only:=Pos('sel',TButton(Sender).Name)>0;
-    dat_only:=NOT (Pos('datraw',TButton(Sender).Name)>0);
-    convert:=Pos('convert',TButton(Sender).Name)>0;
-    one_file:=Pos('toone',TButton(Sender).Name)>0;
-    IF dat_only THEN settings:=[DO_dat]
-    ELSE settings:=[DO_dat,DO_raw];
-    IF convert THEN settings:=settings+[DO_convert];
-    IF one_file THEN settings:=settings+[DO_toone];
-    progress.Position:=0;
-
-    IF saved.Execute THEN BEGIN
-      begintime:=Time;
-      group_progress.Visible:=True;
-      group_select.Enabled:=False;
-      group_singlefiles.Enabled:=False;
-      group_onefile.Enabled:=False;
-      lbl_estimated.Caption:='Estimated finishing time: unknown';
-      IF one_file THEN BEGIN
-        IF FileExists(saved.FileName) THEN BEGIN
-          IF MessageBox(Self.Handle,PChar('File already exists. Do you want to overwrite it?'),PChar('Warning!'),MB_YESNO)=ID_YES THEN BEGIN
-            DeleteFile(saved.FileName);
-          END ELSE BEGIN
-            group_progress.Visible:=False;
-            group_select.Enabled:=True;
-            group_singlefiles.Enabled:=True;
-            group_onefile.Enabled:=True;
-            Exit;
-          END;
-        END;
-        i:=FileCreate(saved.FileName);
-        FileClose(i);
-        i:=0;
-      END;
-      IF sel_only THEN BEGIN
-        files:=list.SelCount;
-        lbl_progress.Caption:='Files done: 0/'+IntToStr(files);
-        progress.Max:=files;
-        done:=0;
-        FOR i:=0 TO list.Count-1 DO BEGIN
-          IF list.Selected[i] THEN BEGIN
-            IF one_file THEN BEGIN
-              ExportFile(OniDataConnection.ExtractFileID(list.Items.Strings[list.ItemIndex]),ExtractFileName(saved.FileName),settings,ExtractFileDir(saved.FileName));
-            END ELSE BEGIN
-              ExportFile(OniDataConnection.ExtractFileID(list.Items.Strings[list.ItemIndex]),list.Items.Strings[i],settings,'D:');
-            END;
-            Inc(done);
-          END;
-          IF ((done MOD 10)=0) AND (done>=50) THEN
-            lbl_estimated.Caption:='Estimated finishing time: '+TimeToStr((Time-begintime)/done*files+begintime);
-          IF (i MOD 10)=0 THEN BEGIN
-            progress.Position:=done;
-            lbl_progress.Caption:='Files done: '+IntToStr(done)+'/'+IntToStr(files);
-            Application.ProcessMessages;
-          END;
-        END;
-      END ELSE BEGIN
-        files:=list.Count;
-        lbl_progress.Caption:='Files done: 0/'+IntToStr(files);
-        progress.Max:=files;
-        FOR i:=0 TO list.Count-1 DO BEGIN
-          IF one_file THEN BEGIN
-            ExportFile(OniDataConnection.ExtractFileID(list.Items.Strings[list.ItemIndex]),ExtractFileName(saved.FileName),settings,ExtractFileDir(saved.FileName));
-          END ELSE BEGIN
-            ExportFile(OniDataConnection.ExtractFileID(list.Items.Strings[list.ItemIndex]),list.Items.Strings[i],settings,'D:');
-          END;
-          IF ((i MOD 10)=0) AND (i>=50) THEN
-            lbl_estimated.Caption:='Estimated finishing time: '+TimeToStr((Time-begintime)/i*files+begintime);
-          IF (i MOD 5)=0 THEN BEGIN
-            progress.Position:=i;
-            lbl_progress.Caption:='Files done: '+IntToStr(i)+'/'+IntToStr(files);
-            Application.ProcessMessages;
-          END;
-        END;
-      END;
-      group_progress.Visible:=False;
-      group_select.Enabled:=True;
-      group_singlefiles.Enabled:=True;
-      group_onefile.Enabled:=True;
-    END;
-  END;
-
-END.
Index: oup/current/Unit12_ValueEdit.dfm
===================================================================
--- oup/current/Unit12_ValueEdit.dfm	(revision 40)
+++ 	(revision )
@@ -1,157 +1,0 @@
-object Form12: TForm12
-  Left = 0
-  Top = 0
-  BorderStyle = bsNone
-  BorderWidth = 1
-  Caption = 'Value Edit'
-  ClientHeight = 145
-  ClientWidth = 298
-  Color = clBtnFace
-  Constraints.MaxHeight = 147
-  Constraints.MaxWidth = 700
-  Constraints.MinHeight = 147
-  Constraints.MinWidth = 300
-  Font.Charset = DEFAULT_CHARSET
-  Font.Color = clWindowText
-  Font.Height = -11
-  Font.Name = 'Tahoma'
-  Font.Style = []
-  OldCreateOrder = False
-  Position = poMainFormCenter
-  PixelsPerInch = 96
-  TextHeight = 13
-  object group: TGroupBox
-    Left = 0
-    Top = 0
-    Width = 298
-    Height = 145
-    Align = alClient
-    Caption = '---'
-    TabOrder = 0
-    DesignSize = (
-      298
-      145)
-    object lbl_current: TLabel
-      Left = 8
-      Top = 64
-      Width = 73
-      Height = 17
-      AutoSize = False
-      Caption = 'Current value:'
-    end
-    object lbl_new: TLabel
-      Left = 8
-      Top = 88
-      Width = 73
-      Height = 17
-      AutoSize = False
-      Caption = 'New value:'
-    end
-    object lbl_offset: TLabel
-      Left = 8
-      Top = 16
-      Width = 73
-      Height = 17
-      AutoSize = False
-      Caption = 'Offset:'
-    end
-    object lbl_datatype: TLabel
-      Left = 8
-      Top = 40
-      Width = 73
-      Height = 17
-      AutoSize = False
-      Caption = 'Datatype:'
-    end
-    object btn_ok: TButton
-      Left = 153
-      Top = 112
-      Width = 65
-      Height = 25
-      Anchors = [akTop, akRight]
-      Caption = 'OK'
-      Default = True
-      TabOrder = 0
-      OnClick = btn_okClick
-    end
-    object btn_cancel: TButton
-      Left = 225
-      Top = 112
-      Width = 65
-      Height = 25
-      Anchors = [akTop, akRight]
-      Cancel = True
-      Caption = 'Cancel'
-      TabOrder = 1
-      OnClick = btn_cancelClick
-    end
-    object edit_current: TEdit
-      Left = 88
-      Top = 64
-      Width = 203
-      Height = 18
-      Anchors = [akLeft, akTop, akRight]
-      AutoSize = False
-      Color = clInfoBk
-      ReadOnly = True
-      TabOrder = 2
-    end
-    object edit_offset: TEdit
-      Left = 87
-      Top = 16
-      Width = 203
-      Height = 18
-      Anchors = [akLeft, akTop, akRight]
-      AutoSize = False
-      Color = clInfoBk
-      ReadOnly = True
-      TabOrder = 3
-    end
-    object edit_datatype: TEdit
-      Left = 87
-      Top = 40
-      Width = 203
-      Height = 18
-      Anchors = [akLeft, akTop, akRight]
-      AutoSize = False
-      Color = clInfoBk
-      ReadOnly = True
-      TabOrder = 4
-    end
-    object edit_new: TCrossEdit
-      Left = 88
-      Top = 88
-      Width = 203
-      Height = 18
-      Anchors = [akLeft, akTop, akRight]
-      AutoSize = False
-      BorderStyle = bsNone
-      Color = clWhite
-      Font.Charset = DEFAULT_CHARSET
-      Font.Color = clWindowText
-      Font.Height = -11
-      Font.Name = 'Tahoma'
-      Font.Style = []
-      HideSelection = False
-      ParentFont = False
-      TabOrder = 5
-      Text = '0000'
-      FocusAlignment = taLeftJustify
-      NoFocusAlignment = taLeftJustify
-      Precision = 15
-      Decimals = 4
-      FocusWidthInc = 0
-      EditType = etHex
-      NextDialogOnEnter = True
-      DialogOnCursorKeys = True
-      NextPriorStep = 1
-      AutoFocus = False
-      LimitCheck = True
-      Max = 2147483647.000000000000000000
-      FocusColor = clWhite
-      NoFocusColor = clWhite
-      ErrorColor = clRed
-      StringCharSet = scFull
-    end
-  end
-end
Index: oup/current/Unit12_ValueEdit.pas
===================================================================
--- oup/current/Unit12_ValueEdit.pas	(revision 40)
+++ 	(revision )
@@ -1,119 +1,0 @@
-UNIT Unit12_ValueEdit;
-INTERFACE
-USES
-  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
-  Dialogs, StdCtrls, CrossEdit, Math;
-TYPE
-  TForm12 = Class(TForm)
-    group: TGroupBox;
-    btn_ok: TButton;
-    btn_cancel: TButton;
-    lbl_current: TLabel;
-    edit_current: TEdit;
-    lbl_new: TLabel;
-    lbl_offset: TLabel;
-    lbl_datatype: TLabel;
-    edit_offset: TEdit;
-    edit_datatype: TEdit;
-    edit_new: TCrossEdit;
-    PROCEDURE btn_cancelClick(Sender: TObject);
-    PROCEDURE btn_okClick(Sender: TObject);
-    PROCEDURE MakeVarInput(objectname:String; offset:LongWord; datatype:Word; current:String; caller:TObject);
-  PRIVATE
-  PUBLIC
-  END;
-
-VAR
-  Form12: TForm12;
-
-
-IMPLEMENTATION
-USES Unit8_binedit, Unit13_rawedit,Unit9_data_structures, Unit1_main;
-{$R *.dfm}
-VAR
-  caller_win_dat:TForm8;
-  caller_win_raw:TForm13;
-  _datatype:Word;
-  _offset:LongWord;
-
-
-PROCEDURE TForm12.MakeVarInput(objectname:String; offset:LongWord; datatype:Word; current:String; caller:TObject);
-  BEGIN
-    caller_win_dat:=NIL;
-    caller_win_raw:=NIL;
-    IF Pos('rawedit',TComponent(caller).Name)>0 THEN
-      caller_win_raw:=TForm13(caller)
-    ELSE
-      caller_win_dat:=TForm8(caller);
-    Form1.Enabled:=False;
-    Self.Visible:=True;
-    group.Caption:='Edit value';
-    _datatype:=datatype;
-    _offset:=offset;
-    IF Length(objectname)>0 THEN group.Caption:=group.Caption+' for '+objectname;
-    edit_offset.Text:='0x'+IntToHex(offset,8);
-    edit_datatype.Text:=GetDataType(datatype);
-    edit_current.Text:=current;
-    edit_new.EditType:=etString;
-    edit_new.Text:='';
-    edit_new.LimitCheck:=False;
-    edit_new.MaxLength:=0;
-    edit_new.Max:=0;
-    edit_new.BorderStyle:=bsSingle;
-    Form12.Width:=300;
-    CASE datatype OF
-      1..4: BEGIN
-              edit_new.EditType:=etUnsignedInt;
-              edit_new.LimitCheck:=True;
-              edit_new.Max:=Int(Power(256,datatype))-1;
-            END;
-      5..8: BEGIN
-              edit_new.MaxLength:=2*(datatype-4);
-              edit_new.EditType:=etHex;
-            END;
-      9:    BEGIN
-              edit_new.EditType:=etFloat;
-              edit_new.LimitCheck:=False;
-            END;
-      10:   BEGIN
-              edit_new.EditType:=etBinary;
-              edit_new.LimitCheck:=False;
-              edit_new.MaxLength:=8;
-            END;
-      13..16: BEGIN
-              Exit;
-              edit_new.EditType:=etInteger;
-              edit_new.LimitCheck:=True;
-              edit_new.Max:=Int((Power(256,datatype-13)) / 2)-1;
-              edit_new.Min:=1-Int((Power(256,datatype-13)) / 2)-1;
-            END;
-      10000..65535: BEGIN
-              edit_new.EditType:=etString;
-              edit_new.LimitCheck:=False;
-              edit_new.MaxLength:=datatype-10000;
-              Form12.Width:=700;
-            END;
-    END;
-    edit_new.SetFocus;
-    edit_new.SelectAll;
-  END;
-
-PROCEDURE TForm12.btn_okClick(Sender: TObject);
-  BEGIN
-    IF NOT edit_new.NoValidValue THEN BEGIN
-      Form1.Enabled:=True;
-      Self.Visible:=False;
-      IF caller_win_dat=NIL THEN
-        caller_win_raw.SetNewValue(_datatype,_offset,edit_new.Text)
-      ELSE
-        caller_win_dat.SetNewValue(_datatype,_offset,edit_new.Text);
-    END;
-  END;
-
-PROCEDURE TForm12.btn_cancelClick(Sender: TObject);
-  BEGIN
-    Form1.Enabled:=True;
-    Self.Visible:=False;
-  END;
-
-END.
Index: oup/current/Unit13_rawedit.dfm
===================================================================
--- oup/current/Unit13_rawedit.dfm	(revision 40)
+++ 	(revision )
@@ -1,301 +1,0 @@
-object Form13: TForm13
-  Left = 0
-  Top = 0
-  BorderIcons = [biSystemMenu, biMaximize]
-  Caption = 'Binary .raw-Editor'
-  ClientHeight = 640
-  ClientWidth = 642
-  Color = clBtnFace
-  Font.Charset = DEFAULT_CHARSET
-  Font.Color = clWindowText
-  Font.Height = -11
-  Font.Name = 'Tahoma'
-  Font.Style = []
-  FormStyle = fsMDIChild
-  KeyPreview = True
-  OldCreateOrder = False
-  Visible = True
-  WindowState = wsMaximized
-  OnClose = FormClose
-  OnCloseQuery = FormCloseQuery
-  OnCreate = FormCreate
-  OnKeyUp = FormKeyUp
-  OnResize = FormResize
-  PixelsPerInch = 96
-  TextHeight = 13
-  object Splitter1: TSplitter
-    Left = 150
-    Top = 0
-    Width = 9
-    Height = 640
-    AutoSnap = False
-    Beveled = True
-    MinSize = 150
-  end
-  object panel_data: TPanel
-    Left = 159
-    Top = 0
-    Width = 483
-    Height = 640
-    Align = alClient
-    BevelOuter = bvNone
-    TabOrder = 0
-    OnResize = panel_dataResize
-    object Splitter2: TSplitter
-      Left = 0
-      Top = 450
-      Width = 483
-      Height = 9
-      Cursor = crVSplit
-      Align = alTop
-      AutoSnap = False
-      Beveled = True
-      MinSize = 40
-      ExplicitTop = 209
-    end
-    object hex: TMPHexEditor
-      Left = 0
-      Top = 0
-      Width = 483
-      Height = 450
-      Cursor = crIBeam
-      Align = alTop
-      Font.Charset = DEFAULT_CHARSET
-      Font.Color = clWindowText
-      Font.Height = -16
-      Font.Name = 'Courier'
-      Font.Style = []
-      OnKeyUp = hexKeyUp
-      ParentFont = False
-      TabOrder = 0
-      BytesPerRow = 16
-      Translation = tkAsIs
-      OffsetFormat = '6!10:0x|'
-      Colors.Background = clWindow
-      Colors.ChangedBackground = clWindow
-      Colors.ChangedText = clRed
-      Colors.CursorFrame = clNavy
-      Colors.Offset = clBlack
-      Colors.OddColumn = clBlue
-      Colors.EvenColumn = clNavy
-      Colors.CurrentOffsetBackground = clBtnShadow
-      Colors.OffsetBackGround = clBtnFace
-      Colors.CurrentOffset = clBtnHighlight
-      Colors.Grid = clBtnFace
-      Colors.NonFocusCursorFrame = clAqua
-      Colors.ActiveFieldBackground = clWindow
-      FocusFrame = True
-      NoSizeChange = True
-      AllowInsertMode = False
-      DrawGridLines = False
-      Version = 'May 23, 2005; '#169' markus stephany, vcl[at]mirkes[dot]de'
-      OnChange = hexChange
-      ShowPositionIfNotFocused = True
-      OnSelectionChanged = hexSelectionChanged
-    end
-    object value_viewer: TWrapGrid
-      Left = 0
-      Top = 459
-      Width = 483
-      Height = 181
-      Align = alClient
-      ColCount = 1
-      DefaultColWidth = 80
-      DefaultRowHeight = 18
-      FixedCols = 0
-      RowCount = 8
-      FixedRows = 0
-      Font.Charset = DEFAULT_CHARSET
-      Font.Color = clWindowText
-      Font.Height = -11
-      Font.Name = 'Tahoma'
-      Font.Style = []
-      Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goColSizing]
-      ParentFont = False
-      PopupMenu = value_viewer_context
-      TabOrder = 1
-      OnDblClick = value_viewerDblClick
-      OnMouseDown = value_viewerMouseDown
-    end
-  end
-  object panel_files: TPanel
-    Left = 0
-    Top = 0
-    Width = 150
-    Height = 640
-    Align = alLeft
-    BevelOuter = bvNone
-    TabOrder = 1
-    object Splitter4: TSplitter
-      Left = 0
-      Top = 442
-      Width = 150
-      Height = 9
-      Cursor = crVSplit
-      Align = alBottom
-      AutoSnap = False
-      Beveled = True
-      MinSize = 150
-    end
-    object panel_imexport: TPanel
-      Left = 0
-      Top = 580
-      Width = 150
-      Height = 60
-      Align = alBottom
-      BevelOuter = bvNone
-      TabOrder = 0
-      OnResize = panel_imexportResize
-      object btn_export: TButton
-        Left = 4
-        Top = 4
-        Width = 142
-        Height = 25
-        Caption = 'Export to file...'
-        TabOrder = 0
-        OnClick = btn_exportClick
-      end
-      object btn_import: TButton
-        Left = 4
-        Top = 32
-        Width = 142
-        Height = 25
-        Caption = 'Import from file...'
-        TabOrder = 1
-        OnClick = btn_importClick
-      end
-    end
-    object group_file: TGroupBox
-      Left = 0
-      Top = 0
-      Width = 150
-      Height = 442
-      Align = alClient
-      Caption = '1. Select file'
-      TabOrder = 1
-      object list: TListBox
-        Left = 2
-        Top = 15
-        Width = 146
-        Height = 337
-        Align = alClient
-        ItemHeight = 13
-        TabOrder = 0
-        OnClick = listClick
-      end
-      object panel_extension: TPanel
-        Left = 2
-        Top = 352
-        Width = 146
-        Height = 88
-        Align = alBottom
-        BevelOuter = bvNone
-        TabOrder = 1
-        OnResize = panel_extensionResize
-        object lbl_filter: TLabel
-          Left = 2
-          Top = 46
-          Width = 100
-          Height = 17
-          AutoSize = False
-          Caption = 'Filter by &extension:'
-          FocusControl = combo_extension
-        end
-        object combo_extension: TComboBox
-          Left = 2
-          Top = 60
-          Width = 145
-          Height = 21
-          Style = csDropDownList
-          DropDownCount = 12
-          Font.Charset = DEFAULT_CHARSET
-          Font.Color = clWindowText
-          Font.Height = -11
-          Font.Name = 'Tahoma'
-          Font.Style = []
-          ItemHeight = 13
-          ParentFont = False
-          Sorted = True
-          TabOrder = 2
-          OnClick = combo_extensionClick
-        end
-        object edit_filtername: TEdit
-          Left = 2
-          Top = 20
-          Width = 145
-          Height = 18
-          AutoSize = False
-          TabOrder = 1
-        end
-        object check_filtername: TCheckBox
-          Left = 2
-          Top = 5
-          Width = 130
-          Height = 15
-          Caption = 'Filter by file&name:'
-          TabOrder = 0
-          OnClick = check_filternameClick
-        end
-      end
-    end
-    object GroupBox1: TGroupBox
-      Left = 0
-      Top = 451
-      Width = 150
-      Height = 129
-      Align = alBottom
-      Caption = '2. Select .dat-link-offset'
-      TabOrder = 2
-      object list_offset: TListBox
-        Left = 2
-        Top = 15
-        Width = 146
-        Height = 112
-        Align = alClient
-        ItemHeight = 13
-        TabOrder = 0
-        OnClick = list_offsetClick
-      end
-    end
-  end
-  object value_viewer_context: TPopupMenu
-    AutoHotkeys = maManual
-    OnPopup = value_viewer_contextPopup
-    Left = 368
-    Top = 264
-    object value_viewer_context_copy: TMenuItem
-      Caption = 'Copy to &clipboard'
-      OnClick = value_viewer_context_copyClick
-    end
-    object value_viewer_context_copyasdec: TMenuItem
-      Caption = 'Copy to clipboard (as &dec)'
-      OnClick = value_viewer_context_copyClick
-    end
-    object value_viewer_context_copyasfloat: TMenuItem
-      Caption = 'Copy to clipboard (as &float)'
-      OnClick = value_viewer_context_copyClick
-    end
-    object value_viewer_context_copyasbitset: TMenuItem
-      Caption = 'Copy to clipboard (as &bitset)'
-      OnClick = value_viewer_context_copyClick
-    end
-    object value_viewer_context_copyasstring: TMenuItem
-      Caption = 'Copy to clipboard (as &string)'
-      OnClick = value_viewer_context_copyClick
-    end
-    object value_viewer_context_copyashex: TMenuItem
-      Caption = 'Copy to clipboard (as &hex)'
-      OnClick = value_viewer_context_copyClick
-    end
-  end
-  object opend: TOpenDialog
-    Options = [ofPathMustExist, ofFileMustExist, ofEnableSizing]
-    Left = 120
-    Top = 584
-  end
-  object saved: TSaveDialog
-    Options = [ofOverwritePrompt, ofPathMustExist, ofEnableSizing]
-    Left = 120
-    Top = 608
-  end
-end
Index: oup/current/Unit13_rawedit.pas
===================================================================
--- oup/current/Unit13_rawedit.pas	(revision 40)
+++ 	(revision )
@@ -1,723 +1,0 @@
-UNIT Unit13_rawedit;
-INTERFACE
-USES
-  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
-  Dialogs, Wrapgrid, StdCtrls, Grids, StrUtils, MPHexEditor, ExtCtrls, Clipbrd,
-  Unit3_data, Unit2_functions, Unit9_data_structures, Unit4_exporters, Unit15_Classes,
-  Menus, Math;
-
-TYPE
-  TForm13 = Class(TForm)
-    Splitter1: TSplitter;
-    panel_data: TPanel;
-    hex: TMPHexEditor;
-    Splitter2: TSplitter;
-    value_viewer: TWrapGrid;
-    value_viewer_context: TPopupMenu;
-    value_viewer_context_copy: TMenuItem;
-    value_viewer_context_copyashex: TMenuItem;
-    value_viewer_context_copyasdec: TMenuItem;
-    value_viewer_context_copyasfloat: TMenuItem;
-    value_viewer_context_copyasbitset: TMenuItem;
-    value_viewer_context_copyasstring: TMenuItem;
-    panel_files: TPanel;
-    opend: TOpenDialog;
-    saved: TSaveDialog;
-    panel_imexport: TPanel;
-    btn_export: TButton;
-    btn_import: TButton;
-    group_file: TGroupBox;
-    list: TListBox;
-    panel_extension: TPanel;
-    lbl_filter: TLabel;
-    combo_extension: TComboBox;
-    edit_filtername: TEdit;
-    check_filtername: TCheckBox;
-    GroupBox1: TGroupBox;
-    list_offset: TListBox;
-    Splitter4: TSplitter;
-    procedure hexKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
-    PROCEDURE list_offsetClick(Sender: TObject);
-    PROCEDURE LoadRaw(raw_info:TRawInfo);
-    PROCEDURE LoadFileNames;
-    PROCEDURE check_filternameClick(Sender: TObject);
-    PROCEDURE combo_extensionClick(Sender: TObject);
-    PROCEDURE panel_extensionResize(Sender: TObject);
-    PROCEDURE listClick(Sender: TObject);
-    PROCEDURE Recreatelist;
-
-    PROCEDURE FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
-    PROCEDURE value_viewerDblClick(Sender: TObject);
-    PROCEDURE value_viewer_context_copyClick(Sender: TObject);
-    PROCEDURE value_viewerMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
-    PROCEDURE value_viewer_contextPopup(Sender: TObject);
-    PROCEDURE btn_importClick(Sender: TObject);
-    PROCEDURE btn_exportClick(Sender: TObject);
-    PROCEDURE panel_imexportResize(Sender: TObject);
-    FUNCTION Save:Boolean;
-    PROCEDURE FormClose(Sender: TObject; var Action: TCloseAction);
-    FUNCTION GetValue(datatype:Word; offset:LongWord):String;
-    PROCEDURE hexSelectionChanged(Sender: TObject);
-    PROCEDURE hexChange(Sender: TObject);
-    PROCEDURE panel_dataResize(Sender: TObject);
-    PROCEDURE FormResize(Sender: TObject);
-    PROCEDURE FormCloseQuery(Sender: TObject; var CanClose: Boolean);
-    PROCEDURE FormCreate(Sender: TObject);
-    PROCEDURE ClearValues;
-    PROCEDURE WriteValues;
-    PROCEDURE SetNewValue(datatype:Word; offset:LongWord; value:String);
-  PRIVATE
-    fileid:LongWord;
-    dat_offset:LongWord;
-    fileid_opened,dat_offset_opened:LongWord;
-  PUBLIC
-  END;
-
-VAR
-  Form13: TForm13;
-
-IMPLEMENTATION
-{$R *.dfm}
-USES Unit1_main, Unit12_ValueEdit;
-
-
-PROCEDURE TForm13.LoadRaw(raw_info:TRawInfo);
-  VAR
-    i:LongWord;
-    data:Tdata;
-    mem:TMemoryStream;
-  BEGIN
-    IF hex.Modified THEN BEGIN
-      IF NOT Save THEN BEGIN
-        Exit;
-      END;
-    END;
-    IF list_offset.Count=0 THEN BEGIN
-      FOR i:=0 TO list.Count-1 DO BEGIN
-        IF OniDataConnection.ExtractFileID(list.Items.Strings[i])=raw_info.src_id THEN BEGIN
-          list.ItemIndex:=i;
-          listClick(Self);
-          Break;
-        END;
-      END;
-      FOR i:=0 TO list_offset.Count-1 DO BEGIN
-        IF MidStr(list_offset.Items.Strings[i],3,8)=IntToHex(raw_info.src_offset,8) THEN BEGIN
-          list_offset.ItemIndex:=i;
-          Break;
-        END;
-      END;
-    END;
-    SetLength(data,raw_info.raw_size);
-    OniDataConnection.LoadRawFile(raw_info.src_id,raw_info.src_offset,@data[0]);
-    IF Length(data)>0 THEN BEGIN
-      hex.DataSize:=0;
-      hex.DataSize:=raw_info.raw_size;
-      FOR i:=0 TO High(data) DO
-        hex.Data[i]:=data[i];
-      //WriteStructureInfos(GetStructureInfoId(GetFileInfo(fileid).Extension));
-//      structs.Height:=structs.RowCount*20;
-//      IF structs.Height>120 THEN structs.Height:=120;
-      hexSelectionChanged(Self);
-      fileid_opened:=raw_info.src_id;
-      dat_offset_opened:=raw_info.src_offset;
-      hex.Modified:=False;
-    END ELSE BEGIN
-      ClearValues;
-      hex.DataSize:=0;
-    END;
-  END;
-
-PROCEDURE TForm13.Recreatelist;
-  VAR
-    i:LongWord;
-    exts:TStringArray;
-    count:LongWord;
-  BEGIN
-    combo_extension.Items.Clear;
-    combo_extension.Items.Add('_All files_ ('{+IntToStr(dat_header.Files)}+')');
-    exts:=OniDataConnection.GetExtensionsList;
-    FOR i:=0 TO High(RawListHandlers) DO BEGIN
-      count:=Length(OniDataConnection.GetFilesList(RawListHandlers[i].Ext,'',True));
-      combo_extension.Items.Add(RawListHandlers[i].ext+' ('+IntToStr(count)+')');
-    END;
-//    FOR i:=0 TO High(exts) DO
-//      combo_extension.Items.Add(exts[i]);
-    combo_extension.ItemIndex:=0;
-    combo_extensionClick(Self);
-  END;
-
-PROCEDURE TForm13.LoadFileNames;
-  VAR
-    Extension:String;
-    no_zero_bytes:Boolean;
-    pattern:String;
-    files:TStringArray;
-    i:LongWord;
-  BEGIN
-    Extension:=MidStr(combo_extension.Items.Strings[combo_extension.ItemIndex],1,4);
-    pattern:='';
-    IF check_filtername.Checked THEN pattern:=edit_filtername.Text;
-    IF Extension='_All' THEN BEGIN
-      Extension:='';
-      FOR i:=0 TO High(RawListHandlers) DO BEGIN
-        IF Length(Extension)>0 THEN Extension:=Extension+',';
-        Extension:=Extension+RawListHandlers[i].Ext;
-      END;
-    END;
-
-    files:=OniDataConnection.GetFilesList(extension,pattern,TRUE);
-    list.Items.Clear;
-    IF Length(files)>0 THEN
-      FOR i:=0 TO High(files) DO
-        list.Items.Add(files[i]);
-    list_offset.Items.Clear;
-  END;
-
-PROCEDURE TForm13.panel_extensionResize(Sender: TObject);
-  BEGIN
-    combo_extension.Width:=panel_extension.Width-5;
-    edit_filtername.Width:=panel_extension.Width-5;
-  END;
-
-PROCEDURE TForm13.combo_extensionClick(Sender: TObject);
-  BEGIN
-    LoadFileNames;
-  END;
-
-PROCEDURE TForm13.check_filternameClick(Sender: TObject);
-  BEGIN
-    edit_filtername.Enabled:=NOT check_filtername.Checked;
-    LoadFileNames;
-  END;
-
-PROCEDURE TForm13.listClick(Sender: TObject);
-  VAR
-    mem:TMemoryStream;
-    data:Tdata;
-    i:LongWord;
-    offsets:TRawList;
-  BEGIN
-    IF hex.Modified THEN BEGIN
-      IF NOT Save THEN BEGIN
-        Exit;
-      END;
-    END;
-    ClearValues;
-    hex.DataSize:=0;
-    fileid:=OniDataConnection.ExtractFileID(list.Items.Strings[list.ItemIndex]);
-    list_offset.Enabled:=True;
-    IF OniDataConnection.GetFileInfo(fileid).size>0 THEN BEGIN
-      offsets:=OniDataConnection.GetRawList(fileid);
-      list_offset.Items.Clear;
-      IF Length(offsets)>0 THEN BEGIN
-        FOR i:=0 TO High(offsets) DO BEGIN
-          list_offset.Items.Add('0x'+IntToHex(offsets[i].src_offset,8)+', '+IntToStr(offsets[i].raw_size)+' bytes');
-        END;
-      END ELSE BEGIN
-        list_offset.Enabled:=False;
-      END;
-    END ELSE BEGIN
-      list_offset.Enabled:=False;
-    END;
-  END;
-
-PROCEDURE TForm13.list_offsetClick(Sender: TObject);
-  VAR
-    i:LongWord;
-    raw_info:TRawInfo;
-  BEGIN
-    ClearValues;
-    dat_offset:=StrToInt('$'+MidStr(list_offset.Items.Strings[list_offset.ItemIndex],3,8));
-    LoadRaw(OniDataConnection.GetRawInfo(fileid,dat_offset));
-  END;
-
-
-
-
-FUNCTION IntToBin(value:Byte):String;
-  VAR i:Byte;
-  BEGIN
-    Result:='';
-    FOR i:=7 DOWNTO 0 DO BEGIN
-      Result:=Result+IntToStr((value SHR i) AND $01);
-    END;
-  END;
-
-FUNCTION TForm13.GetValue(datatype:Word; offset:LongWord):String;
-  VAR
-    data:Tdata;
-    i:Word;
-  BEGIN
-    CASE datatype OF
-      1: Result:=IntToStr(hex.data[offset]);
-      2: Result:=IntToStr(hex.data[offset]+hex.data[offset+1]*256);
-      3: Result:=IntToStr(hex.data[offset]+hex.data[offset+1]*256+hex.data[offset+2]*256*256);
-      4: Result:=IntToStr(hex.data[offset]+hex.data[offset+1]*256+hex.data[offset+2]*256*256+hex.data[offset+3]*256*256*256);
-      5: Result:='0x'+IntToHex(hex.data[offset],2);
-      6: Result:='0x'+IntToHex(hex.data[offset]+hex.data[offset+1]*256,4);
-      7: Result:='0x'+IntToHex(hex.data[offset]+hex.data[offset+1]*256+hex.data[offset+2]*256*256,6);
-      8: Result:='0x'+IntToHex(hex.data[offset]+hex.data[offset+1]*256+hex.data[offset+2]*256*256+hex.data[offset+3]*256*256*256,8);
-      9: BEGIN
-          SetLength(data,4);
-          data[0]:=hex.data[offset];
-          data[1]:=hex.data[offset+1];
-          data[2]:=hex.data[offset+2];
-          data[3]:=hex.data[offset+3];
-          Result:=FloatToStr(Decode_Float(data));
-        END;
-      10: Result:=IntToBin(hex.data[offset]);
-      11: Result:='0x'+IntToHex(hex.data[offset]+hex.data[offset+1]*256+hex.data[offset+2]*256*256+hex.data[offset+3]*256*256*256,8);
-      10000..65535: BEGIN
-          Result:='';
-          FOR i:=1 TO datatype-10000 DO BEGIN
-            IF hex.Data[offset+i-1]>=32 THEN
-              Result:=Result+Chr(hex.Data[offset+i-1])
-            ELSE
-              Result:=Result+'.';
-          END;
-        END;
-    END;
-  END;
-
-PROCEDURE TForm13.ClearValues;
-  VAR
-    i:Byte;
-  BEGIN
-    FOR i:=1 TO value_viewer.RowCount-1 DO BEGIN
-      value_viewer.Cells[1,i]:='';
-    END;
-  END;
-
-PROCEDURE TForm13.WriteValues;
-  VAR
-    i,j:Byte;
-    data:Tdata;
-    str:String;
-    value:LongWord;
-  BEGIN
-    FOR i:=1 TO value_viewer.RowCount-1 DO BEGIN
-      IF value_viewer.Cells[0,i]='1 byte, unsigned' THEN BEGIN
-        IF ((hex.SelCount=1) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+1)>hex.DataSize) THEN BEGIN
-          value:=hex.Data[hex.SelStart];
-          value_viewer.Cells[1,i]:=IntToStr( value )+' / 0x'+IntToHex( value , 2 );
-        END ELSE
-          value_viewer.Cells[1,i]:='';
-      END;
-      IF value_viewer.Cells[0,i]='2 bytes, unsigned' THEN BEGIN
-        IF ((hex.SelCount=2) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+2)>hex.DataSize) THEN BEGIN
-          value:=hex.Data[hex.SelStart] + hex.Data[hex.SelStart+1]*256;
-          value_viewer.Cells[1,i]:=IntToStr( value )+' / 0x'+IntToHex( value , 4 );
-        END ELSE
-          value_viewer.Cells[1,i]:='';
-      END;
-      IF value_viewer.Cells[0,i]='4 bytes, unsigned' THEN BEGIN
-        IF ((hex.SelCount=4) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+4)>hex.DataSize) THEN BEGIN
-          value:=hex.Data[hex.SelStart]+hex.Data[hex.SelStart+1]*256+hex.Data[hex.SelStart+2]*256*256+hex.Data[hex.SelStart+3]*256*256*256;
-          value_viewer.Cells[1,i]:=IntToStr( value )+' / 0x'+IntToHex( value , 8 );
-        END ELSE
-          value_viewer.Cells[1,i]:='';
-      END;
-      IF value_viewer.Cells[0,i]='Bitset' THEN BEGIN
-        IF (hex.SelCount<=8) THEN BEGIN
-          IF hex.SelCount=0 THEN BEGIN
-            SetLength(data,1);
-            data[0]:=hex.Data[hex.SelStart];
-          END ELSE BEGIN
-            SetLength(data,hex.SelCount);
-            FOR j:=0 TO hex.SelCount-1 DO
-              data[j]:=hex.Data[hex.SelStart+j];
-          END;
-          value_viewer.Cells[1,i]:=DataToBin(data);
-        END ELSE
-          value_viewer.Cells[1,i]:='';
-      END;
-      IF value_viewer.Cells[0,i]='Float' THEN BEGIN
-        IF ((hex.SelCount=4) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+4)>hex.DataSize) THEN BEGIN
-          SetLength(data,4);
-          FOR j:=0 TO 3 DO
-            data[j]:=hex.Data[hex.SelStart+j];
-          value_viewer.Cells[1,i]:=FloatToStr(Decode_Float(data));
-        END ELSE
-          value_viewer.Cells[1,i]:='';
-      END;
-      IF value_viewer.Cells[0,i]='Selected length' THEN BEGIN
-        value_viewer.Cells[1,i]:=IntToStr(hex.SelCount)+' bytes';
-      END;
-      IF value_viewer.Cells[0,i]='String' THEN BEGIN
-        j:=0;
-        str:='';
-        IF hex.SelCount=0 THEN BEGIN
-          WHILE (hex.Data[hex.SelStart+j]>0) AND ((hex.SelStart+j)<hex.DataSize) DO BEGIN
-            IF hex.Data[hex.selstart+j]>=32 THEN
-              str:=str+Char(hex.Data[hex.SelStart+j])
-            ELSE
-              str:=str+'.';
-            Inc(j);
-          END;
-        END ELSE BEGIN
-          FOR j:=0 TO hex.SelCount-1 DO
-            IF hex.Data[hex.selstart+j]>=32 THEN
-              str:=str+Char(hex.Data[hex.SelStart+j])
-            ELSE
-              IF hex.Data[hex.selstart+j]>0 THEN
-                str:=str+'.'
-              ELSE
-                Break;
-        END;
-        value_viewer.Cells[1,i]:=str;
-      END;
-    END;
-  END;
-
-PROCEDURE TForm13.FormCreate(Sender: TObject);
-  BEGIN
-    Self.Caption:='';
-    fileid:=0;
-    value_viewer.ColCount:=2;
-    value_viewer.RowCount:=8;
-    value_viewer.FixedRows:=1;
-    value_viewer.Cells[0,0]:='Type';
-    value_viewer.Cells[1,0]:='Value';
-    value_viewer.Cells[0,1]:='1 byte, unsigned';
-    value_viewer.Cells[0,2]:='2 bytes, unsigned';
-    value_viewer.Cells[0,3]:='4 bytes, unsigned';
-    value_viewer.Cells[0,4]:='Bitset';
-    value_viewer.Cells[0,5]:='Float';
-    value_viewer.Cells[0,6]:='String';
-    value_viewer.Cells[0,7]:='Selected length';
-    value_viewer.ColWidths[0]:=100;
-    hex.Height:=panel_data.Height-190;
-    Self.panel_dataResize(Self);
-//
-    value_viewer.Font.Charset:=AppSettings.CharSet;
-//
-  END;
-
-FUNCTION TForm13.Save:Boolean;
-  VAR
-    mem:TMemoryStream;
-    data:Tdata;
-    i:LongWord;
-  BEGIN
-    CASE MessageBox(Self.Handle,PChar('Save changes to .raw-part of file '+OniDataConnection.GetFileInfo(fileid).FileName+'?'),PChar('Data changed...'),MB_YESNOCANCEL) OF
-      IDYES: BEGIN
-          mem:=TMemoryStream.Create;
-          hex.SaveToStream(mem);
-          mem.Seek(0,soFromBeginning);
-          SetLength(data,mem.Size);
-          mem.Read(data[0],mem.Size);
-          mem.Free;
-          OniDataConnection.UpdateRawFile(fileid_opened,dat_offset_opened,Length(data),@data[0]);
-          hex.Modified:=False;
-          FOR i:=0 TO hex.Datasize-1 DO hex.ByteChanged[i]:=False;
-          Result:=True;
-        END;
-      IDNO: Result:=True;
-      IDCANCEL: BEGIN
-          Result:=False;
-        END;
-    END;
-  END;
-
-PROCEDURE TForm13.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
-  BEGIN
-    IF hex.Modified THEN BEGIN
-      IF NOT Save THEN CanClose:=False;
-    END;
-  END;
-
-PROCEDURE TForm13.FormResize(Sender: TObject);
-  BEGIN
-    IF Self.Width>=650 THEN BEGIN
-    END ELSE Self.Width:=650;
-    IF Self.Height>=450 THEN BEGIN
-    END ELSE Self.Height:=450;
-  END;
-
-PROCEDURE TForm13.panel_dataResize(Sender: TObject);
-  BEGIN
-    value_viewer.ColWidths[1]:=value_viewer.Width-value_viewer.ColWidths[0]-28;
-  END;
-
-PROCEDURE TForm13.hexChange(Sender: TObject);
-  BEGIN
-    ClearValues;
-    IF hex.DataSize>0 THEN BEGIN
-{      WriteStructureInfos(GetStructureInfoId(GetFileInfo(fileid).Extension));
-      WriteValues;
-}    END;
-  END;
-
-PROCEDURE TForm13.hexKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
-  VAR
-    temps: String;
-  BEGIN
-    IF (Shift=[ssCtrl]) AND (Key=Ord('C')) THEN BEGIN
-      IF hex.SelCount>0 THEN BEGIN
-        IF hex.InCharField THEN
-          Clipboard.AsText:=hex.SelectionAsText
-        ELSE
-          Clipboard.AsText:=hex.SelectionAsHex;
-      END;
-    END;
-    IF (Shift=[ssCtrl]) AND (Key=Ord('V')) THEN BEGIN
-{      temps:=Clipboard.AsText;
-      IF hex.SelStart+Length(temps)>hex.DataSize THEN
-        SetLength(temps, hex.DataSize-hex.SelStart);
-      hex.Sel
-      hex.SelCount:=Length(temps);
-      hex.ReplaceSelection(temps,Length(temps));
-}    END;
-  END;
-
-PROCEDURE TForm13.hexSelectionChanged(Sender: TObject);
-  VAR
-    selstart:Integer;
-    i,j:Word;
-  BEGIN
-{    FOR i:=1 TO structs.RowCount-1 DO BEGIN
-      FOR j:=0 TO structs.ColCount-1 DO BEGIN
-        structs.CellColors[j,i]:=clWhite;
-        structs.CellFontColors[j,i]:=clBlack;
-      END;
-    END;
-}    IF hex.DataSize>0 THEN BEGIN
-{      selstart:=hex.SelStart;
-      IF GetStructureInfoId(GetFileInfo(fileid).Extension)>=0 THEN BEGIN
-        WITH structure_infos[GetStructureInfoId(GetFileInfo(fileid).Extension)] DO BEGIN
-          FOR i:=0 TO High(entries) DO BEGIN
-            IF ((selstart-entries[i].offset)<GetTypeDataLength(entries[i].datatype)) AND ((selstart-entries[i].offset)>=0) THEN BEGIN
-              FOR j:=0 TO structs.ColCount-1 DO BEGIN
-                structs.CellColors[j,i+1]:=clBlue;
-                structs.CellFontColors[j,i+1]:=clWhite;
-              END;
-              structs.Row:=i+1;
-            END;
-          END;
-        END;
-      END;
-}      WriteValues;
-    END;
-  END;
-
-PROCEDURE TForm13.FormClose(Sender: TObject; var Action: TCloseAction);
-  BEGIN
-    Action:=caFree;
-  END;
-
-PROCEDURE TForm13.panel_imexportResize(Sender: TObject);
-  BEGIN
-    btn_import.Width:=panel_imexport.Width-8;
-    btn_export.Width:=panel_imexport.Width-8;
-  END;
-
-PROCEDURE TForm13.btn_exportClick(Sender: TObject);
-  VAR
-    fs:TFileStream;
-  BEGIN
-    saved.Filter:='Files of matching extension (*.'+OniDataConnection.GetFileInfo(fileid).Extension+')|*.'+OniDataConnection.GetFileInfo(fileid).Extension+'|All files|*.*';
-    saved.DefaultExt:=OniDataConnection.GetFileInfo(fileid).Extension;
-    IF saved.Execute THEN BEGIN
-      fs:=TFileStream.Create(saved.FileName,fmCreate);
-      hex.SaveToStream(fs);
-      fs.Free;
-    END;
-  END;
-
-PROCEDURE TForm13.btn_importClick(Sender: TObject);
-  VAR
-    data:Tdata;
-    fs:TFileStream;
-  BEGIN
-    opend.Filter:='Files of matching extension (*.'+OniDataConnection.GetFileInfo(fileid).Extension+')|*.'+OniDataConnection.GetFileInfo(fileid).Extension+'|All files|*.*';
-    IF opend.Execute THEN BEGIN
-      fs:=TFileStream.Create(opend.FileName,fmOpenRead);
-      IF fs.Size<>hex.DataSize THEN BEGIN
-        ShowMessage('Can''t import '+ExtractFilename(opend.FileName)+
-                    ', file has to have same size as file in .dat.'+CrLf+
-                    'Size of file in .dat: '+FormatFileSize(hex.datasize)+CrLf+
-                    'Size of chosen file: '+FormatFileSize(fs.Size));
-      END ELSE BEGIN
-        hex.LoadFromStream(fs);
-        hex.Modified:=True;
-      END;
-      fs.Free;
-    END;
-  END;
-
-PROCEDURE TForm13.value_viewer_contextPopup(Sender: TObject);
-  VAR
-    i:Byte;
-  BEGIN
-    FOR i:=0 TO value_viewer_context.Items.Count-1 DO
-      value_viewer_context.Items.Items[i].Visible:=False;
-    WITH value_viewer DO BEGIN
-      IF (Col=1) AND (Row>0) AND (Length(Cells[Col,Row])>0) THEN BEGIN
-        IF Pos(' byte',Cells[0,Row])=2 THEN BEGIN
-          value_viewer_context.Items.Find('Copy to &clipboard').Visible:=True;
-          value_viewer_context.Items.Find('Copy to clipboard (as &dec)').Visible:=True;
-          value_viewer_context.Items.Find('Copy to clipboard (as &hex)').Visible:=True;
-        END;
-        IF Pos('Float',Cells[0,Row])=1 THEN
-          value_viewer_context.Items.Find('Copy to clipboard (as &float)').Visible:=True;
-        IF Pos('Bitset',Cells[0,Row])=1 THEN
-          value_viewer_context.Items.Find('Copy to clipboard (as &bitset)').Visible:=True;
-        IF Pos('String',Cells[0,Row])=1 THEN
-          value_viewer_context.Items.Find('Copy to clipboard (as &string)').Visible:=True;
-        IF Pos('Selected length',Cells[0,Row])=1 THEN
-          value_viewer_context.Items.Find('Copy to &clipboard').Visible:=True;
-      END;
-    END;
-  END;
-
-PROCEDURE TForm13.value_viewerMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
-  VAR
-    ACol,ARow:Integer;
-  BEGIN
-    IF Button=mbRight THEN BEGIN
-      value_viewer.MouseToCell(x,y,ACol,ARow);
-      IF ARow>0 THEN BEGIN
-        value_viewer.Col:=ACol;
-        value_viewer.Row:=ARow;
-      END;
-    END;
-  END;
-
-PROCEDURE TForm13.value_viewer_context_copyClick(Sender: TObject);
-  VAR
-    i:Byte;
-    name:String;
-    value:LongWord;
-  BEGIN
-    name:=TMenuItem(Sender).Name;
-    IF Pos('asstring',name)>0 THEN BEGIN
-      Clipboard.AsText:=value_viewer.Cells[value_viewer.Col,value_viewer.Row];
-    END ELSE
-    IF Pos('asfloat',name)>0 THEN BEGIN
-      Clipboard.AsText:=value_viewer.Cells[value_viewer.Col,value_viewer.Row];
-    END ELSE
-    IF Pos('asbitset',name)>0 THEN BEGIN
-      Clipboard.AsText:=value_viewer.Cells[value_viewer.Col,value_viewer.Row];
-    END ELSE
-    IF (Pos('ashex',name)>0) OR (Pos('asdec',name)>0) THEN BEGIN
-      IF value_viewer.Cells[0,value_viewer.Row]='1 byte, unsigned' THEN BEGIN
-        IF ((hex.SelCount=1) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+1)>hex.DataSize) THEN
-          value:=hex.Data[hex.SelStart];
-      END;
-      IF value_viewer.Cells[0,value_viewer.Row]='2 bytes, unsigned' THEN BEGIN
-        IF ((hex.SelCount=2) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+2)>hex.DataSize) THEN
-          value:=hex.Data[hex.SelStart] + hex.Data[hex.SelStart+1]*256;
-      END;
-      IF value_viewer.Cells[0,value_viewer.Row]='4 bytes, unsigned' THEN BEGIN
-        IF ((hex.SelCount=4) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+4)>hex.DataSize) THEN
-          value:=hex.Data[hex.SelStart]+hex.Data[hex.SelStart+1]*256+hex.Data[hex.SelStart+2]*256*256+hex.Data[hex.SelStart+3]*256*256*256;
-      END;
-      IF Pos('asdec',name)>0 THEN BEGIN
-        Clipboard.AsText:=IntToStr(value);
-      END ELSE BEGIN
-        IF value_viewer.Cells[0,value_viewer.Row]='1 byte, unsigned' THEN
-          Clipboard.AsText:='0x'+IntToHex(value,2);
-        IF value_viewer.Cells[0,value_viewer.Row]='2 bytes, unsigned' THEN
-          Clipboard.AsText:='0x'+IntToHex(value,4);
-        IF value_viewer.Cells[0,value_viewer.Row]='4 bytes, unsigned' THEN
-          Clipboard.AsText:='0x'+IntToHex(value,8);
-      END;
-    END ELSE BEGIN
-      Clipboard.AsText:=value_viewer.Cells[value_viewer.Col,value_viewer.Row];
-    END;
-  END;
-
-PROCEDURE TForm13.SetNewValue(datatype:Word; offset:LongWord; value:String);
-  VAR
-    data:Tdata;
-    value_int:LongWord;
-    value_float:Single;
-    i:Word;
-  BEGIN
-    CASE datatype OF
-      1..4: BEGIN
-              value_int:=StrToInt(value);
-              SetLength(data,datatype);
-              FOR i:=0 TO datatype-1 DO BEGIN
-                data[i]:=value_int MOD 256;
-                value_int:=value_int DIV 256;
-              END;
-            END;
-      5..8: BEGIN
-              value_int:=StrToInt('$'+value);
-              SetLength(data,datatype-4);
-              FOR i:=0 TO datatype-5 DO BEGIN
-                data[i]:=value_int MOD 256;
-                value_int:=value_int DIV 256;
-              END;
-            END;
-      9:    BEGIN
-              value_float:=StrToFloat(value);
-              data:=Encode_Float(value_float);
-            END;
-      10:   BEGIN
-              value_int:=BinToInt(value);
-              SetLength(data,1);
-              data[0]:=value_int;
-            END;
-      10000..65535: BEGIN
-              SetLength(data,datatype-10000);
-              FOR i:=1 TO datatype-10000 DO BEGIN
-                IF i<=Length(value) THEN
-                  data[i-1]:=Ord(value[i])
-                ELSE
-                  data[i-1]:=0;
-              END;
-            END;
-    END;
-    FOR i:=0 TO High(data) DO BEGIN
-      IF hex.Data[offset+i]<>data[i] THEN hex.ByteChanged[offset+i]:=True;
-      hex.Data[offset+i]:=data[i];
-    END;
-    hex.Modified:=True;
-    hexChange(Self);
-    hex.Repaint;
-  END;
-
-PROCEDURE TForm13.value_viewerDblClick(Sender: TObject);
-  VAR
-    offset:LongWord;
-    datatype:Word;
-    objectname:String;
-    value:String;
-  BEGIN
-    IF (value_viewer.Col=1) AND (Length(value_viewer.Cells[1,value_viewer.Row])>0) THEN BEGIN
-      offset:=hex.SelStart;
-      IF value_viewer.Cells[0,value_viewer.Row]='1 byte, unsigned' THEN
-        datatype:=1;
-      IF value_viewer.Cells[0,value_viewer.Row]='2 bytes, unsigned' THEN
-        datatype:=2;
-      IF value_viewer.Cells[0,value_viewer.Row]='4 bytes, unsigned' THEN
-        datatype:=4;
-      IF value_viewer.Cells[0,value_viewer.Row]='Bitset' THEN
-        datatype:=10;
-      IF value_viewer.Cells[0,value_viewer.Row]='Float' THEN
-        datatype:=9;
-      IF value_viewer.Cells[0,value_viewer.Row]='Selected length' THEN
-        Exit;
-      IF value_viewer.Cells[0,value_viewer.Row]='String' THEN BEGIN
-        IF hex.SelCount>0 THEN
-          datatype:=10000+hex.SelCount
-        ELSE
-          datatype:=10000+Length(value_viewer.Cells[1,value_viewer.Row]);
-      END;
-      objectname:='';
-      value:=GetValue(datatype,offset);
-      Form12.MakeVarInput(objectname,offset,datatype,value,Self);
-    END;
-  END;
-
-PROCEDURE TForm13.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
-  BEGIN
-    IF (Shift=[ssCtrl]) AND (Key=83) THEN
-      IF hex.Modified THEN
-        IF NOT Save THEN
-          Exit;
-  END;
-
-END.
Index: oup/current/Unit14_settings.dfm
===================================================================
--- oup/current/Unit14_settings.dfm	(revision 40)
+++ 	(revision )
@@ -1,113 +1,0 @@
-object Form14: TForm14
-  Left = 0
-  Top = 0
-  BorderStyle = bsToolWindow
-  Caption = 'Settings'
-  ClientHeight = 357
-  ClientWidth = 321
-  Color = clBtnFace
-  Font.Charset = DEFAULT_CHARSET
-  Font.Color = clWindowText
-  Font.Height = -11
-  Font.Name = 'Tahoma'
-  Font.Style = []
-  OldCreateOrder = False
-  Position = poMainFormCenter
-  OnCloseQuery = FormCloseQuery
-  OnShow = FormShow
-  PixelsPerInch = 96
-  TextHeight = 13
-  object label_charset: TLabel
-    Left = 8
-    Top = 39
-    Width = 145
-    Height = 26
-    AutoSize = False
-    Caption = 'CharSet for displaying strings in ValueViewer/StructViewer:'
-    WordWrap = True
-  end
-  object check_filesashex: TCheckBox
-    Left = 8
-    Top = 8
-    Width = 145
-    Height = 17
-    Caption = 'Show filenumbers as Hex'
-    TabOrder = 0
-  end
-  object btn_ok: TButton
-    Left = 8
-    Top = 319
-    Width = 57
-    Height = 23
-    Caption = 'OK'
-    Default = True
-    TabOrder = 1
-    OnClick = btn_okClick
-  end
-  object btn_cancel: TButton
-    Left = 120
-    Top = 319
-    Width = 57
-    Height = 23
-    Cancel = True
-    Caption = 'Cancel'
-    TabOrder = 2
-    OnClick = btn_cancelClick
-  end
-  object btn_register_oldb: TButton
-    Left = 8
-    Top = 184
-    Width = 169
-    Height = 25
-    Caption = 'Register .oldb files with OUP'
-    TabOrder = 3
-    OnClick = btn_register_oldbClick
-  end
-  object btn_register_opf: TButton
-    Left = 8
-    Top = 215
-    Width = 169
-    Height = 25
-    Caption = 'Register .opf files with OUP'
-    TabOrder = 4
-    OnClick = btn_register_opfClick
-  end
-  object btn_register_dat: TButton
-    Left = 8
-    Top = 153
-    Width = 169
-    Height = 25
-    Caption = 'Register .dat files with OUP'
-    TabOrder = 5
-    OnClick = btn_register_datClick
-  end
-  object combo_charset: TComboBox
-    Left = 160
-    Top = 40
-    Width = 156
-    Height = 21
-    Style = csDropDownList
-    ItemHeight = 13
-    ItemIndex = 0
-    TabOrder = 6
-    Text = 'default - 1'
-    Items.Strings = (
-      'default - 1'
-      'Arabic - 178'
-      'Baltic - 186'
-      'ChineseBig5 - 136'
-      'EastEurope - 238'
-      'Greek - 161'
-      'Russian - 204'
-      'Thai - 222'
-      'Turkish - 162')
-  end
-  object check_hideunused: TCheckBox
-    Left = 8
-    Top = 79
-    Width = 209
-    Height = 17
-    Caption = 'Hide "Unused" data in StructureViewer'
-    TabOrder = 7
-  end
-end
Index: oup/current/Unit14_settings.pas
===================================================================
--- oup/current/Unit14_settings.pas	(revision 40)
+++ 	(revision )
@@ -1,167 +1,0 @@
-unit Unit14_settings;
-interface
-uses
-  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
-  Dialogs, StdCtrls, StrUtils, Grids, Wrapgrid;
-
-type
-  TForm14 = class(TForm)
-    check_filesashex: TCheckBox;
-    btn_ok: TButton;
-    btn_cancel: TButton;
-    btn_register_oldb: TButton;
-    btn_register_opf: TButton;
-    btn_register_dat: TButton;
-    label_charset: TLabel;
-    combo_charset: TComboBox;
-    check_hideunused: TCheckBox;
-    procedure btn_register_opfClick(Sender: TObject);
-    procedure btn_register_oldbClick(Sender: TObject);
-    procedure btn_register_datClick(Sender: TObject);
-    procedure btn_cancelClick(Sender: TObject);
-    procedure btn_okClick(Sender: TObject);
-    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
-    procedure FormShow(Sender: TObject);
-    function RegisterExtension(ext:String):Integer;
-  private
-  public
-  end;
-
-var
-  Form14: TForm14;
-
-implementation
-{$R *.dfm}
-uses
-  Unit1_main, Unit3_data, ftypesAPI;
-
-function ExtensionRegistered(ext:String; var RegisteredAs:String):Boolean;
-  var
-    ftr:TFileTypeRegistration;
-  begin
-    ftr:=TFileTypeRegistration.Create;
-    if(ftr <> nil) then begin
-      try
-        RegisteredAs:=ftr.GetInternalKey(ext);
-        if RegisteredAs<>'' then
-          Result:=True
-        else
-          Result:=False;
-      finally
-        ftr.Free;
-      end;
-    end;
-  end;
-
-function TForm14.RegisterExtension(ext:String):Integer;
-  var
-    ftr:TFileTypeRegistration;
-    temps:String;
-    warnmsg:String;
-  begin
-    Result:=-1;
-    if ExtensionRegistered(ext,temps) then begin
-      if temps<>'ONI'+ext then begin
-        warnmsg:=ext+'-files are not registered to OUP but as "'+temps+'"-files.'+#13+#10+
-                 'Do you really want to unregister'+ext+'-files?';
-        if MessageBox(Self.Handle, PChar(warnmsg),PChar('Warning'),MB_YESNO)=ID_NO then
-          Exit;
-      end;
-      ftr:=TFileTypeRegistration.Create;
-      if ftr<>nil then
-        try
-          if not ftr.UnregisterExtension(ext) then
-            ShowMessage('Could not unregister '+ext+'-files')
-          else
-            Result:=2;
-        finally
-          ftr.Free;
-        end;
-    end else begin
-      ftr:=TFileTypeRegistration.Create;
-      if ftr<>nil then begin
-        try
-          if ftr.RegisterType(ext,'ONI'+ext,'ONI '+ext+'-file',Application.EXEname+',1') then begin
-            ftr.AddHandler('open','"'+Application.EXEname+'" '+MidStr(ext,2,Length(ext)-1)+' "%1"');
-            ftr.SetDefaultHandler;
-            Result:=1;
-          end;
-        finally
-          ftr.Free;
-        end;
-      end;
-    end;
-  end;
-
-procedure TForm14.btn_cancelClick(Sender: TObject);
-  begin
-    Self.Close;
-  end;
-
-procedure TForm14.btn_okClick(Sender: TObject);
-  begin
-    AppSettings.FilenumbersAsHex:=check_filesashex.Checked;
-    AppSettings.CharSet:=StrToInt(MidStr(combo_charset.Items.Strings[combo_charset.ItemIndex],Pos(' ',combo_charset.Items.Strings[combo_charset.ItemIndex])+3,Length(combo_charset.Items.Strings[combo_charset.ItemIndex])-Pos(' ',combo_charset.Items.Strings[combo_charset.ItemIndex])-2));
-    AppSettings.HideUnusedData:=check_hideunused.Checked;
-
-    Self.Close;
-  end;
-
-procedure TForm14.btn_register_datClick(Sender: TObject);
-  begin
-    case RegisterExtension('.dat') of
-      2: btn_register_dat.Caption:='Register .dat files with OUP';
-      1: btn_register_dat.Caption:='Unregister .dat files';
-    end;
-  end;
-
-procedure TForm14.btn_register_oldbClick(Sender: TObject);
-  begin
-    case RegisterExtension('.oldb') of
-      2: btn_register_oldb.Caption:='Register .oldb files with OUP';
-      1: btn_register_oldb.Caption:='Unregister .oldb files';
-    end;
-  end;
-
-procedure TForm14.btn_register_opfClick(Sender: TObject);
-  begin
-    case RegisterExtension('.opf') of
-      2: btn_register_opf.Caption:='Register .opf files with OUP';
-      1: btn_register_opf.Caption:='Unregister .opf files';
-    end;
-  end;
-
-procedure TForm14.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
-  begin
-    CanClose:=False;
-    Self.Visible:=False;
-    Form1.Enabled:=True;
-    Form1.SetFocus;
-  end;
-
-procedure TForm14.FormShow(Sender: TObject);
-  var
-    temps:String;
-    i:Byte;
-  begin
-    if ExtensionRegistered('.dat',temps) then
-      btn_register_dat.Caption:='Unregister .dat files'
-    else
-      btn_register_dat.Caption:='Register .dat files with OUP';
-    if ExtensionRegistered('.oldb',temps) then
-      btn_register_oldb.Caption:='Unregister .oldb files'
-    else
-      btn_register_oldb.Caption:='Register .oldb files with OUP';
-    if ExtensionRegistered('.opf',temps) then
-      btn_register_opf.Caption:='Unregister .opf files'
-    else
-      btn_register_opf.Caption:='Register .opf files with OUP';
-    check_filesashex.Checked:=AppSettings.FilenumbersAsHex;
-    check_hideunused.Checked:=AppSettings.HideUnusedData;
-
-    for i:=0 to combo_charset.Items.Count-1 do
-      if StrToInt(MidStr(combo_charset.Items.Strings[i],Pos(' ',combo_charset.Items.Strings[i])+3,Length(combo_charset.Items.Strings[i])-Pos(' ',combo_charset.Items.Strings[i])-2))=AppSettings.CharSet then
-        combo_charset.ItemIndex:=i;
-  end;
-
-end.
Index: oup/current/Unit15_Classes.pas
===================================================================
--- oup/current/Unit15_Classes.pas	(revision 40)
+++ 	(revision )
@@ -1,1058 +1,0 @@
-unit Unit15_Classes;
-interface
-uses Unit3_data, Unit9_data_structures, Classes, SysUtils, StrUtils, Dialogs, ABSDecUtil, ABSMain, DB;
-
-
-type
-  TOniData = class
-    private
-      FFileName:String;
-      FLevelInfo:TLevelInfo;
-      FBackend:Integer;
-      Fos_mac:Boolean;
-    protected
-    public
-      property FileName:String read FFileName write FFileName;
-      property Backend:Integer read FBackend write FBackend;
-      property OSisMac:Boolean read Fos_mac write Fos_mac;
-      property LevelInfo:TLevelinfo read FLevelInfo write FLevelInfo;
-
-      constructor Create(filename:String; var Result:Boolean); virtual; abstract;
-      procedure Close; virtual; abstract;
-
-      function GetFileInfo(fileid:LongWord):TFileInfo; virtual; abstract;
-      function GetFilesList(ext:String; pattern:String; NoEmptyFiles:Boolean):TStringArray; virtual; abstract;
-      function GetFilesCount:LongWord; virtual; abstract;
-      function GetExtensionsList:TStringArray; virtual; abstract;
-      function GetExtendedExtensionsList:TExtensionsMap; virtual; abstract;
-      function ExtractFileID(name:String):Integer;
-      function GetFileIDByName(name:String):Integer;
-
-      function LoadDatFile(fileid:LongWord):Tdata; virtual; abstract;
-      procedure UpdateDatFile(fileid:LongWord; data:Tdata); virtual; abstract;
-      procedure LoadDatFilePart(fileid,offset,size:LongWord; target:Pointer); virtual; abstract;
-      procedure UpdateDatFilePart(fileid,offset,size:LongWord; target:Pointer); virtual; abstract;
-
-      function GetRawList(fileid:LongWord):TRawList; virtual; abstract;
-      function GetRawInfo(fileid,dat_offset:LongWord):TRawInfo;
-      procedure LoadRawFile(fileid,dat_offset:LongWord; target:Pointer); virtual; abstract;
-      procedure UpdateRawFile(fileid,dat_offset:LongWord; size:LongWord; target:Pointer); virtual; abstract;
-      procedure LoadRawFilePart(fileid,dat_offset:LongWord; offset,size:LongWord; target:Pointer); virtual; abstract;
-      procedure UpdateRawFilePart(fileid,dat_offset:LongWord; offset,size:LongWord; target:Pointer); virtual; abstract;
-      function AppendRawFile(loc_sep:Boolean; size:LongWord; target:Pointer):LongWord; virtual; abstract;//Returns new Address
-    published
-  end;
-
-  TOniDataDat = class(TOniData)
-    private
-      Fdat_file:TFileStream;
-      Fraw_file:TFileStream;
-      Fsep_file:TFileStream;
-      Fdat_header:THeader;
-      Fdat_filesmap:TFilesMap;
-      Fdat_files:TFiles;
-      Fdat_namedfilesmap:TNamedFilesMap;
-      Fdat_extensionsmap:TExtensionsMap;
-      FUnloadWhenUnused:Boolean;
-      FDatOpened:Boolean;
-      FRawOpened:Boolean;
-      FSepOpened:Boolean;
-    protected
-    public
-      property UnloadWhenUnused:Boolean read FUnloadWhenUnused write FUnloadWhenUnused;
-
-      constructor Create(DatFilename:String; var Result:Boolean); override;
-      procedure Close; override;
-
-      function GetFileInfo(fileid:LongWord):TFileInfo; override;
-      function GetFilesList(ext:String; pattern:String; NoEmptyFiles:Boolean):TStringArray; override;
-      function GetFilesCount:LongWord; override;
-      function GetExtensionsList:TStringArray; override;
-      function GetExtendedExtensionsList:TExtensionsMap; override;
-
-      function LoadDatFile(fileid:LongWord):Tdata; override;
-      procedure UpdateDatFile(fileid:LongWord; data:Tdata); override;
-      procedure LoadDatFilePart(fileid,offset,size:LongWord; target:Pointer); override;
-      procedure UpdateDatFilePart(fileid,offset,size:LongWord; target:Pointer); override;
-
-      procedure LoadRawOffset(loc_sep:Boolean; raw_addr,size:LongWord; target:Pointer);
-      function GetRawList(fileid:LongWord):TRawList; override;
-      procedure LoadRawFile(fileid,dat_offset:LongWord; target:Pointer); override;
-      procedure UpdateRawFile(fileid,dat_offset:LongWord; size:LongWord; target:Pointer); override;
-      procedure LoadRawFilePart(fileid,dat_offset:LongWord; offset,size:LongWord; target:Pointer); override;
-      procedure UpdateRawFilePart(fileid,dat_offset:LongWord; offset,size:LongWord; target:Pointer); override;
-      function AppendRawFile(loc_sep:Boolean; size:LongWord; target:Pointer):LongWord; override;//Returns new Address
-    published
-  end;
-
-  TOniDataADB = class(TOniData)
-    private
-      FDatabase:TABSDatabase;
-      FQuery:TABSQuery;
-    protected
-    public
-      constructor Create(OLDBFilename:String; var Result:Boolean); override;
-      procedure Close; override;
-
-//      function GetDatLinks(srcid:LongWord):TDatLinks;
-      function GetFileInfo(fileid:LongWord):TFileInfo; override;
-      function GetFilesList(ext:String; pattern:String; NoEmptyFiles:Boolean):TStringArray; override;
-      function GetFilesCount:LongWord; override;
-      function GetExtensionsList:TStringArray; override;
-      function GetExtendedExtensionsList:TExtensionsMap; override;
-      function GetNamedFilesMap:TNamedFilesMap;
-
-      function LoadDatFile(fileid:LongWord):Tdata; override;
-      procedure UpdateDatFile(fileid:LongWord; data:Tdata); override;
-      procedure LoadDatFilePart(fileid,offset,size:LongWord; target:Pointer); override;
-      procedure UpdateDatFilePart(fileid,offset,size:LongWord; target:Pointer); override;
-
-      function GetRawList(fileid:LongWord):TRawList; override;
-      procedure LoadRawFile(fileid,dat_offset:LongWord; target:Pointer); override;
-      procedure UpdateRawFile(fileid,dat_offset:LongWord; size:LongWord; target:Pointer); override;
-      procedure LoadRawFilePart(fileid,dat_offset:LongWord; offset,size:LongWord; target:Pointer); override;
-      procedure UpdateRawFilePart(fileid,dat_offset:LongWord; offset,size:LongWord; target:Pointer); override;
-    published
-  end;
-
-
-const
-  ODB_None=-1;
-  ODB_Dat=0;
-  ODB_ADB=1;
-
-var
-  OniDataConnection:TOniData;
-
-function CreateDataConnection(filename:String; backend:Integer):Boolean;
-procedure CloseDataConnection;
-
-
-
-
-implementation
-uses Unit2_Functions;
-
-
-
-(*
-  Implementation of  TOniData
-*)
-
-function TOniData.GetFileIDByName(name:String):Integer;
-  var
-    files:TStringArray;
-    i: Integer;
-  begin
-    Result:=-1;
-    files:=Self.GetFilesList('',name,false);
-    if Length(files)>0 then
-      for i:=0 to High(files) do
-        if Pos(name,files[i])=Pos('-',files[i])+1 then begin
-//        if MidStr(files[i],Pos('-',files[i])+1,Length(files[i])-Pos('-',files[i])-5)=name then begin
-          Result:=Self.ExtractFileID(files[i]);
-          Break;
-        end;
-  end;
-
-function TOniData.ExtractFileID(name:String):Integer;
-  begin
-    if name[5]='-' then
-      Result:=HexToLong(MidStr(name,1,4))
-    else
-      Result:=StrToInt(MidStr(name,1,5));
-  end;
-
-function TOniData.GetRawInfo(fileid,dat_offset:LongWord):TRawInfo;
-  var
-    i:LongWord;
-    raw_list:TRawList;
-  begin
-    raw_list:=Self.GetRawList(fileid);
-    Result.src_id:=0;
-    Result.src_offset:=0;
-    Result.raw_addr:=0;
-    Result.raw_size:=0;
-    for i:=0 to High(raw_list) do begin
-      if raw_list[i].src_offset=dat_offset then begin
-        Result.src_id:=fileid;
-        Result.src_offset:=raw_list[i].src_offset;
-        Result.raw_addr:=raw_list[i].raw_addr;
-        Result.raw_size:=raw_list[i].raw_size;
-        Result.loc_sep:=raw_list[i].loc_sep;
-        Break;
-      end;
-    end;
-  end;
-
-
-
-
-
-
-
-(*
-================================================================================
-                      Implementation of  TOniDataDat
-*)
-
-constructor TOniDataDat.Create(DatFilename:String; var Result:Boolean);
-  const
-    header_ident1_pc:Array[0..$13] of Byte=
-        ($1F,$27,$DC, $33,  $DF,$BC,$03,$00,$31,$33,$52,$56,$40,$00,$14,$00,$10,$00,$08,$00);
-    header_ident1_mac:Array[0..$13] of Byte=
-        ($61,$30,$C1, $23,  $DF,$BC,$03,$00,$31,$33,$52,$56,$40,$00,$14,$00,$10,$00,$08,$00);
-    header_ident1_macbeta:Array[0..$13] of Byte=
-        ($81,$11,$8D, $23,  $DF,$BC,$03,$00,$31,$33,$52,$56,$40,$00,$14,$00,$10,$00,$08,$00);
-    header_ident2:Array[0..$F] of Byte=
-        ($99,$CF,$40,$00,$90,$4F,$63,$00,$F4,$55,$5F,$00,$90,$4F,$63,$00);
-  var
-    i:LongWord;
-    header_pc,header_mac:Boolean;
-  begin
-    FUnloadWhenUnused:=True;
-    FDatOpened:=False;
-    FRawOpened:=False;
-    if not FileExists(DatFilename) then begin
-      ShowMessage('File doesn''t exist!!!');
-      Result:=False;
-      Exit;
-    end;
-    FFileName:=DatFilename;
-    Fdat_file:=TFileStream.Create(FFileName, fmOpenRead);
-    Fdat_file.Read(Fdat_header,SizeOf(Fdat_header));
-    header_pc:=True;
-    header_mac:=True;
-    for i:=0 to High(Fdat_header.Ident) do begin
-      FLevelInfo.Ident[i]:=Fdat_header.Ident[i];
-      if Fdat_header.Ident[i]<>header_ident1_pc[i] then
-        header_pc:=False;
-      if Fdat_header.Ident[i]<>header_ident1_mac[i] then
-        header_mac:=False;
-    end;
-    if not (header_pc xor header_mac) then begin
-      Result:=False;
-      Exit;
-    end else begin
-      if (header_pc and not header_mac) then
-        Fos_mac:=False
-      else
-        Fos_mac:=True;
-    end;
-    SetLength(Fdat_filesmap,Fdat_header.Files);
-    SetLength(Fdat_files,Fdat_header.Files);
-    for i:=0 to Fdat_header.Files-1 do
-      Fdat_file.Read(Fdat_filesmap[i],SizeOf(Fdat_filesmap[i]));
-    for i:=0 to Fdat_header.Files-1 do begin
-      Fdat_files[i].Extension:=Fdat_filesmap[i].Extension;
-      Fdat_files[i].Extension:=ReverseString(Fdat_files[i].Extension);
-      Fdat_files[i].Size:=Fdat_filesmap[i].FileSize;
-      Fdat_files[i].FileType:=Fdat_filesmap[i].FileType;
-      Fdat_files[i].DatAddr:=Fdat_filesmap[i].DataAddr-8+Fdat_header.DataAddr;
-      if (Fdat_filesmap[i].FileType and $01)=0 then begin
-        Fdat_file.Seek(Fdat_filesmap[i].NameAddr+Fdat_header.NamesAddr,soFromBeginning);
-        SetLength(Fdat_files[i].Name,100);
-        Fdat_file.Read(Fdat_files[i].Name[1],100);
-        Fdat_files[i].Name:=MidStr(Fdat_files[i].Name,1+4,Pos(#0,Fdat_files[i].Name)-1-4);
-      end else begin
-        Fdat_files[i].Name:='';
-      end;
-      Fdat_files[i].FileName:=FormatNumber(i,5,'0')+'-'+Fdat_files[i].Name+'.'+Fdat_files[i].Extension;
-      Fdat_files[i].FileNameHex:=IntToHex(i,4)+'-'+Fdat_files[i].Name+'.'+Fdat_files[i].Extension;
-    end;
-    Fdat_file.Seek($40+Fdat_header.Files*$14,soFromBeginning);
-    SetLength(Fdat_namedfilesmap,Fdat_header.NamedFiles);
-    for i:=0 to Fdat_header.NamedFiles-1 do
-      Fdat_file.Read(Fdat_namedfilesmap[i],SizeOf(Fdat_namedfilesmap[i]));
-
-    Fdat_file.Seek($40+Fdat_header.Files*$14+Fdat_header.NamedFiles*$8,soFromBeginning);
-    SetLength(Fdat_extensionsmap,Fdat_header.Extensions);
-    for i:=0 to Fdat_header.Extensions-1 do
-      Fdat_file.Read(Fdat_extensionsmap[i],SizeOf(Fdat_extensionsmap[i]));
-
-    Fdat_file.Seek(Fdat_files[0].DatAddr+7,soFromBeginning);
-    Fdat_file.Read(FLevelInfo.LevelNumber,1);
-    FLevelInfo.LevelNumber:=FLevelInfo.LevelNumber DIV 2;
-
-    Fdat_file.Free;
-
-    Result:=True;
-    FBackend:=ODB_Dat;
-  end;
-
-procedure TOniDataDat.Close;
-  begin
-    if not FUnloadWhenUnused and FDatOpened then
-      Fdat_file.Free;
-    if not FUnloadWhenUnused and FRawOpened then
-      Fraw_file.Free;
-    if not FUnloadWhenUnused and FSepOpened then
-      Fsep_file.Free;
-    Self.Free;
-  end;
-
-
-
-function TOniDataDat.GetFileInfo(fileid:LongWord):TFileInfo;
-  begin
-    if fileid<Self.GetFilesCount then
-      Result:=Fdat_files[fileid]
-    else
-      Result.ID:=-1;
-  end;
-
-function TOniDataDat.GetFilesList(ext:String; pattern:String; NoEmptyFiles:Boolean):TStringArray;
-  var
-    i:LongWord;
-  begin
-    SetLength(Result,0);
-    for i:=0 to Fdat_header.Files-1 do begin
-      if ( (Length(ext)=0) or (Pos(Fdat_files[i].Extension,ext)>0) ) and
-          ( (Length(pattern)=0) or (Pos(UpperCase(pattern),UpperCase(Fdat_files[i].Name))>0) ) then begin
-          if (NoEmptyFiles=false) or ((Fdat_files[i].FileType and $02)=0) then begin
-            SetLength(Result,Length(Result)+1);
-            if AppSettings.FilenumbersAsHex then
-              Result[High(Result)]:=Fdat_files[i].FileNameHex
-            else
-              Result[High(Result)]:=Fdat_files[i].FileName;
-          end;
-      end;
-    end;
-  end;
-
-function TOniDataDat.GetFilesCount:LongWord;
-  begin
-    Result:=Fdat_header.Files;
-  end;
-
-function TOniDataDat.GetExtensionsList:TStringArray;
-  var
-    i:LongWord;
-  begin
-    SetLength(Result,Fdat_header.Extensions);
-    for i:=0 to Fdat_header.Extensions-1 do begin
-      with Fdat_extensionsmap[i] do begin
-        Result[i]:=Extension[3]+Extension[2]+Extension[1]+Extension[0]+' ('+IntToStr(ExtCount)+')';
-      end;
-    end;
-  end;
-
-function TOniDataDat.GetExtendedExtensionsList:TExtensionsMap;
-  var
-    i:LongWord;
-  begin
-    SetLength(Result,Fdat_header.Extensions);
-    for i:=0 to Fdat_header.Extensions-1 do begin
-      Result[i]:=Fdat_extensionsmap[i];
-    end;
-  end;
-
-
-function TOniDataDat.LoadDatFile(fileid:LongWord):Tdata;
-  begin
-    if fileid<Self.GetFilesCount then begin
-      if FUnloadWhenUnused or not FDatOpened then
-        Fdat_file:=TFileStream.Create(FFileName, fmOpenReadWrite);
-      Fdat_file.Seek(Fdat_files[fileid].DatAddr,soFromBeginning);
-      SetLength(Result,Fdat_files[fileid].Size);
-      Fdat_file.Read(Result[0],Fdat_files[fileid].Size);
-      if UnloadWhenUnused then
-        Fdat_file.Free
-      else
-        FDatOpened:=True;
-    end;
-  end;
-
-procedure TOniDataDat.UpdateDatFile(fileid:LongWord; data:Tdata);
-  begin
-    if fileid<Self.GetFilesCount then begin
-      if FUnloadWhenUnused or not FDatOpened then
-        Fdat_file:=TFileStream.Create(FFileName, fmOpenReadWrite);
-      Fdat_file.Seek(Fdat_files[fileid].DatAddr,soFromBeginning);
-      Fdat_file.Write(data[0],Length(data));
-      if UnloadWhenUnused then
-        Fdat_file.Free
-      else
-        FDatOpened:=True;
-    end;
-  end;
-
-procedure TOniDataDat.LoadDatFilePart(fileid,offset,size:LongWord; target:Pointer);
-  begin
-    if fileid<Self.GetFilesCount then begin
-      if FUnloadWhenUnused or not FDatOpened then
-        Fdat_file:=TFileStream.Create(FFileName, fmOpenReadWrite);
-      Fdat_file.Seek(Fdat_files[fileid].DatAddr+offset,soFromBeginning);
-      Fdat_file.Read(target^,size);
-      if UnloadWhenUnused then
-        Fdat_file.Free
-      else
-        FDatOpened:=True;
-    end;
-  end;
-
-procedure TOniDataDat.UpdateDatFilePart(fileid,offset,size:LongWord; target:Pointer);
-  begin
-    if fileid<Self.GetFilesCount then begin
-      if FUnloadWhenUnused or not FDatOpened then
-        Fdat_file:=TFileStream.Create(FFileName, fmOpenReadWrite);
-      Fdat_file.Seek(Fdat_files[fileid].DatAddr+offset,soFromBeginning);
-      Fdat_file.Write(target^,size);
-      if UnloadWhenUnused then
-        Fdat_file.Free
-      else
-        FDatOpened:=True;
-    end;
-  end;
-
-
-
-function TOniDataDat.GetRawList(fileid:LongWord):TRawList;
-  var
-    i:LongWord;
-  begin
-    SetLength(Result,0);
-    for i:=0 to High(RawListHandlers) do
-      if UpperCase(RawListHandlers[i].Ext)=UpperCase(Fdat_files[fileid].extension) then
-        if RawListHandlers[i].needed then begin
-          Result:=RawListHandlers[i].Handler(fileid);
-          Break;
-        end else
-          Break;
-  end;
-
-procedure TOniDataDat.LoadRawOffset(loc_sep:Boolean; raw_addr,size:LongWord; target:Pointer);
-  begin
-    if not loc_sep then begin
-      if FUnloadWhenUnused or not FRawOpened then
-        Fraw_file:=TFileStream.Create(AnsiReplaceStr(FFileName,'.dat','.raw'),fmOpenReadWrite);
-      if raw_addr<=Fraw_file.Size then begin
-        Fraw_file.Seek(raw_addr,soFromBeginning);
-        Fraw_file.Read(target^,size);
-      end;
-      if UnloadWhenUnused then
-        Fraw_file.Free
-      else
-        FRawOpened:=True
-    end else begin
-      if FUnloadWhenUnused or not FSepOpened then
-        Fsep_file:=TFileStream.Create(AnsiReplaceStr(FFileName,'.dat','.sep'),fmOpenReadWrite);
-      if raw_addr<=Fsep_file.Size then begin
-        Fsep_file.Seek(raw_addr,soFromBeginning);
-        Fsep_file.Read(target^,size);
-      end;
-      if UnloadWhenUnused then
-        Fsep_file.Free
-      else
-        FSepOpened:=True;
-    end;
-  end;
-
-procedure TOniDataDat.LoadRawFile(fileid,dat_offset:LongWord; target:Pointer);
-  var
-    raw_info:TRawInfo;
-  begin
-    if fileid<Self.GetFilesCount then begin
-      raw_info:=Self.GetRawInfo(fileid,dat_offset);
-      if not raw_info.loc_sep then begin
-        if FUnloadWhenUnused or not FRawOpened then
-          Fraw_file:=TFileStream.Create(AnsiReplaceStr(FFileName,'.dat','.raw'),fmOpenReadWrite);
-        Fraw_file.Seek(raw_info.raw_addr,soFromBeginning);
-        Fraw_file.Read(target^,raw_info.raw_size);
-        if UnloadWhenUnused then
-          Fraw_file.Free
-        else
-          FRawOpened:=True
-      end else begin
-        if FUnloadWhenUnused or not FSepOpened then
-          Fsep_file:=TFileStream.Create(AnsiReplaceStr(FFileName,'.dat','.sep'),fmOpenReadWrite);
-        Fsep_file.Seek(raw_info.raw_addr,soFromBeginning);
-        Fsep_file.Read(target^,raw_info.raw_size);
-        if UnloadWhenUnused then
-          Fsep_file.Free
-        else
-          FSepOpened:=True;
-      end;
-    end;
-  end;
-
-procedure TOniDataDat.UpdateRawFile(fileid,dat_offset:LongWord; size:LongWord; target:Pointer);
-  var
-    raw_info:TRawInfo;
-  begin
-    if fileid<Self.GetFilesCount then begin
-      raw_info:=Self.GetRawInfo(fileid,dat_offset);
-      if not raw_info.loc_sep then begin
-        if FUnloadWhenUnused or not FRawOpened then
-          Fraw_file:=TFileStream.Create(AnsiReplaceStr(FFileName,'.dat','.raw'),fmOpenReadWrite);
-        Fraw_file.Seek(raw_info.raw_addr,soFromBeginning);
-        Fraw_file.Write(target^,raw_info.raw_size);
-        if UnloadWhenUnused then
-          Fraw_file.Free
-        else
-          FRawOpened:=True
-      end else begin
-        if FUnloadWhenUnused or not FSepOpened then
-          Fsep_file:=TFileStream.Create(AnsiReplaceStr(FFileName,'.dat','.sep'),fmOpenReadWrite);
-        Fsep_file.Seek(raw_info.raw_addr,soFromBeginning);
-        Fsep_file.Write(target^,raw_info.raw_size);
-        if UnloadWhenUnused then
-          Fsep_file.Free
-        else
-          FSepOpened:=True;
-      end;
-    end;
-  end;
-
-procedure TOniDataDat.LoadRawFilePart(fileid,dat_offset:LongWord; offset,size:LongWord; target:Pointer);
-  var
-    raw_info:TRawInfo;
-    data:Tdata;
-    mem:TMemoryStream;
-  begin
-    if fileid<Self.GetFilesCount then begin
-      raw_info:=Self.GetRawInfo(fileid,dat_offset);
-      SetLength(data, raw_info.raw_size);
-      Self.LoadRawFile(fileid,dat_offset,@data[0]);
-      mem:=TMemoryStream.Create;
-      mem.Write(data[offset],size);
-      mem.Read(target^,size);
-      mem.Free;
-    end;
-  end;
-
-procedure TOniDataDat.UpdateRawFilePart(fileid,dat_offset:LongWord; offset,size:LongWord; target:Pointer);
-  var
-    raw_info:TRawInfo;
-  begin
-    if fileid<Self.GetFilesCount then begin
-      raw_info:=Self.GetRawInfo(fileid,dat_offset);
-      if not raw_info.loc_sep then begin
-        if FUnloadWhenUnused or not FRawOpened then
-          Fraw_file:=TFileStream.Create(AnsiReplaceStr(FFileName,'.dat','.raw'),fmOpenReadWrite);
-        Fraw_file.Seek(raw_info.raw_addr+offset,soFromBeginning);
-        Fraw_file.Write(target^,raw_info.raw_size);
-        if UnloadWhenUnused then
-          Fraw_file.Free
-        else
-          FRawOpened:=True
-      end else begin
-        if FUnloadWhenUnused or not FSepOpened then
-          Fsep_file:=TFileStream.Create(AnsiReplaceStr(FFileName,'.dat','.sep'),fmOpenReadWrite);
-        Fsep_file.Seek(raw_info.raw_addr+offset,soFromBeginning);
-        Fsep_file.Write(target^,raw_info.raw_size);
-        if UnloadWhenUnused then
-          Fsep_file.Free
-        else
-          FSepOpened:=True;
-      end;
-    end;
-  end;
-
-function TOniDataDat.AppendRawFile(loc_sep:Boolean; size:LongWord; target:Pointer):LongWord; //Returns new Address
-  begin
-    if not loc_sep then begin
-      if FUnloadWhenUnused or not FRawOpened then
-        Fraw_file:=TFileStream.Create(AnsiReplaceStr(FFileName,'.dat','.raw'),fmOpenReadWrite);
-      Result:=Fraw_file.Size;
-      Fraw_file.Seek(0,soFromEnd);
-      Fraw_file.Write(target^,size);
-      if UnloadWhenUnused then
-        Fraw_file.Free
-      else
-        FRawOpened:=True
-    end else begin
-      if FUnloadWhenUnused or not FSepOpened then
-        Fsep_file:=TFileStream.Create(AnsiReplaceStr(FFileName,'.dat','.sep'),fmOpenReadWrite);
-      Result:=Fsep_file.Size;
-      Fsep_file.Seek(0,soFromEnd);
-      Fsep_file.Write(target^,size);
-      if UnloadWhenUnused then
-        Fsep_file.Free
-      else
-        FSepOpened:=True;
-    end;
-  end;
-
-
-
-
-
-
-
-
-
-
-
-(*
-================================================================================
-                     Implementation of  TOniDataADB
-*)
-
-constructor TOniDataADB.Create(OLDBFilename:String; var Result:Boolean);
-  var
-    i,j:Byte;
-    temps:String;
-  begin
-    if not FileExists(OLDBFilename) then begin
-      ShowMessage('File doesn''t exist!!!');
-      Result:=False;
-      Exit;
-    end;
-    FFileName:=OLDBFilename;
-    FDatabase:=TABSDatabase.Create(nil);
-    FDatabase.DatabaseName:='OLDBcon';
-    FDatabase.DatabaseFileName:=OLDBFilename;
-    FDatabase.Open;
-    FQuery:=TABSQuery.Create(FDatabase);
-    FQuery.DatabaseName:='OLDBcon';
-    FQuery.SQL.Text:='SELECT [name],[value] FROM globals ORDER BY [name] ASC';
-    FQuery.Open;
-    FQuery.First;
-    repeat
-      if FQuery.FieldByName('name').AsString='dbversion' then begin
-        if FQuery.FieldByName('value').AsString<>DBversion then begin
-          ShowMessage('Database-file '+#13+#10+
-                      '"'+OLDBFilename+'"'+#13+#10+
-                      'has wrong version. (Required: '+DBversion+'; found: '+
-                        FQuery.FieldByName('value').AsString+')');
-          FQuery.Close;
-          Result:=False;
-          Exit;
-        end;
-      end;
-      if FQuery.FieldByName('name').AsString='lvl' then begin
-        FLevelInfo.LevelNumber:=StrToInt(FQuery.FieldByName('value').AsString);
-      end;
-      if FQuery.FieldByName('name').AsString='ident' then begin
-        temps:=FQuery.FieldByName('value').AsString;
-        for i:=0 to High(FLevelInfo.Ident) do begin
-          j:=i*2+1;
-          case temps[j] of
-            '0'..'9': FLevelInfo.Ident[i]:=Ord(temps[j])-48;
-            'A'..'F': FLevelInfo.Ident[i]:=Ord(temps[j])-55;
-          end;
-          FLevelInfo.Ident[i]:=FLevelInfo.Ident[i]*16;
-          case temps[j+1] of
-            '0'..'9': FLevelInfo.Ident[i]:=FLevelInfo.Ident[i]+Ord(temps[j+1])-48;
-            'A'..'F': FLevelInfo.Ident[i]:=FLevelInfo.Ident[i]+Ord(temps[j+1])-55;
-          end;
-        end;
-      end;
-      if FQuery.FieldByName('name').AsString='ident' then begin
-        temps:=FQuery.FieldByName('value').AsString;
-        Fos_mac:=temps='MAC';
-      end;
-      FQuery.Next;
-    until FQuery.EoF;
-    FQuery.Close;
-
-    Result:=True;
-    FBackend:=ODB_ADB;
-  end;
-
-procedure TOniDataADB.Close;
-  begin
-    FDatabase.Close;
-    FDatabase.Free;
-    Self.Free;
-  end;
-
-
-
-function TOniDataADB.GetFileInfo(fileid:LongWord):TFileInfo;
-  begin
-    if fileid<Self.GetFilesCount then begin
-      FQuery.SQL.Text:='SELECT * FROM datfiles WHERE id='+IntToStr(fileid)+' ORDER BY id ASC;';
-      FQuery.Open;
-      if FQuery.RecordCount=1 then begin
-        FQuery.First;
-        Result.ID:=FQuery.FieldByName('id').AsInteger;
-        Result.Name:=FQuery.FieldByName('name').AsString;
-        Result.Extension:=FQuery.FieldByName('extension').AsString;
-        Result.FileName:=FormatNumber(Result.ID,5,'0')+'-'+Result.Name+'.'+Result.Extension;
-        Result.Size:=FQuery.FieldByName('size').AsInteger;
-        Result.FileType:=HexToLong(FQuery.FieldByName('contenttype').AsString);
-        Result.DatAddr:=0;
-        Result.opened:=False;
-      end;
-      FQuery.Close;
-    end else begin
-      Result.ID:=-1;
-    end;
-  end;
-
-function TOniDataADB.GetFilesList(ext:String; pattern:String; NoEmptyFiles:Boolean):TStringArray;
-  var
-    i:LongWord;
-    where:String;
-    where_ext:String;
-  begin
-    where:='';
-    if Length(ext)>0 then begin
-      if Length(where)>0 then
-        where:=where+' AND ';
-      if Pos(',',ext)>0 then begin
-        i:=1;
-        where_ext:='';
-        while i<Length(ext) do begin
-          if Length(where_ext)>0 then
-            where_ext:=where_ext+' OR ';
-          where_ext:=where_ext+'(extension="'+MidStr(ext,i,4)+'")';
-          i:=i+5;
-        end;
-        where:=where+'('+where_ext+')';
-      end else begin
-        where:=where+'(extension="'+ext+'")';
-      end;
-    end;
-    if Length(pattern)>0 then begin
-      if Length(where)>0 then
-        where:=where+' AND ';
-      where:=where+'(name LIKE "%'+pattern+'%")';
-    end;
-    if NoEmptyFiles then begin
-      if Length(where)>0 then
-        where:=where+' AND ';
-      where:=where+'(contenttype<>2)';
-    end;
-    if Length(where)>0 then
-      where:=' WHERE '+where;
-    FQuery.SQL.Text:='SELECT id,name,extension FROM datfiles'+where+' ORDER BY id ASC;';
-    FQuery.Open;
-    if FQuery.RecordCount>0 then begin
-      FQuery.First;
-      SetLength(Result,FQuery.RecordCount);
-      i:=0;
-      repeat
-        Result[i]:=FormatNumber(FQuery.FieldByName('id').AsInteger,5,'0')+'-'+FQuery.FieldByName('name').AsString+'.'+FQuery.FieldByName('extension').AsString;
-        Inc(i);
-        FQuery.Next;
-      until FQuery.EOF;
-    end;
-    FQuery.Close;
-  end;
-
-function TOniDataADB.GetFilesCount:LongWord;
-  begin
-    FQuery.SQL.Text:='SELECT Count(*) AS cnumber FROM datfiles;';
-    FQuery.Open;
-    if FQuery.RecordCount>0 then begin
-      FQuery.First;
-      Result:=FQuery.FieldByName('cnumber').AsInteger;
-    end else Result:=0;
-    FQuery.Close;
-  end;
-
-function TOniDataADB.GetExtensionsList:TStringArray;
-  var
-    i:LongWord;
-  begin
-    SetLength(Result,0);
-    FQuery.SQL.Text:='SELECT extension,count(extension) AS x FROM datfiles GROUP BY extension ORDER BY extension ASC;';
-    FQuery.Open;
-    if FQuery.RecordCount>0 then begin
-      SetLength(Result,FQuery.RecordCount);
-      i:=0;
-      repeat
-        Result[i]:=FQuery.FieldByName('extension').AsString+' ('+IntToStr(FQuery.FieldByName('x').AsInteger)+')';
-        Inc(i);
-        FQuery.Next;
-      until FQuery.EOF;
-    end;
-    FQuery.Close;
-  end;
-
-function TOniDataADB.GetExtendedExtensionsList:TExtensionsMap;
-  var
-    i,j:LongWord;
-    temps:String;
-    data:Tdata;
-  begin
-    SetLength(Result,0);
-    FQuery.SQL.Text:='SELECT ext,ident FROM extlist ORDER BY ext ASC;';
-    FQuery.Open;
-    if FQuery.RecordCount>0 then begin
-      SetLength(Result,FQuery.RecordCount);
-      i:=0;
-      repeat
-        temps:=FQuery.FieldByName('ext').AsString;
-        for j:=0 to 3 do Result[i].Extension[j]:=temps[4-j];
-        data:=DecodeHexString(FQuery.FieldByName('ident').AsString);
-        for j:=0 to 7 do Result[i].Ident[j]:=data[j];
-        Inc(i);
-        FQuery.Next;
-      until FQuery.EOF;
-    end;
-    FQuery.Close;
-  end;
-
-function TOniDataADB.GetNamedFilesMap:TNamedFilesMap;
-  var
-    i:LongWord;
-    temp:Integer;
-    temps:String;
-    temparray:Array of Record
-        id:Integer;
-        fullname:String[50];
-      end;
-  begin
-    SetLength(temparray,0);
-    FQuery.SQL.Text:='SELECT id,(extension+name) AS xname FROM datfiles WHERE Length(name)>0 ORDER BY extension,name ASC;';
-    FQuery.Open;
-    if FQuery.RecordCount>0 then begin
-      repeat
-        temp:=FQuery.FieldByName('id').AsInteger;
-        temps:=FQuery.FieldByName('xname').AsString;
-
-        SetLength(temparray,Length(temparray)+1);
-        if Length(temparray)>1 then begin
-          for i:=High(temparray)-1 downto 0 do begin
-            if StringSmaller(temps,temparray[i].fullname) then begin
-              temparray[i+1]:=temparray[i];
-              if i=0 then begin
-                temparray[i].id:=temp;
-                temparray[i].fullname:=temps;
-              end;
-            end else begin
-              temparray[i+1].id:=temp;
-              temparray[i+1].fullname:=temps;
-              Break;
-            end;
-          end;
-        end else begin
-          temparray[0].id:=temp;
-          temparray[0].fullname:=temps;
-        end;
-        FQuery.Next;
-      until FQuery.Eof;
-    end;
-    FQuery.Close;
-    SetLength(Result,Length(temparray));
-    for i:=0 to High(temparray) do begin
-      Result[i].FileNumber:=temparray[i].id;
-      Result[i].blubb:=0;
-    end;
-  end;
-
-
-
-function TOniDataADB.LoadDatFile(fileid:LongWord):Tdata;
-  var
-    mem:TStream;
-  begin
-    if fileid<Self.GetFilesCount then begin
-      FQuery.SQL.Text:='SELECT data FROM datfiles WHERE id='+IntToStr(fileid)+';';
-      FQuery.Open;
-      if FQuery.RecordCount>0 then begin
-        mem:=FQuery.CreateBlobStream(FQuery.FieldByName('data'),bmRead);
-        SetLength(Result,mem.Size);
-        mem.Seek(0,soFromBeginning);
-        mem.Read(Result[0],mem.Size);
-        mem.Free;
-      end;
-      FQuery.Close;
-    end;
-  end;
-
-procedure TOniDataADB.UpdateDatFile(fileid:LongWord; data:Tdata);
-  var
-    MimeCoder: TStringFormat_MIME64;
-    mem:TMemoryStream;
-  begin
-    if fileid<Self.GetFilesCount then begin
-      mimecoder:=TStringFormat_MIME64.Create;
-      mem:=TMemoryStream.Create;
-      mem.Write(data[0],Length(data));
-      mem.Seek(0,soFromBeginning);
-      FQuery.SQL.Text:='UPDATE datfiles SET data=MimeToBin("'+MimeCoder.StrTo(mem.Memory, mem.Size)+'") WHERE id='+IntToStr(fileid)+';';
-      FQuery.ExecSQL;
-      mem.Free;
-      mimecoder.Free;
-    end;
-  end;
-
-procedure TOniDataADB.LoadDatFilePart(fileid,offset,size:LongWord; target:Pointer);
-  var
-    mem:TStream;
-  begin
-    if fileid<Self.GetFilesCount then begin
-      FQuery.SQL.Text:='SELECT data FROM datfiles WHERE id='+IntToStr(fileid)+';';
-      FQuery.Open;
-      IF FQuery.RecordCount>0 THEN BEGIN
-        mem:=FQuery.CreateBlobStream(FQuery.FieldByName('data'),bmRead);
-        mem.Seek(offset,soFromBeginning);
-        mem.Read(target^,size);
-        mem.Free;
-      END;
-      FQuery.Close;
-    END;
-  END;
-
-procedure TOniDataADB.UpdateDatFilePart(fileid,offset,size:LongWord; target:Pointer);
-  var
-    MimeCoder: TStringFormat_MIME64;
-    mem:TMemoryStream;
-    data:Tdata;
-  begin
-    if fileid<Self.GetFilesCount then begin
-      data:=Self.LoadDatFile(fileid);
-      mimecoder:=TStringFormat_MIME64.Create;
-      mem:=TMemoryStream.Create;
-      mem.Write(data[0],Length(data));
-      mem.Seek(offset,soFromBeginning);
-      mem.Write(target^,size);
-      mem.Seek(0,soFromBeginning);
-      FQuery.SQL.Text:='UPDATE datfiles SET data=MimeToBin("'+MimeCoder.StrTo(mem.Memory, mem.Size)+'") WHERE id='+IntToStr(fileid)+';';
-      FQuery.ExecSQL;
-      mem.Free;
-      mimecoder.Free;
-    end;
-  end;
-
-
-
-function TOniDataADB.GetRawList(fileid:LongWord):TRawList;
-  var
-    i:LongWord;
-  begin
-    SetLength(Result,0);
-    FQuery.SQL.Text:='SELECT [src_link_offset],[size],[sep] FROM rawmap WHERE [src_id]='+IntToStr(fileid)+' ORDER BY src_link_offset ASC;';
-    FQuery.Open;
-    if FQuery.RecordCount>0 then begin
-      FQuery.First;
-      SetLength(Result,FQuery.RecordCount);
-      i:=0;
-      repeat
-        Result[i].src_id:=fileid;
-        Result[i].src_offset:=FQuery.FieldByName('src_link_offset').AsInteger;
-        Result[i].raw_addr:=0;
-        Result[i].raw_size:=FQuery.FieldByName('size').AsInteger;
-        Result[i].loc_sep:=FQuery.FieldByName('sep').AsBoolean;
-        Inc(i);
-        FQuery.Next;
-      until FQuery.EOF;
-    end;
-    FQuery.Close;
-  end;
-
-procedure TOniDataADB.LoadRawFile(fileid,dat_offset:LongWord; target:Pointer);
-  var
-    mem:TStream;
-  begin
-    if fileid<Self.GetFilesCount then begin
-      FQuery.SQL.Text:='SELECT data FROM rawmap WHERE (src_id='+IntToStr(fileid)+') AND (src_link_offset='+IntToStr(dat_offset)+');';
-      FQuery.Open;
-      if FQuery.RecordCount>0 then begin
-        mem:=FQuery.CreateBlobStream(FQuery.FieldByName('data'),bmRead);
-        mem.Seek(0,soFromBeginning);
-        mem.Read(target^,mem.size);
-        mem.Free;
-      end;
-      FQuery.Close;
-    end;
-  end;
-
-procedure TOniDataADB.UpdateRawFile(fileid,dat_offset:LongWord; size:LongWord; target:Pointer);
-  var
-    MimeCoder: TStringFormat_MIME64;
-    mem:TMemoryStream;
-  begin
-    if fileid<Self.GetFilesCount then begin
-      mimecoder:=TStringFormat_MIME64.Create;
-      mem:=TMemoryStream.Create;
-      mem.Write(target^,size);
-      mem.Seek(0,soFromBeginning);
-      FQuery.SQL.Text:='UPDATE rawmap SET data=MimeToBin("'+MimeCoder.StrTo(mem.Memory, mem.Size)+'") WHERE (src_id='+IntToStr(fileid)+') AND (src_link_offset='+IntToStr(dat_offset)+');';
-      FQuery.ExecSQL;
-      mem.Free;
-      mimecoder.Free;
-    end;
-  end;
-
-procedure TOniDataADB.LoadRawFilePart(fileid,dat_offset:LongWord; offset,size:LongWord; target:Pointer);
-  var
-    data:Tdata;
-    mem:TMemoryStream;
-  begin
-    if fileid<Self.GetFilesCount then begin
-      SetLength(data, Self.GetRawInfo(fileid,dat_offset).raw_size);
-      Self.LoadRawFile(fileid,dat_offset,@data[0]);
-      mem:=TMemoryStream.Create;
-      mem.Write(data[offset],size);
-      mem.Read(target^,size);
-      mem.Free;
-    end;
-  end;
-
-procedure TOniDataADB.UpdateRawFilePart(fileid,dat_offset:LongWord; offset,size:LongWord; target:Pointer);
-  var
-    MimeCoder: TStringFormat_MIME64;
-    mem:TMemoryStream;
-    data:Tdata;
-  begin
-    if fileid<Self.GetFilesCount then begin
-      SetLength(data, Self.GetRawInfo(fileid,offset).raw_size);
-      Self.LoadRawFile(fileid,offset,@data[0]);
-      mimecoder:=TStringFormat_MIME64.Create;
-      mem:=TMemoryStream.Create;
-      mem.Write(data[0],Length(data));
-      mem.Seek(offset,soFromBeginning);
-      mem.Write(target^,size);
-      mem.Seek(0,soFromBeginning);
-      FQuery.SQL.Text:='UPDATE rawmap SET data=MimeToBin("'+MimeCoder.StrTo(mem.Memory, mem.Size)+'") WHERE (src_id='+IntToStr(fileid)+') AND (src_link_offset='+IntToStr(dat_offset)+');';
-      FQuery.ExecSQL;
-      mem.Free;
-      mimecoder.Free;
-    end;
-  end;
-
-
-
-
-
-
-
-
-
-
-
-function CreateDataConnection(filename:String; backend:Integer):Boolean;
-  var
-    answer:Boolean;
-  begin
-    if Assigned(OniDataConnection) then begin
-      OniDataConnection.Close;
-      OniDataConnection.Free;
-      OniDataConnection:=Nil;
-    end;
-    case backend of
-      ODB_Dat: OniDataConnection:=TOniDataDat.Create(filename, answer);
-      ODB_ADB: OniDataConnection:=TOniDataADB.Create(filename, answer);
-    else
-      ShowMessage('Unknown Backend');
-      Result:=False;
-      Exit;
-    end;
-
-    if answer then begin
-//      ShowMessage('file loaded');
-//      ShowMessage('Files: '+IntToStr(OniDataConnection.GetFilesCount));
-      Result:=True;
-    end else begin
-      ShowMessage('File not loaded');
-      OniDataConnection.Close;
-      OniDataConnection.Free;
-      Result:=False;
-    end;
-  end;
-
-procedure CloseDataConnection;
-  begin
-    if Assigned(OniDataConnection) then begin
-      OniDataConnection.Close;
-      OniDataConnection:=Nil;
-    end;
-  end;
-
-end.
Index: oup/current/Unit1_main.dfm
===================================================================
--- oup/current/Unit1_main.dfm	(revision 40)
+++ 	(revision )
@@ -1,450 +1,0 @@
-object Form1: TForm1
-  Left = 0
-  Top = 0
-  HorzScrollBar.Visible = False
-  VertScrollBar.Visible = False
-  Caption = 'Form1'
-  ClientHeight = 571
-  ClientWidth = 577
-  Color = clBtnFace
-  Font.Charset = DEFAULT_CHARSET
-  Font.Color = clWindowText
-  Font.Height = -11
-  Font.Name = 'Tahoma'
-  Font.Style = []
-  FormStyle = fsMDIForm
-  OldCreateOrder = False
-  WindowState = wsMaximized
-  OnClose = FormClose
-  OnCreate = FormCreate
-  OnResize = FormResize
-  PixelsPerInch = 96
-  TextHeight = 13
-  object statbar: TStatusBar
-    Left = 0
-    Top = 554
-    Width = 577
-    Height = 17
-    BiDiMode = bdLeftToRight
-    Panels = <
-      item
-        Text = 'Nothing loaded'
-        Width = 500
-      end
-      item
-        Text = 'Files: -'
-        Width = 90
-      end
-      item
-        Text = 'Extensions: -'
-        Width = 100
-      end>
-    ParentBiDiMode = False
-    ExplicitTop = 535
-  end
-  object DockTop: TTBDock
-    Left = 0
-    Top = 0
-    Width = 577
-    Height = 75
-    object MainMenu: TTBToolbar
-      Left = 0
-      Top = 0
-      Caption = 'MainMenu'
-      CloseButton = False
-      FullSize = True
-      Images = MenuImages
-      MenuBar = True
-      ProcessShortCuts = True
-      ShrinkMode = tbsmWrap
-      TabOrder = 0
-      object menu_main: TTBSubmenuItem
-        Caption = '&Main'
-        object menu_loaddat: TTBItem
-          Caption = '&Select .dat-file ...'
-          ImageIndex = 1
-          ShortCut = 16463
-          OnClick = menu_loaddatClick
-        end
-        object menu_lvldb: TTBItem
-          Caption = 'Open OUP-Level-&DB ...'
-          ImageIndex = 1
-          ShortCut = 16452
-          OnClick = menu_lvldbClick
-        end
-        object menu_CloseFileDB: TTBItem
-          Caption = '&Close file/DB'
-          ImageIndex = 0
-          OnClick = menu_CloseFileDBClick
-        end
-        object menu_sep1: TTBSeparatorItem
-        end
-        object menu_settings: TTBItem
-          Caption = 'Se&ttings...'
-          OnClick = menu_settingsClick
-        end
-        object menu_sep4: TTBSeparatorItem
-        end
-        object menu_exit: TTBItem
-          Caption = '&Exit'
-          OnClick = menu_exitClick
-        end
-      end
-      object menu_convert: TTBSubmenuItem
-        Caption = '&Convert'
-        object menu_createdb: TTBItem
-          Caption = 'Create level-database ...'
-          OnClick = menu_createdbClick
-        end
-        object menu_createlvl: TTBItem
-          Caption = 'Create level-files ...'
-          OnClick = menu_createlvlClick
-        end
-      end
-      object menu_tools: TTBSubmenuItem
-        Caption = '&Tools'
-        Enabled = False
-        object menu_preview: TTBItem
-          Caption = '&Preview Window ...'
-          ShortCut = 16464
-          OnClick = menu_previewClick
-        end
-        object menu_binedit: TTBItem
-          Caption = '&Binary .dat editor ...'
-          ShortCut = 16450
-          OnClick = menu_bineditClick
-        end
-        object menu_rawedit: TTBItem
-          Caption = 'Binary .&raw editor ...'
-          ShortCut = 16466
-          OnClick = menu_raweditClick
-        end
-        object menu_txmpreplace: TTBItem
-          Caption = '&TXMP replacer ...'
-          ShortCut = 16468
-          OnClick = menu_txmpreplaceClick
-        end
-        object menu_extractor: TTBItem
-          Caption = 'File &extractor ...'
-          ShortCut = 16453
-          OnClick = menu_extractorClick
-        end
-        object menu_filecompare: TTBItem
-          Caption = '&File compare ...'
-          Enabled = False
-          ShortCut = 16454
-          OnClick = menu_filecompareClick
-        end
-        object menu_levelstructedit: TTBItem
-          Caption = 'Levelfile structure editor ...'
-          Enabled = False
-          ShortCut = 16460
-        end
-      end
-      object menu_view: TTBSubmenuItem
-        Caption = '&View'
-        object menu_view_toolbar: TTBItem
-          AutoCheck = True
-          Caption = '&Toolbar'
-          Checked = True
-          OnClick = menu_view_toolbarClick
-        end
-        object menu_view_statusbar: TTBItem
-          Caption = '&Status bar'
-          Checked = True
-          OnClick = menu_view_statusbarClick
-        end
-        object menu_view_mdibar: TTBItem
-          Caption = '&Window list'
-          Checked = True
-          OnClick = menu_view_mdibarClick
-        end
-      end
-      object menu_windows: TTBSubmenuItem
-        Caption = '&Windows'
-        object menu_windows_cascade: TTBItem
-          Caption = 'Cascade'
-          OnClick = menu_windows_cascadeClick
-        end
-        object menu_windows_tile: TTBItem
-          Caption = 'Tile'
-          OnClick = menu_windows_tileClick
-        end
-        object menu_windows_closeall: TTBItem
-          Caption = '&Close all'
-          OnClick = menu_windows_closeallClick
-        end
-        object menu_sep3: TTBSeparatorItem
-        end
-        object menu_windows_next: TTBItem
-          Caption = 'Next window'
-          ShortCut = 16417
-          OnClick = menu_windows_nextClick
-        end
-        object menu_windows_previous: TTBItem
-          Caption = 'Previous window'
-          ShortCut = 16418
-          OnClick = menu_windows_previousClick
-        end
-        object menu_sep2: TTBSeparatorItem
-        end
-      end
-      object menu_About: TTBItem
-        Caption = '&About'
-        OnClick = menu_AboutClick
-      end
-    end
-    object Toolbar: TTBToolbar
-      Left = 0
-      Top = 23
-      Caption = 'Toolbar'
-      Images = MenuImages
-      TabOrder = 1
-      object tbOpen: TTBItem
-        Caption = 'x'
-        ImageIndex = 1
-      end
-    end
-    object MDIToolbar: TTBToolbar
-      Left = 0
-      Top = 49
-      Caption = 'MDIToolbar'
-      DockPos = 0
-      DockRow = 2
-      TabOrder = 2
-      OnResize = MDIToolbarResize
-      object TBControlItem1: TTBControlItem
-        Control = MDITab
-      end
-      object MDITab: TMDITab
-        Left = 0
-        Top = 0
-        Width = 562
-        Height = 22
-        Cursor = crHandPoint
-        About = 'MDI Tab Control 1.4 - Copyright '#169' 1999,2002 MichaL MutL'
-        Align = alTop
-        DragKind = dkDock
-        HotTrack = True
-        Images = MenuImages
-        Style = tsFlatButtons
-        OnGetImageIndex = MDITabGetImageIndex
-        MultiLine = True
-        ParentShowHint = False
-        PopupMenu = MDITabPopUp
-        ShowHint = True
-        ShowOnChange = True
-        TabOrder = 0
-      end
-    end
-    object toolbar_mdi: TTBToolbar
-      Left = 88
-      Top = 23
-      Caption = 'Window list'
-      DockPos = 88
-      Images = MenuImages
-      TabOrder = 3
-      object TBItem2: TTBItem
-        Caption = 'test'
-        DisplayMode = nbdmImageAndText
-      end
-      object TBItem1: TTBItem
-        Caption = 'test2'
-        DisplayMode = nbdmImageAndText
-        ImageIndex = 0
-      end
-    end
-  end
-  object DockLeft: TTBDock
-    Left = 0
-    Top = 75
-    Width = 9
-    Height = 470
-    Position = dpLeft
-    ExplicitHeight = 577
-  end
-  object DockRight: TTBDock
-    Left = 568
-    Top = 75
-    Width = 9
-    Height = 470
-    Position = dpRight
-    ExplicitLeft = 0
-    ExplicitHeight = 577
-  end
-  object DockBottom: TTBDock
-    Left = 0
-    Top = 545
-    Width = 577
-    Height = 9
-    Position = dpBottom
-    ExplicitTop = 75
-  end
-  object opend: TOpenDialog
-    Options = [ofPathMustExist, ofFileMustExist, ofEnableSizing]
-    Left = 32
-    Top = 64
-  end
-  object saved: TSaveDialog
-    Options = [ofOverwritePrompt, ofPathMustExist, ofEnableSizing]
-    Left = 32
-    Top = 88
-  end
-  object MenuImages: TImageList
-    Left = 168
-    Top = 112
-    Bitmap = {
-      494C010102000400040010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
-      0000000000003600000028000000400000001000000001002000000000000010
-      00000000000000000000000000000000000000000000EEB40000EEB40000EEB4
-      0000EEB40000EEB40000EEB40000EEB40000EEB40000EEB40000EEB40000EEB4
-      0000EEB40000EEB40000EEB400000000000000000000EEB40000EEB40000EEB4
-      0000EEB40000EEB40000EEB40000EEB40000EEB40000EEB40000EEB40000EEB4
-      0000EEB40000EEB40000EEB40000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      00000000000000000000000000000000000000000000A4A4A400A4A4A400A4A4
-      A400A4A4A40000000000EEB40000EEB40000EEB40000EEB4000000000000A4A4
-      A400A4A4A400A4A4A400A4A4A400EEB4000000000000A4A4A400A4A4A400A4A4
-      A400A4A4A40000000000EEB40000EEB40000EEB40000EEB4000000000000A4A4
-      A400A4A4A400A4A4A400A4A4A400EEB400000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      000000000000000000000000000000000000000000004A4A4A004A4A4A004A4A
-      4A00A4A4A40014007F00944131009441310094413100EEB400000E0E0E004A4A
-      4A004A4A4A004A4A4A00A4A4A400EEB40000000000004A4A4A004A4A4A004A4A
-      4A00A4A4A40018800000944131009441310094413100EEB400000E0E0E004A4A
-      4A004A4A4A004A4A4A00A4A4A400EEB400000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      000000000000000000000000000000000000000000004A4A4A004A4A4A004A4A
-      4A00A4A4A40018009400944131009441310094413100EEB40000180094004A4A
-      4A004A4A4A004A4A4A00A4A4A400EEB40000000000004A4A4A004A4A4A004A4A
-      4A00A4A4A40018920000944131009441310094413100EEB40000189200004A4A
-      4A004A4A4A004A4A4A00A4A4A400EEB400000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      000000000000000000000000000000000000000000004A4A4A00000000000000
-      0000A4A4A40000000000944131000000000000000000EEB40000020202004A4A
-      4A000000000000000000A4A4A400EEB40000000000004A4A4A00000000000000
-      0000A4A4A40000000000944131000000000000000000EEB40000020202004A4A
-      4A000000000000000000A4A4A400EEB400000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      00000000000000000000000000000000000000000000A4A4A4004A4A4A00A4A4
-      A400A4A4A40000000000EEB4000094413100EEB40000EEB4000000000000A4A4
-      A4004A4A4A00A4A4A400A4A4A400EEB4000000000000A4A4A4004A4A4A00A4A4
-      A400A4A4A40000000000EEB4000094413100EEB40000EEB4000000000000A4A4
-      A4004A4A4A00A4A4A400A4A4A400EEB400000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      000000000000000000000000000000000000000000000000000014007F000000
-      0000000000000000000000000000180094000000000014007F00000000000000
-      000014007F0014007F0000000000EEB40000000000000000000014007F000000
-      0000000000000000000000000000180094000000000000000000000000000000
-      000014007F001880000000000000EEB400000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000014007F0014007F000000
-      00000000000000000000180094000000000014007F0014007F00000000000000
-      0000000000001800940000000000EEB400000000000018800000188000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000001892000000000000EEB400000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000014007F0014007F000000
-      00000000000000000000000000001800940014007F0000000000000000000000
-      0000000000001800940000000000EEB400000000000018800000188000000000
-      0000000000000000000018920000189200000000000000000000000000000000
-      0000000000001892000000000000EEB400000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000014007F0014007F000000
-      0000000000000000000014007F0014007F001800940000000000000000000000
-      0000000000001800940000000000EEB400000000000018800000188000000000
-      0000000000000000000000000000000000001892000000000000000000000000
-      0000000000001892000000000000EEB400000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000014007F00180094000000
-      00000000000014007F0014007F00180094000000000018009400000000000000
-      000014007F001800940000000000EEB400000000000018800000189200000000
-      0000000000000000000000000000180094000000000018920000000000000000
-      0000188000001892000000000000EEB400000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      000000000000000000000000000000000000000000000E0E0E00180094000202
-      0200000000000000000000000000A4A4A4000000000000000000000000000000
-      000014007F0014007F0000000000EEB40000000000000E0E0E00189200000202
-      0200000000000000000000000000A4A4A4000000000000000000000000000000
-      0000188000001880000000000000EEB400000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      00000000000000000000000000000000000000000000A4A4A400A4A4A400A4A4
-      A400A4A4A400A4A4A400A4A4A40094413100A4A4A400A4A4A400A4A4A400A4A4
-      A400A4A4A400A4A4A400EEB40000EEB4000000000000A4A4A400A4A4A400A4A4
-      A400A4A4A400A4A4A400A4A4A40094413100A4A4A400A4A4A400A4A4A400A4A4
-      A400A4A4A400A4A4A400EEB40000EEB400000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      00000000000000000000000000000000000000000000EEB40000EEB40000EEB4
-      0000EEB40000EEB40000EEB40000EEB40000EEB40000EEB40000EEB40000EEB4
-      0000EEB40000EEB40000EEB40000EEB4000000000000EEB40000EEB40000EEB4
-      0000EEB40000EEB40000EEB40000EEB40000EEB40000EEB40000EEB40000EEB4
-      0000EEB40000EEB40000EEB40000EEB400000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      00000000000014007F001800940018009400180094001800940014007F000000
-      0000000000000000000000000000EEB400000000000000000000000000000000
-      0000000000001880000018920000189200001892000018920000188000000000
-      0000000000000000000000000000EEB400000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      000000000000000000000000000000000000EEB4000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      000000000000000000000000000000000000EEB4000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      000000000000000000000000000000000000424D3E000000000000003E000000
-      2800000040000000100000000100010000000000800000000000000000000000
-      000000000000000000000000FFFFFF0080018001000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000000000000000000000000000000000000000000000000
-      0000000000000000000100010000000000000000000000000000000000000000
-      000000000000}
-  end
-  object MDITabPopUp: TPopupMenu
-    AutoHotkeys = maManual
-    AutoLineReduction = maManual
-    Left = 232
-    Top = 112
-    object mdi_close: TMenuItem
-      Caption = 'Close tab'
-    end
-  end
-  object MDIHandler: TTBMDIHandler
-    Toolbar = MainMenu
-    Left = 200
-    Top = 112
-  end
-end
Index: oup/current/Unit1_main.pas
===================================================================
--- oup/current/Unit1_main.pas	(revision 40)
+++ 	(revision )
@@ -1,537 +1,0 @@
-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.Width<MinWidth THEN Form1.Width:=MinWidth;
-    IF Form1.Height<MinHeight THEN Form1.Height:=MinHeight;
-    Form1.statbar.Panels.Items[0].Width:=Form1.Width-200;
-  END;
-
-procedure TForm1.MDITabGetImageIndex(Sender: TObject; TabIndex: Integer; var ImageIndex: Integer);
-  begin
-//    if Pos('binedit',MDITab.MDIChildren[TabIndex].Name)>0 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.
Index: oup/current/Unit2_functions.pas
===================================================================
--- oup/current/Unit2_functions.pas	(revision 40)
+++ 	(revision )
@@ -1,294 +1,0 @@
-UNIT Unit2_functions;
-INTERFACE
-USES Classes, Dialogs, SysUtils, StrUtils, Math,
-      Unit3_data;
-
-TYPE
-  TExportSet=SET OF (DO_dat,DO_raw,DO_convert,DO_toone);
-
-FUNCTION BoolToStr(bool:Boolean):String;
-FUNCTION HexToLong(hex:String):LongWord;
-FUNCTION Decode_Int(buffer:Tdata):LongWord;
-FUNCTION Encode_Int(input:LongWord):Tdata;
-FUNCTION Decode_Float(buffer:Tdata):Single;
-FUNCTION Encode_Float(input:Single):Tdata;
-FUNCTION DataToBin(data:Tdata):String;
-FUNCTION BinToInt(bin:String):Byte;
-
-FUNCTION ExportFile(fileid:LongWord; filename:String; settings:TExportSet; path:String):Integer;
-
-FUNCTION StringSmaller(string1,string2:String):Boolean;
-
-FUNCTION FormatNumber(value:LongWord; width:Byte; leadingzeros:Char):String;
-FUNCTION FormatFileSize(size:LongWord):String;
-FUNCTION CreateHexString(data:Tdata; HexOnly:Boolean):String;
-FUNCTION DecodeHexString(hex:String):Tdata;
-FUNCTION GetWinFileName(name:String):String;
-FUNCTION GetExtractPath:String;
-
-FUNCTION Explode(_string:String; delimiter:Char):TStringArray;
-
-
-IMPLEMENTATION
-USES Unit4_Exporters, Unit15_Classes;
-
-TYPE
-  TValueSwitcher=Record
-    CASE IsFloat: Boolean OF
-      True: (ValueFloat:Single);
-      False: (ValueInt:LongWord);
-  END;
-
-FUNCTION BoolToStr(bool:Boolean):String;
-  BEGIN
-    IF bool THEN
-      Result:='true'
-    ELSE
-      Result:='false';
-  END;
-
-FUNCTION HexToLong(hex:String):LongWord;
-  FUNCTION NormalizeHexString(VAR hex:String):Boolean;
-    VAR
-      i:Byte;
-    BEGIN
-      IF hex[1]='$' THEN BEGIN
-        FOR i:=1 TO Length(hex)-1 DO BEGIN
-          hex[i]:=hex[i+1];
-        END;
-        SetLength(hex, Length(hex)-1);
-      END;
-      IF (hex[1]='0') AND (UpCase(hex[2])='X') THEN BEGIN
-        FOR i:=1 TO Length(hex)-2 DO BEGIN
-          hex[i]:=hex[i+2];
-        END;
-        SetLength(hex, Length(hex)-2);
-      END;
-      IF Length(hex)=0 THEN
-        Result:=False
-      ELSE
-        Result:=True;
-    END;
-  VAR
-    i:Byte;
-  BEGIN
-    IF NormalizeHexString(hex) THEN BEGIN
-      hex:=UpperCase(hex);
-      Result:=0;
-      FOR i:=1 TO Length(hex) DO BEGIN
-        Result:=Result SHL 4;
-        CASE hex[i] OF
-          '0'..'9': Result:=Result+Ord(hex[i])-48;
-          'A'..'F': Result:=Result+Ord(hex[i])-55;
-        ELSE
-          Result:=0;
-          Exit;
-        END;
-      END;
-    END ELSE BEGIN
-      Result:=0;
-    END;
-  END;
-
-FUNCTION Decode_Int(buffer:Tdata):LongWord;
-  BEGIN
-    Result:=buffer[0]+buffer[1]*256+buffer[2]*256*256+buffer[3]*256*256*256;
-  END;
-FUNCTION Encode_Int(input:LongWord):Tdata;
-  BEGIN
-    SetLength(Result,4);
-    Result[0]:=input MOD 256;
-    input:=input DIV 256;
-    Result[1]:=input MOD 256;
-    input:=input DIV 256;
-    Result[2]:=input MOD 256;
-    input:=input DIV 256;
-    Result[3]:=input MOD 256;
-  END;
-FUNCTION Decode_Float(buffer:Tdata):Single;
-  VAR _valueswitcher:TValueSwitcher;
-  BEGIN
-    _valueswitcher.ValueInt:=Decode_Int(buffer);
-    Result:=_valueswitcher.ValueFloat;
-    IF IsNAN(Result) THEN Result:=0.0;
-  END;
-FUNCTION Encode_Float(input:Single):Tdata;
-  VAR _valueswitcher:TValueSwitcher;
-  BEGIN
-    _valueswitcher.ValueFloat:=input;
-    Result:=Encode_Int(_valueswitcher.ValueInt);
-  END;
-
-FUNCTION DataToBin(data:Tdata):String;
-  VAR
-    i,j:Byte;
-    singlebyte:Byte;
-    bytepart:String;
-  BEGIN
-    SetLength(bytepart,8);
-    Result:='';
-    FOR i:=0 TO High(data) DO BEGIN
-      singlebyte:=data[i];
-      FOR j:=7 DOWNTO 0 DO BEGIN
-        bytepart[j+1]:=Char((singlebyte AND $01)+48);
-        singlebyte:=singlebyte SHR 1;
-      END;
-      Result:=Result+bytepart+' ';
-    END;
-  END;
-FUNCTION BinToInt(bin:String):Byte;
-  VAR
-    Add: Integer;
-    i: Byte;
-  BEGIN
-    Result:=0;
-    IF Length(bin)<>8 THEN Exit;
-    Add:=1;
-    FOR i:=8 DOWNTO 1 DO BEGIN
-      IF NOT (bin[i] IN ['0','1']) THEN Exit;
-      IF bin[i] = '1' THEN Inc(Result,Add);
-      Add:=Add SHL 1;
-    END;
-  END;
-
-
-
-FUNCTION FormatNumber(value:LongWord; width:Byte; leadingzeros:Char):String;
-  BEGIN
-    Result:=AnsiReplaceStr(Format('%'+IntToStr(width)+'u',[value]),' ',leadingzeros);
-  END;
-
-FUNCTION FormatFileSize(size:LongWord):String;
-  BEGIN
-    IF size>=1000*1024*1024 THEN BEGIN
-      Result:=FloatToStrF(size/1024/1024/1024,ffFixed,5,1)+' GB';
-    END ELSE BEGIN
-      IF size>=1000*1024 THEN BEGIN
-        Result:=FloatToStrF(size/1024/1024,ffFixed,5,1)+' MB';
-      END ELSE BEGIN
-        IF size>=1000 THEN BEGIN
-          Result:=FloatToStrF(size/1024,ffFixed,5,1)+' KB';
-        END ELSE BEGIN
-          Result:=IntToStr(size)+' B';
-        END;
-      END;
-    END;
-  END;
-
-FUNCTION CreateHexString(data:Tdata; HexOnly:Boolean):String;
-  VAR
-    string_build,ascii_version:String;
-    i:LongWord;
-  BEGIN
-    string_build:='';
-    ascii_version:='';
-    FOR i:=0 TO High(data) DO BEGIN
-      IF NOT HexOnly THEN
-        IF (i MOD 16)=0 THEN
-          string_build:=string_build+'0x'+IntToHex(i,6)+'  ';
-      string_build:=string_build+IntToHex(data[i],2);
-      IF NOT HexOnly THEN BEGIN
-        IF data[i]>=32 THEN ascii_version:=ascii_version+Chr(data[i])
-        ELSE ascii_version:=ascii_version+'.';
-        IF ((i+1) MOD 2)=0 THEN string_build:=string_build+#32;
-        IF ((i+1) MOD 16)=0 THEN BEGIN
-          string_build:=string_build+#32+ascii_version+CrLf;
-          ascii_version:='';
-        END;
-      END;
-    END;
-    Result:=string_build;
-  END;
-
-FUNCTION DecodeHexString(hex:String):Tdata;
-  VAR
-    i:LongWord;
-  BEGIN
-    SetLength(Result, Length(hex) DIV 2);
-    FOR i:=0 TO Length(Result) DO BEGIN
-      Result[i]:=0;
-      CASE UpCase(hex[1+i*2]) OF
-        '0'..'9': Result[i]:=(Ord(UpCase(hex[1+i*2]))-48)*16;
-        'A'..'F': Result[i]:=(Ord(UpCase(hex[1+i*2]))-55)*16;
-      END;
-      CASE UpCase(hex[1+i*2+1]) OF
-        '0'..'9': Result[i]:=Result[i]+(Ord(UpCase(hex[1+i*2+1]))-48);
-        'A'..'F': Result[i]:=Result[i]+(Ord(UpCase(hex[1+i*2+1]))-55);
-      END;
-    END;
-  END;
-
-
-
-FUNCTION StringSmaller(string1,string2:String):Boolean;
-  VAR
-    i:Integer;
-    len:Integer;
-  BEGIN
-    len:=Min(Length(string1),Length(string2));
-    FOR i:=1 TO len DO
-      IF Ord(string1[i])<>Ord(string2[i]) THEN BEGIN
-        Result:=Ord(string1[i])<Ord(string2[i]);
-        Exit;
-      END;
-    Result:=Length(string1)<Length(string2);
-  END;
-
-
-
-
-FUNCTION ExportFile(fileid:LongWord; filename:String; settings:TExportSet; path:String):Integer;
-  VAR
-    i:Byte;
-    extension:String;
-    rawlist:TRawList;
-  BEGIN
-    Result:=export_noerror;
-    extension:=RightStr(filename,4);
-    IF DO_toone IN settings THEN BEGIN
-      ExportDatFile(fileid,path+'\'+GetWinFileName(filename));
-    END ELSE BEGIN
-      IF DO_dat IN settings THEN ExportDatFile(fileid,path+'\'+GetWinFileName(filename));
-      IF DO_raw IN settings THEN BEGIN
-        rawlist:=OniDataConnection.GetRawList(fileid);
-        IF Length(rawlist)>0 THEN BEGIN
-          FOR i:=0 TO High(rawlist) DO BEGIN
-            ExportRawFile(fileid,rawlist[i].src_offset,path+'\'+GetWinFileName(filename));
-          END;
-        END;
-      END;
-    END;
-  END;
-
-FUNCTION Explode(_string:String; delimiter:Char):TStringArray;
-  VAR
-    start,len:Word;
-  BEGIN
-    SetLength(Result, 0);
-    start:=1;
-    WHILE PosEx(delimiter,_string,start)>0 DO BEGIN
-      len:=PosEx(delimiter,_string,start)-start;
-      SetLength(Result, Length(Result)+1);
-      Result[High(Result)]:=MidStr(_string,start,len);
-      start:=start+len+1;
-    END;
-    SetLength(Result, Length(Result)+1);
-    Result[High(Result)]:=MidStr(_string,start,Length(_string)-start+1);
-  END;
-
-FUNCTION GetWinFileName(name:String):String;
-  BEGIN
-    Result:=name;
-    Result:=AnsiReplaceStr(Result,'\','__');
-    Result:=AnsiReplaceStr(Result,'/','__');
-    Result:=AnsiReplaceStr(Result,'>','__');
-    Result:=AnsiReplaceStr(Result,'<','__');
-  END;
-
-FUNCTION GetExtractPath:String;
-  BEGIN
-    Result:=ExtractFilePath(OniDataConnection.FileName)+'\extracted_'+ExtractFileName(OniDataConnection.Filename);
-  END;
-
-
-END.
Index: oup/current/Unit3_data.pas
===================================================================
--- oup/current/Unit3_data.pas	(revision 40)
+++ 	(revision )
@@ -1,130 +1,0 @@
-unit Unit3_data;
-interface
-uses Classes, Graphics;
-
-const
-  Version:String='v0.32a';
-  DBVersion:String='0.3';
-  CrLf:String[2]=#13+#10;
-
-type
-  TData=Array of Byte;
-  THeader=packed Record
-    Ident:Array[0..$13] of Byte;
-    Files:LongWord;
-    NamedFiles:LongWord;
-    Extensions:LongWord;
-    DataAddr:LongWord;
-    DataSize:LongWord;
-    NamesAddr:LongWord;
-    NamesSize:LongWord;
-    Ident2:Array[0..$F] of Byte;
-  end;
-  TFilesMap=Array of packed Record
-    Extension:Array[0..$3] of Char;
-    DataAddr:LongWord;
-    NameAddr:LongWord;
-    FileSize:LongWord;
-    FileType:LongWord;
-  end;
-  TFileInfo=packed Record
-    ID:Integer;
-    FileName:String;
-    FileNameHex:String;
-    Extension:String[4];
-    Name:String;
-    Size:LongWord;
-    FileType:LongWord;
-    DatAddr:LongWord;
-    opened:Boolean;
-  end;
-  TFiles=Array of TFileInfo;
-
-  TNamedFilesMap=Array of packed Record
-  	FileNumber:LongWord;
-	  blubb:LongWord;
-  end;
-  TExtensionsMap=Array of packed Record
-  	Ident:Array[0..$7] of Byte;
-	  Extension:Array[0..$3] of Char;
-  	ExtCount:LongWord;
-  end;
-
-  TLevelInfo=Record
-    Ident:Array[0..$13] of Byte;
-    LevelNumber:Byte;
-  end;
-
-  TAppSettings=Record
-    DatPath:String[250];
-    ExtractPath:String[250];
-    FilenumbersAsHex:Boolean;
-    CharSet:TFontCharSet;
-    HideUnusedData:Boolean;
-  end;
-
-  TExportHandlers=Record
-    Ext:String[4];
-    needed:Boolean;
-    Handler:Function(fileid:LongWord; filename:String; convert:Boolean):Integer;
-  end;
-
-  TStringArray=Array of String;
-  TExtList=Array of Record
-    Ext:String;
-    count:LongWord;
-  end;
-
-  TRawInfo=Record
-    src_id:LongWord;
-    src_offset:LongWord;
-    raw_addr:LongWord;
-    raw_size:LongWord;
-    loc_sep:Boolean;
-  end;
-  TRawList=Array of TRawInfo;
-
-  TDatLinks=Array of Record
-    Src_Offset:LongWord;
-    Target:LongWord;
-  END;
-
-var
-{
-  opened_state:Byte=0;
-  dat_filename:String='';
-  raw_filename:String='';
-  dat_os_mac:Boolean=False;
-  dat_header:Theader;
-  dat_filesmap:Tfilesmap;
-  dat_files:Tfiles;
-  dat_namedfilesmap:Tnamedfilesmap;
-  dat_extensionsmap:Textensionsmap;
-}
-  AppSettings:TAppSettings;
-  AppSettingsFile:File of TAppSettings;
-{
-  database_level:LongWord;
-  database_ident:Array[0..$13] of Byte;
-}
-const
-{  header_ident1_pc:Array[0..$13] of Byte=
-      ($1F,$27,$DC,$33,$DF,$BC,$03,$00,$31,$33,$52,$56,$40,$00,$14,$00,$10,$00,$08,$00);
-  header_ident1_mac:Array[0..$13] of Byte=
-      ($61,$30,$C1,$23,$DF,$BC,$03,$00,$31,$33,$52,$56,$40,$00,$14,$00,$10,$00,$08,$00);
-  header_ident2:Array[0..$F] of Byte=
-      ($99,$CF,$40,$00,$90,$4F,$63,$00,$F4,$55,$5F,$00,$90,$4F,$63,$00);
-}
-  export_noerror:Integer=0;
-  export_nohandler:Integer=1;
-  export_handlererror:Integer=2;
-  export_error:Integer=3;
-{
-  opened_nothing:Byte=0;
-  opened_dat:Byte=1;
-  opened_db:Byte=2;
-}
-implementation
-
-end.
-
Index: oup/current/Unit4_Exporters.pas
===================================================================
--- oup/current/Unit4_Exporters.pas	(revision 40)
+++ 	(revision )
@@ -1,218 +1,0 @@
-UNIT Unit4_Exporters;
-INTERFACE
-USES Classes, Dialogs, StrUtils, SysUtils, Math, Unit3_data, Unit6_imgfuncs;
-
-PROCEDURE ExportDatFile(fileid:LongWord; filename:String);
-PROCEDURE ExportRawFile(fileid:LongWord; dat_offset:LongWord; filename:String);
-
-FUNCTION ExportSNDD(fileid:LongWord; filename:String; convert:Boolean):Integer;
-FUNCTION ExportTRAC(fileid:LongWord; filename:String; convert:Boolean):Integer;
-FUNCTION ExportTXAN(fileid:LongWord; filename:String; convert:Boolean):Integer;
-FUNCTION ExportTXMB(fileid:LongWord; filename:String; convert:Boolean):Integer;
-FUNCTION ExportTXMP(fileid:LongWord; filename:String; convert:Boolean):Integer;
-VAR
-  ExportHandlers:Array[1..1] OF TExportHandlers=(
-//    (Ext:'ABNA'; needed:False),
-    //(Ext:'AGDB'; needed:False),
-    (Ext:'SNDD'; needed:True; Handler:ExportSNDD)
-{    (Ext:'TRAC'; needed:True; Handler:ExportTRAC),
-    (Ext:'TXAN'; needed:True; Handler:ExportTXAN),
-    (Ext:'TXMB'; needed:True; Handler:ExportTXMB),
-    (Ext:'TXMP'; needed:True; Handler:ExportTXMP)
-}  );
-
-
-
-IMPLEMENTATION
-USES Unit2_functions, Unit9_data_structures, Unit15_Classes;
-
-PROCEDURE ExportDatFile(fileid:LongWord; filename:String);
-  VAR
-    filestream:TFileStream;
-    data:Tdata;
-  BEGIN
-    data:=OniDataConnection.LoadDatFile(fileid);
-    IF FileExists(filename) THEN BEGIN
-      filestream:=TFileStream.Create(filename,fmOpenReadWrite);
-      filestream.Seek(0,soFromEnd);
-    END ELSE BEGIN
-      filestream:=TFileStream.Create(filename,fmCreate);
-    END;
-    filestream.Write(data[0],Length(data));
-    filestream.Free;
-  END;
-
-PROCEDURE ExportRawFile(fileid:LongWord; dat_offset:LongWord; filename:String);
-  VAR
-    filestream:TFileStream;
-    data:Tdata;
-  BEGIN
-    SetLength(data, OniDataConnection.GetRawInfo(fileid, dat_offset).raw_size);
-    OniDataConnection.LoadRawFile(fileid,dat_offset,@data[0]);
-    IF FileExists(filename+'.raw0x'+IntToHex(dat_offset,8)) THEN BEGIN
-      filestream:=TFileStream.Create(filename+'.raw0x'+IntToHex(dat_offset,8),fmOpenReadWrite);
-      filestream.Seek(0,soFromEnd);
-    END ELSE BEGIN
-      filestream:=TFileStream.Create(filename+'.raw0x'+IntToHex(dat_offset,8),fmCreate);
-    END;
-    filestream.Write(data[0],Length(data));
-    filestream.Free;
-  END;
-
-FUNCTION ExportSNDD;
-{  CONST
-    WAVheader:Array[0..0] OF Byte=(
-        Ord('R'),Ord('I'),Ord('F'),Ord('F'),0,0,0,0,Ord('W'),Ord('A'),Ord('V'),Ord('E'),
-        Ord('f'),Ord('m'),Ord('t'),Ord(' '),24,0,0,0,
-      );
-}  TYPE
-    TDatData=RECORD
-      {0x00}
-      _fileid:LongWord;
-      level:LongWord;
-      Flag:LongWord;
-      FormatTag:Word;
-      ChanNo:Word;
-      {0x10}
-      SampleRate:LongWord;
-      BytesPSec:LongWord;
-      BPSample:LongWord;
-      BitsPS:LongWord;
-      {0x20}
-      Unknown:Array[1..7] OF LongWord;
-      Unknown2:Word;
-      {0x40}
-      RawSize:LongWord;
-      RawPos:LongWord;
-    END;
-  VAR
-      filestream:TFileStream;
-
-    DatData:TDatData;
-      //Wave Header Stuff
-      ASCII_Group:LongWord; //"RIFF"
-      WAV_Len:LongWord;
-      ASCII_WAV:LongWord; //"WAVE"
-      ASCII_FMT:LongWord; //"fmt "
-      WAV_FMT_Len:LongWord;
-      ASCII_DATA:LongWord; //"data"
-      WAV_FolLen:LongWord;
-
-      data:Tdata;
-  BEGIN
-      Result:=export_noerror;
-    OniDataConnection.LoadDatFilePart(fileid,0,SizeOf(DatData),@DatData);
-    WITH DatData DO BEGIN
-        //Initializing Header vars
-        ASCII_Group:=1179011410; // 'RIFF'
-        WAV_Len:=RAWSize+70;
-        ASCII_WAV:=1163280727;  // 'WAVE'
-        ASCII_FMT:=544501094;   // 'fmt '
-        WAV_FMT_Len:=50;        // 50 bytes
-        ASCII_DATA:=1635017060; // 'data'
-        WAV_FolLen:=RAWSize;
-        SetLength(data,RAWSize);
-        OniDataConnection.LoadRawFile(fileid,$44,data);
-
-      filestream:=TFileStream.Create(filename+'.raw',fmCreate);
-      filestream.Write(data[0],Length(data));
-      filestream.Free;
-
-      IF convert THEN BEGIN
-          //Now start packing this into a neat wave...
-        filestream:=TFileStream.Create(filename+'.wav',fmCreate);
-          filestream.Write(ASCII_Group,SizeOf(ASCII_Group));
-          filestream.Write(WAV_Len,SizeOf(WAV_Len));
-          filestream.Write(ASCII_WAV,SizeOf(ASCII_WAV));
-          filestream.Write(ASCII_FMT,SizeOf(ASCII_FMT));
-          filestream.Write(WAV_FMT_Len,SizeOf(WAV_FMT_Len));
-          filestream.Write(ChanNo,SizeOf(ChanNo));
-          filestream.Write(Samplerate,SizeOf(Samplerate));
-          filestream.Write(BytesPSec,SizeOf(BytesPSec));
-          filestream.Write(BPSample,SizeOf(BPSample));
-          filestream.Write(BitsPS,SizeOf(BitsPS));
-          filestream.Write(Unknown[1],SizeOf(Unknown));
-          filestream.Write(Unknown2,SizeOf(Unknown2));
-          filestream.Write(ASCII_DATA,SizeOf(ASCII_DATA));
-          filestream.Write(WAV_FolLen,SizeOf(WAV_FolLen));
-          filestream.Write(data[0],Length(data));
-          filestream.Free;
-      END;
-    END;
-  END;
-
-FUNCTION ExportTRAC;
-  VAR
-    link:LongWord;
-    linkcount:Word;
-    i:LongWord;
-  BEGIN
-    Result:=export_noerror;
-
-    OniDataConnection.LoadDatFilePart(fileid,$18,SizeOf(link),@link);
-    link:=link DIV 256;
-
-    OniDataConnection.LoadDatFilePart(fileid,$1E,SizeOf(linkcount),@linkcount);
-    FOR i:=1 TO linkcount DO BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$20+(i-1)*12+8,SizeOf(link),@link);
-      link:=link DIV 256;
-    END;
-  END;
-
-FUNCTION ExportTXAN;
-  VAR
-    loop_speed,unknown:Word;
-    linkcount:LongWord;
-    link:LongWord;
-    i:Byte;
-  BEGIN
-    Result:=export_noerror;
-
-    OniDataConnection.LoadDatFilePart(fileid,$14,SizeOf(loop_speed),@loop_speed);
-    OniDataConnection.LoadDatFilePart(fileid,$16,SizeOf(unknown),@unknown);
-
-    OniDataConnection.LoadDatFilePart(fileid,$1C,SizeOf(linkcount),@linkcount);
-    FOR i:=0 TO linkcount-1 DO BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$20+i*4,SizeOf(link),@link);
-      link:=link DIV 256;
-      IF link=0 THEN link:=fileid-1;
-    END;
-  END;
-
-FUNCTION ExportTXMB;
-  VAR
-    filestream:TFileStream;
-//    img:TImgPackage;
-    data:Tdata;
-  BEGIN
-    Result:=export_noerror;
-    IF convert THEN BEGIN
-{      img:=LoadTXMBconnected(fileid);
-      data:=ImgdataToBmp(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
-      filestream:=TFileStream.Create(filename+'.bmp',fmCreate);
-      filestream.Write(data[0],Length(data));
-      filestream.Free;
-}    END;
-  END;
-
-FUNCTION ExportTXMP;
-  VAR
-    filestream:TFileStream;
-//    img:TImgPackage;
-  BEGIN
-    Result:=export_noerror;
-{    img:=LoadImgData(fileid);
-
-    filestream:=TFileStream.Create(filename+'.raw',fmCreate);
-    filestream.Write(img.imgdata[0],Length(img.imgdata));
-    filestream.Free;
-
-    IF convert THEN BEGIN
-      img.imgdata:=ImgdataToBMP(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
-      filestream:=TFileStream.Create(filename+'.bmp',fmCreate);
-      filestream.Write(img.imgdata[0],Length(img.imgdata));
-      filestream.Free;
-    END;
-}  END;
-
-END.
Index: oup/current/Unit5_preview.dfm
===================================================================
--- oup/current/Unit5_preview.dfm	(revision 40)
+++ 	(revision )
@@ -1,191 +1,0 @@
-object Form5: TForm5
-  Left = 0
-  Top = 0
-  Caption = 'Preview'
-  ClientHeight = 473
-  ClientWidth = 472
-  Color = clBtnFace
-  Font.Charset = DEFAULT_CHARSET
-  Font.Color = clWindowText
-  Font.Height = -11
-  Font.Name = 'Tahoma'
-  Font.Style = []
-  FormStyle = fsMDIChild
-  OldCreateOrder = False
-  Visible = True
-  WindowState = wsMaximized
-  OnClose = FormClose
-  OnCreate = FormCreate
-  OnResize = FormResize
-  PixelsPerInch = 96
-  TextHeight = 13
-  object Splitter1: TSplitter
-    Left = 150
-    Top = 0
-    Width = 9
-    Height = 473
-    AutoSnap = False
-    Beveled = True
-    MinSize = 150
-  end
-  object panel_preview: TPanel
-    Left = 159
-    Top = 0
-    Width = 313
-    Height = 473
-    Align = alClient
-    BevelOuter = bvNone
-    TabOrder = 0
-    object img: TImage
-      Left = 0
-      Top = 20
-      Width = 313
-      Height = 453
-      Align = alClient
-    end
-    object lbl_notpossible: TLabel
-      Left = 16
-      Top = 56
-      Width = 97
-      Height = 65
-      AutoSize = False
-      Caption = 'No preview possible for this filetype'
-      Font.Charset = DEFAULT_CHARSET
-      Font.Color = clWindowText
-      Font.Height = -16
-      Font.Name = 'Tahoma'
-      Font.Style = []
-      ParentFont = False
-      Visible = False
-      WordWrap = True
-    end
-    object panel_buttons: TPanel
-      Left = 0
-      Top = 0
-      Width = 313
-      Height = 20
-      Align = alTop
-      BevelOuter = bvNone
-      TabOrder = 0
-      Visible = False
-      OnResize = panel_buttonsResize
-      object btn_dec: TButton
-        Left = 0
-        Top = 0
-        Width = 20
-        Height = 20
-        Caption = '-'
-        Enabled = False
-        TabOrder = 0
-        OnClick = btn_decClick
-      end
-      object btn_startstop: TButton
-        Left = 21
-        Top = 0
-        Width = 80
-        Height = 20
-        Caption = 'Stop automatic'
-        TabOrder = 1
-        OnClick = btn_startstopClick
-      end
-      object btn_inc: TButton
-        Left = 102
-        Top = 0
-        Width = 20
-        Height = 20
-        Caption = '+'
-        Enabled = False
-        TabOrder = 2
-        OnClick = btn_incClick
-      end
-    end
-  end
-  object panel_files: TPanel
-    Left = 0
-    Top = 0
-    Width = 150
-    Height = 473
-    Align = alLeft
-    BevelOuter = bvNone
-    TabOrder = 1
-    object list: TListBox
-      Left = 0
-      Top = 0
-      Width = 150
-      Height = 370
-      Align = alClient
-      ItemHeight = 13
-      TabOrder = 0
-      OnClick = listClick
-    end
-    object panel_extension: TPanel
-      Left = 0
-      Top = 370
-      Width = 150
-      Height = 103
-      Align = alBottom
-      BevelOuter = bvNone
-      TabOrder = 1
-      OnResize = panel_extensionResize
-      object lbl_filter: TLabel
-        Left = 2
-        Top = 62
-        Width = 100
-        Height = 17
-        AutoSize = False
-        Caption = 'Filter by &extension:'
-        FocusControl = combo_extension
-      end
-      object combo_extension: TComboBox
-        Left = 2
-        Top = 76
-        Width = 145
-        Height = 21
-        Style = csDropDownList
-        DropDownCount = 12
-        Font.Charset = DEFAULT_CHARSET
-        Font.Color = clWindowText
-        Font.Height = -11
-        Font.Name = 'Tahoma'
-        Font.Style = []
-        ItemHeight = 13
-        ParentFont = False
-        Sorted = True
-        TabOrder = 3
-        OnClick = combo_extensionClick
-      end
-      object check_zerobyte: TCheckBox
-        Left = 2
-        Top = 44
-        Width = 130
-        Height = 13
-        Caption = 'Show &zero-byte files'
-        TabOrder = 2
-        OnClick = check_zerobyteClick
-      end
-      object edit_filtername: TEdit
-        Left = 2
-        Top = 20
-        Width = 145
-        Height = 18
-        AutoSize = False
-        TabOrder = 1
-      end
-      object check_filtername: TCheckBox
-        Left = 2
-        Top = 5
-        Width = 130
-        Height = 15
-        Caption = 'Filter by file&name:'
-        TabOrder = 0
-        OnClick = check_filternameClick
-      end
-    end
-  end
-  object timer: TTimer
-    Enabled = False
-    OnTimer = timerTimer
-    Left = 144
-    Top = 24
-  end
-end
Index: oup/current/Unit5_preview.pas
===================================================================
--- oup/current/Unit5_preview.pas	(revision 40)
+++ 	(revision )
@@ -1,301 +1,0 @@
-UNIT Unit5_preview;
-INTERFACE
-USES
-  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
-  Dialogs, Math, ExtCtrls, StdCtrls, StrUtils, Menus,
-  Unit2_functions, Unit3_data, Unit4_exporters, Unit6_imgfuncs, Unit15_Classes;
-
-TYPE
-  TForm5 = Class(TForm)
-    timer: TTimer;
-    panel_preview: TPanel;
-    img: TImage;
-    panel_buttons: TPanel;
-    btn_dec: TButton;
-    btn_startstop: TButton;
-    btn_inc: TButton;
-    Splitter1: TSplitter;
-    lbl_notpossible: TLabel;
-    panel_files: TPanel;
-    list: TListBox;
-    panel_extension: TPanel;
-    lbl_filter: TLabel;
-    combo_extension: TComboBox;
-    check_zerobyte: TCheckBox;
-    edit_filtername: TEdit;
-    check_filtername: TCheckBox;
-    PROCEDURE LoadFileNames;
-    PROCEDURE check_filternameClick(Sender: TObject);
-    PROCEDURE check_zerobyteClick(Sender: TObject);
-    PROCEDURE combo_extensionClick(Sender: TObject);
-    PROCEDURE panel_extensionResize(Sender: TObject);
-    PROCEDURE listClick(Sender: TObject);
-    PROCEDURE Recreatelist;
-
-    PROCEDURE PreviewTXAN;
-    PROCEDURE PreviewTXMB;
-    PROCEDURE PreviewTXMP;
-    PROCEDURE PreviewPSpc;
-    PROCEDURE btn_incClick(Sender: TObject);
-    PROCEDURE btn_decClick(Sender: TObject);
-    PROCEDURE FormResize(Sender: TObject);
-    PROCEDURE btn_startstopClick(Sender: TObject);
-    PROCEDURE panel_buttonsResize(Sender: TObject);
-    PROCEDURE timerTimer(Sender: TObject);
-    PROCEDURE FormCreate(Sender: TObject);
-    PROCEDURE FormClose(Sender: TObject; var Action: TCloseAction);
-  PRIVATE
-    memstreams:Array OF TMemoryStream;
-    actualimg:Byte;
-    _fileid:LongWord;
-  PUBLIC
-  END;
-
-VAR
-  Form5: TForm5;
-
-IMPLEMENTATION
-{$R *.dfm}
-USES Unit1_main;
-
-
-PROCEDURE TForm5.Recreatelist;
-  VAR
-    i:LongWord;
-    exts:TStringArray;
-  BEGIN
-    combo_extension.Items.Clear;
-    combo_extension.Items.Add('_All files_ ('+IntToStr(OniDataConnection.GetFilesCount)+')');
-    exts:=OniDataConnection.GetExtensionsList;
-    FOR i:=0 TO High(exts) DO
-      combo_extension.Items.Add(exts[i]);
-    combo_extension.ItemIndex:=0;
-    combo_extensionClick(Self);
-  END;
-
-PROCEDURE TForm5.LoadFileNames;
-  VAR
-    Extension:String[4];
-    no_zero_bytes:Boolean;
-    pattern:String;
-    files:TStringArray;
-    i:LongWord;
-  BEGIN
-    Extension:=MidStr(combo_extension.Items.Strings[combo_extension.ItemIndex],1,4);
-    no_zero_bytes:=NOT check_zerobyte.Checked;
-    pattern:='';
-    IF check_filtername.Checked THEN pattern:=edit_filtername.Text;
-    IF Extension='_All' THEN Extension:='';
-
-    files:=OniDataConnection.GetFilesList(extension,pattern,no_zero_bytes);
-    list.Items.Clear;
-    IF Length(files)>0 THEN
-      FOR i:=0 TO High(files) DO
-        list.Items.Add(files[i]);
-  END;
-
-PROCEDURE TForm5.panel_extensionResize(Sender: TObject);
-  BEGIN
-    combo_extension.Width:=panel_extension.Width-5;
-    edit_filtername.Width:=panel_extension.Width-5;
-  END;
-
-PROCEDURE TForm5.combo_extensionClick(Sender: TObject);
-  BEGIN
-    LoadFileNames;
-  END;
-
-PROCEDURE TForm5.check_zerobyteClick(Sender: TObject);
-  VAR
-    i:Byte;
-  BEGIN
-    LoadFileNames;
-  END;
-
-PROCEDURE TForm5.check_filternameClick(Sender: TObject);
-  BEGIN
-    edit_filtername.Enabled:=NOT check_filtername.Checked;
-    LoadFileNames;
-  END;
-
-PROCEDURE TForm5.listClick(Sender: TObject);
-  BEGIN
-    _fileid:=OniDataConnection.ExtractFileID(list.Items.Strings[list.ItemIndex]);
-    lbl_notpossible.Visible:=False;
-    Self.img.Visible:=True;
-    Self.timer.Enabled:=False;
-    Self.panel_buttons.Visible:=False;
-    IF RightStr(list.Items.Strings[list.ItemIndex],4)='PSpc' THEN PreviewPSpc
-    ELSE
-    IF RightStr(list.Items.Strings[list.ItemIndex],4)='TXAN' THEN PreviewTXAN
-    ELSE
-    IF RightStr(list.Items.Strings[list.ItemIndex],4)='TXMB' THEN PreviewTXMB
-    ELSE
-    IF RightStr(list.Items.Strings[list.ItemIndex],4)='TXMP' THEN PreviewTXMP
-    ELSE BEGIN
-      Self.lbl_notpossible.Visible:=True;
-      Self.img.Visible:=False;
-    END;
-  END;
-
-
-
-PROCEDURE TForm5.PreviewPSpc;
-  VAR
-    OniImage:TOniImage;
-    data:Tdata;
-  BEGIN
-    SetLength(memstreams,1);
-    OniImage:=TOniImage.Create;
-    OniImage.LoadFromPSpc(_fileid);
-    data:=OniImage.GetAsBMP;
-    OniImage.Free;
-
-    memstreams[0].Clear;
-    memstreams[0].Write(data[0],Length(data));
-    memstreams[0].Seek(0,soFromBeginning);
-
-    Self.img.Picture.Bitmap.LoadFromStream(memstreams[0]);
-  END;
-
-
-PROCEDURE TForm5.PreviewTXMB;
-  VAR
-    OniImage:TOniImage;
-    data:Tdata;
-  BEGIN
-    SetLength(memstreams,1);
-    OniImage:=TOniImage.Create;
-    OniImage.LoadFromTXMB(_fileid);
-    data:=OniImage.GetAsBMP;
-    OniImage.Free;
-
-    memstreams[0].Clear;
-    memstreams[0].Write(data[0],Length(data));
-    memstreams[0].Seek(0,soFromBeginning);
-
-    Self.img.Picture.Bitmap.LoadFromStream(memstreams[0]);
-  END;
-
-PROCEDURE TForm5.PreviewTXMP;
-  VAR
-    OniImage:TOniImage;
-    data:Tdata;
-  BEGIN
-    SetLength(memstreams,1);
-    OniImage:=TOniImage.Create;
-    OniImage.LoadFromTXMP(_fileid);
-    data:=OniImage.GetAsBMP;
-    OniImage.Free;
-
-    memstreams[0].Clear;
-    memstreams[0].Write(data[0],Length(data));
-    memstreams[0].Seek(0,soFromBeginning);
-
-    Self.img.Picture.Bitmap.LoadFromStream(memstreams[0]);
-  END;
-
-PROCEDURE TForm5.PreviewTXAN;
-  VAR
-    loop_speed:Word;
-    linkcount:LongWord;
-    link:LongWord;
-    i:Byte;
-    data:Tdata;
-    OniImage:TOniImage;
-  BEGIN
-    OniDataConnection.LoadDatFilePart(_fileid,$14,SizeOf(loop_speed),@loop_speed);
-    OniDataConnection.LoadDatFilePart(_fileid,$1C,SizeOf(linkcount),@linkcount);
-    SetLength(memstreams,linkcount);
-    FOR i:=0 TO linkcount-1 DO BEGIN
-      OniDataConnection.LoadDatFilePart(_fileid,$20+i*4,SizeOf(link),@link);
-      link:=link DIV 256;
-      IF link=0 THEN link:=_fileid-1;
-      memstreams[i]:=TMemoryStream.Create;
-      OniImage:=TOniImage.Create;
-      OniImage.LoadFromTXMP(link);
-      data:=OniImage.GetAsBMP;
-      OniImage.Free;
-      memstreams[i].Clear;
-      memstreams[i].Write(data[0],Length(data));
-      memstreams[i].Seek(0,soFromBeginning);
-    END;
-    actualimg:=254;
-    Self.timer.Interval:=Floor(loop_speed*(1/60)*1000);
-    Self.timer.Enabled:=False;
-    Self.btn_startstopClick(Self);
-    Self.panel_buttons.Visible:=True;
-  END;
-
-
-PROCEDURE TForm5.FormCreate(Sender: TObject);
-  BEGIN
-    SetLength(memstreams,1);
-    memstreams[0]:=TMemoryStream.Create;
-    Self.Width:=260;
-    Self.Height:=300;
-  END;
-
-PROCEDURE TForm5.timerTimer(Sender: TObject);
-  BEGIN
-    Inc(actualimg);
-    IF actualimg>=Length(memstreams) THEN actualimg:=0;
-    Self.img.Picture.Bitmap.LoadFromStream(memstreams[actualimg]);
-    memstreams[actualimg].Seek(0,soFromBeginning);
-    Self.Caption:='Preview '+OniDataConnection.GetFileInfo(_fileid).FileName+' ('+IntToStr(actualimg+1)+'/'+IntToStr(Length(memstreams))+')';
-  END;
-
-PROCEDURE TForm5.panel_buttonsResize(Sender: TObject);
-  BEGIN
-    btn_startstop.Width:=panel_buttons.Width-45;
-    btn_inc.Left:=panel_buttons.Width-23;
-  END;
-
-PROCEDURE TForm5.btn_startstopClick(Sender: TObject);
-  BEGIN
-    Self.timer.Enabled:=NOT Self.timer.Enabled;
-    Self.btn_dec.Enabled:=NOT Self.timer.Enabled;
-    Self.btn_inc.Enabled:=NOT Self.timer.Enabled;
-    IF Self.timer.Enabled THEN
-      Self.btn_startstop.Caption:='Stop automatic'
-    ELSE
-      Self.btn_startstop.Caption:='Start automatic';
-  END;
-
-PROCEDURE TForm5.FormResize(Sender: TObject);
-  BEGIN
-    IF Self.Width>=300 THEN BEGIN
-    END ELSE Self.Width:=300;
-    IF Self.Height>=200 THEN BEGIN
-    END ELSE Self.Height:=200;
-  END;
-
-PROCEDURE TForm5.btn_decClick(Sender: TObject);
-  BEGIN
-    IF actualimg>0 THEN
-      Dec(actualimg)
-    ELSE
-      actualimg:=High(memstreams);
-    Self.Caption:='Preview '+OniDataConnection.GetFileInfo(_fileid).FileName+' ('+IntToStr(actualimg+1)+'/'+IntToStr(Length(memstreams))+')';
-    Self.img.Picture.Bitmap.LoadFromStream(memstreams[actualimg]);
-    memstreams[actualimg].Seek(0,soFromBeginning);
-  END;
-
-PROCEDURE TForm5.btn_incClick(Sender: TObject);
-  BEGIN
-    IF actualimg<High(memstreams) THEN
-      Inc(actualimg)
-    ELSE
-      actualimg:=0;
-    Self.Caption:='Preview '+OniDataConnection.GetFileInfo(_fileid).FileName+' ('+IntToStr(actualimg+1)+'/'+IntToStr(Length(memstreams))+')';
-    Self.img.Picture.Bitmap.LoadFromStream(memstreams[actualimg]);
-    memstreams[actualimg].Seek(0,soFromBeginning);
-  END;
-
-
-PROCEDURE TForm5.FormClose(Sender: TObject; var Action: TCloseAction);
-  BEGIN
-    Action:=caFree;
-  END;
-
-END.
Index: oup/current/Unit6_imgfuncs.pas
===================================================================
--- oup/current/Unit6_imgfuncs.pas	(revision 40)
+++ 	(revision )
@@ -1,693 +1,0 @@
-unit Unit6_imgfuncs;
-interface
-uses Math, Dialogs, Types, SysUtils, Classes, Unit3_data, Unit15_Classes;
-
-type
-  TImgDataType=Set of (DT_OniReverted,DT_Oni,DT_Decoded32);
-
-type
-  TOniImage = class
-    private
-      FLoaded:Boolean;
-      FDataType:TImgDataType;
-      FData:Tdata;
-      FWidth,FHeight:Word;
-      FDepth:Byte;
-      FStoreType:Byte;
-
-      function ResizeImage(oldx,oldy:LongWord; img:Tdata):Tdata;
-      procedure RevertImage;
-      procedure DecodeImage;
-      procedure DecompressImage;
-    protected
-    public
-      property Loaded:Boolean read FLoaded write FLoaded;
-      property DataType:TImgDataType read FDataType write FDataType;
-      property Width:Word read FWidth write FWidth;
-      property Height:Word read FHeight write FHeight;
-      property Depth:Byte read FDepth write FDepth;
-      property StoreType:Byte read FStoreType write FStoreType;
-      property Data:Tdata read FData write FData;
-
-      constructor Create;
-      function LoadFromPSpc(fileid:LongWord):Boolean;
-      function LoadFromTXMP(fileid:LongWord):Boolean;
-      function LoadFromTXMB(fileid:LongWord):Boolean;
-      function GetImageDataSize(fading:Boolean):LongWord;
-
-      function GetAsData:Tdata;
-      function GetAs32bit:Tdata;
-      function GetAsBMP:Tdata;
-      function LoadFromBMP(filename:String):Boolean;
-      function WriteToBMP(filename:String):Boolean;
-      function GetMipMappedImage(var faded:Tdata):Boolean;
-    published
-  end;
-
-
-implementation
-uses Unit2_functions;
-
-
-
-constructor TOniImage.Create;
-  begin
-    Self.FLoaded:=False;
-    Self.FDataType:=[];
-    SetLength(Self.FData,0);
-    Self.FWidth:=0;
-    Self.FHeight:=0;
-    Self.FDepth:=0;
-    Self.FStoreType:=0;
-  end;
-
-
-
-function TOniImage.ResizeImage(oldx,oldy:LongWord; img:Tdata):Tdata;
-  var
-    i,j:LongWord;
-    col,row,row_orig:LongWord;
-  begin
-    SetLength(Result,(oldx div 2)*(oldy div 2)*(Self.FDepth div 8));
-    row_orig:=0;
-    row:=0;
-    col:=0;
-    for i:=0 to (oldx*oldy)-1 do begin
-      if ((i mod oldx)=0) and (i>0) then begin
-        Inc(row_orig);
-        if (row_orig mod 2)=0 then begin
-          Inc(row);
-          col:=0;
-        end;
-      end;
-      if (row_orig mod 2)=0 then begin
-        if (i mod 2)=0 then begin
-          for j:=0 to (Self.FDepth div 8)-1 do
-            Result[((row*(oldx div 2))+col)*(Self.FDepth div 8)+j]:=img[(i*(Self.FDepth div 8))+j];
-          Inc(col);
-        end;
-      end;
-    end;
-  end;
-
-
-
-procedure TOniImage.RevertImage;
-  var
-    x,y,i:LongWord;
-    tempd:Tdata;
-  begin
-    SetLength(tempd, Self.FWidth * Self.FHeight *(Self.FDepth div 8));
-    for y:=0 to Self.FHeight-1 do
-      for x:=0 to Self.FWidth-1 do
-        for i:=0 to (Self.FDepth div 8)-1 do
-          tempd[((Self.FWidth*(Self.FHeight-1-y)+x)*(Self.FDepth div 8))+i]:=
-                  Self.FData[(Self.FWidth*y+x)*(Self.FDepth div 8)+i];
-    for x:=0 to High(tempd) do
-      Self.FData[x]:=tempd[x];
-    if DT_OniReverted in Self.FDataType then
-      Self.FDataType:=Self.FDataType-[DT_OniReverted]
-    else
-      Self.FDataType:=Self.FDataType+[DT_OniReverted];
-  end;
-
-
-
-procedure TOniImage.DecodeImage;
-  var
-    x,y:LongWord;
-    tempd:Tdata;
-  begin
-    if not (DT_Decoded32 in Self.FDataType) then begin
-      SetLength(tempd, Self.FWidth * Self.FHeight * 4);
-      case Self.FStoreType of
-        0: begin
-            for y:=0 to Self.FHeight-1 do begin
-              for x:=0 to Self.FWidth-1 do begin
-                tempd[((Self.FWidth*y+x)*4)+0]:=Floor( ( (Self.FData[(Self.FWidth*y+x)*2]+Self.FData[(Self.FWidth*y+x)*2+1]*256) AND $000F ) / $000F * 255);
-                tempd[((Self.FWidth*y+x)*4)+1]:=Floor( ( (Self.FData[(Self.FWidth*y+x)*2]+Self.FData[(Self.FWidth*y+x)*2+1]*256) AND $00F0 ) / $00F0 * 255);
-                tempd[((Self.FWidth*y+x)*4)+2]:=Floor( ( (Self.FData[(Self.FWidth*y+x)*2]+Self.FData[(Self.FWidth*y+x)*2+1]*256) AND $0F00 ) / $0F00 * 255);
-                tempd[((Self.FWidth*y+x)*4)+3]:=0;
-              end;
-            end;
-          end;
-        1,2: begin
-            for y:=0 to Self.FHeight-1 do begin
-              for x:=0 to Self.FWidth-1 do begin
-                tempd[((Self.FWidth*y+x)*4)+0]:=Floor( ( (Self.FData[(Self.FWidth*y+x)*2]+Self.FData[(Self.FWidth*y+x)*2+1]*256) AND $001F ) / $001F * 255);
-                tempd[((Self.FWidth*y+x)*4)+1]:=Floor( ( (Self.FData[(Self.FWidth*y+x)*2]+Self.FData[(Self.FWidth*y+x)*2+1]*256) AND $03E0 ) / $03E0 * 255);
-                tempd[((Self.FWidth*y+x)*4)+2]:=Floor( ( (Self.FData[(Self.FWidth*y+x)*2]+Self.FData[(Self.FWidth*y+x)*2+1]*256) AND $7C00 ) / $7C00 * 255);
-                tempd[((Self.FWidth*y+x)*4)+3]:=0;
-              end;
-            end;
-          end;
-        9: begin
-            DecompressImage;
-          end;
-      end;
-      Self.FDepth:=32;
-      if (Self.FStoreType<>9) AND (Self.FStoreType<>8) then begin
-        SetLength(Self.FData, Length(tempd));
-        for x:=0 to High(tempd) do
-          Self.FData[x]:=tempd[x];
-      end;
-      Self.FStoreType:=8;
-      if DT_Oni in Self.FDataType then
-        Self.FDataType:=Self.FDataType-[DT_Oni];
-      Self.FDataType:=Self.FDataType+[DT_Decoded32];
-    end;
-    if DT_OniReverted in Self.FDataType then
-      Self.RevertImage;
-  end;
-
-
-
-procedure TOniImage.DecompressImage;
-  type
-    Tcolor=record
-        RGBb:Byte;
-        RGBg:Byte;
-        RGBr:Byte;
-        RGBa:Byte;
-      end;
-  var
-    i,j,x,y:LongWord;
-    color:Array[1..4] of Tcolor;
-    pixel:Array[1..16] of Byte;
-    tempd:Tdata;
-  begin
-    x:=0;
-    y:=0;
-    SetLength(tempd, Self.FWidth * Self.FHeight * 4);
-    for i:=0 to ((Self.FWidth * Self.FHeight) div 16)-1 do begin
-      Color[1].RGBb:=Floor(((Self.FData[(i*8)+0]+Self.FData[(i*8)+1]*256) and $001F) / $001F * 255);
-      Color[1].RGBg:=Floor(((Self.FData[(i*8)+0]+Self.FData[(i*8)+1]*256) and $07E0) / $07E0 * 255);
-      Color[1].RGBr:=Floor(((Self.FData[(i*8)+0]+Self.FData[(i*8)+1]*256) and $F800) / $F800 * 255);
-      Color[1].RGBa:=255;
-      Color[2].RGBb:=Floor(((Self.FData[(i*8)+2]+Self.FData[(i*8)+3]*256) and $001F) / $001F * 255);
-      Color[2].RGBg:=Floor(((Self.FData[(i*8)+2]+Self.FData[(i*8)+3]*256) and $07E0) / $07E0 * 255);
-      Color[2].RGBr:=Floor(((Self.FData[(i*8)+2]+Self.FData[(i*8)+3]*256) and $F800) / $F800 * 255);
-      Color[2].RGBa:=255;
-      Color[3].RGBb:=Floor( Color[1].RGBb/3*2 + Color[2].RGBb/3 );
-      Color[3].RGBg:=Floor( Color[1].RGBg/3*2 + Color[2].RGBg/3 );
-      Color[3].RGBr:=Floor( Color[1].RGBr/3*2 + Color[2].RGBr/3 );
-      Color[3].RGBa:=255;
-      Color[4].RGBb:=Floor( Color[1].RGBb/3 + Color[2].RGBb/3*2 );
-      Color[4].RGBg:=Floor( Color[1].RGBg/3 + Color[2].RGBg/3*2 );
-      Color[4].RGBr:=Floor( Color[1].RGBr/3 + Color[2].RGBr/3*2 );
-      Color[4].RGBa:=255;
-      Pixel[1]:=Floor( (Self.FData[(i*8)+4] and $C0) / $40 + 1 );
-      Pixel[2]:=Floor( (Self.FData[(i*8)+4] and $30) / $10 + 1 );
-      Pixel[3]:=Floor( (Self.FData[(i*8)+4] and $0C) / $04 + 1 );
-      Pixel[4]:=Floor( (Self.FData[(i*8)+4] and $03) + 1 );
-      Pixel[5]:=Floor( (Self.FData[(i*8)+5] and $C0) / $40 + 1 );
-      Pixel[6]:=Floor( (Self.FData[(i*8)+5] and $30) / $10 + 1 );
-      Pixel[7]:=Floor( (Self.FData[(i*8)+5] and $0C) / $04 + 1 );
-      Pixel[8]:=Floor( (Self.FData[(i*8)+5] and $03) + 1 );
-      Pixel[9]:=Floor( (Self.FData[(i*8)+6] and $C0) / $40 + 1 );
-      Pixel[10]:=Floor( (Self.FData[(i*8)+6] and $30) / $10 + 1 );
-      Pixel[11]:=Floor( (Self.FData[(i*8)+6] and $0C) / $04 + 1 );
-      Pixel[12]:=Floor( (Self.FData[(i*8)+6] and $03) + 1 );
-      Pixel[13]:=Floor( (Self.FData[(i*8)+7] and $C0) / $40 + 1 );
-      Pixel[14]:=Floor( (Self.FData[(i*8)+7] and $30) / $10 + 1 );
-      Pixel[15]:=Floor( (Self.FData[(i*8)+7] and $0C) / $04 + 1 );
-      Pixel[16]:=Floor( (Self.FData[(i*8)+7] and $03) + 1 );
-      for j:=0 to 3 do begin
-        tempd[((y+3)*Self.FWidth+x+j)*4+0]:=Color[Pixel[16-j]].RGBb;
-        tempd[((y+3)*Self.FWidth+x+j)*4+1]:=Color[Pixel[16-j]].RGBg;
-        tempd[((y+3)*Self.FWidth+x+j)*4+2]:=Color[Pixel[16-j]].RGBr;
-        tempd[((y+3)*Self.FWidth+x+j)*4+3]:=0;
-      end;
-      for j:=0 to 3 do begin
-        tempd[((y+2)*Self.FWidth+x+j)*4+0]:=Color[Pixel[12-j]].RGBb;
-        tempd[((y+2)*Self.FWidth+x+j)*4+1]:=Color[Pixel[12-j]].RGBg;
-        tempd[((y+2)*Self.FWidth+x+j)*4+2]:=Color[Pixel[12-j]].RGBr;
-        tempd[((y+2)*Self.FWidth+x+j)*4+3]:=0;
-      end;
-      for j:=0 to 3 do begin
-        tempd[((y+1)*Self.FWidth+x+j)*4+0]:=Color[Pixel[8-j]].RGBb;
-        tempd[((y+1)*Self.FWidth+x+j)*4+1]:=Color[Pixel[8-j]].RGBg;
-        tempd[((y+1)*Self.FWidth+x+j)*4+2]:=Color[Pixel[8-j]].RGBr;
-        tempd[((y+1)*Self.FWidth+x+j)*4+3]:=0;
-      end;
-      for j:=0 to 3 do begin
-        tempd[((y+0)*Self.FWidth+x+j)*4+0]:=Color[Pixel[4-j]].RGBb;
-        tempd[((y+0)*Self.FWidth+x+j)*4+1]:=Color[Pixel[4-j]].RGBg;
-        tempd[((y+0)*Self.FWidth+x+j)*4+2]:=Color[Pixel[4-j]].RGBr;
-        tempd[((y+0)*Self.FWidth+x+j)*4+3]:=0;
-      end;
-      x:=x+4;
-      if x=Self.FWidth THEN begin
-        y:=y+4;
-        x:=0;
-      end;
-    end;
-    SetLength(Self.FData, Length(tempd));
-    for i:=0 to High(tempd) do
-      Self.FData[i]:=tempd[i];
-    Self.FStoreType:=8;
-    Self.FDepth:=32;
-    Self.FDataType:=Self.FDataType-[DT_Oni]+[DT_Decoded32];
-  end;
-
-
-
-
-
-function TOniImage.LoadFromPSpc(fileid:LongWord):Boolean;
-  type
-    TPoint=Packed Record
-      X,Y:Word;
-    end;
-    TPSpc=Packed Record
-      p1:Array[0..8] of TPoint;
-      p2:Array[0..8] of TPoint;
-      TXMP:LongWord;
-    end;
-    TPart=Packed Record
-      x_txmp,y_txmp:Word;
-      x_pspc,y_pspc:Word;
-      w,h:Word;
-      imgdata:Tdata;
-      used:Boolean;
-    end;
-  const
-    PartMatch:Array[0..8] of Byte=(0,3,6,1,4,7,2,5,8);
-  var
-    x,y,pixel:Word;
-    i:Integer;
-
-    PSpc:TPSpc;
-    txmpimg:TOniImage;
-    txmpdata:Tdata;
-    
-    parts:Array[0..8] of TPart;
-    part:Byte;
-    cols:Array[0..2] of Word;
-    rows:Array[0..2] of Word;
-    col,row:Byte;
-  begin
-    OniDataConnection.LoadDatFilePart ( fileid , $08 , SizeOf(PSpc) , @PSpc );
-    PSpc.TXMP := PSpc.TXMP div 256;
-    if PSpc.TXMP = 0 then begin
-      Result := False;
-      Exit;
-    end;
-    txmpimg := TOniImage.Create;
-    txmpimg.LoadFromTXMP ( PSpc.TXMP );
-    txmpimg.DecodeImage;
-    txmpimg.WriteToBMP('D:\file.bmp'); 
-    txmpdata:=txmpimg.GetAs32bit;
-{    ShowMessage(IntToStr(txmpimg.Width)+'x'+IntToStr(txmpimg.Height));
-    for i:=0 to High(txmpdata) do
-      txmpimg.Data[i]:=txmpdata[i];
-    txmpimg.WriteToBMP('D:\file2.bmp');
-}
-    with PSpc do begin
-      for i := 0 to 2 do begin
-        cols[i] := 0;
-        rows[i] := 0;
-      end;
-      for i := 0 to 8 do begin
-        part := PartMatch[i];
-        col := i div 3;
-        row := i mod 3;
-        if (p2[i].X>0) or (p2[i].Y>0) then begin
-          parts[part].x_txmp := p1[i].X - 1;
-          parts[part].y_txmp := p1[i].Y - 1;
-          parts[part].x_pspc := 0;
-          if col>0 then
-            for x := 0 to col-1 do
-              Inc( parts[part].x_pspc , cols[x] );
-          parts[part].y_pspc := 0;
-          if row>0 then
-            for y := 0 to row-1 do
-              Inc ( parts[part].y_pspc , rows[y] );
-          parts[part].w := p2[i].X - p1[i].X + 1;
-          parts[part].h := p2[i].Y - p1[i].Y + 1;
-          parts[part].used := True;
-          cols[col] := parts[part].w;
-          rows[row] := parts[part].h;
-          SetLength(parts[part].imgdata, parts[part].w * parts[part].h * 4);
-          for y := 0 to parts[part].h-1 do begin
-            for x := 0 to parts[part].w-1 do begin
-              for pixel := 0 to 3 do begin
-                parts[part].imgdata[ ( y*parts[part].w + x ) * 4 + pixel ] :=
-                   txmpdata[ ( ( parts[part].y_txmp + y ) * txmpimg.Width + parts[part].x_txmp + x ) * 4 + pixel ];
-              end;
-            end;
-          end;
-        end else begin
-          parts[part].used := False;
-        end;
-      end;
-
-    end;
-
-    txmpimg.Free;
-    txmpimg:=TOniImage.Create;
-    for i:=0 to 8 do begin
-      if parts[i].used then begin
-        SetLength( txmpimg.FData, Length(parts[i].imgdata) );
-        for pixel:=0 to High(parts[i].imgdata) do
-          txmpimg.Data[pixel]:=parts[i].imgdata[pixel];
-        txmpimg.Width:=parts[i].w;
-        txmpimg.Height:=parts[i].h;
-        txmpimg.StoreType:=8;
-        txmpimg.DataType:=[DT_Decoded32];
-        txmpimg.Depth:=32;
-        txmpimg.WriteToBMP('D:\'+IntToStr(i)+'.bmp');
-      end;
-    end;
-    txmpimg.Free;
-
-    Self.FWidth := 0;
-    Self.FHeight := 0;
-    for i := 0 to 2 do begin
-      Inc( Self.FWidth , cols[i] );
-      Inc( Self.FHeight , rows[i] );
-    end;
-    SetLength(Self.FData, Self.FWidth * Self.FHeight * 4);
-
-//Combine data parts
-
-    Self.FDepth:=32;
-    Self.FStoreType:=8;
-    Self.FDataType:=[DT_Decoded32];
-//    Self.RevertImage;
-  end;
-
-
-function TOniImage.LoadFromTXMP(fileid:LongWord):Boolean;
-  var
-    img_addr:LongWord;
-  begin
-    Result:=True;
-    OniDataConnection.LoadDatFilePart(fileid,$8C,SizeOf(Self.FWidth),@Self.FWidth);
-    OniDataConnection.LoadDatFilePart(fileid,$8E,SizeOf(Self.FHeight),@Self.FHeight);
-    OniDataConnection.LoadDatFilePart(fileid,$90,SizeOf(Self.FStoreType),@Self.FStoreType);
-    if not OniDataConnection.OSisMac then
-      OniDataConnection.LoadDatFilePart(fileid,$9C,SizeOf(img_addr),@img_addr)
-    else
-      OniDataConnection.LoadDatFilePart(fileid,$A0,SizeOf(img_addr),@img_addr);
-
-    case Self.FStoreType of
-      0,1,2: begin
-          SetLength(Self.FData, Self.FWidth * Self.FHeight * 2);
-          Self.FDepth:=16;
-        end;
-      8: begin
-          SetLength(Self.FData, Self.FWidth * Self.FHeight * 4);
-          Self.FDepth:=32;
-        end;
-      9: begin
-          SetLength(Self.FData, Self.FWidth * Self.FHeight div 2);
-          Self.FDepth:=16;
-        end;
-    else
-      Result:=False;
-      Exit;
-    end;
-
-    if not OniDataConnection.OSisMac then
-      OniDataConnection.LoadRawFile(fileid,$9C,@Self.FData[0])
-    else
-      OniDataConnection.LoadRawFile(fileid,$A0,@Self.FData[0]);
-
-    Self.FDataType:=[DT_OniReverted,DT_Oni];
-  end;
-
-
-
-function TOniImage.LoadFromTXMB(fileid:LongWord):Boolean;
-  var
-    i,x,y,x2,y2,pixelid,imgid:LongWord;
-    rows,cols:Word;
-    linkcount:LongWord;
-    link:LongWord;
-    images_decoded:Array of TOniImage;
-    x_start,y_start:LongWord;
-  begin
-    OniDataConnection.LoadDatFilePart(fileid,$10,SizeOf(Self.FWidth),@Self.FWidth);
-    OniDataConnection.LoadDatFilePart(fileid,$12,SizeOf(Self.FHeight),@Self.FHeight);
-    OniDataConnection.LoadDatFilePart(fileid,$18,SizeOf(cols),@cols);
-    OniDataConnection.LoadDatFilePart(fileid,$1A,SizeOf(rows),@rows);
-    OniDataConnection.LoadDatFilePart(fileid,$1C,SizeOf(linkcount),@linkcount);
-    SetLength(images_decoded,linkcount);
-    for i:=0 to linkcount-1 do begin
-      OniDataConnection.LoadDatFilePart(fileid,$20+i*4,SizeOf(link),@link);
-      link:=link div 256;
-      images_decoded[i]:=TOniImage.Create;
-      images_decoded[i].LoadFromTXMP(link);
-      images_decoded[i].DecodeImage;
-      images_decoded[i].RevertImage;
-    end;
-    SetLength(Self.FData, Self.FWidth * Self.FHeight * 4);
-    for y:=0 to rows-1 do begin
-      for x:=0 to cols-1 do begin
-        imgid:=y*cols+x;
-        x_start:=0;
-        y_start:=0;
-        for i:=0 to x do   if i<x then x_start:=x_start+images_decoded[i].Width;
-        for i:=0 to y do   if i<y then y_start:=y_start+images_decoded[i].Height;
-        for y2:=0 to images_decoded[imgid].Height-1 do begin
-          for x2:=0 to images_decoded[imgid].Width-1 do begin
-            if ( (x_start+x2)<Self.FWidth ) and ( (y_start+y2)<Self.FHeight ) then begin
-              pixelid:=y_start*Self.FWidth+x_start+y2*Self.FWidth+x2;
-              Self.FData[pixelid*4+0]:=images_decoded[imgid].Data[(y2*images_decoded[imgid].Width+x2)*4+0];
-              Self.FData[pixelid*4+1]:=images_decoded[imgid].Data[(y2*images_decoded[imgid].Width+x2)*4+1];
-              Self.FData[pixelid*4+2]:=images_decoded[imgid].Data[(y2*images_decoded[imgid].Width+x2)*4+2];
-              Self.FData[pixelid*4+3]:=images_decoded[imgid].Data[(y2*images_decoded[imgid].Width+x2)*4+3];
-            end;
-          end;
-        end;
-      end;
-    end;
-    for i:=0 to linkcount-1 do
-      images_decoded[i].Free;
-    Self.FDepth:=32;
-    Self.FStoreType:=8;
-    Self.FDataType:=[DT_Decoded32];
-    Self.RevertImage;
-  end;
-
-
-
-function TOniImage.GetImageDataSize(fading:Boolean):LongWord;
-  var
-    size:LongWord;
-    x,y:Word;
-    bpp:Byte;
-  begin
-    case Self.FStoreType of
-        9: bpp:=8;
-        0,1,2: bpp:=16;
-        8: bpp:=32;
-    else
-      Result:=0;
-      Exit;
-    end;
-
-    x:=Self.FWidth;
-    y:=Self.FHeight;
-    size:=x*y*bpp div 8;
-    if fading then begin
-      repeat
-        x:=x div 2;
-        y:=y div 2;
-        size:=size+x*y*bpp div 8;
-      until (x=1) or (y=1);
-    end;
-    Result:=size;
-  end;
-
-
-
-function TOniImage.GetAsData:Tdata;
-  var
-    i: Integer;
-    revert:Boolean;
-  begin
-//    if not (DT_Decoded32 in Self.FDataType) then
-//      Self.DecodeImage;
-    if not (DT_OniReverted in Self.FDataType) then begin
-      revert:=True;
-      Self.RevertImage;
-    end else revert:=False;
-    SetLength(Result, Length(Self.FData));
-    for i:=0 to High(Result) do
-      Result[i]:=Self.FData[i];
-    if revert then
-      Self.RevertImage;
-  end;
-
-
-
-function TOniImage.GetAs32bit:Tdata;
-  var
-    i:Integer;
-  begin
-    if not (DT_Decoded32 in Self.FDataType) then
-      Self.DecodeImage;
-    SetLength(Result,Length(Self.FData));
-    for i:=0 to High(Result) do
-      Result[i]:=Self.FData[i];
-  end;
-
-
-
-function TOniImage.GetAsBMP:Tdata;
-  const BMPheader:Array[0..53] of Byte=
-          ($42,$4D,0,0,0,0,0,0,0,0,54,0,0,0,
-           40,0,0,0,0,0,0,0,0,0,0,0,1,0,$18,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
-  var
-    i,x,y:LongWord;
-  begin
-    if not (DT_Decoded32 in Self.FDataType) then
-      Self.DecodeImage;
-
-    SetLength(Result, Self.FWidth * Self.FHeight * 3 + 54);
-    for y:=0 to Self.FHeight-1 do begin
-      for x:=0 to Self.FWidth-1 do begin
-        Result[((Self.FWidth*y+x)*3)+0+54]:=Self.FData[(Self.FWidth*y+x)*4+0];
-        Result[((Self.FWidth*y+x)*3)+1+54]:=Self.FData[(Self.FWidth*y+x)*4+1];
-        Result[((Self.FWidth*y+x)*3)+2+54]:=Self.FData[(Self.FWidth*y+x)*4+2];
-      end;
-    end;
-
-    for i:=0 to High(BMPheader) do
-      Result[i]:=BMPheader[i];
-    Result[2]:=((Self.FWidth*Self.FHeight*3+54) and $000000FF) div $1;
-    Result[3]:=((Self.FWidth*Self.FHeight*3+54) and $0000FF00) div $100;
-    Result[4]:=((Self.FWidth*Self.FHeight*3+54) and $00FF0000) div $10000;
-    Result[5]:=((Self.FWidth*Self.FHeight*3+54) and $FF000000) div $1000000;
-    Result[18]:=(Self.FWidth and $000000FF) div $1;
-    Result[19]:=(Self.FWidth and $0000FF00) div $100;
-    Result[20]:=(Self.FWidth and $00FF0000) div $10000;
-    Result[21]:=(Self.FWidth and $FF000000) div $1000000;
-    Result[22]:=(Self.FHeight and $000000FF) div $1;
-    Result[23]:=(Self.FHeight and $0000FF00) div $100;
-    Result[24]:=(Self.FHeight and $00FF0000) div $10000;
-    Result[25]:=(Self.FHeight and $FF000000) div $1000000;
-    Result[34]:=((Self.FWidth*Self.FHeight*3) and $000000FF) div $1;
-    Result[35]:=((Self.FWidth*Self.FHeight*3) and $0000FF00) div $100;
-    Result[36]:=((Self.FWidth*Self.FHeight*3) and $00FF0000) div $10000;
-    Result[37]:=((Self.FWidth*Self.FHeight*3) and $FF000000) div $1000000;
-  end;
-
-
-
-function TOniImage.LoadFromBMP(filename:String):Boolean;
-  var
-    filestream:TFileStream;
-    tempd:Tdata;
-
-    x,y:LongWord;
-  begin
-    filestream:=TFileStream.Create(filename, fmOpenRead);
-    SetLength(tempd,filestream.Size);
-    filestream.Read(tempd[0],filestream.Size);
-    filestream.Free;
-
-    if not((tempd[00]=$42) and (tempd[01]=$4D)) then begin
-      Result:=False;
-      ShowMessage('Not a standard 24bit bitmap');
-      Exit;
-    end;
-    if not(tempd[10]=54) then begin
-      Result:=False;
-      ShowMessage('Imagedata has to start at 0x54');
-      Exit;
-    end;
-    if not(tempd[14]=40) then begin
-      Result:=False;
-      ShowMessage('Second bitmap header has to have 40 bytes');
-      Exit;
-    end;
-    if not(tempd[28]=24) then begin
-      Result:=False;
-      ShowMessage('Bitmap has to have 24bits');
-      Exit;
-    end;
-    if not(tempd[30]=0) then begin
-      Result:=False;
-      ShowMessage('Bitmap has to be uncompressed');
-      Exit;
-    end;
-
-    Self.FWidth :=tempd[18]+tempd[19]*256+tempd[20]*256*256+tempd[21]*256*256*256;
-    Self.FHeight:=tempd[22]+tempd[23]*256+tempd[24]*256*256+tempd[25]*256*256*256;
-    Self.FDepth:=32;
-    Self.FStoreType:=8;
-
-    SetLength(Self.FData, Self.FWidth * Self.FHeight * Self.FDepth div 8);
-    for y:=0 to Self.FHeight-1 do begin
-      for x:=0 to Self.FWidth-1 do begin
-        Self.FData[((Self.FWidth*y+x)*4)+0]:=tempd[54+(Self.FWidth*y+x)*3+0];
-        Self.FData[((Self.FWidth*y+x)*4)+1]:=tempd[54+(Self.FWidth*y+x)*3+1];
-        Self.FData[((Self.FWidth*y+x)*4)+2]:=tempd[54+(Self.FWidth*y+x)*3+2];
-        Self.FData[((Self.FWidth*y+x)*4)+3]:=0;
-      end;
-    end;
-
-    Self.FDataType:=[DT_Decoded32];
-  end;
-
-
-
-function TOniImage.WriteToBMP(filename:String):Boolean;
-  var
-    filestream:TFileStream;
-    tempd:Tdata;
-  begin
-    tempd:=Self.GetAsBMP;
-    filestream:=TFileStream.Create(filename,fmCreate);
-    filestream.Write(tempd[0],Length(tempd));
-    filestream.Free;
-  end;
-
-
-
-function TOniImage.GetMipMappedImage(var faded:Tdata):Boolean;
-  var
-    i:LongWord;
-    x,y:Word;
-    fadelvldata:Tdata;
-    revert:Boolean;
-  begin
-    Result:=False;
-
-//    if not (DT_Decoded32 in Self.FDataType) then
-//      Self.DecodeImage;
-    if Self.FStoreType=9 then
-      Self.DecompressImage;
-    if not (DT_OniReverted in Self.FDataType) then begin
-      revert:=True;
-      Self.RevertImage;
-    end else revert:=False;
-
-    x:=Self.FWidth;
-    y:=Self.FHeight;
-    SetLength(faded,x*y*Self.FDepth div 8);
-    SetLength(fadelvldata,x*y*Self.FDepth div 8);
-    for i:=0 to Length(faded)-1 do begin
-      faded[i]:=Self.FData[i];
-      fadelvldata[i]:=Self.FData[i];
-    end;
-    repeat
-      fadelvldata:=Self.ResizeImage(x,y,fadelvldata);
-      x:=x div 2;
-      y:=y div 2;
-      SetLength(faded,Length(faded)+x*y*Self.FDepth div 8);
-      for i:=0 to Length(fadelvldata)-1 do
-        faded[Length(faded)-x*y*Self.FDepth div 8+i]:=fadelvldata[i];
-    until (x=1) or (y=1) or ((x mod 2)=1) or ((y mod 2)=1);
-    if (x>1) and (y>1) then Exit;
-    Result:=True;
-
-    if revert then
-      Self.RevertImage;
-  end;
-
-
-end.
Index: oup/current/Unit7_txmpreplace.dfm
===================================================================
--- oup/current/Unit7_txmpreplace.dfm	(revision 40)
+++ 	(revision )
@@ -1,178 +1,0 @@
-object Form7: TForm7
-  Left = 0
-  Top = 0
-  BorderStyle = bsSingle
-  Caption = 'TXMP Replacer'
-  ClientHeight = 428
-  ClientWidth = 394
-  Color = clBtnFace
-  Font.Charset = DEFAULT_CHARSET
-  Font.Color = clWindowText
-  Font.Height = -11
-  Font.Name = 'Tahoma'
-  Font.Style = []
-  FormStyle = fsMDIChild
-  OldCreateOrder = False
-  Visible = True
-  WindowState = wsMaximized
-  OnClose = FormClose
-  OnCreate = FormCreate
-  PixelsPerInch = 96
-  TextHeight = 13
-  object panel_12: TPanel
-    Left = 0
-    Top = 0
-    Width = 394
-    Height = 349
-    Align = alClient
-    BevelOuter = bvNone
-    TabOrder = 0
-    object Splitter1: TSplitter
-      Left = 200
-      Top = 0
-      Width = 8
-      Height = 349
-      AutoSnap = False
-      Beveled = True
-      MinSize = 150
-    end
-    object group_txmpselect: TGroupBox
-      Left = 0
-      Top = 0
-      Width = 200
-      Height = 349
-      Align = alLeft
-      Caption = '1. Select TXMP to replace'
-      TabOrder = 0
-      object splitter_txmp: TSplitter
-        Left = 2
-        Top = 190
-        Width = 196
-        Height = 8
-        Cursor = crVSplit
-        Align = alTop
-        AutoSnap = False
-        Beveled = True
-        MinSize = 60
-      end
-      object image_txmppreview: TImage
-        Left = 2
-        Top = 198
-        Width = 196
-        Height = 119
-        Align = alClient
-      end
-      object list_txmp: TListBox
-        Left = 2
-        Top = 15
-        Width = 196
-        Height = 175
-        Align = alTop
-        ItemHeight = 13
-        TabOrder = 0
-        OnClick = list_txmpClick
-      end
-      object panel_txmppreview: TPanel
-        Left = 2
-        Top = 317
-        Width = 196
-        Height = 30
-        Align = alBottom
-        BevelOuter = bvNone
-        TabOrder = 1
-        object btn_save: TButton
-          Left = 2
-          Top = 2
-          Width = 111
-          Height = 25
-          Caption = 'Save TXMP-Picture'
-          TabOrder = 0
-          OnClick = btn_saveClick
-        end
-      end
-    end
-    object group_bmpselect: TGroupBox
-      Left = 208
-      Top = 0
-      Width = 186
-      Height = 349
-      Align = alClient
-      Caption = '2. Open BMP to replace with'
-      Enabled = False
-      TabOrder = 1
-      object image_bmppreview: TImage
-        Left = 2
-        Top = 45
-        Width = 182
-        Height = 302
-        Align = alClient
-      end
-      object panel_load: TPanel
-        Left = 2
-        Top = 15
-        Width = 182
-        Height = 30
-        Align = alTop
-        BevelOuter = bvNone
-        TabOrder = 0
-        object btn_load: TButton
-          Left = 2
-          Top = 2
-          Width = 121
-          Height = 25
-          Caption = 'Load BMP ...'
-          TabOrder = 0
-          OnClick = btn_loadClick
-        end
-      end
-    end
-  end
-  object group_options: TGroupBox
-    Left = 0
-    Top = 349
-    Width = 394
-    Height = 79
-    Align = alBottom
-    Caption = '3. Options && Replace'
-    Enabled = False
-    TabOrder = 1
-    object btn_replace: TButton
-      Left = 4
-      Top = 50
-      Width = 157
-      Height = 25
-      Caption = 'Replace'
-      TabOrder = 0
-      OnClick = btn_replaceClick
-    end
-    object check_transparency: TCheckBox
-      Left = 8
-      Top = 16
-      Width = 105
-      Height = 17
-      Caption = 'Transparency'
-      TabOrder = 1
-    end
-    object check_fading: TCheckBox
-      Left = 8
-      Top = 32
-      Width = 105
-      Height = 17
-      Caption = 'MIP Mapping'
-      TabOrder = 2
-    end
-  end
-  object opend: TOpenDialog
-    Filter = '24bit Bitmap (*.bmp)|*.bmp'
-    Options = [ofPathMustExist, ofFileMustExist, ofEnableSizing]
-    Left = 352
-    Top = 16
-  end
-  object saved: TSaveDialog
-    DefaultExt = 'bmp'
-    Filter = 'Windows Bitmap (*.bmp)|*.bmp'
-    Options = [ofOverwritePrompt, ofHideReadOnly, ofPathMustExist, ofEnableSizing]
-    Left = 104
-    Top = 320
-  end
-end
Index: oup/current/Unit7_txmpreplace.pas
===================================================================
--- oup/current/Unit7_txmpreplace.pas	(revision 40)
+++ 	(revision )
@@ -1,194 +1,0 @@
-UNIT Unit7_txmpreplace;
-INTERFACE
-USES
-  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
-  Dialogs, ExtCtrls, StdCtrls, StrUtils, Unit2_functions, Unit3_data, Unit6_imgfuncs;
-
-TYPE
-  TForm7 = Class(TForm)
-    panel_12: TPanel;
-    group_txmpselect: TGroupBox;
-    splitter_txmp: TSplitter;
-    list_txmp: TListBox;
-    Splitter1: TSplitter;
-    group_bmpselect: TGroupBox;
-    panel_load: TPanel;
-    btn_load: TButton;
-    image_bmppreview: TImage;
-    opend: TOpenDialog;
-    group_options: TGroupBox;
-    btn_replace: TButton;
-    check_transparency: TCheckBox;
-    check_fading: TCheckBox;
-    panel_txmppreview: TPanel;
-    btn_save: TButton;
-    image_txmppreview: TImage;
-    saved: TSaveDialog;
-    procedure FormCreate(Sender: TObject);
-    PROCEDURE btn_saveClick(Sender: TObject);
-    PROCEDURE FormClose(Sender: TObject; var Action: TCloseAction);
-    PROCEDURE btn_replaceClick(Sender: TObject);
-    PROCEDURE btn_loadClick(Sender: TObject);
-    PROCEDURE list_txmpClick(Sender: TObject);
-    PROCEDURE Recreatelist;
-  PRIVATE
-    OniImage_Old:TOniImage;
-    OniImage_New:TOniImage;
-  PUBLIC
-  END;
-
-VAR
-  Form7: TForm7;
-
-IMPLEMENTATION
-USES Unit1_main, Unit15_Classes;
-{$R *.dfm}
-
-PROCEDURE TForm7.Recreatelist;
-  VAR
-    files:TStringArray;
-    i:LongWord;
-  BEGIN
-    list_txmp.Items.Clear;
-    files:=OniDataConnection.GetFilesList('TXMP','',True);
-    IF Length(files)>0 THEN
-      FOR i:=0 TO High(files) DO
-        list_txmp.Items.Add(files[i]);
-    group_bmpselect.Enabled:=False;
-    check_transparency.Checked:=False;
-    check_fading.Checked:=False;
-  END;
-
-  
-PROCEDURE TForm7.list_txmpClick(Sender: TObject);
-  VAR
-    id:LongWord;
-    data:Tdata;
-    mem:TMemoryStream;
-    fadingbyte,depthbyte,storebyte:Byte;
-  BEGIN
-    id:=OniDataConnection.ExtractFileID(list_txmp.Items.Strings[list_txmp.ItemIndex]);
-    OniDataConnection.LoadDatFilePart(id,$88,SizeOf(fadingbyte),@fadingbyte);
-    OniDataConnection.LoadDatFilePart(id,$89,SizeOf(depthbyte),@depthbyte);
-    OniDataConnection.LoadDatFilePart(id,$90,SizeOf(storebyte),@storebyte);
-    check_fading.Checked:=(fadingbyte AND $01)>0;
-    check_transparency.Checked:=(depthbyte AND $04)>0;
-
-    OniImage_Old.LoadFromTXMP(id);
-    data:=OniImage_Old.GetAsBMP;
-    mem:=TMemoryStream.Create;
-    mem.Write(data[0],Length(data));
-    mem.Seek(0,soFromBeginning);
-    image_txmppreview.Picture.Bitmap.LoadFromStream(mem);
-    mem.Free;
-
-    group_bmpselect.Enabled:=True;
-  END;
-
-PROCEDURE TForm7.btn_loadClick(Sender: TObject);
-  VAR
-    mem:TMemoryStream;
-    tempd:Tdata;
-  BEGIN
-    IF opend.Execute THEN BEGIN
-      OniImage_New.LoadFromBMP(opend.FileName);
-      tempd:=OniImage_New.GetAsBMP;
-      mem:=TMemoryStream.Create;
-      mem.Write(tempd[0],Length(tempd));
-      mem.Seek(0,soFromBeginning);
-      image_bmppreview.Picture.Bitmap.LoadFromStream(mem);
-      mem.Free;
-      group_options.Enabled:=True;
-    END;
-  END;
-
-PROCEDURE TForm7.btn_replaceClick(Sender: TObject);
-  VAR
-    id:LongWord;
-
-    oldsize,newsize:LongWord;
-    old_rawaddr,new_rawaddr:LongWord;
-    oldfading:Byte;
-    tempd:Tdata;
-
-    datbyte:Word;
-  BEGIN
-    IF list_txmp.ItemIndex>=0 THEN BEGIN
-      id:=OniDataConnection.ExtractFileID(list_txmp.Items.Strings[list_txmp.ItemIndex]);
-      OniDataConnection.LoadDatFilePart(id,$88,1,@oldfading);
-      if OniDataConnection.OSisMac then
-        OniDataConnection.UpdateDatFilePart(id,$A0,4,@old_rawaddr)
-      else
-        OniDataConnection.LoadDatFilePart(id,$9C,4,@old_rawaddr);
-
-      IF (OniImage_Old.Width<>OniImage_New.Width) OR (OniImage_Old.Height<>OniImage_New.Height) THEN BEGIN
-        IF MessageBox(Self.Handle,
-                    PChar('Current image and new image have different size'+CrLf+
-                            '(Current: '+IntToStr(OniImage_Old.Width)+'x'+IntToStr(OniImage_Old.Height)+
-                            ' - New: '+IntToStr(OniImage_New.Width)+'x'+IntToStr(OniImage_New.Height)+')'+CrLf+
-                            'Replace anyways?'),
-                    PChar(list_txmp.Items.Strings[list_txmp.ItemIndex]),
-                    MB_YESNO)=IDNO THEN Exit;
-      END;
-
-      oldsize:=OniImage_Old.GetImageDataSize((oldfading and $01)>0);
-
-      IF check_fading.Checked THEN
-        IF NOT OniImage_New.GetMipMappedImage(tempd) THEN
-          IF MessageBox(Self.Handle, PChar('Can not create a MipMapped-image (probably because of a wrong dimension).'+#13+#10+'Do you want to continue without MipMapping?'), PChar('Warning'), MB_YESNO)=ID_YES THEN
-            check_fading.Checked:=False
-          ELSE
-            Exit;
-
-      IF NOT check_fading.Checked THEN
-        tempd:=OniImage_New.GetAsData;
-
-      newsize:=OniImage_New.GetImageDataSize(check_fading.Checked);
-      ShowMessage(IntToStr(newsize));
-
-      IF (newsize>oldsize) AND (OniDataConnection.Backend=ODB_Dat) THEN
-        new_rawaddr:=OniDataConnection.AppendRawFile(OniDataConnection.OSisMac,Length(tempd),tempd)
-      ELSE BEGIN
-        new_rawaddr:=old_rawaddr;
-        OniDataConnection.UpdateRawFile(id,$9C,Length(tempd),tempd);
-      END;
-
-      datbyte:=$00;
-      IF check_fading.Checked THEN datbyte:=datbyte OR $01;
-      OniDataConnection.UpdateDatFilePart(id,$88,1,@datbyte);
-      datbyte:=$10;
-      IF check_transparency.Checked THEN datbyte:=datbyte OR $04;
-      OniDataConnection.UpdateDatFilePart(id,$89,1,@datbyte);
-      OniDataConnection.UpdateDatFilePart(id,$8C,2,@OniImage_New.Width);
-      OniDataConnection.UpdateDatFilePart(id,$8E,2,@OniImage_New.Height);
-      datbyte:=$08;
-      OniDataConnection.UpdateDatFilePart(id,$90,1,@datbyte);
-      if OniDataConnection.OSisMac then
-        OniDataConnection.UpdateDatFilePart(id,$A0,4,@new_rawaddr)
-      else
-        OniDataConnection.UpdateDatFilePart(id,$9C,4,@new_rawaddr);
-
-      ShowMessage('TXMP-image replaced');
-    END;
-  END;
-
-PROCEDURE TForm7.FormClose(Sender: TObject; var Action: TCloseAction);
-  BEGIN
-    OniImage_Old.Free;
-    OniImage_New.Free;
-    Action:=caFree;
-  END;
-
-PROCEDURE TForm7.FormCreate(Sender: TObject);
-  BEGIN
-    OniImage_Old:=TOniImage.Create;
-    OniImage_New:=TOniImage.Create;
-  END;
-
-PROCEDURE TForm7.btn_saveClick(Sender: TObject);
-  BEGIN
-    IF saved.Execute THEN
-      OniImage_Old.WriteToBMP(saved.FileName);
-  END;
-
-END.
Index: oup/current/Unit8_binedit.dfm
===================================================================
--- oup/current/Unit8_binedit.dfm	(revision 40)
+++ 	(revision )
@@ -1,384 +1,0 @@
-object Form8: TForm8
-  Left = 0
-  Top = 0
-  BorderIcons = [biSystemMenu, biMaximize]
-  Caption = 'Binary .dat-Editor'
-  ClientHeight = 555
-  ClientWidth = 642
-  Color = clBtnFace
-  Font.Charset = DEFAULT_CHARSET
-  Font.Color = clWindowText
-  Font.Height = -11
-  Font.Name = 'Tahoma'
-  Font.Style = []
-  FormStyle = fsMDIChild
-  KeyPreview = True
-  OldCreateOrder = False
-  Visible = True
-  WindowState = wsMaximized
-  OnClose = FormClose
-  OnCloseQuery = FormCloseQuery
-  OnCreate = FormCreate
-  OnKeyUp = FormKeyUp
-  OnResize = FormResize
-  PixelsPerInch = 96
-  TextHeight = 13
-  object Splitter1: TSplitter
-    Left = 150
-    Top = 0
-    Width = 9
-    Height = 555
-    AutoSnap = False
-    Beveled = True
-    MinSize = 150
-    ExplicitHeight = 423
-  end
-  object panel_data: TPanel
-    Left = 159
-    Top = 0
-    Width = 483
-    Height = 555
-    Align = alClient
-    BevelOuter = bvNone
-    TabOrder = 0
-    object Splitter2: TSplitter
-      Left = 0
-      Top = 209
-      Width = 483
-      Height = 9
-      Cursor = crVSplit
-      Align = alTop
-      AutoSnap = False
-      Beveled = True
-      MinSize = 40
-    end
-    object Splitter3: TSplitter
-      Left = 0
-      Top = 450
-      Width = 483
-      Height = 8
-      Cursor = crVSplit
-      Align = alBottom
-      AutoSnap = False
-      Beveled = True
-      MinSize = 40
-      ExplicitTop = 375
-    end
-    object hex: TMPHexEditor
-      Left = 0
-      Top = 0
-      Width = 483
-      Height = 209
-      Cursor = crIBeam
-      Align = alTop
-      Font.Charset = DEFAULT_CHARSET
-      Font.Color = clWindowText
-      Font.Height = -16
-      Font.Name = 'Courier'
-      Font.Style = []
-      OnKeyUp = hexKeyUp
-      ParentFont = False
-      TabOrder = 0
-      BytesPerRow = 16
-      Translation = tkASCII
-      OffsetFormat = '6!10:0x|'
-      Colors.Background = clWindow
-      Colors.ChangedBackground = clWindow
-      Colors.ChangedText = clRed
-      Colors.CursorFrame = clNavy
-      Colors.Offset = clBlack
-      Colors.OddColumn = clBlue
-      Colors.EvenColumn = clNavy
-      Colors.CurrentOffsetBackground = clBtnShadow
-      Colors.OffsetBackGround = clBtnFace
-      Colors.CurrentOffset = clBtnHighlight
-      Colors.Grid = clBtnFace
-      Colors.NonFocusCursorFrame = clAqua
-      Colors.ActiveFieldBackground = clWindow
-      FocusFrame = True
-      NoSizeChange = True
-      AllowInsertMode = False
-      DrawGridLines = False
-      Version = 'May 23, 2005; '#169' markus stephany, vcl[at]mirkes[dot]de'
-      OnChange = hexChange
-      ShowPositionIfNotFocused = True
-      OnSelectionChanged = hexSelectionChanged
-    end
-    object value_viewer: TWrapGrid
-      Left = 0
-      Top = 218
-      Width = 483
-      Height = 232
-      Align = alClient
-      ColCount = 1
-      DefaultColWidth = 80
-      DefaultRowHeight = 18
-      FixedCols = 0
-      RowCount = 8
-      FixedRows = 0
-      Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goColSizing]
-      PopupMenu = value_viewer_context
-      TabOrder = 1
-      OnDblClick = value_viewerDblClick
-      OnMouseDown = value_viewerMouseDown
-    end
-    object VST: TVirtualStringTree
-      Left = 0
-      Top = 458
-      Width = 483
-      Height = 97
-      Align = alBottom
-      AnimationDuration = 0
-      AutoExpandDelay = 300
-      BiDiMode = bdLeftToRight
-      Colors.UnfocusedSelectionColor = clGradientActiveCaption
-      Colors.UnfocusedSelectionBorderColor = clGradientActiveCaption
-      Ctl3D = True
-      DragOperations = []
-      DrawSelectionMode = smBlendedRectangle
-      EditDelay = 200
-      Font.Charset = DEFAULT_CHARSET
-      Font.Color = clWindowText
-      Font.Height = -11
-      Font.Name = 'Tahoma'
-      Font.Style = []
-      Header.AutoSizeIndex = 0
-      Header.Font.Charset = DEFAULT_CHARSET
-      Header.Font.Color = clWindowText
-      Header.Font.Height = -11
-      Header.Font.Name = 'Tahoma'
-      Header.Font.Style = []
-      Header.Options = [hoColumnResize, hoDblClickResize, hoDrag, hoVisible]
-      Header.PopupMenu = VTHPopup
-      Header.Style = hsFlatButtons
-      HintAnimation = hatNone
-      HintMode = hmTooltip
-      Indent = 14
-      ParentBiDiMode = False
-      ParentCtl3D = False
-      ParentFont = False
-      ParentShowHint = False
-      ShowHint = True
-      TabOrder = 2
-      TreeOptions.MiscOptions = [toAcceptOLEDrop, toCheckSupport, toFullRepaintOnResize, toInitOnSave, toToggleOnDblClick, toWheelPanning]
-      TreeOptions.PaintOptions = [toShowButtons, toShowDropmark, toShowHorzGridLines, toShowRoot, toShowTreeLines, toShowVertGridLines, toUseBlendedImages]
-      TreeOptions.SelectionOptions = [toExtendedFocus, toFullRowSelect, toRightClickSelect]
-      OnDblClick = VSTDblClick
-      OnFocusChanged = VSTFocusChanged
-      OnGetText = VSTGetText
-      OnHeaderDragged = VSTHeaderDragged
-      Columns = <
-        item
-          MaxWidth = 300
-          MinWidth = 100
-          Options = [coEnabled, coParentBidiMode, coParentColor, coResizable, coShowDropMark, coVisible]
-          Position = 0
-          Spacing = 20
-          Width = 150
-          WideText = 'Name'
-          WideHint = 'Name of the item.'
-        end
-        item
-          MaxWidth = 110
-          MinWidth = 80
-          Options = [coDraggable, coEnabled, coParentBidiMode, coParentColor, coResizable, coShowDropMark, coVisible]
-          Position = 1
-          Spacing = 20
-          Width = 85
-          WideText = 'Offset'
-          WideHint = 'Offset of the data-item.'
-        end
-        item
-          MaxWidth = 110
-          MinWidth = 75
-          Options = [coDraggable, coEnabled, coParentBidiMode, coParentColor, coResizable, coShowDropMark, coVisible]
-          Position = 2
-          Width = 75
-          WideText = 'Type'
-          WideHint = 'Data type of the item.'
-        end
-        item
-          MaxWidth = 250
-          MinWidth = 80
-          Options = [coDraggable, coEnabled, coParentBidiMode, coParentColor, coResizable, coShowDropMark, coVisible]
-          Position = 3
-          Width = 100
-          WideText = 'Value'
-          WideHint = 'Value of the item.'
-        end
-        item
-          MaxWidth = 400
-          MinWidth = 80
-          Options = [coDraggable, coEnabled, coParentBidiMode, coParentColor, coResizable, coShowDropMark, coVisible]
-          Position = 4
-          Width = 400
-          WideText = 'Description'
-        end>
-      WideDefaultText = ''
-    end
-  end
-  object panel_files: TPanel
-    Left = 0
-    Top = 0
-    Width = 150
-    Height = 555
-    Align = alLeft
-    BevelOuter = bvNone
-    TabOrder = 1
-    object Bevel1: TBevel
-      Left = 0
-      Top = 491
-      Width = 150
-      Height = 6
-      Align = alBottom
-      Style = bsRaised
-      ExplicitTop = 359
-    end
-    object list: TListBox
-      Left = 0
-      Top = 0
-      Width = 150
-      Height = 388
-      Align = alClient
-      ItemHeight = 13
-      TabOrder = 0
-      OnClick = listClick
-    end
-    object panel_extension: TPanel
-      Left = 0
-      Top = 388
-      Width = 150
-      Height = 103
-      Align = alBottom
-      BevelOuter = bvNone
-      TabOrder = 1
-      OnResize = panel_extensionResize
-      object lbl_filter: TLabel
-        Left = 2
-        Top = 62
-        Width = 100
-        Height = 17
-        AutoSize = False
-        Caption = 'Filter by &extension:'
-        FocusControl = combo_extension
-      end
-      object combo_extension: TComboBox
-        Left = 2
-        Top = 76
-        Width = 145
-        Height = 21
-        Style = csDropDownList
-        DropDownCount = 12
-        Font.Charset = DEFAULT_CHARSET
-        Font.Color = clWindowText
-        Font.Height = -11
-        Font.Name = 'Tahoma'
-        Font.Style = []
-        ItemHeight = 13
-        ParentFont = False
-        Sorted = True
-        TabOrder = 3
-        OnClick = combo_extensionClick
-      end
-      object check_zerobyte: TCheckBox
-        Left = 2
-        Top = 44
-        Width = 130
-        Height = 13
-        Caption = 'Show &zero-byte files'
-        TabOrder = 2
-        OnClick = check_zerobyteClick
-      end
-      object edit_filtername: TEdit
-        Left = 2
-        Top = 20
-        Width = 145
-        Height = 18
-        AutoSize = False
-        TabOrder = 1
-      end
-      object check_filtername: TCheckBox
-        Left = 2
-        Top = 5
-        Width = 130
-        Height = 15
-        Caption = 'Filter by file&name:'
-        TabOrder = 0
-        OnClick = check_filternameClick
-      end
-    end
-    object panel_imexport: TPanel
-      Left = 0
-      Top = 497
-      Width = 150
-      Height = 58
-      Align = alBottom
-      BevelOuter = bvNone
-      TabOrder = 2
-      OnResize = panel_imexportResize
-      object btn_export: TButton
-        Left = 4
-        Top = 4
-        Width = 142
-        Height = 25
-        Caption = 'Export to file...'
-        TabOrder = 0
-        OnClick = btn_exportClick
-      end
-      object btn_import: TButton
-        Left = 4
-        Top = 32
-        Width = 142
-        Height = 25
-        Caption = 'Import from file...'
-        TabOrder = 1
-        OnClick = btn_importClick
-      end
-    end
-  end
-  object opend: TOpenDialog
-    Options = [ofPathMustExist, ofFileMustExist, ofEnableSizing]
-    Left = 120
-    Top = 392
-  end
-  object saved: TSaveDialog
-    Options = [ofOverwritePrompt, ofPathMustExist, ofEnableSizing]
-    Left = 120
-    Top = 368
-  end
-  object value_viewer_context: TPopupMenu
-    AutoHotkeys = maManual
-    OnPopup = value_viewer_contextPopup
-    Left = 240
-    Top = 248
-    object value_viewer_context_copy: TMenuItem
-      Caption = 'Copy to &clipboard'
-      OnClick = value_viewer_context_copyClick
-    end
-    object value_viewer_context_copyasdec: TMenuItem
-      Caption = 'Copy to clipboard (as &dec)'
-      OnClick = value_viewer_context_copyClick
-    end
-    object value_viewer_context_copyasfloat: TMenuItem
-      Caption = 'Copy to clipboard (as &float)'
-      OnClick = value_viewer_context_copyClick
-    end
-    object value_viewer_context_copyasbitset: TMenuItem
-      Caption = 'Copy to clipboard (as &bitset)'
-      OnClick = value_viewer_context_copyClick
-    end
-    object value_viewer_context_copyasstring: TMenuItem
-      Caption = 'Copy to clipboard (as &string)'
-      OnClick = value_viewer_context_copyClick
-    end
-    object value_viewer_context_copyashex: TMenuItem
-      Caption = 'Copy to clipboard (as &hex)'
-      OnClick = value_viewer_context_copyClick
-    end
-  end
-  object VTHPopup: TVTHeaderPopupMenu
-    OnColumnChange = VTHPopupColumnChange
-    Left = 200
-    Top = 496
-  end
-end
Index: oup/current/Unit8_binedit.pas
===================================================================
--- oup/current/Unit8_binedit.pas	(revision 40)
+++ 	(revision )
@@ -1,894 +1,0 @@
-UNIT Unit8_binedit;
-INTERFACE
-USES
-  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
-  Dialogs, Wrapgrid, StdCtrls, Grids, StrUtils, MPHexEditor, ExtCtrls, Clipbrd,
-  Unit3_data, Unit2_functions, Unit9_data_structures, Unit4_exporters, Unit15_Classes,
-  Menus, Math, VirtualTrees, VTHeaderPopup;
-
-TYPE
-  TForm8 = Class(TForm)
-    Splitter1: TSplitter;
-    panel_data: TPanel;
-    hex: TMPHexEditor;
-    Splitter2: TSplitter;
-    panel_files: TPanel;
-    list: TListBox;
-    panel_extension: TPanel;
-    lbl_filter: TLabel;
-    combo_extension: TComboBox;
-    Bevel1: TBevel;
-    panel_imexport: TPanel;
-    btn_export: TButton;
-    btn_import: TButton;
-    opend: TOpenDialog;
-    saved: TSaveDialog;
-    value_viewer: TWrapGrid;
-    Splitter3: TSplitter;
-    value_viewer_context: TPopupMenu;
-    value_viewer_context_copy: TMenuItem;
-    value_viewer_context_copyashex: TMenuItem;
-    value_viewer_context_copyasdec: TMenuItem;
-    value_viewer_context_copyasfloat: TMenuItem;
-    value_viewer_context_copyasbitset: TMenuItem;
-    value_viewer_context_copyasstring: TMenuItem;
-    check_zerobyte: TCheckBox;
-    edit_filtername: TEdit;
-    check_filtername: TCheckBox;
-    VST: TVirtualStringTree;
-    VTHPopup: TVTHeaderPopupMenu;
-    procedure VSTFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode;
-      Column: TColumnIndex);
-    procedure VSTDblClick(Sender: TObject);
-    procedure VTHPopupColumnChange(const Sender: TBaseVirtualTree;
-      const Column: TColumnIndex; Visible: Boolean);
-    procedure VSTHeaderDragged(Sender: TVTHeader; Column: TColumnIndex;
-      OldPosition: Integer);
-    procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
-      Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
-    procedure hexKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
-    PROCEDURE LoadDat(_fileid:LongWord);
-    PROCEDURE LoadFileNames;
-    PROCEDURE check_filternameClick(Sender: TObject);
-    PROCEDURE check_zerobyteClick(Sender: TObject);
-    PROCEDURE combo_extensionClick(Sender: TObject);
-    PROCEDURE panel_extensionResize(Sender: TObject);
-    PROCEDURE listClick(Sender: TObject);
-    PROCEDURE Recreatelist;
-
-    PROCEDURE FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
-    PROCEDURE value_viewerDblClick(Sender: TObject);
-    PROCEDURE value_viewer_context_copyClick(Sender: TObject);
-    PROCEDURE value_viewerMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
-    PROCEDURE value_viewer_contextPopup(Sender: TObject);
-    PROCEDURE btn_importClick(Sender: TObject);
-    PROCEDURE btn_exportClick(Sender: TObject);
-    PROCEDURE panel_imexportResize(Sender: TObject);
-    FUNCTION Save:Boolean;
-    PROCEDURE FormClose(Sender: TObject; var Action: TCloseAction);
-    FUNCTION GetValue(datatype:Word; offset:LongWord):String;
-    PROCEDURE WriteStructureInfos; //(structinfoid:Integer);
-    PROCEDURE hexSelectionChanged(Sender: TObject);
-    PROCEDURE hexChange(Sender: TObject);
-    PROCEDURE FormResize(Sender: TObject);
-    PROCEDURE ClearStructViewer;
-    PROCEDURE FormCloseQuery(Sender: TObject; var CanClose: Boolean);
-    PROCEDURE FormCreate(Sender: TObject);
-    PROCEDURE ClearValues;
-    PROCEDURE WriteValues;
-    PROCEDURE SetNewValue(datatype:Word; offset:LongWord; value:String);
-  PRIVATE
-    fileid:LongWord;
-  PUBLIC
-  END;
-
-VAR
-  Form8: TForm8;
-
-IMPLEMENTATION
-{$R *.dfm}
-USES Unit1_main, Unit12_ValueEdit, Unit13_rawedit;
-
-TYPE
-  PNodeData = ^TNodeData;
-  TNodeData = record
-    Caption:String;
-    Offset:LongInt;
-    DataType:Word;
-    Value:String;
-    Description:String;
-  end;
-
-
-function AddVSTEntry(AVST:TCustomVirtualStringTree; ANode:PVirtualNode; ARecord:TNodeData):PVirtualNode;
-  var
-    data:PNodeData;
-  begin
-    Result:=AVST.AddChild(ANode);
-    data:=AVST.GetNodeData(Result);
-    AVST.ValidateNode(Result,False);
-    data^:=ARecord;
-  end;
-
-
-
-PROCEDURE TForm8.LoadDat(_fileid:LongWord);
-  VAR
-    i:LongWord;
-    mem:TMemoryStream;
-    data:Tdata;
-  BEGIN
-    IF hex.Modified THEN BEGIN
-      IF NOT Save THEN BEGIN
-        FOR i:=0 TO list.Count-1 DO BEGIN
-          IF OniDataConnection.ExtractFileID(list.Items.Strings[i])=fileid THEN BEGIN
-            list.ItemIndex:=i;
-            Exit;
-          END;
-        END;
-      END;
-    END;
-    fileid:=_fileid;
-    FOR i:=0 TO list.Count-1 DO
-      IF OniDataConnection.ExtractFileID(list.Items.Strings[i])=fileid THEN BEGIN
-        list.ItemIndex:=i;
-        Break;
-      END;
-    Self.ClearStructViewer;
-    data:=OniDataConnection.LoadDatFile(fileid);
-    IF Length(data)>0 THEN BEGIN
-      mem:=TMemoryStream.Create;
-      mem.Write(data[0],Length(data));
-      mem.Seek(0,soFromBeginning);
-      hex.LoadFromStream(mem);
-      mem.Free;
-      WriteStructureInfos; 
-    END ELSE BEGIN
-      ClearValues;
-      hex.DataSize:=0;
-    END;
-  END;
-
-PROCEDURE TForm8.Recreatelist;
-  VAR
-    i:LongWord;
-    exts:TStringArray;
-  BEGIN
-    combo_extension.Items.Clear;
-    combo_extension.Items.Add('_All files_ ('+IntToStr(OniDataConnection.GetFilesCount)+')');
-    exts:=OniDataConnection.GetExtensionsList;
-    FOR i:=0 TO High(exts) DO
-      combo_extension.Items.Add(exts[i]);
-    combo_extension.ItemIndex:=0;
-    combo_extensionClick(Self);
-  END;
-
-PROCEDURE TForm8.LoadFileNames;
-  VAR
-    Extension:String[4];
-    no_zero_bytes:Boolean;
-    pattern:String;
-    files:TStringArray;
-    i:LongWord;
-  BEGIN
-    Extension:=MidStr(combo_extension.Items.Strings[combo_extension.ItemIndex],1,4);
-    no_zero_bytes:=NOT check_zerobyte.Checked;
-    pattern:='';
-    IF check_filtername.Checked THEN pattern:=edit_filtername.Text;
-    IF Extension='_All' THEN Extension:='';
-
-    files:=OniDataConnection.GetFilesList(extension,pattern,no_zero_bytes);
-    list.Items.Clear;
-    IF Length(files)>0 THEN
-      FOR i:=0 TO High(files) DO
-        list.Items.Add(files[i]);
-  END;
-
-PROCEDURE TForm8.panel_extensionResize(Sender: TObject);
-  BEGIN
-    combo_extension.Width:=panel_extension.Width-5;
-    edit_filtername.Width:=panel_extension.Width-5;
-  END;
-
-PROCEDURE TForm8.combo_extensionClick(Sender: TObject);
-  BEGIN
-    LoadFileNames;
-  END;
-
-PROCEDURE TForm8.check_zerobyteClick(Sender: TObject);
-  BEGIN
-    LoadFileNames;
-  END;
-
-PROCEDURE TForm8.check_filternameClick(Sender: TObject);
-  BEGIN
-    edit_filtername.Enabled:=NOT check_filtername.Checked;
-    LoadFileNames;
-  END;
-
-PROCEDURE TForm8.listClick(Sender: TObject);
-  BEGIN
-    LoadDat(OniDataConnection.ExtractFileID(list.Items.Strings[list.ItemIndex]));
-  END;
-
-
-
-
-FUNCTION IntToBin(value:Byte):String;
-  VAR i:Byte;
-  BEGIN
-    Result:='';
-    FOR i:=7 DOWNTO 0 DO BEGIN
-      Result:=Result+IntToStr((value SHR i) AND $01);
-    END;
-  END;
-
-FUNCTION TForm8.GetValue(datatype:Word; offset:LongWord):String;
-  VAR
-    data:Tdata;
-    i:Word;
-  BEGIN
-    CASE datatype OF
-      1: Result:=IntToStr(hex.data[offset]);
-      2: Result:=IntToStr(hex.data[offset]+hex.data[offset+1]*256);
-      3: Result:=IntToStr(hex.data[offset]+hex.data[offset+1]*256+hex.data[offset+2]*256*256);
-      4: Result:=IntToStr(hex.data[offset]+hex.data[offset+1]*256+hex.data[offset+2]*256*256+hex.data[offset+3]*256*256*256);
-      5: Result:='0x'+IntToHex(hex.data[offset],2);
-      6: Result:='0x'+IntToHex(hex.data[offset]+hex.data[offset+1]*256,4);
-      7: Result:='0x'+IntToHex(hex.data[offset]+hex.data[offset+1]*256+hex.data[offset+2]*256*256,6);
-      8: Result:='0x'+IntToHex(hex.data[offset]+hex.data[offset+1]*256+hex.data[offset+2]*256*256+hex.data[offset+3]*256*256*256,8);
-      9: BEGIN
-          SetLength(data,4);
-          data[0]:=hex.data[offset];
-          data[1]:=hex.data[offset+1];
-          data[2]:=hex.data[offset+2];
-          data[3]:=hex.data[offset+3];
-          Result:=FloatToStr(Decode_Float(data));
-        END;
-      10: Result:=IntToBin(hex.data[offset]);
-      11: Result:='0x'+IntToHex(OniDataConnection.GetRawInfo(fileid,offset).raw_addr,8);
-      12: Result:=FormatNumber(hex.data[offset+1]+hex.data[offset+2]*256+hex.data[offset+3]*256*256,5,'0');
-      13: Result:=IntToStr(hex.data[offset]);
-      14: Result:=IntToStr(hex.data[offset]+hex.data[offset+1]*256);
-      15: Result:=IntToStr(hex.data[offset]+hex.data[offset+1]*256+hex.data[offset+2]*256*256);
-      16: Result:=IntToStr(hex.data[offset]+hex.data[offset+1]*256+hex.data[offset+2]*256*256+hex.data[offset+3]*256*256*256);
-      17: Result:=IntToStr((hex.data[offset+3]) DIV 2);
-      100..300: BEGIN
-          Result:='';
-          FOR i:=1 TO datatype-100 DO BEGIN
-            IF hex.Data[offset+i-1]>=32 THEN
-              Result:=Result+Chr(hex.Data[offset+i-1])
-            ELSE
-              Break;
-          END;
-        END;
-      1000..9999: BEGIN
-          Result:='';
-          FOR i:=1 TO datatype-1000 DO BEGIN
-            IF hex.Data[offset+i-1]>=32 THEN
-              Result:=Result+Chr(hex.Data[offset+i-1])
-            ELSE
-              Result:=Result+'.';
-          END;
-        END;
-      10000..65535: BEGIN
-          Result:='';
-          FOR i:=1 TO datatype-10000 DO BEGIN
-            IF hex.Data[offset+i-1]>=32 THEN
-              Result:=Result+Chr(hex.Data[offset+i-1])
-            ELSE
-              Result:=Result+'.';
-          END;
-        END;
-    END;
-  END;
-
-PROCEDURE TForm8.WriteStructureInfos;
-  VAR
-    i,j:LongWord;
-    pdata: PNodeData;
-    data: TNodeData;
-    node: PVirtualNode;
-    structs: TStructDef;
-  BEGIN
-    VST.BeginUpdate;
-    IF VST.RootNodeCount=0 THEN BEGIN
-      structs:=LoadStructureDefinition(fileid);
-      IF structs.data THEN BEGIN
-        IF Length(structs.Global)>0 THEN BEGIN
-          FOR i:=0 TO High(structs.Global) DO BEGIN
-            data.Caption:=structs.Global[i].name;
-            data.Offset:=structs.Global[i].offset;
-            data.DataType:=structs.Global[i].datatype;
-            data.Value:=GetValue(structs.Global[i].datatype, structs.Global[i].offset);
-            data.Description:=structs.Global[i].description;
-            AddVSTEntry(VST, nil, data);
-          END;
-        END;
-        IF Length(structs.Subs)>0 THEN BEGIN
-          FOR i:=0 TO High(structs.Subs) DO BEGIN
-            WITH structs.Subs[i] DO BEGIN
-              IF Length(Entries)>0 THEN BEGIN
-                IF Pos('#',SubName)>0 THEN BEGIN
-                  data.Offset:=HexToLong(MidStr(SubName, Pos('#',SubName)+1, 8));
-                  data.Value:=MidStr(SubName, PosEx('#',SubName,Pos('#',SubName)+1)+1, 8);
-                  data.Caption:=MidStr(SubName, 1, Pos('#',SubName)-1);
-                  data.Description:=SubDesc;
-                END ELSE BEGIN
-                  data.Caption:=SubName;
-                  data.Description:=SubDesc;
-                  data.Offset:=0;
-                  data.Value:='';
-                END;
-                data.DataType:=0;
-                node:=AddVSTEntry(VST, nil, data);
-                data.Description:='';
-                FOR j:=0 TO High(Entries) DO BEGIN
-                  data.Caption:=Entries[j].name;
-                  data.Offset:=Entries[j].offset;
-                  data.DataType:=Entries[j].datatype;
-                  data.Value:=GetValue(Entries[j].datatype, Entries[j].offset);
-                  data.Description:=Entries[j].description;
-                  AddVSTEntry(VST, node, data);
-                END;
-              END;
-            END;
-          END;
-        END;
-      END;
-      IF VST.RootNodeCount>0 THEN
-        VST.FocusedNode:=VST.GetFirst;
-    END ELSE BEGIN
-      Node:=VST.GetFirst;
-      WHILE Assigned(Node) DO BEGIN
-        pdata:=VST.GetNodeData(Node);
-        IF pdata.DataType>0 THEN
-          pdata.Value:=GetValue(pdata.Datatype, pdata.Offset);
-        Node:=VST.GetNext(Node);
-      END;
-    END;
-    VST.EndUpdate;
-  END;
-
-PROCEDURE TForm8.ClearValues;
-  VAR
-    i:Byte;
-  BEGIN
-    FOR i:=1 TO value_viewer.RowCount-1 DO BEGIN
-      value_viewer.Cells[1,i]:='';
-    END;
-  END;
-
-PROCEDURE TForm8.WriteValues;
-  VAR
-    i,j:Byte;
-    data:Tdata;
-    str:String;
-    value:LongWord;
-  BEGIN
-    FOR i:=1 TO value_viewer.RowCount-1 DO BEGIN
-      IF value_viewer.Cells[0,i]='1 byte, unsigned' THEN BEGIN
-        IF ((hex.SelCount=1) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+1)>hex.DataSize) THEN BEGIN
-          value:=hex.Data[hex.SelStart];
-          value_viewer.Cells[1,i]:=IntToStr( value )+' / 0x'+IntToHex( value , 2 );
-        END ELSE
-          value_viewer.Cells[1,i]:='';
-      END;
-      IF value_viewer.Cells[0,i]='2 bytes, unsigned' THEN BEGIN
-        IF ((hex.SelCount=2) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+2)>hex.DataSize) THEN BEGIN
-          value:=hex.Data[hex.SelStart] + hex.Data[hex.SelStart+1]*256;
-          value_viewer.Cells[1,i]:=IntToStr( value )+' / 0x'+IntToHex( value , 4 );
-        END ELSE
-          value_viewer.Cells[1,i]:='';
-      END;
-      IF value_viewer.Cells[0,i]='4 bytes, unsigned' THEN BEGIN
-        IF ((hex.SelCount=4) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+4)>hex.DataSize) THEN BEGIN
-          value:=hex.Data[hex.SelStart]+hex.Data[hex.SelStart+1]*256+hex.Data[hex.SelStart+2]*256*256+hex.Data[hex.SelStart+3]*256*256*256;
-          value_viewer.Cells[1,i]:=IntToStr( value )+' / 0x'+IntToHex( value , 8 );
-        END ELSE
-          value_viewer.Cells[1,i]:='';
-      END;
-      IF value_viewer.Cells[0,i]='Bitset' THEN BEGIN
-        IF (hex.SelCount<=8) THEN BEGIN
-          IF hex.SelCount=0 THEN BEGIN
-            SetLength(data,1);
-            data[0]:=hex.Data[hex.SelStart];
-          END ELSE BEGIN
-            SetLength(data,hex.SelCount);
-            FOR j:=0 TO hex.SelCount-1 DO
-              data[j]:=hex.Data[hex.SelStart+j];
-          END;
-          value_viewer.Cells[1,i]:=DataToBin(data);
-        END ELSE
-          value_viewer.Cells[1,i]:='';
-      END;
-      IF value_viewer.Cells[0,i]='Float' THEN BEGIN
-        IF ((hex.SelCount=4) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+4)>hex.DataSize) THEN BEGIN
-          SetLength(data,4);
-          FOR j:=0 TO 3 DO
-            data[j]:=hex.Data[hex.SelStart+j];
-          value_viewer.Cells[1,i]:=FloatToStr(Decode_Float(data));
-        END ELSE
-          value_viewer.Cells[1,i]:='';
-      END;
-      IF value_viewer.Cells[0,i]='Selected length' THEN BEGIN
-        value_viewer.Cells[1,i]:=IntToStr(hex.SelCount)+' bytes';
-      END;
-      IF value_viewer.Cells[0,i]='String' THEN BEGIN
-        j:=0;
-        str:='';
-        IF hex.SelCount=0 THEN BEGIN
-          WHILE (hex.Data[hex.SelStart+j]>0) AND ((hex.SelStart+j)<hex.DataSize) DO BEGIN
-            IF hex.Data[hex.selstart+j]>=32 THEN
-              str:=str+Char(hex.Data[hex.SelStart+j])
-            ELSE
-              str:=str+'.';
-            Inc(j);
-          END;
-        END ELSE BEGIN
-          FOR j:=0 TO hex.SelCount-1 DO
-            IF hex.Data[hex.selstart+j]>=32 THEN
-              str:=str+Char(hex.Data[hex.SelStart+j])
-            ELSE
-              IF hex.Data[hex.selstart+j]>0 THEN
-                str:=str+'.'
-              ELSE
-                Break;
-        END;
-        value_viewer.Cells[1,i]:=str;
-      END;
-    END;
-  END;
-
-PROCEDURE TForm8.FormCreate(Sender: TObject);
-  BEGIN
-    Self.Caption:='';
-    fileid:=0;
-    VST.NodeDataSize:=SizeOf(TNodeData);
-    value_viewer.ColCount:=2;
-    value_viewer.RowCount:=8;
-    value_viewer.FixedRows:=1;
-    value_viewer.Cells[0,0]:='Type';
-    value_viewer.Cells[1,0]:='Value';
-    value_viewer.Cells[0,1]:='1 byte, unsigned';
-    value_viewer.Cells[0,2]:='2 bytes, unsigned';
-    value_viewer.Cells[0,3]:='4 bytes, unsigned';
-    value_viewer.Cells[0,4]:='Bitset';
-    value_viewer.Cells[0,5]:='Float';
-    value_viewer.Cells[0,6]:='String';
-    value_viewer.Cells[0,7]:='Selected length';
-    value_viewer.ColWidths[0]:=100;
-    value_viewer.ColWidths[1]:=value_viewer.Width-150;
-    hex.Height:=panel_data.Height-215;
-//
-    value_viewer.Font.Charset:=AppSettings.CharSet;
-    VST.Font.Charset:=AppSettings.CharSet;
-    hex.Translation:=tkAsIs;
-    hex.Font.Charset:=AppSettings.CharSet;
-//
-  END;
-
-FUNCTION TForm8.Save:Boolean;
-  VAR
-    mem:TMemoryStream;
-    data:Tdata;
-    i:LongWord;
-  BEGIN
-    CASE MessageBox(Self.Handle,PChar('Save changes to file '+OniDataConnection.GetFileInfo(fileid).FileName+'?'),PChar('Data changed...'),MB_YESNOCANCEL) OF
-      IDYES: BEGIN
-          mem:=TMemoryStream.Create;
-          hex.SaveToStream(mem);
-          mem.Seek(0,soFromBeginning);
-          SetLength(data,mem.Size);
-          mem.Read(data[0],mem.Size);
-          mem.Free;
-          OniDataConnection.UpdateDatFile(fileid,data);
-          hex.Modified:=False;
-          FOR i:=0 TO hex.Datasize-1 DO hex.ByteChanged[i]:=False;
-          Result:=True;
-        END;
-      IDNO: Result:=True;
-      IDCANCEL: BEGIN
-          Result:=False;
-        END;
-    END;
-  END;
-
-PROCEDURE TForm8.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
-  BEGIN
-    IF hex.Modified THEN BEGIN
-      IF NOT Save THEN CanClose:=False;
-    END;
-  END;
-
-PROCEDURE TForm8.ClearStructViewer;
-  BEGIN
-    VST.Clear;
-  END;
-
-PROCEDURE TForm8.FormResize(Sender: TObject);
-  BEGIN
-    IF Self.Width>=650 THEN BEGIN
-    END ELSE Self.Width:=650;
-    IF Self.Height>=450 THEN BEGIN
-    END ELSE Self.Height:=450;
-  END;
-
-PROCEDURE TForm8.hexChange(Sender: TObject);
-  BEGIN
-    ClearValues;
-    IF hex.DataSize>0 THEN BEGIN
-      WriteStructureInfos;
-      WriteValues;
-    END;
-  END;
-
-PROCEDURE TForm8.hexKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
-  VAR
-    temps: String;
-  BEGIN
-    IF (Shift=[ssCtrl]) AND (Key=Ord('C')) THEN BEGIN
-      IF hex.SelCount>0 THEN BEGIN
-        IF hex.InCharField THEN
-          Clipboard.AsText:=hex.SelectionAsText
-        ELSE
-          Clipboard.AsText:=hex.SelectionAsHex;
-      END;
-    END;
-    IF (Shift=[ssCtrl]) AND (Key=Ord('V')) THEN BEGIN
-{      temps:=Clipboard.AsText;
-      IF hex.SelStart+Length(temps)>hex.DataSize THEN
-        SetLength(temps, hex.DataSize-hex.SelStart);
-      hex.Sel
-      hex.SelCount:=Length(temps);
-      hex.ReplaceSelection(temps,Length(temps));
-}    END;
-  END;
-
-PROCEDURE TForm8.hexSelectionChanged(Sender: TObject);
-  VAR
-    selstart:Integer;
-    node:PVirtualNode;
-    pdata:PNodeData;
-  BEGIN
-    IF hex.DataSize>0 THEN BEGIN
-      WriteValues;
-      selstart:=hex.SelStart;
-      IF VST.RootNodeCount>0 THEN BEGIN
-        Node:=VST.GetFirst;
-        WHILE Assigned(Node) DO BEGIN
-          pdata:=VST.GetNodeData(Node);
-          IF pdata.DataType>0 THEN BEGIN
-            IF ((selstart-pdata.Offset)<GetTypeDataLength(pdata.DataType)) AND ((selstart-pdata.Offset)>=0) THEN BEGIN
-              VST.FocusedNode:=Node;
-              VST.Selected[Node]:=True;
-              Break;
-            END;
-          END;
-          Node:=VST.GetNext(Node);
-        END;
-      END;
-    END;
-  END;
-
-PROCEDURE TForm8.FormClose(Sender: TObject; var Action: TCloseAction);
-  BEGIN
-    Action:=caFree;
-  END;
-
-PROCEDURE TForm8.panel_imexportResize(Sender: TObject);
-  BEGIN
-    btn_import.Width:=panel_imexport.Width-8;
-    btn_export.Width:=panel_imexport.Width-8;
-  END;
-
-PROCEDURE TForm8.btn_exportClick(Sender: TObject);
-  BEGIN
-    saved.Filter:='Files of matching extension (*.'+OniDataConnection.GetFileInfo(fileid).Extension+')|*.'+OniDataConnection.GetFileInfo(fileid).Extension+'|All files|*.*';
-    saved.DefaultExt:=OniDataConnection.GetFileInfo(fileid).Extension;
-    IF saved.Execute THEN BEGIN
-      ExportDatFile(fileid,saved.FileName);
-    END;
-  END;
-
-PROCEDURE TForm8.btn_importClick(Sender: TObject);
-  VAR
-    fs:TFileStream;
-  BEGIN
-    opend.Filter:='Files of matching extension (*.'+OniDataConnection.GetFileInfo(fileid).Extension+')|*.'+OniDataConnection.GetFileInfo(fileid).Extension+'|All files|*.*';
-    IF opend.Execute THEN BEGIN
-      fs:=TFileStream.Create(opend.FileName,fmOpenRead);
-      IF fs.Size<>hex.DataSize THEN BEGIN
-        ShowMessage('Can''t import '+ExtractFilename(opend.FileName)+
-                    ', file has to have same size as file in .dat.'+CrLf+
-                    'Size of file in .dat: '+FormatFileSize(hex.datasize)+CrLf+
-                    'Size of chosen file: '+FormatFileSize(fs.Size));
-      END ELSE BEGIN
-        hex.LoadFromStream(fs);
-        hex.Modified:=True;
-      END;
-      fs.Free;
-    END;
-  END;
-
-PROCEDURE TForm8.value_viewer_contextPopup(Sender: TObject);
-  VAR
-    i:Byte;
-  BEGIN
-    FOR i:=0 TO value_viewer_context.Items.Count-1 DO
-      value_viewer_context.Items.Items[i].Visible:=False;
-    WITH value_viewer DO BEGIN
-      IF (Col=1) AND (Row>0) AND (Length(Cells[Col,Row])>0) THEN BEGIN
-        IF Pos(' byte',Cells[0,Row])=2 THEN BEGIN
-          value_viewer_context.Items.Find('Copy to &clipboard').Visible:=True;
-          value_viewer_context.Items.Find('Copy to clipboard (as &dec)').Visible:=True;
-          value_viewer_context.Items.Find('Copy to clipboard (as &hex)').Visible:=True;
-        END;
-        IF Pos('Float',Cells[0,Row])=1 THEN
-          value_viewer_context.Items.Find('Copy to clipboard (as &float)').Visible:=True;
-        IF Pos('Bitset',Cells[0,Row])=1 THEN
-          value_viewer_context.Items.Find('Copy to clipboard (as &bitset)').Visible:=True;
-        IF Pos('String',Cells[0,Row])=1 THEN
-          value_viewer_context.Items.Find('Copy to clipboard (as &string)').Visible:=True;
-        IF Pos('Selected length',Cells[0,Row])=1 THEN
-          value_viewer_context.Items.Find('Copy to &clipboard').Visible:=True;
-      END;
-    END;
-  END;
-
-PROCEDURE TForm8.value_viewerMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
-  VAR
-    ACol,ARow:Integer;
-  BEGIN
-    IF Button=mbRight THEN BEGIN
-      value_viewer.MouseToCell(x,y,ACol,ARow);
-      IF ARow>0 THEN BEGIN
-        value_viewer.Col:=ACol;
-        value_viewer.Row:=ARow;
-      END;
-    END;
-  END;
-
-PROCEDURE TForm8.value_viewer_context_copyClick(Sender: TObject);
-  VAR
-    name:String;
-    value:LongWord;
-  BEGIN
-    name:=TMenuItem(Sender).Name;
-    IF Pos('asstring',name)>0 THEN BEGIN
-      Clipboard.AsText:=value_viewer.Cells[value_viewer.Col,value_viewer.Row];
-    END ELSE
-    IF Pos('asfloat',name)>0 THEN BEGIN
-      Clipboard.AsText:=value_viewer.Cells[value_viewer.Col,value_viewer.Row];
-    END ELSE
-    IF Pos('asbitset',name)>0 THEN BEGIN
-      Clipboard.AsText:=value_viewer.Cells[value_viewer.Col,value_viewer.Row];
-    END ELSE
-    IF (Pos('ashex',name)>0) OR (Pos('asdec',name)>0) THEN BEGIN
-      IF value_viewer.Cells[0,value_viewer.Row]='1 byte, unsigned' THEN BEGIN
-        IF ((hex.SelCount=1) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+1)>hex.DataSize) THEN
-          value:=hex.Data[hex.SelStart];
-      END;
-      IF value_viewer.Cells[0,value_viewer.Row]='2 bytes, unsigned' THEN BEGIN
-        IF ((hex.SelCount=2) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+2)>hex.DataSize) THEN
-          value:=hex.Data[hex.SelStart] + hex.Data[hex.SelStart+1]*256;
-      END;
-      IF value_viewer.Cells[0,value_viewer.Row]='4 bytes, unsigned' THEN BEGIN
-        IF ((hex.SelCount=4) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+4)>hex.DataSize) THEN
-          value:=hex.Data[hex.SelStart]+hex.Data[hex.SelStart+1]*256+hex.Data[hex.SelStart+2]*256*256+hex.Data[hex.SelStart+3]*256*256*256;
-      END;
-      IF Pos('asdec',name)>0 THEN BEGIN
-        Clipboard.AsText:=IntToStr(value);
-      END ELSE BEGIN
-        IF value_viewer.Cells[0,value_viewer.Row]='1 byte, unsigned' THEN
-          Clipboard.AsText:='0x'+IntToHex(value,2);
-        IF value_viewer.Cells[0,value_viewer.Row]='2 bytes, unsigned' THEN
-          Clipboard.AsText:='0x'+IntToHex(value,4);
-        IF value_viewer.Cells[0,value_viewer.Row]='4 bytes, unsigned' THEN
-          Clipboard.AsText:='0x'+IntToHex(value,8);
-      END;
-    END ELSE BEGIN
-      Clipboard.AsText:=value_viewer.Cells[value_viewer.Col,value_viewer.Row];
-    END;
-  END;
-
-procedure TForm8.VSTDblClick(Sender: TObject);
-  var
-    node:PVirtualNode;
-    nodedata:PNodeData;
-    id:Integer;
-  begin
-    if VST.FocusedColumn=3 then begin
-      node:=VST.FocusedNode;
-      nodedata:=VST.GetNodeData(node);
-
-      if not (nodedata.datatype in [11,12]) and ((nodedata.DataType<100) or (nodedata.DataType>300)) then begin
-        Form12.MakeVarInput(nodedata.Caption,nodedata.offset,nodedata.datatype,nodedata.value,Self);
-      end else begin
-        if nodedata.DataType=11 then begin
-          if OniDataConnection.GetRawInfo(fileid,nodedata.offset).raw_size>0 then begin
-            if Form1.open_child('rawedit') then begin
-              TForm13(Form1.ActiveMDIChild).LoadRaw(OniDataConnection.GetRawInfo(fileid,nodedata.offset));
-            end;
-          end;
-        end;
-        if nodedata.DataType=12 then begin
-          if (StrToInt(nodedata.Value)<OniDataConnection.GetFilesCount) and
-              (StrToInt(nodedata.Value)>0) and
-              (StrToInt(nodedata.Value)<>fileid) then begin
-            if OniDataConnection.GetFileInfo(StrToInt(nodedata.Value)).Size>0 then begin
-              if Form1.open_child('binedit') then begin
-                TForm8(Form1.ActiveMDIChild).LoadDat(StrToInt(nodedata.Value));
-              end;
-            end else begin
-              ShowMessage('Linked filed is a zero-byte-file');
-            end;
-          end;
-        end;
-        if (nodedata.DataType>=100) and (nodedata.DataType<=300) then begin
-          if Form1.open_child('binedit') then begin
-            TForm8(Form1.ActiveMDIChild).edit_filtername.Text:=nodedata.Value;
-            TForm8(Form1.ActiveMDIChild).check_filtername.Checked:=True;
-            TForm8(Form1.ActiveMDIChild).check_filternameClick(Self);
-          end;
-        end;
-      end;
-
-    end;
-  end;
-
-procedure TForm8.VSTFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode;
-  Column: TColumnIndex);
-  var
-    data:PNodeData;
-  begin
-    data:=VST.GetNodeData(node);
-    IF data.DataType>0 THEN BEGIN
-      hex.SelStart:=data.Offset;
-      hex.SelEnd:=data.Offset+GetTypeDataLength(data.DataType)-1;
-    END ELSE BEGIN
-      hex.SelStart:=data.Offset;
-      hex.SelEnd:=data.Offset+HexToLong(data.Value)-1;
-    END;
-  end;
-
-procedure TForm8.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
-  Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
-  var
-    data:PNodeData;
-  begin
-    data := Sender.GetNodeData(Node);
-    CellText := '';
-    if TextType = ttNormal then begin
-      case Column of
-        0: CellText := data.Caption;
-        1:
-          if data.DataType>0 then
-            CellText := '0x'+IntToHex(data.Offset,8)
-          else
-            if data.Offset>0 then
-              CellText := '0x'+IntToHex(data.Offset,8);
-        2:
-          if data.DataType>0 then
-            CellText := GetDataType(data.DataType);
-        3:
-          if data.DataType>0 then
-            CellText := data.Value //GetValue(data.DataType, data.Offset)
-          else
-            if Length(data.Value)>0 then
-              CellText := IntToStr(HexToLong(data.Value))+' Bytes';
-        4:
-          CellText := data.Description;
-      end;
-    end;
-  end;
-
-procedure TForm8.VSTHeaderDragged(Sender: TVTHeader; Column: TColumnIndex;
-  OldPosition: Integer);
-  begin
-    if Sender.Columns.Items[column].Position<1 then
-      Sender.Columns.Items[column].Position:=OldPosition;
-  end;
-
-procedure TForm8.VTHPopupColumnChange(const Sender: TBaseVirtualTree;
-  const Column: TColumnIndex; Visible: Boolean);
-  begin
-    if column=0 then
-      TVirtualStringTree(Sender).Header.Columns.Items[column].Options:=TVirtualStringTree(Sender).Header.Columns.Items[column].Options+[coVisible];
-  end;
-
-PROCEDURE TForm8.SetNewValue(datatype:Word; offset:LongWord; value:String);
-  VAR
-    data:Tdata;
-    value_int:LongWord;
-    value_float:Single;
-    i:Word;
-  BEGIN
-    CASE datatype OF
-      1..4: BEGIN
-              value_int:=StrToInt(value);
-              SetLength(data,datatype);
-              FOR i:=0 TO datatype-1 DO BEGIN
-                data[i]:=value_int MOD 256;
-                value_int:=value_int DIV 256;
-              END;
-            END;
-      5..8: BEGIN
-              value_int:=StrToInt('$'+value);
-              SetLength(data,datatype-4);
-              FOR i:=0 TO datatype-5 DO BEGIN
-                data[i]:=value_int MOD 256;
-                value_int:=value_int DIV 256;
-              END;
-            END;
-      9:    BEGIN
-              value_float:=StrToFloat(value);
-              data:=Encode_Float(value_float);
-            END;
-      10:   BEGIN
-              value_int:=BinToInt(value);
-              SetLength(data,1);
-              data[0]:=value_int;
-            END;
-      10000..65535: BEGIN
-              SetLength(data,datatype-10000);
-              FOR i:=1 TO datatype-10000 DO BEGIN
-                IF i<=Length(value) THEN
-                  data[i-1]:=Ord(value[i])
-                ELSE
-                  data[i-1]:=0;
-              END;
-            END;
-    END;
-    FOR i:=0 TO High(data) DO BEGIN
-      IF hex.Data[offset+i]<>data[i] THEN hex.ByteChanged[offset+i]:=True;
-      hex.Data[offset+i]:=data[i];
-    END;
-    hex.Modified:=True;
-    hexChange(Self);
-    hex.Repaint;
-  END;
-
-PROCEDURE TForm8.value_viewerDblClick(Sender: TObject);
-  VAR
-    offset:LongWord;
-    datatype:Word;
-    objectname:String;
-    value:String;
-  BEGIN
-    IF (value_viewer.Col=1) AND (Length(value_viewer.Cells[1,value_viewer.Row])>0) THEN BEGIN
-      offset:=hex.SelStart;
-      IF value_viewer.Cells[0,value_viewer.Row]='1 byte, unsigned' THEN
-        datatype:=1;
-      IF value_viewer.Cells[0,value_viewer.Row]='2 bytes, unsigned' THEN
-        datatype:=2;
-      IF value_viewer.Cells[0,value_viewer.Row]='4 bytes, unsigned' THEN
-        datatype:=4;
-      IF value_viewer.Cells[0,value_viewer.Row]='Bitset' THEN
-        datatype:=10;
-      IF value_viewer.Cells[0,value_viewer.Row]='Float' THEN
-        datatype:=9;
-      IF value_viewer.Cells[0,value_viewer.Row]='Selected length' THEN
-        Exit;
-      IF value_viewer.Cells[0,value_viewer.Row]='String' THEN BEGIN
-        IF hex.SelCount>0 THEN
-          datatype:=10000+hex.SelCount
-        ELSE
-          datatype:=10000+Length(value_viewer.Cells[1,value_viewer.Row]);
-      END;
-      objectname:='';
-      value:=GetValue(datatype,offset);
-      Form12.MakeVarInput(objectname,offset,datatype,value,Self);
-    END;
-  END;
-
-PROCEDURE TForm8.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
-  BEGIN
-    IF (Shift=[ssCtrl]) AND (Key=83) THEN
-      IF hex.Modified THEN
-        IF NOT Save THEN
-          Exit;
-  END;
-
-
-END.
Index: oup/current/Unit9_data_structures.pas
===================================================================
--- oup/current/Unit9_data_structures.pas	(revision 40)
+++ 	(revision )
@@ -1,476 +1,0 @@
-UNIT Unit9_data_structures;
-INTERFACE
-USES SysUtils, Classes, Unit3_data, Dialogs, StrUtils;
-
-TYPE
-  Tstructure_entry=RECORD
-      name:String;
-      offset:LongWord;
-      datatype:Word;  // 1..4  : Integer[1..4] dec
-                      // 5..8  : Integer[1..4] hex
-                      // 9     : float
-                      // 10    : bitset
-                      // 11    : raw-addr
-                      // 12    : dat-file-ID
-                      // 13..16: Signed Integer[1..4]
-                      // 17    : level-ID
-                      // 100..300: dat-file-name[0..200]
-                      // 1000..9999: Unused data[0-8999]
-                      // 10000+: string[0+]
-      description:String;
-    END;
-  TStructDefSub=RECORD
-      SubName:String;
-      SubDesc:String;
-      Entries:Array OF TStructure_entry;
-    END;
-  TStructDef=RECORD
-      Data:Boolean;
-      Global:Array OF TStructure_entry;
-      Subs:Array OF TStructDefSub;
-    END;
-  THandler=FUNCTION(fileid:LongWord):TRawList;
-  TRawListHandlers=RECORD
-    Ext:String[4];
-    needed:Boolean;
-    Handler:THandler;
-  END;
-
-VAR
-  RawListHandlers:Array OF TRawListHandlers;
-  Raws:String;
-
-
-FUNCTION LoadStructureDefinition(fileid:LongWord):TStructDef;
-FUNCTION GetDataType(typeid:Word):String;
-FUNCTION GetTypeDataLength(datatype:Word):Word;
-
-IMPLEMENTATION
-USES Unit2_functions, Unit15_Classes, Forms;
-
-FUNCTION GetTypeDataLength(datatype:Word):Word;
-  BEGIN
-    CASE datatype OF
-      1..4: Result:=datatype;
-      5..8: Result:=datatype-4;
-      9: Result:=4;
-      10: Result:=1;
-      11: Result:=4;
-      12: Result:=4;
-      13..16: Result:=datatype-12;
-      17: Result:=4;
-      100..300: Result:=datatype-100;
-      1000..9999: Result:=datatype-1000;
-      10000..65535: Result:=datatype-10000;
-    END;
-  END;
-
-FUNCTION GetDataType(typeid:Word):String;
-  BEGIN
-    CASE typeid OF
-      1..4: Result:='Int'+IntToStr(typeid*8);
-      5..8: Result:='Int'+IntToStr((typeid-4)*8);
-      9: Result:='Float';
-      10: Result:='BitSet';
-      11: Result:='Raw-Address';
-      12: Result:='.dat-file-ID';
-      13..16: Result:='SignedInt'+IntToStr((typeid-12)*8);
-      17: Result:='LevelID';
-      100..300: Result:='.dat-file-name('+IntToStr(typeid-100)+')';
-      1000..9999: Result:='Unused('+IntToStr(typeid-1000)+')';
-      10000..65535: Result:='String('+IntToStr(typeid-10000)+')';
-    END;
-  END;
-
-
-
-
-FUNCTION AGDB(fileid:LongWord):TRawList;
-  VAR
-    link:LongWord;
-    links:LongWord;
-    i:LongWord;
-  BEGIN
-    IF NOT OniDataConnection.OSisMac THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$1C,4,@links);
-      links:=links*2;
-      SetLength(Result,links);
-      FOR i:=0 TO links-1 DO BEGIN
-        Result[i].src_offset:=$20+i*4;
-        OniDataConnection.LoadDatFilePart(fileid,$20+i*4,4,@link);
-        Result[i].raw_addr:=link;
-        Result[i].raw_size:=0{????????????????????????????????};
-        Result[i].loc_sep:=False;
-      END;
-    END;
-  END;
-FUNCTION AKVA(fileid:LongWord):TRawList;
-  VAR
-    link:LongWord;
-    links:LongWord;
-    i:LongWord;
-  BEGIN
-    IF NOT OniDataConnection.OSisMac THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$1C,4,@links);
-      SetLength(Result,links);
-      FOR i:=0 TO links-1 DO BEGIN
-        Result[i].src_offset:=$20+i*$74+$24;
-        OniDataConnection.LoadDatFilePart(fileid,$20+i*$74+$24,4,@link);
-        Result[i].raw_addr:=link;
-        OniDataConnection.LoadDatFilePart(fileid,$20+i*$74+$28,4,@link);
-        Result[i].raw_size:=link;
-        Result[i].loc_sep:=False;
-      END;
-    END;
-  END;
-FUNCTION BINA(fileid:LongWord):TRawList;
-  VAR
-    link:LongWord;
-    datasize:LongWord;
-  BEGIN
-    OniDataConnection.LoadDatFilePart(fileid,$0C,4,@link);
-    OniDataConnection.LoadDatFilePart(fileid,$08,4,@datasize);
-    SetLength(Result,1);
-    Result[0].src_offset:=$0C;
-    Result[0].raw_addr:=link;
-    Result[0].raw_size:=datasize;
-    Result[0].loc_sep:=OniDataConnection.OSisMac;
-  END;
-FUNCTION OSBD(fileid:LongWord):TRawList;
-  VAR
-    link:LongWord;
-    datasize:LongWord;
-  BEGIN
-    OniDataConnection.LoadDatFilePart(fileid,$08,4,@datasize);
-    OniDataConnection.LoadDatFilePart(fileid,$0C,4,@link);
-    SetLength(Result,1);
-    Result[0].src_offset:=$0C;
-    Result[0].raw_addr:=link;
-    Result[0].raw_size:=datasize;
-    Result[0].loc_sep:=OniDataConnection.OSisMac;
-  END;
-FUNCTION SNDD(fileid:LongWord):TRawList;
-  VAR
-    link:LongWord;
-    datasize:LongWord;
-  BEGIN
-    SetLength(Result,1);
-    IF NOT OniDataConnection.OSisMac THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$40,4,@datasize);
-      OniDataConnection.LoadDatFilePart(fileid,$44,4,@link);
-      Result[0].src_offset:=$44;
-    END ELSE BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$10,4,@datasize);
-      OniDataConnection.LoadDatFilePart(fileid,$14,4,@link);
-      Result[0].src_offset:=$14;
-    END;
-    Result[0].raw_addr:=link;
-    Result[0].raw_size:=datasize;
-    Result[0].loc_sep:=False;
-  END;
-FUNCTION SUBT(fileid:LongWord):TRawList;
-  VAR
-    baselink,lastlink:LongWord;
-    links:LongWord;
-    j,k:LongWord;
-    data:Tdata;
-  BEGIN
-    OniDataConnection.LoadDatFilePart(fileid,$18,4,@baselink);
-    OniDataConnection.LoadDatFilePart(fileid,$1C,4,@links);
-    IF links>0 THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$20+(links-1)*4,4,@lastlink);
-      SetLength(data,lastlink+1024);
-        TOniDataDat(OniDataConnection).LoadRawOffset(false, baselink,lastlink+1024,data); 
-//      OniDataConnection.LoadRawFile(fileid,$1C,baselink,lastlink+1024,False,@data[0]);
-      k:=0;
-      FOR j:=0 TO 1024 DO BEGIN
-        IF (data[lastlink+j]=$00) OR (j=1024) THEN BEGIN
-          IF j<1024 THEN BEGIN
-            IF k=0 THEN BEGIN
-              k:=1;
-            END ELSE BEGIN
-              SetLength(Result,1);
-              Result[0].src_offset:=$18;
-              Result[0].raw_addr:=baselink;
-              Result[0].raw_size:=lastlink+j;
-              Break;
-            END;
-          END;
-        END;
-      END;
-    END;
-  END;
-FUNCTION TRAM(fileid:LongWord):TRawList;
-  VAR
-    i:Integer;
-    link:LongWord;
-    frames:Word;
-    tempb:Byte;
-    tempw:Word;
-    templ:LongWord;
-    data:Tdata;
-    offset:Word;
-    frame_count:Byte;
-  BEGIN
-    SetLength(Result,13);
-    OniDataConnection.LoadDatFilePart(fileid,$16C,2,@frames);
-    {y-pos}
-    OniDataConnection.LoadDatFilePart(fileid,$0C,4,@link);
-    Result[0].src_offset:=$0C;
-    Result[0].raw_addr:=link;
-    Result[0].raw_size:=frames*4;
-    {x-z-pos}
-    OniDataConnection.LoadDatFilePart(fileid,$10,4,@link);
-    Result[1].src_offset:=$10;
-    Result[1].raw_addr:=link;
-    Result[1].raw_size:=frames*8;
-    {attacks}
-    OniDataConnection.LoadDatFilePart(fileid,$182,1,@tempb);
-    OniDataConnection.LoadDatFilePart(fileid,$14,4,@link);
-    Result[2].src_offset:=$14;
-    Result[2].raw_addr:=link;
-    Result[2].raw_size:=tempb*32;
-    {damage}
-    OniDataConnection.LoadDatFilePart(fileid,$183,1,@tempb);
-    OniDataConnection.LoadDatFilePart(fileid,$18,4,@link);
-    Result[3].src_offset:=$18;
-    Result[3].raw_addr:=link;
-    Result[3].raw_size:=tempb*8;
-    {motionblur}
-    OniDataConnection.LoadDatFilePart(fileid,$184,1,@tempb);
-    OniDataConnection.LoadDatFilePart(fileid,$1C,4,@link);
-    Result[4].src_offset:=$1C;
-    Result[4].raw_addr:=link;
-    Result[4].raw_size:=tempb*8;
-    {shortcut}
-    OniDataConnection.LoadDatFilePart(fileid,$185,1,@tempb);
-    OniDataConnection.LoadDatFilePart(fileid,$20,4,@link);
-    Result[5].src_offset:=$20;
-    Result[5].raw_addr:=link;
-    Result[5].raw_size:=tempb*8;
-    {throw}
-    OniDataConnection.LoadDatFilePart(fileid,$24,4,@link);
-    Result[6].src_offset:=$24;
-    Result[6].raw_addr:=link;
-    IF link>0 THEN
-      Result[6].raw_size:=24
-    ELSE
-      Result[6].raw_size:=0;
-    {footstep}
-    OniDataConnection.LoadDatFilePart(fileid,$186,1,@tempb);
-    OniDataConnection.LoadDatFilePart(fileid,$28,4,@link);
-    Result[7].src_offset:=$28;
-    Result[7].raw_addr:=link;
-    Result[7].raw_size:=tempb*4;
-    {particle}
-    OniDataConnection.LoadDatFilePart(fileid,$187,1,@tempb);
-    OniDataConnection.LoadDatFilePart(fileid,$2C,4,@link);
-    Result[8].src_offset:=$2C;
-    Result[8].raw_addr:=link;
-    Result[8].raw_size:=tempb*24;
-    {position}
-    OniDataConnection.LoadDatFilePart(fileid,$30,4,@link);
-    Result[9].src_offset:=$30;
-    Result[9].raw_addr:=link;
-    Result[9].raw_size:=frames*8;
-    {particle}
-    OniDataConnection.LoadDatFilePart(fileid,$154,2,@tempw);
-    OniDataConnection.LoadDatFilePart(fileid,$38,4,@link);
-    Result[11].src_offset:=$38;
-    Result[11].raw_addr:=link;
-    Result[11].raw_size:=tempw*34;
-    {extent}
-    OniDataConnection.LoadDatFilePart(fileid,$138,4,@templ);
-    OniDataConnection.LoadDatFilePart(fileid,$13C,4,@link);
-    Result[12].src_offset:=$13C;
-    Result[12].raw_addr:=link;
-    Result[12].raw_size:=templ*12;
-
-    OniDataConnection.LoadDatFilePart(fileid,$34,4,@link);
-    IF link>0 THEN BEGIN
-      OniDataConnection.LoadDatFilePart(fileid,$160,2,@tempw);
-      frame_count:=0;
-      i:=0;
-      SetLength(data,$FFFF);
-      TOniDataDat(OniDataConnection).LoadRawOffset(false,link,$FFFF,data); 
-      offset:=data[$24]+data[$25]*256;
-      WHILE (offset+i<Length(data)) AND (frame_count<frames-1) DO BEGIN
-        Inc(i,tempw);
-        frame_count:=frame_count+data[offset+i];
-        Inc(i);
-      END;
-      IF offset+i<Length(data) THEN BEGIN
-        Inc(i,tempw);
-        Result[10].raw_size:=offset+i;
-      END ELSE BEGIN
-        Result[10].raw_size:=0;
-      END;
-    END;
-    Result[10].src_offset:=$34;
-    Result[10].raw_addr:=link;
-  END;
-FUNCTION TXMP(fileid:LongWord):TRawList;
-  VAR
-    link_pc:LongWord;
-    link_mac:LongWord;
-    x,y:Word;
-    storetype:Byte;
-    datasize:LongWord;
-  BEGIN
-    OniDataConnection.LoadDatFilePart(fileid,$8C,SizeOf(x),@x);
-    OniDataConnection.LoadDatFilePart(fileid,$8E,SizeOf(y),@y);
-    OniDataConnection.LoadDatFilePart(fileid,$90,SizeOf(storetype),@storetype);
-    OniDataConnection.LoadDatFilePart(fileid,$9C,4,@link_pc);
-    OniDataConnection.LoadDatFilePart(fileid,$A0,4,@link_mac);
-    CASE storetype OF
-      0,1,2: datasize:=x*y*2;
-      8: datasize:=x*y*4;
-      9: datasize:=x*y DIV 2;
-    END;
-    SetLength(Result,1);
-    IF NOT OniDataConnection.OSisMac THEN BEGIN
-      Result[0].src_offset:=$9C;
-      Result[0].raw_addr:=link_pc
-    END ELSE BEGIN
-      Result[0].src_offset:=$A0;
-      Result[0].raw_addr:=link_mac;
-    END;
-    Result[0].raw_size:=datasize;
-    Result[0].loc_sep:=OniDataConnection.OSisMac;
-  END;
-
-
-PROCEDURE InsertRawListHandler(ext:String; needed:Boolean; handler:THandler);
-  BEGIN
-    SetLength(RawListHandlers,Length(RawListHandlers)+1);
-    RawListHandlers[High(RawListHandlers)].Ext:=ext;
-    RawListHandlers[High(RawListHandlers)].needed:=needed;
-    RawListHandlers[High(RawListHandlers)].handler:=handler;
-    Raws:=Raws+ext;
-  END;
-
-
-
-FUNCTION LoadStructureDefinition(fileid:LongWord):TStructDef;
-  VAR
-    i:LongWord;
-    current_type:Byte; //0: Global, 1: Undynamic, 2: Dynamic
-    current_base,current_package,current_package_size:LongWord;
-    packages:LongWord;
-    deffile:Text;
-    structentry:TStructure_Entry;
-    fields:TStringArray;
-    filename:String;
-    ext:String[4];
-    temps:String;
-    data:TData;
-  BEGIN
-    SetLength(Result.Global,0);
-    SetLength(Result.Subs,0);
-    Result.Data:=False;
-    ext:=OniDataConnection.GetFileInfo(fileid).Extension;
-    filename:=ExtractFilePath(Application.ExeName)+'\StructDefs\'+ext+'.txt';
-    IF FileExists(filename) THEN BEGIN
-      data:=OniDataConnection.LoadDatFile(fileid);
-      AssignFile(deffile,filename);
-      Reset(deffile);
-      current_type:=0;
-      Result.Data:=True;
-      IF NOT EoF(deffile) THEN BEGIN
-        ReadLn(deffile,temps);
-        WHILE NOT EoF(deffile) DO BEGIN
-          ReadLn(deffile,temps);
-          IF (Length(temps)>0) AND (temps[1]<>'#') THEN BEGIN
-            IF temps[1]='*' THEN BEGIN
-              fields:=Explode(temps,#9);
-              CASE Length(fields) OF
-                1..2: BEGIN
-                     current_type:=1;
-                     current_base:=0;
-                     SetLength(Result.Subs, Length(Result.Subs)+1);
-                     Result.Subs[High(Result.Subs)].SubName:=MidStr(fields[0],2,Length(fields[0])-1);
-                     IF Length(fields)=2 THEN
-                       Result.Subs[High(Result.Subs)].SubDesc:=fields[1];
-                   END;
-                3: BEGIN
-                     current_type:=1;
-                     current_base:=HexToLong(fields[2]);
-                     SetLength(Result.Subs, Length(Result.Subs)+1);
-                     Result.Subs[High(Result.Subs)].SubName:=MidStr(fields[0],2,Length(fields[0])-1);
-                     Result.Subs[High(Result.Subs)].SubDesc:=fields[1];
-                   END;
-                6: BEGIN
-                     current_type:=2;
-                     current_base:=HexToLong(fields[2]);
-                     current_package:=0;
-                     current_package_size:=StrToInt(fields[5]);
-                     IF fields[4][1]<>'$' THEN BEGIN
-                       CASE StrToInt(fields[4]) OF
-                         1: packages:=data[HexToLong(fields[3])];
-                         2: packages:=data[HexToLong(fields[3])]+data[HexToLong(fields[3])+1]*256;
-                         4: packages:=data[HexToLong(fields[3])]+data[HexToLong(fields[3])+1]*256+data[HexToLong(fields[3])+2]*256*256+data[HexToLong(fields[3])+3]*256*256*256;
-                       END;
-                     END ELSE BEGIN
-                       packages:=HexToLong(fields[4]);
-                     END;
-                     SetLength(Result.Subs, Length(Result.Subs)+packages);
-                     FOR current_package:=0 TO packages-1 DO BEGIN
-                       Result.Subs[High(Result.Subs)-packages+current_package+1].SubName:=
-                           MidStr(fields[0],2,Length(fields[0])-1)+'['+IntToStr(current_package)+']'+
-                           '#'+IntToHex(current_base+current_package*current_package_size,8)+
-                           '#'+IntToHex(current_package_size,8);
-                       Result.Subs[High(Result.Subs)-packages+current_package+1].SubDesc:=
-                           fields[1];
-                     END;
-                   END;
-              END;
-            END ELSE BEGIN
-              fields:=Explode(temps,#9);
-              IF (Length(fields)=3) OR (Length(fields)=4) THEN BEGIN
-                IF NOT AppSettings.HideUnusedData OR ((StrToInt(fields[2])<1000) OR (StrToInt(fields[2])>9999)) THEN BEGIN 
-                  structentry.name:=fields[0];
-                  structentry.datatype:=StrToInt(fields[2]);
-                  IF Length(fields)=4 THEN
-                    structentry.description:=fields[3]
-                  ELSE
-                    structentry.description:='';
-                  IF current_type IN [0,1] THEN BEGIN
-                    structentry.offset:=HexToLong(fields[1])+current_base;
-                    IF Length(Result.Subs)=0 THEN BEGIN
-                      SetLength(Result.Global,Length(Result.Global)+1);
-                      Result.Global[High(Result.Global)]:=structentry;
-                    END ELSE BEGIN
-                      SetLength(Result.Subs[High(Result.Subs)].Entries,Length(Result.Subs[High(Result.Subs)].Entries)+1);
-                      Result.Subs[High(Result.Subs)].Entries[High(Result.Subs[High(Result.Subs)].Entries)]:=structentry;
-                    END;
-                  END ELSE BEGIN
-                    FOR current_package:=0 TO packages-1 DO BEGIN
-                      structentry.offset:=current_base+current_package*current_package_size+HexToLong(fields[1]);
-                      WITH Result.Subs[High(Result.Subs)-packages+current_package+1] DO BEGIN
-                        SetLength(Entries,Length(Entries)+1);
-                        Entries[High(Entries)]:=structentry;
-                      END;
-                    END;
-                  END;
-                END;
-              END;
-            END;
-          END;
-        END;
-      END;
-      CloseFile(deffile);
-    END;
-  END;
-
-
-BEGIN
-  Raws:='';
-//  InsertRawListHandler('AGDB',True,AGDB);
-  InsertRawListHandler('AKVA',True,AKVA);
-  InsertRawListHandler('BINA',True,BINA);
-  InsertRawListHandler('OSBD',True,OSBD);
-  InsertRawListHandler('SNDD',True,SNDD);
-  InsertRawListHandler('SUBT',True,SUBT);
-  InsertRawListHandler('TRAM',True,TRAM);
-  InsertRawListHandler('TXMP',True,TXMP);
-END.
