Beispiel #1
0
        private void openPackageFile(string pathToPackageFile)
        {
            imppkg = Package.OpenPackage(0, pathToPackageFile, true);

            lrie = imppkg.FindAll(x =>
            {
                return(x.ResourceType == 0x220557DA);
            });

            SelectSTBLfileinPackage f = new SelectSTBLfileinPackage(lrie, imppkg);

            f.ShowDialog();

            packageElId = BigInteger.Parse(f.selectedElement.Replace("0x", ""), NumberStyles.AllowHexSpecifier);

            var el = lrie.Find(x =>
            {
                return(x.Instance == packageElId);
            });

            res = WrapperDealer.GetResource(0, imppkg, el, true);

            openedFromSTBL_File = false;

            ArrayList tempList = ReadAndAnalyzeStream(res.Stream);

            STBLToDataGridView(tempList);

            pathOpened = true;

            //MessageBox.Show(packageElId.ToString());

            //imppkg.Dispose();
        }
Beispiel #2
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);
            }
        }
Beispiel #3
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
            });
        }
Beispiel #4
0
        public void SaveSTBLObjectInPackage(bool isSaveAs, MainUI mainUI)
        {
            List <uint>   textResourceID = new List <uint>();
            List <string> textString     = new List <string>();

            ArrayList tempList = new ArrayList();

            if (dataGridView1.Rows.Count > 0)
            {
                uint   convert = 0;
                string hexText;

                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    hexText = ((string)dataGridView1.Rows[i].Cells[0].Value).Replace("0x", "");
                    convert = Convert.ToUInt32(hexText, 16);
                    textResourceID.Add(convert);
                    textString.Add(dataGridView1.Rows[i].Cells[1].Value.ToString());
                }
            }

            tempList.Add(textResourceID);
            tempList.Add(textString);

            MainUI.lrie = MainUI.imppkg.FindAll(x =>
            {
                return(x.ResourceType == 0x220557DA);
            });


            var el = MainUI.lrie.Find(x =>
            {
                return(x.Instance == MainUI.packageElId);
            });

            if (el != null)
            {
                var res = WrapperDealer.GetResource(0, imppkg, el, true);
                WriteSTBLStream(tempList, res.Stream);

                MainUI.imppkg.ReplaceResource(el, res);
            }

            filenameLabel.Text = publicPath;
            pathOpened         = true;
        }
Beispiel #5
0
        public void SaveSTBL(bool isSaveAs, bool isFile)
        {
            if (dataGridView1.Rows.Count == 0)
            {
                return;
            }

            ArrayList textResourceID = new ArrayList();
            ArrayList textString     = new ArrayList();

            uint   convert = 0;
            string hexText;

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                hexText = ((string)dataGridView1.Rows[i].Cells[0].Value).Replace("0x", "");
                convert = Convert.ToUInt32(hexText, 16);
                textResourceID.Add(convert);
                textString.Add(dataGridView1.Rows[i].Cells[1].Value);
            }

            ArrayList tempList = new ArrayList();

            tempList.Add(textResourceID);
            tempList.Add(textString);

            if (isFile)
            {
                publicPath = WriteSTBLFile(tempList, isSaveAs, publicPath);
            }
            else
            {
                var el = lrie.Find(x =>
                {
                    return(x.Instance == MainUI.packageElId);
                });

                var res = WrapperDealer.GetResource(0, imppkg, el, true);
                publicPath = WriteSTBLStream(tempList, false, publicPath, res.Stream);
                MainUI.imppkg.ReplaceResource(el, res);
                MainUI.imppkg.SavePackage();
                //MainUI.imppkg.Dispose();
            }
            filenameLabel.Text = publicPath;
            pathOpened         = true;
        }
        public SelectSTBLfileinPackage(List <IResourceIndexEntry> lrieInp, IPackage imppkgInp)
        {
            InitializeComponent();

            this.lrie   = lrieInp;
            this.imppkg = imppkgInp;

            foreach (IResourceIndexEntry rie in lrie)
            {
                IResource res = WrapperDealer.GetResource(0, imppkg, rie, true);

                BigInteger bi = BigInteger.Parse(rie.Instance.ToString());

                String fileName = "0x" + bi.ToString("X");


                listBox1.Items.Add(fileName);
            }
        }
        private void Fill_Details(IPackage p)
        {
            foreach (IResourceIndexEntry r in p.GetResourceList)
            {
                if (flags.Contains(r.ResourceType))
                {
                    CASPartResource.CASPartResource text_file = (CASPartResource.CASPartResource)WrapperDealer.GetResource(1, p, r);

                    string[] flag_array = text_file.ParameterFlags.ToString().Split(',');
                    if (flag_array.Contains <string>("AllowForCASRandom"))
                    {
                        tb_flags.Text = "AllowForCASRandom - True";
                    }
                    else
                    {
                        tb_flags.Text = "AllowForCASRandom - False";
                    }

                    tb_age_gender.Text = text_file.AgeGender.ToString();
                    tb_body_type.Text  = text_file.BodyType.ToString();

                    break;
                }
                else if (types.Contains(r.ResourceType))
                {
                    ObjectDefinitionResource text_file = (ObjectDefinitionResource)WrapperDealer.GetResource(1, p, r);

                    try
                    {
                        tb_flags.Text = text_file.Tuning.ToString();
                    }
                    catch (Exception)
                    {
                        tb_flags.Text = null;
                    }
                    break;
                }

                tb_flags.Text      = null;
                tb_age_gender.Text = null;
                tb_body_type.Text  = null;
            }
        }
