示例#1
0
 internal void InsertORSpecificData(SBR block)
 {
     block.VerifyID(TokenID.Tr_Worldfile);
     while (!block.EndOfBlock())
     {
         using (SBR subBlock = block.ReadSubBlock())
         {
             try
             {
                 WorldObject origObject;
                 bool        wrongBlock = false;
                 if (!subBlock.EndOfBlock())
                 {
                     SBR subSubBlockUID = subBlock.ReadSubBlock();
                     // check if a block with this UiD already present
                     if (subSubBlockUID.ID == TokenID.UiD)
                     {
                         uint UID = subSubBlockUID.ReadUInt();
                         origObject = Find(x => x.UiD == UID);
                         if (origObject == null)
                         {
                             wrongBlock = true;
                             Trace.TraceWarning("Skipped world block {0} (0x{0:X}), UID {1} not matching with base file", subBlock.ID, UID);
                             subSubBlockUID.Skip();
                             subBlock.Skip();
                         }
                         else
                         {
                             wrongBlock = !TestMatch(subBlock, origObject);
                             if (!wrongBlock)
                             {
                                 subSubBlockUID.Skip();
                                 while (!subBlock.EndOfBlock() && !wrongBlock)
                                 {
                                     using (SBR subSubBlock = subBlock.ReadSubBlock())
                                     {
                                         origObject.AddOrModifyObj(subSubBlock);
                                     }
                                 }
                             }
                             else
                             {
                                 Trace.TraceWarning("Skipped world block {0} (0x{0:X}), UID {1} not matching with base file", subBlock.ID, UID);
                                 subSubBlockUID.Skip();
                                 subBlock.Skip();
                             }
                         }
                     }
                 }
                 subBlock.EndOfBlock();
             }
             catch (Exception error)
             {
                 Trace.WriteLine(new FileLoadException(block.FileName, error));
             }
         }
     }
 }
示例#2
0
        internal Terrain(SBR block)
        {
            block.VerifyID(TokenID.Terrain);
            while (!block.EndOfBlock())
            {
                using (SBR subBlock = block.ReadSubBlock())
                {
                    switch (subBlock.ID)
                    {
                    case TokenID.Terrain_ErrThreshold_Scale:
                        ErrorThresholdScale = subBlock.ReadFloat();
                        break;

                    case TokenID.Terrain_Water_Height_Offset:
                        WaterLevelOffset = new WaterLevelOffset(subBlock);
                        break;

                    case TokenID.Terrain_AlwaysSelect_MaxDist:
                        AlwaysSelectMaxDistance = subBlock.ReadFloat();
                        break;

                    case TokenID.Terrain_Samples:
                        Samples = new Samples(subBlock);
                        break;

                    case TokenID.Terrain_Shaders:
                        Shaders = new Shader[subBlock.ReadInt()];
                        for (int i = 0; i < Shaders.Length; ++i)
                        {
                            using (SBR terrain_shadersBlock = subBlock.ReadSubBlock())
                                Shaders[i] = new Shader(terrain_shadersBlock);
                        }
                        if (!subBlock.EndOfBlock())
                        {
                            subBlock.Skip();
                        }
                        break;

                    case TokenID.Terrain_Patches:
                        using (SBR patch_sets_Block = subBlock.ReadSubBlock())
                        {
                            Patchsets = new PatchSet[patch_sets_Block.ReadInt()];
                            for (int i = 0; i < Patchsets.Length; ++i)
                            {
                                using (SBR terrain_patchsetBlock = patch_sets_Block.ReadSubBlock())
                                    Patchsets[i] = new PatchSet(terrain_patchsetBlock);
                            }
                            if (!subBlock.EndOfBlock())
                            {
                                subBlock.Skip();
                            }
                        }
                        break;
                    }
                }
            }
        }
