Beispiel #1
0
        private void lZBDeCompressorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter      = "LZB File (*.LZB)|*.LZB|OUT File (*.OUT)|*.OUT|Other Files|*.*";
            openFileDialog.FilterIndex = 0;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string extension = Path.GetExtension(openFileDialog.FileName).ToUpper();
                if (extension == ".LZB")
                {
                    LZBFile lzbFile = new LZBFile(openFileDialog.FileName);

                    TaskProgress progress = new TaskProgress();
                    progress.TaskDone += ProgressOnTaskDone;
                    Enabled            = false;
                    lzbFile.Decompress();
                    Enabled = true;
                }
                else if (extension == ".OUT")
                {
                    LZBFile lzbFile = new LZBFile();
                    lzbFile.DecompressedFile = new BaseFile(openFileDialog.FileName);
                    lzbFile.HeaderFile       = new BaseFile(Path.GetDirectoryName(openFileDialog.FileName) + "\\" + Path.GetFileNameWithoutExtension(openFileDialog.FileName) + ".HEADER");
                    lzbFile.FilePath         = Path.GetDirectoryName(openFileDialog.FileName) + "\\" + Path.GetFileNameWithoutExtension(openFileDialog.FileName);

                    TaskProgress progress = new TaskProgress();
                    progress.TaskDone += ProgressOnTaskDone;
                    Enabled            = false;
                    lzbFile.Compress();
                    Enabled = true;
                }
                else
                {
                    LZBFile          lzbFile          = new LZBFile();
                    SelectModeWindow selectModeWindow = new SelectModeWindow();
                    if (selectModeWindow.ShowDialog() == DialogResult.OK)
                    {
                        string headerPath = openFileDialog.FileName + ".HEADER";
                        using (BinaryWriter writer = new BinaryWriter(new FileStream(headerPath, FileMode.Create)))
                        {
                            writer.Write(LZSSHeader.Empty(selectModeWindow.Mode).GetBytes());
                        }
                        string outputPath = openFileDialog.FileName + ".OUT";
                        File.Copy(openFileDialog.FileName, outputPath);

                        lzbFile.HeaderFile       = new BaseFile(headerPath);
                        lzbFile.DecompressedFile = new BaseFile(outputPath);
                        lzbFile.FilePath         = openFileDialog.FileName + ".LZB";

                        TaskProgress progress = new TaskProgress();
                        progress.TaskDone += ProgressOnTaskDone;
                        Enabled            = false;
                        lzbFile.Compress();
                        Enabled = true;
                    }
                }
            }
        }
Beispiel #2
0
        private void OnClickPKNUnpackDecompAll(object sender, EventArgs eventArgs)
        {
            if (treeView1.SelectedNode == null)
            {
                return;
            }
            if (treeView1.SelectedNode.Tag == null)
            {
                return;
            }

            Enabled = false;

            if (treeView1.SelectedNode.Tag.GetType() == typeof(PKNFile))
            {
                PKNFile pknFile = (PKNFile)treeView1.SelectedNode.Tag;
                foreach (BaseFile file in pknFile.Files)
                {
                    if (file.GetType() == typeof(LZBFile))
                    {
                        LZBFile lzbFile = (LZBFile)file;
                        lzbFile.Decompress();
                    }
                }
            }
            _state.SaveProject();
            Enabled = true;
        }
        public ScriptDocument(BaseFile baseFile)
        {
            BaseFile = baseFile;

            string filePath;

            if (baseFile.GetType() == typeof(LZBFile))
            {
                LZBFile lzbFile = (LZBFile)baseFile;
                if (lzbFile.DecompressedFile == null)
                {
                    lzbFile.Decompress();
                }
                filePath = lzbFile.DecompressedFile.FilePath;
            }
            else
            {
                filePath = baseFile.FilePath;
            }

            using (BinaryReader reader = new BinaryReader(new FileStream(filePath, FileMode.Open)))
            {
                byte[] charArray = new byte[reader.BaseStream.Length];
                reader.Read(charArray, 0, charArray.Length);
                TextBuffer = _shiftJist.GetString(charArray);
                TextBuffer = TextBuffer.Trim('\0');
            }
        }
Beispiel #4
0
        private void OnClickRevertToOriginal(object sender, EventArgs eventArgs)
        {
            TreeNode pknNode  = treeView1.SelectedNode;
            BaseFile baseFile = (BaseFile)pknNode.Tag;

            foreach (PKNFile pknFile in _state.ProjectFile.OriginalImage.PKNFiles)
            {
                foreach (BaseFile file in pknFile.Files)
                {
                    if (file.FileName == baseFile.FileName)
                    {
                        File.Copy(file.FilePath, baseFile.FilePath, true);
                        if (baseFile.GetType() == typeof(LZBFile))
                        {
                            LZBFile lzbFile = (LZBFile)baseFile;
                            if (lzbFile.DecompressedFile != null)
                            {
                                lzbFile.DecompressedFile.Delete();
                                lzbFile.DecompressedFile = null;
                            }
                            if (lzbFile.HeaderFile != null)
                            {
                                lzbFile.HeaderFile.Delete();
                                lzbFile.HeaderFile = null;
                            }
                        }
                        return;
                    }
                }
            }

            MessageBox.Show("Couldn't find the original file", "Error!");
        }
