public void ClientCanExcecuteCommands() { var commands = new[] { new Command{ Trigger = "makeown", Actions = new [] { "r pcbuffer[0].originaltrainerid", "w team[1].originaltrainerid {}", "r pcbuffer[0].gameoforigin", "w team[1].gameoforigin {}", "r pcbuffer[0].originaltrainergender", "w team[1].originaltrainergender {}", "r pcbuffer[0].originaltrainername", "w team[1].originaltrainername {}" } } }; _c = new SimpleCommandLineClient( new InjectionQueueCommunicator( _com ), new CommandHandler( commands ) ); var sf = new SaveFile( "p2.sav" ); Assert.AreNotEqual( sf.Latest.PcBuffer[0].OriginalTrainerName, sf.Latest.Team[1].OriginalTrainerName ); Assert.AreNotEqual( sf.Latest.PcBuffer[0].OriginalTrainerGender, sf.Latest.Team[1].OriginalTrainerGender ); Assert.AreNotEqual( sf.Latest.PcBuffer[0].OriginalTrainerId, sf.Latest.Team[1].OriginalTrainerId ); Assert.AreNotEqual( sf.Latest.PcBuffer[0].GameOfOrigin, sf.Latest.Team[1].GameOfOrigin ); Load( new[] { "ld p2.sav", "c makeown", "st " + Outfile, "q" } ); _c.Run( null ); var sf2 = new SaveFile( Outfile ); Assert.AreEqual( sf2.Latest.PcBuffer[0].OriginalTrainerName, sf2.Latest.Team[1].OriginalTrainerName ); Assert.AreEqual( sf2.Latest.PcBuffer[0].OriginalTrainerGender, sf2.Latest.Team[1].OriginalTrainerGender ); Assert.AreEqual( sf2.Latest.PcBuffer[0].OriginalTrainerId, sf2.Latest.Team[1].OriginalTrainerId ); Assert.AreEqual( sf2.Latest.PcBuffer[0].GameOfOrigin, sf2.Latest.Team[1].GameOfOrigin ); }
public SimpleCommandLineClient( InjectionQueueCommunicator com, CommandHandler commandsfile ) { _com = com; _current = null; _parser = new CommandLineParser(); _handler = commandsfile; }
public void AfterSaveFileHasSameSize() { var f = new SaveFile( "p.sav" ); f.Save( "tmp.sav" ); Assert.AreEqual( new FileInfo( "p.sav" ).Length, new FileInfo( "tmp.sav" ).Length ); }
public PropertyCarrier GetPropertyForString( SaveFile savefile, string line ) { var commandchain = ExtractCommands( line ); var current = new PropertyCarrier() { Parent = savefile }; foreach( var command in commandchain ) { SetCurrentParentFromProperty( current ); var t = current.Parent.GetType(); var match = ExtractIndex.Match( command ); var propertyname = command; if( match.Success ) { propertyname = match.Groups["property"].Captures[0].Value; var indexstring = match.Groups["index"].Captures[0].Value; int index = Int32.Parse( indexstring ); current.Index = index; } else current.Index = null; current.Property = t.GetProperty( propertyname, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance ); if( current.Property == null ) { current.Error = "Not valid property"; return current; } } return current; }
public string List( SaveFile sf, string line ) { var carry = GetPropertyForString( sf, line ); if( !string.IsNullOrEmpty( carry.Error ) ) return carry.Error; if( carry.Property == null ) return ConstructPropertyListFromType( carry.Parent.GetType() ); if( carry.Property.PropertyType.IsGenericType && carry.Property.PropertyType.GetGenericTypeDefinition() == typeof( BindingList<> ) ) return ConstructPropertyListFromType( carry.Property.PropertyType.GetGenericArguments()[0] ); if( carry.Property.PropertyType.IsEnum ) return ConstructEnumValuesList( carry.Property.PropertyType ); return ConstructPropertyListFromType( carry.Property.PropertyType ); }
void Add( string path ) { if( !File.Exists( path ) ) return; if( _controller.OpenFiles.Any( f => f.Path == path ) ) return; var data = File.ReadAllBytes( path ); if( FileTypeDetector.IsGen3SaveFile( data ) ) { var file = new SaveFile( data, path ); var fileinfo = new FileInfo( path ); _controller.OpenFiles.Add( new OpenFile( file ) { Path = path, Type = FileType.Gen3Save, Label = fileinfo.Name } ); } else { var entries = FileTypeDetector.Open( data ); if( entries != null ) { foreach( var entry in entries ) { var existing = _controller.OpenFiles.Where( f => f.Type == FileType.PKM ).ToList(); var md5 = CalculateMD5Hash( entry.RawData ); if( existing.All( e => e.Path != md5 ) ) { _controller.OpenFiles.Add( new OpenFile( entry ) { Path = md5, Label = entry.TypeName + entry.Name, Type = FileType.PKM } ); } } } } }
public void ClientCanSaveLastValue() { var init = new SaveFile( "p.sav" ); Assert.AreNotEqual( init.Latest.TrainerId, init.Latest.Team[1].OriginalTrainerId ); Load( new[] { "ld p.sav", "r trainerid", "w team[1].originaltrainerid {}", "st " + Outfile, "q" } ); _c.Run( null ); var sf = new SaveFile( Outfile ); Assert.AreEqual( sf.Latest.TrainerId, sf.Latest.Team[1].OriginalTrainerId ); }
public void TeamHasStatusAndPP() { _file = new SaveFile( "p4.sav" ); Debug.WriteLine( _file.Latest.Team[0].Full() ); Assert.IsTrue( _file.Latest.Team[0].Poisoned ); Assert.AreEqual( 28, _file.Latest.Team[0].PP1 ); }
public void TeamCorrectMoveName() { _file = new SaveFile( "p4.sav" ); Assert.AreEqual( "Thundershock", _file.Latest.Team[0].Move1Name ); }
public void Setup() { _file = new SaveFile( "p.sav" ); Debug.WriteLine( _file ); }
public void MakeTeamShinyAndSaveFile() { foreach( var p in _file.Latest.Team ) { if( !p.Empty ) { Assert.AreEqual( p.Checksum, p.CalculatedChecksum ); var engine = new PersonalityEngine() { OriginalTrainer = p.OriginalTrainerId }; p.SetPersonality( engine ); Assert.AreEqual( p.Checksum, p.CalculatedChecksum ); p.Item = 1; Assert.AreNotEqual( p.Checksum, p.CalculatedChecksum ); } } _file.Save( "outtmp.sav" ); var f2 = new SaveFile( "outtmp.sav" ); foreach( var p in f2.Latest.Team ) { if( !p.Empty ) { Assert.IsTrue( p.Shiny ); } } }
void LoadFile( string input ) { string name = input.Substring( 2 ).Trim(); if( !File.Exists( name ) ) _com.WriteLine( "No such file" ); else if( new FileInfo( name ).Length != 128 * 1024 ) _com.WriteLine( "File has wrong size" ); else { _current = new SaveFile( name ); if( !_current.A.Valid ) _com.WriteLine( "Warning, game save A not valid" ); if( !_current.B.Valid ) _com.WriteLine( "Warning, game save B not valid" ); } }
public string Write( SaveFile sf, string line ) { var parts = line.Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries ); if( parts.Length < 2 ) return "not enough arguments"; object value = parts[1]; var carry = GetPropertyForString( sf, parts[0] ); if( !string.IsNullOrEmpty( carry.Error ) ) return carry.Error; if( carry.Property == null ) return "you cant set root property"; if( !carry.Property.CanWrite ) return "property is readonly"; var propertyType = carry.Property.PropertyType; if( carry.Property.PropertyType.IsGenericType && carry.Property.PropertyType.GetGenericTypeDefinition() == typeof( BindingList<> ) ) return "you cant set array"; try { if( propertyType == typeof( uint ) ) value = UInt32.Parse( (string) value ); else if( propertyType == typeof( bool ) ) value = Boolean.Parse( (string) value ); else if( propertyType.IsEnum ) value = Enum.IsDefined( propertyType, value ) ? Enum.Parse( propertyType, (string) value, true ) : Enum.ToObject( propertyType, UInt32.Parse( (string) value ) ); carry.Property.SetValue( carry.Parent, value, null ); return "OK, set " + value; } catch( FormatException ) { return "bad argument value"; } catch( ArgumentException ) { return "bad argument value"; } }
public string Read( SaveFile sf, string line ) { var carry = GetPropertyForString( sf, line ); if( !string.IsNullOrEmpty( carry.Error ) ) return carry.Error; if( carry.Property == null ) return carry.Parent.ToString(); var target = carry.Property.GetValue( carry.Parent, null ); if( !( target is IList ) ) return target.ToString(); if( carry.Index != null ) return ( (IList) target )[carry.Index.Value].ToString(); var sb = new StringBuilder(); foreach( var entry in (IList) target ) sb.AppendLine( entry.ToString() ); sb.AppendLine( "index into array using []" ); return sb.ToString(); }
public void Setup() { _c = new CommandLineParser(); _sf = new SaveFile( "p.sav" ); _sf.A.Name = "RED2"; _sf.B.Name = "RED3"; }