コード例 #1
0
        public World(string path)
        {
            if (genRand == null) {
                genRand = new Random((int)DateTime.Now.Ticks);
            }

            using (FileStream stream = new FileStream(path, FileMode.Open)) {
                using (BinaryReader reader = new BinaryReader(stream)) {
                    worldVersion = reader.ReadInt32();
                    Console.WriteLine("World version: " + worldVersion);

                    if (worldVersion >= 28) {
                        tileFrameImportant[4] = true;
                    }

                    Name = reader.ReadString();
                    Console.WriteLine("World name: " + Name);
                    ID = reader.ReadInt32();
                    Console.WriteLine("World ID: " + ID);
                    leftWorld = reader.ReadInt32();
                    Console.WriteLine("World left: " + leftWorld);
                    rightWorld = reader.ReadInt32();
                    Console.WriteLine("World right: " + rightWorld);
                    topWorld = reader.ReadInt32();
                    Console.WriteLine("World top: " + topWorld);
                    bottomWorld = reader.ReadInt32();
                    Console.WriteLine("World bottom: " + bottomWorld);

                    int tilesY = reader.ReadInt32();
                    Console.WriteLine("Tiles Y: " + tilesY);
                    int tilesX = reader.ReadInt32();
                    Console.WriteLine("Tiles X: " + tilesX);
                    Size = new Size(tilesX, tilesY);

                    if (worldVersion >= 63) {
                        moonType = reader.ReadByte();
                        Console.WriteLine("What is the moon type? " + moonType);
                    }

                    if (worldVersion >= 44) {
                        treeX[0] = reader.ReadInt32();
                        treeX[1] = reader.ReadInt32();
                        treeX[2] = reader.ReadInt32();
                        Console.WriteLine("What are the tree type X coords? " + treeX[0] + " " + treeX[1] + " " + treeX[2]);

                        treeStyles[0] = reader.ReadInt32();
                        treeStyles[1] = reader.ReadInt32();
                        treeStyles[2] = reader.ReadInt32();
                        treeStyles[3] = reader.ReadInt32();
                        Console.WriteLine("What are the tree styles? " + treeStyles[0] + " " + treeStyles[1] + " " + treeStyles[2] + " " + treeStyles[3]);
                    }

                    if (worldVersion >= 60) {
                        caveX[0] = reader.ReadInt32();
                        caveX[1] = reader.ReadInt32();
                        caveX[2] = reader.ReadInt32();
                        Console.WriteLine("What are the cave back X coords? " + caveX[0] + " " + caveX[1] + " " + caveX[2]);

                        caveBackStyles[0] = reader.ReadInt32();
                        caveBackStyles[1] = reader.ReadInt32();
                        caveBackStyles[2] = reader.ReadInt32();
                        caveBackStyles[3] = reader.ReadInt32();
                        Console.WriteLine("What are the cave back styles? " + caveBackStyles[0] + " " + caveBackStyles[1] + " " + caveBackStyles[2] + " " + caveBackStyles[3]);

                        iceBackStyle = reader.ReadInt32();
                        Console.WriteLine("What is the ice back style? " + iceBackStyle);
                    }

                    if (worldVersion >= 61) {
                        jungleBackStyle = reader.ReadInt32();
                        Console.WriteLine("What is the jungle back style? " + jungleBackStyle);

                        hellBackStyle = reader.ReadInt32();
                        Console.WriteLine("What is the hell back style? " + hellBackStyle);
                    }

                    Spawn = new Point(reader.ReadInt32(), reader.ReadInt32());
                    Console.WriteLine("Spawn X: " + Spawn.X);
                    Console.WriteLine("Spawn Y: " + Spawn.Y);

                    worldSurface = reader.ReadDouble();
                    Console.WriteLine("World surface: " + worldSurface);
                    rockLayer = reader.ReadDouble();
                    Console.WriteLine("Rock layer: " + rockLayer);

                    double tempTime = reader.ReadDouble();
                    Console.WriteLine("Time: " + tempTime);
                    bool tempDayTime = reader.ReadBoolean();
                    Console.WriteLine("Is it day? " + tempDayTime);
                    int tempMoonPhase = reader.ReadInt32();
                    Console.WriteLine("Moon phase: " + tempMoonPhase);
                    bool tempBloodMoon = reader.ReadBoolean();
                    Console.WriteLine("Is it a blood moon? " + tempBloodMoon);

                    if (worldVersion >= 70) {
                        bool tempEclipse = reader.ReadBoolean();
                        Console.WriteLine("Is it an eclipse? " + tempEclipse);
                    }

                    Dungeon = new Point(reader.ReadInt32(), reader.ReadInt32());
                    Console.WriteLine("Dungeon X: " + Dungeon.X);
                    Console.WriteLine("Dungeon Y: " + Dungeon.Y);

                    if (worldVersion >= 56) {
                        crimsonWorld = reader.ReadBoolean();
                        Console.WriteLine("Crimson world? " + crimsonWorld);
                    }

                    downedBoss1 = reader.ReadBoolean();
                    Console.WriteLine("Is the Eye Of Cthulu dead? " + downedBoss1);
                    downedBoss2 = reader.ReadBoolean();
                    Console.WriteLine("Is the Eater Of Worlds dead? " + downedBoss2);
                    downedBoss3 = reader.ReadBoolean();
                    Console.WriteLine("Is Skeletron dead? " + downedBoss3);

                    if (worldVersion >= 66) {
                        downedBee = reader.ReadBoolean();
                        Console.WriteLine("Is the Queen Bee dead? " + downedBee);
                    }

                    if (worldVersion >= 44) {
                        downedDestroyer = reader.ReadBoolean();
                        Console.WriteLine("Is The Destroyer dead? " + downedDestroyer);
                        downedTwins = reader.ReadBoolean();
                        Console.WriteLine("Are The Twins dead? " + downedTwins);
                        downedPrime = reader.ReadBoolean();
                        Console.WriteLine("Is Skeletron Prime dead? " + downedPrime);
                        downedHardmodeBoss = reader.ReadBoolean();
                        Console.WriteLine("Is any hardmode boss dead? " + downedHardmodeBoss);
                    }

                    if (worldVersion >= 64) {
                        downedPlantera = reader.ReadBoolean();
                        Console.WriteLine("Is Plantera dead? " + downedPlantera);
                        downedGolem = reader.ReadBoolean();
                        Console.WriteLine("Is the Golem dead? " + downedGolem);
                    }

                    if (worldVersion >= 29) {
                        savedGoblinTinkerer = reader.ReadBoolean();
                        Console.WriteLine("Is the goblin tinkerer saved? " + savedGoblinTinkerer);
                        savedWizard = reader.ReadBoolean();
                        Console.WriteLine("Is the wizard saved? " + savedWizard);

                        if (worldVersion >= 34) {
                            savedMechanic = reader.ReadBoolean();
                            Console.WriteLine("Is the mechanic saved? " + savedMechanic);
                        }

                        defeatedGoblinInvasion = reader.ReadBoolean();
                        Console.WriteLine("Is the goblin invasion defeated? " + defeatedGoblinInvasion);

                        if (worldVersion >= 32) {
                            killedClown = reader.ReadBoolean();
                            Console.WriteLine("Is the clown dead? " + killedClown);
                        }

                        if (worldVersion >= 37) {
                            defeatedFrostLegion = reader.ReadBoolean();
                            Console.WriteLine("Is the frost legion defeated? " + defeatedFrostLegion);
                        }
                    }

                    if (worldVersion >= 56) {
                        defeatedPirates = reader.ReadBoolean();
                        Console.WriteLine("Are the pirates defeated? " + defeatedPirates);
                    }

                    shadowOrbSmashed = reader.ReadBoolean();
                    Console.WriteLine("Is an orb broken? " + shadowOrbSmashed);
                    spawnMeteor = reader.ReadBoolean();
                    Console.WriteLine("Is a meteor spawned? " + spawnMeteor);
                    shadowOrbCount = reader.ReadByte();
                    Console.WriteLine("Orbs broken: " + shadowOrbCount);

                    if (worldVersion >= 23) {
                        altarsSmashed = reader.ReadInt32();
                        Console.WriteLine("Altars smashed: " + altarsSmashed);
                        hardMode = reader.ReadBoolean();
                        Console.WriteLine("Is it hard mode? " + hardMode);
                    }

                    invasionDelay = reader.ReadInt32();
                    Console.WriteLine("Invasion delay: " + invasionDelay);
                    invasionSize = reader.ReadInt32();
                    Console.WriteLine("Invasion size: " + invasionSize);
                    invasionType = reader.ReadInt32();
                    Console.WriteLine("Invasion type: " + invasionType);
                    invasionX = reader.ReadDouble();
                    Console.WriteLine("Invasion X: " + invasionX);

                    if (worldVersion >= 53) {
                        isRaining = reader.ReadBoolean();
                        Console.WriteLine("Is raining? " + isRaining);
                        rainTime = reader.ReadInt32();
                        Console.WriteLine("Rain time: " + rainTime);
                        maxRain = reader.ReadSingle();
                        Console.WriteLine("Maximum rain: " + maxRain);
                    }

                    if (worldVersion >= 54) {
                        tier1 = reader.ReadInt32();
                        Console.WriteLine("What is the tier 1 ore? " + tier1);
                        tier2 = reader.ReadInt32();
                        Console.WriteLine("What is the tier 2 ore? " + tier2);
                        tier3 = reader.ReadInt32();
                        Console.WriteLine("What is the tier 3 ore? " + tier3);
                    }

                    if (worldVersion >= 55) {
                        treeStyle = reader.ReadByte();
                        Console.WriteLine("What is the tree style? " + treeStyle);
                        corruptionStyle = reader.ReadByte();
                        Console.WriteLine("What is the corruption style? " + corruptionStyle);
                        jungleStyle = reader.ReadByte();
                        Console.WriteLine("What is the jungle style? " + jungleStyle);
                    }

                    if (worldVersion >= 60) {
                        snowStyle = reader.ReadByte();
                        Console.WriteLine("What is the snow style? " + snowStyle);
                        hallowStyle = reader.ReadByte();
                        Console.WriteLine("What is the hallow style? " + hallowStyle);
                        crimsonStyle = reader.ReadByte();
                        Console.WriteLine("What is the crimson style? " + crimsonStyle);
                        desertStyle = reader.ReadByte();
                        Console.WriteLine("What is the desert style? " + desertStyle);
                        oceanStyle = reader.ReadByte();
                        Console.WriteLine("What is the ocean style? " + oceanStyle);
                        cloudBackground = reader.ReadInt32();
                        Console.WriteLine("What is the cloud background? " + cloudBackground);
                    }

                    if (worldVersion >= 62) {
                        numberOfClouds = reader.ReadInt16();
                        Console.WriteLine("Number of clouds: " + numberOfClouds);
                        windSpeed = reader.ReadSingle();
                        Console.WriteLine("Wind speed: " + windSpeed);
                    }

                    for (int num4 = 0; num4 < MaxTilesX; num4++) {
                        for (int num6 = 0; num6 < MaxTilesY; num6++) {
                            tile[num4, num6] = new Tile();
                        }
                    }

                    for (int i = 0; i < tilesX; i++) {
                        // float num3 = ((float)i) / ((float)tilesX);

                        short repeatTile = 0;
                        for (int n = 0; n < tilesY; n++) {
                            if (repeatTile > 0) {
                                tile[i, n] = tile[i, n - 1].Clone();
                                --repeatTile;
                            } else {

                                tile[i, n].Active = reader.ReadBoolean();

                                if (tile[i, n].Active) {
                                    tile[i, n].Type = reader.ReadByte();
                                    if (tileFrameImportant[tile[i, n].Type]) {
                                        if ((worldVersion < 28 && tile[i, n].Type == 4) || (worldVersion < 40 && tile[i, n].Type == 19)) {
                                            tile[i, n].FrameX = -1;
                                            tile[i, n].FrameY = -1;
                                        }
                                        else {
                                            tile[i, n].FrameX = reader.ReadInt16();
                                            tile[i, n].FrameY = reader.ReadInt16();
                                        }
                                    } else {
                                        tile[i, n].FrameX = -1;
                                        tile[i, n].FrameY = -1;
                                    }
                                    if (worldVersion >= 48) {
                                        bool colorPresent = reader.ReadBoolean();
                                        if (colorPresent) {
                                            tile[i, n].Color = reader.ReadByte();
                                        }
                                    }
                                }
                                if (worldVersion < 26) // This no longer exists after world version 25.
                                {
                                    tile[i, n].Lighted = reader.ReadBoolean();
                                }
                                if (reader.ReadBoolean()) {
                                    tile[i, n].Wall = reader.ReadByte();
                                    if (worldVersion >= 48) {
                                        bool wallColorPresent = reader.ReadBoolean();
                                        if (wallColorPresent) {
                                            tile[i, n].WallColor = reader.ReadByte();
                                        }
                                    }
                                }
                                if (reader.ReadBoolean()) {
                                    tile[i, n].Liquid = reader.ReadByte();
                                    tile[i, n].Lava = reader.ReadBoolean();
                                    if (worldVersion >= 51) {
                                        tile[i, n].Honey = reader.ReadBoolean();
                                    }
                                }
                                if (worldVersion >= 33) {
                                    tile[i, n].Wire = reader.ReadBoolean();
                                }

                                if (worldVersion >= 43) {
                                    tile[i, n].WireGreen = reader.ReadBoolean();
                                    tile[i, n].WireBlue = reader.ReadBoolean();
                                }

                                if (worldVersion >= 41) {
                                    tile[i, n].HalfTile = reader.ReadBoolean();
                                }

                                if (worldVersion >= 49) {
                                    tile[i, n].TileSlope = reader.ReadByte();
                                }

                                if (worldVersion >= 42) {
                                    tile[i, n].ActuatorPresent = reader.ReadBoolean();
                                    tile[i, n].InActive = reader.ReadBoolean();
                                }

                                if (worldVersion >= 25) {
                                    repeatTile = reader.ReadInt16();
                                    //if (repeatTile + n > tilesY) Console.WriteLine("WARNING: Repeating " + repeatTile + " times and there's only " + (tilesY - n) + " left.");
                                }
                            }
                        }
                    }

                    for (int j = 0; j < 1000; j++) {
                        if (reader.ReadBoolean()) {
                            chest[j] = new Chest();
                            chest[j].Position = new Microsoft.Xna.Framework.Vector2(reader.ReadInt32(), reader.ReadInt32());
                            for (int num6 = 0; num6 < Chest.MaxItems; num6++) {
                                byte lowByte = reader.ReadByte();
                                short num7 = lowByte;
                                if (worldVersion >= 59) {
                                    byte highByte = reader.ReadByte();
                                    num7 = (short)((highByte << 8) | lowByte);
                                }
                                if (num7 > 0) {
                                    chest[j].Items[num6] = new Item();
                                    if (worldVersion < 38) {
                                        string itemName = reader.ReadString();
                                        chest[j].Items[num6].Name = itemName;
                                    } else {
                                        int itemID = reader.ReadInt32();
                                        chest[j].Items[num6].Name = itemID.ToString(); // This belongs in a new field.
                                    }
                                    if (worldVersion >= 36) {
                                        byte itemPrefixID = reader.ReadByte();
                                        // Do we need to save this?
                                    }
                                    chest[j].Items[num6].Count = num7;
                                    //Console.WriteLine("Chest contains " + chest[j].Items[num6].Count + " of " + chest[j].Items[num6].Name + ".");
                                }
                            }
                            if (worldVersion >= 58) {
                                for (int num6 = 0; num6 < Chest.MaxItems; num6++) {
                                    byte lowByte = reader.ReadByte();
                                    short num7 = lowByte;
                                    if (worldVersion >= 59) {
                                        byte highByte = reader.ReadByte();
                                        num7 = (short)((highByte << 8) | lowByte);
                                    }
                                    if (num7 > 0) {
                                        chest[j].ItemsMore[num6] = new Item();
                                        if (worldVersion < 38) {
                                            string itemName = reader.ReadString();
                                            chest[j].ItemsMore[num6].Name = itemName;
                                        }
                                        else {
                                            int itemID = reader.ReadInt32();
                                            chest[j].ItemsMore[num6].Name = itemID.ToString(); // This belongs in a new field.
                                        }
                                        if (worldVersion >= 36) {
                                            byte itemPrefixID = reader.ReadByte();
                                            // Do we need to save this?
                                        }
                                        chest[j].ItemsMore[num6].Count = num7;
                                        //Console.WriteLine("Chest contains " + chest[j].Items[num6].Count + " of " + chest[j].Items[num6].Name + ".");
                                    }
                                }
                            }
                        }
                    }
                    for (int k = 0; k < 1000; k++) {
                        if (reader.ReadBoolean()) {
                            string str2 = reader.ReadString();
                            int num9 = reader.ReadInt32();
                            int num10 = reader.ReadInt32();
                            /*if (tile[num9, num10].Active && (tile[num9, num10].Type == 0x37)) {
                                sign[k] = new Sign();
                                sign[k].Position = new Microsoft.Xna.Framework.Vector2(num9, num10);
                                sign[k].Text = str2;
                            }*/
                        }
                    }
                    bool flag = reader.ReadBoolean();
                    for (int m = 0; flag; m++) {
                        npc[m] = new Npc();
                        npc[m].Name = reader.ReadString();
                        npc[m].Position.X = reader.ReadSingle();
                        npc[m].Position.Y = reader.ReadSingle();
                        npc[m].IsHomeless = reader.ReadBoolean();
                        npc[m].HomePosition = new Microsoft.Xna.Framework.Vector2(reader.ReadInt32(), reader.ReadInt32());
                        flag = reader.ReadBoolean();
                    }

                    if (worldVersion >= 31) {
                        String merchantName = reader.ReadString();
                        String nurseName = reader.ReadString();
                        String armsDealerName = reader.ReadString();
                        String dryadName = reader.ReadString();
                        String guideName = reader.ReadString();
                        String clothierName = reader.ReadString();
                        String demolitionistName = reader.ReadString();
                        String goblinTinkererName = reader.ReadString();
                        String wizardName = reader.ReadString();
                        if (worldVersion >= 34) {
                            String mechanicName = reader.ReadString();
                        }
                        if (worldVersion >= 65) {
                            String truffleName = reader.ReadString();
                            String steampunkerName = reader.ReadString();
                            String dyeTraderName = reader.ReadString();
                            String partyGirlName = reader.ReadString();
                            String cyborgName = reader.ReadString();
                            String painterName = reader.ReadString();
                            String witchDoctorName = reader.ReadString();
                            String pirateName = reader.ReadString();
                        }
                    }

                    if (worldVersion >= 7) {
                        Console.WriteLine("Success? " + reader.ReadBoolean());
                        String validateWorldName = reader.ReadString();
                        Console.WriteLine("World name matched? " + (Name == validateWorldName));
                        int validateWorldID = reader.ReadInt32();
                        Console.WriteLine("World ID matched? " + (ID == validateWorldID));
                    }

                    Console.WriteLine((stream.Length - stream.Position) + " bytes left.");

                    reader.Close();

                    waterLine = tilesY;
                }
            }

            FrameTiles();
        }
