Exemplo n.º 1
0
 public NameMap(List<PathPackageTuple> nameMapPPTs)
 {
     namemaps = new List<IDictionary<ulong, string>>();
     if (nameMapPPTs == null) return;
     foreach (var sr in nameMapPPTs.SelectMany(ppt => ppt.FindAll(rie => rie.ResourceType == 0x0166038C)))
     {
         IDictionary<ulong, string> nmp = sr.Resource as IDictionary<ulong, string>;
         if (nmp == null) continue;
         if (latest == null) latest = sr;
         namemaps.Add(nmp);
     }
 }
Exemplo n.º 2
0
 public override List<IResourceKinHelper> CreateKinHelpers(object constraints)
 {
     List<IResourceKinHelper> results = new List<IResourceKinHelper>();
     if (wantThumbs && base.originalKey.ResourceType != MDLR_TID)
     {
         SpecificResource sr = new SpecificResource(FileTable.GameContent, base.originalKey);
         for (int i = 0; i < 3; i++)
         {
             results.Add(new ThumbnailKinFinder(base.originalKey, base.resource,
                 NeededThumbnailSizes[i]));
         }
     }
     return results;
 }
Exemplo n.º 3
0
 public SaveList(MainForm mainForm, SpecificResource selectedItem, Dictionary<string, IResourceKey> rkList,
     PathPackageTuple target, bool compress, bool addSTBLs, bool padSTBLs, bool zeroSTBLIID, bool excludeCommonResources,
         MainForm.updateProgressCallback updateProgressCB, StopSavingCallback stopSavingCB, SaveListComplete savingCompleteCB)
 {
     this.mainForm = mainForm;
     this.selectedItem = selectedItem;
     this.rkList = rkList;
     this.target = target;
     this.compress = compress;
     this.addSTBLs = addSTBLs;
     this.padSTBLs = padSTBLs;
     this.zeroSTBLIID = zeroSTBLIID;
     this.excludeCommonResources = excludeCommonResources;
     this.updateProgressCB = updateProgressCB;
     this.stopSavingCB = stopSavingCB;
     this.savingCompleteCB = savingCompleteCB;
 }
Exemplo n.º 4
0
 private List<IResourceConnection> Item_findObjds()
 {
     Diagnostics.Log("Item_findObjds");
     List<IResourceConnection> results = new List<IResourceConnection>();
     TGIBlockList ltgi = (TGIBlockList)base.Resource["TGIBlocks"].Value;
     TGIBlock tgi;
     StringBuilder builder = new StringBuilder();
     bool addOBJD;
     int missing = 0;
     for (int i = 0; i < ltgi.Count; i++)
     {
         tgi = ltgi[i];
         if (tgi.ResourceType != OBJD_TID) continue;
         addOBJD = true;
         if (preTestResources)
         {
             SpecificResource objd = new SpecificResource(FileTable.GameContent, tgi);
             if (objd.Resource != null)
             {
                 Diagnostics.Log(String.Format("Item_findObjds: Found {0}", objd.LongName));
             }
             else
             {
                 builder.AppendFormat("OBJD {0}\n", tgi);
                 missing++;
                 addOBJD = false;
             }
             if (addOBJD)
             {
                 results.Add(new DefaultConnection(tgi, tgi, ResourceDataActions.FindWrite,
                     "root.TGIBlocks[" + i + "]"));
             }
         }
     }
     if (preTestResources && missing > 0)
     {
         Diagnostics.Show(builder.ToString(),
             String.Format("Item {0} has {1} missing OBJDs:", base.originalKey, missing));
     }
     return results;
 }
Exemplo n.º 5
0
 public static Image getLargestThumbOrDefault(SpecificResource item)
 {
     Image img = getImage(THUMSize.large, item);
     if (img != null) return img;
     img = getImage(THUMSize.medium, item);
     if (img != null) return img;
     img = getImage(THUMSize.small, item);
     if (img != null) return img;
     return defaultThumbnail;
 }
