Пример #1
0
        void Window_Closed(object sender, EventArgs e)
        {
            goOn = false;
            progTimer.Stop();

            if (!step1.HasExited)
            {
                step1.Kill();
            }

            if (!step2.HasExited)
            {
                step2.Kill();
            }

            if (Func.DirectorySize(new DirectoryInfo(Editor.cf_gameDir + "\\Data\\World\\Levels\\_raytwol")) != Setup.INST_FOLDER_SIZE)
            {
                var warn = new Warning("Setup failed", "Something went wrong during setup. Press OK to try again.").ShowDialog();
                if (warn.Value)
                {
                    Setup.FirstTimeSetup();
                }
            }
        }
Пример #2
0
        public static void SetupChecks()
        {
            // Check for LEVELS0.DAT
            if (!File.Exists(Editor.cf_gameDir + "\\Data\\World\\Levels\\LEVELS0.DAT"))
            {
                var warn = new Warning("LEVELS0.DAT not found", "This is a retail install of Rayman 2 and requires LEVELS0.DAT, a 150 MB file included in the GOG version. Press OK to download and install the file.").ShowDialog();
                if (warn.Value)
                {
                    var dl = new Downloader();
                    dl.ShowDialog();
                    if ((bool)!dl.DialogResult)
                    {
                        Environment.Exit(0);
                    }
                }
                else
                {
                    Environment.Exit(0);
                }
            }
            else if (new FileInfo(Editor.cf_gameDir + "\\Data\\World\\Levels\\LEVELS0.DAT").Length != INST_LEVELS0_SIZE)
            {
                var warn = new Warning("LEVELS0.DAT corrupted", "LEVELS0.DAT appears to be corrupted. Press OK to re-download.").ShowDialog();
                if (warn.Value)
                {
                    File.Delete(Editor.cf_gameDir + "\\Data\\World\\Levels\\LEVELS0.DAT");
                    var dl = new Downloader();
                    dl.ShowDialog();
                    if ((bool)!dl.DialogResult)
                    {
                        Environment.Exit(0);
                    }
                }
                else
                {
                    Environment.Exit(0);
                }
            }

            // Check if RayTwol has been used before
            if (!Directory.Exists(Editor.cf_gameDir + "\\Data\\World\\Levels\\_raytwol"))
            {
                var warn = new Warning("Setup", "Press OK to begin the first-time setup procedure. Once complete, RayTwol will open.").ShowDialog();
                if (warn.Value)
                {
                    FirstTimeSetup();
                }
            }
            else
            {
                long size = Func.DirectorySize(new DirectoryInfo(Editor.cf_gameDir + "\\Data\\World\\Levels\\_raytwol"));
                if (!(size == INST_FOLDER_SIZE || size == INST_TEXTURES_FOLDER_SIZE))
                {
                    var warn = new Warning("Warning", "First-time setup is not complete or setup-related files have been modified. If this error persists, press OK to re-initialise the setup.").ShowDialog();
                    if (warn.Value)
                    {
                        FirstTimeSetup();
                    }
                }
            }

            new MainWindow().ShowDialog();
        }
