Skip to content

Commit

Permalink
Feature/qodana maintenance 2 (#95)
Browse files Browse the repository at this point in the history
* Allow non-returning functions

* Remove redundant namespace in solution

* fix naming

* Fix trailing comma solution wide

* multiple small fixes

* Remove unused usings

* Bugfix ER nullref when copying pos from game
  • Loading branch information
FrankvdStam authored Feb 22, 2025
1 parent a54928e commit d728a44
Show file tree
Hide file tree
Showing 73 changed files with 210 additions and 278 deletions.
1 change: 1 addition & 0 deletions SoulSplitter.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Elphael/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Erdtree/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Esgar/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=estus/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Evergaol/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Fallingstar/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Faroth/@EntryIndexedValue">True</s:Boolean>
Expand Down
1 change: 1 addition & 0 deletions qodana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ exclude:
- src/SoulMemory/DarkSouls1/Parameters
- name: SwitchExpressionHandlesSomeKnownEnumValuesWithExceptionInDefault
- name: ArrangeRedundantParentheses
- name: FunctionNeverReturns

dependencyOverrides:
#this unfortunately does not get detected automatically by qodana
Expand Down
13 changes: 6 additions & 7 deletions src/SoulMemory/ArmoredCore6/ArmoredCore6.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ArmoredCore6(IProcessHook? processHook = null)
_armoredCore6 = processHook ?? new ProcessHook("armoredcore6");

_eventFlagMan = new Pointer(_armoredCore6);
_noLogo = new Pointer(_armoredCore6);
var noLogo = new Pointer(_armoredCore6);
_fd4Time = new Pointer(_armoredCore6);
_menuMan = new Pointer(_armoredCore6);

Expand All @@ -41,7 +41,7 @@ public ArmoredCore6(IProcessHook? processHook = null)

_armoredCore6.PointerTreeBuilder
.ScanAbsolute("NoLogo", "33 f6 89 75 97 40 38 75 77 ? ? 48 89 31", 9)
.AddPointer(_noLogo);
.AddPointer(noLogo);

_armoredCore6.PointerTreeBuilder
.ScanRelative("FD4Time", "48 8b 0d ? ? ? ? 0f 28 c8 f3 0f 59 0d", 3, 7)
Expand All @@ -53,13 +53,12 @@ public ArmoredCore6(IProcessHook? processHook = null)

_armoredCore6.Hooked += () =>
{
_noLogo.WriteBytes(0x0, [0x90, 0x90]);
noLogo.WriteBytes(0x0, [0x90, 0x90]);
return InjectMods();
};
}

private readonly Pointer _eventFlagMan;
private readonly Pointer _noLogo;
private readonly Pointer _fd4Time;
private readonly Pointer _menuMan;

Expand All @@ -74,9 +73,9 @@ public bool IsLoadingScreenVisible()

public ResultErr<RefreshError> TryRefresh() => _armoredCore6.TryRefresh();

public SoulMemory.Memory.TreeBuilder GetTreeBuilder()
public Memory.TreeBuilder GetTreeBuilder()
{
var builder = new SoulMemory.Memory.TreeBuilder();
var builder = new Memory.TreeBuilder();
foreach (var node in _armoredCore6.PointerTreeBuilder.Tree)
{
if (node.PointerNodeType == PointerNodeType.RelativeScan)
Expand Down Expand Up @@ -187,7 +186,7 @@ private ResultOk<long> GetEventFlagAddress(uint eventFlagId, out int mask)
//These if statements can obviously be optimized in C#.
//They are written out like this explicitly, to match the game's assembly

long calculatedPointer = 0;
long calculatedPointer;

//jump to calculate ptr if zero
if (mysteryValue != 0)
Expand Down
2 changes: 1 addition & 1 deletion src/SoulMemory/DarkSouls1/Attribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ public enum Attribute : long
Intelligence = 0x60,
Faith = 0x68,
Humanity = 0x7C,
SoulLevel = 0x88,
SoulLevel = 0x88
}
4 changes: 2 additions & 2 deletions src/SoulMemory/DarkSouls1/Bonfire.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public enum Bonfire
OolacileTownshipDungeon = 1211964,

[Annotation(Name = "Chasm of the Abyss", Description = "Chasm of the Abyss")]
ChasmOfTheAbyss = 1211950,
ChasmOfTheAbyss = 1211950
}

[XmlType(Namespace = "SoulMemory.DarkSouls1")]
Expand All @@ -170,5 +170,5 @@ public enum BonfireState
Kindled2 = 30,

[Annotation(Name = "Kindled 3")]
Kindled3 = 40,
Kindled3 = 40
}
2 changes: 1 addition & 1 deletion src/SoulMemory/DarkSouls1/Boss.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,5 @@ public enum Boss : uint
ManusFatherOfTheAbyss = 11210002,

