Exemplo n.º 1
0
        static void Main(string[] args)
        {
            String[]      UnpackedAssetPaths = Directory.GetDirectories(Directory.GetCurrentDirectory());
            EndianWriter  Writer             = new EndianWriter(File.Open("!MKTRT_A_out.txt", FileMode.Create), Endianness.BigEndian);
            List <String> HashList           = new List <String>();

            for (int i = 0; i < UnpackedAssetPaths.Length; i++)
            {
                if (Path.GetFileName(UnpackedAssetPaths[i]).EndsWith("_unpacked") && !HashList.Contains(Path.GetFileName(UnpackedAssetPaths[i]).Split('_')[1]))
                {
                    Writer.WriteString(Path.GetFileName(UnpackedAssetPaths[i]).Split('_')[1] + "=");
                    String[] AssetBundleFiles = Directory.GetFiles(UnpackedAssetPaths[i]);
                    String   FileName         = "";
                    for (int j = 0; j < AssetBundleFiles.Length; j++)
                    {
                        if (Path.GetFileName(AssetBundleFiles[j]).StartsWith("CAB-") && !Path.GetFileName(AssetBundleFiles[j]).EndsWith(".resS"))
                        {
                            FileName = FindString(AssetBundleFiles[j], new byte[] { 0x61, 0x73, 0x73, 0x65, 0x74, 0x73, 0x2F });
                        }
                        else if (Path.GetFileName(AssetBundleFiles[j]).EndsWith(".sharedAssets"))
                        {
                            FileName = FindString(AssetBundleFiles[j], new byte[] { 0x41, 0x73, 0x73, 0x65, 0x74, 0x73, 0x2F });
                        }
                    }
                    Console.WriteLine(FileName);
                    Writer.WriteString(FileName + "\r\n");
                    HashList.Add(Path.GetFileName(UnpackedAssetPaths[i]).Split('_')[1]);
                }
            }
            Writer.Close();
        }
Exemplo n.º 2
0
        public bool WriteToFile(string fileName)
        {
            EndianWriter writer = null;

            try
            {
                // Open the output file in an EndianWriter.
                writer = new EndianWriter(Endianness.Little, new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None));
            }
            catch (Exception e)
            {
                // Failed to open the output file for writing.
                return(false);
            }

            // Write the normal DDS header.
            writer.Write(this.header.dwMagic);
            writer.Write(this.header.dwSize);
            writer.Write((int)this.header.dwFlags);
            writer.Write(this.header.dwHeight);
            writer.Write(this.header.dwWidth);
            writer.Write(this.header.dwPitchOrLinearSize);
            writer.Write(this.header.dwDepth);
            writer.Write(this.header.dwMipMapCount);
            writer.WritePadding(11 * 4);
            writer.Write(this.header.ddspf.dwSize);
            writer.Write((int)this.header.ddspf.dwFlags);
            writer.Write(this.header.ddspf.dwFourCC);
            writer.Write(this.header.ddspf.dwRGBBitCount);
            writer.Write(this.header.ddspf.dwRBitMask);
            writer.Write(this.header.ddspf.dwGBitMask);
            writer.Write(this.header.ddspf.dwBBitMask);
            writer.Write(this.header.ddspf.dwABitMask);
            writer.Write((int)this.header.dwCaps);
            writer.Write((int)this.header.dwCaps2);
            writer.Write(this.header.dwCaps3);
            writer.Write(this.header.dwCaps4);
            writer.WritePadding(4);

            // Check if we are using a DX10 header and if so write it to file.
            if (this.header.ddspf.dwFourCC == MakeFourCC("DX10"))
            {
                // Write the dx10 header.
                writer.Write((int)this.dxt10header.dxgiFormat);
                writer.Write((int)this.dxt10header.resourceDimension);
                writer.Write((int)this.dxt10header.miscFlag);
                writer.Write(this.dxt10header.arraySize);
                writer.Write(this.dxt10header.miscFlags2);
            }

            // Write the pixel data to file.
            writer.Write(this.PixelBuffer);

            // Close the file and return.
            writer.Close();
            return(true);
        }