Beispiel #5
0
        private void OnClickLZBClear(object sender, EventArgs eventArgs)
        {
            TreeNode lzbNode = treeView1.SelectedNode;
            //lzbNode.Nodes.Clear();

            LZBFile lzb = (LZBFile)lzbNode.Tag;

            lzb.DecompressedFile = null;
            _state.SaveProject();

            //UpdateTreeNodes();
        }
Beispiel #6
0
        public void Update(LZBFile lzbFile)
        {
            textBox_Mode.Text             = String.Format("0x{0:X2}", lzbFile.LZSSHeader.Mode);
            textBox_UncompressedSize.Text = String.Format("0x{0:X8}", lzbFile.LZSSHeader.UncompressedSize);
            textBox_Param1.Text           = String.Format("0x{0:X4}", lzbFile.LZSSHeader.Param1);
            textBox_Param2.Text           = String.Format("0x{0:X2}", lzbFile.LZSSHeader.Param2);

            if (lzbFile.DecompressedFile == null)
            {
                dynamicControl.Update(null);
                return;
            }
            dynamicControl.Update(lzbFile.DecompressedFile);
        }
Beispiel #7
0
        private void OnClickLZBDecompress(object sender, EventArgs eventArgs)
        {
            TreeNode lzbNode = treeView1.SelectedNode;
            //lzbNode.Nodes.Clear();

            LZBFile lzb = (LZBFile)lzbNode.Tag;

            Enabled = false;
            lzb.Decompress();
            Enabled = true;
            _state.SaveProject();

            //UpdateTreeNodes();
        }
        public void WriteToOriginalFile()
        {
            string outputPath = BaseFile.FilePath;

            if (BaseFile.GetType() == typeof(LZBFile))
            {
                LZBFile lzbFile = (LZBFile)BaseFile;
                outputPath = lzbFile.DecompressedFile.FilePath;
            }
            using (BinaryWriter writer = new BinaryWriter(new FileStream(outputPath, FileMode.Create)))
            {
                writer.Write(_shiftJist.GetBytes(TextBuffer));
            }
        }
Beispiel #9
0
        private void OnClickLZBCompress(object sender, EventArgs eventArgs)
        {
            LZBFile lzb = (LZBFile)treeView1.SelectedNode.Tag;

            Enabled = false;
            if (!lzb.Compress())
            {
                MessageBox.Show("There is nothing to compress!");
                Enabled = true;
                return;
            }
            _state.SaveProject();
            Enabled = true;

            //UpdateTreeNodes();
        }
Beispiel #10
0
        private void OnShowCurrentFileClick(object sender, EventArgs eventArgs)
        {
            if (listBox_ScriptFiles.SelectedIndex == -1)
            {
                return;
            }
            Enabled = false;
            ScriptDocument file = ScriptFile.Scripts[listBox_ScriptFiles.SelectedIndex];

            file.WriteToOriginalFile();
            if (file.BaseFile.GetType() == typeof(LZBFile))
            {
                LZBFile            lzbFile            = (LZBFile)file.BaseFile;
                ScriptViewerWindow scriptViewerWindow = new ScriptViewerWindow(lzbFile.DecompressedFile);
                scriptViewerWindow.Show();
            }
            Enabled = true;
        }
Beispiel #11
0
        public void DecompressScripts()
        {
            if (ApplicationState.Instance.ProjectFile == null)
            {
                MessageBox.Show("Open a project file before decompressing!", "Project file not found!");
                return;
            }
            PSXImage modifiedImage = ApplicationState.Instance.ProjectFile.ModifiedImage;

            _scriptPKN = modifiedImage.PKNFiles.Find(pkn => pkn.Name == "SCRIPT");
            if (_scriptPKN == null)
            {
                return;
            }
            if (_scriptPKN.Files.Count == 0) //cheap fix for when pkn files dont save files
            {
                _scriptPKN.Unpack();
            }
            Enabled = false;

            ScriptFile = new ScriptFile();

            richTextBox_ScriptFile.Text = "";
            for (int i = 0; i < _scriptPKN.Files.Count; i++)
            {
                BaseFile baseFile = _scriptPKN.Files[i];
                if (baseFile.GetType() == typeof(LZBFile))
                {
                    LZBFile lzbFile = (LZBFile)baseFile;
                    lzbFile.Decompress();
                }
                ScriptDocument scriptFile = new ScriptDocument(baseFile);
                ScriptFile.Scripts.Add(scriptFile);
                progressBar_Progress.Value = (int)((double)i / _scriptPKN.Files.Count * 100);
            }
            listBox_ScriptFiles.Items.Clear();
            foreach (ScriptDocument scriptFile in ScriptFile.Scripts)
            {
                listBox_ScriptFiles.Items.Add(scriptFile);
            }

            progressBar_Progress.Value = 0;
            Enabled = true;
        }