コード例 #2
0
        public World(string path)
        {
            if (genRand == null) {
                genRand = new Random((int) DateTime.Now.Ticks);
            }

            using (FileStream stream = new FileStream(path, FileMode.Open)) {
                using (BinaryReader reader = new BinaryReader(stream)) {
                    worldVersion = reader.ReadInt32();

                    Name = reader.ReadString();
                    ID = reader.ReadInt32();
                    leftWorld = reader.ReadInt32();
                    rightWorld = reader.ReadInt32();
                    topWorld = reader.ReadInt32();
                    bottomWorld = reader.ReadInt32();

                    int tilesY = reader.ReadInt32();
                    int tilesX = reader.ReadInt32();

                    Size = new Size(tilesX, tilesY);
                    Spawn = new Point(reader.ReadInt32(), reader.ReadInt32());

                    worldSurface = reader.ReadDouble();
                    rockLayer = reader.ReadDouble();

                    double tempTime = reader.ReadDouble();
                    bool tempDayTime= reader.ReadBoolean();
                    int tempMoonPhase = reader.ReadInt32();
                    bool tempBloodMoon= reader.ReadBoolean();

                    Dungeon = new Point(reader.ReadInt32(), reader.ReadInt32());
                    downedBoss1 = reader.ReadBoolean();
                    downedBoss2 = reader.ReadBoolean();
                    downedBoss3 = reader.ReadBoolean();

                    shadowOrbSmashed = reader.ReadBoolean();
                    spawnMeteor = reader.ReadBoolean();
                    shadowOrbCount = reader.ReadByte();

                    invasionDelay = reader.ReadInt32();
                    invasionSize = reader.ReadInt32();
                    invasionType = reader.ReadInt32();
                    invasionX = reader.ReadDouble();

                    for (int num4 = 0; num4 < MaxTilesX; num4++) {
                        for (int num6 = 0; num6 < MaxTilesY; num6++) {
                            tile[num4, num6] = new Tile();
                        }
                    }

                    for (int i = 0; i < tilesX; i++) {
                        float num3 = ((float) i) / ((float) tilesX);

                        for (int n = 0; n < tilesY; n++) {
                            tile[i, n].Active = reader.ReadBoolean();

                            if (tile[i, n].Active) {
                                tile[i, n].Type = reader.ReadByte();
                                if (tileFrameImportant[tile[i, n].Type]) {
                                    tile[i, n].FrameX = reader.ReadInt16();
                                    tile[i, n].FrameY = reader.ReadInt16();
                                } else {
                                    tile[i, n].FrameX = -1;
                                    tile[i, n].FrameY = -1;
                                }
                            }
                            tile[i, n].Lighted = reader.ReadBoolean();
                            if (reader.ReadBoolean()) {
                                tile[i, n].Wall = reader.ReadByte();
                            }
                            if (reader.ReadBoolean()) {
                                tile[i, n].Liquid = reader.ReadByte();
                                tile[i, n].Lava = reader.ReadBoolean();
                            }
                        }
                    }

                    for (int j = 0; j < 0x3e8; j++) {
                        if (reader.ReadBoolean()) {
                            chest[j] = new Chest();
                            chest[j].Position = new Microsoft.Xna.Framework.Vector2(reader.ReadInt32(), reader.ReadInt32());
                            for (int num6 = 0; num6 < Chest.MaxItems; num6++) {
                                byte num7 = reader.ReadByte();
                                if (num7 > 0) {
                                    chest[j].Items[num6] = new Item();
                                    string itemName = reader.ReadString();
                                    chest[j].Items[num6].Name = itemName;
                                    chest[j].Items[num6].Count = num7;
                                }
                            }
                        }
                    }
                    for (int k = 0; k < 0x3e8; k++) {
                        if (reader.ReadBoolean()) {
                            string str2 = reader.ReadString();
                            int num9 = reader.ReadInt32();
                            int num10 = reader.ReadInt32();
                            if (tile[num9, num10].Active && (tile[num9, num10].Type == 0x37)) {
                                sign[k] = new Sign();
                                sign[k].Position = new Microsoft.Xna.Framework.Vector2(num9, num10);
                                sign[k].Text = str2;
                            }
                        }
                    }
                    bool flag = reader.ReadBoolean();
                    for (int m = 0; flag; m++) {
                        npc[m] = new Npc();
                        npc[m].Name = reader.ReadString();
                        npc[m].Position.X = reader.ReadSingle();
                        npc[m].Position.Y = reader.ReadSingle();
                        npc[m].IsHomeless = reader.ReadBoolean();
                        npc[m].HomePosition = new Microsoft.Xna.Framework.Vector2(reader.ReadInt32(), reader.ReadInt32());
                        flag = reader.ReadBoolean();
                    }
                    reader.Close();

                    waterLine = tilesY;
                }
            }

            FrameTiles();
        }