Beispiel #1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            ReflectedClass.CreateReflectedAssembly();

            List<ReflectedProperty> Properties = new List<ReflectedProperty>();

            IntProperty HealthProperty = new IntProperty("Health");
            Properties.Add(HealthProperty);

            FloatProperty MassProperty = new FloatProperty("Mass");
            MassProperty.Category = "Physics";
            Properties.Add(MassProperty);

            List<string> TeamValues = new List<string>(new string[] {
                "Humans",
                "Aliens",
                "Neutral",
            });
            Properties.Add(new EnumProperty("Team", "ETeam", TeamValues));

            ReflectedClass TestClass = ReflectedClass.Create("GameUnit", Properties);
            ReflectedClass.SaveReflectedAssembly();

            TestClassInstance = TestClass.Construct();
            Debug.WriteLine(TestClassInstance.ToString());

            PropertyInfo[] Members = TestClassInstance.GetType().GetProperties();
            foreach (PropertyInfo Prop in Members)
            {
                Debug.WriteLine("  {0} = {1}", Prop.Name, Prop.GetValue(TestClassInstance, null));
            }

            PropertyGridControl.SelectedObject = TestClassInstance;
        }
        public IAnimationJob CreateJob(Animator animator)
        {
            IAnimationJobBinder binder = (IAnimationJobBinder)s_Binder;
            TJob job = (TJob)binder.Create(animator, m_Constraint.data, m_Constraint);

            // Bind constraint job weight property
            job.jobWeight = FloatProperty.BindCustom(
                animator,
                PropertyUtils.ConstructCustomPropertyName(m_Constraint, ConstraintProperties.s_Weight)
                );

            return(job);
        }
        public static void RandFloat(PropertyCollection props, string propname, float min, float max, bool createIfMissing)
        {
            var prop = props.GetProp <FloatProperty>(propname);

            if (prop == null && createIfMissing)
            {
                prop = new FloatProperty(0, propname);
                props.Add(prop);
            }
            if (prop != null)
            {
                prop.Value = ThreadSafeRandom.NextFloat(min, max);
            }
        }
 public void SetProperty(FloatProperty property)
 {
     foreach (var mat in materials)
     {
         mat.SetFloat(property.name, property.val);
     }
     foreach (var r in renderers)
     {
         r.SetFloat(property.name, property.val);
     }
     if (toGlobal)
     {
         Shader.SetGlobalFloat(property.name, property.val);
     }
 }
        private void recalculateReachSpec(IExportEntry reachSpecExport, int calculatedProperDistance, float dirX, float dirY, float dirZ)
        {
            Unreal.PropertyCollection props = reachSpecExport.GetProperties();
            IntProperty    prop             = props.GetProp <IntProperty>("Distance");
            StructProperty directionProp    = props.GetProp <StructProperty>("Direction");
            FloatProperty  propX            = directionProp.GetProp <FloatProperty>("X");
            FloatProperty  propY            = directionProp.GetProp <FloatProperty>("Y");
            FloatProperty  propZ            = directionProp.GetProp <FloatProperty>("Z");

            prop.Value  = calculatedProperDistance;
            propX.Value = dirX;
            propY.Value = dirY;
            propZ.Value = dirZ;

            reachSpecExport.WriteProperties(props);
        }
        public void FloatPropertyWrite()
        {
            using (var stream = new MemoryStream())
                using (var writer = new BinaryWriter(stream))
                {
                    var prop = new FloatProperty(FloatName)
                    {
                        Value = FloatValue
                    };

                    prop.Serialize(writer, BuildVersion);

                    Assert.AreEqual(4, prop.SerializedLength);
                    CollectionAssert.AreEqual(FloatBytes, stream.ToArray());
                }
        }
Beispiel #7
0
        public float GetFloatProperty(string name, int index = 0, float?defaultValue = null)
        {
            FloatProperty p = GetPropertyByName <FloatProperty>(name, index);

            if (p == null && defaultValue == null)
            {
                throw new Exception($"No values found for {name}:{index}, and no defaults were given!");
            }
            else if (p == null)
            {
                return(defaultValue.Value);
            }
            else
            {
                return(p.value);
            }
        }
