private bool LoadFile( byte[] Bytes ) { int TextAmount = BitConverter.ToInt32( Bytes, 0 ); if ( TextAmount == 0 ) { Console.WriteLine( "No text found!" ); return false; } TextList = new List<PakTextEntry>( TextAmount ); // sanity check: After EOF no further bytes int ProjectedEnd = BitConverter.ToInt32( Bytes, ( TextAmount + 1 ) * 4 ); if ( ProjectedEnd == 0 ) { ProjectedEnd = Bytes.Length; } // again, someone forgot to set the end pointer //ProjectedEnd = Util.AlignToByteBoundary(ProjectedEnd, 4); for ( int i = ProjectedEnd; i < Bytes.Length; ++i ) { if ( Bytes[i] != 0x00 ) { Console.WriteLine( "Found bytes after calculated EOF!" ); return false; } } for ( int i = 1; i <= TextAmount; i++ ) { PakTextEntry e = new PakTextEntry(); e.OffsetLocation = i * 4; e.Offset = BitConverter.ToInt32( Bytes, e.OffsetLocation ); int NextOffset = BitConverter.ToInt32( Bytes, e.OffsetLocation + 4 ); if ( i == TextAmount ) { NextOffset = Bytes.Length; } // grr e.Text = Encoding.Unicode.GetString( Bytes, e.Offset, NextOffset - e.Offset ); TextList.Add( e ); } return true; }
public void GetSQL( String ConnectionString ) { SQLiteConnection Connection = new SQLiteConnection( ConnectionString ); Connection.Open(); TextList = new List<PakTextEntry>(); using ( SQLiteTransaction Transaction = Connection.BeginTransaction() ) using ( SQLiteCommand Command = new SQLiteCommand( Connection ) ) { Command.CommandText = "SELECT english, PointerRef FROM Text ORDER BY PointerRef"; SQLiteDataReader r = Command.ExecuteReader(); while ( r.Read() ) { String SQLText; try { SQLText = r.GetString( 0 ).Replace( "''", "'" ); } catch ( System.InvalidCastException ) { SQLText = ""; } int PointerRef = r.GetInt32( 1 ); PakTextEntry d = new PakTextEntry(); d.OffsetLocation = PointerRef; d.Text = SQLText; d.Offset = -1; TextList.Add( d ); } Transaction.Rollback(); } return; }