Пример #1
0
        private void GenerateSetValue(Type t, string name, Meta.Item item)
        {
            var canInline =
                !t.IsGenericType && Utils.IsStruct(t) &&
                item != null && item.PropInfo == null &&
                !simpleValueReader.ContainsKey(t);

            if (canInline)
            {
                var meta = Meta.Get(t, options);
                if (meta.IsCompact && meta.Surrogate.FuncFrom == null && meta.AfterDeserialization.Actions.Count == 0)
                {
                    cw.Put("dg.EnsureClassDef(typeof({0}));\n", Utils.GetTypeSpec(t));
                    foreach (var yi in meta.Items)
                    {
                        GenerateSetValue(yi.Type, name + "." + yi.Name, yi);
                    }
                }
                else
                {
                    cw.Put("dg.ReadIntoStruct(ref {0});\n", name);
                }
                return;
            }
            cw.Put("{0} = ", name);
            GenerateValue(t, name);
        }
Пример #2
0
        private void CreateHeaderWidgets(CookingRulesCollection crc, string path, Meta.Item yi,
                                         Widget headerWidget, Widget overridesWidget, CookingRules rules)
        {
            SimpleText computedValueText;
            Button     createOrDestroyOverride = null;

            headerWidget.HitTestTarget = true;
            headerWidget.CompoundPostPresenter.Add(new DelegatePresenter <Widget>((widget) => {
                if (widget.IsMouseOver())
                {
                    widget.PrepareRendererState();
                    Renderer.DrawRect(
                        Vector2.Zero,
                        widget.Size,
                        Theme.Colors.SelectedBackground.Transparentify(0.8f));
                }
            }));
            Func <ITexture> btnTexture = () => IsOverridedByAssociatedCookingRules(crc, path, yi) ? IconPool.GetTexture("Filesystem.Cross") : IconPool.GetTexture("Filesystem.Plus");
            Widget          foldButton;

            headerWidget.Nodes.AddRange(
                (foldButton = CreateFoldButton(overridesWidget)),
                (new ThemedSimpleText {
                ForceUncutText = false,
                VAlignment = VAlignment.Center,
                HAlignment = HAlignment.Left,
                OverflowMode = TextOverflowMode.Ellipsis,
                LayoutCell = new LayoutCell {
                    StretchX = 1
                },
                Size = new Vector2(150, RowHeight),
                MinSize = new Vector2(100, RowHeight),
                MaxSize = new Vector2(200, RowHeight),
                Text = yi.Name,
            }),
                (computedValueText = new ThemedSimpleText {
                LayoutCell = new LayoutCell {
                    StretchX = 3
                },
                ForceUncutText = false,
                HAlignment = HAlignment.Left,
                Size = new Vector2(150, RowHeight),
                MinSize = new Vector2(50, RowHeight),
                MaxSize = new Vector2(300, RowHeight),
            }),
                (createOrDestroyOverride = new ToolbarButton {
                Texture = btnTexture(),
                Clicked = () => CreateOrDestroyFieldOverride(crc, path, yi, overridesWidget, createOrDestroyOverride),
            })
                );
            headerWidget.Clicked            = foldButton.Clicked;
            createOrDestroyOverride.Padding = Thickness.Zero;
            createOrDestroyOverride.Size    = createOrDestroyOverride.MinMaxSize = RowHeight * Vector2.One;
            if (IsCookingRulesFileItself(path))
            {
                rules = GetAssociatedCookingRules(crc, path);
            }
            computedValueText.AddChangeWatcher(() => yi.GetValue(rules.EffectiveRules),
                                               (o) => computedValueText.Text = rules.FieldValueToString(yi, yi.GetValue(rules.EffectiveRules)));
        }
Пример #3
0
 private void GenerateSetValue(Type t, string name, Meta.Item item)
 {
     if (!GenerateSetValueInline(t, name, item))
     {
         cw.Put("{0} = ", name);
         GenerateValue(t, name);
     }
 }
Пример #4
0
 private Action <object> MakeReadOrMergeFunc(Meta.Item yi)
 {
     if (yi.SetValue != null)
     {
         var rf = ReadValueFunc(yi.Type);
         return(obj => yi.SetValue(obj, rf()));
     }
     else
     {
         var mf = MergeValueFunc(yi.Type);
         return(obj => mf(yi.GetValue(obj)));
     }
 }
Пример #5
0
        /// <summary>
        /// The recursively add pieces to meta.
        /// </summary>
        /// <param name="reflex">The reflex.</param>
        /// <param name="destination">The destination.</param>
        /// <param name="BW">The bw.</param>
        /// <remarks></remarks>
        public static void RecursivelyAddPiecesToMeta(
            MetaSplitter.SplitReflexive reflex, ref List <Meta.Item> destination, ref BinaryWriter BW)
        {
            for (int x = 0; x < reflex.Chunks.Count; x++)
            {
                BW.BaseStream.Position = reflex.translation + (reflex.chunksize * x);
                BW.Write(reflex.Chunks[x].MS.ToArray(), 0, reflex.chunksize);
                for (int y = 0; y < reflex.Chunks[x].ChunkResources.Count; y++)
                {
                    Meta.Item i = reflex.Chunks[x].ChunkResources[y];

                    switch (i.type)
                    {
                    case Meta.ItemType.Reflexive:
                        MetaSplitter.SplitReflexive treflex = (MetaSplitter.SplitReflexive)i;
                        treflex.offset += reflex.translation + (reflex.chunksize * x);

                        treflex.translation = metasize;
                        treflex.chunkcount  = treflex.Chunks.Count;

                        metasize                += treflex.chunksize * treflex.chunkcount;
                        treflex.type             = Meta.ItemType.Reflexive;
                        treflex.intag            = TagIndex;
                        treflex.pointstoTagIndex = TagIndex;
                        destination.Add(treflex);
                        RecursivelyAddPiecesToMeta(treflex, ref destination, ref BW);
                        break;

                    case Meta.ItemType.Ident:
                        MetaSplitter.SplitIdent id = new MetaSplitter.SplitIdent((MetaSplitter.SplitIdent)i);
                        id.offset += reflex.translation + (reflex.chunksize * x);
                        id.intag   = TagIndex;
                        destination.Add(id);

                        break;

                    case Meta.ItemType.String:
                        MetaSplitter.SplitString ss = (MetaSplitter.SplitString)i;
                        ss.offset += reflex.translation + (reflex.chunksize * x);
                        ss.intag   = TagIndex;
                        destination.Add(ss);
                        break;
                    }
                }
            }
        }
Пример #6
0
        private string GetSerializeCond(Meta.Item yi)
        {
            if (yi.SerializeCond == null)
            {
                return(null);
            }
            var result =
                yi.SerializeIfMethod != null?
                string.Format("s.{0}()", yi.SerializeIfMethod.Name) :
                    !yi.DefaultValue.Equals(YuzuNoDefault.NoDefault) ?
                    string.Format("s.{0} != {1}", yi.Name, Utils.CodeValueFormat(yi.DefaultValue)) :
                    null;

            if (result == null && !yi.IsMember)
            {
                throw new NotImplementedException("Custom SerializeCondition is not supported");
            }
            return(result);
        }
Пример #7
0
 private Action <object, object> MakeFieldCloner(Meta.Item yi)
 {
     if (yi.SetValue != null)
     {
         var cloner = cl.GetCloner(yi.Type);
         if (yi.SerializeCond != null)
         {
             return (dst, src) => {
                        var v = yi.GetValue(src);
                        if (yi.SerializeCond(src, v))
                        {
                            yi.SetValue(dst, cloner(v));
                        }
             }
         }
         ;
         else
         {
             return((dst, src) => yi.SetValue(dst, cloner(yi.GetValue(src))));
         }
     }
     else
     {
         var merger = cl.GetMerger(yi.Type);
         if (yi.SerializeCond != null)
         {
             return (dst, src) => {
                        var v = yi.GetValue(src);
                        if (yi.SerializeCond(src, v))
                        {
                            merger(yi.GetValue(dst), v);
                        }
             }
         }
         ;
         else
         {
             return((dst, src) => merger(yi.GetValue(dst), yi.GetValue(src)));
         }
     }
 }
Пример #8
0
 public string FieldValueToString(Meta.Item yi, object value)
 {
     if (value == null)
     {
         return("");
     }
     if (yi.Name == "Bundles")
     {
         var vlist = (string[])value;
         return(string.Join(",", vlist));
     }
     else if (value is bool)
     {
         return((bool)value ? "Yes" : "No");
     }
     else if (value is DDSFormat)
     {
         return((DDSFormat)value == DDSFormat.DXTi ? "DXTi" : "RGBA8");
     }
     else if (yi.Name == "TextureAtlas")
     {
         var fi        = new System.IO.FileInfo(SourceFilename);
         var atlasName = fi.DirectoryName.Substring(The.Workspace.AssetsDirectory.Length).Replace('\\', '#');
         if (!atlasName.StartsWith("#"))
         {
             atlasName = "#" + atlasName;
         }
         if (atlasName == value.ToString())
         {
             return(CookingRulesBuilder.DirectoryNameToken);
         }
         else
         {
             return(value.ToString());
         }
     }
     else
     {
         return(value.ToString());
     }
 }
