public void Save(SaveContext saveContext)
        {
            var utility = saveContext.Utility;

            CGFXDebug.SaveStart(this, saveContext);

            utility.Write(TypeId);

            utility.Write(DynamicAllocator);

            // Texture Reference
            saveContext.WritePointerPlaceholder(TextureReference);

            // Sampler
            saveContext.WritePointerPlaceholder(TextureSampler);


            utility.Write(Commands);
            utility.Write(CommandsLength);  // Seems to be length of the aforementioned "Commands"?

            /////////////////////////////
            // Begin saving dependent data

            saveContext.SaveAndMarkReference(TextureReference);
            saveContext.SaveAndMarkReference(TextureSampler);
        }
        }                                           // SPICA doesn't note this, unknown, found through testing

        public override void Load(Utility utility)
        {
            // NOT caling base.Load() as this doesn't use the usual header
            CGFXDebug.LoadStart(this, utility);

            TypeId = utility.ReadU32();
            if (TypeId != 0x80000000)
            {
                throw new InvalidOperationException($"DICTObjAnimGroup: Unexpected TypeId {TypeId.ToString("X8")}");
            }

            Flags      = utility.ReadU32();
            Name       = utility.ReadString();
            MemberType = utility.ReadI32();

            Elements = utility.LoadDICTFromOffset <ChunkDICTAnimGroupElement>();

            var count = utility.ReadU32();

            BlendOperationTypes = utility.ReadInts(count);

            EvaluationTiming = (AnimEvaluationTiming)utility.ReadU32();

            Unknown = utility.ReadU32();
        }
        public static FragmentOperationContainer Load(Utility utility)
        {
            var foc = new FragmentOperationContainer();

            CGFXDebug.LoadStart(foc, utility);

            ///////// DEPTH /////////
            // See also SPICA GfxFragOp / GfxFragOpDepth
            foc.DepthFlags           = utility.ReadU32();
            foc.DepthPICACommandsRaw = utility.ReadUInts(4);


            ///////// BLEND /////////
            // See also SPICA GfxFragOp / GfxFragOpBlend
            foc.BlendMode            = (BlendModeType)utility.ReadU32();
            foc.BlendColor           = ColorFloat.Read(utility);
            foc.BlendPICACommandsRaw = utility.ReadUInts(6);


            ///////// STENCIL /////////
            // See also SPICA GfxFragOp / GfxFragOpStencil
            foc.StencilOperationRaw = utility.ReadUInts(4);

            return(foc);
        }
        public override void Save(SaveContext saveContext)
        {
            var utility = saveContext.Utility;

            CGFXDebug.SaveStart(this, saveContext);

            utility.Write(TypeId);
            utility.Write(Flags);
            saveContext.StringTable.EnqueueAndWriteTempRel(Name);
            utility.Write(MemberType);

            saveContext.WriteDICTPointerPlaceholder(Elements);

            utility.Write(BlendOperationTypes.Length);
            utility.Write(BlendOperationTypes);

            utility.Write((uint)EvaluationTiming);

            utility.Write(Unknown);

            /////////////////////////////
            // Begin saving dependent data

            saveContext.SaveAndMarkReference(Elements);
            Elements?.SaveEntries(saveContext);
        }
        public void Save(SaveContext saveContext)
        {
            var utility = saveContext.Utility;

            CGFXDebug.SaveStart(this, saveContext);

            EmissionF.Save(utility);
            AmbientF.Save(utility);
            DiffuseF.Save(utility);
            Specular0F.Save(utility);
            Specular1F.Save(utility);
            Constant0F.Save(utility);
            Constant1F.Save(utility);
            Constant2F.Save(utility);
            Constant3F.Save(utility);
            Constant4F.Save(utility);
            Constant5F.Save(utility);

            Emission.Save(utility);
            Ambient.Save(utility);
            Diffuse.Save(utility);
            Specular0.Save(utility);
            Specular1.Save(utility);
            Constant0.Save(utility);
            Constant1.Save(utility);
            Constant2.Save(utility);
            Constant3.Save(utility);
            Constant4.Save(utility);
            Constant5.Save(utility);

            utility.Write(CommandCache);
        }
        public static MaterialColorContainer Load(Utility utility)
        {
            var mcc = new MaterialColorContainer();

            CGFXDebug.LoadStart(mcc, utility);

            mcc.EmissionF  = ColorFloat.Read(utility);
            mcc.AmbientF   = ColorFloat.Read(utility);
            mcc.DiffuseF   = ColorFloat.Read(utility);
            mcc.Specular0F = ColorFloat.Read(utility);
            mcc.Specular1F = ColorFloat.Read(utility);
            mcc.Constant0F = ColorFloat.Read(utility);
            mcc.Constant1F = ColorFloat.Read(utility);
            mcc.Constant2F = ColorFloat.Read(utility);
            mcc.Constant3F = ColorFloat.Read(utility);
            mcc.Constant4F = ColorFloat.Read(utility);
            mcc.Constant5F = ColorFloat.Read(utility);

            mcc.Emission  = Color.Read(utility);
            mcc.Ambient   = Color.Read(utility);
            mcc.Diffuse   = Color.Read(utility);
            mcc.Specular0 = Color.Read(utility);
            mcc.Specular1 = Color.Read(utility);
            mcc.Constant0 = Color.Read(utility);
            mcc.Constant1 = Color.Read(utility);
            mcc.Constant2 = Color.Read(utility);
            mcc.Constant3 = Color.Read(utility);
            mcc.Constant4 = Color.Read(utility);
            mcc.Constant5 = Color.Read(utility);

            mcc.CommandCache = utility.ReadU32();

            return(mcc);
        }
        public static TextureMapper Load(Utility utility)
        {
            var tm = new TextureMapper();

            CGFXDebug.LoadStart(tm, utility);

            tm.TypeId = utility.ReadU32();
            if (tm.TypeId != 0x80000000)
            {
                throw new InvalidOperationException($"TextureMapper: Expected type 0x80000000, got {tm.TypeId}");
            }

            tm.DynamicAllocator = utility.ReadU32();

            // Texture Reference
            tm.TextureReference = utility.LoadDICTObj <TextureReference>();

            // Sampler
            utility.LoadIndirect(() =>
            {
                tm.TextureSampler = TextureSampler.Load(tm, utility);
            });

            tm.Commands       = utility.ReadUInts(14);
            tm.CommandsLength = utility.ReadU32();  // Seems to be length of the aforementioned "Commands"?

            // I think this is a fair sanity check??
            if (tm.CommandsLength != (14 * 4))
            {
                throw new InvalidOperationException("CommandsLength mismatch");
            }

            return(tm);
        }
            public void Save(SaveContext saveContext)
            {
                var utility = saveContext.Utility;

                CGFXDebug.SaveStart(this, saveContext);

                // Bone Indices
                if (BoneReferences != null)
                {
                    BoneIndices = BoneReferences.Select(b => (uint)b.Index).ToList();   // Rebuild from referenced objects
                }
                saveContext.WriteValueListPointerPlaceholder(BoneIndices);

                // Skinning
                utility.Write((uint)Skinning);

                // Faces
                saveContext.WriteObjectListPointerPlaceholder(Faces);

                /////////////////////////////
                // Begin saving dependent data

                saveContext.SaveAndMarkReference(BoneIndices);
                saveContext.SaveAndMarkReference(Faces);

                Faces.SaveList(saveContext);
            }