Beispiel #8
0
        public NameMap(List <PathPackageTuple> nameMapPPTs)
        {
            this.namemaps = new List <PNMap>();
            if (nameMapPPTs == null)
            {
                return;
            }
            List <IResourceIndexEntry> rieList;
            IResource resource;
            int       i, j;

            for (i = 0; i < nameMapPPTs.Count; i++)
            {
                rieList = nameMapPPTs[i].Package.FindAll(IsNameMap);
                if (rieList == null)
                {
                    continue;
                }
                for (j = 0; j < rieList.Count; j++)
                {
                    resource = null;
                    try
                    {
                        resource = WrapperDealer.GetResource(0, nameMapPPTs[i].Package, rieList[j]);
                    }
                    catch { }
                    if (resource != null)
                    {
                        IDictionary <ulong, string> nmp = resource as IDictionary <ulong, string>;
                        if (nmp == null)
                        {
                            continue;
                        }
                        if (this.latest == null)
                        {
                            this.latest = new SpecificResource(nameMapPPTs[i], rieList[j]);
                        }
                        this.namemaps.Add(new PNMap(nameMapPPTs[i], nmp));
                    }
                }
            }
        }
Beispiel #9
0
        public Resource NewResource(uint resourceType, uint resourceGroup, ulong instance, string name = null)
        {
            IResource res = WrapperDealer.CreateNewResource(0, "0x" + resourceType.ToString("X8"));

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

            IResourceIndexEntry rie = _package.AddResource(new ResourceKey {
                ResourceType = resourceType, ResourceGroup = resourceGroup, Instance = instance
            }, res.Stream, true);

            if (name != null)
            {
                ResourceName(rie.Instance, name);
            }

            return(GetResource(rie));
        }
Beispiel #10
0
        public JazzPackage(string path, IPackage package, bool readOnly)
        {
            this.ReadOnly = readOnly;
            this.Path     = path;
            this.Package  = package;
            this.Title    = MainForm.CreateTitle(path, readOnly);
            this.Graphs   = new List <JazzGraphContainer>();

            this.KNMapRIE = this.Package.Find(sIsNameMap);
            if (this.KNMapRIE == null)
            {
                this.KNMapRes
                              = new NameMapResource.NameMapResource(0, null);
                this.KNMapRIE = this.Package.AddResource(
                    new RK(KeyNameMap.NameMapTID, 0, 0),
                    this.KNMapRes.Stream, true);
            }
            else
            {
                IResource res = null;
                try
                {
                    res = WrapperDealer.GetResource(
                        0, this.Package, this.KNMapRIE);
                }
                catch { }
                if (res != null)
                {
                    this.KNMapRes
                        = res as NameMapResource.NameMapResource;
                }
                if (this.KNMapRes == null)
                {
                    this.KNMapRes
                                  = new NameMapResource.NameMapResource(0, null);
                    this.KNMapRIE = this.Package.AddResource(
                        new RK(KeyNameMap.NameMapTID, 0, 0),
                        this.KNMapRes.Stream, true);
                }
            }
        }
Beispiel #11
0
            public PackagedNMap(IPackage package, bool create)
            {
                if (package == null)
                {
                    throw new ArgumentNullException("package");
                }
                this.package = package;
                IResource nmap;
                List <IResourceIndexEntry> rieList = package.FindAll(IsNameMap);

                if ((rieList == null || rieList.Count == 0) && create)
                {
                    TGIBlock tgi = new TGIBlock(0, null, NameMapTID, 0u, 0ul);
                    nmap = WrapperDealer.CreateNewResource(0, NameMapTIDStr);
                    IResourceIndexEntry rie
                        = package.AddResource(tgi, nmap.Stream, false);
                    this.nmaps.Add(new KeyValuePair <IResourceIndexEntry,
                                                     IResource>(rie, nmap));
                }
                else
                {
                    int i, count = rieList.Count;
                    for (i = 0; i < count; i++)
                    {
                        nmap = null;
                        try
                        {
                            nmap = WrapperDealer.GetResource(0, package, rieList[i]);
                        }
                        catch { }
                        if (nmap != null)
                        {
                            this.nmaps.Add(new KeyValuePair <IResourceIndexEntry,
                                                             IResource>(rieList[i], nmap));
                        }
                    }
                }
            }