Beispiel #8
0
    void GenerateProperties()
    {
        PropertiesController controller = GetComponent <PropertiesController>();

        // Frontal area
        areaProperty = new FloatProperty(areaPropertyName, areaUnit, areaStartValue, areaMinValue, areaMaxValue, null, GetType().GetMethod("ScaleByArea"), GetType().GetMethod("AreaCost"), null, this);
        controller.uniProperties.floatProperty.Add(areaProperty);

        // Height
        heightProperty = new FloatProperty(heightPropertyName, heightUnit, heightStartValue, heightMinValue, heightMaxValue, null, GetType().GetMethod("SetUpHeight"), GetType().GetMethod("HeightCost"), null, this);
        controller.uniProperties.floatProperty.Add(heightProperty);

        // Number of blades
        bladesProperty = new IntProperty(bladesPropertyName, bladesUnit, bladesStartValue, bladesMinValue, bladesMaxValue, null, GetType().GetMethod("CreateBlades"), null, null, this);
        controller.uniProperties.intProperty.Add(bladesProperty);

        // Rated/Cutoff Speed
        ratedCutoffProperty = new MinMaxFloatProperty(RatedCutoffpropertyName, ratedCutoffUnit, ratedPropertyName, cutoffPropertyName, ratedProperty, cutOffProperty, ratedCutoffMin, ratedCuroffMax, null, null, null, null, null, null, null, null, this);
        controller.uniProperties.minMaxProperty.Add(ratedCutoffProperty);
    }
        /// <summary>
        /// Randomizes the export. Does not check CanRandomize()
        /// </summary>
        /// <param name="export"></param>
        /// <param name="option"></param>
        private static void RandomizeInternal(ExportEntry export, RandomizationOption option)
        {
            var props = export.GetProperties();
            ArrayProperty <StructProperty> m_aMorphFeatures = props.GetProp <ArrayProperty <StructProperty> >("m_aMorphFeatures");

            if (m_aMorphFeatures != null)
            {
                foreach (StructProperty morphFeature in m_aMorphFeatures)
                {
                    FloatProperty offset = morphFeature.GetProp <FloatProperty>("Offset");
                    if (offset != null)
                    {
                        //Debug.WriteLine("Randomizing morph face " + Path.GetFilePath(export.FileRef.FilePath) + " " + export.UIndex + " " + export.FullPath + " offset");
                        offset.Value = offset.Value * ThreadSafeRandom.NextFloat(1 - (option.SliderValue / 3), 1 + (option.SliderValue / 3));
                    }
                }
            }

            ArrayProperty <StructProperty> m_aFinalSkeleton = props.GetProp <ArrayProperty <StructProperty> >("m_aFinalSkeleton");

            if (m_aFinalSkeleton != null)
            {
                foreach (StructProperty offsetBonePos in m_aFinalSkeleton)
                {
                    StructProperty vPos = offsetBonePos.GetProp <StructProperty>("vPos");
                    if (vPos != null)
                    {
                        //Debug.WriteLine("Randomizing morph face " + Path.GetFilePath(export.FileRef.FilePath) + " " + export.UIndex + " " + export.FullPath + " vPos");
                        FloatProperty x = vPos.GetProp <FloatProperty>("X");
                        FloatProperty y = vPos.GetProp <FloatProperty>("Y");
                        FloatProperty z = vPos.GetProp <FloatProperty>("Z");
                        x.Value = x.Value * ThreadSafeRandom.NextFloat(1 - option.SliderValue, 1 + option.SliderValue);
                        y.Value = y.Value * ThreadSafeRandom.NextFloat(1 - option.SliderValue, 1 + option.SliderValue);
                        z.Value = z.Value * ThreadSafeRandom.NextFloat(1 - (option.SliderValue / .85), 1 + (option.SliderValue / .85));
                    }
                }
            }

            export.WriteProperties(props);
        }
Beispiel #10
0
        void InitializeProperties()
        {
            FloatProperty[] attractorParms = new FloatProperty[3];
            attractorParms[0] = new FloatProperty("radius");
            attractorParms[1] = new FloatProperty("power", 0, 0, 4);
            attractorParms[2] = new FloatProperty("strength", 0, -6, 6);

            FloatProperty[] beamParms = new FloatProperty[3];
            beamParms[0] = new FloatProperty("radius");
            beamParms[1] = new FloatProperty("power", 0, 0, 4);
            beamParms[2] = new FloatProperty("strength", 0, -6, 6);

            FloatProperty[] twirlParms = new FloatProperty[4];
            twirlParms[0] = new FloatProperty("radius");
            twirlParms[1] = new FloatProperty("power", 0, 0, 4);
            twirlParms[2] = new FloatProperty("strength", 0, -6, 6);
            twirlParms[3] = new FloatProperty("angle", 0, -180, 180);

            propertyGroups    = new PropertyGroup[3];
            propertyGroups[0] = new PropertyGroup("Attractor", attractorParms);
            propertyGroups[1] = new PropertyGroup("Beam", beamParms);
            propertyGroups[2] = new PropertyGroup("Twirl", twirlParms);
        }