Exemplo n.º 3
0
        public void SaveStrings(IStream stream, List <LocalizedString> locales)
        {
            var offsetData   = new MemoryStream();
            var stringData   = new MemoryStream();
            var offsetWriter = new EndianWriter(offsetData, Endian.BigEndian);
            var stringWriter = new EndianWriter(stringData, Endian.BigEndian);

            try
            {
                // Write the string and offset data to buffers
                foreach (LocalizedString locale in locales)
                {
                    WriteLocalePointer(offsetWriter, locale.Key, (int)stringWriter.Position);
                    stringWriter.WriteUTF8(locale.Value);
                }

                // Round the size of the string data up
                var dataSize = (int)((stringData.Position + _sizeAlign - 1) & ~(_sizeAlign - 1));
                stringData.SetLength(dataSize);

                // Update the two locale data hashes if we need to
                // (the hash arrays are set to null if the build doesn't need them)
                if (IndexTableHash != null)
                {
                    IndexTableHash = SHA1.Transform(offsetData.GetBuffer(), 0, (int)offsetData.Length);
                }
                if (StringDataHash != null)
                {
                    StringDataHash = SHA1.Transform(stringData.GetBuffer(), 0, dataSize);
                }

                // Make sure there's free space for the offset table and then write it to the file
                LocaleIndexTable.Resize((int)offsetData.Length, stream);
                stream.SeekTo(LocaleIndexTableLocation.AsOffset());
                stream.WriteBlock(offsetData.GetBuffer(), 0, (int)offsetData.Length);

                // Encrypt the string data if necessary
                byte[] strings = stringData.GetBuffer();
                if (_encryptionKey != null)
                {
                    strings = AES.Encrypt(strings, 0, dataSize, _encryptionKey.Key, _encryptionKey.IV);
                }

                // Make sure there's free space for the string data and then write it to the file
                LocaleData.Resize(dataSize, stream);
                stream.SeekTo(LocaleDataLocation.AsOffset());
                stream.WriteBlock(strings, 0, dataSize);

                // Update the string count and recalculate the language table offsets
                StringCount = locales.Count;
            }
            finally
            {
                offsetWriter.Close();
                stringWriter.Close();
            }
        }
Exemplo n.º 4
0
        public void SaveTemp(int index)
        {
            var tempName = Path.GetTempPath() + "temp_playback.xma";

            var playback = ugh.PlayBacks[snd.PlaybackIndex];
            var perm     = cache.ugh_.SoundPermutations[playback.FirstPermutation + index];
            var data     = cache.GetSoundRaw(snd.RawID, GetTotalSize(ugh, playback));

            byte[] buffer;

            if (index == -1)
            {
                buffer = data;
            }
            else
            {
                buffer = GetPermData(data, ugh, perm);
            }

            var codec = cache.ugh_.Codecs[snd.CodecIndex];
            var xma   = GetXMA(buffer, snd.SampleRate, codec.Type);

            var          fs = File.OpenWrite(tempName);
            EndianWriter sw = new EndianWriter(fs, EndianFormat.BigEndian);

            sw.Write(xma);

            sw.Close();
            sw.Dispose();

            var info = new ProcessStartInfo(towav, tempName)
            {
                CreateNoWindow   = true,
                UseShellExecute  = false,
                WorkingDirectory = Path.GetTempPath()
            };

            Process.Start(info).WaitForExit();
            if (File.Exists(tempName))
            {
                File.Delete(tempName);
            }
        }
Exemplo n.º 5
0
        public static void DeleteBytes(string filePath, int startOffset, int size)
        {
            var input      = new FileStream(filePath, FileMode.Open);
            var er         = new EndianReader(input);
            var buffer     = er.ReadBytes(startOffset);
            var baseStream = er.BaseStream;

            baseStream.Position += size;
            var buffer2 = er.ReadBytes(((int)er.BaseStream.Length) - ((int)er.BaseStream.Position));

            er.Close();
            input.Close();
            input = new FileStream(filePath, FileMode.Create);
            var ew = new EndianWriter(input);

            ew.Write(buffer);
            ew.Write(buffer2);
            input.Close();
            ew.Close();
        }
Exemplo n.º 6
0
        private void SaveData(IStream stream)
        {
            // Create a memory buffer and write the strings there
            var buffer       = new MemoryStream();
            var bufferWriter = new EndianWriter(buffer, stream.Endianness);

            try
            {
                // Write the strings to the buffer
                foreach (string str in _strings)
                {
                    if (str != null)
                    {
                        bufferWriter.WriteAscii(str);
                    }
                }

                // Align the buffer's length if encryption is necessary
                if (_key != null)
                {
                    buffer.SetLength(AES.AlignSize((int)buffer.Length));
                }

                byte[] data = buffer.GetBuffer();

                // Encrypt the buffer if necessary
                if (_key != null)
                {
                    data = AES.Encrypt(data, 0, (int)buffer.Length, _key.Key, _key.IV);
                }

                // Resize the data area and write it in
                _data.Resize((int)buffer.Length, stream);
                stream.SeekTo(_data.Offset);
                stream.WriteBlock(data, 0, (int)buffer.Length);
            }
            finally
            {
                bufferWriter.Close();
            }
        }
