Example #1
0
            public WaveRenderer(WaveGenerator wave)
            {
                waveTexture = GetGamedataFile.LoadTexture2D(wave.TextureName, false, true, true);
                rampTexture = GetGamedataFile.LoadTexture2D(wave.RampName, false, true, true);

                waveTexture.wrapMode   = TextureWrapMode.Clamp;
                rampTexture.wrapMode   = TextureWrapMode.Clamp;
                waveTexture.mipMapBias = -0.5f;

                mpb = new MaterialPropertyBlock();

                waveMaterial = new Material(Instance.waveMaterial);
                waveMaterial.SetTexture(SHADER_ALBEDO, waveTexture);
                waveMaterial.SetTexture(SHADER_RAMP, rampTexture);

                //waveMaterial.SetVector(SHADER_VELOCITY, wave.Velocity);


                Instance.loadedMaterial = waveMaterial;

                instancesCount = 0;
                count          = 0;

                AddInstance(wave);
            }
Example #2
0
 void Awake()
 {
     analytics = GameObject.FindGameObjectWithTag("Analytics").GetComponent <LevelAnalytics>();
     audio     = GetComponent <AudioSource>();
     wg        = GameObject.FindGameObjectWithTag("WaveGenerator").GetComponent <WaveGenerator>();
     anim      = GetComponent <Animator>();
 }
Example #3
0
 public void AddScore()
 {
     if (WaveGenerator.instance)
     {
         WaveGenerator.AddScore(score);
     }
 }
Example #4
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 #5
0
        public static Generator Create(DeviceSession session, ExecutionOptions options)
        {
            Generator generator = null;

            if (options.Operation == OperationType.Ants)
            {
                generator = new AutoAntsScriptGenerator(session, options.Device);
            }
            else if (options.Operation == OperationType.Json)
            {
                generator = new JsonGenerator(session);
            }
            else if (options.Operation == OperationType.Hz)
            {
                generator = new WaveGenerator(session);
            }
            else if (options.Operation == OperationType.CArray)
            {
                generator = new CArrayGenerator(session, options.Device);
            }
            else if (options.Operation == OperationType.HumanReadable)
            {
                generator = new HumanReadableGenerator(session, options);
            }
            return(generator);
        }
Example #6
0
    /*
     * Desc: Creates all the wave generators the simulate an ocean
     *
     * parameters:
     *
     *
     * Returns:
     *
     * Pre:
     * water is initialized
     * water objects have a WaveGenerator Component
     *
     */
    void BuildOcean()
    {
        //Find the wave generator vertex distance based on the number of expansions
        int vertDist = (int)Mathf.Pow(2, fractalExpansions + 1);

        //Create a new wave generator at the origin with a rotation
        GameObject    waterObj = Instantiate(water, new Vector3(Size / 2f, 0.5f, Size / 2f), Quaternion.identity, transform);
        WaveGenerator wave     = waterObj.GetComponent <WaveGenerator>();

        //Set the wave generator's values
        wave.size           = subMeshSize + 1;
        wave.vertexDistance = vertDist;


        waterObj            = Instantiate(water, new Vector3(Size / 2f, 0.5f, Size / 2f), Quaternion.Euler(0, 90f, 0), transform);
        wave                = waterObj.GetComponent <WaveGenerator>();
        wave.size           = subMeshSize + 1;
        wave.vertexDistance = vertDist;

        waterObj            = Instantiate(water, new Vector3(Size / 2f, 0.5f, Size / 2f), Quaternion.Euler(0, 180f, 0), transform);
        wave                = waterObj.GetComponent <WaveGenerator>();
        wave.size           = subMeshSize + 1;
        wave.vertexDistance = vertDist;

        waterObj            = Instantiate(water, new Vector3(Size / 2f, 0.5f, Size / 2f), Quaternion.Euler(0, -90f, 0), transform);
        wave                = waterObj.GetComponent <WaveGenerator>();
        wave.size           = subMeshSize + 1;
        wave.vertexDistance = vertDist;
    }
Example #7
0
        private void OnGUI()
        {
            minSize = new Vector2(50, 50);

            var rect = new Rect(10, 10, 300, 15);

            WaveGenerator = EditorGUI.ObjectField(rect, WaveGenerator, typeof(WaveGenerator), true) as WaveGenerator;

            if (WaveGenerator == null)
            {
                var waveGenerators = FindObjectsOfType <WaveGenerator>();
                if (waveGenerators.Length == 1)
                {
                    WaveGenerator = waveGenerators[0];
                }
            }

            if (WaveGenerator != null)
            {
                var header = new WaveGeneratorHeader(this, WaveGenerator);
                header.Draw(new Vector2(10, 30));
                //draw the rest
            }
            else
            {
                //label
                rect.x += 320;
                EditorGUI.LabelField(rect, "PUT THAT WAVE GENERATOR IN IT");
            }
        }