Пример #9
0
        private void InitClassDefUnordered(ReaderClassDef def, string typeName)
        {
            var theirCount = Reader.ReadInt16();
            int ourIndex = 0, requiredCountActiual = 0;

            for (int theirIndex = 0; theirIndex < theirCount; ++theirIndex)
            {
                var       theirName = Reader.ReadString();
                Meta.Item yi        = null;
                if (def.Meta.TagToItem.TryGetValue(theirName, out yi))
                {
                    if (!ReadCompatibleType(yi.Type))
                    {
                        throw Error(
                                  "Incompatible type for field {0}, expected {1}", theirName, yi.Type);
                    }
                    def.Fields.Add(new ReaderClassDef.FieldDef {
                        Name     = theirName,
                        OurIndex = def.Meta.Items.IndexOf(yi) + 1,
                        Type     = yi.Type,
                        ReadFunc = MakeReadOrMergeFunc(yi),
                    });
                    ourIndex += 1;
                    if (!yi.IsOptional)
                    {
                        requiredCountActiual += 1;
                    }
                }
                else
                {
                    AddUnknownFieldDef(def, theirName, typeName);
                }
            }
            if (requiredCountActiual != def.Meta.RequiredCount)
            {
                throw Error(
                          "Expected {0} required field(s), but found {1} for class {2}",
                          def.Meta.RequiredCount, requiredCountActiual, typeName);
            }
        }
Пример #10
0
 private static void CreatePropertyEditorForType(Meta.Item yi, IPropertyEditorParams editorParams)
 {
     if (yi.Type.IsEnum)
     {
         Activator.CreateInstance(typeof(EnumPropertyEditor <>).MakeGenericType(yi.Type), editorParams);
     }
     else if (yi.Type == typeof(string))
     {
         new StringPropertyEditor(editorParams);
     }
     else if (yi.Type == typeof(int))
     {
         new IntPropertyEditor(editorParams);
     }
     else if (yi.Type == typeof(bool))
     {
         new BooleanPropertyEditor(editorParams);
     }
     else if (yi.Type == typeof(float))
     {
         new FloatPropertyEditor(editorParams);
     }
 }
Пример #11
0
        private bool GenerateSetValueInline(Type t, string name, Meta.Item item)
        {
            if (t.IsGenericType || !Utils.IsStruct(t) || item == null || simpleValueReader.ContainsKey(t))
            {
                return(false);
            }
            var meta = Meta.Get(t, options);

            if (CanInline(meta))
            {
                cw.Put("dg.EnsureClassDef(typeof({0}));\n", Utils.GetTypeSpec(t));
                if (item.PropInfo == null)
                {
                    foreach (var yi in meta.Items)
                    {
                        GenerateSetValue(yi.Type, name + "." + yi.Name, yi);
                    }
                }
                else
                {
                    var tempStructName = cw.GetTempName();
                    cw.Put("var {0} = {1};\n", tempStructName, GenerateFactoryCall(meta));
                    foreach (var yi in meta.Items)
                    {
                        GenerateSetValue(yi.Type, tempStructName + "." + yi.Name, yi);
                    }
                    cw.Put("{0} = {1};\n", name, tempStructName);
                }
                return(true);
            }
            else if (item.PropInfo == null)
            {
                cw.Put("dg.ReadIntoStruct(ref {0});\n", name);
                return(true);
            }
            return(false);
        }
Пример #12
0
        private bool IsOverridedByAssociatedCookingRules(CookingRulesCollection crc, string path, Meta.Item yi)
        {
            var cr = GetAssociatedCookingRules(crc, path);

            return(cr != null && RulesForActiveTarget(cr).FieldOverrides.Contains(yi));
        }
