Example #1
0
 // Use this for initialization
 void Start()
 {
     //WaveGenerator waveGen = (WaveGenerator)Resources.Load("WaveGenerator");
     transform.position = new Vector3(0, 2F + WaveGenerator.waterHeight/2F, 0);
     waveGen = (WaveGenerator)Object.FindObjectOfType(typeof(WaveGenerator));
     //var waves = waveGen.waves;
 }
Example #2
0
        private void decodePlay_Click(object sender, EventArgs e)
        {
            // Decode the data.

            // Get the dataSize which is in the first 11 pixels (32 / 3 = 10.67).
            int dataSize = 0;
            byte zero = 1;
            int bitShift = 31;
            for (int i = 0, j = 0; j < 11; j++)
            {
                Color color = ((Bitmap)(encryptedImageBox.Image)).GetPixel(i, j);
                dataSize += ((color.R & zero) << bitShift);
                bitShift--;

                dataSize += ((color.G & zero) << bitShift);
                bitShift--;

                if (11 != j)
                {
                    dataSize += ((color.B & zero) << bitShift);
                    bitShift--;
                }
            }

            if (dataSize > (encryptedImageBox.Width * encryptedImageBox.Height) || dataSize < 128)
            {
                MessageBox.Show("WARNING: It is likely the image is not encrypted or has been corrupted.");
            }

            // Get the sample rate.
            int sampleRate = 0;
            bitShift = 31;
            for (int i = 0, j = 10; j < 22; j++)
            {
                Color color = ((Bitmap)(encryptedImageBox.Image)).GetPixel(i, j);
                if (10 == j)
                {
                    sampleRate = ((color.B & zero) << bitShift);
                    bitShift--;
                }
                else if (21 == j)
                {
                    sampleRate += ((color.R & zero) << bitShift);
                    bitShift--;
                }
                else
                {
                    sampleRate += ((color.R & zero) << bitShift);
                    bitShift--;
                    sampleRate += ((color.G & zero) << bitShift);
                    bitShift--;
                    sampleRate += ((color.B & zero) << bitShift);
                    bitShift--;
                }
            }

            // Get the average bytes per second.
            int fmtAvgBPS = 0;
            bitShift = 31;
            for (int i = 0, j = 21; j < 32; j++)
            {
                Color color = ((Bitmap)(encryptedImageBox.Image)).GetPixel(i, j);
                if (21 == j)
                {
                    fmtAvgBPS = ((color.G & zero) << bitShift);
                    bitShift--;
                    fmtAvgBPS = ((color.B & zero) << bitShift);
                    bitShift--;
                }
                else
                {
                    fmtAvgBPS += ((color.R & zero) << bitShift);
                    bitShift--;
                    fmtAvgBPS += ((color.G & zero) << bitShift);
                    bitShift--;
                    fmtAvgBPS += ((color.B & zero) << bitShift);
                    bitShift--;
                }
            }

            // Get the block align.
            int blockAlign = 0;
            bitShift = 15;
            for (int i = 0, j = 32; j < 38; j++)
            {
                Color color = ((Bitmap)(encryptedImageBox.Image)).GetPixel(i, j);
                blockAlign += ((color.R & zero) << bitShift);
                bitShift--;

                if (37 != j)
                {
                    blockAlign += ((color.G & zero) << bitShift);
                    bitShift--;

                    blockAlign += ((color.B & zero) << bitShift);
                    bitShift--;
                }
            }

            // Get the bit depth.
            int bitDepth = 0;
            bitShift = 15;
            for (int i = 0, j = 37; j < 43; j++)
            {
                Color color = ((Bitmap)(encryptedImageBox.Image)).GetPixel(i, j);

                if (37 == j)
                {
                    bitDepth += ((color.G & zero) << bitShift);
                    bitShift--;

                    bitDepth += ((color.B & zero) << bitShift);
                    bitShift--;
                }
                else if (42 == j)
                {
                    bitDepth += ((color.R & zero) << bitShift);
                    bitShift--;

                    bitDepth += ((color.G & zero) << bitShift);
                    bitShift--;
                }
                else
                {
                    bitDepth += ((color.R & zero) << bitShift);
                    bitShift--;

                    bitDepth += ((color.G & zero) << bitShift);
                    bitShift--;

                    bitDepth += ((color.B & zero) << bitShift);
                    bitShift--;
                }
            }

            // Grab the first value, which is the most significant bit.
            // Bit shift it to the leftmost byte position, and store it into the data array.
            // Move the bit shift counter one to the right (meaning divide it by 2).
            // If the counter is zero, reset to leftmost bit = 1.

            if (16 == bitDepth)
            {
                List<short> waveData = new List<short>();
                waveData.Add(0);
                int shift = 7;
                int wavIndex = 0;
                dataSize /= 2;          // Divide by two for shorts (2 bytes long).
                /*  A short is two bytes, xy. It's stored in wave file in reverse order (little-endian).
                *   We extract it by first grabbing the lower significant byte with the shift initialized
                *   to 7, then grabbing the most significant byte with shift = 15. When the shift = 7
                *   again, we add to the list and continue.
                */
                for (int i = 0; i < encryptedImageBox.Image.Width; i++)
                {
                    for (int j = 0; j < encryptedImageBox.Image.Height && wavIndex != dataSize; j++)
                    {
                        Color pixel = ((Bitmap)(encryptedImageBox.Image)).GetPixel(i, j);

                        if (0 == i && 0 == j)
                        {   // Get the first bit of data, not the header information.
                            j = 42;
                            waveData[wavIndex] += (short)((pixel.B & zero) << shift);
                            shift--;
                        }
                        else
                        {
                            waveData[wavIndex] += (short)((pixel.R & zero) << shift);
                            shift--;
                            if (7 == shift)
                            {
                                waveData.Add(0);
                                wavIndex++;
                            }
                            else if (-1 == shift)
                            {
                                shift = 15;
                            }

                            waveData[wavIndex] += (short)((pixel.G & zero) << shift);
                            shift--;
                            if (7 == shift)
                            {
                                waveData.Add(0);
                                wavIndex++;
                            }
                            else if (-1 == shift)
                            {
                                shift = 15;
                            }

                            waveData[wavIndex] += (short)((pixel.B & zero) << shift);
                            shift--;
                            if (7 == shift)
                            {
                                waveData.Add(0);
                                wavIndex++;
                            }
                            else if (-1 == shift)
                            {
                                shift = 15;
                            }
                        }
                    }
                }

                // Create the .wav file.
                string filePath16 = @"C:\Users\onlyo\OneDrive\Pictures\SeniorDesign\tempWavs\temp.wav";
                wave = new WaveGenerator(WaveExampleType.Decrypt, waveData);
                wave.format.dwSamplesPerSec = (uint)sampleRate;
                wave.format.dwAvgBytesPerSec = (uint)fmtAvgBPS;
                wave.format.wBlockAlign = (ushort)blockAlign;
                wave.format.wBitsPerSample = (ushort)bitDepth;
                wave.saveWave(filePath16);
            }
            else if (8 == bitDepth)
            {
                List<byte> waveData = new List<byte>();
                waveData.Add(0);
                int shift = 7;
                int wavIndex = 0;
                for (int i = 0; i < encryptedImageBox.Image.Width; i++)
                {
                    for (int j = 0; j < encryptedImageBox.Image.Height && wavIndex != dataSize; j++)
                    {
                        Color pixel = ((Bitmap)(encryptedImageBox.Image)).GetPixel(i, j);

                        if (0 == i && 0 == j)
                        {   // Get the first bit of data, not the header information.
                            j = 42;
                            waveData[wavIndex] += (byte)((pixel.B & zero) << shift);
                            shift--;
                        }
                        else
                        {
                            waveData[wavIndex] += (byte)((pixel.R & zero) << shift);
                            shift--;
                            if (-1 == shift)
                            {
                                waveData.Add(0);
                                wavIndex++;
                                shift = 7;
                            }

                            waveData[wavIndex] += (byte)((pixel.G & zero) << shift);
                            shift--;
                            if (-1 == shift)
                            {
                                waveData.Add(0);
                                wavIndex++;
                                shift = 7;
                            }

                            waveData[wavIndex] += (byte)((pixel.B & zero) << shift);
                            shift--;
                            if (-1 == shift)
                            {
                                waveData.Add(0);
                                wavIndex++;
                                shift = 7;
                            }
                        }
                    }
                }

                // Create the .wav file.
                string filePath8 = @"C:\Users\onlyo\OneDrive\Pictures\SeniorDesign\tempWavs\temp.wav";
                wave = new WaveGenerator(WaveExampleType.Decrypt, waveData);
                wave.format.dwSamplesPerSec = (uint)sampleRate;
                wave.format.dwAvgBytesPerSec = (uint)fmtAvgBPS;
                wave.format.wBlockAlign = (ushort)blockAlign;
                wave.format.wBitsPerSample = (ushort)bitDepth;
                wave.saveWave(filePath8);
            }
            else
            {
                MessageBox.Show("Terminating: Unencrypted or corrupted image. Bits per sample: " + bitDepth);
                return;
            }

            string filePath = @"C:\Users\onlyo\OneDrive\Pictures\SeniorDesign\tempWavs\temp.wav";

            // Play the sound.
            SoundPlayer player = new SoundPlayer(filePath);
            player.Play();
        }
