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());
        }
Beispiel #2
0
        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);
        }
Beispiel #4
0
        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);
            }
        }
Beispiel #5
0
        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);
        }
Beispiel #7
0
        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));
        }
Beispiel #8
0
        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));
        }
Beispiel #9
0
        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>();
        }
Beispiel #10
0
        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);
        }
Beispiel #11
0
        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);
            }
        }
Beispiel #12
0
 public NosTale(MoonlightAPI moonlightApi, RegionType region)
 {
     Region        = region;
     _moonlightApi = moonlightApi;
 }
 public static void AllocConsole(this MoonlightAPI moonlightApi)
 {
     Kernel32.AllocConsole();
 }
Beispiel #14
0
 public void ConfigureServices(MoonlightAPI api, IServiceCollection services)
 {
     services.AddSingleton(api);
     services.AddTransient <BotWindowViewModel>();
 }