Ejemplo n.º 9
0
        public static TextureSampler Load(TextureMapper parent, Utility utility)
        {
            var s = new TextureSampler();

            CGFXDebug.LoadStart(s, utility);

            // This has a TypeId here...
            s.TypeId = utility.ReadU32();
            if (s.TypeId != 0x80000000)
            {
                throw new InvalidOperationException($"TextureSampler: Expected type 0x80000000, got {s.TypeId}");
            }

            // Just reading the offset but we'll resolve this later
            var ownerModelOffset = utility.ReadOffset();

            s.Parent = parent;

            s.MinFilter = (TextureMinFilter)utility.ReadU32();

            s.BorderColor = ColorFloat.Read(utility);
            s.LODBias     = utility.ReadFloat();

            return(s);
        }
        // Load a list of non-ChunkDICTObject arbitrary objects from a list of pointers
        public TObj[] LoadIndirectObjList <TObj>(Func <TObj> loadAction)
        {
            TObj[] result = null;

            CGFXDebug.LoadStart($"HEADER of list of {typeof(TObj).Name} [LoadIndirectObjList]", this);

            var numObjects = ReadU32();
            var offset     = ReadOffset();

            if (offset > 0)
            {
                PushReadPosition();
                SetReadPosition(offset);

                CGFXDebug.LoadStart($"List of {typeof(TObj).Name} [LoadIndirectObjList]", this);

                result = new TObj[numObjects];
                for (var objIndex = 0; objIndex < numObjects; objIndex++)
                {
                    var objOffset = ReadOffset();
                    PushReadPosition();
                    SetReadPosition(objOffset);

                    result[objIndex] = loadAction();

                    PopReadPosition();
                }

                PopReadPosition();
            }

            return(result);
        }
        // Load the standard pattern of [UINT COUNT][UINT OFFSET TO TABLE] -> [UINT OFFSET 1][UINT OFFSET 2]...
        public IEnumerable <TDICTObj> LoadDICTObjList <TDICTObj>()
            where TDICTObj : ChunkDICTObject, new()
        {
            TDICTObj[] result = null;

            CGFXDebug.LoadStart($"HEADER of list of {typeof(TDICTObj).Name} [LoadDICTObjList]", this);

            var count         = ReadU32();
            var locationTable = ReadOffset();

            if (count > 0)
            {
                result = new TDICTObj[count];

                PushReadPosition();
                SetReadPosition(locationTable);

                CGFXDebug.LoadStart($"List of {typeof(TDICTObj).Name} [LoadDICTObjList]", this);

                for (var index = 0; index < count; index++)
                {
                    result[index] = LoadDICTObj <TDICTObj>();
                }

                PopReadPosition();
            }

            return(result);
        }
