Esempio 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));
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a text file in the current module under the given name.
        /// </summary>
        /// <param name="file">The name to create a file under.</param>
        /// <remarks>MUST save the module after calling this method, or
        /// the resource will not be found.</remarks>
        public void CreateTextFile(string file)
        {
            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 ArgumentException("File '" + file + "' already exists.", "file");
            }

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

            if (resource == null)
            {
                throw new ApplicationException("Failed to retrieve or create resource.");
            }
        }
Esempio n. 3
0
        public bool HasTextFile(string file)
        {
            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);

            return(resource != null);
        }
Esempio n. 4
0
        /// <summary>
        /// Get a 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 resource entry is returned on success, else null if
        /// the resource didn't exist.</returns>
        public IResourceEntry GetResource(OEIResRef ResRef, ushort ResType)
        {
            IResourceEntry ResEntry;

            if (Repositories == null)
            {
                LoadResourceRepositories();
            }

            foreach (IResourceRepository Repository in Repositories)
            {
                ResEntry = Repository.FindResource(ResRef, ResType);

                if (ResEntry == null || ResEntry is MissingResourceEntry)
                {
                    continue;
                }

                return(ResEntry);
            }

            return(null);
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a blueprint and its resource for a given instance.
        /// Cf. ElectronPanel_.DuplicateBlueprint()
        /// </summary>
        /// <param name="iinstance"></param>
        /// <param name="irepo"></param>
        /// <returns></returns>
        static INWN2Blueprint CreateBlueprint(INWN2Instance iinstance, IResourceRepository irepo)
        {
            INWN2Blueprint iblueprint = new NWN2CreatureBlueprint();

            // NWN2Toolset.NWN2.Data.Instances.NWN2CreatureInstance.CreateBlueprintFromInstance()

            iblueprint.CopyFromTemplate(iinstance as INWN2Template);             // does not copy inventory or equipped!

            // workaround toolset glitch re. template resref string ->
            // Loading a module with an instance that doesn't have a template
            // resref string isn't the same as deleting that string. And vice
            // versa: loading a module with an instance that has an invalid
            // template resref string isn't the same as filling a blank string
            // with an invalid resref string.
            //
            // So basically go through things step by step to ensure that all
            // this resource crap exits the poop chute w/out constipation.

            OEIResRef resref;

            if (iinstance.Template == null ||
                iinstance.Template.ResRef == null ||
                iinstance.Template.ResRef.IsEmpty())
            {
                string tag = iinstance.Name.ToLower();                 // create a resref based on tag
                if (String.IsNullOrEmpty(tag))
                {
                    tag = "creature";
                }

                resref = new OEIResRef(tag);
            }
            else
            {
                resref = CommonUtils.SerializationClone(iinstance.Template.ResRef) as OEIResRef;
            }

            iblueprint.TemplateResRef = resref;


            if (iinstance.Template != null)
            {
                iblueprint.Resource = CommonUtils.SerializationClone(iinstance.Template) as IResourceEntry;
            }

            if (iblueprint.Resource == null)
            {
                iblueprint.Resource = new MissingResourceEntry(resref);
            }

            if (iblueprint.Resource.ResRef == null ||
                iblueprint.Resource.ResRef.IsEmpty())
            {
                iblueprint.Resource.ResRef = resref;
            }

            iblueprint.Resource.ResourceType = 2027;

            iblueprint.Comment = iinstance.Comment;

// copy equipped ->
            (iblueprint as NWN2CreatureTemplate).EquippedItems = new NWN2EquipmentSlotCollection();
            NWN2InventoryItem equipped;

            for (int i = 0; i != 18; ++i)
            {
                if ((equipped = (iinstance as NWN2CreatureTemplate).EquippedItems[i].Item) != null && equipped.ValidItem)
                {
                    (iblueprint as NWN2CreatureTemplate).EquippedItems[i].Item = (new NWN2BlueprintInventoryItem(equipped as NWN2InstanceInventoryItem)) as NWN2InventoryItem;
                }
            }

// copy inventory ->
            (iblueprint as NWN2CreatureBlueprint).Inventory = new NWN2BlueprintInventoryItemCollection();
            foreach (NWN2InstanceInventoryItem item in (iinstance as NWN2CreatureInstance).Inventory)
            {
                (iblueprint as NWN2CreatureBlueprint).Inventory.Add(new NWN2BlueprintInventoryItem(item));
            }

            return(iblueprint);            // a blueprint with a resource for an Instance
        }
        /// <summary>
        /// Get a 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 resource entry is returned on success, else null if
        /// the resource didn't exist.</returns>
        public IResourceEntry GetResource(OEIResRef ResRef, ushort ResType)
        {
            IResourceEntry ResEntry;

            if (Repositories == null)
                LoadResourceRepositories();

            foreach (IResourceRepository Repository in Repositories)
            {
                ResEntry = Repository.FindResource(ResRef, ResType);

                if (ResEntry == null || ResEntry is MissingResourceEntry)
                    continue;

                return ResEntry;
            }

            return null;
        }
 public ALFAERFResourceEntry(OEIResRef cResRef, ushort usResourceType, IResourceRepository cRepository) : base(cResRef, usResourceType, cRepository)
 {
 }
Esempio n. 8
0
        /// <summary>
        /// Fetches the script indicated
        /// </summary>
        /// <param name="scriptName">The name of the script that is to be fetched</param>
        /// <returns>The script</returns>
        private static IResourceEntry makeScript(string scriptName)
        {
            string scriptsPath = Path.Combine(OEIShared.IO.ResourceManager.Instance.BaseDirectory, @"Data\Scripts.zip");

            ResourceRepository scripts = (ResourceRepository)OEIShared.IO.ResourceManager.Instance.GetRepositoryByName(scriptsPath);
            ushort ncs1 = BWResourceTypes.GetResourceType("NSS");
            OEIResRef resRef = new OEIResRef(scriptName);
            IResourceEntry entry = scripts.FindResource(resRef, ncs1);
            NWN2GameScript script = new NWN2GameScript(entry);
            script.Demand();
            return script.Resource;
        }
Esempio n. 9
0
 /// <summary>
 /// Inserts an image of the item contained in the actor to the grid in the correct cell
 /// </summary>
 /// <param name="actor">The actor (which will of the type item) that contains the referenes to the icon that will be used</param>
 /// <param name="grid">The grid where the image is inserted in</param>
 /// <param name="index">The index where to incert the image</param>
 private static void fixImage(Actor actor, DataGridView grid, int index)
     {
     String imageFilename = String.Empty;
     TwoDAReference baseItem2daRef = actor.BaseItem;
     Bitmap itemIcon = System.Drawing.SystemIcons.Question.ToBitmap();
     TwoDAReference icon2daRef = actor.Icon;
     TwoDAColumn iconColumn = nwn2IconsColumnCollection["ICON"];
     if (icon2daRef != null && iconColumn != null && iconColumn.IsPopulatedValue(icon2daRef.Row))
         {
         imageFilename = iconColumn.LiteralValue(icon2daRef.Row);
         OEIResRef oeiResRef = new OEIResRef(imageFilename);
         IResourceEntry imageResource = ResourceManager.Instance.GetEntry(oeiResRef, ICON_RESOURCE_TYPE);
         if (imageResource != null)
             {
             itemIcon = SpecialBitmapLoader.LoadImageFromStream(imageResource.GetStream(false));
             if (itemIcon == null)
                 {
                 itemIcon = System.Drawing.SystemIcons.Question.ToBitmap();
                 }
             else
                 {
                 Bitmap tmpImg = resizeImage(itemIcon);
                 itemIcon.Dispose();
                 itemIcon = tmpImg;
                 }
             }
         }
     grid.Rows[index].Cells["propsQuestImage"].Value = itemIcon;
     grid.Rows[index].Cells["propsQuestImage"].ToolTipText = imageFilename;
     grid.AutoResizeRow(index, DataGridViewAutoSizeRowMode.AllCellsExceptHeader);
     }
Esempio n. 10
0
 public ALFAERFResourceEntry(OEIResRef cResRef, ushort usResourceType, IResourceRepository cRepository) : base(cResRef, usResourceType, cRepository)
 {
 }