static void LoadStaticProps()
        {
            BSPFileReader.BaseStream.Seek(BSP_Header.Lumps[35].FileOfs, SeekOrigin.Begin);
            Int32 GameLumpCount = BSPFileReader.ReadInt32();

            dgamelump_t[] BSP_GameLump = new dgamelump_t[GameLumpCount];
            BSPFileReader.ReadArray(ref BSP_GameLump);

            for (Int32 i = 0; i < GameLumpCount; i++)
            {
                if (BSP_GameLump[i].Id == 1936749168)
                {
                    BSPFileReader.BaseStream.Seek(BSP_GameLump[i].FileOfs, SeekOrigin.Begin);

                    var Start = BSPFileReader.BaseStream.Position;

                    String[] ModelEntries = new String[BSPFileReader.ReadInt32()];
                    for (Int32 j = 0; j < ModelEntries.Length; j++)
                    {
                        ModelEntries[j] = new String(BSPFileReader.ReadChars(128)).Replace(".mdl", "");

                        if (ModelEntries[j].Contains('\0'))
                        {
                            ModelEntries[j] = ModelEntries[j].Split('\0')[0];
                        }
                    }

                    UInt16[] LeafEntries = new UInt16[BSPFileReader.ReadInt32()];
                    BSPFileReader.ReadArray(ref LeafEntries);

                    Int32 nStaticProps = BSPFileReader.ReadInt32();
                    //prop_size = (size -(reader.tell()-start))//self.prop_num

                    //REDxEYE "fix".
                    Int32 prop_size = 0;
                    try
                    {
                        prop_size = (Int32)((BSP_GameLump[i].FileLen - (BSPFileReader.BaseStream.Position - Start)) / nStaticProps);
                    }
                    catch (DivideByZeroException)
                    {
                        Debug.Log(String.Format("Static props not found. Division of {0} by zero.", nStaticProps));
                    }

                    for (Int32 l = 0; l < nStaticProps; l++)
                    {
                        var prop_start = BSPFileReader.BaseStream.Position;
                        StaticPropLumpV4_t StaticPropLump_t = new StaticPropLumpV4_t();
                        BSPFileReader.ReadType(ref StaticPropLump_t);

                        switch (BSP_GameLump[i].Version)
                        {
                        case 5:
                            BSPFileReader.ReadBytes(Marshal.SizeOf(typeof(StaticPropLumpV5_t)));
                            break;

                        case 6:
                            BSPFileReader.ReadBytes(Marshal.SizeOf(typeof(StaticPropLumpV6_t)));
                            break;

                        case 7:
                            BSPFileReader.ReadBytes(Marshal.SizeOf(typeof(StaticPropLumpV7_t)));
                            break;

                        case 8:
                            BSPFileReader.ReadBytes(Marshal.SizeOf(typeof(StaticPropLumpV8_t)));
                            break;

                        case 9:
                            BSPFileReader.ReadBytes(Marshal.SizeOf(typeof(StaticPropLumpV9_t)));
                            break;

                        case 10:
                            BSPFileReader.ReadBytes(Marshal.SizeOf(typeof(StaticPropLumpV10_t)));
                            break;
                        }

                        BSPFileReader.BaseStream.Seek(prop_start + prop_size, 0);

                        String    StaticPropName = ModelEntries[StaticPropLump_t.m_PropType];
                        Transform MdlTransform   = StudioMDLLoader.Load(StaticPropName);

                        MdlTransform.position = MathUtils.SwapZY(StaticPropLump_t.m_Origin) * ConfigLoader.WorldScale;
                        Vector3 EulerAngles = new Vector3(StaticPropLump_t.m_Angles.z, -StaticPropLump_t.m_Angles.y, StaticPropLump_t.m_Angles.x);
                        MdlTransform.eulerAngles = EulerAngles;

                        MdlTransform.SetParent(BSP_WorldSpawn.transform);
                    }
                }
            }
        }