Пример #13
0
        /// <summary>
        /// The map rebuilder.
        /// </summary>
        /// <param name="layout">The layout.</param>
        /// <remarks></remarks>
        public void MapRebuilder(ref MapLayout layout)
        {
            int totalshift = 0;

            // find new strings
            ///
            ///
            ArrayList strings = new ArrayList();

            foreach (string s in map.Strings.Name)
            {
                strings.Add(s);
            }

            for (int x = 0; x < MetaList.Count; x++)
            {
                Meta m = (Meta)MetaList[x];
                for (int y = 0; y < m.items.Count; y++)
                {
                    Meta.Item ii = m.items[y];
                    if (ii.type == Meta.ItemType.String)
                    {
                        Meta.String iii = (Meta.String)ii;

                        if (strings.IndexOf(iii.name) == -1)
                        {
                            strings.Add(iii.name);
                        }
                    }
                }
            }

            ///read ugh to meta
            ///
            ///
            map.OpenMap(MapTypes.Internal);
            Meta ughmeta = new Meta(map);

            ughmeta.ReadMetaFromMap(map.IndexHeader.metaCount - 1, false);
            IFPIO ifp = IFPHashMap.GetIfp("ugh!", map.HaloVersion);

            ughmeta.headersize = ifp.headerSize;
            ughmeta.scanner.ScanWithIFP(ref ifp);
            MetaList.Add(ughmeta);

            string temps = string.Empty;

            ///get model info
            int         tempint = layout.FindByType(RawDataContainerType.Model);
            LayOutChunk loc     = (LayOutChunk)layout.chunks[tempint];

            //////////////////////////////////////
            ///model raw data
            ///
            int modeshift = 0;

            loc.startoffset += totalshift;

            for (int x = 0; x < MetaList.Count; x++)
            {
                Meta m = (Meta)MetaList[x];
                if (m.rawType == RawDataContainerType.Model)
                {
                    BinaryWriter BW = new BinaryWriter(m.MS);
                    for (int y = 0; y < m.raw.rawChunks.Count; y++)
                    {
                        RawDataChunk r = m.raw.rawChunks[y];

                        if (r.rawLocation != MapTypes.Internal)
                        {
                            int tempintxx = r.offset;
                            if (r.rawLocation == MapTypes.MPShared)
                            {
                                tempintxx |= int.Parse("80000000", NumberStyles.HexNumber);
                            }
                            else if (r.rawLocation == MapTypes.SPShared)
                            {
                                tempintxx |= int.Parse("C0000000", NumberStyles.HexNumber);
                            }
                            else if (r.rawLocation == MapTypes.MainMenu)
                            {
                                tempintxx |= int.Parse("40000000", NumberStyles.HexNumber);
                            }

                            // writes new pointer to loaded meta
                            BW.BaseStream.Position = r.pointerMetaOffset;
                            BW.Write(tempintxx);
                            BW.Write(r.size);
                            continue;
                        }

                        int tempintx = loc.startoffset + modeshift;

                        // writes new pointer to loaded meta
                        BW.BaseStream.Position = r.pointerMetaOffset;
                        BW.Write(tempintx);
                        BW.Write(r.size);

                        // writes raw to map file
                        map.BW.BaseStream.Position = tempintx;
                        map.BW.BaseStream.Write(r.MS.ToArray(), 0, r.size);

                        // write padding
                        int    tempinty  = map.Functions.Padding(r.size, 512);
                        byte[] tempbytes = new byte[tempinty];
                        map.BW.Write(tempbytes);
                        modeshift += r.size + tempinty;
                    }

                    MetaList[x] = m;
                }
            }

            loc.size      = modeshift;
            loc.endoffset = loc.startoffset + loc.size;

            layout.chunks[tempint] = loc;

            int curroffset = loc.endoffset;

            /////////////////////////////////////
            /// bsp raw
            ///

            int bspcount = 0;

            int[] bspmagic          = new int[20];
            int[] bspmagicreflexive = new int[20];
            int[] bsprawoffset      = new int[20];
            int[] bsprawsize        = new int[20];
            int   totalbsprawsize   = 0;
            bool  found             = false;

            for (int x = 0; x < MetaList.Count; x++)
            {
                Meta m = (Meta)MetaList[x];
                if (m.type == "sbsp")
                {
                    BinaryWriter BW             = new BinaryWriter(m.MS);
                    int[]        tempoff        = new int[m.raw.rawChunks.Count];
                    int          thisbsprawsize = 0;
                    for (int y = 0; y < m.raw.rawChunks.Count; y++)
                    {
                        found = false;
                        RawDataChunk r = m.raw.rawChunks[y];
                        for (int yy = 0; yy < y; yy++)
                        {
                            RawDataChunk rr = m.raw.rawChunks[yy];
                            if (rr.offset == r.offset && rr.rawLocation == r.rawLocation)
                            {
                                tempoff[y] = tempoff[yy];

                                // writes new pointer to loaded meta
                                BW.BaseStream.Position = r.pointerMetaOffset;
                                BW.Write(tempoff[y]);
                                BW.Write(r.size);
                                found = true;
                                break;
                            }
                        }

                        if (found)
                        {
                            continue;
                        }

                        tempoff[y] = curroffset + thisbsprawsize;

                        // writes new pointer to loaded meta
                        BW.BaseStream.Position = r.pointerMetaOffset;
                        BW.Write(tempoff[y]);
                        BW.Write(r.size);

                        // writes raw to map file
                        map.BW.BaseStream.Position = curroffset + thisbsprawsize;
                        map.BW.BaseStream.Write(r.MS.ToArray(), 0, r.size);

                        // write padding
                        int    tempinty  = map.Functions.Padding(r.size, 512);
                        byte[] tempbytes = new byte[tempinty];
                        map.BW.Write(tempbytes);
                        thisbsprawsize  += r.size + tempinty;
                        totalbsprawsize += r.size + tempinty;
                    }

                    bsprawsize[bspcount]        = thisbsprawsize;
                    bspmagic[bspcount]          = m.magic;
                    bspmagicreflexive[bspcount] = m.magic + m.offset;

                    curroffset += bsprawsize[bspcount];

                    // bspmagic=m.magic;
                    // newmagicreflexive=bspmagic+m.offset;
                    bspcount   += 1;
                    MetaList[x] = m;
                }
            }

            //////////////////////////////////////
            ///weather raw data
            ///
            int weathershift = 0;

            for (int x = 0; x < MetaList.Count; x++)
            {
                Meta m = (Meta)MetaList[x];
                if (m.rawType == RawDataContainerType.Weather)
                {
                    BinaryWriter BW = new BinaryWriter(m.MS);
                    for (int y = 0; y < m.raw.rawChunks.Count; y++)
                    {
                        RawDataChunk r = m.raw.rawChunks[y];
                        if (r.rawLocation != MapTypes.Internal)
                        {
                            int tempintxx = r.offset;
                            if (r.rawLocation == MapTypes.MPShared)
                            {
                                tempintxx |= int.Parse("80000000", NumberStyles.HexNumber);
                            }
                            else if (r.rawLocation == MapTypes.SPShared)
                            {
                                tempintxx |= int.Parse("C0000000", NumberStyles.HexNumber);
                            }
                            else if (r.rawLocation == MapTypes.MainMenu)
                            {
                                tempintxx |= int.Parse("40000000", NumberStyles.HexNumber);
                            }

                            // writes new pointer to loaded meta
                            BW.BaseStream.Position = r.pointerMetaOffset;
                            BW.Write(tempintxx);
                            BW.Write(r.size);
                            continue;
                        }

                        int tempintx = curroffset + weathershift;

                        // writes new pointer to loaded meta
                        BW.BaseStream.Position = r.pointerMetaOffset;
                        BW.Write(tempintx);
                        BW.Write(r.size);

                        // writes raw to map file
                        map.BW.BaseStream.Position = tempintx;
                        map.BW.BaseStream.Write(r.MS.ToArray(), 0, r.size);

                        // write padding
                        int    tempinty  = map.Functions.Padding(r.size, 512);
                        byte[] tempbytes = new byte[tempinty];
                        map.BW.Write(tempbytes);
                        weathershift += r.size + tempinty;
                    }

                    MetaList[x] = m;
                }
            }

            curroffset += weathershift;

            //////////////////////////////////////
            ///decr raw data
            ///
            int decrshift = 0;

            for (int x = 0; x < MetaList.Count; x++)
            {
                Meta m = (Meta)MetaList[x];
                if (m.rawType == RawDataContainerType.DECR)
                {
                    BinaryWriter BW = new BinaryWriter(m.MS);
                    for (int y = 0; y < m.raw.rawChunks.Count; y++)
                    {
                        RawDataChunk r = m.raw.rawChunks[y];
                        if (r.rawLocation != MapTypes.Internal)
                        {
                            int tempintxx = r.offset;
                            if (r.rawLocation == MapTypes.MPShared)
                            {
                                tempintxx |= int.Parse("80000000", NumberStyles.HexNumber);
                            }
                            else if (r.rawLocation == MapTypes.SPShared)
                            {
                                tempintxx |= int.Parse("C0000000", NumberStyles.HexNumber);
                            }
                            else if (r.rawLocation == MapTypes.MainMenu)
                            {
                                tempintxx |= int.Parse("40000000", NumberStyles.HexNumber);
                            }

                            // writes new pointer to loaded meta
                            BW.BaseStream.Position = r.pointerMetaOffset;
                            BW.Write(tempintxx);
                            BW.Write(r.size);
                            continue;
                        }

                        int tempintx = curroffset + decrshift;

                        // writes new pointer to loaded meta
                        BW.BaseStream.Position = r.pointerMetaOffset;
                        BW.Write(tempintx);
                        BW.Write(r.size);

                        // writes raw to map file
                        map.BW.BaseStream.Position = tempintx;
                        map.BW.BaseStream.Write(r.MS.ToArray(), 0, r.size);

                        // write padding
                        int    tempinty  = map.Functions.Padding(r.size, 512);
                        byte[] tempbytes = new byte[tempinty];
                        map.BW.Write(tempbytes);
                        decrshift += r.size + tempinty;
                    }

                    MetaList[x] = m;
                }
            }

            curroffset += decrshift;

            //////////////////////////////////////
            ///prtm raw data
            ///
            int prtmshift = 0;

            for (int x = 0; x < MetaList.Count; x++)
            {
                Meta m = (Meta)MetaList[x];
                if (m.rawType == RawDataContainerType.PRTM)
                {
                    BinaryWriter BW = new BinaryWriter(m.MS);
                    for (int y = 0; y < m.raw.rawChunks.Count; y++)
                    {
                        RawDataChunk r = m.raw.rawChunks[y];
                        if (r.rawLocation != MapTypes.Internal)
                        {
                            int tempintxx = r.offset;
                            if (r.rawLocation == MapTypes.MPShared)
                            {
                                tempintxx |= int.Parse("80000000", NumberStyles.HexNumber);
                            }
                            else if (r.rawLocation == MapTypes.SPShared)
                            {
                                tempintxx |= int.Parse("C0000000", NumberStyles.HexNumber);
                            }
                            else if (r.rawLocation == MapTypes.MainMenu)
                            {
                                tempintxx |= int.Parse("40000000", NumberStyles.HexNumber);
                            }

                            // writes new pointer to loaded meta
                            BW.BaseStream.Position = r.pointerMetaOffset;
                            BW.Write(tempintxx);
                            BW.Write(r.size);
                            continue;
                        }

                        int tempintx = curroffset + prtmshift;

                        // writes new pointer to loaded meta
                        BW.BaseStream.Position = r.pointerMetaOffset;
                        BW.Write(tempintx);
                        BW.Write(r.size);

                        // writes raw to map file
                        map.BW.BaseStream.Position = tempintx;
                        map.BW.BaseStream.Write(r.MS.ToArray(), 0, r.size);

                        // write padding
                        int    tempinty  = map.Functions.Padding(r.size, 512);
                        byte[] tempbytes = new byte[tempinty];
                        map.BW.Write(tempbytes);
                        prtmshift += r.size + tempinty;
                    }

                    MetaList[x] = m;
                }
            }

            curroffset += prtmshift;

            //////////////////////////////////////
            ///jmad raw data
            ///
            int jmadshift = 0;

            for (int x = 0; x < MetaList.Count; x++)
            {
                Meta m = (Meta)MetaList[x];
                if (m.rawType == RawDataContainerType.Animation)
                {
                    BinaryWriter BW = new BinaryWriter(m.MS);
                    for (int y = 0; y < m.raw.rawChunks.Count; y++)
                    {
                        RawDataChunk r = m.raw.rawChunks[y];
                        if (r.rawLocation != MapTypes.Internal)
                        {
                            int tempintxx = r.offset;
                            if (r.rawLocation == MapTypes.MPShared)
                            {
                                tempintxx |= int.Parse("80000000", NumberStyles.HexNumber);
                            }
                            else if (r.rawLocation == MapTypes.SPShared)
                            {
                                tempintxx |= int.Parse("C0000000", NumberStyles.HexNumber);
                            }
                            else if (r.rawLocation == MapTypes.MainMenu)
                            {
                                tempintxx |= int.Parse("40000000", NumberStyles.HexNumber);
                            }

                            // writes new pointer to loaded meta
                            BW.BaseStream.Position = r.pointerMetaOffset - 4;
                            BW.Write(r.size);
                            BW.Write(tempintxx);
                            continue;
                        }

                        int tempintx = curroffset + jmadshift;

                        // writes new pointer to loaded meta
                        BW.BaseStream.Position = r.pointerMetaOffset - 4;
                        BW.Write(r.size);
                        BW.Write(tempintx);

                        // writes raw to map file
                        map.BW.BaseStream.Position = tempintx;
                        map.BW.BaseStream.Write(r.MS.ToArray(), 0, r.size);

                        // write padding
                        int    tempinty  = map.Functions.Padding(r.size, 512);
                        byte[] tempbytes = new byte[tempinty];
                        map.BW.Write(tempbytes);
                        jmadshift += r.size + tempinty;
                    }

                    MetaList[x] = m;
                }
            }

            curroffset += jmadshift;

            //////////////////////////////////////
            ///bsp meta data
            ///

            int[] bspmetaoffset = new int[20];
            int[] bspmetasize   = new int[20];

            int tempcount = 0;

            for (int x = 0; x < MetaList.Count; x++)
            {
                Meta m = (Meta)MetaList[x];
                if (m.type == "sbsp")
                {
                    Meta mm = (Meta)MetaList[3];
                    if (mm.type == "scnr")
                    {
                        BinaryWriter BWX      = new BinaryWriter(mm.MS);
                        int          tempoffx = map.BSP.sbsp[tempcount].pointerOffset;
                        BWX.BaseStream.Position = tempoffx;

                        BWX.Write(curroffset);
                        BWX.Write(m.size);
                        BWX.Write(bspmagicreflexive[tempcount]);
                        MetaList[3] = mm;
                    }

                    map.BW.BaseStream.Position = curroffset;
                    map.BW.BaseStream.Write(m.MS.ToArray(), 0, m.size);
                    bspmetasize[tempcount]   = m.size;
                    bspmetaoffset[tempcount] = curroffset;
                    curroffset += m.size;
                    tempcount++;
                }
            }

            ////stringnames1
            ///

            byte[] tempb = new byte[strings.Count * 128];
            map.BW.BaseStream.Position = curroffset;
            map.BW.BaseStream.Write(tempb, 0, strings.Count * 128);
            for (int x = 0; x < strings.Count; x++)
            {
                map.BW.BaseStream.Position = curroffset + (x * 128);
                char[] tempc = ((String)strings[x]).ToCharArray();
                map.BW.Write(tempc);
            }

            map.BW.BaseStream.Position = 352;
            map.BW.Write(curroffset);
            int newcount = strings.Count;

            map.BW.Write(newcount);

            curroffset += strings.Count * 128;

            int padding = map.Functions.Padding(curroffset, 512);

            tempb = new byte[padding];
            map.BW.BaseStream.Position = curroffset;
            map.BW.BaseStream.Write(tempb, 0, padding);
            curroffset += padding;

            ////stringsindex
            ///

            int tempnewsrsize = strings.Count * 4;

            map.BW.BaseStream.Position = curroffset;

            int temporary = 0;

            for (int x = 0; x < strings.Count; x++)
            {
                map.BW.BaseStream.Position = curroffset + (x * 4);
                map.BW.Write(temporary);
                temporary += ((String)strings[x]).Length + 1;
            }

            map.BW.BaseStream.Position = 364;
            map.BW.Write(curroffset);
            curroffset += tempnewsrsize;

            padding = map.Functions.Padding(curroffset, 512);
            tempb   = new byte[padding];
            map.BW.BaseStream.Position = curroffset;
            map.BW.BaseStream.Write(tempb, 0, padding);
            curroffset += padding;

            ////strings2
            ///

            temporary = 0;
            byte zero = 0;

            for (int x = 0; x < strings.Count; x++)
            {
                map.BW.BaseStream.Position = curroffset + temporary;
                char[] h = ((String)strings[x]).ToCharArray();
                map.BW.Write(h);
                map.BW.Write(zero);
                temporary += ((String)strings[x]).Length + 1;
            }

            map.BW.BaseStream.Position = 360;
            map.BW.Write(temporary);
            map.BW.BaseStream.Position = 368;
            map.BW.Write(curroffset);
            curroffset += temporary;

            padding = map.Functions.Padding(curroffset, 512);
            tempb   = new byte[padding];
            map.BW.BaseStream.Position = curroffset;
            map.BW.BaseStream.Write(tempb, 0, padding);
            curroffset += padding;

            ////file names
            ///

            temporary = 0;
            for (int x = 0; x < MetaList.Count; x++)
            {
                map.BW.BaseStream.Position = curroffset + temporary;
                char[] h = ((Meta)MetaList[x]).name.ToCharArray();
                map.BW.Write(h);
                map.BW.Write(zero);
                temporary += ((Meta)MetaList[x]).name.Length + 1;
            }

            map.BW.BaseStream.Position = 704;
            newcount = MetaList.Count;
            map.BW.Write(newcount);
            map.BW.Write(curroffset);
            map.BW.Write(temporary);
            curroffset += temporary;

            padding = map.Functions.Padding(curroffset, 512);
            tempb   = new byte[padding];
            map.BW.BaseStream.Position = curroffset;
            map.BW.BaseStream.Write(tempb, 0, padding);
            curroffset += padding;

            ////files index
            ///
            temporary = 0;
            for (int x = 0; x < MetaList.Count; x++)
            {
                map.BW.BaseStream.Position = curroffset + (x * 4);
                map.BW.Write(temporary);
                temporary += ((Meta)MetaList[x]).name.Length + 1;
            }

            map.BW.BaseStream.Position = 716;
            map.BW.Write(curroffset);

            curroffset += MetaList.Count * 4;
            padding     = map.Functions.Padding(curroffset, 512);
            tempb       = new byte[padding];
            map.BW.BaseStream.Position = curroffset;
            map.BW.BaseStream.Write(tempb, 0, padding);
            curroffset += padding;

            tempint = layout.FindByType(RawDataContainerType.UnicodeNamesIndex);
            for (int x = 0; x < 9; x++)
            {
                map.Unicode.ut[x].indexOffset = curroffset;
                if (x != 8)
                {
                    loc                        = (LayOutChunk)layout.chunks[tempint + (x * 2)];
                    loc.startoffset            = curroffset;
                    loc.endoffset              = loc.startoffset + loc.size;
                    map.BW.BaseStream.Position = loc.startoffset;
                    map.BW.BaseStream.Write(loc.MS.ToArray(), 0, loc.size);
                    layout.chunks[tempint + (x * 2)] = loc;
                    curroffset += loc.size;
                }

                map.Unicode.ut[x].tableOffset = curroffset;
                if (x != 8)
                {
                    LayOutChunk loc2 = (LayOutChunk)layout.chunks[tempint + (x * 2) + 1];
                    loc2.startoffset           = curroffset;
                    loc2.endoffset             = loc2.startoffset + loc.size;
                    map.BW.BaseStream.Position = loc2.startoffset;
                    map.BW.BaseStream.Write(loc2.MS.ToArray(), 0, loc2.size);
                    layout.chunks[tempint + (x * 2) + 1] = loc2;

                    curroffset += loc2.size;
                }
            }

            Meta         tempmatg = (Meta)MetaList[0];
            BinaryWriter BWXX     = new BinaryWriter(tempmatg.MS);

            for (int x = 0; x < 9; x++)
            {
                BWXX.BaseStream.Position = map.Unicode.ut[x].indexPointerOffset;
                BWXX.Write(map.Unicode.ut[x].indexOffset);
                BWXX.Write(map.Unicode.ut[x].tableOffset);
            }

            MetaList[0] = tempmatg;

            tempint         = layout.FindByType(RawDataContainerType.Crazy);
            loc             = (LayOutChunk)layout.chunks[tempint];
            loc.startoffset = curroffset;

            // loc.endoffset+=totalshift;
            map.BW.BaseStream.Position = loc.startoffset;
            map.BW.BaseStream.Write(loc.MS.ToArray(), 0, loc.size);
            map.BW.BaseStream.Position = 344;
            map.BW.Write(loc.startoffset);
            layout.chunks[tempint] = loc;

            curroffset += loc.size;

            //////////////////////////////////////
            ///bitmap raw data
            ///
            int bitmshift = 0;

            for (int x = 0; x < MetaList.Count; x++)
            {
                Meta m = (Meta)MetaList[x];
                if (m.rawType == RawDataContainerType.Bitmap)
                {
                    BinaryWriter BW = new BinaryWriter(m.MS);
                    for (int y = 0; y < m.raw.rawChunks.Count; y++)
                    {
                        RawDataChunk r = m.raw.rawChunks[y];
                        if (r.rawLocation != MapTypes.Internal)
                        {
                            int tempintxx = r.offset;
                            if (r.rawLocation == MapTypes.MPShared)
                            {
                                tempintxx |= int.Parse("80000000", NumberStyles.HexNumber);
                            }
                            else if (r.rawLocation == MapTypes.SPShared)
                            {
                                tempintxx |= int.Parse("C0000000", NumberStyles.HexNumber);
                            }
                            else if (r.rawLocation == MapTypes.MainMenu)
                            {
                                tempintxx |= int.Parse("40000000", NumberStyles.HexNumber);
                            }

                            // writes new pointer to loaded meta
                            BW.BaseStream.Position = r.pointerMetaOffset;
                            BW.Write(tempintxx);
                            BW.BaseStream.Position = r.pointerMetaOffset + 24;
                            BW.Write(r.size);
                            continue;
                        }

                        int tempintx = curroffset + bitmshift;

                        // writes new pointer to loaded meta
                        BW.BaseStream.Position = r.pointerMetaOffset;
                        BW.Write(tempintx);
                        BW.BaseStream.Position = r.pointerMetaOffset + 24;
                        BW.Write(r.size);

                        // writes raw to map file
                        map.BW.BaseStream.Position = tempintx;
                        map.BW.BaseStream.Write(r.MS.ToArray(), 0, r.size);

                        // write padding
                        int    tempinty  = map.Functions.Padding(r.size, 512);
                        byte[] tempbytes = new byte[tempinty];
                        map.BW.Write(tempbytes);
                        bitmshift += r.size + tempinty;
                    }

                    MetaList[x] = m;
                }
            }

            curroffset += bitmshift;

            tempint = layout.FindByType(RawDataContainerType.MetaIndex);

            loc             = (LayOutChunk)layout.chunks[tempint];
            loc.startoffset = curroffset;

            map.BW.BaseStream.Position = loc.startoffset;
            map.BW.BaseStream.Write(loc.MS.ToArray(), 0, loc.size);
            map.BW.BaseStream.Position = 16;
            map.BW.Write(loc.startoffset);
            newcount = MetaList.Count;
            map.BW.BaseStream.Position = loc.startoffset + 24;
            map.BW.Write(newcount);

            int tagsoff = map.IndexHeader.tagsOffset - map.MapHeader.indexOffset;

            map.PrimaryMagic   = map.IndexHeader.constant - (curroffset + 32);
            map.SecondaryMagic = map.PrimaryMagic + bspmetasize[0];

            // map.SecondaryMagic=map.BR.ReadInt32()-(loc.startoffset+map.MapHeader.metaStart);
            int where = curroffset + map.MapHeader.metaStart;
            tempcount = 0;
            int howfar = 0;

            int[] newoffset = new int[MetaList.Count];
            int[] newident  = new int[MetaList.Count];

            for (int x = 0; x < MetaList.Count; x++)
            {
                Meta m    = (Meta)MetaList[x];
                int  f**k = curroffset + tagsoff + (x * 16);

                char[] metatype = m.type.ToCharArray();
                Array.Reverse(metatype);
                int ident  = map.MetaInfo.Ident[0] + (x * 65537);
                int offset = where + howfar;

                if (x == MetaList.Count - 1)
                {
                    int wherex = curroffset + map.MapHeader.metaStart + 756;
                    map.BW.BaseStream.Position = wherex;
                    map.BW.Write(ident);
                }

                if (m.type == "phmo" | m.type == "coll" | m.type == "spas")
                {
                    int tempoffset = offset;
                    do
                    {
                        string tempss = tempoffset.ToString("X");
                        char[] tempc  = tempss.ToCharArray();
                        int    xxx    = tempc.Length;
                        if (m.padding == tempc[xxx - 1])
                        {
                            int diff = tempoffset - offset;
                            tempb = new byte[diff];
                            map.BW.BaseStream.Position = offset;
                            map.BW.Write(tempb);

                            int tempsize = ((Meta)MetaList[x - 1]).size;
                            tempsize += diff;
                            int temploc = f**k - 4;
                            map.BW.BaseStream.Position = temploc;
                            map.BW.Write(tempsize);

                            offset  = tempoffset;
                            howfar += diff;
                            break;
                        }

                        tempoffset++;
                    }while (temps != null);
                }

                newoffset[x] = offset;
                newident[x]  = ident;
                int offsetwithmagic = offset + map.SecondaryMagic;
                int size            = m.size;

                map.BW.BaseStream.Position = f**k;
                map.BW.Write(metatype);
                map.BW.Write(ident);

                if (m.type != "sbsp" && m.type != "ltmp")
                {
                    map.BW.Write(offsetwithmagic);
                    map.BW.Write(size);
                    howfar += m.size;
                    map.BW.BaseStream.Position = offset;
                    map.BW.BaseStream.Write(m.MS.ToArray(), 0, m.size);
                }
                else
                {
                    int zeroi = 0;
                    map.BW.Write(zeroi);
                    map.BW.Write(zeroi);
                    if (m.type == "sbsp")
                    {
                        offset       = bspmetaoffset[tempcount];
                        newoffset[x] = offset;
                        tempcount++;
                    }
                    else
                    {
                        continue;
                    }
                }
            }

            for (int x = 0; x < MetaList.Count; x++)
            {
                Meta m = (Meta)MetaList[x];
                for (int xx = 0; xx < m.items.Count; xx++)
                {
                    Meta.Item i = m.items[xx];
                    for (int e = 0; e < MetaList.Count; e++)
                    {
                        Meta tempm = (Meta)MetaList[e];
                        if (tempm.name == i.intagname && tempm.type == i.intagtype)
                        {
                            i.intag = e;
                            break;
                        }
                    }

                    if (i.intag != x)
                    {
                        continue;
                    }

                    switch (i.type)
                    {
                    case Meta.ItemType.Ident:
                        Meta.Ident id = (Meta.Ident)i;
                        id.ident = -1;
                        for (int e = 0; e < MetaList.Count; e++)
                        {
                            Meta tempm = (Meta)MetaList[e];
                            if (tempm.name == id.pointstotagname && tempm.type == id.pointstotagtype)
                            {
                                id.ident = newident[e];
                                break;
                            }
                        }

                        map.BW.BaseStream.Position = newoffset[x] + id.offset;
                        map.BW.Write(id.ident);
                        break;

                    case Meta.ItemType.Reflexive:
                        if (m.type != "sbsp")
                        {
                            Meta.Reflexive reflex = (Meta.Reflexive)i;
                            for (int e = 0; e < MetaList.Count; e++)
                            {
                                Meta tempm = (Meta)MetaList[e];
                                if (reflex.pointstotagname == tempm.name && reflex.pointstotagtype == tempm.type)
                                {
                                    reflex.pointstoTagIndex = e;
                                    break;
                                }
                            }

                            int newreflex = reflex.translation + newoffset[reflex.pointstoTagIndex] +
                                            map.SecondaryMagic;
                            map.BW.BaseStream.Position = newoffset[x] + reflex.offset;
                            map.BW.Write(reflex.chunkcount);
                            map.BW.Write(newreflex);
                        }

                        break;

                    case Meta.ItemType.String:
                        Meta.String s            = (Meta.String)i;
                        short       stringnum    = 0;
                        byte        stringlength = 0;
                        for (int e = 0; e < strings.Count; e++)
                        {
                            if (s.name == (string)strings[e])
                            {
                                stringnum    = (short)e;
                                stringlength = (byte)((string)strings[e]).Length;
                                break;
                            }
                        }

                        map.BW.BaseStream.Position = newoffset[x] + s.offset;
                        map.BW.Write(stringnum);
                        map.BW.Write(zero);
                        map.BW.Write(stringlength);
                        break;
                    }
                }
            }

            // totalshift+=howfar;
            int tempfilesize = curroffset + map.MapHeader.metaStart + howfar;

            // map.MapHeader.fileSize+totalshift+howfar-map.MetaInfo.Size [map.IndexHeader.metaCount-1];
            padding = map.Functions.Padding(tempfilesize, 512);
            tempb   = new byte[padding];
            map.BW.BaseStream.Position = tempfilesize;
            map.BW.Write(tempb);
            tempfilesize += padding;

            int olddifference = map.MapHeader.fileSize - (map.MapHeader.indexOffset);
            int difference    = tempfilesize - (map.MapHeader.indexOffset + totalshift);
            int metasize      = tempfilesize - (curroffset + map.MapHeader.metaStart);

            int combined = bspmetasize[0] + (tempfilesize - curroffset);

            map.BW.BaseStream.Position = 8;
            map.BW.Write(tempfilesize);
            map.BW.BaseStream.Position = 24;
            map.BW.Write(metasize);
            map.BW.Write(combined);

            map.BW.BaseStream.SetLength(tempfilesize);

            map.CloseMap();
        }
