Ejemplo n.º 1
0
        public MainMenuScreen(BaseMenuScreen parent)
            : base(parent)
        {
            if (!SoundCache.IsInitialized)
            {
                GameEngine.Audio.SetDefaultVolume(1);
                SoundCache.Initialize();

                GameVars.Palette = new PaletteFile(GameVars.BasePath + "reg\\palettes\\drrender.pal");
            }

            GameEngine.musicPlayer = new MusicPlayer();
            GameEngine.musicPlayer.Play();

            _inAnimation = new AnimationPlayer(LoadAnimation("MAI2COME.fli"), 1);
            _inAnimation.Play(false);
            ScreenEffects.Instance.FadeSpeed = 300;
            ScreenEffects.Instance.UnFadeScreen();

            _outAnimation = new AnimationPlayer(LoadAnimation("MAI2AWAY.fli"));

            _options.Add(
                new TextureMenuOption(BaseHUDItem.ScaleRect(0.181f, 0.256f, 0.68f, 0.045f),
                                      LoadAnimation("MAI2N1GL.fli")[0])
                );

            _options.Add(
                new TextureMenuOption(BaseHUDItem.ScaleRect(0.180f, 0.711f, 0.715f, 0.045f),
                                      LoadAnimation("MAI2QTGL.fli")[0])
                );
        }
Ejemplo n.º 2
0
        public static SoundEffect GetSound(string path)
        {
            path = NormalizePath(path);
            SoundEffect sound = null;

            SoundCache.TryGetValue(path, out sound);
            return(sound);
        }
Ejemplo n.º 3
0
 public ReplaceSoundTransaction(SNDFile sndFile, SoundCache cache, int id, string name, byte[] data) : base("Replace sound")
 {
     this.sndFile = sndFile;
     this.id      = id;
     this.name    = name;
     this.data    = data;
     this.cache   = cache;
 }
Ejemplo n.º 4
0
    // Start is called before the first frame update
    void Start()
    {
        if (SoundCache.instance != null)
        {
            throw new System.Exception("SoundCache is singleton");
        }

        SoundCache.instance = this;
        SoundCache.cache.Add("tirin1", Resources.Load <AudioClip>("Sound/tirin1"));
    }
Ejemplo n.º 5
0
 public void Init()
 {
     //move arm into view
     timer  = 90;
     x      = 410;
     inhole = false;
     y1     = 900;
     y2     = 900;
     state  = LevelState.INIT;
     dx     = 0;
     foreach (Light l in lights)
     {
         l.Off();
     }
     lights[activeHole - 1].On();
     SoundCache.PlaySound("Pilot Are You Ready");
     mainLoop.Play();
 }
Ejemplo n.º 6
0
        private static MemoryStream GetSoundStream(string soundName)
        {
            byte[] data;
            if (!SoundCache.TryGetValue(soundName, out data))
            {
                var moduleName       = Assembly.GetExecutingAssembly().GetName().Name;
                var resourceLocation = $"pack://application:,,,/{moduleName};component/Resources/Sounds/{soundName}";
                var stream           = Application.GetResourceStream(new Uri(resourceLocation));

                if (stream == null)
                {
                    return(null);
                }

                data = new byte[stream.Stream.Length];
                stream.Stream.Read(data, 0, data.Length);

                SoundCache[soundName] = data;
            }
            return(new MemoryStream(data));
        }
Ejemplo n.º 7
0
        public RaceCompletedMode(CompletionType type)
        {
            _camera               = new FixedChaseCamera(6.3f, 2.3f);
            _camera.FieldOfView   = MathHelper.ToRadians(55.55f);
            _camera.RotationSpeed = 0.8f;
            _camera.MinHeight     = 10;

            switch (type)
            {
            case CompletionType.Opponents:
                MessageRenderer.Instance.PostHeaderMessage("Every opponent wasted!!", 10);
                MessageRenderer.Instance.PostMainMessage("raceover.pix", 8, 0.7f, 0.003f, 1.4f);
                SoundCache.Play(SoundIds.RaceCompleted, null, false);
                SoundCache.Play(SoundIds.Clapping, null, false);
                break;

            case CompletionType.Checkpoints:
                MessageRenderer.Instance.PostHeaderMessage("All checkpoints passed!!", 10);
                MessageRenderer.Instance.PostMainMessage("raceover.pix", 8, 0.7f, 0.003f, 1.4f);
                SoundCache.Play(SoundIds.RaceCompleted, null, false);
                SoundCache.Play(SoundIds.Clapping, null, false);
                break;

            case CompletionType.Peds:
                MessageRenderer.Instance.PostHeaderMessage("Every pedestrian murdered!!", 10);
                MessageRenderer.Instance.PostMainMessage("raceover.pix", 8, 0.7f, 0.003f, 1.4f);
                SoundCache.Play(SoundIds.RaceCompleted, null, false);
                SoundCache.Play(SoundIds.Clapping, null, false);
                break;

            case CompletionType.TimeUp:
                MessageRenderer.Instance.PostMainMessage("timeup.pix", 8, 0.7f, 0.003f, 1.4f);
                SoundCache.Play(SoundIds.OutOfTime, null, false);
                break;
            }

            _camera.ResetRotation();
            _camera.RotateTo(MathHelper.Pi * 2);
            Engine.Camera = _camera;
        }
Ejemplo n.º 8
0
 public void read_wems(string folder)
 {
     string[] files = Directory.GetFiles(folder, "*.wem", SearchOption.AllDirectories);
     foreach (string f in files)
     {
         try
         {
             FileInfo fi       = new FileInfo(f);
             WEM      w        = new WEM();
             var      sbi_name = SoundCache.GetIDFromPath(f);
             uint.TryParse(Path.GetFileNameWithoutExtension(sbi_name), out w._id);
             w._size = (UInt32)fi.Length;
             BinaryReader br = new BinaryReader(fi.OpenRead());
             w._data = br.ReadBytes((int)br.BaseStream.Length);
             _to_add.Add(w);
             Console.WriteLine("\tFile ->" + f + " | " + sbi_name);
         }
         catch
         {
             continue;
         }
     }
 }