Beispiel #12
0
        private void openedStblFileFromPackageToEditor()
        {
            SelectSTBLfileFromPackage f = selectSTBLfileinPackage(false);

            if (f.selectedSTBLObjects.Count() > 0)
            {
                packageElId = BigInteger.Parse(f.selectedSTBLObjects[0].Replace("0x", ""), NumberStyles.AllowHexSpecifier);

                var el = lrie.Find(x =>
                {
                    return(x.Instance == packageElId);
                });

                res = WrapperDealer.GetResource(0, imppkg, el, true);

                openedFromSTBL_File = false;

                ArrayList tempList = ReadAndAnalyzeStream(res.Stream);
                STBLToDataGridView(tempList);

                pathOpened = true;
            }
        }
Beispiel #13
0
        private void Fill_Image_Array(IPackage p)
        {
            thumbnail_bitmaps.Clear();

            foreach (IResourceIndexEntry r in p.GetResourceList)
            {
                if (thumbnails.Contains(r.ResourceType))
                {
                    IResource   image_resource = WrapperDealer.GetResource(1, p, r);
                    BitmapFrame my_image       = BitmapFrame.Create(image_resource.Stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
                    thumbnail_bitmaps.Add(my_image);
                }
            }

            if (thumbnail_bitmaps.Count() == 0)
            {
                thumbnail_bitmaps.Add(BitmapFrame.Create(new Uri("pack://application:,,,/Clear.bmp")));
            }

            img_thumbnail.Source = thumbnail_bitmaps[0];
            num_of_images        = thumbnail_bitmaps.Count();
            now_displayed        = 0;
            img_counter.Content  = now_displayed + 1 + "/" + num_of_images;
        }
Beispiel #14
0
        static void Translate(FileInfo inFile, String outPath, XmlDictionary dict)
        {
            if (!File.Exists(inFile.FullName))
            {
                throw new FileNotFoundException(inFile.FullName);
            }

            String _outFile = outPath + "\\" + inFile.Name;

            if (!Directory.Exists(outPath))
            {
                Directory.CreateDirectory(outPath);
            }

            IPackage _package = Package.OpenPackage(-1, inFile.FullName);

            Byte _targetCode     = 0;
            var  _stblIndexEntry = new List <KeyValuePair <IResourceIndexEntry, IResourceIndexEntry> >();

            {
                List <IResourceIndexEntry> _resourceEntry = _package.GetResourceList;
                var _stblRes = _resourceEntry.Where((o) => { return(o.ResourceType == 0x220557DA); });

                Byte _sourceCode = dict.To == TranslateTo.B ? dict.LanguageA : dict.LanguageB;
                IEnumerable <IResourceIndexEntry> _stblScoure = _stblRes.Where((o) => { return(GetLanguageCode(o.Instance) == _sourceCode); });

                _targetCode = dict.To == TranslateTo.A ? dict.LanguageA : dict.LanguageB;
                IEnumerable <IResourceIndexEntry> _stblTarget = _stblRes.Where((o) => { return(GetLanguageCode(o.Instance) == _targetCode); });

                foreach (var s in _stblScoure)
                {
                    Boolean hasTarget = false;
                    UInt64  _is       = s.Instance << (4 * 2);
                    foreach (var t in _stblTarget)
                    {
                        UInt64 _it = t.Instance << (4 * 2);
                        if (s.ResourceType == t.ResourceType &&
                            s.ResourceGroup == t.ResourceGroup &&
                            _is == _it)
                        {
                            hasTarget = true;
                            _stblIndexEntry.Add(new KeyValuePair <IResourceIndexEntry, IResourceIndexEntry>(s, t));
                            break;
                        }
                    }

                    if (!hasTarget)
                    {
                        _stblIndexEntry.Add(new KeyValuePair <IResourceIndexEntry, IResourceIndexEntry>(s, null));
                    }
                }
            }

            if (_stblIndexEntry.Count() == 0)
            {
                _package.SaveAs(_outFile);
                throw new ApplicationException($"源语言不存在,文件未修改。文件:{_outFile}");
            }
            else
            {
                var _newDict = new XmlDictionary(dict.LanguageA, dict.LanguageB, dict.To);

                Int32 _changedCount = 0;
                foreach (var item in _stblIndexEntry)
                {
                    IResource res = WrapperDealer.GetResource(-1, _package, item.Key, false);

                    Stream             _fs         = res.Stream;
                    List <StringEntry> _stringList = ReadStbl(inFile.Name, _fs, item.Key);

                    foreach (var str in _stringList)
                    {
                        if (dict.TryFind(str.Text, inFile.Name, str.Ident, out String s))
                        {
                            str.Text = s;
                            _changedCount++;
                        }
                        else
                        {
                            Entry _entry = new Entry(str.Text, str.Text, str.Ident, inFile.Name);
                            _newDict.Add(_entry);
                        }
                    }

                    var _ms = new MemoryStream();
                    StringListToStbl(_ms, _stringList);

                    if (item.Value == null)
                    {
                        var _rk = new TranslateResourceIndexEntry();
                        _rk.ResourceGroup = item.Key.ResourceGroup;
                        _rk.ResourceType  = item.Key.ResourceType;
                        _rk.Instance      = item.Key.Instance;
                        _rk.Instance      = _rk.Instance << (4 * 2);
                        _rk.Instance      = _rk.Instance >> (4 * 2);
                        _rk.Instance      = _rk.Instance + ((( UInt64 )_targetCode) << (4 * 14));

                        _package.AddResource(_rk, _ms, true);
                    }
                    else
                    {
                        var _st = new StblResource.StblResource(0, _ms);
                        _package.ReplaceResource(item.Value, _st);
                    }

                    _package.SaveAs(_outFile);
                }

                if (_newDict.Count != 0)
                {
                    throw new EntryNotFoundException(_newDict, _changedCount);
                }
            }
        }
Beispiel #15
0
        private KeyNameMap(List <PathPackageTuple> ppts, string knmName)
        {
            if (ppts == null)
            {
                this.mKNMPackages = null;
                this.mGenCLIPs    = null;
                return;
            }
            KNMPackage knmp;
            IResource  resource;
            IDictionary <ulong, string> map;
            List <IResourceIndexEntry>  rieList;
            List <KNMPackage>           knmps = new List <KNMPackage>();

            foreach (PathPackageTuple ppt in ppts)
            {
                if (ppt != null && ppt.Package != null)
                {
                    if (StatusMessage != null)
                    {
                        StatusMessage("Searching " + knmName +
                                      " Package:\n" + ppt.Path);
                    }
                    rieList = ppt.Package.FindAll(IsNameMapPred);
                    if (rieList != null && rieList.Count > 0)
                    {
                        if (this.mGenCLIPs == null)
                        {
                            this.mGenCLIPs
                                = new Dictionary <ulong, GenCLIP>();
                        }
                        knmp = new KNMPackage(ppt.Path);
                        foreach (IResourceIndexEntry rie in rieList)
                        {
                            resource = null;
                            try
                            {
                                resource = WrapperDealer.GetResource(
                                    0, ppt.Package, rie);
                            }
                            catch { }
                            if (resource != null)
                            {
                                map = resource as IDictionary <ulong, string>;
                                if (map != null && map.Count > 0)
                                {
                                    this.FillKNMP(knmp, map);
                                }
                            }
                        }
                        if (knmp.Names.Count > 0)
                        {
                            knmps.Add(knmp);
                        }
                    }
                }
            }
            if (knmps.Count == 0)
            {
                this.mKNMPackages = null;
            }
            else
            {
                this.mKNMPackages = knmps.ToArray();
            }
        }
Beispiel #16
0
        private void ResourceImportAsDbc()
        {
            if (MainForm.allowList.Count == 0)
            {
                MainForm.allowList.AddRange(MainForm.xmlList);
                MainForm.allowList.AddRange(MainForm.stblList);
                MainForm.allowList.AddRange(MainForm.nmapList);
            }
            try
            {
                this.Enabled = false;
                DialogResult dr = this.importPackagesDialog.ShowDialog();
                if (dr != DialogResult.OK)
                {
                    return;
                }

                AutoSaveState autoSaveState = AutoSaveState.Always;
                if (Properties.Settings.Default.AskDBCAutoSave)
                {
                    autoSaveState = AutoSaveState.Ask;
                }
                this.ImportPackagesCommon(this.importPackagesDialog.FileNames,
                                          this.importPackagesDialog.Title,
                                          DuplicateHandling.Allow,
                                          true,
                                          useNames: true,
                                          dupsList: MainForm.allowList,
                                          autoSaveState: autoSaveState);

                this.browserWidget1.Visible = false;
                this.lbProgress.Text        = @"Doing DBC clean up...";

                Application.DoEvents();
                DateTime now = DateTime.UtcNow;
                IList <IResourceIndexEntry> lrie =
                    this.DupsOnly(this.CurrentPackage.FindAll(x => MainForm.stblList.Contains(x.ResourceType)));
                foreach (IResourceIndexEntry dup in lrie)
                {
                    IList <IResourceIndexEntry> ldups =
                        this.CurrentPackage.FindAll(rie => ((IResourceKey)dup).Equals(rie));
                    IResourceIndexEntry         newRie  = this.NewResource(dup, null, DuplicateHandling.Allow, true);
                    IDictionary <ulong, string> newStbl =
                        (IDictionary <ulong, string>)WrapperDealer.GetResource(0, this.CurrentPackage, newRie);
                    foreach (IResourceIndexEntry rie in ldups)
                    {
                        IDictionary <ulong, string> oldStbl =
                            (IDictionary <ulong, string>)WrapperDealer.GetResource(0, this.CurrentPackage, rie);
                        foreach (var kvp in oldStbl)
                        {
                            if (!newStbl.ContainsKey(kvp.Key))
                            {
                                newStbl.Add(kvp);
                            }
                        }
                        rie.IsDeleted = true;
                        if (now.AddMilliseconds(100) < DateTime.UtcNow)
                        {
                            Application.DoEvents();
                            now = DateTime.UtcNow;
                        }
                    }
                    this.CurrentPackage.ReplaceResource(newRie, (IResource)newStbl);
                    this.browserWidget1.Add(newRie, false);
                }

                // Get rid of Sims3Pack resource that sneak in
                this.CurrentPackage.FindAll(x =>
                {
                    if (now.AddMilliseconds(100) < DateTime.UtcNow)
                    {
                        Application.DoEvents();
                        now = DateTime.UtcNow;
                    }
                    if (MainForm.deleteList.Contains(x.ResourceType))
                    {
                        x.IsDeleted = true;
                        return(false);
                    }
                    return(false);
                });

                // If there are any remaining duplicate XMLs, give up - they're too messy to fix automatically
                if (this.DupsOnly(this.CurrentPackage.FindAll(x => MainForm.xmlList.Contains(x.ResourceType))).Count > 0)
                {
                    CopyableMessageBox.Show("Manual merge of XML files required.");
                }
            }
            finally
            {
                this.browserWidget1.Visible = true;
                this.lbProgress.Text        = "";
                Application.DoEvents();
                this.Enabled = true;
            }
        }
Beispiel #17
0
        private KeyNameS3SA(List <PathPackageTuple> ppts)
        {
            if (ppts == null)
            {
                this.mKNAPackages = null;
                return;
            }
            long len;

            byte[]     data;
            IResource  res;
            KNAPackage knap;
            Assembly   asm;

            ScriptResource.ScriptResource s3sa;
            List <IResourceIndexEntry>    rieList;
            List <KNAPackage>             knaps = new List <KNAPackage>();

            foreach (PathPackageTuple ppt in ppts)
            {
                if (ppt != null && ppt.Package != null)
                {
                    rieList = ppt.Package.FindAll(sIsS3SA);
                    if (rieList != null && rieList.Count > 0)
                    {
                        knap = new KNAPackage(ppt.Path);
                        foreach (IResourceIndexEntry rie in rieList)
                        {
                            res = null;
                            try
                            {
                                res = WrapperDealer.GetResource(
                                    0, ppt.Package, rie);
                            }
                            catch { }
                            if (res != null)
                            {
                                s3sa = res as ScriptResource.ScriptResource;
                                if (s3sa != null)
                                {
                                    len  = s3sa.Assembly.BaseStream.Length;
                                    data = new byte[len];
                                    s3sa.Assembly.BaseStream.Read(
                                        data, 0, (int)len);
                                    asm = Assembly.ReflectionOnlyLoad(data);
                                    if (asm != null)
                                    {
                                        ScanNames(asm, knap);
                                    }
                                }
                            }
                        }
                        if (knap.Names.Count > 0)
                        {
                            knaps.Add(knap);
                        }
                    }
                }
            }
            if (knaps.Count == 0)
            {
                this.mKNAPackages = null;
            }
            else
            {
                this.mKNAPackages = knaps.ToArray();
            }
        }
Beispiel #18
0
        public static void GenerateNameMap(IPackage package, List <TGIN> addedResourceKeys, List <TGIN> removedResourceKeys)
        {
            AResourceKey nameMapKey = new TGIBlock(0, null, 23462796u, 0u, 0uL);

            IResourceIndexEntry nameMapEntry = package.Find(nameMapKey.Equals);

            if (nameMapEntry == null)
            {
                nameMapEntry = package.AddResource(nameMapKey, null, false);
            }

            if (nameMapEntry != null)
            {
                NameMapResource.NameMapResource nameMapResource = (NameMapResource.NameMapResource)WrapperDealer.GetResource(0, package, nameMapEntry);

                if (nameMapResource == null || !typeof(IDictionary <ulong, string>).IsAssignableFrom(nameMapResource.GetType()))
                {
                    package.DeleteResource(nameMapEntry);
                    nameMapEntry    = package.AddResource(nameMapKey, null, false);
                    nameMapResource = (NameMapResource.NameMapResource)WrapperDealer.GetResource(0, package, nameMapEntry);
                }

                if (removedResourceKeys != null)
                {
                    for (int removedResourceKeyIndex = 0; removedResourceKeyIndex < removedResourceKeys.Count; removedResourceKeyIndex++)
                    {
                        if (nameMapResource.Contains(removedResourceKeys[removedResourceKeyIndex].ResInstance))
                        {
                            nameMapResource.Remove(removedResourceKeys[removedResourceKeyIndex].ResInstance);
                        }
                    }
                }

                if (addedResourceKeys != null)
                {
                    for (int addedResourceKeyIndex = 0; addedResourceKeyIndex < addedResourceKeys.Count; addedResourceKeyIndex++)
                    {
                        if (addedResourceKeys[addedResourceKeyIndex].ResName == null)
                        {
                            continue;
                        }

                        if (nameMapResource.Contains(addedResourceKeys[addedResourceKeyIndex].ResInstance))
                        {
                            nameMapResource[addedResourceKeys[addedResourceKeyIndex].ResInstance] = addedResourceKeys[addedResourceKeyIndex].ResName;
                        }
                        else
                        {
                            nameMapResource.Add(addedResourceKeys[addedResourceKeyIndex].ResInstance, addedResourceKeys[addedResourceKeyIndex].ResName);
                        }
                    }
                }

                List <KeyValuePair <ulong, string> > orderedNameMapResource = nameMapResource.ToList();
                orderedNameMapResource.Sort((pair1, pair2) => pair1.Value.CompareTo(pair2.Value));

                nameMapResource.Clear();

                for (int orderedNameMapResourceIndex = 0; orderedNameMapResourceIndex < orderedNameMapResource.Count; orderedNameMapResourceIndex++)
                {
                    nameMapResource.Add(orderedNameMapResource[orderedNameMapResourceIndex].Key, orderedNameMapResource[orderedNameMapResourceIndex].Value);
                }

                package.ReplaceResource(nameMapEntry, nameMapResource);
            }
        }
Beispiel #19
0
        private void packageFilesMassInsertOfCopiedValuesToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (pathOpened)
            {
                saveSTBL();
                closeSTBL();
                SavePackage();
                closePackage();
            }

            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            switch (Thread.CurrentThread.CurrentUICulture.ThreeLetterWindowsLanguageName)
            {
            case "CHS":
            case "ZHI":
                openFileDialog1.Filter      = "STBL文件 (*.package)|*.package|所有文件 (*.*)|*.*";
                openFileDialog1.FilterIndex = 1;
                openFileDialog1.Title       = "选择STBL文件";
                break;

            case "CHT":
            case "ZHH":
            case "ZHM":
                openFileDialog1.Filter      = "STBL檔案 (*.package)|*.package|所有檔案 (*.*)|*.*";
                openFileDialog1.FilterIndex = 1;
                openFileDialog1.Title       = "選取STBL檔案";
                break;

            default:
                openFileDialog1.Filter      = "STBL Files (*.package)|*.package|All Files (*.*)|*.*";
                openFileDialog1.FilterIndex = 1;
                openFileDialog1.Title       = "Choose .package File";
                break;
            }

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                openPackageFile(openFileDialog1.FileName);

                var f = selectSTBLfileinPackage(true);

                openedFromSTBL_File = false;
                foreach (string idStr in f.selectedSTBLObjects)
                {
                    packageElId = BigInteger.Parse(idStr.Replace("0x", ""), NumberStyles.AllowHexSpecifier);

                    var el = lrie.Find(x =>
                    {
                        return(x.Instance == packageElId);
                    });

                    res = WrapperDealer.GetResource(0, imppkg, el, true);
                    ArrayList tempList = ReadAndAnalyzeStream(res.Stream);
                    STBLToDataGridView(tempList);

                    for (int x = 0; x < MainUI.copiedValuesStrHolders.Count; x++)
                    {
                        StringHolder copiedStrElement = MainUI.copiedValuesStrHolders[x];

                        DataTable dt = (DataTable)dataGridView1.DataSource;

                        var drArr = (from rowEl in dt.AsEnumerable()
                                     where rowEl.Field <string>(0) == copiedStrElement.textIDFld
                                     select rowEl);

                        if (drArr.Count() == 0)
                        {
                            DataRow dr = dt.NewRow();
                            dr[0] = copiedStrElement.textIDFld;
                            dr[1] = copiedStrElement.displayTextFld;
                            dt.Rows.Add(dr);
                            dataGridView1.Rows[dataGridView1.Rows.Count - 1].HeaderCell.Value = (dataGridView1.Rows.Count).ToString();
                        }
                        else
                        {
                            DataRow dr = drArr.First();
                            dr[1] = copiedStrElement.displayTextFld;
                        }
                    }

                    dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.RowCount - 1;

                    canAlsoSave   = true;
                    isTextChanged = true;
                    pathOpened    = true;
                    saveSTBL();
                    closeSTBL();
                }
                SavePackage();
                closePackage();
                MessageBox.Show("Done!");
            }
            else
            {
                switch (Thread.CurrentThread.CurrentUICulture.ThreeLetterWindowsLanguageName)
                {
                case "CHS":
                case "ZHI":
                    filenameLabel.Text = "未打开任何文件。";
                    break;

                case "CHT":
                case "ZHH":
                case "ZHM":
                    filenameLabel.Text = "未開啟任何檔案。";
                    break;

                default:
                    filenameLabel.Text = "No file is opened.";
                    break;
                }
                pathOpened = false;
            }
        }
