Example #1
0
        public int MeshFlags; // 60 is normal, 124 is decal

        public static int Deserialise(BinaryReader reader, GameObject parent)
        {
            GameObject go = new GameObject("Mesh Part");
            MeshPart part = go.AddComponent<MeshPart>();
            part.transform.SetParent(parent.transform);

            long offset = reader.BaseStream.Position;

            int NextOffset = reader.ReadInt32();
            reader.SkipInt32(64);
            reader.SkipInt32();//Length 
            reader.SkipInt32(0);

            int VertexCount = reader.ReadInt32();
            part.ObjectType = reader.ReadInt32(); //1 = static, 2 = can be or not there, 3 = can move
            int val = reader.ReadInt32();
            part.OcclusionGroup = "0x" + val.ToString("X") + " 0b" + Convert.ToString(val, 2);
            part.MeshFlags = reader.ReadInt32();

            reader.SkipBytes(32, 0);

            go.isStatic = part.ObjectType != 3;

            Matrix4x4 matrix = part.GetComponentInParent<Scene>().GetSH3ToUnityMatrix();

            List<Vector3> _verts = new List<Vector3>();
            List<Vector3> _norms = new List<Vector3>();
            List<Vector2> _uvs = new List<Vector2>();
            List<Color32> _colors = new List<Color32>();
            for (int i = 0; i != VertexCount; i++)
            {
                Vector3 temp = reader.ReadVector3();
                temp.y = -temp.y;
                _verts.Add(matrix.MultiplyPoint(temp));

                temp = reader.ReadVector3();
                temp.x = -temp.x;
                temp.z = -temp.z;
                _norms.Add(temp);

                _uvs.Add(reader.ReadVector2());
                _colors.Add(reader.ReadBGRA());
            }

            Mesh mesh = MeshUtils.MakeStripped(_verts, _norms, _uvs, _colors);

            mesh.name = "mesh_" + offset;
            go.AddComponent<MeshFilter>().sharedMesh = mesh;
            go.AddComponent<MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;

            return NextOffset;
        }
Example #2
0
        /// <summary>
        /// Reads the event data from the underlying stream.
        /// </summary>
        /// <param name="reader">The reader.</param>
        public override void Read(BinaryReader reader)
        {
            base.Read(reader);

            Scale = new MinMax<Vector2>(reader.ReadVector2(), reader.ReadVector2());
        }
Example #3
0
        static void ReadVertices(BinaryReader br, M2Model model)
        {
            var vertInfo = model.Header.Vertices;

            model.Vertices = new ModelVertices[vertInfo.Count];

            br.BaseStream.Position = vertInfo.Offset;
            for (int i = 0; i < vertInfo.Count; i++)
            {
                var mv = new ModelVertices
                             {
                                 Position = br.ReadVector3(),
                                 BoneWeight = br.ReadBytes(4),
                                 BoneIndices = br.ReadBytes(4),
                                 Normal = br.ReadVector3(),
                                 TextureCoordinates = br.ReadVector2(),
                                 Float_1 = br.ReadSingle(),
                                 Float_2 = br.ReadSingle()
                             };

                model.Vertices[i] = mv;
            }
        }
Example #4
0
 /// <summary>
 /// Reads a channel frame from the underlying stream.
 /// </summary>
 /// <param name="reader">The reader.</param>
 /// <param name="frame">The frame to read.</param>
 public override void ReadFrame(BinaryReader reader, int frame)
 {
     frames[frame] = reader.ReadVector2();
 }
Example #5
0
 public static EnemyBuildingUpdater Deserialize(BinaryReader s, GameState state)
 {
     int ti = s.ReadInt32();
     ViewedBuilding vb = new ViewedBuilding();
     vb.Team = s.ReadInt32();
     vb.Type = s.ReadInt32();
     vb.CellPoint = s.ReadPoint();
     vb.WorldPosition = s.ReadVector3();
     vb.ViewDirection = s.ReadVector2();
     int uuid = s.ReadInt32();
     RTSBuilding b = null;
     foreach(var building in state.teams[vb.Team].Buildings) {
         if(building.UUID == uuid) {
             b = building;
             break;
         }
     }
     EnemyBuildingUpdater ebu = new EnemyBuildingUpdater(state, ti, vb, b);
     ebu.Added = s.ReadBoolean();
     ebu.isDead = s.ReadBoolean();
     if(ebu.Added) {
         state.teams[ebu.teamIndex].ViewedEnemyBuildings.Add(vb);
     }
     return ebu;
 }
