public ResourceKey(int APIversion, EventHandler handler, IResourceKey basis)
     : this(APIversion, handler)
 {
     this.instance = basis.Instance;
     this.ResourceGroup = basis.ResourceGroup;
     this.ResourceType = basis.ResourceType;
 }
Beispiel #2
0
 /// <summary>
 /// Take into account some of the weird ways in which one resource refers to another, based on resource type.
 /// </summary>
 /// <param name="rk">An <c>IResourceKey</c> to compare with.</param>
 /// <returns></returns>
 public new int CompareTo(IResourceKey rk)
 {
     int res = this.ResourceType.CompareTo(rk.ResourceType); if (res != 0) return res;
     res = (this.ResourceGroup & 0x07FFFFFF).CompareTo(rk.ResourceGroup & 0x07FFFFFF); if (res != 0) return res;
     return ((this.ResourceType == 0x736884F1 && this.Instance >> 32 == 0) ? this.Instance & 0x07FFFFFF : this.Instance)
         .CompareTo(((rk.ResourceType == 0x736884F1 && rk.Instance >> 32 == 0) ? rk.Instance & 0x07FFFFFF : rk.Instance));
 }
Beispiel #3
0
 /// <summary>
 /// Instantiate a new <see cref="TGIN"/> based on the <see cref="IResourceKey"/> and <paramref name="name"/>.
 /// </summary>
 /// <param name="rk">An <see cref="IResourceKey"/>.</param>
 /// <param name="name">A <see cref="String"/>, the name of the resource.</param>
 public TGIN(IResourceKey rk, string name)
 {
     this.ResType     = rk.ResourceType;
     this.ResGroup    = rk.ResourceGroup;
     this.ResInstance = rk.Instance;
     this.ResName     = name;
 }
Beispiel #4
0
 public static bool Contains(IResourceKey rk)
 {
     return(ExcludedResources != null && ExcludedResources.Exists(mrk =>
                                                                  (!mrk.ResourceType.HasValue || mrk.ResourceType.Value == rk.ResourceType) &&
                                                                  (!mrk.ResourceGroup.HasValue || mrk.ResourceGroup.Value == rk.ResourceGroup) &&
                                                                  (!mrk.Instance.HasValue || mrk.Instance.Value == rk.Instance)));
 }
 public override void CreateKindredRK(IResourceKey parentKey,
     IResourceKey newParentKey, ref IResourceKey kindredKey)
 {
     kindredKey.ResourceType = this.thumType;
     kindredKey.ResourceGroup = (uint)(this.isCWAL ? 1 : 0);
     kindredKey.Instance = newParentKey.Instance;
 }
 protected override bool ICanSlurpRK(IResourceKey key)
 {
     // From Catlg_removeRefdCatlgs
     return (!Enum.IsDefined(typeof(CatalogType), key.ResourceType) ||
         key.Instance == base.originalKey.Instance) &&
         (base.includeDDSes || !ResourceGraph.IsDDS(key.ResourceType));
 }
Beispiel #7
0
        string Compare(IPackage pkgA, IPackage pkgB, IResourceKey rk)
        {
            IResource left  = s3pi.WrapperDealer.WrapperDealer.GetResource(0, pkgA, pkgA.Find(x => x.CompareTo(rk) == 0), true);
            IResource right = s3pi.WrapperDealer.WrapperDealer.GetResource(0, pkgB, pkgB.Find(x => x.CompareTo(rk) == 0), true);

            return(left.AsBytes.CompareTo(right.AsBytes) == 0 ? "=" : "!");
        }
