Надо поменять в 4 местах hex значение в большом файле 6 gb Использую этот код
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
public static class BinaryUtility
{
public static IEnumerable<byte> GetByteStream(BinaryReader reader)
{
const int bufferSize = 1024;
byte[] buffer;
do
{
buffer = reader.ReadBytes(bufferSize);
foreach (var d in buffer) { yield return d; }
} while (bufferSize == buffer.Length);
}
public static void Replace(BinaryReader reader, BinaryWriter writer, IEnumerable<Tuple<byte[], byte[]>> searchAndReplace)
{
foreach (byte d in Replace(GetByteStream(reader), searchAndReplace)) { writer.Write(d); }
}
public static IEnumerable<byte> Replace(IEnumerable<byte> source, IEnumerable<Tuple<byte[], byte[]>> searchAndReplace)
{
foreach (var s in searchAndReplace)
{
source = Replace(source, s.Item1, s.Item2);
}
return source;
}
public static IEnumerable<byte> Replace(IEnumerable<byte> input, IEnumerable<byte> from, IEnumerable<byte> to)
{
var fromEnumerator = from.GetEnumerator();
fromEnumerator.MoveNext();
int match = 0;
foreach (var data in input)
{
if (data == fromEnumerator.Current)
{
match++;
if (fromEnumerator.MoveNext()) { continue; }
foreach (byte d in to) { yield return d; }
match = 0;
fromEnumerator.Reset();
fromEnumerator.MoveNext();
continue;
}
if (0 != match)
{
foreach (byte d in from.Take(match)) { yield return d; }
match = 0;
fromEnumerator.Reset();
fromEnumerator.MoveNext();
}
yield return data;
}
if (0 != match)
{
foreach (byte d in from.Take(match)) { yield return d; }
}
}
}
private void FastReplace()
{
var byteFastHitPak = File.ReadAllBytes(Directory.GetCurrentDirectory() + @"\SC\Fast.pak");
var byteFastHitSig = File.ReadAllBytes(Directory.GetCurrentDirectory() + @"\SC\Fast.sig");
var searchAndReplace = new List<Tuple<byte[], byte[]>>()
{
Tuple.Create(byteFastHitPak, byteFastHitSig),
};
using (var reader = new BinaryReader(new FileStream(TexBoxPath.Text + pakchunk0, FileMode.Open)))
{
using (var writer = new BinaryWriter(new FileStream(TexBoxPath.Text + pakchunk0 + "1", FileMode.Create)))
{
BinaryUtility.Replace(reader, writer, searchAndReplace);
}
}
}
Но он мне не подходит, т.к. файл имеет большой размер + создаётся второй файл что мне тоже не надо. Нужен код который будет быстро искать hex в файле и заменять его. Замена pos не подходит, т.к. файл может меняться
Подскажите, как запустить анимацию пушки во время выстрела ядра из нее? Создание и выстрел ядра у меня происходит в методе Shoot()Не понимаю...