Exemple #1
0
        /* public static void exportCompressedImage(System.IO.BinaryReader br, long address, int headerOffset, int type, bool unheaded = false)
         * {
         *  //Dummy.exportCompressedImage(0x031E83, br, headerOffset, 4); // Chocobo Haryuu and PJs
         *
         *  List<Byte> picture = Compressor.uncompress(address, br, headerOffset, unheaded);
         *  System.Drawing.Bitmap newBitmap = new System.Drawing.Bitmap(0, 0);
         *
         *  //System.IO.File.WriteAllBytes("DummyImage.smc", picture.ToArray());
         *
         *  switch (type)
         *  {
         *      case 01:
         *          newBitmap = Transformations.transform1bpp(picture, 0, picture.Count);
         *          ManageBMP.exportBPM("1bpp", newBitmap, Palettes.palette1b);
         *          break;
         *      case 02:
         *          newBitmap = Transformations.transform2bpp(picture, 0, picture.Count);
         *          ManageBMP.exportBPM("2bpp", newBitmap, Palettes.palette2b);
         *          break;
         *      case 03:
         *          newBitmap = Transformations.transform3bpp(picture, 0, picture.Count);
         *          ManageBMP.exportBPM("3bpp", newBitmap, Palettes.palette3b);
         *          break;
         *      case 04:
         *          newBitmap = Transformations.transform4b(picture, 0, picture.Count);
         *          ManageBMP.exportBPM("4bpp", newBitmap, Palettes.palette4b);
         *          break;
         *      default:
         *          break;
         *  };
         * }
         */



        /* public static void injectImage(System.IO.BinaryWriter bw, long address, int headerOffset, int type, int imageSize, int maxCompSize, bool unheaded = false)
         * {
         *  //Dummy.injectImage(bw, 0x105C0A, headerOffset, 0x04, 0x1400, 0x0BF5); // New Title
         *
         *  List<Byte> newBytes = new List<Byte>();
         *  Byte size00 = BitConverter.GetBytes(imageSize)[1];
         *  Byte size01 = BitConverter.GetBytes(imageSize)[0];
         *
         *  System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
         *  openFileDialog.Filter = "PNG File|*.png|BMP File|*.bmp";
         *  openFileDialog.Title = "Choose a file";
         *
         *  // Show the Dialog
         *  if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         *  {
         *      if (openFileDialog.FileName != "")
         *      {
         *          try
         *          {
         *              System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(openFileDialog.FileName);
         *              int size = bitmap.Width * bitmap.Height;
         *              byte[] bitmapPixels = new byte[size];
         *
         *              // Open it to edit
         *              System.Drawing.Imaging.BitmapData data = bitmap.LockBits(
         *                  new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),
         *                  System.Drawing.Imaging.ImageLockMode.WriteOnly,
         *                  System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
         *
         *              // Recover the original values (now lost because of the conversion)
         *              for (int i = 0; i < size; i++)
         *              {
         *                  bitmapPixels[i] = System.Runtime.InteropServices.Marshal.ReadByte(data.Scan0, i);
         *              }
         *
         *              int nColumns = (int)Math.Truncate(128.0 / 8);
         *              size = (size - (size % ((8 * nColumns) * 8)));
         *              if (size == imageSize * 2)
         *              {
         *                  switch (type)
         *                  {
         *                      case 01:
         *                          newBytes = InvertingTransformations.import1bpp(bitmapPixels, 8, 8, size);
         *                          break;
         *                      case 02:
         *                          newBytes = InvertingTransformations.import2bpp(bitmapPixels, 8, 8, size);
         *                          break;
         *                      case 03:
         *                          newBytes = InvertingTransformations.import3bpp(bitmapPixels, 8, 8, size);
         *                          break;
         *                      case 04:
         *                          newBytes = InvertingTransformations.import4bpp(bitmapPixels, 8, 8, size);
         *                          break;
         *                      default:
         *                          break;
         *                  };
         *              }
         *              else
         *              {
         *                  newBytes = new List<Byte>();
         *              }
         *          }
         *          catch (Exception error)
         *          {
         *              System.Windows.Forms.MessageBox.Show("Error reading the file: " + error.ToString(), "Error");
         *          }
         *      }
         *  }
         *
         *  openFileDialog.Dispose();
         *  openFileDialog = null;
         *
         *  newBytes = Compressor.compress(newBytes, null);
         *  newBytes.Insert(0, BitConverter.GetBytes(imageSize)[1]);
         *  newBytes.Insert(0, BitConverter.GetBytes(imageSize)[0]);
         *
         *  if(!unheaded)
         *    newBytes.Insert(0, 0x02);
         *
         *  if (newBytes.Count <= maxCompSize)
         *  {
         *      try
         *      {
         *          bw.BaseStream.Position = address + headerOffset;
         *
         *          foreach (Byte item in newBytes)
         *          {
         *              bw.BaseStream.WriteByte(item);
         *          }
         *
         *          System.Windows.Forms.MessageBox.Show("Operation done successfully.", "Info");
         *      }
         *      catch (Exception e)
         *      {
         *          System.Windows.Forms.MessageBox.Show("Error writing the file: " + e.ToString(), "Error");
         *      }
         *  }
         *  else
         *  {
         *      System.Windows.Forms.MessageBox.Show("Compressed data is bigger than expected.", "Error");
         *  }
         * }
         */



        public static void injectNewTitleOAM(System.IO.BinaryWriter bw, int headerOffset)
        {
            List <Byte> newTable = new List <byte>()
            {
                //  Ac    AX    AY    TL    Fl    B1    B2
                //----------------------------------------
                0x40, 0x58, 0xB8, 0x80, 0x38, 0x00, 0x00, // (C)
                0x8F, 0x10, 0x00, 0x81, 0x38, 0x00, 0x00, // S
                0x8F, 0x08, 0x00, 0x82, 0x38, 0x00, 0x00, // Q
                0x8F, 0x08, 0x00, 0x83, 0x38, 0x00, 0x00, // U
                0x8F, 0x08, 0x00, 0x84, 0x38, 0x00, 0x00, // A
                0x8F, 0x08, 0x00, 0x85, 0x38, 0x00, 0x00, // R
                0x8F, 0x08, 0x00, 0x86, 0x38, 0x00, 0x00, // E
                0x8F, 0x10, 0x00, 0x87, 0x38, 0x00, 0x00, // 19
                0x8F, 0x08, 0x00, 0x88, 0x38, 0x00, 0x00, // 92
                0x49, 0x20, 0x00, 0x00, 0x0C, 0x08, 0x00, // Dragon
                0x8F, 0x10, 0x00, 0x02, 0x0C, 0x20, 0x00,
                0x8F, 0x10, 0x00, 0x04, 0x0C, 0x80, 0x00,
                0x8F, 0x10, 0x00, 0x06, 0x0C, 0x00, 0x02,
                0x8F, 0x10, 0x00, 0x08, 0x0C, 0x00, 0x08,
                0x8F, 0x10, 0x00, 0x0A, 0x0C, 0x00, 0x20,
                0x8F, 0x10, 0x00, 0x0C, 0x0C, 0x00, 0x80,
                0x8F, 0xA0, 0x10, 0x20, 0x0C, 0x02, 0x00,
                0x8F, 0x10, 0x00, 0x22, 0x0C, 0x08, 0x00,
                0x8F, 0x10, 0x00, 0x24, 0x0C, 0x20, 0x00,
                0x8F, 0x10, 0x00, 0x26, 0x0C, 0x80, 0x00,
                0x8F, 0x10, 0x00, 0x28, 0x0C, 0x00, 0x02,
                0x8F, 0x10, 0x00, 0x2A, 0x0C, 0x00, 0x08,
                0x8F, 0x10, 0x00, 0x2C, 0x0C, 0x00, 0x20,
                0x8F, 0x10, 0x00, 0x2E, 0x0C, 0x00, 0x80,
                0x8F, 0x90, 0x10, 0x40, 0x0C, 0x02, 0x00,
                0x8F, 0x10, 0x00, 0x42, 0x0C, 0x08, 0x00,
                0x8F, 0x10, 0x00, 0x44, 0x0C, 0x20, 0x00,
                0x8F, 0x10, 0x00, 0x46, 0x0C, 0x80, 0x00,
                0x8F, 0x10, 0x00, 0x48, 0x0C, 0x00, 0x02,
                0x8F, 0x10, 0x00, 0x4A, 0x0C, 0x00, 0x08,
                0x8F, 0x10, 0x00, 0x4C, 0x0C, 0x00, 0x20,
                0x8F, 0x10, 0x00, 0x4E, 0x0C, 0x00, 0x80,
                0x8F, 0x90, 0x10, 0x60, 0x0C, 0x02, 0x00,
                0x8F, 0x10, 0x00, 0x62, 0x0C, 0x08, 0x00,
                0x8F, 0x10, 0x00, 0x64, 0x0C, 0x20, 0x00,
                0x8F, 0x10, 0x00, 0x66, 0x0C, 0x80, 0x00,
                0x8F, 0x10, 0x00, 0x68, 0x0C, 0x00, 0x02,
                0x8F, 0x10, 0x00, 0x6A, 0x0C, 0x00, 0x08,
                0x8F, 0x10, 0x00, 0x6C, 0x0C, 0x00, 0x20,
                0x8F, 0x10, 0x00, 0x6E, 0x0C, 0x00, 0x80,
                0x8F, 0x10, 0xE0, 0x0E, 0x0C, 0x02, 0x00,
                0x70, 0x69, 0xC2, 0x8A, 0x38, 0x00, 0x00, // noisecross
                0x8F, 0x08, 0x00, 0x8B, 0x38, 0x00, 0x00,
                0x8F, 0x08, 0x00, 0x8C, 0x38, 0x00, 0x00,
                0x8F, 0x08, 0x00, 0x8D, 0x38, 0x00, 0x00,
                0x8F, 0x08, 0x00, 0x8E, 0x38, 0x00, 0x00,
                0x8F, 0x08, 0x00, 0x8F, 0x38, 0x00, 0x00,
                0x76, 0x69, 0xCB, 0x9A, 0x38, 0x00, 0x00,
                0x8F, 0x08, 0x00, 0x9B, 0x38, 0x00, 0x00,
                0x8F, 0x08, 0x00, 0x9C, 0x38, 0x00, 0x00,
                0x8F, 0x08, 0x00, 0x9D, 0x38, 0x00, 0x00,
                0x8F, 0x08, 0x00, 0x9E, 0x38, 0x00, 0x00,
                0x8F, 0x08, 0x00, 0x9F, 0x38, 0x00, 0x00,
                0x7C, 0xA0, 0xC7, 0x97, 0x38, 0x00, 0x00, // 2015
                0x8F, 0x08, 0x00, 0x98, 0x38, 0x00, 0x00,
                0x80
            };
            int imageSize = newTable.Count;

            newTable = Compressor.compress(newTable, null);

            newTable.Insert(0, BitConverter.GetBytes(imageSize)[1]);
            newTable.Insert(0, BitConverter.GetBytes(imageSize)[0]);
            newTable.Insert(0, 0x02);

            if (newTable.Count <= 0x450)
            {
                try
                {
                    bw.BaseStream.Position = 0x105C0A + headerOffset;

                    foreach (Byte item in newTable)
                    {
                        bw.BaseStream.WriteByte(item);
                    }

                    System.Windows.Forms.MessageBox.Show("Operation done successfully.", "Info");
                }
                catch (Exception e)
                {
                    System.Windows.Forms.MessageBox.Show("Error writing the file: " + e.ToString(), "Error");
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Compressed data is bigger than expected.", "Error");
            }
        }