User Tools

Site Tools


falcon4:file_formats:rsc_idx_fileformat

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
falcon4:file_formats:rsc_idx_fileformat [2009-02-07 00:47]
lightning
falcon4:file_formats:rsc_idx_fileformat [2009-02-07 07:02] (current)
Line 84: Line 84:
  
 ===== Example Code in C# ===== ===== Example Code in C# =====
-The following C# class (F4Resources.F4ResourceBundleReader) illustrates how to read a Falcon Resource Bundle (.RSC file + .IDX file). ​ It's not optimized for speed (i.e. it uses SetPixel for setting image colors and it uses Array.Copy for copying raw binary data instead of the faster native memory bit-to-block transfer techniques),​ but it is more illustrative,​ as a result. +The following C# class (F4Resources.F4ResourceBundleReader) illustrates how to read a Falcon Resource Bundle (.RSC file + .IDX file) at a low level.  It's not optimized for speed (i.e. it uses SetPixel for setting image colors and it uses Array.Copy for copying raw binary data instead of the faster native memory bit-to-block transfer techniques),​ but it is more illustrative,​ as a result. 
-<​code ​language="​c#"​>+<​code ​cpp>
 using System; using System;
 using System.Collections.Generic;​ using System.Collections.Generic;​
Line 291: Line 291:
             }             }
         }         }
-        public int Count+        public int NumResources
         {         {
             get             get
Line 441: Line 441:
             return null;             return null;
         }         }
 +    }
 +}
 +</​code>​
 +
 +The next chunk of C# example code shows the above class being used in a Windows Forms application,​ and illustrates how one might use the class presented in the previous example.
 +<code cpp>
 +using System;
 +using System.Drawing;​
 +using System.Windows.Forms;​
 +using System.IO;
 +using System.Runtime.InteropServices;​
 +
 +namespace WindowsFormsApplication1
 +{
 +    public partial class Form1 : Form
 +    {
 +        public Form1()
 +        {
 +            InitializeComponent();​
 +        }
 +
 +        private void button1_Click(object sender, EventArgs e)
 +        {
 +            string resourceBundleIndexPath = @"​C:​\Microprose\Falcon4\Theaters\Vietnam\art\art\resource\select.idx";​
 +            F4Resources.F4ResourceBundleReader resourceBundleReader = new F4Resources.F4ResourceBundleReader();​
 +            resourceBundleReader.Load(resourceBundleIndexPath);​
 +            for (int i = 0; i < resourceBundleReader.NumResources;​ i++)
 +            {
 +                Application.DoEvents();​
 +                F4Resources.F4ResourceType thisResourceType = resourceBundleReader.GetResourceType(i);​
 +                switch (thisResourceType)
 +                {
 +                    case F4Resources.F4ResourceType.Unknown:​
 +                        break;
 +                    case F4Resources.F4ResourceType.ImageResource:​ //read an image resource (you could assign the image to a picturebox, or save it to disk, or whatever)
 +                        Bitmap thisImage = resourceBundleReader.GetImageResource(i);​
 +                        break;
 +                    case F4Resources.F4ResourceType.SoundResource:​ //read and play a sound file (writes sound to a temp file and calls WinAPI PlaySound to play it)
 +                        byte[] thisSound = resourceBundleReader.GetSoundResource(i);​
 +                        string tempFile = Path.GetTempFileName();​
 +                        try
 +                        {
 +                            using (FileStream fs = new FileStream(tempFile,​ FileMode.Create))
 +                            {
 +                                fs.Write(thisSound,​ 0, thisSound.Length);​
 +                                fs.Flush();
 +                                fs.Close();
 +                            }
 +                            PlaySound(tempFile,​ IntPtr.Zero,​ SoundFlags.SND_FILENAME);​
 +                        }
 +                        finally
 +                        {
 +                            try
 +                            {
 +                                new FileInfo(tempFile).Delete();​
 +                            }
 +                            catch (IOException)
 +                            {
 +                            }
 +                        }
 +                        break;
 +                    case F4Resources.F4ResourceType.FlatResource:​
 +                        byte[] thisFlatResource = resourceBundleReader.GetFlatResource(i);​
 +                        break;
 +                    default:
 +                        break;
 +                }
 +            }
 +        }
 +        [Flags]
 +        public enum SoundFlags : int
 +        {
 +            SND_SYNC = 0x0000, ​ // play synchronously (default) ​
 +            SND_ASYNC = 0x0001, ​ // play asynchronously ​
 +            SND_NODEFAULT = 0x0002, ​ // silence (!default) if sound not found 
 +            SND_MEMORY = 0x0004, ​ // pszSound points to a memory file
 +            SND_LOOP = 0x0008, ​ // loop the sound until next sndPlaySound ​
 +            SND_NOSTOP = 0x0010, ​ // don't stop any currently playing sound 
 +            SND_NOWAIT = 0x00002000, // don't wait if the driver is busy 
 +            SND_ALIAS = 0x00010000, // name is a registry alias 
 +            SND_ALIAS_ID = 0x00110000, // alias is a predefined ID
 +            SND_FILENAME = 0x00020000, // name is file name 
 +            SND_RESOURCE = 0x00040004 ​ // name is resource name or atom 
 +        }
 +
 +        [System.Runtime.InteropServices.DllImport("​winmm.DLL",​ EntryPoint = "​PlaySound",​ SetLastError = true, CharSet = CharSet.Unicode,​ ThrowOnUnmappableChar = true)]
 +        private static extern bool PlaySound(string szSound, System.IntPtr hMod, SoundFlags flags);
     }     }
 } }
 </​code>​ </​code>​
falcon4/file_formats/rsc_idx_fileformat.1233967626.txt.gz · Last modified: 2009-02-07 00:47 by lightning