Beispiel #8
0
        bool importFile(string filename, TGIN tgin, bool useName, bool rename, bool compress, DuplicateHandling dups, bool select)
        {
            IResourceKey rk      = (TGIBlock)tgin;
            string       resName = tgin.ResName;
            bool         nmOK    = true;
            MemoryStream ms      = new MemoryStream();
            BinaryWriter w       = new BinaryWriter(ms);
            BinaryReader r       = new BinaryReader(new FileStream(filename, FileMode.Open, FileAccess.Read));

            w.Write(r.ReadBytes((int)r.BaseStream.Length));
            r.Close();
            w.Flush();

            if (useName && resName != null && resName.Length > 0)
            {
                nmOK = browserWidget1.ResourceName(rk.Instance, resName, true, rename);
            }

            IResourceIndexEntry rie = NewResource(rk, ms, dups, compress);

            if (rie != null)
            {
                browserWidget1.Add(rie, select);
            }
            return(nmOK);
        }
 public override void CreateKindredRK(IResourceKey parentKey,
                                      IResourceKey newParentKey, ref IResourceKey kindredKey)
 {
     kindredKey.ResourceType  = this.thumType;
     kindredKey.ResourceGroup = (uint)(this.isCWAL ? 1 : 0);
     kindredKey.Instance      = newParentKey.Instance;
 }
            public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
            {
                AApiVersionedFieldsCTD.TypedValuePropertyDescriptor pd = (AApiVersionedFieldsCTD.TypedValuePropertyDescriptor)context.PropertyDescriptor;
                IResourceKeyCTD     rkCTD = (IResourceKeyCTD)pd.GetValue(null);
                AApiVersionedFields owner = rkCTD.owner;
                string       field        = rkCTD.field;
                object       component    = rkCTD.component;
                IResourceKey rk           = (IResourceKey)AApiVersionedFieldsCTD.GetFieldValue(owner, field).Value;

                if (typeof(IResourceKey).IsAssignableFrom(value.GetType()))
                {
                    IResourceKey rkNew = (IResourceKey)value;
                    rk.ResourceType  = rkNew.ResourceType;
                    rk.ResourceGroup = rkNew.ResourceGroup;
                    rk.Instance      = rkNew.Instance;
                    return(rk);
                }
                if (value != null && value is string)
                {
                    if (AResourceKey.TryParse((string)value, rk))
                    {
                        return(rk);
                    }
                    else
                    {
                        throw new NotSupportedException("Invalid data: " + (string)value);
                    }
                }
                return(base.ConvertFrom(context, culture, value));
            }
Beispiel #11
0
 MemoryStream TextEdit(IResourceKey key, IResource res)
 {
     return(s3pi.Helpers.HelperManager.Edit(key, res,
                                            Settings.Default.TextEditorCmd,
                                            Settings.Default.TextEditorWantsQuotes,
                                            Settings.Default.TextEditorIgnoreTS));
 }
Beispiel #12
0
 public DefaultConnection(IResourceKey rk,
                          RKContainer rkContainer, ResourceDataActions childActions,
                          string absolutePath)
     : base(rk, absolutePath, childActions)
 {
     this.rkContainer = rkContainer;
 }
Beispiel #13
0
 public bool Equals(IResourceKey other)
 {
     return(other != null &&
            this.IID == other.Instance &&
            this.GID == other.ResourceGroup &&
            this.TID == other.ResourceType);
 }
Beispiel #14
0
 MemoryStream HexEdit(IResourceKey key, IResource res)
 {
     return(s4pi.Helpers.HelperManager.Edit(key, res,
                                            S4PIDemoFE.Properties.Settings.Default.HexEditorCmd,
                                            S4PIDemoFE.Properties.Settings.Default.HexEditorWantsQuotes,
                                            S4PIDemoFE.Properties.Settings.Default.HexEditorIgnoreTS));
 }
Beispiel #15
0
            protected internal void SetKindredRK(IResourceKey newParentKey)
            {
                IResourceKey kinKey = this.Child.Key;

                this.Core.CreateKindredRK(this.Parent.OriginalKey, newParentKey, ref kinKey);
                this.Child.Key = new RK(kinKey);
            }
Beispiel #16
0
            public GraphNode(ResourceGraph graph, IResourceKey originalKey, IResourceNode core,
                             PathPackageTuple origin, ResourceDataActions nodeActions, RFileType fileType = RFileType.Unknown)
            {
                this.Graph        = graph;
                this.key          = new RK(originalKey);
                this.OriginalKey  = new RK(originalKey);
                this.ExtensionTag = s3pi.Extensions.ExtList.Ext[originalKey.ResourceType][0];
                this.NodeActions  = nodeActions;
                this.Core         = core;
                this.Origin       = origin;
                if (fileType == RFileType.Unknown)
                {
                    this.fileType = ResourceGraph.GetFileType(originalKey.ResourceType);
                }
                else
                {
                    this.fileType = fileType;
                }
                switch (this.fileType)
                {
                case RFileType.Game:
                    this.name = NameMap.GameNMap.GetName(originalKey.Instance, origin);
                    break;

                case RFileType.DDS:
                    this.name = NameMap.DDSNMap.GetName(originalKey.Instance, origin);
                    break;

                case RFileType.Thum:
                    this.name = NameMap.ThumNMap.GetName(originalKey.Instance, origin);
                    break;
                }
                this.originalName = this.name;
            }
