public static void BinToJson(string filename) { // Create this early on UnitxtFile unitxt = new UnitxtFile(); string pathPR2 = Path.ChangeExtension(filename, "pr2"); string pathPR3 = Path.ChangeExtension(filename, "pr3"); byte[] dataPR2 = File.ReadAllBytes(pathPR2); byte[] dataPR3 = File.ReadAllBytes(pathPR3); dataPR2 = PSOCT.DecompressPRC(dataPR2, true); dataPR3 = PSOCT.DecompressPRC(dataPR3, true); ByteArray baPR2 = new ByteArray(dataPR2); ByteArray baPR3 = new ByteArray(dataPR3); int shortPointerTableOffset = baPR3.ReadI32(); baPR3.Endianess = Endianess.BigEndian; int shortPointerTableCount = baPR3.ReadI32(); baPR3.Position = shortPointerTableOffset; List <int> shortPointerTable = new List <int>(); int chain = 0; for (int i1 = 0; i1 < shortPointerTableCount; i1++) { chain = baPR3.ReadI16() * 4 + chain; shortPointerTable.Add(chain); } // Read starting pointers for the PR2 data // Last 2 pointers are the ones we need baPR2.Position = shortPointerTable[shortPointerTable.Count - 2]; baPR2.Endianess = Endianess.BigEndian; int unitxtTablesPointer = baPR2.ReadI32(); int unitxtStringGroupsPointer = baPR2.ReadI32(); // Judging by other REL files this is the count, but the data says 023C0000... // Could be an error in the data? We'll find out baPR2.Position = unitxtTablesPointer; baPR2.Endianess = Endianess.LittleEndian; unitxt.tableValue = baPR2.ReadI32(); baPR2.Endianess = Endianess.BigEndian; int unitxtTablePointer = baPR2.ReadI32(); for (int i1 = 0; i1 < 2; i1++) { baPR2.Position = baPR2.ReadI32(unitxtTablePointer + i1 * 4); unitxt.SomeTables.Add(new List <short>()); for (int i2 = 0; i2 < 0xE0; i2++) { short value = baPR2.ReadI16(); unitxt.SomeTables[i1].Add(value); } } for (int i1 = 0; i1 < stringGroupCount; i1++) { unitxt.StringGroups.Add(new UnitxtGroup() { name = string.Format("Group {0:D2}", i1) }); int groupPointer = shortPointerTable[shortPointerTable.Count - (stringGroupCount + 2) + i1]; int groupAddress = baPR2.ReadI32(groupPointer); int nextGroupPointer = shortPointerTable[shortPointerTable.Count - (stringGroupCount + 2) + (i1 + 1)]; int nextGroupAddress = baPR2.ReadI32(nextGroupPointer); if (i1 >= (stringGroupCount - 1)) { nextGroupPointer = shortPointerTable[shortPointerTable.Count - 1]; nextGroupAddress = baPR2.ReadI32(nextGroupPointer); } while (groupAddress < nextGroupAddress) { int stringPointer = baPR2.ReadI32(groupAddress); string text = baPR2.ReadStringA(-1, stringPointer); unitxt.StringGroups[i1].entries.Add(text); groupAddress += 4; } unitxt.StringGroups[i1].count = unitxt.StringGroups[i1].entries.Count; } string jsonText = Json.Serialize(unitxt, true); File.WriteAllText(Path.ChangeExtension(filename, ".json"), jsonText); }
public static void BinToJson(string filename) { // Create this early on UnitxtFile unitxt = new UnitxtFile(); string pathPR2 = Path.ChangeExtension(filename, "pr2"); string pathPR3 = Path.ChangeExtension(filename, "pr3"); byte[] dataPR2 = File.ReadAllBytes(pathPR2); byte[] dataPR3 = File.ReadAllBytes(pathPR3); dataPR2 = PSOCT.DecompressPRC(dataPR2, false); dataPR3 = PSOCT.DecompressPRC(dataPR3, false); ByteArray baPR2 = new ByteArray(dataPR2); ByteArray baPR3 = new ByteArray(dataPR3); int shortPointerTableOffset = baPR3.ReadI32(); int shortPointerTableCount = baPR3.ReadI32(); baPR3.Position = shortPointerTableOffset; List <int> shortPointerTable = new List <int>(); int chain = 0; for (int i1 = 0; i1 < shortPointerTableCount; i1++) { chain = baPR3.ReadI16() * 4 + chain; shortPointerTable.Add(chain); } int unitxtTablesPointer = shortPointerTable[shortPointerTable.Count - stringGroupCount + 12]; baPR2.Position = baPR2.ReadI32(unitxtTablesPointer); unitxt.tableValue = baPR2.ReadI32(); unitxt.SomeTables2.Add(new List <byte>()); int unitxtTablesPointer2 = baPR2.ReadI32(); for (int i1 = 0; i1 < 0x70; i1++) { byte value = baPR2.ReadU8(unitxtTablesPointer2 + i1); unitxt.SomeTables2[0].Add(value); } int unitxtTablePointer = baPR2.ReadI32(); for (int i1 = 0; i1 < 2; i1++) { int unitxtTableOffset = baPR2.ReadI32(unitxtTablePointer + i1 * 4); unitxt.SomeTables.Add(new List <short>()); for (int i2 = 0; i2 < 0x70; i2++) { short value = baPR2.ReadI16(unitxtTableOffset + i2 * 2); unitxt.SomeTables[i1].Add(value); } } unitxt.SomeTables2.Add(new List <byte>()); unitxtTablesPointer2 = baPR2.ReadI32(); for (int i1 = 0; i1 < 0x30; i1++) { byte value = baPR2.ReadU8(unitxtTablesPointer2 + i1); unitxt.SomeTables2[1].Add(value); } int stringGroupsCurrentIndex = 0; for (int i1 = 0; i1 < stringGroupCount - 1; i1++) { if (i1 == 12) { continue; } unitxt.StringGroups.Add(new UnitxtGroup() { name = string.Format("Group {0:D2}", stringGroupsCurrentIndex) }); int groupPointer = shortPointerTable[shortPointerTable.Count - stringGroupCount + i1]; int groupAddress = baPR2.ReadI32(groupPointer); int nextGroupPointer = shortPointerTable[shortPointerTable.Count - stringGroupCount + i1]; int nextGroupAddress = baPR2.ReadI32(nextGroupPointer); // This one goes into the table itself so gotta do some magic if (i1 == 9) { nextGroupPointer = shortPointerTable[shortPointerTable.Count - stringGroupCount + 12]; nextGroupAddress = baPR2.ReadI32(unitxtTablesPointer); nextGroupAddress += 8; nextGroupAddress = baPR2.ReadI32(nextGroupAddress); nextGroupAddress = baPR2.ReadI32(nextGroupAddress); } else if (i1 == 11) { nextGroupPointer = shortPointerTable[shortPointerTable.Count - stringGroupCount + i1 + 2]; nextGroupAddress = baPR2.ReadI32(nextGroupPointer); } else if (i1 == (stringGroupCount - 2)) { nextGroupPointer = shortPointerTable[shortPointerTable.Count - stringGroupCount]; nextGroupAddress = shortPointerTable[shortPointerTable.Count - stringGroupCount]; } else { nextGroupPointer = shortPointerTable[shortPointerTable.Count - stringGroupCount + i1 + 1]; nextGroupAddress = baPR2.ReadI32(nextGroupPointer); } while (groupAddress < nextGroupAddress) { int stringPointer = baPR2.ReadI32(groupAddress); string text = baPR2.ReadStringA(-1, stringPointer); unitxt.StringGroups[stringGroupsCurrentIndex].entries.Add(text); groupAddress += 4; } unitxt.StringGroups[stringGroupsCurrentIndex].count = unitxt.StringGroups[stringGroupsCurrentIndex].entries.Count; stringGroupsCurrentIndex++; } string jsonText = Json.Serialize(unitxt, true); File.WriteAllText(Path.ChangeExtension(filename, ".json"), jsonText); }