예제 #1
0
        public static void DoEdit(ChangeArgs args)
        {
            // collect characters
            AICCollection result = new AICCollection();

            foreach (Change c in Version.Changes)
            {
                if (!c.IsChecked || !(c is AICChange))
                {
                    continue;
                }

                AICCollection collection = ((AICChange)c).Collection;
                foreach (AICharacter aic in collection.Values)
                {
                    // topmost aics have priority
                    if (!result.ContainsKey(aic.Index))
                    {
                        result.Add(aic.Index, aic);
                    }
                }
            }

            CreateEdit(result).Activate(args);
        }
예제 #2
0
        public static void Activate(ChangeArgs args)
        {
            AICCollection coll;

            using (FileStream fs = new FileStream("vanilla.aic", FileMode.Open))
                coll = new AICCollection(fs);

            CreateEdit(coll).Activate(args);
        }
예제 #3
0
 public virtual void Activate(ChangeArgs args)
 {
     foreach (var header in headerList)
     {
         if (header.IsEnabled)
         {
             header.Activate(args);
         }
     }
 }
예제 #4
0
        public void Activate(ChangeArgs args)
        {
            this.labels.Clear();
            if (!editList.TrueForAll(e => e.Initialize(args)))
            {
                return;
            }

            editList.ForEach(e => e.Activate(args));
        }
        public override void Activate(ChangeArgs args)
        {
            double  value   = Parent is ValueHeader vHeader ? vHeader.Value : 0;
            BinArgs binArgs = new BinArgs(args.Data, this.Parent.Labels, value);

            foreach (BinElement e in elements)
            {
                if (e is IBinCollection group)
                {
                    foreach (BinElement ge in group.Collection)
                    {
                        ge.Write(binArgs);
                    }
                }
                else
                {
                    e.Write(binArgs);
                }
            }
        }
        public override bool Initialize(ChangeArgs args)
        {
            if (!GetAddresses(args.OriData, out int rawAddr, out int virtAddr))
            {
                return(false);
            }

            foreach (BinElement e in elements)
            {
                if (e is IBinCollection group)
                {
                    foreach (BinElement ge in group.Collection)
                    {
                        InitElement(ge, ref rawAddr, ref virtAddr, args.OriData);
                    }
                }
                else
                {
                    InitElement(e, ref rawAddr, ref virtAddr, args.OriData);
                }
            }

            return(true);
        }
예제 #7
0
 public virtual void Activate(ChangeArgs args)
 {
     if (multiChange != null)
     {
         Dictionary <string, Dictionary <string, object> > parameters = new Dictionary <string, Dictionary <string, object> >();
         foreach (var header in headerList)
         {
             parameters.Add(header.DescrIdent, new Dictionary <string, object>()
             {
                 { "isEnabled", header.IsEnabled },
                 { "value", (object)header is ValueHeader && header.IsEnabled ? (header as ValueHeader).Value : (object)header.IsEnabled }
             });
         }
         multiChange(parameters).Activate(args);
         return;
     }
     foreach (var header in headerList)
     {
         if (header.IsEnabled)
         {
             header.Activate(args);
         }
     }
 }
예제 #8
0
        static void DoBinaryChanges(string filePath, bool xtreme, Percentage perc)
        {
            fails.Clear();
            SectionEditor.Reset();

            // only take binary changes
            var           changes  = Version.Changes.Where(c => c.IsChecked && c is Change && !(c is ResourceChange) && !(c is StartTroopChange));
            List <Change> todoList = new List <Change>(changes);

            int    todoIndex = 0;
            double todoCount = 9 + todoList.Count; // +2 for AIprops +3 for read, +1 for version edit, +3 for writing data

            // read original data & section preparation
            byte[] oriData = File.ReadAllBytes(filePath);
            byte[] data    = (byte[])oriData.Clone();
            SectionEditor.Init(data);
            todoIndex += 3;

            perc.Set(todoIndex / todoCount);

            ChangeArgs args = new ChangeArgs(data, oriData);

            // change version display in main menu
            try
            {
                (xtreme ? Version.MenuChange_XT : Version.MenuChange).Activate(args);
            }
            catch (Exception e)
            {
                Debug.Error(e);
            }
            perc.Set(++todoIndex / todoCount);

            // change stuff
            foreach (Change change in todoList)
            {
                change.Activate(args);
                perc.Set(++todoIndex / todoCount);
            }
            AICChange.DoChange(args);
            StartTroopChange.DoChange(args);
            ResourceChange.DoChange(args);

            todoIndex += 2;
            perc.Set(todoIndex / todoCount);



            // Write everything to file
            data = SectionEditor.AttachSection(data);

            if (filePath.EndsWith(BackupFileEnding))
            {
                filePath = filePath.Remove(filePath.Length - BackupFileEnding.Length);
            }
            else
            {
                File.WriteAllBytes(filePath + BackupFileEnding, oriData); // create backup
            }
            File.WriteAllBytes(filePath, data);

            perc.Set(1);

            ShowFailures(filePath);
        }