Example #6
0
		private void init(string filename, Stream stream, string contentDirectory, Dictionary<string,Type> materialTypes, List<MaterialFieldBinder> value1BinderTypes, List<MaterialFieldBinder> value2BinderTypes, List<MaterialFieldBinder> value3BinderTypes, List<MaterialFieldBinder> value4BinderTypes, List<MaterialFieldBinder> textureBinderTypes, Dictionary<string,string> fileExtOverrides, int classicInstanceCount, Loader.LoadedCallbackMethod loadedCallback)
		{
			try
			{
				var reader = new BinaryReader(stream);

				// meta data
				if (reader.ReadInt32() != Streams.MakeFourCC('R', 'M', 'F', 'T')) Debug.ThrowError("Error", "Not a ReignModel file: " + filename);
				float version = reader.ReadSingle();
				if (version != 1.0f) Debug.ThrowError("Error", "Unsuported model version: " + version.ToString());
				bool compressed = reader.ReadBoolean();

				// frames
				FrameStart = reader.ReadSingle();
				FrameEnd = reader.ReadSingle();
				FrameCount = FrameEnd - FrameStart;
				FPS = reader.ReadSingle();

				// materials
				int materialCount = reader.ReadInt32();
				Materials = new MaterialI[materialCount];
				Textures = new List<ITexture2D>();
				for (int i = 0; i != materialCount; ++i)
				{
					string name = reader.ReadString();

					// create material
					bool pass = false;
					foreach (var materialType in (Dictionary<string,Type>)materialTypes)
					{
						if (materialType.Key == name)
						{
							Materials[i] = (MaterialI)Activator.CreateInstance(materialType.Value);
							Materials[i].Name = name;
							pass = true;
							break;
						}
					}
					if (!pass) Debug.ThrowError("Model", "Failed to find a valid material type for: " + name);
					var material = Materials[i];

					// values1
					var values1 = new Dictionary<string,float>();
					int valueCount = reader.ReadInt32();
					for (int i2 = 0; i2 != valueCount; ++i2) values1.Add(reader.ReadString(), reader.ReadSingle());
					bindTypes(material, values1, value1BinderTypes, contentDirectory, fileExtOverrides, handleFoundValueBinder);

					// values2
					var values2 = new Dictionary<string,Vector2>();
					valueCount = reader.ReadInt32();
					for (int i2 = 0; i2 != valueCount; ++i2) values2.Add(reader.ReadString(), reader.ReadVector2());
					bindTypes(material, values2, value2BinderTypes, contentDirectory, fileExtOverrides, handleFoundValueBinder);

					// values3
					var values3 = new Dictionary<string,Vector3>();
					valueCount = reader.ReadInt32();
					for (int i2 = 0; i2 != valueCount; ++i2) values3.Add(reader.ReadString(), reader.ReadVector3());
					bindTypes(material, values3, value3BinderTypes, contentDirectory, fileExtOverrides, handleFoundValueBinder);

					// values4
					var values4 = new Dictionary<string,Vector4>();
					valueCount = reader.ReadInt32();
					for (int i2 = 0; i2 != valueCount; ++i2) values4.Add(reader.ReadString(), reader.ReadVector4());
					bindTypes(material, values4, value4BinderTypes, contentDirectory, fileExtOverrides, handleFoundValueBinder);

					// textures
					var textures = new Dictionary<string,string>();
					int textureCount = reader.ReadInt32();
					for (int i2 = 0; i2 != textureCount; ++i2) textures.Add(reader.ReadString(), reader.ReadString());
					bindTypes(material, textures, textureBinderTypes, contentDirectory, fileExtOverrides, handleFoundTextureBinder);
				}

				// meshes
				int meshCount = reader.ReadInt32();
				Meshes = new Mesh[meshCount];
				for (int i = 0; i != meshCount; ++i)
				{
					Meshes[i] = new Mesh(reader, this, classicInstanceCount);
				}

				// actions
				int actionCount = reader.ReadInt32();
				Actions = new Action[actionCount];
				for (int i = 0; i != actionCount; ++i)
				{
					Actions[i] = new Action(reader);
				}

				// armatures
				int armatureCount = reader.ReadInt32();
				Armatures = new Armature[armatureCount];
				for (int i = 0; i != armatureCount; ++i)
				{
					Armatures[i] = new Armature(reader);
				}

				// objects
				int objectCount = reader.ReadInt32();
				Objects = new Object[objectCount];
				for (int i = 0; i != objectCount; ++i)
				{
					string type = reader.ReadString();
					if (type == "MESH") Objects[i] = new ObjectMesh(reader, this);
					else if (type == "ARMATURE") Objects[i] = new ObjectArmature(reader, this);
					else Debug.ThrowError("Mesh", "Unsuported Object type: " + type);
				}

				// link objects
				foreach (var o in Objects)
				{
					o.linkObjects(Objects);
				}
			}
			catch (Exception e)
			{
				FailedToLoad = true;
				Loader.AddLoadableException(e);
				Dispose();
				if (loadedCallback != null) loadedCallback(this, false);
				return;
			}

			if (Textures.Count == 0)
			{
				Loaded = true;
				if (loadedCallback != null) loadedCallback(this, true);
			}
			else
			{
				new LoadWaiter(Textures.ToArray(),
				delegate(object sender, bool succeeded)
				{
					if (succeeded)
					{
						Loaded = true;
						if (loadedCallback != null) loadedCallback(this, true);
					}
					else
					{
						FailedToLoad = true;
						Dispose();
						if (loadedCallback != null) loadedCallback(this, false);
					}
				});
			}
		}
