Beispiel #1
0
		public static BitmapSource Deswizzle(string FilePath, int resizeWidth = -1, int resizeHeight = -1,
			bool onlyResizeIfGreater = false, bool dontSettingsResize = false)
		{
			//Open the temp dds
			var fs = new FileStream(FilePath, FileMode.Open, FileAccess.ReadWrite);
			var es = new EndianStream(fs, Endian.LittleEndian);

			//Read the dds header
			es.SeekTo(0x0C);
			int height = es.ReadInt32();
			int width = es.ReadInt32();

			//Read our random bytes
			es.SeekTo(0x5C);
			string randomBuf = BitConverter.ToString(es.ReadBlock(12)).Replace("-", "");

			//Read the buffer
			es.SeekTo(0x80);
			int size = width*height*4;
			byte[] buffer = es.ReadBlock(size);
			es.Close();

			Bitmap bitmap = null;

			//A2R10G10B10
			switch (randomBuf)
			{
				case "FF03000000FC0F000000F03F":
					bitmap = DeswizzleA2R10G10B10(buffer, width, height);
					if (App.AssemblyStorage.AssemblySettings.XdkScreenshotGammaCorrect)
					{
						BitmapData imageData = (bitmap).LockBits(
							new Rectangle(0, 0, bitmap.Width, bitmap.Height),
							ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
						GammaCorrect(App.AssemblyStorage.AssemblySettings.XdkScreenshotGammaModifier, imageData);
						bitmap.UnlockBits(imageData);
					}
					break;
				case "0000FF0000FF0000FF000000":
					bitmap = DeswizzleA8R8G8B8(buffer, width, height);
					break;
			}

			if (bitmap == null)
				return null;

			// Resize
			if (App.AssemblyStorage.AssemblySettings.XdkResizeImages && !dontSettingsResize)
				bitmap = ResizeImage(bitmap);

			if (width != -1 && height != -1)
				if (onlyResizeIfGreater && (bitmap.Width > width && bitmap.Height > height))
					bitmap = ResizeImage(bitmap, width, height);
				else
					bitmap = ResizeImage(bitmap, width, height);

			return loadBitmap(bitmap);
		}
Beispiel #2
0
        public static BitmapSource Deswizzle(string FilePath)
        {
            //Open the temp dds
            var fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read);
            var es = new EndianStream(fs, Endian.LittleEndian);

            //Read the dds header
            es.SeekTo(0x0C);
            var height = es.ReadInt32();
            var width = es.ReadInt32();

            //Read our random bytes
            es.SeekTo(0x5C);
            var randomBuf = BitConverter.ToString(es.ReadBlock(12)).Replace("-", "");

            //Read the buffer
            es.SeekTo(0x80);
            var size = width * height * 4;
            var buffer = es.ReadBlock(size);
            es.Close();

            Bitmap bitmap = null;

            //A2R10G10B10
            switch (randomBuf)
            {
                case "FF03000000FC0F000000F03F":
                    bitmap = DeswizzleA2R10G10B10(buffer, width, height);
                    if (Settings.XDKScreenshotGammaCorrect)
                    {
                        var imageData = (bitmap).LockBits(
                            new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                            ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
                        GammaCorrect(Settings.XDKScreenshotGammaModifier, imageData);
                        bitmap.UnlockBits(imageData);
                    }
                    break;
                case "0000FF0000FF0000FF000000":
                    bitmap = DeswizzleA8R8G8B8(buffer, width, height);
                    break;
            }

            if (bitmap == null)
                return null;

            // Resize
            if (Settings.XDKResizeImages)
                bitmap = ResizeImage(bitmap);

            return loadBitmap(bitmap);
        }
Beispiel #3
0
		private void btnExtractInfo_Click(object sender, RoutedEventArgs e)
		{
			System.Windows.Clipboard.SetText("Name: " + txtApplyPatchName.Text +
				"\r\nDescription: " + txtApplyPatchDesc.Text);

			var messageString = "The patch name and description has been copied to the clipboard.";

			if (currentPatch.Screenshot != null)
				try
				{
					var stream = new EndianStream(new MemoryStream(currentPatch.Screenshot), Endian.BigEndian);
					stream.SeekTo(0x0);
					ushort imageMagic = stream.ReadUInt16();

					var sfd = new SaveFileDialog();
					sfd.Title = "Assembly - Save Patch Image";

					switch (imageMagic)
					{
						case 0x8950:
							sfd.Filter = "PNG Image (*.png)|*.png";
							break;
						default:
							sfd.Filter = "JPEG Image (*.jpg)|*.jpg";
							break;
					}
					if (sfd.ShowDialog() == DialogResult.OK)
					{
						File.WriteAllBytes(sfd.FileName, currentPatch.Screenshot);
						messageString += "\r\n\r\nThe patch image has been saved.";
					}
				}
				catch (Exception ex)
				{
					messageString += "\r\n\r\nThe patch image could not saved: \n" + ex.Message;
				}

			MetroMessageBox.Show("Information Extracted!", messageString);
		}
Beispiel #4
0
        private void loadBLF()
        {
            try
            {
                _blf = new PureBLF(_blfLocation);

                var imgChunkData = new List<byte>(_blf.BLFChunks[1].ChunkData);
                imgChunkData.RemoveRange(0, 0x08);

                Dispatcher.Invoke(new Action(delegate
                {
                    var image = new BitmapImage();
                    image.BeginInit();
                    image.StreamSource = new MemoryStream(imgChunkData.ToArray());
                    image.EndInit();

                    imgBLF.Source = image;

                    var stream = new EndianStream(new MemoryStream(imgChunkData.ToArray<byte>()), Endian.BigEndian);
                    stream.SeekTo(0x0);
                    ushort imageMagic = stream.ReadUInt16();

                    switch (imageMagic)
                    {
                        case 0xFFD8:
                            blfImageFormat = "JPEG";
                            break;
                        case 0x8950:
                            blfImageFormat = "PNG";
                            break;
                        case 0x424D:
                            blfImageFormat = "BMP";
                            break;
                        default:
                            blfImageFormat = "Unknown";
                            break;
                    }

                    // Add Image Info
                    paneImageInfo.Children.Insert(0, new MapHeaderEntry("Image Format:", blfImageFormat));
                    paneImageInfo.Children.Insert(1, new MapHeaderEntry("Image Width:", image.PixelWidth + "px"));
                    paneImageInfo.Children.Insert(2, new MapHeaderEntry("Image Height", image.PixelHeight + "px"));

                    // Add BLF Info
                    paneBLFInfo.Children.Insert(0, new MapHeaderEntry("BLF Length:", "0x" + _blf.BLFStream.Length.ToString("X")));
                    paneBLFInfo.Children.Insert(1,
                        new MapHeaderEntry("BLF Chunks:", _blf.BLFChunks.Count.ToString(CultureInfo.InvariantCulture)));

                    if (App.AssemblyStorage.AssemblySettings.StartpageHideOnLaunch)
                        App.AssemblyStorage.AssemblySettings.HomeWindow.ExternalTabClose(Home.TabGenre.StartPage);

                    RecentFiles.AddNewEntry(new FileInfo(_blfLocation).Name, _blfLocation, "BLF Image", Settings.RecentFileType.Blf);
                    Close();
                }));
            }
            catch (Exception ex)
            {
                Close();
                Dispatcher.Invoke(new Action(delegate
                {
                    MetroMessageBox.Show("Unable to open BLF", ex.Message.ToString(CultureInfo.InvariantCulture));
                    App.AssemblyStorage.AssemblySettings.HomeWindow.ExternalTabClose((LayoutDocument)Parent);
                }));
            }
        }
Beispiel #5
0
        private void btnInjectImage_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                _blf = new PureBLF(_blfLocation);
                var ofd = new OpenFileDialog
                {
                    Title = "Open an image to be injected",
                    Filter = "JPEG Image (*.jpg,*.jpeg,)|*.jpg;*.jpeg|PNG Image [H3/ODST]|*.png|BMP Image [H3/ODST]|*.bmp"
                };

                if (!((bool)ofd.ShowDialog()))
                {
                    Close();
                    return;
                }
                byte[] newImage = File.ReadAllBytes(ofd.FileName);
                var stream = new EndianStream(new MemoryStream(newImage), Endian.BigEndian);

                // Check if it's a supported image
                stream.SeekTo(0x0);
                ushort imageMagic = stream.ReadUInt16();
                if (imageMagic != 0xFFD8 && imageMagic != 0x8950 && imageMagic != 0x424D)
                    throw new Exception("Invalid image type. Only JPEG, PNG, and BMP are supported.");

                // Check for size and dimension differences
                var imageSize = new FileInfo(ofd.FileName).Length;
                var image = new BitmapImage();
                image.BeginInit();
                image.StreamSource = new MemoryStream(newImage);
                image.EndInit();
                string sizeMessage = "";
                string dimensionMessage = "";

                if (new FileInfo(ofd.FileName).Length >= 0x1C000)
                    sizeMessage = String.Format("- The size of the new image (0x{0}) exceeds Halo 3/ODST's modified limit of 0x1C000. This image will not display in those games as a result. Can be ignored otherwise.\n",
                        imageSize.ToString("X"));

                if (image.PixelWidth != ((BitmapImage)imgBLF.Source).PixelWidth ||
                    image.PixelHeight != ((BitmapImage)imgBLF.Source).PixelHeight)
                    dimensionMessage = String.Format("- The dimensions of the new image ({0}x{1}) are not the same as the dimensions of the original image ({2}x{3}). This blf may appear stretched or not appear at all as a result.\n",
                        image.PixelWidth, image.PixelHeight, ((BitmapImage)imgBLF.Source).PixelWidth, ((BitmapImage)imgBLF.Source).PixelHeight);

                if (dimensionMessage != "" || sizeMessage != "")
                    if (MetroMessageBox.Show("Warning",
                        "There were some potential issue(s) found with your new image;\n\n" + String.Format("{0}{1}",
                        sizeMessage, dimensionMessage) + "\nInject anyway?",
                        MetroMessageBox.MessageBoxButtons.OkCancel) != MetroMessageBox.MessageBoxResult.OK)
                        {
                            Close();
                            return;
                        }

                // It's the right everything! Let's inject

                var newImageChunkData = new List<byte>();
                newImageChunkData.AddRange(new byte[] { 0x00, 0x00, 0x00, 0x00 });
                byte[] imageLength = BitConverter.GetBytes(newImage.Length);
                Array.Reverse(imageLength);
                newImageChunkData.AddRange(imageLength);
                newImageChunkData.AddRange(newImage);

                // Write data to chunk file
                _blf.BLFChunks[1].ChunkData = newImageChunkData.ToArray<byte>();

                _blf.RefreshRelativeChunkData();
                _blf.UpdateChunkTable();

                // Update eof offset value
                var eofstream = new EndianStream(new MemoryStream(_blf.BLFChunks[2].ChunkData), Endian.BigEndian);

                uint eofFixup = (uint)_blf.BLFStream.Length - 0x111; //real cheap but hey it works and is always the same in all games

                eofstream.SeekTo(0);
                eofstream.WriteUInt32(eofFixup);

                _blf.RefreshRelativeChunkData();
                _blf.UpdateChunkTable();

                Close();
                MetroMessageBox.Show("Injected!", "The BLF Image has been injected. This image tab will now close.");
                App.AssemblyStorage.AssemblySettings.HomeWindow.ExternalTabClose(_tab);
            }
            catch (Exception ex)
            {
                Close();
                MetroMessageBox.Show("Inject Failed!", "The BLF Image failed to be injected: \n " + ex.Message);
            }
        }
        private void ProcessMapHeader()
        {
            using (IReader reader = new EndianStream(new MemoryStream(MapHeader), Endian.LittleEndian))
            {
                reader.SeekTo(MapTypeOffset);
                MapType = (CacheFileType) reader.ReadInt32();

                reader.SeekTo(MapNameOffset);
                MapName = reader.ReadAscii();

                reader.SeekTo(ScenarioNameOffset);
                ScenarioName = reader.ReadAscii();
            }
        }
