Esempio n. 1
0
        public static ContainerSaveId ReadFrom(IReader reader)
        {
            ContainerType containerType = (ContainerType)reader.ReadByte();
            int           num           = containerType == ContainerType.Dictionary ? 2 : 1;
            List <SaveId> saveIdList    = new List <SaveId>();

            for (int index = 0; index < num; ++index)
            {
                SaveId saveId = (SaveId)null;
                switch (reader.ReadByte())
                {
                case 0:
                    saveId = (SaveId)TypeSaveId.ReadFrom(reader);
                    break;

                case 1:
                    saveId = (SaveId)GenericSaveId.ReadFrom(reader);
                    break;

                case 2:
                    saveId = (SaveId)ContainerSaveId.ReadFrom(reader);
                    break;
                }
                saveIdList.Add(saveId);
            }
            SaveId keyId   = saveIdList[0];
            SaveId valueId = saveIdList.Count > 1 ? saveIdList[1] : (SaveId)null;

            return(new ContainerSaveId(containerType, keyId, valueId));
        }
Esempio n. 2
0
        public static GenericSaveId ReadFrom(IReader reader)
        {
            int           num1       = (int)reader.ReadByte();
            TypeSaveId    baseId     = TypeSaveId.ReadFrom(reader);
            byte          num2       = reader.ReadByte();
            List <SaveId> saveIdList = new List <SaveId>();

            for (int index = 0; index < (int)num2; ++index)
            {
                SaveId saveId = (SaveId)null;
                switch (reader.ReadByte())
                {
                case 0:
                    saveId = (SaveId)TypeSaveId.ReadFrom(reader);
                    break;

                case 1:
                    saveId = (SaveId)GenericSaveId.ReadFrom(reader);
                    break;

                case 2:
                    saveId = (SaveId)ContainerSaveId.ReadFrom(reader);
                    break;
                }
                saveIdList.Add(saveId);
            }
            return(new GenericSaveId(baseId, saveIdList.ToArray()));
        }
Esempio n. 3
0
        public static SaveId ReadSaveIdFrom(IReader reader)
        {
            byte   num    = reader.ReadByte();
            SaveId saveId = (SaveId)null;

            switch (num)
            {
            case 0:
                saveId = (SaveId)TypeSaveId.ReadFrom(reader);
                break;

            case 1:
                saveId = (SaveId)GenericSaveId.ReadFrom(reader);
                break;

            case 2:
                saveId = (SaveId)ContainerSaveId.ReadFrom(reader);
                break;
            }
            return(saveId);
        }