Beispiel #12
0
        public void CompressScripts()
        {
            if (ApplicationState.Instance.ProjectFile == null)
            {
                MessageBox.Show("Open a project file before compressing!", "Project file not found!");
                return;
            }

            for (int i = 0; i < ScriptFile.Scripts.Count; i++)
            {
                ScriptDocument scriptFile = ScriptFile.Scripts[i];

                //Don't touch those file! - (can) Softlock the engine, and we dont need to modify gamelogic to that degree
                if (scriptFile.Name == "FLAG.TXT")
                {
                    continue;
                }

                //Enforce correct end of file as done by other conan files (prevents softlock on EOF)
                scriptFile.TextBuffer += "\r\n\r\n\r\n\r\n";

                scriptFile.WriteToOriginalFile();
                if (scriptFile.BaseFile.GetType() == typeof(LZBFile))
                {
                    LZBFile lzbFile = (LZBFile)scriptFile.BaseFile;
                    lzbFile.Compress(false);
                }
                Invoke((MethodInvoker) delegate
                {
                    progressBar_Progress.Value = (int)((double)i / ScriptFile.Scripts.Count * 100);
                });
            }

            Invoke((MethodInvoker) delegate
            {
                progressBar_Progress.Value = 0;
                Enabled = true;
            });
        }
Beispiel #13
0
        private void OnCompressClick(object sender, EventArgs eventArgs)
        {
            if (ScriptFile.Scripts.Count == 0)
            {
                MessageBox.Show("Decompress all first!");
                return;
            }
            if (listBox_ScriptFiles.SelectedIndex == -1)
            {
                return;
            }
            Enabled = false;
            ScriptDocument file = ScriptFile.Scripts[listBox_ScriptFiles.SelectedIndex];

            file.TextBuffer = richTextBox_ScriptFile.Text.Replace("\n", "\r\n");
            file.WriteToOriginalFile();
            if (file.BaseFile.GetType() == typeof(LZBFile))
            {
                LZBFile lzbFile = (LZBFile)file.BaseFile;
                lzbFile.Compress(false);
            }
            Enabled = true;
        }
        public void Update(BaseFile baseFile)
        {
            if (baseFile == null)
            {
                if (EnabledLZB)
                {
                    lzbControl.Visible = false;
                }
                if (EnabledTIM)
                {
                    timControl.Visible = false;
                }
                if (EnabledPB)
                {
                    pbControl.Visible = false;
                }
                if (EnabledBG)
                {
                    bgControl.Visible = false;
                }
                textControl.Visible = false;
                return;
            }
            if (baseFile.GetType() == typeof(TIMFile) && EnabledTIM)
            {
                TIMFile timFile = (TIMFile)baseFile;
                timControl.Update(timFile);
                timControl.Visible = true;
                if (EnabledLZB)
                {
                    lzbControl.Visible = false;
                }
                if (EnabledPB)
                {
                    pbControl.Visible = false;
                }
                if (EnabledBG)
                {
                    bgControl.Visible = false;
                }
                textControl.Visible = false;
                return;
            }
            if (baseFile.GetType() == typeof(LZBFile) && EnabledLZB)
            {
                LZBFile lzbFile = (LZBFile)baseFile;
                lzbControl.Update(lzbFile);
                lzbControl.Visible = true;
                if (EnabledTIM)
                {
                    timControl.Visible = false;
                }
                if (EnabledPB)
                {
                    pbControl.Visible = false;
                }
                if (EnabledBG)
                {
                    bgControl.Visible = false;
                }
                textControl.Visible = false;
                return;
            }
            if (baseFile.GetType() == typeof(PBFile) && EnabledPB)
            {
                PBFile pbFile = (PBFile)baseFile;
                pbControl.Update(pbFile);
                pbControl.Visible = true;
                if (EnabledTIM)
                {
                    timControl.Visible = false;
                }
                if (EnabledLZB)
                {
                    lzbControl.Visible = false;
                }
                if (EnabledBG)
                {
                    bgControl.Visible = false;
                }
                textControl.Visible = false;
                return;
            }
            if (baseFile.GetType() == typeof(BGFile) && EnabledBG)
            {
                BGFile bgFile = (BGFile)baseFile;
                bgControl.Update(bgFile);
                bgControl.Visible = true;
                if (EnabledTIM)
                {
                    timControl.Visible = false;
                }
                if (EnabledLZB)
                {
                    lzbControl.Visible = false;
                }
                if (EnabledPB)
                {
                    pbControl.Visible = false;
                }
                textControl.Visible = false;
                return;
            }

            textControl.Update(baseFile);
            textControl.Visible = true;
            if (EnabledLZB)
            {
                lzbControl.Visible = false;
            }
            if (EnabledTIM)
            {
                timControl.Visible = false;
            }
            if (EnabledPB)
            {
                pbControl.Visible = false;
            }
            if (EnabledBG)
            {
                bgControl.Visible = false;
            }
        }