Exemple #1
0
        public eList[] Load(string elFile, string ConfigsPath, string ErrorMsg, ProgressBar progressBar_Progress, ToolStripProgressBar toolStripProgressBar_Progress, int AdditionalProgBarMaxValue)
        {
            eList[] Li = new eList[0];

            FileStream   fs = File.OpenRead(elFile);
            BinaryReader br = new BinaryReader(fs);

            Version   = br.ReadInt16();
            Signature = br.ReadInt16();

            string[] configFiles = Directory.GetFiles(ConfigsPath, "PW_*_v" + Version + ".cfg");
            if (configFiles.Length > 0)
            {
                ConfigFile = configFiles[0];
                Li         = loadConfiguration(ConfigFile);
                if (progressBar_Progress != null)
                {
                    progressBar_Progress.Maximum = Li.Length + AdditionalProgBarMaxValue;
                    progressBar_Progress.Value   = 0;
                }
                if (toolStripProgressBar_Progress != null)
                {
                    toolStripProgressBar_Progress.Maximum = Li.Length + AdditionalProgBarMaxValue;
                    toolStripProgressBar_Progress.Value   = 0;
                }

                for (int l = 0; l < Li.Length; l++)
                {
                    Application.DoEvents();

                    if (Li[l].listOffset != null)
                    {
                        if (Li[l].listOffset.Length > 0)
                        {
                            Li[l].listOffset = br.ReadBytes(Li[l].listOffset.Length);
                        }
                    }
                    else
                    {
                        if (l == 0)
                        {
                            byte[] t      = br.ReadBytes(4);
                            byte[] len    = br.ReadBytes(4);
                            byte[] buffer = br.ReadBytes(BitConverter.ToInt32(len, 0));
                            Li[l].listOffset = new byte[t.Length + len.Length + buffer.Length];
                            Array.Copy(t, 0, Li[l].listOffset, 0, t.Length);
                            Array.Copy(len, 0, Li[l].listOffset, 4, len.Length);
                            Array.Copy(buffer, 0, Li[l].listOffset, 8, buffer.Length);
                        }
                        if (l == 20)
                        {
                            byte[] tag    = br.ReadBytes(4);
                            byte[] len    = br.ReadBytes(4);
                            byte[] buffer = br.ReadBytes(BitConverter.ToInt32(len, 0));
                            byte[] t      = br.ReadBytes(4);
                            Li[l].listOffset = new byte[tag.Length + len.Length + buffer.Length + t.Length];
                            Array.Copy(tag, 0, Li[l].listOffset, 0, tag.Length);
                            Array.Copy(len, 0, Li[l].listOffset, 4, len.Length);
                            Array.Copy(buffer, 0, Li[l].listOffset, 8, buffer.Length);
                            Array.Copy(t, 0, Li[l].listOffset, 8 + buffer.Length, t.Length);
                        }
                        int NPC_WAR_TOWERBUILD_SERVICE_index = 100;
                        if (Version >= 191)
                        {
                            NPC_WAR_TOWERBUILD_SERVICE_index = 99;
                        }
                        if (l == NPC_WAR_TOWERBUILD_SERVICE_index)
                        {
                            byte[] tag    = br.ReadBytes(4);
                            byte[] len    = br.ReadBytes(4);
                            byte[] buffer = br.ReadBytes(BitConverter.ToInt32(len, 0));
                            Li[l].listOffset = new byte[tag.Length + len.Length + buffer.Length];
                            Array.Copy(tag, 0, Li[l].listOffset, 0, tag.Length);
                            Array.Copy(len, 0, Li[l].listOffset, 4, len.Length);
                            Array.Copy(buffer, 0, Li[l].listOffset, 8, buffer.Length);
                        }
                    }
                    if (l == ConversationListIndex)
                    {
                        Li[l].elementValues = new object[0][];
                        talk_procs          = new talk_proc[br.ReadInt32()];
                        for (int ti = 0; ti < talk_procs.Length; ti++)
                        {
                            talk_procs[ti]            = new talk_proc();
                            talk_procs[ti].id_talk    = br.ReadInt32();
                            talk_procs[ti].text       = br.ReadBytes(128);
                            talk_procs[ti].num_window = br.ReadInt32();
                            talk_procs[ti].windows    = new window[talk_procs[ti].num_window];
                            for (int wi = 0; wi < talk_procs[ti].num_window; wi++)
                            {
                                talk_procs[ti].windows[wi]               = new window();
                                talk_procs[ti].windows[wi].id            = br.ReadInt32();
                                talk_procs[ti].windows[wi].id_parent     = br.ReadInt32();
                                talk_procs[ti].windows[wi].talk_text_len = br.ReadInt32();
                                talk_procs[ti].windows[wi].talk_text     = br.ReadBytes(2 * talk_procs[ti].windows[wi].talk_text_len);
                                talk_procs[ti].windows[wi].num_option    = br.ReadInt32();
                                talk_procs[ti].windows[wi].options       = new option[talk_procs[ti].windows[wi].num_option];
                                for (int oi = 0; oi < talk_procs[ti].windows[wi].num_option; oi++)
                                {
                                    talk_procs[ti].windows[wi].options[oi]       = new option();
                                    talk_procs[ti].windows[wi].options[oi].param = br.ReadInt32();
                                    talk_procs[ti].windows[wi].options[oi].text  = br.ReadBytes(128);
                                    talk_procs[ti].windows[wi].options[oi].id    = br.ReadInt32();
                                }
                            }
                        }
                    }
                    else
                    {
                        if (Version >= 191)
                        {
                            Li[l].listType = br.ReadInt32();
                        }
                        Li[l].elementValues = new object[br.ReadInt32()][];
                        if (Version >= 191)
                        {
                            Li[l].elementSize = br.ReadInt32();
                        }
                        for (int e = 0; e < Li[l].elementValues.Length; e++)
                        {
                            Li[l].elementValues[e] = new object[Li[l].elementTypes.Length];
                            for (int f = 0; f < Li[l].elementValues[e].Length; f++)
                            {
                                Li[l].elementValues[e][f] = readValue(br, Li[l].elementTypes[f]);
                            }
                        }
                    }
                    if (progressBar_Progress != null)
                    {
                        progressBar_Progress.Value++;
                    }
                    if (toolStripProgressBar_Progress != null)
                    {
                        toolStripProgressBar_Progress.Value++;
                    }
                }
            }
            else
            {
                MessageBox.Show(String.Format(ErrorMsg, Version, Version));
            }

            br.Close();
            fs.Close();

            return(Li);
        }