Пример #14
0
        /// <summary>
        /// The fix reflexives.
        /// </summary>
        /// <param name="metas">The metas.</param>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public static void FixReflexives(ArrayList metas, Map map)
        {
            int where = map.MapHeader.indexOffset + map.MapHeader.metaStart;

            int howfar = 0;

            int[] oldoffset = (int[])map.MetaInfo.Offset.Clone();
            int   padding   = 0;

            for (int x = 0; x < metas.Count; x++)
            {
                Meta m      = (Meta)metas[x];
                int  f**k   = map.IndexHeader.tagsOffset + (x * 16);
                int  offset = oldoffset[x] + padding;
                if (x > map.ChunkTools.TagIndex)
                {
                    offset += map.ChunkTools.SizeOfShift;
                }

                int offsetwithmagic = offset + map.SecondaryMagic;
                int size            = m.size;
                if (m.type == "phmo" | m.type == "coll" | m.type == "spas")
                {
                    int tempoffset = offset;
                    do
                    {
                        string tempss = tempoffset.ToString("X");
                        char[] tempc  = tempss.ToCharArray();
                        int    xxx    = tempc.Length;
                        if (m.padding == tempc[xxx - 1])
                        {
                            int    diff  = tempoffset - offset;
                            byte[] tempb = new byte[diff];
                            map.BW.BaseStream.Position = offset;
                            map.BW.Write(tempb);

                            int tempsize = ((Meta)metas[x - 1]).size;
                            tempsize += diff;
                            int temploc = map.IndexHeader.tagsOffset + ((x - 1) * 16) + 12;
                            map.BW.BaseStream.Position = temploc;
                            map.BW.Write(tempsize);

                            offset   = tempoffset;
                            howfar  += diff;
                            padding += diff;
                            break;
                        }

                        tempoffset++;
                    }while (f**k != -54454);
                }

                if (m.type != "sbsp" && m.type != "ltmp")
                {
                }
                else
                {
                    continue;
                }

                howfar += size;

                map.BW.BaseStream.Position = offset;
                map.BW.BaseStream.Write(m.MS.ToArray(), 0, m.size);

                map.MetaInfo.Offset[x] = offset;

                // if (x == 0x334) { MessageBox.Show("test"); }
                // if (x == 0) {
                // map.BW.BaseStream.Position = f**k + 8;
                // map.BW.Write(offsetwithmagic);
                // map.BW.Write(size);
                // continue; }

                // if (oldoffset[x-1] == oldoffset[x]) {
                // map.MetaInfo.Offset[x] = map.MetaInfo.Offset[x - 1];
                // }
                offsetwithmagic            = map.MetaInfo.Offset[x] + map.SecondaryMagic;
                map.BW.BaseStream.Position = f**k + 8;
                map.BW.Write(offsetwithmagic);
                map.BW.Write(size);
            }

            for (int x = 0; x < metas.Count; x++)
            {
                Meta m = (Meta)metas[x];
                if (m.type == "sbsp" || m.type == "ltmp")
                {
                    continue;
                }

                int offset = map.MetaInfo.Offset[x];
                for (int xx = 0; xx < m.items.Count; xx++)
                {
                    Meta.Item i = m.items[xx];
                    switch (i.type)
                    {
                    case Meta.ItemType.Reflexive:
                        Meta.Reflexive reflex    = (Meta.Reflexive)i;
                        int            newreflex = reflex.translation + offset + map.SecondaryMagic;
                        if (reflex.intag != m.TagIndex)
                        {
                            continue;
                        }

                        if (reflex.pointstoTagIndex != m.TagIndex)
                        {
                            newreflex = map.MetaInfo.Offset[reflex.pointstoTagIndex] + reflex.translation +
                                        map.SecondaryMagic;

                            // if (reflex.pointstoTagIndex > ChunkAdder.TagIndex) { newreflex += ChunkAdder.SizeOfShift; }
                        }

                        map.BW.BaseStream.Position = offset + reflex.offset;
                        map.BW.Write(reflex.chunkcount);
                        map.BW.Write(newreflex);
                        break;
                    }
                }
            }

            int prevsize = map.MapHeader.fileSize - (map.MapHeader.indexOffset + map.MapHeader.metaStart);
            int paddingx = map.Functions.Padding(howfar, 512);

            byte[] tempbb = new byte[paddingx];
            map.BW.BaseStream.Position = map.MapHeader.indexOffset + map.MapHeader.metaStart + howfar;
            map.BW.Write(tempbb);
            howfar += paddingx;

            int sizediff    = howfar - prevsize;
            int newfilesize = map.MapHeader.fileSize + sizediff;

            map.BW.BaseStream.Position = 8;
            map.BW.Write(newfilesize);
            int metasize = map.MapHeader.metaSize + sizediff;
            int combined = map.MapHeader.combinedSize + sizediff;

            map.BW.BaseStream.Position = 24;
            map.BW.Write(metasize);
            map.BW.Write(combined);
            map.FS.SetLength(newfilesize);
        }