Example #7
0
 public void LoadFrom(Stream stream)
 {
     BinaryReader reader = new BinaryReader(stream);
     enabled = reader.ReadBoolean();
     reader.ReadBytes(3);
     curve = new MinMaxCurve(stream);
     range = reader.ReadVector2();
 }
Example #8
0
        public void RestoreSuspendedState(CanvasDevice device, BinaryReader reader)
        {
            bitmapFormat = (DirectXPixelFormat)reader.ReadInt32();
            bitmapData = reader.ReadByteArray();

            Size = reader.ReadVector2();

            reader.ReadCollection(Edits, () => EditGroup.RestoreSuspendedState(this, reader));

            RecoverAfterDeviceLost(device);
        }
 public UserHintWellPointBlock(BinaryReader binaryReader)
 {
     this.type = (Type)binaryReader.ReadInt16();
     this.padding = binaryReader.ReadBytes(2);
     this.point = binaryReader.ReadVector3();
     this.referenceFrame = binaryReader.ReadInt16();
     this.padding0 = binaryReader.ReadBytes(2);
     this.sectorIndex = binaryReader.ReadInt32();
     this.normal = binaryReader.ReadVector2();
 }
Example #10
0
 public FiringPositionsBlock(BinaryReader binaryReader)
 {
     this.positionLocal = binaryReader.ReadVector3();
     this.referenceFrame = binaryReader.ReadInt16();
     this.flags = (Flags)binaryReader.ReadInt16();
     this.area = binaryReader.ReadShortBlockIndex1();
     this.clusterIndex = binaryReader.ReadInt16();
     this.skip = binaryReader.ReadBytes(4);
     this.normal = binaryReader.ReadVector2();
 }
Example #11
0
 public ActorStartingLocationsBlock(BinaryReader binaryReader)
 {
     this.name = binaryReader.ReadStringID();
     this.position = binaryReader.ReadVector3();
     this.referenceFrame = binaryReader.ReadInt16();
     this.padding = binaryReader.ReadBytes(2);
     this.facingYawPitchDegrees = binaryReader.ReadVector2();
     this.flags = (Flags)binaryReader.ReadInt32();
     this.characterType = binaryReader.ReadShortBlockIndex1();
     this.initialWeapon = binaryReader.ReadShortBlockIndex1();
     this.initialSecondaryWeapon = binaryReader.ReadShortBlockIndex1();
     this.padding0 = binaryReader.ReadBytes(2);
     this.vehicleType = binaryReader.ReadShortBlockIndex1();
     this.seatType = (SeatType)binaryReader.ReadInt16();
     this.grenadeType = (GrenadeType)binaryReader.ReadInt16();
     this.swarmCountNumberOfCreturesInSwarmIfASwarmIsSpawnedAtThisLocation = binaryReader.ReadInt16();
     this.actorVariantName = binaryReader.ReadStringID();
     this.vehicleVariantName = binaryReader.ReadStringID();
     this.initialMovementDistanceBeforeDoingAnythingElseTheActorWillTravelTheGivenDistanceInItsForwardDirection = binaryReader.ReadSingle();
     this.emitterVehicle = binaryReader.ReadShortBlockIndex1();
     this.initialMovementMode = (InitialMovementMode)binaryReader.ReadInt16();
     this.placementScript = binaryReader.ReadString32();
     this.skip1 = binaryReader.ReadBytes(2);
     this.padding2 = binaryReader.ReadBytes(2);
 }
