diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 13907072e..ecc53e141 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -651,8 +651,7 @@ - - + SettingsSingleFileGenerator Offsets.Designer.cs diff --git a/Artemis/Artemis/Models/Profiles/LayerConditionModel.cs b/Artemis/Artemis/Models/Profiles/LayerConditionModel.cs index ee659913e..cc8f723dd 100644 --- a/Artemis/Artemis/Models/Profiles/LayerConditionModel.cs +++ b/Artemis/Artemis/Models/Profiles/LayerConditionModel.cs @@ -40,7 +40,7 @@ namespace Artemis.Models.Profiles switch (Type) { case "Enum": - var enumType = _interpreter.Eval($"subject.{Field}.GetType()", new Parameter("subject", typeof(T), subject)); + var enumType = GeneralHelpers.GetPropertyValue(subject, Field).GetType(); rightParam = new Parameter("value", Enum.Parse(enumType, Value)); break; case "Boolean": @@ -51,7 +51,8 @@ namespace Artemis.Models.Profiles break; } - return _interpreter.Eval($"subject.{Field} {Operator} value", new Parameter("subject", typeof(T), subject), rightParam); + return _interpreter.Eval($"subject.{Field} {Operator} value", + new Parameter("subject", typeof(T), subject), rightParam); } } } \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/Witcher3/Witcher3DataModel.cs b/Artemis/Artemis/Modules/Games/Witcher3/Witcher3DataModel.cs index c30f4fa28..e153ad6bd 100644 --- a/Artemis/Artemis/Modules/Games/Witcher3/Witcher3DataModel.cs +++ b/Artemis/Artemis/Modules/Games/Witcher3/Witcher3DataModel.cs @@ -5,6 +5,11 @@ namespace Artemis.Modules.Games.Witcher3 public class Witcher3DataModel : IDataModel { public WitcherSign WitcherSign { get; set; } + public int MaxHealth { get; set; } + public int Health { get; set; } + public int Stamina { get; set; } + public int Toxicity { get; set; } + public int Vitality { get; set; } } public enum WitcherSign diff --git a/Artemis/Artemis/Modules/Games/Witcher3/Witcher3Model.cs b/Artemis/Artemis/Modules/Games/Witcher3/Witcher3Model.cs index 465aaca9f..a61da7526 100644 --- a/Artemis/Artemis/Modules/Games/Witcher3/Witcher3Model.cs +++ b/Artemis/Artemis/Modules/Games/Witcher3/Witcher3Model.cs @@ -1,22 +1,20 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Drawing; -using System.Drawing.Drawing2D; +using System.Globalization; using System.IO; +using System.Linq; using System.Text.RegularExpressions; using Artemis.Managers; using Artemis.Models; using Artemis.Models.Profiles; -using Artemis.Utilities.Keyboard; namespace Artemis.Modules.Games.Witcher3 { public class Witcher3Model : GameModel { - private readonly Regex _signRegex; private readonly Stopwatch _updateSw; - private KeyboardRectangle _signRect; + private readonly Regex _configRegex; private string _witcherSettings; public Witcher3Model(MainManager mainManager, Witcher3Settings settings) @@ -29,7 +27,7 @@ namespace Artemis.Modules.Games.Witcher3 Initialized = false; _updateSw = new Stopwatch(); - _signRegex = new Regex("ActiveSign=(.*)", RegexOptions.Compiled); + _configRegex = new Regex("\\[Artemis\\](.+?)\\[", RegexOptions.Singleline); } public int Scale { get; set; } @@ -46,13 +44,6 @@ namespace Artemis.Modules.Games.Witcher3 { Initialized = false; - _signRect = new KeyboardRectangle(MainManager.DeviceManager.ActiveKeyboard, 0, 0, new List(), - LinearGradientMode.Horizontal) - { - Rotate = true, - LoopSpeed = 0.5 - }; - // Ensure the config file is found var witcherSettings = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + @"\The Witcher 3\user.settings"; @@ -80,28 +71,69 @@ namespace Artemis.Modules.Games.Witcher3 var configContent = reader.ReadToEnd(); reader.Close(); - var signRes = _signRegex.Match(configContent); - if (signRes.Groups.Count < 2) - return; - var sign = signRes.Groups[1].Value; + var signRes = _configRegex.Match(configContent); + var parts = signRes.Value.Split('\n').Skip(1).Select(v => v.Replace("\r", "")).ToList(); + parts.RemoveAt(parts.Count - 1); - switch (sign) + // Update sign + var sign = parts.FirstOrDefault(p => p.Contains("ActiveSign=")); + if (sign != null) { - case "ST_Aard\r": - gameDataModel.WitcherSign = WitcherSign.Aard; - break; - case "ST_Yrden\r": - gameDataModel.WitcherSign = WitcherSign.Yrden; - break; - case "ST_Igni\r": - gameDataModel.WitcherSign = WitcherSign.Igni; - break; - case "ST_Quen\r": - gameDataModel.WitcherSign = WitcherSign.Quen; - break; - case "ST_Axii\r": - gameDataModel.WitcherSign = WitcherSign.Axii; - break; + var singString = sign.Split('=')[1]; + switch (singString) + { + case "ST_Aard": + gameDataModel.WitcherSign = WitcherSign.Aard; + break; + case "ST_Yrden": + gameDataModel.WitcherSign = WitcherSign.Yrden; + break; + case "ST_Igni": + gameDataModel.WitcherSign = WitcherSign.Igni; + break; + case "ST_Quen": + gameDataModel.WitcherSign = WitcherSign.Quen; + break; + case "ST_Axii": + gameDataModel.WitcherSign = WitcherSign.Axii; + break; + } + } + + // Update max health + var maxHealth = parts.FirstOrDefault(p => p.Contains("MaxHealth=")); + if (maxHealth != null) + { + var healthInt = int.Parse(maxHealth.Split('=')[1].Split('.')[0]); + gameDataModel.MaxHealth = healthInt; + } + // Update health + var health = parts.FirstOrDefault(p => p.Contains("Health=")); + if (health != null) + { + var healthInt = int.Parse(health.Split('=')[1].Split('.')[0]); + gameDataModel.Health = healthInt; + } + // Update stamina + var stamina = parts.FirstOrDefault(p => p.Contains("Stamina=")); + if (stamina != null) + { + var staminaInt = int.Parse(stamina.Split('=')[1].Split('.')[0]); + gameDataModel.Stamina = staminaInt; + } + // Update stamina + var toxicity = parts.FirstOrDefault(p => p.Contains("Toxicity=")); + if (toxicity != null) + { + var toxicityInt = int.Parse(toxicity.Split('=')[1].Split('.')[0]); + gameDataModel.Toxicity = toxicityInt; + } + // Update vitality + var vitality = parts.FirstOrDefault(p => p.Contains("Vitality=")); + if (vitality != null) + { + var vitalityInt = int.Parse(vitality.Split('=')[1].Split('.')[0]); + gameDataModel.Vitality = vitalityInt; } } diff --git a/Artemis/Artemis/Modules/Games/Witcher3/Witcher3ViewModel.cs b/Artemis/Artemis/Modules/Games/Witcher3/Witcher3ViewModel.cs index 559e7c8df..adee38e81 100644 --- a/Artemis/Artemis/Modules/Games/Witcher3/Witcher3ViewModel.cs +++ b/Artemis/Artemis/Modules/Games/Witcher3/Witcher3ViewModel.cs @@ -1,11 +1,13 @@ using System; using System.Diagnostics; using System.IO; +using System.IO.Compression; using System.Linq; +using System.Reflection; using System.Windows.Forms; using Artemis.InjectionFactories; using Artemis.Managers; -using Artemis.Properties; +using Artemis.Utilities; using Artemis.ViewModels.Abstract; using Caliburn.Micro; @@ -20,8 +22,6 @@ namespace Artemis.Modules.Games.Witcher3 MainManager.EffectManager.EffectModels.Add(GameModel); } - public static string Name => "The Witcher 3"; - public async void AutoInstall() { // Request The Witcher 3 folder @@ -48,6 +48,13 @@ namespace Artemis.Modules.Games.Witcher3 return; } + // Load the ZIP from resources + var stream = Assembly.GetExecutingAssembly() + .GetManifestResourceStream("Artemis.Resources.Witcher3.Witcher3Artemis.zip"); + if (stream == null) + throw new FileNotFoundException("Couldn't load the Witcher 3 mod files from resources."); + var archive = new ZipArchive(stream); + // Look for any conflicting mods if (Directory.Exists(dialog.SelectedPath + @"\mods")) { @@ -62,28 +69,16 @@ namespace Artemis.Modules.Games.Witcher3 var viewHelp = await 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?"); + $"Conflicting file: {file.Remove(0, dialog.SelectedPath.Length)}\n\n" + + "Would 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"); - if ( - !Directory.Exists(folder + @"\Witcher3\bin\config\r4game\user_config_matrix\pc")) - Directory.CreateDirectory(folder + @"\Witcher3\bin\config\r4game\user_config_matrix\pc"); - // Install the mod files - File.WriteAllText(folder + @"\Witcher3\bin\config\r4game\user_config_matrix\pc\artemis.xml", - Resources.artemisXml); - File.WriteAllText( - folder + @"\Witcher3\mods\modArtemis\content\scripts\game\player\playerWitcher.ws", - Resources.playerWitcherWs); + archive.ExtractToDirectory(folder + @"witcher3-mod", true); Process.Start(new ProcessStartInfo("https://github.com/SpoinkyNL/Artemis/wiki/The-Witcher-3")); return; @@ -91,18 +86,7 @@ namespace Artemis.Modules.Games.Witcher3 } } - // Create the directory structure - if (!Directory.Exists(dialog.SelectedPath + @"\mods\modArtemis\content\scripts\game\player")) - Directory.CreateDirectory(dialog.SelectedPath + @"\mods\modArtemis\content\scripts\game\player"); - if (!Directory.Exists(dialog.SelectedPath + @"\bin\config\r4game\user_config_matrix\pc")) - Directory.CreateDirectory(dialog.SelectedPath + @"\bin\config\r4game\user_config_matrix\pc"); - - // Install the mod files - File.WriteAllText(dialog.SelectedPath + @"\bin\config\r4game\user_config_matrix\pc\artemis.xml", - Resources.artemisXml); - File.WriteAllText(dialog.SelectedPath + @"\mods\modArtemis\content\scripts\game\player\playerWitcher.ws", - Resources.playerWitcherWs); - + archive.ExtractToDirectory(dialog.SelectedPath, true); DialogService.ShowMessageBox("Success", "The mod was successfully installed!"); } } diff --git a/Artemis/Artemis/Properties/Resources.Designer.cs b/Artemis/Artemis/Properties/Resources.Designer.cs index b8bbfd563..e7e5363ad 100644 --- a/Artemis/Artemis/Properties/Resources.Designer.cs +++ b/Artemis/Artemis/Properties/Resources.Designer.cs @@ -60,23 +60,6 @@ namespace Artemis.Properties { } } - /// - /// Looks up a localized string similar to <?xml version="1.0" encoding="UTF-16"?> - ///<!-- Used by Artemis to get the active Sign --> - ///<UserConfig> - /// <Group id="Artemis" displayName="Artemis"> - /// <VisibleVars> - /// <Var id="ActiveSign" displayName="ActiveSign" displayType="SLIDER:0:1:1000000"/> - /// </VisibleVars> - /// </Group> - ///</UserConfig>. - /// - internal static string artemisXml { - get { - return ResourceManager.GetString("artemisXml", resourceCulture); - } - } - /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -285,30 +268,6 @@ namespace Artemis.Properties { } } - /// - /// Looks up a localized string similar to /***********************************************************************/ - ////** © 2015 CD PROJEKT S.A. All rights reserved. - ////** THE WITCHER® is a trademark of CD PROJEKT S. A. - ////** The Witcher game is based on the prose of Andrzej Sapkowski. - ////***********************************************************************/ - /// - /// - /// - /// - ///statemachine class W3PlayerWitcher extends CR4Player - ///{ - /// - /// private saved var craftingSchematics : array<name>; - /// - /// - /// private saved var alchemyRecipes : array<name>; [rest of string was truncated]";. - /// - internal static string playerWitcherWs { - get { - return ResourceManager.GetString("playerWitcherWs", resourceCulture); - } - } - /// /// Looks up a localized resource of type System.Byte[]. /// @@ -328,5 +287,15 @@ namespace Artemis.Properties { return ((System.Drawing.Bitmap)(obj)); } } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] Witcher3Artemis { + get { + object obj = ResourceManager.GetObject("Witcher3Artemis", resourceCulture); + return ((byte[])(obj)); + } + } } } diff --git a/Artemis/Artemis/Properties/Resources.resx b/Artemis/Artemis/Properties/Resources.resx index 32fe5bf19..3db4fb76e 100644 --- a/Artemis/Artemis/Properties/Resources.resx +++ b/Artemis/Artemis/Properties/Resources.resx @@ -118,9 +118,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - ..\resources\witcher3\artemis.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - ..\Resources\bow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -139,9 +136,6 @@ ..\Resources\logo-disabled.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\resources\witcher3\playerwitcher.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-16 - ..\resources\keyboards\k65.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -184,4 +178,7 @@ ..\Resources\Keyboards\demo-gif.gif;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\Witcher3\Witcher3Artemis.zip;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file diff --git a/Artemis/Artemis/Resources/Witcher3/Witcher3Artemis.zip b/Artemis/Artemis/Resources/Witcher3/Witcher3Artemis.zip new file mode 100644 index 000000000..8269c99d9 Binary files /dev/null and b/Artemis/Artemis/Resources/Witcher3/Witcher3Artemis.zip differ diff --git a/Artemis/Artemis/Resources/Witcher3/artemis.txt b/Artemis/Artemis/Resources/Witcher3/artemis.txt deleted file mode 100644 index 6621adc2c..000000000 --- a/Artemis/Artemis/Resources/Witcher3/artemis.txt +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/Artemis/Artemis/Resources/Witcher3/playerWitcher.txt b/Artemis/Artemis/Resources/Witcher3/playerWitcher.txt deleted file mode 100644 index 2fead1e77..000000000 Binary files a/Artemis/Artemis/Resources/Witcher3/playerWitcher.txt and /dev/null differ