Ejemplo n.º 9
0
        private List <String> getMessageFolders(List <MessageFragment> messageFragments, Boolean hasAlternative)
        {
            List <String> messages = new List <String>();

            for (int i = 0; i < messageFragments.Count; i++)
            {
                MessageFragment messageFragment = messageFragments[i];
                if (messageFragment == null)
                {
                    Console.WriteLine("Message " + this.messageName + " can't be played because it has no contents");
                    canBePlayed = false;
                    break;
                }
                // if this fragment is not the last message fragment, then some languages (Italian only at the time of writing)
                // require a different inflection to the final part of a time / number sound.
                Boolean useMoreInflection = i < messageFragments.Count - 1;
                switch (messageFragment.type)
                {
                case FragmentType.Text:
                    if (messageFragment.text.StartsWith(AudioPlayer.PAUSE_ID) || SoundCache.availableSounds.Contains(messageFragment.text) ||
                        SoundCache.hasSingleSound(messageFragment.text))
                    {
                        messages.Add(messageFragment.text);
                    }
                    else
                    {
                        Console.WriteLine("Message " + this.messageName + " can't be played because there is no sound for text fragment " + messageFragment.text);
                        canBePlayed = false;
                    }
                    break;

                case FragmentType.Time:
                    if (numberReader != null)
                    {
                        List <String> timeFolders = numberReader.ConvertTimeToSounds(messageFragment.timeSpan, useMoreInflection);
                        if (timeFolders.Count == 0)
                        {
                            Console.WriteLine("Message " + this.messageName + " can't be played because the number reader found no sounds for timespan "
                                              + messageFragment.timeSpan.timeSpan.ToString() + " precision " + messageFragment.timeSpan.getPrecision());
                            canBePlayed = false;
                        }
                        else
                        {
                            foreach (String timeFolder in timeFolders)
                            {
                                if (!timeFolder.StartsWith(AudioPlayer.PAUSE_ID) && !SoundCache.availableSounds.Contains(timeFolder))
                                {
                                    Console.WriteLine("Message " + this.messageName + " can't be played because there is no sound for time fragment " + timeFolder);
                                    canBePlayed = false;
                                    break;
                                }
                            }
                            messages.AddRange(timeFolders);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Message " + this.messageName + " can't be played because the number reader is not available");
                        canBePlayed = false;
                    }
                    break;

                case FragmentType.Opponent:
                    canBePlayed = false;
                    if (messageFragment.opponent != null && messageFragment.opponent.CanUseName)
                    {
                        String usableName = DriverNameHelper.getUsableDriverName(messageFragment.opponent.DriverRawName);
                        if (SoundCache.availableDriverNames.Contains(usableName))
                        {
                            messages.Add(usableName);
                            canBePlayed = true;
                        }
                        else if (usableName != null && usableName.Count() > 0 && AudioPlayer.ttsOption != AudioPlayer.TTS_OPTION.NEVER &&
                                 (!hasAlternative || AudioPlayer.ttsOption == AudioPlayer.TTS_OPTION.ANY_TIME))
                        {
                            messages.Add(SoundCache.TTS_IDENTIFIER + usableName);
                            canBePlayed = true;
                        }
                        else
                        {
                            Console.WriteLine("Message " + this.messageName + " can't be played because there is no sound for opponent name " + usableName);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Message " + this.messageName + " can't be played because the opponent is null or unusable");
                    }
                    break;

                case FragmentType.Integer:
                    if (numberReader != null)
                    {
                        List <String> integerFolders = numberReader.GetIntegerSounds(messageFragment.integer, messageFragment.allowShortHundreds, useMoreInflection);
                        if (integerFolders.Count() == 0)
                        {
                            Console.WriteLine("Message " + this.messageName + " can't be played because the number reader found no sounds for number " + messageFragment.integer);
                            canBePlayed = false;
                            break;
                        }
                        else
                        {
                            foreach (String integerFolder in integerFolders)
                            {
                                if (!integerFolder.StartsWith(AudioPlayer.PAUSE_ID) && !SoundCache.availableSounds.Contains(integerFolder))
                                {
                                    Console.WriteLine("Message " + this.messageName + " can't be played because there is no sound for number fragment " + integerFolder);
                                    canBePlayed = false;
                                    break;
                                }
                            }
                        }
                        messages.AddRange(integerFolders);
                    }
                    else
                    {
                        Console.WriteLine("Message " + this.messageName + " can't be played because the number reader is not available");
                        canBePlayed = false;
                    }
                    break;
                }
                if (!canBePlayed)
                {
                    break;
                }
            }
            return(messages);
        }
Ejemplo n.º 10
0
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

            //update all lights
            foreach (Light l in lights)
            {
                l.Update(gameTime);
            }

            //update all sounds
            mainLoop.Update(gameTime);

            //game state
            switch (state)
            {
            case LevelState.INIT:
                //move bar up until in start position
                y1 -= (float)gameTime.ElapsedGameTime.TotalMilliseconds / 30;
                y2 -= (float)gameTime.ElapsedGameTime.TotalMilliseconds / 30;
                if (y1 < 830)
                {
                    y1 = 830;
                    y2 = 830;
                    StartGame();
                }
                break;

            case LevelState.RESETTING:
                //move bar down to get new ball
                if (gameTime.TotalGameTime.TotalMilliseconds > lastRandomLight + 100)
                {
                    if (randomLight != 0)
                    {
                        lights[randomLight - 1].Off();
                    }
                    randomLight++;
                    if (randomLight == 11)
                    {
                        randomLight = 1;
                    }
                    lights[randomLight - 1].On();
                    lastRandomLight = gameTime.TotalGameTime.TotalMilliseconds;
                }
                if (y1 < 900)
                {
                    y1 += (float)gameTime.ElapsedGameTime.TotalMilliseconds / 15;
                }
                if (y2 < 900)
                {
                    y2 += (float)gameTime.ElapsedGameTime.TotalMilliseconds / 15;
                }
                if (y1 >= 900 && y2 >= 900)
                {
                    if (lives != 0)
                    {
                        Init();
                    }
                    else
                    {
                        EndGame();
                    }
                }
                break;

            case LevelState.ENDING:
                endSequence -= gameTime.ElapsedGameTime.TotalMilliseconds;
                if (endSequence < 0)
                {
                    StartAttractMode();
                }
                break;

            case LevelState.ATTRACT:
                //update attract mode message
                if (gameTime.TotalGameTime.TotalMilliseconds > lastMsgUpdate + 200)
                {
                    msgpos++;
                    if (msgpos == msg.Length - 5)
                    {
                        msgpos = 0;
                    }
                    lastMsgUpdate = gameTime.TotalGameTime.TotalMilliseconds;
                }
                //update attract mode lights
                if (gameTime.TotalGameTime.TotalMilliseconds > lastRandomLight + 5)
                {
                    //if (MediaPlayer.State == MediaState.Playing)

                    /*{
                     *  MediaPlayer.GetVisualizationData(data);
                     *  float total = 0;
                     *  for (int i = 0; i < 256; i++)
                     *  {
                     *      total += data.Samples[i];
                     *  }
                     *  total = Math.Abs(total / 256)*40;
                     *
                     *  if (total > 1.0f) total = 1.0f;
                     *  for(int i=0;i<10;i++) lights[i].Off();
                     *  randomLight = (int)(total * 9) + 1;
                     *  for(int i=0;i<randomLight;i++) lights[i].On();
                     * }*/

                    lastRandomLight = gameTime.TotalGameTime.TotalMilliseconds;
                }
                break;

            case LevelState.PLAYING:
                //update timer
                if (gameTime.TotalGameTime.TotalMilliseconds > lastTimerUpdate + 1000)
                {
                    timer--;
                    if (timer == 0)
                    {
                        PlayerDie();
                        Reset();
                    }
                    if (timer == 2)
                    {
                        SoundCache.PlaySound("Oxygen Depleted");
                    }
                    if (timer == 30)
                    {
                        SoundCache.PlaySound("Oxygen Reserves Are Low");
                    }
                    if (timer == 45)
                    {
                        SoundCache.PlaySound("Hurry Up Pilot");
                    }
                    lastTimerUpdate = gameTime.TotalGameTime.TotalMilliseconds;
                }


                break;
            }


            //physics
            angle = (float)Math.Atan((y2 - y1) / 820);

            if (!inhole)
            {
                //max angle
                if (angle > 0.15f)
                {
                    angle = 0.15f;
                }
                if (angle < -0.15f)
                {
                    angle = -0.15f;
                }

                //max left and right
                maxx  = (float)Math.Sqrt(Math.Pow(820.0f, 2) - Math.Pow(y1 - y2, 2));
                maxx /= 2;
                maxx -= 140;

                //acceleration
                dx += (float)Math.Sin(angle) / 200.0f;

                //drag
                if (dx > 0)
                {
                    dx -= 0.00001f;
                    if (dx < 0)
                    {
                        dx = 0;
                    }
                }
                if (dx < 0)
                {
                    dx += 0.00001f;
                    if (dx > 0)
                    {
                        dx = 0;
                    }
                }

                x += dx * (float)gameTime.ElapsedGameTime.TotalMilliseconds;

                //bounce
                if (x > 410 + maxx)
                {
                    x  = 410 + maxx;
                    dx = -dx / 5.0f;
                    if (Math.Abs(dx) < 0.01f)
                    {
                        dx = 0;
                    }
                }
                if (x < 410 - maxx)
                {
                    x  = 410 - maxx;
                    dx = -dx / 5.0f;
                    if (Math.Abs(dx) < 0.01f)
                    {
                        dx = 0;
                    }
                }


                float     by       = 2 + (y1) + ((y2 - y1) * (x / 820.0f));
                Rectangle ballrect = new Rectangle((int)x - 5, (int)by - 3, 10, 6);

                foreach (Hole h in holes)
                {
                    Rectangle holerect = new Rectangle(h.x - 5, h.y - 8, 10, 10);
                    if (!h.small)
                    {
                        holerect = new Rectangle(h.x - 8, h.y - 10, 16, 16);
                    }
                    if (ballrect.Intersects(holerect))
                    {
                        if (x > h.x)
                        {
                            dx -= 0.0002f;
                        }
                        if (x < h.x)
                        {
                            dx += 0.0002f;
                        }
                    }
                }

                ballrect = new Rectangle((int)x - 1, (int)by - 3, 2, 6);

                foreach (Hole h in holes)
                {
                    Rectangle holerect = new Rectangle(h.x - 1, h.y - 8, 2, 10);
                    if (!h.small)
                    {
                        holerect = new Rectangle(h.x - 4, h.y - 10, 8, 16);
                    }
                    if (ballrect.Intersects(holerect) && !inhole)
                    {
                        inhole = true;
                        dx     = 0;
                        fallx  = x;
                        fally  = 2 + (y1) + ((y2 - y1) * (x / 820.0f));
                        if (h.isBlack || h.nr != activeHole)
                        {
                            SoundCache.PlaySound("Come Back To Me");
                            PlayerDie();
                            Reset();
                        }
                        else
                        {
                            SoundCache.PlaySound("Entering Wormhole");
                            PlayerNextHole();
                            Reset();
                        }
                    }
                }
            }
            else
            {
                anim += 0.2f;
            }
        }
Ejemplo n.º 11
0
        public override void Activate(bool instancePreserved)
        {
            base.Activate(instancePreserved);
            if (!instancePreserved)
            {
                if (content == null)
                {
                    content = new ContentManager(ScreenManager.Game.Services, "Content");
                }
            }

            spriteBatch = ScreenManager.SpriteBatch;

            digital         = content.Load <SpriteFont>("digital");
            digital.Spacing = -12;
            part            = content.Load <Texture2D>("part2");
            ball            = content.Load <Texture2D>("ball");
            light           = content.Load <Texture2D>("light");
            background      = content.Load <Texture2D>("background");
            overlay         = content.Load <Texture2D>("overlay");
            music           = content.Load <SoundEffect>("Music/Main");
            alarm           = content.Load <SoundEffect>("Music/Alarm30seccut");

            loopmusic          = music.CreateInstance();
            loopmusic.IsLooped = true;
            loopmusic.Volume   = 0.9f;
            mainLoop           = new SoundFader(ScreenManager.Game, loopmusic);

            loopalarm        = alarm.CreateInstance();
            loopalarm.Volume = 0.75f;

            attractsong = content.Load <Song>("Music/Attract Mode");
            //MediaPlayer.IsVisualizationEnabled = true;
            MediaPlayer.Play(attractsong);
            MediaPlayer.IsRepeating = true;


            SoundCache.LoadSound(content, "Oxygen Depleted");
            SoundCache.LoadSound(content, "Oxygen Reserves Are Low");
            SoundCache.LoadSound(content, "Pilot Are You Ready");
            SoundCache.LoadSound(content, "Come Back To Me");
            SoundCache.LoadSound(content, "Entering Wormhole");
            SoundCache.LoadSound(content, "Goodbye Pilot");
            SoundCache.LoadSound(content, "Welcome To Space Base");
            SoundCache.LoadSound(content, "Hurry Up Pilot");


            reflect = content.Load <Effect>("Effects/Reflect");

            #region holes
            holes.Add(new Hole(411, 784, false, 1));
            holes.Add(new Hole(594, 760, false, 2));
            holes.Add(new Hole(227, 709, false, 3));
            holes.Add(new Hole(504, 653, false, 4));
            holes.Add(new Hole(336, 560, false, 5));
            holes.Add(new Hole(582, 468, false, 6));
            holes.Add(new Hole(424, 420, false, 7));
            holes.Add(new Hole(253, 370, false, 8));
            holes.Add(new Hole(512, 302, false, 9));
            holes.Add(new Hole(358, 260, false, 10));

            holes.Add(new Hole(485, 766));
            holes.Add(new Hole(280, 758));
            holes.Add(new Hole(204, 777));
            holes.Add(new Hole(653, 761));
            holes.Add(new Hole(361, 640));
            holes.Add(new Hole(321, 610));
            holes.Add(new Hole(391, 608));
            holes.Add(new Hole(495, 712));
            holes.Add(new Hole(547, 732));
            holes.Add(new Hole(614, 714));
            holes.Add(new Hole(614, 830));
            holes.Add(new Hole(412, 733));
            holes.Add(new Hole(271, 679));
            holes.Add(new Hole(166, 727));
            holes.Add(new Hole(194, 562));
            holes.Add(new Hole(288, 578));
            holes.Add(new Hole(438, 562));
            holes.Add(new Hole(471, 587));
            holes.Add(new Hole(516, 590));
            holes.Add(new Hole(583, 540));
            holes.Add(new Hole(545, 505));
            holes.Add(new Hole(642, 510));
            holes.Add(new Hole(655, 468));
            holes.Add(new Hole(618, 433));
            holes.Add(new Hole(507, 469));
            holes.Add(new Hole(423, 495));
            holes.Add(new Hole(336, 485));
            holes.Add(new Hole(294, 520));
            holes.Add(new Hole(171, 521));
            holes.Add(new Hole(348, 422));
            holes.Add(new Hole(298, 414));
            holes.Add(new Hole(254, 431));
            holes.Add(new Hole(209, 415));
            holes.Add(new Hole(192, 371));
            holes.Add(new Hole(211, 331));
            holes.Add(new Hole(254, 317));
            holes.Add(new Hole(314, 370));
            holes.Add(new Hole(424, 350));
            holes.Add(new Hole(512, 361));
            holes.Add(new Hole(582, 395));
            holes.Add(new Hole(544, 334));
            holes.Add(new Hole(574, 303));
            holes.Add(new Hole(544, 273));
            holes.Add(new Hole(513, 245));
            holes.Add(new Hole(480, 273));
            holes.Add(new Hole(451, 303));
            holes.Add(new Hole(296, 261));
            holes.Add(new Hole(359, 322));
            holes.Add(new Hole(422, 261));

            holes.Add(new Hole(345, 754, true, 0, false));
            holes.Add(new Hole(416, 664, true, 0, false));
            holes.Add(new Hole(555, 652, true, 0, false));
            holes.Add(new Hole(675, 664, true, 0, false));
            holes.Add(new Hole(674, 718, true, 0, false));
            holes.Add(new Hole(146, 666, true, 0, false));
            holes.Add(new Hole(233, 621, true, 0, false));
            holes.Add(new Hole(619, 585, true, 0, false));
            holes.Add(new Hole(241, 539, true, 0, false));
            holes.Add(new Hole(145, 476, true, 0, false));
            holes.Add(new Hole(152, 387, true, 0, false));
            holes.Add(new Hole(386, 456, true, 0, false));
            holes.Add(new Hole(387, 384, true, 0, false));
            holes.Add(new Hole(461, 385, true, 0, false));
            holes.Add(new Hole(461, 456, true, 0, false));
            holes.Add(new Hole(507, 421, true, 0, false));
            holes.Add(new Hole(222, 273, true, 0, false));
            holes.Add(new Hole(326, 229, true, 0, false));
            holes.Add(new Hole(326, 289, true, 0, false));
            holes.Add(new Hole(390, 231, true, 0, false));
            holes.Add(new Hole(390, 289, true, 0, false));
            holes.Add(new Hole(652, 291, true, 0, false));
            holes.Add(new Hole(675, 428, true, 0, false));
            #endregion

#if DEBUG
            lines = new LineBatchComponent(ScreenManager.Game);
            lines.Initialize();
#endif

            for (int i = 0; i < 10; i++)
            {
                Hole  h2 = holes.Find(h => h.nr == i + 1);
                Light l  = new Light(ScreenManager.Game, new Vector2(h2.x, h2.y), Color.LightYellow);
                l.Initialize();
                lights.Add(l);
            }

            msg = "     SPACE BASE     PRESS " + GameSettings.getKey("Settings.Start").ToString() + " TO START     ";

#if DEBUG
            sw = new StreamWriter("holes.txt", true);
#endif
        }
Ejemplo n.º 12
0
 private void EndGame()
 {
     state = LevelState.ENDING;
     mainLoop.FadeOut();
     SoundCache.PlaySound("Goodbye Pilot");
 }
Ejemplo n.º 13
0
 public virtual void Update()
 {
     if (_waitingForOutAnimation)
     {
         if (_outAnimation == null || !_outAnimation.IsPlaying)
         {
             _waitingForOutAnimation = false;
             OnOutAnimationFinished();
             return;
         }
     }
     else
     {
         if (Engine.Input.WasPressed(Keys.Escape) && Parent != null)
         {
             if (SoundCache.IsInitialized)
             {
                 SoundCache.Play(SoundIds.UI_Esc, null, false);
             }
             ReturnToParent();
         }
         if (Engine.Input.WasPressed(Keys.Down))
         {
             if (_selectedOption < _options.Count - 1)
             {
                 _selectedOption++;
             }
             else
             {
                 _selectedOption = 0;
             }
             if (SoundCache.IsInitialized)
             {
                 SoundCache.Play(SoundIds.UI_UpDown, null, false);
             }
         }
         else if (Engine.Input.WasPressed(Keys.Up))
         {
             if (_selectedOption > 0)
             {
                 _selectedOption--;
             }
             else
             {
                 _selectedOption = _options.Count - 1;
             }
             if (SoundCache.IsInitialized)
             {
                 SoundCache.Play(SoundIds.UI_UpDown, null, false);
             }
         }
         else if (Engine.Input.WasPressed(Keys.Enter))
         {
             if (_options.Count == 0 || _options[_selectedOption].CanBeSelected)
             {
                 if (SoundCache.IsInitialized)
                 {
                     SoundCache.Play(SoundIds.UI_Ok, null, false);
                 }
                 PlayOutAnimation();
             }
         }
     }
     if (_inAnimation != null)
     {
         _inAnimation.Update();
     }
     if (_outAnimation != null)
     {
         _outAnimation.Update();
     }
 }
Ejemplo n.º 14
0
        public static Boolean loadPaceNotes(GameEnum gameEnum, String trackName, CarData.CarClassEnum carClass)
        {
            if (!isRecordingPaceNotes && !isPlayingPaceNotes)
            {
                Console.WriteLine("Playing pace notes for circuit " + trackName + " with car class " + carClass.ToString());

                isRecordingPaceNotes = false;
                isRecordingSound     = false;
                if (carClass != CarData.CarClassEnum.USER_CREATED && carClass != CarData.CarClassEnum.UNKNOWN_RACE)
                {
                    DriverTrainingService.folderPathForPaceNotes = getCarSpecificFolderPath(gameEnum, trackName, carClass);
                    if (!Directory.Exists(DriverTrainingService.folderPathForPaceNotes))
                    {
                        Console.WriteLine("No pace notes folder exists for car class " + carClass + ", game " + gameEnum + ", track " + trackName +
                                          ". Checking for pace notes folder applicable to any car");
                        DriverTrainingService.folderPathForPaceNotes = getAnyCarFolderPath(gameEnum, trackName);
                        if (!Directory.Exists(DriverTrainingService.folderPathForPaceNotes))
                        {
                            Console.WriteLine("Unable to find any pace notes set for game " + gameEnum + ", track " + trackName);
                            return(false);
                        }
                    }
                }
                else
                {
                    DriverTrainingService.folderPathForPaceNotes = getAnyCarFolderPath(gameEnum, trackName);
                    if (!Directory.Exists(DriverTrainingService.folderPathForPaceNotes))
                    {
                        Console.WriteLine("Unable to find any pace notes set for game " + gameEnum + ", track " + trackName);
                        return(false);
                    }
                }

                String fileName = System.IO.Path.Combine(folderPathForPaceNotes, "metadata.json");
                if (File.Exists(fileName))
                {
                    try
                    {
                        DriverTrainingService.recordingMetaData = JsonConvert.DeserializeObject <MetaData>(File.ReadAllText(fileName));
                        if (DriverTrainingService.recordingMetaData.description != null && !DriverTrainingService.recordingMetaData.description.Equals(""))
                        {
                            Console.WriteLine("Playing pace notes with description " + DriverTrainingService.recordingMetaData.description);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Unable to parse pace notes metadata file: " + e.Message);
                        return(false);
                    }
                    foreach (MetaDataEntry entry in DriverTrainingService.recordingMetaData.entries)
                    {
                        for (int i = 0; i < entry.recordingNames.Count; i++)
                        {
                            try
                            {
                                SoundCache.loadSingleSound(entry.recordingNames[i], System.IO.Path.Combine(DriverTrainingService.folderPathForPaceNotes, entry.fileNames[i]));
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("Unable to load a sound from pace notes set " + DriverTrainingService.folderPathForPaceNotes + " : " + e.Message);
                                return(false);
                            }
                        }
                    }
                    isPlayingPaceNotes = true;
                }
                else
                {
                    Console.WriteLine("No metadata.json file exists in the pace notes folder " + DriverTrainingService.folderPathForPaceNotes);
                }
                return(true);
            }
            else
            {
                if (isRecordingPaceNotes)
                {
                    Console.WriteLine("A recording is already in progress, complete this first");
                }
                else
                {
                    Console.WriteLine("Already playing a session");
                }
                return(false);
            }
        }
Ejemplo n.º 15
0
        public int PrecacheSound(string name)
        {
            var(added, resource) = SoundCache.TryAdd(name, PrecachingAllowed, () => EngineFuncs.pfnPrecacheSound(StringPool.GetPooledString(name)));

            return(resource?.Index ?? 0);
        }
Ejemplo n.º 16
0
        public async override Task <bool> PackAndInstallProject()
        {
            var ActiveMod = MainController.Get().ActiveMod;
            var _logger   = ServiceLocator.Default.ResolveType <ILoggerService>();

            if (ActiveMod == null)
            {
                return(false);
            }
            if (Process.GetProcessesByName("Witcher3").Length != 0)
            {
                _logger.LogString("Please close The Witcher 3 before tinkering with the files!", Logtype.Error);
                return(false);
            }

            var packsettings = new WolvenKit.Common.Model.WitcherPackSettings();

            if (packsettings != null)
            {
                MainController.Get().ProjectStatus  = EProjectStatus.Busy;
                MainController.Get().StatusProgress = 0;

                //IsToolStripBtnPackEnabled = false;

                //SaveAllFiles();

                //Create the dirs. So script only mods don't die.
                Directory.CreateDirectory(ActiveMod.PackedModDirectory);
                if (!string.IsNullOrEmpty(ActiveMod.GetDlcName()))
                {
                    Directory.CreateDirectory(ActiveMod.PackedDlcDirectory);
                }


                //------------------------PRE COOKING------------------------------------//
                // have a check if somehow users forget to add a dlc folder in their dlc :(
                // but have files inform them that it just not gonna work
                bool initialDlcCheck = true;
                if (ActiveMod.DLCFiles.Any() && string.IsNullOrEmpty(ActiveMod.GetDlcName()))
                {
                    _logger.LogString("Files in your dlc directory need to have the following structure: dlc\\DLCNAME\\files. Dlc will not be packed.", Logtype.Error);
                    initialDlcCheck = false;
                }

                #region Pre Cooking
                //Handle strings.
                //if (packsettings.Strings.Item1 || packsettings.Strings.Item2)
                {
                    //m_windowFactory.RequestStringsGUI(); TODO
                }

                // Cleanup Directories
                WccHelper.CleanupDirectories();

                // Create Virtial Links
                WccHelper.CreateVirtualLinks();

                // analyze files in dlc
                int statusanalyzedlc = -1;

                var seedfile = Path.Combine(ActiveMod.ProjectDirectory, @"cooked", $"seed_dlc{ActiveMod.Name}.files");

                if (initialDlcCheck)
                {
                    if (Directory.GetFiles(ActiveMod.DlcDirectory, "*", SearchOption.AllDirectories).Any())
                    {
                        _logger.LogString($"======== Analyzing dlc files ======== \n", Logtype.Important);
                        if (Directory.GetFiles(ActiveMod.DlcDirectory, "*.reddlc", SearchOption.AllDirectories).Any())
                        {
                            var reddlcfile = Directory.GetFiles(ActiveMod.DlcDirectory, "*.reddlc", SearchOption.AllDirectories).FirstOrDefault();
                            var analyze    = new Wcc_lite.analyze()
                            {
                                Analyzer = analyzers.r4dlc,
                                Out      = seedfile,
                                reddlc   = reddlcfile
                            };
                            statusanalyzedlc *= await Task.Run(() => MainController.Get().WccHelper.RunCommand(analyze));

                            if (statusanalyzedlc == 0)
                            {
                                _logger.LogString("Analyzing dlc failed, creating fallback seedfiles. \n", Logtype.Error);
                                WccHelper.CreateFallBackSeedFile(seedfile);
                            }
                        }
                        else
                        {
                            _logger.LogString("No reddlc found, creating fallback seedfiles. \n", Logtype.Error);
                            WccHelper.CreateFallBackSeedFile(seedfile);
                        }
                    }
                }
                #endregion
                MainController.Get().StatusProgress = 5;

                //------------------------- COOKING -------------------------------------//
                #region Cooking
                int statusCook = -1;

                // cook uncooked files
                var taskCookCol = Task.Run(() => WccHelper.Cook());
                await taskCookCol.ContinueWith(antecedent =>
                {
                    //Logger.LogString($"Cooking Collision ended with status: {antecedent.Result}", Logtype.Important);
                    statusCook = antecedent.Result;
                });

                if (statusCook == 0)
                {
                    _logger.LogString("Cooking collision finished with errors. \n", Logtype.Error);
                }

                #endregion
                MainController.Get().StatusProgress = 15;

                //------------------------- POST COOKING --------------------------------//
                #region Copy Cooked Files
                // copy mod files from Archive (cooked files) to \cooked
                if (Directory.GetFiles(ActiveMod.ModCookedDirectory, "*", SearchOption.AllDirectories).Any())
                {
                    _logger.LogString($"======== Adding cooked mod files ======== \n", Logtype.Important);
                    try
                    {
                        var di    = new DirectoryInfo(ActiveMod.ModCookedDirectory);
                        var files = di.GetFiles("*", SearchOption.AllDirectories);
                        _logger.LogString($"Found {files.Length} files in {di.FullName}. \n");
                        foreach (var fi in files)
                        {
                            string relpath = fi.FullName.Substring(ActiveMod.ModCookedDirectory.Length + 1);
                            string newpath = Path.Combine(ActiveMod.CookedModDirectory, relpath);

                            if (File.Exists(newpath))
                            {
                                _logger.LogString($"Duplicate cooked file found {newpath}. Overwriting. \n", Logtype.Important);
                                File.Delete(newpath);
                            }

                            fi.CopyToAndCreate(newpath);
                            _logger.LogString($"Copied file to cooked directory: {fi.FullName}. \n", Logtype.Normal);
                        }
                    }
                    catch (Exception)
                    {
                        _logger.LogString("Copying cooked mod files finished with errors. \n", Logtype.Error);
                    }
                    finally
                    {
                        _logger.LogString("Finished succesfully. \n", Logtype.Success);
                    }
                }

                // copy dlc files from Archive (cooked files) to \cooked
                if (Directory.GetFiles(ActiveMod.DlcCookedDirectory, "*", SearchOption.AllDirectories).Any())
                {
                    _logger.LogString($"======== Adding cooked dlc files ======== \n", Logtype.Important);
                    try
                    {
                        var di    = new DirectoryInfo(ActiveMod.DlcCookedDirectory);
                        var files = di.GetFiles("*", SearchOption.AllDirectories);
                        _logger.LogString($"Found {files.Length} files in {di.FullName}. \n");
                        foreach (var fi in files)
                        {
                            string relpath = fi.FullName.Substring(ActiveMod.DlcCookedDirectory.Length + 1);
                            string newpath = Path.Combine(ActiveMod.CookedDlcDirectory, relpath);

                            if (File.Exists(newpath))
                            {
                                _logger.LogString($"Duplicate cooked file found {newpath}. Overwriting. \n", Logtype.Important);
                                File.Delete(newpath);
                            }

                            fi.CopyToAndCreate(newpath);
                            _logger.LogString($"Copied file to cooked directory: {fi.FullName}. \n", Logtype.Normal);
                        }
                    }
                    catch (Exception)
                    {
                        _logger.LogString("Copying cooked dlc files finished with errors. \n", Logtype.Error);
                    }
                    finally
                    {
                        _logger.LogString("Finished succesfully. \n", Logtype.Success);
                    }
                }
                #endregion
                MainController.Get().StatusProgress = 20;

                //------------------------- PACKING -------------------------------------//
                #region Packing
                int statusPack = -1;

                //Handle bundle packing.
                if (packsettings.dlcPackBundles || packsettings.modPackBundles)
                {
                    // packing
                    //if (statusCookCol * statusCookTex != 0)
                    {
                        var t = WccHelper.Pack(packsettings.modPackBundles, packsettings.dlcPackBundles);
                        await t.ContinueWith(antecedent =>
                        {
                            //Logger.LogString($"Packing Bundles ended with status: {antecedent.Result}", Logtype.Important);
                            statusPack = (int)antecedent.Status;
                        });

                        if (statusPack == 0)
                        {
                            _logger.LogString("Packing bundles finished with errors. \n", Logtype.Error);
                        }
                    }
                    //else
                    //    Logger.LogString("Cooking assets failed. No bundles will be packed!\n", Logtype.Error);
                }
                #endregion
                MainController.Get().StatusProgress = 40;

                //------------------------ METADATA -------------------------------------//
                #region Metadata
                //Handle metadata generation.
                int statusMetaData = -1;

                if (packsettings.modGenMetadata || packsettings.dlcGenMetadata)
                {
                    if (statusPack == 1)
                    {
                        var t = WccHelper.CreateMetaData(packsettings.modGenMetadata,
                                                         packsettings.dlcGenMetadata);
                        await t.ContinueWith(antecedent =>
                        {
                            statusMetaData = antecedent.Result;
                            //Logger.LogString($"Creating metadata ended with status: {statusMetaData}", Logtype.Important);
                        });

                        if (statusMetaData == 0)
                        {
                            _logger.LogString("Creating metadata finished with errors. \n", Logtype.Error);
                        }
                    }
                    else
                    {
                        _logger.LogString("Packing bundles failed. No metadata will be created!\n", Logtype.Error);
                    }
                }
                #endregion
                MainController.Get().StatusProgress = 50;

                //------------------------ POST COOKING ---------------------------------//

                //---------------------------- CACHES -----------------------------------//
                #region Buildcache
                int statusCol = -1;
                int statusTex = -1;

                //Generate collision cache
                if (packsettings.modGenCollCache || packsettings.dlcGenCollCache)
                {
                    var t = WccHelper.GenerateCache(EArchiveType.CollisionCache, packsettings.modGenCollCache,
                                                    packsettings.dlcGenCollCache);
                    await t.ContinueWith(antecedent =>
                    {
                        statusCol = antecedent.Result;
                        //Logger.LogString($"Building collision cache ended with status: {statusCol}", Logtype.Important);
                    });

                    if (statusCol == 0)
                    {
                        _logger.LogString("Building collision cache finished with errors. \n", Logtype.Error);
                    }
                }

                //Handle texture caching
                if (packsettings.modGenTexCache || packsettings.dlcGenTexCache)
                {
                    var t = WccHelper.GenerateCache(EArchiveType.TextureCache, packsettings.modGenTexCache, packsettings.dlcGenTexCache);
                    await t.ContinueWith(antecedent =>
                    {
                        statusTex = antecedent.Result;
                        //Logger.LogString($"Building texture cache ended with status: {statusTex}", Logtype.Important);
                    });

                    if (statusTex == 0)
                    {
                        _logger.LogString("Building texture cache finished with errors. \n", Logtype.Error);
                    }
                }


                //Handle sound caching
                if (packsettings.modSound || packsettings.dlcSound)
                {
                    if (packsettings.modSound)
                    {
                        var soundmoddir = Path.Combine(ActiveMod.ModDirectory, EArchiveType.SoundCache.ToString());

                        // We need to have the original soundcache's so we can rebuild them when packing the mod
                        foreach (var wem in Directory.GetFiles(soundmoddir, "*.wem", SearchOption.AllDirectories))
                        {
                            // Get the file id so we can search for the parent soundcache
                            var id = Path.GetFileNameWithoutExtension(SoundCache.GetIDFromPath(wem));

                            // Find the parent bank
                            foreach (var bnk in SoundCache.info.Banks)
                            {
                                if (bnk.IncludedFullFiles.Any(x => x.Id == id) || bnk.IncludedPrefetchFiles.Any(x => x.Id == id))
                                {
                                    if (!File.Exists(Path.Combine(soundmoddir, bnk.Path)))
                                    {
                                        //TODO: Fix this somehow
                                        //var bytes = MainController.ImportFile(bnk.Path, MainController.Get().SoundManager);
                                        //File.WriteAllBytes(Path.Combine(soundmoddir, bnk.Path), bytes[0].ToArray());
                                        MainController.Get().Logger.LogString("Imported " + bnk.Path + " for rebuilding with the modded wem files!");
                                    }
                                    break;
                                }
                            }
                        }

                        foreach (var bnk in Directory.GetFiles(soundmoddir, "*.bnk", SearchOption.AllDirectories))
                        {
                            Soundbank bank = new Soundbank(bnk);
                            bank.readFile();
                            bank.read_wems(soundmoddir);
                            bank.rebuild_data();
                            File.Delete(bnk);
                            bank.build_bnk(bnk);
                            _logger.LogString("Rebuilt modded bnk " + bnk, Logtype.Success);
                        }

                        //Create mod soundspc.cache
                        if (Directory.Exists(soundmoddir) &&
                            new DirectoryInfo(soundmoddir)
                            .GetFiles("*.*", SearchOption.AllDirectories)
                            .Where(file => file.Name.ToLower().EndsWith("wem") || file.Name.ToLower().EndsWith("bnk")).Any())
                        {
                            SoundCache.Write(
                                new DirectoryInfo(soundmoddir)
                                .GetFiles("*.*", SearchOption.AllDirectories)
                                .Where(file => file.Name.ToLower().EndsWith("wem") || file.Name.ToLower().EndsWith("bnk"))
                                .ToList().Select(x => x.FullName).ToList(),
                                Path.Combine(ActiveMod.PackedModDirectory, @"soundspc.cache"));
                            _logger.LogString("Mod soundcache generated!\n", Logtype.Important);
                        }
                        else
                        {
                            _logger.LogString("Mod soundcache wasn't generated!\n", Logtype.Important);
                        }
                    }

                    if (packsettings.dlcSound)
                    {
                        var sounddlcdir = Path.Combine(ActiveMod.DlcDirectory, EArchiveType.SoundCache.ToString());

                        //Create dlc soundspc.cache
                        if (Directory.Exists(sounddlcdir) && new DirectoryInfo(sounddlcdir)
                            .GetFiles("*.*", SearchOption.AllDirectories).Any(file => file.Name.ToLower().EndsWith("wem") || file.Name.ToLower().EndsWith("bnk")))
                        {
                            SoundCache.Write(
                                new DirectoryInfo(sounddlcdir)
                                .GetFiles("*.*", SearchOption.AllDirectories)
                                .Where(file => file.Name.ToLower().EndsWith("wem") || file.Name.ToLower().EndsWith("bnk")).ToList().Select(x => x.FullName).ToList(),
                                Path.Combine(ActiveMod.PackedDlcDirectory, @"soundspc.cache"));
                            _logger.LogString("DLC soundcache generated!\n", Logtype.Important);
                        }
                        else
                        {
                            _logger.LogString("DLC soundcache wasn't generated!\n", Logtype.Important);
                        }
                    }
                }
                #endregion
                MainController.Get().StatusProgress = 60;

                //---------------------------- SCRIPTS ----------------------------------//
                #region Scripts
                bool packscriptsMod = packsettings.modScripts;
                bool packscriptsdlc = packsettings.dlcScripts;
                //Handle mod scripts
                if (packscriptsMod && Directory.Exists(Path.Combine(ActiveMod.ModDirectory, "scripts")) && Directory.GetFiles(Path.Combine(ActiveMod.ModDirectory, "scripts"), "*.*", SearchOption.AllDirectories).Any())
                {
                    if (!Directory.Exists(Path.Combine(ActiveMod.ModDirectory, "scripts")))
                    {
                        Directory.CreateDirectory(Path.Combine(ActiveMod.ModDirectory, "scripts"));
                    }
                    //Now Create all of the directories
                    foreach (string dirPath in Directory.GetDirectories(Path.Combine(ActiveMod.ModDirectory, "scripts"), "*.*",
                                                                        SearchOption.AllDirectories))
                    {
                        Directory.CreateDirectory(dirPath.Replace(Path.Combine(ActiveMod.ModDirectory, "scripts"), Path.Combine(ActiveMod.PackedModDirectory, "scripts")));
                    }

                    //Copy all the files & Replaces any files with the same name
                    foreach (string newPath in Directory.GetFiles(Path.Combine(ActiveMod.ModDirectory, "scripts"), "*.*",
                                                                  SearchOption.AllDirectories))
                    {
                        File.Copy(newPath, newPath.Replace(Path.Combine(ActiveMod.ModDirectory, "scripts"), Path.Combine(ActiveMod.PackedModDirectory, "scripts")), true);
                    }
                }

                //Handle the DLC scripts
                if (packscriptsdlc && Directory.Exists(Path.Combine(ActiveMod.DlcDirectory, "scripts")) && Directory.GetFiles(Path.Combine(ActiveMod.DlcDirectory, "scripts"), "*.*", SearchOption.AllDirectories).Any())
                {
                    if (!Directory.Exists(Path.Combine(ActiveMod.DlcDirectory, "scripts")))
                    {
                        Directory.CreateDirectory(Path.Combine(ActiveMod.DlcDirectory, "scripts"));
                    }
                    //Now Create all of the directories
                    foreach (string dirPath in Directory.GetDirectories(Path.Combine(ActiveMod.DlcDirectory, "scripts"), "*.*",
                                                                        SearchOption.AllDirectories))
                    {
                        Directory.CreateDirectory(dirPath.Replace(Path.Combine(ActiveMod.DlcDirectory, "scripts"), Path.Combine(ActiveMod.PackedDlcDirectory, "scripts")));
                    }

                    //Copy all the files & Replaces any files with the same name
                    foreach (string newPath in Directory.GetFiles(Path.Combine(ActiveMod.DlcDirectory, "scripts"), "*.*",
                                                                  SearchOption.AllDirectories))
                    {
                        File.Copy(newPath, newPath.Replace(Path.Combine(ActiveMod.DlcDirectory, "scripts"), Path.Combine(ActiveMod.PackedDlcDirectory, "scripts")), true);
                    }
                }
                #endregion
                MainController.Get().StatusProgress = 80;

                //---------------------------- STRINGS ----------------------------------//
                #region Strings
                //Copy the generated w3strings
                if (packsettings.modStrings || packsettings.dlcStrings)
                {
                    var files = Directory.GetFiles((ActiveMod.ProjectDirectory + "\\strings")).Where(s => Path.GetExtension(s) == ".w3strings").ToList();

                    if (packsettings.modStrings)
                    {
                        files.ForEach(x => File.Copy(x, Path.Combine(ActiveMod.PackedDlcDirectory, Path.GetFileName(x))));
                    }
                    if (packsettings.dlcStrings)
                    {
                        files.ForEach(x => File.Copy(x, Path.Combine(ActiveMod.PackedModDirectory, Path.GetFileName(x))));
                    }
                }
                #endregion
                MainController.Get().StatusProgress = 90;

                //---------------------------- FINALIZE ---------------------------------//

                InstallMod();

                //Report that we are done
                MainController.Get().StatusProgress = 100;
                MainController.Get().ProjectStatus  = EProjectStatus.Ready;
                return(true);
            }
            else
            {
                return(false);
            }
        }