Example #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TexDesc"/> class.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="reader">The reader.</param>
        public TexDesc(NiFile file, BinaryReader reader)
		{
			this.Source = new NiRef<NiSourceTexture>(reader);
			if (file.Version <= eNifVersion.VER_20_0_0_5)
			{
				this.ClampMode = (eTexClampMode)reader.ReadUInt32();
				this.FilterMode = (eTexFilterMode)reader.ReadUInt32();
			}
			if (file.Version >= eNifVersion.VER_20_1_0_3)
			{
				this.Flags = reader.ReadUInt16();
			}
			if (file.Version <= eNifVersion.VER_20_0_0_5)
			{
				this.UVSetIndex = reader.ReadUInt32();
			}
			if (file.Version <= eNifVersion.VER_10_4_0_1)
			{
				this.PS2L = reader.ReadInt16();
				this.PS2K = reader.ReadInt16();
			}
			if (file.Version <= eNifVersion.VER_4_1_0_12)
			{
				reader.ReadUInt16();
			}
			if (file.Version >= eNifVersion.VER_10_1_0_0)
			{
				this.HasTextureTransform = reader.ReadBoolean(file.Version);
				if (this.HasTextureTransform)
				{
					this.Translation = reader.ReadVector2();
					this.Tiling = reader.ReadVector2();
					this.WRotation = reader.ReadSingle();
					this.TransformType = reader.ReadUInt32();
					this.CenterOffset = reader.ReadVector2();
				}
			}
		}
 public GlobalGeometrySectionRawVertexBlock(BinaryReader binaryReader)
 {
     this.position = binaryReader.ReadVector3();
     this.nodeIndicesOLD = new NodeIndicesOLD[4];
     for (int i = 0; i < 4; ++i)
     {
         this.nodeIndicesOLD[i] = new NodeIndicesOLD(binaryReader);
     }
     this.nodeWeights = new NodeWeights[4];
     for (int i = 0; i < 4; ++i)
     {
         this.nodeWeights[i] = new NodeWeights(binaryReader);
     }
     this.nodeIndicesNEW = new NodeIndicesNEW[4];
     for (int i = 0; i < 4; ++i)
     {
         this.nodeIndicesNEW[i] = new NodeIndicesNEW(binaryReader);
     }
     this.useNewNodeIndices = binaryReader.ReadInt32();
     this.adjustedCompoundNodeIndex = binaryReader.ReadInt32();
     this.texcoord = binaryReader.ReadVector2();
     this.normal = binaryReader.ReadVector3();
     this.binormal = binaryReader.ReadVector3();
     this.tangent = binaryReader.ReadVector3();
     this.anisotropicBinormal = binaryReader.ReadVector3();
     this.secondaryTexcoord = binaryReader.ReadVector2();
     this.primaryLightmapColor = binaryReader.ReadColorR8G8B8();
     this.primaryLightmapTexcoord = binaryReader.ReadVector2();
     this.primaryLightmapIncidentDirection = binaryReader.ReadVector3();
     this.padding = binaryReader.ReadBytes(12);
     this.padding0 = binaryReader.ReadBytes(8);
     this.padding1 = binaryReader.ReadBytes(12);
 }
Example #14
0
 public static RTSBuilding Deserialize(BinaryReader s, RTSTeam team, out int? target)
 {
     int type = s.ReadInt32();
     RTSBuilding e = team.AddBuilding(type, Vector2.Zero);
     if(e == null) throw new Exception("Could Not Create A Building That Was Previously Created");
     e.UUID = s.ReadInt32();
     e.State = s.ReadInt32();
     e.ViewDirection = s.ReadVector2();
     e.GridPosition = s.ReadVector2();
     e.Height = s.ReadSingle();
     if(s.ReadBoolean()) {
         target = s.ReadInt32();
     }
     else {
         target = null;
     }
     e.Health = s.ReadInt32();
     for(int i = 0; i < GameState.MAX_PLAYERS; i++) {
         e.viewedInfo.Set(i, s.ReadBoolean());
     }
     if(s.ReadBoolean()) {
         if(e.ActionController != null) e.ActionController.Deserialize(s);
     }
     else {
         e.ActionController = null;
     }
     return e;
 }
Example #15
0
 public static RTSUnitData Deserialize(BinaryReader s, GameState state, int index)
 {
     RTSUnitData data = new RTSUnitData(index);
     data.FriendlyName = s.ReadString();
     data.InfoFile = s.ReadString();
     data.Health = s.ReadInt32();
     data.CapitalCost = s.ReadInt32();
     data.PopulationCost = s.ReadInt32();
     data.MaxCount = s.ReadInt32();
     data.MovementSpeed = s.ReadSingle();
     data.Impact = s.ReadInt32();
     data.BuildTime = s.ReadInt32();
     data.CarryingCapacity = s.ReadInt32();
     data.IsWorker = s.ReadBoolean();
     BaseCombatData.Deserialize(s, data.BaseCombatData);
     CollisionType ct = (CollisionType)s.ReadInt32();
     Vector2 cc = s.ReadVector2();
     bool cs = s.ReadBoolean();
     switch(ct) {
         case CollisionType.Circle:
             float cr = s.ReadSingle();
             data.ICollidableShape = new CollisionCircle(cr, cc, cs);
             break;
         case CollisionType.Rectangle:
             float cw = s.ReadSingle();
             float cd = s.ReadSingle();
             data.ICollidableShape = new CollisionRect(cw, cd, cc, cs);
             break;
         default:
             throw new Exception("Nonexistent Collision Type");
     }
     data.BBox.Min = s.ReadVector3();
     data.BBox.Max = s.ReadVector3();
     data.DefaultActionController = state.Scripts[s.ReadString()];
     data.DefaultCombatController = state.Scripts[s.ReadString()];
     data.DefaultMoveController = state.Scripts[s.ReadString()];
     data.DefaultAnimationController = state.Scripts[s.ReadString()];
     return data;
 }
