first commit

This commit is contained in:
Beyhan Oğur
2026-09-03 04:45:36 +03:00
commit d5f52cc3d3
1038 changed files with 169579 additions and 0 deletions
+524
View File
@@ -0,0 +1,524 @@
//TODO
//using System.Collections.Generic;
//using System.Collections.ObjectModel;
//using System.Diagnostics;
//using System.IO;
//using System.Linq;
//using System.Threading;
//using Assistant;
//using ClassicAssist.Data.Autoloot;
//using ClassicAssist.UO.Data;
//using ClassicAssist.UO.Network;
//using ClassicAssist.UO.Network.PacketFilter;
//using ClassicAssist.UO.Objects;
//using Microsoft.VisualStudio.TestTools.UnitTesting;
//namespace ClassicAssist.Tests.Agents
//{
// [TestClass]
// public class AutolootTests
// {
// [TestMethod]
// public void WillRehueMatchingItemProperties()
// {
// const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";
// if ( !Directory.Exists( localPath ) )
// {
// Debug.WriteLine( "Not running test, requires Cliloc.enu" );
// return;
// }
// Cliloc.Initialize( localPath );
// Item corpse = new Item( 0x40000000 ) { ID = 0x2006 };
// Engine.Items.Add( corpse );
// IncomingPacketHandlers.Initialize();
// AutolootViewModel vm = new AutolootViewModel { Enabled = true };
// AutolootEntry lootEntry = new AutolootEntry
// {
// Rehue = true,
// Autoloot = false,
// Constraints = new ObservableCollection<AutolootConstraintEntry>(),
// ID = 0x108a
// };
// AutolootConstraintEntry constraintEntry = new AutolootConstraintEntry
// {
// Property = vm.Constraints.FirstOrDefault( c => c.Name == "Faster Casting" ),
// Operator = AutolootOperator.GreaterThan,
// Value = 1
// };
// lootEntry.Constraints.Add( constraintEntry );
// vm.Items.Add( lootEntry );
// Engine.PacketWaitEntries = new PacketWaitEntries();
// AutoResetEvent are = new AutoResetEvent( false );
// void OnPacketReceivedEvent( byte[] data, int length )
// {
// if ( data[0] == 0x25 )
// {
// are.Set();
// }
// else
// {
// Assert.Fail();
// }
// }
// Engine.InternalPacketReceivedEvent += OnPacketReceivedEvent;
// Engine.PacketWaitEntries.WaitEntryAddedEvent += entry =>
// {
// byte[] containerContentsPacket =
// {
// 0x3C, 0x00, 0x19, 0x00, 0x01, 0x43, 0x13, 0xFC, 0x5E, 0x10, 0x8A, 0x00, 0x00, 0x01, 0x00, 0x13,
// 0x00, 0x82, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00
// };
// PacketHandler handler = IncomingPacketHandlers.GetHandler( 0x3C );
// handler.OnReceive( new PacketReader( containerContentsPacket, containerContentsPacket.Length, false ) );
// entry.Packet = containerContentsPacket;
// entry.Lock.Set();
// byte[] propertiesPacket =
// {
// 0xD6, 0x00, 0x53, 0x00, 0x01, 0x43, 0x13, 0xFC, 0x5E, 0x00, 0x00, 0x01, 0x6E, 0x08, 0xB4, 0x00,
// 0x0F, 0xA0, 0xEA, 0x00, 0x00, 0x00, 0x10, 0x5E, 0x94, 0x00, 0x02, 0x31, 0x00, 0x00, 0x10, 0x2E,
// 0x64, 0x00, 0x14, 0x23, 0x00, 0x31, 0x00, 0x30, 0x00, 0x34, 0x00, 0x34, 0x00, 0x30, 0x00, 0x38,
// 0x00, 0x35, 0x00, 0x09, 0x00, 0x39, 0x00, 0x00, 0x10, 0x2E, 0x3C, 0x00, 0x02, 0x32, 0x00, 0x00,
// 0x10, 0x2E, 0x3D, 0x00, 0x02, 0x31, 0x00, 0x00, 0x10, 0x2E, 0x83, 0x00, 0x02, 0x34, 0x00, 0x00,
// 0x00, 0x00, 0x00
// };
// handler = IncomingPacketHandlers.GetHandler( 0xD6 );
// handler.OnReceive( new PacketReader( propertiesPacket, propertiesPacket.Length, false ) );
// };
// vm.OnCorpseEvent( corpse.Serial );
// bool result = are.WaitOne( 5000 );
// Assert.IsTrue( result );
// Engine.Items.Clear();
// Engine.PacketWaitEntries = null;
// Engine.InternalPacketReceivedEvent -= OnPacketReceivedEvent;
// }
// [TestMethod]
// public void WillRehueMatchingObjectProperties()
// {
// Item corpse = new Item( 0x40000000 ) { ID = 0x2006 };
// Engine.Items.Add( corpse );
// IncomingPacketHandlers.Initialize();
// AutolootViewModel vm = new AutolootViewModel { Enabled = true };
// AutolootEntry lootEntry = new AutolootEntry
// {
// Rehue = true,
// Autoloot = false,
// Constraints = new ObservableCollection<AutolootConstraintEntry>(),
// ID = 0x108a
// };
// AutolootConstraintEntry autolootConstraint = new AutolootConstraintEntry
// {
// Property = vm.Constraints.FirstOrDefault( c => c.Name == "Hue" ),
// Operator = AutolootOperator.Equal,
// Value = 0
// };
// lootEntry.Constraints.Add( autolootConstraint );
// vm.Items.Add( lootEntry );
// Engine.PacketWaitEntries = new PacketWaitEntries();
// AutoResetEvent are = new AutoResetEvent( false );
// void OnPacketReceivedEvent( byte[] data, int length )
// {
// if ( data[0] == 0x25 )
// {
// are.Set();
// }
// else
// {
// Assert.Fail();
// }
// }
// Engine.InternalPacketReceivedEvent += OnPacketReceivedEvent;
// Engine.PacketWaitEntries.WaitEntryAddedEvent += entry =>
// {
// byte[] containerContentsPacket =
// {
// 0x3C, 0x00, 0x19, 0x00, 0x01, 0x43, 0x13, 0xFC, 0x5E, 0x10, 0x8A, 0x00, 0x00, 0x01, 0x00, 0x13,
// 0x00, 0x82, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00
// };
// PacketHandler handler = IncomingPacketHandlers.GetHandler( 0x3C );
// handler.OnReceive( new PacketReader( containerContentsPacket, containerContentsPacket.Length, false ) );
// entry.Packet = containerContentsPacket;
// entry.Lock.Set();
// };
// vm.OnCorpseEvent( corpse.Serial );
// bool result = are.WaitOne( 5000 );
// Assert.IsTrue( result );
// Engine.Items.Clear();
// Engine.PacketWaitEntries = null;
// Engine.InternalPacketReceivedEvent -= OnPacketReceivedEvent;
// }
// [TestMethod]
// public void WillLootMatchingObjectProperties()
// {
// const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";
// if ( !Directory.Exists( localPath ) )
// {
// Debug.WriteLine( "Not running test, requires Cliloc.enu" );
// return;
// }
// TileData.Initialize( localPath );
// Engine.Player = new PlayerMobile( 0x01 );
// Item backpack = new Item( 0x40000001, 0x01 ) { Container = new ItemCollection( 0x40000001 ) };
// Engine.Player.SetLayer( Layer.Backpack, backpack.Serial );
// Engine.Items.Add( backpack );
// Item corpse = new Item( 0x40000000 ) { ID = 0x2006 };
// Engine.Items.Add( corpse );
// IncomingPacketHandlers.Initialize();
// AutolootViewModel vm = new AutolootViewModel { Enabled = true };
// AutolootEntry lootEntry = new AutolootEntry
// {
// Rehue = false,
// Autoloot = true,
// Constraints = new ObservableCollection<AutolootConstraintEntry>(),
// ID = 0x108a
// };
// AutolootConstraintEntry autolootConstraint = new AutolootConstraintEntry
// {
// Property = vm.Constraints.FirstOrDefault( c => c.Name == "ID" ),
// Operator = AutolootOperator.Equal,
// Value = 0x108a
// };
// lootEntry.Constraints.Add( autolootConstraint );
// vm.Items.Add( lootEntry );
// Engine.PacketWaitEntries = new PacketWaitEntries();
// AutoResetEvent are = new AutoResetEvent( false );
// void OnPacketSentEvent( byte[] data, int length )
// {
// if ( data[0] == 0x07 || data[0] == 0x08 )
// {
// are.Set();
// }
// else if ( data[0] == 0xD6 || data[0] == 0x06 )
// {
// }
// else
// {
// Assert.Fail();
// }
// }
// Engine.InternalPacketSentEvent += OnPacketSentEvent;
// Engine.PacketWaitEntries.WaitEntryAddedEvent += entry =>
// {
// byte[] containerContentsPacket =
// {
// 0x3C, 0x00, 0x19, 0x00, 0x01, 0x43, 0x13, 0xFC, 0x5E, 0x10, 0x8A, 0x00, 0x00, 0x01, 0x00, 0x13,
// 0x00, 0x82, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x64
// };
// PacketHandler handler = IncomingPacketHandlers.GetHandler( 0x3C );
// handler.OnReceive( new PacketReader( containerContentsPacket, containerContentsPacket.Length, false ) );
// entry.Packet = containerContentsPacket;
// entry.Lock.Set();
// };
// vm.OnCorpseEvent( corpse.Serial );
// bool result = are.WaitOne( 5000 );
// Assert.IsTrue( result );
// Engine.Items.Clear();
// Engine.PacketWaitEntries = null;
// Engine.InternalPacketSentEvent -= OnPacketSentEvent;
// Engine.Player = null;
// }
// [TestMethod]
// public void WontLootDisabledInGuardzone()
// {
// const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";
// if ( !Directory.Exists( localPath ) )
// {
// Debug.WriteLine( "Not running test, requires Cliloc.enu" );
// return;
// }
// TileData.Initialize( localPath );
// Engine.Player = new PlayerMobile( 0x01 ) { X = 652, Y = 869 };
// Item backpack = new Item( 0x40000001, 0x01 ) { Container = new ItemCollection( 0x40000001 ) };
// Engine.Player.SetLayer( Layer.Backpack, backpack.Serial );
// Engine.Items.Add( backpack );
// Item corpse = new Item( 0x40000000 ) { ID = 0x2006 };
// Engine.Items.Add( corpse );
// IncomingPacketHandlers.Initialize();
// AutolootViewModel vm = new AutolootViewModel { Enabled = true, DisableInGuardzone = true };
// AutolootEntry lootEntry = new AutolootEntry
// {
// Rehue = false,
// Autoloot = true,
// Constraints = new ObservableCollection<AutolootConstraintEntry>(),
// ID = 0x108a
// };
// AutolootConstraintEntry autolootConstraint = new AutolootConstraintEntry
// {
// Property = vm.Constraints.FirstOrDefault( c => c.Name == "Hue" ),
// Operator = AutolootOperator.Equal,
// Value = 0
// };
// lootEntry.Constraints.Add( autolootConstraint );
// vm.Items.Add( lootEntry );
// Engine.PacketWaitEntries = new PacketWaitEntries();
// void OnPacketSentEvent( byte[] data, int length )
// {
// if ( data[0] == 0xD6 || data[0] == 0x06 )
// {
// return;
// }
// Assert.Fail();
// }
// Engine.InternalPacketSentEvent += OnPacketSentEvent;
// Engine.PacketWaitEntries.WaitEntryAddedEvent += entry =>
// {
// byte[] containerContentsPacket =
// {
// 0x3C, 0x00, 0x19, 0x00, 0x01, 0x43, 0x13, 0xFC, 0x5E, 0x10, 0x8A, 0x00, 0x00, 0x01, 0x00, 0x13,
// 0x00, 0x82, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00
// };
// PacketHandler handler = IncomingPacketHandlers.GetHandler( 0x3C );
// handler.OnReceive( new PacketReader( containerContentsPacket, containerContentsPacket.Length, false ) );
// entry.Packet = containerContentsPacket;
// entry.Lock.Set();
// };
// vm.OnCorpseEvent( corpse.Serial );
// Engine.Items.Clear();
// Engine.PacketWaitEntries = null;
// Engine.InternalPacketSentEvent -= OnPacketSentEvent;
// Engine.Player = null;
// }
// [TestMethod]
// public void WontRehueNotEnabledEntry()
// {
// Item corpse = new Item( 0x40000000 ) { ID = 0x2006 };
// Engine.Items.Add( corpse );
// IncomingPacketHandlers.Initialize();
// AutolootViewModel vm = new AutolootViewModel { Enabled = true };
// AutolootEntry lootEntry = new AutolootEntry
// {
// Rehue = true,
// Autoloot = false,
// Constraints = new ObservableCollection<AutolootConstraintEntry>(),
// ID = 0x108a,
// Enabled = false
// };
// vm.Items.Add( lootEntry );
// Engine.PacketWaitEntries = new PacketWaitEntries();
// void OnPacketReceivedEvent( byte[] data, int length )
// {
// Assert.Fail();
// }
// Engine.InternalPacketReceivedEvent += OnPacketReceivedEvent;
// Engine.PacketWaitEntries.WaitEntryAddedEvent += entry =>
// {
// byte[] containerContentsPacket =
// {
// 0x3C, 0x00, 0x19, 0x00, 0x01, 0x43, 0x13, 0xFC, 0x5E, 0x10, 0x8A, 0x00, 0x00, 0x01, 0x00, 0x13,
// 0x00, 0x82, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00
// };
// PacketHandler handler = IncomingPacketHandlers.GetHandler( 0x3C );
// handler.OnReceive( new PacketReader( containerContentsPacket, containerContentsPacket.Length, false ) );
// entry.Packet = containerContentsPacket;
// entry.Lock.Set();
// };
// vm.OnCorpseEvent( corpse.Serial );
// Engine.Items.Clear();
// Engine.PacketWaitEntries = null;
// Engine.InternalPacketReceivedEvent -= OnPacketReceivedEvent;
// }
// [TestMethod]
// public void WontRehueNotEnabled()
// {
// Item corpse = new Item( 0x40000000 ) { ID = 0x2006 };
// Engine.Items.Add( corpse );
// IncomingPacketHandlers.Initialize();
// AutolootViewModel vm = new AutolootViewModel { Enabled = true };
// AutolootEntry lootEntry = new AutolootEntry
// {
// Rehue = true,
// Autoloot = false,
// Constraints = new ObservableCollection<AutolootConstraintEntry>(),
// ID = 0x108a,
// Enabled = true
// };
// vm.Items.Add( lootEntry );
// vm.Enabled = false;
// Engine.PacketWaitEntries = new PacketWaitEntries();
// void OnPacketReceivedEvent( byte[] data, int length )
// {
// Assert.Fail();
// }
// Engine.InternalPacketReceivedEvent += OnPacketReceivedEvent;
// Engine.PacketWaitEntries.WaitEntryAddedEvent += entry =>
// {
// byte[] containerContentsPacket =
// {
// 0x3C, 0x00, 0x19, 0x00, 0x01, 0x43, 0x13, 0xFC, 0x5E, 0x10, 0x8A, 0x00, 0x00, 0x01, 0x00, 0x13,
// 0x00, 0x82, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00
// };
// PacketHandler handler = IncomingPacketHandlers.GetHandler( 0x3C );
// handler.OnReceive( new PacketReader( containerContentsPacket, containerContentsPacket.Length, false ) );
// entry.Packet = containerContentsPacket;
// entry.Lock.Set();
// };
// vm.OnCorpseEvent( corpse.Serial );
// Engine.Items.Clear();
// Engine.PacketWaitEntries = null;
// Engine.InternalPacketReceivedEvent -= OnPacketReceivedEvent;
// }
// [TestMethod]
// public void WontMatchNotIncluded()
// {
// PropertyEntry property1 = new PropertyEntry { ClilocIndex = -1, Clilocs = new[] { 1 }, Name = "Test" };
// PropertyEntry property2 = new PropertyEntry { ClilocIndex = -1, Clilocs = new[] { 2 }, Name = "Test 2" };
// ItemCollection container = new ItemCollection( 2 )
// {
// new Item( 1 ) { Properties = new[] { new Property { Cliloc = 1, Text = "Test" } } }
// };
// AutolootEntry filter = new AutolootEntry
// {
// Constraints = new ObservableCollection<AutolootConstraintEntry>
// {
// new AutolootConstraintEntry
// {
// Operator = AutolootOperator.Equal, Property = property1, Value = 0
// }
// }
// };
// IEnumerable<Item> matchItems = AutolootHelpers.AutolootFilter( container.GetItems(), filter );
// Assert.IsTrue( matchItems.Any() );
// container.Clear();
// container.Add( new Item( 3 )
// {
// Properties = new[]
// {
// new Property { Cliloc = 1, Text = "Test" }, new Property { Cliloc = 2, Text = "Test 2" }
// }
// } );
// filter.Constraints.Add( new AutolootConstraintEntry
// {
// Operator = AutolootOperator.NotPresent, Property = property2, Value = 0
// } );
// matchItems = AutolootHelpers.AutolootFilter( container.GetItems(), filter );
// Assert.IsTrue( !matchItems.Any() );
// Engine.Items.Clear();
// }
// [TestCleanup]
// public void Cleanup()
// {
// ActionPacketQueue.Clear();
// }
// }
//}
+205
View File
@@ -0,0 +1,205 @@
#region License
// Copyright (C) 2020 Reetus
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#endregion
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using ClassicAssist.Shared;
using ClassicAssist.Data.Vendors;
using ClassicAssist.UO.Data;
using ClassicAssist.UO.Network;
using ClassicAssist.UO.Objects;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ClassicAssist.Tests.Agents
{
[TestClass]
public class BuyAgentTests
{
[TestMethod]
public void WillBuyCorrectAmount()
{
int vendorSerial = 0x0b0354;
byte[] shopList =
{
0x74, 0x01, 0x67, 0x42, 0x0C, 0x82, 0x83, 0x1B, 0x00, 0x00, 0x00, 0x12, 0x08, 0x31, 0x30, 0x32,
0x33, 0x38, 0x33, 0x34, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x31, 0x30, 0x32, 0x34, 0x30, 0x33,
0x31, 0x00, 0x00, 0x00, 0x00, 0x05, 0x08, 0x31, 0x30, 0x32, 0x33, 0x38, 0x32, 0x37, 0x00, 0x00,
0x00, 0x00, 0x0B, 0x08, 0x31, 0x30, 0x34, 0x31, 0x30, 0x37, 0x32, 0x00, 0x00, 0x00, 0x00, 0x0F,
0x08, 0x31, 0x30, 0x32, 0x37, 0x39, 0x35, 0x36, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x08, 0x31, 0x30,
0x32, 0x33, 0x38, 0x35, 0x31, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x08, 0x31, 0x30, 0x32, 0x33, 0x38,
0x34, 0x38, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x08, 0x31, 0x30, 0x32, 0x33, 0x38, 0x34, 0x36, 0x00,
0x00, 0x00, 0x00, 0x0F, 0x08, 0x31, 0x30, 0x32, 0x33, 0x38, 0x35, 0x32, 0x00, 0x00, 0x00, 0x00,
0x0F, 0x08, 0x31, 0x30, 0x32, 0x33, 0x38, 0x34, 0x39, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x08, 0x31,
0x30, 0x32, 0x33, 0x38, 0x34, 0x37, 0x00, 0x00, 0x00, 0x00, 0x05, 0x08, 0x31, 0x30, 0x32, 0x33,
0x39, 0x36, 0x32, 0x00, 0x00, 0x00, 0x00, 0x05, 0x08, 0x31, 0x30, 0x32, 0x33, 0x39, 0x36, 0x33,
0x00, 0x00, 0x00, 0x00, 0x03, 0x08, 0x31, 0x30, 0x32, 0x33, 0x39, 0x37, 0x32, 0x00, 0x00, 0x00,
0x00, 0x03, 0x08, 0x31, 0x30, 0x32, 0x33, 0x39, 0x37, 0x33, 0x00, 0x00, 0x00, 0x00, 0x03, 0x08,
0x31, 0x30, 0x32, 0x33, 0x39, 0x37, 0x34, 0x00, 0x00, 0x00, 0x00, 0x03, 0x08, 0x31, 0x30, 0x32,
0x33, 0x39, 0x37, 0x36, 0x00, 0x00, 0x00, 0x00, 0x03, 0x08, 0x31, 0x30, 0x32, 0x33, 0x39, 0x38,
0x31, 0x00, 0x00, 0x00, 0x00, 0x03, 0x08, 0x31, 0x30, 0x32, 0x33, 0x39, 0x38, 0x30, 0x00, 0x00,
0x00, 0x00, 0x0C, 0x08, 0x31, 0x30, 0x32, 0x37, 0x39, 0x38, 0x32, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x08, 0x31, 0x30, 0x32, 0x37, 0x39, 0x38, 0x33, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x08, 0x31, 0x30,
0x32, 0x37, 0x39, 0x38, 0x34, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x08, 0x31, 0x30, 0x32, 0x37, 0x39,
0x38, 0x35, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x08, 0x31, 0x30, 0x32, 0x37, 0x39, 0x38, 0x36, 0x00,
0x00, 0x00, 0x00, 0x0C, 0x08, 0x31, 0x30, 0x32, 0x37, 0x39, 0x38, 0x37, 0x00, 0x00, 0x00, 0x00,
0x0C, 0x08, 0x31, 0x30, 0x32, 0x37, 0x39, 0x38, 0x31, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x08, 0x31,
0x30, 0x32, 0x37, 0x39, 0x38, 0x38, 0x00
};
byte[] contents =
{
0x3C, 0x02, 0x21, 0x00, 0x1B, 0x40, 0x1F, 0x00, 0x1B, 0x1F, 0x34, 0x00, 0x00, 0x14, 0x00, 0x1B,
0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00, 0x1A, 0x1F, 0x2D, 0x00,
0x00, 0x14, 0x00, 0x1A, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00,
0x19, 0x1F, 0x33, 0x00, 0x00, 0x14, 0x00, 0x19, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00,
0x00, 0x40, 0x1F, 0x00, 0x17, 0x1F, 0x32, 0x00, 0x00, 0x14, 0x00, 0x18, 0x00, 0x01, 0x00, 0x42,
0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00, 0x14, 0x1F, 0x31, 0x00, 0x00, 0x14, 0x00, 0x17,
0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00, 0x13, 0x1F, 0x30, 0x00,
0x00, 0x14, 0x00, 0x16, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00,
0x12, 0x1F, 0x2F, 0x00, 0x00, 0x14, 0x00, 0x15, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00,
0x00, 0x40, 0x1F, 0x00, 0x10, 0x1F, 0x2E, 0x00, 0x00, 0x14, 0x00, 0x14, 0x00, 0x01, 0x00, 0x42,
0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00, 0x0F, 0x0F, 0x8C, 0x00, 0x00, 0x28, 0x00, 0x13,
0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00, 0x0E, 0x0F, 0x8D, 0x00,
0x00, 0x28, 0x00, 0x12, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00,
0x0D, 0x0F, 0x88, 0x00, 0x00, 0x28, 0x00, 0x11, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00,
0x00, 0x40, 0x1F, 0x00, 0x0C, 0x0F, 0x86, 0x00, 0x00, 0x14, 0x00, 0x10, 0x00, 0x01, 0x00, 0x42,
0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00, 0x0A, 0x0F, 0x85, 0x00, 0x00, 0x28, 0x00, 0x0F,
0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00, 0x09, 0x0F, 0x84, 0x00,
0x00, 0x28, 0x00, 0x0E, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00,
0x08, 0x0F, 0x7B, 0x00, 0x00, 0x14, 0x00, 0x0D, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00,
0x00, 0x40, 0x1F, 0x00, 0x07, 0x0F, 0x7A, 0x00, 0x00, 0x14, 0x00, 0x0C, 0x00, 0x01, 0x00, 0x42,
0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00, 0x06, 0x0F, 0x07, 0x00, 0x00, 0x14, 0x00, 0x0B,
0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00, 0x05, 0x0F, 0x09, 0x00,
0x00, 0x14, 0x00, 0x0A, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00,
0x04, 0x0F, 0x0C, 0x00, 0x00, 0x14, 0x00, 0x09, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00,
0x00, 0x40, 0x1F, 0x00, 0x02, 0x0F, 0x06, 0x00, 0x00, 0x14, 0x00, 0x08, 0x00, 0x01, 0x00, 0x42,
0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00, 0x01, 0x0F, 0x08, 0x00, 0x00, 0x14, 0x00, 0x07,
0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00, 0x00, 0x0F, 0x0B, 0x00,
0x00, 0x14, 0x00, 0x06, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1E, 0xFF,
0xFF, 0x1F, 0x14, 0x00, 0x00, 0x10, 0x00, 0x05, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00,
0x00, 0x40, 0x1E, 0xFF, 0xFE, 0x17, 0x18, 0x00, 0x00, 0x0A, 0x00, 0x04, 0x00, 0x01, 0x00, 0x42,
0x0C, 0x82, 0x83, 0x00, 0xE1, 0x40, 0x1E, 0xFF, 0xFD, 0x0E, 0xF3, 0x00, 0x00, 0x14, 0x00, 0x03,
0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1E, 0xFF, 0xFC, 0x0F, 0xBF, 0x00,
0x00, 0x14, 0x00, 0x02, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1E, 0xFF,
0xFB, 0x0E, 0xFA, 0x00, 0x00, 0x0A, 0x00, 0x01, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00
};
byte[] containerDisplay = { 0x24, 0x00, 0x0B, 0x03, 0x54, 0x00, 0x30, 0x00, 0x00 };
Mobile vendor = new Mobile( vendorSerial );
vendor.SetLayer( Layer.ShopBuy, 0x420c8283 );
Engine.Mobiles.Add( vendor );
IncomingPacketHandlers.Initialize();
//TODO
//VendorBuyTabViewModel vm = new VendorBuyTabViewModel();
//vm.Items.Add( new VendorBuyAgentEntry
//{
// Graphic = 0xf8c,
// Amount = 1,
// Enabled = true,
// Hue = -1,
// MaxPrice = -1
//} );
//vm.Items.Add( new VendorBuyAgentEntry
//{
// Graphic = 0xf8d,
// Amount = 1,
// Enabled = true,
// Hue = -1,
// MaxPrice = -1
//} );
//vm.Items.Add( new VendorBuyAgentEntry
//{
// Graphic = 0xf85,
// Amount = 1,
// Enabled = true,
// Hue = -1,
// MaxPrice = -1
//} );
//vm.Items.Add( new VendorBuyAgentEntry
//{
// Graphic = 0xf88,
// Amount = 1,
// Enabled = true,
// Hue = -1,
// MaxPrice = -1
//} );
//vm.Enabled = true;
//PacketHandler containerContentsHandler = IncomingPacketHandlers.GetHandler( 0x3C );
//containerContentsHandler?.OnReceive( new PacketReader( contents, contents.Length, false ) );
//vendor.Equipment.Add( Engine.Items.GetItem( 0x420c8283 ) );
//PacketHandler shopListHandler = IncomingPacketHandlers.GetHandler( 0x74 );
//shopListHandler?.OnReceive( new PacketReader( shopList, shopList.Length, false ) );
//PacketHandler containerDisplayHandler = IncomingPacketHandlers.GetHandler( 0x24 );
//AutoResetEvent are = new AutoResetEvent( false );
//List<ShopListEntry> buyList = new List<ShopListEntry>();
//void OnPacketSentEvent( byte[] data, int length )
//{
// if ( data[0] != 0x3B )
// {
// return;
// }
// PacketReader reader = new PacketReader( data, data.Length, false );
// int count = ( data.Length - 8 ) / 7;
// reader.Seek( 5, SeekOrigin.Current );
// for ( int i = 0; i < count; i++ )
// {
// reader.ReadByte(); // layer
// int serial = reader.ReadInt32();
// int amount = reader.ReadInt16();
// buyList.Add( new ShopListEntry { Amount = amount, Item = Engine.Items.GetItem( serial ) } );
// }
//}
//Engine.InternalPacketSentEvent += OnPacketSentEvent;
//containerDisplayHandler?.OnReceive( new PacketReader( containerDisplay, containerDisplay.Length, true ) );
//foreach ( VendorBuyAgentEntry entry in vm.Items )
//{
// int amount = buyList.Where( e => e.Item.ID == entry.Graphic ).Sum( e => e.Amount );
// Assert.AreEqual( entry.Amount, amount, 0, "Buy incorrect amount" );
//}
//Engine.Items.Clear();
//Engine.Mobiles.Clear();
}
}
}
@@ -0,0 +1,269 @@
using System;
using System.Collections.Generic;
using System.IO;
using ClassicAssist.Shared;
using ClassicAssist.Data.Dress;
using ClassicAssist.UO.Data;
using ClassicAssist.UO.Network;
using ClassicAssist.UO.Objects;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
namespace ClassicAssist.Tests.Agents
{
[TestClass]
public class DressAgentTests
{
private Item _backpack;
private int[] _packetLengths;
private PlayerMobile _player;
[TestInitialize]
public void Initialize()
{
_packetLengths = new int[byte.MaxValue];
string json = File.ReadAllText( Path.Combine( Environment.CurrentDirectory, "packetlengths.json" ) );
JObject jsonObj = JObject.Parse( json );
foreach ( JProperty token in jsonObj["PacketLengths"].Children<JProperty>() )
{
int key = int.Parse( token.Name );
int val = token.Value.ToObject<int>();
if ( val == 0x8000 )
{
val = 0;
}
_packetLengths[key] = val;
}
_player = new PlayerMobile( 0x01 ) { Equipment = new ItemCollection( 0x01 ) };
_backpack = new Item( 0x40000002 ) { Container = new ItemCollection( 0x40000002 ), Owner = 0x01 };
_player.SetLayer( Layer.Backpack, _backpack.Serial );
Engine.Items.Add( _backpack );
Engine.Player = _player;
IncomingPacketHandlers.Initialize();
OutgoingPacketHandlers.Initialize();
Engine.ClientVersion = new Version( 7, 0, 45, 1 );
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
}
private void OnInternalPacketSentEvent( byte[] data, int length )
{
PacketHandler handler = OutgoingPacketHandlers.GetHandler( data[0] );
handler?.OnReceive( new PacketReader( data, data.Length, _packetLengths[data[0]] != 0 ) );
if ( data[0] == 0x08 )
{
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
int containerSerial = ( data[11] << 24 ) | ( data[12] << 16 ) | ( data[13] << 8 ) | data[14];
//container cont update
PacketWriter pw = new PacketWriter( 21 );
pw.Write( (byte) 0x25 );
pw.Write( serial );
pw.Seek( 10, SeekOrigin.Current );
pw.Write( containerSerial );
pw.Write( (short) 0 );
byte[] packet = pw.ToArray();
handler = IncomingPacketHandlers.GetHandler( packet[0] );
handler?.OnReceive( new PacketReader( packet, packet.Length, true ) );
}
if ( data[0] == 0x13 )
{
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
Layer layer = (Layer) data[5];
int containerSerial = ( data[6] << 24 ) | ( data[7] << 16 ) | ( data[8] << 8 ) | data[9];
Mobile mobile = Engine.Mobiles.GetMobile( containerSerial );
int itemInLayer = mobile?.GetLayer( layer ) ?? 0;
if ( itemInLayer != 0 )
{
// item already in layer / liftrej
return;
}
// equip update
PacketWriter pw = new PacketWriter( 15 );
pw.Write( (byte) 0x2E );
pw.Write( serial );
pw.Write( (short) 0 );
pw.Write( (byte) 0 );
pw.Write( (byte) layer );
pw.Write( containerSerial );
pw.Write( (short) 0 );
byte[] packet = pw.ToArray();
handler = IncomingPacketHandlers.GetHandler( packet[0] );
handler?.OnReceive( new PacketReader( packet, packet.Length, true ) );
}
}
[TestMethod]
public void WillDressUndressItem()
{
Item dressItem = new Item( 0x40000003 );
Engine.Items.Add( dressItem );
DressAgentEntry dae = new DressAgentEntry
{
Name = "Test",
Items = new List<DressAgentItem>
{
new DressAgentItem { Layer = Layer.Talisman, Serial = dressItem.Serial }
}
};
dae.Dress().Wait();
Assert.AreEqual( dressItem.Serial, _player.GetLayer( dressItem.Layer ) );
dae.Undress().Wait();
Assert.AreEqual( 0, _player.GetLayer( dressItem.Layer ) );
Assert.AreEqual( 1, _player.Backpack.Container.GetTotalItemCount() );
Assert.IsNotNull( _player.Backpack.Container.GetItem( dressItem.Serial ) );
}
[TestMethod]
public void WillDressUndressItemContainer()
{
Item dressItem = new Item( 0x40000003 );
Item undressContainer = new Item( 0x40000004 ) { Container = new ItemCollection( 0x40000004 ) };
Engine.Items.Add( dressItem );
Engine.Items.Add( undressContainer );
DressAgentEntry dae = new DressAgentEntry
{
Name = "Test",
Items = new List<DressAgentItem>
{
new DressAgentItem { Layer = Layer.Talisman, Serial = dressItem.Serial }
},
UndressContainer = undressContainer.Serial
};
dae.Dress().Wait();
Assert.AreEqual( dressItem.Serial, _player.GetLayer( dressItem.Layer ) );
dae.Undress().Wait();
Assert.AreEqual( 0, _player.GetLayer( dressItem.Layer ) );
Assert.AreEqual( 1, undressContainer.Container.GetTotalItemCount() );
Assert.IsNotNull( undressContainer.Container.GetItem( dressItem.Serial ) );
Engine.Items.Remove( undressContainer );
}
[TestMethod]
public void WillUndressAll()
{
Item dressItem = new Item( 0x40000003 );
Engine.Items.Add( dressItem );
DressAgentEntry dae = new DressAgentEntry
{
Name = "Test",
Items = new List<DressAgentItem>
{
new DressAgentItem { Layer = Layer.Talisman, Serial = dressItem.Serial }
}
};
dae.Dress().Wait();
Assert.AreEqual( dressItem.Serial, _player.GetLayer( dressItem.Layer ) );
DressManager.GetInstance().UndressAll().Wait();
Assert.AreEqual( 0, _player.GetLayer( dressItem.Layer ) );
Assert.AreEqual( 1, _player.Backpack.Container.GetTotalItemCount() );
Assert.IsNotNull( _player.Backpack.Container.GetItem( dressItem.Serial ) );
}
[TestMethod]
public void WontDressNoMoveConflicting()
{
Item dressItem = new Item( 0x40000003 );
Engine.Items.Add( dressItem );
Item conflictingItem = new Item( 0x40000004 ) { Owner = _player.Serial };
Engine.Items.Add( conflictingItem );
_player.SetLayer( Layer.Talisman, conflictingItem.Serial );
DressAgentEntry dae = new DressAgentEntry
{
Name = "Test",
Items = new List<DressAgentItem>
{
new DressAgentItem { Layer = Layer.Talisman, Serial = dressItem.Serial }
}
};
Assert.AreEqual( conflictingItem.Serial, _player.GetLayer( Layer.Talisman ) );
dae.Dress( false ).Wait();
Assert.AreEqual( conflictingItem.Serial, _player.GetLayer( Layer.Talisman ) );
Engine.Items.Remove( conflictingItem );
}
[TestMethod]
public void WillDressMoveConflicting()
{
Item dressItem = new Item( 0x40000003 );
Engine.Items.Add( dressItem );
Item conflictingItem = new Item( 0x40000004 ) { Owner = _player.Serial };
Engine.Items.Add( conflictingItem );
_player.SetLayer( Layer.Talisman, conflictingItem.Serial );
DressAgentEntry dae = new DressAgentEntry
{
Name = "Test",
Items = new List<DressAgentItem>
{
new DressAgentItem { Layer = Layer.Talisman, Serial = dressItem.Serial }
}
};
Assert.AreEqual( conflictingItem.Serial, _player.GetLayer( Layer.Talisman ) );
dae.Dress().Wait();
Assert.AreEqual( dressItem.Serial, _player.GetLayer( Layer.Talisman ) );
Engine.Items.Remove( conflictingItem );
}
[TestCleanup]
public void Cleanup()
{
ActionPacketQueue.Clear();
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
Engine.Player = null;
Engine.Items.Clear();
}
}
}
@@ -0,0 +1,151 @@
#region License
// Copyright (C) 2020 Reetus
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#endregion
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using ClassicAssist.Shared;
using ClassicAssist.Data.Organizer;
using ClassicAssist.UO.Data;
using ClassicAssist.UO.Network.PacketFilter;
using ClassicAssist.UO.Objects;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ClassicAssist.Tests.Agents
{
[TestClass]
public class OrganizerTests
{
[TestMethod]
public void WillOrganizeAnyHue()
{
Engine.Items.Clear();
Item container = new Item( 0x40000000 ) { Container = new ItemCollection( 0x40000000 ) };
container.Container.Add( new Item( 0x40000001 ) { ID = 0xf06, Hue = 1000 } );
container.Container.Add( new Item( 0x40000002 ) { ID = 0xf06, Hue = 1161 } );
Engine.Items.Add( container );
Engine.PacketWaitEntries = new PacketWaitEntries();
OrganizerManager manager = OrganizerManager.GetInstance();
OrganizerEntry entry = new OrganizerEntry();
entry.Items.Add( new OrganizerItem { ID = 0xf06, Hue = -1, Amount = -1, Item = "Test" } );
AutoResetEvent are = new AutoResetEvent( false );
void OnInternalPacketSentEvent( byte[] data, int length )
{
if ( data[0] == 0x06 )
{
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
PacketWriter writer = new PacketWriter();
writer.Write( 0x3C );
writer.Seek( 19, SeekOrigin.Begin );
writer.Write( serial );
Engine.SendPacketToClient( writer );
}
if ( data[0] == 0x07 )
{
are.Set();
}
}
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
Task.Run( () => manager.Organize( entry, container.Serial, container.Serial ) ).Wait();
bool result = are.WaitOne( 4000 );
Assert.IsTrue( result );
manager.Items.Clear();
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
Engine.PacketWaitEntries = null;
Engine.Items.Clear();
}
[TestMethod]
public void WillOrganizeOnlyHue()
{
Engine.Items.Clear();
Item container = new Item( 0x40000000 ) { Container = new ItemCollection( 0x40000000 ) };
container.Container.Add( new Item( 0x40000001 ) { ID = 0xf06, Hue = 1000 } );
container.Container.Add( new Item( 0x40000002 ) { ID = 0xf06, Hue = 1161 } );
Engine.Items.Add( container );
Engine.PacketWaitEntries = new PacketWaitEntries();
OrganizerManager manager = OrganizerManager.GetInstance();
OrganizerEntry entry = new OrganizerEntry();
entry.Items.Add( new OrganizerItem { ID = 0xf06, Hue = 1161, Amount = -1, Item = "Test" } );
AutoResetEvent are = new AutoResetEvent( false );
void OnInternalPacketSentEvent( byte[] data, int length )
{
if ( data[0] == 0x06 )
{
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
PacketWriter writer = new PacketWriter();
writer.Write( 0x3C );
writer.Seek( 19, SeekOrigin.Begin );
writer.Write( serial );
Engine.SendPacketToClient( writer );
}
if ( data[0] == 0x07 )
{
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
if ( serial == 0x40000002 )
{
are.Set();
}
else
{
Assert.Fail();
}
}
}
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
Task.Run( () => manager.Organize( entry, container.Serial, container.Serial ) ).Wait();
bool result = are.WaitOne( 4000 );
Assert.IsTrue( result );
manager.Items.Clear();
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
Engine.PacketWaitEntries = null;
Engine.Items.Clear();
}
}
}
@@ -0,0 +1,123 @@
#region License
// Copyright (C) 2020 Reetus
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#endregion
using System.IO;
using System.Threading;
using ClassicAssist.Shared;
using ClassicAssist.Data.Scavenger;
using ClassicAssist.UO.Data;
using ClassicAssist.UO.Objects;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ClassicAssist.Tests.Agents
{
[TestClass]
public class ScavengerTests
{
[TestMethod]
public void WillScavengerEnabled()
{
//TODO
//ScavengerTabViewModel vm = new ScavengerTabViewModel { Enabled = true };
//ScavengerManager manager = ScavengerManager.GetInstance();
//if ( !Directory.Exists( @"C:\Program Files (x86)\Electronic Arts\Ultima Online Classic" ) )
//{
// return;
//}
//TileData.Initialize( @"C:\Program Files (x86)\Electronic Arts\Ultima Online Classic" );
//Engine.Player = new PlayerMobile( 0x0 ) { WeightMax = 500 };
//Engine.Player.SetLayer( Layer.Backpack, 0x40000001 );
//manager.Items.Add( new ScavengerEntry { Enabled = true, Graphic = 0xff, Hue = -1, Name = "Test" } );
//Engine.Items.Add( new Item( 0x40000001 ) { Container = new ItemCollection( 0x4000001 ) } );
//Engine.Items.Add( new Item( 0x40000000 ) { ID = 0xff } );
//AutoResetEvent are = new AutoResetEvent( false );
//void OnInternalPacketSentEvent( byte[] data, int length )
//{
// if ( data[0] == 0x07 )
// {
// are.Set();
// }
//}
//Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
//vm.CheckArea();
//bool result = are.WaitOne( 5000 );
//if ( !result )
//{
// Assert.Fail();
//}
//Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
//Engine.Player = null;
//Engine.Items.Clear();
//manager.Items.Clear();
}
[TestMethod]
public void WontScavengerEntryDisabled()
{
//TODO
//ScavengerTabViewModel vm = new ScavengerTabViewModel { Enabled = true };
ScavengerManager manager = ScavengerManager.GetInstance();
if ( !Directory.Exists( @"C:\Program Files (x86)\Electronic Arts\Ultima Online Classic" ) )
{
return;
}
TileData.Initialize( @"C:\Program Files (x86)\Electronic Arts\Ultima Online Classic" );
Engine.Player = new PlayerMobile( 0x0 ) { WeightMax = 500 };
Engine.Player.SetLayer( Layer.Backpack, 0x40000001 );
manager.Items.Add( new ScavengerEntry { Enabled = false, Graphic = 0xff, Hue = -1, Name = "Test" } );
Engine.Items.Add( new Item( 0x40000001 ) { Container = new ItemCollection( 0x4000001 ) } );
Engine.Items.Add( new Item( 0x40000000 ) { ID = 0xff } );
AutoResetEvent are = new AutoResetEvent( false );
void OnInternalPacketSentEvent( byte[] data, int length )
{
if ( data[0] == 0x07 )
{
Assert.Fail();
}
}
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
//TODO
//vm.CheckArea();
bool result = are.WaitOne( 500 );
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
Engine.Player = null;
Engine.Items.Clear();
manager.Items.Clear();
}
}
}
@@ -0,0 +1,202 @@
//TODO
//using System.Threading;
//using Assistant;
//using ClassicAssist.Data.Vendors;
//using ClassicAssist.UO.Data;
//using ClassicAssist.UO.Network;
//using Microsoft.VisualStudio.TestTools.UnitTesting;
//namespace ClassicAssist.Tests.Agents
//{
// [TestClass]
// public class SellAgentTests
// {
// [TestMethod]
// public void WontSellIncorrectHue()
// {
// //TODO
// //void OnPacket( byte[] data, int length )
// //{
// // Assert.Fail();
// //}
// //Engine.InternalPacketSentEvent += OnPacket;
// //VendorSellTabViewModel vsvm = new VendorSellTabViewModel();
// //vsvm.Items.Add( new VendorSellAgentEntry
// //{
// // Enabled = true,
// // Graphic = 0xff,
// // MinPrice = 10,
// // Name = "Shmoo",
// // Hue = 0xff
// //} );
// //IncomingPacketHandlers.Initialize();
// //PacketHandler handler = IncomingPacketHandlers.GetHandler( 0x9E );
// //PacketWriter pw = new PacketWriter( 23 );
// //pw.Write( (byte) 0x9E );
// //pw.Write( (short) 21 );
// //pw.Write( 0 );
// //pw.Write( (short) 1 );
// //pw.Write( 0 );
// //pw.Write( (short) 0xFF );
// //pw.Write( (short) 0 );
// //pw.Write( (short) 0 );
// //pw.Write( (short) 9 );
// //pw.Write( (short) 0 );
// //byte[] packet = pw.ToArray();
// //handler.OnReceive( new PacketReader( packet, packet.Length, false ) );
// //vsvm.Items.Clear();
// //Engine.InternalPacketSentEvent -= OnPacket;
// }
// [TestMethod]
// public void WontSellUnderMinPrice()
// {
// //TODO
// //void OnPacket( byte[] data, int length )
// //{
// // Assert.Fail();
// //}
// //Engine.InternalPacketSentEvent += OnPacket;
// //VendorSellTabViewModel vsvm = new VendorSellTabViewModel();
// //vsvm.Items.Add( new VendorSellAgentEntry
// //{
// // Enabled = true, Graphic = 0xff, MinPrice = 10, Name = "Shmoo"
// //} );
// //IncomingPacketHandlers.Initialize();
// //PacketHandler handler = IncomingPacketHandlers.GetHandler( 0x9E );
// //PacketWriter pw = new PacketWriter( 23 );
// //pw.Write( (byte) 0x9E );
// //pw.Write( (short) 21 );
// //pw.Write( 0 );
// //pw.Write( (short) 1 );
// //pw.Write( 0 );
// //pw.Write( (short) 0xFF );
// //pw.Write( (short) 0 );
// //pw.Write( (short) 0 );
// //pw.Write( (short) 9 );
// //pw.Write( (short) 0 );
// //byte[] packet = pw.ToArray();
// //handler.OnReceive( new PacketReader( packet, packet.Length, false ) );
// //vsvm.Items.Clear();
// //Engine.InternalPacketSentEvent -= OnPacket;
// }
// [TestMethod]
// public void WillSellMinPrice()
// {
// AutoResetEvent are = new AutoResetEvent( false );
// void OnPacket( byte[] data, int length )
// {
// if ( data[0] == 0x9F )
// {
// are.Set();
// }
// }
// Engine.InternalPacketSentEvent += OnPacket;
// VendorSellTabViewModel vsvm = new VendorSellTabViewModel();
// vsvm.Items.Add( new VendorSellAgentEntry { Enabled = true, Graphic = 0xff, MinPrice = 9, Name = "Shmoo" } );
// IncomingPacketHandlers.Initialize();
// PacketHandler handler = IncomingPacketHandlers.GetHandler( 0x9E );
// PacketWriter pw = new PacketWriter( 23 );
// pw.Write( (byte) 0x9E );
// pw.Write( (short) 21 );
// pw.Write( 0 );
// pw.Write( (short) 1 );
// pw.Write( 0 );
// pw.Write( (short) 0xFF );
// pw.Write( (short) 0 );
// pw.Write( (short) 0 );
// pw.Write( (short) 9 );
// pw.Write( (short) 0 );
// byte[] packet = pw.ToArray();
// handler.OnReceive( new PacketReader( packet, packet.Length, false ) );
// bool result = are.WaitOne( 1000 );
// Assert.IsTrue( result );
// vsvm.Items.Clear();
// Engine.InternalPacketSentEvent -= OnPacket;
// }
// [TestMethod]
// public void WontSellMoreThanAmount()
// {
// AutoResetEvent are = new AutoResetEvent( false );
// void OnPacket( byte[] data, int length )
// {
// if ( data[0] != 0x9F )
// {
// return;
// }
// int amount = ( data[13] << 8 ) | data[14];
// if ( amount != 10 )
// {
// Assert.Fail();
// return;
// }
// are.Set();
// }
// Engine.InternalPacketSentEvent += OnPacket;
// VendorSellTabViewModel vsvm = new VendorSellTabViewModel();
// vsvm.Items.Add( new VendorSellAgentEntry { Enabled = true, Graphic = 0xff, Amount = 10, Name = "Shmoo" } );
// IncomingPacketHandlers.Initialize();
// PacketHandler handler = IncomingPacketHandlers.GetHandler( 0x9E );
// PacketWriter pw = new PacketWriter( 23 );
// pw.Write( (byte) 0x9E );
// pw.Write( (short) 21 );
// pw.Write( 0 );
// pw.Write( (short) 1 );
// pw.Write( 0 );
// pw.Write( (short) 0xFF );
// pw.Write( (short) 0 );
// pw.Write( (short) 100 );
// pw.Write( (short) 9 );
// pw.Write( (short) 0 );
// byte[] packet = pw.ToArray();
// handler.OnReceive( new PacketReader( packet, packet.Length, false ) );
// bool result = are.WaitOne( 1000 );
// Assert.IsTrue( result );
// vsvm.Items.Clear();
// Engine.InternalPacketSentEvent -= OnPacket;
// }
// }
//}
+64
View File
@@ -0,0 +1,64 @@
#region License
// Copyright (C) 2020 Reetus
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#endregion
using ClassicAssist.Data.BuffIcons;
using ClassicAssist.UO.Data;
using ClassicAssist.UO.Network;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ClassicAssist.Tests
{
[TestClass]
public class BuffIconTests
{
[TestMethod]
public void WillSetExpireTime()
{
byte[] packet =
{
0xDF, 0x00, 0x44, 0x00, 0x00, 0x77, 0x42, 0x04, 0x45, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04,
0x45, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x10, 0x2E, 0xF4,
0x00, 0x11, 0x9B, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x09, 0x31, 0x00,
0x30, 0x00, 0x09, 0x00, 0x32, 0x00, 0x34, 0x00, 0x09, 0x00, 0x34, 0x00, 0x30, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00
};
IncomingPacketHandlers.Initialize();
PacketHandler handler = IncomingPacketHandlers.GetHandler( 0xDF );
BuffIconManager manager = BuffIconManager.GetInstance();
handler?.OnReceive( new PacketReader( packet, packet.Length, false ) );
double milliseconds = manager.BuffTime( "Confidence" );
Assert.IsTrue( milliseconds > 0 );
}
[TestMethod]
public void UnsetBuffWillReturnTimeZero()
{
BuffIconManager manager = BuffIconManager.GetInstance();
double milliseconds = manager.BuffTime( "Enemy Of One" );
Assert.AreEqual( 0, milliseconds );
}
}
}
@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Configurations>Debug;Release;Develop;Linux</Configurations>
</PropertyGroup>
<ItemGroup>
<None Remove="packetlengths.json" />
</ItemGroup>
<ItemGroup>
<Content Include="packetlengths.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ClassicAssist.Shared\ClassicAssist.Shared.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<Reference Include="cuoapi">
<HintPath>..\ClassicAssist.Shared\cuoapi.dll</HintPath>
</Reference>
<Reference Include="WindowsBase" />
</ItemGroup>
</Project>
@@ -0,0 +1,23 @@
using ClassicAssist.Data.Commands;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ClassicAssist.Tests
{
[TestClass]
public class CommandsManagerTests
{
[TestMethod]
public void WillHandleEncodedCommands()
{
byte[] packet =
{
0xAD, 0x1B, 0x00, 0xC0, 0x00, 0x5D, 0x00, 0x03, 0x45, 0x4E, 0x41, 0x00, 0x00, 0x10, 0x02, 0x2B,
0x77, 0x68, 0x65, 0x72, 0x65, 0x20, 0x62, 0x61, 0x6E, 0x6B, 0x00
};
string text = CommandsManager.ParseUnicodeSpeech( packet, packet.Length );
Assert.AreEqual( "+where bank", text );
}
}
}
+74
View File
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using ClassicAssist.Shared;
using ClassicAssist.Data;
using ClassicAssist.Misc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
namespace ClassicAssist.Tests
{
[TestClass]
[Serializable]
public class ConfigTests
{
private string _profilePath;
[TestMethod]
public void WontThrowExceptionOnDeserializeNullConfig()
{
AppDomain appDomain = AppDomain.CreateDomain( "WontThrowExceptionOnDeserializeNullConfig",
AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation );
appDomain.DoCallBack( () => TestConfig( null ) );
}
[TestMethod]
public void WontThrowExceptionOnDeserializeEmptyConfig()
{
AppDomain appDomain = AppDomain.CreateDomain( "WontThrowExceptionOnDeserializeEmptyConfig",
AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation );
appDomain.DoCallBack( () => TestConfig( new JObject() ) );
}
public void TestConfig( JObject json )
{
string path = Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location );
_profilePath = Path.Combine( path, "Profiles" );
if ( File.Exists( Path.Combine( _profilePath, "settings.json" ) ) )
{
File.Delete( Path.Combine( _profilePath, "settings.json" ) );
}
IEnumerable<Type> allSettingProvider = Assembly.GetAssembly( typeof( Engine ) ).GetTypes()
.Where( t => typeof( ISettingProvider ).IsAssignableFrom( t ) && t.IsClass );
Options options = new Options();
foreach ( Type type in allSettingProvider )
{
if ( !type.IsPublic )
{
continue;
}
ISettingProvider p = (ISettingProvider) Activator.CreateInstance( type );
p.Deserialize( json, options );
p.Serialize( json );
}
if ( File.Exists( Path.Combine( _profilePath, "settings.json" ) ) )
{
File.Delete( Path.Combine( _profilePath, "settings.json" ) );
}
}
}
}
+484
View File
@@ -0,0 +1,484 @@
//using System;
//using System.IO;
//using System.Reflection;
//using System.Runtime.InteropServices;
//using System.Threading;
//using Assistant;
//using ClassicAssist.Data;
//using ClassicAssist.Data.Friends;
//using ClassicAssist.UO.Data;
//using ClassicAssist.UO.Network;
//using ClassicAssist.UO.Network.PacketFilter;
//using CUO_API;
//using Microsoft.VisualStudio.TestTools.UnitTesting;
//using Newtonsoft.Json.Linq;
//namespace ClassicAssist.Tests
//{
// [TestClass]
// [TestCategory( "Engine" )]
// public class EngineTests
// {
// private const string CLIENT_PATH = @"C:\Users\johns\Desktop\KvG Client 2.0";
// private OnGetPacketLength _getPacketLength;
// private OnGetUOFilePath _getUOFilePath;
// private int[] _packetLengths;
// private PluginHeader _pluginHeader;
// private OnPacketSendRecv _receivePacket;
// private RequestMove _requestMove;
// private OnPacketSendRecv _sendPacket;
// private string _startupPath;
// [TestInitialize]
// public void Initialize()
// {
// _startupPath = Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location );
// _getUOFilePath = GetUOFilePath;
// _getPacketLength = GetPacketLength;
// _sendPacket = SendPacket;
// _receivePacket = ReceivePacket;
// _requestMove = ( dir, run ) => true;
// _pluginHeader = new PluginHeader
// {
// GetPacketLength = Marshal.GetFunctionPointerForDelegate( _getPacketLength ),
// GetUOFilePath = Marshal.GetFunctionPointerForDelegate( _getUOFilePath ),
// Recv = Marshal.GetFunctionPointerForDelegate( _receivePacket ),
// Send = Marshal.GetFunctionPointerForDelegate( _sendPacket ),
// RequestMove = Marshal.GetFunctionPointerForDelegate( _requestMove )
// };
// Engine.StartupPath = _startupPath;
// _packetLengths = new int[byte.MaxValue];
// string json = File.ReadAllText( Path.Combine( _startupPath ?? throw new InvalidOperationException(),
// "packetlengths.json" ) );
// JObject jsonObj = JObject.Parse( json );
// foreach ( JProperty token in jsonObj["PacketLengths"].Children<JProperty>() )
// {
// int key = int.Parse( token.Name );
// int val = token.Value.ToObject<int>();
// if ( val == 0x8000 )
// {
// val = 0;
// }
// _packetLengths[key] = val;
// }
// }
// [TestMethod]
// public void WillGetPacketLength()
// {
// // Fixed Length
// int length = GetPacketLength( 0x1B );
// Assert.AreEqual( 37, length );
// // Dynamic Length
// length = GetPacketLength( 0x1C );
// Assert.AreEqual( 0, length );
// }
// [TestMethod]
// public void WillInitializePlugin()
// {
// InitializePlugin();
// Assert.AreEqual( CLIENT_PATH, Engine.ClientPath );
// }
// private unsafe void InitializePlugin()
// {
// fixed ( void* func = &_pluginHeader )
// {
// Engine.InitializePlugin( (PluginHeader*) func );
// }
// }
// [TestMethod]
// public unsafe void WillSendPacket()
// {
// fixed ( void* func = &_pluginHeader )
// {
// Engine.Install( (PluginHeader*) func );
// }
// using ( AutoResetEvent are = new AutoResetEvent( false ) )
// {
// void OnPacketSentEvent( byte[] data, int len )
// {
// Engine.PacketSentEvent -= OnPacketSentEvent;
// int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
// if ( (uint) serial != 0xaabbccdd )
// {
// Assert.Fail();
// }
// // ReSharper disable once AccessToDisposedClosure
// are.Set();
// }
// Engine.PacketSentEvent += OnPacketSentEvent;
// byte[] packet = { 0x06, 0xAA, 0xBB, 0xCC, 0xDD };
// int length = packet.Length;
// Marshal.GetDelegateForFunctionPointer<OnPacketSendRecv>( _pluginHeader.OnSend )
// .Invoke( ref packet, ref length );
// bool result = are.WaitOne( 5000 );
// Assert.IsTrue( result );
// }
// }
// [TestMethod]
// public unsafe void WillFilterSendPacket()
// {
// fixed ( void* func = &_pluginHeader )
// {
// Engine.Install( (PluginHeader*) func );
// }
// byte[] packet = { 0x06, 0xAA, 0xBB, 0xCC, 0xDD };
// int length = packet.Length;
// try
// {
// Engine.AddSendPreFilter( new PacketFilterInfo( 0x06 ) );
// using ( AutoResetEvent are = new AutoResetEvent( false ) )
// {
// void OnSentPacketFilteredEvent( byte[] data, int len )
// {
// Engine.SentPacketFilteredEvent -= OnSentPacketFilteredEvent;
// int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
// if ( (uint) serial != 0xaabbccdd )
// {
// Assert.Fail();
// }
// // ReSharper disable once AccessToDisposedClosure
// are.Set();
// }
// Engine.SentPacketFilteredEvent += OnSentPacketFilteredEvent;
// Marshal.GetDelegateForFunctionPointer<OnPacketSendRecv>( _pluginHeader.OnSend )
// .Invoke( ref packet, ref length );
// bool result = are.WaitOne( 5000 );
// Assert.IsTrue( result );
// }
// }
// finally
// {
// Engine.ClearSendPreFilter();
// }
// }
// [TestMethod]
// public unsafe void WillFilterReceivedPacket()
// {
// fixed ( void* func = &_pluginHeader )
// {
// Engine.Install( (PluginHeader*) func );
// }
// byte[] packet = { 0x2F, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 };
// int length = packet.Length;
// try
// {
// Engine.AddReceiveFilter( new PacketFilterInfo( 0x2F ) );
// using ( AutoResetEvent are = new AutoResetEvent( false ) )
// {
// void OnSentPacketFilteredEvent( byte[] data, int len )
// {
// Engine.ReceivedPacketFilteredEvent -= OnSentPacketFilteredEvent;
// int attacker = ( data[2] << 24 ) | ( data[3] << 16 ) | ( data[4] << 8 ) | data[5];
// int defender = ( data[6] << 24 ) | ( data[7] << 16 ) | ( data[8] << 8 ) | data[9];
// if ( (uint) attacker != 0x11223344 || defender != 0x55667788 )
// {
// Assert.Fail();
// }
// // ReSharper disable once AccessToDisposedClosure
// are.Set();
// }
// Engine.ReceivedPacketFilteredEvent += OnSentPacketFilteredEvent;
// Marshal.GetDelegateForFunctionPointer<OnPacketSendRecv>( _pluginHeader.OnRecv )
// .Invoke( ref packet, ref length );
// bool result = are.WaitOne( 5000 );
// Assert.IsTrue( result );
// }
// }
// finally
// {
// Engine.ClearReceiveFilter();
// }
// }
// [TestMethod]
// public unsafe void WillReceivePacket()
// {
// fixed ( void* func = &_pluginHeader )
// {
// Engine.Install( (PluginHeader*) func );
// }
// byte[] packet = { 0x2F, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 };
// int length = packet.Length;
// AutoResetEvent are = new AutoResetEvent( false );
// void OnPacketReceivedEvent( byte[] data, int len )
// {
// Engine.PacketReceivedEvent -= OnPacketReceivedEvent;
// int attacker = ( data[2] << 24 ) | ( data[3] << 16 ) | ( data[4] << 8 ) | data[5];
// int defender = ( data[6] << 24 ) | ( data[7] << 16 ) | ( data[8] << 8 ) | data[9];
// if ( (uint) attacker != 0x11223344 || defender != 0x55667788 )
// {
// Assert.Fail();
// }
// are.Set();
// }
// Engine.PacketReceivedEvent += OnPacketReceivedEvent;
// Marshal.GetDelegateForFunctionPointer<OnPacketSendRecv>( _pluginHeader.OnRecv )
// .Invoke( ref packet, ref length );
// bool result = are.WaitOne( 5000 );
// Assert.IsTrue( result );
// }
// [TestMethod]
// public void OnConnectedWillSetEngineConnected()
// {
// InitializePlugin();
// Marshal.GetDelegateForFunctionPointer<OnConnected>( _pluginHeader.OnConnected )();
// Assert.IsTrue( Engine.Connected );
// }
// [TestMethod]
// public void OnDisconnectedWillSetEngineDisconnected()
// {
// InitializePlugin();
// Marshal.GetDelegateForFunctionPointer<OnDisconnected>( _pluginHeader.OnDisconnected )();
// Assert.IsFalse( Engine.Connected );
// }
// [TestMethod]
// public void OnDisconnectedWillInvokeDisconnectedEvent()
// {
// InitializePlugin();
// using ( AutoResetEvent are = new AutoResetEvent( false ) )
// {
// void OnDisconnectedEvent()
// {
// // ReSharper disable once AccessToDisposedClosure
// are.Set();
// }
// Engine.DisconnectedEvent += OnDisconnectedEvent;
// Marshal.GetDelegateForFunctionPointer<OnDisconnected>( _pluginHeader.OnDisconnected )();
// bool result = are.WaitOne( 5000 );
// Assert.IsTrue( result );
// Engine.DisconnectedEvent -= OnDisconnectedEvent;
// are.Dispose();
// }
// }
// [TestMethod]
// public void OnConnectedWillInvokeDisconnectedEvent()
// {
// InitializePlugin();
// using ( AutoResetEvent are = new AutoResetEvent( false ) )
// {
// void OnConnectedEvent()
// {
// // ReSharper disable once AccessToDisposedClosure
// are.Set();
// }
// Engine.ConnectedEvent += OnConnectedEvent;
// Marshal.GetDelegateForFunctionPointer<OnConnected>( _pluginHeader.OnConnected )();
// bool result = are.WaitOne( 5000 );
// Assert.IsTrue( result );
// Engine.ConnectedEvent -= OnConnectedEvent;
// are.Dispose();
// }
// }
// [TestMethod]
// public void WillAutoAcceptPartyInvite()
// {
// Options.CurrentOptions.AutoAcceptPartyInvite = true;
// Options.CurrentOptions.AutoAcceptPartyOnlyFromFriends = false;
// AutoResetEvent are = new AutoResetEvent( false );
// void OnPacketSentEvent( byte[] data, int length )
// {
// if ( data[0] == 0xBF && data[5] == 0x08 )
// {
// are.Set();
// }
// }
// Engine.InternalPacketSentEvent += OnPacketSentEvent;
// IncomingPacketHandlers.Initialize();
// PacketHandler handler = IncomingPacketHandlers.GetHandler( 0xBF );
// byte[] packet = { 0xBF, 0x00, 0x0A, 0x00, 0x06, 0x07, 0x00, 0xaa, 0xbb, 0xcc };
// handler.OnReceive( new PacketReader( packet, packet.Length, false ) );
// bool result = are.WaitOne( 5000 );
// Assert.IsTrue( result );
// Engine.InternalPacketSentEvent -= OnPacketSentEvent;
// }
// [TestMethod]
// public void WontAutoAcceptPartyInviteNonFriend()
// {
// Options.CurrentOptions.AutoAcceptPartyInvite = true;
// Options.CurrentOptions.AutoAcceptPartyOnlyFromFriends = true;
// void OnPacketSentEvent( byte[] data, int length )
// {
// if ( data[0] == 0xBF && data[5] == 0x08 )
// {
// Assert.Fail();
// }
// }
// Engine.InternalPacketSentEvent += OnPacketSentEvent;
// IncomingPacketHandlers.Initialize();
// PacketHandler handler = IncomingPacketHandlers.GetHandler( 0xBF );
// byte[] packet = { 0xBF, 0x00, 0x0A, 0x00, 0x06, 0x07, 0x00, 0xaa, 0xbb, 0xcc };
// handler.OnReceive( new PacketReader( packet, packet.Length, false ) );
// Engine.InternalPacketSentEvent -= OnPacketSentEvent;
// }
// [TestMethod]
// public void WillAutoAcceptPartyInviteIfFriend()
// {
// Options.CurrentOptions.AutoAcceptPartyInvite = true;
// Options.CurrentOptions.AutoAcceptPartyOnlyFromFriends = true;
// AutoResetEvent are = new AutoResetEvent( false );
// FriendEntry fe = new FriendEntry { Name = "Test", Serial = 0xaabbcc };
// Options.CurrentOptions.Friends.Add( fe );
// void OnPacketSentEvent( byte[] data, int length )
// {
// if ( data[0] == 0xBF && data[5] == 0x08 )
// {
// are.Set();
// }
// }
// Engine.InternalPacketSentEvent += OnPacketSentEvent;
// IncomingPacketHandlers.Initialize();
// PacketHandler handler = IncomingPacketHandlers.GetHandler( 0xBF );
// byte[] packet = { 0xBF, 0x00, 0x0A, 0x00, 0x06, 0x07, 0x00, 0xaa, 0xbb, 0xcc };
// handler.OnReceive( new PacketReader( packet, packet.Length, false ) );
// bool result = are.WaitOne( 5000 );
// Assert.IsTrue( result );
// Options.CurrentOptions.Friends.Remove( fe );
// Engine.InternalPacketSentEvent -= OnPacketSentEvent;
// }
// [TestCleanup]
// public void TestCleanup()
// {
// if ( _pluginHeader.OnClientClosing != IntPtr.Zero )
// {
// Marshal.GetDelegateForFunctionPointer<OnClientClose>( _pluginHeader.OnClientClosing )();
// }
// }
// #region Plugin Functions
// private short GetPacketLength( int id )
// {
// return (short) _packetLengths[id];
// }
// private static string GetUOFilePath()
// {
// return CLIENT_PATH;
// }
// private static bool ReceivePacket( ref byte[] data, ref int length )
// {
// return true;
// }
// private static bool SendPacket( ref byte[] data, ref int length )
// {
// return true;
// }
// #endregion
// }
//}
@@ -0,0 +1,136 @@
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading;
using ClassicAssist.Shared;
using ClassicAssist.Data.Filters;
using ClassicAssist.UO.Data;
using ClassicAssist.UO.Network;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ClassicAssist.Tests.Filters
{
[TestClass]
public class ClilocFilterTests
{
[TestMethod]
public void WillFilterLocalizedText()
{
const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";
if ( !Directory.Exists( localPath ) )
{
Debug.WriteLine( "Not running test, requires Cliloc.enu" );
return;
}
Cliloc.Initialize( localPath );
byte[] packet =
{
0xC1, 0x00, 0x32, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x03, 0xB2, 0x00, 0x03, 0x00, 0x07,
0xA1, 0x96, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00
};
int length = packet.Length;
const int cliloc = 500118;
const string replaceText = "The quick brown fox jumped over the lazy dog.";
AutoResetEvent are = new AutoResetEvent( false );
void OnReceivedEvent( byte[] data, int _ )
{
if ( data[0] != 0xAE )
{
Assert.Fail();
}
string text = Encoding.BigEndianUnicode.GetString( data, 48, data.Length - 48 );
if ( text != replaceText )
{
Assert.Fail();
}
are.Set();
}
Engine.InternalPacketReceivedEvent += OnReceivedEvent;
ClilocFilter.IsEnabled = true;
ClilocFilter.Filters.Add( cliloc, replaceText );
IncomingPacketFilters.Initialize();
IncomingPacketFilters.CheckPacket( ref packet, ref length );
bool result = are.WaitOne( 5000 );
Assert.IsTrue( result );
Engine.InternalPacketReceivedEvent -= OnReceivedEvent;
}
[TestMethod]
public void WillFilterLocalizedTextAffix()
{
const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";
if ( !Directory.Exists( localPath ) )
{
Debug.WriteLine( "Not running test, requires Cliloc.enu" );
return;
}
Cliloc.Initialize( localPath );
byte[] packet =
{
0xCC, 0x00, 0x36, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x06, 0x03, 0xB2, 0x00, 0x03, 0x00, 0x0F,
0x62, 0x1E, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x31, 0x34, 0x00, 0x00, 0x00
};
int length = packet.Length;
const int cliloc = 1008158;
const string replaceText = "The value is: ";
AutoResetEvent are = new AutoResetEvent( false );
void OnReceivedEvent( byte[] data, int _ )
{
if ( data[0] != 0xAE )
{
Assert.Fail();
}
string text = Encoding.BigEndianUnicode.GetString( data, 48, data.Length - 48 );
if ( !text.StartsWith( replaceText ) )
{
Assert.Fail();
}
are.Set();
}
Engine.InternalPacketReceivedEvent += OnReceivedEvent;
ClilocFilter.IsEnabled = true;
ClilocFilter.Filters.Add( cliloc, replaceText );
IncomingPacketFilters.Initialize();
IncomingPacketFilters.CheckPacket( ref packet, ref length );
bool result = are.WaitOne( 5000 );
Assert.IsTrue( result );
Engine.InternalPacketReceivedEvent -= OnReceivedEvent;
}
}
}
@@ -0,0 +1,140 @@
#region License
// Copyright (C) 2020 Reetus
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#endregion
using System;
using ClassicAssist.Shared;
using ClassicAssist.Data.Filters;
using ClassicAssist.UO.Network;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ClassicAssist.Tests.Filters
{
[TestClass]
public class RepeatedMessageFilterTests
{
[TestMethod]
public void WillFilterOldAsciiSystemMessages()
{
AppDomain appDomain = AppDomain.CreateDomain( "WillFilterOldAsciiSystemMessages",
AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation );
appDomain.DoCallBack( () =>
{
byte[] packet =
{
0x1C, 0x00, 0x4B, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x04, 0x81, 0x00, 0x03, 0x53, 0x79,
0x73, 0x74, 0x65, 0x6D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x61, 0x72, 0x67,
0x65, 0x74, 0x20, 0x69, 0x73, 0x20, 0x6E, 0x6F, 0x74, 0x20, 0x69, 0x6E, 0x20, 0x6C, 0x69, 0x6E,
0x65, 0x20, 0x6F, 0x66, 0x20, 0x73, 0x69, 0x67, 0x68, 0x74, 0x00
};
int length = packet.Length;
IncomingPacketFilters.Initialize();
RepeatedMessagesFilter.IsEnabled = true;
IncomingPacketFilters.CheckPacket( ref packet, ref length );
IncomingPacketFilters.CheckPacket( ref packet, ref length );
IncomingPacketFilters.CheckPacket( ref packet, ref length );
IncomingPacketFilters.CheckPacket( ref packet, ref length );
IncomingPacketFilters.CheckPacket( ref packet, ref length );
IncomingPacketFilters.CheckPacket( ref packet, ref length );
bool result = IncomingPacketFilters.CheckPacket( ref packet, ref length );
Assert.IsTrue( result );
} );
}
[TestMethod]
public void WillSendToJournalFilteredMessages()
{
AppDomain appDomain = AppDomain.CreateDomain( "WillSendToJournalFilteredMessages",
AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation );
appDomain.DoCallBack( () =>
{
byte[] packet =
{
0x1C, 0x00, 0x4B, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x04, 0x81, 0x00, 0x03, 0x53, 0x79,
0x73, 0x74, 0x65, 0x6D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x61, 0x72, 0x67,
0x65, 0x74, 0x20, 0x69, 0x73, 0x20, 0x6E, 0x6F, 0x74, 0x20, 0x69, 0x6E, 0x20, 0x6C, 0x69, 0x6E,
0x65, 0x20, 0x6F, 0x66, 0x20, 0x73, 0x69, 0x67, 0x68, 0x74, 0x00
};
int length = packet.Length;
IncomingPacketFilters.Initialize();
RepeatedMessagesFilter.IsEnabled = true;
RepeatedMessagesFilter.FilterOptions.SendToJournal = true;
IncomingPacketFilters.CheckPacket( ref packet, ref length );
IncomingPacketFilters.CheckPacket( ref packet, ref length );
IncomingPacketFilters.CheckPacket( ref packet, ref length );
IncomingPacketFilters.CheckPacket( ref packet, ref length );
IncomingPacketFilters.CheckPacket( ref packet, ref length );
IncomingPacketFilters.CheckPacket( ref packet, ref length );
bool result = IncomingPacketFilters.CheckPacket( ref packet, ref length );
Assert.IsTrue( result );
Assert.IsTrue( Engine.Journal.Count > 0 );
} );
}
[TestMethod]
public void WontSendToJournalFilteredMessagesDisabled()
{
AppDomain appDomain = AppDomain.CreateDomain( "WontSendToJournalFilteredMessagesDisabled",
AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation );
appDomain.DoCallBack( () =>
{
byte[] packet =
{
0x1C, 0x00, 0x4B, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x04, 0x81, 0x00, 0x03, 0x53, 0x79,
0x73, 0x74, 0x65, 0x6D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x61, 0x72, 0x67,
0x65, 0x74, 0x20, 0x69, 0x73, 0x20, 0x6E, 0x6F, 0x74, 0x20, 0x69, 0x6E, 0x20, 0x6C, 0x69, 0x6E,
0x65, 0x20, 0x6F, 0x66, 0x20, 0x73, 0x69, 0x67, 0x68, 0x74, 0x00
};
int length = packet.Length;
IncomingPacketFilters.Initialize();
RepeatedMessagesFilter.IsEnabled = true;
RepeatedMessagesFilter.FilterOptions.SendToJournal = false;
IncomingPacketFilters.CheckPacket( ref packet, ref length );
IncomingPacketFilters.CheckPacket( ref packet, ref length );
IncomingPacketFilters.CheckPacket( ref packet, ref length );
IncomingPacketFilters.CheckPacket( ref packet, ref length );
IncomingPacketFilters.CheckPacket( ref packet, ref length );
IncomingPacketFilters.CheckPacket( ref packet, ref length );
bool result = IncomingPacketFilters.CheckPacket( ref packet, ref length );
Assert.IsTrue( result );
Assert.AreEqual( 0, Engine.Journal.Count );
} );
}
}
}
@@ -0,0 +1,100 @@
using System;
using System.Text;
using ClassicAssist.Data;
using ClassicAssist.UO.Data;
using ClassicAssist.UO.Network;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ClassicAssist.Tests.Filters
{
[TestClass]
public class SavedPasswordsTests
{
[TestMethod]
public void WillSavePasswordIfEnabled()
{
AssistantOptions.SavedPasswords.Clear();
OutgoingPacketFilters.Initialize();
PacketWriter writer = new PacketWriter( 62 );
writer.Write( (byte) 0x80 );
writer.WriteAsciiFixed( "fakeusername", 30 );
writer.WriteAsciiFixed( "fakepassword", 30 );
writer.Write( (byte) 0 );
byte[] packet = writer.ToArray();
int length = packet.Length;
OutgoingPacketFilters.CheckPacket( ref packet, ref length );
Assert.AreEqual( 0, AssistantOptions.SavedPasswords.Count );
AssistantOptions.SavePasswords = true;
OutgoingPacketFilters.CheckPacket( ref packet, ref length );
Assert.AreEqual( 1, AssistantOptions.SavedPasswords.Count );
AssistantOptions.SavedPasswords.Clear();
}
[TestMethod]
public void WillSavePasswordOnlyIfBlanl()
{
AssistantOptions.SavedPasswords.Clear();
OutgoingPacketFilters.Initialize();
AssistantOptions.SavePasswords = true;
AssistantOptions.SavePasswordsOnlyBlank = true;
PacketWriter writer = new PacketWriter( 62 );
writer.Write( (byte) 0x80 );
writer.WriteAsciiFixed( "fakeusername", 30 );
writer.WriteAsciiFixed( "fakepassword", 30 );
writer.Write( (byte) 0 );
byte[] packet = writer.ToArray();
int length = packet.Length;
OutgoingPacketFilters.CheckPacket( ref packet, ref length );
Assert.AreEqual( 1, AssistantOptions.SavedPasswords.Count );
PacketWriter writer2 = new PacketWriter( 62 );
writer2.Write( (byte) 0x80 );
writer2.WriteAsciiFixed( "fakeusername", 30 );
writer2.WriteAsciiFixed( "", 30 );
writer2.Write( (byte) 0 );
byte[] packet2 = writer2.ToArray();
int length2 = packet2.Length;
OutgoingPacketFilters.CheckPacket( ref packet2, ref length2 );
byte[] tmp = new byte[30];
Buffer.BlockCopy( packet2, 31, tmp, 0, 30 );
Assert.AreEqual( "fakepassword", Encoding.ASCII.GetString( tmp ).TrimEnd( '\0' ) );
PacketWriter writer3 = new PacketWriter( 62 );
writer3.Write( (byte) 0x80 );
writer3.WriteAsciiFixed( "fakeusername", 30 );
writer3.WriteAsciiFixed( "butter", 30 );
writer3.Write( (byte) 0 );
byte[] packet3 = writer3.ToArray();
int length3 = packet3.Length;
OutgoingPacketFilters.CheckPacket( ref packet3, ref length3 );
byte[] tmp2 = new byte[30];
Buffer.BlockCopy( packet3, 31, tmp2, 0, 30 );
Assert.AreEqual( "butter", Encoding.ASCII.GetString( tmp2 ).TrimEnd( '\0' ) );
AssistantOptions.SavedPasswords.Clear();
}
}
}
File diff suppressed because one or more lines are too long
+31
View File
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using ClassicAssist.Shared;
using ClassicAssist.Data.Hotkeys.Commands;
using ClassicAssist.UI.Misc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ClassicAssist.Tests
{
[TestClass]
public class HotkeyTests
{
[TestMethod]
public void WillInstantiateAllHotkeysCommandsNoExceptions()
{
IEnumerable<Type> hotkeyCommands = Assembly.GetAssembly( typeof( Engine ) ).GetTypes()
.Where( i => i.IsSubclassOf( typeof( HotkeyCommand ) ) );
ObservableCollectionEx<HotkeyCommand> hotkeys = new ObservableCollectionEx<HotkeyCommand>();
foreach ( Type hotkeyCommand in hotkeyCommands )
{
HotkeyCommand hkc = (HotkeyCommand) Activator.CreateInstance( hotkeyCommand );
hotkeys.Add( hkc );
}
}
}
}
@@ -0,0 +1,129 @@
using ClassicAssist.Shared;
using ClassicAssist.UO.Data;
using ClassicAssist.UO.Network;
using ClassicAssist.UO.Network.Packets;
using ClassicAssist.UO.Objects;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ClassicAssist.Tests
{
[TestClass]
public class IncomingPacketHandlerTests
{
[TestInitialize]
public void Initialize()
{
Engine.Items = new ItemCollection( 0 );
Engine.Mobiles = new MobileCollection( Engine.Items );
Engine.Player = new PlayerMobile( 1 );
IncomingPacketHandlers.Initialize();
}
[TestMethod]
public void ContainerContentsWillAddToPlayerBackpack()
{
const int backpackSerial = 0x40000001;
const int itemSerial = 0x40000002;
Item backpack = new Item( backpackSerial, 1 ) { Layer = Layer.Backpack };
Engine.Player.SetLayer( Layer.Backpack, backpack.Serial );
Engine.Items.Add( backpack );
Assert.IsTrue( Engine.Player.Backpack.Serial > 0 );
ContainerContentsPacket cc =
new ContainerContentsPacket( new ItemCollection( backpackSerial ) { new Item( itemSerial ) } );
PacketHandler handler = IncomingPacketHandlers.GetHandler( 0x3C );
Assert.IsNotNull( handler );
byte[] packet = cc.ToArray();
handler.OnReceive( new PacketReader( packet, packet.Length, false ) );
Item item = Engine.Items.GetItem( backpackSerial );
Assert.IsNotNull( item.Container );
Assert.AreEqual( 1, item.Container.GetTotalItemCount() );
Assert.IsNotNull( Engine.Items.GetItem( itemSerial ) );
Assert.IsNotNull( item.Container.GetItem( itemSerial ) );
Engine.Items.Clear();
Engine.Player.SetLayer( Layer.Backpack, 0 );
}
[TestMethod]
public void WillSetPoisonedOnHealthbarColour()
{
Engine.Player = new PlayerMobile( 0x01 );
byte[] packet = { 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01 };
PacketHandler handler = IncomingPacketHandlers.GetHandler( 0x17 );
Assert.IsNotNull( handler );
handler.OnReceive( new PacketReader( packet, packet.Length, false ) );
Assert.IsTrue( Engine.Player.IsPoisoned );
packet = new byte[] { 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00 };
handler.OnReceive( new PacketReader( packet, packet.Length, false ) );
Assert.IsFalse( Engine.Player.IsPoisoned );
Engine.Player = null;
}
[TestMethod]
public void WillSetYellowHitsOnHealthbarColour()
{
Engine.Player = new PlayerMobile( 0x01 );
byte[] packet = { 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x01 };
PacketHandler handler = IncomingPacketHandlers.GetHandler( 0x17 );
Assert.IsNotNull( handler );
handler.OnReceive( new PacketReader( packet, packet.Length, false ) );
Assert.IsTrue( Engine.Player.IsYellowHits );
packet = new byte[] { 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x00 };
handler.OnReceive( new PacketReader( packet, packet.Length, false ) );
Assert.IsFalse( Engine.Player.IsYellowHits );
Engine.Player = null;
}
[TestMethod]
public void WillSetFrozenOnMobileStatus()
{
Engine.Player = new PlayerMobile( 0x01 );
Assert.IsFalse( Engine.Player.IsFrozen );
byte[] packet =
{
0x20, 0x00, 0x00, 0x00, 0x01, 0x01, 0x90, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00
};
PacketHandler handler = IncomingPacketHandlers.GetHandler( 0x20 );
Assert.IsNotNull( handler );
handler.OnReceive( new PacketReader( packet, packet.Length, true ) );
Assert.IsTrue( Engine.Player.IsFrozen );
Engine.Player = null;
}
}
}
@@ -0,0 +1,227 @@
using System.Threading;
using ClassicAssist.Shared;
using ClassicAssist.Data.Abilities;
using ClassicAssist.Data.Macros.Commands;
using ClassicAssist.UO.Objects;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ClassicAssist.Tests.MacroCommands
{
[TestClass]
public class AbilitiesCommandsTest
{
private readonly AutoResetEvent _are = new AutoResetEvent( false );
[TestMethod]
public void WillOnlySetPrimaryAbilityOnce()
{
AbilitiesManager manager = AbilitiesManager.GetInstance();
Engine.Player = new PlayerMobile( 0x01 );
Engine.InternalPacketSentEvent += ExpectAbilityPacket;
AbilitiesCommands.SetAbility( "primary", "on" );
bool result = _are.WaitOne( 5000 );
if ( !result )
{
Assert.Fail();
}
Assert.AreEqual( AbilityType.Primary, manager.Enabled );
Assert.IsTrue( manager.IsPrimaryEnabled );
Engine.InternalPacketSentEvent -= ExpectAbilityPacket;
Engine.InternalPacketSentEvent += NotExpectAbilityPacket;
AbilitiesCommands.SetAbility( "primary", "on" );
Engine.InternalPacketSentEvent -= NotExpectAbilityPacket;
AbilitiesCommands.ClearAbility();
Engine.Player = null;
}
[TestMethod]
public void WillTogglePrimaryAbility()
{
AbilitiesManager manager = AbilitiesManager.GetInstance();
Engine.Player = new PlayerMobile( 0x01 );
Engine.InternalPacketSentEvent += ExpectAbilityPacket;
AbilitiesCommands.SetAbility( "primary" );
bool result = _are.WaitOne( 5000 );
if ( !result )
{
Assert.Fail();
}
Assert.AreEqual( AbilityType.Primary, manager.Enabled );
Assert.IsTrue( manager.IsPrimaryEnabled );
AbilitiesCommands.SetAbility( "primary" );
result = _are.WaitOne( 5000 );
if ( !result )
{
Assert.Fail();
}
Assert.AreEqual( AbilityType.None, manager.Enabled );
Assert.IsFalse( manager.IsPrimaryEnabled );
Engine.InternalPacketSentEvent -= ExpectAbilityPacket;
Engine.Player = null;
}
[TestMethod]
public void WillOnlySetSecondaryAbilityOnce()
{
AbilitiesManager manager = AbilitiesManager.GetInstance();
Engine.Player = new PlayerMobile( 0x01 );
Engine.InternalPacketSentEvent += ExpectAbilityPacket;
AbilitiesCommands.SetAbility( "secondary", "on" );
bool result = _are.WaitOne( 5000 );
if ( !result )
{
Assert.Fail();
}
Assert.AreEqual( AbilityType.Secondary, manager.Enabled );
Assert.IsTrue( manager.IsSecondaryEnabled );
Engine.InternalPacketSentEvent -= ExpectAbilityPacket;
Engine.InternalPacketSentEvent += NotExpectAbilityPacket;
AbilitiesCommands.SetAbility( "secondary", "on" );
Engine.InternalPacketSentEvent -= NotExpectAbilityPacket;
AbilitiesCommands.ClearAbility();
Engine.Player = null;
}
[TestMethod]
public void WillToggleSecondaryAbility()
{
AbilitiesManager manager = AbilitiesManager.GetInstance();
Engine.Player = new PlayerMobile( 0x01 );
Engine.InternalPacketSentEvent += ExpectAbilityPacket;
AbilitiesCommands.SetAbility( "secondary" );
bool result = _are.WaitOne( 5000 );
if ( !result )
{
Assert.Fail();
}
Assert.AreEqual( AbilityType.Secondary, manager.Enabled );
Assert.IsTrue( manager.IsSecondaryEnabled );
AbilitiesCommands.SetAbility( "secondary" );
result = _are.WaitOne( 5000 );
if ( !result )
{
Assert.Fail();
}
Assert.AreEqual( AbilityType.None, manager.Enabled );
Assert.IsFalse( manager.IsSecondaryEnabled );
Engine.InternalPacketSentEvent -= ExpectAbilityPacket;
Engine.Player = null;
}
[TestMethod]
public void WillClearAbilities()
{
Engine.Player = new PlayerMobile( 0x01 );
AbilitiesManager manager = AbilitiesManager.GetInstance();
Engine.InternalPacketSentEvent += ExpectAbilityPacket;
manager.Enabled = AbilityType.Primary;
AbilitiesCommands.ClearAbility();
bool result = _are.WaitOne( 5000 );
if ( !result )
{
Assert.Fail();
}
Assert.AreEqual( AbilityType.None, manager.Enabled );
manager.Enabled = AbilityType.Secondary;
AbilitiesCommands.ClearAbility();
result = _are.WaitOne( 5000 );
if ( !result )
{
Assert.Fail();
}
Assert.AreEqual( AbilityType.None, manager.Enabled );
Engine.InternalPacketSentEvent -= ExpectAbilityPacket;
Engine.Player = null;
}
[TestMethod]
public void WontSetAbilitySetOff()
{
Engine.Player = new PlayerMobile( 0x01 );
Engine.InternalPacketSentEvent += NotExpectAbilityPacket;
AbilitiesCommands.SetAbility( "primary", "off" );
Assert.AreEqual( AbilityType.None, AbilitiesManager.GetInstance().Enabled );
Engine.Player = null;
}
private static void NotExpectAbilityPacket( byte[] data, int length )
{
if ( data[0] == 0xD7 && data[8] == 0x19 )
{
Assert.Fail();
}
}
private void ExpectAbilityPacket( byte[] data, int length )
{
if ( data[0] == 0xD7 && data[8] == 0x19 )
{
_are.Set();
}
}
}
}
@@ -0,0 +1,368 @@
using System;
using System.Text;
using System.Threading;
using ClassicAssist.Shared;
using ClassicAssist.Data.Macros.Commands;
using ClassicAssist.UO.Data;
using ClassicAssist.UO.Network;
using ClassicAssist.UO.Objects;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ClassicAssist.Tests.MacroCommands
{
[TestClass]
public class ActionCommandTests
{
[TestInitialize]
public void Initialize()
{
Engine.ClientVersion = new Version( 7, 0, 45, 1 );
}
[TestMethod]
public void AttackWillSendAttackPacket()
{
AutoResetEvent are = new AutoResetEvent( false );
void OnInternalPacketSentEvent( byte[] data, int length )
{
if ( data[0] != 0x05 )
{
return;
}
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
Assert.AreEqual( 0x00aabbcc, serial );
are.Set();
}
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
ActionCommands.Attack( 0x00aabbcc );
bool result = are.WaitOne( 5000 );
Assert.IsTrue( result );
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
}
[TestMethod]
public void ClearHandsWillSendDragPacket()
{
AutoResetEvent are = new AutoResetEvent( false );
void OnInternalPacketSentEvent( byte[] data, int length )
{
if ( data[0] != 0x07 )
{
return;
}
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
Assert.AreEqual( 0x00aabbcc, serial );
are.Set();
}
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
Engine.Player = new PlayerMobile( 0x01 );
Engine.Player.SetLayer( Layer.OneHanded, 0x00aabbcc );
ActionCommands.ClearHands( "left" );
bool result = are.WaitOne( 5000 );
Assert.IsTrue( result );
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
Engine.Player = null;
}
[TestMethod]
public void ClickObjectWillSendPacket()
{
AutoResetEvent are = new AutoResetEvent( false );
void OnInternalPacketSentEvent( byte[] data, int length )
{
if ( data[0] != 0x09 )
{
return;
}
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
Assert.AreEqual( 0x00aabbcc, serial );
are.Set();
}
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
AliasCommands.SetAlias( "thing", 0x00aabbcc );
ActionCommands.ClickObject( "thing" );
bool result = are.WaitOne( 5000 );
Assert.IsTrue( result );
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
Engine.Player = null;
}
[TestMethod]
public void MoveItemWillSendDragPacket()
{
AutoResetEvent are = new AutoResetEvent( false );
void OnInternalPacketSentEvent( byte[] data, int length )
{
if ( data[0] != 0x07 )
{
return;
}
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
Assert.AreEqual( 0x00aabbcc, serial );
are.Set();
}
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
Engine.Items.Add( new Item( 0x00aabbcc ) { Count = 50 } );
ObjectCommands.MoveItem( 0x00aabbcc, 0xaabbdd );
bool result = are.WaitOne( 5000 );
Assert.IsTrue( result );
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
}
[TestMethod]
public void FeedWillSendDragPacket()
{
PlayerMobile player = new PlayerMobile( 0x01 );
Item backpack = new Item( 0x02 )
{
Container = new ItemCollection( 0x02 ) { new Item( 0x00aabbcc ) { ID = 0xff, Count = 1 } },
Owner = 0x01,
Layer = Layer.Backpack
};
player.SetLayer( Layer.Backpack, 0x02 );
Engine.Player = player;
Engine.Items.Add( backpack );
AutoResetEvent are = new AutoResetEvent( false );
void OnInternalPacketSentEvent( byte[] data, int length )
{
if ( data[0] != 0x07 )
{
return;
}
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
Assert.AreEqual( 0x00aabbcc, serial );
are.Set();
}
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
ActionCommands.Feed( 0x01, 0xff );
bool result = are.WaitOne( 5000 );
Assert.IsTrue( result );
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
Engine.Items.Clear();
Engine.Player = null;
}
[TestMethod]
public void RenameWillSendRenamePacket()
{
AutoResetEvent are = new AutoResetEvent( false );
void OnInternalPacketSentEvent( byte[] data, int length )
{
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
Assert.AreEqual( 0x00aabbcc, serial );
string name = Encoding.ASCII.GetString( data, 5, 30 ).TrimEnd( '\0' );
Assert.AreEqual( "Snorlax", name );
are.Set();
}
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
ActionCommands.Rename( 0x00aabbcc, "Snorlax" );
bool result = are.WaitOne( 5000 );
Assert.IsTrue( result );
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
}
[TestMethod]
public void ShowNamesWillSendLookRequest()
{
PlayerMobile player = new PlayerMobile( 0x01 );
Mobile mobile = new Mobile( 0x00aabbcc );
Engine.Player = player;
Engine.Mobiles.Add( mobile );
AutoResetEvent are = new AutoResetEvent( false );
void OnInternalPacketSentEvent( byte[] data, int length )
{
Assert.AreEqual( 0x09, data[0] );
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
Assert.AreEqual( 0x00aabbcc, serial );
are.Set();
}
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
ActionCommands.ShowNames( "mobiles" );
bool result = are.WaitOne( 5000 );
Assert.IsTrue( result );
Engine.Mobiles.Remove( mobile );
Engine.Items.Add( new Item( 0x00aabbcc ) { ID = 0x2006 } );
ActionCommands.ShowNames( "corpses" );
result = are.WaitOne( 5000 );
Assert.IsTrue( result );
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
Engine.Player = null;
Engine.Mobiles.Clear();
Engine.Items.Clear();
}
[TestMethod]
public void EquipItemWillSendDragPacket()
{
AutoResetEvent are = new AutoResetEvent( false );
void OnInternalPacketSentEvent( byte[] data, int length )
{
if ( data[0] != 0x07 )
{
return;
}
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
Assert.AreEqual( 0x00aabbcc, serial );
are.Set();
}
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
Engine.Items.Add( new Item( 0x00aabbcc ) );
Engine.Player = new PlayerMobile( 0x01 );
ActionCommands.EquipItem( 0x00aabbcc, Layer.OneHanded );
bool result = are.WaitOne( 5000 );
Assert.IsTrue( result );
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
Engine.Player = null;
Engine.Items.Clear();
}
[TestMethod]
public void EquipTypeWillSendDragPacket()
{
Item backpack = new Item( 0x40000000 ) { Owner = 1, Container = new ItemCollection( 0x40000000 ) };
Engine.Player = new PlayerMobile( 1 ) { Equipment = { backpack } };
Engine.Player.SetLayer( Layer.Backpack, backpack.Serial );
Engine.Items.Add( backpack );
Item item = new Item( 0x40000001, backpack.Serial ) { ID = 0xff };
backpack.Container.Add( item );
AutoResetEvent are = new AutoResetEvent( false );
void OnInternalPacketSentEvent( byte[] data, int length )
{
if ( data[0] != 0x07 )
{
return;
}
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
Assert.AreEqual( item.Serial, serial );
are.Set();
}
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
ActionCommands.EquipType( item.ID, Layer.OneHanded );
bool result = are.WaitOne( 5000 );
Assert.IsTrue( result );
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
Engine.Player = null;
Engine.Items.Clear();
}
[TestMethod]
public void WillFindLayer()
{
Engine.Player = new PlayerMobile( 1 );
Engine.Player.SetLayer( Layer.OneHanded, 0x40000001 );
AliasCommands.SetAlias( "self", Engine.Player.Serial );
Assert.IsTrue( ActionCommands.FindLayer( "OneHanded" ) );
Assert.IsFalse( ActionCommands.FindLayer( "TwoHanded" ) );
AliasCommands.UnsetAlias( "self" );
Engine.Player = null;
}
[TestCleanup]
public void Cleanup()
{
ActionPacketQueue.Clear();
}
}
}
@@ -0,0 +1,283 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ClassicAssist.Shared;
using ClassicAssist.Data.Counters;
using ClassicAssist.Data.Macros.Commands;
using ClassicAssist.Data.Organizer;
using ClassicAssist.UO.Data;
using ClassicAssist.UO.Network.PacketFilter;
using ClassicAssist.UO.Objects;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ClassicAssist.Tests.MacroCommands
{
[TestClass]
public class AgentTests
{
[TestMethod]
public void CounterWillCountType()
{
PlayerMobile player = new PlayerMobile( 0x01 );
Item backpack = new Item( 0x02 ) { Layer = Layer.Backpack, Container = new ItemCollection( 0x02 ) };
player.SetLayer( Layer.Backpack, backpack.Serial );
Engine.Items.Add( backpack );
Engine.Player = player;
CountersManager manager = CountersManager.GetInstance();
manager.Items.Add( new CountersAgentEntry { Name = "test", Color = -1, Graphic = 0xff } );
backpack.Container.Add( new Item( 0x03 ) { ID = 0xff, Owner = 0x02, Count = 1 } );
manager.RecountAll = () =>
{
foreach ( CountersAgentEntry entry in manager.Items )
{
entry.Recount();
}
};
manager.RecountAll();
int count = AgentCommands.Counter( "test" );
Assert.AreEqual( 1, count );
}
[TestMethod]
public void WillOrganizeLimitAmount()
{
AppDomain appDomain = AppDomain.CreateDomain( "WillOrganizeLimitAmount", AppDomain.CurrentDomain.Evidence,
AppDomain.CurrentDomain.SetupInformation );
appDomain.DoCallBack( () =>
{
Dictionary<int, int> serialAmount = new Dictionary<int, int>();
void OnInternalPacketSentEvent( byte[] data, int length )
{
if ( data[0] == 0x07 )
{
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
int amount = ( data[5] << 8 ) | data[6];
if ( serialAmount.ContainsKey( serial ) )
{
serialAmount.Remove( serial );
}
serialAmount.Add( serial, amount );
}
if ( data[0] == 0x08 )
{
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
int containerSerial = ( data[11] << 24 ) | ( data[12] << 16 ) | ( data[13] << 8 ) | data[14];
Item sourceItem = Engine.Items.GetItem( serial );
Item containerItem = Engine.Items.GetItem( containerSerial );
if ( serialAmount.ContainsKey( serial ) )
{
sourceItem.Count = serialAmount[serial];
}
containerItem.Container.Add( sourceItem );
}
}
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
OrganizerEntry entry = new OrganizerEntry();
entry.Items.Add( new OrganizerItem { ID = 0xff, Item = "Shmoo", Amount = 10 } );
Item sourceContainer = new Item( 0x40000004 ) { Container = new ItemCollection( 0x40000004 ) };
sourceContainer.Container.Add(
new Item( 0x40000005, 0x40000004 ) { ID = 0xff, Count = 5, Owner = 0x40000004 } );
sourceContainer.Container.Add(
new Item( 0x40000006, 0x40000004 ) { ID = 0xff, Count = 100, Owner = 0x40000004 } );
Engine.Items.Add( sourceContainer );
Item destinationContainer = new Item( 0x40000007 ) { Container = new ItemCollection( 0x40000007 ) };
Engine.Items.Add( destinationContainer );
entry.SourceContainer = sourceContainer.Serial;
entry.DestinationContainer = destinationContainer.Serial;
Engine.PacketWaitEntries = new PacketWaitEntries();
OrganizerManager.GetInstance().Organize( entry ).Wait();
Item[] destinationItems = destinationContainer.Container.GetItems();
Assert.AreEqual( entry.Items[0].Amount,
destinationItems.Sum( i => i.ID == entry.Items[0].ID ? i.Count : 0 ) );
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
Engine.Items.Clear();
Engine.PacketWaitEntries = null;
} );
}
[TestMethod]
public void WillOrganizeNoLimit()
{
AppDomain appDomain = AppDomain.CreateDomain( "WillOrganizeNoLimit", AppDomain.CurrentDomain.Evidence,
AppDomain.CurrentDomain.SetupInformation );
appDomain.DoCallBack( () =>
{
Dictionary<int, int> serialAmount = new Dictionary<int, int>();
void OnInternalPacketSentEvent( byte[] data, int length )
{
if ( data[0] == 0x07 )
{
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
int amount = ( data[5] << 8 ) | data[6];
if ( serialAmount.ContainsKey( serial ) )
{
serialAmount.Remove( serial );
}
serialAmount.Add( serial, amount );
}
if ( data[0] == 0x08 )
{
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
int containerSerial = ( data[11] << 24 ) | ( data[12] << 16 ) | ( data[13] << 8 ) | data[14];
Item sourceItem = Engine.Items.GetItem( serial );
Item containerItem = Engine.Items.GetItem( containerSerial );
if ( serialAmount.ContainsKey( serial ) )
{
sourceItem.Count = serialAmount[serial];
}
containerItem.Container.Add( sourceItem );
}
}
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
OrganizerEntry entry = new OrganizerEntry();
entry.Items.Add( new OrganizerItem { ID = 0xff, Item = "Shmoo", Amount = -1 } );
int amnt = 13013;
Item sourceContainer = new Item( 0x40000004 ) { Container = new ItemCollection( 0x40000004 ) };
sourceContainer.Container.Add(
new Item( 0x40000005, 0x40000004 ) { ID = 0xff, Count = amnt, Owner = 0x40000004 } );
Engine.Items.Add( sourceContainer );
Item destinationContainer = new Item( 0x40000007 ) { Container = new ItemCollection( 0x40000007 ) };
Engine.Items.Add( destinationContainer );
entry.SourceContainer = sourceContainer.Serial;
entry.DestinationContainer = destinationContainer.Serial;
Engine.PacketWaitEntries = new PacketWaitEntries();
OrganizerManager.GetInstance().Organize( entry ).Wait();
Item[] destinationItems = destinationContainer.Container.GetItems();
Assert.AreEqual( amnt, destinationItems.Sum( i => i.Count ) );
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
Engine.Items.Clear();
Engine.PacketWaitEntries = null;
} );
}
[TestMethod]
public void WillOrganizeNoLimitMultiple()
{
AppDomain appDomain = AppDomain.CreateDomain( "WillOrganizeNoLimitMultiple",
AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation );
appDomain.DoCallBack( () =>
{
Dictionary<int, int> serialAmount = new Dictionary<int, int>();
void OnInternalPacketSentEvent( byte[] data, int length )
{
if ( data[0] == 0x07 )
{
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
int amount = ( data[5] << 8 ) | data[6];
if ( serialAmount.ContainsKey( serial ) )
{
serialAmount.Remove( serial );
}
serialAmount.Add( serial, amount );
}
if ( data[0] == 0x08 )
{
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
int containerSerial = ( data[11] << 24 ) | ( data[12] << 16 ) | ( data[13] << 8 ) | data[14];
Item sourceItem = Engine.Items.GetItem( serial );
Item containerItem = Engine.Items.GetItem( containerSerial );
if ( serialAmount.ContainsKey( serial ) )
{
sourceItem.Count = serialAmount[serial];
}
containerItem.Container.Add( sourceItem );
}
}
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
OrganizerEntry entry = new OrganizerEntry();
entry.Items.Add( new OrganizerItem { ID = 0xff, Item = "Shmoo", Amount = -1 } );
entry.Items.Add( new OrganizerItem { ID = 0xfe, Item = "Shmoo", Amount = -1 } );
int amnt = 13013;
Item sourceContainer = new Item( 0x40000004 ) { Container = new ItemCollection( 0x40000004 ) };
sourceContainer.Container.Add(
new Item( 0x40000005, 0x40000004 ) { ID = 0xff, Count = amnt, Owner = 0x40000004 } );
sourceContainer.Container.Add(
new Item( 0x40000006, 0x40000004 ) { ID = 0xfe, Count = amnt, Owner = 0x40000004 } );
Engine.Items.Add( sourceContainer );
Item destinationContainer = new Item( 0x40000007 ) { Container = new ItemCollection( 0x40000007 ) };
Engine.Items.Add( destinationContainer );
entry.SourceContainer = sourceContainer.Serial;
entry.DestinationContainer = destinationContainer.Serial;
Engine.PacketWaitEntries = new PacketWaitEntries();
OrganizerManager.GetInstance().Organize( entry ).Wait();
Item[] destinationItems = destinationContainer.Container.GetItems();
Assert.AreEqual( 2, destinationContainer.Container.GetTotalItemCount() );
Assert.AreEqual( amnt * 2, destinationItems.Sum( i => i.Count ) );
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
Engine.Items.Clear();
Engine.PacketWaitEntries = null;
} );
}
}
}
@@ -0,0 +1,52 @@
using ClassicAssist.Shared;
using ClassicAssist.Data.Macros.Commands;
using ClassicAssist.UO.Data;
using ClassicAssist.UO.Network;
using ClassicAssist.UO.Objects;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ClassicAssist.Tests.MacroCommands
{
[TestClass]
public class AliasCommandTests
{
private PlayerMobile _player;
[TestInitialize]
public void Initialize()
{
_player = new PlayerMobile( 0x01 );
Engine.Player = _player;
}
[TestMethod]
public void WillSetDefaultAliases()
{
AliasCommands.SetDefaultAliases();
Assert.AreEqual( _player.Serial, AliasCommands.GetAlias( "self" ) );
}
[TestMethod]
public void WillChangeLastAliasOnTargetSent()
{
_player.LastTargetSerial = 0x02;
AliasCommands.SetDefaultAliases();
Assert.AreEqual( 0x02, AliasCommands.GetAlias( "last" ) );
OutgoingPacketHandlers.Initialize();
PacketHandler handler = OutgoingPacketHandlers.GetHandler( 0x6C );
byte[] packet =
{
0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
handler?.OnReceive( new PacketReader( packet, packet.Length, true ) );
Assert.AreEqual( 0xAABBCCDD, (uint) AliasCommands.GetAlias( "last" ) );
}
}
}
@@ -0,0 +1,150 @@
using System.Diagnostics;
using System.IO;
using ClassicAssist.Shared;
using ClassicAssist.Data;
using ClassicAssist.Data.Macros.Commands;
using ClassicAssist.UO.Data;
using ClassicAssist.UO.Network;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ClassicAssist.Tests.MacroCommands
{
[TestClass]
public class JournalCommandsTests
{
[TestMethod]
public void WillMatchSystem()
{
Engine.Journal.Write( new JournalEntry
{
Text = "You are now under the protection of town guards.", SpeechType = JournalSpeech.System
} );
Assert.IsTrue( JournalCommands.InJournal( "town guards", "system" ) );
Engine.Journal.Clear();
}
[TestMethod]
public void WillMatchSystemRegular()
{
const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";
if ( !Directory.Exists( localPath ) )
{
Debug.WriteLine( "Not running test, requires Cliloc.enu" );
return;
}
Cliloc.Initialize( localPath );
byte[] packet =
{
0xC1, 0x00, 0x32, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x03, 0xB2, 0x00, 0x03, 0x00, 0x07,
0xA4, 0xE1, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00
};
IncomingPacketHandlers.Initialize();
PacketHandler handler = IncomingPacketHandlers.GetHandler( 0xc1 );
Assert.IsNotNull( handler );
handler.OnReceive( new PacketReader( packet, packet.Length, false ) );
Assert.IsTrue( JournalCommands.InJournal( "fingers slip!", "system" ) );
}
[TestMethod]
public void WillMatchAuthor()
{
Engine.Journal.Write( new JournalEntry
{
Text = "The quick brown bow jumped over the lazy dog.",
SpeechType = JournalSpeech.Say,
Name = "Tony"
} );
Assert.IsTrue( JournalCommands.InJournal( "lazy dog", "tony" ) );
Engine.Journal.Clear();
}
[TestMethod]
public void WillMatchAny()
{
Engine.Journal.Write( new JournalEntry
{
Text = "You are now under the protection of town guards.", SpeechType = JournalSpeech.System
} );
Engine.Journal.Write( new JournalEntry
{
Text = "The quick brown bow jumped over the lazy dog.",
SpeechType = JournalSpeech.Say,
Name = "Tony"
} );
Assert.IsTrue( JournalCommands.InJournal( "town guards" ) );
Assert.IsTrue( JournalCommands.InJournal( "lazy dog" ) );
Engine.Journal.Clear();
}
[TestMethod]
public void WillClearJournal()
{
Engine.Journal.Write( new JournalEntry
{
Text = "The quick brown bow jumped over the lazy dog.",
SpeechType = JournalSpeech.Say,
Name = "Tony"
} );
JournalCommands.ClearJournal();
Assert.AreEqual( 0, Engine.Journal.Count );
Engine.Journal.Clear();
}
//[TestMethod]
//public void WaitForJournalWillMatch()
//{
// const string text = "You are now under the protection of town guards.";
// byte[] textBytes = Encoding.Unicode.GetBytes( text );
// PacketWriter pw = new PacketWriter( 48 + textBytes.Length );
// pw.Write( (byte) 0xAE );
// pw.Write( (short) ( 48 + textBytes.Length ));
// pw.Write((int)0 );
// pw.Write( (short) 0 );
// pw.Write((byte)1 ); // system
// pw.Seek( 39, SeekOrigin.Current );
// pw.Write(textBytes, 0, textBytes.Length );
// IncomingPacketHandlers.Initialize();
// PacketHandler handler = IncomingPacketHandlers.GetHandler( 0xAE );
// Task<bool> t = Task.Run(() => JournalCommands.WaitForJournal("town guards", 20000, "system"));
// handler?.OnReceive(new PacketReader( pw.ToArray(), pw.ToArray().Length, false ));
// bool finished = t.Wait( 20000 );
// Assert.IsTrue( finished );
// bool result = t.Result;
// Assert.IsTrue( result );
// Engine.Journal.Clear();
//}
}
}
@@ -0,0 +1,41 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using static ClassicAssist.Data.Macros.Commands.ListCommands;
namespace ClassicAssist.Tests.MacroCommands
{
[TestClass]
public class ListCommandTests
{
[TestInitialize]
public void Initialize()
{
CreateList( "shmoo" );
PushList( "shmoo", 0 );
PushList( "shmoo", 1 );
}
[TestMethod]
public void ListExistsWillReturnTrue()
{
Assert.IsTrue( ListExists( "shmoo" ) );
}
[TestMethod]
public void GetListWillReturnArray()
{
Assert.IsTrue( GetList( "shmoo" ) is int[] _ );
}
[TestMethod]
public void ListCountWillReturnCorrect()
{
Assert.AreEqual( 2, List( "shmoo" ) );
}
[TestCleanup]
public void Cleanup()
{
RemoveList( "shmoo" );
}
}
}
@@ -0,0 +1,213 @@
using ClassicAssist.Shared;
using ClassicAssist.Data.Macros.Commands;
using ClassicAssist.Data.SpecialMoves;
using ClassicAssist.UO.Data;
using ClassicAssist.UO.Network;
using ClassicAssist.UO.Objects;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ClassicAssist.Tests.MacroCommands
{
[TestClass]
public class MobileCommandTests
{
private PlayerMobile _player;
[TestInitialize]
public void Initialize()
{
_player = new PlayerMobile( 0x01 ) { Name = "Shmoo", Notoriety = Notoriety.Murderer };
Engine.Player = _player;
AliasCommands.SetAlias( "self", 0x01 );
}
[TestMethod]
public void WillGetName()
{
string name = EntityCommands.Name( "self" );
Assert.AreEqual( "Shmoo", name );
}
[TestMethod]
public void WillTrimNameItem()
{
Engine.Items.Add( new Item( 0x40000000 ) { Name = " need trim " } );
Assert.AreEqual( "need trim", EntityCommands.Name( 0x40000000 ) );
Assert.AreEqual( string.Empty, EntityCommands.Name( 0x40000001 ) );
Engine.Items.Remove( 0x40000000 );
}
[TestMethod]
public void WillGetNotoriety()
{
Assert.IsTrue( NotorietyCommands.Murderer( "self" ) );
}
[TestMethod]
public void WillGetHitsNoParam()
{
_player.Hits = 100;
int val = MobileCommands.Hits();
Assert.AreEqual( 100, val );
_player.Hits = 0;
}
[TestMethod]
public void WillGetHitsSerialParam()
{
Mobile mobile = new Mobile( 2 ) { Hits = 200 };
Engine.Mobiles.Add( mobile );
int val = MobileCommands.Hits( mobile.Serial );
Assert.AreEqual( 200, val );
Engine.Mobiles.Remove( mobile );
}
[TestMethod]
public void WillGetHitsStringParam()
{
Mobile mobile = new Mobile( 2 ) { Hits = 250 };
Engine.Mobiles.Add( mobile );
AliasCommands.SetAlias( "mobile", mobile.Serial );
int val = MobileCommands.Hits( "mobile" );
Assert.AreEqual( 250, val );
Engine.Mobiles.Remove( mobile );
}
[TestMethod]
public void WillGetHiddenNoParam()
{
_player.Status |= MobileStatus.Hidden;
_player.Status |= MobileStatus.Female;
bool hidden = MobileCommands.Hidden();
Assert.IsTrue( hidden );
}
[TestMethod]
public void WillGetDead()
{
Assert.IsFalse( MobileCommands.Dead() );
_player.ID = 0x192;
Assert.IsTrue( MobileCommands.Dead() );
_player.ID = 0x190;
}
[TestMethod]
public void WillGetDeadParam()
{
Mobile m = new Mobile( 2 );
Engine.Mobiles.Add( m );
Assert.IsFalse( MobileCommands.Dead( 2 ) );
m.ID = 0x192;
Assert.IsTrue( MobileCommands.Dead( 2 ) );
Engine.Mobiles.Remove( m );
}
[TestMethod]
public void WillGetMountedParam()
{
Item mount = new Item( 2 );
Engine.Items.Add( mount );
AliasCommands.SetAlias( "self", 1 );
AliasCommands.SetAlias( "mount", 2 );
Assert.IsFalse( MobileCommands.Mounted( "self" ) );
_player.SetLayer( Layer.Mount, 2 );
Assert.IsTrue( MobileCommands.Mounted( "self" ) );
Engine.Items.Remove( mount );
_player.SetLayer( Layer.Mount, 0 );
}
[TestMethod]
public void WillGetMaxHits()
{
_player.HitsMax = 100;
Assert.AreEqual( 100, MobileCommands.MaxHits( _player.Serial ) );
}
[TestMethod]
public void WillGetHits()
{
_player.Hits = 100;
Assert.AreEqual( 100, MobileCommands.Hits( _player.Serial ) );
}
[TestMethod]
public void WillGetDiffHits()
{
_player.Hits = 90;
_player.HitsMax = 100;
Assert.AreEqual( 10, MobileCommands.DiffHits( _player.Serial ) );
}
[TestMethod]
public void WillGetStats()
{
_player.Strength = 100;
_player.Int = 90;
_player.Dex = 25;
Assert.AreEqual( 100, MobileCommands.Str() );
Assert.AreEqual( 90, MobileCommands.Int() );
Assert.AreEqual( 25, MobileCommands.Dex() );
}
[TestMethod]
public void WillEnableDisableSpecialMove()
{
SpecialMovesManager manager = SpecialMovesManager.GetInstance();
byte[] enablePacket = { 0xBF, 0x00, 0x08, 0x00, 0x25, 0x01, 0xF6, 0x01 };
byte[] disablePacket = { 0xBF, 0x00, 0x08, 0x00, 0x25, 0x01, 0xF6, 0x00 };
IncomingPacketHandlers.Initialize();
PacketHandler handler = IncomingPacketHandlers.GetHandler( 0xBF );
handler?.OnReceive( new PacketReader( enablePacket, enablePacket.Length, false ) );
bool result = EntityCommands.SpecialMoveExists( "Death Strike" );
Assert.IsTrue( result );
handler?.OnReceive( new PacketReader( disablePacket, disablePacket.Length, false ) );
result = EntityCommands.SpecialMoveExists( "Death Strike" );
Assert.IsFalse( result );
}
}
}
@@ -0,0 +1,245 @@
using System.Threading;
using ClassicAssist.Shared;
using ClassicAssist.Data.Macros.Commands;
using ClassicAssist.UO.Data;
using ClassicAssist.UO.Network;
using ClassicAssist.UO.Objects;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ClassicAssist.Tests.MacroCommands
{
[TestClass]
public class ObjectCommandTests
{
[TestMethod]
public void WillFindTypeGround()
{
Engine.Items.Add( new Item( 0x40000001 ) { ID = 0xdda } );
bool result = ObjectCommands.FindType( 0xdda );
Assert.IsTrue( result );
int val = AliasCommands.GetAlias( "found" );
Assert.AreEqual( 0x40000001, val );
Engine.Items.Clear();
}
[TestMethod]
public void WillFindTypeGroundMobile()
{
Engine.Mobiles.Add( new Mobile( 0x02 ) { ID = 0x190 } );
bool result = ObjectCommands.FindType( 0x190 );
Assert.IsTrue( result );
int val = AliasCommands.GetAlias( "found" );
Assert.AreEqual( 0x02, val );
Engine.Mobiles.Clear();
}
[TestMethod]
public void WillFindTypeSubcontainer()
{
Item container = new Item( 1 )
{
Container = new ItemCollection( 1 ) { new Item( 0x02 ) { ID = 0xdda, Owner = 1 } }
};
Engine.Items.Add( container );
AliasCommands.SetAlias( "cont", 1 );
bool result = ObjectCommands.FindType( 0xdda, -1, "cont" );
Assert.IsTrue( result );
int val = AliasCommands.GetAlias( "found" );
Assert.AreEqual( 0x02, val );
Engine.Items.Clear();
}
[TestMethod]
public void WillFindTypeInRange()
{
Engine.Player = new PlayerMobile( 1 );
Engine.Mobiles.Add( new Mobile( 0x02 ) { ID = 0x190, X = 5, Y = 5 } );
bool result = ObjectCommands.FindType( 0x190, 8 );
Assert.IsTrue( result );
Engine.Mobiles.Clear();
Engine.Player = null;
}
[TestMethod]
public void WontFindTypeOutOfRange()
{
Engine.Player = new PlayerMobile( 1 );
Engine.Mobiles.Add( new Mobile( 0x02 ) { ID = 0x190, X = 5, Y = 5 } );
bool result = ObjectCommands.FindType( 0x190, 1 );
Assert.IsFalse( result );
Engine.Mobiles.Clear();
Engine.Player = null;
}
[TestMethod]
public void WillIgnoreObject()
{
Engine.Mobiles.Add( new Mobile( 0x02 ) { ID = 0x190, X = 5, Y = 5 } );
bool result = ObjectCommands.FindType( 0x190 );
Assert.IsTrue( result );
ObjectCommands.IgnoreObject( "found" );
result = ObjectCommands.FindType( 0x190 );
Assert.IsFalse( result );
Engine.Mobiles.Clear();
ObjectCommands.ClearIgnoreList();
}
[TestMethod]
public void WillCountType()
{
PlayerMobile player = new PlayerMobile( 1 );
Item backpack =
new Item( 0x40000001 ) { ID = 0xff, Owner = 0x01, Container = new ItemCollection( 0x40000001 ) };
Engine.Player = player;
Engine.Items.Add( backpack );
player.SetLayer( Layer.Backpack, 0x40000001 );
backpack.Container.Add( new Item( 0x40000002 ) { ID = 0xFE, Owner = 0x40000001 } );
int count = ObjectCommands.CountType( 0xfe, 0x40000001 );
Assert.AreEqual( 1, count );
Engine.Items.Clear();
Engine.Player = null;
}
[TestMethod]
public void WillCountMobileGround()
{
Engine.Player = new PlayerMobile( 0x01 );
Mobile mobile = new Mobile( 0x02 ) { ID = 0x190 };
Mobile mobile2 = new Mobile( 0x03 ) { ID = 0x191 };
Engine.Mobiles.Add( mobile );
Engine.Mobiles.Add( mobile2 );
int count = ObjectCommands.CountTypeGround( 0x190, -1, 5 );
Assert.AreEqual( 1, count );
Engine.Mobiles.Clear();
Engine.Player = null;
}
[TestMethod]
public void WillSendUseObjectPacket()
{
AutoResetEvent are = new AutoResetEvent( false );
void InternalPacketSentEvent( byte[] data, int length )
{
if ( data[0] != 0x06 )
{
Assert.Fail();
}
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
Assert.AreEqual( 0x40000001, serial );
are.Set();
}
Engine.InternalPacketSentEvent += InternalPacketSentEvent;
Engine.Items.Add( new Item( 0x40000001 ) );
AliasCommands.SetAlias( "item", 0x40000001 );
ObjectCommands.UseObject( "item" );
bool result = are.WaitOne( 5000 );
Assert.IsTrue( result );
Engine.InternalPacketSentEvent -= InternalPacketSentEvent;
Engine.Items.Clear();
AliasCommands.UnsetAlias( "item" );
}
[TestMethod]
public void WillFindObjectInContainer()
{
Item container = new Item( 0x55 ) { Container = new ItemCollection( 0x55 ) };
Engine.Items.Add( container );
container.Container.Add( new Item( 0x56 ) { Owner = 0x55 } );
bool result = ObjectCommands.FindObject( 0x56, -1, 0x55 );
Assert.IsTrue( result );
Item subContainer = new Item( 0x57 ) { Container = new ItemCollection( 0x57 ), Owner = 0x55 };
container.Container.Add( subContainer );
subContainer.Container.Add( new Item( 0x58 ) { Owner = 0x57 } );
result = ObjectCommands.FindObject( 0x57, -1, 0x55 );
Assert.IsTrue( result );
Engine.Items.Remove( container );
}
[TestMethod]
public void WillFindObjectGround()
{
Engine.Player = new PlayerMobile( 0x01 ) { X = 0, Y = 0 };
Item item1 = new Item( 0x40000001 );
Item item2 = new Item( 0x40000002 ) { X = 100, Y = 100 };
Engine.Items.Add( item1 );
Engine.Items.Add( item2 );
Assert.IsTrue( ObjectCommands.FindObject( item1.Serial ) );
Assert.IsTrue( ObjectCommands.FindObject( item2.Serial ) );
Assert.IsFalse( ObjectCommands.FindObject( item2.Serial, 5 ) );
Engine.Items.Remove( item2 );
Engine.Items.Remove( item1 );
Engine.Player = null;
}
[TestCleanup]
public void Cleanup()
{
ActionPacketQueue.Clear();
}
}
}
@@ -0,0 +1,137 @@
using System.Diagnostics;
using System.IO;
using ClassicAssist.Shared;
using ClassicAssist.Data.Macros.Commands;
using ClassicAssist.UO.Data;
using ClassicAssist.UO.Network;
using ClassicAssist.UO.Network.PacketFilter;
using ClassicAssist.UO.Objects;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ClassicAssist.Tests.MacroCommands
{
[TestClass]
public class PropertiesCommandTests
{
[TestMethod]
public void WillWaitForProperties()
{
Engine.PacketWaitEntries = new PacketWaitEntries();
void OnInternalPacketSentEvent( byte[] data, int length )
{
if ( data[0] != 0xD6 )
{
Assert.Fail();
}
int serial = ( data[3] << 24 ) | ( data[4] << 16 ) | ( data[5] << 8 ) | data[6];
byte[] packet = { 0xD6, 0x00, 0x09, 0x00, 0x01, data[3], data[4], data[5], data[6] };
Engine.PacketWaitEntries.CheckWait( packet, PacketDirection.Incoming );
}
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
bool result = PropertiesCommands.WaitForProperties( 0x00aabbcc, 5000 );
Assert.IsTrue( result );
Engine.PacketWaitEntries = null;
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
}
[TestMethod]
[TestCategory( "Data" )]
public void WillReturnTrueOnPropertyName()
{
const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";
if ( !Directory.Exists( localPath ) )
{
Debug.WriteLine( "Not running test, requires Cliloc.enu" );
return;
}
Cliloc.Initialize( localPath );
byte[] packet =
{
0xD6, 0x00, 0x43, 0x00, 0x01, 0x40, 0xC5, 0xF6, 0x09, 0x00, 0x00, 0x02, 0xA0, 0x3B, 0xCF, 0x00,
0x0F, 0x9E, 0xD5, 0x00, 0x00, 0x00, 0x10, 0x5E, 0x95, 0x00, 0x04, 0x37, 0x00, 0x34, 0x00, 0x00,
0x10, 0x5C, 0x71, 0x00, 0x1A, 0x34, 0x00, 0x39, 0x00, 0x09, 0x00, 0x31, 0x00, 0x32, 0x00, 0x35,
0x00, 0x09, 0x00, 0x37, 0x00, 0x31, 0x00, 0x09, 0x00, 0x35, 0x00, 0x35, 0x00, 0x30, 0x00, 0x00,
0x00, 0x00, 0x00
};
Item item = new Item( 0x40c5f609 );
Engine.Items.Add( item );
IncomingPacketHandlers.Initialize();
PacketHandler handler = IncomingPacketHandlers.GetHandler( 0xD6 );
handler.OnReceive( new PacketReader( packet, packet.Length, false ) );
Assert.IsNotNull( item.Properties );
bool result = PropertiesCommands.Property( item.Serial, "Contents" );
Assert.IsTrue( result );
result = PropertiesCommands.Property( item.Serial, "Donkey" );
Assert.IsFalse( result );
Engine.Items.Clear();
}
[TestMethod]
[TestCategory( "Data" )]
public void WillGetPropertyValue()
{
const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";
if ( !Directory.Exists( localPath ) )
{
Debug.WriteLine( "Not running test, requires Cliloc.enu" );
return;
}
Cliloc.Initialize( localPath );
byte[] packet =
{
0xD6, 0x00, 0x43, 0x00, 0x01, 0x40, 0xC5, 0xF6, 0x09, 0x00, 0x00, 0x02, 0xA0, 0x3B, 0xCF, 0x00,
0x0F, 0x9E, 0xD5, 0x00, 0x00, 0x00, 0x10, 0x5E, 0x95, 0x00, 0x04, 0x37, 0x00, 0x34, 0x00, 0x00,
0x10, 0x5C, 0x71, 0x00, 0x1A, 0x34, 0x00, 0x39, 0x00, 0x09, 0x00, 0x31, 0x00, 0x32, 0x00, 0x35,
0x00, 0x09, 0x00, 0x37, 0x00, 0x31, 0x00, 0x09, 0x00, 0x35, 0x00, 0x35, 0x00, 0x30, 0x00, 0x00,
0x00, 0x00, 0x00
};
Item item = new Item( 0x40c5f609 );
Engine.Items.Add( item );
IncomingPacketHandlers.Initialize();
PacketHandler handler = IncomingPacketHandlers.GetHandler( 0xD6 );
handler.OnReceive( new PacketReader( packet, packet.Length, false ) );
Assert.IsNotNull( item.Properties );
int value = PropertiesCommands.PropertyValue<int>( item.Serial, "Contents" );
Assert.AreEqual( 49, value );
value = PropertiesCommands.PropertyValue<int>( item.Serial, "Contents", 2 );
Assert.AreEqual( 71, value );
Engine.Items.Clear();
}
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,51 @@
using System;
using ClassicAssist.Data.Macros.Commands;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ClassicAssist.Tests.MacroCommands
{
[TestClass]
public class TimerTests
{
[TestMethod]
public void WillAddOffset()
{
TimerCommands.CreateTimer( "shmoo" );
TimerCommands.SetTimer( "shmoo", (int) TimeSpan.FromMinutes( 2 ).TotalMilliseconds );
long timerValue = TimerCommands.Timer( "shmoo" );
TimeSpan timespan = TimeSpan.FromMilliseconds( timerValue );
Assert.AreEqual( 2, (int) timespan.TotalMinutes );
TimerCommands.RemoveTimer( "shmoo" );
}
[TestMethod]
public void WillCreateTimer()
{
TimerCommands.CreateTimer( "shmoo2" );
Assert.IsTrue( TimerCommands.TimerExists( "shmoo2" ) );
TimerCommands.RemoveTimer( "shmoo2" );
}
[TestMethod]
public void WillRemoveTimer()
{
TimerCommands.CreateTimer( "shmoo3" );
TimerCommands.RemoveTimer( "shmoo3" );
Assert.IsFalse( TimerCommands.TimerExists( "shmoo3" ) );
}
[TestMethod]
public void WillCreateTimerSetTimer()
{
TimerCommands.SetTimer( "shmoo4" );
Assert.IsTrue( TimerCommands.TimerExists( "shmoo4" ) );
}
}
}
+206
View File
@@ -0,0 +1,206 @@
//TODO
//using System;
//using System.Collections.Generic;
//using System.IO;
//using System.Linq;
//using System.Reflection;
//using Assistant;
//using ClassicAssist.Data.Macros;
//using ClassicAssist.Resources;
//using ClassicAssist.Shared.Resources;
//using ClassicAssist.UI.ViewModels;
//using Microsoft.VisualStudio.TestTools.UnitTesting;
//namespace ClassicAssist.Tests
//{
// [TestClass]
// public class MacroTests
// {
// [TestMethod]
// public void WillExecute()
// {
// MacroEntry me = new MacroEntry();
// MacroManager mi = MacroManager.GetInstance();
// mi.Execute( me );
// }
// [TestMethod]
// public void WontThrowExceptionNewMacroNoAssistantOptions()
// {
// try
// {
// string path = Path.Combine( Engine.StartupPath ?? Environment.CurrentDirectory, "Assistant.json" );
// if ( File.Exists( path ) )
// {
// File.Delete( path );
// }
// MacrosTabViewModel vm = new MacrosTabViewModel();
// vm.NewMacroCommand.Execute( null );
// }
// catch ( Exception )
// {
// Assert.Fail();
// }
// }
// //[TestMethod]
// //public void WillAbortRunning()
// //{
// // MacroEntry me = new MacroEntry { Macro = "while true:\r\n\t" };
// // MacroManager mi = MacroManager.GetInstance();
// // mi.Execute( me );
// // mi.Stop();
// // bool result = mi.CurrentMacro.MacroInvoker.Thread.Join( 5000 );
// // Assert.IsTrue( result );
// //}
// //[TestMethod]
// //public void WillRaiseStartedEvent()
// //{
// // MacroEntry me = new MacroEntry();
// // MacroManager mi = MacroManager.GetInstance();
// // AutoResetEvent are = new AutoResetEvent( false );
// // void OnStartedEvent()
// // {
// // are.Set();
// // }
// // mi.CurrentMacro.MacroInvoker.StartedEvent += OnStartedEvent;
// // mi.Execute( me );
// // bool result = are.WaitOne( 5000 );
// // Assert.IsTrue( result );
// //}
// //[TestMethod]
// //public void WillRaiseStoppedEvent()
// //{
// // MacroEntry me = new MacroEntry();
// // MacroManager mi = MacroManager.GetInstance();
// // AutoResetEvent are = new AutoResetEvent( false );
// // void OnStoppedEvent()
// // {
// // are.Set();
// // }
// // mi.CurrentMacro.MacroInvoker.StoppedEvent += OnStoppedEvent;
// // mi.Execute( me );
// // bool result = are.WaitOne( 5000 );
// // Assert.IsTrue( result );
// //}
// //[TestMethod]
// //public void WillExecuteRunDummy()
// //{
// // MacroEntry me = new MacroEntry { Macro = "Dummy(5,7)" };
// // MacroManager mi = MacroManager.GetInstance();
// // mi.Execute( me );
// // mi.CurrentMacro.MacroInvoker.Thread.Join();
// // Assert.IsFalse( mi.CurrentMacro.MacroInvoker.IsFaulted );
// //}
// //[TestMethod]
// //public void WillExceptionEvent()
// //{
// // MacroEntry me = new MacroEntry { Macro = "kjdkdsdksdfsdk" };
// // MacroManager mi = MacroManager.GetInstance();
// // AutoResetEvent are = new AutoResetEvent( false );
// // void OnExceptionEvent( Exception e )
// // {
// // Assert.IsTrue( mi.CurrentMacro.MacroInvoker.IsFaulted );
// // Assert.IsNotNull( mi.CurrentMacro.MacroInvoker.Exception );
// // are.Set();
// // }
// // mi.CurrentMacro.MacroInvoker.ExceptionEvent += OnExceptionEvent;
// // mi.Execute( me );
// // bool result = are.WaitOne( 5000 );
// // Assert.IsTrue( result );
// //}
// [TestMethod]
// public void EnsureAllCommandsHaveAttribute()
// {
// IEnumerable<Type> types = Assembly.GetAssembly( typeof( Engine ) ).GetTypes().Where( t =>
// t.Namespace != null && t.Namespace.EndsWith( "Macros.Commands" ) && t.IsClass && t.IsPublic &&
// !t.Name.Contains( "Dummy" ) );
// foreach ( Type type in types )
// {
// MethodInfo[] members = type.GetMethods( BindingFlags.Public | BindingFlags.Static );
// foreach ( MethodInfo member in members )
// {
// CommandsDisplayAttribute attr = member.GetCustomAttribute<CommandsDisplayAttribute>();
// if ( attr == null )
// {
// Assert.Fail( $"{type.Name}.{member.Name} has no CommandsDisplayAttribute." );
// }
// }
// }
// }
// [TestMethod]
// public void EnsureAllCategoriesAreLocalizable()
// {
// IEnumerable<Type> types = Assembly.GetAssembly( typeof( Engine ) ).GetTypes().Where( t =>
// t.Namespace != null && t.Namespace.EndsWith( "Macros.Commands" ) && t.IsClass && t.IsPublic &&
// !t.Name.Contains( "Dummy" ) );
// foreach ( Type type in types )
// {
// MethodInfo[] members = type.GetMethods( BindingFlags.Public | BindingFlags.Static );
// foreach ( MethodInfo member in members )
// {
// CommandsDisplayAttribute attr = member.GetCustomAttribute<CommandsDisplayAttribute>();
// if ( attr == null )
// {
// Assert.Fail( $"{type.Name}.{member.Name} has no CommandsDisplayAttribute." );
// }
// string resourceName = Strings.ResourceManager.GetString( attr.Category );
// if ( string.IsNullOrEmpty( resourceName ) )
// {
// Assert.Fail(
// $"{type.Name}.{member.Name}: Category \"{attr.Category}\" has no resource entry." );
// }
// }
// }
// }
// }
//}
@@ -0,0 +1,42 @@
//TODO
//using System.Linq;
//using ClassicAssist.Data.Macros;
//using ClassicAssist.UI.ViewModels;
//using Microsoft.VisualStudio.TestTools.UnitTesting;
//namespace ClassicAssist.Tests
//{
// [TestClass]
// public class MacrosViewModelTests
// {
// private MacrosTabViewModel _model;
// [TestInitialize]
// public void Initialize()
// {
// _model = new MacrosTabViewModel();
// }
// [TestMethod]
// public void NewCommandWillAddItem()
// {
// _model.NewMacroCommand.Execute( null );
// Assert.AreEqual( 1, _model.Items.Count );
// _model.Items.Clear();
// }
// [TestMethod]
// public void RemoveCommandWillRemoveItem()
// {
// _model.NewMacroCommand.Execute( null );
// MacroEntry item = _model.Items.FirstOrDefault();
// _model.RemoveMacroCommand.Execute( item );
// Assert.AreEqual( 0, _model.Items.Count );
// }
// }
//}
+33
View File
@@ -0,0 +1,33 @@
#region License
// Copyright (C) 2020 Reetus
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#endregion
using System.Collections.Generic;
using System.Linq;
using ClassicAssist.UO.Objects;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ClassicAssist.Tests
{
[TestClass]
public class MiscTests
{
[TestMethod]
public void Test()
{
}
}
}
+252
View File
@@ -0,0 +1,252 @@
#region License
// Copyright (C) 2020 Reetus
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#endregion
using System;
using System.Linq;
using System.Threading;
using ClassicAssist.Shared;
using ClassicAssist.UO.Data;
using ClassicAssist.UO.Network;
using ClassicAssist.UO.Network.Packets;
using ClassicAssist.UO.Objects;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ClassicAssist.Tests
{
[TestClass]
public class OldPacketTests
{
[TestMethod]
public void WillSendProperDropRequest()
{
AppDomain appDomain = AppDomain.CreateDomain( "WillSendProperDropRequest", AppDomain.CurrentDomain.Evidence,
AppDomain.CurrentDomain.SetupInformation );
appDomain.DoCallBack( () =>
{
Engine.ClientVersion = new Version( 5, 0, 9, 1 );
AutoResetEvent are = new AutoResetEvent( false );
void OnInternalPacketSentEvent( byte[] data, int length )
{
if ( data[0] != 0x08 )
{
return;
}
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
int x = ( data[5] << 8 ) | data[6];
int y = ( data[7] << 8 ) | data[8];
int z = data[9];
int containerSerial = ( data[10] << 24 ) | ( data[11] << 16 ) | ( data[12] << 8 ) | data[13];
Assert.AreEqual( 0x11223344, serial );
Assert.AreEqual( 1, x );
Assert.AreEqual( 2, y );
Assert.AreEqual( 3, z );
Assert.AreEqual( 0x55667788, containerSerial );
are.Set();
}
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
Engine.SendPacketToServer( new DropItem( 0x11223344, 0x55667788, 1, 2, 3 ) );
are.WaitOne( 5000 );
Engine.ClientVersion = new Version( 7, 0, 45, 1 );
} );
}
[TestMethod]
public void WillParseOldContainerContents()
{
AppDomain appDomain = AppDomain.CreateDomain( "WillParseOldContainerContents",
AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation );
appDomain.DoCallBack( () =>
{
Engine.ClientVersion = new Version( 5, 0, 9, 1 );
byte[] packet =
{
0x3C, 0x00, 0x2B, 0x00, 0x02, 0x46, 0x13, 0xFF, 0x71, 0x0E, 0x76, 0x00, 0x00, 0x01, 0x00, 0x2C,
0x00, 0x7F, 0x46, 0x13, 0xFF, 0x6D, 0x00, 0x00, 0x46, 0x58, 0x64, 0xFB, 0x0E, 0xED, 0x00, 0x03,
0xE8, 0x00, 0x4C, 0x00, 0x48, 0x46, 0x13, 0xFF, 0x6D, 0x00, 0x00
};
IncomingPacketHandlers.Initialize();
Engine.Items = new ItemCollection( 0 );
PacketHandler handler = IncomingPacketHandlers.GetHandler( 0x3C );
handler?.OnReceive( new PacketReader( packet, packet.Length, false ) );
Assert.AreEqual( 1, Engine.Items.GetItemCount() );
Assert.IsTrue( Engine.Items.Any( i => i.Serial == 0x4613ff6d ) );
Item container = Engine.Items.GetItem( 0x4613ff6d );
Assert.IsNotNull( container );
Assert.AreEqual( 2, container.Container.GetItemCount() );
Engine.Items = null;
Engine.ClientVersion = new Version( 7, 0, 45, 1 );
} );
}
[TestMethod]
public void WillParseOldHealthbarColour()
{
AppDomain appDomain = AppDomain.CreateDomain( "WillParseOldHealthbarColour",
AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation );
appDomain.DoCallBack( () =>
{
Engine.ClientVersion = new Version( 5, 0, 9, 1 );
byte[] packet =
{
0x17, 0x00, 0x0F, 0x00, 0x07, 0x5D, 0x67, 0x00, 0x02, 0x00, 0x01, 0x01, 0x00, 0x02, 0x00
};
IncomingPacketHandlers.Initialize();
Mobile mobile = new Mobile( 0x00075D67 );
Engine.Mobiles.Add( mobile );
PacketHandler handler = IncomingPacketHandlers.GetHandler( 0x17 );
handler?.OnReceive( new PacketReader( packet, packet.Length, false ) );
Assert.IsTrue( mobile.IsPoisoned );
} );
}
[TestMethod]
public void WillSetPoisonedFromOldMoving()
{
AppDomain appDomain = AppDomain.CreateDomain( "WillSetPoisonedFromOldMoving",
AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation );
appDomain.DoCallBack( () =>
{
Engine.ClientVersion = new Version( 5, 0, 9, 1 );
byte[] packet =
{
0x77, 0x00, 0x25, 0x49, 0xbb, 0x01, 0x90, 0x0d, 0xf9, 0x0a, 0x37, 0x00, 0x84, 0x83, 0xea, 0x04,
0x01
};
IncomingPacketHandlers.Initialize();
PacketHandler handler = IncomingPacketHandlers.GetHandler( 0x77 );
handler?.OnReceive( new PacketReader( packet, packet.Length, true ) );
Mobile mobile = Engine.Mobiles.GetMobile( 0x2549bb );
Assert.IsNotNull( mobile );
Assert.IsTrue( mobile.IsPoisoned );
byte[] packet2 =
{
0x77, 0x00, 0x06, 0xbc, 0x06, 0x01, 0x90, 0x09, 0xd0, 0x02, 0x2b, 0x00, 0x02, 0x83, 0xea, 0x44,
0x01
};
handler?.OnReceive( new PacketReader( packet2, packet2.Length, true ) );
mobile = Engine.Mobiles.GetMobile( 0x6bc06 );
Assert.IsNotNull( mobile );
Assert.IsTrue( mobile.IsPoisoned );
} );
}
//[TestMethod]
//public void WillSetPoisonedFromOldIncoming()
//{
// AppDomain appDomain = AppDomain.CreateDomain( "WillSetPoisonedFromOldIncoming",
// AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation );
// appDomain.DoCallBack( () =>
// {
// Engine.ClientVersion = new Version( 5, 0, 9, 1 );
// byte[] packet =
// {
// 0x78, 0x00, 0x6e, 0x00, 0x05, 0xca, 0x65, 0x01, 0x90, 0x09, 0xba, 0x02, 0x23, 0x00, 0x03, 0x03,
// 0xff, 0x00, 0x01, 0x40, 0x05, 0xca, 0x5d, 0xa0, 0x48, 0x0b, 0x04, 0x65, 0x40, 0x05, 0xca, 0x58,
// 0xa0, 0x3e, 0x10, 0x04, 0x65, 0x40, 0x05, 0xca, 0x57, 0x95, 0x17, 0x05, 0x03, 0x1c, 0x40, 0x05,
// 0xca, 0x54, 0x95, 0x2e, 0x04, 0x01, 0xb6, 0x40, 0x05, 0xca, 0x53, 0x14, 0x15, 0x0d, 0x40, 0x05,
// 0xca, 0x51, 0x14, 0x11, 0x18, 0x40, 0x05, 0xca, 0x4f, 0x14, 0x10, 0x13, 0x40, 0x05, 0xca, 0x46,
// 0x95, 0x41, 0x11, 0x03, 0xaf, 0x40, 0x05, 0xca, 0x3b, 0x0e, 0x75, 0x15, 0x40, 0x05, 0xca, 0x35,
// 0x3e, 0xa0, 0x19, 0x40, 0x05, 0xca, 0x42, 0x14, 0x3e, 0x02, 0x00, 0x00, 0x00, 0x00
// };
// IncomingPacketHandlers.Initialize();
// PacketHandler handler = IncomingPacketHandlers.GetHandler( 0x78 );
// handler?.OnReceive( new PacketReader( packet, packet.Length, false ) );
// Mobile mobile = Engine.Mobiles.GetMobile( 0x5ca65 );
// Assert.IsNotNull( mobile );
// Assert.IsTrue( mobile.IsPoisoned );
// } );
//}
[TestMethod]
public void WillParseItemListMenu()
{
/*
* Display Item List Menu Packet.
from server
byte ID (7C)
word Packet Size
dword Sender Serial
word Gump ID
byte Title Length
char[Title Length] Title
byte Number Of Lines
loop Lines
word Choice ID
word Hue
byte Line Length
char[Line Length] Texte
endloop Lines
*/
byte[] packet =
{
0x7C, 0x00, 0x39, 0x00, 0x07, 0x76, 0x7C, 0x01, 0xCF, 0x0D, 0x42, 0x6C, 0x61, 0x63, 0x6B, 0x73,
0x6D, 0x69, 0x74, 0x68, 0x69, 0x6E, 0x67, 0x03, 0x0F, 0xAF, 0x00, 0x00, 0x06, 0x52, 0x65, 0x70,
0x61, 0x69, 0x72, 0x0F, 0xB1, 0x00, 0x00, 0x05, 0x53, 0x6D, 0x65, 0x6C, 0x74, 0x13, 0xB9, 0x00,
0x00, 0x07, 0x57, 0x65, 0x61, 0x70, 0x6F, 0x6E, 0x73
};
/*
* Item List Menu Response Packet.
13 bytesfrom server
byte ID (7D)
dword Sender Serial
word Gump ID
word Index
word Item ID
word Hue
*/
byte[] packet2 = { 0x7D, 0x00, 0x07, 0x76, 0x7C, 0x01, 0xCF, 0x00, 0x03, 0x13, 0xB9, 0x00, 0x00 };
}
}
}
@@ -0,0 +1,59 @@
#region License
// Copyright (C) 2020 Reetus
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#endregion
using ClassicAssist.Shared;
using ClassicAssist.UO.Data;
using ClassicAssist.UO.Network;
using ClassicAssist.UO.Objects;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ClassicAssist.Tests
{
[TestClass]
public class OutgoingPacketHandlerTests
{
[TestInitialize]
public void Initialize()
{
Engine.Items = new ItemCollection( 0 );
Engine.Mobiles = new MobileCollection( Engine.Items );
Engine.Player = new PlayerMobile( 1 );
OutgoingPacketHandlers.Initialize();
}
[TestMethod]
public void WillSetHolding()
{
byte[] packet = { 0x07, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
PacketHandler handler = OutgoingPacketHandlers.GetHandler( 0x07 );
handler.OnReceive( new PacketReader( packet, packet.Length, true ) );
Assert.AreEqual( unchecked( (int) 0xAABBCCDD ), Engine.Player.Holding );
Assert.AreEqual( 0xEEFF, Engine.Player.HoldingAmount );
}
[TestCleanup]
public void Cleanup()
{
}
}
}
+36
View File
@@ -0,0 +1,36 @@
using System.IO;
using ClassicAssist.UO.Data;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ClassicAssist.Tests
{
[TestClass]
public class PacketReaderTests
{
[TestMethod]
public void PacketReaderWillReadCorrect()
{
byte[] packet = { 0x1B, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x0A };
PacketReader reader = new PacketReader( packet, packet.Length, true );
int int32 = reader.ReadInt32();
int int16 = reader.ReadInt16();
int int8 = reader.ReadByte();
Assert.AreEqual( unchecked( (int) 0xAABBCCDD ), int32 );
Assert.AreEqual( unchecked( (short) 0xEEFF ), int16 );
Assert.AreEqual( 0x0A, int8 );
reader.Seek( 1, SeekOrigin.Begin );
uint uint32 = reader.ReadUInt32();
uint uint16 = reader.ReadUInt16();
sbyte uint8 = reader.ReadSByte();
Assert.AreEqual( 0xAABBCCDD, uint32 );
Assert.AreEqual( (ushort) 0xEEFF, uint16 );
Assert.AreEqual( 0x0A, uint8 );
}
}
}
+68
View File
@@ -0,0 +1,68 @@
//TODO
//using System;
//using System.Diagnostics;
//using System.IO;
//using System.Linq;
//using ClassicAssist.Data;
//using ClassicAssist.Data.Hotkeys;
//using ClassicAssist.Resources;
//using ClassicAssist.UI.ViewModels;
//using ClassicAssist.UO.Data;
//using Microsoft.VisualStudio.TestTools.UnitTesting;
//using Newtonsoft.Json.Linq;
//namespace ClassicAssist.Tests
//{
// [TestClass]
// public class ProfileSwitching
// {
// [TestMethod]
// public void WontDuplicateSkillsCategory()
// {
// AppDomain appDomain = AppDomain.CreateDomain( "WontThrowExceptionOnDeserializeNullConfig",
// AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation );
// appDomain.DoCallBack( () =>
// {
// const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";
// if ( !Directory.Exists( localPath ) )
// {
// Debug.WriteLine( "Not running test, requires Cliloc.enu" );
// return;
// }
// SkillsTabViewModel vm = new SkillsTabViewModel();
// Options options = Options.CurrentOptions;
// Skills.Initialize( localPath );
// JObject json = new JObject
// {
// {
// "Skills",
// new JArray
// {
// new JObject
// {
// { "Name", "Hiding" },
// { "Keys", new JObject { { "Keys", 94 }, { "Modifier", 0 }, { "Mouse", 7 } } },
// { "PassToUO", false }
// }
// }
// }
// };
// vm.Deserialize( json, options );
// vm.Deserialize( json, options );
// HotkeyManager hotkeys = HotkeyManager.GetInstance();
// int count = hotkeys.Items.Count( hk => hk.IsCategory && hk.Name == Strings.Skills );
// Assert.AreEqual( 1, count );
// } );
// }
// }
//}
+112
View File
@@ -0,0 +1,112 @@
//#region License
//// Copyright (C) 2020 Reetus
////
//// This program is free software: you can redistribute it and/or modify
//// it under the terms of the GNU General Public License as published by
//// the Free Software Foundation, either version 3 of the License, or
//// (at your option) any later version.
////
//// This program is distributed in the hope that it will be useful,
//// but WITHOUT ANY WARRANTY; without even the implied warranty of
//// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//// GNU General Public License for more details.
////
//// You should have received a copy of the GNU General Public License
//// along with this program. If not, see <https://www.gnu.org/licenses/>.
//#endregion
//using System;
//using System.Collections.Generic;
//using System.IO;
//using System.Linq;
//using Assistant;
//using ClassicAssist.UO.Data;
//using ClassicAssist.UO.Network;
//using ClassicAssist.UO.Network.PacketFilter;
//using ClassicAssist.UO.Objects;
//using Microsoft.VisualStudio.TestTools.UnitTesting;
//using Newtonsoft.Json;
//using Newtonsoft.Json.Linq;
//namespace ClassicAssist.Tests
//{
// [TestClass]
// public class ReplayPacketLog
// {
// [TestMethod]
// public void CheckPoisonStatus()
// {
// AppDomain appDomain = AppDomain.CreateDomain( "CheckPoisonStatus", AppDomain.CurrentDomain.Evidence,
// AppDomain.CurrentDomain.SetupInformation );
// appDomain.DoCallBack( () =>
// {
// Engine.ClientVersion = new Version( 5, 0, 9, 1 );
// string fileName = @"C:\Users\johns\source\repos\ClassicAssist\Output\net48\export.packets.json";
// if ( !File.Exists( fileName ) )
// {
// return;
// }
// IEnumerable<PacketEntry> packetEntries = ParseLog( fileName );
// byte[] packetIds = { 0x20, 0x77, 0x78 };
// IEnumerable<PacketEntry> filteredEntries = packetEntries.Where( i =>
// packetIds.Contains( i.Data[0] ) && i.Direction == PacketDirection.Incoming );
// IncomingPacketHandlers.Initialize();
// foreach ( PacketEntry filteredEntry in filteredEntries )
// {
// PacketHandler handler = IncomingPacketHandlers.GetHandler( filteredEntry.Data[0] );
// handler?.OnReceive( new PacketReader( filteredEntry.Data, filteredEntry.Data.Length, true ) );
// Mobile mobile = Engine.Mobiles.GetMobile( 0x002549bb );
// Assert.IsTrue( mobile.IsPoisoned );
// }
// } );
// }
// private static IEnumerable<PacketEntry> ParseLog( string fileName )
// {
// string text = File.ReadAllText( fileName );
// List<PacketEntry> packets = new List<PacketEntry>();
// JObject[] data = JsonConvert.DeserializeObject<JObject[]>( text );
// if ( data == null )
// {
// return packets;
// }
// packets.AddRange( from entry in data
// where entry != null
// select new PacketEntry
// {
// Title = entry?["Title"].ToObject<string>() ?? string.Empty,
// Direction = entry["Direction"].ToObject<PacketDirection>(),
// DateTime = entry["DateTime"].ToObject<DateTime>(),
// Data = Convert.FromBase64String( entry["Base64"].ToObject<string>() )
// } );
// return packets;
// }
// public class PacketEntry
// {
// public byte[] Data { get; set; }
// public DateTime DateTime { get; set; }
// public PacketDirection Direction { get; set; }
// public string Title { get; set; }
// }
// }
//}
+64
View File
@@ -0,0 +1,64 @@
#region License
// Copyright (C) 2020 Reetus
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#endregion
using System.IO;
using ClassicAssist.UO.Data;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ClassicAssist.Tests
{
[TestClass]
public class TileDataFormatTest
{
private const string oldFormatPath = @"D:\Games\Ultima Online\";
private static readonly string newFormatPath = @"C:\Program Files (x86)\Electronic Arts\Ultima Online Classic";
[TestMethod]
public void WillReadOldFormatStatic()
{
if ( !Directory.Exists( oldFormatPath ) )
{
return;
}
TileData.Initialize( oldFormatPath );
StaticTile td = TileData.GetStaticTile( 0x1bf8 );
Assert.AreEqual( "silver ingot", td.Name );
Assert.IsTrue( td.Flags.HasFlag( TileFlags.Stackable ) );
}
[TestMethod]
public void WillReadNewFormatStatic()
{
if ( !Directory.Exists( newFormatPath ) )
{
return;
}
TileData.Initialize( newFormatPath );
StaticTile td = TileData.GetStaticTile( 0x1bf8 );
Assert.AreEqual( "silver ingot", td.Name );
Assert.IsTrue( td.Flags.HasFlag( TileFlags.Stackable ) );
}
}
}
+255
View File
@@ -0,0 +1,255 @@
{
"ClientVersion": "0.0.0.0",
"PacketLengths": {
"248": 106,
"1": 5,
"2": 7,
"3": 32768,
"4": 2,
"5": 5,
"6": 5,
"7": 7,
"8": 15,
"9": 5,
"10": 11,
"11": 7,
"12": 32768,
"13": 3,
"14": 32768,
"15": 61,
"16": 215,
"17": 32768,
"18": 32768,
"19": 10,
"20": 6,
"21": 9,
"22": 32768,
"23": 32768,
"24": 32768,
"25": 32768,
"26": 32768,
"27": 37,
"28": 32768,
"29": 5,
"30": 4,
"31": 8,
"32": 19,
"33": 8,
"34": 3,
"35": 26,
"36": 9,
"37": 21,
"38": 5,
"39": 2,
"40": 5,
"41": 1,
"42": 5,
"43": 2,
"44": 2,
"45": 17,
"46": 15,
"47": 10,
"48": 5,
"49": 32768,
"50": 2,
"51": 2,
"52": 10,
"53": 653,
"54": 32768,
"55": 8,
"56": 7,
"57": 9,
"58": 32768,
"59": 32768,
"60": 32768,
"61": 2,
"62": 37,
"63": 32768,
"64": 201,
"65": 32768,
"66": 32768,
"67": 553,
"68": 713,
"69": 5,
"70": 32768,
"71": 11,
"72": 73,
"73": 93,
"74": 5,
"75": 9,
"76": 32768,
"77": 32768,
"78": 6,
"79": 2,
"80": 32768,
"81": 32768,
"82": 32768,
"83": 2,
"84": 12,
"85": 1,
"86": 11,
"87": 110,
"88": 106,
"89": 32768,
"90": 32768,
"91": 4,
"92": 2,
"93": 73,
"94": 32768,
"95": 49,
"96": 5,
"97": 9,
"98": 15,
"99": 13,
"100": 1,
"101": 4,
"102": 32768,
"103": 21,
"104": 32768,
"105": 32768,
"106": 3,
"107": 9,
"108": 19,
"109": 3,
"110": 14,
"111": 32768,
"112": 28,
"113": 32768,
"114": 5,
"115": 2,
"116": 32768,
"117": 35,
"118": 16,
"119": 17,
"120": 32768,
"121": 9,
"122": 32768,
"123": 2,
"124": 32768,
"125": 13,
"126": 2,
"127": 32768,
"128": 62,
"129": 32768,
"130": 2,
"131": 39,
"132": 69,
"133": 2,
"134": 32768,
"135": 32768,
"136": 66,
"137": 32768,
"138": 32768,
"139": 32768,
"140": 11,
"141": 32768,
"142": 32768,
"143": 32768,
"144": 19,
"145": 65,
"146": 32768,
"147": 99,
"148": 32768,
"149": 9,
"150": 32768,
"151": 2,
"152": 32768,
"153": 30,
"154": 32768,
"155": 258,
"156": 309,
"157": 51,
"158": 32768,
"159": 32768,
"160": 3,
"161": 9,
"162": 9,
"163": 9,
"164": 149,
"165": 32768,
"166": 32768,
"167": 4,
"168": 32768,
"169": 32768,
"170": 5,
"171": 32768,
"172": 32768,
"173": 32768,
"174": 32768,
"175": 13,
"176": 32768,
"177": 32768,
"178": 32768,
"179": 32768,
"180": 32768,
"181": 64,
"182": 9,
"183": 32768,
"184": 32768,
"185": 5,
"186": 10,
"187": 9,
"188": 3,
"189": 32768,
"190": 32768,
"191": 32768,
"192": 36,
"193": 32768,
"194": 32768,
"195": 32768,
"196": 6,
"197": 203,
"198": 1,
"199": 49,
"200": 2,
"201": 6,
"202": 6,
"203": 7,
"204": 32768,
"205": 1,
"206": 32768,
"207": 78,
"208": 32768,
"209": 2,
"210": 25,
"211": 32768,
"212": 32768,
"213": 32768,
"214": 32768,
"215": 32768,
"216": 32768,
"217": 268,
"218": 32768,
"219": 32768,
"220": 9,
"221": 32768,
"222": 32768,
"223": 32768,
"224": 32768,
"225": 32768,
"226": 10,
"227": 32768,
"228": 32768,
"229": 32768,
"230": 5,
"231": 12,
"232": 13,
"233": 75,
"234": 3,
"235": 32768,
"236": 32768,
"237": 32768,
"238": 8192,
"239": 8192,
"240": 32768,
"241": 9,
"242": 25,
"243": 26,
"244": 32768,
"245": 21,
"246": 32768,
"247": 32768,
"249": 32768,
"250": 1
}
}