コード例 #1
0
ファイル: MainForm.cs プロジェクト: BAD-AL/LVLTool
        // Goes through the lvl file extracts all the chunks; if a child is a lvl file
        // those are split up and returned.
        private List <Chunk> GetAllChunks(string filename)
        {
            List <Chunk> retVal = new List <Chunk>();
            UcfbHelper   helper = new UcfbHelper();

            helper.FileName = filename;
            helper.InitializeRead();
            Chunk cur = null;

            while ((cur = helper.RipChunk(false)) != null)
            {
                if (cur.Type != "lvl_")
                {
                    retVal.Add(cur);
                }
                else
                {
                    string tmpFile = "tmp_child.lvl";
                    UcfbHelper.SaveFileUCFB(tmpFile, cur.Data);
                    List <Chunk> childChunks = GetAllChunks(tmpFile);
                    File.Delete(tmpFile);
                    retVal.AddRange(childChunks);
                }
            }
            return(retVal);
        }
コード例 #2
0
ファイル: CoreMerge.cs プロジェクト: BAD-AL/LVLTool
        /// <summary>
        /// Gather the strings from a core.lvl file or .txt file in the correct string format.
        /// </summary>
        /// <param name="file"></param>
        public void GatherStrings(string file)
        {
            if (file.EndsWith(".lvl", StringComparison.InvariantCultureIgnoreCase))
            {
                UcfbHelper ucfbFileHelper = new UcfbHelper();
                ucfbFileHelper.FileName = file;
                ucfbFileHelper.InitializeRead();

                Chunk cur = null;
                while ((cur = ucfbFileHelper.RipChunk(false)) != null)
                {
                    if (cur.Type == "Locl")
                    {
                        cur.LocHelper = new LocHelper(cur.GetAssetData());
                        string allStrings = cur.LocHelper.GetAllStrings();
                        if (mStringsToAdd.ContainsKey(cur.Name))
                        {
                            StringBuilder sb = mStringsToAdd[cur.Name];
                            if (sb[sb.Length - 1] != '\n')
                            {
                                sb.Append("\n");
                            }
                            sb.Append(allStrings);
                        }
                        else
                        {
                            mStringsToAdd.Add(cur.Name, new StringBuilder(allStrings));
                        }
                    }
                }
            }
            else if (file.EndsWith(".txt", StringComparison.InvariantCultureIgnoreCase))
            {
                int    slashLoc = file.LastIndexOf('\\');
                string langName = "";
                if (slashLoc > -1)
                {
                    langName = file.Substring(slashLoc + 1).Replace(".txt", "");
                    string allStrings = File.ReadAllText(file);
                    if (mStringsToAdd.ContainsKey(langName))
                    {
                        StringBuilder sb = mStringsToAdd[langName];
                        if (sb[sb.Length - 1] != '\n')
                        {
                            sb.Append("\n");
                        }
                        sb.Append(allStrings);
                    }
                    else
                    {
                        mStringsToAdd.Add(langName, new StringBuilder(allStrings));
                    }
                }
            }
            else
            {
                Console.WriteLine("skipping file '{0}'", file);
            }
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: BAD-AL/LVLTool
 private void mLVLFileTextBox_TextChanged(object sender, EventArgs e)
 {
     if (File.Exists(mLVLFileTextBox.Text))
     {
         mMainTextBox.Clear();
         mUcfbFileHelper          = new UcfbHelper();
         mUcfbFileHelper.FileName = mLVLFileTextBox.Text;
         PopulateListBox();
         State1();
         ShowLVLSummary();
     }
     else
     {
         State0();
     }
 }
コード例 #4
0
ファイル: Program.cs プロジェクト: BAD-AL/LVLTool
        public static Chunk FindChunk(string lvlFile, string name)
        {
            Chunk      cur    = null;
            UcfbHelper helper = new UcfbHelper();

            helper.FileName = lvlFile;
            helper.InitializeRead();
            while ((cur = helper.RipChunk(false)) != null)
            {
                if (cur.Name == name)
                {
                    return(cur);
                }
            }
            return(null);
        }
コード例 #5
0
ファイル: CoreMerge.cs プロジェクト: BAD-AL/LVLTool
 /// <summary>
 /// The base core.lvl file, typically should be named 'base.core.lvl'
 /// </summary>
 public CoreMerge(string baseCoreFile)
 {
     mCoreUucfbFileHelper          = new UcfbHelper();
     mCoreUucfbFileHelper.FileName = baseCoreFile;
     mCoreUucfbFileHelper.InitializeRead();
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: BAD-AL/LVLTool
        public static void Main(string[] args)
        {
            LoadSettings();
            if (args.Length == 0)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new MainForm());
            }
            else
            {
                try
                {
                    ProcessArgs(args);
                }
                catch (Exception)
                {
                    Console.Error.WriteLine("Error! Check arguments!");
                    return;
                }
                string[] files_ = GetFiles(files);
                switch (operation)
                {
                case OperationMode.ShowHelp:
                    PrintHelp();
                    break;

                case OperationMode.Extract:
                    if (input_lvl != null)
                    {
                        UcfbHelper helper = new UcfbHelper();
                        helper.FileName = input_lvl;
                        helper.ExtractContents();
                    }
                    else
                    {
                        Console.WriteLine("Error! Must specify input file");
                    }
                    break;

                case OperationMode.Add:
                    if (output_lvl == null)
                    {
                        output_lvl = input_lvl;
                    }
                    if (input_lvl != null)
                    {
                        UcfbHelper helper = new UcfbHelper();
                        helper.FileName = input_lvl;
                        foreach (string f in files_)
                        {
                            string fileName = Munger.EnsureMungedFile(f, platform);
                            helper.AddItemToEnd(fileName);
                        }
                        helper.SaveData(output_lvl);
                    }
                    else
                    {
                        Console.WriteLine("Error! Must specify input file");
                    }
                    break;

                case OperationMode.Replace:
                    if (output_lvl == null)
                    {
                        output_lvl = input_lvl;
                    }
                    if (input_lvl != null)
                    {
                        ReplaceItem_WithForm(input_lvl, output_lvl, files_);
                    }
                    else
                    {
                        Console.WriteLine("Error! Must specify input file");
                    }
                    break;

                case OperationMode.Rename:
                    if (input_lvl == null)
                    {
                        Console.WriteLine("Rename Error: no input file specified");
                        return;
                    }
                    if (old_name != null && new_name != null && old_name.Length == new_name.Length)
                    {
                        UcfbHelper helper = new UcfbHelper();
                        helper.FileName = input_lvl;
                        helper.InitializeRead();
                        Chunk c = null;
                        while ((c = helper.RipChunk(false)) != null)
                        {
                            if (c.Name == old_name)
                            {
                                break;
                            }
                        }
                        if (c != null)
                        {
                            int start = (int)BinUtils.GetLocationOfGivenBytes(c.Start, ASCIIEncoding.ASCII.GetBytes(c.Name), helper.Data, 80);
                            for (int i = 0; i < c.Name.Length; i++)
                            {
                                helper.Data[start + i] = (byte)new_name[i];
                            }
                            helper.SaveData(output_lvl);
                            Console.WriteLine("Changed {0} to {1}, saved to {2}", old_name, new_name, output_lvl);
                        }
                        else
                        {
                            Console.WriteLine("Coould not find '{0}'. No action taken", old_name);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Rename Error: old name and new name must be specified and be equal length");
                    }
                    break;

                case OperationMode.ListContents:
                    UcfbHelper listHelper = new UcfbHelper();
                    listHelper.FileName = input_lvl;
                    listHelper.InitializeRead();
                    Chunk cur = null;
                    while ((cur = listHelper.RipChunk(false)) != null)
                    {
                        Console.WriteLine("{0}.{1}", cur.Name, cur.Type);
                    }
                    break;

                case OperationMode.MergeCore:
                    List <string> theFiles = new List <string>(Directory.GetFiles(
                                                                   merge_strings_search_dir, "core.lvl", SearchOption.AllDirectories));

                    //english,spanigh,italian,french,german,japanese,uk_english
                    theFiles.AddRange(Directory.GetFiles(merge_strings_search_dir, "english.txt", SearchOption.AllDirectories));
                    theFiles.AddRange(Directory.GetFiles(merge_strings_search_dir, "spanish.txt", SearchOption.AllDirectories));
                    theFiles.AddRange(Directory.GetFiles(merge_strings_search_dir, "italian.txt", SearchOption.AllDirectories));
                    theFiles.AddRange(Directory.GetFiles(merge_strings_search_dir, "french.txt", SearchOption.AllDirectories));
                    theFiles.AddRange(Directory.GetFiles(merge_strings_search_dir, "german.txt", SearchOption.AllDirectories));
                    theFiles.AddRange(Directory.GetFiles(merge_strings_search_dir, "japanese.txt", SearchOption.AllDirectories));
                    theFiles.AddRange(Directory.GetFiles(merge_strings_search_dir, "uk_english.txt", SearchOption.AllDirectories));

                    CoreMerge.MergeLoc(input_lvl, output_lvl, theFiles);
                    break;

                case OperationMode.PS2_BF1AddonScript:
                    // This code operates as expected; but currently the PS2 crashes when reading the generated .lvl .
                    string[] neededFiles = new String[] {
                        ".\\bin\\luac_4.exe",
                        ".\\bin\\BF1_LevelPack.exe",
                        ".\\bin\\BF1_ScriptMunge.exe"
                    };
                    foreach (string nf in neededFiles)
                    {
                        if (!File.Exists(nf))
                        {
                            MessageBox.Show("Required files for operation:\r\n" + String.Join("\r\n", neededFiles), "Error, missing required files");
                            return;
                        }
                    }
                    StringBuilder builder = new StringBuilder();
                    builder.Append("print('PROCESS_ADDONS_PS2_BF1 start', 'debug')\r\n");

                    //string debugFile = "DEBUG\\DEBUG.lvl";
                    //if (File.Exists(debugFile))
                    //{
                    //    builder.Append("  ReadDataFile('addon\\debug\\debug.lvl'); \r\n");
                    //    builder.Append("  ScriptCB_DoFile('debug'); \r\n");
                    //}
                    string current = "";

                    for (int i = 0; i < 1000; i++)
                    {
                        current = string.Format("{0:D3}\\ADDON{0:D3}.lvl", i);
                        if (File.Exists(current))
                        {
                            builder.Append(String.Format("  ReadDataFile('addon\\{0:D3}\\addon{0:D3}.lvl'); \r\n", i));
                            builder.Append(String.Format("  ScriptCB_DoFile('addon{0:D3}'); \r\n", i));
                        }
                    }
                    builder.Append("print('PROCESS_ADDONS_PS2_BF1 end', 'debug')");

                    // copy to 'PROCESS_ADDONS_PS2_BF1.LUA'
                    String ps2LuaFileName = "PROCESS_ADDONS_PS2_BF1.LUA";

                    File.WriteAllText(Path.GetFullPath(ps2LuaFileName), builder.ToString());
                    // create the lvl with the 'CreateLvlForm'
                    CreateLvlForm lvlMaker = new CreateLvlForm();
                    lvlMaker.OverrideScriptMunge = Path.GetFullPath("bin\\BF1_ScriptMunge.exe");
                    lvlMaker.OverrideLevelPack   = Path.GetFullPath("bin\\BF1_LevelPack.exe");
                    File.Copy("bin\\luac_4.exe", ".\\luac.exe", true);     // ensure lua4 for BF1
                    lvlMaker.AddItem(ps2LuaFileName);
                    try
                    {
                        lvlMaker.CreateLvl(".\\", "PROCESS_ADDONS_PS2_BF1.LVL", "PS2", true);
                        RemoveLogFiles();
                    }
                    catch (Exception lvlExc)
                    {
                        Console.WriteLine("Error Creating PROCESS_ADDONS_PS2_BF1.LVL!" + lvlExc.Message);
                    }
                    finally
                    {
                        File.Delete(".\\luac.exe");
                        lvlMaker.Dispose();
                    }
                    break;
                }
            }
        }