示例#1
0
        public void TestInitialGold()
        {
            var service = new GoldService();

            Assert.AreEqual(0, service.GetGold(0));
            Assert.AreEqual(0, service.GetGold(1));
            Assert.AreEqual(0, service.GetGold(10));
        }
示例#2
0
        public void TestGoldReset()
        {
            var service = new GoldService();


            service.AddGold(0, 3);
            service.AddGold(1, 12);

            service.Reset();

            Assert.AreEqual(0, service.GetGold(0));
            Assert.AreEqual(0, service.GetGold(1));
            Assert.AreEqual(0, service.GetGold(2));
        }
示例#3
0
        public void TestGold()
        {
            var service = new GoldService();

            service.AddGold(0, 1);

            Assert.AreEqual(1, service.GetGold(0));

            service.AddGold(0, 3);

            Assert.AreEqual(4, service.GetGold(0));
            Assert.AreEqual(0, service.GetGold(1));

            service.AddGold(1, 1);

            Assert.AreEqual(4, service.GetGold(0));
            Assert.AreEqual(1, service.GetGold(1));


            service.RemoveGold(0, 2);

            Assert.AreEqual(2, service.GetGold(0));
            Assert.AreEqual(1, service.GetGold(1));

            service.RemoveGold(0, -10);

            Assert.AreEqual(12, service.GetGold(0));
            Assert.AreEqual(1, service.GetGold(1));

            service.RemoveGold(1, 1);

            Assert.AreEqual(12, service.GetGold(0));
            Assert.AreEqual(0, service.GetGold(1));

            service.RemoveGold(1, 1);

            Assert.AreEqual(12, service.GetGold(0));
            Assert.AreEqual(0, service.GetGold(1));

            service.RemoveGold(0, 100);

            Assert.AreEqual(0, service.GetGold(0));
            Assert.AreEqual(0, service.GetGold(1));
        }
 public GoldModule(GoldService goldserv)
 {
     _goldserv = goldserv;
 }
        public static Dictionary<string, Dictionary<int, Dictionary<string, int>>> getListGoldSupplier(IntPtr handle, int procId, int address) {
            listGoldSupplierCount++;

            if (listGoldSupplierCount > 5) {
                if (getActiveWinName(handle) == "MsgBox_LinkBroken") {
                    Form1.runThread.Abort();
                }
            }

            Dictionary<string, Dictionary<int, Dictionary<string, int>>> goldArray = new Dictionary<string, Dictionary<int, Dictionary<string, int>>>();

            Dictionary<int, Dictionary<string, int>> saleArray = new Dictionary<int, Dictionary<string, int>>();
            Dictionary<int, Dictionary<string, int>> buyArray = new Dictionary<int, Dictionary<string, int>>();

            //addToConsole("Пакет на обновление");

            PacketService.sendPacket(handle, procId, GoldService.RefreshListPacketSupplier());

            //addToConsole("отправили");
            //address = 0x1ce7f3e8;

            var dateTime1 = DateTime.Now;

            while (true) {
                var tmp = new byte [230];
                IntPtr read = IntPtr.Zero;

                ReadProcessMemory(handle, (IntPtr) address, tmp, 230, out read);
                //addToConsole("0 - " + tmp [0] + "1 - " + tmp [1]);
       

                if (tmp [0] == 0x81 && tmp [1] == 0x96) {

                    int rateCount = tmp [8];
                    int offsetId = 9;
                    int offsetPrice = 21;
                    int offsetCount = 25;

                    if (tmp[7] == 0) {
                        goldArray.Add("buy", buyArray);
                        goldArray.Add("sale", saleArray);
                        return goldArray;
                    } else if (tmp[9] == 0) {

                    } else if (tmp [8] == 0 && tmp[3] == 0) {
                        rateCount = tmp [7];

                        offsetId--;
                        offsetPrice--;
                        offsetCount--;
                    }

                    var tmp123 = BitConverter.ToString(tmp);

                    if (rateCount > 10 || rateCount < 0) {
                        /*addToConsoleBug("");
                        addToConsoleBug(DateTime.Now.ToString());
                        addToConsoleBug("Пришел конченый запрос");
                        addToConsoleBug(BitConverter.ToString(tmp));*/
                        return getListGoldSupplier(handle, procId, address);
                    }

                    byte [] idsByte2 = new byte [4];
                    byte [] priceByte2 = new byte [4];
                    byte [] countByte2 = new byte [4];

                    for (int i = 0; i < rateCount; i++) {
                        Dictionary<string, int> goldInfo = new Dictionary<string, int>();


                        idsByte2 [0] = tmp [offsetId + i * 21];
                        idsByte2 [1] = tmp [offsetId + i * 21 + 1];
                        idsByte2 [2] = tmp [offsetId + i * 21 + 2];
                        idsByte2 [3] = tmp [offsetId + i * 21 + 3];

                        priceByte2 [0] = tmp [offsetPrice + i * 21];
                        priceByte2 [1] = tmp [offsetPrice + i * 21 + 1];
                        priceByte2 [2] = tmp [offsetPrice + i * 21 + 2];
                        priceByte2 [3] = tmp [offsetPrice + i * 21 + 3];

                        countByte2 [0] = tmp [offsetCount + i * 21];
                        countByte2 [1] = tmp [offsetCount + i * 21 + 1];
                        countByte2 [2] = tmp [offsetCount + i * 21 + 2];
                        countByte2 [3] = tmp [offsetCount + i * 21 + 3];

                        int id = Int32.Parse(ByteArrayToString(idsByte2), System.Globalization.NumberStyles.HexNumber);
                        int price = Int32.Parse(ByteArrayToString(priceByte2), System.Globalization.NumberStyles.HexNumber);
                        int count = Int32.Parse(ByteArrayToString(countByte2), System.Globalization.NumberStyles.HexNumber);

                        if (count < 0 || count > 1000) {
                            /*addToConsoleBug("");
                            addToConsoleBug(DateTime.Now.ToString());
                            addToConsoleBug("Пришел конченый запрос, количество хреновое");
                            addToConsoleBug(BitConverter.ToString(tmp));*/
                            return getListGoldSupplier(handle, procId, address);
                        }

                        goldInfo.Add("id", id);
                        goldInfo.Add("count", count);

                        if (price > 0) {
                            goldInfo.Add("price", price);

                            saleArray.Add(id, goldInfo);
                        } else {
                            goldInfo.Add("price", price * -1);
                            buyArray.Add(id, goldInfo);
                        }

                    }

                    goldArray.Add("buy", buyArray);
                    goldArray.Add("sale", saleArray);

                    listGoldSupplierCount = 0;

                    return goldArray;
                }
                var dateTime2 = DateTime.Now;
                var diffInSeconds = (dateTime2 - dateTime1).TotalSeconds;

                if (diffInSeconds > 5) {
                    //addToConsole("Прошло 5 сек");

                    if ((tmp [0] == 0 && tmp [1] == 0 && tmp [2] == 0 && tmp [3] == 0) || LowLevelReadIntFromMemory(handle, GameService.OnlineAddress) == 2) {
                        if(getActiveWinName(handle) == "MsgBox_LinkBroken") {
                            Form1.runThread.Abort();
                        }
                    }
                    return getListGoldSupplier(handle, procId, address);
                }

            }

            
        }
        public static Dictionary<string, Dictionary<int, int>> getListGold(IntPtr handle, int procId, int address) {
            listGoldCount++;

            if (listGoldCount > 5) {
                if (getActiveWinName(handle) == "MsgBox_LinkBroken") {
                    Form1.runThread.Abort();
                }
            }

            Dictionary<string, Dictionary<int, int>> goldArray = new Dictionary<string, Dictionary<int, int>>();

            Dictionary<int, int> saleArray = new Dictionary<int, int>();
            Dictionary<int, int> saleArray2 = new Dictionary<int, int>();
            Dictionary<int, int> buyArray = new Dictionary<int, int>();

            

            PacketService.sendPacket(handle, procId, GoldService.RefreshListPacket());

            var dateTime1 = DateTime.Now;

            while (true) {
                var tmp = new byte [141];
                IntPtr read = IntPtr.Zero;

                ReadProcessMemory(handle, (IntPtr) address, tmp, 141, out read);

                if (tmp [0] == 0x81 && tmp [1] == 0x98) {

                    byte [] priceByte = new byte [4];
                    byte [] countByte = new byte [4];

                    byte [] moneyByte = new byte [4];
                    byte [] goldByte = new byte [4];

                    int offsetPrice = 13;
                    int offsetCount = 17;
                    int offsetMoney = 8;
                    int offsetGold = 4;

                    int count2 = tmp [12];

                    if (count2 == 0 || count2 == 255) {
                        count2 = tmp [11];
                        offsetPrice--;
                        offsetCount--;
                        offsetMoney--;
                        offsetGold--;
                    }

                    if (count2 > 16) {
                        count2 = 0;
                    }

                    moneyByte [0] = tmp [offsetMoney];
                    moneyByte [1] = tmp [offsetMoney + 1];
                    moneyByte [2] = tmp [offsetMoney + 2];
                    moneyByte [3] = tmp [offsetMoney + 3];

                    goldByte [0] = tmp [offsetGold];
                    goldByte [1] = tmp [offsetGold + 1];
                    goldByte [2] = tmp [offsetGold + 2];
                    goldByte [3] = tmp [offsetGold + 3];

                    goldAuctionMoney = Int32.Parse(ByteArrayToString(moneyByte), System.Globalization.NumberStyles.HexNumber);
                    goldAuctionGold = Int32.Parse(ByteArrayToString(goldByte), System.Globalization.NumberStyles.HexNumber);



                    for (int i = 0; i < count2; i++) {

                        priceByte [0] = tmp [offsetPrice + i * 8];
                        priceByte [1] = tmp [offsetPrice + i * 8 + 1];
                        priceByte [2] = tmp [offsetPrice + i * 8 + 2];
                        priceByte [3] = tmp [offsetPrice + i * 8 + 3];

                        countByte [0] = tmp [offsetCount + i * 8];
                        countByte [1] = tmp [offsetCount + i * 8 + 1];
                        countByte [2] = tmp [offsetCount + i * 8 + 2];
                        countByte [3] = tmp [offsetCount + i * 8 + 3];

                        int price = Int32.Parse(ByteArrayToString(priceByte), System.Globalization.NumberStyles.HexNumber);
                        int count = Int32.Parse(ByteArrayToString(countByte), System.Globalization.NumberStyles.HexNumber);

                        if (price < 0) {
                            price *= -1;
                            buyArray.Add(price, count);
                        } else {
                            saleArray.Add(price, count);
                        }

                    }


                    
                    goldArray.Add("buy", buyArray);


                    var saleKeys = saleArray.Keys.ToList();
                    saleKeys.Sort();
                    foreach (var key in saleKeys) {
                        saleArray2.Add(key, saleArray[key]);
                    }

                    goldArray.Add("sale", saleArray2);

                    listGoldCount = 0;

                    return goldArray;
                }
                var dateTime2 = DateTime.Now;
                var diffInSeconds = (dateTime2 - dateTime1).TotalSeconds;

                if (diffInSeconds > 5) {
                    if ((tmp[0] == 0 && tmp[1] == 0 && tmp[2] == 0 && tmp[3] == 0) || LowLevelReadIntFromMemory(handle, GameService.OnlineAddress) == 2) {
                        if (getActiveWinName(handle) == "MsgBox_LinkBroken") {
                            Form1.runThread.Abort();
                        }
                    }
                    return getListGold(handle, procId, address);
                }

                Thread.Sleep(10);
            }
        }