Example #1
0
        private void SkillsForm_Load(object sender, EventArgs e)
        {
            Settings.Default.VerifySetoaLocation();

            using (var archive = DataArchive.Open(Settings.Default.SetoaLocation))
                using (var g = Graphics.FromImage(_skillTilesImage))
                {
                    var epf = new EPFFile(archive.GetEntry(_fileName));
                    var pal = new Palette(archive.GetEntry("gui06.pal"));

                    for (int col = 0; col < columns; ++col)
                    {
                        for (int row = 0; row < rows; ++row)
                        {
                            int frameIndex = columns * row + col;
                            if (frameIndex < epf.Frames.Count)
                            {
                                var frame      = epf.Frames[frameIndex];
                                var frameImage = frame.Render(pal);
                                g.DrawImage(frameImage, col * tileWidth + frame.Left, row * tileHeight + frame.Top);
                            }
                        }
                    }
                }
        }
Example #2
0
        private void PlaySoundAsync(object parameter)
        {
            string fileName = (string)parameter;

            using (var archive = DataArchive.Open(Settings.Default.LegendLocation))
                using (var stream = archive.GetEntry(fileName).Open())
                {
                    stream.Position = 0;
                    using (var reader = new Mp3FileReader(stream))
                        using (var conversionStream = WaveFormatConversionStream.CreatePcmStream(reader))
                            using (var provider = new BlockAlignReductionStream(conversionStream))
                                using (var waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()))
                                {
                                    waveOut.Init(provider);
                                    waveOut.Play();

                                    while (waveOut.PlaybackState == PlaybackState.Playing)
                                    {
                                        Thread.Sleep(100);
                                    }
                                }
                }

            TogglePlayButtonEnabled(true);
        }
Example #3
0
        private void UpdateEffectImage()
        {
            animationTimer.Stop();
            Settings.Default.VerifyRohLocation();
            animationTimer.Start();

            using (var archive = DataArchive.Open(Settings.Default.RohLocation))
            {
                if (_selectedFileName.EndsWith(".epf", StringComparison.CurrentCultureIgnoreCase))
                {
                    var epf = new EPFFile(archive.GetEntry(_selectedFileName));

                    if (_animationFrame >= epf.Frames.Count)
                    {
                        _animationFrame = 0;
                    }

                    var frame = epf.Frames[_animationFrame];

                    int paletteNumber = _paletteTable.GetPaletteNumber(_selectedFileNumber);

                    bool useBlending = false;

                    if (paletteNumber >= 1000)
                    {
                        paletteNumber -= 1000;
                        useBlending    = true;
                    }

                    var palette = new Palette(archive.GetEntry($"eff{paletteNumber:d3}.pal"));

                    _effectImage = new Bitmap(epf.Width, epf.Height);

                    using (var g = Graphics.FromImage(_effectImage))
                    {
                        if (useBlending)
                        {
                            // temporary solution
                            g.Clear(Color.Black);
                        }
                        g.DrawImage(frame.Render(palette), frame.Left, frame.Top);
                    }
                }
                else
                {
                    var efa = new EFAFile(archive.GetEntry(_selectedFileName));

                    if (_animationFrame >= efa.Frames.Count)
                    {
                        _animationFrame = 0;
                    }

                    var frame = efa.Frames[_animationFrame];

                    _effectImage = frame.Render();
                }
            }

            effectPanel.Refresh();
        }