Beispiel #17
0
        public static List <SpecificResource> SlurpKindredResources(
            IResourceKey parentKey, IResourceKinHelper kinHelper)
        {
            List <SpecificResource> resources = new List <SpecificResource>();
            int i, j;
            List <PathPackageTuple> ppts = FileTable.GameContent;

            if (kinHelper.IsKinDDS)
            {
                ppts = FileTable.DDSImages;
            }
            if (kinHelper.IsKinThum)
            {
                ppts = FileTable.Thumbnails;
            }
            if (ppts != null)
            {
                SlurpKindredRKsHelper      helper = new SlurpKindredRKsHelper(parentKey, kinHelper);
                List <IResourceIndexEntry> entries;
                for (i = 0; i < ppts.Count; i++)
                {
                    entries = ppts[i].Package.FindAll(helper.IsKindred);
                    if (entries != null)
                    {
                        for (j = 0; j < entries.Count; j++)
                        {
                            helper.Seen.Add(entries[j]);
                            resources.Add(new SpecificResource(ppts[i], entries[j]));
                        }
                    }
                }
            }
            return(resources);
        }
Beispiel #18
0
 protected override bool ICanSlurpRK(IResourceKey key)
 {
     // From Catlg_removeRefdCatlgs
     return((!Enum.IsDefined(typeof(CatalogType), key.ResourceType) ||
             key.Instance == base.originalKey.Instance) &&
            (base.includeDDSes || !ResourceGraph.IsDDS(key.ResourceType)));
 }
Beispiel #19
0
        public ResourceDetails(IResourceKey key, bool useName = true)
        {
            AvaloniaXamlLoader.Load(this);

            DataContext = new ResourceDetailsViewModel(useName, key);

            SetupDragAndDrop();
        }
Beispiel #20
0
        /*public override bool SetParentReferenceRK(IResourceKey newKey)
         * {
         *  string[] fieldNames = this.contentFieldPath.Split(new char[] { '.' },
         *      StringSplitOptions.RemoveEmptyEntries);
         *  if (fieldNames.Length == 1)
         *  {
         *      IResourceKey rk = this.rootField as IResourceKey;
         *      rk.Instance = newKey.Instance;
         *  }
         *  int i, j, index, indexStrStart, indexStrLength;
         *  TypedValue tv;
         *  string name;
         *  AApiVersionedFields field = this.rootField;
         *  for (i = 1; i < fieldNames.Length; i++)
         *  {
         *      name = fieldNames[i];
         *      indexStrStart = name.IndexOf('[');
         *      if (indexStrStart == -1)
         *      {
         *          tv = field[name];
         *          // TODO: Should we account for the possibility of value type resource keys?
         *          if (typeof(IResourceKey).IsAssignableFrom(tv.Type))
         *          {
         *              IResourceKey rk = tv.Value as IResourceKey;
         *              rk.Instance = newKey.Instance;
         *              field[name] = tv;
         *              return true;
         *          }
         *          if (typeof(TextReader).IsAssignableFrom(tv.Type))
         *          {
         *              this.textFieldHelper.SetReferenceRK(base.OriginalChildKey, newKey);
         *              field[name] = new TypedValue(tv.Type, this.textFieldHelper.FlushReferenceRKs());
         *          }
         *          field = tv.Value as AApiVersionedFields;
         *      }
         *      else
         *      {
         *          indexStrLength = name.IndexOf(']');
         *          if (indexStrLength == -1)
         *              indexStrLength = name.Length - 1 - indexStrStart;
         *          else
         *              indexStrLength = indexStrLength - 1 - indexStrStart;
         *          index = int.Parse(name.Substring(indexStrStart, indexStrLength));
         *          tv = field[name.Substring(0, indexStrStart)];
         *          j = -1;
         *          foreach (var e in tv.Value as IEnumerable)
         *          {
         *              if (index == ++j)
         *              {
         *                  if (e is IResourceKey)
         *                  {
         *                      IResourceKey rk = e as IResourceKey;
         *                      rk.Instance = newKey.Instance;
         *                      return true;
         *                  }
         *                  else if (e is IEnumerable)
         *                  {
         *                      IEnumerable list = e as IEnumerable;
         *                      string suffix = name.Substring(indexStrStart + indexStrLength + 1);
         *                      indexStrStart = suffix.IndexOf('[');
         *                      while (indexStrStart != -1)
         *                      {
         *                          indexStrLength = suffix.IndexOf(']');
         *                          if (indexStrLength == -1)
         *                              indexStrLength = suffix.Length - 1 - indexStrStart;
         *                          else
         *                              indexStrLength = indexStrLength - 1 - indexStrStart;
         *                          int subIndex = int.Parse(suffix.Substring(indexStrStart, indexStrLength));
         *                          int k = -1;
         *                          foreach (var f in list)
         *                          {
         *                              if (index == ++k)
         *                              {
         *                                  if (f is IResourceKey)
         *                                  {
         *                                      IResourceKey rk = f as IResourceKey;
         *                                      rk.Instance = newKey.Instance;
         *                                      return true;
         *                                  }
         *                                  else if (f is IEnumerable)
         *                                  {
         *                                      list = f as IEnumerable;
         *                                      suffix = suffix.Substring(indexStrStart + indexStrLength + 1);
         *                                      indexStrStart = suffix.IndexOf('[');
         *                                  }
         *                                  else
         *                                  {
         *                                      field = f as AApiVersionedFields;
         *                                  }
         *                              }
         *                          }
         *                      }
         *                  }
         *                  else
         *                  {
         *                      field = e as AApiVersionedFields;
         *                  }
         *              }
         *          }
         *      }
         *  }
         *  return false;
         * }/**/

        public DefaultConnection(IResourceKey rk,
                                 AApiVersionedFields rkField, ResourceDataActions childActions,
                                 string absolutePath, string rkFieldPath = "root",
                                 Predicate <IResourceKey> validate       = null)
            : base(rk, absolutePath, childActions)
        {
            this.rkContainer = new RKContainer(rkFieldPath, rkField, absolutePath, validate);
        }
