private void CheckUser(object sender, EventArgs e) { CPK cpk = new CPK(this, (CheckUser)sender); cpk.Enabled_Button((CheckUser)sender); cpk.Network = true; cpk.ShowDialog(); }
/// <summary> /// <todo>计算 CPK</todo> /// </summary> /// <param name="cpm"></param> /// <param name="maxThreshold"></param> /// <param name="minThreshold"></param> /// <returns></returns> private static CPK getCPK(Cpm cpm, CpmChartThreshold maxThreshold, CpmChartThreshold minThreshold) { CPK cpk = new CPK() { Value = 1.8 }; return(cpk); }
public CPK MapToObject(TobascoTest.GeneratedEntity2.CPK objectToMapFrom) { var objectToMapTo = new CPK { Training = objectToMapFrom.Training, Duur = objectToMapFrom.Duur, Kosten = objectToMapFrom.Kosten, }; return(objectToMapTo); }
/// <summary> /// 把牌丟給玩家,看是否要吃 碰 槓 過水 胡 /// </summary> internal virtual void toUser(Brand brand, bool chow, bool pong, bool kong, bool darkkong, bool win) { CPK cpk = new CPK(this, brand); CheckBrands c = new CheckBrands(brand, NowPlayer_removeTeam); CheckBrands w = new CheckBrands(brand, all.NowPlayer); cpk.Enabled_Button(chow, pong, kong, darkkong, win); if (chow || pong || kong || win || darkkong) { cpk.ShowDialog(); } }
/// <summary> /// 把牌丟給玩家,看是否要吃 碰 槓 過水 胡 /// </summary> internal virtual void toUser(CheckUser check) { CPK cpk = new CPK(this, check); CheckBrands c = new CheckBrands(check.Brand, NowPlayer_removeTeam); CheckBrands w = new CheckBrands(check.Brand, all.NowPlayer); cpk.Enabled_Button(check.Chow, check.Pong, check.Kong, check.DarkKong, check.Win); if (check.Chow || check.Pong || check.Kong || check.Win || check.DarkKong) { cpk.ShowDialog(); } }
public CPKData(string filePath) { FilePath = filePath; CPK = new CPK(new Tools()); CPK.ReadCPK(filePath, Encoding); Tables = new List <CPKTable>(); BinaryReader binaryReader = new BinaryReader(File.OpenRead(filePath)); List <FileEntry> list = CPK.FileTable.OrderBy((FileEntry x) => x.FileOffset).ToList(); int i = 0; bool flag = Tools.CheckListRedundant(list); for (; i < list.Count; i++) { if (list[i].FileType != null) { Nums++; CPKTable cPKTable = new CPKTable(); if (list[i].ID == null) { cPKTable.id = -1; } else { cPKTable.id = Convert.ToInt32(list[i].ID); } if (cPKTable.id >= 0 && flag) { cPKTable.FileName = ((list[i].DirName != null) ? string.Concat(list[i].DirName, "/") : "") + $"[{cPKTable.id.ToString()}]" + list[i].FileName; } else { cPKTable.FileName = ((list[i].DirName != null) ? string.Concat(list[i].DirName, "/") : "") + list[i].FileName; } cPKTable.LocalName = list[i].FileName.ToString(); cPKTable.FileOffset = Convert.ToUInt64(list[i].FileOffset); cPKTable.FileSize = Convert.ToInt32(list[i].FileSize); cPKTable.ExtractSize = Convert.ToInt32(list[i].ExtractSize); cPKTable.FileType = list[i].FileType; if (list[i].FileType == "FILE") { cPKTable.Pt = (float)Math.Round((float)cPKTable.FileSize / (float)cPKTable.ExtractSize, 2) * 100f; } else { cPKTable.Pt = 100f; } Tables.Add(cPKTable); } } binaryReader.Close(); }
private static void OperationExtractCPK() { string filename = ConsolePath("Full path to CPK archive..?"); if (filename.IsEmpty()) { return; } Stream stream = new CachedReadStream(new FileStream(filename, FileMode.Open, FileAccess.Read)); CPK cpk = new CPK(stream); string path = Path.Combine(Path.GetDirectoryName(filename), Path.GetFileName(filename) + ".ext"); cpk.Root.Extract(path); stream.Close(); }
internal void getBrand(Brand brand) { if (myTurn) { CPK cpk = new CPK(this, checkuser); cpk.Network = true; //cpk.Checkuser = checkuser; CheckBrands c = new CheckBrands(brand, NowPlayer_removeTeam); CheckBrands w = new CheckBrands(brand, all.NowPlayer); cpk.Enabled_Button(checkuser.Chow, checkuser.Pong, checkuser.Kong, checkuser.DarkKong, checkuser.Win); //if (checkuser.Chow || checkuser.Pong || checkuser.Kong || checkuser.Win || checkuser.DarkKong) cpk.ShowDialog(); chat.SendObject(cpk.Checkuser); } else if (iAmServer) { chat.SendObject(all); makeBrand(brand); } }
public byte[] Extract(string cpkFile) { BinaryReader binaryReader = new BinaryReader(File.OpenRead(cpkFile)); binaryReader.BaseStream.Seek((long)FileOffset, SeekOrigin.Begin); string @string = Encoding.ASCII.GetString(binaryReader.ReadBytes(8)); binaryReader.BaseStream.Seek((long)FileOffset, SeekOrigin.Begin); byte[] array = binaryReader.ReadBytes(int.Parse(FileSize.ToString())); string b = "CRILAYLA"; if (@string == b) { int num = (ExtractSize != 0) ? ExtractSize : FileSize; if (num != 0) { array = new CPK(new Tools()).DecompressLegacyCRI(array, num); } } binaryReader.Close(); return(array); }
protected float GetCPKValue(int paramCodeID, int machineID) { var bllColData = new MesWeb.BLL.T_CollectedDataParameters(); var colData = bllColData.GetModelList("ParameterCodeID = " + (int)paramCodeID + " AND MachineID = " + machineID); if (colData.Count < 4) { return(1.6f); } List <float> dataList = new List <float>(); foreach (var item in colData) { dataList.Add(float.Parse(item.CollectedValue)); } var bllParamSetting = new MesWeb.BLL.T_ParametersCol(); var paramSetting = bllParamSetting.GetModelList("MachineID = " + machineID + "AND ParameterCodeID = " + (int)paramCodeID).FirstOrDefault(); CPK cpk = new CPK(float.Parse(paramSetting.ParametersColMaxiumValue), float.Parse(paramSetting.ParametersColMiniumValue), dataList, -1); return(cpk.getCPK()); }
// Taken from CriPakTools - see adknowledgements private void ReplaceCPKFiles(string sourceCPK, string targetCPK, Dictionary <string, string> batchFileList) { CPK cpk = new CPK(new Tools()); cpk.ReadCPK(sourceCPK, ActiveEncodings.currentEncoding); BinaryReader oldFile = new BinaryReader(File.OpenRead(sourceCPK)); bool bUseCompress = false; // this could cause problems later if access to compressed files is needed FileInfo fi = new FileInfo(sourceCPK); string outputName = targetCPK; BinaryWriter newCPK = new BinaryWriter(File.OpenWrite(outputName)); List <FileEntry> entries = cpk.FileTable.OrderBy(x => x.FileOffset).ToList(); Tools tool = new Tools(); for (int i = 0; i < entries.Count; i++) { if (entries[i].FileType != "CONTENT") { if (entries[i].FileType == "FILE") { // I'm too lazy to figure out how to update the ContextOffset position so this works :) if ((ulong)newCPK.BaseStream.Position < cpk.ContentOffset) { ulong padLength = cpk.ContentOffset - (ulong)newCPK.BaseStream.Position; for (ulong z = 0; z < padLength; z++) { newCPK.Write((byte)0); } } } string currentName = ((entries[i].DirName != null) ? entries[i].DirName + "/" : "") + entries[i].FileName; if (!currentName.Contains("/")) { currentName = "/" + currentName; } if (!batchFileList.Keys.Contains(currentName.ToString())) //如果不在表中,复制原始数据 { oldFile.BaseStream.Seek((long)entries[i].FileOffset, SeekOrigin.Begin); entries[i].FileOffset = (ulong)newCPK.BaseStream.Position; if (entries[i].FileName.ToString() == "ETOC_HDR") { cpk.EtocOffset = entries[i].FileOffset; Console.WriteLine("Fix ETOC_OFFSET to {0:x8}", cpk.EtocOffset); } cpk.UpdateFileEntry(entries[i]); byte[] chunk = oldFile.ReadBytes(Int32.Parse(entries[i].FileSize.ToString())); newCPK.Write(chunk); if ((newCPK.BaseStream.Position % 0x800) > 0 && i < entries.Count - 1) { long cur_pos = newCPK.BaseStream.Position; for (int j = 0; j < (0x800 - (cur_pos % 0x800)); j++) { newCPK.Write((byte)0); } } } else { string replace_with = batchFileList[currentName.ToString()]; //Got patch file name Console.WriteLine("Patching: {0}", currentName.ToString()); byte[] newbie = File.ReadAllBytes(replace_with); entries[i].FileOffset = (ulong)newCPK.BaseStream.Position; int o_ext_size = Int32.Parse((entries[i].ExtractSize).ToString()); int o_com_size = Int32.Parse((entries[i].FileSize).ToString()); if ((o_com_size < o_ext_size) && entries[i].FileType == "FILE" && bUseCompress == true) { // is compressed Console.Write("Compressing data:{0:x8}", newbie.Length); byte[] dest_comp = cpk.CompressCRILAYLA(newbie); entries[i].FileSize = Convert.ChangeType(dest_comp.Length, entries[i].FileSizeType); entries[i].ExtractSize = Convert.ChangeType(newbie.Length, entries[i].FileSizeType); cpk.UpdateFileEntry(entries[i]); newCPK.Write(dest_comp); Console.Write(">> {0:x8}\r\n", dest_comp.Length); } else { Console.Write("Storing data:{0:x8}\r\n", newbie.Length); entries[i].FileSize = Convert.ChangeType(newbie.Length, entries[i].FileSizeType); entries[i].ExtractSize = Convert.ChangeType(newbie.Length, entries[i].FileSizeType); cpk.UpdateFileEntry(entries[i]); newCPK.Write(newbie); } if ((newCPK.BaseStream.Position % 0x800) > 0 && i < entries.Count - 1) { long cur_pos = newCPK.BaseStream.Position; for (int j = 0; j < (0x800 - (cur_pos % 0x800)); j++) { newCPK.Write((byte)0); } } } } else { // Content is special.... just update the position cpk.UpdateFileEntry(entries[i]); } } cpk.WriteCPK(newCPK); cpk.WriteITOC(newCPK); cpk.WriteTOC(newCPK); cpk.WriteETOC(newCPK, cpk.EtocOffset); cpk.WriteGTOC(newCPK); newCPK.Close(); oldFile.Close(); }
private static void OperationPatchCPK(bool sub) { bool togf = false; uint cpkoffset = 0; string cpkname = ConsolePath("Full path to CPK archive..?"); string subcpkname = cpkname; if (cpkname.IsEmpty()) { return; } Stream stream = new CachedReadStream(new FileStream(cpkname, FileMode.Open, FileAccess.Read, FileShare.Read)); Stream substream = stream; CPK cpk = new CPK(stream); if (sub) { string subname = ConsolePath("Filename of CPK sub-archive..?"); if (subname.IsEmpty()) { return; } FileNode subfile = cpk.Root.Find(subname, SearchOption.AllDirectories) as FileNode; if (subfile == null) { Console.WriteLine("Could not find the specified file in the parent CPK archive."); return; } substream = subfile.Data; cpkoffset = (uint)(substream as Substream).Offset; subcpkname = cpkname + "-" + Path.GetFileNameWithoutExtension(subname); cpk = new CPK(substream); } togf = (cpk.Version == 7); UTF.ShortValue align = cpk.Header.Rows[0].FindValue("Align") as UTF.ShortValue; ushort alignment = align == null ? (ushort)0x20 : align.Value; ulong cpklen = Util.RoundUp((ulong)Math.Max(stream.Length, togf ? stream.Length : 0x70000000), alignment); string cpklenfile = cpkname + ".patch"; if (File.Exists(cpklenfile)) { cpklen = ulong.Parse(File.ReadAllText(cpklenfile)); } long tocoffset = (long)(cpk.Header.Rows[0].FindValue("TocOffset") as UTF.LongValue).Value; long rowoffset = tocoffset + 0x10; EndianReader reader = new EndianReader(substream, Endianness.BigEndian); reader.Position = rowoffset + 0x1A; uint rowsize = reader.ReadUInt16(); reader.Position = rowoffset + 0x08; rowoffset += reader.ReadUInt32() + 0x08; ulong baseoffset = cpkoffset + (togf ? (ulong)tocoffset : (cpk.Header.Rows[0].FindValue("ContentOffset") as UTF.LongValue).Value); string tocname = subcpkname + ".toc"; Stream toc = new FileStream(tocname, FileMode.OpenOrCreate); EndianReader writer = new EndianReader(toc, Endianness.BigEndian); long begin = Util.RoundDown(rowoffset, 4); long end = Util.RoundUp(rowoffset + rowsize * cpk.ToC.Rows.Count, 4); if (toc.Length == 0) { reader.Position = begin; Util.StreamCopy(toc, reader, end - begin); } while (true) { string filename = ConsolePath("Full path to file to patch in..?"); if (filename.IsEmpty()) { break; } string path = filename; if (path.EndsWith(".new")) { path = path.Substring(0, path.Length - 4); } bool dirstr = cpk.ToC.Columns.Find(r => r.Name == "DirName") != null; rowsearch: string shortname = Path.GetFileName(path); string dirname = Path.GetDirectoryName(path).Replace('\\', '/'); UTF.Row filerow = cpk.ToC.Rows.Find(r => (r.FindValue("FileName") as UTF.StringValue).Value == shortname && (!dirstr || dirname.EndsWith((r.FindValue("DirName") as UTF.StringValue).Value))); if (filerow == null) { path = ConsolePath("A matching filename was not found. Please enter the original filename now..."); if (path.IsEmpty()) { break; } goto rowsearch; } uint filelen = (uint)new FileInfo(filename).Length; ulong fileoffset = baseoffset + (filerow.FindValue("FileOffset") as UTF.LongValue).Value; if (filelen > (filerow.FindValue("FileSize") as UTF.IntValue).Value) { fileoffset = cpklen; } writer.Position = rowoffset - begin + rowsize * cpk.ToC.Rows.IndexOf(filerow); foreach (UTF.Value value in filerow.Values) { switch (value.Type.Name) { case "FileSize": writer.Write(filelen); break; case "ExtractSize": writer.Write(filelen); break; case "FileOffset": writer.Write((ulong)(fileoffset - baseoffset)); break; default: writer.Position += value.Type.Size; break; } } if (fileoffset == cpklen) { cpklen = Util.RoundUp(fileoffset + filelen, alignment); File.WriteAllText(cpklenfile, cpklen.ToString()); } Console.WriteLine("The following patches will need to be applied."); Console.WriteLine("<file resize=\"false\" offset=\"0x" + Util.ToString((uint)begin + cpkoffset) + "\" disc=\"" + Path.GetFileName(cpkname) + "\" external=\"" + Path.GetFileName(tocname) + "\" />"); Console.WriteLine("<file resize=\"false\" offset=\"0x" + Util.ToString((uint)fileoffset) + "\" disc=\"" + Path.GetFileName(cpkname) + "\" external=\"" + Path.GetFileName(filename) + "\" />"); } stream.Close(); toc.Close(); }
private CPKBuildObject FilterCPKFile(FileLocationMeta file, string sourceDirectoryPath, string targetDirectoryPath) { var cpkFile = new CPK(new Tools()); // this function gets a bit confusings since file, cpkFile and embeddedFile are all thrown around - i will need to fix that var filePath = Path.Combine(sourceDirectoryPath, file.subPath, file.fileName); if (!cpkFile.ReadCPK(filePath, ActiveEncodings.currentEncoding)) { string errorMessage = string.Format("Unknown error while attempting to open {0}.", filePath); MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); // this could be replaced with a custom form that allows the user to skip all errors or a simple "errors while opening X files" after the files are done being read. though, the later option would require a small restructuring of the code. Environment.Exit(1); } int realFileCount = 0; foreach (var embeddedFile in cpkFile.FileTable) { if (embeddedFile.FileType.ToString() == "FILE") { realFileCount += 1; } } if (realFileCount == 0) { string errorMessage = string.Format("CPK file {0} was empty.", filePath); // i am not sure this should be a fatal error - i will attempt to come back to it once i have a more complete picture of how the build system works and thus have a better idea of how to handle such an eventuality MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } CPKBuildObject cpkBuildInstructions = new CPKBuildObject(); string originalFileLocation = Path.Combine(ProjectFolder.extractedISODir, file.subPath, file.fileName); cpkBuildInstructions.SetOriginalFileLocation(originalFileLocation); string targetFileLocation = Path.Combine(ProjectFolder.repackedGameFilesDir, file.subPath, file.fileName); cpkBuildInstructions.SetTargetFileLocation(targetFileLocation); if (realFileCount > 1) // if there is more than one file in the CPK we move the files within it to their own directory { string newSubDir = Path.GetFileNameWithoutExtension(file.fileName); string newSubPath = Path.Combine(file.subPath, newSubDir); file.subPath = newSubPath; } foreach (var embeddedFile in cpkFile.FileTable) { var cpkMeta = new CPKEmbeddedFileMeta(); if (embeddedFile.FileType != "FILE") { continue; // skip headers etc. } if (FileParser.IsParseable(embeddedFile.FileName.ToString())) // use this to determine whether to unpack or not, not save location { file.switchPath = editableDirectory; } else { file.switchPath = rawDirectory; } string targetFileAbsolutePath = Path.Combine(targetDirectoryPath, ProjectFolder.unpackedGameFilesDir, file.subPath, embeddedFile.FileName.ToString()); DirectoryGuard.CheckDirectory(targetFileAbsolutePath); byte[] fileAsBytes = GrabCPKData(filePath, embeddedFile); if (DebugSettings.ATTEMPT_DECOMPRESSION) { if (fileAsBytes.Length >= 8) // 8 = length of "CRILAYLA" { byte[] crilaylaCheck = new byte[8]; Array.Copy(fileAsBytes, 0, crilaylaCheck, 0, 8); string crilaylaString = Encoding.ASCII.GetString(crilaylaCheck); if (crilaylaString == "CRILAYLA") { byte[] decompressedBytes = cpkFile.DecompressCRILAYLA(fileAsBytes, fileAsBytes.Length); fileAsBytes = decompressedBytes; } } } if (DebugSettings.ALLOW_FILE_WRITES) { FileStream fs = new FileStream(targetFileAbsolutePath, FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); bw.Write(fileAsBytes); bw.Close(); fs.Close(); } if (DebugSettings.COPY_UNPACKED_FILES) { string secondTargetPath = Path.Combine(targetDirectoryPath, ProjectFolder.reassembledGameFilesDir, file.subPath, embeddedFile.FileName.ToString()); DirectoryGuard.CheckDirectory(secondTargetPath); FileStream fs = new FileStream(secondTargetPath, FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); bw.Write(fileAsBytes); bw.Close(); fs.Close(); } string relativeFilePath = Path.Combine(file.subPath, embeddedFile.FileName.ToString()); uint fileID = (uint)embeddedFile.ID; cpkMeta.filePath = Path.Combine(ProjectFolder.reassembledGameFilesDir, relativeFilePath); cpkMeta.fileName = embeddedFile.FileName.ToString(); cpkMeta.checksumType = Checksum.MD5; cpkMeta.checksumValue = Checksums.GetMD5(fileAsBytes); cpkMeta.ID = fileID; cpkBuildInstructions.AddFile(fileID, cpkMeta); } cpkBuildInstructions.SerializeToDisk(Path.Combine(targetDirectoryPath, ProjectFolder.buildScriptsDir)); return(cpkBuildInstructions); }
public CPK Save(CPK cpk) { cpk = _genericRepository.Save(cpk); return(cpk); }
/// <summary> /// 更新曲线数据 /// 该函数被多线程调用,所以给每个 Code 对应的 Chart 都上了一把锁 /// </summary> private static void updateChartView(CpmDetailViewStore cpmDetail, Cpm cpm, CpmChartThreshold maxThreshold, CpmChartThreshold minThreshold, CPK cpk) { lock (cpmDetail.ChartCpmSourceDict[cpm.Code]) { if (cpm.ValueType == SmParamType.Signal) { AsureChartPointNums(cpmDetail, cpm); cpmDetail.ChartCpmSourceDict[cpm.Code].Add(cpm); cpmDetail.Avgcalculator[cpm.Code](cpm.GetFloatVal()); if (!cpmDetail.AvgLast[cpm.Code].HasValue) { cpmDetail.AvgLast[cpm.Code] = cpm.GetFloatVal(); } cpmDetail.AvgDict[cpm.Code].Add(new CpmAvg() { Value = cpmDetail.AvgLast[cpm.Code].Value, UpdateTime = cpm.PickTime }); //同步最值和实时曲线的时间 if (maxThreshold != null) { maxThreshold.UpdateTime = cpm.PickTime; cpmDetail.MaxThresholdDict[cpm.Code].Add(maxThreshold); } if (minThreshold != null) { minThreshold.UpdateTime = cpm.PickTime; cpmDetail.MinThresholdDict[cpm.Code].Add(minThreshold); } if (cpk != null) { cpk.UpdateTime = cpm.PickTime; cpmDetail.CPKDict[cpm.Code].Add(cpk); } } if (cpm.Code == cpmDetail.SelectedCpm.Code) { cpmDetail.SelectedPointNums = "点数:" + cpmDetail.SelectedCpmChartSource.Count; //保证实时曲线的动态绘制 cpmDetail.SelectedVisualMax = DateTime.Now; } } }
private void PatchCPK(object t) { string msg; string cpkDir = ((actionCPK)t).cpkDir; string patchDir = ((actionCPK)t).patchDir; bool bForceCompress = ((actionCPK)t).bForceCompress; Dictionary <string, string> batch_file_list = ((actionCPK)t).batch_file_list; CPK cpk = myPackage.cpk; BinaryReader oldFile = new BinaryReader(File.OpenRead(myPackage.cpk_name)); string outputName = cpkDir; BinaryWriter newCPK = new BinaryWriter(File.OpenWrite(outputName)); List <FileEntry> entries = cpk.FileTable.OrderBy(x => x.FileOffset).ToList(); Tools tool = new Tools(); int id; bool bFileRepeated = Tools.CheckListRedundant(entries); for (int i = 0; i < entries.Count; i++) { this.UI_SetProgess((float)i / (float)entries.Count * 100f); if (entries[i].FileType != "CONTENT") { if (entries[i].FileType == "FILE") { // I'm too lazy to figure out how to update the ContextOffset position so this works :) if ((ulong)newCPK.BaseStream.Position < cpk.ContentOffset) { ulong padLength = cpk.ContentOffset - (ulong)newCPK.BaseStream.Position; for (ulong z = 0; z < padLength; z++) { newCPK.Write((byte)0); } } } id = Convert.ToInt32(entries[i].ID); string currentName; if (id > 0 && bFileRepeated) { currentName = (((entries[i].DirName != null) ? entries[i].DirName + "/" : "") + string.Format("[{0}]", id.ToString()) + entries[i].FileName); } else { currentName = ((entries[i].DirName != null) ? entries[i].DirName + "/" : "") + entries[i].FileName; } if (!currentName.Contains("/")) { currentName = "/" + currentName; } Debug.Print("Got File:" + currentName.ToString()); if (!batch_file_list.Keys.Contains(currentName.ToString())) //如果不在表中,复制原始数据 { oldFile.BaseStream.Seek((long)entries[i].FileOffset, SeekOrigin.Begin); entries[i].FileOffset = (ulong)newCPK.BaseStream.Position; if (entries[i].FileName.ToString() == "ETOC_HDR") { cpk.EtocOffset = entries[i].FileOffset; Debug.Print("Fix ETOC_OFFSET to {0:x8}", cpk.EtocOffset); } cpk.UpdateFileEntry(entries[i]); byte[] chunk = oldFile.ReadBytes(Int32.Parse(entries[i].FileSize.ToString())); newCPK.Write(chunk); if ((newCPK.BaseStream.Position % 0x800) > 0 && i < entries.Count - 1) { long cur_pos = newCPK.BaseStream.Position; for (int j = 0; j < (0x800 - (cur_pos % 0x800)); j++) { newCPK.Write((byte)0); } } } else { string replace_with = batch_file_list[currentName.ToString()]; //Got patch file name msg = string.Format("Patching: {0}", currentName.ToString()); this.UI_SetTextBlock(msg); Debug.Print(msg); byte[] newbie = File.ReadAllBytes(replace_with); entries[i].FileOffset = (ulong)newCPK.BaseStream.Position; int o_ext_size = Int32.Parse((entries[i].ExtractSize).ToString()); int o_com_size = Int32.Parse((entries[i].FileSize).ToString()); if ((o_com_size < o_ext_size) && entries[i].FileType == "FILE" && bForceCompress == true) { // is compressed msg = string.Format("Compressing data:{0:x8}", newbie.Length); this.UI_SetTextBlock(msg); Console.Write(msg); byte[] dest_comp = cpk.CompressCRILAYLA(newbie); entries[i].FileSize = Convert.ChangeType(dest_comp.Length, entries[i].FileSizeType); entries[i].ExtractSize = Convert.ChangeType(newbie.Length, entries[i].FileSizeType); cpk.UpdateFileEntry(entries[i]); newCPK.Write(dest_comp); msg = string.Format(">> {0:x8}\r\n", dest_comp.Length); this.UI_SetTextBlock(msg); Console.Write(msg); } else { msg = string.Format("Storing data:{0:x8}\r\n", newbie.Length); this.UI_SetTextBlock(msg); Console.Write(msg); entries[i].FileSize = Convert.ChangeType(newbie.Length, entries[i].FileSizeType); entries[i].ExtractSize = Convert.ChangeType(newbie.Length, entries[i].FileSizeType); cpk.UpdateFileEntry(entries[i]); newCPK.Write(newbie); } if ((newCPK.BaseStream.Position % 0x800) > 0 && i < entries.Count - 1) { long cur_pos = newCPK.BaseStream.Position; for (int j = 0; j < (0x800 - (cur_pos % 0x800)); j++) { newCPK.Write((byte)0); } } } } else { // Content is special.... just update the position cpk.UpdateFileEntry(entries[i]); } } cpk.WriteCPK(newCPK); msg = string.Format("Writing TOC...."); this.UI_SetTextBlock(msg); Console.WriteLine(msg); cpk.WriteITOC(newCPK); cpk.WriteTOC(newCPK); cpk.WriteETOC(newCPK, cpk.EtocOffset); cpk.WriteGTOC(newCPK); newCPK.Close(); oldFile.Close(); msg = string.Format("Saving CPK to {0}....", outputName); this.UI_SetTextBlock(msg); Console.WriteLine(msg); MessageBox.Show("CPK Patched."); this.UI_SetProgess(0f); }