Ejemplo n.º 1
0
        private static CVariable GetRedProperty(IEditableVariable cvar, string propertyName)
        {
            foreach (var member in REDReflection.GetMembers(cvar))
            {
                try
                {
                    var redname = REDReflection.GetREDNameString(member);
                    if (redname != propertyName)
                    {
                        continue;
                    }

                    var prop  = cvar.accessor[cvar, member.Name];
                    var cprop = prop as CVariable;

                    return(cprop);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        public override void Read(BinaryReader file, uint size)
        {
            CVariable parsedvar = null;
            var       varsize   = file.ReadUInt32();
            var       buffer    = file.ReadBytes((int)varsize - 4);

            using (var ms = new MemoryStream(buffer))
                using (var br = new BinaryReader(ms))
                {
                    var nameId = br.ReadUInt16();
                    var typeId = br.ReadUInt16();

                    if (nameId == 0)
                    {
                        return;
                    }

                    var typename = cr2w.Names[typeId].Str;
                    var varname  = cr2w.Names[nameId].Str;

                    parsedvar = CR2WTypeManager.Create(typename, varname, cr2w, this);
                    parsedvar.IsSerialized = true;
                    parsedvar.Read(br, size);
                    this.SetREDName(varname);
                }

            Variant = parsedvar;
        }
Ejemplo n.º 3
0
        public static void SetFromDictionary(this IEditableVariable cvar, Dictionary <string, object> dictionary)
        {
            if (cvar is IREDVariant var)
            {
                var type = dictionary["Type"] as string;
                var name = "Variant";
                if (dictionary.ContainsKey("Name"))
                {
                    name = dictionary["Name"] as string;
                }

                var jvalue  = dictionary["Variant"];
                var variant = CR2WTypeManager.Create(type, name, cvar.Cr2wFile as IRed4EngineFile, cvar as CVariable);
                variant.IsSerialized = true;
                variant.SetFromJObject(jvalue);
                var.SetVariant(variant);

                return;
            }

            foreach (var(propertyName, value) in dictionary)
            {
                var redProperty = GetRedProperty(cvar, propertyName);
                if (redProperty == null)
                {
                    throw new InvalidParsingException("not a CVariable");
                }
                redProperty.SetFromJObject(value);
            }
        }
Ejemplo n.º 4
0
        private void treeView_FormatRow(object sender, FormatRowEventArgs e)
        {
            IEditableVariable model = (IEditableVariable)e.Model;

            if (model != null && (model.IsSerialized))
            {
                //if (!showOnlySerialized)
                {
                    int themeID   = (int)UIController.Get().Configuration.ColorTheme;
                    var forecolor = Color.FromArgb(UIController.Get().Configuration.CustomHighlightColor[themeID]);
                    e.Item.ForeColor = forecolor;
                }
            }
            else
            {
            }

            // check for errors
            // do this here until we have a proper error log
            if ((model is IPtrAccessor ptr && ptr.Reference == null) ||
                (model is IHandleAccessor handle && handle.ChunkHandle && handle.Reference == null))
            {
                if (model.IsSerialized)
                {
                    e.Item.ForeColor = Color.Red;
                }
            }
        }
Ejemplo n.º 5
0
 public override void RemoveVariable(IEditableVariable child)
 {
     if (child is CName v)
     {
         flags.Remove(v);
         v.ParentVariable = null;
     }
 }
Ejemplo n.º 6
0
 public override void RemoveVariable(IEditableVariable child)
 {
     if (child is T)
     {
         elements.Remove(child as T);
         UpdateNames();
     }
 }
Ejemplo n.º 7
0
 public override void AddVariable(IEditableVariable var)
 {
     if (var is CName)
     {
         var tag = (CName)var;
         tags.Add(tag);
     }
 }
Ejemplo n.º 8
0
        internal VariableListNode CreatePropertyLayout(IEditableVariable v)
        {
            var root = AddListViewItems(v);

            Root.Add(root);

            return(root);
        }
Ejemplo n.º 9
0
        public ChunkPropertyViewModel(IEditableVariable prop)
        {
            _property = prop;

            Name  = prop.REDName;
            Type  = prop.REDType;
            Value = prop.REDValue;
        }
Ejemplo n.º 10
0
 public override void RemoveVariable(IEditableVariable child)
 {
     if (child is CName)
     {
         var tag = (CName)child;
         tags.Remove(tag);
         tag.ParentVariable = null;
     }
 }
Ejemplo n.º 11
0
 public override void RemoveVariable(IEditableVariable child)
 {
     if (child is CVariable)
     {
         var v = (CVariable)child;
         array.Remove(v);
         v.ParentVariable = null;
     }
 }
Ejemplo n.º 12
0
 public override void AddVariable(IEditableVariable variable)
 {
     if (variable is T tvar)
     {
         variable.SetREDName(Elements.Count.ToString());
         tvar.IsSerialized = true;
         Elements.Add(tvar);
     }
 }
Ejemplo n.º 13
0
        public override bool CanRemoveVariable(IEditableVariable child)
        {
            //FIXME
            if (child is CVariable v)
            {
                //return flags.Contains(v);
            }

            return(true);
        }
Ejemplo n.º 14
0
 public override bool RemoveVariable(IEditableVariable child)
 {
     if (child is T tvar)
     {
         Elements.Remove(tvar);
         UpdateNames();
         return(true);
     }
     return(false);
 }
Ejemplo n.º 15
0
 public override bool RemoveVariable(IEditableVariable child)
 {
     if (child is CName)
     {
         var tag = (CName)child;
         tags.Remove(tag);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 16
0
        public override bool CanRemoveVariable(IEditableVariable child)
        {
            if (child is CName)
            {
                var tag = (CName)child;
                return(tags.Contains(tag));
            }

            return(false);
        }
Ejemplo n.º 17
0
        public override bool CanRemoveVariable(IEditableVariable child)
        {
            if (child is CVariable)
            {
                var v = (CVariable)child;
                return(array.Contains(v));
            }

            return(false);
        }
Ejemplo n.º 18
0
 public void RemoveVariable(IEditableVariable child)
 {
     if (child is T)
     {
         List.Remove((T)child);
         if (child is CVariable)
         {
             ((CVariable)child).ParentVariable = null;
         }
     }
 }
Ejemplo n.º 19
0
        public ChunkPropertyViewModel(IEditableVariable prop)
        {
            Property = prop;

            var disposable = Property.ChildrEditableVariables
                             .AsObservableChangeSet()
                             .Transform(GetViewModel)
                             .ObserveOn(RxApp.MainThreadScheduler)
                             .Bind(out _children)
                             .Subscribe();
        }
Ejemplo n.º 20
0
 public override void AddVariable(IEditableVariable var)
 {
     switch (var)
     {
     case CBytes b:
     {
         Bytes = new byte[b.Bytes.Length];
         Buffer.BlockCopy(b.Bytes, 0, Bytes, 0, b.Bytes.Length);
         break;
     }
     }
 }
Ejemplo n.º 21
0
        public override void RemoveVariable(IEditableVariable child)
        {
            if (child is CVariable)
            {
                var v = (CVariable)child;
                array.Remove(v);
                v.ParentVariable = null;

                if (fixedTypeArray)
                {
                    Type = "[" + array.Count + "]" + elementtype;
                }
            }
        }
Ejemplo n.º 22
0
        public static IEditableVariable CopyViaBuffer(IEditableVariable source, IEditableVariable destination)
        {
            using (MemoryStream ms = new MemoryStream())
                using (BinaryWriter bw = new BinaryWriter(ms))
                {
                    source.Write(bw);

                    ms.Position = 0;

                    using (BinaryReader reader = new BinaryReader(ms))
                    {
                        destination.Read(reader, (uint)ms.Length);
                    }
                }

            return(destination);
        }
Ejemplo n.º 23
0
        public static void SetFromDictionary(this IEditableVariable cvar, Dictionary <string, object> dictionary)
        {
            if (cvar is IREDVariant var)
            {
                var type = dictionary["Type"] as string;
                var name = "Variant";
                if (dictionary.ContainsKey("Name"))
                {
                    name = dictionary["Name"] as string;
                }

                var jvalue  = dictionary["Variant"];
                var variant = CR2WTypeManager.Create(type, name, cvar.Cr2wFile as IRed4EngineFile, cvar as CVariable);
                variant.IsSerialized = true;
                variant.SetFromJObject(jvalue);
                var.SetVariant(variant);

                return;
            }

            if (cvar is ICurveDataAccessor curve)
            {
                var interpolation     = dictionary["InterpolationType"];
                var interpolationByte = int.Parse(interpolation.ToString());

                curve.SetInterpolationType((EInterpolationType)interpolationByte);

                var link     = dictionary["LinkType"];
                var linkByte = int.Parse(link.ToString());
                curve.SetLinkType((ESegmentsLinkType)linkByte);

                curve.SetFromJObject(dictionary["Elements"]);

                return;
            }

            foreach (var(propertyName, value) in dictionary)
            {
                var redProperty = GetRedProperty(cvar, propertyName);
                if (redProperty == null)
                {
                    throw new InvalidParsingException("not a CVariable");
                }
                redProperty.SetFromJObject(value);
            }
        }
Ejemplo n.º 24
0
        public override CVariable SetValue(object val)
        {
            //if (val is CVariable)
            //{
            //    Variant = (CVariable)val;
            //}
            /*else*/ if (val is CVariant cvar)
            {
                var context = new CR2WCopyAction()
                {
                    DestinationFile = this.cr2w,
                    Parent          = this.ParentVar as CVariable
                };
                this.Variant = cvar.Variant.Copy(context);
            }

            return(this);
        }
Ejemplo n.º 25
0
        public override void Read(BinaryReader file, uint size)
        {
            var typeId   = file.ReadUInt16();
            var typename = cr2w.Names[typeId].Str;

            var varsize = file.ReadUInt32() - 4;

            if (varsize > 0)
            {
                Variant = CR2WTypeManager.Create(typename, nameof(Variant), cr2w, this);
                Variant.Read(file, varsize);
                Variant.IsSerialized = true;
            }
            else
            {
                // do nothing I guess?
            }
        }
Ejemplo n.º 26
0
        private void RemoveListElement(HotKeyEventArgs e)
        {
            // removing variables from arrays
            if (treeView.SelectedObjects.Count <= 0)
            {
                return;
            }

            var temp = new IEditableVariable[treeView.SelectedObjects.Count];

            treeView.SelectedObjects.CopyTo(temp, 0);

            // remove target chunks if any ptr
            var toberemovedchunks = new List <CR2WExportWrapper>();

            foreach (var selectedobject in treeView.SelectedObjects)
            {
                if (selectedobject is IChunkPtrAccessor chunkptraccessor &&
                    chunkptraccessor.ParentVar != null &&
                    chunkptraccessor.ParentVar.CanRemoveVariable(chunkptraccessor) &&
                    chunkptraccessor.Reference != null)
                {
                    toberemovedchunks.Add(chunkptraccessor.Reference);
                }
            }

            if (toberemovedchunks.Any())
            {
                if (viewModel.File is CR2WFile file)
                {
                    file.RemoveChunks(
                        toberemovedchunks,
                        false,
                        (CR2WFile.EChunkDisplayMode)viewModel.chunkDisplayMode);
                }
            }

            foreach (var node in temp)
            {
                node.ParentVar.RemoveVariable(node);
            }

            UpdateTreeListView();
        }
Ejemplo n.º 27
0
        private VariableListNode AddListViewItems(IEditableVariable v, VariableListNode parent = null,
                                                  int arrayindex = 0)
        {
            var node = new VariableListNode()
            {
                Variable = v,
                Children = new List <VariableListNode>(),
                Parent   = parent
            };
            var vars = v.GetEditableVariables();

            if (vars != null)
            {
                for (var i = 0; i < vars.Count; i++)
                {
                    node.Children.Add(AddListViewItems(vars[i], node, i));
                }
            }

            return(node);
        }
Ejemplo n.º 28
0
        public override CVariable SetValue(object val)
        {
            this.IsSerialized = true;
            switch (val)
            {
            case CVariantSizeNameType var:
                var context = new CR2WCopyAction()
                {
                    DestinationFile = this.cr2w,
                    Parent          = this.ParentVar as CVariable
                };
                this.Variant = var.Variant.Copy(context);
                this.SetREDName(var.REDName);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(this);
        }
Ejemplo n.º 29
0
        public static void WriteVariable(BinaryWriter file, IEditableVariable ivar)
        {
            if (ivar is CVariable cvar)
            {
                file.Write(cvar.GetnameId());
                file.Write(cvar.GettypeId());

                var pos = file.BaseStream.Position;
                file.Write((uint)0); // size placeholder

                cvar.Write(file);
                var endpos = file.BaseStream.Position;

                file.Seek((int)pos, SeekOrigin.Begin);
                var actualsize = (uint)(endpos - pos);
                file.Write(actualsize); // Write size
                file.Seek((int)endpos, SeekOrigin.Begin);
            }
            else
            {
                throw new SerializationException();
            }
        }
Ejemplo n.º 30
0
        public void CreatePropertyLayout(IEditableVariable v)
        {
            if (EditObject != v)
            {
                EditObject = v;


                if (v == null)
                {
                    treeView.Roots = null;
                    return;
                }

                var root = AddListViewItems(v);

                treeView.Roots = root.Children;
                treeView.RefreshObjects(root.Children);

                for (var depth = 0; ExpandOneLevel(depth, root.Children); depth++)
                {
                }
            }
        }