Ejemplo n.º 12
0
        public void Save(SaveContext saveContext)
        {
            var utility = saveContext.Utility;

            CGFXDebug.SaveStart(this, saveContext);

            utility.Write(TypeId);


            // The 4 UInts here WOULD BE:
            //  Count of Targets
            //  Offset to Targets
            //  Count of Types
            //  Offset to Types
            utility.Write(Stubs);

            // ... but just make sure they're all unused for now
            for (var i = 0; i < 4; i++)
            {
                if (Stubs[i] != 0)
                {
                    throw new NotImplementedException("BlendShape: Trying to fetch data, NOT IMPLEMENTED");
                }
            }
        }
Ejemplo n.º 13
0
            public void Save(SaveContext saveContext)
            {
                var utility = saveContext.Utility;

                CGFXDebug.SaveStart(this, saveContext);

                utility.Write((uint)Constant);
                utility.Write(RawCommands);
            }
Ejemplo n.º 14
0
        public override void Load(Utility utility)
        {
            base.Load(utility);

            Height = utility.ReadU32();
            Width  = utility.ReadU32();

            // These are Ohana3DS names, I don't know if this is really what these are??
            // (And even if they are, not sure how they map to OpenGL exactly)
            OpenGLFormat = utility.ReadU32();
            OpenGLType   = utility.ReadU32();

            MipmapLevels = utility.ReadU32();

            // NOTE: Unsure of the exact implication of multiple mipmap levels in terms of data.
            // It seems like this wasn't properly supported by "old" Ohana3DS, so I'd like to know...
            if (MipmapLevels > 1)
            {
                throw new NotImplementedException($"ChunkDICTTexture Load: More than 1 mipmap level ({MipmapLevels}); need to investigate if that means more texture data or what...");
            }

            // Once again, Ohana3DS names, not sure what they are or if I should support them
            TextureObject = utility.ReadU32();
            LocationFlags = utility.ReadU32();

            if (TextureObject != 0)
            {
                // Note to self, if I get here... this may be non-fatal, I'm more worried if it's pointing to data
                throw new NotImplementedException();
            }

            TextureFormat = (Format)utility.ReadU32();

            // Not even Ohana3DS tried to address these!
            Unknown1 = utility.ReadU32();
            Unknown2 = utility.ReadU32();
            Unknown3 = utility.ReadU32();

            // Texture will be stored as raw blob rather than as length/offset values
            var dataLength = utility.ReadU32();
            var dataOffset = utility.ReadOffset();

            CGFXDebug.WriteLog($"NOTE: TextureCGFXData of format {TextureFormat} starts at {dataOffset.ToString("X4")}");
            utility.PushReadPosition();
            utility.SetReadPosition(dataOffset);
            TextureCGFXData = utility.ReadBytes(dataLength);
            utility.PopReadPosition();

            DynamicAllocator = utility.ReadU32();
            BitsPerPixel     = utility.ReadU32();
            LocationAddress  = utility.ReadU32();
            MemoryAddress    = utility.ReadU32();

            //var testRGBA = TextureCodec.ConvertTextureToRGBA(utility, TextureCGFXData, TextureFormat, Width, Height);
            //var textCGFX = TextureCodec.ConvertTextureToCGFX(utility, testRGBA, TextureFormat, Width, Height);
        }
            public void Save(SaveContext saveContext)
            {
                var utility = saveContext.Utility;

                CGFXDebug.SaveStart(this, saveContext);

                Center.Write(utility);
                Orientation.Write(utility);
                Size.Write(utility);
                utility.Write(Unknown);
            }
