private void Startup(object sender, EventArgs e) { var pe = new PEFileCollection(); pe.PopulateCollectionWithStandardGFX(); this.EIF = ItemFile.FromBytes(File.ReadAllBytes(Path.Combine(Environment.CurrentDirectory, "pub", "dat001.eif"))); this.GFX = new NativeGraphicsManager(new NativeGraphicsLoader(pe)); itemPillow = GFX.BitmapFromResource(GFXTypes.MapTiles, 0, true); flowItemPanel.HorizontalScroll.Enabled = false; flowItemPanel.HorizontalScroll.Visible = false; EOItemScrollBar.Padding = new Padding(0); EOItemScrollBar.BorderColor = Color.Transparent; EOItemScrollBar.DisabledBorderColor = Color.Transparent; panel2.Controls.Add(EOItemScrollBar); EOItemScrollBar.BringToFront(); EOItemScrollBar.Maximum = flowItemPanel.VerticalScroll.Maximum; EOItemScrollBar.Minimum = flowItemPanel.VerticalScroll.Minimum; EOItemScrollBar.Height = flowItemPanel.Height; EOItemScrollBar.Scroll += EOItemsScrollBar_Scroll; tabWeapons.PerformClick(); // load your shop using (var wc = new WebClient() { Proxy = null }) { var response = wc.DownloadString($"{APIEndpoint}/api/v1/index/username/{this.Username}"); try { var deserialized = JsonConvert.DeserializeObject <MarketIndexByUsernameRecord[]>(response); this.CurrentShop = new Shop(deserialized, this.Username); } catch { MessageBox.Show(response); } } }
public ShopManager() { this.PECollection = new PEFileCollection(); this.PECollection.PopulateCollectionWithStandardGFX(); this.EIF = ItemFile.FromBytes(File.ReadAllBytes(Path.Combine(Environment.CurrentDirectory, "pub", "dat001.eif"))); this.GFX = new NativeGraphicsManager(new NativeGraphicsLoader(this.PECollection)); this.Pillow = this.GFX.BitmapFromResource(GFXTypes.MapTiles, 0, true); var config = new IniReader(Path.Combine(Environment.CurrentDirectory, "config", "setup.ini")); config.Load(); if (!config.GetValue("CONNECTION", "Host", out string host)) { throw new Exception("Unable to read 'Host' from client config."); } this.APIEndpoint = $"http://{host}:8076"; }
public EOMarketBot() { this.EIF = ItemFile.FromBytes(File.ReadAllBytes(Path.Combine(Environment.CurrentDirectory, "data", "pub", "dat001.eif"))); this.Client = new EOClient(new PacketProcessActions(new SequenceRepository(), new PacketEncoderRepository(), new PacketEncoderService(), new PacketSequenceService())); this.API = new PacketAPI(this.Client); if (!File.Exists("config/market.ini")) { throw new Exception("Unable to locate market configuration file."); } if (!File.Exists("config/server.ini")) { throw new Exception("Unable to locate server configuration file."); } var parser = new FileIniDataParser ( new IniDataParser(new IniParserConfiguration() { AllowKeysWithoutSection = true, CommentRegex = new Regex("\\#.*", RegexOptions.Compiled) }) ); var serverConfig = parser.ReadFile("config/server.ini"); var marketConfig = parser.ReadFile("config/market.ini"); if (!serverConfig.TryGetKey("PasswordSalt", out var serverPasswordSalt)) { throw new Exception("Unable to read 'PasswordSalt' from server config."); } if (!serverConfig.TryGetKey("Port", out var serverPort)) { throw new Exception("Unable to read 'Port' from server config."); } if (!marketConfig.TryGetKey("MarketAdminAccount", out var marketAdminAccount)) { throw new Exception("Unable to read 'MarketAdminAccount' from market config."); } this.Username = marketAdminAccount.Split(':')[0]; this.Password = marketAdminAccount.Split(':')[1]; this.ServerPasswordSalt = serverPasswordSalt; this.ServerPort = int.Parse(serverPort); this.Client.ConnectToServer("localhost", this.ServerPort); if (!this.API.Initialize(0, 0, 28, new HDSerialNumberService().GetHDSerialNumber(), out var data)) { throw new TimeoutException(string.Format("Failed initialization handshake with server!")); } this.Client.SetInitData(data); if (!this.API.ConfirmInit(data.emulti_e, data.emulti_d, data.clientID)) { throw new TimeoutException(string.Format("Failed initialization handshake with server!")); } if (!this.API.Initialized || !this.Client.ConnectedAndInitialized || data.ServerResponse != InitReply.INIT_OK) { throw new InvalidOperationException(string.Format("Invalid response from server or connection failed! Must receive an OK reply.")); } if (!this.API.LoginRequest(this.Username, this.Password, out var reply, out var loginData)) { throw new Exception($"Unable to login to the server. {reply}"); } if (!this.API.SelectCharacter(loginData[0].ID, out var welcomeReqData)) { throw new Exception("Unable to select character."); } if (!this.API.WelcomeMessage(welcomeReqData.ActiveCharacterID, out var welcomeMsgData)) { throw new Exception("Unable to send welcome message."); } this.API.OnServerPingReply += (ping) => Console.WriteLine($"[Marketplace Bot] Ping. ({ping})"); this.Client.AddPacketHandler(new FamilyActionPair(PacketFamily.AdminInteract, PacketAction.List), new PacketHandler((packet) => { var name = packet.GetBreakString().Split(' ').Reverse().Skip(1).Take(1).First().ToLower(); var inventoryItems = new List <(int id, int amount)>(); packet.Skip(4 + 1 + 4 + 1); while (packet.PeekByte() != 255) { var id = (int)packet.GetShort(); var amount = packet.GetInt(); if (id == 1) { continue; } inventoryItems.Add((id, amount)); } this.RequestedInventories.RemoveAll(p => p.Name == name); this.RequestedInventories.Add(new CharacterInventory() { Name = name, Items = inventoryItems.Select(i => new InventoryItem() { Id = i.id, Amount = i.amount }).ToList(), Timestamp = DateTime.Now }); }), true); EasyTimer.SetInterval(() => { if (this.CommandsQueue.Any()) { this.API.Speak(TalkType.Local, this.CommandsQueue.Dequeue()); } }, 500); EasyTimer.SetInterval(() => { if (this.Client.ConnectedAndInitialized && this.API.Initialized) { this.API.PingServer(); } }, 5000); // TODO: Update the EIF data from the server, supporting remotely hosted EOMarket bots. //this.API.RequestFile(InitFileType.Item); }