Ejemplo n.º 1
0
		void UnpackRATileData(MemoryStream ms)
		{
			var types = new ushort[mapSize, mapSize];
			for (var j = 0; j < mapSize; j++)
			{
				for (var i = 0; i < mapSize; i++)
				{
					var tileID = ms.ReadUInt16();
					types[i, j] = tileID == (ushort)0 ? (ushort)255 : tileID; // RAED weirdness
				}
			}

			for (var j = 0; j < mapSize; j++)
				for (var i = 0; i < mapSize; i++)
					map.MapTiles.Value[new CPos(i, j)] = new TerrainTile(types[i, j], ms.ReadUInt8());
		}
Ejemplo n.º 2
0
        void UnpackRATileData(MemoryStream ms)
        {
            for (int i = 0; i < mapSize; i++)
                for (int j = 0; j < mapSize; j++)
                    map.MapTiles.Value[i, j] = new TileReference<ushort, byte>();

            for (int j = 0; j < mapSize; j++)
                for (int i = 0; i < mapSize; i++)
                    map.MapTiles.Value[i, j].Type = ms.ReadUInt16();

            for (int j = 0; j < mapSize; j++)
                for (int i = 0; i < mapSize; i++)
                    map.MapTiles.Value[i, j].Index = ms.ReadUInt8();
        }
Ejemplo n.º 3
0
        public void ReadUInt16()
        {
            UInt16 testValue = 1024;
            using( var stream = new MemoryStream() )
            {
                var bytes = BitConverter.GetBytes( testValue );
                stream.Write( bytes, 0, bytes.Length );
                stream.Seek( 0, SeekOrigin.Begin );

                var value = stream.ReadUInt16();
                Assert.AreEqual( value, testValue );
            }
        }
		static void ReadTiles(Map map, IniFile file, int2 fullSize)
		{
			var tileset = Game.ModData.DefaultTileSets[map.Tileset];
			var mapSection = file.GetSection("IsoMapPack5");

			var data = Convert.FromBase64String(mapSection.Aggregate(string.Empty, (a, b) => a + b.Value));
			int cells = (fullSize.X * 2 - 1) * fullSize.Y;
			int lzoPackSize = cells * 11 + 4; // last 4 bytes contains a lzo pack header saying no more data is left
			var isoMapPack = new byte[lzoPackSize];
			UnpackLZO(data, isoMapPack);

			var mf = new MemoryStream(isoMapPack);
			for (var i = 0; i < cells; i++)
			{
				var rx = mf.ReadUInt16();
				var ry = mf.ReadUInt16();
				var tilenum = mf.ReadUInt16();
				/*var zero1 = */mf.ReadInt16();
				var subtile = mf.ReadUInt8();
				var z = mf.ReadUInt8();
				/*var zero2 = */mf.ReadUInt8();

				int dx = rx - ry + fullSize.X - 1;
				int dy = rx + ry - fullSize.X - 1;
				var mapCell = new MPos(dx / 2, dy);
				var cell = mapCell.ToCPos(map);

				if (map.Tiles.Contains(cell))
				{
					if (!tileset.Templates.ContainsKey(tilenum))
						tilenum = subtile = 0;

					map.Tiles[cell] = new TerrainTile(tilenum, subtile);
					map.Height[cell] = z;
				}
			}
		}
Ejemplo n.º 5
0
        void UnpackRATileData(MemoryStream ms)
        {
            for (int i = 0; i < mapSize; i++)
                for (int j = 0; j < mapSize; j++)
                    map.MapTiles.Value[i, j] = new TileReference<ushort, byte>();

            for (int j = 0; j < mapSize; j++)
                for (int i = 0; i < mapSize; i++)
                {
                    var tileID = ms.ReadUInt16();
                    map.MapTiles.Value[i, j].Type = tileID == (ushort)0 ? (ushort)255 : tileID; // RAED weirdness
                }

            for (int j = 0; j < mapSize; j++)
                for (int i = 0; i < mapSize; i++)
                    map.MapTiles.Value[i, j].Index = ms.ReadUInt8();
        }