Exemplo n.º 7
0
        public static void InsertBytes(string filePath, int startOffset, int size)
        {
            var input = new FileStream(filePath, FileMode.Open);
            var er    = new EndianReader(input)
            {
                BaseStream = { Position = startOffset }
            };
            var buffer = er.ReadBytes(((int)er.BaseStream.Length) - ((int)er.BaseStream.Position));

            er.Close();
            input.Close();
            input = new FileStream(filePath, FileMode.Open);
            var ew = new EndianWriter(input)
            {
                BaseStream = { Position = startOffset }
            };

            ew.Write(new byte[size]);
            ew.Write(buffer);
            input.Close();
            ew.Close();
        }
Exemplo n.º 8
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                FileStream stream = new FileStream(ofd.FileName, FileMode.Open);
                EndianReader reader = new EndianReader(stream, EndianType.BigEndian);
                EndianWriter writer = new EndianWriter(stream, EndianType.BigEndian);

                int CSum = 0;
                reader.BaseStream.Position = 0xD000;
                for (int i = 0; i < 0x768; i += 4)
                    CSum += reader.ReadInt32();

                writer.Write(CSum);
                writer.Flush();
                writer.Close();
                reader.Close();
                MessageBox.Show("New Checksum: " + CSum.ToString("X2"), "Done!");
            }
        }
Exemplo n.º 9
0
        private void SaveData(IStream stream)
        {
            // Create a memory buffer and write the strings there
            var buffer       = new MemoryStream();
            var bufferWriter = new EndianWriter(buffer, stream.Endianness);

            try
            {
                int count            = _strings.Count();
                int start_offset     = 0x8 + count * 4; // Start data offset of the first string
                int string_data_size = 0;
                foreach (string str in _strings)
                {
                    string_data_size += str.Length + 1;
                }
                int data_size = start_offset + string_data_size;

                // Headder
                bufferWriter.WriteInt32(count);
                bufferWriter.WriteInt32(data_size);

                // Offsets
                SaveOffsets(stream);

                // Write the strings to the buffer
                foreach (string str in _strings)
                {
                    if (str != null)
                    {
                        bufferWriter.WriteAscii(str);
                    }
                }
            }
            finally
            {
                bufferWriter.Close();
            }
        }
Exemplo n.º 10
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                FileStream   stream = new FileStream(ofd.FileName, FileMode.Open);
                EndianReader reader = new EndianReader(stream, EndianType.BigEndian);
                EndianWriter writer = new EndianWriter(stream, EndianType.BigEndian);

                int CSum = 0;
                reader.BaseStream.Position = 0xD000;
                for (int i = 0; i < 0x768; i += 4)
                {
                    CSum += reader.ReadInt32();
                }

                writer.Write(CSum);
                writer.Flush();
                writer.Close();
                reader.Close();
                MessageBox.Show("New Checksum: " + CSum.ToString("X2"), "Done!");
            }
        }