Пример #15
0
 private void GenerateCloneItem(Meta meta, Meta.Item yi)
 {
     if (yi.SetValue != null)
     {
         var n            = "s." + yi.Name;
         var simpleCloner = yi.IsCopyable ? n : GenerateClonerSimple(yi.Type, n);
         if (simpleCloner != null)
         {
             cw.Put("result.{0} = {1};\n", yi.Name, simpleCloner);
             return;
         }
     }
     if (yi.Type.IsArray)
     {
         var e = yi.Type.GetElementType();
         cw.Put("if (s.{0} != null) {{\n", yi.Name);
         if (Cloner.IsCopyable(e, options))
         {
             cw.Put("result.{0} = ({1})s.{0}.Clone();\n", yi.Name, Utils.GetTypeSpec(yi.Type));
         }
         else if (yi.Type.GetArrayRank() == 1)
         {
             cw.Put("result.{0} = new {1}[s.{0}.Length];\n", yi.Name, Utils.GetTypeSpec(e));
             var indexName  = cw.GetTempName();
             var clonerCall = GenerateClonerInit(e, string.Format("s.{0}[{1}]", yi.Name, indexName));
             cw.Put("for(int {0} = 0; {0} < s.{1}.Length; ++{0})\n", indexName, yi.Name);
             cw.PutInd("result.{0}[{1}] = {2};\n", yi.Name, indexName, clonerCall);
         }
         else
         {
             var rank = yi.Type.GetArrayRank();
             Func <string, string> allDims = name =>
                                             string.Join(", ", Enumerable.Range(0, rank).Select(
                                                             dim => string.Format("s.{0}.{1}({2})", yi.Name, name, dim)));
             cw.Put("result.{0} = ({1})Array.CreateInstance(typeof({2}),\n",
                    yi.Name, Utils.GetTypeSpec(yi.Type), Utils.GetTypeSpec(e));
             cw.PutInd("new int[] {{ {0} }},\n", allDims("GetLength"));
             cw.PutInd("new int[] {{ {0} }});\n", allDims("GetLowerBound"));
             var indexNames    = Enumerable.Range(0, rank).Select(_ => cw.GetTempName()).ToArray();
             var indexNamesStr = string.Join(", ", indexNames);
             for (int dim = 0; dim < rank; ++dim)
             {
                 cw.Put(
                     "for(int {0} = s.{1}.GetLowerBound({2}); {0} <= s.{1}.GetLowerBound({2}); ++{0}) {{\n",
                     indexNames[dim], yi.Name, dim);
             }
             var clonerCall = GenerateClonerInit(
                 e, string.Format("s.{0}[{1}]", yi.Name, indexNamesStr));
             cw.Put("result.{0}[{1}] = {2};\n", yi.Name, indexNamesStr, clonerCall);
             for (int dim = 0; dim < rank; ++dim)
             {
                 cw.PutEndBlock();
             }
         }
         cw.PutEndBlock();
         return;
     }
     {
         var idict = Utils.GetIDictionary(yi.Type);
         if (idict != null)
         {
             var a = idict.GetGenericArguments();
             cw.Put("if (s.{0} != null) {{\n", yi.Name);
             if (yi.SetValue != null)
             {
                 cw.Put("result.{0} = new {1}();\n", yi.Name, Utils.GetTypeSpec(yi.Type));
             }
             var itemName    = cw.GetTempName();
             var clonerCallK = GenerateClonerInit(a[0], string.Format("{0}.Key", itemName));
             var clonerCallV = GenerateClonerInit(a[1], string.Format("{0}.Value", itemName));
             cw.Put("foreach (var {0} in s.{1})\n", itemName, yi.Name);
             cw.PutInd("result.{0}.Add({1}, {2});\n", yi.Name, clonerCallK, clonerCallV);
             cw.PutEndBlock();
             return;
         }
     }
     {
         var icoll = Utils.GetICollection(yi.Type);
         if (icoll != null)
         {
             if (yi.SetValue != null)
             {
                 cw.Put("if (s.{0} != null) {{\n", yi.Name);
                 cw.Put("result.{0} = new {1}();\n", yi.Name, Utils.GetTypeSpec(yi.Type));
             }
             else
             {
                 cw.Put("if (s.{0} != null && result.{0} != null) {{\n", yi.Name);
             }
             var a = icoll.GetGenericArguments();
             GenerateCloneCollection(
                 Meta.Get(yi.Type, options), icoll, a[0], "result." + yi.Name, "s." + yi.Name);
             cw.PutEndBlock();
             return;
         }
     }
     if (yi.SetValue != null)
     {
         cw.Put("result.{0} = ({1})cl.DeepObject(s.{0});\n", yi.Name, Utils.GetTypeSpec(yi.Type));
     }
     else
     {
         cw.Put("cl.GetMerger<{1}>()(result.{0}, s.{0});\n", yi.Name, Utils.GetTypeSpec(yi.Type));
     }
 }
