Example #1
0
        public static bool Read(RAFFileListEntry file, ref InibinFile data, Logger logger)
        {
            bool result = true;

            logger.Event("Reading inibin: " + file.FileName);

            try
            {
                // Get the data from the archive
                MemoryStream myInput = new MemoryStream( file.GetContent() );
                result = ReadCharacterInibin(myInput, ref data, logger);

                int end = file.FileName.LastIndexOf("/");
                String directory = file.FileName.Substring(0, end);
                String archive = file.RAFArchive.RAFFilePath;
                archive = archive.Replace("\\", "/");
                end = archive.LastIndexOf("/");
                archive = archive.Substring(0, end);

                data.directory = new DirectoryInfo(archive + "/" + directory);
                myInput.Close();
            }
            catch(Exception e)
            {
                logger.Error("Unable to open memory stream: " + file.FileName);
                logger.Error(e.Message);
                result = false;
            }

            return result;
        }
Example #2
0
        /// <summary>
        /// Read in binary .dds file from RAF.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="data">The contents of the file are stored in here.</param>
        /// <returns></returns>
        public static bool Read(RAFFileListEntry file, ref Bitmap bitmap, Logger logger)
        {
            bool result = true;

            logger.Event("Reading dds: " + file.FileName);

            try
            {
                // Create image.
                int[] images = new int[1];
                Il.ilGenImages(1, images);

                // Bind image.
                Il.ilBindImage(images[0]);

                // Load the image data into DevIL.
                byte[] data = file.GetContent();
                result = Il.ilLoadL(Il.IL_DDS, data, data.Length);
                if (result == true)
                {
                    int width = Il.ilGetInteger(Il.IL_IMAGE_WIDTH);
                    int height = Il.ilGetInteger(Il.IL_IMAGE_HEIGHT); ;

                    // Create the bitmap.
                    bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
                    Rectangle rect = new Rectangle(0, 0, width, height);

                    // Store the DevIL image data into the bitmap.
                    BitmapData bitmapData = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);

                    Il.ilConvertImage(Il.IL_BGRA, Il.IL_UNSIGNED_BYTE);
                    Il.ilCopyPixels(0, 0, 0, width, height, 1, Il.IL_BGRA, Il.IL_UNSIGNED_BYTE, bitmapData.Scan0);

                    bitmap.UnlockBits(bitmapData);
                }

                // Free image.
                Il.ilDeleteImages(1, images);

                if (result == false)
                {
                    throw new System.Exception("Unable to load image data.");
                }
            }
            catch(Exception e)
            {
                logger.Error("Unable to open dds file: " + file.FileName);
                logger.Error(e.Message);
                result = false;
            }

            return result;
        }
Example #3
0
        /// <summary>
        /// Read in binary .anm file from RAF.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="data">The contents of the file are stored in here.</param>
        /// <returns></returns>
        public static bool Read(RAFFileListEntry file, ref ANMFile data, Logger logger)
        {
            bool result = true;

            logger.Event("Reading anm: " + file.FileName);

            try
            {
                // Get the data from the archive
                MemoryStream myInput = new MemoryStream( file.GetContent() );
                result = ReadBinary(myInput, ref data, logger);
                myInput.Close();
            }
            catch(Exception e)
            {
                logger.Error("Unable to open memory stream: " + file.FileName);
                logger.Error(e.Message);
                result = false;
            }

            return result;
        }
Example #4
0
        /// <summary>
        /// Load texture from RAF.
        /// </summary>
        /// <param name="file">The RAF file entry of the texture.</param>
        /// <param name="target">Only supports 2D.</param>
        /// <returns></returns>
        public bool Create(RAFFileListEntry file, TextureTarget target, SupportedImageEncodings encoding, Logger logger)
        {
            bool result = true;

            this.target = target;

            // Hacky sanity check
            if (target != TextureTarget.Texture2D)
            {
                return false;
            }

            GL.Enable(EnableCap.Texture2D);
            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);

            // Create a System.Drawing.Bitmap.
            Bitmap bitmap = null;
            if (encoding == SupportedImageEncodings.DDS)
            {
                // Special case.
                result = DDSReader.Read(file, ref bitmap, logger);
            }
            else
            {
                // Normal case.
                result = CreateBitmap(file.GetContent(), ref bitmap);
            }

            // Pass the Bitmap into OpenGL.
            if (result == true &&
                bitmap != null)
            {
                result = CreateTexture(bitmap, target);
            }

            if (result == true)
            {
                // Set up texture parameters.
                GL.TexEnv(TextureEnvTarget.TextureEnv,
                    TextureEnvParameter.TextureEnvMode,
                    (Int32)TextureEnvModeCombine.Modulate);

                GL.TexParameter(TextureTarget.Texture2D,
                    TextureParameterName.TextureMinFilter,
                    (Int32)TextureMinFilter.Linear);

                GL.TexParameter(TextureTarget.Texture2D,
                    TextureParameterName.TextureMagFilter,
                    (Int32)TextureMagFilter.Linear);

                GL.TexParameter(TextureTarget.Texture2D,
                    TextureParameterName.TextureWrapS,
                    (Int32)TextureWrapMode.Repeat);

                GL.TexParameter(TextureTarget.Texture2D,
                    TextureParameterName.TextureWrapT,
                    (Int32)TextureWrapMode.Repeat);
            }

            return result;
        }