Beispiel #21
0
 protected override bool ICanSlurpRK(IResourceKey key)
 {
     return key.ResourceType != 0x034AEECB //CASP
         && base.isDeepClone || (
            key.ResourceType != 0x00B2D882 //_IMG
         && key.ResourceType != 0x0333406C //_XML
         && key.ResourceType != 0x8FFB80F6 //_DDS
         );
 }
Beispiel #22
0
 protected override bool ICanSlurpRK(IResourceKey key)
 {
     return(key.ResourceType != 0x034AEECB && //CASP
            base.isDeepClone || (
                key.ResourceType != 0x00B2D882 && //_IMG
                key.ResourceType != 0x0333406C && //_XML
                key.ResourceType != 0x8FFB80F6 //_DDS
                ));
 }
 public AResourceConnection(IResourceKey childKey, string path, 
     ResourceDataActions childActions)
 {
     this.absolutePath = path;
     this.originalChildKey = childKey;
     this.childDataActions = childActions;
     this.isChildDDS = ResourceGraph.IsDDS(childKey.ResourceType);
     this.isChildThum = ResourceGraph.IsThum(childKey.ResourceType);
 }
 public AResourceConnection(IResourceKey childKey, string path,
                            ResourceDataActions childActions)
 {
     this.absolutePath     = path;
     this.originalChildKey = childKey;
     this.childDataActions = childActions;
     this.isChildDDS       = ResourceGraph.IsDDS(childKey.ResourceType);
     this.isChildThum      = ResourceGraph.IsThum(childKey.ResourceType);
 }
 public int Add(IResourceKey key)
 {
     if (mKeys.Contains(key))
     {
         return(mKeys.IndexOf(key));
     }
     mKeys.Add(key);
     return(mKeys.Count - 1);
 }
 public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
 {
     if (destinationType.Equals(typeof(string)))
     {
         IResourceKeyCTD ctd = value as IResourceKeyCTD;
         IResourceKey    rk  = (IResourceKey)GetFieldValue(ctd.owner, ctd.field).Value;
         return("" + rk);
     }
     return(base.ConvertTo(context, culture, value, destinationType));
 }