Beispiel #11
0
        private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (this.DataContext is FloatProperty)
            {
                FloatProperty prop = this.DataContext as FloatProperty;
                txtFloat.Text = prop.Value.ToString();
            }
            if (this.DataContext is Int32Property)
            {
                Int32Property prop = this.DataContext as Int32Property;
                txtFloat.Text = prop.Value.ToString();
            }
            if (this.DataContext is UInt32Property)
            {
                UInt32Property prop = this.DataContext as UInt32Property;



                // txtFloat.Text = string.Format("{0} {1}", prop.Value.ToHex(), InstanceRegistry.Instance.Find(prop.Value)).Trim();

                txtFloat.Text = string.Format("{0}", prop.Value.ToHex()).Trim();
            }
        }
        public static DotArkProperty ReadPropertyFromDisk(DotArkDeserializer d)
        {
            var ms = d.ms;

            //First, read a name and open it.
            ArkClassName name = ms.ReadArkClassname(d);

            //If this name is null, we've done something wrong.
            if (name == null)
            {
                throw new Exception("A property reading error occurred and got an unexpected NULL value; do not save");
            }

            //If the name is None, we've read to the final property and we can stop.
            if (name.IsNone())
            {
                return(null);
            }

            //Now, read the type
            ArkClassName type = ms.ReadArkClassname(d);

            //If the type is None or unreadable, something has gone wrong.
            if (type == null)
            {
                throw new Exception($"A property name was identified as {name.classname}, but the type failed to read.");
            }

            //Read in the index and size
            int size  = ms.ReadInt();
            int index = ms.ReadInt();

            //Based on the type, deserialize this.
            DotArkProperty prop;

            switch (type.classname)
            {
            case "IntProperty":
                prop = new IntProperty(d, index, size);
                break;

            case "UInt32Property":
                prop = new UInt32Property(d, index, size);
                break;

            case "Int8Property":
                prop = new Int8Property(d, index, size);
                break;

            case "Int16Property":
                prop = new Int16Property(d, index, size);
                break;

            case "UInt16Property":
                prop = new UInt16Property(d, index, size);
                break;

            case "UInt64Property":
                prop = new UInt64Property(d, index, size);
                break;

            case "BoolProperty":
                prop = new BoolProperty(d, index, size);
                break;

            case "ByteProperty":
                prop = new ByteProperty(d, index, size);
                break;

            case "FloatProperty":
                prop = new FloatProperty(d, index, size);
                break;

            case "DoubleProperty":
                prop = new DoubleProperty(d, index, size);
                break;

            case "NameProperty":
                prop = new NameProperty(d, index, size);
                break;

            case "ObjectProperty":
                prop = new ObjectProperty(d, index, size);
                break;

            case "StrProperty":
                prop = new StrProperty(d, index, size);
                break;

            case "StructProperty":
                prop = new StructProperty(d, index, size);
                break;

            case "ArrayProperty":
                prop = DotArkArray.ReadArray(d, index, size);     //UNFINISHED
                break;

            case "TextProperty":
                prop = new TextProperty(d, index, size);
                break;

            default:
                //Unknown
                throw new Exception($"Type {type.classname} was not a valid property type. Something failed to read.");
            }
            //Set additional values in the property and return it.
            prop.type  = type;
            prop.name  = name;
            prop.index = index;
            prop.size  = size;

            return(prop);
        }
 public override void debugFillProperties(DiagnosticPropertiesBuilder properties)
 {
     base.debugFillProperties(properties);
     properties.add(FloatProperty.lazy("maxExtent", () => this.maxExtent));
     properties.add(FloatProperty.lazy("child position", () => this.childMainAxisPosition(this.child)));
 }