Example #16
0
        static void ReadMOTV2(BinaryReader br, WMOGroup group, uint size)
        {
            // Texture coordinates, 2 floats per vertex in (X,Y) order. The values range from 0.0 to 1.0.
            // Vertices, normals and texture coordinates are in corresponding order, of course. 
            group.TextureVertices2 = new Vector2[size / 8];

            for (int i = 0; i < group.TextureVertices2.Length; i++)
            {
                group.TextureVertices2[i] = br.ReadVector2();
            }
        }
Example #17
0
        /// <summary>
        /// Loads the file from the specified stream.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        public override void Load(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream, Encoding.GetEncoding("EUC-KR"));

            string identifier = reader.ReadNullTerminatedString();

            int version;

            if (string.Compare(identifier, FILE_IDENTIFIER_7, false) == 0) {
                version = 7;
            } else if (string.Compare(identifier, FILE_IDENTIFIER_8, false) == 0) {
                version = 8;
            } else {
                throw new FileIdentifierMismatchException(FilePath, string.Format("{0} / {1}", FILE_IDENTIFIER_7, FILE_IDENTIFIER_8), identifier);
            }

            format = (VertexFormat)reader.ReadInt32();
            BoundingBox = new Bounds(reader.ReadVector3(), reader.ReadVector3());

            short boneCount = reader.ReadInt16();

            for (int i = 0; i < boneCount; i++) {
                BoneTable.Add(reader.ReadInt16());
            }

            short vertexCount = reader.ReadInt16();

            for (int i = 0; i < vertexCount; i++) {
                ModelVertex vertex = new ModelVertex();
                vertex.Position = reader.ReadVector3();

                Vertices.Add(vertex);
            }

            if (NormalsEnabled) {
                for (int i = 0; i < vertexCount; i++) {
                    ModelVertex vertex = Vertices[i];
                    vertex.Normal = reader.ReadVector3();
                }
            }

            if (ColoursEnabled) {
                for (int i = 0; i < vertexCount; i++) {
                    float a = reader.ReadSingle();
                    ModelVertex vertex = Vertices[i];
                    vertex.Colour = new Color(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), a);
                }
            }

            if (BonesEnabled) {
                for (int i = 0; i < vertexCount; i++) {
                    ModelVertex vertex = Vertices[i];
                    vertex.BoneWeights = reader.ReadVector4();
                    vertex.BoneIndices = reader.ReadShortVector4();
                }
            }

            if (TangentsEnabled) {
                for (int i = 0; i < vertexCount; i++) {
                    ModelVertex vertex = Vertices[i];
                    vertex.Tangent = reader.ReadVector3();
                }
            }

            if (TextureCoordinates1Enabled) {
                for (int i = 0; i < vertexCount; i++) {
                    ModelVertex vertex = Vertices[i];
                    vertex.TextureCoordinates[0] = reader.ReadVector2();
                }
            }

            if (TextureCoordinates2Enabled) {
                for (int i = 0; i < vertexCount; i++) {
                    ModelVertex vertex = Vertices[i];
                    vertex.TextureCoordinates[1] = reader.ReadVector2();
                }
            }

            if (TextureCoordinates3Enabled) {
                for (int i = 0; i < vertexCount; i++) {
                    ModelVertex vertex = Vertices[i];
                    vertex.TextureCoordinates[2] = reader.ReadVector2();
                }
            }

            if (TextureCoordinates4Enabled) {
                for (int i = 0; i < vertexCount; i++) {
                    ModelVertex vertex = Vertices[i];
                    vertex.TextureCoordinates[3] = reader.ReadVector2();
                }
            }

            short indexCount = reader.ReadInt16();

            for (int i = 0; i < indexCount; i++) {
                Indices.Add(reader.ReadShortVector3());
            }

            short materialCount = reader.ReadInt16();

            for (int i = 0; i < materialCount; i++) {
                Materials.Add(reader.ReadInt16());
            }

            short stripCount = reader.ReadInt16();

            for (int i = 0; i < stripCount; i++) {
                Strips.Add(reader.ReadInt16());
            }

            if (version >= 8) {
                Pool = (PoolType)reader.ReadInt16();
            }
        }
