Beispiel #1
0
        public override bool CanDecode(Chunks.Chunk chunk)
        {
            SRFile file = chunk.File;

            file.Position = chunk.Offset;
            return(file.ReadFourCC() == "5VSM");
        }
Beispiel #2
0
        public void LoadAnnotationsForFile(SRFile file)
        {
            AnnotationMap map      = new AnnotationMap();
            string        checksum = file.GetRecognitionChecksum();

            annotations.Add(file, map);
        }
Beispiel #3
0
 public KAPLChunk(SRFile file, Chunk parent)
     : base(file, parent)
 {
     this.Name   = "KAPL";
     this.Offset = file.Position;
     this.Size   = file.Size;
 }
 public TellTaleFileChunk(SRFile file, Chunk parent, string name, ulong offset, uint size) : base(file, parent)
 {
     spec   = FileChunkSpecs.GetSpec(Path.GetExtension(name).ToLowerInvariant());
     Name   = name;
     Offset = offset;
     Size   = size;
 }
Beispiel #5
0
        protected byte[] DecodeSmap(Chunk smapChunk, ImageInfo info)
        {
            byte[] buffer = new byte[info.Width * info.Height];

            int stripCount = info.Width / 8;

            Chunk offsChunk = smapChunk.SelectSingle("BSTR/WRAP/OFFS");

            int[] stripOffsets = new int[stripCount];

            BinReader reader = offsChunk.GetReader();

            reader.Position = 8;
            for (int i = 0; i < stripCount; i++)
            {
                int offs = reader.ReadS32LE();
                stripOffsets[i] = (int)(offs - offsChunk.Size);
            }
            uint dataSize = offsChunk.Parent.Size - offsChunk.Size - 8;

            SRFile file = smapChunk.File;

            file.Position = offsChunk.Offset + offsChunk.Size;
            byte[] source;
            file.Read(dataSize, out source);

            return(MMucusImageDecoder.DecodeStrips(info, source, buffer, stripOffsets));
        }
Beispiel #6
0
 public SCUMM1Chunk(SRFile file, Chunk parent, string name, ulong offset, uint size) : base(file, parent)
 {
     Offset = offset;
     Size   = size;
     Name   = name;
     spec   = SCUMM1ChunkSpecs.GetSpec(name, parent);
 }
Beispiel #7
0
        public SCUMM5Chunk(SRFile file, Chunk parent, string name, ulong offset, uint size) : base(file, parent)
        {
            Offset = offset;
            Name   = name;
            spec   = SCUMM5ChunkSpecs.GetSpec(name, parent);

            CalculateSize(parent, size);
        }
Beispiel #8
0
        // TODO: Try to get rid of this static function
        // (needed in order for file to read root chunks without having a parent chunk)
        public static Chunk ReadChunk(SRFile file, Chunk parent)
        {
            ulong offset = file.Position;
            uint  size   = file.ReadU32LE();
            TwoCC fourCC = file.ReadTwoCC();

            if (!fourCC.IsValid)
            {
                return(new UnknownChunk(file, parent, offset, (uint)(parent.Offset + parent.Size - offset)));
            }

            return(new SCUMM3Chunk(file, parent, fourCC.Name, offset, size));
        }
Beispiel #9
0
        // TODO: Try to get rid of this static function
        // (needed in order for file to read root chunks without having a parent chunk)
        public static Chunk ReadChunk(SRFile file, Chunk parent)
        {
            ulong  offset = file.Position;
            uint   size;
            FourCC fourCC = file.ReadFourCC();

            if (!fourCC.IsValid)
            {
                size = (uint)(parent != null ? parent.Offset + parent.Size - offset : file.Size - offset);
                return(new UnknownChunk(file, parent, offset, size));
            }
            size = file.ReadU32BE();

            return(new SCUMM5Chunk(file, parent, fourCC.Name, offset, size));
        }
Beispiel #10
0
        /// <summary>
        /// Determines version of SCUMM engine used for a particular file.
        /// The revision is rarely, if ever, relevant or determinable by file (without checksums).
        /// For now, we're also leaving out minor version
        ///
        /// Versions by game:
        /// - Maniac Mansion                        0.0
        /// - Zak McKracken                         1.0
        /// - Maniac Mansion (NES)                  1.5
        /// - Maniac Mansion (enhanced)             2.0
        /// - Zak McKracken (enhanced)              2.0
        /// - Last Crusade                          3.0
        /// - Zak McKracken (FM-TOWNS)              3.0
        /// - Loom                                  3.5
        /// - Secret of Monkey Island (EGA)         4.0
        /// - Secret of Monkey Island (VGA)         5.0
        /// - Loom (CD)                             5.1
        /// - Monkey Island 2                       5.2
        /// - Fate of Atlantis                      5.2
        /// - Secret of Monkey Island (CD)          5.3
        /// - Fate of Atlantis (TALKIE)             5.5
        /// - Day of the Tentacle                   6.4
        /// - Sam & Max Hit the Road                6.5
        /// - Sam & Max Hit the Road (CD)           7.0
        /// - Full Throttle                         7.3
        /// - The Dig                               7.5
        /// - Curse of Monkey Island                8.1
        /// </summary>
        public static int DetermineSCUMMVersion(SRFile file)
        {
            if (file is SCUMM3File)
            {
                // TODO: Uncertain
                // SCUMM 4 has LE root chunks
                if (file.RootChunk.SelectSingle("/LE") != null)
                {
                    return(4);
                }
                return(3);
            }

            if (file is SCUMM5File)
            {
                // SCUMM 8 has room scripts chunk
                if (file.RootChunk.SelectSingle("/LECF/LFLF/RMSC") != null)
                {
                    return(8);
                }
                // SCUMM 7 has AKOS costumes
                if (file.RootChunk.SelectSingle("/LECF/LFLF/AKOS") != null)
                {
                    return(7);
                }
                // SCUMM 5 has a 24 byte IMHD
                Chunk imhdChunk = file.RootChunk.SelectSingle("/LECF/LFLF/ROOM/OBIM/IMHD");
                if (imhdChunk != null && imhdChunk.Size == 24)
                {
                    return(5);
                }

                // It's not 5, 7 or 8, so must be 6:
                return(6);
            }
            // Not a SCUMM file
            return(-1);
        }