[Annotation(Name = "Sanctuary Guardian")]
SanctuaryGuardian = 11210000,
SanctuaryGuardian = 11210000
}
12 changes: 5 additions & 7 deletions src/SoulMemory/DarkSouls1/DarkSouls1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,14 @@ public ResultErr<RefreshError> TryRefresh()
Thread.Sleep(4000); //let the game boot
return _darkSouls1.TryRefresh();
}
else

var result = _darkSouls1.TryRefresh();
if (result.IsOk)
{
var result = _darkSouls1.TryRefresh();
if(result.IsErr)
{
_darkSouls1 = null;
return result;
}
return Result.Ok();
}
_darkSouls1 = null;
return result;
}
catch (Exception e)
{
Expand Down
8 changes: 4 additions & 4 deletions src/SoulMemory/DarkSouls1/DropMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ private void GuaranteeDrop(int rowId, int itemId)
private struct SwitchableDrop(ItemType switchItem, int rowId, int itemId1, int itemId2)
{
public bool ShouldSwitch = true;
public ItemType SwitchItem = switchItem;
public int RowId = rowId;
public int ItemId1 = itemId1;
public int ItemId2 = itemId2;
public readonly ItemType SwitchItem = switchItem;
public readonly int RowId = rowId;
public readonly int ItemId1 = itemId1;
public readonly int ItemId2 = itemId2;
}
}
86 changes: 11 additions & 75 deletions src/SoulMemory/DarkSouls1/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// 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 System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
Expand All @@ -25,13 +24,13 @@ namespace SoulMemory.DarkSouls1;
[ExcludeFromCodeCoverage]
public class Item(string name, int id, ItemType itemType, ItemCategory category, int stackLimit, ItemUpgrade upgrade)
{
public string Name { get; set; } = name;
public int Id { get; set; } = id;
public ItemType ItemType { get; set; } = itemType;
public ItemCategory Category { get; set; } = category;
public int StackLimit { get; set; } = stackLimit;
public string Name { get; } = name;
public int Id { get; } = id;
public ItemType ItemType { get; } = itemType;
public ItemCategory Category { get; } = category;
public int StackLimit { get; } = stackLimit;
public int Quantity { get; set; }
public ItemUpgrade Upgrade { get; set; } = upgrade;
public ItemUpgrade Upgrade { get; } = upgrade;
public ItemInfusion Infusion { get; set; }

Check warning on line 34 in src/SoulMemory/DarkSouls1/Item.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Auto-property accessor is never used (non-private accessibility)

Auto-property accessor 'Infusion.get' is never used
public int UpgradeLevel { get; set; }

Check warning on line 35 in src/SoulMemory/DarkSouls1/Item.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Auto-property accessor is never used (non-private accessibility)

Auto-property accessor 'UpgradeLevel.get' is never used

Expand All @@ -41,69 +40,6 @@ public override string ToString()
return $"{Name} {Quantity}";
}



public int GetGameValue()
{
var id = (int)ItemType;
if (Upgrade is ItemUpgrade.PyroFlame or ItemUpgrade.PyroFlameAscended)
{
id += UpgradeLevel * 100;
}
else
{
id += UpgradeLevel;
}

if (Upgrade is ItemUpgrade.Infusable or ItemUpgrade.InfusableRestricted)
{
id += (int)Upgrade;
}
return id;
}

public int MaxUpgrade
{
get
{
return Infusion switch
{
ItemInfusion.Normal => 15,
ItemInfusion.Chaos => 5,
ItemInfusion.Crystal => 5,
ItemInfusion.Divine => 10,
ItemInfusion.Enchanted => 5,
ItemInfusion.Fire => 10,
ItemInfusion.Lightning => 5,
ItemInfusion.Magic => 10,
ItemInfusion.Occult => 5,
ItemInfusion.Raw => 5,
_ => throw new NotSupportedException($"Unknown infusion type: {Infusion}")
};
}
}

public bool RestrictUpgrade
{
get
{
return Infusion switch
{
ItemInfusion.Normal => false,
ItemInfusion.Chaos => true,
ItemInfusion.Crystal => false,
ItemInfusion.Divine => false,
ItemInfusion.Enchanted => true,
ItemInfusion.Fire => false,
ItemInfusion.Lightning => false,
ItemInfusion.Magic => false,
ItemInfusion.Occult => true,
ItemInfusion.Raw => true,
_ => throw new NotSupportedException($"Unknown infusion type: {Infusion}")
};
}
}