Пример #2
0
        static void LoadGameAndProps(BinaryReader br, Header header)
        {
            // Game Lump
            dgamelumpheader_t gameheader = new dgamelumpheader_t();
            br.BaseStream.Seek(header.lumps[35].fileofs, SeekOrigin.Begin);
            int gamelen = header.lumps[35].filelen;
            gameheader.lumpCount = br.ReadInt32();
            gameheader.gamelump = new dgamelump_t[gameheader.lumpCount];
            for (int i = 0; i < gameheader.lumpCount; i++)
            {
                dgamelump_t game = new dgamelump_t();
                game.id = br.ReadInt32();
                game.flags = br.ReadUInt16();
                game.version = br.ReadUInt16();
                game.fileofs = br.ReadInt32();
                game.filelen = br.ReadInt32();

                gameheader.gamelump[i] = game;
            }

            // Read Static Props
            foreach (dgamelump_t game in gameheader.gamelump)
            {
                if (game.id == 1936749168)
                {
                    // read prop dict
                    StaticPropDictLump_t dict = new StaticPropDictLump_t();
                    br.BaseStream.Seek(game.fileofs, SeekOrigin.Begin);
                    dict.dictEntries = br.ReadInt32();
                    dict.Name = new string[dict.dictEntries];
                    Dictionary<string, SourceModel> srcmodels = new Dictionary<string, SourceModel>();
                    for (int i = 0; i < dict.dictEntries; i++)
                    {
                        char[] name = br.ReadChars(128);
                        dict.Name[i] = new string(name);
                        // cut \0 chars
                        int dindex = -1;
                        if ((dindex = dict.Name[i].IndexOf('\0')) != -1)
                        {
                            dict.Name[i] = dict.Name[i].Substring(0, dindex);
                            if (MDLReader.ReadFile(dict.Name[i]))
                            {
                                MDLReader.srcModel.Name = dict.Name[i];
                                srcmodels.Add(MDLReader.srcModel.Name, MDLReader.srcModel);
                            }
                        }
                    }

                    // Read prop leafs
                    StaticPropLeafLump_t propleaf = new StaticPropLeafLump_t();
                    propleaf.leafEntries = br.ReadInt32();
                    propleaf.leaf = new ushort[propleaf.leafEntries];
                    for (int i = 0; i < propleaf.leafEntries; i++)
                    {
                        propleaf.leaf[i] = br.ReadUInt16();
                    }
                    world.propleafs = propleaf;

                    // read props
                    int nStaticProps = br.ReadInt32();
                    StaticPropLump_t[] props = new StaticPropLump_t[nStaticProps];
                    for (int i = 0; i < nStaticProps; i++)
                    {
                        StaticPropLump_t prop = new StaticPropLump_t();
                        prop.Origin = SwapZY(new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()));
                        prop.Angles = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                        prop.PropType = br.ReadUInt16();
                        prop.PropName = dict.Name[(int)prop.PropType];
                        prop.FirstLeaf = br.ReadUInt16();
                        prop.LeafCount = br.ReadUInt16();
                        prop.Solid = br.ReadByte();
                        prop.Flags = br.ReadByte();
                        prop.Skin = br.ReadInt32();
                        prop.FadeMinDist = br.ReadSingle();
                        prop.FadeMaxDist = br.ReadSingle();
                        prop.LightingOrigin = SwapZY(new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()));
                        if (game.version == 5)
                            prop.ForcedFaceScale = br.ReadSingle();
                        else
                            prop.ForcedFaceScale = 1f;

                        props[i] = prop;
                        SourceProp sprop = new SourceProp(prop);
                        if (srcmodels.ContainsKey(prop.PropName))
                        {
                            sprop.srcModel = srcmodels[prop.PropName];

                            world.sourceProps.Add(sprop);
                        }

                        // Index into leaves
                        if (prop.LeafCount + prop.FirstLeaf < world.propleafs.leafEntries)
                        {
                            for (int j = 0; j < prop.LeafCount; j++)
                            {
                                ushort leafIndex = world.propleafs.leaf[prop.FirstLeaf + j];
                                if (leafIndex >= world.leafs.Length)
                                {
                                    int test = 2;
                                }
                                world.leafs[leafIndex].staticProps.Add(sprop);
                            }
                        }
                    }
                    world.props = props;

                    break;
                }
            }
        }