Example #8
0
    /// <summary>
    ///
    /// </summary>
    private void Emit()
    {
        bool    right    = Random.Range(0, 100) > 50;
        Vector3 position = right? rightEmitter.localPosition:leftEmitter.localPosition;

        CreateWave(WaveGenerator.GenerateWave(position, right));
    }
Example #9
0
 private void UpdateCreepCountAndStopCurrentBehavior(WaveGenerator waveGenerator)
 {
     creepCountForCurrentWave     += creepCount;
     creepsSpawnedFromCurrentGroup = 0;
     waveGenerator.Start <WaveCreation>();
     waveGenerator.waveList[0].CreepsAndGroupsList.RemoveAt(0);
     waveGenerator.Stop <SpawnAllCreepsInGroup>();
 }
Example #10
0
 // Use this for initialization
 void Start()
 {
     waveGenerator = GameObject.Find("WavesManager").GetComponent <WaveGenerator>();
     mtext         = this.GetComponent <Text>();
     wave          = 0;
     maxWave       = waveGenerator.MaxWaves();
     mtext.text    = "Vague " + wave + " / " + maxWave;
 }
Example #11
0
        static async void CalculateWave(double daysBeforeZeroPoint, double daysAfterZeroPoint, double timeInterval, int waveFactor)
        {
            WaveGenerator wave = new WaveGenerator(daysBeforeZeroPoint, daysAfterZeroPoint, timeInterval, waveFactor);

            wave.OnWavePointGenerated     += Toolbox.Events.OnWavePointGenerated;
            wave.OnWaveGenerationComplete += Toolbox.Events.OnWaveGenerationComplete;
            await wave.GenerateAsync();
        }
Example #12
0
 private void AddCreepWaves()
 {
     foreach (var wave in Waves)
     {
         CreepWaves.Add(new CreepWave(wave));
     }
     WaveGenerator = new WaveGenerator(CreepWaves);
 }
        public void CreateScriptTest()
        {
            List <DeviceSession> sessions  = TestSetup.GetSessions();
            WaveGenerator        generator = new WaveGenerator(sessions[8]);
            string output = generator.Generate();

            Assert.IsNotNull(output);
        }
Example #14
0
 public static void StopInstrumentNote(WaveGenerator generator)
 {
     generator.Stop();
     if (Voices.Contains(generator))
     {
         Voices.Remove(generator);
     }
 }
        public static void WriteRebootWav(string outputfilename)
        {
            List <short> RebootData = new List <short>();

            WriteReboot(RebootData);
            WaveGenerator W3 = new WaveGenerator(RebootData);

            W3.Save(outputfilename);
        }
        public static void WriteEepromCommand(string outfile, UInt32 address, byte value)
        {
            List <short> EepromData = new List <short>();

            WriteEeprom(EepromData, address, value);
            WaveGenerator W3 = new WaveGenerator(EepromData);

            W3.Save(outfile);
        }
        public static void WriteDACCommand(string outfile, uint value1, uint value2)
        {
            List <short> DACData = new List <short>();

            WriteDAC(DACData, value1, value2);
            WaveGenerator W3 = new WaveGenerator(DACData);

            W3.Save(outfile);
        }
Example #18
0
 // Start is called before the first frame update
 void Start()
 {
     instance = this;
     foreach (GameObject spawnPoint in GameObject.FindGameObjectsWithTag("Respawn"))
     {
         spawnPoints.Add(spawnPoint);
     }
     LoadNextWave();
 }
Example #19
0
        public WaveStream(List <WaveSample> fullAudioStream)
        {
            WaveAudioFormat audioFormat = fullAudioStream?[0]?.SampleFormat;

            byte[] audioData = WaveGenerator.ToByteArray(fullAudioStream.ToArray());
            this.riff = new WaveFileFormat.RIFF_CHUNK();
            this.fmt  = new WaveFileFormat.FMT_CHUNK(audioFormat);
            this.data = new WaveFileFormat.DATA_CHUNK(audioData);
            this.riff.SetChunkSize(4 + (8 + this.fmt.GetChunkSize()) + (8 + this.data.GetChunkSize()));
        }
Example #20
0
 // Use this for initialization
 void Start()
 {
     gm            = GameObject.FindObjectOfType <GameManager>().GetComponent <GameManager> ();
     livesDisplay  = GameObject.Find("LivesDisplay").GetComponent <Text> ();
     moneyDisplay  = GameObject.Find("MoneyDisplay").GetComponent <Text> ();
     detailsText   = GameObject.Find("DetailsText").GetComponent <Text> ();
     countdown     = GameObject.Find("Countdown").GetComponent <Text> ();
     towerPanel    = GameObject.Find("TowerPanel").GetComponent <TowerPanel> ();
     waveGenerator = GameObject.Find("WaveGenerator").GetComponent <WaveGenerator> ();
 }
Example #21
0
        private void button1_Click(object sender, EventArgs e)
        {
            string        filePath = filepathTextBox1.Text;
            WaveGenerator wave     = new WaveGenerator(WaveExampleType.Sine, frequency_single, volume_single, duration_single);

            wave.Save(filePath);
            SoundPlayer player = new SoundPlayer(filePath);

            player.Play();
        }