Exemplo n.º 11
0
        public static byte[] GetXMA(byte[] buffer, SampleRate sRate, SoundType sType)
        {
            int rate;

            switch (sRate)
            {
            case SampleRate._22050Hz:
                rate = 22050;
                break;

            case SampleRate._44100Hz:
                rate = 44100;
                break;

            default:
                rate = 44100;
                break;
                //throw new Exception("Check sample rate.");
            }

            int cCount;

            switch (sType)
            {
            case SoundType.Mono:
                cCount = 1;
                break;

            case SoundType.Stereo:
                cCount = 2;
                break;

            //case SoundType.Unknown2:
            //    cCount = 2;
            //    footer = stereoFooter;
            //    break;
            //case SoundType.Unknown3:
            //    cCount = 2;
            //    footer = stereoFooter;
            //    break;
            default:
                throw new NotSupportedException("Unsupported Sound Type.");
            }

            var          ms = new MemoryStream();
            EndianWriter sw = new EndianWriter(ms, EndianFormat.BigEndian);

            sw.Write(0x52494646); // 'RIFF'
            sw.EndianType = EndianFormat.LittleEndian;
            sw.Write(buffer.Length + 0x34);
            sw.EndianType = EndianFormat.BigEndian;
            sw.Write(RIFFFormat.WAVE);

            // Generate the 'fmt ' chunk
            sw.Write(0x666D7420); // 'fmt '
            sw.EndianType = EndianFormat.LittleEndian;
            sw.Write(0x20);
            sw.Write((short)0x165);
            sw.Write((short)16);
            sw.Write((short)0);
            sw.Write((short)0);
            sw.Write((short)1);
            sw.Write((byte)0);
            sw.Write((byte)3);
            sw.Write(0);
            sw.Write(rate);
            sw.Write(0);
            sw.Write(0);
            sw.Write((byte)0);
            sw.Write((byte)cCount);
            sw.Write((short)0x0002);

            // 'data' chunk
            sw.EndianType = EndianFormat.BigEndian;
            sw.Write(0x64617461); // 'data'
            sw.EndianType = EndianFormat.LittleEndian;
            sw.Write(buffer.Length);
            sw.Write(buffer);

            sw.Close();
            sw.Dispose();

            return(ms.ToArray());
        }
Exemplo n.º 12
0
        /// <summary>
        /// Saves all permutations of a sound tag concatenated as a single sound file.
        /// </summary>
        /// <param name="Filename">The file to save the data to.</param>
        /// <param name="Cache">The CacheFile containing the tag.</param>
        /// <param name="Tag">The sound tag.</param>
        /// <param name="Format">The format in which to save the data.</param>
        public static void SaveAllAsSingle(string Filename, CacheBase Cache, CacheBase.IndexItem Tag, SoundFormat Format)
        {
            var snd_ = DefinitionsManager.snd_(Cache, Tag);

            #region XMA
            if (Format == SoundFormat.XMA)
            {
                var total = GetTotalSize(Cache.ugh_, Cache.ugh_.PlayBacks[snd_.PlaybackIndex]);

                byte[] buffer = Cache.GetSoundRaw(snd_.RawID, total);

                if (buffer.Length == 0)
                {
                    throw new Exception("Empty raw data.");
                }
                var codec = Cache.ugh_.Codecs[snd_.CodecIndex];
                var xma   = GetXMA(buffer, snd_.SampleRate, codec.Type);

                if (!Directory.GetParent(Filename).Exists)
                {
                    Directory.GetParent(Filename).Create();
                }

                var          fs = File.OpenWrite(Filename);
                EndianWriter sw = new EndianWriter(fs, EndianFormat.BigEndian);
                sw.Write(xma);

                sw.Close();
                sw.Dispose();
            }
            #endregion
            #region WAV
            else if (Format == SoundFormat.WAV)
            {
                var tempName = Path.GetTempFileName();

                SaveAllAsSingle(tempName, Cache, Tag, SoundFormat.XMA);

                var info = new ProcessStartInfo(towav, tempName)
                {
                    CreateNoWindow   = true,
                    UseShellExecute  = false,
                    WorkingDirectory = Directory.GetParent(tempName).FullName
                };

                Process.Start(info).WaitForExit();

                if (File.Exists(Filename))
                {
                    File.Delete(Filename);
                }
                if (!Directory.GetParent(Filename).Exists)
                {
                    Directory.GetParent(Filename).Create();
                }
                File.Move(Path.ChangeExtension(tempName, "wav"), Filename);
                if (File.Exists(tempName))
                {
                    File.Delete(tempName);
                }
            }
            #endregion
            #region RAW
            else if (Format == SoundFormat.RAW)
            {
                byte[] buffer = Cache.GetSoundRaw(snd_.RawID, GetTotalSize(Cache.ugh_, Cache.ugh_.PlayBacks[snd_.PlaybackIndex]));

                if (!Directory.GetParent(Filename).Exists)
                {
                    Directory.GetParent(Filename).Create();
                }

                var          fs = new FileStream(Filename, FileMode.Create);
                BinaryWriter sw = new BinaryWriter(fs);

                sw.Write(buffer);
                sw.Close();
                sw.Dispose();
            }
            #endregion
            #region Other
            else
            {
                throw new InvalidOperationException("Invalid sound format received.");
            }
            #endregion
        }