Beispiel #14
0
        /// <summary>
        /// 解析普通属性
        /// </summary>
        private void ResolveDefaultProperty()
        {
            var errorFalg = false;
            /* [0] 属性定义行 */
            /* 属性定义样式 */

            /*
             *  int,float,string,bool: TYPE#PROPERTY_NAME(类型#属性名称#特殊设置)
             */
            var propertyRaw = scriptRawData.GetRow(0);
            /* 读取一次属性后,到下一个属性步进值,需要根据当前属性数据占用范围来计算 */
            /* 像Array或Array2D这样的数据占用的宽度会更大 */
            var dataSourceColumnIndex = 0;

            for (var columnIndex = 0; columnIndex < propertyRaw.Length; columnIndex++)
            {
                var propertyRawData = propertyRaw[columnIndex];
                var propertyData    = propertyRawData.Split(Helper.SETTING_SPLIT);
                if (propertyData[0].Equals(RawData.FILLING_DATA))
                {
                    continue;
                }
                /* 整竖行都是空,则忽略该竖行 */
                var columnIsEmpty = true;
                for (var y = 0; y < scriptRawData.height; y++)
                {
                    columnIsEmpty &= string.IsNullOrEmpty(scriptRawData[columnIndex, y]);
                    if (!columnIsEmpty)
                    {
                        break;
                    }
                }
                if (columnIsEmpty)
                {
                    dataSourceColumnIndex++;
                    continue;
                }
                if (string.IsNullOrEmpty(propertyRawData))
                {
                    continue;
                }
                var property = default(IProperty);
                var range    = new RawRange(1, dataSourceColumnIndex, 1, scriptRawData.height - 1);
                /* @开头,为自定义类型 */
                if (propertyData[0].StartsWith("@"))
                {
                    property = new DynamicProperty();
                }
                else
                {
                    /* 基础模式 */
                    if (generateData.scriptSetting.scriptObjectDataType == ScriptObjectDataType.BASE)
                    {
                        /* 数组模式 */
                        if (propertyData.Length == 3 && int.TryParse(propertyData[2], out var width))
                        {
                            switch (propertyData[0])
                            {
                            case "int":
                                property = new IntArrayProperty();
                                break;

                            case "float":
                                property = new FloatArrayProperty();
                                break;

                            case "string":
                                property = new StringArrayProperty();
                                break;

                            case "bool":
                                property = new BooleanArrayProperty();
                                break;

                            default: throw new System.Exception($"\"{generateData.loadFilePath}\"未定义类型\"{propertyData[0]}\"");
                            }
                            range.width = Convert.ToInt32(width);
                            /* 为了适应数据宽度超过属性栏宽度 */
                            columnIndex += range.width - 1;
                        }
                        /* 字典模式 */
                        else if (propertyData.Length == 3 && propertyData[2].ToLower().StartsWith("key"))
                        {
                            switch (propertyData[0])
                            {
                            case "int":
                                property = new IntKeyProperty();
                                break;

                            case "float":
                                property = new FloatKeyProperty();
                                break;

                            case "string":
                                property = new StringKeyProperty();
                                break;

                            default: throw new System.Exception($"\"{generateData.loadFilePath}\"未定义类型\"{propertyData[0]}\"");
                            }
                        }
                        /* 普通模式 */
                        else
                        {
                            switch (propertyData[0])
                            {
                            case "int":
                                property = new IntProperty();
                                break;

                            case "float":
                                property = new FloatProperty();
                                break;

                            case "string":
                                property = new StringProperty();
                                break;

                            case "bool":
                                property = new BooleanProperty();
                                break;

                            default: throw new System.Exception($"\"{generateData.loadFilePath}\"未定义类型\"{propertyData[0]}\"");
                            }
                        }
                    }
                    /* 二维数组模式 */
                    else if (generateData.scriptSetting.scriptObjectDataType == ScriptObjectDataType.ARRAY2D)
                    {
                        switch (propertyData[0])
                        {
                        case "int":
                            property = new IntArray2DProperty();
                            break;

                        case "float":
                            property = new FloatArray2DProperty();
                            break;

                        case "string":
                            property = new StringArray2DProperty();
                            break;

                        case "bool":
                            property = new BooleanArray2DProperty();
                            break;

                        default: throw new System.Exception($"\"{generateData.loadFilePath}\"未定义类型\"{propertyData[0]}\"");
                        }
                        range.width = Convert.ToInt32(propertyData[2]);
                    }
                    else if (generateData.scriptSetting.scriptObjectDataType == ScriptObjectDataType.ARRAY2DWITHNAME)
                    {
                        switch (propertyData[0])
                        {
                        case "int":
                            property = new IntArray2DWithnameProperty();
                            break;

                        case "float":
                            property = new FloatArray2DWithnameProperty();
                            break;

                        case "string":
                            property = new StringArray2DWithnameProperty();
                            break;

                        case "bool":
                            property = new BooleanArray2DWithnameProperty();
                            break;

                        default: throw new System.Exception($"\"{generateData.loadFilePath}\"未定义类型\"{propertyData[0]}\"");
                        }
                        /* +1为名称占用宽度 */
                        range.width = Convert.ToInt32(propertyData[2]) + 1;
                    }
                    else
                    {
                        throw new System.Exception($"未定义的类型\"{generateData.scriptSetting.scriptObjectDataType}\"");
                    }
                }
                property.InitProperty(propertyData, scriptRawData.GetRangeRawData(range));
                if (recordPropertyMap.ContainsKey(property.propertyName))
                {
                    CSVLoaderWindow.window.ShowNotification(new GUIContent($"文件\"{generateData.scriptSetting.scriptName}\"存在相同属性名称{property.propertyName}"));
                    generateData.SetState(BlockState.ERROR);
                    errorFalg = true;
                    break;
                }
                recordPropertyMap.Add(property.propertyName, property);
                dataSourceColumnIndex += range.width;

                if (property is DynamicProperty)
                {
                    // var dynamicProperty = property as DynamicProperty;
                    // generateData.dynamicDataMap.Add(dynamicProperty.dynamicTypeFullname, new GenerateData());
                    // generateData.dynamicDataList
                    // var dynamicPropertyInfo = new DynamicPropertyInfo();
                    // dynamicPropertyInfo.dynamicProperty = dynamicProperty;
                    // dynamicPropertyInfo.hasScripts = generateData.CheckHaveSameScript(dynamicProperty.dynamicTypeFullname, false);
                }
            }

            /* true: 字典模式 */

            var dictionaryFlag = false;

            foreach (var property in recordPropertyMap.Values)
            {
                if (property is IDictionaryKey)
                {
                    dictionaryFlag = true;
                    break;
                }
            }
            if (dictionaryFlag)
            {
                var keyCount = 0;
                foreach (var property in recordPropertyMap.Values)
                {
                    if (!(property is IDictionaryKey))
                    {
                        continue;
                    }
                    var key = property as IDictionaryKey;
                    if (key.keyFlag)
                    {
                        keyCount++;
                    }
                }
                if (keyCount <= 0)
                {
                    throw new System.Exception($"\"{generateData.csvFileInfo.Name}\"为字典类型,但未选择key");
                }
                else if (keyCount > 1)
                {
                    throw new System.Exception($"\"{generateData.csvFileInfo.Name}\"定义了多个属性作为key");
                }
            }
            if (!errorFalg)
            {
                GenerateScriptContent();
            }
        }
 protected override void InitializeProperties()
 {
     _agent = InitProperty <FloatProperty>(_propName);
 }