Exemplo n.º 6
0
        void AddSTBL(IDictionary <ulong, string> outstbl, ulong guid, SpecificResource oldStbl, SpecificResource fbStbl)
        {
            if (oldStbl == null && !padSTBLs)
            {
                return;
            }
            if (outstbl.ContainsKey(guid))
            {
                return;
            }

            if (oldStbl == null)
            {
                oldStbl = fbStbl;
            }
            IDictionary <ulong, string> oldDict = oldStbl != null ? oldStbl.Resource as IDictionary <ulong, string> : null;
            string name = oldDict != null && oldDict.ContainsKey(guid) ? oldDict[guid] : "";

            outstbl.Add(guid, name);
        }
 private static void FindAllBrushPairs()
 {
     List<PathPackageTuple> ppts = FileTable.GameContent;
     PathPackageTuple ppt;
     int i, j;
     for (i = 0; i < ppts.Count; i++)
     {
         ppt = ppts[i];
         List<IResourceIndexEntry> lrs = ppt.Package.FindAll(IsCTPT);
         for (j = 0; j < lrs.Count; j++)
         {
             SpecificResource sr = new SpecificResource(ppt, lrs[j]);
             if (sr.Resource != null)
             {
                 byte status = (byte)sr.Resource["CommonBlock.BuildBuyProductStatusFlags"].Value;
                 if ((status & 0x01) == 0) // do not list
                 {
                     UInt64 brushIndex = (UInt64)sr.Resource["CommonBlock.NameGUID"].Value;
                     if (!CTPTBrushIndexToPair.ContainsKey(brushIndex))//Try to leave one behind...
                     {
                         CTPTBrushIndexToPair.Add(brushIndex, sr);
                         return;
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 8
0
 bool MatchResourceName(SpecificResource item) { return nameMap != null && nameMap.ContainsKey(item.RequestedRK.Instance) && nameMap[item.RequestedRK.Instance].Trim().ToLowerInvariant().Contains(criteria.text); }
Exemplo n.º 9
0
 bool MatchCatalogDesc(SpecificResource item) { return MatchStbl((ulong)item.Resource["CommonBlock.DescGUID"].Value); }
Exemplo n.º 10
0
 public bool HasGUID(SpecificResource sr)
 {
     var stbl = sr.Resource as IDictionary<ulong, string>;
     if (stbl == null) return false;
     return stbl.ContainsKey(guid);
 }
Exemplo n.º 11
0
            public void Search()
            {
                bool complete = false;
                bool abort = false;
                List<ulong> lres = new List<ulong>();
                List<string> errors = new List<string>();
                try
                {
                    updateProgress(true, "Searching...", true, FileTable.GameContent.Count + 1, true, 1);
                    for (int p = 0; p < FileTable.GameContent.Count; p++)
                    {
                        if (stopSearch) return;
                        PathPackageTuple ppt = FileTable.GameContent[p];

                        if (criteria.text.Length > 0)
                        {
                            #region Fetch name map
                            if (criteria.resourceName)
                            {
                                updateProgress(true, String.Format("Retrieving name map for package {0} of {1}...", p + 1, FileTable.GameContent.Count), false, -1, false, -1);
                                SpecificResource sr = ppt.Find(rie => rie.ResourceType == 0x0166038C);//NMAP
                                nameMap = sr == null ? null : sr.Resource as IDictionary<ulong, string>;
                                if (stopSearch) return;
                            }
                            #endregion

                            #region Fetch STBLs
                            if (criteria.catalogType != CatalogType.CAS_Part)
                                if (criteria.catalogName || criteria.catalogDesc)
                                {
                                    updateProgress(true, String.Format("Retrieving string tables for package {0} of {1}...", p + 1, FileTable.GameContent.Count), true, -1, false, 0);
                                    stbls = new List<IDictionary<ulong, string>>();
                                    foreach (var rk in ppt.Package.FindAll(rie => rie.ResourceType == 0x220557DA //STBL
                                        && (criteria.allLanguages || rie.Instance >> 56 == 0x00)))
                                    {
                                        if (stopSearch) return;
                                        SpecificResource sr = new SpecificResource(ppt, rk);
                                        var stbl = sr.Resource as IDictionary<ulong, string>;
                                        if (stbl == null) continue;
                                        stbls.Add(stbl);
                                    }
                                }
                            #endregion
                        }

                        // Find the right type of resource to search and apply matching
                        updateProgress(true, String.Format("Searching package {0} of {1}...", p + 1, FileTable.GameContent.Count), false, -1, false, -1);
                        foreach (var match in Find(ppt).Where(sr => stopSearch || (!lres.Contains(sr.RequestedRK.Instance) && (criteria.text.Length == 0 || Match(sr, errors)))))
                        {
                            if (stopSearch) return;
                            lres.Add(match.RequestedRK.Instance);
                            Add(match);
                        }

                        updateProgress(false, "", false, -1, true, p + 2);
                    }
                    complete = true;
                }
                catch (ThreadAbortException) { abort = true; }
                finally
                {
                    if (!abort)
                    {
                        updateProgress(true, "Search ended", true, -1, false, 0);
                        searchComplete(complete, errors);
                    }
                }
            }
Exemplo n.º 12
0
 public static IResourceKey getNewRK(THUMSize size, SpecificResource item)
 {
     if (item.RequestedRK.CType() == CatalogType.ModularResource)
     {
         return RK.NULL;
     }
     else if (item.RequestedRK.CType() == CatalogType.CAS_Part)
     {
         return getNewRK(item.RequestedRK.ResourceType, item.RequestedRK.Instance, size, false);
     }
     else
     {
         ulong png = (item.Resource != null) ? (ulong)item.Resource["CommonBlock.PngInstance"].Value : 0;
         return getNewRK(item.RequestedRK.ResourceType, png != 0 ? png : item.RequestedRK.Instance, size, png != 0);
     }
 }
Exemplo n.º 13
0
 private IResourceConnection OBJD_getOBJK()
 {
     Diagnostics.Log("OBJD_getOBJK");
     uint index = (uint)base.Resource["OBJKIndex"].Value;
     IList<TGIBlock> ltgi = (IList<TGIBlock>)base.Resource["TGIBlocks"].Value;
     TGIBlock objkTGI = ltgi[(int)index];
     if (preTestResources)
     {
         SpecificResource objkItem = new SpecificResource(FileTable.GameContent, objkTGI);
         if (objkItem == null || objkItem.ResourceIndexEntry == null)
         {
             Diagnostics.Show(String.Format("OBJK {0} -> OBJK {1}: not found\n", base.originalKey, objkTGI),
                 "Missing OBJK");
             return null;
         }
         else
         {
             Diagnostics.Log(String.Format("OBJD_getOBJK: Found {0}", objkItem.LongName));
         }
     }
     return new DefaultConnection(objkTGI, objkTGI, ResourceDataActions.FindWrite,
         "objd.TGIBlocks[" + (int)index + "]");
 }
Exemplo n.º 14
0
            public void Search()
            {
                bool          complete = false;
                bool          abort    = false;
                List <ulong>  lres     = new List <ulong>();
                List <string> errors   = new List <string>();

                try
                {
                    updateProgress(true, "Searching...", true, FileTable.GameContent.Count + 1, true, 1);
                    for (int p = 0; p < FileTable.GameContent.Count; p++)
                    {
                        if (stopSearch)
                        {
                            return;
                        }
                        PathPackageTuple ppt = FileTable.GameContent[p];

                        if (criteria.text.Length > 0)
                        {
                            #region Fetch name map
                            if (criteria.resourceName)
                            {
                                updateProgress(true, String.Format("Retrieving name map for package {0} of {1}...", p + 1, FileTable.GameContent.Count), false, -1, false, -1);
                                SpecificResource sr = ppt.Find(rie => rie.ResourceType == 0x0166038C);//NMAP
                                nameMap = sr == null ? null : sr.Resource as IDictionary <ulong, string>;
                                if (stopSearch)
                                {
                                    return;
                                }
                            }
                            #endregion

                            #region Fetch STBLs
                            if (criteria.catalogType != CatalogType.CAS_Part)
                            {
                                if (criteria.catalogName || criteria.catalogDesc)
                                {
                                    updateProgress(true, String.Format("Retrieving string tables for package {0} of {1}...", p + 1, FileTable.GameContent.Count), true, -1, false, 0);
                                    stbls = new List <IDictionary <ulong, string> >();
                                    foreach (var rk in ppt.Package.FindAll(rie => rie.ResourceType == 0x220557DA && //STBL
                                                                           (criteria.allLanguages || rie.Instance >> 56 == 0x00)))
                                    {
                                        if (stopSearch)
                                        {
                                            return;
                                        }
                                        SpecificResource sr = new SpecificResource(ppt, rk);
                                        var stbl            = sr.Resource as IDictionary <ulong, string>;
                                        if (stbl == null)
                                        {
                                            continue;
                                        }
                                        stbls.Add(stbl);
                                    }
                                }
                            }
                            #endregion
                        }

                        // Find the right type of resource to search and apply matching
                        updateProgress(true, String.Format("Searching package {0} of {1}...", p + 1, FileTable.GameContent.Count), false, -1, false, -1);
                        foreach (var match in Find(ppt).Where(sr => stopSearch || (!lres.Contains(sr.RequestedRK.Instance) && (criteria.text.Length == 0 || Match(sr, errors)))))
                        {
                            if (stopSearch)
                            {
                                return;
                            }
                            lres.Add(match.RequestedRK.Instance);
                            Add(match);
                        }

                        updateProgress(false, "", false, -1, true, p + 2);
                    }
                    complete = true;
                }
                catch (ThreadAbortException) { abort = true; }
                finally
                {
                    if (!abort)
                    {
                        updateProgress(true, "Search ended", true, -1, false, 0);
                        searchComplete(complete, errors);
                    }
                }
            }
Exemplo n.º 15
0
        public static SpecificResource ItemForTGIBlock0(SpecificResource item)
        {
            IResourceKey rk = ((TGIBlockList)item.Resource["TGIBlocks"].Value)[0];

            return(new SpecificResource(FileTable.GameContent, rk));
        }
Exemplo n.º 16
0
        //Type: 0x00B2D882 resources are in Fullbuild2, everything else is in Fullbuild0, except thumbs
        //FullBuild0 is:
        //  ...\Gamedata\Shared\Packages\FullBuild0.package
        //Relative path to ALLThumbnails is:
        // .\..\..\..\Thumbnails\ALLThumbnails.package
        public void SavePackage()
        {
            bool complete = false;

            updateProgress(true, "Please wait...", false, -1, false, -1);

            NameMap fb0nm = new NameMap(FileTable.GameContent);
            NameMap ddsnm = new NameMap(FileTable.DDSImages);

            SpecificResource newnmap = target.Find(rie => rie.ResourceType == 0x0166038C);

            if (newnmap == null)
            {
                newnmap = target.AddResource(fb0nm.rk == RK.NULL ? new TGIBlock(0, null, 0x0166038C, 0, selectedItem.RequestedRK.Instance) : fb0nm.rk);
            }
            IDictionary <ulong, string> newnamemap = (IDictionary <ulong, string>)newnmap.Resource;

            #region Skip everything we already have or don't want and de-duplicate
            Dictionary <string, IResourceKey> wrkList = new Dictionary <string, IResourceKey>();
            List <ulong> missingNameMapEntries        = new List <ulong>();
            foreach (var kvp in rkList)
            {
                if (target.Find(rie => rie.Equals(kvp.Value)) != null || (excludeCommonResources && Exclusions.Contains(kvp.Value)))
                {
                    if (!newnamemap.ContainsKey(kvp.Value.Instance) && !missingNameMapEntries.Contains(kvp.Value.Instance))
                    {
                        missingNameMapEntries.Add(kvp.Value.Instance);
                    }
                    Diagnostics.Log(String.Format(target.Find(rie => rie.Equals(kvp.Value)) != null ? "{1} ({0}) already exists" : "{0} ({1}) is excluded", kvp.Key, kvp.Value));
                    continue;
                }
                wrkList.Add(kvp.Key, kvp.Value);
            }
            rkList  = wrkList;
            wrkList = new Dictionary <string, IResourceKey>();
            List <IResourceKey> seen = new List <IResourceKey>();
            foreach (var kvp in rkList)
            {
                if (seen.Contains(kvp.Value))
                {
                    Diagnostics.Log(String.Format("Duplicate RK for {1} ({0})", kvp.Key, kvp.Value));
                    continue;
                }
                wrkList.Add(kvp.Key, kvp.Value);
                seen.Add(kvp.Value);
            }
            rkList = wrkList;
            #endregion

            #region Repair the name map with stuff we won't do later
            updateProgress(true, "Adding missing name map entries...", false, -1, false, -1);
            foreach (ulong key in missingNameMapEntries)
            {
                if (fb0nm.map.ContainsKey(key))
                {
                    newnamemap.Add(key, fb0nm.map[key]);
                }
                else if (ddsnm.map.ContainsKey(key))
                {
                    newnamemap.Add(key, ddsnm.map[key]);
                }
            }
            #endregion

            try
            {
                #region Update target package with required resources
                int i    = 0;
                int freq = Math.Max(1, rkList.Count / 50);
                updateProgress(true, "Seeking resources... 0%", true, rkList.Count, true, i);
                string lastSaved = "nothing yet";

                foreach (var kvp in rkList)
                {
                    List <PathPackageTuple> lppt =
                        (selectedItem.RequestedRK.ResourceType != 0x04ED4BB2 && kvp.Value.ResourceType == 0x00B2D882) ? FileTable.DDSImages
                        : kvp.Key.EndsWith("Thumb") ? FileTable.Thumbnails
                        : FileTable.GameContent;
                    NameMap nm = kvp.Value.ResourceType == 0x00B2D882 ? ddsnm : fb0nm;

                    if (stopSaving)
                    {
                        return;
                    }
                    SpecificResource item = new SpecificResource(lppt, kvp.Value, true); // use default wrapper

                    if (item.ResourceIndexEntry != null)
                    {
                        if (stopSaving)
                        {
                            return;
                        }
                        target.AddResource(item.ResourceIndexEntry, item.Resource.Stream);
                        Diagnostics.Log(String.Format("Added {0} ({1})", kvp.Key, item.LongName));
                        lastSaved = kvp.Key;

                        if (!newnamemap.ContainsKey(kvp.Value.Instance))
                        {
                            string name = nm[kvp.Value.Instance];
                            if (name != null)
                            {
                                if (stopSaving)
                                {
                                    return;
                                }
                                newnamemap.Add(kvp.Value.Instance, name);
                                Diagnostics.Log(String.Format("Added 0x{0:X16} -> \"{1}\" to name map", kvp.Value.Instance, name));
                            }
                        }
                    }
                    else
                    {
                        Diagnostics.Log(String.Format("Failed to find {0}", kvp.Key));
                    }

                    if (++i % freq == 0)
                    {
                        updateProgress(true, "Added " + lastSaved + "... " + i * 100 / rkList.Count + "%", true, rkList.Count, true, i);
                    }
                }
                updateProgress(true, "", true, rkList.Count, true, rkList.Count);
                #endregion

                if (stopSaving)
                {
                    return;
                }
                if (addSTBLs)
                {
                    AddSTBLs(newnamemap);
                }

                if (stopSaving)
                {
                    return;
                }
                updateProgress(true, "Committing new name map... ", true, 0, true, 0);
                newnmap.Commit();
                Diagnostics.Log("Committed new name map...");

                if (stopSaving)
                {
                    return;
                }
                updateProgress(true, "Compressing... ", true, 0, true, 0);
                target.Package.GetResourceList.ForEach(rie => rie.Compressed = (ushort)(compress ? 0xffff : 0x0000));
                updateProgress(true, "", true, 0, true, 0);

                complete = true;
            }
            catch (ThreadAbortException) { }
            finally
            {
                savingComplete(complete);
            }
        }
Exemplo n.º 17
0
 void Add(SpecificResource res) { Thread.Sleep(0); if (control.IsHandleCreated) control.Invoke(addCB, new object[] { res, }); }
Exemplo n.º 18
0
        void Add(SpecificResource res)
        {
            if (!this.IsHandleCreated || this.IsDisposed) return;

            string name = NameMap.NMap[res.ResourceIndexEntry.Instance];
            if (name == null) name = "";

            List<string> exts;
            string tag = "";
            if (s3pi.Extensions.ExtList.Ext.TryGetValue("0x" + res.ResourceIndexEntry.ResourceType.ToString("X8"), out exts)) tag = exts[0];
            else tag = "UNKN";

            listView1.Items.Add(new ListViewItem(new string[] {
                name, tag, res.RGVsn, "" + (AResourceKey)res.ResourceIndexEntry, res.PathPackage.Path + " (" + res.PPSource + ")",
            }) { Tag = res, });
        }
Exemplo n.º 19
0
 private List<IResourceConnection> Catlg_getVPXYs()
 {
     Diagnostics.Log("Catlg_getVPXYs");
     string rootName = this.GetContentPathRootName();
     List<IResourceConnection> results = new List<IResourceConnection>();
     TGIBlockList ltgi = (TGIBlockList)base.Resource["TGIBlocks"].Value;
     TGIBlock tgi;
     StringBuilder builder = new StringBuilder();
     bool addVPXY;
     int i, found = 0;
     for (i = 0; i < ltgi.Count; i++)
     {
         tgi = ltgi[i];
         if (tgi.ResourceType != VisualProxyNode.VPXY_TID) continue;
         addVPXY = true;
         if (preTestResources)
         {
             SpecificResource vpxy = new SpecificResource(FileTable.GameContent, tgi);
             if (vpxy.Resource == null)
             {
                 builder.AppendFormat("Catalog Resource {0} -> RK {1}: not found\n", base.originalKey, tgi);
                 addVPXY = false;
             }
         }
         if (addVPXY)
         {
             results.Add(new DefaultConnection(tgi, tgi, ResourceDataActions.FindWrite,
                 rootName + ".TGIBlocks[" + i + "]"));
             found++;
         }
     }
     if (preTestResources)
         Diagnostics.Show(builder.ToString(), "Missing VPXYs");
     if (found == 0)
     {
         Diagnostics.Show(String.Format("Catalog Resource {0} has no VPXY items", base.originalKey), "No VPXY items");
         return null;
     }
     return results;
 }
Exemplo n.º 20
0
 public static Image getImage(THUMSize size, SpecificResource item)
 {
     if (item.RequestedRK.CType() == CatalogType.ModularResource)
     {
         return getImage(size, MainForm.ItemForTGIBlock0(item));
     }
     else if (item.RequestedRK.CType() == CatalogType.CAS_Part)
     {
         return Thumb[item.RequestedRK.ResourceType, item.RequestedRK.Instance, size, false];
     }
     else
     {
         ulong png = (item.Resource != null) ? (ulong)item.Resource["CommonBlock.PngInstance"].Value : 0;
         return Thumb[item.RequestedRK.ResourceType, png != 0 ? png : item.RequestedRK.Instance, size, png != 0];
     }
 }
Exemplo n.º 21
0
 void Add(SpecificResource item)
 {
     if (!this.IsHandleCreated || this.IsDisposed) return;
     listViewAddCB(item, listView1);
 }
Exemplo n.º 22
0
        void AddSTBL(IDictionary<ulong, string> outstbl, ulong guid, SpecificResource oldStbl, SpecificResource fbStbl)
        {
            if (oldStbl == null && !padSTBLs) return;
            if (outstbl.ContainsKey(guid)) return;

            if (oldStbl == null) oldStbl = fbStbl;
            IDictionary<ulong, string> oldDict = oldStbl != null ? oldStbl.Resource as IDictionary<ulong, string> : null;
            string name = oldDict != null && oldDict.ContainsKey(guid) ? oldDict[guid] : "";

            outstbl.Add(guid, name);
        }
Exemplo n.º 23
0
            bool Match(SpecificResource match, List<string> errors)
            {
                match = match.ResourceIndexEntry.ResourceType == (uint)CatalogType.ModularResource ? MainForm.ItemForTGIBlock0(match) : match;
                if (criteria.resourceName && MatchResourceName(match)) return true;

                if (criteria.catalogType == CatalogType.CAS_Part || match.RequestedRK.ResourceType == (uint)CatalogType.CAS_Part) return false;

                if ((criteria.objectName || criteria.objectDesc || criteria.catalogName || criteria.catalogDesc) && match.Resource == null)
                {
                    errors.Add(match.LongName + ": " + (match.Exception != null ?
                        (match.Exception.InnerException != null ? match.Exception.InnerException.Message : match.Exception.Message) :
                        "unknown error"));
                    return false;
                }

                if (criteria.objectName && MatchObjectName(match)) return true;
                if (criteria.objectDesc && MatchObjectDesc(match)) return true;
                if (criteria.catalogName && MatchCatalogName(match)) return true;
                if (criteria.catalogDesc && MatchCatalogDesc(match)) return true;
                return false;
            }
Exemplo n.º 24
0
        //Type: 0x00B2D882 resources are in Fullbuild2, everything else is in Fullbuild0, except thumbs
        //FullBuild0 is:
        //  ...\Gamedata\Shared\Packages\FullBuild0.package
        //Relative path to ALLThumbnails is:
        // .\..\..\..\Thumbnails\ALLThumbnails.package
        public void SavePackage()
        {
            bool complete = false;

            updateProgress(true, "Please wait...", false, -1, false, -1);

            NameMap fb0nm = new NameMap(FileTable.GameContent);
            NameMap ddsnm = new NameMap(FileTable.DDSImages);

            SpecificResource newnmap = target.Find(rie => rie.ResourceType == 0x0166038C);
            if (newnmap == null)
                newnmap = target.AddResource(fb0nm.rk == RK.NULL ? new TGIBlock(0, null, 0x0166038C, 0, selectedItem.RequestedRK.Instance) : fb0nm.rk);
            IDictionary<ulong, string> newnamemap = (IDictionary<ulong, string>)newnmap.Resource;

            #region Skip everything we already have or don't want and de-duplicate
            Dictionary<string, IResourceKey> wrkList = new Dictionary<string, IResourceKey>();
            List<ulong> missingNameMapEntries = new List<ulong>();
            foreach (var kvp in rkList)
            {
                if (target.Find(rie => rie.Equals(kvp.Value)) != null || (excludeCommonResources && Exclusions.Contains(kvp.Value)))
                {
                    if (!newnamemap.ContainsKey(kvp.Value.Instance) && !missingNameMapEntries.Contains(kvp.Value.Instance)) missingNameMapEntries.Add(kvp.Value.Instance);
                    Diagnostics.Log(String.Format(target.Find(rie => rie.Equals(kvp.Value)) != null ? "{1} ({0}) already exists" : "{0} ({1}) is excluded", kvp.Key, kvp.Value));
                    continue;
                }
                wrkList.Add(kvp.Key, kvp.Value);
            }
            rkList = wrkList;
            wrkList = new Dictionary<string, IResourceKey>();
            List<IResourceKey> seen = new List<IResourceKey>();
            foreach (var kvp in rkList)
            {
                if (seen.Contains(kvp.Value))
                {
                    Diagnostics.Log(String.Format("Duplicate RK for {1} ({0})", kvp.Key, kvp.Value));
                    continue;
                }
                wrkList.Add(kvp.Key, kvp.Value);
                seen.Add(kvp.Value);
            }
            rkList = wrkList;
            #endregion

            #region Repair the name map with stuff we won't do later
            updateProgress(true, "Adding missing name map entries...", false, -1, false, -1);
            foreach (ulong key in missingNameMapEntries)
            {
                if (fb0nm.map.ContainsKey(key))
                    newnamemap.Add(key, fb0nm.map[key]);
                else if (ddsnm.map.ContainsKey(key))
                    newnamemap.Add(key, ddsnm.map[key]);
            }
            #endregion

            try
            {
                #region Update target package with required resources
                int i = 0;
                int freq = Math.Max(1, rkList.Count / 50);
                updateProgress(true, "Seeking resources... 0%", true, rkList.Count, true, i);
                string lastSaved = "nothing yet";

                foreach (var kvp in rkList)
                {
                    List<PathPackageTuple> lppt =
                        (selectedItem.RequestedRK.ResourceType != 0x04ED4BB2 && kvp.Value.ResourceType == 0x00B2D882) ? FileTable.DDSImages
                        : kvp.Key.EndsWith("Thumb") ? FileTable.Thumbnails
                        : FileTable.GameContent;
                    NameMap nm = kvp.Value.ResourceType == 0x00B2D882 ? ddsnm : fb0nm;

                    if (stopSaving) return;
                    SpecificResource item = new SpecificResource(lppt, kvp.Value, true); // use default wrapper

                    if (item.ResourceIndexEntry != null)
                    {
                        if (stopSaving) return;
                        target.AddResource(item.ResourceIndexEntry, item.Resource.Stream);
                        Diagnostics.Log(String.Format("Added {0} ({1})", kvp.Key, item.LongName));
                        lastSaved = kvp.Key;

                        if (!newnamemap.ContainsKey(kvp.Value.Instance))
                        {
                            string name = nm[kvp.Value.Instance];
                            if (name != null)
                            {
                                if (stopSaving) return;
                                newnamemap.Add(kvp.Value.Instance, name);
                                Diagnostics.Log(String.Format("Added 0x{0:X16} -> \"{1}\" to name map", kvp.Value.Instance, name));
                            }
                        }
                    }
                    else
                        Diagnostics.Log(String.Format("Failed to find {0}", kvp.Key));

                    if (++i % freq == 0)
                        updateProgress(true, "Added " + lastSaved + "... " + i * 100 / rkList.Count + "%", true, rkList.Count, true, i);
                }
                updateProgress(true, "", true, rkList.Count, true, rkList.Count);
                #endregion

                if (stopSaving) return;
                if (addSTBLs)
                    AddSTBLs(newnamemap);

                if (stopSaving) return;
                updateProgress(true, "Committing new name map... ", true, 0, true, 0);
                newnmap.Commit();
                Diagnostics.Log("Committed new name map...");

                if (stopSaving) return;
                updateProgress(true, "Compressing... ", true, 0, true, 0);
                target.Package.GetResourceList.ForEach(rie => rie.Compressed = (ushort)(compress ? 0xffff : 0x0000));
                updateProgress(true, "", true, 0, true, 0);

                complete = true;
            }
            catch (ThreadAbortException) { }
            finally
            {
                savingComplete(complete);
            }
        }
Exemplo n.º 25
0
 bool MatchObjectDesc(SpecificResource item) { return ((string)item.Resource["CommonBlock.Desc"].Value).Trim().ToLowerInvariant().Contains(criteria.text); }
Exemplo n.º 26
0
 public CTPTConnection(SpecificResource brush)
     : base(brush.ResourceIndexEntry, "CatalogTerrainPaintBrush.CommonBlock.NameGUID", 
     ResourceDataActions.Write)
 {
     this.brushPairCounterPart = brush;
 }
Exemplo n.º 27
0
 void Add(SpecificResource sr) { Thread.Sleep(0); if (control.IsHandleCreated && !control.IsDisposed) control.Invoke(addCB, new object[] { sr, }); }
Exemplo n.º 28
0
        void AddSTBLs(IDictionary <ulong, string> newnamemap)
        {
            #region Determine whether anything should be done
            SpecificResource catlgItem = selectedItem.RequestedRK.CType() == CatalogType.ModularResource
                ? MainForm.ItemForTGIBlock0(selectedItem)
                : selectedItem;

            if (catlgItem.ResourceIndexEntry == null)
            {
                Diagnostics.Log("Modular Resource but could not find OBJD zero.");
                updateProgress(true, "Modular Resource but could not find OBJD zero.", true, 0, false, 0);
                return;
            }

            ulong nameGUID = (ulong)catlgItem.Resource["CommonBlock.NameGUID"].Value;
            ulong descGUID = (ulong)catlgItem.Resource["CommonBlock.DescGUID"].Value;

            if (nameGUID == STBLHandler.FNV64Blank && descGUID == STBLHandler.FNV64Blank)
            {
                Diagnostics.Log(String.Format("Both Name (0x{0:X16}) and Desc (0x{1:X16}) GUIDs are FNV64Blank.", nameGUID, descGUID));
                updateProgress(true, "Both Name and Desc GUIDs are FNV64Blank.", true, 0, false, 0);
                return;
            }

            Diagnostics.Log("Finding string tables...");
            updateProgress(true, "Finding string tables...", true, 0, true, 0);

            SpecificResource nameStbl = STBLHandler.findStblFor(nameGUID);
            SpecificResource descStbl = STBLHandler.findStblFor(descGUID);

            if (nameStbl == null && descStbl == null)
            {
                Diagnostics.Log(String.Format("Neither Name (0x{0:X16}) nor Desc (0x{1:X16}) GUID found.", nameGUID, descGUID));
                updateProgress(true, "No string tables found!", true, 0, false, 0);
                return;
            }

            /*
             * Decided to leave this to the code in the loop below
             * if ((nameStbl != null && nameStbl.PathPackage == target) && (descStbl != null && descStbl.PathPackage == target) && !padSTBLs)
             * {
             *  Diagnostics.Log(String.Format("Both Name (0x{0:X16}) and Desc (0x{1:X16}) exist in {2} and not padding.", nameGUID, descGUID, target.Path));
             *  updateProgress(true, "Both Name and Desc GUIDs already present.", true, 0, false, 0);
             *  return;
             * }/**/
            #endregion

            IResourceKey oldRK        = (nameStbl != null ? nameStbl : descStbl).RequestedRK;
            uint         stblGroup    = oldRK.ResourceGroup;
            ulong        stblInstance = oldRK.Instance & (ulong)(zeroSTBLIID ? 0x00FFFFFFFFFF0000 : 0x00FFFFFFFFFFFFFF);

            byte lang = 0;
            int  freq = 1;// Math.Max(1, lrie.Count / 10);
            Diagnostics.Log("Creating string tables extracts...");
            updateProgress(true, "Creating string tables extracts... 0%", true, 0x17, true, lang);

            while (lang < 0x17)
            {
                if (stopSaving)
                {
                    return;
                }
                try
                {
                    STBLHandler.AddSTBLToNameMap(newnamemap, lang, ((ulong)lang << 56) | stblInstance);

                    SpecificResource oldName = STBLHandler.findStblFor(nameGUID, (byte)lang);
                    SpecificResource oldDesc = STBLHandler.findStblFor(descGUID, (byte)lang);

                    // Nothing to copy from and not padding
                    if (oldName == null && oldDesc == null && !padSTBLs)
                    {
                        continue;
                    }
                    // *Both* found in target for this language
                    if ((oldName != null && oldName.PathPackage == target) && (oldDesc != null && oldDesc.PathPackage == target))
                    {
                        continue;
                    }

                    IResourceKey     newRK   = new TGIBlock(0, null, 0x220557DA, stblGroup, ((ulong)lang << 56) | stblInstance);
                    SpecificResource newstbl = target.Find(rie => rie.Equals(newRK));
                    if (newstbl == null)
                    {
                        newstbl = target.AddResource(newRK);
                    }
                    IDictionary <ulong, string> outstbl = newstbl.Resource as IDictionary <ulong, string>;

                    AddSTBL(outstbl, nameGUID, oldName, nameStbl);
                    AddSTBL(outstbl, descGUID, oldDesc, descStbl);

                    if (stopSaving)
                    {
                        return;
                    }
                    newstbl.Commit();
                }
                finally
                {
                    if (++lang % freq == 0)
                    {
                        updateProgress(true, "Creating string tables extracts... " + lang * 100 / 0x17 + "%", true, 0x17, true, lang);
                    }
                }
            }
        }