Esempio n. 4
0
        internal GenericTypeDefinition ConstructGenericStructDefinition(Type type)
        {
            TypeDefinition structDefinition = this.GetStructDefinition(type.GetGenericTypeDefinition());
            TypeSaveId     saveId1          = (TypeSaveId)structDefinition.SaveId;

            SaveId[] saveIds = new SaveId[type.GenericTypeArguments.Length];
            for (int index = 0; index < type.GenericTypeArguments.Length; ++index)
            {
                TypeDefinitionBase typeDefinition = this.GetTypeDefinition(type.GenericTypeArguments[index]);
                saveIds[index] = typeDefinition.SaveId;
            }
            GenericSaveId         saveId2 = new GenericSaveId(saveId1, saveIds);
            GenericTypeDefinition genericStructDefinition = new GenericTypeDefinition(type, saveId2);

            foreach (CustomField customField in structDefinition.CustomFields)
            {
                genericStructDefinition.AddCustomField(customField.Name, customField.SaveId);
            }
            genericStructDefinition.CollectFields();
            genericStructDefinition.CollectProperties();
            this.AddGenericStructDefinition(genericStructDefinition);
            return(genericStructDefinition);
        }
        private void GenerateForClassOrStruct(TypeDefinition typeDefinition)
        {
            Type   type1         = typeDefinition.Type;
            bool   isClass       = type1.IsClass;
            bool   flag1         = !isClass;
            bool   flag2         = this.CheckIfBaseTypeDefind(type1);
            string name1         = type1.Namespace;
            string str1          = type1.FullName.Replace('+', '.');
            string fullClassName = str1.Substring(name1.Length + 1, str1.Length - name1.Length - 1).Replace('+', '.');

            string[]      nestedClasses     = this.GetNestedClasses(fullClassName);
            NamespaceCode orCreateNamespace = this._codeGenerationContext.FindOrCreateNamespace(name1);
            string        str2      = nestedClasses[nestedClasses.Length - 1];
            ClassCode     classCode = (ClassCode)null;

            for (int index = 0; index < nestedClasses.Length; ++index)
            {
                string    className = nestedClasses[index];
                ClassCode clasCode  = new ClassCode();
                clasCode.IsPartial = true;
                if (index + 1 == nestedClasses.Length)
                {
                    clasCode.IsClass = isClass;
                }
                clasCode.AccessModifier = ClassCodeAccessModifier.DoNotMention;
                int genericInformation = this.GetClassGenericInformation(className);
                if (genericInformation >= 0)
                {
                    clasCode.IsGeneric        = true;
                    clasCode.GenericTypeCount = genericInformation;
                    className = className.Substring(0, className.Length - 2);
                }
                clasCode.Name = className;
                if (classCode != null)
                {
                    classCode.AddNestedClass(clasCode);
                }
                else
                {
                    orCreateNamespace.AddClass(clasCode);
                }
                classCode = clasCode;
            }
            TypeSaveId saveId        = (TypeSaveId)typeDefinition.SaveId;
            int        delegateCount = this._delegateCount;

            ++this._delegateCount;
            this._managerMethod.AddLine("var typeDefinition" + (object)delegateCount + " =  (global::TaleWorlds.SaveSystem.Definition.TypeDefinition)definitionContext.TryGetTypeDefinition(new global::TaleWorlds.SaveSystem.Definition.TypeSaveId(" + (object)saveId.Id + "));");
            if (!type1.IsGenericTypeDefinition && !type1.IsAbstract)
            {
                MethodCode methodCode = new MethodCode();
                methodCode.IsStatic        = true;
                methodCode.AccessModifier  = flag1 ? MethodCodeAccessModifier.Public : MethodCodeAccessModifier.Internal;
                methodCode.Name            = "AutoGeneratedStaticCollectObjects" + str2;
                methodCode.MethodSignature = "(object o, global::System.Collections.Generic.List<object> collectedObjects)";
                methodCode.AddLine("var target = (global::" + str1 + ")o;");
                methodCode.AddLine("target.AutoGeneratedInstanceCollectObjects(collectedObjects);");
                classCode.AddMethod(methodCode);
                this._managerMethod.AddLine("TaleWorlds.SaveSystem.Definition.CollectObjectsDelegate d" + (object)delegateCount + " = global::" + name1 + "." + fullClassName + "." + methodCode.Name + ";");
                this._managerMethod.AddLine(nameof(typeDefinition) + (object)delegateCount + ".InitializeForAutoGeneration(d" + (object)delegateCount + ");");
            }
            this._managerMethod.AddLine("");
            MethodCode methodCode1 = new MethodCode();

            if (flag2)
            {
                methodCode1.PolymorphismInfo = MethodCodePolymorphismInfo.Override;
                methodCode1.AccessModifier   = MethodCodeAccessModifier.Protected;
            }
            else if (!type1.IsSealed)
            {
                methodCode1.PolymorphismInfo = MethodCodePolymorphismInfo.Virtual;
                methodCode1.AccessModifier   = MethodCodeAccessModifier.Protected;
            }
            else
            {
                methodCode1.PolymorphismInfo = MethodCodePolymorphismInfo.None;
                methodCode1.AccessModifier   = MethodCodeAccessModifier.Private;
            }
            methodCode1.Name            = "AutoGeneratedInstanceCollectObjects";
            methodCode1.MethodSignature = "(global::System.Collections.Generic.List<object> collectedObjects)";
            if (flag2)
            {
                methodCode1.AddLine("base.AutoGeneratedInstanceCollectObjects(collectedObjects);");
                methodCode1.AddLine("");
            }
            foreach (MemberDefinition memberDefinition in typeDefinition.MemberDefinitions)
            {
                if (memberDefinition is FieldDefinition)
                {
                    FieldInfo fieldInfo = (memberDefinition as FieldDefinition).FieldInfo;
                    Type      fieldType = fieldInfo.FieldType;
                    string    name2     = fieldInfo.Name;
                    if (fieldType.IsClass || fieldType.IsInterface)
                    {
                        if (fieldType != typeof(string))
                        {
                            bool flag3         = false;
                            Type declaringType = fieldInfo.DeclaringType;
                            if (declaringType != type1)
                            {
                                flag3 = this.CheckIfTypeDefined(declaringType);
                            }
                            string str3 = "";
                            if (flag3)
                            {
                                str3 += "//";
                            }
                            string line = str3 + "collectedObjects.Add(this." + name2 + ");";
                            methodCode1.AddLine(line);
                        }
                    }
                    else if (!fieldType.IsClass && this._definitionContext.GetStructDefinition(fieldType) != null)
                    {
                        string str3          = "";
                        bool   flag3         = false;
                        Type   declaringType = fieldInfo.DeclaringType;
                        if (declaringType != type1)
                        {
                            flag3 = this.CheckIfTypeDefined(declaringType);
                        }
                        if (flag3)
                        {
                            str3 += "//";
                        }
                        string str4 = fieldType.FullName.Replace('+', '.');
                        string line = str3 + "global::" + str4 + ".AutoGeneratedStaticCollectObjects" + fieldType.Name + "(this." + name2 + ", collectedObjects);";
                        methodCode1.AddLine(line);
                    }
                }
            }
            methodCode1.AddLine("");
            foreach (MemberDefinition memberDefinition in typeDefinition.MemberDefinitions)
            {
                if (memberDefinition is PropertyDefinition)
                {
                    PropertyDefinition propertyDefinition = memberDefinition as PropertyDefinition;
                    PropertyInfo       propertyInfo       = propertyDefinition.PropertyInfo;
                    Type   propertyType = propertyDefinition.PropertyInfo.PropertyType;
                    string name2        = propertyInfo.Name;
                    if (propertyType.IsClass || propertyType.IsInterface)
                    {
                        if (propertyType != typeof(string))
                        {
                            bool flag3         = false;
                            Type declaringType = propertyInfo.DeclaringType;
                            if (declaringType != type1)
                            {
                                flag3 = this.CheckIfTypeDefined(declaringType);
                            }
                            string str3 = "";
                            if (flag3)
                            {
                                str3 += "//";
                            }
                            string line = str3 + "collectedObjects.Add(this." + name2 + ");";
                            methodCode1.AddLine(line);
                        }
                    }
                    else if (!propertyType.IsClass && this._definitionContext.GetStructDefinition(propertyType) != null)
                    {
                        bool flag3         = false;
                        Type declaringType = propertyInfo.DeclaringType;
                        if (declaringType != type1)
                        {
                            flag3 = this.CheckIfTypeDefined(declaringType);
                        }
                        string str3 = "";
                        if (flag3)
                        {
                            str3 += "//";
                        }
                        string str4 = propertyType.FullName.Replace('+', '.');
                        string line = str3 + "global::" + str4 + ".AutoGeneratedStaticCollectObjects" + propertyType.Name + "(this." + name2 + ", collectedObjects);";
                        methodCode1.AddLine(line);
                    }
                }
            }
            classCode.AddMethod(methodCode1);
            foreach (MemberDefinition memberDefinition in typeDefinition.MemberDefinitions)
            {
                if (!type1.IsGenericTypeDefinition)
                {
                    MethodCode methodCode2 = new MethodCode();
                    string     str3        = "";
                    Type       type2       = (Type)null;
                    switch (memberDefinition)
                    {
                    case PropertyDefinition _:
                        PropertyDefinition propertyDefinition = memberDefinition as PropertyDefinition;
                        str3  = propertyDefinition.PropertyInfo.Name;
                        type2 = propertyDefinition.PropertyInfo.DeclaringType;
                        break;

                    case FieldDefinition _:
                        FieldDefinition fieldDefinition = memberDefinition as FieldDefinition;
                        str3  = fieldDefinition.FieldInfo.Name;
                        type2 = fieldDefinition.FieldInfo.DeclaringType;
                        break;
                    }
                    bool flag3 = false;
                    if (type2 != type1)
                    {
                        flag3 = this.CheckIfTypeDefined(type2);
                    }
                    if (!flag3)
                    {
                        methodCode2.Name             = "AutoGeneratedGetMemberValue" + str3;
                        methodCode2.MethodSignature  = "(object o)";
                        methodCode2.IsStatic         = true;
                        methodCode2.AccessModifier   = MethodCodeAccessModifier.Internal;
                        methodCode2.PolymorphismInfo = MethodCodePolymorphismInfo.None;
                        methodCode2.ReturnParameter  = "object";
                        methodCode2.AddLine("var target = (global::" + str1 + ")o;");
                        methodCode2.AddLine("return (object)target." + str3 + ";");
                        classCode.AddMethod(methodCode2);
                        string str4 = "GetPropertyDefinitionWithId";
                        if (memberDefinition is FieldDefinition)
                        {
                            str4 = "GetFieldDefinitionWithId";
                        }
                        this._managerMethod.AddLine("{");
                        this._managerMethod.AddLine("var memberDefinition = typeDefinition" + (object)delegateCount + "." + str4 + "(new global::TaleWorlds.SaveSystem.Definition.MemberTypeId(" + (object)memberDefinition.Id.TypeLevel + "," + (object)memberDefinition.Id.LocalSaveId + "));");
                        this._managerMethod.AddLine("memberDefinition.InitializeForAutoGeneration(" + ("global::" + name1 + "." + fullClassName + "." + methodCode2.Name) + ");");
                        this._managerMethod.AddLine("}");
                        this._managerMethod.AddLine("");
                    }
                }
            }
        }
Esempio n. 6
0
 public GenericSaveId(TypeSaveId baseId, SaveId[] saveIds)
 {
     this.BaseId         = (SaveId)baseId;
     this.GenericTypeIDs = saveIds;
     this._stringId      = this.CalculateStringId();
 }