public static readonly ReadOnlyCollection<Item> AllItems = new((List<Item>)
[
new Item("Catarina Helm" , 10000, ItemType.CatarinaHelm , ItemCategory.Armor , 1, ItemUpgrade.Unique ),
Expand Down Expand Up @@ -801,7 +737,7 @@ public bool RestrictUpgrade
new Item("Thank you Carving" , 511, ItemType.ThankyouCarving , ItemCategory.UsableItems , 1, ItemUpgrade.None ),
new Item("Very good! Carving" , 512, ItemType.VerygoodCarving , ItemCategory.UsableItems , 1, ItemUpgrade.None ),
new Item("I'm sorry Carving" , 513, ItemType.ImsorryCarving , ItemCategory.UsableItems , 1, ItemUpgrade.None ),
new Item("Help me! Carving" , 514, ItemType.HelpmeCarving , ItemCategory.UsableItems , 1, ItemUpgrade.None ),
new Item("Help me! Carving" , 514, ItemType.HelpmeCarving , ItemCategory.UsableItems , 1, ItemUpgrade.None )
]);
}

Expand All @@ -816,7 +752,7 @@ public enum ItemInfusion
Divine = 6,

Check notice on line 752 in src/SoulMemory/DarkSouls1/Item.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Type member is never used (non-private accessibility)

Enum member 'Divine' is never used
Occult = 7,

Check notice on line 753 in src/SoulMemory/DarkSouls1/Item.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Type member is never used (non-private accessibility)

Enum member 'Occult' is never used
Fire = 8,

Check notice on line 754 in src/SoulMemory/DarkSouls1/Item.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Type member is never used (non-private accessibility)

Enum member 'Fire' is never used
Chaos = 9,
Chaos = 9

Check notice on line 755 in src/SoulMemory/DarkSouls1/Item.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Type member is never used (non-private accessibility)

Enum member 'Chaos' is never used
}

public enum ItemUpgrade
Expand All @@ -827,7 +763,7 @@ public enum ItemUpgrade
Infusable = 3,
InfusableRestricted = 4,
PyroFlame = 5,

Check notice on line 765 in src/SoulMemory/DarkSouls1/Item.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Type member is never used (non-private accessibility)

Enum member 'PyroFlame' is never used
PyroFlameAscended = 6,
PyroFlameAscended = 6

Check notice on line 766 in src/SoulMemory/DarkSouls1/Item.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Type member is never used (non-private accessibility)

Enum member 'PyroFlameAscended' is never used
}

public enum ItemCategory
Expand All @@ -843,7 +779,7 @@ public enum ItemCategory
Spells,
SpellTools,
UpgradeMaterials,
UsableItems,
UsableItems
}

[XmlType(Namespace = "SoulMemory.DarkSouls1")]
Expand Down Expand Up @@ -1558,5 +1494,5 @@ public enum ItemType
ThankyouCarving,
VerygoodCarving,
ImsorryCarving,
HelpmeCarving,
HelpmeCarving
}
6 changes: 3 additions & 3 deletions src/SoulMemory/DarkSouls1/ItemReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace SoulMemory.DarkSouls1;

internal static class ItemReader
{
internal static List<Item> GetCurrentInventoryItems(byte[] data, int listCount, int itemCount, int keyCount)
internal static List<Item> GetCurrentInventoryItems(byte[] data, int listCount)
{
var items = new List<Item>();

Expand Down Expand Up @@ -68,12 +68,12 @@ internal static List<Item> GetCurrentInventoryItems(byte[] data, int listCount,
}

//Decode item
var id = 0;
int id;
var infusion = ItemInfusion.Normal;
var level = 0;

//if 4 or less digits -> non-upgradable item.
if (categories.Contains(ItemCategory.Consumables) && item is >= 200 and <= 215 && !items.Any(j => j.ItemType == ItemType.EstusFlask))
if (categories.Contains(ItemCategory.Consumables) && item is >= 200 and <= 215 && items.All(j => j.ItemType != ItemType.EstusFlask))
{
var estus = Item.AllItems.First(j => j.ItemType == ItemType.EstusFlask);
var instance = new Item(estus.Name, estus.Id, estus.ItemType, estus.Category, estus.StackLimit, estus.Upgrade);
Expand Down
2 changes: 1 addition & 1 deletion src/SoulMemory/DarkSouls1/KnownFlag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,5 @@ public enum KnownFlag : uint
CutsceneSkippedWarpToAnorLondo = 11500210,

[Annotation(Name = "Goughless Kalameeth Death Animation 11210063", Description = "Other")]
GoughlessKalameethDeathAnimation = 11210063,
GoughlessKalameethDeathAnimation = 11210063
}
Loading

0 comments on commit d728a44

Please sign in to comment.