Example #22
0
 // Start is called before the first frame update
 void Start()
 {
     instance = this;
     foreach (GameObject spawnPoint in GameObject.FindGameObjectsWithTag("Respawn"))
     {
         spawnPoints.Add(spawnPoint);
     }
     StartCoroutine(DisplayUI(waveStartUI, 3));
     LoadNextWave();
 }
        public void TestTheTotalOfNumberOfCreepsInLevel()
        {
            var waveA     = new CreepWave(1.0f, 1.0f, "Paper, Paper", "PaperWave");
            var generator = new WaveGenerator(new List <CreepWave> {
                waveA
            }, Vector3D.One);

            AdvanceTimeAndUpdateEntities(1.01f);
            AdvanceTimeAndUpdateEntities(0.1f);
            Assert.AreEqual(2, generator.TotalCreepsInLevel);
        }
Example #24
0
        private static void PlayNotes(List <Note> notes)
        {
            using (var stream = new MemoryStream())
            {
                WaveGenerator wave = new WaveGenerator(notes);
                wave.Save(stream);

                stream.Seek(0, SeekOrigin.Begin);
                SoundPlayer player = new SoundPlayer(stream);
                player.Play();
            }
        }
Example #25
0
 public void StartGame()
 {
     Enemy.OnEnemiesChange += OnEnemiesChange;
     WaveGenerator.Init();
     this.cannonLevel = 1;
     this.money       = 0;
     glass.Damage     = 0;
     timeStarted      = DateTime.Now;
     glass.ResetGlass();
     startScreen.SetActive(false);
     endScreen.SetActive(false);
     emittersControl.StartEmitting();
 }
Example #26
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Vector v1 = new Vector(0, -1);
            Vector v2 = new Vector(-.95f, -.35f);
            Vector v3 = new Vector(-.59f, .81f);
            Vector v4 = new Vector(.59f, .81f);
            Vector v5 = new Vector(.95f, -.35f);

            WaveGenerator wg = new WaveGenerator();

            wg.SetWaveShape(new Vector[] { v1, v3, v5, v2, v4 });
            wg.Generate();
            wg.Save("C:\\Users\\theen\\Desktop\\wawawaw\\test.wav");
        }
Example #27
0
 private static void CreateWave(CreepWave wave, WaveGenerator waveGenerator)
 {
     if (creepCountForCurrentWave >= wave.TotalCreepsInWave)
     {
         creepCountForCurrentWave = 0;
         waveGenerator.waveList.RemoveAt(0);
         waveGenerator.level.UpdateWave();
         return;
     }
     if (!Time.CheckEvery(wave.SpawnInterval))
     {
         return;
     }
     SpawnNextItemFromList(wave.CreepsAndGroupsList[0], waveGenerator);
 }
    // Use this for initialization
    void Start()
    {
        audioSource           = GetComponent <AudioSource>();
        waveGenerators        = new Queue <WaveGenerator>();
        epicenterZoneCollider = epicenterZone.GetComponent <Collider2D>();

        // Create a few wave generators: More load time but smoother run time
        for (int i = 0; i < initialWaveGenerators; i++)
        {
            WaveGenerator wg = (WaveGenerator)GameObject.Instantiate(instance, transform.position, Quaternion.identity);
            wg.lifeTime = lifeTime;
            wg.gameObject.SetActive(false);
            waveGenerators.Enqueue(wg);
        }
    }
Example #29
0
        public void saveAsWav()
        {
            if (wav == null)
            {
                return;
            }
            SaveFileDialog saveDialog = new SaveFileDialog();

            saveDialog.Filter = "WAV|*.wav";
            if (saveDialog.ShowDialog() == DialogResult.OK)
            {
                WaveGenerator wave = new WaveGenerator(samples);
                wave.Save(saveDialog.FileName);
            }
        }
        public void playSound(WaveExampleType waveType)
        {
            // Set filepath
            string filePath = this.GetHashCode().ToString();

            // Instantiate wave generator
            WaveGenerator wave = new WaveGenerator(waveType, getFrequency(), 0.1);

            // Save to filepath
            wave.Save(filePath);

            // Play the sound
            player = new SoundPlayer(filePath);
            player.PlayLooping();
        }
        public void updatePlaying(double freq, WaveGenerator.WaveType wavetype)
        {
            frequencies.Clear();
            frequencies.Add(freq);
            mixer.RemoveAllSources();
            VolumeSource  vol;
            WaveGenerator generator = new WaveGenerator(wavetype, freq, 1.0, 0);

            mixer.AddSource(
                generator.ToWaveSource()
                .AppendSource(x => new DmoChannelResampler(x, monoToStereoChannelMatrix, sampleRate))
                .AppendSource(x => new VolumeSource(x.ToSampleSource()), out vol)
                );

            Debug.WriteLine(frequencies.Count().ToString() + " frequencies");
        }
Example #32
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;
    }
Example #33
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();
        }