Beispiel #16
0
        public bool ApplyUpdate(IMEPackage package, PropertyCollection properties, MergeFileChange1 mfc)
        {
            var propKeys = PropertyName.Split('.');

            PropertyCollection operatingCollection = properties;

            int i = 0;

            while (i < propKeys.Length - 1)
            {
                var matchingProp = operatingCollection.FirstOrDefault(x => x.Name.Instanced == propKeys[i]);
                if (matchingProp is StructProperty sp)
                {
                    operatingCollection = sp.Properties;
                }

                // ARRAY PROPERTIES NOT SUPPORTED
                i++;
            }

            Log.Information($@"Applying property update: {PropertyName} -> {PropertyValue}");
            switch (PropertyType)
            {
            case @"FloatProperty":
                FloatProperty fp = new FloatProperty(float.Parse(PropertyValue, CultureInfo.InvariantCulture), propKeys.Last());
                operatingCollection.AddOrReplaceProp(fp);
                break;

            case @"IntProperty":
                IntProperty ip = new IntProperty(int.Parse(PropertyValue), propKeys.Last());
                operatingCollection.AddOrReplaceProp(ip);
                break;

            case @"BoolProperty":
                BoolProperty bp = new BoolProperty(bool.Parse(PropertyValue), propKeys.Last());
                operatingCollection.AddOrReplaceProp(bp);
                break;

            case @"NameProperty":
                var index      = 0;
                var baseName   = PropertyValue;
                var indexIndex = PropertyValue.IndexOf(@"|", StringComparison.InvariantCultureIgnoreCase);
                if (indexIndex > 0)
                {
                    baseName = baseName.Substring(0, indexIndex);
                    index    = int.Parse(baseName.Substring(indexIndex + 1));
                }

                NameProperty np = new NameProperty(new NameReference(baseName, index), PropertyName);
                operatingCollection.AddOrReplaceProp(np);
                break;

            case @"ObjectProperty":
                // This does not support porting in, only relinking existing items
                ObjectProperty op = new ObjectProperty(0, PropertyName);
                if (PropertyValue != null && PropertyValue != @"M3M_NULL")     //M3M_NULL is a keyword for setting it to null to satisfy the schema
                {
                    var entry = package.FindEntry(PropertyValue);
                    if (entry == null)
                    {
                        throw new Exception(M3L.GetString(M3L.string_interp_mergefile_failedToUpdateObjectPropertyItemNotInPackage, PropertyName, PropertyValue, PropertyValue, package.FilePath));
                    }
                    op.Value = entry.UIndex;
                }
                operatingCollection.AddOrReplaceProp(op);
                break;

            case @"EnumProperty":
                var          enumInfo = PropertyValue.Split('.');
                EnumProperty ep       = new EnumProperty(enumInfo[0], mfc.OwningMM.Game, PropertyName);
                ep.Value = NameReference.FromInstancedString(enumInfo[1]);
                operatingCollection.AddOrReplaceProp(ep);
                break;

            case @"StrProperty":
                var sp = new StrProperty(PropertyValue, propKeys.Last());
                operatingCollection.AddOrReplaceProp(sp);
                break;

            default:
                throw new Exception(M3L.GetString(M3L.string_interp_mergefile_unsupportedPropertyType, PropertyType));
            }
            return(true);
        }
Beispiel #17
0
 get => (bool)GetValue(FloatProperty); set => SetValue(FloatProperty, value);
Beispiel #18
0
 void Start()
 {
     this.floatProperty = (FloatProperty)this.Target;
     this.updateText();
 }
Beispiel #19
0
    public void SetValue(object value)
    {
        string typeName = value.GetType().ToString();

        switch (typeName)
        {
        case "byte":
        {
            if (type == EPropertyType.EPropertyType_Byte)
            {
                ByteProperty prop = this as ByteProperty;
                prop.SetValue((byte)value);
                return;
            }
        }
        break;

        case "bool":
        {
            if (type == EPropertyType.EPropertyType_Bool)
            {
                BoolProperty prop = this as BoolProperty;
                prop.SetValue((bool)value);
                return;
            }
        }
        break;

        case "short":
        {
            if (type == EPropertyType.EPropertyType_Short)
            {
                ShortProperty prop = this as ShortProperty;
                prop.SetValue((short)value);
                return;
            }
        }
        break;

        case "int":
        {
            if (type == EPropertyType.EPropertyType_Int)
            {
                IntProperty prop = this as IntProperty;
                prop.SetValue((int)value);
                return;
            }
        }
        break;

        case "long":
        {
            if (type == EPropertyType.EPropertyType_Long)
            {
                LongProperty prop = this as LongProperty;
                prop.SetValue((long)value);
                return;
            }
        }
        break;

        case "float":
        {
            if (type == EPropertyType.EPropertyType_Float)
            {
                FloatProperty prop = this as FloatProperty;
                prop.SetValue((float)value);
                return;
            }
        }
        break;

        case "double":
        {
            if (type == EPropertyType.EPropertyType_Double)
            {
                DoubleProperty prop = this as DoubleProperty;
                prop.SetValue((double)value);
                return;
            }
        }
        break;

        case "Vector2":
        {
            if (type == EPropertyType.EPropertyType_Vector2)
            {
                Vector2Property prop = this as Vector2Property;
                prop.SetValue((Vector2)value);
                return;
            }
        }
        break;

        case "Vector3":
        {
            if (type == EPropertyType.EPropertyType_Vector3)
            {
                Vector3Property prop = this as Vector3Property;
                prop.SetValue((Vector3)value);
                return;
            }
        }
        break;

        case "Vector4":
        {
            if (type == EPropertyType.EPropertyType_Vector4)
            {
                Vector4Property prop = this as Vector4Property;
                prop.SetValue((Vector4)value);
                return;
            }
        }
        break;

        case "Quaternion":
        {
            if (type == EPropertyType.EPropertyType_Quaternion)
            {
                QuaternionProperty prop = this as QuaternionProperty;
                prop.SetValue((Quaternion)value);
                return;
            }
        }
        break;

        case "Matrix4x4":
        {
            if (type == EPropertyType.EPropertyType_Matrix4x4)
            {
                Matrix4x4Property prop = this as Matrix4x4Property;
                prop.SetValue((Matrix4x4)value);
                return;
            }
        }
        break;

        case "Color":
        {
            if (type == EPropertyType.EPropertyType_Color)
            {
                ColorProperty prop = this as ColorProperty;
                prop.SetValue((Color)value);
                return;
            }
        }
        break;

        case "string":
        {
            if (type == EPropertyType.EPropertyType_String)
            {
                StringProperty prop = this as StringProperty;
                prop.SetValue((string)value);
                return;
            }
        }
        break;

        case "object":
        {
            if (type == EPropertyType.EPropertyType_Object)
            {
                m_value = value;
                return;
            }
        }
        break;
        }
        return;
    }