Example #4
0
        /// <summary>
        /// Sets up the <see cref="CurrentDataArchive"/> and <see cref="CurrentWorkingSet"/> to respond to events from the srcML service
        /// </summary>
        protected override void Setup() {
            string storagePath = _srcMLService.CurrentMonitor.MonitorStoragePath;
            SrcMLArchive sourceArchive = _srcMLService.CurrentSrcMLArchive;

            CurrentDataArchive = new DataArchive(storagePath, sourceArchive, GlobalScheduler);
            CurrentDataArchive.Generator.ErrorLog = sourceArchive.Generator.ErrorLog;
            CurrentDataArchive.Generator.IsLoggingErrors = true;

            _srcMonitor = new ArchiveMonitor<SrcMLArchive>(GlobalScheduler, storagePath, sourceArchive, CurrentDataArchive);
            CurrentWorkingSet = _workingSetFactories.Default.CreateWorkingSet(storagePath, CurrentDataArchive, GlobalTaskFactory);
            CurrentWorkingSet.UseAsynchronousMethods = true;
        }
        /// <summary>
        /// Sets up the <see cref="CurrentDataArchive"/> and <see cref="CurrentWorkingSet"/> to respond to events from the srcML service
        /// </summary>
        protected override void Setup()
        {
            string       storagePath   = _srcMLService.CurrentMonitor.MonitorStoragePath;
            SrcMLArchive sourceArchive = _srcMLService.CurrentSrcMLArchive;

            CurrentDataArchive = new DataArchive(storagePath, sourceArchive, GlobalScheduler);
            CurrentDataArchive.Generator.ErrorLog        = sourceArchive.Generator.ErrorLog;
            CurrentDataArchive.Generator.IsLoggingErrors = true;

            _srcMonitor       = new ArchiveMonitor <SrcMLArchive>(GlobalScheduler, storagePath, sourceArchive, CurrentDataArchive);
            CurrentWorkingSet = _workingSetFactories.Default.CreateWorkingSet(storagePath, CurrentDataArchive, GlobalTaskFactory);
            CurrentWorkingSet.UseAsynchronousMethods = true;
        }
Example #6
0
 private void RespondToMonitoringStopped(object sender, EventArgs e)
 {
     try {
         if (null != CurrentWorkingSet)
         {
             IsMonitoring = false;
             CurrentWorkingSet.StopMonitoring();
             _srcMonitor.StopMonitoring();
             CurrentWorkingSet.Dispose();
             _srcMonitor.Dispose();
             CurrentWorkingSet  = null;
             CurrentDataArchive = null;
             _srcMonitor        = null;
         }
     } catch (Exception ex) {
         SrcMLFileLogger.DefaultLogger.Error(SrcMLExceptionFormatter.CreateMessage(ex, "Exception in SrcMLDataService.RespondToMonitoringStopped"));
     }
 }
Example #7
0
        private void UpdateMonsterTileImage()
        {
            Settings.Default.VerifyHadesLocation();

            using (var archive = DataArchive.Open(Settings.Default.HadesLocation))
            {
                var mpf = new MPFFile(archive.GetEntry(_selectedFileName));
                var pal = new Palette(archive.GetEntry($"mns{mpf.PaletteNumber:d3}.pal"));

                int frontStopFrameIndex;

                int stopFrameCount = Math.Max(mpf.StopFrameCount, mpf.StopMotionFrameCount);

                if (mpf.WalkFrameIndex == 0 && mpf.WalkFrameCount > stopFrameCount)
                {
                    frontStopFrameIndex = mpf.WalkFrameCount;
                }
                else
                {
                    frontStopFrameIndex = stopFrameCount;
                }

                if (frontStopFrameIndex >= mpf.Frames.Count)
                {
                    frontStopFrameIndex = 0;
                }

                if (_animationFrame >= mpf.StopFrameCount || (frontStopFrameIndex + _animationFrame) >= mpf.Frames.Count)
                {
                    _animationFrame = 0;
                }

                var frame = mpf.Frames[frontStopFrameIndex + _animationFrame];

                _monsterTileImage = new Bitmap(mpf.Width, mpf.Height);

                using (var g = Graphics.FromImage(_monsterTileImage))
                {
                    g.DrawImage(frame.Render(pal), frame.Left, frame.Top);
                }
            }

            monsterTilePanel.Refresh();
        }
Example #8
0
        private void MonstersForm_Load(object sender, EventArgs e)
        {
            Settings.Default.VerifyHadesLocation();

            using (var archive = DataArchive.Open(Settings.Default.HadesLocation))
            {
                var entries = from entry in archive.Entries
                              where EntryIsMonster(entry)
                              orderby int.Parse(entry.EntryName.Substring(3, 3))
                              select entry.EntryName;

                monsterFilesListBox.Items.AddRange(entries.ToArray());
            }

            if (monsterFilesListBox.Items.Count > 0)
            {
                monsterFilesListBox.SelectedIndex = 0;
            }
        }