Exemplo n.º 13
0
        /// <summary>
        /// Saves selected permutations of a sound tag.
        /// </summary>
        /// <param name="Folder">The folder to save all files in. Each file will be named as the permutation name.</param>
        /// <param name="Cache">The CacheFile containing the tag.</param>
        /// <param name="Tag">The sound tag.</param>
        /// <param name="Format">The format in which to save the data.</param>
        /// <param name="Indices">The indices of the permutations to extract.</param>
        public static void SaveSelected(string Folder, CacheBase Cache, CacheBase.IndexItem Tag, SoundFormat Format, List <int> Indices, bool Overwrite)
        {
            var           snd_  = DefinitionsManager.snd_(Cache, Tag);
            List <byte[]> perms = new List <byte[]>();

            var ugh_     = Cache.ugh_;
            var playback = ugh_.PlayBacks[snd_.PlaybackIndex];
            var data     = Cache.GetSoundRaw(snd_.RawID, GetTotalSize(ugh_, playback));

            if (playback.PermutationCount == 1)
            {
                perms.Add(data);
            }
            else
            {
                Folder = Directory.GetParent(Folder) + "\\" + Path.GetFileNameWithoutExtension(Folder);

                for (int i = 0; i < playback.PermutationCount; i++)
                {
                    var perm = Cache.ugh_.SoundPermutations[playback.FirstPermutation + i];
                    perms.Add(GetPermData(data, ugh_, perm));
                }
            }

            #region XMA
            if (Format == SoundFormat.XMA)
            {
                foreach (int index in Indices)
                {
                    string Filename = (playback.PermutationCount == 1) ? Folder : Folder + "\\" + ugh_.SoundNames[ugh_.SoundPermutations[playback.FirstPermutation + index].NameIndex].Name + ".xma";
                    if (!Filename.EndsWith(".xma"))
                    {
                        Filename += ".xma";
                    }

                    if (File.Exists(Filename) && !Overwrite)
                    {
                        continue;
                    }

                    byte[] buffer = perms[index];
                    var    codec  = Cache.ugh_.Codecs[snd_.CodecIndex];
                    var    xma    = GetXMA(buffer, snd_.SampleRate, codec.Type);

                    if (!Directory.GetParent(Filename).Exists)
                    {
                        Directory.GetParent(Filename).Create();
                    }

                    var          fs = new FileStream(Filename, FileMode.Create);
                    EndianWriter sw = new EndianWriter(fs, EndianFormat.BigEndian);
                    sw.Write(xma);

                    sw.Close();
                    sw.Dispose();
                }
            }
            #endregion
            #region WAV
            else if (Format == SoundFormat.WAV)
            {
                foreach (int index in Indices)
                {
                    string Filename = (playback.PermutationCount == 1) ? Folder : Folder + "\\" + ugh_.SoundNames[ugh_.SoundPermutations[playback.FirstPermutation + index].NameIndex].Name + ".wav";
                    if (!Filename.EndsWith(".wav"))
                    {
                        Filename += ".wav";
                    }

                    if (File.Exists(Filename) && !Overwrite)
                    {
                        continue;
                    }

                    var tempName = Path.GetTempFileName();

                    #region Write XMA
                    var buffer = perms[index];
                    var codec  = Cache.ugh_.Codecs[snd_.CodecIndex];
                    var xma    = GetXMA(buffer, snd_.SampleRate, codec.Type);

                    var          fs = File.OpenWrite(tempName);
                    EndianWriter sw = new EndianWriter(fs, EndianFormat.BigEndian);
                    sw.Write(xma);

                    sw.Close();
                    sw.Dispose();
                    #endregion

                    var info = new ProcessStartInfo(towav, tempName)
                    {
                        CreateNoWindow   = true,
                        UseShellExecute  = false,
                        WorkingDirectory = Directory.GetParent(tempName).FullName
                    };

                    Process.Start(info).WaitForExit();

                    if (File.Exists(Filename))
                    {
                        File.Delete(Filename);
                    }
                    if (!Directory.GetParent(Filename).Exists)
                    {
                        Directory.GetParent(Filename).Create();
                    }
                    File.Move(Path.ChangeExtension(tempName, "wav"), Filename);
                    if (File.Exists(tempName))
                    {
                        File.Delete(tempName);
                    }
                }
            }
            #endregion
            #region RAW
            else if (Format == SoundFormat.RAW)
            {
                foreach (int index in Indices)
                {
                    string Filename = (playback.PermutationCount == 1) ? Folder : Folder + "\\" + ugh_.SoundNames[ugh_.SoundPermutations[playback.FirstPermutation + index].NameIndex].Name + ".bin";
                    if (!Filename.EndsWith(".bin"))
                    {
                        Filename += ".bin";
                    }

                    if (File.Exists(Filename) && !Overwrite)
                    {
                        continue;
                    }

                    byte[] buffer = perms[index];

                    if (!Directory.GetParent(Filename).Exists)
                    {
                        Directory.GetParent(Filename).Create();
                    }

                    var          fs = new FileStream(Filename, FileMode.Create);
                    BinaryWriter sw = new BinaryWriter(fs);

                    sw.Write(buffer);
                    sw.Close();
                    sw.Dispose();
                }
            }
            #endregion
        }