Beispiel #20
0
        public static UProperty ReadProp(IOMemoryStream ms, UAssetFile f, string arrayType, bool isStruct)
        {
            //Read the name
            long start = ms.position;

            //Read the remainder of the properties
            string name;
            int    u1;
            string type;
            int    u2;
            int    length;
            int    index;

            if (arrayType == null)
            {
                //Not an array
                name = ms.ReadNameTableEntry(f);

                //Return null if this is "None". That means we're done reading
                if (name == "None")
                {
                    return(null);
                }

                u1     = ms.ReadInt();
                type   = ms.ReadNameTableEntry(f);
                u2     = ms.ReadInt();
                length = ms.ReadInt();
                index  = ms.ReadInt();
            }
            else
            {
                name   = null;
                u1     = 0;
                type   = arrayType;
                u2     = 0;
                length = 0;
                index  = 0;
            }
            long payloadStart = ms.position;

            //Create the object
            UProperty u;

            switch (type)
            {
            case "ArrayProperty": u = new ArrayProperty(ms, f); break;

            case "BoolProperty": u = new BoolProperty(ms, f); break;

            case "ByteProperty": u = new ByteProperty(ms, f); break;

            case "DoubleProperty": u = new DoubleProperty(ms, f); break;

            case "FloatProperty": u = new FloatProperty(ms, f); break;

            case "Int16Property": u = new Int16Property(ms, f); break;

            case "Int8Property": u = new Int8Property(ms, f); break;

            case "IntProperty": u = new IntProperty(ms, f); break;

            case "NameProperty": u = new NameProperty(ms, f); break;

            case "ObjectProperty": u = new ObjectProperty(ms, f); break;

            case "StrProperty": u = new StrProperty(ms, f); break;

            case "StructProperty": u = new StructProperty(ms, f); break;

            case "TextProperty": u = new TextProperty(ms, f); break;

            case "UInt16Property": u = new UInt16Property(ms, f); break;

            case "UInt32Property": u = new UInt32Property(ms, f); break;

            case "UInt64Property": u = new UInt64Property(ms, f); break;

            default:
                throw new Exception($"FAILED TO READ UPROPERTY: Type {type} was not a valid type. Name={name}, u1={u1}, u2={u2}, length={length}, index={index}, position={start}");
            }

            //Set attributes
            u.name         = name;
            u.unknown1     = u1;
            u.type         = type;
            u.unknown2     = u2;
            u.length       = length;
            u.index        = index;
            u.start        = start;
            u.payloadStart = payloadStart;
            u.isArray      = arrayType != null;

            //Dump
            f.DebugDump("UProperty Reading", ConsoleColor.Green, "name", name, "u1", u1.ToString(), "type", type, "u2", u2.ToString(), "length", length.ToString(), "index", index.ToString(), "start", start.ToString(), "payloadStart", payloadStart.ToString());

            //Read
            u.Read(ms, f);

            //Log
            string msg = u.WriteString();

            f.Debug("UProperty Read " + type, msg, ConsoleColor.DarkGreen);

            return(u);
        }