Пример #16
0
        private void CreateOrDestroyFieldOverride(CookingRulesCollection crc, string path, Meta.Item yi, Widget overridesWidget, Button addRemoveField)
        {
            var overrided = IsOverridedByAssociatedCookingRules(crc, path, yi);
            var key       = NormalizePath(path);

            if (overrided)
            {
                var cr          = GetAssociatedCookingRules(crc, path);
                var targetRules = RulesForActiveTarget(cr);
                targetRules.FieldOverrides.Remove(yi);
                cr.Save();
                if (!cr.HasOverrides())
                {
                    var acr = GetAssociatedCookingRules(crc, cr.SourceFilename);
                    if (!acr.SourceFilename.EndsWith(key))
                    {
                        crc[key] = cr.Parent;
                    }
                    crc.Remove(NormalizePath(acr.SourceFilename));
                    System.IO.File.Delete(cr.SourceFilename);
                }
                List <Node> toUnlink = new List <Node>();
                foreach (var node in overridesWidget.Nodes)
                {
                    var c = node.Components.Get <PropertyOverrideComponent>();
                    if (c.Rules == cr && c.YuzuItem == yi)
                    {
                        toUnlink.Add(node);
                    }
                }
                foreach (var node in toUnlink)
                {
                    node.Unlink();
                }
                addRemoveField.Texture = IconPool.GetTexture("Filesystem.Plus");
            }
            else
            {
                var cr          = GetAssociatedCookingRules(crc, path, true);
                var targetRules = RulesForActiveTarget(cr);
                targetRules.Override(yi.Name);
                cr.Save();
                addRemoveField.Texture = IconPool.GetTexture("Filesystem.Cross");
                CreateOverridesWidgets(crc, key, activeTarget, yi, cr, overridesWidget);
            }
        }