Beispiel #11
0
 public LB83Chunk(SRFile file, Chunk parent) : base(file, parent)
 {
     Name   = "LB83";
     Offset = file.Position;
     Size   = file.Size;
 }
Beispiel #12
0
 public RootChunk(SRFile file) : base(file, null, "__ROOT__", 0, file.Size)
 {
 }
Beispiel #13
0
        public void HandleDebugRendering(CDC.Objects.ExportOptions options)
        {
            bool useDebugColouring = false;

            if ((options.RenderMode != RenderMode.Standard))
            {
                useDebugColouring = true;
            }
            if (!useDebugColouring)
            {
                return;
            }

            if (useDebugColouring)
            {
                for (int p = 0; p < _polygons.Length; p++)
                {
                    _polygons[p].material.textureUsed = false;
                    if ((options.MakeAllPolygonsVisible) || (options.MakeAllPolygonsOpaque) || (!options.DiscardNonVisible))
                    {
                        _polygons[p].material.visible = true;
                    }
                    //_polygons[p].material.visible = true;
                    _polygons[p].material.emissivity = 0.0f;
                    if (options.RenderMode == RenderMode.NoTextures)
                    {
                        //return;
                        //_polygons[p].material.colour = |= 0xFF000000;
                    }


                    //_polygons[p].material.colour = (TransparentMaterial & 0xFF000000) | 0x404040;

                    if (options.SetAllPolygonColoursToValue)
                    {
                        //_polygons[p].material.colour |= 0x0000FF00;
                        _polygons[p].material.colour  = SRFile.FloatARGBToUInt32ARGB(new float[] { options.PolygonColourAlpha, options.PolygonColourRed, options.PolygonColourGreen, options.PolygonColourBlue });
                        _polygons[p].colour           = _polygons[p].material.colour;
                        _polygons[p].material.opacity = options.PolygonColourAlpha;
                    }
                    else
                    {
                        _polygons[p].material.colour  = 0xFF404040;
                        _polygons[p].colour           = _polygons[p].material.colour;
                        _polygons[p].material.opacity = 0.75f;
                    }
                    //_polygons[p].v1.colourID = 0;
                    //_polygons[p].v2.colourID = 0;
                    //_polygons[p].v3.colourID = 0;
                    if (options.RenderMode == RenderMode.DebugPolygonFlagsHash)
                    {
                        ColourPolygonFromUInt(p, _polygons[p].material.polygonFlags);
                    }

                    if (options.RenderMode == RenderMode.DebugPolygonFlags1)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.polygonFlags, 0x0001, 0x0002, 0x0004);
                        // 0x01 = hidden polygon (portal, collision box, etc.), not sure why sometimes it's this and sometimes 0x40
                        // 0x02 = inverted half of quad? It's one triangle out of every quad in a lot of models (but not all)
                        // 0x04 = hidden polygon
                    }
                    if (options.RenderMode == RenderMode.DebugPolygonFlags2)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.polygonFlags, 0x0008, 0x0010, 0x0020);
                        // 0x08 = translucent? glowing? - used for the water in tower10 (1999-02-16), lthbeam  (1999-02-16), morlock eyes (1999-05-12), Kain's feet (1999-05-12)
                        // 0x10 = glowing? reflective? specular? That Z-depth thing Andrew mentioned? - water in cityout3 is cyan, not used in cathy69, pipes and platforms in intvaly1 are green, used for the columns in tower10 (1999-02-16)
                        // 0x20 = translucent - water in cityout3 is cyan, not used in cathy69, water in intvaly1 is blue, lava in lair1 is blue
                    }
                    if (options.RenderMode == RenderMode.DebugPolygonFlags3)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.polygonFlags, 0x0040, 0x0080, 0x0100);
                        // 0x40 = hidden polygon (portal, collision box, etc.), not sure why sometimes it's this and sometimes 0x01
                    }
                    if (options.RenderMode == RenderMode.DebugPolygonFlagsSoulReaverA)
                    {
                        byte tempFlags = _polygons[p].material.polygonFlags;
                        if ((_polygons[p].material.polygonFlags & 0x40) == 0x40)
                        {
                            tempFlags |= 0x01;
                        }
                        ColourPolygonFromFlags(p, _polygons[p].material.polygonFlags, 0x0001, 0x0020, 0x0010);
                        // hidden polygons == red
                        // transparent/translucent == green
                        // glowing? reflective? == blue
                    }

                    if (options.RenderMode == RenderMode.DebugTextureAttributesHash)
                    {
                        ColourPolygonFromUInt(p, _polygons[p].material.textureAttributes);
                    }

                    if (options.RenderMode == RenderMode.DebugTextureAttributes1)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.textureAttributes, 0x0001, 0x0002, 0x0004);
                    }
                    if (options.RenderMode == RenderMode.DebugTextureAttributes2)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.textureAttributes, 0x0008, 0x0010, 0x0020);
                        // 0x10 = use alpha mask mode instead of opaque
                        // the glass shell around the lighthouse in intvaly1 has this flag
                        // tiny squares below the wall sconces in nighta2 (1999-01-23) have this flag too
                        // stair coverings and the bridge in cliff1 (release version) have this flag
                        // flags in city2 (NTSC release)
                    }
                    if (options.RenderMode == RenderMode.DebugTextureAttributes3)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.textureAttributes, 0x0040, 0x0080, 0x0100);
                        // 0x40 = Reflective/specular? Glowing?
                    }
                    if (options.RenderMode == RenderMode.DebugTextureAttributes4)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.textureAttributes, 0x0200, 0x0400, 0x0800);
                        // 0x0200 = climbable walls? city2 (NTSC release)
                    }
                    if (options.RenderMode == RenderMode.DebugTextureAttributes5)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.textureAttributes, 0x1000, 0x2000, 0x4000);
                        // 0x1000 = parts of the gate in nighta1 (1999-02-16) have this flag
                        // 0x2000 = waterfall in intvaly1 (1999-01-23) has this flag - maybe animated texture, or translucency?
                        //          Parts of the water in cliff1 have it too
                        // 0x4000 = most of the intvaly1 terrain mesh has this flag
                    }
                    if (options.RenderMode == RenderMode.DebugTextureAttributes6)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.textureAttributes, 0x10000, 0x8000, 0x20000);
                        // 0x8000 = lighting effects?
                    }

                    if (options.RenderMode == RenderMode.DebugTextureAttributesAHash)
                    {
                        ColourPolygonFromUInt(p, _polygons[p].material.textureAttributesA);
                    }
                    if (options.RenderMode == RenderMode.DebugTextureAttributesA1)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.textureAttributesA, 0x0001, 0x0002, 0x0004);
                    }
                    if (options.RenderMode == RenderMode.DebugTextureAttributesA2)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.textureAttributesA, 0x0008, 0x0010, 0x0020);
                    }
                    if (options.RenderMode == RenderMode.DebugTextureAttributesA3)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.textureAttributesA, 0x0040, 0x0080, 0x0100);
                    }
                    if (options.RenderMode == RenderMode.DebugTextureAttributesA4)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.textureAttributesA, 0x0200, 0x0400, 0x0800);
                    }
                    if (options.RenderMode == RenderMode.DebugTextureAttributesA5)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.textureAttributesA, 0x1000, 0x2000, 0x4000);
                    }
                    if (options.RenderMode == RenderMode.DebugTextureAttributesA6)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.textureAttributesA, 0x10000, 0x8000, 0x10000);
                    }


                    UInt16 clutNonRowColumnBits = (UInt16)((_polygons[p].material.clutValue & 0xC000) >> 11);
                    clutNonRowColumnBits |= (UInt16)((_polygons[p].material.clutValue & 0x00E0) >> 5);

                    if (options.RenderMode == RenderMode.DebugCLUTNonRowColBitsHash)
                    {
                        ColourPolygonFromUInt(p, clutNonRowColumnBits);
                    }
                    if (options.RenderMode == RenderMode.DebugCLUTNonRowColBits1)
                    {
                        ColourPolygonFromFlags(p, clutNonRowColumnBits, 0x0001, 0x0002, 0x0004);
                    }
                    if (options.RenderMode == RenderMode.DebugCLUTNonRowColBits2)
                    {
                        ColourPolygonFromFlags(p, clutNonRowColumnBits, 0x0008, 0x0010, 0x10000);
                    }

                    if (options.RenderMode == RenderMode.DebugCLUTHash)
                    {
                        ColourPolygonFromUInt(p, _polygons[p].material.clutValue);
                    }
                    if (options.RenderMode == RenderMode.DebugCLUT1)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.clutValue, 0x0001, 0x0002, 0x0004);
                    }
                    if (options.RenderMode == RenderMode.DebugCLUT2)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.clutValue, 0x0008, 0x0010, 0x0020);
                    }
                    if (options.RenderMode == RenderMode.DebugCLUT3)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.clutValue, 0x0040, 0x0080, 0x0100);
                    }
                    if (options.RenderMode == RenderMode.DebugCLUT4)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.clutValue, 0x0200, 0x0400, 0x0800);
                    }
                    if (options.RenderMode == RenderMode.DebugCLUT5)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.clutValue, 0x1000, 0x2000, 0x4000);
                    }
                    if (options.RenderMode == RenderMode.DebugCLUT6)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.clutValue, 0x10000, 0x8000, 0x10000);
                    }


                    if (options.RenderMode == RenderMode.DebugTexturePageHash)
                    {
                        ColourPolygonFromUInt(p, _polygons[p].material.texturePage);
                    }
                    if (options.RenderMode == RenderMode.DebugTexturePageUpper28BitsHash)
                    {
                        //ColourPolygonFromUInt(p, (_polygons[p].material.texturePage & 0xFFFFFF00));
                        ColourPolygonFromUInt(p, (_polygons[p].material.texturePage & 0xFFFFFFF0));
                    }
                    if (options.RenderMode == RenderMode.DebugTexturePageUpper5BitsHash)
                    {
                        //ColourPolygonFromUInt(p, (_polygons[p].material.texturePage & 0xFFFFFF00));
                        ColourPolygonFromUInt(p, (_polygons[p].material.texturePage & 0xFFFFF800));
                    }
                    if (options.RenderMode == RenderMode.DebugTexturePage1)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.texturePage, 0x0001, 0x0002, 0x0004);
                    }
                    if (options.RenderMode == RenderMode.DebugTexturePage2)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.texturePage, 0x0008, 0x0010, 0x0020);
                        // 0x0020 == glowing?
                    }
                    if (options.RenderMode == RenderMode.DebugTexturePage3)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.texturePage, 0x0040, 0x0080, 0x0100);
                        // 0x0040 == glowing brightly?
                    }
                    if (options.RenderMode == RenderMode.DebugTexturePage4)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.texturePage, 0x0200, 0x0400, 0x0800);
                    }
                    if (options.RenderMode == RenderMode.DebugTexturePage5)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.texturePage, 0x1000, 0x2000, 0x4000);
                    }
                    if (options.RenderMode == RenderMode.DebugTexturePage6)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.texturePage, 0x10000, 0x8000, 0x10000);
                    }

                    if (options.RenderMode == RenderMode.DebugSortPushHash)
                    {
                        ColourPolygonFromUInt(p, _polygons[p].material.sortPush);
                    }
                    if (options.RenderMode == RenderMode.DebugSortPushFlags1)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.sortPush, 0x0001, 0x0002, 0x0004);
                    }
                    if (options.RenderMode == RenderMode.DebugSortPushFlags2)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.sortPush, 0x0008, 0x0010, 0x0020);
                    }
                    if (options.RenderMode == RenderMode.DebugSortPushFlags3)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.sortPush, 0x0040, 0x0080, 0x0100);
                    }

                    if (options.RenderMode == RenderMode.AverageVertexAlpha)
                    {
                        _polygons[p].material.opacity = 0.75f;
                        float[] fV1       = SRFile.UInt32ARGBToFloatARGB(_geometry.Colours[_polygons[p].v1.colourID]);
                        float[] fV2       = SRFile.UInt32ARGBToFloatARGB(_geometry.Colours[_polygons[p].v2.colourID]);
                        float[] fV3       = SRFile.UInt32ARGBToFloatARGB(_geometry.Colours[_polygons[p].v3.colourID]);
                        float[] fVAverage = new float[4];
                        fVAverage[0] = 1.0f;
                        fVAverage[1] = (fV1[0] + fV2[0] + fV3[0]) / 3.0f;
                        fVAverage[2] = 1.0f;
                        fVAverage[3] = (fV1[0] + fV2[0] + fV3[0]) / 3.0f;
                        _polygons[p].material.colour = SRFile.FloatARGBToUInt32ARGB(fVAverage);
                        _polygons[p].colour          = _polygons[p].material.colour;
                    }

                    if (options.RenderMode == RenderMode.PolygonAlpha)
                    {
                        float[] fPoly     = SRFile.UInt32ARGBToFloatARGB(_polygons[p].material.colour);
                        float[] fVAverage = new float[4];
                        fVAverage[0] = 0.75f;
                        fVAverage[1] = fPoly[0];
                        fVAverage[2] = 1.0f;
                        fVAverage[3] = fPoly[0];
                        _polygons[p].material.colour  = SRFile.FloatARGBToUInt32ARGB(fVAverage);
                        _polygons[p].colour           = _polygons[p].material.colour;
                        _polygons[p].material.opacity = 0.75f;
                    }

                    if (options.RenderMode == RenderMode.PolygonOpacity)
                    {
                        float[] fVAverage = new float[4];
                        fVAverage[0] = 0.75f;
                        fVAverage[1] = _polygons[p].material.opacity;
                        fVAverage[2] = 1.0f;
                        fVAverage[3] = _polygons[p].material.opacity;
                        _polygons[p].material.colour  = SRFile.FloatARGBToUInt32ARGB(fVAverage);
                        _polygons[p].colour           = _polygons[p].material.colour;
                        _polygons[p].material.opacity = 0.75f;
                    }

                    if (options.RenderMode == RenderMode.DebugBoneIDHash)
                    {
                        UInt32 boneIDColourV1 = GetColourFromHash(GetHashOfUInt((uint)_polygons[p].v1.boneID));
                        UInt32 boneIDColourV2 = GetColourFromHash(GetHashOfUInt((uint)_polygons[p].v2.boneID));
                        UInt32 boneIDColourV3 = GetColourFromHash(GetHashOfUInt((uint)_polygons[p].v3.boneID));
                        _geometry.Colours[_polygons[p].v1.colourID] = boneIDColourV1;
                        _geometry.Colours[_polygons[p].v2.colourID] = boneIDColourV2;
                        _geometry.Colours[_polygons[p].v3.colourID] = boneIDColourV3;
                        if ((boneIDColourV1 == boneIDColourV2) && (boneIDColourV2 == boneIDColourV3))
                        {
                            _polygons[p].material.opacity = 1.0f;
                            _polygons[p].material.colour  = boneIDColourV1;
                            _polygons[p].colour           = boneIDColourV1;
                        }
                        else
                        {
                            if (options.InterpolatePolygonColoursWhenColouringBasedOnVertices)
                            {
                                // average the vertex colours and make the polygon translucent to highlight the fact that it's dependent on multiple bones.
                                _polygons[p].material.opacity = 0.25f;
                                float[] fV1       = SRFile.UInt32ARGBToFloatARGB(boneIDColourV1);
                                float[] fV2       = SRFile.UInt32ARGBToFloatARGB(boneIDColourV2);
                                float[] fV3       = SRFile.UInt32ARGBToFloatARGB(boneIDColourV3);
                                float[] fVAverage = new float[4];
                                fVAverage[0] = (fV1[0] + fV2[0] + fV3[0]) / 3.0f;
                                fVAverage[1] = (fV1[1] + fV2[1] + fV3[1]) / 3.0f;
                                fVAverage[2] = (fV1[2] + fV2[2] + fV3[2]) / 3.0f;
                                fVAverage[3] = (fV1[3] + fV2[3] + fV3[3]) / 3.0f;
                                _polygons[p].material.colour = SRFile.FloatARGBToUInt32ARGB(fVAverage);
                                _polygons[p].colour          = _polygons[p].material.colour;
                            }
                            else
                            {
                                _polygons[p].material.opacity = 0.5f;
                                _polygons[p].material.colour  = 0xFFFFFFFF;
                                _polygons[p].colour           = _polygons[p].material.colour;
                            }
                        }
                    }

                    if (options.RenderMode == RenderMode.DebugBSPRootTreeNumber)
                    {
                        ColourPolygonFromUInt(p, _polygons[p].RootBSPTreeNumber);
                    }

                    if (options.RenderMode == RenderMode.DebugBSPTreeNodeID)
                    {
                        ColourPolygonFromString(p, _polygons[p].BSPNodeID);
                    }

                    if (options.RenderMode == RenderMode.DebugBSPRootTreeFlagsHash)
                    {
                        ColourPolygonFromUInt(p, _polygons[p].material.BSPTreeRootFlags);
                    }
                    if (options.RenderMode == RenderMode.DebugBSPRootTreeFlags1)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.BSPTreeRootFlags, 0x0001, 0x0002, 0x0004);
                    }
                    if (options.RenderMode == RenderMode.DebugBSPRootTreeFlags2)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.BSPTreeRootFlags, 0x0008, 0x0010, 0x0020);
                    }
                    if (options.RenderMode == RenderMode.DebugBSPRootTreeFlags3)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.BSPTreeRootFlags, 0x0040, 0x0080, 0x0100);
                    }
                    if (options.RenderMode == RenderMode.DebugBSPRootTreeFlags4)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.BSPTreeRootFlags, 0x0200, 0x0400, 0x0800);
                    }
                    if (options.RenderMode == RenderMode.DebugBSPRootTreeFlags5)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.BSPTreeRootFlags, 0x1000, 0x2000, 0x4000);
                    }
                    if (options.RenderMode == RenderMode.DebugBSPRootTreeFlags6)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.BSPTreeRootFlags, 0x10000, 0x8000, 0x10000);
                    }

                    if (options.RenderMode == RenderMode.DebugBSPTreeImmediateParentFlagsHash)
                    {
                        ColourPolygonFromUInt(p, _polygons[p].material.BSPTreeParentNodeFlags);
                    }
                    if (options.RenderMode == RenderMode.DebugBSPTreeImmediateParentFlags1)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.BSPTreeParentNodeFlags, 0x0001, 0x0002, 0x0004);
                    }
                    if (options.RenderMode == RenderMode.DebugBSPTreeImmediateParentFlags2)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.BSPTreeParentNodeFlags, 0x0008, 0x0010, 0x0020);
                    }
                    if (options.RenderMode == RenderMode.DebugBSPTreeImmediateParentFlags3)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.BSPTreeParentNodeFlags, 0x0040, 0x0080, 0x0100);
                    }
                    if (options.RenderMode == RenderMode.DebugBSPTreeImmediateParentFlags4)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.BSPTreeParentNodeFlags, 0x0200, 0x0400, 0x0800);
                    }
                    if (options.RenderMode == RenderMode.DebugBSPTreeImmediateParentFlags5)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.BSPTreeParentNodeFlags, 0x1000, 0x2000, 0x4000);
                    }
                    if (options.RenderMode == RenderMode.DebugBSPTreeImmediateParentFlags6)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.BSPTreeParentNodeFlags, 0x10000, 0x8000, 0x10000);
                    }

                    UInt16 allParentFlagsORd = _polygons[p].material.BSPTreeAllParentNodeFlagsORd;
                    if (options.BSPRenderingIncludeLeafFlagsWhenORing)
                    {
                        allParentFlagsORd |= _polygons[p].material.BSPTreeLeafFlags;
                    }
                    if (options.BSPRenderingIncludeRootTreeFlagsWhenORing)
                    {
                        allParentFlagsORd |= _polygons[p].material.BSPTreeRootFlags;
                    }
                    if (options.RenderMode == RenderMode.DebugBSPTreeAllParentFlagsORdHash)
                    {
                        ColourPolygonFromUInt(p, allParentFlagsORd);
                    }
                    if (options.RenderMode == RenderMode.DebugBSPTreeAllParentFlagsORd1)
                    {
                        ColourPolygonFromFlags(p, allParentFlagsORd, 0x0001, 0x0002, 0x0004);
                    }
                    if (options.RenderMode == RenderMode.DebugBSPTreeImmediateParentFlags2)
                    {
                        ColourPolygonFromFlags(p, allParentFlagsORd, 0x0008, 0x0010, 0x0020);
                    }
                    if (options.RenderMode == RenderMode.DebugBSPTreeImmediateParentFlags3)
                    {
                        ColourPolygonFromFlags(p, allParentFlagsORd, 0x0040, 0x0080, 0x0100);
                    }
                    if (options.RenderMode == RenderMode.DebugBSPTreeImmediateParentFlags4)
                    {
                        ColourPolygonFromFlags(p, allParentFlagsORd, 0x0200, 0x0400, 0x0800);
                    }
                    if (options.RenderMode == RenderMode.DebugBSPTreeImmediateParentFlags5)
                    {
                        ColourPolygonFromFlags(p, allParentFlagsORd, 0x1000, 0x2000, 0x4000);
                    }
                    if (options.RenderMode == RenderMode.DebugBSPTreeImmediateParentFlags6)
                    {
                        ColourPolygonFromFlags(p, allParentFlagsORd, 0x10000, 0x8000, 0x10000);
                    }

                    if (options.RenderMode == RenderMode.DebugBSPTreeLeafFlagsHash)
                    {
                        ColourPolygonFromUInt(p, _polygons[p].material.BSPTreeLeafFlags);
                    }
                    if (options.RenderMode == RenderMode.DebugBSPTreeLeafFlags1)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.BSPTreeLeafFlags, 0x0001, 0x0002, 0x0004);
                    }
                    if (options.RenderMode == RenderMode.DebugBSPTreeLeafFlags2)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.BSPTreeLeafFlags, 0x0008, 0x0010, 0x0020);
                    }
                    if (options.RenderMode == RenderMode.DebugBSPTreeLeafFlags3)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.BSPTreeLeafFlags, 0x0040, 0x0080, 0x0100);
                    }
                    if (options.RenderMode == RenderMode.DebugBSPTreeLeafFlags4)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.BSPTreeLeafFlags, 0x0200, 0x0400, 0x0800);
                    }
                    if (options.RenderMode == RenderMode.DebugBSPTreeLeafFlags5)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.BSPTreeLeafFlags, 0x1000, 0x2000, 0x4000);
                    }
                    if (options.RenderMode == RenderMode.DebugBSPTreeLeafFlags6)
                    {
                        ColourPolygonFromFlags(p, _polygons[p].material.BSPTreeLeafFlags, 0x10000, 0x8000, 0x10000);
                    }

                    // default to grey for non-coloured elements - black makes it too hard to see anything in ModelEx

                    if ((_polygons[p].material.colour & 0x00FFFFFF) == 0x00000000)
                    {
                        _polygons[p].material.colour |= 0x80D0D0D0;
                    }
                    _polygons[p].colour = _polygons[p].material.colour;
                }
            }
        }