Exemplo n.º 14
0
 public static void DeleteBytes(string filePath, int startOffset, int size)
 {
     var input = new FileStream(filePath, FileMode.Open);
     var er = new EndianReader(input);
     var buffer = er.ReadBytes(startOffset);
     var baseStream = er.BaseStream;
     baseStream.Position += size;
     var buffer2 = er.ReadBytes(((int)er.BaseStream.Length) - ((int)er.BaseStream.Position));
     er.Close();
     input.Close();
     input = new FileStream(filePath, FileMode.Create);
     var ew = new EndianWriter(input);
     ew.Write(buffer);
     ew.Write(buffer2);
     input.Close();
     ew.Close();
 }
Exemplo n.º 15
0
        // Patch Creation
        private void btnCreatePatch_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Check the user isn't completly retarded
                if (!CheckAllCreateMandatoryFields())
                {
                    return;
                }

                // Check the user isn't a skid
                if (!CheckAllCreateMetaFilesExists())
                {
                    return;
                }

                // Paths
                string cleanMapPath  = txtCreatePatchUnModifiedMap.Text;
                string moddedMapPath = txtCreatePatchModifiedMap.Text;
                string outputPath    = txtCreatePatchOutputPatch.Text;
                string previewImage  = txtCreatePatchPreviewImage.Text;

                // Details
                string author = txtCreatePatchContentAuthor.Text;
                string desc   = txtCreatePatchContentDescription.Text;
                string name   = txtCreatePatchContentName.Text;

                // Make dat patch
                var patch = new Patch
                {
                    Author      = author,
                    Description = desc,
                    Name        = name,
                    Screenshot  = String.IsNullOrEmpty(previewImage)
                                                ? null
                                                : File.ReadAllBytes(previewImage)
                };

                EndianReader originalReader = null;
                EndianReader newReader      = null;
                try
                {
                    originalReader = new EndianReader(File.OpenRead(cleanMapPath), Endian.BigEndian);
                    newReader      = new EndianReader(File.OpenRead(moddedMapPath), Endian.BigEndian);

                    ICacheFile originalFile = CacheFileLoader.LoadCacheFile(originalReader,
                                                                            App.AssemblyStorage.AssemblySettings.DefaultDatabase);
                    ICacheFile newFile = CacheFileLoader.LoadCacheFile(newReader, App.AssemblyStorage.AssemblySettings.DefaultDatabase);

                    if (cbCreatePatchHasCustomMeta.IsChecked != null && (bool)cbCreatePatchHasCustomMeta.IsChecked &&
                        cboxCreatePatchTargetGame.SelectedIndex < 4)
                    {
                        var      targetGame      = (TargetGame)cboxCreatePatchTargetGame.SelectedIndex;
                        byte[]   mapInfo         = File.ReadAllBytes(txtCreatePatchMapInfo.Text);
                        var      mapInfoFileInfo = new FileInfo(txtCreatePatchMapInfo.Text);
                        FileInfo blfFileInfo;

                        patch.CustomBlfContent = new BlfContent(mapInfoFileInfo.FullName, mapInfo, targetGame);

                        #region Blf Data

                        if (PatchCreationBlfOption0.Visibility == Visibility.Visible)
                        {
                            blfFileInfo = new FileInfo(txtCreatePatchblf0.Text);
                            patch.CustomBlfContent.BlfContainerEntries.Add(new BlfContainerEntry(blfFileInfo.Name,
                                                                                                 File.ReadAllBytes(blfFileInfo.FullName)));
                        }
                        if (PatchCreationBlfOption1.Visibility == Visibility.Visible)
                        {
                            blfFileInfo = new FileInfo(txtCreatePatchblf1.Text);
                            patch.CustomBlfContent.BlfContainerEntries.Add(new BlfContainerEntry(blfFileInfo.Name,
                                                                                                 File.ReadAllBytes(blfFileInfo.FullName)));
                        }
                        if (PatchCreationBlfOption2.Visibility == Visibility.Visible)
                        {
                            blfFileInfo = new FileInfo(txtCreatePatchblf2.Text);
                            patch.CustomBlfContent.BlfContainerEntries.Add(new BlfContainerEntry(blfFileInfo.Name,
                                                                                                 File.ReadAllBytes(blfFileInfo.FullName)));
                        }
                        if (PatchCreationBlfOption3.Visibility == Visibility.Visible)
                        {
                            blfFileInfo = new FileInfo(txtCreatePatchblf3.Text);
                            patch.CustomBlfContent.BlfContainerEntries.Add(new BlfContainerEntry(blfFileInfo.Name,
                                                                                                 File.ReadAllBytes(blfFileInfo.FullName)));
                        }

                        #endregion
                    }

                    PatchBuilder.BuildPatch(originalFile, originalReader, newFile, newReader, patch);
                }
                finally
                {
                    if (originalReader != null)
                    {
                        originalReader.Close();
                    }
                    if (newReader != null)
                    {
                        newReader.Close();
                    }
                }

                IWriter output = new EndianWriter(File.Open(outputPath, FileMode.Create, FileAccess.Write), Endian.BigEndian);
                AssemblyPatchWriter.WritePatch(patch, output);
                output.Close();

                MetroMessageBox.Show("Patch Created!",
                                     "Your patch has been created in the designated location. Happy sailing, modder!");
            }
            catch (Exception ex)
            {
                MetroException.Show(ex);
            }
        }