Example #3
0
    public bool Load(string Filename)
    {
        if (string.IsNullOrEmpty(Filename))
            return false;
        if (!System.IO.File.Exists(Filename))
            return false;

        this.Filename = Filename;

        Clear();

        System.IO.FileStream fs = new System.IO.FileStream(Filename, System.IO.FileMode.Open, System.IO.FileAccess.Read);
        BinaryReader Stream = new BinaryReader(fs);

		TexturemapTex = new Texture2D(0,0);
		TexturemapTex2 = new Texture2D(0,0);
		NormalmapTex = new Texture2D(0,0);
		WatermapTex = new Texture2D(0,0);
		PreviewTex = new Texture2D(0,0);

        byte[] PreviewData = new byte[0];
        byte[] TexturemapData = new byte[0];
        byte[] TexturemapData2 = new byte[0];
        byte[] NormalmapData = new byte[0];
        byte[] WatermapData = new byte[0];
        int Count = 0;

        BinaryReader _with1 = Stream;
        //# Header Section #
        if (_with1.ReadInt32() == MAP_MAGIC)
        {
            VersionMajor = _with1.ReadInt32();
            //? always 2
            Unknown10 = _with1.ReadInt32();
            //? always EDFE EFBE
            Unknown11 = _with1.ReadInt32();
            //? always 2
            _with1.ReadSingle();
            //Map Width (in float)
            _with1.ReadSingle();
            //Map Height (in float)
            Unknown12 = _with1.ReadInt32();
            //? always 0
            Unknown13 = _with1.ReadInt16();
            //? always 0
            int ImageLength = _with1.ReadInt32();
            PreviewData = _with1.ReadBytes(ImageLength);

            VersionMinor = _with1.ReadInt32();
            if (VersionMinor <= 0)
                VersionMinor = 56;

            if (VersionMinor > 56)
            {
                Console.WriteLine("This map uses SCMAP file version" + VersionMinor + " which is not yet supported by this editor. I will try to load it with the newest known version (" + 56 + "), but it is very likely to fail or cause errors.");
            }

            //# Heightmap Section #
            Width = _with1.ReadInt32();
            Height = _with1.ReadInt32();

            HeightScale = _with1.ReadSingle();
            //Height Scale, usually 1/128
            HeightmapData = _with1.ReadInt16Array((Height + 1) * (Width + 1));//TODO: Current saving method gets a memory overload on trying to reload the map here.
            //heightmap dimension is always 1 more than texture dimension!

            if (VersionMinor >= 56)
                _with1.ReadByte();
            //Always 0?

            //# Texture Definition Section #
            TerrainShader = _with1.ReadStringNull();
            //Terrain Shader, usually "TTerrain"
            TexPathBackground = _with1.ReadStringNull();
            TexPathSkyCubemap = _with1.ReadStringNull();

            if (VersionMinor >= 56)
            {
                Count = _with1.ReadInt32();
                //always 1?
                EnvCubemapsName = new string[Count];
                EnvCubemapsFile = new string[Count];
                for (int i = 0; i <= Count - 1; i++)
                {
                    EnvCubemapsName[i] = _with1.ReadStringNull();
                    EnvCubemapsFile[i] = _with1.ReadStringNull();
                }
            }
            else
            {
                EnvCubemapsName = new string[2];
                EnvCubemapsName[0] = "<default>";
                EnvCubemapsFile = new string[2];
                EnvCubemapsFile[0] = _with1.ReadStringNull();
            }

            LightingMultiplier = _with1.ReadSingle();
            SunDirection = _with1.ReadVector3();
            SunAmbience = _with1.ReadVector3();
            SunColor = _with1.ReadVector3();
            ShadowFillColor = _with1.ReadVector3();
            SpecularColor = _with1.ReadVector4();
            Bloom = _with1.ReadSingle();

            FogColor = _with1.ReadVector3();
            FogStart = _with1.ReadSingle();
            FogEnd = _with1.ReadSingle();


            Water.Load(Stream);

            Count = _with1.ReadInt32();
            WaveGenerators.Clear();
            for (int i = 0; i <= Count - 1; i++)
            {
                WaveGenerator WaveGen = new WaveGenerator();
                WaveGen.Load(Stream);
                WaveGenerators.Add(WaveGen);
            }

            if (VersionMinor < 56)
            {
                _with1.ReadStringNull();
                // always "No Tileset"
                Count = _with1.ReadInt32();
                //always 6
                for (int i = 0; i <= 4; i++)
                {
                    Layer Layer = new Layer();
                    Layer.Load(Stream);
                    Layers.Add(Layer);
                }
                for (int i = 5; i <= 8; i++)
                {
                    Layers.Add(new Layer());
                }
                for (int i = 9; i <= 9; i++)
                {
                    Layer Layer = new Layer();
                    Layer.Load(Stream);
                    Layers.Add(Layer);
                }
            }
            else
			{
                MinimapContourInterval = _with1.ReadInt32();

				int argb = _with1.ReadInt32();
				int r = (argb)&0xFF;
				int g = (argb>>8)&0xFF;
				int b = (argb>>16)&0xFF;
				int a = (argb>>24)&0xFF;
                MinimapDeepWaterColor = new Color(r,g,b,a);
				int argb2 = _with1.ReadInt32();
				int r2 = (argb2)&0xFF;
				int g2 = (argb2>>8)&0xFF;
				int b2 = (argb2>>16)&0xFF;
				int a2 = (argb2>>24)&0xFF;
				MinimapContourColor = new Color(r2,g2,b2,a2);
				int argb3 = _with1.ReadInt32();
				int r3 = (argb3)&0xFF;
				int g3 = (argb3>>8)&0xFF;
				int b3 = (argb3>>16)&0xFF;
				int a3 = (argb3>>24)&0xFF;
				MinimapShoreColor = new Color(r3,g3,b3,a3);
				int argb4 = _with1.ReadInt32();
				int r4 = (argb4)&0xFF;
				int g4 = (argb4>>8)&0xFF;
				int b4 = (argb4>>16)&0xFF;
				int a4 = (argb4>>24)&0xFF;
				MinimapLandStartColor = new Color(r4,g4,b4,a4);
				int argb5 = _with1.ReadInt32();
				int r5 = (argb5)&0xFF;
				int g5 = (argb5>>8)&0xFF;
				int b5 = (argb5>>16)&0xFF;
				int a5 = (argb5>>24)&0xFF;
				MinimapLandEndColor = new Color(r5,g5,b5,a5);
                
                if (VersionMinor > 56)
                {
                    Unknown14 = _with1.ReadSingle(); //Not sure what this is.
                }
                Count = 10;
                for (int i = 0; i <= Count - 1; i++)
                {
                    Layer Layer = new Layer();
                    Layer.LoadAlbedo(Stream);
                    Layers.Add(Layer);
                }
                for (int i = 0; i <= Count - 2; i++)
                {
                    Layers[i].LoadNormal(Stream);
                }
            }
            Unknown7 = _with1.ReadInt32();
            //?
            Unknown8 = _with1.ReadInt32();
            //?

            int DecalCount = _with1.ReadInt32();
            for (int i = 0; i <= DecalCount - 1; i++)
            {
                Decal Feature = new Decal();
                Feature.Load(Stream);
                Decals.Add(Feature);
            }

            int GroupCount = _with1.ReadInt32();
            for (int i = 0; i <= GroupCount - 1; i++)
            {
                IntegerGroup Group = new IntegerGroup();
                Group.Load(Stream);
                DecalGroups.Add(Group);
            }

            _with1.ReadInt32();
            //Width again
            _with1.ReadInt32();
            //Height again

            int Length = 0;
            int NormalmapCount = _with1.ReadInt32();
            //always 1
            for (int i = 0; i <= NormalmapCount - 1; i++)
            {
                Length = _with1.ReadInt32();
                if (i == 0)
                {
                    NormalmapData = _with1.ReadBytes(Length);
                }
                else
                {
                    _with1.BaseStream.Position += Length;
                    // just to make sure that it doesn't crash if it is not just 1 normalmap for some reason
                }
            }


            if (VersionMinor < 56)
                _with1.ReadInt32();
            //always 1
            Length = _with1.ReadInt32();
            TexturemapData = _with1.ReadBytes(Length);

            if (VersionMinor >= 56)
            {
                Length = _with1.ReadInt32();
                TexturemapData2 = _with1.ReadBytes(Length);
            }

            //Watermap
            _with1.ReadInt32();
            //always 1
            Length = _with1.ReadInt32();
            WatermapData = _with1.ReadBytes(Length);

            int HalfSize = (Width / 2) * (Height / 2);
            WaterFoamMask = _with1.ReadBytes(HalfSize);
            WaterFlatnessMask = _with1.ReadBytes(HalfSize);
            WaterDepthBiasMask = _with1.ReadBytes(HalfSize);

            TerrainTypeData = _with1.ReadBytes(Width * Height);

            if (VersionMinor <= 52)
                _with1.ReadInt16();
            //always 0

            int PropCount = _with1.ReadInt32();
            for (int i = 0; i <= PropCount - 1; i++)
            {
                Prop Prop = new Prop();
                Prop.Load(Stream);
                Props.Add(Prop);
            }
        }
        _with1.Close();
        fs.Close();
        fs.Dispose();

		PreviewTex = TextureLoader.LoadTextureDXT(PreviewData,TextureFormat.DXT5);//.LoadImage(PreviewData);// = Texture.FromMemory(Device, PreviewData, 256, 256, 1, Usage.None, Format.A8R8G8B8, Pool.Scratch, Filter.None, Filter.None, 0);
        PreviewData = new byte[0];
      //  PreviewBitmap = TextureToBitmap(PreviewTex);

		TexturemapTex = TextureLoader.LoadTextureDXT(TexturemapData,TextureFormat.RGBA32);//.LoadImage(TexturemapData);// = Texture.FromMemory(Device, TexturemapData, Width / 2, Height / 2, 1, Usage.None, Format.A8R8G8B8, Pool.Scratch, Filter.None, Filter.None, 0);
        TexturemapData = new byte[0];

        if (TexturemapData2.Length > 0)
        {
			TexturemapTex2 = TextureLoader.LoadTextureDXT(TexturemapData2,TextureFormat.ARGB32);//.LoadImage(TexturemapData2);// = Texture.FromMemory(Device, TexturemapData2, Width / 2, Height / 2, 1, Usage.None, Format.A8R8G8B8, Pool.Scratch, Filter.None, Filter.None, 0);
            TexturemapData2 = new byte[0];
        }
        else
        {
			TexturemapTex2 = new Texture2D(Width/2,Height/2);//(Device, Width / 2, Height / 2, 1, Usage.None, Format.A8R8G8B8, Pool.Managed);
        }

		NormalmapTex = TextureLoader.LoadTextureDXT(NormalmapData,TextureFormat.DXT5);//.LoadImage(NormalmapData);// = Texture.FromMemory(Device, NormalmapData, Width, Height, 1, Usage.None, Format.Dxt5, Pool.Scratch, Filter.None, Filter.None, 0);
        NormalmapData = new byte[0];

		WatermapTex = TextureLoader.LoadTextureDXT(WatermapData,TextureFormat.DXT5);//.LoadImage(WatermapData);// = Texture.FromMemory(Device, WatermapData, Width / 2, Height / 2,  1, Usage.None, Format.Dxt5, Pool.Scratch, Filter.None, Filter.None, 0);
        WatermapData = new byte[0];

        return true;
    }