Exemplo n.º 1
0
 public static void Reset()
 {
     nmap = null;
 }
Exemplo n.º 2
0
 public static void Reset() { nmap = null; }
Exemplo n.º 3
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.º 4
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);
            }
        }