public static Client CreateLocalClient(this MoonlightAPI moonlightApi) { if (LocalClient.NonSharedInstanceCreated) { throw new InvalidOperationException("There is already one instance of local client created for non shared context. Packet or walk functions cannot be hooked."); } if (LocalClient.SharedInstanceCreated && !moonlightApi.SharedInstance) { throw new InvalidOperationException("There is already one instance of local client created for shared context. Packet or walk functions cannot be hooked. Use MoonlightAPI.GetSharedMoonlightAPI for more injected dlls at once."); } if (!moonlightApi.SharedInstance) { LocalClient.NonSharedInstanceCreated = true; } else { LocalClient.SharedInstanceCreated = true; if (moonlightApi.Client is LocalClient) { return(moonlightApi.Client); } } IClientManager clientManager = moonlightApi.Services.GetService <IClientManager>(); return(moonlightApi.Client = clientManager.CreateLocalClient()); }
public void ConfigureServices(MoonlightAPI api, IServiceCollection services) { services.AddSingleton(api); services.AddServices(); services.AddViewModels(); }
protected PacketHandlingTests() { var clientMock = new Mock <Client>(); Moonlight = new MoonlightAPI(new AppConfig { Database = "../../database.db" }); SkillFactory = Moonlight.Services.GetService <ISkillFactory>(); EntityFactory = Moonlight.Services.GetService <IEntityFactory>(); MapFactory = Moonlight.Services.GetService <IMapFactory>(); IPacketHandlerManager _packetHandlerManager = Moonlight.Services.GetService <IPacketHandlerManager>(); clientMock.Setup(x => x.SendPacket(It.IsAny <string>())).Callback <string>(x => _packetHandlerManager.Handle(clientMock.Object, x)); clientMock.Setup(x => x.ReceivePacket(It.IsAny <string>())).Callback <string>(x => _packetHandlerManager.Handle(clientMock.Object, x)); Client = clientMock.Object; Client.Character = Character = new Character(new SerilogLogger(), 999, "Moonlight", Client); Map map = MapFactory.CreateMap(1); map.AddEntity(Client.Character); }
protected override void OnStartup(StartupEventArgs e) { try { AppConfig config = new AppConfig { Configuration = (App)App.Current }; MoonlightAPI api = new MoonlightAPI(config) { Language = Language.EN }; api.AllocConsole(); api.DeferPackets(); BotWindow bot = new BotWindow() { DataContext = api.Services.GetService <BotWindowViewModel>() }; bot.Show(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public MoonlightMainViewModel(MoonlightAPI api) { Client client = api.Client; SendInfoCommand = new RelayCommand(() => { client.ReceivePacket("info Hello from Moonlight library!"); // receive packet with message }); }
public BotWindowViewModel(MoonlightAPI api) { Client = api.CreateLocalClient(); Bot = new Bot(Client); StartCommand = new RelayCommand(Bot.Start); StopCommand = new RelayCommand(Bot.Stop); }
public NosTaleLogin(MoonlightAPI api, RemoteClient client) { _api = api; _serializer = api.Services.GetService <ISerializer>(); _client = client; IEventManager eventManager = api.Services.GetService <IEventManager>(); eventManager.RegisterOnceListener(new ServersReceivedListener(this)); eventManager.RegisterOnceListener(new LoginFailListener(this)); }
public NostaleWorld(MoonlightAPI api, RemoteClient client) { _client = client; _api = api; _serializer = api.Services.GetService <ISerializer>(); IEventManager eventManager = api.Services.GetService <IEventManager>(); eventManager.RegisterOnceListener(new CharactersListReceivedListener(this)); eventManager.RegisterListener(new ServerChangeListener(api.Logger, this, client)); }
public FactoryTests() { var moonlight = new MoonlightAPI(new AppConfig { Database = "../../../database.db" }); _itemFactory = moonlight.Services.GetService <IItemFactory>(); _entityFactory = moonlight.Services.GetService <IEntityFactory>(); _mapFactory = moonlight.Services.GetService <IMapFactory>(); _skillFactory = moonlight.Services.GetService <ISkillFactory>(); _languageService = moonlight.Services.GetService <ILanguageService>(); }
protected PacketHandlingTest() { var clientMock = new Mock <Client>(); Moonlight = new MoonlightAPI(new AppConfig { Database = "../../database.db" }); clientMock.Setup(x => x.SendPacket(It.IsAny <string>())).Callback <string>(x => Moonlight.GetPacketHandlerManager().Handle(clientMock.Object, x)); clientMock.Setup(x => x.ReceivePacket(It.IsAny <string>())).Callback <string>(x => Moonlight.GetPacketHandlerManager().Handle(clientMock.Object, x)); Client = clientMock.Object; Client.Character = Character = new Character(new SerilogLogger(), 999, "Moonlight", Client); }
protected override void OnStartup(StartupEventArgs e) { try // prevent whole process crash on exception { AppConfig config = new AppConfig { Configuration = (App)App.Current }; MoonlightAPI api = new MoonlightAPI(config) { Language = Language.CZ }; #if DEBUG api.AllocConsole(); #endif api.DeferPackets(); // handle packets in separate thread to prevent slowing down NosTale // this is useful if you don't need to modify or cancel packets... // and if you don't need 'to send packets at precise time right after particular packet etc. // to disable this use api.SyncPackets(); that is the default behavior api.CreateLocalClient(); // creates local client so it will be middleware for real game packet send/receive MoonlightMainWindow nosDamage = new MoonlightMainWindow { DataContext = api.Services.GetService <MoonlightMainViewModel>() }; nosDamage.Show(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public NosTale(MoonlightAPI moonlightApi, RegionType region) { Region = region; _moonlightApi = moonlightApi; }
public static void AllocConsole(this MoonlightAPI moonlightApi) { Kernel32.AllocConsole(); }
public void ConfigureServices(MoonlightAPI api, IServiceCollection services) { services.AddSingleton(api); services.AddTransient <BotWindowViewModel>(); }