Exemplo n.º 16
0
 public static void InsertBytes(string filePath, int startOffset, int size)
 {
     var input = new FileStream(filePath, FileMode.Open);
     var er = new EndianReader(input)
     {
         BaseStream = { Position = startOffset }
     };
     var buffer = er.ReadBytes(((int)er.BaseStream.Length) - ((int)er.BaseStream.Position));
     er.Close();
     input.Close();
     input = new FileStream(filePath, FileMode.Open);
     var ew = new EndianWriter(input)
     {
         BaseStream = { Position = startOffset }
     };
     ew.Write(new byte[size]);
     ew.Write(buffer);
     input.Close();
     ew.Close();
 }
Exemplo n.º 17
0
        public override byte[] ToBuffer()
        {
            // Create a new memory stream to back our file with.
            MemoryStream ms     = new MemoryStream();
            EndianWriter writer = new EndianWriter(this.IsBigEndian == true ? Endianness.Big : Endianness.Little, ms);

            // Write the header fields.
            writer.Write(rTextureHeader.kMagic);
            writer.Write((byte)rTextureHeader.kVersion);
            writer.Write((byte)this.header.TextureType);
            writer.Write((byte)this.header.Flags);
            writer.Write(this.header.MipMapCount);
            writer.Write(this.header.Width);
            writer.Write(this.header.Height);
            writer.Write(this.header.Depth);
            writer.Write(FourCCFromTextureFormat(this.header.Format, this.XboxFormat));

            // Check if we need to write the background color.
            if (this.header.Flags.HasFlag(TextureFlags.HasD3DClearColor) == true)
            {
                // Write the background color.
                writer.Write(this.BackgroundColor[0]);
                writer.Write(this.BackgroundColor[1]);
                writer.Write(this.BackgroundColor[2]);
                writer.Write(this.BackgroundColor[3]);
            }

            // If this is a cubemap write the cubemap data.
            if (this.header.TextureType == TextureType.Type_CubeMap)
            {
                // Write the cubemap data.
                writer.Write(this.cubemapData);
            }

            // If this is a depth map we need to write a DDS header for it.
            if (this.header.TextureType == TextureType.Type_DepthMap)
            {
                // Write the DDS header for the depth map.
                writer.Write(this.depthMapHeader.dwMagic);
                writer.Write(this.depthMapHeader.dwSize);
                writer.Write((int)this.depthMapHeader.dwFlags);
                writer.Write(this.depthMapHeader.dwHeight);
                writer.Write(this.depthMapHeader.dwWidth);
                writer.Write(this.depthMapHeader.dwPitchOrLinearSize);
                writer.Write(this.depthMapHeader.dwDepth);
                writer.Write(this.depthMapHeader.dwMipMapCount);
                writer.WritePadding(11 * 4);
                writer.Write(this.depthMapHeader.ddspf.dwSize);
                writer.Write((int)this.depthMapHeader.ddspf.dwFlags);
                writer.Write(this.depthMapHeader.ddspf.dwFourCC);
                writer.Write(this.depthMapHeader.ddspf.dwRGBBitCount);
                writer.Write(this.depthMapHeader.ddspf.dwRBitMask);
                writer.Write(this.depthMapHeader.ddspf.dwGBitMask);
                writer.Write(this.depthMapHeader.ddspf.dwBBitMask);
                writer.Write(this.depthMapHeader.ddspf.dwABitMask);
                writer.Write((int)this.depthMapHeader.dwCaps);
                writer.Write((int)this.depthMapHeader.dwCaps2);
                writer.Write(this.depthMapHeader.dwCaps3);
                writer.Write(this.depthMapHeader.dwCaps4);
                writer.WritePadding(4);
            }

            // Read the pixel buffer from the data stream.
            byte[] pixelData = new byte[this.PixelDataStream.Length];
            this.PixelDataStream.Seek(0, SeekOrigin.Begin);
            this.PixelDataStream.Read(pixelData, 0, pixelData.Length);

            // TODO: For xbox textures we need to tile the pixel buffer.

            // Write the pixel data.
            writer.Write(pixelData);

            // Close the binary writer and return the memory stream as a byte array.
            writer.Close();
            return(ms.ToArray());
        }
