コード例 #1
0
ファイル: GetMapClient.cs プロジェクト: sikker/StawdewValley
        public static void receiveMapFromServer(GameLocation map, bool isStructure)
        {
            long num = DateTime.Now.Ticks / 10000L;

            byte[]     buffer     = new byte[4];
            IPEndPoint ipEndPoint = new IPEndPoint(Game1.client.serverAddress, 24643);
            Socket     socket     = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            socket.Connect((EndPoint)ipEndPoint);
            Console.WriteLine("Socket connected to {0}", (object)socket.RemoteEndPoint.ToString());
            byte[] bytes = Encoding.ASCII.GetBytes((isStructure ? map.uniqueName : map.name) + "_" + isStructure.ToString() + "_<EOF>");
            socket.Send(bytes);
            socket.Receive(buffer);
            byte[] numArray = new byte[BitConverter.ToInt32(buffer, 0)];
            socket.Receive(numArray);
            GameLocation gameLocation = (GameLocation)GetMapClient.FromXml(Encoding.ASCII.GetString(numArray), typeof(GameLocation));

            map.terrainFeatures = gameLocation.terrainFeatures;
            foreach (TerrainFeature terrainFeature in map.terrainFeatures.Values)
            {
                terrainFeature.loadSprite();
            }
            map.objects = gameLocation.objects;
            foreach (StardewValley.Object @object in map.objects.Values)
            {
                @object.reloadSprite();
            }
            map.characters = gameLocation.characters;
            if (gameLocation is Farm && map is Farm)
            {
                (map as Farm).buildings = (gameLocation as Farm).buildings;
                foreach (Building building in (map as Farm).buildings)
                {
                    building.load();
                }
                (map as Farm).animals = (gameLocation as Farm).animals;
                foreach (KeyValuePair <long, FarmAnimal> animal in (Dictionary <long, FarmAnimal>)(map as Farm).animals)
                {
                    animal.Value.reload();
                }
            }
            foreach (NPC character in map.characters)
            {
                character.reloadSprite();
            }
            Game1.player.remotePosition = Game1.player.position;
            Console.WriteLine("Time: " + (object)(DateTime.Now.Ticks / 10000L - num));
            socket.Close();
        }
コード例 #2
0
        // Token: 0x06000B2A RID: 2858 RVA: 0x000E33AC File Offset: 0x000E15AC
        public static void receiveMapFromServer(GameLocation map, bool isStructure)
        {
            long currentTime = DateTime.Now.Ticks / 10000L;

            byte[]     bytes    = new byte[4];
            IPEndPoint remoteEP = new IPEndPoint(Game1.client.serverAddress, 24643);
            Socket     sender   = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            sender.Connect(remoteEP);
            Console.WriteLine("Socket connected to {0}", sender.RemoteEndPoint.ToString());
            byte[] msg = Encoding.ASCII.GetBytes((isStructure ? map.uniqueName : map.name) + "_" + isStructure.ToString() + "_<EOF>");
            sender.Send(msg);
            sender.Receive(bytes);
            bytes = new byte[BitConverter.ToInt32(bytes, 0)];
            sender.Receive(bytes);
            GameLocation receivedMap = (GameLocation)GetMapClient.FromXml(Encoding.ASCII.GetString(bytes), typeof(GameLocation));

            map.terrainFeatures = receivedMap.terrainFeatures;
            using (Dictionary <Vector2, TerrainFeature> .ValueCollection.Enumerator enumerator = map.terrainFeatures.Values.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    enumerator.Current.loadSprite();
                }
            }
            map.objects = receivedMap.objects;
            using (Dictionary <Vector2, Object> .ValueCollection.Enumerator enumerator2 = map.objects.Values.GetEnumerator())
            {
                while (enumerator2.MoveNext())
                {
                    enumerator2.Current.reloadSprite();
                }
            }
            map.characters = receivedMap.characters;
            if (receivedMap is Farm && map is Farm)
            {
                (map as Farm).buildings = (receivedMap as Farm).buildings;
                using (List <Building> .Enumerator enumerator3 = (map as Farm).buildings.GetEnumerator())
                {
                    while (enumerator3.MoveNext())
                    {
                        enumerator3.Current.load();
                    }
                }
                (map as Farm).animals = (receivedMap as Farm).animals;
                foreach (KeyValuePair <long, FarmAnimal> kvp in (map as Farm).animals)
                {
                    kvp.Value.reload();
                }
            }
            using (List <NPC> .Enumerator enumerator5 = map.characters.GetEnumerator())
            {
                while (enumerator5.MoveNext())
                {
                    enumerator5.Current.reloadSprite();
                }
            }
            Game1.player.remotePosition = Game1.player.position;
            Console.WriteLine("Time: " + (DateTime.Now.Ticks / 10000L - currentTime));
            sender.Close();
        }