Пример #3
0
        public static void OpenLevel(string map, string suffix = "")
        {
            Mouse.OverrideCursor = Cursors.Wait;

            // LEVEL
            currLevel = map.ToUpper();
            world     = new string(new char[] { currLevel.ToCharArray()[0], currLevel.ToCharArray()[1], currLevel.ToCharArray()[2] });
            string fullName = string.Format("RAY\\{0}\\{1}.XXX", world, currLevel);

            ExtractTiles(world);

            if (!File.Exists(fullName + "_ORIG"))
            {
                File.Copy(fullName, fullName + "_ORIG");
            }

            FileStream mapFile = new FileStream(fullName + suffix, FileMode.Open);

            byte[] XXX = new byte[mapFile.Length];
            mapFile.Read(XXX, 0, (int)mapFile.Length);
            mapFile.Close();

            off_events  = BitConverter.ToInt32(XXX, 0x8);
            off_types   = BitConverter.ToInt32(XXX, 0xC);
            off_sprites = BitConverter.ToInt32(XXX, 0x10);
            off_end     = BitConverter.ToInt32(XXX, 0x14);

            // types
            Scenes.Level.width  = BitConverter.ToUInt16(XXX, off_types);
            Scenes.Level.height = BitConverter.ToUInt16(XXX, off_types + 2);

            if (Scenes.Level.width == 0 || Scenes.Level.height == 0)
            {
                var warn = new Warning("Level open failed", string.Format("Could not read the map dimensions. Hit OK to load the original {0}.", currLevel));
                warn.ShowDialog();
                if (warn.DialogResult == true)
                {
                    OpenLevel(currLevel, "_ORIG");
                }
                else
                {
                    Environment.Exit(0);
                }
                return;
            }

            Scenes.Level.types = new Type[Scenes.Level.width * Scenes.Level.height];
            types_screen       = Scenes.Level.types.ToArray();
            levelName          = map;

            int i = off_types + 4;

            for (int n = 0; n < Scenes.Level.width * Scenes.Level.height; n++)
            {
                Scenes.Level.types[n] = new Type();
                int graphic = XXX[i] + ((XXX[i + 1] & 3) << 8);
                Scenes.Level.types[n].graphic.X = graphic & 15;
                Scenes.Level.types[n].graphic.Y = graphic >> 4;
                Scenes.Level.types[n].collision = (Collisions)(XXX[i + 1] >> 2);
                i += 2;
            }

            // events
            Scenes.Level.events.Clear();
            int ID = 0;

            count_events = 0;
            for (int e = off_events + 16; XXX[e] > 0; e += 0x70, ID++)
            {
                // position
                int x  = BitConverter.ToUInt16(XXX, e + event_off_pos);
                int y  = BitConverter.ToUInt16(XXX, e + event_off_pos + 2);
                var ev = new Event(x, y);
                ev.ID   = ID;
                ev.type = (Behaviours)XXX[e + event_off_type];
                Scenes.Level.events.Add(ev);

                // bytes
                for (int b = 0; b < 0x70; b++)
                {
                    ev.bytes[b] = XXX[b + e];
                }

                off_types   -= 113;
                off_sprites -= 113;
                off_end     -= 113;

                count_events++;
            }
            RefreshObjectsList();



            // TILESET
            Scenes.Tileset.width  = 16;
            Scenes.Tileset.height = tileset.Height / 16;
            Scenes.Tileset.types  = new Type[tileset.Height];
            for (int y = 0; y < Scenes.Tileset.height; y++)
            {
                for (int x = 0; x < 16; x++)
                {
                    Scenes.Tileset.types[x + (y * Scenes.Tileset.width)].graphic   = new System.Drawing.Point(x, y);
                    Scenes.Tileset.types[x + (y * Scenes.Tileset.width)].collision = Collisions.none;
                }
            }

            // TEMPLATE
            Scenes.Template = new Scene(10, 10);
            if (File.Exists(world + "_template.txt"))
            {
                var      template = new StreamReader(world + "_template.txt");
                var      spl      = new char[] { ' ' };
                string[] line     = template.ReadLine().Split(spl);
                int      tWidth   = int.Parse(line[0]);
                int      tHeight  = int.Parse(line[1]);
                Scenes.Template = new Scene(tWidth, tHeight);
                for (int t = 0; t < tWidth * tHeight; t++)
                {
                    if (template.EndOfStream)
                    {
                        break;
                    }
                    var l = template.ReadLine().Split(spl);
                    Scenes.Template.types[t].graphic   = new System.Drawing.Point(int.Parse(l[0]), int.Parse(l[1]));
                    Scenes.Template.types[t].collision = (Collisions)int.Parse(l[2]);
                }
                template.Close();
            }

            activeTypeGroup  = Scenes.Level;
            mainWindow.Title = string.Format("RayTwol  -  {0}  -  {1}×{2}", levelName, Scenes.Level.width, Scenes.Level.height);

            Mouse.OverrideCursor = Cursors.Arrow;
        }
