This is the object for storing .mod job data.
        /// <summary>
        /// Loads a .mod file from given file and returns a nullable boolean (True, null, False).
        /// </summary>
        /// <param name="file">.mod file to load.</param>
        /// <param name="modCount">REF: Total number of jobs loaded.</param>
        /// <param name="progbar">ProgressBar to increment/change during method.</param>
        /// <param name="ExternalCall">If true, certain functions are disabled/automated.</param>
        /// <returns>True if update is to be done automatically, false if not, and null if user requests to stop loading .mod.</returns>
        public static bool?LoadDotMod(string file, ref int modCount, ToolStripProgressBar progbar, bool ExternalCall)
        {
            bool AutoUpdate = false;

            // KFreon: Load from file
            using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read))
            {
                // KFreon: Attempt to get version
                fs.Seek(0, SeekOrigin.Begin);
                int    versionLength    = fs.ReadValueS32();
                long   countOffset      = fs.Seek(0, SeekOrigin.Current); // Just in case
                string version          = "";
                int    count            = -1;
                string ExecutingVersion = null;
                bool   validVersion     = false;
                if (versionLength > 20)     // KFreon: Version is definitely wrong
                {
                    ExecutingVersion = "";
                }
                else
                {
                    // KFreon: Do version checking
                    for (int i = 0; i < versionLength; i++)
                    {
                        version += (char)fs.ReadByte();
                    }

                    // KFreon: Get Executing Version and check validity of read .mod version
                    string vers;
                    ExecutingVersion = GetVersion(version, out vers, out validVersion);
                    version          = vers;

                    count = fs.ReadValueS32();

                    // KFreon: Check if update required
                    if (version != ExecutingVersion)
                    {
                        if (ExternalCall)
                        {
                            AutoUpdate = true;
                        }
                    }
                    else   // KFreon: Reset to null to signify success
                    {
                        ExecutingVersion = null;
                    }
                }


                // KFreon: Ask what to do about version
                if (ExecutingVersion != null) //&& !ExternalCall) // Heff: do we want to suppress this for external calls? should they always autoupdate?
                {                             // Seems better to keep it the current way, so that users get prompted if they load old .mods.
                    DialogResult dr = MessageBox.Show(Path.GetFileName(file) + " is old and unsupported by this version of ME3Explorer." + Environment.NewLine + "Click Yes to update .mod now, No to continue loading .mod, or Cancel to stop loading .mod", "Ancient .mod detected.", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                    if (dr == System.Windows.Forms.DialogResult.Cancel)
                    {
                        return(null);
                    }
                    else if (dr == System.Windows.Forms.DialogResult.Yes)
                    {
                        AutoUpdate = true;
                    }
                }

                /*else if (ExecutingVersion != null) // Heff: could use this for always updating if its an external call:
                 *  AutoUpdate = true;*/

                // KFreon: Reset stream position if necessary
                if (!validVersion)
                {
                    count = versionLength;
                    fs.Seek(countOffset, SeekOrigin.Begin);
                }

                // KFreon: Increment progress bar
                if (progbar != null)
                {
                    progbar.GetCurrentParent().Invoke(new Action(() =>
                    {
                        progbar.Value   = 0;
                        progbar.Maximum = count;
                    }));
                }

                // KFreon: Read Data
                DebugOutput.PrintLn("Found " + count + " Jobs", true);
                modCount += count;
                for (int i = 0; i < count; i++)
                {
                    // KFreon: Read name
                    ModMaker.ModJob md  = new ModMaker.ModJob();
                    int             len = fs.ReadValueS32();
                    md.Name = "";
                    for (int j = 0; j < len; j++)
                    {
                        md.Name += (char)fs.ReadByte();
                    }

                    // KFreon: Read script
                    len       = fs.ReadValueS32();
                    md.Script = "";
                    for (int j = 0; j < len; j++)
                    {
                        md.Script += (char)fs.ReadByte();
                    }

                    // KFreon: Read data
                    len = fs.ReadValueS32();
                    byte[] buff = fs.ReadBytes(len);
                    md.data = buff;
                    ModMaker.JobList.Add(md);
                    DebugOutput.PrintLn("Add Job \"" + md.Name + "\"", true);

                    if (progbar != null)
                    {
                        progbar.GetCurrentParent().Invoke(new Action(() => progbar.Increment(1)));
                    }
                }
            }
            return(AutoUpdate);
        }
