Index: oup/rewrite/Tools/BinEdit.dfm
===================================================================
--- oup/rewrite/Tools/BinEdit.dfm	(revision 104)
+++ oup/rewrite/Tools/BinEdit.dfm	(revision 105)
@@ -3,4 +3,5 @@
   KeyPreview = True
   OnCloseQuery = FormCloseQuery
+  OnCreate = FormCreate
   OnKeyUp = FormKeyUp
   ExplicitWidth = 500
Index: oup/rewrite/Tools/BinEdit.pas
===================================================================
--- oup/rewrite/Tools/BinEdit.pas	(revision 104)
+++ oup/rewrite/Tools/BinEdit.pas	(revision 105)
@@ -176,17 +176,4 @@
   end;
 end;
-
-
-
-
-function IntToBin(Value: Byte): String;
-var
-  i: Byte;
-begin
-  Result := '';
-  for i := 7 downto 0 do
-    Result := Result + IntToStr((Value shr i) and $01);
-end;
-
 
 
Index: oup/rewrite/Tools/Extractor.dfm
===================================================================
--- oup/rewrite/Tools/Extractor.dfm	(revision 104)
+++ oup/rewrite/Tools/Extractor.dfm	(revision 105)
@@ -22,4 +22,5 @@
       Width = 333
       Height = 338
+      MultiSelect = True
       ExplicitWidth = 333
       ExplicitHeight = 338
Index: oup/rewrite/Tools/Extractor.pas
===================================================================
--- oup/rewrite/Tools/Extractor.pas	(revision 104)
+++ oup/rewrite/Tools/Extractor.pas	(revision 105)
@@ -36,5 +36,5 @@
 implementation
 {$R *.dfm}
-uses Main, Functions, Data, OniDataClass, FolderBrowser, Exporters;
+uses Main, Functions, Data, ConnectionManager, FolderBrowser, Exporters;
 
 
@@ -105,12 +105,12 @@
     if (selonly and filelist.Selected[i]) or not selonly then
     begin
-      fileid := Connection.ExtractFileID(filelist.Items.Strings[i]);
+      fileid := ConManager.Connection[ConnectionID].ExtractFileIDOfName(filelist.Items.Strings[i]);
       filename := GetWinFilename(filelist.Items.Strings[i]);
       if check_dat.Checked then
-        ExportDatFile(Connection, fileid, path + filename);
+        ExportDatFile(ConnectionID, fileid, path + filename);
       if check_raw.Checked then
-        ExportRawFiles(Connection, fileid, path + filename);
+        ExportRawFiles(ConnectionID, fileid, path + filename);
       if check_convert.Checked then
-        ExportConverted(Connection, fileid, path + filename);
+        ExportConverted(ConnectionID, fileid, path + filename);
       Inc(done);
     end;
Index: oup/rewrite/Tools/RawEdit.dfm
===================================================================
--- oup/rewrite/Tools/RawEdit.dfm	(revision 104)
+++ oup/rewrite/Tools/RawEdit.dfm	(revision 105)
@@ -3,4 +3,5 @@
   KeyPreview = True
   OnCloseQuery = FormCloseQuery
+  OnCreate = FormCreate
   OnKeyUp = FormKeyUp
   ExplicitWidth = 500
Index: oup/rewrite/Tools/RawEdit.pas
===================================================================
--- oup/rewrite/Tools/RawEdit.pas	(revision 104)
+++ oup/rewrite/Tools/RawEdit.pas	(revision 105)
@@ -63,5 +63,5 @@
 implementation
 {$R *.dfm}
-uses Main, ValueEdit;
+uses Main, ValueEdit, RawList;
 
 procedure TForm_RawEdit.NewFile(fileinfo: TFileInfo);
@@ -115,5 +115,5 @@
     for i := 0 to filelist.Count - 1 do
     begin
