diff --git a/DataTypes.cs b/DataTypes.cs new file mode 100644 index 0000000..be9ec7d --- /dev/null +++ b/DataTypes.cs @@ -0,0 +1,111 @@ +using System; +using static RPG_Maker_LDB_Printer.Program; +using static RPG_Maker_LDB_Printer.Formating; +namespace RPG_Maker_LDB_Printer +{ + public class Data + { + public static void GetSound() + { + GetInt(); + OpenIndent(); + for (bool Data_end = false; Data_end == false;) + { + ContinueIndent(); + int subData = GetInt(); + if (subData == 0x00) + Data_end = true; + else if (subData == 0x01) + GetString(); + else + GetBytes(); + } + CloseIndent(); + } + + public static void Subdata(byte PartID, int data) + { + GetInt(); + int subEntries = GetInt(); + if (subEntries > 0) + { + OpenIndent(); + for (int se = 0; se < subEntries; se++) + { + ContinueIndent(); + GetInt(); + OpenIndent(); + for (bool Data_end = false; Data_end == false;) + { + ContinueIndent(); + int subData = GetInt(); + if (subData == 0x00) + Data_end = true; + else if (PartID == 0x1D & data == 0x0A & subData == 0x01 | PartID == 0x20 & data == 0x0A & subData == 0x01 | PartID == 0x20 & data == 0x0A & subData == 0x02 | PartID == 0x20 & data == 0x0B & subData == 0x01 | PartID == 0x20 & data == 0x0B & subData == 0x02) + GetString(); + else + GetBytes(); + } + CloseIndent(); + } + CloseIndent(); + } + } + + public static int GetInt() + { + return Convert7BitHex(0); + } + + public static int Convert7BitHex(int Prefix) + { + Prefix *= 0x80;//Shift higher-order bytes + byte[] EntryNumber_FirstByte = br.ReadBytes(1); + string ByteHex = BitConverter.ToString(EntryNumber_FirstByte); + sw.Write(ByteHex + " "); + int EntryNumber = EntryNumber_FirstByte[0]; + if (EntryNumber_FirstByte[0] > 0x7f) + { + EntryNumber -= 0x80;//Subtract 8th bit + EntryNumber = Prefix + EntryNumber; + EntryNumber = Convert7BitHex(EntryNumber);//process remaining bytes + } + else + { + EntryNumber = Prefix + EntryNumber;//case of least significant byte + } + return EntryNumber; + } + + public static byte[] GetBytes() + { + int length = GetInt(); + byte[] unknownBytes = br.ReadBytes(length); + string ByteHex = BitConverter.ToString(unknownBytes); + sw.Write(ByteHex + " "); + return unknownBytes; + } + + public static int[] GetInts() + { + int values = GetInt(); + int[] unknownInts = new int[values]; + OpenIndent(); + for (int i = 0; i < values; i++) + { + ContinueIndent(); + unknownInts[i] = GetInt(); + } + CloseIndent(); + return unknownInts; + } + + public static void GetString() + { + string text = br.ReadString(); + br.BaseStream.Position -= text.Length + 1; + sw.Write(BitConverter.ToString(br.ReadBytes(text.Length + 1))); + sw.Write("//" + text); + } + } +} diff --git a/Formating.cs b/Formating.cs new file mode 100644 index 0000000..d903716 --- /dev/null +++ b/Formating.cs @@ -0,0 +1,28 @@ +using static RPG_Maker_LDB_Printer.Program; +namespace RPG_Maker_LDB_Printer +{ + internal class Formating + { + public static int indent = 0; + public static void OpenIndent() + { + ContinueIndent(); + sw.Write("{"); + indent++; + } + + public static void ContinueIndent() + { + sw.Write("\r\n"); + for (int tab = 0; tab < indent; tab++) + sw.Write("\t"); + } + + public static void CloseIndent() + { + indent--; + ContinueIndent(); + sw.Write("}"); + } + } +} diff --git a/GetEvent.cs b/GetEvent.cs new file mode 100644 index 0000000..abd291d --- /dev/null +++ b/GetEvent.cs @@ -0,0 +1,103 @@ +using System; +using static RPG_Maker_LDB_Printer.Program; +namespace RPG_Maker_LDB_Printer +{ + public class Event + { + public static void GetEvent() + { + Formating.ContinueIndent(); + int commoneventdata = Data.GetInt(); + Formating.OpenIndent(); + Formating.ContinueIndent(); + Byte[] level = br.ReadBytes(1); + sw.Write(BitConverter.ToString(level)); + Formating.OpenIndent(); + Formating.ContinueIndent(); + Data.GetString(); + Formating.ContinueIndent(); + int[] gotInts = Data.GetInts(); + switch (commoneventdata) + { + case 0: + case 10://0A + case 20141://81 9D 2D + stop = true; + break; + case 10140://CF 1C + case 20140://81 9D 2C + while (stop == false) + { + GetEvent(); + } + stop = false; + break; + case 12010://DD 6A + case 13310://E7 7E + while (stop == false) + { + GetEvent(); + } + stop = false; + if (gotInts[5] == 1) + { + while (stop == false) + { + GetEvent(); + } + stop = false; + } + GetEvent(); + break; + case 10710://D3 56 + if (gotInts[3] == 2 || gotInts[4] == 1) + { + GetEvent(); + while (stop == false) + { + GetEvent(); + } + stop = false; + GetEvent(); + while (stop == false) + { + GetEvent(); + } + stop = false; + GetEvent(); + } + break; + case 10720://D3 60 + case 10730://D3 6A + if (gotInts[2] == 1) + { + stop = false; + GetEvent(); + while (stop == false) + { + GetEvent(); + } + stop = false; + GetEvent(); + while (stop == false) + { + GetEvent(); + } + stop = false; + GetEvent(); + } + break; + case 12210://DF 32 + while (stop == false) + { + GetEvent(); + } + stop = false; + GetEvent(); + break; + } + Formating.CloseIndent(); + Formating.CloseIndent(); + } + } +} diff --git a/Program.cs b/Program.cs index a933f2b..4d0f181 100644 --- a/Program.cs +++ b/Program.cs @@ -1,13 +1,13 @@ using System; using System.IO; +using static RPG_Maker_LDB_Printer.Formating; namespace RPG_Maker_LDB_Printer { - class Program + public static class Program { public static BinaryReader br; public static StreamWriter sw; - public static int indent = 0; public static bool stop; static void Main(string[] args) @@ -15,7 +15,7 @@ namespace RPG_Maker_LDB_Printer br = new BinaryReader(File.OpenRead(args[0])); sw = new StreamWriter(File.Create(args[0] + ".txt")); - GetString();//LcfDataBase + Data.GetString();//LcfDataBase ContinueIndent(); for (byte[] PartID = new byte[1]; PartID[0] < 0x20;) @@ -26,48 +26,48 @@ namespace RPG_Maker_LDB_Printer sw.Write(PartHex + " "); if (PartID[0] == 0x15 || PartID[0] == 0x16 || PartID[0] == 0x1D) { - GetInt(); + Data.GetInt(); OpenIndent(); for (bool stop = false; stop == false;) { ContinueIndent(); - int data = GetInt(); + int data = Data.GetInt(); if (data == 0x00) stop = true; else if (PartID[0] == 0x15 || PartID[0] == 0x16 & data != 0x0A & data != 0x0f & data != 0x10 & data != 0x15 & data != 0x16 & data != 0x1A & data != 0x1B & data != 0x3D & data != 0x3E & data != 0x3F & data != 0x40 & data != 0x41 & data != 0x42 & data != 0x48 & data != 0x51 & data != 0x52 & data != 0x55 & data != 0x5B & data != 0x60 & data != 0x61) - GetString(); + Data.GetString(); else if (PartID[0] == 0x1D & data == 0x0A) - Subdata(0x1D, 0x0A); + Data.Subdata(0x1D, 0x0A); else - GetBytes(); + Data.GetBytes(); } CloseIndent(); sw.Write("\r\n"); } else { - int length = GetInt(); + int length = Data.GetInt(); if (length > 0) { - int entry = GetInt(); + int entry = Data.GetInt(); OpenIndent(); for (int i = 0; i < entry; i++) { ContinueIndent(); - GetInt(); + Data.GetInt(); OpenIndent(); stop = false; while (stop == false) { ContinueIndent(); - int data = GetInt(); + int data = Data.GetInt(); if (data == 0x00) stop = true; else if (data == 0x01) { - GetString(); + Data.GetString(); } else { @@ -88,7 +88,7 @@ namespace RPG_Maker_LDB_Printer case (0x12, 0x37): case (0x13, 0x02): case (0x14, 0x02): - GetString(); + Data.GetString(); break; #endregion #region Subdata @@ -100,17 +100,17 @@ namespace RPG_Maker_LDB_Printer case (0x1e, 0x3f): case (0x20, 0x0a): case (0x20, 0x0b): - Subdata(PartID[0], data); + Data.Subdata(PartID[0], data); break; #endregion case (0x0c, 0x10): case (0x10, 0x0f): - GetSound(); + Data.GetSound(); break; case (0x0b, 0x1f): case (0x1e, 0x1f): #region system - int system = GetInt(); + int system = Data.GetInt(); OpenIndent(); ContinueIndent(); sw.Write(BitConverter.ToString(br.ReadBytes(system / 6))); @@ -129,19 +129,19 @@ namespace RPG_Maker_LDB_Printer #endregion case (0x13, 0x06): #region AnimationTiming - GetInt(); - int AnimationTiming = GetInt(); + Data.GetInt(); + int AnimationTiming = Data.GetInt(); if (AnimationTiming > 0) OpenIndent(); for (int t = 0; t < AnimationTiming; t++) { ContinueIndent(); - GetInt(); + Data.GetInt(); OpenIndent(); for (bool timingStop = false; timingStop == false;) { ContinueIndent(); - int timingData = GetInt(); + int timingData = Data.GetInt(); if (timingData == 0x00) { CloseIndent(); @@ -149,11 +149,11 @@ namespace RPG_Maker_LDB_Printer } else if (timingData == 0x02) { - GetSound(); + Data.GetSound(); } else { - GetBytes(); + Data.GetBytes(); } } } @@ -163,19 +163,19 @@ namespace RPG_Maker_LDB_Printer #endregion case (0x13, 0x0c): #region Animation Frame - GetInt(); - int AnimationFrame = GetInt(); + Data.GetInt(); + int AnimationFrame = Data.GetInt(); if (AnimationFrame > 0) OpenIndent(); for (int f = 0; f < AnimationFrame; f++) { ContinueIndent(); - GetInt(); + Data.GetInt(); OpenIndent(); for (bool frameStop = false; frameStop == false;) { ContinueIndent(); - int frameData = GetInt(); + int frameData = Data.GetInt(); if (frameData == 0x00) { CloseIndent(); @@ -183,19 +183,19 @@ namespace RPG_Maker_LDB_Printer } else if (frameData == 0x01) { - GetInt(); - int cellData = GetInt(); + Data.GetInt(); + int cellData = Data.GetInt(); if (cellData > 0) OpenIndent(); for (int cd = 0; cd < cellData; cd++) { ContinueIndent(); - GetInt(); + Data.GetInt(); OpenIndent(); for (bool cellDataStop = false; cellDataStop == false;) { ContinueIndent(); - int Cell_Data = GetInt(); + int Cell_Data = Data.GetInt(); if (Cell_Data == 0x00) { cellDataStop = true; @@ -203,7 +203,7 @@ namespace RPG_Maker_LDB_Printer } else { - GetBytes(); + Data.GetBytes(); } } } @@ -211,7 +211,7 @@ namespace RPG_Maker_LDB_Printer CloseIndent(); } else - GetBytes(); + Data.GetBytes(); } } if (AnimationFrame > 0) @@ -220,12 +220,12 @@ namespace RPG_Maker_LDB_Printer #endregion case (0x19, 0x16): #region Event - GetInt(); + Data.GetInt(); OpenIndent(); stop = false; while (stop == false) { - GetEvent(); + Event.GetEvent(); } stop = false; CloseIndent(); @@ -233,52 +233,52 @@ namespace RPG_Maker_LDB_Printer #endregion case (0x0f, 0x0b): #region subEntries - GetInt(); - int subEntries = GetInt(); + Data.GetInt(); + int subEntries = Data.GetInt(); if (subEntries > 0) { OpenIndent(); for (int se = 0; se < subEntries; se++) { ContinueIndent(); - GetInt(); + Data.GetInt(); OpenIndent(); while (stop == false) { ContinueIndent(); - int subData = GetInt(); + int subData = Data.GetInt(); if (subData == 0x00) stop = true; else if (subData == 0x02) { - GetInt(); + Data.GetInt(); OpenIndent(); while (stop == false) { ContinueIndent(); - int subSubData = GetInt(); + int subSubData = Data.GetInt(); if (subSubData == 0x00) stop = true; else - GetBytes(); + Data.GetBytes(); } CloseIndent(); stop = false; } else if (subData == 0x0C) { - GetInt(); + Data.GetInt(); OpenIndent(); ContinueIndent(); while (stop == false) { - GetEvent(); + Event.GetEvent(); } stop = false; CloseIndent(); } else - GetBytes(); + Data.GetBytes(); } stop = false; CloseIndent(); @@ -288,7 +288,7 @@ namespace RPG_Maker_LDB_Printer break; #endregion default: - GetBytes(); + Data.GetBytes(); break; } } @@ -302,225 +302,5 @@ namespace RPG_Maker_LDB_Printer } sw.Close(); } - - static void OpenIndent() - { - ContinueIndent(); - sw.Write("{"); - indent++; - } - - static void ContinueIndent() - { - sw.Write("\r\n"); - for (int tab = 0; tab < indent; tab++) - sw.Write("\t"); - } - - static void CloseIndent() - { - indent--; - ContinueIndent(); - sw.Write("}"); - } - - static void GetSound() - { - GetInt(); - OpenIndent(); - for (bool Data_end = false; Data_end == false;) - { - ContinueIndent(); - int subData = GetInt(); - if (subData == 0x00) - Data_end = true; - else if (subData == 0x01) - GetString(); - else - GetBytes(); - } - CloseIndent(); - } - - static void Subdata(byte PartID, int data) - { - GetInt(); - int subEntries = GetInt(); - if (subEntries > 0) - { - OpenIndent(); - for (int se = 0; se < subEntries; se++) - { - ContinueIndent(); - GetInt(); - OpenIndent(); - for (bool Data_end = false; Data_end == false;) - { - ContinueIndent(); - int subData = GetInt(); - if (subData == 0x00) - Data_end = true; - else if (PartID == 0x1D & data == 0x0A & subData == 0x01 | PartID == 0x20 & data == 0x0A & subData == 0x01 | PartID == 0x20 & data == 0x0A & subData == 0x02 | PartID == 0x20 & data == 0x0B & subData == 0x01 | PartID == 0x20 & data == 0x0B & subData == 0x02) - GetString(); - else - GetBytes(); - } - CloseIndent(); - } - CloseIndent(); - } - } - - static int GetInt() - { - return Convert7BitHex(0); - } - - static int Convert7BitHex(int Prefix) - { - Prefix *= 0x80;//Shift higher-order bytes - byte[] EntryNumber_FirstByte = br.ReadBytes(1); - string ByteHex = BitConverter.ToString(EntryNumber_FirstByte); - sw.Write(ByteHex + " "); - int EntryNumber = EntryNumber_FirstByte[0]; - if (EntryNumber_FirstByte[0] > 0x7f) - { - EntryNumber -= 0x80;//Subtract 8th bit - EntryNumber = Prefix + EntryNumber; - EntryNumber = Convert7BitHex(EntryNumber);//process remaining bytes - } - else - { - EntryNumber = Prefix + EntryNumber;//case of least significant byte - } - return EntryNumber; - } - - static byte[] GetBytes() - { - int length = GetInt(); - byte[] unknownBytes = br.ReadBytes(length); - string ByteHex = BitConverter.ToString(unknownBytes); - sw.Write(ByteHex + " "); - return unknownBytes; - } - - static int[] GetInts() - { - int values = GetInt(); - int[] unknownInts = new int[values]; - OpenIndent(); - for (int i = 0; i < values; i++) - { - ContinueIndent(); - unknownInts[i] = GetInt(); - } - CloseIndent(); - return unknownInts; - } - - static void GetString() - { - string text = br.ReadString(); - br.BaseStream.Position -= text.Length + 1; - sw.Write(BitConverter.ToString(br.ReadBytes(text.Length + 1))); - sw.Write("//" + text); - } - - static void GetEvent() - { - ContinueIndent(); - int commoneventdata = GetInt(); - OpenIndent(); - ContinueIndent(); - Byte[] level = br.ReadBytes(1); - sw.Write(BitConverter.ToString(level)); - OpenIndent(); - ContinueIndent(); - GetString(); - ContinueIndent(); - int[] gotInts = GetInts(); - switch (commoneventdata) - { - case 0: - case 10://0A - case 20141://81 9D 2D - stop = true; - break; - case 10140://CF 1C - case 20140://81 9D 2C - while (stop == false) - { - GetEvent(); - } - stop = false; - break; - case 12010://DD 6A - case 13310://E7 7E - while (stop == false) - { - GetEvent(); - } - stop = false; - if (gotInts[5] == 1) - { - while (stop == false) - { - GetEvent(); - } - stop = false; - } - GetEvent(); - break; - case 10710://D3 56 - if (gotInts[3] == 2 || gotInts[4] == 1) - { - GetEvent(); - while (stop == false) - { - GetEvent(); - } - stop = false; - GetEvent(); - while (stop == false) - { - GetEvent(); - } - stop = false; - GetEvent(); - } - break; - case 10720://D3 60 - case 10730://D3 6A - if (gotInts[2] == 1) - { - stop = false; - GetEvent(); - while (stop == false) - { - GetEvent(); - } - stop = false; - GetEvent(); - while (stop == false) - { - GetEvent(); - } - stop = false; - GetEvent(); - } - break; - case 12210://DF 32 - while (stop == false) - { - GetEvent(); - } - stop = false; - GetEvent(); - break; - } - CloseIndent(); - CloseIndent(); - } } }