Beispiel #21
0
        public static bool RandomizeExport(ExportEntry export, RandomizationOption option)
        {
            if (!CanRandomize(export))
            {
                return(false);
            }
            MERLog.Information($"[{Path.GetFileNameWithoutExtension(export.FileRef.FilePath)}] Randomizing movement interpolations for " + export.UIndex + ": " + export.InstancedFullPath);
            var props    = export.GetProperties();
            var posTrack = props.GetProp <StructProperty>("PosTrack");

            if (posTrack != null)
            {
                var points = posTrack.GetProp <ArrayProperty <StructProperty> >("Points");
                if (points != null)
                {
                    foreach (StructProperty s in points)
                    {
                        var outVal = s.GetProp <StructProperty>("OutVal");
                        if (outVal != null)
                        {
                            FloatProperty x = outVal.GetProp <FloatProperty>("X");
                            FloatProperty y = outVal.GetProp <FloatProperty>("Y");
                            FloatProperty z = outVal.GetProp <FloatProperty>("Z");
                            x.Value = x.Value * ThreadSafeRandom.NextFloat(1 - option.SliderValue, 1 + option.SliderValue);
                            y.Value = y.Value * ThreadSafeRandom.NextFloat(1 - option.SliderValue, 1 + option.SliderValue);
                            z.Value = z.Value * ThreadSafeRandom.NextFloat(1 - option.SliderValue, 1 + option.SliderValue);
                        }
                    }
                }
            }

            var eulerTrack = props.GetProp <StructProperty>("EulerTrack");

            if (eulerTrack != null)
            {
                var points = eulerTrack.GetProp <ArrayProperty <StructProperty> >("Points");
                if (points != null)
                {
                    foreach (StructProperty s in points)
                    {
                        var outVal = s.GetProp <StructProperty>("OutVal");
                        if (outVal != null)
                        {
                            FloatProperty x = outVal.GetProp <FloatProperty>("X");
                            FloatProperty y = outVal.GetProp <FloatProperty>("Y");
                            FloatProperty z = outVal.GetProp <FloatProperty>("Z");
                            if (x.Value != 0)
                            {
                                x.Value = x.Value * ThreadSafeRandom.NextFloat(1 - option.SliderValue, 1 + option.SliderValue);
                            }
                            else
                            {
                                x.Value = ThreadSafeRandom.NextFloat(0, ThreadSafeRandom.NextFloat(-1000 * option.SliderValue, 1000 * option.SliderValue));
                            }

                            if (y.Value != 0)
                            {
                                y.Value = y.Value * ThreadSafeRandom.NextFloat(1 - option.SliderValue, 1 + option.SliderValue);
                            }
                            else
                            {
                                y.Value = ThreadSafeRandom.NextFloat(0, ThreadSafeRandom.NextFloat(-1000 * option.SliderValue, 1000 * option.SliderValue));
                            }

                            if (z.Value != 0)
                            {
                                z.Value = z.Value * ThreadSafeRandom.NextFloat(1 - option.SliderValue, 1 + option.SliderValue);
                            }
                            else
                            {
                                z.Value = ThreadSafeRandom.NextFloat(0, ThreadSafeRandom.NextFloat(-1000 * option.SliderValue, 1000 * option.SliderValue));
                            }
                        }
                    }
                }
            }

            export.WriteProperties(props);
            return(true);
        }
        public static SerializedFields Parse(int length, BinaryReader reader)
        {
            var start  = reader.BaseStream.Position;
            var result = new SerializedFields();

            while (true)
            {
                var propertyName = reader.ReadLengthPrefixedString();
                if (propertyName == "None")
                {
                    break;
                }

                var fieldType = reader.ReadLengthPrefixedString();
                var size      = reader.ReadInt32();

                var index = reader.ReadInt32();

                int overhead;
                var before = reader.BaseStream.Position;
                switch (fieldType)
                {
                case ArrayProperty.TypeName:
                    result.Add(ArrayProperty.Parse(propertyName, index, reader, size, out overhead));
                    break;

                case FloatProperty.TypeName:
                    overhead = 1;
                    result.Add(FloatProperty.Parse(propertyName, index, reader));
                    break;

                case IntProperty.TypeName:
                    overhead = 1;
                    result.Add(IntProperty.Parse(propertyName, index, reader));
                    break;

                case ByteProperty.TypeName:
                    result.Add(ByteProperty.Parse(propertyName, index, reader, out overhead));
                    break;

                case EnumProperty.TypeName:
                    result.Add(EnumProperty.Parse(propertyName, index, reader, out overhead));
                    break;

                case BoolProperty.TypeName:
                    overhead = 2;
                    result.Add(BoolProperty.Parse(propertyName, index, reader));
                    break;

                case StrProperty.TypeName:
                    overhead = 1;
                    result.Add(StrProperty.Parse(propertyName, index, reader));
                    break;

                case NameProperty.TypeName:
                    overhead = 1;
                    result.Add(NameProperty.Parse(propertyName, index, reader));
                    break;

                case ObjectProperty.TypeName:
                    overhead = 1;
                    result.Add(ObjectProperty.Parse(propertyName, index, reader));
                    break;

                case StructProperty.TypeName:
                    result.Add(StructProperty.Parse(propertyName, index, reader, size, out overhead));
                    break;

                case MapProperty.TypeName:
                    result.Add(MapProperty.Parse(propertyName, index, reader, size, out overhead));
                    break;

                case TextProperty.TypeName:
                    overhead = 1;
                    result.Add(TextProperty.Parse(propertyName, index, reader));
                    break;

                default:
                    throw new NotImplementedException(fieldType);
                }
                var after = reader.BaseStream.Position;

                if (before + size + overhead != after)
                {
                    throw new InvalidOperationException($"Expected {size} bytes read but got {after - before - overhead}");
                }
            }

            var int1 = reader.ReadInt32();

            Trace.Assert(int1 == 0);

            var remainingBytes = start + length - reader.BaseStream.Position;

            if (remainingBytes > 0)
            {
                result.TrailingData = reader.ReadBytes((int)remainingBytes);
            }

            //if (remainingBytes == 4)
            ////if(result.Fields.Count > 0)
            //{
            //    var int2 = reader.ReadInt32();
            //}
            //else if (remainingBytes > 0 && result.Any(f => f is ArrayProperty && ((ArrayProperty)f).Type == StructProperty.TypeName))
            //{
            //    var unk = reader.ReadBytes((int)remainingBytes);
            //}
            //else if (remainingBytes > 4)
            //{
            //    var int2 = reader.ReadInt32();
            //    var str2 = reader.ReadLengthPrefixedString();
            //    var str3 = reader.ReadLengthPrefixedString();
            //}


            return(result);
        }
