Skip to content

Commit

Permalink
Merge pull request #14 from FrankvdStam/feature/sonar-loc-cdp
Browse files Browse the repository at this point in the history
Feature/sonar loc cdp
  • Loading branch information
FrankvdStam authored Sep 9, 2023
2 parents 7c7b00b + 32d64bb commit f6e0340
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/SoulMemory/FlagWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

namespace SoulMemory
{
/// <summary>
/// Util to easily track event flag changes, helps with debugging.
/// </summary>
[ExcludeFromCodeCoverage]
public class FlagWatcher
{
public FlagWatcher(IGame game, IEnumerable<uint> flags)
Expand Down
3 changes: 3 additions & 0 deletions src/SoulMemory/MemoryV2/ByteArrayMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

namespace SoulMemory.MemoryV2
{
/// <summary>
/// IMemory access to an array of memory. Allows resolving pointers and reading data/writing data.
/// </summary>
public class ByteArrayMemory : IMemory
{
private readonly byte[] _data;
Expand Down
3 changes: 3 additions & 0 deletions src/SoulMemory/MemoryV2/Memory/IMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

namespace SoulMemory.MemoryV2.Memory
{
/// <summary>
/// Abstracts a resource that can be read from and written to
/// </summary>
public interface IMemory
{
byte[] ReadBytes(long offset, int length);
Expand Down
3 changes: 3 additions & 0 deletions src/SoulMemory/MemoryV2/Process/IProcessHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

namespace SoulMemory.MemoryV2.Process
{
/// <summary>
/// Abstracts a hooked process and makes it injectable and testable
/// </summary>
public interface IProcessHook : IMemory
{
/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions src/SoulMemory/MemoryV2/Process/IProcessWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

namespace SoulMemory.MemoryV2.Process
{
/// <summary>
/// Abstract away the functionality from System.Diagnostics.Process, to make it injectable and testable
/// </summary>
public interface IProcessWrapper : IMemory
{
ProcessRefreshResult TryRefresh(string name, out Exception exception);
Expand Down
2 changes: 2 additions & 0 deletions src/SoulMemory/Native/Kernel32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;

namespace SoulMemory.Native
{
[ExcludeFromCodeCoverage]
public static class Kernel32
{
#region Read process memory ==================================================================================================================
Expand Down
2 changes: 2 additions & 0 deletions src/SoulMemory/Native/Ntdll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;

namespace SoulMemory.Native
{
[ExcludeFromCodeCoverage]
public static class Ntdll
{
[DllImport("ntdll.dll", SetLastError = true)]
Expand Down
8 changes: 5 additions & 3 deletions src/SoulMemory/Native/User32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;

namespace SoulMemory.Native
{
[ExcludeFromCodeCoverage]
internal static class User32
{
[DllImport("user32.dll")]
public static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, out uint ProcessId);
private static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, out uint processId);

[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
private static extern IntPtr GetForegroundWindow();

public static uint GetForegroundProcessID()
public static uint GetForegroundProcessId()
{
IntPtr hWnd = GetForegroundWindow();
GetWindowThreadProcessId(hWnd, out uint pid);
Expand Down
2 changes: 2 additions & 0 deletions src/SoulMemory/Parameters/ParamClassGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Xml;

namespace SoulMemory.Parameters
{
[ExcludeFromCodeCoverage]
public static class ParamClassGenerator
{
public static string GenerateFromXml(string xml, string className, string classHeader)
Expand Down
2 changes: 1 addition & 1 deletion src/SoulMemory/SoulMemory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<SonarQubeSetting Include="sonar.exclusions">
<SonarQubeSetting Include="sonar.cpd.exclusions">
<Value>DarkSouls1\Parameters\*.cs</Value>
</SonarQubeSetting>
</ItemGroup>
Expand Down
5 changes: 1 addition & 4 deletions src/SoulSplitter/UI/EldenRing/PositionViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ namespace SoulSplitter.UI.EldenRing
{
public class PositionViewModel : INotifyPropertyChanged
{
public PositionViewModel()
{
}

public Position Position = new Position();
public readonly Position Position = new Position();


public byte Area
Expand Down
7 changes: 3 additions & 4 deletions src/SoulSplitter/UI/FlagTrackerWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.indigo.xaml" />

<ResourceDictionary>
<converters:SplitObjectToDescriptionConverter x:Key="SplitObjectToDescriptionConverter"/>
<converters:ColorToBrushConverter x:Key="ColorToBrushConverter"/>
<converters:ColorToHexTextConverter x:Key="ColorToHexTextConverter"/>
<converters:DoubleToGridLengthConverter x:Key="DoubleToGridLengthConverter"/>
<validation:TextToRgbHexConverter x:Key="TextToRgbHexConverter"/>

<system:Int32 x:Key="InputCategory" >0</system:Int32>
<system:Int32 x:Key="InputFlag" >1</system:Int32>
<system:Int32 x:Key="InputButtons" >2</system:Int32>
Expand Down Expand Up @@ -197,7 +196,7 @@
<TextBox.Text>
<Binding UpdateSourceTrigger="PropertyChanged" Path="BackgroundColor" Converter="{StaticResource ColorToHexTextConverter}">
<Binding.ValidationRules>
<validation:TextToRgbHexConverter/>
<validation:TextToRgbHexValidator/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
Expand All @@ -222,7 +221,7 @@
<TextBox.Text>
<Binding UpdateSourceTrigger="PropertyChanged" Path="TextColor" Converter="{StaticResource ColorToHexTextConverter}">
<Binding.ValidationRules>
<validation:TextToRgbHexConverter/>
<validation:TextToRgbHexValidator/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@

namespace SoulSplitter.UI.Validation
{
internal class TextToRgbHexConverter : ValidationRule
public class TextToRgbHexValidator : ValidationRule
{
private static readonly Regex _rgbValidator = new Regex("^#(?:[0-9a-fA-F]{3}){1,2}$");
private static readonly Regex RgbValidator = new Regex("^#(?:[0-9a-fA-F]{3}){1,2}$");

public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
if (value is string hex && _rgbValidator.Match(hex).Success)
if (value is string hex && RgbValidator.Match(hex).Success)
{
return new ValidationResult(true, null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// This file is part of the SoulSplitter distribution (https://github.com/FrankvdStam/SoulSplitter).
// Copyright (c) 2022 Frank van der Stam.
// https://github.com/FrankvdStam/SoulSplitter/blob/main/LICENSE
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using Microsoft.VisualStudio.TestTools.UnitTesting;
using SoulSplitter.UI.Validation;

namespace SoulSplitter.Tests.UI.Validation
{
[TestClass]
public class TextToRgbHexValidatorTests
{
[TestMethod]
public void Validate()
{
var validator = new TextToRgbHexValidator();
Assert.IsTrue(validator.Validate("#123456", null).IsValid);
Assert.IsTrue(validator.Validate("#A2C4DD", null).IsValid);
}


[TestMethod]
public void Validate_Invalid_Hex()
{
var validator = new TextToRgbHexValidator();
Assert.IsFalse(validator.Validate("123456", null).IsValid);
Assert.IsFalse(validator.Validate("#12345G", null).IsValid);
Assert.IsFalse(validator.Validate("test", null).IsValid);
Assert.AreEqual("test is not a valid RGB hex", validator.Validate("test", null).ErrorContent);
}
}
}

0 comments on commit f6e0340

Please sign in to comment.