Beispiel #27
0
        /// <summary>
        /// Add a resource, identified by <paramref name="rk"/> with the content from <paramref name="stream"/>
        /// the package referenced by this <see cref="PathPackageTuple"/>.  The new <see cref="SpecificResource"/>
        /// value is returned.
        /// </summary>
        /// <param name="rk">The <see cref="IResourceKey"/> to use to identify the new resource.</param>
        /// <param name="stream">A <see cref="Stream"/> of data to use to populate the new resource.</param>
        /// <returns>The <see cref="SpecificResource"/> representing the newly added <see cref="IResourceIndexEntry"/>.</returns>
        public SpecificResource AddResource(IResourceKey rk, Stream stream = null)
        {
            IResourceIndexEntry rie = Package.AddResource(rk, stream, true);

            if (rie == null)
            {
                return(null);
            }
            return(new SpecificResource(this, rie));
        }
Beispiel #28
0
 public TrackMask(int APIversion, EventHandler handler, uint version,
                  IResourceKey rigKey, float vertexAnimBlendWeight, byte[] unused, TrackMaskList trackMasks)
     : base(APIversion, handler, null)
 {
     mVersion = version;
     mRigKey  = rigKey == null ? new TGIBlock(APIversion, handler, kRigKeyOrder)
         : new TGIBlock(APIversion, handler, kRigKeyOrder, rigKey);
     mVertexAnimBlendWeight = vertexAnimBlendWeight;
     mUnused     = unused ?? (version < 0x201 ? new byte[48] : new byte[28]);
     mTrackMasks = trackMasks ?? new TrackMaskList(handler);
 }
Beispiel #29
0
        public override bool SetRK(IResourceKey newKey, IResourceKey originalKey)
        {
            bool success = true;
            int  i, count = this.kindredRCOLChunkKeys.Count;

            for (i = 0; i < count; i++)
            {
                this.kindredRCOLChunkKeys[i].Instance = newKey.Instance;
            }
            return(success && base.SetRK(newKey, originalKey));
        }
 /// <summary>
 /// Retrieve a resource node to contain the given resource,
 /// readying the appropriate node class or the default node class
 /// </summary>
 /// <param name="resource">The resource to contain in a resource node</param>
 /// <param name="resourceKey">The identifying key of the given resource,
 /// which is used to find the right node to contain it</param>
 /// <param name="AlwaysDefault">When true, indicates ResourceNodeDealer
 /// should always use the <see cref="DefaultNode"/> class</param>
 /// <returns>A resource node containing the given resource</returns>
 public static IResourceNode GetResource(IResource resource, IResourceKey resourceKey,
                                         bool AlwaysDefault = false)
 {
     if (AlwaysDefault)
     {
         return(new DefaultNode(resource, resourceKey));
     }
     else
     {
         return(NodeForType(resource, resourceKey));
     }
 }
 public override bool IsKindred(IResourceKey parentKey, IResourceKey key)
 {
     if (this.thumInstance != 0)
     {
         return(key.ResourceType == this.thumType &&
                key.Instance == this.thumInstance &&
                (!this.isCWAL || (key.ResourceGroup & 0x00FFFFFF) > 0));
     }
     return(key.ResourceType == this.thumType &&
            key.Instance == parentKey.Instance &&
            (!this.isCWAL || (key.ResourceGroup & 0x00FFFFFF) > 0));
 }
Beispiel #32
0
 public ResourceDetails(bool useName, bool displayFilename, IResourceKey rk)
     : this(useName, displayFilename)
 {
     internalchg = true;
     try
     {
         ResourceType = rk.ResourceType;
         ResourceGroup = rk.ResourceGroup;
         Instance = rk.Instance;
         btnOK.Enabled = btnOKCanEnable;
     }
     finally { internalchg = false; UpdateTGIN(); }
 }
 public ResourceDetails(bool useName, bool displayFilename, IResourceKey rk)
     : this(useName, displayFilename)
 {
     internalchg = true;
     try
     {
         ResourceType  = rk.ResourceType;
         ResourceGroup = rk.ResourceGroup;
         Instance      = rk.Instance;
         btnOK.Enabled = btnOKCanEnable;
     }
     finally { internalchg = false; UpdateTGIN(); }
 }
