private static Stream GetStream(string resref, ResourceType type)
        {
            Stream resourceStream;
            uint   id;

            //Look in unity's resources first
            //Then in the override folder
            //Then check the active modules for local files
            for (int i = 0; i < activeModules.Count; i++)
            {
                if (activeModules[i].TryGetResource(resref, type, out resourceStream))
                {
                    return(resourceStream);
                }
            }

            //Then try and load from BIFs
            if (keyObject.TryGetResourceID(resref, type, out id))
            {
                uint      bifIndex = id >> 20;
                BIFObject bif      = bifObjects[bifIndex];

                return(bif.GetResourceData(bif.GetResourceById(id)));
            }
            //And finally, try and load from global ERFs
            else if ((resourceStream = textures.GetResource(resref, type)) != null)
            {
            }
            else if ((resourceStream = guiTextures.GetResource(resref, type)) != null)
            {
            }

            return(resourceStream);
        }
        public static void Init(string rootDir, Game game)
        {
            targetGame = game;

            RootDirectory   = rootDir;
            ModuleDirectory = rootDir + "\\modules";

            activeModules = new List <Module>();
            loaded2das    = new Dictionary <string, _2DAObject>();

            //File.Open(@"‪D:\\Program Files\\Star Wars - KotOR2\\chitin.key", FileMode.Open);

            keyObject = new KEYObject(rootDir + "\\chitin.key");

            KEYObject.BIFStream[] bifs = keyObject.GetBIFs();
            bifObjects = new BIFObject[bifs.Length];
            for (int i = 0; i < bifs.Length; i++)
            {
                bifObjects[i] = new BIFObject(rootDir + "\\" + bifs[i].Filename);
            }

            textures    = new ERFObject(rootDir + "\\TexturePacks\\swpc_tex_tpa.erf");
            guiTextures = new ERFObject(rootDir + "\\TexturePacks\\swpc_tex_gui.erf");
        }