Skip to content

Commit

Permalink
Merge pull request #13 from FrankvdStam/feature/sonar-issues
Browse files Browse the repository at this point in the history
Feature/sonar issues
  • Loading branch information
FrankvdStam authored Sep 9, 2023
2 parents 6d00fe4 + 9a890af commit 7c7b00b
Show file tree
Hide file tree
Showing 39 changed files with 175 additions and 544 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"FrankvdStam_SoulSplitter_AYT9tJW7QlZ0fhD27xsa" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="${{ secrets.SONAR_HOST_URL }}" /d:sonar.exclusions=src/cli/Program.cs /d:sonar.cs.opencover.reportsPaths=TestResults/*.xml
.\.sonar\scanner\dotnet-sonarscanner begin /k:"FrankvdStam_SoulSplitter_AYT9tJW7QlZ0fhD27xsa" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="${{ secrets.SONAR_HOST_URL }}" /d:sonar.cs.opencover.reportsPaths=TestResults/*.xml
dotnet build src/soulsplitter/soulsplitter.csproj
dotnet test -p:CollectCoverage=true -p:CoverletOutput=../../TestResults/ -p:MergeWith=../../TestResults/ -p:CoverletOutputFormat=opencover
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
Expand Down
4 changes: 1 addition & 3 deletions src/SoulMemory/ArmoredCore6/ArmoredCore6.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ namespace SoulMemory.ArmoredCore6
public class ArmoredCore6 : IGame
{
private readonly IProcessHook _armoredCore6;

public ArmoredCore6() : this(null) { }


public ArmoredCore6(IProcessHook processHook = null)
{
_armoredCore6 = processHook ?? new ProcessHook("armoredcore6");
Expand Down
3 changes: 1 addition & 2 deletions src/SoulMemory/DarkSouls1/DropMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public void UpdateAllAchievements()
var s = temp; //structs need to be put in a variable in order to be mutable. Meme.
if (s.ShouldSwitch && items.Any(j => j.ItemType == s.SwitchItem))
{
//Console.WriteLine($"Switching {s.RowId} {s.SwitchItem}");
GuaranteeDrop(s.RowId, s.ItemId2);
s.ShouldSwitch = false;
}
Expand Down Expand Up @@ -110,7 +109,7 @@ private void GuaranteeDrop(int rowId, int itemId)
}


private List<SwitchableDrop> _switchableWeapons = new List<SwitchableDrop>()
private readonly List<SwitchableDrop> _switchableWeapons = new List<SwitchableDrop>()
{
//Darkroot
new SwitchableDrop(ItemType.StoneGreatsword , 23800000, 306000 , 1503000),
Expand Down
5 changes: 2 additions & 3 deletions src/SoulMemory/DarkSouls1/Ptde.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,7 @@ public void WriteWeaponDescription(uint weaponId, string description)
//weaponName 0x1d0 - 0x30
//weaponInfo 0x1cc - 0x58
//weaponCaption 0x1ac - 0x68

//var weaponDescriptionsPointer = _msgMan.CreatePointerFromAddress(0x1ac);

var weaponDescriptionsPointer = _msgMan.CreatePointerFromAddress(0x68);

if (!_weaponDescriptionsTable.Any())
Expand All @@ -429,7 +428,7 @@ public void WriteWeaponDescription(uint weaponId, string description)

var dataPointer = weaponDescriptionsPointer.CreatePointerFromAddress(0x14);
var textOffset = dataPointer.ReadInt32(weaponDescription.DataOffset * 4);
var str = weaponDescriptionsPointer.ReadUnicodeString(out int length, offset: textOffset);
weaponDescriptionsPointer.ReadUnicodeString(out int length, offset: textOffset);

var buffer = Encoding.Unicode.GetBytes(description);
var bytes = new byte[length];
Expand Down
6 changes: 4 additions & 2 deletions src/SoulMemory/DarkSouls3/DarkSouls3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ private ResultErr<RefreshError> InitPointers()
{
try
{
if (!Version.TryParse(_process.MainModule.FileVersionInfo.ProductVersion, out Version v))
var versionString = _process?.MainModule?.FileVersionInfo.ProductVersion ?? "Read failed";

if (!Version.TryParse(versionString, out Version v))
{
return Result.Err(new RefreshError(RefreshErrorReason.UnknownException, $"Unable to determine game version: {_process?.MainModule?.FileVersionInfo?.ProductVersion}"));
return Result.Err(new RefreshError(RefreshErrorReason.UnknownException, $"Unable to determine game version: {versionString}"));
}

//Clear count: 0x78 -> likely subject to the same shift that happens to IGT offset
Expand Down
23 changes: 4 additions & 19 deletions src/SoulMemory/EldenRing/EldenRing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,6 @@ public class EldenRing : IGame
private long _mapIdOffset;
private long _playerInsOffset;

public EldenRing()
{
_applyIgtFix = true;
}

public EldenRing(bool applyIgtFix = true)
{
_applyIgtFix = applyIgtFix;
}

private readonly bool _applyIgtFix;


#region Refresh/init/reset ================================================================================================
public Process GetProcess() => _process;
Expand Down Expand Up @@ -144,9 +132,10 @@ private ResultErr<RefreshError> InitPointers()
{
try
{
if (!Version.TryParse(_process.MainModule.FileVersionInfo.ProductVersion, out Version v))
var versionString = _process?.MainModule?.FileVersionInfo.ProductVersion ?? "Read failed";
if (!Version.TryParse(versionString, out Version v))
{
return Result.Err(new RefreshError(RefreshErrorReason.UnknownException, $"Unable to determine game version: {_process?.MainModule?.FileVersionInfo?.ProductVersion}"));
return Result.Err(new RefreshError(RefreshErrorReason.UnknownException, $"Unable to determine game version: {versionString}"));
}

InitializeOffsets(v);
Expand All @@ -158,7 +147,7 @@ private ResultErr<RefreshError> InitPointers()
return result;
}

if (_applyIgtFix && !ApplyIgtFix())
if (!ApplyIgtFix())
{
return Result.Err(new RefreshError(RefreshErrorReason.UnknownException, "MIGT injection failed"));
}
Expand Down Expand Up @@ -555,10 +544,6 @@ public void WriteInGameTimeMilliseconds(int milliseconds)
_igt.WriteInt32(milliseconds);
}

public void ResetIgt()
{
_igt.WriteInt32(0);
}
#endregion

#region B3's IGT fix
Expand Down
20 changes: 1 addition & 19 deletions src/SoulMemory/Memory/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,7 @@ public static string ToHexString(this byte[] bytes)
{
return BitConverter.ToString(bytes).Replace("-", " ");
}

public static string ToHexFileString(this byte[] bytes)
{
var sb = new StringBuilder();
var newline = 0;
foreach (var b in bytes)
{
sb.AppendFormat("{0:x2}", b);
newline++;

if (newline >= 10)
{
sb.AppendLine();
newline = 0;
}
}
return sb.ToString();
}


public static string GetDisplayName(this Enum enumValue)
{
var displayName = enumValue
Expand Down
33 changes: 1 addition & 32 deletions src/SoulMemory/Memory/IMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface IMemory

public class ByteArrayMemory : IMemory
{
private byte[] _data;
private readonly byte[] _data;
public ByteArrayMemory(byte[] data)
{
_data = data;
Expand Down Expand Up @@ -63,37 +63,6 @@ public void WriteBytes(long? offset, byte[] bytes)
}
}

public class ProcessMemory : IMemory
{
private Process _process;
public ProcessMemory(Process process)
{
_process = process;
}

public byte[] ReadBytes(long? offset, int length)
{
ResultOk<byte[]> result = null;
if (offset != null)
{
result = _process.ReadProcessMemory(offset.Value, length);
}

if (result != null && result.IsOk)
{
return result.Unwrap();
}

var buffer = new byte[length];
return buffer;
}

public void WriteBytes(long? offset, byte[] bytes)
{
_process.WriteProcessMemory(offset.Value, bytes);
}
}

public static class MemoryExtensions
{
#region Read
Expand Down
2 changes: 1 addition & 1 deletion src/SoulMemory/MemoryV2/ByteArrayMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace SoulMemory.MemoryV2
{
public class ByteArrayMemory : IMemory
{
private byte[] _data;
private readonly byte[] _data;
public ByteArrayMemory(byte[] data)
{
_data = data;
Expand Down
4 changes: 2 additions & 2 deletions src/SoulMemory/MemoryV2/Memory/Pointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class Pointer : IMemory

public Pointer(IMemory memory)
{
if (memory is Pointer p)
if (memory is Pointer)
{
throw new ArgumentException("Can't initialize pointer object with another pointer.", nameof(memory));
}
Expand All @@ -41,7 +41,7 @@ public Pointer(IMemory memory)

public Pointer(IMemory memory, params long[] offsets)
{
if (memory is Pointer p)
if (memory is Pointer)
{
throw new ArgumentException("Can't initialize pointer object with another pointer.", nameof(memory));
}
Expand Down
2 changes: 1 addition & 1 deletion src/SoulMemory/MemoryV2/PointerTreeBuilder/PointerNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class PointerNode

//used for pointers
public long[] Offsets = new long[] { };
public Pointer Pointer;// = new Pointer();
public Pointer Pointer;

public List<PointerNode> Pointers = new List<PointerNode>();

Expand Down
9 changes: 2 additions & 7 deletions src/SoulMemory/MemoryV2/Process/ProcessWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ public class ProcessWrapper : IProcessWrapper

public List<ProcessWrapperModule> GetProcessModules()
{
var result = new List<ProcessWrapperModule>();
foreach (var pm in _process.Modules)
{
result.Add(ProcessWrapperModule.FromProcessModule((ProcessModule)pm));
}
return result;
return (from object pm in _process.Modules select ProcessWrapperModule.FromProcessModule((ProcessModule)pm)).ToList();
}

/// <summary>
Expand Down Expand Up @@ -91,7 +86,7 @@ public byte[] ReadBytes(long offset, int length)
{
return new byte[length];
}
return _process?.ReadProcessMemoryNoError(offset, length);
return _process.ReadProcessMemoryNoError(offset, length);
}

public void WriteBytes(long offset, byte[] bytes) => _process?.WriteProcessMemoryNoError(offset, bytes);
Expand Down
14 changes: 7 additions & 7 deletions src/SoulMemory/Parameters/BaseParam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,28 @@ namespace SoulMemory.Parameters
{
public abstract class BaseParam
{
private List<(PropertyInfo propertyInfo, ParamFieldAttribute paramFieldAttribute)> ParamFieldPropertyCache;
private List<(PropertyInfo propertyInfo, ParamBitFieldAttribute paramFieldAttribute)> ParamBitfieldPropertyCache;
private readonly List<(PropertyInfo propertyInfo, ParamFieldAttribute paramFieldAttribute)> _paramFieldPropertyCache;
private readonly List<(PropertyInfo propertyInfo, ParamBitFieldAttribute paramFieldAttribute)> _paramBitfieldPropertyCache;

protected BaseParam(Pointer basePointer, ByteArrayMemory memory, long offset, ParamTableEntry paramTableEntry)
{
BasePointer = basePointer;
Id = paramTableEntry.Id;

ParamFieldPropertyCache = GetType()
_paramFieldPropertyCache = GetType()
.GetProperties()
.Where(i => i.IsDefined(typeof(ParamFieldAttribute)))
.Select(i => (i, i.GetCustomAttribute<ParamFieldAttribute>()))
.OrderBy(i => i.Item2.Offset)
.ToList();

ParamBitfieldPropertyCache = GetType()
_paramBitfieldPropertyCache = GetType()
.GetProperties()
.Where(i => i.IsDefined(typeof(ParamBitFieldAttribute)))
.Select(i => (i, i.GetCustomAttribute<ParamBitFieldAttribute>()))
.ToList();

foreach (var field in ParamFieldPropertyCache)
foreach (var field in _paramFieldPropertyCache)
{
var fieldOffset = offset + field.paramFieldAttribute.Offset;
var paramType = field.paramFieldAttribute.ParamType;
Expand Down Expand Up @@ -156,7 +156,7 @@ protected void WriteParamField<T>(ref T field, T value, [CallerMemberName] strin

protected T GetbitfieldValue<T>(T field, [CallerMemberName] string propertyName = null)
{
var bitfield = ParamBitfieldPropertyCache.First(i => i.propertyInfo.Name == propertyName);
var bitfield = _paramBitfieldPropertyCache.First(i => i.propertyInfo.Name == propertyName);
var currentValue = (long)Convert.ChangeType(field, typeof(long));

var bitIndex = 0;
Expand All @@ -176,7 +176,7 @@ protected T GetbitfieldValue<T>(T field, [CallerMemberName] string propertyName

protected void SetBitfieldValue<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
{
var bitfield = ParamBitfieldPropertyCache.First(i => i.propertyInfo.Name == propertyName);
var bitfield = _paramBitfieldPropertyCache.First(i => i.propertyInfo.Name == propertyName);
var currentValue = (long)Convert.ChangeType(field, typeof(long));
var newValue = (long)Convert.ChangeType(value, typeof(long));

Expand Down
6 changes: 3 additions & 3 deletions src/SoulMemory/Parameters/ParamClassGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private static List<BaseField> ParseFields(List<PreParsedField> preParsedFields)
currentBitfield.Bitfields.Add((currentField.Name, currentField.Bits.Value));

//Check if this is the last bitfield in this sequence
if (nextField == null || nextField?.Bits == null)
if (nextField?.Bits == null)
{
result.Add(currentBitfield);
currentBitfield = null;
Expand Down Expand Up @@ -275,7 +275,7 @@ private class BaseField
public long Offset;
}

private class Field : BaseField
private sealed class Field : BaseField
{
public Field(long offset, string name, ParamType paramType, int? arraySize = null)
{
Expand All @@ -289,7 +289,7 @@ public Field(long offset, string name, ParamType paramType, int? arraySize = nul
public int? ArraySize;
}

private class Bitfield : BaseField
private sealed class Bitfield : BaseField
{
public Bitfield(long offset, ParamType paramType)
{
Expand Down
2 changes: 0 additions & 2 deletions src/SoulMemory/Parameters/ParamReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public static class ParamReader
{
public static List<TextTableEntry> GetTextTables(Pointer textBasePointer)
{
//var dataOffset = textBasePointer.ReadUInt16(0x14);
var rowCount = textBasePointer.ReadUInt16(0xc);

var tableBytes = textBasePointer.ReadBytes(12 * rowCount, 0x18);
Expand Down Expand Up @@ -81,7 +80,6 @@ public static List<T> ReadParam<T>(Pointer paramBasePointer) where T : BaseParam

var rowBasePointer = paramBasePointer.Copy();
rowBasePointer.Offsets.Clear();
//var baseasdf = (IntPtr)paramBasePointer.ReadInt32();
rowBasePointer.BaseAddress = paramBasePointer.BaseAddress + dataOffset + i * rowSize;

parameters.Add(
Expand Down
1 change: 0 additions & 1 deletion src/SoulMemory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ ScreenState GetScreenState(); //Returns the current "scre
bool IsBlackscreenActive(); //Reads a combination of flags in memory to determine of a blackscreen is active
List<Item> ReadInventory(); //Reads the player's inventory. A part of the inventory seems stored in event flags (especially key-items) so be warned: some things might not be in this list
void WriteInGameTimeMilliseconds(int milliseconds); //Overwrite the game's in game time with a new value (used in blackscreen removal to create the illusion of a paused timer)
void ResetIgt(); //Overwrite the game's in game time with 0 (used to prepare NG+ save files)
```

### Armored Core 6
Expand Down
5 changes: 0 additions & 5 deletions src/SoulMemory/Sekiro/Sekiro.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,6 @@ private ResultErr<RefreshError> InitPointers()
}

ApplySavefileMods();

//Task.Run(() =>
//{
// BitBlt = this.GetBitBlt(_files, _bitBltValues);
//});

return Result.Ok();
}
Expand Down
7 changes: 6 additions & 1 deletion src/SoulMemory/SoulMemory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<ItemGroup>
<SonarQubeSetting Include="sonar.exclusions">
<Value>DarkSouls1\Parameters\*.cs</Value>
</SonarQubeSetting>
</ItemGroup>
<ItemGroup>
<Compile Remove="resources\**" />
<EmbeddedResource Remove="resources\**" />
<None Remove="resources\**" />
Expand Down
2 changes: 1 addition & 1 deletion src/SoulMemory/soulsmods/Soulsmods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace SoulMemory.soulsmods
{
public class Soulsmods
public static class Soulsmods
{
public static void Inject(Process process)
{
Expand Down
Loading

0 comments on commit 7c7b00b

Please sign in to comment.