Beispiel #7
0
        private void StartupDetermineType(string path)
        {
            try
            {
                if (File.Exists(path))
                {
                    // Magic Check
                    var stream = new EndianStream(new FileStream(path, FileMode.Open), Endian.BigEndian);
                    stream.SeekTo(0);

                    switch (stream.ReadAscii(0x04).ToLower())
                    {
                        case "head":
                            // Map File
                            stream.Close();
                            AddCacheTabModule(path);
                            return;

                        case "asmp":
                            // Patch File
                            stream.Close();
                            AddPatchTabModule(path);
                            return;

                        case "_blf":
                            // BLF Container, needs more checking
                            stream.Close();
                            var blf = new PureBLF(path);
                            blf.Close();
                            if (blf.BLFChunks.Count > 2)
                            {
                                switch (blf.BLFChunks[1].ChunkMagic)
                                {
                                    case "levl":
                                        AddInfooTabModule(path);
                                        return;
                                    case "mapi":
                                        AddImageTabModule(path);
                                        return;
                                }
                            }
                            MetroMessageBox.Show("Unsupported BLF Type", "The selected BLF file is not supported in assembly.");
                            return;

                        default:
                            MetroMessageBox.Show("Unsupported file type", "The selected file is not supported in assembly.");
                            return;
                    }
                }

                MetroMessageBox.Show("Unable to find file", "The selected file could no longer be found");
            }
            catch (Exception ex) { MetroException.Show(ex); }
        }
