1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 21:38:38 +00:00

Generalized GamesViewModel and applied fixes to them, closing #27

This commit is contained in:
SpoinkyNL 2016-03-01 14:10:49 +01:00
parent 6ccfaf45d5
commit 8eb7ed2863
22 changed files with 215 additions and 255 deletions

View File

@ -17,7 +17,7 @@
<!-- Accent and AppTheme setting -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Teal.xaml" />
<ResourceDictionary
Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
<ResourceDictionary Source="/Resources/Icons.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

View File

@ -245,7 +245,8 @@
<Compile Include="Managers\KeyboardManager.cs" />
<Compile Include="Managers\MainManager.cs" />
<Compile Include="Models\EffectModel.cs" />
<Compile Include="Models\GamePointersCollectionModel.cs" />
<Compile Include="Models\EffectSettings.cs" />
<Compile Include="Models\GameSettings.cs" />
<Compile Include="Modules\Effects\AudioVisualizer\AudioVisualization.Designer.cs">
<DependentUpon>AudioVisualization.settings</DependentUpon>
<AutoGen>True</AutoGen>
@ -291,7 +292,6 @@
<Compile Include="Modules\Overlays\VolumeDisplay\VolumeDisplayModel.cs" />
<Compile Include="Modules\Effects\AudioVisualizer\AudioVisualizerSettings.cs" />
<Compile Include="Modules\Effects\Debug\DebugEffectSettings.cs" />
<Compile Include="Models\EffectSettings.cs" />
<Compile Include="Modules\Overlays\VolumeDisplay\VolumeDisplaySettings.cs" />
<Compile Include="Modules\Games\RocketLeague\RocketLeagueSettings.cs" />
<Compile Include="Modules\Effects\TypeWave\TypeWaveSettings.cs" />
@ -321,6 +321,7 @@
<Compile Include="Utilities\GameState\GameStateWebServer.cs" />
<Compile Include="Utilities\ImageUtilities.cs" />
<Compile Include="Utilities\Keyboard\KeyboardHook.cs" />
<Compile Include="Utilities\Memory\GamePointer.cs" />
<Compile Include="Utilities\Memory\Memory.cs" />
<Compile Include="Utilities\Memory\MemoryHelpers.cs" />
<Compile Include="Utilities\Memory\Win32.cs" />
@ -329,6 +330,7 @@
<Compile Include="Utilities\ShellLink.cs" />
<Compile Include="Utilities\Updater.cs" />
<Compile Include="ViewModels\Abstract\EffectViewModel.cs" />
<Compile Include="ViewModels\Abstract\GameViewModel.cs" />
<Compile Include="ViewModels\EffectsViewModel.cs" />
<Compile Include="Modules\Effects\AudioVisualizer\AudioVisualizerViewModel.cs" />
<Compile Include="Modules\Effects\Debug\DebugEffectViewModel.cs" />

View File

@ -52,8 +52,6 @@ namespace Artemis.Managers
if (!keyboardProvider.CanEnable())
{
_mainManager.DialogService.ShowErrorMessageBox(keyboardProvider.CantEnableText);
//MessageBox.Show(keyboardProvider.CantEnableText, "Artemis (╯°□°)╯︵ ┻━┻", MessageBoxButtons.OK,
// MessageBoxIcon.Warning);
return;
}

View File