Ejemplo n.º 16
0
            }                                                   // Raw PICA200 GPU commands

            public static TexEnv Load(Utility utility)
            {
                var te = new TexEnv();

                CGFXDebug.LoadStart(te, utility);

                te.Constant    = (GfxTexEnvConstant)utility.ReadU32();
                te.RawCommands = utility.ReadUInts(6);

                return(te);
            }
Ejemplo n.º 17
0
        public void Save(SaveContext saveContext)
        {
            var utility = saveContext.Utility;

            CGFXDebug.SaveStart(this, saveContext);

            utility.Write(IsPolygonOffsetEnabled ? 1U : 0U);
            utility.Write((uint)FaceCulling);
            utility.Write(PolygonOffsetUnit);

            utility.Write(FaceCullingCommand);
        }
Ejemplo n.º 18
0
        public virtual void Save(SaveContext saveContext)
        {
            CGFXDebug.SaveStart(this, saveContext);

            var utility = saveContext.Utility;

            utility.Write(TypeId);
            saveContext.StringTable.EnqueueAndWriteTempRel(Name);
            utility.Write((uint)Type);

            SaveInternal(saveContext);
        }
Ejemplo n.º 19
0
        // Intended for simple lists of ints, floats, etc.
        public void WriteValueListPointerPlaceholder <TVal>(IEnumerable <TVal> values)
        {
            CGFXDebug.SaveStart($"HEADER of list of {typeof(TVal).Name} [WriteValueListPointerPlaceholder]", this);

            // Number of values
            var length = values?.Count() ?? 0;

            Utility.Write(length);

            // Reference the value list
            WritePointerPlaceholder(values);
        }
            }                                   // Found during discovery of unread bytes, no idea what this is for

            public static GfxBoundingBox Load(Utility utility)
            {
                var bb = new GfxBoundingBox();

                CGFXDebug.LoadStart(bb, utility);

                bb.Center      = Vector3.Read(utility);
                bb.Orientation = Matrix3x3.Read(utility);
                bb.Size        = Vector3.Read(utility);
                bb.Unknown     = utility.ReadFloat();

                return(bb);
            }
Ejemplo n.º 21
0
        public void Save(SaveContext saveContext)
        {
            var utility = saveContext.Utility;

            CGFXDebug.SaveStart(this, saveContext);

            utility.Write(TypeId);

            saveContext.StringTable.EnqueueAndWriteTempRel(SamplerName);
            saveContext.StringTable.EnqueueAndWriteTempRel(TableName);

            saveContext.WritePointerPlaceholder(LUT);
        }
