コード例 #1
0
ファイル: WorldLoader.cs プロジェクト: DrFlave/Quadradria
        public void LoadWorld()
        {
            WorldInfo Info = worldInfo;

            Task.Run(() =>
            {
                lock (fsWorld)
                {
                    try
                    {
                        fsWorld.Seek(0, SeekOrigin.Begin);

                        uint magicNumber = WorldReader.ReadUInt32();
                        uint version     = WorldReader.ReadUInt32();
                        long seed        = WorldReader.ReadInt64();

                        char[] worldChars = WorldReader.ReadChars(128);

                        string worldName = "";
                        for (int i = 0; i < 128; i++)
                        {
                            if (worldChars[i] == 0)
                            {
                                break;
                            }
                            worldName += worldChars[i];
                        }

                        uint width            = WorldReader.ReadUInt32();
                        WorldSize worldSize   = (WorldSize)WorldReader.ReadByte();
                        DateTime creationTime = DateTime.FromBinary(WorldReader.ReadInt64());
                        ulong playTime        = WorldReader.ReadUInt64();
                        Difficulty difficulty = (Difficulty)WorldReader.ReadByte();
                        Generator generator   = (Generator)WorldReader.ReadByte();
                        uint timeOfDay        = WorldReader.ReadUInt32();
                        uint lengthOfDay      = WorldReader.ReadUInt32();

                        Console.WriteLine("magic number: {0}, {1}", magicNumber, magicNumber == 0x42171701 ? "Matches." : "No Match!");
                        Console.WriteLine("version: {0}", version.ToString("X"));
                        Console.WriteLine("seed: {0}", seed.ToString("X"));
                        Console.WriteLine("worldName: {0}", worldName);
                        Console.WriteLine("width: {0}", width.ToString("X"));
                        Console.WriteLine("worldSize: {0}", worldSize.ToString("X"));
                        Console.WriteLine("creationTime: {0}", creationTime.ToString());
                        Console.WriteLine("playTime: {0}", playTime.ToString("X"));
                        Console.WriteLine("difficulty: {0}", difficulty.ToString("X"));
                        Console.WriteLine("generator: {0}", generator.ToString("X"));
                        Console.WriteLine("timeOfDay: {0}", timeOfDay.ToString("X"));
                        Console.WriteLine("lengthOfDay: {0}", lengthOfDay.ToString("X"));

                        Info.seed         = seed;
                        Info.width        = width;
                        Info.timeOfDay    = timeOfDay;
                        Info.lengthOfDay  = lengthOfDay;
                        Info.Name         = worldName;
                        Info.difficulty   = difficulty;
                        Info.generator    = generator;
                        Info.Size         = worldSize;
                        Info.creationTime = creationTime;
                        Info.playTime     = playTime;
                    }
                    catch (Exception e)
                    {
                        throw new Exception("Error reading world", e);
                    }
                }
            });
        }