namespace fx.meta.bgi.util { public sealed class ExtractText { public static void Main( string[ ] args ) { if ( args.Length < 1 ) { Console.WriteLine( "Give a valid script file as the first parameter." ); return; }
FileInfo infile = new FileInfo( infilename ); if ( !infile.Exists ) { Console.WriteLine( "Give a valid script file as the first parameter." ); return; }
long filelen = infile.Length;
// read all the text and write to output Encoding utf16le = new UnicodeEncoding( false, true ); Encoding jis = Encoding.GetEncoding( 932 ); using ( BinaryReader reader = new BinaryReader( infile.OpenRead( ), jis ) ) { using ( BinaryWriter writer = new BinaryWriter( File.Create( outfilename ), utf16le ) ) {
if ( opcode != 0x07F ) { throw new Exception( "Unsupported script. Expecting 0x7F at 0x20, but found " + opcode.ToString( "X" ) ); } if ( codeSize > filelen ) { throw new Exception( "Bad script. Code size greater than file size." ); }
writer.Write( ( ushort ) 0xFEFF ); reader.BaseStream.Seek( ( long ) codeSize, SeekOrigin.Begin ); StringBuilder builder = null; while ( reader.BaseStream.Position < reader.BaseStream.Length ) { string position = reader.BaseStream.Position.ToString( "X" ); builder = new StringBuilder( ); char c = '\0'; while ( ( c = reader.ReadChar( ) ) != '\0' ) { if ( c == '\n' ) { builder.Append( @"\n" ); } else { builder.Append( c ); } } string text = builder.ToString( ); string strlen = jis.GetByteCount( text ).ToString( ); writer.Write( utf16le.GetBytes( string.Format( "{0}, {1}, {2}{3}", position, strlen, text, Environment.NewLine ) ) ); } } } } } }
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Text;
namespace fx.meta.bgi.util { public sealed class InsertText { public static void Main( string[ ] args ) {
if ( args.Length < 1 ) { Console.WriteLine( "Give a valid script file as the first parameter." ); return; }
FileInfo scriptFile = new FileInfo( scriptName ); if ( !scriptFile.Exists ) { Console.WriteLine( "Give a valid script file as the first parameter." ); return; } if ( !File.Exists( textName ) ) { Console.WriteLine( "Correspoding text file not available." ); return; }
long filelen = scriptFile.Length;
// read all the text and write to output Encoding utf16le = new UnicodeEncoding( false, true ); Encoding jis = Encoding.GetEncoding( 932 ); Encoding gbk = Encoding.GetEncoding( 936 ); using ( BinaryReader script = new BinaryReader( scriptFile.OpenRead( ), jis ) ) { using ( StreamReader text = new StreamReader( File.OpenRead( textName ), utf16le ) ) { using ( BinaryWriter writer = new BinaryWriter( File.Create( newScriptName ), gbk ) ) {
Dictionary<uint, uint> offsetMapping = new Dictionary<uint, uint>( ); List<string> newTexts = new List<string>( ); int offsetDifference = 0;
if ( opcode != 0x07F ) { throw new Exception( "Unsupported script. Expecting 0x7F at 0x20, but found " + opcode.ToString( "X" ) ); } if ( codeSize > filelen ) { throw new Exception( "Bad script. Code size greater than file size." ); }
uint currentOffset = codeSize; string line = text.ReadLine( ); while ( line != null && !line.Equals( string.Empty ) ) {