-      if ConManager.Connection[ConID].ExtractFileIDOfName(filelist.Items.Strings[i]) = RawInfo.SrcID then
+      if ConManager.Connection[ConID].ExtractFileIDOfName(filelist.Items.Strings[i]) = Raw_Info.SrcID then
       begin
         filelist.ItemIndex := i;
@@ -132,5 +132,5 @@
   end;
   mem := nil;
-  ConManager.Connection[ConID].LoadRawFile(raw_info.SrcID, raw_info.SrcOffset, mem);
+  ConManager.Connection[ConID].LoadRawFile(raw_info.SrcID, raw_info.SrcOffset, TStream(mem));
   hex.LoadFromStream(mem);
   ClearValues;
@@ -146,21 +146,7 @@
 begin
   ClearValues;
-  dat_offset := StrToInt('$' + MidStr(
+  datoffset := StrToInt('$' + MidStr(
     list_offset.Items.Strings[list_offset.ItemIndex], 3, 8));
-  LoadRaw(Connection.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;
+  LoadRaw(ConManager.Connection[ConID].GetRawInfo(fileid, datoffset));
 end;
 
@@ -170,5 +156,5 @@
 function TForm_RawEdit.GetValue(datatype: Word; offset: LongWord): String;
 var
-  Data: Tdata;
+  Data: TByteData;
   i:    Word;
   floatformat: TFormatSettings;
@@ -231,7 +217,5 @@
 begin
   for i := 1 to value_viewer.RowCount - 1 do
-  begin
     value_viewer.Cells[1, i] := '';
-  end;
 end;
 
@@ -242,5 +226,5 @@
 var
   i, j:  Integer;
-  Data:  Tdata;
+  Data:  TByteData;
   str:   String;
   Value: LongWord;
@@ -363,11 +347,11 @@
 
   exts := '';
-  if Length(RawListHandlers) > 0 then
-  begin
-    for i := 0 to High(RawListHandlers) do
+  if Length(RawLists.RawListHandlers) > 0 then
+  begin
+    for i := 0 to High(RawLists.RawListHandlers) do
       if Length(exts) > 0 then
-        exts := exts + ',' + RawListHandlers[i].Ext
+        exts := exts + ',' + RawLists.RawListHandlers[i].Ext
       else
-        exts := RawListHandlers[i].Ext;
+        exts := RawLists.RawListHandlers[i].Ext;
   end;
   Self.AllowedExts := exts;
@@ -404,9 +388,8 @@
 var
   mem:  TMemoryStream;
-  Data: Tdata;
   i:    LongWord;
 begin
   case MessageBox(Self.Handle, PChar('Save changes to .raw-part of file ' +
-      Connection.GetFileInfo(fileid).FileName + '?'), PChar('Data changed...'),
+      ConManager.Connection[ConID].GetFileInfo(fileid).Name + '?'), PChar('Data changed...'),
       MB_YESNOCANCEL) of
     idYes:
@@ -415,9 +398,6 @@
       hex.SaveToStream(mem);
       mem.Seek(0, soFromBeginning);
-      SetLength(Data, mem.Size);
-      mem.Read(Data[0], mem.Size);
+      ConManager.Connection[ConID].UpdateRawFile(fileid, datoffset, mem);
       mem.Free;
-      Connection.UpdateRawFile(fileid_opened, dat_offset_opened,
-        Length(Data), @Data[0]);
       hex.Modified := False;
       for i := 0 to hex.Datasize - 1 do
@@ -428,7 +408,5 @@
       Result := True;
     idCancel:
-    begin
       Result := False;
-    end;
   end;
 end;
@@ -440,8 +418,6 @@
 begin
   if hex.Modified then
-  begin
     if not Save then
       CanClose := False;
-  end;
 end;
 
@@ -529,8 +505,9 @@
   fs: TFileStream;
 begin
-  saved.Filter     := 'Files of matching extension (*.' + Connection.GetFileInfo(
-    fileid).Extension + ')|*.' + Connection.GetFileInfo(fileid).Extension +
+  saved.Filter     := 'Files of matching extension (*.' +
+    ConManager.Connection[ConID].GetFileInfo(fileid).Extension + ')|*.' +
+    ConManager.Connection[ConID].GetFileInfo(fileid).Extension +
     '|All files|*.*';
-  saved.DefaultExt := Connection.GetFileInfo(fileid).Extension;
+  saved.DefaultExt := ConManager.Connection[ConID].GetFileInfo(fileid).Extension;
   if saved.Execute then
   begin
@@ -548,7 +525,11 @@
 //  Data: Tdata;
   fs:   TFileStream;
-begin
-  opend.Filter := 'Files of matching extension (*.' + Connection.GetFileInfo(
-    fileid).Extension + ')|*.' + Connection.GetFileInfo(fileid).Extension +
+  data: TByteData;
+  i: Integer;
+  rawinfo: TRawDataInfo;
+begin
+  opend.Filter := 'Files of matching extension (*.' +
+    ConManager.Connection[ConID].GetFileInfo(fileid).Extension + ')|*.' +
+    ConManager.Connection[ConID].GetFileInfo(fileid).Extension +
     '|All files|*.*';
   if opend.Execute then
@@ -557,14 +538,38 @@
     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;
+      if (not (CR_ResizeRaw in ConManager.Connection[ConID].ChangeRights)) and (not (CR_AppendRaw in ConManager.Connection[ConnectionID].ChangeRights)) then
+      begin
+        ShowMessage('Can''t import ' + ExtractFilename(importd.FileName) +
+            ', file has to have same size as file in .raw with this backend.' + CrLf +
+            'Size of file in .raw: ' + FormatFileSize(hex.DataSize) + CrLf +
+            'Size of chosen file: ' + FormatFileSize(fs.Size));
+        Exit;
+      end else begin
+        if MessageBox(Self.Handle,
+              PChar('File has different size from the file in the .raw.' + CrLf +
+                    'Size of file in .dat: ' + FormatFileSize(hex.DataSize) + CrLf +
+                    'Size of chosen file: ' + FormatFileSize(fs.Size) + CrLf +
+                    'Replace anyway?' + CrLf +
+                    'WARNING: This only replaces the raw-data. It doesn''t' + CrLf +
+                    'do the according changes in the .dat. Oni probably' + CrLf +
+                    'won''t be able to use the data correctly!'), PChar('Different size'), MB_YESNO + MB_ICONWARNING) = ID_NO then
+        begin
+          Exit;
+        end;
+      end;
+      rawinfo := ConManager.Connection[ConID].GetRawInfo(fileid, datoffset);
+      if CR_ResizeRaw in ConManager.Connection[ConID].ChangeRights then
+        ConManager.Connection[ConID].UpdateRawFile(fileid, datoffset, fs)
+      else if CR_AppendRaw in ConManager.Connection[ConID].ChangeRights then
+        i := ConManager.Connection[ConID].AppendRawFile(rawinfo.LocSep, fs);
+        ConManager.Connection[ConID].UpdateDatFilePart(fileid, datoffset, 4, @i);
+    end else begin
+      ConManager.Connection[ConID].UpdateRawFile(fileid, datoffset, fs);
+    end;
+    fs.Seek(0, soFromBeginning);
+    hex.LoadFromStream(fs);
+    hex.Modified := False;
+    for i := 0 to hex.Datasize - 1 do
+      hex.ByteChanged[i] := False;
     fs.Free;
   end;
@@ -691,5 +696,5 @@
 procedure TForm_RawEdit.SetNewValue(datatype: Word; offset: LongWord; Value: String);
 var
-  Data: Tdata;
+  Data: TByteData;
   value_int: LongWord;
   value_float: Single;
Index: oup/rewrite/Tools/Template.dfm
===================================================================
--- oup/rewrite/Tools/Template.dfm	(revision 104)
+++ oup/rewrite/Tools/Template.dfm	(revision 105)
@@ -242,5 +242,5 @@
         Style = csDropDownList
         Anchors = [akLeft, akTop, akRight]
-        DropDownCount = 12
+        DropDownCount = 20
         Font.Charset = DEFAULT_CHARSET
         Font.Color = clWindowText
@@ -288,4 +288,5 @@
         Style = csDropDownList
         Anchors = [akLeft, akTop, akRight]
+        DropDownCount = 12
         ItemHeight = 13
         TabOrder = 4
Index: oup/rewrite/Tools/Template.pas
===================================================================
--- oup/rewrite/Tools/Template.pas	(revision 104)
+++ oup/rewrite/Tools/Template.pas	(revision 105)
@@ -117,5 +117,5 @@
       else
         datatype := 'Unknown: ';
-      boxstring := datatype + fn + ' (Level: ' + IntToStr(level) + ')';
+      boxstring := datatype + fn + ' (Level: ' + IntToStr(level) + ') [' + IntToStr(ConManager.ConnectionByIndex[i].ConnectionID) + ']';
       combo_connection.Items.Add(boxstring);
       if ConManager.ConnectionByIndex[i].ConnectionID = FConnectionID then
@@ -276,5 +276,8 @@
 begin
   if combo_connection.ItemIndex >= 0 then
-    FConnectionID := combo_connection.ItemIndex
+  begin
+    name := combo_connection.Items.Strings[combo_connection.ItemIndex];
+    FConnectionID := StrToInt(MidStr(name, Pos('[', name) + 1, Pos(']', name) - Pos('[', name)  - 1));
+  end
   else
     FConnectionID := -1;
Index: oup/rewrite/Tools/TxmpReplace.dfm
===================================================================
--- oup/rewrite/Tools/TxmpReplace.dfm	(revision 104)
+++ oup/rewrite/Tools/TxmpReplace.dfm	(revision 105)
@@ -1,4 +1,5 @@
 inherited Form_TxmpReplace: TForm_TxmpReplace
   Caption = 'TxmpReplace'
+  OnCreate = FormCreate
   PixelsPerInch = 96
   TextHeight = 13
Index: oup/rewrite/Tools/TxmpReplace.pas
===================================================================
--- oup/rewrite/Tools/TxmpReplace.pas	(revision 104)
+++ oup/rewrite/Tools/TxmpReplace.pas	(revision 105)
@@ -47,20 +47,18 @@
 procedure TForm_TxmpReplace.SelectFile(fileinfo: TFileInfo);
 var
-  Data: TByteData;
   mem:  TMemoryStream;
   fadingbyte, depthbyte, storebyte: Byte;
 begin
   fileid := fileinfo.ID;
-  Connection.LoadDatFilePart(fileid, $88, SizeOf(fadingbyte), @fadingbyte);
-  Connection.LoadDatFilePart(fileid, $89, SizeOf(depthbyte), @depthbyte);
-  Connection.LoadDatFilePart(fileid, $90, SizeOf(storebyte), @storebyte);
+  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $88, SizeOf(fadingbyte), @fadingbyte);
+  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $89, SizeOf(depthbyte), @depthbyte);
+  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $90, SizeOf(storebyte), @storebyte);
   check_fading.Checked := (fadingbyte and $01) > 0;
   check_transparency.Checked := (depthbyte and $04) > 0;
 
