Ejemplo n.º 1
0
        public JazzGraphContainer(int index,
                                  StateMachine sm, Control view, TabPage page)
        {
            this.Index     = index;
            this.mName     = sm.Name;
            this.UndoRedo  = new UndoManager();
            this.SaveState = JazzSaveState.Dirty;
            this.Key       = new RK(GlobalManager.kJazzTID, 0,
                                    FNVHash.HashString64(this.mName));
            this.Comp = true;
            this.JP   = null;
            this.RIE  = null;

            this.Scene = new StateMachineScene(sm, view, this);
            KKLayoutAlgorithm <StateNode, StateEdge> layout
                = new KKLayoutAlgorithm <StateNode, StateEdge>(
                      this.Scene.StateGraph, this.Scene);

            layout.LengthFactor = 1.25f;
            this.Scene.Layout   = layout;
            layout.ShuffleNodes();
            this.Scene.LayoutPaused = true;
            this.Scene.StartLayout();

            this.mPage = page;
            this.mPage.Controls.Add(view);
            this.mPage.Text         = this.mName + " *";
            this.mPage.SizeChanged +=
                new EventHandler(this.OnTabSizeChanged);
        }
Ejemplo n.º 2
0
        protected virtual void Set(IResourceIndexEntry entry, IPackage package)
        {
            mEntry = entry;
            mPackage = package;

            mType = (ResourceType)mEntry.ResourceType;

            if (mEntry != null)
            {
                // NameColumn
                NameMapResource.NameMapResource nameMap = MainForm.CreateKeyResource(package) as NameMapResource.NameMapResource;
                if ((nameMap != null) && (nameMap.ContainsKey(mEntry.Instance)))
                {
                    Text = nameMap[mEntry.Instance];
                }

                // TagColumn
                SubItems.Add(Type.ToString());

                // Instance
                mInstance = SubItems.Add(Instance);

                // Filename
                mFilename = SubItems.Add("");
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Tell the package to delete the resource indexed by <paramref name="rc"/>
 /// </summary>
 /// <param name="rc">Target resource index</param>
 public override void DeleteResource(IResourceIndexEntry rc)
 {
     if (!rc.IsDeleted)
     {
         (rc as ResourceIndexEntry).Delete();
     }
 }
Ejemplo n.º 4
0
        public JazzGraphContainer(int index, string name, Control view)
        {
            this.Index     = index;
            this.mName     = name ?? "";
            this.UndoRedo  = new UndoManager();
            this.SaveState = JazzSaveState.Dirty;
            ulong iid = 0;

            if (!this.mName.StartsWith("0x") ||
                !ulong.TryParse(this.mName.Substring(2),
                                System.Globalization.NumberStyles.HexNumber,
                                null, out iid))
            {
                iid = FNVHash.HashString64(this.mName);
            }
            this.Key  = new RK(GlobalManager.kJazzTID, 0, iid);
            this.Comp = true;
            this.JP   = null;
            this.RIE  = null;

            StateMachine sm = new StateMachine(name);

            this.Scene = new StateMachineScene(sm, view, this);
            KKLayoutAlgorithm <StateNode, StateEdge> layout
                = new KKLayoutAlgorithm <StateNode, StateEdge>(
                      this.Scene.StateGraph, this.Scene);

            layout.LengthFactor = 1.25f;
            this.Scene.Layout   = layout;
            layout.ShuffleNodes();
            this.Scene.LayoutPaused = true;
            this.Scene.StartLayout();
        }
Ejemplo n.º 5
0
 void Add(IResourceIndexEntry rie)
 {
     Thread.Sleep(0); if (form.IsHandleCreated)
     {
         form.Invoke(addCB, new object[] { rie, });
     }
 }
Ejemplo n.º 6
0
        protected virtual void Set(IResourceIndexEntry entry, IPackage package)
        {
            mEntry   = entry;
            mPackage = package;

            mType = (ResourceType)mEntry.ResourceType;

            if (mEntry != null)
            {
                // NameColumn
                NameMapResource.NameMapResource nameMap = MainForm.CreateKeyResource(package) as NameMapResource.NameMapResource;
                if ((nameMap != null) && (nameMap.ContainsKey(mEntry.Instance)))
                {
                    Text = nameMap[mEntry.Instance];
                }

                // TagColumn
                SubItems.Add(Type.ToString());

                // Instance
                mInstance = SubItems.Add(Instance);

                // Filename
                mFilename = SubItems.Add("");
            }
        }
Ejemplo n.º 7
0
        private void BrowserWidget_ResourceIndexEntryChanged(object sender, EventArgs e)
        {
            IResourceIndexEntry rie = sender as IResourceIndexEntry;

            if (rie == null)
            {
                return;
            }

            if (lookup == null)
            {
                return;
            }
            if (!lookup.ContainsKey(rie))
            {
                (rie as AResourceIndexEntry).ResourceIndexEntryChanged -= new EventHandler(BrowserWidget_ResourceIndexEntryChanged); return;
            }

            ListViewItem lvi    = lookup[rie];
            ListViewItem newlvi = CreateItem(rie);

            listView1.SuspendLayout();
            lvi.SubItems.Clear(); for (int i = 1; i < newlvi.SubItems.Count; i++)
            {
                lvi.SubItems.Add(newlvi.SubItems[i]);
            }
            lvi.Font = newlvi.Font;
            lvi.Text = newlvi.Text;
            listView1.ResumeLayout();
        }
Ejemplo n.º 8
0
        ListViewItem CreateItem(IResourceIndexEntry ie)
        {
            ListViewItem lvi = new ListViewItem();

            if (ie.IsDeleted)
            {
                lvi.Font = new Font(lvi.Font, lvi.Font.Style | FontStyle.Strikeout);
            }
            for (int j = 0; j < fields.Count + 1; j++)
            {
                if (j == 0)
                {
                    lvi.Text = ResourceName(ie);
                }
                else if (j == 1)
                {
                    lvi.SubItems.Add(ResourceTag(ie));
                }
                else
                {
                    lvi.SubItems.Add(ie[fields[j - 2]] + "");
                }
            }
            lvi.Tag = ie;
            (ie as AResourceIndexEntry).ResourceIndexEntryChanged -= new EventHandler(BrowserWidget_ResourceIndexEntryChanged);
            (ie as AResourceIndexEntry).ResourceIndexEntryChanged += new EventHandler(BrowserWidget_ResourceIndexEntryChanged);
            return(lvi);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        static bool FlagMatch(uint flags, IResourceIndexEntry values, IResourceIndexEntry target)
        {
            if (flags == 0)
            {
                return(true);
            }

            for (int i = 0; i < sizeof(uint); i++)
            {
                uint j = (uint)(1 << i);
                if ((flags & j) == 0)
                {
                    continue;
                }
                string f = values.ContentFields[i];
                if (!target.ContentFields.Contains(f))
                {
                    return(false);
                }
                if (!values[f].Equals(target[f]))
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 11
0
 public void Add(IResourceIndexEntry rie, bool select = true)
 {
     AddRange(new[] { rie, });
     if (select)
     {
         SelectedResource = rie;
     }
 }
Ejemplo n.º 12
0
        public Save(string strPath)
        {
            nhdPath = strPath;
            Package             package = (Package)Package.OpenPackage(Path.Combine(Path.GetDirectoryName(strPath), "Meta.data"));
            IResourceIndexEntry rie     = package.Find(r => r.ResourceType == 1653241999U);

            UnParse(S3PI.WrapperDealer.GetResource(package, rie).Stream);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Initialise a new helpers list for a given resource
        /// </summary>
        /// <param name="key">The resource index entry</param>
        /// <param name="res">The resource</param>
        /// <param name="resname">(Optional) The resource name</param>
        public HelperManager(IResourceIndexEntry key, IResource res, string resname = null)
        {
            if (helpers == null)
            {
                ReadConfig();
            }

            if (res == null || key == null)
            {
                return;
            }

            string wrapper = res.GetType().Name.ToLower();

            foreach (string cfg in helpers.Keys)
            {
                Dictionary <string, string> match = null;

                foreach (string kwd in helpers[cfg].Keys)
                {
                    if (kwd.Equals("wrapper"))
                    {
                        if ((new List <string>(helpers[cfg]["wrapper"].Split(' '))).Contains("*"))
                        {
                            match = helpers[cfg]; goto matched;
                        }
                        if ((new List <string>(helpers[cfg]["wrapper"].ToLower().Split(' '))).Contains(wrapper))
                        {
                            match = helpers[cfg]; goto matched;
                        }
                        continue;
                    }

                    if (reserved.Contains(kwd))
                    {
                        continue;
                    }

                    if (keywords.Contains(kwd))
                    {
                        if ((new List <string>(helpers[cfg][kwd].Split(' '))).Contains("" + key[kwd]))
                        {
                            match = helpers[cfg]; goto matched;
                        }
                        if ((new List <string>(helpers[cfg][kwd].Split(' '))).Contains("*"))
                        {
                            match = helpers[cfg]; goto matched;
                        }
                        continue;
                    }
                }
matched:
                if (match != null)
                {
                    this.Add(new Helper(match, new s3pi.Extensions.TGIN(key, resname), res));
                }
            }
        }
Ejemplo n.º 14
0
 bool IEquatable <IResourceIndexEntry> .Equals(
     IResourceIndexEntry other)
 {
     if (this.RIE == null)
     {
         return(false);
     }
     return(this.RIE.Equals(other));
 }
Ejemplo n.º 15
0
        public JazzGraphContainer(int index, JazzPackage jp,
                                  IResourceIndexEntry rie, Control view, TabPage page)
        {
            this.Index     = index;
            this.UndoRedo  = new UndoManager();
            this.SaveState = JazzSaveState.Saved;
            this.Key       = new RK(rie);
            this.Comp      = rie.Compressed == 0xFFFF;
            this.JP        = jp;
            this.RIE       = rie;
            IResource           res  = null;
            GenericRCOLResource rcol = null;

            try
            {
                res = WrapperDealer.GetResource(0, jp.Package, rie);
            }
            catch (Exception ex)
            {
                MainForm.ShowException(ex,
                                       "Could not load JAZZ resource: " + this.Key + "\n",
                                       MainForm.kName + ": Unable to load JAZZ resource");
            }
            if (res != null)
            {
                rcol = res as GenericRCOLResource;
                if (rcol != null)
                {
                    this.Scene = new StateMachineScene(
                        new StateMachine(rcol), view, this);
                    KKLayoutAlgorithm <StateNode, StateEdge> layout
                        = new KKLayoutAlgorithm <StateNode, StateEdge>(
                              this.Scene.StateGraph, this.Scene);
                    layout.LengthFactor = 1.25f;
                    this.Scene.Layout   = layout;
                    layout.ShuffleNodes();
                    this.Scene.LayoutPaused = true;
                    this.Scene.StartLayout();
                }
                else
                {
                    this.Scene = null;
                }
            }
            if (!KeyNameReg.TryFindName(rie.Instance, out this.mName))
            {
                this.mName = "0x" + rie.Instance.ToString("X16");
            }
            if (this.Scene != null)
            {
                this.mPage = page;
                this.mPage.Controls.Add(view);
                this.mPage.Text         = this.mName;
                this.mPage.SizeChanged +=
                    new EventHandler(this.OnTabSizeChanged);
            }
        }
Ejemplo n.º 16
0
        public Resource FindResource(Predicate <IResourceKey> Match)
        {
            IResourceIndexEntry rie = _package.Find(Match);

            if (rie == null)
            {
                return(default(Resource));
            }
            return(GetResource(rie));
        }
Ejemplo n.º 17
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));
        }
Ejemplo n.º 18
0
        protected static Dictionary <ulong, STBLImporter.Lookup> ReadTable(string prefix, string instance, IPackage package, bool addOtherKeys)
        {
            instance = prefix + instance.Substring(4);

            Dictionary <ulong, STBLImporter.Lookup> lookup = new Dictionary <ulong, STBLImporter.Lookup>();

            IResourceIndexEntry entry = package.Find(key => ((key.ResourceType == (uint)ResourceType.STBL) && (key["Instance"] == instance)));

            if (entry != null)
            {
                StblResource.StblResource resource = ResourceHandlers.CreateResource(entry, package) as StblResource.StblResource;

                foreach (KeyValuePair <ulong, string> element in resource)
                {
                    bool space = false;

                    string keyValue = element.Value;
                    if (prefix == "0x17")
                    {
                        if (keyValue.StartsWith("PackerSpace|"))
                        {
                            keyValue = keyValue.Replace("PackerSpace|", "");
                            space    = true;
                        }
                    }

                    if (!lookup.ContainsKey(element.Key))
                    {
                        STBLImporter.Lookup recent = new STBLImporter.Lookup(keyValue, keyValue, space);
                        lookup.Add(element.Key, recent);
                    }

                    if ((addOtherKeys) && (!HasSuffix(keyValue)))
                    {
                        foreach (string suffix in sSuffixes)
                        {
                            string value = keyValue + suffix;

                            ulong key = FNV64.GetHash(value);

                            if (lookup.ContainsKey(key))
                            {
                                continue;
                            }

                            STBLImporter.Lookup recent = new STBLImporter.Lookup(value, value, space);
                            lookup.Add(key, recent);
                        }
                    }
                }
            }

            return(lookup);
        }
Ejemplo n.º 19
0
 static bool NameMatch(string[] names, TypedValue[] values, IResourceIndexEntry target)
 {
     for (int i = 0; i < names.Length; i++)
     {
         if (!target.ContentFields.Contains(names[i]) || !values[i].Equals(target[names[i]]))
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 20
0
        public Resource GetResource(IResourceIndexEntry rie)
        {
            IResource res = WrapperDealer.GetResource(0, _package, rie);

            if (res != null)
            {
                res.ResourceChanged += new EventHandler(OnResourceChanged);
            }
            return(new Resource {
                IResourceIndexEntry = rie, IResource = res
            });
        }
Ejemplo n.º 21
0
        public Resource GetResource(uint resourceType, uint resourceGroup, ulong instance)
        {
            IResourceIndexEntry rie = _package.Find(x =>
                                                    x.ResourceType == resourceType && x.ResourceGroup == resourceGroup && x.Instance == instance);

            if (rie == null)
            {
                return(default(Resource));
            }

            return(GetResource(rie));
        }
Ejemplo n.º 22
0
        public static IResource CreateKeyResource(IPackage package)
        {
            IResourceIndexEntry key = package.Find(value => value.ResourceType == (uint)ResourceType._KEY);

            if (key == null)
            {
                return(null);
            }
            else
            {
                return(ResourceHandlers.CreateResource(key, package));
            }
        }
Ejemplo n.º 23
0
        public static void AddFiles(IPackage package, List <string> sourceFilePaths)
        {
            List <TGIN> addedResourceKeys = new List <TGIN>();

            for (int sourceFilePathIndex = 0; sourceFilePathIndex < sourceFilePaths.Count; sourceFilePathIndex++)
            {
                string sourceInfoFilePath = sourceFilePaths[sourceFilePathIndex] + "." + SourceInfoFileExtension;

                TGIN targetResourceKeyTGIN = Path.GetFileName(sourceFilePaths[sourceFilePathIndex]);

                if (File.Exists(sourceInfoFilePath))
                {
                    try {
                        SourceInfo sourceInfo = (SourceInfo)Tools.ReadXML <SourceInfo>(sourceInfoFilePath);
                        targetResourceKeyTGIN = sourceInfo.ToTGIN();
                    } catch (Exception e) {
                        Console.Error.Write("Failed to read source info file.\n" + sourceInfoFilePath + "\n" + e.ToString());
                    }
                }

                AResourceKey targetResourceKey = targetResourceKeyTGIN;

                MemoryStream sourceStream       = new MemoryStream();
                BinaryWriter sourceStreamWriter = new BinaryWriter(sourceStream);

                using (BinaryReader sourceFileReader = new BinaryReader(new FileStream(sourceFilePaths[sourceFilePathIndex], FileMode.Open, FileAccess.Read))) {
                    sourceStreamWriter.Write(sourceFileReader.ReadBytes((int)sourceFileReader.BaseStream.Length));
                    sourceStreamWriter.Flush();
                }

                IResourceIndexEntry targetPreviousEntry = package.Find(targetResourceKey.Equals);

                while (targetPreviousEntry != null)
                {
                    package.DeleteResource(targetPreviousEntry);
                    targetPreviousEntry = package.Find(targetResourceKey.Equals);
                }

                IResourceIndexEntry targetEntry = package.AddResource(targetResourceKey, sourceStream, false);

                if (targetEntry == null)
                {
                    continue;
                }

                targetEntry.Compressed = 23106;
                addedResourceKeys.Add(targetResourceKeyTGIN);
            }

            GenerateNameMap(package, addedResourceKeys, null);
        }
Ejemplo n.º 24
0
        public string ResourceTag(IResourceIndexEntry rie)
        {
            string key = rie["ResourceType"];

            if (s4pi.Extensions.ExtList.Ext.ContainsKey(key))
            {
                return(s4pi.Extensions.ExtList.Ext[key][0]);
            }
            if (s4pi.Extensions.ExtList.Ext.ContainsKey("*"))
            {
                return(s4pi.Extensions.ExtList.Ext["*"][0]);
            }
            return("");
        }
Ejemplo n.º 25
0
        void importStream(myDataFormat data, bool useName, bool rename, bool compress, DuplicateHandling dups, bool select)
        {
            if (useName && data.tgin.ResName != null && data.tgin.ResName.Length > 0)
            {
                browserWidget1.ResourceName(data.tgin.ResInstance, data.tgin.ResName, true, rename);
            }

            IResourceIndexEntry rie = NewResource((TGIBlock)data.tgin, new MemoryStream(data.data), dups, compress);

            if (rie != null)
            {
                browserWidget1.Add(rie, select);
            }
        }
Ejemplo n.º 26
0
        public static ListItem CreateHandler(IResourceIndexEntry entry, IPackage package)
        {
            ResourceType type = (ResourceType)entry.ResourceType;

            ListItem item;

            if (Handlers.TryGetValue(type, out item))
            {
                item = item.Clone() as ListItem;
                item.Set(entry, package);
                return(item);
            }

            return(null);
        }
Ejemplo n.º 27
0
        void Add(IResourceIndexEntry rie)
        {
            XmlElement key = CreateElement("reskey", string.Format("1:{0:x8}:{1:x8}:{2:x16}", rie.ResourceType, rie.ResourceGroup, rie.Instance));

            KeyList.AppendChild(key);
            if (icons.Contains(rie.ResourceType))
            {
                NumOfThumbs.InnerText = "" + ++numofthumbs;
                Document.DocumentElement.AppendChild(CreateElement("thumbnail", string.Format("{0:x8}:{1:x8}:{2:x16}", rie.ResourceType, rie.ResourceGroup, rie.Instance)));
            }
            if (catlgResTypes.Contains(rie.ResourceType))
            {
                numofCatlgResources++;
            }
        }
Ejemplo n.º 28
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);
        }
Ejemplo n.º 29
0
 public bool IsKindred(IResourceIndexEntry rie)
 {
     if (this.KinHelper.IsKindred(this.ParentKey, rie))
     {
         RK rk = new RK(rie);
         for (int i = 0; i < this.Seen.Count; i++)
         {
             if (rk.Equals(this.Seen[i]))
             {
                 return(false);
             }
         }
         return(true);
     }
     return(false);
 }
Ejemplo n.º 30
0
        public static IResource CreateResource(IResourceIndexEntry entry, IPackage package)
        {
            Type t = GetHandler(entry["ResourceType"]);
            if (t == null) return null;

            APackage localPackage = package as APackage;

            try
            {
                return t.GetConstructor(new Type[] { typeof(int), typeof(Stream), }).Invoke(new object[] { 0, localPackage.GetResource(entry) }) as IResource;
            }
            catch
            { }

            return null;
        }
Ejemplo n.º 31
0
        private void UnParse(Stream s)
        {
            BinaryReader binaryReader = new BinaryReader(s);

            binaryReader.ReadInt32();
            StringBuilder stringBuilder = new StringBuilder();

            int num1 = checked (binaryReader.ReadInt32() - 1);
            int num2 = 0;

            while (num2 <= num1)
            {
                short num3 = binaryReader.ReadInt16();
                stringBuilder.Append((char)num3);
                checked { ++num2; }
            }

            stringBuilder.Append(' ');
            int num4 = checked (binaryReader.ReadInt32() - 1);
            int num5 = 0;

            while (num5 <= num4)
            {
                short num3 = binaryReader.ReadInt16();
                stringBuilder.Append((char)num3);
                checked { ++num5; }
            }

            WorldName = stringBuilder.ToString();
            binaryReader.ReadInt32();

            IPackage pkg = Package.OpenPackage(nhdPath);

            ImgInstance = binaryReader.ReadUInt64();
            IResourceIndexEntry rie = pkg.Find(entry => (long)entry.Instance == (long)ImgInstance & entry.ResourceType == 1802339198U);

            if (rie != null)
            {
                FamilyIcon = new Bitmap(S3PI.WrapperDealer.GetResource(pkg, rie).Stream);
            }
            else
            {
                FamilyIcon = App.GetResource <DrawingImage>("UnknownIcon");
            }

            binaryReader.ReadUInt64();
        }
Ejemplo n.º 32
0
 public string ResourceName(IResourceIndexEntry rie)
 {
     if (!displayResourceNames)
     {
         return("");
     }
     if (nameMap == null)
     {
         return("");
     }
     foreach (IDictionary <ulong, string> nmap in nameMap)
     {
         if (nmap.ContainsKey(rie.Instance))
         {
             return(nmap[rie.Instance]);
         }
     }
     return("");
 }
Ejemplo n.º 33
0
 public abstract List<IResourceIndexEntry> FindAll(uint flags, IResourceIndexEntry values);
Ejemplo n.º 34
0
 public TextImporter(IResourceIndexEntry entry)
     : base (entry)
 { }
Ejemplo n.º 35
0
 public GoEventArgs(IResourceIndexEntry rie) { this.rie = rie; }
Ejemplo n.º 36
0
 private static bool IsSTBL(IResourceIndexEntry rie)
 {
     return rie.ResourceType == STBL_TID;
 }
Ejemplo n.º 37
0
        static bool FlagMatch(uint flags, IResourceIndexEntry values, IResourceIndexEntry target)
        {
            if (flags == 0) return true;

            for (int i = 0; i < sizeof(uint); i++)
            {
                uint j = (uint)(1 << i);
                if ((flags & j) == 0) continue;
                string f = values.ContentFields[i];
                if (!target.ContentFields.Contains(f)) return false;
                if (!values[f].Equals(target[f])) return false;
            }
            return true;
        }
Ejemplo n.º 38
0
        // Required by API, not user tools

        /// <summary>
        /// Required internally by s3pi - <b>not</b> for use in user tools.
        /// Please use <c>WrapperDealer.GetResource(int, IPackage, IResourceIndexEntry)</c> instead.
        /// </summary>
        /// <param name="rie">IResourceIndexEntry of resource</param>
        /// <returns>The resource data (uncompressed, if necessary)</returns>
        /// <remarks>Used by WrapperDealer to get the data for a resource.</remarks>
        public abstract Stream GetResource(IResourceIndexEntry rie);
Ejemplo n.º 39
0
 public IMAGImporter(IResourceIndexEntry entry)
     : base (entry)
 { }
Ejemplo n.º 40
0
 private static bool IsEffectResource(IResourceIndexEntry entry)
 {
     return entry.ResourceType == kEffectTID;
 }
Ejemplo n.º 41
0
 /// <summary>
 /// Tell the package to replace the data for the resource indexed by <paramref name="rc"/>
 /// with the data from the resource <paramref name="res"/>
 /// </summary>
 /// <param name="rc">Target resource index</param>
 /// <param name="res">Source resource</param>
 public override void ReplaceResource(IResourceIndexEntry rc, IResource res) { (rc as ResourceIndexEntry).ResourceStream = res.Stream; }
Ejemplo n.º 42
0
        // Required by API, not user tools

        /// <summary>
        /// Required internally by s3pi - <b>not</b> for use in user tools.
        /// Please use <c>WrapperDealer.GetResource(int, IPackage, IResourceIndexEntry)</c> instead.
        /// </summary>
        /// <param name="rc">IResourceIndexEntry of resource</param>
        /// <returns>The resource data (uncompressed, if necessary)</returns>
        /// <remarks>Used by WrapperDealer to get the data for a resource.</remarks>
        public override Stream GetResource(IResourceIndexEntry rc)
        {
            ResourceIndexEntry rie = rc as ResourceIndexEntry;
            if (rie == null) return null;
            if (rie.ResourceStream != null) return rie.ResourceStream;

            if (rc.Chunkoffset == 0xffffffff) return null;
            packageStream.Position = rc.Chunkoffset;

            byte[] data = null;
            if (rc.Filesize == 1 && rc.Memsize == 0xFFFFFFFF) return null;//{ data = new byte[0]; }
            else if (rc.Filesize == rc.Memsize)
            {
                data = (new BinaryReader(packageStream)).ReadBytes((int)rc.Filesize);
            }
            else
            {
                data = Compression.UncompressStream(packageStream, (int)rc.Filesize, (int)rc.Memsize);
            }

            MemoryStream ms = new MemoryStream();
            ms.Write(data, 0, data.Length);
            ms.Position = 0;
            return ms;
        }
Ejemplo n.º 43
0
 /// <summary>
 /// Tell the package to delete the resource indexed by <paramref name="rc"/>
 /// </summary>
 /// <param name="rc">Target resource index</param>
 public override void DeleteResource(IResourceIndexEntry rc)
 {
     if (!rc.IsDeleted)
         (rc as ResourceIndexEntry).Delete();
 }
Ejemplo n.º 44
0
 void Add(IResourceIndexEntry rie)
 {
     lbxHits.Items.Add(fromRIE(rie));
     lrie.Add(rie);
 }
Ejemplo n.º 45
0
 bool search(IResourceIndexEntry rie)
 {
     IResource res = s4pi.WrapperDealer.WrapperDealer.GetResource(0, pkg, rie, true);// we're searching bytes
     byte[] resBytes = res.AsBytes;
     for (int i = 0; i < resBytes.Length - pattern.Length; i++)
     {
         for (int j = 0; j < pattern.Length; j++)
             if (resBytes[i + j] != pattern[j]) goto fail;
         return true;
     fail: { }
     }
     return false;
 }
Ejemplo n.º 46
0
 void Add(IResourceIndexEntry rie) { Thread.Sleep(0); if (form.IsHandleCreated) form.Invoke(addCB, new object[] { rie, }); }
Ejemplo n.º 47
0
 /// <summary>
 /// Tell the package to replace the data for the resource indexed by <paramref name="rc"/>
 /// with the data from the resource <paramref name="res"/>
 /// </summary>
 /// <param name="rc">Target resource index</param>
 /// <param name="res">Source resource</param>
 public abstract void ReplaceResource(IResourceIndexEntry rc, IResource res);
Ejemplo n.º 48
0
 public static bool IsNameMap(IResourceIndexEntry rie)
 {
     return rie.ResourceType == NameMapTID;
 }
Ejemplo n.º 49
0
 /// <summary>
 /// Tell the package to delete the resource indexed by <paramref name="rc"/>
 /// </summary>
 /// <param name="rc">Target resource index</param>
 public abstract void DeleteResource(IResourceIndexEntry rc);
Ejemplo n.º 50
0
 public override List<IResourceIndexEntry> FindAll(uint flags, IResourceIndexEntry values) { return Index.FindAll(x => !x.IsDeleted && FlagMatch(flags, values, x)); }
Ejemplo n.º 51
0
 public S3SAImporter(IResourceIndexEntry entry)
     : base (entry)
 { }
Ejemplo n.º 52
0
 static bool NameMatch(string[] names, TypedValue[] values, IResourceIndexEntry target)
 {
     for (int i = 0; i < names.Length; i++) if (!target.ContentFields.Contains(names[i]) || !values[i].Equals(target[names[i]])) return false;
     return true;
 }
Ejemplo n.º 53
0
 public STBLExporter(IResourceIndexEntry entry)
     : base (entry)
 { }
Ejemplo n.º 54
0
 private void exportFile(IResourceIndexEntry rie, string filename)
 {
     IResource res = s4pi.WrapperDealer.WrapperDealer.GetResource(0, CurrentPackage, rie, true);//Don't need wrapper
     Stream s = res.Stream;
     s.Position = 0;
     if (s.Length != rie.Memsize) CopyableMessageBox.Show(String.Format("Resource stream has {0} bytes; index entry says {1}.", s.Length, rie.Memsize));
     BinaryWriter w = new BinaryWriter(new FileStream(filename, FileMode.Create));
     w.Write((new BinaryReader(s)).ReadBytes((int)s.Length));
     w.Close();
 }
Ejemplo n.º 55
0
 /// <summary>
 /// Indicates whether the current <see cref="IResourceIndexEntry"/> instance is equal to another <see cref="IResourceIndexEntry"/> instance.
 /// </summary>
 /// <param name="other">An <see cref="IResourceIndexEntry"/> instance to compare with this instance.</param>
 /// <returns>true if the current instance is equal to the <paramref name="other"/> parameter; otherwise, false.</returns>
 public abstract bool Equals(IResourceIndexEntry other);
Ejemplo n.º 56
0
        private void exportResourceToPackage(IPackage tgtpkg, IResourceIndexEntry srcrie, bool replace)
        {
            IResourceIndexEntry rie = tgtpkg.Find(x => ((IResourceKey)srcrie).Equals(x));
            if (rie != null)
            {
                if (!replace) return;
                tgtpkg.DeleteResource(rie);
            }

            rie = tgtpkg.AddResource(srcrie, null, true);
            if (rie == null) return;
            rie.Compressed = srcrie.Compressed;

            IResource srcres = s4pi.WrapperDealer.WrapperDealer.GetResource(0, CurrentPackage, srcrie, true);//Don't need wrapper
            tgtpkg.ReplaceResource(rie, srcres);
        }
Ejemplo n.º 57
0
 private static bool IsCTPT(IResourceIndexEntry rie)
 {
     return (CatalogType)rie.ResourceType == CatalogType.CatalogTerrainPaintBrush;
 }
Ejemplo n.º 58
0
 public abstract IResourceIndexEntry Find(uint flags, IResourceIndexEntry values);
Ejemplo n.º 59
0
 public string ResourceTag(IResourceIndexEntry rie)
 {
     string key = rie["ResourceType"];
     if (s4pi.Extensions.ExtList.Ext.ContainsKey(key)) return s4pi.Extensions.ExtList.Ext[key][0];
     if (s4pi.Extensions.ExtList.Ext.ContainsKey("*")) return s4pi.Extensions.ExtList.Ext["*"][0];
     return "";
 }
Ejemplo n.º 60
0
 string fromRIE(IResourceIndexEntry rie) { return (rie as AResourceKey) + ""; }