Exemple #1
0
        private void TsmiOpenScript_Click(object sender, EventArgs e)
        {
            try
            {
                using (var ofd = new OpenFileDialog())
                {
                    ofd.Filter           = $"DNUP files (.{Constants.ScriptFileExtension})|*.{Constants.ScriptFileExtension}|All files (*.*)|*.*";
                    ofd.CheckFileExists  = true;
                    ofd.RestoreDirectory = true;

                    if (ofd.ShowDialog() == DialogResult.OK)
                    {
                        Script = JsonConvert.DeserializeObject <PatcherScript>(File.ReadAllText(ofd.FileName), new JsonSerializerSettings
                        {
                            DefaultValueHandling = DefaultValueHandling.Ignore,
                            NullValueHandling    = NullValueHandling.Ignore,
                            DateFormatString     = "dd.MM.yyyy"
                        });

                        ScriptEngineHelpers.ValidateScript(Script);

                        PatchList.Clear();

                        _patchCount = 0;

                        foreach (var patch in Script.PatchList)
                        {
                            patch.Name = $"Patch {_patchCount++}";

                            PatchList.Add(patch);
                        }

                        RefreshPatchList();

                        Text = $"Script Editor - ({ofd.FileName})";

                        _scriptFileName = ofd.FileName;

                        if (tabTargetOptions.SelectedIndex != 0)
                        {
                            tabTargetOptions.SelectedTab = tpTargetList;
                        }

                        cmbPatchList.SelectedIndex = 0;

                        grpPatchList.Enabled = true;

                        tsmiNewScript.Enabled    = true;
                        tsmiOpenScript.Enabled   = true;
                        tsmiCloseScript.Enabled  = true;
                        tsmiSaveScript.Enabled   = true;
                        tsmiSaveAsScript.Enabled = true;
                    }
                }
            }
            catch (Exception ex)
            {
                Helpers.ExceptionMessageBox(ex);
            }
        }
        private void FrmMain_Load(object sender, EventArgs e)
        {
            Text = Helpers.BuildTitle();

            Engine = new ScriptEngine();

            ScriptEngineHelpers.AddSpecialFoldersToPlaceholders();

            RefreshScripts();
        }
Exemple #3
0
        private void FrmMain_Load(object sender, EventArgs e)
        {
            Text = BuildTitle();

            Engine = new ScriptEngine();

            ScriptEngineHelpers.AddSpecialFoldersToPlaceholders();

            Engine.LoadAndParseScripts();

            cmbSoftware.Items.AddRange(Engine.GetSoftwareNames());

            if (cmbSoftware.Items.Count > 0)
            {
                cmbSoftware.SelectedIndex = 0;
            }
            else
            {
                SetLogVisible(Engine.IsLoadingError, Engine.IsLoadingError);
            }
        }
Exemple #4
0
        private void CheckScript()
        {
            Script.PatchList = PatchList;

            ScriptEngineHelpers.ValidateScript(Script);

            if (Script.PatcherOptions.Placeholders != null)
            {
                if (Script.PatcherOptions.Placeholders.Count == 0)
                {
                    Script.PatcherOptions.Placeholders = null;
                }
                else
                {
                    foreach (var placeholder in Script.PatcherOptions.Placeholders)
                    {
                        if (placeholder.Key == string.Empty)
                        {
                            throw new Exception($"Placeholder Key is empty!\r\nPlaceholder Value -> \"{placeholder.Value}\"");
                        }
                    }
                }
            }

            if (Script.PatchList != null)
            {
                if (Script.PatchList.Count == 0)
                {
                    throw new Exception("Patch List is Empty!");
                }

                foreach (var patch in Script.PatchList)
                {
                    if (patch.TargetList.Count == 0)
                    {
                        throw new Exception("Target List is Empty!");
                    }

                    foreach (var target in patch.TargetList)
                    {
                        switch (target.Action)
                        {
                        case ActionMethod.Patch:
                            target.Indices  = null;
                            target.Optional = null;
                            break;

                        case ActionMethod.Insert:
                            target.Optional = null;
                            break;

                        case ActionMethod.Replace:
                            target.Optional = null;
                            break;

                        case ActionMethod.Remove:
                            target.ILCodes  = null;
                            target.Optional = null;
                            break;

                        case ActionMethod.EmptyBody:
                            target.ILCodes  = null;
                            target.Indices  = null;
                            target.Optional = null;
                            break;

                        case ActionMethod.ReturnBody:
                            target.ILCodes = null;
                            target.Indices = null;
                            break;
                        }

                        if (target.Action == ActionMethod.Patch || target.Action == ActionMethod.Insert || target.Action == ActionMethod.Replace)
                        {
                            if (target.ILCodes != null && target.ILCodes.Count == 0)
                            {
                                throw new Exception($"Instructions are Empty!\r\nTarget -> {target.FullName}");
                            }
                        }

                        if (target.Indices != null)
                        {
                            bool checkIndices = false;

                            foreach (string index in target.Indices)
                            {
                                checkIndices = index == string.Empty;

                                if (checkIndices)
                                {
                                    if (target.Action == ActionMethod.Insert || target.Action == ActionMethod.Replace || target.Action == ActionMethod.Remove)
                                    {
                                        throw new Exception($"Indices are empty! -> {target.FullName}");
                                    }
                                }
                            }

                            if (checkIndices || target.Indices.Count == 0)
                            {
                                target.Indices = null;
                            }
                        }
                    }
                }
            }
        }