Beispiel #34
0
        /// <summary>
        /// Compare this <see cref="AResourceKey"/> to another <see cref="IResourceKey"/> for sort order purposes
        /// </summary>
        /// <param name="other">Target <see cref="IResourceKey"/></param>
        /// <returns>A 32-bit signed integer that indicates the relative order of the objects being compared.  The return value has these meanings:
        /// <table>
        /// <thead><tr><td><strong>Value</strong></td><td><strong>Meaning</strong></td></tr></thead>
        /// <tbody>
        /// <tr><td>Less than zero</td><td>This instance is less than <paramref name="other"/>.</td></tr>
        /// <tr><td>Zero</td><td>This instance is equal to <paramref name="other"/>.</td></tr>
        /// <tr><td>Greater than zero</td><td>This instance is greater than <paramref name="other"/>.</td></tr>
        /// </tbody>
        /// </table>
        /// </returns>
        /// <exception cref="NotImplementedException">Either this object's Type or the target's is not comparable</exception>
        /// <exception cref="ArgumentException">The target is not comparable with this object</exception>
        public int CompareTo(IResourceKey other)
        {
            int res = ResourceType.CompareTo(other.ResourceType); if (res != 0)

            {
                return(res);
            }

            res = ResourceGroup.CompareTo(other.ResourceGroup); if (res != 0)
            {
                return(res);
            }
            return(Instance.CompareTo(other.Instance));
        }
Beispiel #35
0
        public IResourceIndexEntry Add(IResourceKey rk)
        {
            ResourceIndexEntry rc = new ResourceIndexEntry(new Int32[Hdrsize], new Int32[numFields - Hdrsize]);

            rc.ResourceType   = rk.ResourceType;
            rc.ResourceGroup  = rk.ResourceGroup;
            rc.Instance       = rk.Instance;
            rc.Chunkoffset    = 0xffffffff;
            rc.Unknown2       = 1;
            rc.ResourceStream = null;

            base.Add(rc);
            return(rc);
        }
 public override bool SetRK(IResourceKey oldKey, IResourceKey newKey)
 {
     RKPos rkPos;
     int foundIndex = -1;
     for (int i = 0; i < this.oldToNewRKs.Count; i++)
     {
         rkPos = this.oldToNewRKs[i];
         if (rkPos.OldResourceKey.Equals(oldKey))
         {
             rkPos.NewResourceKey = new RK(newKey);
             foundIndex = i;
         }
     }
     return foundIndex != -1;
 }
            static uint CreateReferenceHelper(GenericRCOLResource rcol, IResourceKey rk)
            {
                int i = rcol.ChunkEntries.FindIndex(x => x.TGIBlock.Equals(rk));

                if (i < 0)
                {
                    i = rcol.Resources.FindIndex(x => x.Equals(rk));
                    return(i < 0 ? 0 : (uint)(i + 1) | 0x30000000);
                }
                else
                {
                    i++;
                    return(i < rcol.publicChunks ? (uint)i : (uint)i | 0x10000000);
                }
            }
        /// <summary>
        /// Add a resource to the package
        /// </summary>
        /// <param name="rk">The resource key</param>
        /// <param name="stream">The stream that contains the resource data</param>
        /// <param name="rejectDups">If true, fail if the resource key already exists</param>
        /// <returns>Null if rejectDups and the resource key exists; else the new IResourceIndexEntry</returns>
        public override IResourceIndexEntry AddResource(IResourceKey rk, Stream stream, bool rejectDups)
        {
            if (rejectDups && Index[rk] != null && !Index[rk].IsDeleted)
            {
                return(null);
            }
            IResourceIndexEntry newrc = Index.Add(rk);

            if (stream != null)
            {
                (newrc as ResourceIndexEntry).ResourceStream = stream;
            }

            return(newrc);
        }
        public override List<SpecificResource> FindKindredResources(IResourceKey parentKey)
        {
            if (this.thumType == 0)
                return null;
            if (this.isCWAL)
                return ResourceGraph.SlurpKindredResources(parentKey, this);

            List<SpecificResource> results = new List<SpecificResource>();
            SpecificResource sr = THUM.getItem(this.isPNG,
                this.thumInstance != 0 ? this.thumInstance : parentKey.Instance,
                this.thumType);
            if (sr != null && sr.Resource != null)
                results.Add(sr);
            return results;
        }