Пример #17
0
 private void GenerateCloneItem(Meta meta, Meta.Item yi)
 {
     if (yi.SetValue != null)
     {
         var n            = "s." + yi.Name;
         var simpleCloner = yi.IsCopyable ? n : GenerateClonerSimple(yi.Type, n);
         if (simpleCloner != null)
         {
             cw.Put("result.{0} = {1};\n", yi.Name, simpleCloner);
             return;
         }
     }
     if (yi.Type.IsArray)
     {
         var e = yi.Type.GetElementType();
         cw.Put("if (s.{0} != null) {{\n", yi.Name);
         cw.Put("result.{0} = new {1}[s.{0}.Length];\n", yi.Name, Utils.GetTypeSpec(e));
         if (Cloner.IsCopyable(e, options))
         {
             cw.Put("Array.Copy(s.{0}, result.{0}, s.{0}.Length);\n", yi.Name);
         }
         else
         {
             var indexName  = cw.GetTempName();
             var clonerCall = GenerateClonerInit(e, string.Format("s.{0}[{1}]", yi.Name, indexName));
             cw.Put("for(int {0} = 0; {0} < s.{1}.Length; ++{0})\n", indexName, yi.Name);
             cw.PutInd("result.{0}[{1}] = {2};\n", yi.Name, indexName, clonerCall);
         }
         cw.Put("}\n");
         return;
     }
     {
         var idict = Utils.GetIDictionary(yi.Type);
         if (idict != null)
         {
             var a = idict.GetGenericArguments();
             cw.Put("if (s.{0} != null) {{\n", yi.Name);
             if (yi.SetValue != null)
             {
                 cw.Put("result.{0} = new {1}();\n", yi.Name, Utils.GetTypeSpec(yi.Type));
             }
             var itemName    = cw.GetTempName();
             var clonerCallK = GenerateClonerInit(a[0], string.Format("{0}.Key", itemName));
             var clonerCallV = GenerateClonerInit(a[1], string.Format("{0}.Value", itemName));
             cw.Put("foreach (var {0} in s.{1})\n", itemName, yi.Name);
             cw.PutInd("result.{0}.Add({1}, {2});\n", yi.Name, clonerCallK, clonerCallV);
             cw.Put("}\n");
             return;
         }
     }
     {
         var icoll = Utils.GetICollection(yi.Type);
         if (icoll != null)
         {
             if (yi.SetValue != null)
             {
                 cw.Put("if (s.{0} != null) {{\n", yi.Name);
                 cw.Put("result.{0} = new {1}();\n", yi.Name, Utils.GetTypeSpec(yi.Type));
             }
             else
             {
                 cw.Put("if (s.{0} != null && result.{0} != null) {{\n", yi.Name);
             }
             var a = icoll.GetGenericArguments();
             GenerateCloneCollection(
                 Meta.Get(yi.Type, options), icoll, a[0], "result." + yi.Name, "s." + yi.Name);
             cw.Put("}\n");
             return;
         }
     }
     if (yi.SetValue != null)
     {
         cw.Put("result.{0} = ({1})cl.DeepObject(s.{0});\n", yi.Name, Utils.GetTypeSpec(yi.Type));
     }
     else
     {
         cw.Put("cl.GetMerger<{1}>()(result.{0}, s.{0});\n", yi.Name, Utils.GetTypeSpec(yi.Type));
     }
 }
Пример #18
0
 internal bool IsCopyable(Meta.Item yi) => yi.IsCopyable || IsCopyable(yi.Type, Options);
Пример #19
0
        private void CreateOverridesWidgets(CookingRulesCollection crc, string key, Target target, Meta.Item yi, CookingRules rules, Widget overridesWidget)
        {
            Widget innerContainer;
            var    sourceFilenameText = string.IsNullOrEmpty(rules.SourceFilename)
                                ? "Default"
                                : rules.SourceFilename.Substring(The.Workspace.AssetsDirectory.Length);
            var targetName = target == null ? "" : $" ({target.Name})";
            var container  = new Widget {
                Padding = new Thickness {
                    Right = 30
                },
                Nodes =
                {
                    (innerContainer    = new Widget {
                        Layout         = new HBoxLayout(),
                    }),
                    new ThemedSimpleText(sourceFilenameText + targetName)
                    {
                        FontHeight     = 16,
                        ForceUncutText = false,
                        OverflowMode   = TextOverflowMode.Ellipsis,
                        HAlignment     = HAlignment.Right,
                        VAlignment     = VAlignment.Center,
                        MinSize        = new Vector2(100, RowHeight),
                        MaxSize        = new Vector2(500, RowHeight)
                    },
                    (new ToolbarButton {
                        Texture        = IconPool.GetTexture("Filesystem.ArrowRight"),
                        Padding        = Thickness.Zero,
                        Size           = RowHeight * Vector2.One,
                        MinMaxSize     = RowHeight * Vector2.One,
                        Clicked        = () => navigateAndSelect(rules.SourceFilename),
                    })
                },
                Layout = new HBoxLayout(),
            };

            container.CompoundPostPresenter.Add(new DelegatePresenter <Widget>((w) => {
                var topmostOverride = crc[key];
                while (
                    topmostOverride.Parent != null &&
                    !(topmostOverride.CommonRules.FieldOverrides.Contains(yi) ||
                      RulesForActiveTarget(topmostOverride).FieldOverrides.Contains(yi))
                    )
                {
                    topmostOverride = topmostOverride.Parent;
                }
                w.PrepareRendererState();
                if (target != activeTarget || rules != topmostOverride)
                {
                    Renderer.DrawLine(10.0f - 30.0f, w.Height * 0.6f, w.Width - 10.0f, w.Height * 0.6f, Color4.Black.Transparentify(0.5f), 1.0f);
                }
                else
                {
                    Renderer.DrawRect(Vector2.Right * -20.0f, w.Size, Color4.Green.Lighten(0.5f).Transparentify(0.5f));
                }
            }));
            container.Components.Add(new PropertyOverrideComponent {
                Rules    = rules,
                YuzuItem = yi,
            });
            overridesWidget.Nodes.Add(container);
            var targetRuels  = RulesForTarget(rules, target);
            var editorParams = new PropertyEditorParams(innerContainer, targetRuels, yi.Name)
            {
                ShowLabel      = false,
                PropertySetter = (owner, name, value) => {
                    yi.SetValue(owner, value);
                    targetRuels.Override(name);
                    rules.DeduceEffectiveRules(target);
                    rules.Save();
                },
                NumericEditBoxFactory = () => {
                    var r = new ThemedNumericEditBox();
                    r.MinMaxHeight           = r.Height = RowHeight;
                    r.TextWidget.VAlignment  = VAlignment.Center;
                    r.TextWidget.Padding.Top = r.TextWidget.Padding.Bottom = 0.0f;
                    return(r);
                },
                DropDownListFactory = () => {
                    var r = new ThemedDropDownList();
                    r.MinMaxHeight = r.Height = RowHeight;
                    return(r);
                },
                EditBoxFactory = () => {
                    var r = new ThemedEditBox();
                    r.MinMaxHeight           = r.Height = RowHeight;
                    r.TextWidget.Padding.Top = r.TextWidget.Padding.Bottom = 0.0f;
                    return(r);
                },
            };

            CreatePropertyEditorForType(yi, editorParams);
        }