@ -1,32 +1,32 @@
using System;
using System.Drawing;
using Artemis.Managers;
namespace Artemis.Models
{
public abstract class EffectModel : IDisposable
{
public delegate void SettingsUpdateHandler(EffectSettings settings);
public bool Initialized;
public MainManager MainManager;
public string Name;
protected EffectModel(MainManager mainManager)
{
MainManager = mainManager;
}
public abstract void Dispose();
// Called on creation
public abstract void Enable();
// Called every iteration
public abstract void Update();
// Called after every update
public abstract Bitmap GenerateBitmap();
}
using System;
using System.Drawing;
using Artemis.Managers;
namespace Artemis.Models
{
public abstract class EffectModel : IDisposable
{
public delegate void SettingsUpdateHandler(EffectSettings settings);
public bool Initialized;
public MainManager MainManager;
public string Name;
protected EffectModel(MainManager mainManager)
{
MainManager = mainManager;
}
public abstract void Dispose();
// Called on creation
public abstract void Enable();
// Called every iteration
public abstract void Update();
// Called after every update
public abstract Bitmap GenerateBitmap();
}
}

View File

@ -0,0 +1,7 @@
namespace Artemis.Models
{
public abstract class GameSettings : EffectSettings
{
public bool Enabled { get; set; }
}
}

View File

@ -18,7 +18,7 @@ namespace Artemis.Modules.Effects.AudioVisualizer
// Create effect model and add it to MainManager
EffectModel = new AudioVisualizerModel(mainManager, (AudioVisualizerSettings) EffectSettings);
MainManager.EffectManager.EffectModels.Add((AudioVisualizerModel) EffectModel);
MainManager.EffectManager.EffectModels.Add(EffectModel);
}
public static string Name => "Audio Visualizer";

View File

@ -27,7 +27,7 @@ namespace Artemis.Modules.Effects.Debug
// Create effect model and add it to MainManager
EffectModel = new DebugEffectModel(mainManager, (DebugEffectSettings) EffectSettings);
MainManager.EffectManager.EffectModels.Add((DebugEffectModel) EffectModel);
MainManager.EffectManager.EffectModels.Add(EffectModel);
}

View File

@ -15,7 +15,7 @@ namespace Artemis.Modules.Effects.TypeHole
// Create effect model and add it to MainManager
EffectModel = new TypeHoleModel(mainManager);
MainManager.EffectManager.EffectModels.Add((TypeHoleModel) EffectModel);
MainManager.EffectManager.EffectModels.Add(EffectModel);
}
public static string Name => "Type Holes (NYI)";

View File

@ -18,7 +18,7 @@ namespace Artemis.Modules.Effects.TypeWave
// Create effect model and add it to MainManager
EffectModel = new TypeWaveModel(mainManager, (TypeWaveSettings) EffectSettings);
MainManager.EffectManager.EffectModels.Add((TypeWaveModel) EffectModel);
MainManager.EffectManager.EffectModels.Add(EffectModel);
}
public static string Name => "Type Waves";

View File