Beispiel #40
0
        public static bool TryParse(string value, out IResourceKey result)
        {
            result = (AResourceKey)new s4pi.Extensions.TGIN();

            string[] tgi = value.Trim().ToLower().Split('-');
            if (tgi.Length != 3) return false;
            foreach (var x in tgi) if (!x.StartsWith("0x")) return false;

            uint tg;
            if (!uint.TryParse(tgi[0].Substring(2), System.Globalization.NumberStyles.HexNumber, null, out tg)) return false;
            result.ResourceType = tg;
            if (!uint.TryParse(tgi[1].Substring(2), System.Globalization.NumberStyles.HexNumber, null, out tg)) return false;
            result.ResourceGroup = tg;

            ulong i;
            if (!ulong.TryParse(tgi[2].Substring(2), System.Globalization.NumberStyles.HexNumber, null, out i)) return false;
            result.Instance = i;

            return true;
        }
 public ThumbnailKinFinder(IResourceKey parentKey, IResource parent, THUM.THUMSize size)
     : base(size.ToString())
 {
     this.isPNG = false;
     if (THUM.CType(parentKey) == CatalogType.ModularResource)
     {
         this.thumType = 0;
     }
     else if (THUM.CType(parentKey) == CatalogType.CAS_Part)
     {
         this.thumType = THUM.getThumbType(parentKey.ResourceType, size, false);
     }
     else
     {
         this.thumInstance = (parent != null) ?
             (ulong)parent["CommonBlock.PngInstance"].Value : 0;
         this.isPNG = this.thumInstance != 0;
         this.thumType = THUM.getThumbType(parentKey.ResourceType, size, this.isPNG);
     }
     this.CompleteKinName();
 }
 //find the chunk, replace the chunk, perhaps create or remove the reference
 public static void ReplaceChunk(this GenericRCOLResource rcolResource, MLOD.Mesh mesh, string field, IResourceKey rk, ARCOLBlock block)
 {
     ARCOLBlock current = GenericRCOLResource.ChunkReference.GetBlock(rcolResource, (GenericRCOLResource.ChunkReference)mesh[field].Value) as ARCOLBlock;
     if (block != null)
     {
         if (current != null) // replacing is easy
         {
             if (current.Tag != block.Tag)
                 throw new Exception(string.Format("mesh field {0} is '{1}' but replacement is '{2}'.", field, current.Tag, block.Tag));
             // ...not entirely sure if these are required...
             current.Data = block.Data;
             block = current;
         }
         else // adding is okay
         {
             rcolResource.ChunkEntries.Add(new GenericRCOLResource.ChunkEntry(0, null, new TGIBlock(0, null, rk), block));
             mesh[field] = new TypedValue(typeof(GenericRCOLResource.ChunkReference), GenericRCOLResource.ChunkReference.CreateReference(rcolResource, rk), "X");
         }
     }
     else // deleting is not allowed - we can only null the reference, not remove the chunk
     {
         mesh[field] = new TypedValue(typeof(GenericRCOLResource.ChunkReference), new GenericRCOLResource.ChunkReference(0, null, 0), "X");
     }
 }
 public virtual bool IsKindred(IResourceKey parentKey, IResourceKey key)
 {
     return key.Instance == parentKey.Instance;
 }
 public virtual bool SetRK(IResourceKey newKey, IResourceKey originalKey)
 {
     return true;
 }
Beispiel #45
0
 /// <summary>
 /// Instantiate a new <see cref="TGIN"/> based on the <see cref="IResourceKey"/> and <paramref name="name"/>.
 /// </summary>
 /// <param name="rk">An <see cref="IResourceKey"/>.</param>
 /// <param name="name">A <see cref="String"/>, the name of the resource.</param>
 public TGIN(IResourceKey rk, string name) { ResType = rk.ResourceType; ResGroup = rk.ResourceGroup; ResInstance = rk.Instance; ResName = name; }
Beispiel #46
0
 /// <summary>
 /// Add a resource to the package
 /// </summary>
 /// <param name="rk">The resource key</param>
 /// <param name="stream">The stream that contains the resource data</param>
 /// <param name="rejectDups">If true, fail if the resource key already exists</param>
 /// <returns>Null if rejectDups and the resource key exists; else the new IResourceIndexEntry</returns>
 public abstract IResourceIndexEntry AddResource(IResourceKey rk, Stream stream, bool rejectDups);
