public static int Import( List<string> args ) { if ( args.Count < 3 ) { Console.WriteLine( "Usage: file Database GracesJapanese" ); return -1; } string InFile = args[0]; string OutDatabase = args[1]; string GracesJapanese = args[2]; HyoutaTools.LastRanker.StringFile StringFile = new HyoutaTools.LastRanker.StringFile( System.IO.File.ReadAllBytes( InFile ) ); System.IO.File.WriteAllBytes( OutDatabase, Properties.Resources.gndb_template ); List<GraceNoteDatabaseEntry> Entries = new List<GraceNoteDatabaseEntry>( StringFile.Strings.Count ); foreach ( HyoutaTools.LastRanker.bscrString e in StringFile.Strings ) { int status = 0; if ( e.String.StartsWith( "func" ) || e.String.StartsWith( "■" ) || e.String.Trim() == "" ) { status = -1; } GraceNoteDatabaseEntry gn = new GraceNoteDatabaseEntry( e.String, e.String, "", status, (int)e.Position, "", 0 ); Entries.Add( gn ); } GraceNoteDatabaseEntry.InsertSQL( Entries.ToArray(), "Data Source=" + OutDatabase, "Data Source=" + GracesJapanese ); return 0; }
public static int Execute( List<string> args ) { if ( args.Count != 4 ) { Console.WriteLine( "Usage: LuxPainEvt_GraceNote event.evt NewDBFile GracesJapanese event.jp.evt" ); return -1; } String Filename = args[0]; String NewDB = args[1]; String GracesDB = args[2]; String JapaneseFilename = args[3]; LuxPainEvt Evt; LuxPainEvt EvtJp; try { Evt = new LuxPainEvt( Filename ); EvtJp = new LuxPainEvt( JapaneseFilename ); } catch ( Exception ex ) { Console.WriteLine( ex.Message ); Console.WriteLine( "Failed loading text file!" ); return -1; } Evt.FormatTextForEditing(); EvtJp.FormatTextForEditing(); if ( Evt.TextEntries.Count != EvtJp.TextEntries.Count ) { Console.WriteLine( "Entry count over languages doesn't match, padding..." ); while ( Evt.TextEntries.Count < EvtJp.TextEntries.Count ) { LuxPainEvtText t = new LuxPainEvtText(); t.OffsetLocation = 0x7FFFFFFF; t.Text = "[Entry does not exist in this language, this is just for completion's sake.]"; Evt.TextEntries.Add( t ); } while ( Evt.TextEntries.Count > EvtJp.TextEntries.Count ) { LuxPainEvtText t = new LuxPainEvtText(); t.OffsetLocation = 0x7FFFFFFF; t.Text = "[Entry does not exist in this language, this is just for completion's sake.]"; EvtJp.TextEntries.Add( t ); } if ( Evt.TextEntries.Count != EvtJp.TextEntries.Count ) { throw new Exception( "this shouldn't happen!" ); } } Console.WriteLine( "Found " + Evt.TextEntries.Count + " entries, importing..." ); System.IO.File.WriteAllBytes( NewDB, Properties.Resources.gndb_template ); List<GraceNoteDatabaseEntry> Entries = new List<GraceNoteDatabaseEntry>( Evt.TextEntries.Count ); for ( int i = 0; i < Evt.TextEntries.Count; ++i ) { // fetch GracesJapanese ID or generate new & insert new text String EnPlusJp = Evt.TextEntries[i].Text + "\n\n" + EvtJp.TextEntries[i].Text; GraceNoteDatabaseEntry gn = new GraceNoteDatabaseEntry( EnPlusJp, Evt.TextEntries[i].Text, "", 0, (int)Evt.TextEntries[i].OffsetLocation, "", 0 ); Entries.Add( gn ); } GraceNoteDatabaseEntry.InsertSQL( Entries.ToArray(), "Data Source=" + NewDB, "Data Source=" + GracesDB ); Console.WriteLine( "Successfully imported entries!" ); return 0; }
public static int Execute(List <string> args) { string string_dic = args[0]; string databasename = args[1]; string gracesjapanese = args[2]; TSSFile TSS; try { TSS = new TSSFile(System.IO.File.ReadAllBytes(string_dic)); } catch (System.IO.FileNotFoundException) { Console.WriteLine("Could not open STRING_DIC.SO, exiting."); return(-1); } List <GraceNoteDatabaseEntry> entries = new List <GraceNoteDatabaseEntry>(); foreach (TSSEntry e in TSS.Entries) { GraceNoteDatabaseEntry g = new GraceNoteDatabaseEntry(e.StringJpn, e.StringEng); entries.Add(g); } GraceNoteUtil.GenerateEmptyDatabase(databasename); GraceNoteDatabaseEntry.InsertSQL(entries.ToArray(), "Data Source=" + databasename, "Data Source=" + gracesjapanese); return(0); }
public static int Execute(List <string> args) { if (args.Count != 4) { Console.WriteLine("Usage: btlpack_GraceNote btlpackexFile NewDBFile GracesJapanese StartOfTextpointersInHex"); return(-1); } String Filename = args[0]; String NewDB = args[1]; String GracesDB = args[2]; int TextPointersAddress = Int32.Parse(args[3], System.Globalization.NumberStyles.AllowHexSpecifier); byte[] btlpack = System.IO.File.ReadAllBytes(Filename); byte[] PointerDifferenceBytes = { btlpack[0x27], btlpack[0x26], btlpack[0x25], btlpack[0x24] }; int PointerDifference = BitConverter.ToInt32(PointerDifferenceBytes, 0); PointerDifference -= 0x400; ScenarioString[] AllStrings = FindAllStrings(btlpack, TextPointersAddress, PointerDifference); GraceNoteUtil.GenerateEmptyDatabase(NewDB); List <GraceNoteDatabaseEntry> Entries = new List <GraceNoteDatabaseEntry>(AllStrings.Length); foreach (ScenarioString str in AllStrings) { GraceNoteDatabaseEntry gn = new GraceNoteDatabaseEntry(str.Jpn, str.Eng, "", str.Eng == str.Jpn ? 1 : 0, str.Pointer, "", 0); Entries.Add(gn); } GraceNoteDatabaseEntry.InsertSQL(Entries.ToArray(), "Data Source=" + NewDB, "Data Source=" + GracesDB); return(0); }
public static int Execute( List<string> args ) { string string_dic = args[0]; string databasename = args[1]; string gracesjapanese = args[2]; TSSFile TSS; try { TSS = new TSSFile( System.IO.File.ReadAllBytes( string_dic ) ); } catch ( System.IO.FileNotFoundException ) { Console.WriteLine( "Could not open STRING_DIC.SO, exiting." ); return -1; } List<GraceNoteDatabaseEntry> entries = new List<GraceNoteDatabaseEntry>(); foreach ( TSSEntry e in TSS.Entries ) { GraceNoteDatabaseEntry g = new GraceNoteDatabaseEntry( e.StringJpn, e.StringEng ); entries.Add( g ); } System.IO.File.WriteAllBytes( databasename, Properties.Resources.gndb_template ); GraceNoteDatabaseEntry.InsertSQL( entries.ToArray(), "Data Source=" + databasename, "Data Source=" + gracesjapanese ); return 0; }
public static int Execute( List<string> args ) { if ( args.Count != 3 ) { Console.WriteLine( "Usage: XilliaScript_GraceNote XilliaScriptFile NewDBFile GracesJapanese" ); return -1; } String Filename = args[0]; String NewDB = args[1]; String GracesDB = args[2]; SDB XSF = new SDB( Filename ); System.IO.File.WriteAllBytes( NewDB, Properties.Resources.gndb_template ); if ( !System.IO.File.Exists( GracesDB ) ) { System.IO.File.WriteAllBytes( GracesDB, Properties.Resources.gngj_template ); } List<GraceNoteDatabaseEntry> Entries = new List<GraceNoteDatabaseEntry>( XSF.TextList.Count ); foreach ( SDBEntry entry in XSF.TextList ) { GraceNoteDatabaseEntry gn = new GraceNoteDatabaseEntry( entry.Text, entry.Text, "", 0, (int)entry.PointerText, entry.IDString, (int)entry.PointerIDString ); Entries.Add( gn ); } GraceNoteDatabaseEntry.InsertSQL( Entries.ToArray(), "Data Source=" + NewDB, "Data Source=" + GracesDB ); return 0; }
public static int Import(List <string> args) { if (args.Count < 3) { Console.WriteLine("Usage: sscr Database GracesJapanese"); return(-1); } string InFile = args[0]; string OutDatabase = args[1]; string GracesJapanese = args[2]; SSCR SscrFile = new SSCR(System.IO.File.ReadAllBytes(InFile)); GraceNoteUtil.GenerateEmptyDatabase(OutDatabase); List <GraceNoteDatabaseEntry> Entries = new List <GraceNoteDatabaseEntry>(SscrFile.Names.Count + SscrFile.SystemTerms.Count + SscrFile.Somethings.Count); foreach (var x in SscrFile.Names) { Entries.Add(new GraceNoteDatabaseEntry(x.Name, x.Name, "", 0, 1, x.Id, (int)x.Unknown)); } foreach (var x in SscrFile.SystemTerms) { Entries.Add(new GraceNoteDatabaseEntry(x.Term, x.Term, "", 0, 2, "", (int)x.Unknown)); } foreach (var x in SscrFile.Somethings) { Entries.Add(new GraceNoteDatabaseEntry(x.Text, x.Text, "", 0, 3, x.Id, (int)x.Unknown4)); } GraceNoteDatabaseEntry.InsertSQL(Entries.ToArray(), "Data Source=" + OutDatabase, "Data Source=" + GracesJapanese); return(0); }
public static int Import(List <string> args) { if (args.Count < 3) { Console.WriteLine("Usage: bscr Database GracesJapanese"); return(-1); } string InFile = args[0]; string OutDatabase = args[1]; string GracesJapanese = args[2]; HyoutaTools.LastRanker.bscr bscrFile = new HyoutaTools.LastRanker.bscr(System.IO.File.ReadAllBytes(InFile)); GraceNoteUtil.GenerateEmptyDatabase(OutDatabase); List <GraceNoteDatabaseEntry> Entries = new List <GraceNoteDatabaseEntry>(bscrFile.Strings.Count); foreach (HyoutaTools.LastRanker.bscrString e in bscrFile.Strings) { int status = 0; if (e.String.StartsWith("func") || e.String.StartsWith("■") || e.String.Trim() == "") { status = -1; } GraceNoteDatabaseEntry gn = new GraceNoteDatabaseEntry(e.String, e.String, "", status, (int)e.Position, "", 0); Entries.Add(gn); } GraceNoteDatabaseEntry.InsertSQL(Entries.ToArray(), "Data Source=" + OutDatabase, "Data Source=" + GracesJapanese); return(0); }
public static int Execute(List <string> args) { if (args.Count != 3) { Console.WriteLine("Usage: XilliaScript_GraceNote XilliaScriptFile NewDBFile GracesJapanese"); return(-1); } String Filename = args[0]; String NewDB = args[1]; String GracesDB = args[2]; SDB XSF = new SDB(Filename); GraceNoteUtil.GenerateEmptyDatabase(NewDB); if (!System.IO.File.Exists(GracesDB)) { GraceNoteUtil.GenerateEmptyGracesJapanese(GracesDB); } List <GraceNoteDatabaseEntry> Entries = new List <GraceNoteDatabaseEntry>(XSF.TextList.Count); foreach (SDBEntry entry in XSF.TextList) { GraceNoteDatabaseEntry gn = new GraceNoteDatabaseEntry(entry.Text, entry.Text, "", 0, (int)entry.PointerText, entry.IDString, (int)entry.PointerIDString); Entries.Add(gn); } GraceNoteDatabaseEntry.InsertSQL(Entries.ToArray(), "Data Source=" + NewDB, "Data Source=" + GracesDB); return(0); }
public static int Execute(List <string> args) { if (args.Count != 3) { Console.WriteLine("Usage: VVoicesGenerate VOBTLdir VVoices.db GracesJapanese.db"); return(-1); } String VOBTLDir = args[0]; String VoiceDB = args[1]; String GracesDB = args[2]; String[] VOBTLFiles = System.IO.Directory.GetFiles(VOBTLDir); List <GraceNoteDatabaseEntry> Entries = new List <GraceNoteDatabaseEntry>(); foreach (String VOBTL in VOBTLFiles) { String VOBTLcut = VOBTL.Substring(VOBTL.LastIndexOfAny(new char[] { '/', '\\' }) + 1); if (VOBTLcut.Contains('.')) { VOBTLcut = VOBTLcut.Remove(VOBTLcut.LastIndexOf('.')); } String s = "\t(" + VOBTLcut + ')'; Entries.Add(new GraceNoteDatabaseEntry(s, s, "", 0, 0, "", 0)); } GraceNoteDatabaseEntry.InsertSQL(Entries.ToArray(), "Data Source=" + VoiceDB, "Data Source=" + GracesDB); return(0); }
public static int Execute( List<string> args ) { if ( args.Count != 4 ) { Console.WriteLine( "Usage: btlpack_GraceNote btlpackexFile NewDBFile GracesJapanese StartOfTextpointersInHex" ); return -1; } String Filename = args[0]; String NewDB = args[1]; String GracesDB = args[2]; int TextPointersAddress = Int32.Parse( args[3], System.Globalization.NumberStyles.AllowHexSpecifier ); byte[] btlpack = System.IO.File.ReadAllBytes( Filename ); byte[] PointerDifferenceBytes = { btlpack[0x27], btlpack[0x26], btlpack[0x25], btlpack[0x24] }; int PointerDifference = BitConverter.ToInt32( PointerDifferenceBytes, 0 ); PointerDifference -= 0x400; ScenarioString[] AllStrings = FindAllStrings( btlpack, TextPointersAddress, PointerDifference ); System.IO.File.WriteAllBytes( NewDB, Properties.Resources.gndb_template ); List<GraceNoteDatabaseEntry> Entries = new List<GraceNoteDatabaseEntry>( AllStrings.Length ); foreach ( ScenarioString str in AllStrings ) { GraceNoteDatabaseEntry gn = new GraceNoteDatabaseEntry( str.Jpn, str.Eng, "", str.Eng == str.Jpn ? 1 : 0, str.Pointer, "", 0 ); Entries.Add( gn ); } GraceNoteDatabaseEntry.InsertSQL( Entries.ToArray(), "Data Source=" + NewDB, "Data Source=" + GracesDB ); return 0; }
public static int Import(List <string> args) { if (args.Count < 3) { Console.WriteLine("Usage: scr Database GracesJapanese"); return(-1); } string InFile = args[0]; string OutDatabase = args[1]; string GracesJapanese = args[2]; var bscrFile = new HyoutaTools.Narisokonai.scr(System.IO.File.ReadAllBytes(InFile)); GraceNoteUtil.GenerateEmptyDatabase(OutDatabase); if (!System.IO.File.Exists(GracesJapanese)) { GraceNoteUtil.GenerateEmptyGracesJapanese(GracesJapanese); } List <GraceNoteDatabaseEntry> Entries = new List <GraceNoteDatabaseEntry>(); foreach (var sec in bscrFile.Sections) { if (sec.Elements == null) { continue; // dummy section } GraceNoteDatabaseEntry gn; foreach (var e in sec.Elements) { switch (e.Type) { case HyoutaTools.Narisokonai.scrElement.scrElementType.Code: StringBuilder sb = new StringBuilder(); for (int i = 0; i < e.Code.Length; ++i) { sb.Append('<').Append(e.Code[i].ToString("X2")).Append("> "); } gn = new GraceNoteDatabaseEntry(sb.ToString(), sb.ToString(), "", -1, (int)sec.Location, e.Type.ToString(), sec.PointerIndex); break; case HyoutaTools.Narisokonai.scrElement.scrElementType.Text: gn = new GraceNoteDatabaseEntry(e.Text, e.Text, "", 0, (int)sec.Location, e.Type.ToString(), sec.PointerIndex); break; default: throw new Exception("scrImport: Unknown Element Type!"); } Entries.Add(gn); } } GraceNoteDatabaseEntry.InsertSQL(Entries.ToArray(), "Data Source=" + OutDatabase, "Data Source=" + GracesJapanese); return(0); }
public static bool Export(string originalScriptFilename, string databaseFilename, string gracesJapaneseFilename, string newScriptFilename) { byte[] script = System.IO.File.ReadAllBytes(originalScriptFilename); uint sectionPointerLocation = BitConverter.ToUInt32(script, 0); // this is SUPER HACKY but should work using (var stream = new System.IO.FileStream(newScriptFilename, System.IO.FileMode.Create)) { var entries = GraceNoteDatabaseEntry.GetAllEntriesFromDatabase("Data Source=" + databaseFilename, "Data Source=" + gracesJapaneseFilename); // copy whole flie except for the section pointers for (int i = 0; i < sectionPointerLocation; ++i) { stream.WriteByte(script[i]); } long pos = stream.Position; // remove original strings from the file foreach (var entry in entries) { stream.Position = entry.PointerRef; RemoveString(stream, stream.ReadUInt32()); } stream.Position = pos; // now write the modified strings from the GN db at the end of the file foreach (var entry in entries) { uint stringLocation = Convert.ToUInt32(stream.Position); stream.Position = entry.PointerRef; stream.WriteUInt32(stringLocation); stream.Position = stringLocation; stream.Write(StringToBytesBlazeUnion(entry.TextEN)); stream.WriteByte(0); } // write the section pointers and replace position stream.Position = stream.Position.Align(4); uint newSectionPointerLocation = Convert.ToUInt32(stream.Position); for (uint i = sectionPointerLocation; i < script.Length; ++i) { stream.WriteByte(script[i]); } stream.Position = 0; stream.WriteUInt32(newSectionPointerLocation); } return(true); }
public static int Import(String Filename, String NewDB, String GracesDB) { LIN lin; try { lin = new LIN(Filename); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine("Failed loading text file!"); return(-1); } Console.WriteLine("Importing..."); GraceNoteUtil.GenerateEmptyDatabase(NewDB); List <GraceNoteDatabaseEntry> Entries = new List <GraceNoteDatabaseEntry>(); string TextToInsert = ""; foreach (ScriptEntry s in lin.ScriptData) { if (s.Type == 0x02) { Entries.Add(new GraceNoteDatabaseEntry(TextToInsert, TextToInsert, "", -1, 1, "[Game Code]", 0)); Entries.Add(new GraceNoteDatabaseEntry(s.Text, s.Text, "", 0, 2, s.IdentifyString, 0)); TextToInsert = ""; continue; } TextToInsert = TextToInsert + s.FormatForGraceNote() + '\n'; } if (TextToInsert != null) { Entries.Add(new GraceNoteDatabaseEntry(TextToInsert, TextToInsert, "", -1, 1, "[Game Code]", 0)); } if (lin.UnreferencedText != null) { foreach (KeyValuePair <int, string> u in lin.UnreferencedText) { Entries.Add(new GraceNoteDatabaseEntry(u.Value, u.Value, "", 0, 3, "[Unreferenced Text]", u.Key)); } } GraceNoteDatabaseEntry.InsertSQL(Entries.ToArray(), "Data Source=" + NewDB, "Data Source=" + GracesDB); Console.WriteLine("Successfully imported entries!"); return(0); }
public static int Import( List<string> args ) { if ( args.Count < 3 ) { Console.WriteLine( "Usage: scr Database GracesJapanese" ); return -1; } string InFile = args[0]; string OutDatabase = args[1]; string GracesJapanese = args[2]; var bscrFile = new HyoutaTools.Narisokonai.scr( System.IO.File.ReadAllBytes( InFile ) ); System.IO.File.WriteAllBytes( OutDatabase, Properties.Resources.gndb_template ); if ( !System.IO.File.Exists( GracesJapanese ) ) { System.IO.File.WriteAllBytes( GracesJapanese, Properties.Resources.gngj_template ); } List<GraceNoteDatabaseEntry> Entries = new List<GraceNoteDatabaseEntry>(); foreach ( var sec in bscrFile.Sections ) { if ( sec.Elements == null ) continue; // dummy section GraceNoteDatabaseEntry gn; foreach ( var e in sec.Elements ) { switch ( e.Type ) { case HyoutaTools.Narisokonai.scrElement.scrElementType.Code: StringBuilder sb = new StringBuilder(); for ( int i = 0; i < e.Code.Length; ++i ) { sb.Append( '<' ).Append( e.Code[i].ToString( "X2" ) ).Append( "> " ); } gn = new GraceNoteDatabaseEntry( sb.ToString(), sb.ToString(), "", -1, (int)sec.Location, e.Type.ToString(), sec.PointerIndex ); break; case HyoutaTools.Narisokonai.scrElement.scrElementType.Text: gn = new GraceNoteDatabaseEntry( e.Text, e.Text, "", 0, (int)sec.Location, e.Type.ToString(), sec.PointerIndex ); break; default: throw new Exception("scrImport: Unknown Element Type!"); } Entries.Add( gn ); } } GraceNoteDatabaseEntry.InsertSQL( Entries.ToArray(), "Data Source=" + OutDatabase, "Data Source=" + GracesJapanese ); return 0; }
public static int Execute(List <string> args) { if (args.Count != 3) { Console.WriteLine("Usage: TO8CHTX_GraceNote ChatFilename NewDBFilename GracesJapanese"); return(-1); } String Filename = args[0]; String NewDB = args[1]; String GracesDB = args[2]; ChatFile c = new ChatFile(System.IO.File.ReadAllBytes(Filename)); GraceNoteUtil.GenerateEmptyDatabase(NewDB); List <GraceNoteDatabaseEntry> Entries = new List <GraceNoteDatabaseEntry>(c.Lines.Length * 2); foreach (ChatFileLine Line in c.Lines) { String EnglishText; int EnglishStatus; if (Line.SENG == "Dummy" || Line.SENG == "") { EnglishText = Line.SJPN; EnglishStatus = 0; } else { EnglishText = Line.SENG; EnglishStatus = 1; } Entries.Add(new GraceNoteDatabaseEntry(Line.SName, Line.SName, "", 1, Line.Location, "", 0)); Entries.Add(new GraceNoteDatabaseEntry(Line.SJPN, EnglishText, "", EnglishStatus, Line.Location + 4, "", 0)); } GraceNoteDatabaseEntry.InsertSQL(Entries.ToArray(), "Data Source=" + NewDB, "Data Source=" + GracesDB); return(0); }
public static int Execute(List <string> args) { if (args.Count != 3) { Console.WriteLine("Usage: menu.pak NewDBFile GracesJapanese"); return(-1); } String Filename = args[0]; String NewDB = args[1]; String GracesDB = args[2]; PakText DRMF; try { DRMF = new PakText(Filename); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine("Failed loading menu file!"); return(-1); } Console.WriteLine("Found " + DRMF.TextList.Count + " entries, importing..."); GraceNoteUtil.GenerateEmptyDatabase(NewDB); List <GraceNoteDatabaseEntry> Entries = new List <GraceNoteDatabaseEntry>(DRMF.TextList.Count); foreach (PakTextEntry entry in DRMF.TextList) { GraceNoteDatabaseEntry gn = new GraceNoteDatabaseEntry(entry.Text, entry.Text, "", 0, entry.OffsetLocation, "", 0); Entries.Add(gn); } GraceNoteDatabaseEntry.InsertSQL(Entries.ToArray(), "Data Source=" + NewDB, "Data Source=" + GracesDB); Console.WriteLine("Successfully imported entries!"); //byte[] newfile = DRMF.CreateFile(); //System.IO.File.WriteAllBytes(Filename + ".new", newfile); return(0); }
public static bool Import(String filename, String newDb, String gracesJapanese) { BlazeUnionScriptFile scriptfile = new BlazeUnionScriptFile(filename); List <GraceNoteDatabaseEntry> entries = new List <GraceNoteDatabaseEntry>(); GraceNoteUtil.GenerateEmptyDatabase(newDb); if (!System.IO.File.Exists(gracesJapanese)) { GraceNoteUtil.GenerateEmptyGracesJapanese(gracesJapanese); } foreach (var section in scriptfile.Sections) { foreach (var kvp in section.Strings) { entries.Add(new GraceNoteDatabaseEntry(kvp.Value, PointerRef: (int)kvp.Key)); } } GraceNoteDatabaseEntry.InsertSQL(entries.ToArray(), "Data Source=" + newDb, "Data Source=" + gracesJapanese); return(true); }
public static List <GraceNoteDatabaseEntry> ReadDatabase(string ConnectionString) { SQLiteConnection Connection = new SQLiteConnection(ConnectionString); Connection.Open(); List <GraceNoteDatabaseEntry> Entries = new List <GraceNoteDatabaseEntry>(); using (SQLiteTransaction Transaction = Connection.BeginTransaction()) using (SQLiteCommand Command = new SQLiteCommand(Connection)) { Command.CommandText = "SELECT english, PointerRef, IdentifyString, IdentifyPointerRef FROM Text ORDER BY PointerRef ASC, IdentifyPointerRef ASC"; SQLiteDataReader r = Command.ExecuteReader(); while (r.Read()) { String SQLText; try { SQLText = r.GetString(0).Replace("''", "'"); } catch (System.InvalidCastException) { SQLText = ""; } int PointerRef = r.GetInt32(1); GraceNoteDatabaseEntry e = new GraceNoteDatabaseEntry(); e.PointerRef = PointerRef; e.TextEN = SQLText; e.IdentifyString = r.GetString(2); e.IdentifyPointerRef = r.GetInt32(3); Entries.Add(e); } Transaction.Rollback(); } return(Entries); }
public static void FormatDatabase(string Filename, string FilenameGracesJapanese, int maxCharsPerLine) { //CleanGracesJapanese("Data Source=" + FilenameGracesJapanese); //CleanDatabase( "Data Source=" + Filename ); //return; GraceNoteDatabaseEntry[] entries = GraceNoteDatabaseEntry.GetAllEntriesFromDatabase("Data Source=" + Filename, "Data Source=" + FilenameGracesJapanese); SQLiteConnection conn = new SQLiteConnection("Data Source=" + Filename); conn.Open(); SQLiteTransaction transaction = conn.BeginTransaction(); foreach (GraceNoteDatabaseEntry e in entries) { //e.TextEN = e.TextEN; if (e.Status == -1) { continue; } //e.TextEN = e.TextEN.Trim(); e.TextEN = FormatString(e.TextEN, maxCharsPerLine); SqliteUtil.Update( transaction, "UPDATE Text SET english = ? WHERE ID = ?", new object[] { e.TextEN, e.ID } ); } transaction.Commit(); conn.Close(); return; }
public static int Execute( List<string> args ) { if ( args.Count != 3 ) { Console.WriteLine( "Usage: menu.pak NewDBFile GracesJapanese" ); return -1; } String Filename = args[0]; String NewDB = args[1]; String GracesDB = args[2]; PakText DRMF; try { DRMF = new PakText( Filename ); } catch ( Exception ex ) { Console.WriteLine( ex.Message ); Console.WriteLine( "Failed loading menu file!" ); return -1; } Console.WriteLine( "Found " + DRMF.TextList.Count + " entries, importing..." ); System.IO.File.WriteAllBytes( NewDB, Properties.Resources.gndb_template ); List<GraceNoteDatabaseEntry> Entries = new List<GraceNoteDatabaseEntry>( DRMF.TextList.Count ); foreach ( PakTextEntry entry in DRMF.TextList ) { GraceNoteDatabaseEntry gn = new GraceNoteDatabaseEntry( entry.Text, entry.Text, "", 0, entry.OffsetLocation, "", 0 ); Entries.Add( gn ); } GraceNoteDatabaseEntry.InsertSQL( Entries.ToArray(), "Data Source=" + NewDB, "Data Source=" + GracesDB ); Console.WriteLine( "Successfully imported entries!" ); //byte[] newfile = DRMF.CreateFile(); //System.IO.File.WriteAllBytes(Filename + ".new", newfile); return 0; }
public static int Execute(List <string> args) { if (args.Count != 4) { Console.WriteLine("Usage: TropSFM_GraceNote TROP.SFM TROPCONF.SFM NewDBFile GracesJapanese"); return(-1); } String Filename = args[0]; String FilenameTropConf = args[1]; String NewDB = args[2]; String GracesDB = args[3]; TrophyConfNode TROPSFM = TrophyConfNode.ReadTropSfmWithTropConf(Filename, FilenameTropConf); GraceNoteUtil.GenerateEmptyDatabase(NewDB); List <GraceNoteDatabaseEntry> Entries = new List <GraceNoteDatabaseEntry>(TROPSFM.Trophies.Values.Count * 2); foreach (TrophyNode Trophy in TROPSFM.Trophies.Values) { string Ident = "<ID: " + Trophy.ID + "> " + "<Hidden: " + Trophy.Hidden.ToString() + "> " + "<TType: " + Trophy.TType + "> " + "<PID: " + Trophy.PID + ">"; Entries.Add(new GraceNoteDatabaseEntry(Trophy.Name, Trophy.Name, "", 0, 0, Ident, 0)); Entries.Add(new GraceNoteDatabaseEntry(Trophy.Detail, Trophy.Detail, "", 0, 1, Ident, 0)); } GraceNoteDatabaseEntry.InsertSQL(Entries.ToArray(), "Data Source=" + NewDB, "Data Source=" + GracesDB); //System.IO.File.WriteAllBytes(@"C:\TROPHY\newTrophyConf.trp", Encoding.UTF8.GetBytes(TROPSFM.ExportTropSFM(true))); //System.IO.File.WriteAllBytes(@"C:\TROPHY\newTrophy.trp", Encoding.UTF8.GetBytes(TROPSFM.ExportTropSFM(false))); return(0); }
public static List<GraceNoteDatabaseEntry> ReadDatabase( string ConnectionString ) { SQLiteConnection Connection = new SQLiteConnection( ConnectionString ); Connection.Open(); List<GraceNoteDatabaseEntry> Entries = new List<GraceNoteDatabaseEntry>(); using ( SQLiteTransaction Transaction = Connection.BeginTransaction() ) using ( SQLiteCommand Command = new SQLiteCommand( Connection ) ) { Command.CommandText = "SELECT english, PointerRef, IdentifyString, IdentifyPointerRef FROM Text ORDER BY PointerRef ASC, IdentifyPointerRef ASC"; SQLiteDataReader r = Command.ExecuteReader(); while ( r.Read() ) { String SQLText; try { SQLText = r.GetString( 0 ).Replace( "''", "'" ); } catch ( System.InvalidCastException ) { SQLText = ""; } int PointerRef = r.GetInt32( 1 ); GraceNoteDatabaseEntry e = new GraceNoteDatabaseEntry(); e.PointerRef = PointerRef; e.TextEN = SQLText; e.IdentifyString = r.GetString( 2 ); e.IdentifyPointerRef = r.GetInt32( 3 ); Entries.Add( e ); } Transaction.Rollback(); } return Entries; }
public static void FindEarliestGracesJapaneseEntry(String ConnectionString, String GracesJapaneseConnectionString) { using (SQLiteConnection ConnectionE = new SQLiteConnection(ConnectionString)) using (SQLiteConnection ConnectionJ = new SQLiteConnection(GracesJapaneseConnectionString)) { ConnectionE.Open(); ConnectionJ.Open(); using (SQLiteTransaction TransactionE = ConnectionE.BeginTransaction()) using (SQLiteTransaction TransactionJ = ConnectionJ.BeginTransaction()) using (SQLiteCommand CommandEFetch = new SQLiteCommand(ConnectionE)) using (SQLiteCommand CommandEUpdate = new SQLiteCommand(ConnectionE)) using (SQLiteCommand CommandJ = new SQLiteCommand(ConnectionJ)) { // fetch, from the individual game file Database, all IDs and corresponding GracesJapanese StringIDs CommandEFetch.CommandText = "SELECT ID, StringID FROM Text ORDER BY ID"; SQLiteDataReader r = CommandEFetch.ExecuteReader(); List <GraceNoteDatabaseEntry> DatabaseEntries = new List <GraceNoteDatabaseEntry>(); while (r.Read()) { int ID = r.GetInt32(0); int StringID = r.GetInt32(1); var gn = new GraceNoteDatabaseEntry(); gn.ID = ID; gn.JPID = StringID; DatabaseEntries.Add(gn); } r.Close(); CommandJ.CommandText = "PRAGMA case_sensitive_like = ON"; int affected = CommandJ.ExecuteNonQuery(); // This finds all entries in GracesJapanese that have the same Japanese text as the current game file DB entry CommandJ.CommandText = "SELECT ID FROM Japanese WHERE CAST(string AS BLOB) = " + "( SELECT CAST(string AS BLOB) FROM Japanese WHERE ID = ? ) ORDER BY ID ASC"; SQLiteParameter ParamJId = new SQLiteParameter(); CommandJ.Parameters.Add(ParamJId); // This updates the game file DB with the new StringID CommandEUpdate.CommandText = "UPDATE Text SET StringID = ? WHERE ID = ?"; SQLiteParameter ParamEStringId = new SQLiteParameter(); SQLiteParameter ParamEId = new SQLiteParameter(); CommandEUpdate.Parameters.Add(ParamEStringId); CommandEUpdate.Parameters.Add(ParamEId); int entryCounter = 0; int alreadyCorrectChainCounter = 0; foreach (var e in DatabaseEntries) { ++entryCounter; // get the lowest StringID ParamJId.Value = e.JPID; int?EarliestStringId = (int?)CommandJ.ExecuteScalar(); // and put it into the game file DB, if needed if (EarliestStringId != null && EarliestStringId != e.JPID) { alreadyCorrectChainCounter = 0; Console.WriteLine("Changing Entry #" + e.ID + " from StringID " + e.JPID + " to " + EarliestStringId); ParamEId.Value = e.ID; ParamEStringId.Value = EarliestStringId; CommandEUpdate.ExecuteNonQuery(); } else { ++alreadyCorrectChainCounter; if (alreadyCorrectChainCounter >= 10) { Console.WriteLine("Processing Entry " + entryCounter + " of " + DatabaseEntries.Count); alreadyCorrectChainCounter = 0; } } } TransactionJ.Rollback(); TransactionE.Commit(); } } }
public static int Export(List <string> args) { if (args.Count < 2) { Console.WriteLine("Usage: db src"); return(-1); } string InDatabase = args[0]; string OutFile = args[1]; scr s = new scr(); List <GraceNoteDatabaseEntry> Entries = ReadDatabase("Data Source=" + InDatabase); // init loop stuff s.Sections = new List <scrSection>(); scrSection sec = new scrSection(); sec.Elements = new List <scrElement>(); sec.Location = (uint)Entries[0].PointerRef; sec.PointerIndex = Entries[0].IdentifyPointerRef; int SectionPointerIndex = sec.PointerIndex; for (int i = 0; i < Entries.Count; ++i) { GraceNoteDatabaseEntry e = Entries[i]; if (e.IdentifyPointerRef != SectionPointerIndex) { // reached new section, write old to scr s.Sections.Add(sec); sec = new scrSection(); sec.Elements = new List <scrElement>(); sec.Location = (uint)e.PointerRef; sec.PointerIndex = e.IdentifyPointerRef; SectionPointerIndex = sec.PointerIndex; } scrElement screlem = new scrElement(); switch (e.IdentifyString) { case "Code": screlem.Type = scrElement.scrElementType.Code; screlem.Code = CodeStringToArray(e.TextEN); break; case "Text": screlem.Type = scrElement.scrElementType.Text; screlem.Text = e.TextEN; break; default: throw new Exception("scrExport: Unknown IdentifyString type!"); } sec.Elements.Add(screlem); } s.Sections.Add(sec); s.CreateFile(OutFile); return(0); }
public static int Execute(List <string> args) { if (args.Count != 4) { Console.WriteLine("Usage: LuxPainEvt_GraceNote event.evt NewDBFile GracesJapanese event.jp.evt"); return(-1); } String Filename = args[0]; String NewDB = args[1]; String GracesDB = args[2]; String JapaneseFilename = args[3]; LuxPainEvt Evt; LuxPainEvt EvtJp; try { Evt = new LuxPainEvt(Filename); EvtJp = new LuxPainEvt(JapaneseFilename); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine("Failed loading text file!"); return(-1); } Evt.FormatTextForEditing(); EvtJp.FormatTextForEditing(); if (Evt.TextEntries.Count != EvtJp.TextEntries.Count) { Console.WriteLine("Entry count over languages doesn't match, padding..."); while (Evt.TextEntries.Count < EvtJp.TextEntries.Count) { LuxPainEvtText t = new LuxPainEvtText(); t.OffsetLocation = 0x7FFFFFFF; t.Text = "[Entry does not exist in this language, this is just for completion's sake.]"; Evt.TextEntries.Add(t); } while (Evt.TextEntries.Count > EvtJp.TextEntries.Count) { LuxPainEvtText t = new LuxPainEvtText(); t.OffsetLocation = 0x7FFFFFFF; t.Text = "[Entry does not exist in this language, this is just for completion's sake.]"; EvtJp.TextEntries.Add(t); } if (Evt.TextEntries.Count != EvtJp.TextEntries.Count) { throw new Exception("this shouldn't happen!"); } } Console.WriteLine("Found " + Evt.TextEntries.Count + " entries, importing..."); GraceNoteUtil.GenerateEmptyDatabase(NewDB); List <GraceNoteDatabaseEntry> Entries = new List <GraceNoteDatabaseEntry>(Evt.TextEntries.Count); for (int i = 0; i < Evt.TextEntries.Count; ++i) { // fetch GracesJapanese ID or generate new & insert new text String EnPlusJp = Evt.TextEntries[i].Text + "\n\n" + EvtJp.TextEntries[i].Text; GraceNoteDatabaseEntry gn = new GraceNoteDatabaseEntry(EnPlusJp, Evt.TextEntries[i].Text, "", 0, (int)Evt.TextEntries[i].OffsetLocation, "", 0); Entries.Add(gn); } GraceNoteDatabaseEntry.InsertSQL(Entries.ToArray(), "Data Source=" + NewDB, "Data Source=" + GracesDB); Console.WriteLine("Successfully imported entries!"); return(0); }
public static int Execute(List <string> args) { List <string> Game1_Databases = new List <string>(); List <string> Game2_Databases = new List <string>(); string Game1_GracesJapanese = null; string Game2_GracesJapanese = null; string DiffLogPath = null; string MatchLogPath = null; for (int i = 0; i < args.Count; ++i) { switch (args[i]) { case "-db1": Game1_Databases.Add(args[++i]); break; case "-db2": Game2_Databases.Add(args[++i]); break; case "-gj1": Game1_GracesJapanese = args[++i]; break; case "-gj2": Game2_GracesJapanese = args[++i]; break; case "-difflog": DiffLogPath = args[++i]; break; case "-matchlog": MatchLogPath = args[++i]; break; } } if (Game1_Databases.Count == 0 || Game2_Databases.Count == 0 || Game1_GracesJapanese == null || Game2_GracesJapanese == null) { Console.WriteLine("Tool to compare entries from two games."); Console.WriteLine("This can be used for checking consistency between e.g. multiple games in the same series."); Console.WriteLine(); Console.WriteLine("Usage:"); Console.WriteLine(" Required:"); Console.WriteLine(" -db1 path Add a database of Game 1. (can be used multiple times)"); Console.WriteLine(" -db2 path Add a database of Game 2. (can be used multiple times)"); Console.WriteLine(" -gj1 path GracesJapanese of Game 1."); Console.WriteLine(" -gj2 path GracesJapanese of Game 2."); Console.WriteLine(); Console.WriteLine(" Optional:"); Console.WriteLine(" -difflog path Log all entries where the Japanese matches, but the English does not."); Console.WriteLine(" -matchlog path Log all entries where the Japanese and English both match."); return(-1); } List <GraceNoteDatabaseEntry> Game1_Entries = new List <GraceNoteDatabaseEntry>(); List <GraceNoteDatabaseEntry> Game2_Entries = new List <GraceNoteDatabaseEntry>(); Stream DiffLogStream = null; StreamWriter DiffLogWriter = null; Stream MatchLogStream = null; StreamWriter MatchLogWriter = null; if (DiffLogPath != null) { DiffLogStream = new FileStream(DiffLogPath, FileMode.Append); } else { DiffLogStream = Stream.Null; } if (MatchLogPath != null) { MatchLogStream = new FileStream(MatchLogPath, FileMode.Append); } else { MatchLogStream = Stream.Null; } DiffLogWriter = new StreamWriter(DiffLogStream); MatchLogWriter = new StreamWriter(MatchLogStream); //DirectoryInfo di1 = new DirectoryInfo( @"e:\_\ToV\" ); //DirectoryInfo di2 = new DirectoryInfo( @"e:\_\ToX\" ); //foreach ( var x in di1.GetFiles() ) { // Game1_Databases.Add( x.FullName ); //} //foreach ( var x in di2.GetFiles() ) { // Game2_Databases.Add( x.FullName ); //} foreach (var db in Game1_Databases) { Game1_Entries.AddRange( GraceNoteDatabaseEntry.GetAllEntriesFromDatabase("Data Source=" + db, "Data Source=" + Game1_GracesJapanese) ); } foreach (var db in Game2_Databases) { Game2_Entries.AddRange( GraceNoteDatabaseEntry.GetAllEntriesFromDatabase("Data Source=" + db, "Data Source=" + Game2_GracesJapanese) ); } Regex VariableRemoveRegex = new Regex("<[^<>]+>"); Regex VesperiaFuriRemoveRegex = new Regex("\r[(][0-9]+[,][\\p{IsHiragana}\\p{IsKatakana}]+[)]"); foreach (var e1 in Game1_Entries) { string j1 = VesperiaFuriRemoveRegex.Replace(VariableRemoveRegex.Replace(e1.TextJP, ""), ""); foreach (var e2 in Game2_Entries) { string j2 = VariableRemoveRegex.Replace(e2.TextJP, ""); if (j1 == j2) { if (e1.TextEN != e2.TextEN) { DiffLogWriter.WriteLine(j1); DiffLogWriter.WriteLine(e1.Database + "/" + e1.ID + ": " + e1.TextEN); DiffLogWriter.WriteLine(e2.Database + "/" + e2.ID + ": " + e2.TextEN); DiffLogWriter.WriteLine(); DiffLogWriter.WriteLine("------------------------------------------------------"); DiffLogWriter.WriteLine(); } else { MatchLogWriter.WriteLine(j1); MatchLogWriter.WriteLine(e1.Database + "/" + e1.ID + ": " + e1.TextEN); MatchLogWriter.WriteLine(e2.Database + "/" + e2.ID + ": " + e2.TextEN); MatchLogWriter.WriteLine(); MatchLogWriter.WriteLine("------------------------------------------------------"); MatchLogWriter.WriteLine(); SqliteUtil.Update(e1.Database, "UPDATE Text SET updated = 1, status = 4 WHERE ID = " + e1.ID); } } } } MatchLogWriter.Close(); MatchLogStream.Close(); DiffLogWriter.Close(); DiffLogStream.Close(); return(0); }
public static void FindEarliestGracesJapaneseEntry( String ConnectionString, String GracesJapaneseConnectionString ) { using ( SQLiteConnection ConnectionE = new SQLiteConnection( ConnectionString ) ) using ( SQLiteConnection ConnectionJ = new SQLiteConnection( GracesJapaneseConnectionString ) ) { ConnectionE.Open(); ConnectionJ.Open(); using ( SQLiteTransaction TransactionE = ConnectionE.BeginTransaction() ) using ( SQLiteTransaction TransactionJ = ConnectionJ.BeginTransaction() ) using ( SQLiteCommand CommandEFetch = new SQLiteCommand( ConnectionE ) ) using ( SQLiteCommand CommandEUpdate = new SQLiteCommand( ConnectionE ) ) using ( SQLiteCommand CommandJ = new SQLiteCommand( ConnectionJ ) ) { // fetch, from the individual game file Database, all IDs and corresponding GracesJapanese StringIDs CommandEFetch.CommandText = "SELECT ID, StringID FROM Text ORDER BY ID"; SQLiteDataReader r = CommandEFetch.ExecuteReader(); List<GraceNoteDatabaseEntry> DatabaseEntries = new List<GraceNoteDatabaseEntry>(); while ( r.Read() ) { int ID = r.GetInt32( 0 ); int StringID = r.GetInt32( 1 ); var gn = new GraceNoteDatabaseEntry(); gn.ID = ID; gn.JPID = StringID; DatabaseEntries.Add( gn ); } r.Close(); CommandJ.CommandText = "PRAGMA case_sensitive_like = ON"; int affected = CommandJ.ExecuteNonQuery(); // This finds all entries in GracesJapanese that have the same Japanese text as the current game file DB entry CommandJ.CommandText = "SELECT ID FROM Japanese WHERE CAST(string AS BLOB) = " + "( SELECT CAST(string AS BLOB) FROM Japanese WHERE ID = ? ) ORDER BY ID ASC"; SQLiteParameter ParamJId = new SQLiteParameter(); CommandJ.Parameters.Add( ParamJId ); // This updates the game file DB with the new StringID CommandEUpdate.CommandText = "UPDATE Text SET StringID = ? WHERE ID = ?"; SQLiteParameter ParamEStringId = new SQLiteParameter(); SQLiteParameter ParamEId = new SQLiteParameter(); CommandEUpdate.Parameters.Add( ParamEStringId ); CommandEUpdate.Parameters.Add( ParamEId ); int entryCounter = 0; int alreadyCorrectChainCounter = 0; foreach ( var e in DatabaseEntries ) { ++entryCounter; // get the lowest StringID ParamJId.Value = e.JPID; int? EarliestStringId = (int?)CommandJ.ExecuteScalar(); // and put it into the game file DB, if needed if ( EarliestStringId != null && EarliestStringId != e.JPID ) { alreadyCorrectChainCounter = 0; Console.WriteLine( "Changing Entry #" + e.ID + " from StringID " + e.JPID + " to " + EarliestStringId ); ParamEId.Value = e.ID; ParamEStringId.Value = EarliestStringId; CommandEUpdate.ExecuteNonQuery(); } else { ++alreadyCorrectChainCounter; if ( alreadyCorrectChainCounter >= 10 ) { Console.WriteLine( "Processing Entry " + entryCounter + " of " + DatabaseEntries.Count ); alreadyCorrectChainCounter = 0; } } } TransactionJ.Rollback(); TransactionE.Commit(); } } }