示例#3
0
        protected void ReadBlock(SBR block, int tileX, int tileZ)
        {
            PositionHolder holder = new PositionHolder()
            {
                TileX = tileX,
                TileZ = tileZ,
            };

            while (!block.EndOfBlock())
            {
                using (var subBlock = block.ReadSubBlock())
                {
                    if (subBlock.ID == TokenID.UiD)
                    {
                        UiD = subBlock.ReadUInt();
                    }
                    else
                    {
                        AddOrModifyObj(subBlock, holder);
                    }
                }
            }
            worldPosition = PositionHolder.WorldPositionFromMSTSLocation(holder, UiD);
            if (this is HazardObject hazard)  //remember the Quaternation component
            {
                hazard.Direction = holder.Direction;
            }
        }
示例#4
0
        public terrain_shader(SBR block)
        {
            block.VerifyID(TokenID.terrain_shader);
            ShaderName = block.ReadString();
            while (!block.EndOfBlock())
            {
                using (var subBlock = block.ReadSubBlock())
                {
                    switch (subBlock.ID)
                    {
                    case TokenID.terrain_texslots:
                        terrain_texslots = new terrain_texslot[subBlock.ReadUInt()];
                        for (var i = 0; i < terrain_texslots.Length; ++i)
                        {
                            terrain_texslots[i] = new terrain_texslot(subBlock.ReadSubBlock());
                        }
                        break;

                    case TokenID.terrain_uvcalcs:
                        terrain_uvcalcs = new terrain_uvcalc[subBlock.ReadUInt()];
                        for (var i = 0; i < terrain_uvcalcs.Length; ++i)
                        {
                            terrain_uvcalcs[i] = new terrain_uvcalc(subBlock.ReadSubBlock());
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
        }
示例#5
0
        public PatchSet(SBR block)
        {
            block.VerifyID(TokenID.Terrain_PatchSet);
            while (!block.EndOfBlock())
            {
                using (var subBlock = block.ReadSubBlock())
                {
                    switch (subBlock.ID)
                    {
                    case TokenID.Terrain_PatchSet_Distance:
                        Distance = subBlock.ReadInt();
                        break;

                    case TokenID.Terrain_PatchSet_NPatches:
                        PatchSize = subBlock.ReadInt();
                        break;

                    case TokenID.Terrain_PatchSet_Patches:
                        Patches = new Patch[PatchSize * PatchSize];
                        for (var i = 0; i < Patches.Length; ++i)
                        {
                            Patches[i] = new Patch(subBlock.ReadSubBlock());
                        }
                        break;
                    }
                }
            }
        }
示例#6
0
        public terrain_patchset(SBR block)
        {
            block.VerifyID(TokenID.terrain_patchset);
            while (!block.EndOfBlock())
            {
                using (var subBlock = block.ReadSubBlock())
                {
                    switch (subBlock.ID)
                    {
                    case TokenID.terrain_patchset_distance:
                        terrain_patchset_distance = subBlock.ReadInt();
                        break;

                    case TokenID.terrain_patchset_npatches:
                        terrain_patchset_npatches = subBlock.ReadInt();
                        break;

                    case TokenID.terrain_patchset_patches:
                        terrain_patchset_patches = new terrain_patchset_patch[terrain_patchset_npatches * terrain_patchset_npatches];
                        for (var i = 0; i < terrain_patchset_patches.Length; ++i)
                        {
                            terrain_patchset_patches[i] = new terrain_patchset_patch(subBlock.ReadSubBlock());
                        }
                        break;
                    }
                }
            }
        }
示例#7
0
        internal Shader(SBR block)
        {
            block.VerifyID(TokenID.Terrain_Shader);
            Name = block.ReadString();
            while (!block.EndOfBlock())
            {
                using (SBR subBlock = block.ReadSubBlock())
                {
                    switch (subBlock.ID)
                    {
                    case TokenID.Terrain_TexSlots:
                        int size = (int)subBlock.ReadUInt();
                        Textureslots = new List <TextureSlot>(size);
                        for (int i = 0; i < size; ++i)
                        {
                            Textureslots.Add(new TextureSlot(subBlock.ReadSubBlock()));
                        }
                        break;

                    case TokenID.Terrain_UVCalcs:
                        size    = (int)subBlock.ReadUInt();
                        UVCalcs = new List <UVCalc>(size);
                        for (int i = 0; i < size; ++i)
                        {
                            UVCalcs.Add(new UVCalc(subBlock.ReadSubBlock()));
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
        }
示例#8
0
        internal PatchSet(SBR block)
        {
            block.VerifyID(TokenID.Terrain_PatchSet);
            while (!block.EndOfBlock())
            {
                using (SBR subBlock = block.ReadSubBlock())
                {
                    switch (subBlock.ID)
                    {
                    case TokenID.Terrain_PatchSet_Distance:
                        Distance = subBlock.ReadInt();
                        break;

                    case TokenID.Terrain_PatchSet_NPatches:
                        PatchSize = subBlock.ReadInt();
                        break;

                    case TokenID.Terrain_PatchSet_Patches:
                        Patches = new List <Patch>(PatchSize * PatchSize);
                        for (int i = 0; i < (PatchSize * PatchSize); ++i)
                        {
                            Patches.Add(new Patch(subBlock.ReadSubBlock()));
                        }
                        break;
                    }
                }
            }
        }
示例#9
0
        public Shader(SBR block)
        {
            block.VerifyID(TokenID.Terrain_Shader);
            Name = block.ReadString();
            while (!block.EndOfBlock())
            {
                using (var subBlock = block.ReadSubBlock())
                {
                    switch (subBlock.ID)
                    {
                    case TokenID.Terrain_TexSlots:
                        Textureslots = new TextureSlot[subBlock.ReadUInt()];
                        for (var i = 0; i < Textureslots.Length; ++i)
                        {
                            Textureslots[i] = new TextureSlot(subBlock.ReadSubBlock());
                        }
                        break;

                    case TokenID.Terrain_UVCalcs:
                        UVCalcs = new UVCalc[subBlock.ReadUInt()];
                        for (var i = 0; i < UVCalcs.Length; ++i)
                        {
                            UVCalcs[i] = new UVCalc(subBlock.ReadSubBlock());
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
        }
示例#10
0
 public Shape(SBR block)
 {
     block.VerifyID(TokenID.Shape);
     ShapeHeader        = new ShapeHeader(block.ReadSubBlock());
     Volumes            = new Volumes(block.ReadSubBlock());
     ShaderNames        = new ShaderNames(block.ReadSubBlock());
     TextureFilterNames = new TextureFilterNames(block.ReadSubBlock());
     Points             = new Points(block.ReadSubBlock());
     UVPoints           = new UVPoints(block.ReadSubBlock());
     Normals            = new Normals(block.ReadSubBlock());
     SortVectors        = new SortVectors(block.ReadSubBlock());
     Colors             = new Colors(block.ReadSubBlock());
     Matrices           = new Matrices(block.ReadSubBlock());
     ImageNames         = new ImageNames(block.ReadSubBlock());
     Textures           = new Textures(block.ReadSubBlock());
     LightMaterials     = new LightMaterials(block.ReadSubBlock());
     LightModelConfigs  = new LightModelConfigs(block.ReadSubBlock());
     VertexStates       = new VertexStates(block.ReadSubBlock());
     PrimaryStates      = new PrimaryStates(block.ReadSubBlock());
     LodControls        = new LodControls(block.ReadSubBlock());
     if (!block.EndOfBlock())
     {
         Animations = new Animations(block.ReadSubBlock());
     }
     block.VerifyEndOfBlock();
 }
示例#11
0
        public terrain_samples(SBR block)
        {
            block.VerifyID(TokenID.terrain_samples);
            while (!block.EndOfBlock())
            {
                using (var subBlock = block.ReadSubBlock())
                {
                    switch (subBlock.ID)
                    {
                    case TokenID.terrain_nsamples:
                        terrain_nsamples = subBlock.ReadInt();
                        break;

                    case TokenID.terrain_sample_rotation:
                        terrain_sample_rotation = subBlock.ReadFloat();
                        break;

                    case TokenID.terrain_sample_floor:
                        terrain_sample_floor = subBlock.ReadFloat();
                        break;

                    case TokenID.terrain_sample_scale:
                        terrain_sample_scale = subBlock.ReadFloat();
                        break;

                    case TokenID.terrain_sample_size:
                        terrain_sample_size = subBlock.ReadFloat();
                        break;

                    case TokenID.terrain_sample_ybuffer:
                        terrain_sample_ybuffer = subBlock.ReadString();
                        break;

                    case TokenID.terrain_sample_ebuffer:
                        terrain_sample_ebuffer = subBlock.ReadString();
                        break;

                    case TokenID.terrain_sample_nbuffer:
                        terrain_sample_nbuffer = subBlock.ReadString();
                        break;

                    case TokenID.terrain_sample_asbuffer:
                        subBlock.Skip();     // TODO parse this
                        break;

                    case TokenID.terrain_sample_fbuffer:
                        subBlock.Skip();     // TODO parse this
                        break;

                    case (TokenID)282:      // TODO figure out what this is and handle it
                        subBlock.Skip();
                        break;

                    default:
                        throw new InvalidDataException("Unknown token " + subBlock.ID.ToString());
                    }
                }
            }
        }
示例#12
0
        internal Samples(SBR block)
        {
            block.VerifyID(TokenID.Terrain_Samples);
            while (!block.EndOfBlock())
            {
                using (SBR subBlock = block.ReadSubBlock())
                {
                    switch (subBlock.ID)
                    {
                    case TokenID.Terrain_NSamples:
                        SampleCount = subBlock.ReadInt();
                        break;

                    case TokenID.Terrain_Sample_Rotation:
                        SampleRotation = subBlock.ReadFloat();
                        break;

                    case TokenID.Terrain_Sample_Floor:
                        SampleFloor = subBlock.ReadFloat();
                        break;

                    case TokenID.Terrain_Sample_Scale:
                        SampleScale = subBlock.ReadFloat();
                        break;

                    case TokenID.Terrain_Sample_Size:
                        SampleSize = subBlock.ReadFloat();
                        break;

                    case TokenID.Terrain_Sample_YBuffer:
                        SampleBufferY = subBlock.ReadString();
                        break;

                    case TokenID.Terrain_Sample_EBuffer:
                        SampleBufferE = subBlock.ReadString();
                        break;

                    case TokenID.Terrain_Sample_NBuffer:
                        SampleBufferN = subBlock.ReadString();
                        break;

                    case TokenID.Terrain_Sample_AsBuffer:
                        subBlock.Skip();     // TODO parse this
                        break;

                    case TokenID.Terrain_Sample_FBuffer:
                        subBlock.Skip();     // TODO parse this
                        break;

                    case (TokenID)282:      // TODO figure out what this is and handle it
                        subBlock.Skip();
                        break;

                    default:
                        throw new InvalidDataException("Unknown token " + subBlock.ID.ToString());
                    }
                }
            }
        }
示例#13
0
        public terrain(SBR block)
        {
            block.VerifyID(TokenID.terrain);
            while (!block.EndOfBlock())
            {
                using (var subBlock = block.ReadSubBlock())
                {
                    switch (subBlock.ID)
                    {
                    case TokenID.terrain_errthreshold_scale:
                        terrain_errthreshold_scale = subBlock.ReadFloat();
                        break;

                    case TokenID.terrain_water_height_offset:
                        terrain_water_height_offset = new terrain_water_height_offset(subBlock);
                        break;

                    case TokenID.terrain_alwaysselect_maxdist:
                        terrain_alwaysselect_maxdist = subBlock.ReadFloat();
                        break;

                    case TokenID.terrain_samples:
                        terrain_samples = new terrain_samples(subBlock);
                        break;

                    case TokenID.terrain_shaders:
                        terrain_shaders = new terrain_shader[subBlock.ReadInt()];
                        for (var i = 0; i < terrain_shaders.Length; ++i)
                        {
                            using (var terrain_shadersBlock = subBlock.ReadSubBlock())
                                terrain_shaders[i] = new terrain_shader(terrain_shadersBlock);
                        }
                        if (!subBlock.EndOfBlock())
                        {
                            subBlock.Skip();
                        }
                        break;

                    case TokenID.terrain_patches:
                        using (var patch_sets_Block = subBlock.ReadSubBlock())
                        {
                            terrain_patchsets = new terrain_patchset[patch_sets_Block.ReadInt()];
                            for (var i = 0; i < terrain_patchsets.Length; ++i)
                            {
                                using (var terrain_patchsetBlock = patch_sets_Block.ReadSubBlock())
                                    terrain_patchsets[i] = new terrain_patchset(terrain_patchsetBlock);
                            }
                            if (!subBlock.EndOfBlock())
                            {
                                subBlock.Skip();
                            }
                        }
                        break;
                    }
                }
            }
        }
示例#14
0
 public ShapeHeader(SBR block)
 {
     block.VerifyID(TokenID.Shape_Header);
     Flags1 = block.ReadFlags();
     if (!block.EndOfBlock())
     {
         Flags2 = block.ReadFlags();
     }
     block.VerifyEndOfBlock();
 }
示例#15
0
        public SubObjectHeader(SBR block)
        {
            block.VerifyID(TokenID.Sub_Object_Header);

            Flags                        = block.ReadFlags();
            SortVectorIndex              = block.ReadInt();
            VolumeIndex                  = block.ReadInt();
            SourceVertexFormatFlags      = block.ReadFlags();
            DestinationVertexFormatFlags = block.ReadFlags();
            GeometryInfo                 = new GeometryInfo(block.ReadSubBlock());

            if (!block.EndOfBlock())
            {
                var subBlock = block.ReadSubBlock();
                subBlock.VerifyID(TokenID.SubObject_Shaders);
                SubObjectShaders = new int[subBlock.ReadInt()];
                for (var i = 0; i < SubObjectShaders.Length; ++i)
                {
                    SubObjectShaders[i] = subBlock.ReadInt();
                }
                subBlock.VerifyEndOfBlock();
            }

            if (!block.EndOfBlock())
            {
                var subBlock = block.ReadSubBlock();
                subBlock.VerifyID(TokenID.SubObject_Light_Cfgs);
                SubObjectLightConfigs = new int[subBlock.ReadInt()];
                for (var i = 0; i < SubObjectLightConfigs.Length; ++i)
                {
                    SubObjectLightConfigs[i] = subBlock.ReadInt();
                }
                subBlock.VerifyEndOfBlock();
            }

            if (!block.EndOfBlock())
            {
                SubObjectID = block.ReadInt();
            }

            block.VerifyEndOfBlock();
        }
示例#16
0
 internal WaterLevelOffset(SBR block)
 {
     block.VerifyID(TokenID.Terrain_Water_Height_Offset);
     if (!block.EndOfBlock())
     {
         SW = block.ReadFloat();
     }
     if (!block.EndOfBlock())
     {
         SE = block.ReadFloat();
     }
     if (!block.EndOfBlock())
     {
         NE = block.ReadFloat();
     }
     if (!block.EndOfBlock())
     {
         NW = block.ReadFloat();
     }
 }
示例#17
0
 public terrain_water_height_offset(SBR block)
 {
     block.VerifyID(TokenID.terrain_water_height_offset);
     if (!block.EndOfBlock())
     {
         SW = block.ReadFloat();
     }
     if (!block.EndOfBlock())
     {
         SE = block.ReadFloat();
     }
     if (!block.EndOfBlock())
     {
         NE = block.ReadFloat();
     }
     if (!block.EndOfBlock())
     {
         NW = block.ReadFloat();
     }
 }
示例#18
0
 public Texture(SBR block)
 {
     block.VerifyID(TokenID.Texture);
     ImageIndex    = block.ReadInt();
     FilterMode    = block.ReadInt();
     MipMapLODBias = block.ReadFloat();
     if (!block.EndOfBlock())
     {
         BorderColor = block.ReadFlags();
     }
     block.VerifyEndOfBlock();
 }
示例#19
0
 public VertexState(SBR block)
 {
     block.VerifyID(TokenID.Vtx_State);
     Flags            = block.ReadFlags();
     MatrixIndex      = block.ReadInt();
     LightMatrixIndex = block.ReadInt();
     LightConfigIndex = block.ReadInt();
     LightFlags       = block.ReadFlags();
     if (!block.EndOfBlock())
     {
         Matrix2 = block.ReadInt();
     }
     block.VerifyEndOfBlock();
 }
示例#20
0
        internal WorldObjects(SBR block, List <TokenID> allowedTokens, int tileX, int tileZ)
        {
            block.VerifyID(TokenID.Tr_Worldfile);
            int detailLevel = 0;

            while (!block.EndOfBlock())
            {
                using (var subBlock = block.ReadSubBlock())
                {
                    try
                    {
                        if (allowedTokens == null || allowedTokens.Contains(subBlock.ID))
                        {
                            switch (subBlock.ID)
                            {
                            case TokenID.CollideObject:
                            case TokenID.Static:
                                Add(new StaticObject(subBlock, detailLevel, tileX, tileZ));
                                break;

                            case TokenID.TrackObj:
                                Add(new TrackObject(subBlock, detailLevel, tileX, tileZ));
                                break;

                            case TokenID.CarSpawner:
                            case (TokenID)357:
                                Add(new CarSpawnerObject(subBlock, detailLevel, tileX, tileZ));
                                break;

                            case TokenID.Siding:
                            case (TokenID)361:
                                Add(new SidingObject(subBlock, detailLevel, tileX, tileZ));
                                break;

                            case TokenID.Platform:
                                Add(new PlatformObject(subBlock, detailLevel, tileX, tileZ));
                                break;

                            case TokenID.Forest:
                                Add(new ForestObject(subBlock, detailLevel, tileX, tileZ));
                                break;

                            case TokenID.LevelCr:
                                Add(new LevelCrossingObject(subBlock, detailLevel, tileX, tileZ));
                                break;

                            case TokenID.Dyntrack:
                            case (TokenID)306:
                                Add(new DynamicTrackObject(subBlock, detailLevel, tileX, tileZ));
                                break;

                            case TokenID.Transfer:
                            case (TokenID)363:
                                Add(new TransferObject(subBlock, detailLevel, tileX, tileZ));
                                break;

                            case TokenID.Gantry:
                            case (TokenID)356:
                                // TODO: Add real handling for gantry objects.
                                Add(new BasicObject(subBlock, detailLevel, tileX, tileZ));
                                break;

                            case TokenID.Pickup:
                            case (TokenID)359:
                                Add(new PickupObject(subBlock, detailLevel, tileX, tileZ));
                                break;

                            case TokenID.Hazard:
                                //case (TokenID)359:
                                Add(new HazardObject(subBlock, detailLevel, tileX, tileZ));
                                break;

                            case TokenID.Signal:
                                Add(new SignalObject(subBlock, detailLevel, tileX, tileZ));
                                break;

                            case TokenID.Speedpost:
                                Add(new SpeedPostObject(subBlock, detailLevel, tileX, tileZ));
                                break;

                            case TokenID.Tr_Watermark:
                                detailLevel = subBlock.ReadInt();
                                break;

                            default:
                                if (!UnknownBlockIDs.Contains(subBlock.ID))
                                {
                                    UnknownBlockIDs.Add(subBlock.ID);
                                    Trace.TraceWarning("Skipped unknown world block {0} (0x{0:X}) first seen in {1}", subBlock.ID, subBlock.FileName);
                                }
                                subBlock.Skip();
                                break;
                            }
                        }
                        else
                        {
                            subBlock.Skip();
                        }
                    }
                    catch (Exception error)
                    {
                        Trace.WriteLine(new FileLoadException(subBlock.FileName, error));
                    }
                }
            }
        }