Example #9
0
        private void RespondToMonitoringStarted(object sender, EventArgs e)
        {
            CurrentDataArchive = new DataArchive(_srcMLService.CurrentMonitor.MonitorStoragePath, _srcMLService.CurrentSrcMLArchive, Scheduler);
            CurrentDataArchive.Generator.ErrorLog        = _srcMLService.CurrentSrcMLArchive.Generator.ErrorLog;
            CurrentDataArchive.Generator.IsLoggingErrors = true;

            _srcMonitor       = new ArchiveMonitor <SrcMLArchive>(Scheduler, _srcMLService.CurrentMonitor.MonitorStoragePath, _srcMLService.CurrentSrcMLArchive, CurrentDataArchive);
            CurrentWorkingSet = _workingSetFactories.Default.CreateWorkingSet(_srcMLService.CurrentMonitor.MonitorStoragePath, CurrentDataArchive, TaskFactory);

            if (_srcMLService.IsUpdating)
            {
                _srcMLService.UpdateArchivesCompleted += GenerateDataAfterUpdate;
            }
            else
            {
                GenerateDataAfterUpdate(this, e);
            }
            IsMonitoring = true;
        }
Example #10
0
        private void EffectsForm_Load(object sender, EventArgs e)
        {
            Settings.Default.VerifyRohLocation();

            using (var archive = DataArchive.Open(Settings.Default.RohLocation))
            {
                var entries = from entry in archive.Entries
                              where EntryIsEffect(entry)
                              orderby int.Parse(entry.EntryName.Substring(4, 3))
                              select entry.EntryName;

                effectFilesListBox.Items.AddRange(entries.ToArray());
                _paletteTable.AddTable(archive.GetEntry("effpal.tbl"));
            }

            if (effectFilesListBox.Items.Count > 0)
            {
                effectFilesListBox.SelectedIndex = 0;
            }
        }
Example #11
0
        private void SoundsForm_Load(object sender, EventArgs e)
        {
            Settings.Default.VerifyLegendLocation();

            using (var archive = DataArchive.Open(Settings.Default.LegendLocation))
            {
                int soundNumber;
                var entries = from entry in archive.Entries
                              let name                     = Path.GetFileNameWithoutExtension(entry.EntryName)
                                                   let ext = Path.GetExtension(entry.EntryName)
                                                             where ext.Equals(".mp3", StringComparison.CurrentCultureIgnoreCase) && int.TryParse(name, out soundNumber)
                                                             orderby int.Parse(name)
                                                             select entry.EntryName;

                soundFilesListBox.Items.AddRange(entries.ToArray());
            }

            if (soundFilesListBox.Items.Count > 0)
            {
                soundFilesListBox.SelectedIndex = 0;
            }
        }
Example #12
0
        private void UpdateItemTilesImage()
        {
            Settings.Default.VerifyLegendLocation();

            using (var archive = DataArchive.Open(Settings.Default.LegendLocation))
                using (var g = Graphics.FromImage(_itemTilesImage))
                {
                    g.Clear(itemTilesPanel.BackColor);

                    var epf = new EPFFile(archive.GetEntry(_selectedFileName));

                    for (int col = 0; col < columns; ++col)
                    {
                        for (int row = 0; row < rows; ++row)
                        {
                            int frameIndex = columns * row + col;

                            if (frameIndex < epf.Frames.Count)
                            {
                                var frame = epf.Frames[frameIndex];

                                int tileNumber    = (_selectedFileNumber - 1) * 266 + frameIndex + 1;
                                int paletteNumber = _paletteTable.GetPaletteNumber(tileNumber);

                                var palette = new Palette(archive.GetEntry($"item{paletteNumber:d3}.pal"));

                                var frameImage = frame.Render(palette);

                                g.DrawImage(frameImage, col * tileWidth + frame.Left, row * tileHeight + frame.Top);
                            }
                        }
                    }
                }

            itemTilesPanel.Refresh();
        }