Ejemplo n.º 6
0
		//-------------------------------------------------------------------------------------
		private static void UnPackArray(ref object arr, byte[] data, Type elemType, uint owner, DeserContext cox)
		{
			MemoryStream ms = null;
			try
			{
				ms = new MemoryStream(data);
				int[] dims = new int[ms.ReadByte()];
				for(int a = 0; a < dims.Length; a++)
					dims[a] = ms.ReadInt32();

				arr = Array.CreateInstance(elemType, dims);

				//bool fullDeser = true;

				if(IsPrimitive(elemType))
				{
					#region
					uint size = (uint)SizeOfPrimitive(elemType);
					ArrayIndexEnumerator aie = new ArrayIndexEnumerator((Array)arr);
					while(aie.MoveNext())
						((Array)arr).SetValue(FromBytes(elemType, ms.ReadBytes(size)), aie.Current);
					#endregion
				}
				else if(elemType == typeof(String) || elemType == typeof(RefString))
				{
					#region
					byte b;
					ArrayIndexEnumerator aie = new ArrayIndexEnumerator((Array)arr);
					while(aie.MoveNext())
					{
						using(MemoryStream line = new MemoryStream())
							while(true)
							{
								b = (byte)ms.ReadByte();
								if(b == 0xFE)
									((Array)arr).SetValue(null, aie.Current);
								else if(b == 0xFF)
									((Array)arr).SetValue(FromBytes(elemType, line.ToArray()), aie.Current);
								else
									line.WriteByte(b);
								if(b >= 0xFE)
									break;
							}
					}
					#endregion
				}
				else if(elemType == typeof(Type))
				{
					#region
					ArrayIndexEnumerator aie = new ArrayIndexEnumerator((Array)arr);
					while(aie.MoveNext())
					{
						ushort typeid = ms.ReadUInt16();
						if(typeid != 0)
							((Array)arr).SetValue(cox.types[typeid], aie.Current);
					}
					#endregion
				}
				else
				{
					ArrayIndexEnumerator aie = new ArrayIndexEnumerator((Array)arr);
					while(aie.MoveNext())
					{
						ushort typeid = ms.ReadUInt16();
						if(typeid == 0)
							continue;
						Type t = cox.types[typeid];

						if(t.IsArray)
						{
							object val = null;
							uint len = ms.ReadUInt32();
							UnPackArray(ref val, ms.ReadBytes(len), t.GetElementType(), owner, cox);
							((Array)arr).SetValue(val, aie.Current);
						}
						else if(typeid < 25 || t.IsEnum)
							((Array)arr).SetValue(FromBytes(t, ms.ReadBytes((uint)SizeOfPrimitive(t))), aie.Current);
						else if(t == typeof(String) || t == typeof(RefString))
						{
							#region
							using(MemoryStream line = new MemoryStream())
							{
								byte b;
								while(true)
								{
									b = (byte)ms.ReadByte();
									if(b == 0xFE)
										((Array)arr).SetValue(null, aie.Current);
									else if(b == 0xFF)
										((Array)arr).SetValue(FromBytes(t, line.ToArray()), aie.Current);
									else
										line.WriteByte(b);
									if(b >= 0xFE)
										break;
								}
							}
							#endregion
						}
						else if(typeof(ISelfSerialization).IsAssignableFrom(t))
						{
							#region
							object val = FormatterServices.GetUninitializedObject(t);
							TypeSerializationWrap tw = TypeSerializationWrap.GetTypeSerializationWrap(t);
							tw.OnDeserializing(val);

							byte len = (byte)ms.ReadByte();
							if(len > 0)
								((ISelfSerialization)val).Deserialize(ms.ReadBytes(len));
							
							tw.OnDeserialized(val);

							((Array)arr).SetValue(val, aie.Current); 
							#endregion
						}
						else if(t == typeof(Type))
							((Array)arr).SetValue(cox.types[ms.ReadUInt16()], aie.Current);
						else
						{
							uint id = ms.ReadUInt32();

							DeserObj dId;
							if(cox.objs.TryGetValue(id, out dId))
							{
								if(dId.WaitsCount == 0)
									((Array)arr).SetValue(dId.Obj, aie.Current);
								else
								{
									cox.objs[owner].WaitsCount++;
									List<LateDeserInfo> lll;
									if(cox.lateSet.TryGetValue(id, out lll) == false)
										cox.lateSet.Add(id, lll = new List<LateDeserInfo>());
									lll.Add(new LateDeserInfo(owner, ((Array)arr), (int[])aie.Current.Clone()));
								}
							}
							else
							{
								// Противоречит "глубокой" сериализации
								//if(typeof(GlobalObject).IsAssignableFrom(t))
								// throw new Exception("Попытка создать GlobalObject вне GOL!");
								cox.objs.Add(id, new DeserObj(t));
								cox.objs[owner].WaitsCount++;
								List<LateDeserInfo> lll;
								if(cox.lateSet.TryGetValue(id, out lll) == false)
									cox.lateSet.Add(id, lll = new List<LateDeserInfo>());
								lll.Add(new LateDeserInfo(owner, ((Array)arr), (int[])aie.Current.Clone()));
							}
						}
					}
				}
			}
			catch
			{
				throw;
			}
			finally
			{
				if(ms != null)
					ms.Dispose();
			}
		}