Exemplo n.º 18
0
 /// <summary>
 /// Closes map streams
 /// </summary>
 public void Close()
 {
     InputStream.Close();
     OutputStream.Close();
 }
Exemplo n.º 19
0
        public void Save()
        {
            //// Double Check Path
            //if (!File.Exists(path))
            //{
            //    SaveFileDialog sfd = new SaveFileDialog();
            //    sfd.Filter = "Halo 2 Tags (*." + TagClass + "|*." + TagClass;
            //    if (sfd.ShowDialog() == DialogResult.OK)
            //    {
            //        path = sfd.FileName;
            //        Globals.Tags.Add(path);
            //    }
            //}

            // Get new values
            //int Field = 0;
            //for (int i = 0; i < this.Controls[0].Controls.Count; i++)
            //{
            //    if (this.Controls[0].Controls[i].GetType() == typeof(Value))
            //    {
            //        Field = ((Value)this.Controls[0].Controls[i]).Index;
            //        plugin[Field].SetValue(((Value)this.Controls[0].Controls[i]).Save());
            //    }
            //    else if (this.Controls[0].Controls[i].GetType() == typeof(Enum))
            //    {
            //        Field = ((Enum)this.Controls[0].Controls[i]).Index;
            //        plugin[Field].SetValue(((Enum)this.Controls[0].Controls[i]).Save());
            //    }
            //    else if (this.Controls[0].Controls[i].GetType() == typeof(Bitmask))
            //    {
            //        Field = ((Bitmask)this.Controls[0].Controls[i]).Index;
            //        plugin[Field].SetValue(((Bitmask)this.Controls[0].Controls[i]).Save());
            //    }
            //    else if (this.Controls[0].Controls[i].GetType() == typeof(HaloControls.String))
            //    {
            //        Field = ((HaloControls.String)this.Controls[0].Controls[i]).Index;
            //        plugin[Field].SetValue(((HaloControls.String)this.Controls[0].Controls[i]).Save());
            //    }
            //    else if (this.Controls[0].Controls[i].GetType() == typeof(TagReference))
            //    {
            //        Field = ((HaloControls.TagReference)this.Controls[0].Controls[i]).Index;
            //        plugin[Field].SetValue(((HaloControls.TagReference)this.Controls[0].Controls[i]).Save());
            //    }
            //    else if (this.Controls[0].Controls[i].GetType() == typeof(TagBlock))
            //    {
            //        Field = ((TagBlock)this.Controls[0].Controls[i]).Index;
            //        ((TagBlock)this.Controls[0].Controls[i]).Save();
            //    }
            //}

            // Delete the file
            File.Delete(Path);

            // Reopen stream
            EndianWriter bw = new EndianWriter(Endianness.Little, new FileStream(Path, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite));

            // Write to tag
            plugin.Write(bw);

            // Close
            bw.Close();

            // Done
            MessageBox.Show("Done!");
        }