Example #18
0
 public CsPointBlock(BinaryReader binaryReader)
 {
     this.name = binaryReader.ReadString32();
     this.position = binaryReader.ReadVector3();
     this.referenceFrame = binaryReader.ReadInt16();
     this.padding = binaryReader.ReadBytes(2);
     this.surfaceIndex = binaryReader.ReadInt32();
     this.facingDirection = binaryReader.ReadVector2();
 }
        public GeometrySectionData( SectionHeader header, FramedStream stream )
        {
            SectionHeader dataHeader = new SectionHeader( stream );
            BinaryReader reader = new BinaryReader( stream );

            Flags = (GeometryFlag) reader.ReadUInt16();
            reader.ReadUInt16(); // Unknown
            FaceCount = reader.ReadUInt32();
            VertexCount = reader.ReadUInt32();
            FrameCount = reader.ReadUInt32();

            if ( dataHeader.Version == 4099 )
            {
                Ambient = reader.ReadSingle();
                Diffuse = reader.ReadSingle();
                Specular = reader.ReadSingle();
            }

            if ( ( Flags & GeometryFlag.Colors ) != 0 )
            {
                Colours = new Color4[ VertexCount ];
                for ( int i = 0; i < VertexCount; ++i )
                {
                    byte r = reader.ReadByte();
                    byte g = reader.ReadByte();
                    byte b = reader.ReadByte();
                    byte a = reader.ReadByte();
                    Colours[ i ] = new Color4( r, g, b, a );
                }
            }

            if ( ( Flags & GeometryFlag.TexCoords ) != 0 )
            {
                TexCoords = new Vector2[ VertexCount ];
                for ( int i = 0; i < VertexCount; ++i )
                    TexCoords[ i ] = reader.ReadVector2();
            }

            Faces = new FaceInfo[ FaceCount ];
            for ( int i = 0; i < FaceCount; ++i )
                Faces[ i ] = new FaceInfo( reader );

            BoundingSphere = new BoundingSphere( reader );

            HasPosition = reader.ReadUInt32();
            HasNormals = reader.ReadUInt32();

            if ( HasPosition > 1 || HasNormals > 1 )
                throw new Exception( "Well there you go" );

            Vertices = new Vector3[ VertexCount ];
            for ( int i = 0; i < VertexCount; ++i )
                Vertices[ i ] = reader.ReadVector3();

            if ( ( Flags & GeometryFlag.Normals ) != 0 )
            {
                Normals = new Vector3[ VertexCount ];
                for ( int i = 0; i < VertexCount; ++i )
                    Normals[ i ] = reader.ReadVector3();
            }

            Materials = ( new Section( stream ).Data as MaterialListSectionData ).Materials;

            SectionHeader extHeader = new SectionHeader( stream );
            MaterialSplitSectionData msplits = new Section( stream ).Data as MaterialSplitSectionData;
            MaterialSplits = msplits.MaterialSplits;
            FaceCount = msplits.FaceCount;
            IndexCount = msplits.IndexCount;

            foreach ( MaterialSplit mat in MaterialSplits )
                mat.Material = Materials[ mat.MaterialIndex ];
        }
Example #20
0
 public ScenarioCutsceneFlagBlock(BinaryReader binaryReader)
 {
     this.padding = binaryReader.ReadBytes(4);
     this.name = binaryReader.ReadString32();
     this.position = binaryReader.ReadVector3();
     this.facing = binaryReader.ReadVector2();
 }
Example #21
0
 public void LoadFrom(Stream stream)
 {
     BinaryReader reader = new BinaryReader(stream);
     enabled = reader.ReadBoolean();
     reader.ReadBytes(3);
     gradient = new MinMaxGradient(stream);
     range = reader.ReadVector2();
 }
Example #22
0
 public ScenarioCutsceneTitleBlock(BinaryReader binaryReader)
 {
     this.name = binaryReader.ReadStringID();
     this.textBoundsOnScreen = binaryReader.ReadVector2();
     this.justification = (Justification)binaryReader.ReadInt16();
     this.font = (Font)binaryReader.ReadInt16();
     this.textColor = binaryReader.ReadRGBColor();
     this.shadowColor = binaryReader.ReadRGBColor();
     this.fadeInTimeSeconds = binaryReader.ReadSingle();
     this.upTimeSeconds = binaryReader.ReadSingle();
     this.fadeOutTimeSeconds = binaryReader.ReadSingle();
     this.paddingpadding = binaryReader.ReadBytes(2);
 }
Example #23
0
 public KeyFrame(BinaryReader reader)
 {
     Cordinate = reader.ReadVector2();
     InterpolationType = (InterpolationTypes)reader.ReadInt32();
 }
Example #24
0
 public FlockSourceBlock(BinaryReader binaryReader)
 {
     this.position = binaryReader.ReadVector3();
     this.startingYawPitchDegrees = binaryReader.ReadVector2();
     this.radius = binaryReader.ReadSingle();
     this.weightProbabilityOfProducingAtThisSource = binaryReader.ReadSingle();
 }
Example #25
0
 private static void LoadNPCs(BinaryReader reader)
 {
     int num = 0;
     bool flag = reader.ReadBoolean();
     while (flag)
     {
         NPC nPC = Main.npc[num];
         nPC.SetDefaults(reader.ReadString());
         nPC.displayName = reader.ReadString();
         nPC.position.X = reader.ReadSingle();
         nPC.position.Y = reader.ReadSingle();
         nPC.homeless = reader.ReadBoolean();
         nPC.homeTileX = reader.ReadInt32();
         nPC.homeTileY = reader.ReadInt32();
         num++;
         flag = reader.ReadBoolean();
     }
     if (WorldFile.versionNumber < 140)
     {
         return;
     }
     flag = reader.ReadBoolean();
     while (flag)
     {
         NPC nPC = Main.npc[num];
         nPC.SetDefaults(reader.ReadString());
         nPC.position = reader.ReadVector2();
         num++;
         flag = reader.ReadBoolean();
     }
 }