Ejemplo n.º 7
0
 protected override void ParseData(MemoryStream ms)
 {
     SequenceNumber = Helper.ConvertEndian(ms.ReadUInt32());
     Width = Helper.ConvertEndian(ms.ReadUInt32());
     Height = Helper.ConvertEndian(ms.ReadUInt32());
     XOffset = Helper.ConvertEndian(ms.ReadUInt32());
     YOffset = Helper.ConvertEndian(ms.ReadUInt32());
     DelayNum = Helper.ConvertEndian(ms.ReadUInt16());
     DelayDen = Helper.ConvertEndian(ms.ReadUInt16());
     DisposeOp = (DisposeOps)ms.ReadByte();
     BlendOp = (BlendOps)ms.ReadByte();
 }
        public SwitchContainerObject(byte[] data)
        {
            Data = data;

            using (MemoryStream s = new MemoryStream(data))
            {
                ID = s.ReadUInt32();
                bool overrideEffects = s.ReadBoolean();
                byte effectCount = s.ReadUInt8();
                if (effectCount > 0)
                {
                    s.ReadUInt8(); // effectmask
                }
                for (int i = 0; i < effectCount; i++)
                {
                    s.ReadUInt8(); // effect index
                    s.ReadUInt32(); // effect id
                    s.ReadUInt16(); // zeroes
                }
                OutputBus = s.ReadUInt32();
                ParentObjectId = s.ReadUInt32();
                s.ReadBoolean(); // overrideParentPlaybackPriority
                s.ReadBoolean(); // offset priority by ... at max distance activated
                
                byte additionalParameterCount = s.ReadUInt8();
                byte[] additionalParameterTypes = new byte[additionalParameterCount];
                for (int i = 0; i < additionalParameterCount; i++)
                {
                    additionalParameterTypes[i] = s.ReadUInt8();
                }
                for (int i = 0; i < additionalParameterCount; i++)
                {
                    s.ReadUInt32(); // most of these are floats but it doesn't actually matter. 4 bytes is 4 bytes
                }

                s.ReadUInt8(); // unknown

                bool positioningSection = s.ReadBoolean();
                if (positioningSection)
                {
                    byte positionType = s.ReadUInt8();
                    if (positionType == 0x00)
                    {
                        // 2D
                        s.ReadBoolean(); // panner enabled?
                    }
                    else if (positionType == 0x01)
                    {
                        // 3D
                        uint positionSource = s.ReadUInt32();
                        s.ReadUInt32(); // attenuation object
                        s.ReadBoolean(); // spatialization?
                        if (positionSource == 0x02)
                        {
                            // User defined
                            s.ReadUInt32(); // play type
                            s.ReadBoolean(); // loop? 
                            s.ReadUInt32(); // transition time
                            s.ReadBoolean(); // follow listener orientation?
                        }
                        else if (positionSource == 0x03)
                        {
                            // Game defined
                            s.ReadBoolean(); // update at each frame?
                        }
                    }
                }

                s.ReadBoolean(); // override parent settings for Game-Defined Auxiliary Sends?
                s.ReadBoolean(); // use Game-Defined Auxiliary Sends?
                s.ReadBoolean(); // override parent settings for User-Defined Auxiliary Sends?
                bool udasExist = s.ReadBoolean(); // User-Defined Auxiliary Sends exist?
                if (udasExist)
                {
                    uint auxBus0 = s.ReadUInt32(); // Auxiliary bus 0
                    uint auxBus1 = s.ReadUInt32(); // Auxiliary bus 1
                    uint auxBus2 = s.ReadUInt32(); // Auxiliary bus 2
                    uint auxBus3 = s.ReadUInt32(); // Auxiliary bus 3
                }
                
                bool unkPlaybackLimit = s.ReadBoolean(); // unknown param for playback limit
                if (unkPlaybackLimit)
                {
                    s.ReadUInt8(); // priority equal action
                    s.ReadUInt8(); // limit action
                    s.ReadUInt16(); // limit sound instances to ...
                }

                s.ReadUInt8(); // how to limit source instances
                s.ReadUInt8(); // virtual voice behaviour

                s.ReadBoolean(); // override parent settings for playback limit
                s.ReadBoolean(); // override parent settings for virtual voice

                uint stateGroupCount = s.ReadUInt32();
                for (int i = 0; i < stateGroupCount; i++)
                {
                    uint stateGroupId = s.ReadUInt32();
                    s.ReadUInt8(); // change occurs at
                    ushort statesDifferentFromDefault = s.ReadUInt16();
                    for (int j = 0; j < statesDifferentFromDefault; j++)
                    {
                        uint stateObjectId = s.ReadUInt32();
                        uint objectWithSettings = s.ReadUInt32();
                        Console.WriteLine("{0:X8} {1:X8} {2:X8}", stateGroupId, stateObjectId, objectWithSettings);
                    }
                }
            }


            Console.WriteLine("SwitchContainer ID: {0:X8} OutputBus: {1:X8} ParentObjectId: {2:X8}", ID, OutputBus, ParentObjectId);
        }