@ -3,14 +3,13 @@ using Artemis.Models;
namespace Artemis.Modules.Games.CounterStrike
{
public class CounterStrikeSettings : EffectSettings
public class CounterStrikeSettings : GameSettings
{
public CounterStrikeSettings()
{
Load();
}
public bool Enabled { get; set; }
public string GameDirectory { get; set; }
public bool AmmoEnabled { get; set; }

View File

@ -37,7 +37,7 @@
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Label Content="Enable effect" Margin="0 3 0 0" HorizontalAlignment="Right" />
<ToggleButton x:Name="EffectEnabled" Margin="0 3 0 0" Width="25" Height="25"
IsChecked="{Binding Path=CounterStrikeSettings.Enabled, Mode=TwoWay}"
IsChecked="{Binding Path=GameSettings.Enabled, Mode=TwoWay}"
Style="{DynamicResource MetroCircleToggleButtonStyle}"
cal:Message.Attach="[Event Click] = [Action ToggleEffect]" />
</StackPanel>
@ -50,7 +50,7 @@
Width="130" HorizontalAlignment="Left" />
<Grid>
<TextBox x:Name="GameDirectory" Height="23" TextWrapping="Wrap" Margin="5,0,30,0"
Text="{Binding Path=CounterStrikeSettings.GameDirectory, Mode=TwoWay}"
Text="{Binding Path=GameSettings.GameDirectory, Mode=TwoWay}"
cal:Message.Attach="[Event LostFocus] = [Action PlaceConfigFile]" />
<Button x:Name="BrowseDirectory" Content="..." RenderTransformOrigin="-0.039,-0.944"
HorizontalAlignment="Right" Width="25"
@ -63,7 +63,7 @@
Height="16" Margin="0,10,0,9">
Display ammo on F-keys
</TextBlock>
<controls:ToggleSwitch IsChecked="{Binding Path=CounterStrikeSettings.AmmoEnabled, Mode=TwoWay}"
<controls:ToggleSwitch IsChecked="{Binding Path=GameSettings.AmmoEnabled, Mode=TwoWay}"
Grid.Row="2" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No"
Margin="0,0,-5,0" Width="114" />
@ -73,7 +73,7 @@
Main ammo color
</TextBlock>
<xctk:ColorPicker x:Name="MainColor"
SelectedColor="{Binding Path=CounterStrikeSettings.AmmoMainColor, Mode=TwoWay}"
SelectedColor="{Binding Path=GameSettings.AmmoMainColor, Mode=TwoWay}"
Grid.Row="3" Grid.Column="1" Width="110" HorizontalAlignment="Right"
VerticalAlignment="Center" Margin="0,5,-1,5" Height="22" />
@ -83,7 +83,7 @@
Secondary ammo color
</TextBlock>
<xctk:ColorPicker x:Name="SecondaryColor"
SelectedColor="{Binding Path=CounterStrikeSettings.AmmoSecondaryColor, Mode=TwoWay}"
SelectedColor="{Binding Path=GameSettings.AmmoSecondaryColor, Mode=TwoWay}"
Grid.Row="4" Grid.Column="1" Width="110" HorizontalAlignment="Right"
VerticalAlignment="Center" Margin="0,5,-1,5" Height="22" />
@ -92,7 +92,7 @@
Height="16" Margin="0,9,0,10">
Display smoked effect
</TextBlock>
<controls:ToggleSwitch IsChecked="{Binding Path=CounterStrikeSettings.SmokeEnabled, Mode=TwoWay}"
<controls:ToggleSwitch IsChecked="{Binding Path=GameSettings.SmokeEnabled, Mode=TwoWay}"
Grid.Row="5" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No"
Margin="0,0,-5,0" Width="114" />
@ -101,7 +101,7 @@
Height="16" Margin="0,10,0,9">
Display flashed effect
</TextBlock>
<controls:ToggleSwitch IsChecked="{Binding Path=CounterStrikeSettings.FlashEnabled, Mode=TwoWay}"
<controls:ToggleSwitch IsChecked="{Binding Path=GameSettings.FlashEnabled, Mode=TwoWay}"
Grid.Row="6" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No"
Margin="0,0,-5,0" Width="114" />
@ -110,7 +110,7 @@
Height="16" Margin="0,9,0,10">
Color keyboard according to team
</TextBlock>
<controls:ToggleSwitch IsChecked="{Binding Path=CounterStrikeSettings.TeamColorEnabled, Mode=TwoWay}"
<controls:ToggleSwitch IsChecked="{Binding Path=GameSettings.TeamColorEnabled, Mode=TwoWay}"
Grid.Row="7" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No"
Margin="0,0,-5,0" Width="114" />
@ -119,7 +119,7 @@
Height="16" Margin="0,10,0,9">
Color keyboard red on low HP
</TextBlock>
<controls:ToggleSwitch IsChecked="{Binding Path=CounterStrikeSettings.LowHpEnabled, Mode=TwoWay}"
<controls:ToggleSwitch IsChecked="{Binding Path=GameSettings.LowHpEnabled, Mode=TwoWay}"
Grid.Row="8" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No"
Margin="0,0,-5,0" Width="114" />

View File

@ -2,92 +2,63 @@
using System.Windows.Forms;
using Artemis.Managers;
using Artemis.Properties;
using Screen = Caliburn.Micro.Screen;
using Artemis.ViewModels.Abstract;
namespace Artemis.Modules.Games.CounterStrike
{
public class CounterStrikeViewModel : Screen
public class CounterStrikeViewModel : GameViewModel
{
private CounterStrikeSettings _counterStrikeSettings;
public CounterStrikeViewModel(MainManager mainManager)
{
MainManager = mainManager;
// Settings are loaded from file by class
CounterStrikeSettings = new CounterStrikeSettings();
GameSettings = new CounterStrikeSettings();
// Create effect model and add it to MainManager
CounterStrikeModel = new CounterStrikeModel(mainManager, CounterStrikeSettings);
MainManager.EffectManager.EffectModels.Add(CounterStrikeModel);
GameModel = new CounterStrikeModel(mainManager, (CounterStrikeSettings) GameSettings);
MainManager.EffectManager.EffectModels.Add(GameModel);
PlaceConfigFile();
}
public CounterStrikeSettings CounterStrikeSettings
{
get { return _counterStrikeSettings; }
set
{
if (Equals(value, _counterStrikeSettings)) return;
_counterStrikeSettings = value;
NotifyOfPropertyChange(() => CounterStrikeSettings);
}
}
public CounterStrikeModel CounterStrikeModel { get; set; }
public MainManager MainManager { get; set; }
public static string Name => "CS:GO";
public string Content => "Counter-Strike: GO Content";
public void SaveSettings()
{
CounterStrikeSettings?.Save();
}
public void ResetSettings()
{
// TODO: Confirmation dialog (Generic MVVM approach)
CounterStrikeSettings.ToDefault();
NotifyOfPropertyChange(() => CounterStrikeSettings);
SaveSettings();
}
public void ToggleEffect()
{
CounterStrikeModel.Enabled = _counterStrikeSettings.Enabled;
}
public void BrowseDirectory()
{
var dialog = new FolderBrowserDialog {SelectedPath = CounterStrikeSettings.GameDirectory};
var dialog = new FolderBrowserDialog {SelectedPath = ((CounterStrikeSettings) GameSettings).GameDirectory};
var result = dialog.ShowDialog();
if (result != DialogResult.OK)
return;
CounterStrikeSettings.GameDirectory = dialog.SelectedPath;
NotifyOfPropertyChange(() => CounterStrikeSettings);
((CounterStrikeSettings) GameSettings).GameDirectory = dialog.SelectedPath;
NotifyOfPropertyChange(() => GameSettings);
GameSettings.Save();
PlaceConfigFile();
}
public void PlaceConfigFile()
{
if (CounterStrikeSettings.GameDirectory == string.Empty)
if (((CounterStrikeSettings) GameSettings).GameDirectory == string.Empty)
return;
if (Directory.Exists(CounterStrikeSettings.GameDirectory + "/csgo/cfg"))
if (Directory.Exists(((CounterStrikeSettings) GameSettings).GameDirectory + "/csgo/cfg"))
{
var cfgFile = Resources.gamestateConfiguration.Replace("{{port}}",
MainManager.GameStateWebServer.Port.ToString());
File.WriteAllText(CounterStrikeSettings.GameDirectory + "/csgo/cfg/gamestate_integration_artemis.cfg",
File.WriteAllText(
((CounterStrikeSettings) GameSettings).GameDirectory + "/csgo/cfg/gamestate_integration_artemis.cfg",
cfgFile);
return;
}
MessageBox.Show("Please select a valid CS:GO directory");
CounterStrikeSettings.GameDirectory = string.Empty;
NotifyOfPropertyChange(() => CounterStrikeSettings);
MainManager.DialogService.ShowErrorMessageBox("Please select a valid CS:GO directory\n\n" +
@"By default CS:GO is in \SteamApps\common\Counter-Strike Global Offensive");
((CounterStrikeSettings) GameSettings).GameDirectory = string.Empty;
NotifyOfPropertyChange(() => GameSettings);
GameSettings.Save();
}
}
}

View File

@ -20,8 +20,9 @@ namespace Artemis.Modules.Games.RocketLeague
private int _boostAmount;
private bool _boostGrowing;
private KeyboardRectangle _boostRect;
private bool _contextualColor;
private Memory _memory;
private GamePointersCollectionModel _pointer;
private GamePointersCollection _pointer;
private int _previousBoost;
public RocketLeagueModel(MainManager mainManager, RocketLeagueSettings settings) : base(mainManager)
@ -37,7 +38,6 @@ namespace Artemis.Modules.Games.RocketLeague
public RocketLeagueSettings Settings { get; set; }
public int Scale { get; set; }
public bool ContextualColor { get; set; }
public override void Dispose()
{
@ -49,7 +49,7 @@ namespace Artemis.Modules.Games.RocketLeague
{
Initialized = false;
ContextualColor = Settings.ContextualColor;
_contextualColor = Settings.ContextualColor;
_boostRect = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0, 0, new List<Color>
{
@ -58,7 +58,7 @@ namespace Artemis.Modules.Games.RocketLeague
}, LinearGradientMode.Horizontal);
Updater.GetPointers();
_pointer = JsonConvert.DeserializeObject<GamePointersCollectionModel>(Offsets.Default.RocketLeague);
_pointer = JsonConvert.DeserializeObject<GamePointersCollection>(Offsets.Default.RocketLeague);
var tempProcess = MemoryHelpers.GetProcessIfRunning(ProcessName);
_memory = new Memory(tempProcess);
@ -89,7 +89,7 @@ namespace Artemis.Modules.Games.RocketLeague
_boostRect.Width =
(int) Math.Ceiling(MainManager.KeyboardManager.ActiveKeyboard.Width*Scale/100.00*_boostAmount);
if (ContextualColor)
if (_contextualColor)
{
if (_boostAmount < 33)
_boostRect.Colors = new List<Color> {Color.Red};
@ -98,15 +98,6 @@ namespace Artemis.Modules.Games.RocketLeague
else if (_boostAmount >= 66)
_boostRect.Colors = new List<Color> {Color.Lime};
}
else
{
_boostRect.Colors = new List<Color>
{
ColorHelpers.ToDrawingColor(Settings.MainColor),
ColorHelpers.ToDrawingColor(Settings.SecondaryColor)
};
}
Task.Run(() => GrowIfHigher());
}

View File

@ -3,14 +3,13 @@ using Artemis.Models;
namespace Artemis.Modules.Games.RocketLeague
{
public class RocketLeagueSettings : EffectSettings
public class RocketLeagueSettings : GameSettings
{
public RocketLeagueSettings()
{
Load();
}
public bool Enabled { get; set; }
public Color MainColor { get; set; }
public Color SecondaryColor { get; set; }
public bool ContextualColor { get; set; }

View File

@ -34,7 +34,7 @@
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Label Content="Enable effect" Margin="0 3 0 0" HorizontalAlignment="Right" />
<ToggleButton x:Name="EffectEnabled" Margin="0 3 0 0" Width="25" Height="25"
IsChecked="{Binding Path=RocketLeagueSettings.Enabled, Mode=TwoWay}"
IsChecked="{Binding Path=GameSettings.Enabled, Mode=TwoWay}"
Style="{DynamicResource MetroCircleToggleButtonStyle}"
cal:Message.Attach="[Event Click] = [Action ToggleEffect]" />
</StackPanel>
@ -46,7 +46,7 @@
Main boost display color
</TextBlock>
<xctk:ColorPicker x:Name="MainColor"
SelectedColor="{Binding Path=RocketLeagueSettings.MainColor, Mode=TwoWay}"
SelectedColor="{Binding Path=GameSettings.MainColor, Mode=TwoWay}"
Grid.Row="1" Grid.Column="1" Width="110" HorizontalAlignment="Right"
VerticalAlignment="Center" Margin="0,5,-1,5" Height="22" />
@ -56,7 +56,7 @@
Secondary boost display color
</TextBlock>
<xctk:ColorPicker x:Name="SecondaryColor"
SelectedColor="{Binding Path=RocketLeagueSettings.SecondaryColor, Mode=TwoWay}"
SelectedColor="{Binding Path=GameSettings.SecondaryColor, Mode=TwoWay}"
Grid.Row="2" Grid.Column="1" Width="110" HorizontalAlignment="Right"
VerticalAlignment="Center" Margin="0,5,-1,5" Height="22" />
@ -65,7 +65,7 @@
Height="16" Margin="0,8">
Color bar according to boost amount
</TextBlock>
<controls:ToggleSwitch IsChecked="{Binding Path=RocketLeagueSettings.ContextualColor, Mode=TwoWay}"
<controls:ToggleSwitch IsChecked="{Binding Path=GameSettings.ContextualColor, Mode=TwoWay}"
Grid.Row="3" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No"
Margin="0,0,-5,0" Width="114" />

View File

@ -1,15 +1,14 @@
using Artemis.Managers;
using Artemis.Models;
using Artemis.Settings;
using Artemis.Utilities;
using Caliburn.Micro;
using Artemis.Utilities.Memory;
using Artemis.ViewModels.Abstract;
using Newtonsoft.Json;
namespace Artemis.Modules.Games.RocketLeague
{
public class RocketLeagueViewModel : Screen
public class RocketLeagueViewModel : GameViewModel
{
private RocketLeagueSettings _rocketLeagueSettings;
private string _versionText;
public RocketLeagueViewModel(MainManager mainManager)
@ -17,15 +16,17 @@ namespace Artemis.Modules.Games.RocketLeague
MainManager = mainManager;
// Settings are loaded from file by class
RocketLeagueSettings = new RocketLeagueSettings();
GameSettings = new RocketLeagueSettings();
// Create effect model and add it to MainManager
RocketLeagueModel = new RocketLeagueModel(mainManager, RocketLeagueSettings);
MainManager.EffectManager.EffectModels.Add(RocketLeagueModel);
GameModel = new RocketLeagueModel(mainManager, (RocketLeagueSettings) GameSettings);
MainManager.EffectManager.EffectModels.Add(GameModel);
SetVersionText();
}
public static string Name => "Rocket League";
public string VersionText
{
get { return _versionText; }
@ -37,22 +38,8 @@ namespace Artemis.Modules.Games.RocketLeague
}
}
public static string Name => "Rocket League";
public MainManager MainManager { get; set; }
public RocketLeagueModel RocketLeagueModel { get; set; }
public RocketLeagueSettings RocketLeagueSettings
{
get { return _rocketLeagueSettings; }
set
{
if (Equals(value, _rocketLeagueSettings)) return;
_rocketLeagueSettings = value;
NotifyOfPropertyChange(() => RocketLeagueSettings);
}
}
private void SetVersionText()
{
if (!General.Default.EnablePointersUpdate)
@ -64,32 +51,10 @@ namespace Artemis.Modules.Games.RocketLeague
Updater.GetPointers();
var version = JsonConvert
.DeserializeObject<GamePointersCollectionModel>(Offsets.Default.RocketLeague)
.DeserializeObject<GamePointersCollection>(Offsets.Default.RocketLeague)
.GameVersion;
VersionText = $"Note: Requires patch {version}. When a new patch is released Artemis downloads " +
"new pointers for the latest version (unless disabled in settings).";
}
public void SaveSettings()
{
if (RocketLeagueModel == null)
return;
RocketLeagueSettings.Save();
}
public void ResetSettings()
{
// TODO: Confirmation dialog (Generic MVVM approach)
RocketLeagueSettings.ToDefault();
NotifyOfPropertyChange(() => RocketLeagueSettings);
SaveSettings();
}
public void ToggleEffect()
{
RocketLeagueModel.Enabled = _rocketLeagueSettings.Enabled;
}
}
}

View File

@ -2,15 +2,13 @@
namespace Artemis.Modules.Games.Witcher3
{
public class Witcher3Settings : EffectSettings
public class Witcher3Settings : GameSettings
{
public Witcher3Settings()
{
Load();
}
public bool Enabled { get; set; }
public sealed override void Load()
{
Enabled = Witcher3.Default.Enabled;

View File

@ -5,65 +5,27 @@ using System.Linq;
using System.Windows.Forms;
using Artemis.Managers;
using Artemis.Properties;
using Screen = Caliburn.Micro.Screen;
using Artemis.ViewModels.Abstract;
namespace Artemis.Modules.Games.Witcher3
{
public class Witcher3ViewModel : Screen
public class Witcher3ViewModel : GameViewModel
{
private Witcher3Settings _witcher3Settings;
public Witcher3ViewModel(MainManager mainManager)
{
MainManager = mainManager;
// Settings are loaded from file by class
Witcher3Settings = new Witcher3Settings();
GameSettings = new Witcher3Settings();
// Create effect model and add it to MainManager
Witcher3Model = new Witcher3Model(mainManager, Witcher3Settings);
MainManager.EffectManager.EffectModels.Add(Witcher3Model);
GameModel = new Witcher3Model(mainManager, (Witcher3Settings) GameSettings);
MainManager.EffectManager.EffectModels.Add(GameModel);
}
public static string Name => "The Witcher 3";
public MainManager MainManager { get; set; }
public Witcher3Model Witcher3Model { get; set; }
public Witcher3Settings Witcher3Settings
{
get { return _witcher3Settings; }
set
{
if (Equals(value, _witcher3Settings)) return;
_witcher3Settings = value;
NotifyOfPropertyChange(() => Witcher3Settings);
}
}
public void SaveSettings()
{
if (Witcher3Model == null)
return;
Witcher3Settings.Save();
}
public void ResetSettings()
{
// TODO: Confirmation dialog (Generic MVVM approach)
Witcher3Settings.ToDefault();
NotifyOfPropertyChange(() => Witcher3Settings);
SaveSettings();
}
public void ToggleEffect()
{
Witcher3Model.Enabled = _witcher3Settings.Enabled;
}
public void AutoInstall()
public async void AutoInstall()
{
// Request The Witcher 3 folder
var dialog = new FolderBrowserDialog
@ -77,15 +39,16 @@ namespace Artemis.Modules.Games.Witcher3
// If the subfolder doesn't contain witcher3.exe, it's the wrong folder.
if (!File.Exists(dialog.SelectedPath + @"\bin\x64\witcher3.exe"))
{
var error = MessageBox.Show("That's not a valid Witcher 3 directory\n\n" +
"Default directories:\n" +
"Steam: C:\\Program Files (x86)\\Steam\\steamapps\\common\\The Witcher 3\n" +
"GOG: C:\\GOG Games\\The Witcher 3 Wild Hunt", "Installation error",
MessageBoxButtons.RetryCancel);
if (error == DialogResult.Retry)
var retry = await
MainManager.DialogService.ShowQuestionMessageBox("Installation error",
"That's not a valid Witcher 3 directory\n\n" +
"Default directories:\n" +
"Steam: \\SteamApps\\common\\The Witcher 3\n" +
"GOG: C:\\GOG Games\\The Witcher 3 Wild Hunt\n\n" +
"Retry?");
if (retry.Value)
AutoInstall();
else
return;
return;
}
// Look for any conflicting mods
@ -99,17 +62,21 @@ namespace Artemis.Modules.Games.Witcher3
// Don't trip over our own mod
if (!file.Contains("modArtemis"))
{
MessageBox.Show("Oh no, you have a conflicting mod!\n\n" +
"Conflicting file: " + file.Remove(0, dialog.SelectedPath.Length) +
"\n\nOnce you press OK you will be taken to an instructions page.",
"Conflicting mod found");
var viewHelp = await
MainManager.DialogService.ShowQuestionMessageBox("Conflicting mod found",
"Oh no, you have a conflicting mod!\n\n" +
"Conflicting file: " + file.Remove(0, dialog.SelectedPath.Length) +
"\n\nWould you like to view instructions on how to manually install the mod?");
if (!viewHelp.Value)
return;
// Put the mod in the documents folder instead
// Create the directory structure
var folder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Artemis";
if (
!Directory.Exists(folder + @"\Witcher3\mods\modArtemis\content\scripts\game\player"))
Directory.CreateDirectory(folder + @"\Witcher3\mods\modArtemis\content\scripts\game\player");
Directory.CreateDirectory(folder +
@"\Witcher3\mods\modArtemis\content\scripts\game\player");
if (
!Directory.Exists(folder + @"\Witcher3\bin\config\r4game\user_config_matrix\pc"))
Directory.CreateDirectory(folder + @"\Witcher3\bin\config\r4game\user_config_matrix\pc");
@ -122,7 +89,6 @@ namespace Artemis.Modules.Games.Witcher3
Resources.playerWitcherWs);
Process.Start(new ProcessStartInfo("https://github.com/SpoinkyNL/Artemis/wiki/The-Witcher-3"));
return;
}
}
@ -140,7 +106,7 @@ namespace Artemis.Modules.Games.Witcher3
File.WriteAllText(dialog.SelectedPath + @"\mods\modArtemis\content\scripts\game\player\playerWitcher.ws",
Resources.playerWitcherWs);
MessageBox.Show("The mod was successfully installed!", "Success");
MainManager.DialogService.ShowMessageBox("Success", "The mod was successfully installed!");
}
}
}

View File

@ -1,26 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace Artemis.Models
{
public class GamePointersCollectionModel
{
public string Game { get; set; }
public string GameVersion { get; set; }
public List<GamePointer> GameAddresses { get; set; }
}
public class GamePointer
{
public string Description { get; set; }
public IntPtr BasePointer { get; set; }
public int[] Offsets { get; set; }
public override string ToString()
{
return Offsets.Aggregate(BasePointer.ToString("X"),
(current, offset) => current + $"+{offset.ToString("X")}");
}
}
using System;
using System.Collections.Generic;
using System.Linq;
namespace Artemis.Utilities.Memory
{
public class GamePointer
{
public string Description { get; set; }
public IntPtr BasePointer { get; set; }
public int[] Offsets { get; set; }
public override string ToString()
{
return Offsets.Aggregate(BasePointer.ToString("X"),
(current, offset) => current + $"+{offset.ToString("X")}");
}
}
public class GamePointersCollection
{
public string Game { get; set; }
public string GameVersion { get; set; }
public List<GamePointer> GameAddresses { get; set; }
}
}

View File

@ -7,6 +7,7 @@ using System.Threading.Tasks;
using Artemis.Models;
using Artemis.Services;
using Artemis.Settings;
using Artemis.Utilities.Memory;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@ -86,7 +87,7 @@ namespace Artemis.Utilities
"https://raw.githubusercontent.com/SpoinkyNL/Artemis/master/pointers.json?random=" + rand.Next());
// Get a list of pointers
var pointers = JsonConvert.DeserializeObject<List<GamePointersCollectionModel>>(json);
var pointers = JsonConvert.DeserializeObject<List<GamePointersCollection>>(json);
// Assign each pointer to the settings file
var rlPointers = JsonConvert.SerializeObject(pointers.FirstOrDefault(p => p.Game == "RocketLeague"));
if (rlPointers != null)

View File

@ -61,9 +61,15 @@ namespace Artemis.ViewModels.Abstract
MainManager.EffectManager.ChangeEffect(EffectModel, true);
}
public void ResetSettings()
public async void ResetSettings()
{
// TODO: Confirmation dialog (Generic MVVM approach)
var resetConfirm = await
MainManager.DialogService.ShowQuestionMessageBox("Reset effect settings",
"Are you sure you wish to reset this effect's settings? \nAny changes you made will be lost.");
if (!resetConfirm.Value)
return;
EffectSettings.ToDefault();
NotifyOfPropertyChange(() => EffectSettings);

View File

@ -0,0 +1,57 @@
using Artemis.Managers;
using Artemis.Models;
using Caliburn.Micro;
namespace Artemis.ViewModels.Abstract
{
public abstract class GameViewModel : Screen
{
private GameSettings _gameSettings;
public GameModel GameModel { get; set; }
public MainManager MainManager { get; set; }
public GameSettings GameSettings
{
get { return _gameSettings; }
set
{
if (Equals(value, _gameSettings)) return;
_gameSettings = value;
NotifyOfPropertyChange(() => GameSettings);
}
}
public bool GameEnabled => MainManager.EffectManager.ActiveEffect == GameModel;
public void ToggleEffect()
{
GameModel.Enabled = GameSettings.Enabled;
}
public void SaveSettings()
{
GameSettings?.Save();
if (!GameEnabled)
return;
// Restart the game if it's currently running to apply settings.
MainManager.EffectManager.ChangeEffect(GameModel, true);
}
public async void ResetSettings()
{
var resetConfirm = await
MainManager.DialogService.ShowQuestionMessageBox("Reset effect settings",
"Are you sure you wish to reset this effect's settings? \nAny changes you made will be lost.");
if (!resetConfirm.Value)
return;
GameSettings.ToDefault();
NotifyOfPropertyChange(() => GameSettings);
SaveSettings();
}
}
}