Beispiel #14
0
 public UnknownChunk(SRFile file, Chunk parent, ulong offset, uint size) : base(file, parent)
 {
     this.Offset = offset;
     this.Size   = size;
     this.Name   = "????";
 }
Beispiel #15
0
 public BUNDChunk(SRFile file, Chunk parent, string name, ulong offset, uint size) : base(file, parent, name, offset, size)
 {
 }
Beispiel #16
0
        protected virtual void HandlePolygonInfo(BinaryReader xReader, int p, CDC.Objects.ExportOptions options, byte flags, UInt32 colourOrMaterialPosition, bool forceTranslucent)
        {
            bool isTranslucent = false;

            if (forceTranslucent)
            {
                isTranslucent = true;
            }

            // unless the user has explicitly requested distinct materials for each flag, remove use of anything ignored at this level
            if (!options.DistinctMaterialsForAllFlags)
            {
                _polygons[p].material.clutValueUsedMask                   &= 0x3F1F;
                _polygons[p].material.texturePageUsedMask                 &= 0x07FF;
                _polygons[p].material.BSPTreeRootFlagsUsedMask             = 0x0000;
                _polygons[p].material.BSPTreeAllParentNodeFlagsORdUsedMask = 0x0000;
                _polygons[p].material.BSPTreeParentNodeFlagsUsedMask      &= 0x0001;
                _polygons[p].material.BSPTreeLeafFlagsUsedMask             = 0x0000;
            }

            _polygons[p].material.polygonFlags = flags;

            if (options.MakeAllPolygonsVisible)
            {
                _polygons[p].material.visible = true;
            }

            if (options.RenderMode == RenderMode.NoTextures)
            {
                _polygons[p].material.clutValueUsedMask                    = 0;
                _polygons[p].material.texturePageUsedMask                  = 0;
                _polygons[p].material.BSPTreeRootFlagsUsedMask             = 0;
                _polygons[p].material.BSPTreeAllParentNodeFlagsORdUsedMask = 0;
                _polygons[p].material.BSPTreeParentNodeFlagsUsedMask       = 0;
                _polygons[p].material.BSPTreeLeafFlagsUsedMask             = 0;
            }

            if (options.MakeAllPolygonsOpaque)
            {
                _polygons[p].material.colour |= 0xFF000000;
            }

            if (options.SetAllPolygonColoursToValue)
            {
                //_polygons[p].material.colour |= 0x0000FF00;
                _polygons[p].material.colour = SRFile.FloatARGBToUInt32ARGB(new float[] { options.PolygonColourAlpha, options.PolygonColourRed, options.PolygonColourGreen, options.PolygonColourBlue });
                _polygons[p].colour          = _polygons[p].material.colour;
            }

            if (_polygons[p].material.visible)
            {
                if (options.UnhideCompletelyTransparentTextures)
                {
                    if ((_polygons[p].material.colour & 0xFF000000) == 0x00)
                    {
                        _polygons[p].material.colour |= 0xFF000000;
                    }
                }

                // these cause big issues for object models, moving them to units
                if ((flags & 0x08) == 0x08)
                {
                    //_polygons[p].material.emissivity = 1.0f;
                }
                if ((flags & 0x10) == 0x10)
                {
                }
                if ((flags & 0x20) == 0x20)
                {
                    isTranslucent = true;
                    //_polygons[p].material.opacity = CDC.Material.OPACITY_TRANSLUCENT;
                }
            }

            //if (!_polygons[p].material.visible)
            //{
            //    if (options.DiscardNonVisible)
            //    {
            //        isTranslucent = true;
            //        _polygons[p].material.opacity = 0.0f;
            //        _polygons[p].material.colour &= 0x00000000;
            //        _polygons[p].colour &= 0x00000000;
            //    }
            //}
            //if (!_polygons[p].material.visible)
            //{
            //    _polygons[p].material.textureUsed = false;
            //    //_polygons[p].material.colour = (_polygons[p].material.colour & 0x00FFFFFF) | TransparentMaterial;
            //}
            //else
            //{
            //    _polygons[p].material.textureUsed = true;
            //}
            //_polygons[p].sr1TextureFT3Attributes = 0;
            if (_polygons[p].material.textureUsed)
            {
                HandleMaterialRead(xReader, p, options, flags, colourOrMaterialPosition);
            }
            else
            {
                //_polygons[p].material.textureUsed = false;
                //_polygons[p].material.colour = 0xFFFFFFFF;        //2019-12-22
                //_polygons[p].material.visible = false;
            }

            // 0x1, 2, 4, and 8 are not used in any known version of the game
            // alphamasked terrain
            if ((_polygons[p].material.textureAttributes & 0x0010) == 0x0010)
            {
                _polygons[p].material.UseAlphaMask = true;
            }
            // 20 is not used in any known version of the game
            // translucent terrain, e.g. water, glass
            if ((_polygons[p].material.textureAttributes & 0x0040) == 0x0040)
            {
                isTranslucent = true;
                _polygons[p].material.opacity = CDC.Material.OPACITY_TRANSLUCENT;
            }
            if ((_polygons[p].material.textureAttributes & 0x0080) == 0x0080)
            {
            }
            if ((_polygons[p].material.textureAttributes & 0x0100) == 0x0100)
            {
            }
            if ((_polygons[p].material.textureAttributes & 0x0200) == 0x0200)
            {
            }
            // 400 and 800 are not used in any known version of the game
            if ((_polygons[p].material.textureAttributes & 0x1000) == 0x1000)
            {
            }
            if ((_polygons[p].material.textureAttributes & 0x2000) == 0x2000)
            {
                isTranslucent = true;
                _polygons[p].material.opacity = CDC.Material.OPACITY_TRANSLUCENT;
            }
            if ((_polygons[p].material.textureAttributes & 0x4000) == 0x4000)
            {
                //_polygons[p].material.visible = false;
            }
            // lighting effects? i.e. invisible, animated polygon that only affects vertex colours?
            if ((_polygons[p].material.textureAttributes & 0x8000) == 0x8000)
            {
                _polygons[p].material.emissivity = 1.0f;
                //isTranslucent = true;
                //_polygons[p].material.opacity = 0.0f;
            }
            //if ((_polygons[p].sr1TextureFT3Attributes & 0x2000) == 0x2000)
            //{
            //    isTranslucent = true;
            //    //_polygons[p].colour = (_polygons[p].material.colour & 0x00FFFFFF) | BarelyVisibleMaterial;
            //    _polygons[p].material.opacity = CDC.Material.OPACITY_BARELY_VISIBLE;
            //    //_polygons[p].material.HasTranslucentElements = true;
            //}

            if (isTranslucent)
            {
                //_polygons[p].material.HasTranslucentElements = true;
                //_polygons[p].material.opacity = CDC.Material.OPACITY_TRANSLUCENT;
                //_polygons[p].material = _polygons[p].material.Clone();
                //_polygons[p].material.colour = (_polygons[p].material.colour & 0x00FFFFFF) | TranslucentMaterial;
            }
            else
            {
                //_polygons[p].colour = _polygons[p].material.colour | 0xFF000000;
            }



            Utility.FlipRedAndBlue(ref _polygons[p].material.colour);
        }