Example #26
0
 public DecalVerticesBlock(BinaryReader binaryReader)
 {
     this.position = binaryReader.ReadVector3();
     this.texcoord0 = binaryReader.ReadVector2();
     this.texcoord1 = binaryReader.ReadVector2();
     this.color = binaryReader.ReadRGBColor();
 }
 public static RTSBuildingData Deserialize(BinaryReader s, GameState state, int index)
 {
     RTSBuildingData data = new RTSBuildingData(index);
     data.FriendlyName = s.ReadString();
     data.InfoFile = s.ReadString();
     data.Health = s.ReadInt32();
     data.CapitalCost = s.ReadInt32();
     data.PopCapChange = s.ReadInt32();
     data.MaxCount = s.ReadInt32();
     data.IsResource = s.ReadBoolean();
     data.Impact = s.ReadInt32();
     data.BuildAmount = s.ReadInt32();
     data.Depositable = s.ReadBoolean();
     data.SightRadius = s.ReadInt32();
     data.GridSize = s.ReadPoint();
     CollisionType ct = (CollisionType)s.ReadInt32();
     Vector2 cc = s.ReadVector2();
     bool cs = s.ReadBoolean();
     switch(ct) {
         case CollisionType.Circle:
             float cr = s.ReadSingle();
             data.ICollidableShape = new CollisionCircle(cr, cc, cs);
             break;
         case CollisionType.Rectangle:
             float cw = s.ReadSingle();
             float cd = s.ReadSingle();
             data.ICollidableShape = new CollisionRect(cw, cd, cc, cs);
             break;
         default:
             throw new Exception("Nonexistent Collision Type");
     }
     data.BBox.Min = s.ReadVector3();
     data.BBox.Max = s.ReadVector3();
     data.DefaultActionController = state.Scripts[s.ReadString()];
     return data;
 }
Example #28
0
 public SpriteVerticesBlock(BinaryReader binaryReader)
 {
     this.position = binaryReader.ReadVector3();
     this.offset = binaryReader.ReadVector3();
     this.axis = binaryReader.ReadVector3();
     this.texcoord = binaryReader.ReadVector2();
     this.color = binaryReader.ReadRGBColor();
 }
Example #29
0
        /// <summary>
        /// Loads the file from the specified stream.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        public override void Load(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream, Encoding.GetEncoding("EUC-KR"));

            int blockCount = reader.ReadInt32();

            for (int i = 0; i < blockCount; i++) {
                ZoneBlock type = (ZoneBlock)reader.ReadInt32();
                int offset = reader.ReadInt32();

                long nextBlock = stream.Position;
                stream.Seek(offset, SeekOrigin.Begin);

                switch (type) {
                    case ZoneBlock.Info:
                        Type = (ZoneType)reader.ReadInt32();
                        Width = reader.ReadInt32();
                        Height = reader.ReadInt32();
                        GridCount = reader.ReadInt32();
                        GridSize = reader.ReadSingle();
                        StartPosition = new IntVector2(reader.ReadInt32(), reader.ReadInt32());

                        for (int w = 0; w < Width; w++) {
                            for (int h = 0; h < Height; h++) {
                                Positions[w, h].IsUsed = reader.ReadBoolean();
                                Positions[w, h].Position = reader.ReadVector2();
                            }
                        }
                        break;
                    case ZoneBlock.SpawnPoints:
                        int spawnCount = reader.ReadInt32();

                        for (int j = 0; j < spawnCount; j++) {
                            SpawnPoint spawnPoint = new SpawnPoint();
                            spawnPoint.Position = reader.ReadVector3();
                            spawnPoint.Name = reader.ReadByteString();

                            SpawnPoints.Add(spawnPoint);
                        }
                        break;
                    case ZoneBlock.Textures:
                        int textureCount = reader.ReadInt32();

                        for (int j = 0; j < textureCount; j++) {
                            Textures.Add(reader.ReadByteString());
                        }
                        break;
                    case ZoneBlock.Tiles:
                        int tileCount = reader.ReadInt32();

                        for (int j = 0; j < tileCount; j++) {
                            ZoneTile tile = new ZoneTile();
                            tile.Layer1 = reader.ReadInt32();
                            tile.Layer2 = reader.ReadInt32();
                            tile.Offset1 = reader.ReadInt32();
                            tile.Offset2 = reader.ReadInt32();
                            tile.BlendingEnabled = reader.ReadInt32() != 0;
                            tile.Rotation = (TileRotation)reader.ReadInt32();
                            tile.TileType = reader.ReadInt32();

                            Tiles.Add(tile);
                        }
                        break;
                    case ZoneBlock.Economy:
                        Name = reader.ReadByteString();
                        IsUnderground = reader.ReadInt32() != 0;
                        BackgroundMusicFilePath = reader.ReadByteString();
                        SkyFilePath = reader.ReadByteString();
                        EconomyCheckRate = reader.ReadInt32();
                        PopulationBase = reader.ReadInt32();
                        PopulationGrowthRate = reader.ReadInt32();
                        MetalConsumption = reader.ReadInt32();
                        StoneConsumption = reader.ReadInt32();
                        WoodConsumption = reader.ReadInt32();
                        LeatherConsumption = reader.ReadInt32();
                        ClothConsumption = reader.ReadInt32();
                        AlchemyConsumption = reader.ReadInt32();
                        ChemicalConsumption = reader.ReadInt32();
                        IndustrialConsumption = reader.ReadInt32();
                        MedicineConsumption = reader.ReadInt32();
                        FoodConsumption = reader.ReadInt32();
                        break;
                }

                if (i < blockCount - 1) {
                    stream.Seek(nextBlock, SeekOrigin.Begin);
                }
            }
        }