-  OniImage_Old.LoadFromTXMP(connection, fileid);
+  OniImage_Old.LoadFromTXMP(ConnectionID, fileid);
   old_size := OniImage_Old.GetImageDataSize((fadingbyte and $01) > 0);
-  Data := OniImage_Old.GetAsBMP;
   mem  := TMemoryStream.Create;
-  mem.Write(Data[0], Length(Data));
+  OniImage_Old.GetAsBMP(TStream(mem));
   mem.Seek(0, soFromBeginning);
   image_txmppreview.Picture.Bitmap.LoadFromStream(mem);
@@ -74,12 +72,10 @@
 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));
+    OniImage_New.GetAsBMP(TStream(mem));
     mem.Seek(0, soFromBeginning);
     image_bmppreview.Picture.Bitmap.LoadFromStream(mem);
@@ -97,36 +93,37 @@
   old_rawaddr, new_rawaddr: LongWord;
   oldfading: Byte;
-  tempd:     Tdata;
-
   datbyte: Word;
+  mem: TMemoryStream;
 begin
   if filelist.ItemIndex >= 0 then
   begin
-    Connection.LoadDatFilePart(fileid, $88, 1, @oldfading);
-    if Connection.OSisMac then
-      Connection.UpdateDatFilePart(fileid, $A0, 4, @old_rawaddr)
+    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $88, 1, @oldfading);
+    if not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN) then
+      ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $A0, 4, @old_rawaddr)
     else