Beispiel #17
0
        public static ObjectInfo GetObjectInfo(Chunk chunk)
        {
            ObjectInfo info        = new ObjectInfo();
            Chunk      headerChunk = GetObjectImageHeader(chunk);
            SRFile     file        = chunk.File;

            file.Position = headerChunk.Offset + 8;
            uint mmucusVersion = file.ReadU16LE();

            if (headerChunk.Size >= 34 && mmucusVersion == 730)
            {
                // SCUMM 7
                file.Position   = headerChunk.Offset + 12;
                info.Version    = 7;
                info.Name       = "";
                info.Id         = file.ReadU16LE();
                info.ImageCount = file.ReadU16LE();
                file.ReadU16LE();
                file.ReadU16LE();
                info.X      = file.ReadU16LE();
                info.Y      = file.ReadU16LE();
                info.Width  = file.ReadU16LE();
                info.Height = file.ReadU16LE();
            }
            else if (headerChunk.Size == 24)
            {
                // SCUMM 5
                file.Position   = headerChunk.Offset + 8;
                info.Version    = 5;
                info.Name       = "";
                info.Id         = file.ReadU16LE();
                info.ImageCount = file.ReadU16LE();
                file.ReadU16LE();
                file.ReadU16LE();
                info.X      = file.ReadU16LE();
                info.Y      = file.ReadU16LE();
                info.Width  = file.ReadU16LE();
                info.Height = file.ReadU16LE();
            }
            else
            {
                mmucusVersion = 0;
                if (headerChunk.Size >= 52)
                {
                    file.Position = headerChunk.Offset + 48;
                    mmucusVersion = file.ReadU32LE();
                }
                if (mmucusVersion == 801)
                {
                    file.Position   = headerChunk.Offset + 8;
                    info.Version    = 8;
                    info.Name       = file.ReadStringZ();
                    file.Position   = headerChunk.Offset + 52;
                    info.Id         = -1;
                    info.ImageCount = file.ReadU32LE();
                    info.X          = file.ReadS32LE();
                    info.Y          = file.ReadS32LE();
                    info.Width      = file.ReadS32LE();
                    info.Height     = file.ReadS32LE();
                }
                else
                {
                    // SCUMM 6
                    file.Position   = headerChunk.Offset + 8;
                    info.Version    = 6;
                    info.Name       = "";
                    info.Id         = file.ReadU16LE();
                    info.ImageCount = file.ReadU16LE();
                    file.ReadU16LE();
                    file.ReadU16LE();
                    info.X      = file.ReadU16LE();
                    info.Y      = file.ReadU16LE();
                    info.Width  = file.ReadU16LE();
                    info.Height = file.ReadU16LE();
                }
            }

            return(info);
        }
Beispiel #18
0
 public TTARCHChunk(SRFile file, Chunk parent) : base(file, parent)
 {
     this.Name   = "TTARCH";
     this.Offset = file.Position;
     this.Size   = file.Size;
 }
Beispiel #19
0
 public ForgeChunk(SRFile file, Chunk parent) : base(file, parent)
 {
     this.Name   = "Forge";
     this.Offset = 0;
     this.Size   = file.Size;
 }
Beispiel #20
0
 public ForgeFileChunk(DataBlockInfo info, SRFile file, Chunk parent) : base(file, parent)
 {
     Offset = info.Offset;
     Size   = info.Size;
     Name   = info.Name;
 }
Beispiel #21
0
 protected Chunk(SRFile file, Chunk parent)
 {
     this.file = file;
     Parent    = parent;
 }
Beispiel #22
0
 private bool CheckFormat(SRFile file)
 {
     return(file.ReadString(8) == "scimitar");
 }
Beispiel #23
0
 public BNDTChunk(SRFile file, Chunk parent, ulong offset, uint size) : base(file, parent)
 {
     Name   = "BNDT";
     Offset = offset;
     Size   = size;
 }