private void WriteImports(BinaryWriter writer, GpkPackage package) { if (writer.BaseStream.Position != package.Header.ImportOffset) { package.Header.ImportOffset = (int)writer.BaseStream.Position; writer.BaseStream.Seek(offsetImportPos, SeekOrigin.Begin); writer.Write(package.Header.ImportOffset); writer.BaseStream.Seek(package.Header.ImportOffset, SeekOrigin.Begin); logger.Debug("import offset mismatch, fixed!"); } foreach (GpkImport imp in package.ImportList.Values) { writer.Write(package.GetStringIndex(imp.ClassPackage)); writer.Write(package.GetStringIndex(imp.ClassName)); writer.Write(imp.PackageRef); writer.Write((int)package.GetStringIndex(imp.ObjectName)); writer.Write(imp.Unk); stat.progress++; } logger.Debug("Wrote imports pos " + writer.BaseStream.Position); }
public void WriteData(BinaryWriter writer, GpkPackage package) { if (package.x64) { writer.Write(package.GetStringIndex(enumType)); } if (size == 1) { writer.Write(byteValue); } else { writer.Write(package.GetStringIndex(nameValue)); } }
private void WriteExports(BinaryWriter writer, GpkPackage package) { if (writer.BaseStream.Position != package.Header.ExportOffset) { package.Header.ExportOffset = (int)writer.BaseStream.Position; writer.BaseStream.Seek(offsetExportPos, SeekOrigin.Begin); writer.Write(package.Header.ExportOffset); writer.BaseStream.Seek(package.Header.ExportOffset, SeekOrigin.Begin); logger.Debug("export offset mismatch, fixed!"); } foreach (GpkExport export in package.ExportList.Values) { writer.Write((int)package.GetObjectIndex(export.ClassName)); writer.Write((int)package.GetObjectIndex(export.SuperName)); writer.Write((int)package.GetObjectIndex(export.PackageName)); writer.Write(Convert.ToInt32(package.GetStringIndex(export.ObjectName))); writer.Write(export.Unk1); writer.Write(export.Unk2); writer.Write(export.SerialSize); //save for future use, when we write our data parts we muss seek back and modify this export.SerialOffsetPosition = writer.BaseStream.Position; if (export.SerialSize > 0) { writer.Write(export.SerialOffset); } writer.Write(export.Unk3); writer.Write(export.UnkHeaderCount); writer.Write(export.Unk4); writer.Write(export.Guid); writer.Write(export.UnkExtraInts); stat.progress++; } logger.Debug("Wrote exports pos " + writer.BaseStream.Position); }
private void WriteExportsData(BinaryWriter writer, GpkPackage package) { //puffer, seems random in many files, we use 10 empty bytes writer.Write(new byte[package.datapuffer]); foreach (GpkExport export in package.ExportList.Values) { if (export.SerialSize == 0) { logger.Trace("skipping export data for " + export.ObjectName); } else { logger.Trace("export data for " + export.ObjectName); } long data_start = writer.BaseStream.Position; if (export.SerialOffset != data_start) { //if we have diffrent layout of the data then teh orginal file we need to fix the data pointers logger.Trace(string.Format("fixing export {0} offset old:{1} new:{2}", export.ObjectName, export.SerialOffset, data_start)); export.SerialOffset = (int)data_start; writer.BaseStream.Seek(export.SerialOffsetPosition, SeekOrigin.Begin); writer.Write(export.SerialOffset); writer.BaseStream.Seek(data_start, SeekOrigin.Begin); } if (export.NetIndexName != null) { writer.Write((int)package.GetObjectIndex(export.NetIndexName)); } else { writer.Write(export.NetIndex); } if (export.PropertyPadding != null) { writer.Write(export.PropertyPadding); } foreach (IProperty iProp in export.Properties) { GpkBaseProperty baseProperty = (GpkBaseProperty)iProp; writer.Write(package.GetStringIndex(baseProperty.name)); writer.Write(package.GetStringIndex(baseProperty.type)); writer.Write(baseProperty.size); writer.Write(baseProperty.arrayIndex); iProp.WriteData(writer, package); } //end with a none nameindex writer.Write(package.GetStringIndex("None")); //check long propRealSize = (writer.BaseStream.Position - data_start); if (Settings.Default.Debug && propRealSize != export.PropertySize) { logger.Trace("Compu Prop Size: {0}, Diff {1} -", export.PropertySize, propRealSize - export.PropertySize); } if (export.DataPadding != null) { writer.Write((export.DataPadding)); } //finally our data if (export.Payload != null) { //pos is important. we cant be sure that the data is acurate. export.Payload.WriteData(writer, package, export); } else if (export.Data != null) { writer.Write(export.Data); } long data_end = writer.BaseStream.Position; int data_size = (int)(data_end - data_start); if (data_size != export.SerialSize) { //maybe replaced data OR some property errors. write new data size. logger.Trace(string.Format("fixing export {0} size old:{1} new:{2}", export.ObjectName, export.SerialSize, data_size)); export.SerialSize = data_size; writer.BaseStream.Seek(export.SerialOffsetPosition - 4, SeekOrigin.Begin); writer.Write(export.SerialSize); writer.BaseStream.Seek(data_end, SeekOrigin.Begin); } logger.Trace("wrote export data for " + export.ObjectName + " end pos " + writer.BaseStream.Position); stat.progress++; } logger.Debug("Wrote export data pos " + writer.BaseStream.Position); }
public void WriteData(BinaryWriter writer, GpkPackage package) { writer.Write(package.GetStringIndex(innerType)); writer.Write(value); }
public void CheckAndAddNames(GpkPackage package) { package.GetStringIndex(value); }
public void WriteData(BinaryWriter writer, GpkPackage package) { writer.Write((int)package.GetStringIndex(value)); writer.Write(padding); }
public void CheckAndAddNames(GpkPackage package) { package.GetStringIndex(innerType); }
public void CheckAndAddNames(GpkPackage package) { package.GetStringIndex(enumType); package.GetStringIndex(nameValue); }