Пример #4
0
        public static void LoadSceneFromFolder(string folderName)
        {
            try
            {
                if (Directory.Exists(folderName))
                {
                    // ------ LOAD GEOMETRY ------ //
                    string[] OBJs = Directory.GetFiles(folderName, "*.obj");
                    foreach (string OBJ in OBJs)
                    {
                        StreamReader obj     = new StreamReader(OBJ);
                        char[]       spl     = new char[] { ' ' };
                        char[]       splFace = new char[] { '/' };
                        string[]     line;
                        Mesh         mesh = new Mesh();
                        List <Vec2>  vt   = new List <Vec2>();
                        mesh.tag    = "world";
                        mesh.colour = new Colour(37, 95, 75);

                        while (!obj.EndOfStream)
                        {
                            line = obj.ReadLine().Split(spl);
                            switch (line[0])
                            {
                            case "v":
                                mesh.AddVert(float.Parse(line[1], CultureInfo.InvariantCulture), float.Parse(line[2], CultureInfo.InvariantCulture), float.Parse(line[3], CultureInfo.InvariantCulture));
                                break;

                            case "vt":
                                vt.Add(new Vec2(float.Parse(line[1], CultureInfo.InvariantCulture), float.Parse(line[2], CultureInfo.InvariantCulture)));
                                break;

                            case "f":
                                Face face = new Face();
                                for (int i = 1; i < line.Length; i++)
                                {
                                    string[] fDat = line[i].Split(splFace);
                                    for (int p = 0; p < fDat.Length; p++)
                                    {
                                        switch (p)
                                        {
                                        case 0:
                                            face.verts.Add(int.Parse(fDat[0]) - 1);
                                            break;

                                        case 1:
                                            face.uv.Add(vt[int.Parse(fDat[1]) - 1]);
                                            break;
                                        }
                                    }
                                }

                                if (face.verts.Count > 2)
                                {
                                    mesh.AddFace(face);
                                }
                                break;
                            }
                        }
                        obj.Close();
                    }

                    // ------ LOAD TEXTURE ------ //
                    string[] MTLs  = Directory.GetFiles(folderName, "*.mtl");
                    uint     texID = 0;

                    GL.GenTextures(texture.Length, texture);

                    foreach (string MTL in MTLs)
                    {
                        StreamReader mtl     = new StreamReader(MTL);
                        char[]       spl     = new char[] { ' ' };
                        string[]     splMat  = new string[] { @"..\", ".png" };
                        char[]       splName = new char[] { @"\"[0] };
                        string[]     line;
                        string       texDir = "";
                        string       texName;

                        while (!mtl.EndOfStream)
                        {
                            line = mtl.ReadLine().Split(spl);
                            switch (line[0])
                            {
                            case "map_Kd":
                                if (line[1].Split(splMat, StringSplitOptions.None).Length > 2)
                                {
                                    texDir = Editor.cf_gameDir + "\\Data\\World\\Levels\\_raytwol\\" + line[1].Split(splMat, StringSplitOptions.None)[1] + ".png";
                                }
                                break;
                            }
                        }
                        mtl.Close();
                        texName = texDir.Split(splName)[texDir.Split(splName).Length - 1];

                        bool transparent = false;
                        if (texDir != "")
                        {
                            Bitmap textureImage = new Bitmap(Image.FromFile(texDir));
                            textureImage.RotateFlip(RotateFlipType.RotateNoneFlipY);

                            // -- Check cache --
                            bool texFound = false;
                            if (File.Exists("RayTwol_texcache.txt"))
                            {
                                var cache = new StreamReader("RayTwol_texcache.txt");
                                while (!cache.EndOfStream)
                                {
                                    string[] l = cache.ReadLine().Split(spl);
                                    if (l[0] == texName)
                                    {
                                        texFound = true;
                                        if (l[1] == "tr")
                                        {
                                            transparent = true;
                                        }
                                        else if (l[1] == "op")
                                        {
                                            transparent = false;
                                        }
                                    }
                                }
                                cache.Close();
                            }
                            if (!texFound)
                            {
                                transparent = Func.CheckIfTransparent(textureImage);
                                var cache = new StreamWriter("RayTwol_texcache.txt", true);
                                if (transparent)
                                {
                                    cache.WriteLine(texName + " tr");
                                }
                                else
                                {
                                    cache.WriteLine(texName + " op");
                                }
                                cache.Close();
                            }

                            // -- OpenGL --
                            GL.BindTexture(TextureTarget.Texture2D, texture[texID]);
                            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, textureImage.Width, textureImage.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte,
                                          textureImage.LockBits(new Rectangle(0, 0, textureImage.Width, textureImage.Height),
                                                                ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb).Scan0);

                            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (float)TextureMinFilter.Linear);
                            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (float)TextureMinFilter.Linear);
                        }
                        Meshes.all[(int)texID].texID = texID;

                        if (transparent)
                        {
                            Meshes.world_transparent.Add(Meshes.all[(int)texID]);
                        }
                        else
                        {
                            Meshes.world_opaque.Add(Meshes.all[(int)texID]);
                        }

                        texID++;
                    }
                    textureCount = (int)texID;
                }
            }
            catch (Exception e)
            {
                var warn = new Warning("Error", string.Format("The geometry for this level could not be loaded ({0}). Press OK to re-initialise, or Cancel to continue.", e.Message)).ShowDialog();
                if (warn.Value)
                {
                    Setup.FirstTimeSetup();
                    Environment.Exit(0);
                }
            }
        }