Пример #3
0
    public StaticProps_t GetStaticProps()
    {
        dgamelump_t lump = null;

        //Debug.Log("# Game Lumps: " + gameLumpHeader.gamelump.Length);
        for (int i = 0; i < gameLumpHeader.gamelump.Length; i++)
        {
            //Debug.Log("Static Prop Dict Index: " + i + " id: " + gameLumpHeader.gamelump[i].id + " fileofs: " + gameLumpHeader.gamelump[i].fileofs + " filelen: " + gameLumpHeader.gamelump[i].filelen + " version: " + gameLumpHeader.gamelump[i].version);
            if (gameLumpHeader.gamelump[i].id == 1936749168)
            {
                lump = gameLumpHeader.gamelump[i];
            }
        }

        StaticProps_t staticProps = new StaticProps_t();

        //staticProp.staticPropDict = new StaticPropDictLump_t();
        if (lump != null)
        {
            stream.Position = lump.fileofs;

            #region Dict Lump
            staticProps.staticPropDict.dictEntries = FileReader.readInt(stream);
            staticProps.staticPropDict.names       = new string[staticProps.staticPropDict.dictEntries];

            for (int i = 0; i < staticProps.staticPropDict.names.Length; i++)
            {
                char[] nullPaddedName = new char[128];
                for (int j = 0; j < nullPaddedName.Length; j++)
                {
                    nullPaddedName[j] = FileReader.readChar(stream);
                }
                staticProps.staticPropDict.names[i] = new string(nullPaddedName);
                //Debug.Log(i + ": " + staticProps.staticPropDict.names[i]);
            }
            #endregion

            #region Leaf Lump
            staticProps.staticPropLeaf.leafEntries = FileReader.readInt(stream);
            staticProps.staticPropLeaf.leaf        = new ushort[staticProps.staticPropLeaf.leafEntries];

            for (int i = 0; i < staticProps.staticPropLeaf.leaf.Length; i++)
            {
                staticProps.staticPropLeaf.leaf[i] = FileReader.readUShort(stream);
            }
            //Debug.Log("Leaf Entries: " + staticProps.staticPropLeaf.leaf.Length);
            #endregion

            #region Info Lump
            staticProps.staticPropInfo = new StaticPropLump_t[FileReader.readInt(stream)];
            //long currentSizeUsed = stream.Position - lump.fileofs;
            //Debug.Log("Used: " + currentSizeUsed + " Intended Length: " + lump.filelen + " BytesPerInfo: " + ((lump.filelen - currentSizeUsed) / staticProps.staticPropInfo.Length));
            //int largestIndex = -1;
            for (int i = 0; i < staticProps.staticPropInfo.Length; i++)
            {
                staticProps.staticPropInfo[i].Origin = new Vector3(FileReader.readFloat(stream), FileReader.readFloat(stream), FileReader.readFloat(stream)); // origin
                staticProps.staticPropInfo[i].Origin = new Vector3(staticProps.staticPropInfo[i].Origin.x, staticProps.staticPropInfo[i].Origin.z, staticProps.staticPropInfo[i].Origin.y);
                staticProps.staticPropInfo[i].Angles = new Vector3(FileReader.readFloat(stream), FileReader.readFloat(stream), FileReader.readFloat(stream)); // orientation (pitch roll yaw)
                //staticProps.staticPropInfo[i].Angles = new Vector3(staticProps.staticPropInfo[i].Angles.x, staticProps.staticPropInfo[i].Angles.z, staticProps.staticPropInfo[i].Angles.y);
                staticProps.staticPropInfo[i].PropType       = FileReader.readUShort(stream);                                                                 // index into model name dictionary
                staticProps.staticPropInfo[i].FirstLeaf      = FileReader.readUShort(stream);                                                                 // index into leaf array
                staticProps.staticPropInfo[i].LeafCount      = FileReader.readUShort(stream);
                staticProps.staticPropInfo[i].Solid          = FileReader.readByte(stream);                                                                   // solidity type
                staticProps.staticPropInfo[i].Flags          = FileReader.readByte(stream);
                staticProps.staticPropInfo[i].Skin           = FileReader.readInt(stream);                                                                    // model skin numbers
                staticProps.staticPropInfo[i].FadeMinDist    = FileReader.readFloat(stream);
                staticProps.staticPropInfo[i].FadeMaxDist    = FileReader.readFloat(stream);
                staticProps.staticPropInfo[i].LightingOrigin = new Vector3(FileReader.readFloat(stream), FileReader.readFloat(stream), FileReader.readFloat(stream)); // for lighting
                // since v5
                staticProps.staticPropInfo[i].ForcedFadeScale = FileReader.readFloat(stream);                                                                         // fade distance scale
                // v6 and v7 only
                staticProps.staticPropInfo[i].MinDXLevel = FileReader.readUShort(stream);                                                                             // minimum DirectX version to be visible
                staticProps.staticPropInfo[i].MaxDXLevel = FileReader.readUShort(stream);                                                                             // maximum DirectX version to be visible
                // since v8
                staticProps.staticPropInfo[i].MinCPULevel = FileReader.readByte(stream);
                staticProps.staticPropInfo[i].MaxCPULevel = FileReader.readByte(stream);
                staticProps.staticPropInfo[i].MinGPULevel = FileReader.readByte(stream);
                staticProps.staticPropInfo[i].MaxGPULevel = FileReader.readByte(stream);
                // since v7
                staticProps.staticPropInfo[i].DiffuseModulation = new Color32(FileReader.readByte(stream), FileReader.readByte(stream), FileReader.readByte(stream), FileReader.readByte(stream)); // per instance color and alpha modulation
                // since v10
                staticProps.staticPropInfo[i].unknown = FileReader.readFloat(stream);
                // since v9
                //staticProps.staticPropInfo[i].DisableX360 = Convert.ToBoolean(FileReader.readByte(stream));     // if true, don't show on XBox 360

                //largestIndex = staticProps.staticPropInfo[i].PropType > largestIndex ? staticProps.staticPropInfo[i].PropType : largestIndex;

                #region Full Debug

                /*Debug.Log(i +
                 *  " Origin: " + staticProps.staticPropInfo[i].Origin +
                 *  " Angle: " + staticProps.staticPropInfo[i].Angles +
                 *  " Prop Type: " + staticProps.staticPropInfo[i].PropType +
                 *  " First Leaf: " + staticProps.staticPropInfo[i].FirstLeaf +
                 *  " Leaf Count: " + staticProps.staticPropInfo[i].LeafCount +
                 *  " Solid: " + staticProps.staticPropInfo[i].Solid +
                 *  " Flags: " + staticProps.staticPropInfo[i].Flags +
                 *  " Skin: " + staticProps.staticPropInfo[i].Skin +
                 *  " FadeMinDist: " + staticProps.staticPropInfo[i].FadeMinDist +
                 *  " FadeMaxDist: " + staticProps.staticPropInfo[i].FadeMaxDist +
                 *  " LightingOrigin: " + staticProps.staticPropInfo[i].LightingOrigin +
                 *  " ForcedFadeScale: " + staticProps.staticPropInfo[i].ForcedFadeScale +
                 *  " MinDXLevel: " + staticProps.staticPropInfo[i].MinDXLevel +
                 *  " MaxDXLevel: " + staticProps.staticPropInfo[i].MaxDXLevel +
                 *  " MinCPULevel: " + staticProps.staticPropInfo[i].MinCPULevel +
                 *  " MaxCPULevel: " + staticProps.staticPropInfo[i].MaxCPULevel +
                 *  " MinGPULevel: " + staticProps.staticPropInfo[i].MinGPULevel +
                 *  " MaxGPULevel: " + staticProps.staticPropInfo[i].MaxGPULevel +
                 *  " DiffuseModulation: " + staticProps.staticPropInfo[i].DiffuseModulation +
                 *  " Unknown: " + staticProps.staticPropInfo[i].unknown +
                 *  " DisableX360: " + staticProps.staticPropInfo[i].DisableX360);*/
                #endregion
            }
            //Debug.Log("Total Static Props: " + staticProps.staticPropInfo.Length + " Largest index into dict: " + largestIndex);
            #endregion
        }

        return(staticProps);
    }