private static void LoadAIC(string fileName)
        {
            if (fileName.EndsWith(".aic"))
            {
                AICChange change = new AICChange(Path.GetFileName(fileName), true)
                {
                    new DefaultHeader(String.Empty, true, true)
                    {
                    }
                };
                changes.Add(change);
                return;
            }

            JavaScriptSerializer serializer = new JavaScriptSerializer();

            serializer.RegisterConverters(new ReadOnlyCollection <JavaScriptConverter>(new List <JavaScriptConverter>()
            {
                new AISerializer(errorMessages, errorHints)
            }));
            StreamReader reader = new StreamReader(new FileStream(fileName, FileMode.Open), Encoding.UTF8);
            string       text   = reader.ReadToEnd();

            reader.Close();

            string aicName = Path.GetFileNameWithoutExtension(fileName);

            try
            {
                if (availableSelection.ContainsKey(aicName))
                {
                    throw new Exception("AIC with the same filename has already been loaded");
                }

                AICollection ch     = serializer.Deserialize <AICollection>(text);;
                AICChange    change = new AICChange(aicName, true)
                {
                    new DefaultHeader("aic_" + aicName, true)
                    {
                    }
                };
                change.collection                     = ch;
                change.characters                     = ch.GetCharacters();
                change.customCharacterNames           = ch.GetCustomCharacterNames();
                availableSelection[change.TitleIdent] = ch.GetCharacters();
                changes.Add(change);
            }
            catch (AICSerializationException e)
            {
                File.AppendAllText("AICParsing.log", e.ToErrorString(fileName));
                throw e;
            }
            catch (Exception e)
            {
                File.AppendAllText("AICParsing.log", "\n" + aicName + ": " + e.Message + "\n");
                throw e;
            }
        }
Ejemplo n.º 2
0
 private void Refresh(object s, RoutedEventArgs e, TreeView view)
 {
     AICChange.Refresh(s, e);
     foreach (AICChange change in AICChange.changes)
     {
         change.InitUI();
         view.Items.Add(change.UIElement);
     }
 }
Ejemplo n.º 3
0
 private static void DeselectOthers(AICChange selected)
 {
     foreach (var change in changes)
     {
         if (change != selected)
         {
             change.titleBox.IsChecked = false;
         }
     }
 }
Ejemplo n.º 4
0
        private static ChangeHeader CreateEdit()
        {
            List <AICharacter> characterChanges = new List <AICharacter>();

            foreach (AICharacterName name in Enum.GetValues(typeof(AICharacterName)))
            {
                if (!currentSelection.ContainsKey(name))
                {
                    continue;
                }
                string    changeLocation = currentSelection[name];
                AICChange changeSource   = null;

                foreach (AICChange change in changes)
                {
                    if (change.TitleIdent == changeLocation)
                    {
                        changeSource = change;
                        break;
                    }
                }

                foreach (AICharacter character in changeSource.collection.AICharacters)
                {
                    if ((AICharacterName)Enum.Parse(typeof(AICharacterName), character.Name.ToString()) == name)
                    {
                        characterChanges.Add(character);
                        break;
                    }
                }
            }

            byte[] data;
            using (MemoryStream ms = new MemoryStream())
                using (BinaryWriter bw = new BinaryWriter(ms))
                {
                    foreach (AICharacter aic in characterChanges)
                    {
                        // mov eax, index
                        bw.Write((byte)0xB8);
                        bw.Write((int)aic._Name * 0x2A4);

                        // imul eax, 2A4

                        /*bw.Write((byte)0x69);
                         * bw.Write((byte)0xC0);
                         * bw.Write(0x2A4);*/

                        // add eax, esi
                        bw.Write((byte)0x01);
                        bw.Write((byte)0xF0);

                        // edit AI's properties
                        for (int i = 0; i < Enum.GetNames(typeof(AIPersonalityFieldsEnum)).Length; i++)
                        {
                            string       propertyName = Enum.GetName(typeof(AIPersonalityFieldsEnum), i);
                            PropertyInfo property     = typeof(AIPersonality).GetProperty("_" + propertyName);
                            if (property == null)
                            {
                                property = typeof(AIPersonality).GetProperty(propertyName);
                            }
                            if (property == null)
                            {
                                throw new Exception(propertyName);
                            }
                            object objValue = property.GetValue(aic.Personality, null);
                            int    value    = Convert.ToInt32(objValue);

                            // mov [eax + prop], value
                            bw.Write((byte)0xC7);
                            bw.Write((byte)0x80);
                            bw.Write((int)(i * 4));
                            bw.Write(value);
                        }
                    }
                    data = ms.ToArray();
                }

            // 004D1928
            BinaryEdit be = new BinaryEdit("ai_prop")
            {
                new BinAddress("call", 0x1B + 1, true),

                new BinSkip(0x1B),
                new BinHook(5)
                {
                    // ori code
                    0xE8, new BinRefTo("call"),

                    // edit ais
                    new BinBytes(data),
                }
            };

            return(new DefaultHeader("ai_prop")
            {
                be
            });
        }