Example #2
0
 /// <summary>
 /// Create a .mod job from current TPF texture object.
 /// </summary>
 /// <param name="ExecFolder">Path to ME3Explorer \exec\ folder.</param>
 /// <param name="pathBIOGame">Path to BIOGame.</param>
 /// <returns>New ModJob created from current TPF texture object.</returns>
 public ModMaker.ModJob CreateModJob(string ExecFolder, string pathBIOGame)
 {
     ModMaker.ModJob job = new ModMaker.ModJob();
     job.Name = (NumMips > 1 ? "Upscale (with MIP's): " : "Upscale: ") + TexName;
     job.Script = ModMaker.GenerateTextureScript(ExecFolder, Files, ExpIDs, TexName, GameVersion, pathBIOGame);
     job.data = Extract(null, true);
     return job;
 }
        /// <summary>
        /// Loads a .mod file from given file and returns a nullable boolean (True, null, False).
        /// </summary>
        /// <param name="file">.mod file to load.</param>
        /// <param name="modCount">REF: Total number of jobs loaded.</param>
        /// <param name="progbar">ProgressBar to increment/change during method.</param>
        /// <param name="ExternalCall">If true, certain functions are disabled/automated.</param>
        /// <returns>True if update is to be done automatically, false if not, and null if user requests to stop loading .mod.</returns>
        public static bool? LoadDotMod(string file, ref int modCount, ToolStripProgressBar progbar, bool ExternalCall)
        {
            bool AutoUpdate = false;

            // KFreon: Load from file
            using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read))
            {
                // KFreon: Attempt to get version
                fs.Seek(0, SeekOrigin.Begin);
                int versionLength = fs.ReadValueS32();
                long countOffset = fs.Seek(0, SeekOrigin.Current);  // Just in case
                string version = "";
                int count = -1;
                string ExecutingVersion = null;
                bool validVersion = false;
                if (versionLength > 20)     // KFreon: Version is definitely wrong
                    ExecutingVersion = "";
                else
                {
                    // KFreon: Do version checking
                    for (int i = 0; i < versionLength; i++)
                        version += (char)fs.ReadByte();

                    // KFreon: Get Executing Version and check validity of read .mod version
                    string vers;
                    ExecutingVersion = GetVersion(version, out vers, out validVersion);
                    version = vers;

                    count = fs.ReadValueS32();

                    // KFreon: Check if update required
                    if (version != ExecutingVersion)
                    {
                        if (ExternalCall)
                            AutoUpdate = true;
                    }
                    else   // KFreon: Reset to null to signify success
                        ExecutingVersion = null;
                }

                
                // KFreon: Ask what to do about version
                if (ExecutingVersion != null) //&& !ExternalCall) // Heff: do we want to suppress this for external calls? should they always autoupdate?
                {                                                 // Seems better to keep it the current way, so that users get prompted if they load old .mods.
                    DialogResult dr = MessageBox.Show(Path.GetFileName(file) + " is old and unsupported by this version of ME3Explorer." + Environment.NewLine + "Click Yes to update .mod now, No to continue loading .mod, or Cancel to stop loading .mod", "Ancient .mod detected.", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                    if (dr == System.Windows.Forms.DialogResult.Cancel)
                        return null;
                    else if (dr == System.Windows.Forms.DialogResult.Yes)
                        AutoUpdate = true;
                }
                /*else if (ExecutingVersion != null) // Heff: could use this for always updating if its an external call:
                    AutoUpdate = true;*/

                // KFreon: Reset stream position if necessary
                if (!validVersion)
                {
                    count = versionLength;
                    fs.Seek(countOffset, SeekOrigin.Begin);
                }

                // KFreon: Increment progress bar
                if (progbar != null)
                    progbar.GetCurrentParent().Invoke(new Action(() =>
                    {
                        progbar.Value = 0;
                        progbar.Maximum = count;
                    }));

                // KFreon: Read Data
                DebugOutput.PrintLn("Found " + count + " Jobs", true);
                modCount += count;
                for (int i = 0; i < count; i++)
                {
                    // KFreon: Read name
                    ModMaker.ModJob md = new ModMaker.ModJob();
                    int len = fs.ReadValueS32();
                    md.Name = "";
                    for (int j = 0; j < len; j++)
                        md.Name += (char)fs.ReadByte();

                    // KFreon: Read script
                    len = fs.ReadValueS32();
                    md.Script = "";
                    for (int j = 0; j < len; j++)
                        md.Script += (char)fs.ReadByte();

                    // KFreon: Read data
                    len = fs.ReadValueS32();
                    byte[] buff = fs.ReadBytes(len);
                    md.data = buff;
                    ModMaker.JobList.Add(md);
                    DebugOutput.PrintLn("Add Job \"" + md.Name + "\"", true);

                    if (progbar != null)
                        progbar.GetCurrentParent().Invoke(new Action(() => progbar.Increment(1)));
                }
            }
            return AutoUpdate;
        }