diff --git a/VStancer.Client/VStancer.Client.csproj b/VStancer.Client/VStancer.Client.csproj index d4466a6..6ae7553 100644 --- a/VStancer.Client/VStancer.Client.csproj +++ b/VStancer.Client/VStancer.Client.csproj @@ -20,12 +20,19 @@ + 1.0.2104 runtime compile; build; native; contentfiles; analyzers; buildtransitive + + + + + $(PkgNewtonsoft_Json)\lib\portable-net40+sl5+win8+wp8+wpa81\Newtonsoft.Json.dll + @@ -33,7 +40,7 @@ - + diff --git a/VStancer.Client/VStancerConfig.cs b/VStancer.Client/VStancerConfig.cs index 0ba5068..4d9db47 100644 --- a/VStancer.Client/VStancerConfig.cs +++ b/VStancer.Client/VStancerConfig.cs @@ -16,8 +16,8 @@ public class VStancerConfig public long Timer { get; set; } public int ToggleMenuControl { get; set; } public float FloatStep { get; set; } - public WheelLimits FrontLimits { get; set; } - public WheelLimits RearLimits { get; set; } + public NodeLimits FrontLimits { get; set; } + public NodeLimits RearLimits { get; set; } public VStancerConfig() { @@ -28,89 +28,12 @@ public VStancerConfig() Timer = 1000; ToggleMenuControl = 167; FloatStep = 0.01f; - FrontLimits = new WheelLimits { PositionX = 0.25f, RotationY = 0.20f }; - RearLimits = new WheelLimits { PositionX = 0.25f, RotationY = 0.20f }; - } - - public void LoadXml(string xml) - { - string txt = Helpers.RemoveByteOrderMarks(xml); - - XmlDocument doc = new XmlDocument(); - doc.LoadXml(txt); - - var rootNode = doc[nameof(VStancerConfig)]; - - foreach (XmlNode node in rootNode?.ChildNodes) - { - if (node.NodeType != XmlNodeType.Element) - continue; - - if (node.Name == nameof(Debug) && bool.TryParse(node.InnerText, out bool debugValue)) - Debug = debugValue; - - else if (node.Name == nameof(ExposeCommand) && bool.TryParse(node.InnerText, out bool exposeCommandValue)) - ExposeCommand = exposeCommandValue; - - else if (node.Name == nameof(ExposeEvent) && bool.TryParse(node.InnerText, out bool exposeEventValue)) - ExposeEvent = exposeEventValue; - - else if (node.Name == nameof(ScriptRange) && float.TryParse(node.InnerText, out float scriptRangeValue)) - ScriptRange = scriptRangeValue; - - else if (node.Name == nameof(Timer) && long.TryParse(node.InnerText, out long timerValue)) - Timer = timerValue; - - else if (node.Name == nameof(ToggleMenuControl) && int.TryParse(node.InnerText, out int toggleMenuControlValue)) - ToggleMenuControl = toggleMenuControlValue; - - else if (node.Name == nameof(FloatStep) && float.TryParse(node.InnerText, out float floatStepValue)) - FloatStep = floatStepValue; - - else if (node.Name == nameof(FrontLimits)) - { - var frontLimits = new WheelLimits(); - - foreach (XmlNode child in node.ChildNodes) - { - if (node.NodeType != XmlNodeType.Element) - continue; - - if (child.Name == nameof(WheelLimits.PositionX) && float.TryParse(child.InnerText, out float positionXValue)) - frontLimits.PositionX = positionXValue; - - if (child.Name == nameof(WheelLimits.RotationY) && float.TryParse(child.InnerText, out float rotationYValue)) - frontLimits.RotationY = rotationYValue; - - FrontLimits = frontLimits; - } - } - - else if (node.Name == nameof(RearLimits)) - { - var rearLimits = new WheelLimits(); - - foreach (XmlNode child in node.ChildNodes) - { - if (node.NodeType == XmlNodeType.Comment) - continue; - - if (child.Name == nameof(WheelLimits.PositionX) && float.TryParse(child.InnerText, out float positionXValue)) - rearLimits.PositionX = positionXValue; - - if (child.Name == nameof(WheelLimits.RotationY) && float.TryParse(child.InnerText, out float rotationYValue)) - rearLimits.RotationY = rotationYValue; - - RearLimits = rearLimits; - } - } - - else continue; - } + FrontLimits = new NodeLimits { PositionX = 0.25f, RotationY = 0.20f }; + RearLimits = new NodeLimits { PositionX = 0.25f, RotationY = 0.20f }; } } - public struct WheelLimits + public struct NodeLimits { public float PositionX { get; set; } public float RotationY { get; set; } diff --git a/VStancer.Client/VStancerEditor.cs b/VStancer.Client/VStancerEditor.cs index 2c54345..d6af62b 100644 --- a/VStancer.Client/VStancerEditor.cs +++ b/VStancer.Client/VStancerEditor.cs @@ -6,6 +6,7 @@ using CitizenFX.Core; using CitizenFX.Core.UI; using static CitizenFX.Core.Native.API; +using Newtonsoft.Json; namespace Vstancer.Client { @@ -790,14 +791,14 @@ private bool HasDecorators(int entity) /// Loads the config file containing all the customizable properties /// /// The name of the file - private void LoadConfig(string filename = "config.xml") + private void LoadConfig(string filename = "config.json") { - VStancerConfig config = new VStancerConfig(); + VStancerConfig config = null; try { string strings = LoadResourceFile(ResourceName, filename); - config.LoadXml(strings); + config = JsonConvert.DeserializeObject(strings); Debug.WriteLine($"{ScriptName}: Loaded config from {filename}"); } @@ -805,6 +806,8 @@ private void LoadConfig(string filename = "config.xml") { Debug.WriteLine($"{ScriptName}: Impossible to load {filename}", e.Message); Debug.WriteLine(e.StackTrace); + + config = new VStancerConfig(); } finally { diff --git a/VStancer.Client/VStancerPreset.cs b/VStancer.Client/VStancerPreset.cs index 3f7f994..d127f64 100644 --- a/VStancer.Client/VStancerPreset.cs +++ b/VStancer.Client/VStancerPreset.cs @@ -190,8 +190,8 @@ public struct VStancerNode { //public Vector3 Position { get; set; } //public Vector3 Rotation { get; set; } + //public Vector3 Scale { get; set; } public float PositionX { get; set; } public float RotationY { get; set; } - //public Vector3 Scale { get; set; } } } diff --git a/appveyor.yml b/appveyor.yml index 83558bc..729ee76 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,7 +4,7 @@ install: - ps: if ($env:APPVEYOR_REPO_TAG -ne $True){ $env:TAG_NUMBER = $env:TAG_NUMBER + "." + $env:APPVEYOR_BUILD_NUMBER } else { $env:TAG_NUMBER = $env:TAG_NUMBER + "." + 0 } version: 1.0.{build} -image: Visual Studio 2017 +image: Visual Studio 2019 configuration: Release dotnet_csproj: @@ -22,7 +22,6 @@ build: project: fivem-vstancer.sln before_build: -- cmd: git submodule update --init --recursive - nuget restore after_build: @@ -30,6 +29,7 @@ after_build: - cmd: move /Y %APPVEYOR_BUILD_FOLDER%\dist\*.* %APPVEYOR_BUILD_FOLDER%\dist\vstancer - cmd: move /Y %APPVEYOR_BUILD_FOLDER%\VStancer.Client\bin\%CONFIGURATION%\net452\VStancer.Client.net.dll %APPVEYOR_BUILD_FOLDER%\dist\vstancer - cmd: move /Y %APPVEYOR_BUILD_FOLDER%\VStancer.Client\bin\%CONFIGURATION%\net452\MenuAPI.dll %APPVEYOR_BUILD_FOLDER%\dist\vstancer +- cmd: move /Y %APPVEYOR_BUILD_FOLDER%\VStancer.Client\bin\%CONFIGURATION%\net452\Newtonsoft.Json.dll %APPVEYOR_BUILD_FOLDER%\dist\vstancer - 7z a vstancer-v%TAG_NUMBER%.zip %APPVEYOR_BUILD_FOLDER%\dist\* artifacts: diff --git a/dist/config.json b/dist/config.json new file mode 100644 index 0000000..30eff40 --- /dev/null +++ b/dist/config.json @@ -0,0 +1,17 @@ +{ + "Debug": false, + "ExposeCommand": false, + "ExposeEvent": false, + "ScriptRange": 150.0, + "Timer": 1000, + "ToggleMenuControl": 167, + "FloatStep": 0.01, + "FrontLimits": { + "PositionX": 0.25, + "RotationY": 0.2 + }, + "RearLimits": { + "PositionX": 0.25, + "RotationY": 0.2 + } +} \ No newline at end of file diff --git a/dist/config.xml b/dist/config.xml deleted file mode 100644 index 987b664..0000000 --- a/dist/config.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - false - false - false - 150 - 1000 - 167 - 0.01 - - 0.25 - 0.2 - - - 0.25 - 0.2 - - \ No newline at end of file diff --git a/dist/fxmanifest.lua b/dist/fxmanifest.lua index dcefed7..b0a003b 100644 --- a/dist/fxmanifest.lua +++ b/dist/fxmanifest.lua @@ -5,7 +5,8 @@ games { 'gta5' } files { --'@MenuAPI/MenuAPI.dll', 'MenuAPI.dll', - 'config.xml' + 'Newtonsoft.Json.dll', + 'config.json' } client_scripts { diff --git a/fivem-vstancer.sln b/fivem-vstancer.sln index 4d4171a..e25b61b 100644 --- a/fivem-vstancer.sln +++ b/fivem-vstancer.sln @@ -7,7 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VStancer.Client", "VStancer EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{886C4B07-F58C-4E89-A80F-849679435A18}" ProjectSection(SolutionItems) = preProject - dist\config.xml = dist\config.xml + dist\config.json = dist\config.json dist\fxmanifest.lua = dist\fxmanifest.lua LICENSE = LICENSE postbuild.bat = postbuild.bat