Exemple #2
0
        public ArrayList JoinElements(eList newList, int listID, bool addNew, bool backupNew, bool replaceChanged, bool backupChanged, bool removeMissing, bool backupMissing, string dirBackupNew, string dirBackupChanged, string dirBackupMissing)
        {
            object[][] newElementValues = newList.elementValues;
            string[]   newElementTypes  = newList.elementTypes;

            ArrayList report = new ArrayList();
            bool      exists;

            for (int n = 0; n < elementValues.Length; n++)
            {
                Application.DoEvents();
                exists = false;
                for (int e = 0; e < newElementValues.Length; e++)
                {
                    if (this.GetValue(n, 0) == newList.GetValue(e, 0))
                    {
                        exists = true;
                    }
                }
                if (!exists)
                {
                    if (dirBackupMissing != null && Directory.Exists(dirBackupMissing))
                    {
                        ExportItem(dirBackupMissing + "\\List_" + listID.ToString() + "_Item_" + this.GetValue(n, 0) + ".txt", n);
                    }
                    if (removeMissing)
                    {
                        report.Add("- MISSING ITEM (*removed): " + ((int)elementValues[n][0]).ToString());
                        RemoveItem(n);
                        n--;
                    }
                    else
                    {
                        report.Add("- MISSING ITEM (*not removed): " + ((int)elementValues[n][0]).ToString());
                    }
                }
            }

            for (int e = 0; e < newElementValues.Length; e++)
            {
                Application.DoEvents();
                exists = false;
                for (int n = 0; n < elementValues.Length; n++)
                {
                    if (this.GetValue(n, 0) == newList.GetValue(e, 0))
                    {
                        exists = true;
                        if (this.elementValues[n].Length != newList.elementValues[e].Length)
                        {
                            report.Add("<> DIFFERENT ITEM (*not replaced, invalid amount of values): " + this.GetValue(n, 0));
                        }
                        else
                        {
                            for (int i = 0; i < this.elementValues[n].Length; i++)
                            {
                                if (this.GetValue(n, i) != newList.GetValue(e, i))
                                {
                                    if (backupChanged && Directory.Exists(dirBackupChanged))
                                    {
                                        ExportItem(dirBackupChanged + "\\List_" + listID.ToString() + "_Item_" + this.GetValue(n, 0) + ".txt", n);
                                    }
                                    if (replaceChanged)
                                    {
                                        report.Add("<> DIFFERENT ITEM (*replaced): " + this.GetValue(n, 0));
                                        elementValues[n] = newList.elementValues[e];
                                    }
                                    else
                                    {
                                        report.Add("<> DIFFERENT ITEM (*not replaced): " + this.GetValue(n, 0));
                                    }
                                    break;
                                }
                            }
                        }
                        break;
                    }
                }
                if (!exists)
                {
                    if (backupNew && Directory.Exists(dirBackupNew))
                    {
                        newList.ExportItem(dirBackupNew + "\\List_" + listID.ToString() + "_Item_" + newList.GetValue(e, 0) + ".txt", e);
                    }
                    if (addNew)
                    {
                        AddItem(newElementValues[e]);
                        report.Add("+ NEW ITEM (*added): " + this.GetValue(elementValues.Length - 1, 0));
                    }
                    else
                    {
                        report.Add("+ NEW ITEM (*not added): " + this.GetValue(elementValues.Length - 1, 0));
                    }
                }
            }

            return(report);
        }