Example #13
0
        private void UpdateMotionTilesImage()
        {
            string archiveFileName, idleFileName, motionFileName;

            if (genderListBox.SelectedIndex == 0)
            {
                animationTimer.Stop();
                Settings.Default.VerifyKhanmadLocation();
                animationTimer.Start();
                archiveFileName = Settings.Default.KhanmadLocation;

                idleFileName = "mb00101.epf";

                if (_selectedMotion.Number == 1)
                {
                    motionFileName = "mb00102.epf";
                }
                else if (_selectedMotion.Number == 6)
                {
                    motionFileName = "mb00103.epf";
                }
                else
                {
                    motionFileName = $"mb001{(char)('a' + _selectedMotion.FileNumber)}.epf";
                }
            }
            else
            {
                animationTimer.Stop();
                Settings.Default.VerifyKhanwadLocation();
                animationTimer.Start();
                archiveFileName = Settings.Default.KhanwadLocation;

                idleFileName = "wb00101.epf";

                if (_selectedMotion.Number == 1)
                {
                    motionFileName = "wb00102.epf";
                }
                else if (_selectedMotion.Number == 6)
                {
                    motionFileName = "wb00103.epf";
                }
                else
                {
                    motionFileName = $"wb001{(char)('a' + _selectedMotion.FileNumber)}.epf";
                }
            }

            animationTimer.Stop();
            Settings.Default.VerifyKhanpalLocation();
            animationTimer.Start();

            using (var epfArchive = DataArchive.Open(archiveFileName))
                using (var palArchive = DataArchive.Open(Settings.Default.KhanpalLocation))
                {
                    var idleEpf   = new EPFFile(epfArchive.GetEntry(idleFileName));
                    var motionEpf = new EPFFile(epfArchive.GetEntry(motionFileName));
                    var pal       = new Palette(palArchive.GetEntry("palb000.pal"));

                    EPFFrame frame;

                    if (_animationFrame >= _selectedMotion.FrameCount)
                    {
                        _animationFrame = -1;
                    }

                    if (_animationFrame == -1)
                    {
                        frame = idleEpf.Frames[5];
                    }
                    else
                    {
                        frame = motionEpf.Frames[_selectedMotion.StartIndex + _selectedMotion.FrameCount + _animationFrame];
                    }

                    using (var g = Graphics.FromImage(_motionTilesImage))
                    {
                        g.Clear(motionTilesPanel.BackColor);
                        g.DrawImage(frame.Render(pal), frame.Left, frame.Top);
                    }
                }

            motionTilesPanel.Refresh();
        }
 /// <summary>
 /// Creates a new complete working set object
 /// </summary>
 /// <param name="archive">The data archive to monitor</param>
 /// <param name="factory">The task factory for asynchronous methods</param>
 public CompleteWorkingSet(DataArchive archive, TaskFactory factory) : base(archive, factory) { }
Example #15
0
        private void RespondToMonitoringStarted(object sender, EventArgs e) {
            CurrentDataArchive = new DataArchive(_srcMLService.CurrentMonitor.MonitorStoragePath, _srcMLService.CurrentSrcMLArchive, Scheduler);
            CurrentDataArchive.Generator.ErrorLog = _srcMLService.CurrentSrcMLArchive.Generator.ErrorLog;
            CurrentDataArchive.Generator.IsLoggingErrors = true;

            _srcMonitor = new ArchiveMonitor<SrcMLArchive>(Scheduler, _srcMLService.CurrentMonitor.MonitorStoragePath, _srcMLService.CurrentSrcMLArchive, CurrentDataArchive);
            CurrentWorkingSet = _workingSetFactories.Default.CreateWorkingSet(_srcMLService.CurrentMonitor.MonitorStoragePath, CurrentDataArchive, TaskFactory);
            
            if(_srcMLService.IsUpdating) {
                _srcMLService.UpdateArchivesCompleted += GenerateDataAfterUpdate;
            } else {
                GenerateDataAfterUpdate(this, e);
            }
            IsMonitoring = true;
        }
Example #16
0
        private void RespondToMonitoringStopped(object sender, EventArgs e) {

            try {
                if(null != CurrentWorkingSet) {
                    IsMonitoring = false;
                    CurrentWorkingSet.StopMonitoring();
                    _srcMonitor.StopMonitoring();
                    CurrentWorkingSet.Dispose();
                    _srcMonitor.Dispose();
                    CurrentWorkingSet = null;
                    CurrentDataArchive = null;
                    _srcMonitor = null;
                }
            } catch(Exception ex) {
                SrcMLFileLogger.DefaultLogger.Error(SrcMLExceptionFormatter.CreateMessage(ex, "Exception in SrcMLDataService.RespondToMonitoringStopped"));
            }
            
        }
Example #17
0
 /// <summary>
 /// Creates a new null working set object
 /// </summary>
 /// <param name="archive">The data archive</param>
 /// <param name="factory">The task factory</param>
 public NullWorkingSet(DataArchive archive, TaskFactory factory) : base(archive, factory) { }
 /// <summary>
 /// Creates a new complete working set object
 /// </summary>
 /// <param name="archive">The data archive to monitor</param>
 public CompleteWorkingSet(DataArchive archive) : this(archive, Task.Factory) { }