public UopPatchError Replace(string sWhat, UOPPairData upData, bool bUncompressed) { if (upData == null) { return(UopPatchError.IndexBlockError); } if ((sWhat == null) || (!File.Exists(sWhat))) { return(UopPatchError.FileError); } byte[] fileContent = null; using (FileStream fsToParse = new FileStream(sWhat, FileMode.Open)) { using (BinaryReader brToParse = new BinaryReader(fsToParse)) { long fSize = fsToParse.Seek(0, SeekOrigin.End); fileContent = new byte[fSize]; fsToParse.Seek(0, SeekOrigin.Begin); fileContent = brToParse.ReadBytes((int)fSize); } } byte[] compressedStream = null; int iDestLength = -1; if (bUncompressed) { compressedStream = fileContent; iDestLength = fileContent.Length; } else { compressedStream = new byte[(int)Compressor.CompressBound((ulong)(fileContent.Length))]; iDestLength = compressedStream.Length; if (ZLibError.Okay != Compressor.Compress(compressedStream, ref iDestLength, fileContent, fileContent.Length)) { GC.Collect(); return(UopPatchError.CompressionError); } } if ((compressedStream == null) || (iDestLength == -1) || (bUncompressed && (compressedStream.Length != iDestLength))) { GC.Collect(); return(UopPatchError.BufferError); } bool bResultReplace = upData.ReplaceData(compressedStream, (uint)(iDestLength), (uint)(fileContent.Length)); GC.Collect(); return(bResultReplace ? UopPatchError.Okay : UopPatchError.ReplaceError); }
public Form1() { InitializeComponent(); DoingSomeJob.TheForm = this; this.FormClosing += delegate(object sender, FormClosingEventArgs e) { if (DoingSomeJob.Working) { DialogResult drData = MessageBox.Show("Are you sure to close? Still working in background!", "UO:KR Uop Dumper", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (drData == DialogResult.No) { e.Cancel = true; } } }; this.toolBtnDontFix.Click += delegate(object sender, EventArgs e) { this.toolBtnDontFix.Checked = !this.toolBtnDontFix.Checked; //this.toolBtnDontFix.BackColor = (this.toolBtnDontFix.Checked) ? System.Drawing.Color.Gainsboro : System.Drawing.SystemColors.Control; }; this.btn_pnlUopFile_RecountFiles.LinkClicked += delegate(object sender, LinkLabelLinkClickedEventArgs e) { UOPFile upCurrent = (UOPFile)this.gbSelectedData.Tag; this.num_pnlUopFile_Files.Value = upCurrent.FilesDynamicCount; this.btn_pnlUopFile_RecountFiles.LinkVisited = false; }; this.btn_pnUopDatafile_RecountFiles.LinkClicked += delegate(object sender, LinkLabelLinkClickedEventArgs e) { UOPIndexBlockHeader upCurrent = (UOPIndexBlockHeader)this.gbSelectedData.Tag; this.nud_pnUopDatafile_Files.Value = upCurrent.FilesDynamicCount; this.btn_pnUopDatafile_RecountFiles.LinkVisited = false; }; this.btn_pnUopHeaderAndData_PatchData.LinkClicked += delegate(object sender, LinkLabelLinkClickedEventArgs e) { UOPPairData upDataPair = (UOPPairData)this.gbSelectedData.Tag; this.txt_pnUopHeaderAndData_Data.Tag = AddData(upDataPair, false); this.btn_pnUopHeaderAndData_PatchData.LinkVisited = false; }; this.btn_pnUopHeaderAndData_PatchDataUnc.LinkClicked += delegate(object sender, LinkLabelLinkClickedEventArgs e) { UOPPairData upDataPair = (UOPPairData)this.gbSelectedData.Tag; this.txt_pnUopHeaderAndData_Data.Tag = AddData(upDataPair, true); this.btn_pnUopHeaderAndData_PatchData.LinkVisited = false; }; this.btn_pnUopHeaderAndData_PatchData.Tag = null; this.btn_pnUopHeaderAndData_PatchDataUnc.Tag = null; this.num_pnlUopFile_Files.Minimum = 0; this.num_pnlUopFile_Files.Maximum = Int32.MaxValue; }
public void Delete(UOPPairData toDelete) { foreach (UOPIndexBlockHeader ibhCurrent in UopFile.m_Content) { for (int i = 0; i < ibhCurrent.m_ListData.Count; i++) { if (toDelete.Equals(ibhCurrent.m_ListData[i])) { ibhCurrent.m_ListData.RemoveAt(i); } } } }
private System.Collections.Hashtable AddData(UOPPairData pData, bool unCompressed) { this.txt_pnUopHeaderAndData_Data.Tag = null; if (this.oPatchDlgUopopen.ShowDialog(this) == DialogResult.OK) { System.Collections.Hashtable htTosend = new System.Collections.Hashtable(); htTosend.Add("file", this.oPatchDlgUopopen.FileName); htTosend.Add("uncompressed", unCompressed); return(htTosend); } return(null); }
private void SetPanel(ShowPanels panelType, object dataObject) { this.gbSelectedData.SuspendLayout(); this.SetModifyButtons(true); this.btnDetailsUnpack.Enabled = true; // ----------------- this.pnUopfile.Visible = this.pnUopfile.Enabled = false; this.pnUopDatafile.Visible = this.pnUopDatafile.Enabled = false; this.pnUopHeaderAndData.Visible = this.pnUopHeaderAndData.Enabled = false; // ----------------- this.gbSelectedData.Tag = dataObject; switch (panelType) { case ShowPanels.RootNode: { UOPFile uppeCurrent = (UOPFile)this.gbSelectedData.Tag; this.txt_pnlUopFile_Header1.Text = Utility.ByteArrayToString(uppeCurrent.m_Header.m_variousData, Utility.HashStringStyle.HexWithSeparator); this.num_pnlUopFile_Files.Value = uppeCurrent.m_Header.m_totalIndex; this.txt_pnlUopFile_Header2.Text = Utility.ByteArrayToString(uppeCurrent.m_Header.m_Unknown, Utility.HashStringStyle.HexWithSeparator); this.pnUopfile.Visible = true; } break; case ShowPanels.DataNode: { UOPIndexBlockHeader upCurrent = (UOPIndexBlockHeader)this.gbSelectedData.Tag; this.txt_pnUopDatafile_Offset.Text = String.Format("{0:X}", upCurrent.m_OffsetNextIndex); this.nud_pnUopDatafile_Files.Value = upCurrent.FilesDynamicCount; this.pnUopDatafile.Visible = true; } break; case ShowPanels.SingleHeader: { UOPPairData upCurrent = (UOPPairData)this.gbSelectedData.Tag; // Header block this.txt_pnUopHeaderAndData_Offset.Text = String.Format("{0:X}", upCurrent.First.m_OffsetOfDataBlock); this.txt_pnUopHeaderAndData_SizeHeader.Text = upCurrent.First.m_SizeofDataHeaders.ToString(); this.txt_pnUopHeaderAndData_Unk1.Text = String.Format("{0:X}", upCurrent.First.m_Unknown1); this.txt_pnUopHeaderAndData_Unk2.Text = String.Format("{0:X}", upCurrent.First.m_Unknown2); this.txt_pnUopHeaderAndData_Unk3.Text = String.Format("{0:X}", upCurrent.First.m_Unknown3); this.chk_pnUopHeaderAndData_Compressed.Checked = upCurrent.First.IsCompressed; // Data block byte[] bData = new byte[10]; Array.Copy(upCurrent.Second.m_CompressedData, bData, Math.Min(10, upCurrent.Second.m_CompressedData.Length)); this.txt_pnUopHeaderAndData_Data.Text = Utility.ByteArrayToString(bData, Utility.HashStringStyle.HexWithSeparator) + " ..."; this.txt_pnUopHeaderAndData_DataFlags.Text = String.Format("{0:X}", upCurrent.Second.m_DataFlag); this.txt_pnUopHeaderAndData_DataLocalOffset.Text = String.Format("{0:X}", upCurrent.Second.m_LocalOffsetToData); this.txt_pnUopHeaderAndData_DataUnk1.Text = String.Format("{0:X}", upCurrent.Second.m_Unknown); this.lbl_pnUopHeaderAndData_SizeC.Text = String.Format("Compressed: {0}", Utility.StringFileSize(upCurrent.First.m_LenghtCompressed)); this.lbl_pnUopHeaderAndData_SizeU.Text = String.Format("Uncompressed: {0}", Utility.StringFileSize(upCurrent.First.m_LenghtUncompressed)); this.pnUopHeaderAndData.Visible = true; } break; case ShowPanels.Nothing: { } break; } this.gbSelectedData.ResumeLayout(true); }
private void btnDetailsApply_Click(object sender, EventArgs e) { if (DoingSomeJob.Working) { MessageBox.Show("Please wait... Still working in background!", "UO:KR Uop Dumper", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } DoingSomeJob.Working = true; if (this.pnUopfile.Enabled) { try { UOPFile uppeCurrent = (UOPFile)this.gbSelectedData.Tag; byte[] bHeader1 = Utility.StringToByteArray(this.txt_pnlUopFile_Header1.Text, Utility.HashStringStyle.HexWithSeparator, 24); byte[] bHeader2 = Utility.StringToByteArray(this.txt_pnlUopFile_Header2.Text, Utility.HashStringStyle.HexWithSeparator, 12); uint uCount = Decimal.ToUInt32(this.num_pnlUopFile_Files.Value); if ((bHeader1 == null) || (bHeader1 == null)) { throw new Exception(); } else { uppeCurrent.m_Header.m_variousData = bHeader1; uppeCurrent.m_Header.m_totalIndex = uCount; uppeCurrent.m_Header.m_Unknown = bHeader2; } } catch { MessageBox.Show("Error while parsing the data!", "UO:KR Uop Dumper - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } SetPanel(ShowPanels.RootNode, this.gbSelectedData.Tag); } else if (this.pnUopDatafile.Enabled) { try { UOPIndexBlockHeader uppeCurrent = (UOPIndexBlockHeader)this.gbSelectedData.Tag; ulong ulOffset = UInt64.Parse(this.txt_pnUopDatafile_Offset.Text, System.Globalization.NumberStyles.AllowHexSpecifier); uint uCount = Decimal.ToUInt32(this.nud_pnUopDatafile_Files.Value); uppeCurrent.m_Files = uCount; uppeCurrent.m_OffsetNextIndex = ulOffset; } catch { MessageBox.Show("Error while parsing the data!", "UO:KR Uop Dumper - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } SetPanel(ShowPanels.DataNode, this.gbSelectedData.Tag); } else if (this.pnUopHeaderAndData.Enabled) { try { UOPPairData uppeCurrent = (UOPPairData)this.gbSelectedData.Tag; // Header block ulong ulOffset = UInt64.Parse(this.txt_pnUopHeaderAndData_Offset.Text, System.Globalization.NumberStyles.AllowHexSpecifier); uint uiUnk1 = UInt32.Parse(this.txt_pnUopHeaderAndData_Unk1.Text, System.Globalization.NumberStyles.AllowHexSpecifier); uint uiUnk2 = UInt32.Parse(this.txt_pnUopHeaderAndData_Unk2.Text, System.Globalization.NumberStyles.AllowHexSpecifier); uint uiUnk3 = UInt32.Parse(this.txt_pnUopHeaderAndData_Unk3.Text, System.Globalization.NumberStyles.AllowHexSpecifier); string sNewFile = null; bool bUncompressed = false; if (this.txt_pnUopHeaderAndData_Data.Tag != null) { sNewFile = (string)(((System.Collections.Hashtable) this.txt_pnUopHeaderAndData_Data.Tag)["file"]); bUncompressed = (bool)(((System.Collections.Hashtable) this.txt_pnUopHeaderAndData_Data.Tag)["uncompressed"]); } ulong ulUnkData = UInt64.Parse(this.txt_pnUopHeaderAndData_DataUnk1.Text, System.Globalization.NumberStyles.AllowHexSpecifier); if (sNewFile != null) { if (UopManager.getIstance().Replace(sNewFile, uppeCurrent, bUncompressed) != UopManager.UopPatchError.Okay) { throw new Exception(); } } uppeCurrent.First.m_OffsetOfDataBlock = ulOffset; uppeCurrent.First.m_Unknown1 = uiUnk1; uppeCurrent.First.m_Unknown2 = uiUnk2; uppeCurrent.First.m_Unknown3 = uiUnk2; } catch { MessageBox.Show("Error while parsing the data!", "UO:KR Uop Dumper - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } SetPanel(ShowPanels.SingleHeader, this.gbSelectedData.Tag); } else { SetPanel(ShowPanels.Nothing, null); } DoingSomeJob.Working = false; }
private void CommonDump(ShowPanels spType, object oCast) { if (DoingSomeJob.Working) { MessageBox.Show("Please wait... Still working in background!", "UO:KR Uop Dumper", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { ThreadArgs.MyThreadDelegate mtdParse = delegate(object args) { ThreadArgs theArgs = (ThreadArgs)args; StupidInterface theForm = (StupidInterface)theArgs.Args[0]; string thePath = (string)theArgs.Args[1]; ShowPanels theType = (ShowPanels)theArgs.Args[2]; object theObject = theArgs.Args[3]; UopManager upIstance = UopManager.getIstance(); string baseName = Path.GetFileNameWithoutExtension(upIstance.UopPath); string resultName = ""; try { if (!Directory.Exists(thePath)) { Directory.CreateDirectory(thePath); } int i = 0, j = 0; switch (spType) { case ShowPanels.RootNode: { UOPFile toDump = (UOPFile)theObject; foreach (UOPIndexBlockHeader dumpTemp1 in toDump.m_Content) { foreach (UOPPairData dumpTemp2 in dumpTemp1.m_ListData) { using (FileStream fsWrite = File.Create(thePath + @"\" + String.Format(StaticData.UNPACK_NAMEPATTERN, baseName, i, j, dumpTemp2.First.IsCompressed ? StaticData.UNPACK_EXT_COMP : StaticData.UNPACK_EXT_UCOMP))) { using (BinaryWriter bwWrite = new BinaryWriter(fsWrite)) { bwWrite.Write(dumpTemp2.Second.Extract(dumpTemp2.First.IsCompressed, dumpTemp2.First.m_LenghtUncompressed)); } } j++; } i++; j = 0; } resultName = "the UOP file."; } break; case ShowPanels.DataNode: { UOPIndexBlockHeader toDump = (UOPIndexBlockHeader)theObject; foreach (UOPIndexBlockHeader dumpTemp1 in upIstance.UopFile.m_Content) { if (dumpTemp1.Equals(toDump)) { break; } i++; } foreach (UOPPairData dumpTemp2 in toDump.m_ListData) { using (FileStream fsWrite = File.Create(thePath + @"\" + String.Format(StaticData.UNPACK_NAMEPATTERN, baseName, i, j, dumpTemp2.First.IsCompressed ? StaticData.UNPACK_EXT_COMP : StaticData.UNPACK_EXT_UCOMP))) { using (BinaryWriter bwWrite = new BinaryWriter(fsWrite)) { bwWrite.Write(dumpTemp2.Second.Extract(dumpTemp2.First.IsCompressed, dumpTemp2.First.m_LenghtUncompressed)); } } j++; } resultName = "the Header Block " + i.ToString() + "."; } break; case ShowPanels.SingleHeader: { UOPPairData toDump = (UOPPairData)theObject; bool bBreakLoop = false; foreach (UOPIndexBlockHeader dumpTemp1 in upIstance.UopFile.m_Content) { foreach (UOPPairData dumpTemp2 in dumpTemp1.m_ListData) { bBreakLoop = dumpTemp2.Equals(toDump); if (bBreakLoop) { break; } j++; } if (bBreakLoop) { break; } i++; j = 0; } using (FileStream fsWrite = File.Create(thePath + @"\" + String.Format(StaticData.UNPACK_NAMEPATTERN, baseName, i, j, toDump.First.IsCompressed ? StaticData.UNPACK_EXT_COMP : StaticData.UNPACK_EXT_UCOMP))) { using (BinaryWriter bwWrite = new BinaryWriter(fsWrite)) { bwWrite.Write(toDump.Second.Extract(toDump.First.IsCompressed, toDump.First.m_LenghtUncompressed)); } } resultName = "the Index " + j.ToString() + "."; } break; } GC.Collect(); theForm.SetTextArea("Completed unpacking for " + resultName); } catch { theForm.SetTextArea("ERROR while unpacking selected data."); } finally { theForm.DisableOtherIcon(false); theForm.SetLoadIcon(true); DoingSomeJob.Working = false; } }; DoingSomeJob.Working = true; SetTextArea("Unpacking seleceted data to \"" + Application.StartupPath + StaticData.UNPACK_DIR + "\" ..."); this.SetDisableIcon(true); this.SetLoadIcon(false); System.Threading.Thread tRun = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(mtdParse)); tRun.Start(new ThreadArgs(new object[] { this, Application.StartupPath + StaticData.UNPACK_DIR, spType, oCast })); } }