コード例 #1
0
 private void Cleanup()
 {
     this.buttonSave.Enabled = this.buttonAddSelect.Enabled = this.inputType.Enabled = this.inputIDS.Enabled = false;
     this.listBox.Items.Clear();
     if (bar == null)
     {
         bar = null; fileName = "";
     }
 }
コード例 #2
0
 private void openFile(string filename, bool ro = false)
 {
     Cleanup();
     try { bar = new BAR(System.IO.File.Open(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.None)); }
     catch (Exception e) { MessageBox.Show(e.Message, "Fatal error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error); bar = null; return; }
     fileName = System.IO.Path.GetFileName(filename);
     this.listBox.BeginUpdate();
     for (int i = 0; i < bar.fileCount; i++)
     {
         BAR.BARFile b = bar.fileList[i];
         this.listBox.Items.Add(b.id + " [0x" + b.type.ToString("X2") + "]");
     }
     if (bar.fileCount > 0)
     {
         this.listBox.SelectedIndex = 0;
     }
     this.listBox.EndUpdate();
     SetUp();
 }
コード例 #3
0
ファイル: Form1.cs プロジェクト: GovanifY/EVENTVIEWER_EDITOR
        private void openFile(string filename, bool ro = false)
        {
            try
            {
                Cleanup();
                try
                {
                    bar =
                        new BAR(System.IO.File.Open(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read,
                            System.IO.FileShare.None));
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Fatal error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    bar = null;
                    return;
                }
                fileName = System.IO.Path.GetFileName(filename);
                b = this.bar.fileList[0];
                //Now let's extract the file
                if (bar.fileCount != 1)
                {
                    MessageBox.Show("This BAR files contains more than one file!\nAre you sure it is eventviewer.bar?",
                        "Fatal error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    bar = null;
                    return;
                }
                if (b.id != "even")
                {
                    MessageBox.Show(
                        "This BAR files don't have a file called even!\nAre you sure it is eventviewer.bar?",
                        "Fatal error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    bar = null;
                    return;
                }

                string nameextractedevent =
                    Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                        System.IO.Path.GetTempFileName());
                try
                {
                    System.IO.File.WriteAllBytes(nameextractedevent, b.data);
                }
                catch
                {
                    MessageBox.Show(
                        "Event file can't be extracted in temp folder!\nDo you have enough access to write in the TEMP folder?",
                        "Fatal error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    bar = null;
                    return;
                }
                //Fun part:let's load it!
                uint version;
                BinaryReader br = new BinaryReader(new FileStream(nameextractedevent, FileMode.Open));
                br.BaseStream.Position = 0;
                version = br.ReadUInt32();
                nentries = br.ReadUInt32();
                this.listBox1.BeginUpdate();

                for (uint i = 0; i < nentries; i++)
                {
                    //Read shits
                    var Contents = new EVENT();
                    Contents.IsSubLevel = br.ReadUInt16();
                    Contents.StringID = br.ReadUInt16();
                    Contents.WorldID = br.ReadUInt16();
                    Contents.EnID = br.ReadUInt16();
                    Contents.JAID = br.ReadUInt16();
                    Contents.RestrictionID = br.ReadUInt16();
                    Contents.number = i;
                    EVENTS.Add(Contents.StringID, Contents);
                    this.listBox1.Items.Add(Contents.StringID.ToString("X4"));
                }
                this.listBox1.EndUpdate();
                SetUp();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Fatal error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                bar = null;
            }
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: GovanifY/EVENTVIEWER_EDITOR
        private void LoadStr(string filename, bool ro = false)
        {
            try
            {
                bar =
                    new BAR(System.IO.File.Open(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read,
                        System.IO.FileShare.None));
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Fatal error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                bar = null;
                return;
            }
            fileName = System.IO.Path.GetFileName(filename);
            b = this.bar.fileList[0];
            //Now let's extract the file
            if (bar.fileCount != 2)
            {
                MessageBox.Show("This BAR files contains more than two file!\nAre you sure it is title.bar?",
                    "Fatal error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                bar = null;
                return;
            }
            if (b.id != "titl")
            {
                MessageBox.Show("This BAR files don't have a file called titl!\nAre you sure it is title.bar?",
                    "Fatal error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                bar = null;
                return;
            }

            string nameextractedstr = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), System.IO.Path.GetTempFileName());
            try
            {
                System.IO.File.WriteAllBytes(nameextractedstr, b.data);
            }
            catch
            {
                MessageBox.Show(
                    "Text file can't be extracted in temp folder!\nDo you have enough access to write in the TEMP folder?",
                    "Fatal error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                bar = null;
                return;
            }
            //Now let's load this shit inside a dictionnary
            uint version;
            uint nentriesStr;
            long brpos = 0;
            bool jap = false;
            STRINGS.Clear();

            BinaryReader br = new BinaryReader(new FileStream(nameextractedstr, FileMode.Open));
            br.BaseStream.Position = 0;
            version = br.ReadUInt32();
            nentriesStr = br.ReadUInt32();
            for (int i = 0; i < nentriesStr; i++)
            {
                var Contents = new STRING();
                Contents.ID = br.ReadUInt32();
                brpos = br.BaseStream.Position + 4;
                br.BaseStream.Position = br.ReadUInt32();
                //Contents.Offset = (uint) br.BaseStream.Position;
                //MessageBox.Show(Contents.Offset.ToString(), nameextractedstr, MessageBoxButtons.OK, MessageBoxIcon.Error);
                bar = null;
                byte c = br.ReadByte();
                while (true)
                {
                    Contents.text = Contents.bytetotext(c, Contents.text, jap);
                        c = br.ReadByte();
                    if (c == 0)
                    {
                        goto next;
                    }
                }
                next:
                //MessageBox.Show(Contents.text, nameextractedstr, MessageBoxButtons.OK, MessageBoxIcon.Error);
                bar = null;
                if (checkBox1.Checked)
                {
                    jap = true;
                }
                STRINGS.Add(Contents.ID, Contents);
                br.BaseStream.Position = brpos;
            }
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: GovanifY/EVENTVIEWER_EDITOR
 private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     string curItem = "";
     retry:
     try { curItem = listBox1.SelectedItem.ToString(); }
     catch { listBox1.SelectedIndex = 0; goto retry; }
     uint key = Convert.ToUInt16(curItem, 16);
     if (EVENTS.ContainsKey(key))
     {
         var Values = EVENTS[key];
         this.numericUpDown6.Value = Values.RestrictionID;
         this.numericUpDown5.Value = Values.IsSubLevel;
         this.numericUpDown4.Value = Values.WorldID;
         this.numericUpDown3.Value = Values.JAID;
         this.numericUpDown2.Value = Values.EnID;
         this.numericUpDown1.Value = Values.StringID;
     }
     else
     {
         MessageBox.Show("Contents of the event can't be loaded!", "Fatal error opening file",
             MessageBoxButtons.OK, MessageBoxIcon.Error);
         bar = null;
         return;
     }
     if (STRINGS.ContainsKey((key)))
     {
         var Values = STRINGS[key];
         textBox1.Text = Values.text;
     }
     else
     {
         textBox1.Text = "NULL or String Mapping not loaded!";
     }
 }
コード例 #6
0
ファイル: Form1.cs プロジェクト: GovanifY/EVENTVIEWER_EDITOR
 private void Cleanup()
 {
     this.buttonSave.Enabled =
         this.numericUpDown1.Enabled =
             this.numericUpDown2.Enabled =
                 this.numericUpDown3.Enabled =
                     this.numericUpDown4.Enabled =
                         this.numericUpDown5.Enabled = this.numericUpDown6.Enabled = false;
     this.listBox1.Items.Clear();
     EVENTS.Clear();
     if (bar == null)
     {
         bar = null;
         fileName = "";
     }
 }
コード例 #7
0
 private void openFile(string filename, bool ro = false)
 {
     try
     {
         Cleanup();
         try
         {
             bar =
                 new BAR(System.IO.File.Open(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read,
                     System.IO.FileShare.None));
         }
         catch (Exception e)
         {
             MessageBox.Show(e.Message, "Fatal error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error);
             bar = null;
             return;
         }
         fileName = System.IO.Path.GetFileName(filename);
         b = this.bar.fileList[0];
         //Now let's extract the file
         if (bar.fileCount != 2)
         {
             MessageBox.Show("This BAR file doesn't exactly contains two files!\nAre you sure it is a text file?",
                 "Fatal error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error);
             bar = null;
             return;
         }
                        string nameextractedtext =
             Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                 System.IO.Path.GetTempFileName());
         try
         {
             System.IO.File.WriteAllBytes(nameextractedtext, b.data);
         }
         catch
         {
             MessageBox.Show(
                 "String file can't be extracted in temp folder!\nDo you have enough access to write in the TEMP folder?",
                 "Fatal error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error);
             bar = null;
             return;
         }
         BinaryReader br = new BinaryReader(new FileStream(nameextractedtext, FileMode.Open));
     br.BaseStream.Position = 0;
     var version = br.ReadUInt32();
     nentriesStr = br.ReadUInt32();
     bool jap = false;
     for (int i = 0; i < nentriesStr; i++)
     {
         var Contents = new STRING();
         Contents.ID = br.ReadUInt32();
         var brpos = br.BaseStream.Position + 4;
         br.BaseStream.Position = br.ReadUInt32();
         //Contents.Offset = (uint) br.BaseStream.Position;
         //MessageBox.Show(Contents.Offset.ToString(), nameextractedstr, MessageBoxButtons.OK, MessageBoxIcon.Error);
         bar = null;
         byte c = br.ReadByte();
         while (true)
         {
             Contents.text = Contents.bytetotext(c, Contents.text, jap);
                 c = br.ReadByte();
             if (c == 0)
             {
                 goto next;
             }
         }
         next:
         //MessageBox.Show(Contents.text, nameextractedstr, MessageBoxButtons.OK, MessageBoxIcon.Error);
         bar = null;
         if (Jap_mapping.Checked){jap = true;}
         STRINGS.Add(Contents.ID, Contents);
         br.BaseStream.Position = brpos;
         this.listText.Items.Add(Contents.ID.ToString("X4"));
     }
         SetUp();
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message, "Fatal error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error);
         bar = null;
     }
 }
コード例 #8
0
 private void listText_SelectedIndexChanged(object sender, EventArgs e)
 {
     string curItem = "";
     retry:
     try { curItem = listText.SelectedItem.ToString(); }
     catch { listText.SelectedIndex = 0; goto retry; }
     uint key = Convert.ToUInt16(curItem, 16);
     if (STRINGS.ContainsKey(key))
     {
         var Values = STRINGS[key];
         this.textBox1.Text  = Values.text;
     }
     else
     {
         MessageBox.Show("Contents of the strings cannot be loaded!", "Fatal error opening file",
             MessageBoxButtons.OK, MessageBoxIcon.Error);
         bar = null;
         return;
     }
 }
コード例 #9
0
 private void buttonNew_Click(object sender, EventArgs e)
 {
     Cleanup();
     bar = new BAR();
     SetUp();
 }
コード例 #10
0
ファイル: Program.cs プロジェクト: Truthkey/OpenKH
 static int Main(string[] args)
 {
     if (args.Length != 0)
     {
         // Return codes:
         // * 0 Success
         // * -1 No BAR file has been opened\made (aka bar is null)
         // * -2 Not enough arguments
         // * -3 Failed to parse argument
         // * -4 Index is out of range (too high)
         // * -10 File not found
         // * -1313 Unknown error
         try
         {
             BAR bar = null;
             for (int i = 0; i < args.Length; i++)
             {
                 int index, i2;
                 string s;
                 BAR.BARFile bf;
                 switch (args[i])
                 {
                     case "-newbar": bar = new BAR(); break;
                     case "-openbar":
                         if (i + 1 >= args.Length) { return -2; }
                         try { bar = new BAR(System.IO.File.Open(args[++i], System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)); }
                         catch (System.IO.FileNotFoundException) { return -10; }
                         break;
                     case "-savebar":
                         if (bar == null) { return -1; }
                         if (i + 1 >= args.Length) { return -2; }
                         bar.save(System.IO.File.Open(args[++i], System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None));
                         break;
                     case "-addfile":
                         if (bar == null) { return -1; }
                         if (i + 3 >= args.Length) { return -2; }
                         bf = new BAR.BARFile();
                         if (!uint.TryParse(args[++i], out bf.type)) { return -3; }
                         bf.id = args[++i];
                         try { bf.data = System.IO.File.ReadAllBytes(args[++i]); }
                         catch (System.IO.FileNotFoundException) { return -10; }
                         bar.fileList.Add(bf);
                         bf = null;
                         break;
                     case "-replacefile":
                         if (bar == null) { return -1; }
                         if (i + 2 >= args.Length) { return -2; }
                         if (!int.TryParse(args[++i], out index) || index < 0) { return -3; }
                         if (index >= bar.fileList.Count) { return -4; }
                         try { bar.fileList[index].data = System.IO.File.ReadAllBytes(args[++i]); }
                         catch (System.IO.FileNotFoundException) { return -10; }
                         break;
                     case "-deletefile":
                         if (bar == null) { return -1; }
                         if (i + 1 >= args.Length) { return -2; }
                         if (!int.TryParse(args[++i], out index) || index < 0) { return -3; }
                         if (index >= bar.fileList.Count) { return -4; }
                         bar.fileList.RemoveAt(index);
                         break;
                     case "-extractfile":
                         if (bar == null) { return -1; }
                         if (i + 2 >= args.Length) { return -2; }
                         if (!int.TryParse(args[++i], out index) || index < 0) { return -3; }
                         if (index >= bar.fileList.Count) { return -4; }
                         System.IO.File.WriteAllBytes(args[++i], bar.fileList[index].data);
                         break;
                     case "-extractmatch":
                         if (bar == null) { return -1; }
                         if (i + 2 >= args.Length) { return -2; }
                         if (!int.TryParse(args[++i], out index)) { return -3; } else if (index < -1) { index = -1; }
                         s = args[++i].Trim();
                         if (s.Length > 4) { s = s.Substring(0, 4); }
                         i2 = 0;
                         foreach (BAR.BARFile bfl in bar.fileList)
                         {
                             if ((index == -1 || bfl.type == index) && (s.Length == 0 || bfl.id.Equals(s, StringComparison.InvariantCultureIgnoreCase)))
                             {
                                 System.IO.File.WriteAllBytes(string.Format("{0}. {1} [0x{2:X2}].bin", ++i2, bfl.id, bfl.type), bfl.data);
                             }
                         }
                         break;
                 }
             }
         }
         catch (Exception) { return -1313; }
     }
     else
     {
         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);
         Application.Run(new FormMain());
     }
     return 0;
 }
コード例 #11
0
ファイル: FormMain.cs プロジェクト: Truthkey/OpenKH
 private void buttonNew_Click(object sender, EventArgs e)
 {
     Cleanup();
     bar = new BAR();
     SetUp();
 }
コード例 #12
0
ファイル: FormMain.cs プロジェクト: Truthkey/OpenKH
 private void openFile(string filename, bool ro = false)
 {
     Cleanup();
     try { bar = new BAR(System.IO.File.Open(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.None)); }
     catch (Exception e) { MessageBox.Show(e.Message, "Fatal error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error); bar = null; return; }
     fileName = System.IO.Path.GetFileName(filename);
     this.listBox.BeginUpdate();
     for (int i = 0; i < bar.fileCount; i++)
     {
         BAR.BARFile b = bar.fileList[i];
         this.listBox.Items.Add(b.id + " [0x" + b.type.ToString("X2") + "]");
     }
     if (bar.fileCount > 0)
     {
         this.listBox.SelectedIndex = 0;
     }
     this.listBox.EndUpdate();
     SetUp();
 }
コード例 #13
0
ファイル: FormMain.cs プロジェクト: Truthkey/OpenKH
 private void Cleanup()
 {
     this.buttonSave.Enabled = this.buttonAddSelect.Enabled = this.inputType.Enabled = this.inputIDS.Enabled = false;
     this.listBox.Items.Clear();
     if (bar == null) { bar = null; fileName = ""; }
 }
コード例 #14
0
        static int Main(string[] args)
        {
            if (args.Length != 0)
            {
                // Return codes:
                // * 0 Success
                // * -1 No BAR file has been opened\made (aka bar is null)
                // * -2 Not enough arguments
                // * -3 Failed to parse argument
                // * -4 Index is out of range (too high)
                // * -10 File not found
                // * -1313 Unknown error
                try
                {
                    BAR bar = null;
                    for (int i = 0; i < args.Length; i++)
                    {
                        int         index, i2;
                        string      s;
                        BAR.BARFile bf;
                        switch (args[i])
                        {
                        case "-newbar": bar = new BAR(); break;

                        case "-openbar":
                            if (i + 1 >= args.Length)
                            {
                                return(-2);
                            }
                            try { bar = new BAR(System.IO.File.Open(args[++i], System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)); }
                            catch (System.IO.FileNotFoundException) { return(-10); }
                            break;

                        case "-savebar":
                            if (bar == null)
                            {
                                return(-1);
                            }
                            if (i + 1 >= args.Length)
                            {
                                return(-2);
                            }
                            bar.save(System.IO.File.Open(args[++i], System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None));
                            break;

                        case "-addfile":
                            if (bar == null)
                            {
                                return(-1);
                            }
                            if (i + 3 >= args.Length)
                            {
                                return(-2);
                            }
                            bf = new BAR.BARFile();
                            if (!uint.TryParse(args[++i], out bf.type))
                            {
                                return(-3);
                            }
                            bf.id = args[++i];
                            try { bf.data = System.IO.File.ReadAllBytes(args[++i]); }
                            catch (System.IO.FileNotFoundException) { return(-10); }
                            bar.fileList.Add(bf);
                            bf = null;
                            break;

                        case "-replacefile":
                            if (bar == null)
                            {
                                return(-1);
                            }
                            if (i + 2 >= args.Length)
                            {
                                return(-2);
                            }
                            if (!int.TryParse(args[++i], out index) || index < 0)
                            {
                                return(-3);
                            }
                            if (index >= bar.fileList.Count)
                            {
                                return(-4);
                            }
                            try { bar.fileList[index].data = System.IO.File.ReadAllBytes(args[++i]); }
                            catch (System.IO.FileNotFoundException) { return(-10); }
                            break;

                        case "-deletefile":
                            if (bar == null)
                            {
                                return(-1);
                            }
                            if (i + 1 >= args.Length)
                            {
                                return(-2);
                            }
                            if (!int.TryParse(args[++i], out index) || index < 0)
                            {
                                return(-3);
                            }
                            if (index >= bar.fileList.Count)
                            {
                                return(-4);
                            }
                            bar.fileList.RemoveAt(index);
                            break;

                        case "-extractfile":
                            if (bar == null)
                            {
                                return(-1);
                            }
                            if (i + 2 >= args.Length)
                            {
                                return(-2);
                            }
                            if (!int.TryParse(args[++i], out index) || index < 0)
                            {
                                return(-3);
                            }
                            if (index >= bar.fileList.Count)
                            {
                                return(-4);
                            }
                            System.IO.File.WriteAllBytes(args[++i], bar.fileList[index].data);
                            break;

                        case "-extractmatch":
                            if (bar == null)
                            {
                                return(-1);
                            }
                            if (i + 2 >= args.Length)
                            {
                                return(-2);
                            }
                            if (!int.TryParse(args[++i], out index))
                            {
                                return(-3);
                            }
                            else if (index < -1)
                            {
                                index = -1;
                            }
                            s = args[++i].Trim();
                            if (s.Length > 4)
                            {
                                s = s.Substring(0, 4);
                            }
                            i2 = 0;
                            foreach (BAR.BARFile bfl in bar.fileList)
                            {
                                if ((index == -1 || bfl.type == index) && (s.Length == 0 || bfl.id.Equals(s, StringComparison.InvariantCultureIgnoreCase)))
                                {
                                    System.IO.File.WriteAllBytes(string.Format("{0}. {1} [0x{2:X2}].bin", ++i2, bfl.id, bfl.type), bfl.data);
                                }
                            }
                            break;
                        }
                    }
                }
                catch (Exception) { return(-1313); }
            }
            else
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new FormMain());
            }
            return(0);
        }