Beispiel #23
0
        /// <summary>
        /// Retrieves all block ITerminalProperty values.
        /// </summary>
        private void GetScrollableProps()
        {
            propBuf.Clear();
            TextProperty argProperty = null;

            TBlock.GetProperties(propBuf);

            foreach (ITerminalProperty prop in propBuf)
            {
                var control = prop as IMyTerminalControl;

                if (control != null && control.CanUseControl(TBlock))
                {
                    nameBuilder.Clear();
                    GetTooltipName(prop, nameBuilder);

                    if (nameBuilder.Length > 0)
                    {
                        if (prop is ITerminalProperty <StringBuilder> )
                        {
                            var textProp = prop as ITerminalProperty <StringBuilder>;

                            if (textProp.CanAccessValue(TBlock))
                            {
                                if (prop.Id == "ConsoleCommand")
                                {
                                    argProperty = TextProperty.GetProperty(nameBuilder, textProp, this);
                                }
                                else if (prop.Id == "Name" || prop.Id == "CustomName")
                                {
                                    blockProperties.Insert(0, TextProperty.GetProperty(nameBuilder, textProp, this));
                                }
                                else
                                {
                                    blockProperties.Add(TextProperty.GetProperty(nameBuilder, textProp, this));
                                }
                            }
                        }
                        if (prop is IMyTerminalControlCombobox)
                        {
                            var comboBox = prop as IMyTerminalControlCombobox;

                            if (comboBox.CanAccessValue(TBlock, comboItemBuffer))
                            {
                                blockProperties.Add(ComboBoxProperty.GetProperty(nameBuilder, comboBox, comboItemBuffer, this));
                            }
                        }
                        else if (prop is ITerminalProperty <bool> )
                        {
                            var boolProp = prop as ITerminalProperty <bool>;

                            if (boolProp.CanAccessValue(TBlock))
                            {
                                blockProperties.Add(BoolProperty.GetProperty(nameBuilder, boolProp, this));
                            }
                        }
                        else if (prop is ITerminalProperty <float> )
                        {
                            var floatProp = prop as ITerminalProperty <float>;

                            if (floatProp.CanAccessValue(TBlock))
                            {
                                blockProperties.Add(FloatProperty.GetProperty(nameBuilder, floatProp, this));
                            }
                        }
                        else if (prop is ITerminalProperty <Color> )
                        {
                            var colorProp = prop as ITerminalProperty <Color>;

                            if (colorProp.CanAccessValue(TBlock))
                            {
                                blockProperties.Add(ColorProperty.GetProperty(nameBuilder, colorProp, this));
                            }
                        }
                        else if (prop is ITerminalProperty <Vector3> && prop.Id.Contains("Color"))
                        {
                            var colorProp = prop as ITerminalProperty <Vector3>;

                            if (colorProp.CanAccessValue(TBlock))
                            {
                                blockProperties.Add(HsvColorProperty.GetProperty(nameBuilder, colorProp, this));
                            }
                        }
                    }
                }
            }

            if (argProperty != null)
            {
                blockProperties.Add(argProperty);
            }

            blockMembers.AddRange(blockProperties);
            comboItemBuffer.Clear();
        }
Beispiel #24
0
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>   Visit configuration float. </summary>
 /// <remarks>   Neil MacMullen, 18/02/2011. </remarks>
 /// <param name="node"> The node. </param>
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 protected override void VisitFloatProperty(FloatProperty node) {
     AppendLineIndented(node.Name + "=" + TextFile.ToString(node.Value) + ";");
     base.VisitFloatProperty(node);
 }
Beispiel #25
0
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>   Visit float property. </summary>
 /// <param name="node"> The node. </param>
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 protected virtual void VisitFloatProperty(FloatProperty node) {
     //nothing to be done for basic type
 }
Beispiel #26
0
 public BoolListProperty(int apiVersion, EventHandler handler, FloatProperty basis)
     : base(apiVersion, handler, basis)
 {
 }
Beispiel #27
0
 public bool equals(FloatProperty other)
 {
     return(this.GetValue() == other.GetValue());
 }