Exemple #1
0
        private void fileToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "GTA V Script Files|*.xsc;*.csc;*.ysc";
#if !DEBUG
            try
            {
#endif
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                DateTime   Start = DateTime.Now;
                ScriptFile file  = new ScriptFile(ofd.OpenFile(), (Path.GetExtension(ofd.FileName) != ".ysc"));
                file.Save(Path.Combine(Path.GetDirectoryName(ofd.FileName),
                                       Path.GetFileNameWithoutExtension(ofd.FileName) + ".c"));
                file.Close();
                if ((Path.GetExtension(ofd.FileName) != ".ysc"))
                {
                    ScriptFile.npi.savefile();
                }
                else
                {
                    ScriptFile.X64npi.savefile();
                }
                updatestatus("File Saved, Time taken: " + (DateTime.Now - Start).ToString());
            }
#if !DEBUG
        }

        catch (Exception ex)
        {
            updatestatus("Error decompiling script " + ex.Message);
        }
#endif
        }
Exemple #2
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "GTA V Script Files|*.xsc;*.csc;*.ysc;*.ysc.full";
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                DateTime Start = DateTime.Now;
                filename    = Path.GetFileNameWithoutExtension(ofd.FileName);
                loadingfile = true;
                fctb1.Clear();
                listView1.Items.Clear();
                updatestatus("Opening Script File...");
                string ext = Path.GetExtension(ofd.FileName);
                if (ext == ".full")                 //handle openIV exporting pc scripts as *.ysc.full
                {
                    ext = Path.GetExtension(Path.GetFileNameWithoutExtension(ofd.FileName));
                }
#if !DEBUG
                try
                {
#endif
                fileopen = new ScriptFile(ofd.OpenFile(), ext != ".ysc");
#if !DEBUG
            }
            catch (Exception ex)
            {
                updatestatus("Error decompiling script " + ex.Message);
                return;
            }
#endif
                updatestatus("Decompiled Script File, Time taken: " + (DateTime.Now - Start).ToString());
                MemoryStream ms = new MemoryStream();

                fileopen.Save(ms, false);


                foreach (KeyValuePair <string, Tuple <int, int> > locations in fileopen.Function_loc)
                {
                    listView1.Items.Add(new ListViewItem(new string[] { locations.Key, locations.Value.Item1.ToString(), locations.Value.Item2.ToString() }));
                }
                fileopen.Close();
                StreamReader sr = new StreamReader(ms);
                ms.Position = 0;
                updatestatus("Loading Text in Viewer...");
                fctb1.Text = sr.ReadToEnd();
                SetFileName(filename);
                ScriptOpen = true;
                updatestatus("Ready, Time taken: " + (DateTime.Now - Start).ToString());
                if (ext != ".ysc")
                {
                    ScriptFile.npi.savefile();
                }
                else
                {
                    ScriptFile.X64npi.savefile();
                }
            }
        }
        private static void Decompile()
        {
            while (CompileList.Count > 0)
            {
                string scriptToDecode;
                lock (Program.ThreadLock)
                {
                    scriptToDecode = CompileList.Dequeue();
                }
                try
                {
                    string suffix  = ".c" + (Program.CompressedOutput ? ".gz" : "");
                    string outname = Path.GetFileNameWithoutExtension(scriptToDecode);
                    if (Path.GetExtension(scriptToDecode) == ".gz") // Ensure the extension without compression is removed.
                    {
                        outname = Path.GetFileNameWithoutExtension(outname);
                    }

                    string output = Path.Combine(SaveDirectory, outname + suffix);
                    Console.WriteLine("Decompiling: " + scriptToDecode + " > " + output);

                    ScriptFile scriptFile = ProcessScriptfile(scriptToDecode, output);
                    if (Program.AggregateFunctions) /* Compile aggregation statistics for each function. */
                    {
                        scriptFile.CompileAggregate();
                    }

                    scriptFile.Close();
                    if ((_gcCount.Value++) % 25 == 0)
                    {
                        GC.Collect();
                    }
                }
                catch (Exception ex)
                {
                    throw new SystemException("Error decompiling script " + Path.GetFileNameWithoutExtension(scriptToDecode) + " - " + ex.Message);
                }
            }
            Program.ThreadCount--;
        }
Exemple #4
0
 private void Decompile()
 {
     while (CompileList.Count > 0)
     {
         Tuple <string, bool> scriptToDecode;
         lock (Program.ThreadLock)
         {
             scriptToDecode = CompileList.Dequeue();
         }
         try
         {
             ScriptFile scriptFile = new ScriptFile((Stream)File.OpenRead(scriptToDecode.Item1), scriptToDecode.Item2);
             scriptFile.Save(Path.Combine(SaveDirectory, Path.GetFileNameWithoutExtension(scriptToDecode.Item1) + ".c"));
             scriptFile.Close();
         }
         catch (Exception ex)
         {
             MessageBox.Show("Error decompiling script " + Path.GetFileNameWithoutExtension(scriptToDecode.Item1) + " - " + ex.Message);
         }
     }
     Program.ThreadCount--;
 }
        private void bulkDecompiler(string path, string theFileName)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.FileName = theFileName;
            DateTime Start = DateTime.Now;

            filename    = Path.GetFileNameWithoutExtension(ofd.FileName);
            loadingfile = true;
            fctb1.Clear();
            listView1.Items.Clear();
            updatestatus("Opening Script File...");
            string ext = Path.GetExtension(ofd.FileName);

            if (ext == ".full") //handle openIV exporting pc scripts as *.ysc.full
            {
                ext = Path.GetExtension(Path.GetFileNameWithoutExtension(ofd.FileName));
            }
#if !DEBUG
            try
            {
#endif
            fileopen = new ScriptFile(ofd.OpenFile(), ext != ".ysc");
#if !DEBUG
        }
        catch (Exception ex)
        {
            updatestatus("Error decompiling script " + ex.Message);
            return;
        }
#endif
            updatestatus("Decompiled Script File, Time taken: " + (DateTime.Now - Start).ToString());
            MemoryStream ms = new MemoryStream();

            fileopen.Save(ms, false);


            foreach (KeyValuePair <string, Tuple <int, int> > locations in fileopen.Function_loc)
            {
                listView1.Items.Add(new ListViewItem(new string[] { locations.Key, locations.Value.Item1.ToString(), locations.Value.Item2.ToString() }));
            }
            fileopen.Close();
            StreamReader sr = new StreamReader(ms);
            ms.Position = 0;
            updatestatus("Loading Text in Viewer...");
            fctb1.Text = sr.ReadToEnd();
            SetFileName(filename);
            ScriptOpen = true;
            updatestatus("Ready, Time taken: " + (DateTime.Now - Start).ToString());
            if (ext != ".ysc")
            {
                ScriptFile.npi.savefile();
            }
            else
            {
                ScriptFile.X64npi.savefile();
            }

            bool exists = Directory.Exists(path + "\\decomplied");
            if (!exists)
            {
                Directory.CreateDirectory(path + "\\decomplied");
            }

            using (StreamWriter sw = new StreamWriter(path + "\\decomplied\\" + Path.GetFileNameWithoutExtension(ofd.FileName) + ".c4", true))
            {
                sw.WriteLine(fctb1.Text);
            }
        }