Beispiel #20
0
        private void Sort_mods()
        {
            list_of_mods.Items.Clear();
            thumbnail_bitmaps.Clear();
            string[]      folders   = Directory.GetDirectories(mod_folder_path);
            string[]      mod_names = Directory.GetFiles(mod_folder_path);
            string        current_body_type;
            List <string> new_folders = new List <string>();

            Custom_Message_Box("Please wait, this can take some time. " + mod_names.Length.ToString() + " mods need to be sorted.");

            foreach (string name in mod_names)
            {
                current_body_type = "";
                if (!name.Contains(".package"))
                {
                    continue;
                }
                IPackage now_open      = Package.OpenPackage(0, name);
                string   only_mod_name = Regex.Match(name, regex_pattern).ToString();

                foreach (IResourceIndexEntry r in now_open.GetResourceList)
                {
                    if (flags.Contains(r.ResourceType))
                    {
                        CASPartResource.CASPartResource text_file = (CASPartResource.CASPartResource)WrapperDealer.GetResource(1, now_open, r);

                        current_body_type = text_file.BodyType.ToString();

                        break;
                    }
                    else if (types.Contains(r.ResourceType))
                    {
                        current_body_type = "Objects";

                        break;
                    }
                }

                now_open.Dispose();

                if (folders.Contains(current_body_type) || new_folders.Contains(current_body_type))
                {
                    File.Move(name, mod_folder_path + "\\" + current_body_type + "\\" + only_mod_name + ".package");
                }
                else
                {
                    Directory.CreateDirectory(mod_folder_path + "\\" + current_body_type);
                    new_folders.Add(current_body_type);
                    File.Move(name, mod_folder_path + "\\" + current_body_type + "\\" + only_mod_name + ".package");
                }
            }
            Custom_Message_Box("All mods have been sorted!");
        }