-      Connection.LoadDatFilePart(fileid, $9C, 4, @old_rawaddr);
+      ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $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(filelist.Items.Strings[filelist.ItemIndex]),
-        MB_YESNO) = idNo then
+      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 anyway?'),
+            PChar(filelist.Items.Strings[filelist.ItemIndex]), MB_YESNO) = idNo then
         Exit;
     end;
 
+    mem := TMemoryStream.Create;
+
     if check_fading.Checked then
-      if not OniImage_New.GetMipMappedImage(tempd) then
+      if not OniImage_New.GetMipMappedImage(TStream(mem)) 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
+              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
@@ -134,15 +131,18 @@
 
     if not check_fading.Checked then
-      tempd := OniImage_New.GetAsData;
+    begin
+      mem.Clear;
+      OniImage_New.GetAsData(TStream(mem));
+    end;
 
     newsize := OniImage_New.GetImageDataSize(check_fading.Checked);
 
-    if (newsize > old_size) and (Connection.Backend = ODB_Dat) then
-      new_rawaddr := Connection.AppendRawFile(
-        Connection.OSisMac, Length(tempd), tempd)
+    if (newsize > old_size) and (ConManager.Connection[ConnectionID].Backend = DB_ONI) then
+      new_rawaddr := ConManager.Connection[ConnectionID].AppendRawFile(
+        not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN), mem.Size, mem)
     else
     begin
       new_rawaddr := old_rawaddr;