예제 #9
0
        static void DoChanges(string filePath, bool xtreme, Percentage perc)
        {
            fails.Clear();
            SectionEditor.Reset();

            // only take binary changes
            var           changes  = Version.Changes.Where(c => c.IsChecked && c.GetType() == typeof(Change));
            List <Change> todoList = new List <Change>(changes);

            int    todoIndex = 0;
            double todoCount = 9 + todoList.Count; // +2 for AIprops +3 for read, +1 for version edit, +3 for writing data

            // read original data & section preparation
            byte[] oriData = File.ReadAllBytes(filePath);
            byte[] data    = (byte[])oriData.Clone();
            SectionEditor.Init(data);
            todoIndex += 3;

            perc.Set(todoIndex / todoCount);

            ChangeArgs args = new ChangeArgs(data, oriData);

            // change version display in main menu
            try
            {
                (xtreme ? Version.MenuChange_XT : Version.MenuChange).Activate(args);
            }
            catch (Exception e)
            {
                Debug.Error(e);
            }
            perc.Set(++todoIndex / todoCount);



            // change stuff
            foreach (Change change in todoList)
            {
                change.Activate(args);
                perc.Set(++todoIndex / todoCount);
            }



            // change AI properties
            AICChange.DoEdit(args);
            todoIndex += 2;
            perc.Set(todoIndex / todoCount);



            // Write everything to file

            data = SectionEditor.AttachSection(data);

            if (filePath.EndsWith(BackupFileEnding))
            {
                filePath = filePath.Remove(filePath.Length - BackupFileEnding.Length);
            }
            else
            {
                File.WriteAllBytes(filePath + BackupFileEnding, oriData); // create backup
            }

            File.WriteAllBytes(filePath, data);

            perc.Set(1);

            // Show failures
            if (fails.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("Version Differences in ");
                sb.Append(Path.GetFileName(filePath));
                sb.AppendLine(":");
                foreach (var f in fails)
                {
                    sb.AppendLine(f.Ident + " " + f.Type);
                }

                fails.Clear();
                Debug.Show(sb.ToString());
            }
        }
예제 #10
0
 public abstract bool Initialize(ChangeArgs args);
예제 #11
0
 public abstract void Activate(ChangeArgs args);
        static void DoBinaryChanges(string filePath, bool xtreme, Percentage perc)
        {
            fails.Clear();
            SectionEditor.Reset();

            string gameSeedsFolder = Path.Combine(Configuration.Path, GAME_SEEDS_FOLDER);

            if (!Directory.Exists(gameSeedsFolder))
            {
                Directory.CreateDirectory(gameSeedsFolder);
            }

            // Retrieve set of selected binary changes
            var           changes  = Version.Changes.Where(c => c.IsChecked && c is Change && !(c is ResourceChange) && !(c is StartTroopChange));
            List <Change> todoList = new List <Change>(changes);

            int    todoIndex = 0;
            double todoCount = 9 + todoList.Count; // +2 for AIprops +3 for read, +1 for version edit, +3 for writing data

            // Read original data & perform section preparation adding .ucp section to binary
            byte[] oriData = File.ReadAllBytes(filePath);
            byte[] data    = (byte[])oriData.Clone();
            SectionEditor.Init(data);
            todoIndex += 3;

            perc.Set(todoIndex / todoCount);

            ChangeArgs args = new ChangeArgs(data, oriData);

            // Change version display in main menu
            try
            {
                (xtreme ? Version.MenuChange_XT : Version.MenuChange).Activate(args);
            }
            catch (Exception e)
            {
                Debug.Error(e);
            }
            perc.Set(++todoIndex / todoCount);

            // Apply each selected binary change
            foreach (Change change in todoList)
            {
                change.Activate(args);
                perc.Set(++todoIndex / todoCount);
            }

            // Apply changes handled in their respective submodules
            AICChange.DoChange(args);
            StartTroopChange.DoChange(args);
            ResourceChange.DoChange(args);

            todoIndex += 2;
            perc.Set(todoIndex / todoCount);



            // Write everything to file
            data = SectionEditor.AttachSection(data);

            if (filePath.EndsWith(BackupFileEnding))
            {
                filePath = filePath.Remove(filePath.Length - BackupFileEnding.Length);
            }
            else
            {
                File.WriteAllBytes(filePath + BackupFileEnding, oriData); // create backup
            }
            File.WriteAllBytes(filePath, data);

            perc.Set(1);

            ShowFailures(filePath);
        }
예제 #13
0
 public override void Activate(ChangeArgs args)
 {
     args.Data = SectionEditor.GetBuffer();
     base.Activate(args);
 }