public string HandlePacketFromServer(ENetPacket packet)
        {
            if (MainForm.proxyPeer == null)
            {
                return("");
            }
            if (MainForm.proxyPeer.State != ENetPeerState.Connected)
            {
                return("");
            }
            if (MainForm.realPeer == null)
            {
                return("");
            }
            if (MainForm.realPeer.State != ENetPeerState.Connected)
            {
                return("");
            }

            byte[] data = packet.GetPayloadFinal();
            if (data.Length > 5)
            {
                if (data[5] == 3)
                {
                    return("_none_");
                }
            }
            //else
            //{
            //return "_none_";
            //}


            NetTypes.NetMessages msgType = GetMessageType(data);
            switch (msgType)
            {
            case NetTypes.NetMessages.SERVER_HELLO:

                MainForm.LogText += ("[" + DateTime.UtcNow + "] (SERVER): Initial logon accepted." + "\n");
                break;

            case NetTypes.NetMessages.GAME_MESSAGE:

                string str = GetProperGenericText(data);
                MainForm.LogText += ("[" + DateTime.UtcNow + "] (SERVER): A game_msg packet was sent: " + str + "\n");
                if (str.Contains("Server requesting that you re-logon..."))
                {
                    MainForm.token  = 0;
                    MainForm.doorid = "";

                    SwitchServers("213.179.209.168", 17234);

                    return("Server forces logon request, switching server automatically so user does not have to cancel to login menu and reconnect.");
                }
                break;

            case NetTypes.NetMessages.GAME_PACKET:

                byte[] tankPacket = VariantList.get_struct_data(data);
                if (tankPacket == null)
                {
                    break;
                }

                NetTypes.PacketTypes packetType = GetPacketType(tankPacket);


                switch (packetType)
                {
                case NetTypes.PacketTypes.CALL_FUNCTION:
                    VariantList.VarList VarListFetched = VariantList.GetCall(VariantList.get_extended_data(tankPacket));
                    VarListFetched.netID = BitConverter.ToInt32(tankPacket, 4);         // add netid
                    VarListFetched.delay = BitConverter.ToUInt32(tankPacket, 20);       // add keep track of delay modifier

                    int    netID   = OperateVariant(VarListFetched);
                    string argText = string.Empty;

                    for (int i = 0; i < VarListFetched.functionArgs.Count(); i++)
                    {
                        argText += " [" + i.ToString() + "]: " + (string)VarListFetched.functionArgs[i].ToString();
                    }

                    MainForm.LogText += ("[" + DateTime.UtcNow + "] (SERVER): A function call was requested, see log infos below:\nFunction Name: " + VarListFetched.FunctionName + " parameters: " + argText + " \n");

                    if (VarListFetched.FunctionName == "OnSendToServer")
                    {
                        return("Server switching forced, not continuing as Proxy Client has to deal with this.");
                    }
                    if (VarListFetched.FunctionName == "onShowCaptcha")
                    {
                        return("Received captcha solving request, instantly bypassed it so it doesnt show up on client side.");
                    }
                    if (VarListFetched.FunctionName == "OnDialogRequest" && ((string)VarListFetched.functionArgs[1]).ToLower().Contains("captcha"))
                    {
                        return("Received captcha solving request, instantly bypassed it so it doesnt show up on client side.");
                    }
                    if (VarListFetched.FunctionName == "OnSetPos" && MainForm.ignoreonsetpos && netID == worldMap.netID)
                    {
                        return("Ignored position set by server, may corrupt doors but is used so it wont set back. (CAN BE BUGGY WITH SLOW CONNECTIONS)");
                    }
                    if (VarListFetched.FunctionName == "OnSpawn" && netID == -2)
                    {
                        return("Modified OnSpawn for unlimited zoom (mstate|1)");                                                                 // only doing unlimited zoom and not unlimited punch/place to be sure that no bans occur due to this. If you wish to use unlimited punching/placing as well, change the smstate in OperateVariant function instead.
                    }

                    /*if (VarListFetched.FunctionName == "OnSetClothing" && VarListFetched.netID == worldMap.netID)
                     * {
                     *  if (!worldMap.player.didClothingLoad)
                     *  {
                     *      worldMap.player.didClothingLoad = true;
                     *      Task.Delay(400).ContinueWith(t => PacketSending.SendData(data, MainForm.proxyPeer));
                     *      return "applying onsetclothing delayed...";
                     *  }
                     * }*/
                    // unused since 1.5.5
                    break;

                case NetTypes.PacketTypes.SET_CHARACTER_STATE:
                    /*if (!worldMap.player.didCharacterStateLoad)
                     * {
                     *  worldMap.player.didCharacterStateLoad = true; // optimization
                     *  Task.Delay(400).ContinueWith(t => PacketSending.SendData(data, MainForm.proxyPeer));
                     * }*/
                    // unused since 1.5.5
                    break;

                case NetTypes.PacketTypes.PING_REQ:
                    SpoofedPingReply();
                    break;

                case NetTypes.PacketTypes.LOAD_MAP:
                    if (MainForm.LogText.Length >= 65536)
                    {
                        MainForm.LogText = string.Empty;
                    }

                    worldMap = worldMap.LoadMap(tankPacket);
                    worldMap.player.didCharacterStateLoad = false;
                    worldMap.player.didClothingLoad       = false;

                    break;

                case NetTypes.PacketTypes.MODIFY_ITEM_OBJ:
                {
                    TankPacket p = TankPacket.UnpackFromPacket(data);
                    if (p.NetID == -1)
                    {
                        if (worldMap == null)
                        {
                            MainForm.LogText += ("[" + DateTime.UtcNow + "] (PROXY): (ERROR) World map was null." + "\n");
                            break;
                        }

                        worldMap.dropped_ITEMUID++;

                        DroppedObject dItem = new DroppedObject();
                        dItem.id        = p.MainValue;
                        dItem.itemCount = data[16];
                        dItem.x         = p.X;
                        dItem.y         = p.Y;
                        dItem.uid       = worldMap.dropped_ITEMUID;
                        worldMap.droppedItems.Add(dItem);

                        if (MainForm.cheat_magplant)
                        {
                            TankPacket p2 = new TankPacket();
                            p2.PacketType = (int)NetTypes.PacketTypes.ITEM_ACTIVATE_OBJ;
                            p2.NetID      = p.NetID;
                            p2.X          = (int)p.X;
                            p2.Y          = (int)p.Y;
                            p2.MainValue  = dItem.uid;

                            PacketSending.SendPacketRaw((int)NetTypes.NetMessages.GAME_PACKET, p2.PackForSendingRaw(), MainForm.realPeer);
                            //return "Blocked dropped packet due to magplant hack (auto collect/pickup range) tried to collect it instead, infos of dropped item => uid was " + worldMap.dropped_ITEMUID.ToString() + " id: " + p.MainValue.ToString();
                        }
                    }
                }
                break;

                default:
                    break;
                }
                break;

            case NetTypes.NetMessages.TRACK:
            case NetTypes.NetMessages.LOG_REQ:
            case NetTypes.NetMessages.ERROR:
                return("Blocked track/logreq/error message type by server.");

            default:
                return("(SERVER): An unknown event occured. Message Type: " + msgType.ToString() + "\n");

                break;
            }

            PacketSending.SendData(data, MainForm.proxyPeer, ENetPacketFlags.Reliable);
            if (msgType == NetTypes.NetMessages.GAME_PACKET && data[4] > 39) // customizable on which packets you wanna log, for speed im just gonna do this!
            {
                TankPacket p           = TankPacket.UnpackFromPacket(data);
                uint       extDataSize = BitConverter.ToUInt32(data, 56);
                byte[]     actualData  = data.Skip(4).Take(56).ToArray();
                byte[]     extData     = data.Skip(60).ToArray();

                string extDataStr      = "";
                string extDataStrShort = "";
                string extDataString   = Encoding.UTF8.GetString(extData);
                for (int i = 0; i < extDataSize; i++)
                {
                    //ushort pos = BitConverter.ToUInt16(extData, i);
                    extDataStr += extData[i].ToString() + "|";
                }


                return("Log of potentially wanted received GAME_PACKET Data:" +
                       "\npackettype: " + actualData[0].ToString() +
                       "\npadding byte 1|2|3: " + actualData[1].ToString() + "|" + actualData[2].ToString() + "|" + actualData[3].ToString() +
                       "\nnetID: " + p.NetID +
                       "\nsecondnetid: " + p.SecondaryNetID +
                       "\ncharacterstate (prob 8): " + p.CharacterState +
                       "\nwaterspeed / offs 16: " + p.Padding +
                       "\nmainval: " + p.MainValue +
                       "\nX|Y: " + p.X + "|" + p.Y +
                       "\nXSpeed: " + p.XSpeed +
                       "\nYSpeed: " + p.YSpeed +
                       "\nSecondaryPadding: " + p.SecondaryPadding +
                       "\nPunchX|PunchY: " + p.PunchX + "|" + p.PunchY +
                       "\nExtended Packet Data Length: " + extDataSize.ToString() +
                       "\nExtended Packet Data:\n" + extDataStr + "\n");

                return(string.Empty);
            }
            else
            {
                return(string.Empty);
            }
        }
        private void ghostmodskin_CheckedChanged(object sender, EventArgs e)
        {
            if (ghostmodskin.Checked)
            {
                skinColor[0] = 110; // A - transparency
                skinColor[1] = 255;
                skinColor[2] = 255;
                skinColor[3] = 255;

                GamePacketProton variantPacket = new GamePacketProton();
                variantPacket.AppendString("OnChangeSkin");
                variantPacket.AppendUInt(BitConverter.ToUInt32(skinColor, 0));
                variantPacket.NetID = messageHandler.worldMap.netID;
                //variantPacket.delay = 100;
                PacketSending.SendData(variantPacket.GetBytes(), proxyPeer);
            }
            else
            {
                skinColor[0] = 255;
                GamePacketProton variantPacket = new GamePacketProton();
                variantPacket.AppendString("OnChangeSkin");
                variantPacket.AppendUInt(BitConverter.ToUInt32(skinColor, 0));
                variantPacket.NetID = messageHandler.worldMap.netID;
                //variantPacket.delay = 100;
                PacketSending.SendData(variantPacket.GetBytes(), proxyPeer);
            }
        }
        private void changeNameBox_TextChanged(object sender, EventArgs e)
        {
            GamePacketProton variantPacket = new GamePacketProton();

            variantPacket.AppendString("OnNameChanged");
            variantPacket.AppendString("`w" + changeNameBox.Text + "``");
            variantPacket.NetID = messageHandler.worldMap.netID;
            PacketSending.SendData(variantPacket.GetBytes(), proxyPeer);
            //variantPacket.NetID =
        }
        void doRGBHack()
        {
            bool k1   = false;
            bool k2   = false;
            bool k3   = false;
            bool kAll = false;

            while (rgbSkinHack.Checked)
            {
                Thread.Sleep(32);
                skinColor[0] = 255;

                if (kAll == false)
                {
                    if (skinColor[1] < 255)
                    {
                        skinColor[1]++;
                    }
                    else
                    {
                        k1 = true;
                    }
                    if (k1 == true)
                    {
                        if (skinColor[2] < 255)
                        {
                            skinColor[2]++;
                        }
                        else
                        {
                            k2 = true;
                        }
                    }
                    if (k2 == true)
                    {
                        if (skinColor[3] < 255)
                        {
                            skinColor[3]++;
                        }
                        else
                        {
                            k3 = true;
                        }
                    }

                    if (k3 == true)
                    {
                        kAll = true;
                    }
                }
                else
                {
                    if (skinColor[3] > 0)
                    {
                        skinColor[3]--;
                    }
                    else
                    {
                        k1 = false;
                    }
                    if (k1 == false)
                    {
                        if (skinColor[2] > 0)
                        {
                            skinColor[2]--;
                        }
                        else
                        {
                            k2 = false;
                        }
                    }
                    if (k2 == false)
                    {
                        if (skinColor[1] > 0)
                        {
                            skinColor[1]--;
                        }
                        else
                        {
                            k3 = false;
                        }
                    }

                    if (k3 == false)
                    {
                        kAll = false;
                    }
                }



                //else Array.Copy(BitConverter.GetBytes(0), 0, skinColor, 1, 3);

                GamePacketProton variantPacket = new GamePacketProton();
                variantPacket.AppendString("OnChangeSkin");
                variantPacket.AppendUInt(BitConverter.ToUInt32(skinColor, 0));
                variantPacket.NetID = messageHandler.worldMap.netID;
                //variantPacket.delay = 100;
                PacketSending.SendData(variantPacket.GetBytes(), proxyPeer);
            }
        }
        public string HandlePacketFromClient(ENetPacket packet) // Why string? Oh yeah, it's the best thing to also return a string response for anything you want!
        {
            if (MainForm.proxyPeer == null)
            {
                return("");
            }
            if (MainForm.proxyPeer.State != ENetPeerState.Connected)
            {
                return("");
            }
            if (MainForm.realPeer == null)
            {
                return("");
            }
            if (MainForm.realPeer.State != ENetPeerState.Connected)
            {
                return("");
            }

            byte[] data = packet.GetPayloadFinal();

            switch (GetMessageType(data))
            {
            case NetTypes.NetMessages.GENERIC_TEXT:
                string str = GetProperGenericText(data);

                MainForm.LogText += ("[" + DateTime.UtcNow + "] (CLIENT): String package fetched:\n" + str + "\n");
                if (str.StartsWith("action|"))
                {
                    string actionExecuted = str.Substring(7, str.Length - 7);
                    string inputPH        = "input\n|text|";
                    if (actionExecuted.StartsWith("enter_game"))
                    {
                        if (MainForm.blockEnterGame)
                        {
                            return("Blocked enter_game packet!");
                        }
                        enteredGame = true;
                    }
                    else if (actionExecuted.StartsWith(inputPH))
                    {
                        string text = actionExecuted.Substring(inputPH.Length);

                        if (text.Length > 0)
                        {
                            if (text.StartsWith("/"))     // bAd hAcK - but also lazy, so i'll be doing this.
                            {
                                switch (text)
                                {
                                case "/banworld":
                                {
                                    banEveryoneInWorld();
                                    return("called /banworld, attempting to ban everyone who is in world (requires admin/owner)");
                                }
                                break;

                                default:
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    // for (int i = 0; i < 1000; i++) PacketSending.SendPacket(2, "action|refresh_item_data\n", MainForm.realPeer);
                    string[] lines = str.Split('\n');

                    string tankIDName = "";
                    foreach (string line in lines)
                    {
                        string[] lineToken = line.Split('|');
                        if (lineToken.Length != 2)
                        {
                            continue;
                        }
                        switch (lineToken[0])
                        {
                        case "tankIDName":
                            tankIDName = lineToken[1];
                            break;

                        case "tankIDPass":
                            MainForm.tankIDPass = lineToken[1];
                            break;

                        case "requestedName":
                            MainForm.requestedName = lineToken[1];
                            break;
                        }
                    }
                    MainForm.tankIDName = tankIDName;

                    bool hasAcc = false;
                    if (tankIDName.Length > 0)
                    {
                        hasAcc = true;
                    }
                    PacketSending.SendPacket((int)NetTypes.NetMessages.GENERIC_TEXT, MainForm.CreateLogonPacket(hasAcc), MainForm.realPeer);
                    return("Sent logon packet!");    // handling logon over proxy
                }
                break;

            case NetTypes.NetMessages.GAME_MESSAGE:
                string str2 = GetProperGenericText(data);
                MainForm.LogText += ("[" + DateTime.UtcNow + "] (CLIENT): String package fetched:\n" + str2 + "\n");
                if (str2.StartsWith("action|"))
                {
                    string actionExecuted = str2.Substring(7, str2.Length - 7);
                    if (actionExecuted == "quit")
                    {
                        MainForm.token          = 0;
                        MainForm.Growtopia_IP   = "213.179.209.168";
                        MainForm.Growtopia_Port = 17234;
                        MainForm.realPeer.DisconnectLater(100);
                        MainForm.proxyPeer.DisconnectLater(100);
                    }
                }
                break;

            case NetTypes.NetMessages.GAME_PACKET:
            {
                TankPacket p = TankPacket.UnpackFromPacket(data);
                switch ((NetTypes.PacketTypes)(byte) p.PacketType)
                {
                case NetTypes.PacketTypes.APP_INTEGRITY_FAIL:                                             /*rn definitely just blocking autoban packets,
                                                                                                           * usually a failure of an app integrity is never good
                                                                                                           * and usually used for security stuff*/
                    return("Possible autoban packet with id (25) from your GT Client has been blocked."); // remember, returning anything will interrupt sending this packet. To Edit packets, load/parse them and you may just resend them like normally after fetching their bytes.

                case NetTypes.PacketTypes.PLAYER_LOGIC_UPDATE:
                    if (p.PunchX > 0 || p.PunchY > 0)
                    {
                        MainForm.LogText += ("[" + DateTime.UtcNow + "] (PROXY): PunchX/PunchY detected, pX: " + p.PunchX.ToString() + " pY: " + p.PunchY.ToString() + "\n");
                    }
                    worldMap.player.X = (int)p.X;
                    worldMap.player.Y = (int)p.Y;
                    break;

                case NetTypes.PacketTypes.ITEM_ACTIVATE_OBJ:             // just incase, to keep better track of items incase something goes wrong
                    worldMap.dropped_ITEMUID = p.MainValue;
                    break;

                default:
                    break;
                }
            }
            break;

            case NetTypes.NetMessages.TRACK:
                return("Packet with messagetype used for tracking was blocked!");

            case NetTypes.NetMessages.LOG_REQ:
                return("Log request packet from client was blocked!");

            default:
                break;
            }

            PacketSending.SendData(data, MainForm.realPeer, ENetPacketFlags.Reliable);
            return(string.Empty);
        }
Exemple #6
-1
        /*
         **ONSENDTOSERVER INDEXES/VALUE LOCATIONS**
         *  port = 1
         *  token = 2
         *  userId = 3
         *  IPWithExtraData = 4
         *  lmode = 5 (Used for determining how client should behave when leaving, and could also influence the connection after.
         */
        private int OperateVariant(VariantList.VarList vList)
        {
            switch (vList.FunctionName)
            {
            case "OnSuperMainStartAcceptLogonHrdxs47254722215a":
            {
                if (MainForm.skipCache)
                {
                    MainForm.LogText += ("[" + DateTime.UtcNow + "] (CLIENT): Skipping potential caching (will make world list disappear)...");
                    GamePacketProton gp = new GamePacketProton();         // variant list
                    gp.AppendString("OnRequestWorldSelectMenu");
                    packetSender.SendData(gp.GetBytes(), MainForm.proxyPeer);
                }
                return(-1);
            }

            case "OnZoomCamera":
            {
                MainForm.LogText += ("[" + DateTime.UtcNow + "] (SERVER): Camera zoom parameters (" + vList.functionArgs.Length + "): v1: " + ((float)vList.functionArgs[1] / 1000).ToString() + " v2: " + vList.functionArgs[2].ToString());
                return(-1);
            }

            case "onShowCaptcha":
                ((string)vList.functionArgs[1]).Replace("PROCESS_LOGON_PACKET_TEXT_42", "");    // make captcha completable
                try
                {
                    string[] lines = ((string)vList.functionArgs[1]).Split('\n');
                    foreach (string line in lines)
                    {
                        if (line.Contains("+"))
                        {
                            string   line2 = line.Replace(" ", "");
                            int      a1, a2;
                            string[] splitByPipe = line2.Split('|');
                            string[] splitByPlus = splitByPipe[1].Split('+');
                            a1 = int.Parse(splitByPlus[0]);
                            a2 = int.Parse(splitByPlus[1]);
                            int    result          = a1 + a2;
                            string resultingPacket = "action|dialog_return\ndialog_name|captcha_submit\ncaptcha_answer|" + result.ToString() + "\n";
                            packetSender.SendPacket(2, resultingPacket, MainForm.realPeer);
                        }
                    }
                    return(-1);
                }
                catch
                {
                    return(-1);    // Give this to user.
                }

            case "OnDialogRequest":
                MainForm.LogText += ("[" + DateTime.UtcNow + "] (SERVER): OnDialogRequest called, logging its params here:\n" +
                                     (string)vList.functionArgs[1] + "\n");
                if (!((string)vList.functionArgs[1]).ToLower().Contains("captcha"))
                {
                    return(-1);                                                                 // Send Client Dialog
                }
                ((string)vList.functionArgs[1]).Replace("PROCESS_LOGON_PACKET_TEXT_42", "");    // make captcha completable
                try
                {
                    string[] lines = ((string)vList.functionArgs[1]).Split('\n');
                    foreach (string line in lines)
                    {
                        if (line.Contains("+"))
                        {
                            string   line2 = line.Replace(" ", "");
                            int      a1, a2;
                            string[] splitByPipe = line2.Split('|');
                            string[] splitByPlus = splitByPipe[1].Split('+');
                            a1 = int.Parse(splitByPlus[0]);
                            a2 = int.Parse(splitByPlus[1]);
                            int    result          = a1 + a2;
                            string resultingPacket = "action|dialog_return\ndialog_name|captcha_submit\ncaptcha_answer|" + result.ToString() + "\n";
                            packetSender.SendPacket(2, resultingPacket, MainForm.realPeer);
                        }
                    }
                    return(-1);
                }
                catch
                {
                    return(-1);    // Give this to user.
                }

            case "OnSendToServer":
            {
                string ip = (string)vList.functionArgs[4];

                if (ip.Contains("|"))
                {
                    ip = ip.Substring(0, ip.IndexOf("|"));
                }

                int port   = (int)vList.functionArgs[1];
                int userID = (int)vList.functionArgs[3];
                int token  = (int)vList.functionArgs[2];
                int lmode  = (int)vList.functionArgs[5];

                MainForm.lmode = lmode;
                if (MainForm.token <= 0)
                {
                    ip             = MainForm.Growtopia_Master_IP;
                    port           = MainForm.Growtopia_Master_Port;
                    MainForm.token = token;
                }
                MainForm.userID = userID;

                MainForm.LogText += ("[" + DateTime.UtcNow + "] (SERVER): OnSendToServer (func call used for server switching/sub-servers) " +
                                     "IP: " +
                                     ip + " PORT: " + port
                                     + " UserId: " + userID
                                     + " Session-Token: " + token + "\n");
                GamePacketProton variantPacket = new GamePacketProton();
                variantPacket.AppendString("OnConsoleMessage");
                variantPacket.AppendString("`6(PROXY)`o Switching subserver...``");
                packetSender.SendData(variantPacket.GetBytes(), MainForm.proxyPeer);


                GamePacketProton variantPacket2 = new GamePacketProton();
                variantPacket2.AppendString("OnSendToServer");
                variantPacket2.AppendInt(2);
                variantPacket2.AppendInt(token);
                variantPacket2.AppendInt(userID);
                variantPacket2.AppendString("127.0.0.1|" + MainForm.doorid);
                variantPacket2.AppendInt(lmode);

                // MainForm.doorid = ""; fix cant enter door with link to other door in other subserver/world
                packetSender.SendData(variantPacket2.GetBytes(), MainForm.proxyPeer);

                MainForm.Growtopia_IP   = ip;       // proper sub server switching
                MainForm.Growtopia_Port = port;



                return(-1);
            }

            case "OnSpawn":
            {
                worldMap.playerCount++;
                string onspawnStr = (string)vList.functionArgs[1];
                //MessageBox.Show(onspawnStr);
                string[] tk    = onspawnStr.Split('|');
                Player   p     = new Player();
                string[] lines = onspawnStr.Split('\n');

                bool localplayer = false;

                foreach (string line in lines)
                {
                    string[] lineToken = line.Split('|');
                    if (lineToken.Length != 2)
                    {
                        continue;
                    }
                    switch (lineToken[0])
                    {
                    case "netID":
                        p.netID = Convert.ToInt32(lineToken[1]);
                        break;

                    case "userID":
                        p.userID = Convert.ToInt32(lineToken[1]);
                        break;

                    case "name":
                        p.name = lineToken[1];
                        break;

                    case "country":
                        p.country = lineToken[1];
                        break;

                    case "invis":
                        p.invis = Convert.ToInt32(lineToken[1]);
                        break;

                    case "mstate":
                        p.mstate = Convert.ToInt32(lineToken[1]);
                        break;

                    case "smstate":
                        p.mstate = Convert.ToInt32(lineToken[1]);
                        break;

                    case "type":
                        if (lineToken[1] == "local")
                        {
                            localplayer = true;
                        }
                        break;
                    }
                }
                //MainForm.LogText += ("[" + DateTime.UtcNow + "] (PROXY): " + onspawnStr);
                worldMap.players.Add(p);
                if (p.name.Length > 2)
                {
                    worldMap.AddPlayerControlToBox(p);
                }


                /*if (p.name.Contains(MainForm.tankIDName))
                 * {
                 *
                 * }*///crappy code

                if (p.mstate > 0 || p.smstate > 0 || p.invis > 0)
                {
                    if (MainForm.cheat_autoworldban_mod)
                    {
                        banEveryoneInWorld();
                    }
                    MainForm.LogText += ("[" + DateTime.UtcNow + "] (PROXY): A moderator or developer seems to have joined your world!\n");
                }

                if (localplayer)
                {
                    string lestring = (string)vList.functionArgs[1];

                    string[] avatardata          = lestring.Split('\n');
                    string   modified_avatardata = string.Empty;

                    foreach (string av in avatardata)
                    {
                        if (av.Length <= 0)
                        {
                            continue;
                        }

                        string key   = av.Substring(0, av.IndexOf('|'));
                        string value = av.Substring(av.IndexOf('|') + 1);

                        switch (key)
                        {
                        case "mstate":             // unlimited punch/place range edit smstate, but is dangerous/detectable and can autoban!
                            value = "1";
                            break;
                        }

                        modified_avatardata += key + "|" + value + "\n";
                    }

                    //lestring = lestring.Replace("mstate|0", "mstate|1");

                    if (MainForm.unlimitedZoom)
                    {
                        GamePacketProton gp = new GamePacketProton();
                        gp.AppendString("OnSpawn");
                        gp.AppendString(modified_avatardata);
                        gp.delay = (int)vList.delay;
                        gp.NetID = vList.netID;

                        packetSender.SendData(gp.GetBytes(), MainForm.proxyPeer);
                    }

                    MainForm.LogText += ("[" + DateTime.UtcNow + "] (PROXY): World player objects loaded! Your NetID:  " + p.netID + " -- Your UserID: " + p.userID + "\n");
                    worldMap.netID    = p.netID;
                    worldMap.userID   = p.userID;
                    return(-2);
                }
                else
                {
                    return(p.netID);
                }
            }

            case "OnRemove":
            {
                int netID = -1;

                string   onremovestr = (string)vList.functionArgs[1];
                string[] lineToken   = onremovestr.Split('|');
                if (lineToken[0] != "netID")
                {
                    break;
                }

                int.TryParse(lineToken[1], out netID);
                for (int i = 0; i < worldMap.players.Count; i++)
                {
                    if (worldMap.players[i].netID == netID)
                    {
                        worldMap.players.RemoveAt(i);
                        break;
                    }
                }
                worldMap.RemovePlayerControl(netID);

                return(netID);
            }

            default:
                return(-1);
            }
            return(0);
        }
Exemple #7
-1
        /*
         **ONSENDTOSERVER INDEXES/VALUE LOCATIONS**
         *  port = 1
         *  token = 2
         *  userId = 3
         *  IPWithExtraData = 4
         *  lmode = 5 (Used for determining how client should behave when leaving, and could also influence the connection after.
         */
        private int OperateVariant(VariantList.VarList vList, object botPeer)
        {
            switch (vList.FunctionName)
            {
            case "OnConsoleMessage":
            {
                string m = (string)vList.functionArgs[1];
                if ((m.Contains("lagged out,") || m.Contains("experiencing high load")) && !m.Contains("<") && !m.Contains("["))
                {
                    GamePacketProton variantPacket2 = new GamePacketProton();
                    variantPacket2.AppendString("OnReconnect");
                    packetSender.SendData(variantPacket2.GetBytes(), Proxyhelper.proxyPeer);
                }


                break;
            }

            case "OnRequestWorldSelectMenu":
            {
                if (Proxyhelper.globalUserData.autoEnterWorld != "")
                {
                    packetSender.SendPacket(3, "action|join_request\nname|" + Proxyhelper.globalUserData.autoEnterWorld, Proxyhelper.realPeer);
                }
                break;
            }

            case "OnSuperMainStartAcceptLogonHrdxs47254722215a":
            {
                if (Proxyhelper.skipCache && botPeer == null)
                {
                    GamePacketProton gp = new GamePacketProton();         // variant list
                    gp.AppendString("OnRequestWorldSelectMenu");
                    packetSender.SendData(gp.GetBytes(), Proxyhelper.proxyPeer);
                }
                if (botPeer != null)
                {
                    Console.WriteLine("BOT PEER IS ENTERING THE GAME...");
                    packetSender.SendPacket(3, "action|enter_game\n", (ENetPeer)botPeer);
                }
                return(-1);
            }

            case "OnZoomCamera":
            {
                return(-1);
            }

            case "onShowCaptcha":
                ((string)vList.functionArgs[1]).Replace("PROCESS_LOGON_PACKET_TEXT_42", "");    // make captcha completable
                try
                {
                    string[] lines = ((string)vList.functionArgs[1]).Split('\n');
                    foreach (string line in lines)
                    {
                        if (line.Contains("+"))
                        {
                            string   line2 = line.Replace(" ", "");
                            int      a1, a2;
                            string[] splitByPipe = line2.Split('|');
                            string[] splitByPlus = splitByPipe[1].Split('+');
                            a1 = int.Parse(splitByPlus[0]);
                            a2 = int.Parse(splitByPlus[1]);
                            int    result          = a1 + a2;
                            string resultingPacket = "action|dialog_return\ndialog_name|captcha_submit\ncaptcha_answer|" + result.ToString() + "\n";
                            packetSender.SendPacket(2, resultingPacket, Proxyhelper.realPeer);
                        }
                    }
                    return(-1);
                }
                catch
                {
                    return(-1);    // Give this to user.
                }

            case "OnDialogRequest":
                if (!((string)vList.functionArgs[1]).ToLower().Contains("captcha"))
                {
                    return(-1);                                                                 // Send Client Dialog
                }
                ((string)vList.functionArgs[1]).Replace("PROCESS_LOGON_PACKET_TEXT_42", "");    // make captcha completable
                try
                {
                    string[] lines = ((string)vList.functionArgs[1]).Split('\n');
                    foreach (string line in lines)
                    {
                        if (line.Contains("+"))
                        {
                            string   line2 = line.Replace(" ", "");
                            int      a1, a2;
                            string[] splitByPipe = line2.Split('|');
                            string[] splitByPlus = splitByPipe[1].Split('+');
                            a1 = int.Parse(splitByPlus[0]);
                            a2 = int.Parse(splitByPlus[1]);
                            int    result          = a1 + a2;
                            string resultingPacket = "action|dialog_return\ndialog_name|captcha_submit\ncaptcha_answer|" + result.ToString() + "\n";
                            packetSender.SendPacket(2, resultingPacket, Proxyhelper.realPeer);
                        }
                    }
                    return(-1);
                }
                catch
                {
                    return(-1);    // Give this to user.
                }

            case "OnSendToServer":
            {
                // TODO FIX THIS AND MIRROR ALL PACKETS AND SOME BUG FIXES.

                string ip     = (string)vList.functionArgs[4];
                string doorid = "";

                if (ip.Contains("|"))
                {
                    doorid = ip.Substring(ip.IndexOf("|") + 1);
                    ip     = ip.Substring(0, ip.IndexOf("|"));
                }

                int port   = (int)vList.functionArgs[1];
                int userID = (int)vList.functionArgs[3];
                int token  = (int)vList.functionArgs[2];
                GamePacketProton variantPacket = new GamePacketProton();
                variantPacket.AppendString("OnConsoleMessage");
                variantPacket.AppendString("`6(PROXY)`o Switching subserver...``");
                packetSender.SendData(variantPacket.GetBytes(), Proxyhelper.proxyPeer);


                Proxyhelper.globalUserData.Growtopia_IP      = token < 0 ? Proxyhelper.globalUserData.Growtopia_Master_IP : ip;
                Proxyhelper.globalUserData.Growtopia_Port    = token < 0 ? Proxyhelper.globalUserData.Growtopia_Master_Port : port;
                Proxyhelper.globalUserData.isSwitchingServer = true;
                Proxyhelper.globalUserData.token             = token;
                Proxyhelper.globalUserData.lmode             = 1;
                Proxyhelper.globalUserData.userID            = userID;
                Proxyhelper.globalUserData.doorid            = doorid;

                packetSender.SendPacket(3, "action|quit", Proxyhelper.realPeer);
                Proxyhelper.realPeer.Disconnect(0);

                return(-1);
            }

            case "OnSpawn":
            {
                worldMap.playerCount++;
                string onspawnStr = (string)vList.functionArgs[1];
                //MessageBox.Show(onspawnStr);
                string[] tk    = onspawnStr.Split('|');
                Player   p     = new Player();
                string[] lines = onspawnStr.Split('\n');

                bool localplayer = false;

                foreach (string line in lines)
                {
                    string[] lineToken = line.Split('|');
                    if (lineToken.Length != 2)
                    {
                        continue;
                    }
                    switch (lineToken[0])
                    {
                    case "netID":
                        p.netID = Convert.ToInt32(lineToken[1]);
                        break;

                    case "userID":
                        p.userID = Convert.ToInt32(lineToken[1]);
                        break;

                    case "name":
                        p.name = lineToken[1];
                        break;

                    case "country":
                        p.country = lineToken[1];
                        break;

                    case "invis":
                        p.invis = Convert.ToInt32(lineToken[1]);
                        break;

                    case "mstate":
                        p.mstate = Convert.ToInt32(lineToken[1]);
                        break;

                    case "smstate":
                        p.mstate = Convert.ToInt32(lineToken[1]);
                        break;

                    case "posXY":
                        if (lineToken.Length == 3)             // exactly 3 not more not less
                        {
                            p.X = Convert.ToInt32(lineToken[1]);
                            p.Y = Convert.ToInt32(lineToken[2]);
                        }
                        break;

                    case "type":
                        if (lineToken[1] == "local")
                        {
                            localplayer = true;
                        }
                        break;
                    }
                }
                //MainForm.LogText += ("[" + DateTime.UtcNow + "] (PROXY): " + onspawnStr);
                worldMap.players.Add(p);


                /*if (p.name.Contains(MainForm.tankIDName))
                 * {
                 *
                 * }*///crappy code

                if (p.mstate > 0 || p.smstate > 0 || p.invis > 0)
                {
                    if (Proxyhelper.globalUserData.cheat_autoworldban_mod)
                    {
                        banEveryoneInWorld();
                    }
                }

                if (localplayer)
                {
                    string lestring = (string)vList.functionArgs[1];

                    string[] avatardata          = lestring.Split('\n');
                    string   modified_avatardata = string.Empty;

                    foreach (string av in avatardata)
                    {
                        if (av.Length <= 0)
                        {
                            continue;
                        }

                        string key   = av.Substring(0, av.IndexOf('|'));
                        string value = av.Substring(av.IndexOf('|') + 1);

                        switch (key)
                        {
                        case "mstate":             // unlimited punch/place range edit smstate
                            value = "1";
                            break;
                        }

                        modified_avatardata += key + "|" + value + "\n";
                    }

                    //lestring = lestring.Replace("mstate|0", "mstate|1");

                    if (Proxyhelper.globalUserData.unlimitedZoom)
                    {
                        GamePacketProton gp = new GamePacketProton();
                        gp.AppendString("OnSpawn");
                        gp.AppendString(modified_avatardata);
                        gp.delay = (int)vList.delay;
                        gp.NetID = vList.netID;

                        packetSender.SendData(gp.GetBytes(), Proxyhelper.proxyPeer);
                    }


                    worldMap.netID  = p.netID;
                    worldMap.userID = p.userID;
                    return(-2);
                }
                else
                {
                    return(p.netID);
                }
            }

            case "OnRemove":
            {
                int netID = -1;

                string   onremovestr = (string)vList.functionArgs[1];
                string[] lineToken   = onremovestr.Split('|');
                if (lineToken[0] != "netID")
                {
                    break;
                }

                int.TryParse(lineToken[1], out netID);
                for (int i = 0; i < worldMap.players.Count; i++)
                {
                    if (worldMap.players[i].netID == netID)
                    {
                        worldMap.players.RemoveAt(i);
                        break;
                    }
                }

                return(netID);
            }

            default:
                return(-1);
            }
            return(0);
        }