Beispiel #21
0
        private void ImportPackagesCommon(string[] packageList,
                                          string title,
                                          DuplicateHandling dups,
                                          bool compress,
                                          bool useNames                         = false,
                                          bool rename                           = false,
                                          List <uint> dupsList                  = null,
                                          AutoSaveState autoSaveState           = AutoSaveState.Ask,
                                          IList <IResourceIndexEntry> selection = null
                                          )
        {
            bool     cpUseNames = this.controlPanel1.UseNames;
            DateTime now        = DateTime.UtcNow;

            bool autoSave = false;

            if (autoSaveState == AutoSaveState.Ask)
            {
                switch (CopyableMessageBox.Show("Auto-save current package after each package imported?",
                                                title,
                                                CopyableMessageBoxButtons.YesNoCancel,
                                                CopyableMessageBoxIcon.Question))
                {
                case 0:
                    autoSave = true;
                    break;

                case 2:
                    return;
                }
            }
            else
            {
                autoSave = autoSaveState == AutoSaveState.Always;
            }

            try
            {
                this.browserWidget1.Visible = false;
                this.controlPanel1.UseNames = false;

                bool skipAll = false;
                foreach (string filename in packageList)
                {
                    if (!string.IsNullOrEmpty(this.Filename) &&
                        Path.GetFullPath(this.Filename).Equals(Path.GetFullPath(filename)))
                    {
                        CopyableMessageBox.Show("Skipping current package.", this.importPackagesDialog.Title);
                        continue;
                    }

                    this.lbProgress.Text = "Importing " + Path.GetFileNameWithoutExtension(filename) + "...";
                    Application.DoEvents();
                    IPackage imppkg;
                    try
                    {
                        imppkg = Package.OpenPackage(0, filename);
                    }
                    catch (InvalidDataException ex)
                    {
                        if (skipAll)
                        {
                            continue;
                        }
                        int btn =
                            CopyableMessageBox.Show(
                                string.Format("Could not open package {0}.\n{1}", Path.GetFileName(filename), ex.Message),
                                title,
                                CopyableMessageBoxIcon.Error,
                                new List <string>(new[] { "Skip this", "Skip all", "Abort" }),
                                0,
                                0);
                        if (btn == 0)
                        {
                            continue;
                        }
                        if (btn == 1)
                        {
                            skipAll = true;
                            continue;
                        }
                        break;
                    }
                    try
                    {
                        List <Tuple <MyDataFormat, DuplicateHandling> > limp =
                            new List <Tuple <MyDataFormat, DuplicateHandling> >();
                        List <IResourceIndexEntry> lrie = selection == null
                            ? imppkg.GetResourceList
                            : imppkg.FindAll(rie => selection.Any(tgt => ((AResourceKey)tgt).Equals(rie)));
                        this.progressBar1.Value   = 0;
                        this.progressBar1.Maximum = lrie.Count;
                        foreach (IResourceIndexEntry rie in lrie)
                        {
                            try
                            {
                                if (rie.ResourceType == 0x0166038C) //NMAP
                                {
                                    if (useNames)
                                    {
                                        this.browserWidget1.MergeNamemap(
                                            WrapperDealer.GetResource(0, imppkg, rie) as IDictionary <ulong, string>,
                                            true,
                                            rename);
                                    }
                                }
                                else
                                {
                                    IResource res = WrapperDealer.GetResource(0, imppkg, rie, true);

                                    MyDataFormat impres = new MyDataFormat()
                                    {
                                        tgin = rie as AResourceIndexEntry,
                                        data = res.AsBytes
                                    };

                                    // dups Replace | Reject | Allow
                                    // dupsList null | list of allowable dup types
                                    DuplicateHandling dupThis =
                                        dups == DuplicateHandling.Allow
                                            ? dupsList == null || dupsList.Contains(rie.ResourceType)
                                                ? DuplicateHandling.Allow
                                                : DuplicateHandling.Replace
                                            : dups;

                                    limp.Add(Tuple.Create(impres, dupThis));
                                    this.progressBar1.Value++;
                                    if (now.AddMilliseconds(100) < DateTime.UtcNow)
                                    {
                                        Application.DoEvents();
                                        now = DateTime.UtcNow;
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                string rk = "";
                                if (rie != null)
                                {
                                    rk = "(RK: " + rie + ")\n";
                                }
                                else
                                {
                                    rk = "(RK is null)\n";
                                }

                                CopyableMessageBox.IssueException(ex,
                                                                  "Could not import all resources - aborting.\n" + rk,
                                                                  title);
                                throw new IgnoredException(ex);
                            }
                        }
                        this.progressBar1.Value = 0;

                        IEnumerable <IResourceIndexEntry> rieList = limp
                                                                    .Select(
                            x =>
                            this.NewResource((AResourceKey)x.Item1.tgin,
                                             new MemoryStream(x.Item1.data),
                                             x.Item2,
                                             compress))
                                                                    .Where(x => x != null);
                        this.browserWidget1.AddRange(rieList);
                    }
                    catch (IgnoredException)
                    {
                        //just the thrown exception, stop looping
                        break;
                    }
                    catch (Exception ex)
                    {
                        CopyableMessageBox.IssueException(ex, "Could not import all resources - aborting.\n", title);
                        break;
                    }
                    finally
                    {
                        imppkg.Dispose();
                    }
                    if (autoSave && !this.FileSave())
                    {
                        break;
                    }
                }
            }
            finally
            {
                this.lbProgress.Text        = "";
                this.progressBar1.Value     = 0;
                this.progressBar1.Maximum   = 0;
                this.controlPanel1.UseNames = cpUseNames;
                this.browserWidget1.Visible = true;
                ForceFocus.Focus(Application.OpenForms[0]);
                Application.DoEvents();
            }
        }