public void WritePatch(Patch patch) { Write(patch.FileID); Write(patch.BlockID); Write(patch.Extra); Write(patch.Length); Write(patch.Data); }
public Animation(DrawImageHandler draw, Patch patch) { _draw = draw; _patch = patch; _frames = GetAnimation(); _timer = new System.Timers.Timer(100); _timer.Elapsed += new ElapsedEventHandler(OnTick); }
public Patcher(Patch[] patches, string serverFolder) { if (string.IsNullOrEmpty(Program.Database.UltimaOnlineDirectory)) throw new Exception("ConnectUO was unable to find the directory that Ultima Online is installed to."); Utility.EnsureDirectory(serverFolder); this.patches = patches; this.serverFolder = serverFolder; //this.thread = new Thread(InternalPatchMuls); }
public static unsafe Bitmap GetGump(Patch p) { int length = p.Length; int extra = p.Extra; int width = ( extra >> 16 ) & 0xFFFF; int height = extra & 0xFFFF; Bitmap bmp = new Bitmap(width, height, PixelFormat.Format16bppArgb1555); BitmapData bd = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format16bppArgb1555); MemoryStream ms = new MemoryStream(p.Data); BinaryReader bin = new BinaryReader(ms); int[] lookups = new int[height]; int start = (int)bin.BaseStream.Position; for( int i = 0; i < height; ++i ) lookups[i] = start + ( bin.ReadInt32() * 4 ); ushort* line = (ushort*)bd.Scan0; int delta = bd.Stride >> 1; for( int y = 0; y < height; ++y, line += delta ) { bin.BaseStream.Seek(lookups[y], SeekOrigin.Begin); ushort* cur = line; ushort* end = line + bd.Width; while( cur < end ) { ushort color = bin.ReadUInt16(); ushort* next = cur + bin.ReadUInt16(); if( color == 0 ) { cur = next; } else { color ^= 0x8000; while( cur < next ) *cur++ = color; } } } bmp.UnlockBits(bd); bin.Close(); return bmp; }
public Patch ReadMUOPatch() { Patch p = new Patch(); p.FileID = ReadInt32(); p.BlockID = ReadInt32(); p.Extra = ReadInt32(); p.Length = ReadInt32(); if (p.Length >= 0) p.Data = ReadBytes(p.Length); else p.Data = new byte[0]; return p; }
public static Image GetFirstFrame( Patch patch ) { Animation anim = new Animation(null, patch); Frame[] frames = anim.GetAnimation(); Image image = null; if( frames.Length > 0 ) image = (Image)frames[0].Bitmap.Clone(); anim = null; frames = null; return image; }
public static void CreateUOP(string path, Patch[] patches, ProgressChangeHandler progressDelegate) { PatchWriter writer = new PatchWriter(File.Create(path), PatchFileType.UOP); writer.WriteUOPHeader(); writer.Write(patches.Length); writer.Write((int)0);//Unknown for( int i = 0; i < patches.Length; i++ ) { writer.WriteUOPPatch(patches[i]); if( i != 0 && progressDelegate != null ) progressDelegate(writer, new ProgressChangeEventArgs(((100 * i) / patches.Length), i, patches.Length)); } writer.Close(); }
public static void CreateMUO(string path, Patch[] patches, ProgressChangeHandler progressDelegate) { PatchWriter writer = new PatchWriter(File.Create(path), PatchFileType.MUO); writer.WriteMUOHeader(); writer.WriteMUOMetaData(new string[] { "MUO", "Created with PatchLib", "Jeff Boulanger" }); writer.Write((int)patches.Length); for( int i = 0; i < patches.Length; i++ ) { writer.WriteMUOPatch(patches[i]); if( i != 0 && progressDelegate != null ) progressDelegate(writer, new ProgressChangeEventArgs(((100 * i) / patches.Length), i, patches.Length)); } writer.Close(); }
public Patcher(Patch[] patches, string patchToFolder, bool patchMuls) { if (File.Exists(patchToFolder)) throw new Exception(patchToFolder + " is not a valid folder"); if ((_UOPath = Client.DetectClient(Client.TwoDClient)) == Client.NotFound && (_UOPath = Client.DetectClient(Client.ThreeDClient)) == Client.NotFound) throw new Exception("Ultima Online does not appear to be installed on this machine."); _UOPath = Path.GetDirectoryName(_UOPath); _patches = patches; _patchToFolder = patchToFolder; _patchMuls = patchMuls; if (_patchMuls) _thread = new Thread(InternalPatchMuls); else _thread = new Thread(InternalCombinePatches); }
protected override void OnDragDrop(DragEventArgs e) { if( e.Data.GetDataPresent(typeof(SelectedObjectCollection)) ) { object obj = e.Data.GetData(typeof(SelectedObjectCollection)); if( obj != null ) { SelectedObjectCollection col = (SelectedObjectCollection)obj; if( col.Count > 0 ) { object data = null; if( col[0] is Patch ) { Patch[] patches = new Patch[col.Count]; for( int i = 0; i < col.Count; i++ ) patches[i] = (Patch)col[i]; data = patches; } else if( col[0] is PatchGroup ) { PatchGroup[] groups = new PatchGroup[col.Count]; for( int i = 0; i < col.Count; i++ ) groups[i] = (PatchGroup)col[i]; data = groups; } if( HandleDroppedData != null ) HandleDroppedData(data, e); } } } else base.OnDragDrop(e); }
public void WritePatch(Patch patch) { switch( _patchFileType ) { case PatchFileType.MUO: { WriteMUOPatch(patch); break; } case PatchFileType.UOP: { WriteUOPPatch(patch); break; } } }
private void PatchFile(string idxPath, string mulPath, string newIdxPath, string newMulPath, List <Patch> patches) { if (StatusChange != null) { StatusChange(this, new StatusChangeEventArgs(String.Format("Creating temp mul/idx file(s)..."))); } File.Copy(idxPath, newIdxPath, true); File.Copy(mulPath, newMulPath, true); if (StatusChange != null) { StatusChange(this, new StatusChangeEventArgs(String.Format("Applying {0} patches to {1}...", patches.Count, Path.GetFileName(newMulPath)))); } FileInfo idxFileInfo = new FileInfo(newIdxPath); FileIndex index = new FileIndex(Path.GetFileName(idxPath), Path.GetFileName(mulPath), (int)(idxFileInfo.Length / 12)); BinaryWriter idx = new BinaryWriter(new FileStream(newIdxPath, FileMode.Open)); BinaryWriter mul = new BinaryWriter(new FileStream(newMulPath, FileMode.Open)); int oldPercent = 0; for (int p = 0; p < patches.Count; p++) { Patch patch = patches[p]; int a = 0; if (patch.BlockID == 0xEEEE) { a = 4; } /* * int pos; * * if (index[patch.BlockID].length > patch.Length) * pos = index[patch.BlockID].lookup; * else */int pos = Convert.ToInt32(mul.BaseStream.Length); idx.Seek(patch.BlockID * 12, SeekOrigin.Begin); idx.Write(pos); idx.Write(patch.Length); idx.Write(patch.Extra); if (patch.Length >= 0) { mul.Seek(pos, SeekOrigin.Begin); mul.Write(patch.Data, 0, patch.Length); } if (p != 0 && ProgressChange != null) { int percent = (p * 100) / patches.Count; if (percent != oldPercent) { ProgressChange.Invoke(this, new ProgressChangeEventArgs(percent, p, patches.Count)); oldPercent = percent; } } } index.Close(); if (idx != null) { idx.Close(); } if (mul != null) { mul.Close(); } if (StatusChange != null) { StatusChange(this, new StatusChangeEventArgs(String.Format("Moving temp mul/idx file(s)..."))); } if (File.Exists(newIdxPath.Substring(0, newIdxPath.Length - 4))) { File.Delete(newIdxPath.Substring(0, newIdxPath.Length - 4)); } File.Move(newIdxPath, newIdxPath.Substring(0, newIdxPath.Length - 4)); if (File.Exists(newMulPath.Substring(0, newMulPath.Length - 4))) { File.Delete(newMulPath.Substring(0, newMulPath.Length - 4)); } File.Move(newMulPath, newMulPath.Substring(0, newMulPath.Length - 4)); if (this.StatusChange != null) { this.StatusChange(this, new StatusChangeEventArgs(string.Format("Cleaning up...", new object[0]))); } File.Delete(newIdxPath); File.Delete(newMulPath); #region Meh for now /* * if (StatusChange != null) * StatusChange(this, new StatusChangeEventArgs(String.Format("Creating temp mul/idx file(s)..."))); * * FileInfo info = new FileInfo(idxPath); * FileIndex oldIndex = new FileIndex(Path.GetFileName(idxPath), Path.GetFileName(mulPath), (int)(info.Length / ((long)12))); * * BinaryWriter idx = new BinaryWriter(new FileStream(newIdxPath, FileMode.Create)); * idx.Seek((int)new FileInfo(idxPath).Length, SeekOrigin.Begin); * * BinaryWriter mul = new BinaryWriter(new FileStream(newMulPath, FileMode.Create)); * mul.Seek((int)new FileInfo(mulPath).Length, SeekOrigin.Begin); * * idx.Seek(0, SeekOrigin.Begin); * mul.Seek(0, SeekOrigin.Begin); * * if (StatusChange != null) * StatusChange(this, new StatusChangeEventArgs(String.Format("Applying {0} patches to {1}...", patches.Count, Path.GetFileName(newMulPath)))); * * int patchIndex = 0; * int oldPercent = 0; * * int offset = 0; * * for (int i = 0; i < oldIndex.IndexCount; i++) * { * if (patchIndex < patches.Count && patches[patchIndex].BlockID == i)//Write the patch * { * if (StatusChange != null) * StatusChange(this, new StatusChangeEventArgs(String.Format("Applying patch id: {0}...", i))); * * Patch patch = patches[patchIndex]; * * idx.Write((int)mul.BaseStream.Position); * idx.Write(patch.Length); * idx.Write(patch.Extra); * * if (patch.Length > 0) * mul.Write(patch.Data, 0, patch.Length); * * patchIndex++; * } * else//Write the regular data * { * if (StatusChange != null && (i % 200 == 0)) * StatusChange(this, new StatusChangeEventArgs(String.Format("Writing index: {0}...", i))); * * idx.Write((int)mul.BaseStream.Position); * idx.Write(oldIndex[i].length); * idx.Write(oldIndex[i].extra); * * if (oldIndex[i].length > 0) * { * BinaryReader reader = new BinaryReader(oldIndex.Seek(i)); * mul.Write(reader.ReadBytes(oldIndex[i].length), 0, oldIndex[i].length); * } * } * * if (i != 0 && ProgressChange != null) * { * int percent = (i * 100) / oldIndex.IndexCount; * * if (percent != oldPercent) * { * ProgressChange(this, new ProgressChangeEventArgs(percent, i, oldIndex.IndexCount)); * oldPercent = percent; * } * } * } * * //Patches out of idx range? Is this possible? * if (patchIndex < patches.Count - 1) * { * if (StatusChange != null) * StatusChange(this, new StatusChangeEventArgs(String.Format("Applying left over patches..."))); * * int count = (patches.Count - 1) - patchIndex; * int i = 0; * while (i < count) * { * if (StatusChange != null) * StatusChange(this, new StatusChangeEventArgs(String.Format("Applying patch id: {0}...", i))); * * Patch patch = patches[patchIndex]; * * idx.Write((int)mul.BaseStream.Position); * idx.Write(patch.Length); * idx.Write(patch.Extra); * * if (patch.Length >= 0) * mul.Write(patch.Data, 0, patch.Length); * * if (i != 0 && ProgressChange != null) * { * int percent = (i * 100) / count; * * if (percent != oldPercent) * { * ProgressChange(this, new ProgressChangeEventArgs(percent, i, count)); * oldPercent = percent; * } * } * * patchIndex++; * i++; * } * } * * oldIndex.Close(); * * if (idx != null) * idx.Close(); * if (mul != null) * mul.Close(); * * if (StatusChange != null) * StatusChange(this, new StatusChangeEventArgs(String.Format("Moving temp mul/idx file(s)..."))); * * if (File.Exists(newIdxPath.Substring(0, newIdxPath.Length - 4))) * File.Delete(newIdxPath.Substring(0, newIdxPath.Length - 4)); * * File.Move(newIdxPath, newIdxPath.Substring(0, newIdxPath.Length - 4)); * * if (File.Exists(newMulPath.Substring(0, newMulPath.Length - 4))) * File.Delete(newMulPath.Substring(0, newMulPath.Length - 4)); * * File.Move(newMulPath, newMulPath.Substring(0, newMulPath.Length - 4)); * * if (this.StatusChange != null) * this.StatusChange(this, new StatusChangeEventArgs(string.Format("Cleaning up...", new object[0]))); * * File.Delete(newIdxPath); * File.Delete(newMulPath);*/ #endregion }
public Patch ReadVerdataPatch() { Patch p = new Patch(); p.FileID = ReadInt32(); p.BlockID = ReadInt32(); int position = ReadInt32(); p.Length = ReadInt32(); p.Extra = ReadInt32(); int streamPos = (int)BaseStream.Position; BaseStream.Seek(position, SeekOrigin.Begin); p.Data = ReadBytes(p.Length); BaseStream.Seek(streamPos, SeekOrigin.Begin); return p; }
public Patch ReadUOPPatch() { Patch p = new Patch(); p.FileID = (int)ReadByte(); p.BlockID = ReadInt32(); p.Length = ReadInt32(); p.Extra = ReadInt32(); p.Data = ReadBytes(p.Length); return p; }
private int CompareTo(Patch one, Patch two) { return(one.BlockID.CompareTo(two.BlockID)); }
public static void CreateUOP(string path, Patch[] patches) { CreateUOP(path, patches, null ); }
public void WriteUOPPatch(Patch patch) { Write((byte)patch.FileID); Write((int)patch.BlockID); Write((int)patch.Length); Write((int)patch.Extra); Write(patch.Data); }
internal static Image GetImage(Patch patch) { switch( (FileID)patch.FileID ) { case FileID.GumpArt_mul: { return GetGump(patch); } case FileID.Art_mul: { try { return LoadLand(new MemoryStream(patch.Data)); } catch { return LoadStatic(new MemoryStream(patch.Data)); } } case FileID.Anim_mul: { return Animation.GetFirstFrame(patch); } default: { return null; } } }
private int CompareTo(Patch one, Patch two) { return one.BlockID.CompareTo(two.BlockID); }
private void CreatePatchFromIdxMul(BinaryReader reader, Entry3D entry) { reader.BaseStream.Seek(entry.lookup, SeekOrigin.Begin); Patch p = new Patch(); }
private bool ContainsPatch(Patch p) { bool found = false; for( int i = 0; i < _patches.Count; i++ ) { if( p.FileID.CompareTo(_patches[i].FileID) != 0 && p.Extra.CompareTo(_patches[i].Extra) != 0 && p.BlockID.CompareTo(_patches[i].BlockID) != 0 && p.Length.CompareTo(_patches[i].Length) != 0 ) { bool hadBreak = false; for( int a = 0; a < p.Data.Length; a++ ) if( p.Data[a] != _patches[i].Data[a] ) { hadBreak = true; break; } if( !hadBreak ) { found = true; break; } } } return found; }