-      Connection.UpdateRawFile(fileid, $9C, Length(tempd), tempd);
+      ConManager.Connection[ConnectionID].UpdateRawFile(fileid, $9C, mem);
     end;
 
@@ -150,17 +150,17 @@
     if check_fading.Checked then
       datbyte := datbyte or $01;
-    Connection.UpdateDatFilePart(fileid, $88, 1, @datbyte);
+    ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $88, 1, @datbyte);
     datbyte := $10;
     if check_transparency.Checked then
       datbyte := datbyte or $04;
-    Connection.UpdateDatFilePart(fileid, $89, 1, @datbyte);
-    Connection.UpdateDatFilePart(fileid, $8C, 2, @OniImage_New.Width);
-    Connection.UpdateDatFilePart(fileid, $8E, 2, @OniImage_New.Height);
+    ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $89, 1, @datbyte);
+    ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $8C, 2, @OniImage_New.Width);
+    ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $8E, 2, @OniImage_New.Height);
     datbyte := $08;
-    Connection.UpdateDatFilePart(fileid, $90, 1, @datbyte);
-    if Connection.OSisMac then
-      Connection.UpdateDatFilePart(fileid, $A0, 4, @new_rawaddr)
+    ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $90, 1, @datbyte);
+    if not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN) then
+      ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $A0, 4, @new_rawaddr)
     else
-      Connection.UpdateDatFilePart(fileid, $9C, 4, @new_rawaddr);
+      ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $9C, 4, @new_rawaddr);
 
     ShowMessage('TXMP-image replaced');
