Exemplo n.º 1
0
        public Stream GetTextFileStream(string file, bool write)
        {
            if (NWN2ToolsetMainForm.App.Module == null)
            {
                throw new InvalidOperationException("Module not open.");
            }
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }
            if (file == String.Empty)
            {
                throw new ArgumentException("File name cannot be empty.", "file");
            }

            OEIResRef resRef = new OEIResRef(file);

            IResourceEntry resource = NWN2ToolsetMainForm.App.Module.Repository.FindResource(resRef, txtCode);

            if (resource == null)
            {
                throw new ApplicationException("Failed to retrieve resource.");
            }

            return(resource.GetStream(write));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Open a 2DA resource by name
        /// </summary>
        /// <param name="ResRef">Supplies the resref to open</param>
        /// <param name="ResType">Supplies the restype code of the resource</param>
        /// <returns>The 2DA reader for the entry is returned on success, else
        /// null if the resource didn't exist</returns>
        public TwoDAFile OpenTwoDAResource(string ResRef, ushort ResType)
        {
            IResourceEntry ResEntry = GetResource(ResRef, ResType);

            if (ResEntry == null)
            {
                return(null);
            }

            return(new TwoDAFile(ResEntry.GetStream(false)));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Assigns an IResourceEntry and creates a SEFGroup for it.
        /// </summary>
        /// <param name="resent"></param>
        internal static void CreateSefgroup(IResourceEntry resent)
        {
            Resent = resent;

            Altgroup = null;
            Solgroup = null;

            Sefgroup = new SEFGroup();

            using (Stream bin = Resent.GetStream(false))
                Sefgroup.XmlUnserialize(bin);

            Resent.Release();
        }
Exemplo n.º 4
0
        /// <summary>
        /// This routine scans module.ifo for a campaign GUID.  If found, a
        /// campaign.cam file with the same GUID is searched for and its
        /// containing directory is added to the directory resource list.
        /// </summary>
        /// <param name="ModuleIfo">Supplies the module.ifo GFF reader.</param>
        /// <param name="HomeDirectory">Supplies the NWN2 home directory.</param>
        /// <param name="InstallDirectory">Supplies the NWN2 install directory.</param>
        private void AddModuleCampaign(GFFFile ModuleIfo, string HomeDirectory, string InstallDirectory)
        {
            byte[] GUIDData = ModuleIfo.TopLevelStruct.GetVoidDataSafe("Campaign_ID", null);

            if (GUIDData == null || GUIDData.Length != 16)
            {
                return;
            }

            Guid CampaignGUID = new Guid(GUIDData);

            string[] SearchDirs = new string[] { HomeDirectory, InstallDirectory };

            //
            // Attempt to locate a campaign.cam file with the same GUID as the
            // module.
            //

            foreach (string PathName in SearchDirs)
            {
                string CampaignFolder = String.Format("{0}\\Campaigns", PathName);

                if (!Directory.Exists(CampaignFolder))
                {
                    continue;
                }

                foreach (string CampaignDir in Directory.EnumerateDirectories(CampaignFolder))
                {
                    using (DirectoryResourceRepository Repository = new DirectoryResourceRepository(CampaignDir))
                    {
                        Repository.PopulateRepository();

                        IResourceEntry ResEntry = Repository.FindResource(new OEIResRef("campaign"), ResCAM);

                        if (ResEntry == null)
                        {
                            continue;
                        }

                        GFFFile CampaignCAM = new GFFFile(ResEntry.GetStream(false));

                        GUIDData = CampaignCAM.TopLevelStruct.GetVoidDataSafe("GUID", null);

                        if (GUIDData == null || GUIDData.Length != 16)
                        {
                            continue;
                        }

                        Guid ID = new Guid(GUIDData);

                        if (!CampaignGUID.Equals(ID))
                        {
                            continue;
                        }

                        Repositories.Add(new DirectoryResourceRepository(CampaignDir));
                        return;
                    }
                }
            }
        }