Beispiel #1
0
        /// <summary>
        /// Gets all resource names for the specified type.
        /// </summary>
        /// <param name="type">A resource type.</param>
        /// <param name="moduleOnly">If true, only bundled module resources will be returned.</param>
        /// <returns>Any matching ResRef names, otherwise an empty enumeration.</returns>
        public IEnumerable <string> FindResourcesOfType(ResRefType type, bool moduleOnly = true)
        {
            CExoStringList resourceList = ResMan.GetResOfType((ushort)type, moduleOnly.ToInt());

            for (int i = 0; i < resourceList.m_nCount; i++)
            {
                yield return(resourceList._OpIndex(i).ToString());
            }
        }
Beispiel #2
0
        /// <summary>
        /// Gets the specified Gff resource.
        /// </summary>
        /// <param name="name">The resource name to fetch, without any filetype extensions.</param>
        /// <param name="type">The type of the file/resource.</param>
        /// <returns>A <see cref="GffResource"/> representation of the specified resource if it exists, otherwise null.</returns>
        public GffResource?GetGenericFile(string name, ResRefType type)
        {
            CResRef resRef = new CResRef(name);

            if (!ResMan.Exists(resRef, (ushort)type).ToBool())
            {
                return(null);
            }

            CResGFF gff = new CResGFF((ushort)type, $"{type.ToString()} ".GetNullTerminatedString(), resRef);

            return(new GffResource(name, gff));
        }
Beispiel #3
0
        private bool TryGetNativeResource(string name, ResRefType type, [NotNullWhen(true)] out CRes?res)
        {
            res = default;
            CResRef resRef = new CResRef(name);

            if (!ResMan.Exists(resRef, (ushort)type).ToBool())
            {
                return(false);
            }

            res = ResMan.GetResObject(resRef, (ushort)type);
            return(res != null);
        }
Beispiel #4
0
        private byte[]? GetStandardResourceData(string name, ResRefType type)
        {
            if (TryGetNativeResource(name, type, out CRes? res))
            {
                void *data = res.GetData();
                int   size = res.GetSize();

                byte[] retVal = new byte[res.m_nSize];
                Marshal.Copy((IntPtr)data, retVal, 0, size);
                return(retVal);
            }

            return(null);
        }
Beispiel #5
0
        /// <summary>
        /// Gets the raw text of the specified resource.
        /// </summary>
        /// <param name="name">The resource name to retrieve.</param>
        /// <param name="type">The type of resource to retrieve.</param>
        /// <returns>The raw text of the associated resource, otherwise null if the resource does not exist.</returns>
        public string?GetResourceText(string name, ResRefType type)
        {
            switch (type)
            {
            case ResRefType.NSS:
                return(GetNSSContents(name.ToExoString()));

            case ResRefType.NCS:
                return(null);

            default:
                byte[]? data = GetStandardResourceData(name, type);
                return(data != null?StringHelper.Cp1252Encoding.GetString(data) : null);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Gets the raw data of the specified resource.
        /// </summary>
        /// <param name="name">The resource name to retrieve.</param>
        /// <param name="type">The type of resource to retrieve.</param>
        /// <returns>The raw data of the associated resource, otherwise null if the resource does not exist.</returns>
        public byte[]? GetResourceData(string name, ResRefType type)
        {
            switch (type)
            {
            case ResRefType.NSS:
                string?source = GetNSSContents(name.ToExoString());
                return(source != null?StringHelper.Cp1252Encoding.GetBytes(source) : null);

            case ResRefType.NCS:
                return(null);

            default:
                return(GetStandardResourceData(name, type));
            }
        }
Beispiel #7
0
 /// <summary>
 /// Determines if the supplied resource exists and is of the specified type.
 /// </summary>
 /// <param name="name">The resource name to check.</param>
 /// <param name="type">The type of this resource.</param>
 /// <returns>true if the supplied resource exists and is of the specified type, otherwise false.</returns>
 public bool IsValidResource(string name, ResRefType type = ResRefType.UTC)
 {
     return(ResMan.Exists(new CResRef(name), (ushort)type, null).ToBool());
 }