Ejemplo n.º 22
0
        }                                                       // NOTE -- Ohana3DS had THREE unknown uints, but SPICA only reads TWO uints here

        public static RasterizationContainer Load(Utility utility)
        {
            var rc = new RasterizationContainer();

            CGFXDebug.LoadStart(rc, utility);

            rc.IsPolygonOffsetEnabled = (utility.ReadU32() & 1) > 0;
            rc.FaceCulling            = (CullMode)utility.ReadU32();
            rc.PolygonOffsetUnit      = utility.ReadFloat();

            rc.FaceCullingCommand = utility.ReadUInts(2);

            return(rc);
        }
        public void Save(SaveContext saveContext)
        {
            var utility = saveContext.Utility;

            CGFXDebug.SaveStart(this, saveContext);

            // Common values...
            utility.Write(TypeId);
            utility.Write((uint)AttrName);
            utility.Write((uint)Type);

            // If all good, continue the save!
            SaveInternal(saveContext);
        }
Ejemplo n.º 24
0
        public virtual void Save(SaveContext saveContext)
        {
            var utility = saveContext.Utility;

            CGFXDebug.SaveStart(this, saveContext);

            utility.Write(TypeId);
            utility.WriteMagic(Magic);
            utility.Write(Revision);

            saveContext.StringTable.EnqueueAndWriteTempRel(Name);

            saveContext.WriteDICTPointerPlaceholder(MetaDatas);
        }
Ejemplo n.º 25
0
        protected override void LoadInternal(Utility utility)
        {
            BufferObject = utility.ReadU32();
            LocationFlag = utility.ReadU32();

            // The RawBuffer contains ???
            CGFXDebug.WriteLog($"NOTE: RawBuffer read in VertexBufferInterleaved, see next address of List");
            RawBuffer = utility.LoadIndirectValueList(() => utility.ReadByte());

            LocationPtr  = utility.ReadU32();
            MemoryArea   = utility.ReadU32();
            VertexStride = utility.ReadI32();

            Attributes = utility.LoadIndirectObjList(() => Load <VertexAttribute>(utility)).ToList();
        }
Ejemplo n.º 26
0
        public void Save(SaveContext saveContext)
        {
            var utility = saveContext.Utility;

            CGFXDebug.SaveStart(this, saveContext);

            utility.Write(TypeId);

            saveContext.WritePointerPlaceholder(Parent);

            utility.Write((uint)MinFilter);

            BorderColor.Save(utility);
            utility.Write(LODBias);
        }
Ejemplo n.º 27
0
            public static FragLightLUT Load(Utility utility)
            {
                var fll = new FragLightLUT();

                CGFXDebug.LoadStart(fll, utility);

                fll.Input = (PICALUTInput)utility.ReadU32();
                fll.Scale = (PICALUTScale)utility.ReadU32();

                utility.LoadIndirect(() =>
                {
                    fll.Sampler = LUTReference.Load(utility);
                });

                return(fll);
            }
Ejemplo n.º 28
0
            public void Save(SaveContext saveContext)
            {
                var utility = saveContext.Utility;

                CGFXDebug.SaveStart(this, saveContext);

                utility.Write((uint)Input);
                utility.Write((uint)Scale);

                saveContext.WritePointerPlaceholder(Sampler);

                /////////////////////////////
                // Begin saving dependent data

                saveContext.SaveAndMarkReference(Sampler);
            }
Ejemplo n.º 29
0
        public void Save(SaveContext saveContext)
        {
            var utility = saveContext.Utility;

            CGFXDebug.SaveStart(this, saveContext);

            utility.Write(TypeId);
            saveContext.StringTable.EnqueueAndWriteTempRel(Name);
            utility.Write(MemberOffset);
            utility.Write(BlendOpIndex);
            utility.Write((uint)ObjType);
            utility.Write(MemberType);
            utility.Write(MaterialPtr);

            SaveInternal(saveContext);
        }
Ejemplo n.º 30
0
        // List of items, writes pointer reference per item
        public void SaveAndMarkReference(IEnumerable <ISaveable> items)
        {
            var itemNames = (items != null) ?
                            items.Where(i => i != null).Select(i => i.GetType().Name).Distinct().ToList()
                : new[] { "<null>" }.ToList();

            CGFXDebug.SaveStart($"List of {string.Join(", ", itemNames)} [WriteObjectListPointerPlaceholder]", this);

            SaveAndMarkReference(items, () =>
            {
                foreach (var item in items)
                {
                    WritePointerPlaceholder(item);
                }
            });
        }