Example #30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NiGeometryData" /> class.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="reader">The reader.</param>
        public NiGeometryData(NiFile file, BinaryReader reader) : base(file, reader)
		{
			if (base.Version >= eNifVersion.VER_10_2_0_0)
			{
				this.Unkown1 = reader.ReadUInt32();
			}
			
			this.NumVertices = (uint)reader.ReadUInt16();
			if (base.Version >= eNifVersion.VER_10_1_0_0)
			{
				this.KeepFlags = reader.ReadByte();
				this.CompressFlags = reader.ReadByte();
			}
			
			this.HasVertices = reader.ReadBoolean(Version);
			if (this.HasVertices)
			{
				this.Vertices = new Vector3[this.NumVertices];
				int num = 0;
				while ((long)num < (long)((ulong)this.NumVertices))
				{
					this.Vertices[num] = reader.ReadVector3();
					num++;
				}
			}
			
			int numUvSets = 0;
			if (base.Version >= eNifVersion.VER_10_0_1_0)
			{
				numUvSets = (int)reader.ReadByte();
				this.TSpaceFlag = reader.ReadByte();
			}
			
			this.HasNormals = reader.ReadBoolean(Version);
			if (this.HasNormals)
			{
				this.Normals = new Vector3[this.NumVertices];
				int num3 = 0;
				while ((long)num3 < (long)((ulong)this.NumVertices))
				{
					this.Normals[num3] = reader.ReadVector3();
					num3++;
				}
			}
			if (base.Version >= eNifVersion.VER_10_1_0_0)
			{
				this.Binormals = new Vector3[this.NumVertices];
				this.Tangents = new Vector3[this.NumVertices];
				if (this.HasNormals && (this.TSpaceFlag & 240) != 0)
				{
					int num4 = 0;
					while ((long)num4 < (long)((ulong)this.NumVertices))
					{
						this.Binormals[num4] = reader.ReadVector3();
						num4++;
					}
					int num5 = 0;
					while ((long)num5 < (long)((ulong)this.NumVertices))
					{
						this.Tangents[num5] = reader.ReadVector3();
						num5++;
					}
				}
			}
			
			this.Center = reader.ReadVector3();
			this.Radius = reader.ReadSingle();
			
			this.HasVertexColors = reader.ReadBoolean(Version);
			if (this.HasVertexColors)
			{
				this.VertexColors = new Color4[this.NumVertices];
				int num6 = 0;
				while ((long)num6 < (long)((ulong)this.NumVertices))
				{
					this.VertexColors[num6] = reader.ReadColor4();
					num6++;
				}
			}
			if (base.Version <= eNifVersion.VER_4_2_2_0)
			{
				numUvSets = (int)reader.ReadByte();
				this.TSpaceFlag = reader.ReadByte();
			}
			if (base.Version <= eNifVersion.VER_4_0_0_2)
			{
				this.HasUV = reader.ReadBoolean(Version);
			}
			int num7;
			if (base.Version < eNifVersion.VER_20_2_0_7 || this.File.Header.UserVersion != 1u)
			{
				num7 = (numUvSets & 63);
			}
			else
			{
				num7 = (numUvSets & 1);
			}
			this.UVSets = new Vector2[num7][];
			for (int i = 0; i < num7; i++)
			{
				this.UVSets[i] = new Vector2[this.NumVertices];
				int num8 = 0;
				while ((long)num8 < (long)((ulong)this.NumVertices))
				{
					this.UVSets[i][num8] = reader.ReadVector2();
					num8++;
				}
			}
			if (base.Version >= eNifVersion.VER_10_0_1_0)
			{
				this.ConsistencyFlags = reader.ReadUInt16();
			}
			if (base.Version >= eNifVersion.VER_20_0_0_4)
			{
				this.AdditionalDataID = reader.ReadUInt32();
			}
		}