Пример #20
0
        private void CreateWidgetsForSingleField(CookingRulesCollection crc, string path, Meta.Item yi)
        {
            var    key    = NormalizePath(path);
            var    parent = crc[key];
            Widget headerWidget;
            Widget overridesWidget;
            var    fieldRootWidget = new Widget {
                Layout = new VBoxLayout(),
                Nodes  =
                {
                    (headerWidget        = new Widget     {
                        Layout           = new HBoxLayout {
                            IgnoreHidden = false,
                        },
                        // TODO: maybe some Metrics.ScrollView.SliderWidth ? (though ScrollView is decorated in DesktopTheme which is inside Lime)
                        Padding          = new Thickness  {
                            Right        =     10.0f
                        },
                    }),
                    (overridesWidget     = new Widget     {
                        Visible          = false,
                        Layout           = new VBoxLayout(),
                        Padding          = new Thickness  {
                            Left         = 30.0f
                        }
                    }),
                }
            };

            fieldRootWidget.AddChangeWatcher(() => WidgetContext.Current.NodeUnderMouse, (value) => {
                if (value != null && value.Parent == fieldRootWidget)
                {
                    Window.Current?.Invalidate();
                }
            });
            scrollView.Content.AddNode(fieldRootWidget);
            bool rootAdded = false;

            while (parent != null)
            {
                var isRoot = parent == crc[key];
                foreach (var kv in parent.Enumerate())
                {
                    if (isRoot && !rootAdded)
                    {
                        rootAdded = true;
                        CreateHeaderWidgets(crc, path, yi, headerWidget, overridesWidget, parent);
                    }
                    if (kv.Value.FieldOverrides.Contains(yi))
                    {
                        CreateOverridesWidgets(crc, key, kv.Key, yi, parent, overridesWidget);
                    }
                }
                parent = parent.Parent;
            }
        }
Пример #21
0
        /// <summary>
        /// The find selected node and add.
        /// </summary>
        /// <param name="reflex">The reflex.</param>
        /// <param name="tn">The tn.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public MetaSplitter.SplitReflexive FindSelectedNodeAndAdd(MetaSplitter.SplitReflexive reflex, TreeNode tn)
        {
            if (reflex.ChunkResources.Count == 0 && reflex.Chunks.Count == 0)
            {
                return(reflex);
            }

            int refcount = 0;

            foreach (TreeNode node in tn.Nodes)
            {
                if (node == treeView1.SelectedNode)
                {
                    if (reflex.splitReflexiveType == MetaSplitter.SplitReflexive.SplitReflexiveType.Container)
                    {
                        if (map.ChunkTools.ChunkClipBoard.splitReflexiveType ==
                            MetaSplitter.SplitReflexive.SplitReflexiveType.Container)
                        {
                            MetaSplitter.SplitReflexive split;
                            split = reflex.Chunks[refcount];
                            for (int x = 0; x < split.ChunkResources.Count; x++)
                            {
                                if (split.ChunkResources[x].type == Meta.ItemType.Reflexive)
                                {
                                    MetaSplitter.SplitReflexive tempref;
                                    tempref = split.ChunkResources[x] as MetaSplitter.SplitReflexive;
                                    if (tempref.description == map.ChunkTools.ChunkClipBoard.description &&
                                        tempref.chunksize == map.ChunkTools.ChunkClipBoard.chunksize)
                                    {
                                        tempref.Chunks.AddRange(map.ChunkTools.ChunkClipBoard.Chunks);

                                        // }
                                        split.ChunkResources[x] = tempref;
                                        reflex.Chunks[refcount] = split;
                                        return(reflex);
                                    }
                                }
                            }

                            if (reflex != map.ChunkTools.ChunkClipBoard)
                            {
                                if (reflex.offset <= reflex.Chunks[refcount].chunksize - 8)
                                {
                                    int lowindex  = -1;
                                    int lowoffset = 0;

                                    int highoffset = reflex.Chunks[refcount].chunksize;
                                    for (int e = 0; e < reflex.Chunks[refcount].ChunkResources.Count; e++)
                                    {
                                        Meta.Item mi = reflex.Chunks[refcount].ChunkResources[e];

                                        if (mi.offset < map.ChunkTools.ChunkClipBoard.offset && mi.offset > lowoffset)
                                        {
                                            lowindex  = e;
                                            lowoffset = mi.offset;
                                        }
                                    }

                                    if (lowindex == -1)
                                    {
                                        reflex.Chunks[refcount].ChunkResources.Insert(0, map.ChunkTools.ChunkClipBoard);
                                    }
                                    else
                                    {
                                        reflex.Chunks[refcount].ChunkResources.Insert(
                                            lowindex + 1, map.ChunkTools.ChunkClipBoard);
                                    }
                                }
                                else
                                {
                                    MessageBox.Show(
                                        "The offset of the reflexive you are trying to paste is too high for this chunk size");
                                }
                            }
                            else
                            {
                                MessageBox.Show("You can not add a reflexive inside of itself");
                            }
                        }
                        else
                        {
                            reflex.Chunks.Insert(refcount + 1, map.ChunkTools.ChunkClipBoard);

                            // MessageBox.Show("Add chunks to reflexives not other chunks");
                        }

                        return(reflex);

                        // reflex.chunkcount += map.ChunkTools.ChunkClipBoard.Chunks.Count;
                    }
                    else if (reflex.splitReflexiveType == MetaSplitter.SplitReflexive.SplitReflexiveType.Chunk)
                    {
                        do
                        {
                            if (reflex.ChunkResources[refcount].type == Meta.ItemType.Reflexive)
                            {
                                // ((MetaSplitter.SplitReflexive)reflex.ChunkResources[refcount]).Chunks.Add(ChunkAdder.ChunkClipBoard);
                                if (map.ChunkTools.ChunkClipBoard.splitReflexiveType ==
                                    MetaSplitter.SplitReflexive.SplitReflexiveType.Chunk)
                                {
                                    ((MetaSplitter.SplitReflexive)reflex.ChunkResources[refcount]).Chunks.Add(
                                        map.ChunkTools.ChunkClipBoard);
                                }
                                else
                                {
                                    MessageBox.Show("Add reflexives to chunks not other reflexives");
                                }

                                // reflex.chunkcount += map.ChunkTools.ChunkClipBoard.ChunkResources.Count;
                                return(reflex);
                            }

                            refcount++;
                        }while (refcount != -1);
                    }
                }

                if (reflex.splitReflexiveType == MetaSplitter.SplitReflexive.SplitReflexiveType.Container)
                {
                    reflex.Chunks[refcount] = FindSelectedNodeAndAdd(reflex.Chunks[refcount], node);

                    refcount++;
                }
                else if (reflex.splitReflexiveType == MetaSplitter.SplitReflexive.SplitReflexiveType.Chunk)
                {
                    do
                    {
                        if (reflex.ChunkResources[refcount].type == Meta.ItemType.Reflexive)
                        {
                            reflex.ChunkResources[refcount] =
                                FindSelectedNodeAndAdd(
                                    (MetaSplitter.SplitReflexive)reflex.ChunkResources[refcount], node);
                            refcount++;
                            break;
                        }

                        refcount++;
                    }while (refcount != -1);

                    // refcount++;
                }
            }

            return(reflex);
        }
Пример #22
0
 private void CreateWidgetsForSingleField(CookingRulesMap rulesMap, string path, Meta.Item yi)
 {
     Widget headerWidget;
     Widget overridesWidget;
     var    fieldRootWidget = new Widget {
         Layout = new VBoxLayout(),
         Nodes  =
         {
             (headerWidget        = new Widget     {
                 Layout           = new HBoxLayout {
                     IgnoreHidden = false,
                 },
                 // TODO: maybe some Metrics.ScrollView.SliderWidth ? (though ScrollView is decorated in DesktopTheme which is inside Lime)
                 Padding          = new Thickness  {
                     Right        =     10.0f
                 },
             }),
             (overridesWidget     = new Widget     {
                 Visible          = cookingRulesFoldState.TryGetValue(yi, out bool v) ? v : false,
                 Layout           = new VBoxLayout(),
                 Padding          = new Thickness  {
                     Left         = 30.0f
                 }
             }),