public HIRCSection(byte[] data)
        {
            Data = data;

            using (MemoryStream s = new MemoryStream(data))
            {
                UInt32 objectCount = s.ReadUInt32();
                for (int i = 0; i < objectCount; i++)
                {
                    Console.Write("HIRC object at: {0:X}", s.Position);
                    HIRCType type = (HIRCType)s.ReadUInt8();
                    UInt32 length = s.ReadUInt32();
                    byte[] buffer = new byte[length];
                    s.Read(buffer, 0, (int)length);

                    Console.WriteLine(" Type {0} Length {1:X}", type, length);

                    IHIRCObject obj = HIRCObject.GetObject(type, buffer);
                    Objects.Add(obj);
                }
            }
        }
示例#2
0
		public static byte[] LoadImaAdpcmSound(byte[] raw, ref int index, ref int currentSample)
		{
			var s = new MemoryStream(raw);
			var dataSize = raw.Length;
			var outputSize = raw.Length * 4;

			var output = new byte[outputSize];
			var offset = 0;

			while (dataSize-- > 0)
			{
				var b = s.ReadUInt8();

				var t = DecodeImaAdpcmSample(b, ref index, ref currentSample);
				output[offset++] = (byte)t;
				output[offset++] = (byte)(t >> 8);

				t = DecodeImaAdpcmSample((byte)(b >> 4), ref index, ref currentSample);
				output[offset++] = (byte)t;
				output[offset++] = (byte)(t >> 8);
			}

			return output;
		}
示例#3
0
		void UnpackRAOverlayData(MemoryStream ms)
		{
			for (var j = 0; j < mapSize; j++)
			{
				for (var i = 0; i < mapSize; i++)
				{
					var o = ms.ReadUInt8();
					var res = Pair.New((byte)0, (byte)0);

					if (o != 255 && overlayResourceMapping.ContainsKey(redAlertOverlayNames[o]))
						res = overlayResourceMapping[redAlertOverlayNames[o]];

					var cell = new CPos(i, j);
					map.MapResources.Value[cell] = new ResourceTile(res.First, res.Second);

					if (o != 255 && overlayActorMapping.ContainsKey(redAlertOverlayNames[o]))
					{
						var ar = new ActorReference(overlayActorMapping[redAlertOverlayNames[o]])
						{
							new LocationInit(cell),
							new OwnerInit("Neutral")
						};

						map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save()));
					}
				}
			}
		}
示例#4
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());
		}
示例#5
0
        public byte[] DecodeImaAdpcmData()
        {
            var s = new MemoryStream(RawOutput);

            var numBlocks = DataSize / BlockAlign;
            var blockDataSize = BlockAlign - (Channels * 4);
            var outputSize = UncompressedSize * Channels * 2;

            var outOffset = 0;
            var output = new byte[outputSize];

            var predictor = new int[Channels];
            var index = new int[Channels];

            // Decode each block of IMA ADPCM data in RawOutput
            for (var block = 0; block < numBlocks; block++)
            {
                // Each block starts with a initial state per-channel
                for (var c = 0; c < Channels; c++)
                {
                    predictor[c] = s.ReadInt16();
                    index[c] = s.ReadUInt8();
                    /* unknown/reserved */ s.ReadUInt8();

                    // Output first sample from input
                    output[outOffset++] = (byte)predictor[c];
                    output[outOffset++] = (byte)(predictor[c] >> 8);

                    if (outOffset >= outputSize)
                        return output;
                }

                // Decode and output remaining data in this block
                var blockOffset = 0;
                while (blockOffset < blockDataSize)
                {
                    for (var c = 0; c < Channels; c++)
                    {
                        // Decode 4 bytes (to 16 bytes of output) per channel
                        var chunk = s.ReadBytes(4);
                        var decoded = ImaAdpcmReader.LoadImaAdpcmSound(chunk, ref index[c], ref predictor[c]);

                        // Interleave output, one sample per channel
                        var outOffsetChannel = outOffset + (2 * c);
                        for (var i = 0; i < decoded.Length; i += 2)
                        {
                            var outOffsetSample = outOffsetChannel + i;
                            if (outOffsetSample >= outputSize)
                                return output;

                            output[outOffsetSample] = decoded[i];
                            output[outOffsetSample + 1] = decoded[i + 1];
                            outOffsetChannel += 2 * (Channels - 1);
                        }

                        blockOffset += 4;
                    }

                    outOffset += 16 * Channels;
                }
            }

            return output;
        }
示例#6
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();
        }
示例#7
0
        void UnpackRAOverlayData(MemoryStream ms)
        {
            for (int j = 0; j < mapSize; j++)
            {
                for (int i = 0; i < mapSize; i++)
                {
                    var o = ms.ReadUInt8();
                    var res = Pair.New((byte)0, (byte)0);

                    if (o != 255 && overlayResourceMapping.ContainsKey(redAlertOverlayNames[o]))
                        res = overlayResourceMapping[redAlertOverlayNames[o]];

                    map.MapResources.Value[i, j] = new TileReference<byte, byte>(res.First, res.Second);

                    if (o != 255 && overlayActorMapping.ContainsKey(redAlertOverlayNames[o]))
                    {
                        map.Actors.Value.Add("Actor" + actorCount++,
                            new ActorReference(overlayActorMapping[redAlertOverlayNames[o]])
                            {
                                new LocationInit(new CPos(i, j)),
                                new OwnerInit("Neutral")
                            });
                    }
                }
            }
        }
		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;
				}
			}
		}
示例#9
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();
        }
        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);
        }