Beispiel #47
0
        void HexEdit(IResourceKey key, IResource res)
        {
            try
            {
                this.Enabled = false;
                Application.DoEvents();

                MemoryStream ms = s4pi.Helpers.HelperManager.Edit(key, res,
                    S4PIDemoFE.Properties.Settings.Default.HexEditorCmd,
                    S4PIDemoFE.Properties.Settings.Default.HexEditorWantsQuotes,
                    S4PIDemoFE.Properties.Settings.Default.HexEditorIgnoreTS);

                MakeFormVisible();
                Application.DoEvents();

                afterEdit(ms);
            }
            finally { this.Enabled = true; }
        }
Beispiel #48
0
 public int CompareTo(IResourceKey other)
 {
     int res = ResourceType.CompareTo(other.ResourceType); if (res != 0) return res;
     res = ResourceGroup.CompareTo(other.ResourceGroup); if (res != 0) return res;
     return Instance.CompareTo(other.Instance);
 }
 public abstract IResourceNode CreateKin(IResource resource, 
     IResourceKey originalKey, object constraints);
Beispiel #50
0
 public bool Equals(IResourceKey x, IResourceKey y) { return x.Equals(y); }
 public CatalogObjectNode(IResource resource, IResourceKey originalKey)
     : base(resource, originalKey)
 {
 }
 public CASPresetXmlNode(IResource resource, IResourceKey originalKey)
     : base(resource, originalKey)
 {
 }
 public override bool SetRK(IResourceKey oldKey, IResourceKey newKey)
 {
     RKElem elem;
     bool success = false;
     for (int i = 0; i < this.oldToNewRKs.Count; i++)
     {
         elem = this.oldToNewRKs[i];
         if (elem.OldResourceKey.Equals(oldKey))
         {
             elem.NewResourceKey = new RK(newKey);
             success = true;
         }
     }
     return success;
 }
Beispiel #54
0
 public int GetHashCode(IResourceKey obj) { return obj.GetHashCode(); }
Beispiel #55
0
 public bool Equals(IResourceKey other) { return CompareTo(other) == 0; }
 MemoryStream HexEdit(IResourceKey key, IResource res)
 {
     return s4pi.Helpers.HelperManager.Edit(key, res,
         S4PIDemoFE.Properties.Settings.Default.HexEditorCmd,
         S4PIDemoFE.Properties.Settings.Default.HexEditorWantsQuotes,
         S4PIDemoFE.Properties.Settings.Default.HexEditorIgnoreTS);
 }
 public virtual void CreateKindredRK(IResourceKey parentKey,
     IResourceKey newParentKey, ref IResourceKey kindredKey)
 {
     kindredKey.Instance = newParentKey.Instance;
 }
Beispiel #58
0
        private IResourceIndexEntry NewResource(IResourceKey rk, MemoryStream ms, DuplicateHandling dups, bool compress)
        {
            IResourceIndexEntry rie = CurrentPackage.Find(x => rk.Equals(x));
            if (rie != null)
            {
                if (dups == DuplicateHandling.reject) return null;
                if (dups == DuplicateHandling.replace) CurrentPackage.DeleteResource(rie);
            }

            rie = CurrentPackage.AddResource(rk, ms, false);//we do NOT want to search again...
            if (rie == null) return null;

            rie.Compressed = (ushort)(compress ? 0x5A42 : 0);

            IsPackageDirty = true;

            return rie;
        }
 public AResourceNode(IResource resource, IResourceKey originalKey)
 {
     this.resource = resource;
 }
Beispiel #60
0
        /// <summary>
        /// Add a resource to the package
        /// </summary>
        /// <param name="rk">The resource key</param>
        /// <param name="stream">The stream that contains the resource data</param>
        /// <param name="rejectDups">If true, fail if the resource key already exists</param>
        /// <returns>Null if rejectDups and the resource key exists; else the new IResourceIndexEntry</returns>
        public override IResourceIndexEntry AddResource(IResourceKey rk, Stream stream, bool rejectDups)
        {
            if (rejectDups && Index[rk] != null && !Index[rk].IsDeleted) return null;
            IResourceIndexEntry newrc = Index.Add(rk);
            if (stream != null) (newrc as ResourceIndexEntry).ResourceStream = stream;

            return newrc;
        }