Beispiel #8
0
        private void btnInjectImage_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var ofd = new OpenFileDialog
                              {
                                  Title = "Opem an image to be injected",
                                  Filter = "JPEG Image (*.jpg)|*.jpg|JPEG Image (*.jpeg)|*.jpeg"
                              };

                if (!((bool) ofd.ShowDialog())) return;

                var newImage = File.ReadAllBytes(ofd.FileName);
                var stream = new EndianStream(new MemoryStream(newImage), Endian.BigEndian);

                // Check if it's a JIFI
                stream.SeekTo(0x02);
                var imageMagic = stream.ReadAscii();
                if (imageMagic != "JFIF")
                    throw new Exception("Invalid image type, it has to be a JPEG (JFIF in the header).");

                // Check if it's the right size
                var image = new BitmapImage();
                image.BeginInit();
                image.StreamSource = new MemoryStream(newImage);
                image.EndInit();

                if (image.PixelWidth != ((BitmapImage)imgBLF.Source).PixelWidth || image.PixelHeight != ((BitmapImage)imgBLF.Source).PixelHeight)
                    throw new Exception(string.Format("Image isn't the right size. It must be {0}x{1}", ((BitmapImage)imgBLF.Source).PixelWidth, ((BitmapImage)imgBLF.Source).PixelHeight));

                // It's the right everything! Let's inject

                var newImageChunkData = new List<byte>();
                newImageChunkData.AddRange(new byte[] { 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 });
                var imageLength = BitConverter.GetBytes(newImage.Length);
                Array.Reverse(imageLength);
                newImageChunkData.AddRange(imageLength);
                newImageChunkData.AddRange(newImage);

                // Write data to chunk file
                _blf.BLFChunks[1].ChunkData = newImageChunkData.ToArray<byte>();

                _blf.RefreshRelativeChunkData();
                _blf.UpdateChunkTable();

                imgBLF.Source = image;

                MetroMessageBox.Show("Injected!", "The BLF Image has been injected.");
            }
            catch (Exception ex)
            {
                MetroMessageBox.Show("Inject Failed!", "The BLF Image failed to be injected: \n " + ex.Message);
            }
        }