Skip to content

Commit

Permalink
=Updated for new HUD
Browse files Browse the repository at this point in the history
  • Loading branch information
vadash committed Feb 1, 2021
0 parents commit d9adc39
Show file tree
Hide file tree
Showing 12 changed files with 459 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/
13 changes: 13 additions & 0 deletions .idea/.idea.EssenceDrainContagion/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/.idea.EssenceDrainContagion/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.EssenceDrainContagion/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.EssenceDrainContagion/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

177 changes: 177 additions & 0 deletions EssenceDrainContagion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using ExileCore;
using ExileCore.PoEMemory.Components;
using ExileCore.PoEMemory.FilesInMemory;
using ExileCore.PoEMemory.MemoryObjects;
using ExileCore.Shared.Enums;
using SharpDX;

namespace EssenceDrainContagion
{
public class EssenceDrainContagion : BaseSettingsPlugin<EssenceDrainContagionSettings>
{
private readonly Stopwatch _aimTimer = Stopwatch.StartNew();
private readonly List<Entity> _entities = new List<Entity>();
private IDictionary<string, StatsDat.StatRecord> _statRecords;
private bool _aiming;
private Vector2 _oldMousePos;
private HashSet<string> _ignoredMonsters;

private readonly string[] _ignoredBuffs = {
"capture_monster_captured",
"capture_monster_disappearing"
};

private readonly string[] _lightLessGrub =
{
"Metadata/Monsters/HuhuGrub/AbyssGrubMobile",
"Metadata/Monsters/HuhuGrub/AbyssGrubMobileMinion"
};

private readonly string[] _raisedZombie =
{
"Metadata/Monsters/RaisedZombies/RaisedZombieStandard",
"Metadata/Monsters/RaisedZombies/RaisedZombieMummy",
"Metadata/Monsters/RaisedZombies/NecromancerRaisedZombieStandard"
};

private readonly string[] _summonedSkeleton =
{
"Metadata/Monsters/RaisedSkeletons/RaisedSkeletonStandard",
"Metadata/Monsters/RaisedSkeletons/RaisedSkeletonStatue",
"Metadata/Monsters/RaisedSkeletons/RaisedSkeletonMannequin",
"Metadata/Monsters/RaisedSkeletons/RaisedSkeletonStatueMale",
"Metadata/Monsters/RaisedSkeletons/RaisedSkeletonStatueGold",
"Metadata/Monsters/RaisedSkeletons/RaisedSkeletonStatueGoldMale",
"Metadata/Monsters/RaisedSkeletons/NecromancerRaisedSkeletonStandard",
"Metadata/Monsters/RaisedSkeletons/TalismanRaisedSkeletonStandard"
};

public override bool Initialise()
{
LoadIgnoredMonsters($@"{DirectoryFullName}\Ignored Monsters.txt");
_statRecords = GameController.Files.Stats.records;
return true;
}

private void LoadIgnoredMonsters(string fileName)
{
_ignoredMonsters = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
if (!File.Exists(fileName))
{
LogError($@"Failed to find {fileName}", 10);
return;
}

foreach (var line in File.ReadAllLines(fileName))
if (!string.IsNullOrWhiteSpace(line) && !line.StartsWith("#"))
_ignoredMonsters.Add(line.Trim().ToLower());
}

public override void Render()
{
if (_aimTimer.ElapsedMilliseconds < 100) return;

try
{
if (!Input.IsKeyDown(Keys.RButton))
_oldMousePos = Input.MousePosition;
if (Input.IsKeyDown(Keys.RButton)
&& !GameController.Game.IngameState.IngameUi.InventoryPanel.IsVisible
&& !GameController.Game.IngameState.IngameUi.OpenLeftPanel.IsVisible)
{
_aiming = true;
var bestTarget = ScanValidMonsters()?.FirstOrDefault();
Attack(bestTarget);
}
if (!Input.IsKeyDown(Keys.RButton) && _aiming)
Input.SetCursorPos(_oldMousePos);
_aiming = false;
}
catch (Exception e)
{
LogError("Something went wrong? " + e, 5);
}

_aimTimer.Restart();
}

public override void EntityAdded(Entity entityWrapper) { _entities.Add(entityWrapper); }

public override void EntityRemoved(Entity entityWrapper) { _entities.Remove(entityWrapper); }

private void Attack(Tuple<float, Entity> bestTarget)
{
if (bestTarget == null) return;
var position = GameController.Game.IngameState.Camera.WorldToScreen(bestTarget.Item2.Pos);
var windowRectangle = GameController.Window.GetWindowRectangle();
if (!position.IsInside(windowRectangle)) return;
var offset = GameController.Window.GetWindowRectangle().TopLeft;
Input.SetCursorPos(position + offset);
Input.KeyPressRelease(bestTarget.Item2.HasBuff("contagion", true) ? Settings.EssenceDrainKey.Value : Settings.ContagionKey.Value);
}

private IEnumerable<Tuple<float, Entity>> ScanValidMonsters()
{
return _entities?.Where(x =>
x.HasComponent<Monster>() &&
x.IsAlive &&
x.IsHostile &&
x.GetStatValue("ignored_by_enemy_target_selection", _statRecords) == 0 &&
x.GetStatValue("cannot_die", _statRecords) == 0 &&
x.GetStatValue("cannot_be_damaged", _statRecords) == 0 &&
!_ignoredBuffs.Any(b => x.HasBuff(b)) &&
!_ignoredMonsters.Any(im => x.Path.ToLower().Contains(im))
)
.Select(x => new Tuple<float, Entity>(ComputeWeight(x), x))
.Where(x => x.Item1 < Settings.AimRange)
.OrderByDescending(x => x.Item1);
}

private float ComputeWeight(Entity entity)
{
var weight = 0;
weight -= GameController.Player.DistanceFrom(entity) / 10;

if (entity.GetComponent<Life>().HasBuff("contagion")) weight += Settings.HasContagionWeight;
if (entity.GetComponent<Life>().HasBuff("capture_monster_trapped")) weight += Settings.capture_monster_trapped;
if (entity.GetComponent<Life>().HasBuff("harbinger_minion_new")) weight += Settings.HarbingerMinionWeight;
if (entity.GetComponent<Life>().HasBuff("capture_monster_enraged")) weight += Settings.capture_monster_enraged;
if (entity.Path.Contains("/BeastHeart")) weight += Settings.BeastHearts;
if (entity.Path == "Metadata/Monsters/Tukohama/TukohamaShieldTotem") weight += Settings.TukohamaShieldTotem;

switch (entity.GetComponent<ObjectMagicProperties>().Rarity)
{
case MonsterRarity.Unique:
weight += Settings.UniqueRarityWeight;
break;
case MonsterRarity.Rare:
weight += Settings.RareRarityWeight;
break;
case MonsterRarity.Magic:
weight += Settings.MagicRarityWeight;
break;
case MonsterRarity.White:
weight += Settings.NormalRarityWeight;
break;
case MonsterRarity.Error:
break;
default:
throw new ArgumentOutOfRangeException();
}

if (entity.HasComponent<DiesAfterTime>()) weight += Settings.DiesAfterTime;
if (_summonedSkeleton.Any(path => entity.Path == path)) weight += Settings.SummonedSkeoton;
if (_raisedZombie.Any(path => entity.Path == path)) weight += Settings.RaisedZombie;
if (_lightLessGrub.Any(path => entity.Path == path)) weight += Settings.LightlessGrub;
if (entity.Path.Contains("TaniwhaTail")) weight += Settings.TaniwhaTail;
return weight;
}
}

}
87 changes: 87 additions & 0 deletions EssenceDrainContagion.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D13AAB32-4C49-46C8-8B1F-1887CAEA3825}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EssenceDrainContagion</RootNamespace>
<AssemblyName>EssenceDrainContagion</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\..\..\PoeHelper\Plugins\Compiled\EssenceDrainContagion\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\..\..\PoeHelper\Plugins\Compiled\EssenceDrainContagion\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="ExileCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\..\PoEHelper\ExileCore.dll</HintPath>
</Reference>
<Reference Include="SharpDX, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1">
<HintPath>..\..\..\..\PoEHelper\SharpDX.dll</HintPath>
</Reference>
<Reference Include="SharpDX.D3DCompiler, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1">
<HintPath>..\..\..\..\PoEHelper\SharpDX.D3DCompiler.dll</HintPath>
</Reference>
<Reference Include="SharpDX.Desktop, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1">
<HintPath>..\..\..\..\PoEHelper\SharpDX.Desktop.dll</HintPath>
</Reference>
<Reference Include="SharpDX.Direct2D1, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1">
<HintPath>..\..\..\..\PoEHelper\SharpDX.Direct2D1.dll</HintPath>
</Reference>
<Reference Include="SharpDX.Direct3D11, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1">
<HintPath>..\..\..\..\PoEHelper\SharpDX.Direct3D11.dll</HintPath>
</Reference>
<Reference Include="SharpDX.DXGI, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1">
<HintPath>..\..\..\..\PoEHelper\SharpDX.DXGI.dll</HintPath>
</Reference>
<Reference Include="SharpDX.Mathematics, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1">
<HintPath>..\..\..\..\PoEHelper\SharpDX.Mathematics.dll</HintPath>
</Reference>
<Reference Include="SharpDX.XAudio2, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1">
<HintPath>..\..\..\..\PoEHelper\SharpDX.XAudio2.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<HintPath>..\..\..\..\PoEHelper\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Windows" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="EssenceDrainContagion.cs" />
<Compile Include="EssenceDrainContagionSettings.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->

</Project>
16 changes: 16 additions & 0 deletions EssenceDrainContagion.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EssenceDrainContagion", "EssenceDrainContagion.csproj", "{D13AAB32-4C49-46C8-8B1F-1887CAEA3825}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D13AAB32-4C49-46C8-8B1F-1887CAEA3825}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D13AAB32-4C49-46C8-8B1F-1887CAEA3825}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D13AAB32-4C49-46C8-8B1F-1887CAEA3825}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D13AAB32-4C49-46C8-8B1F-1887CAEA3825}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
11 changes: 11 additions & 0 deletions EssenceDrainContagion.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005Cprojects_005CPoEHelper_005CExileCore_002Edll/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005Cprojects_005CPoEHelper_005CSharpDX_002ED3DCompiler_002Edll/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005Cprojects_005CPoEHelper_005CSharpDX_002EDesktop_002Edll/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005Cprojects_005CPoEHelper_005CSharpDX_002EDirect2D1_002Edll/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005Cprojects_005CPoEHelper_005CSharpDX_002EDirect3D11_002Edll/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005Cprojects_005CPoEHelper_005CSharpDX_002Edll/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005Cprojects_005CPoEHelper_005CSharpDX_002EDXGI_002Edll/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005Cprojects_005CPoEHelper_005CSharpDX_002EMathematics_002Edll/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005Cprojects_005CPoEHelper_005CSharpDX_002EXAudio2_002Edll/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005Cprojects_005CPoEHelper_005CSystem_002ENumerics_002EVectors_002Edll/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
39 changes: 39 additions & 0 deletions EssenceDrainContagionSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Windows.Forms;
using ExileCore.Shared.Interfaces;
using ExileCore.Shared.Nodes;

namespace EssenceDrainContagion
{
public class EssenceDrainContagionSettings : ISettings
{
public HotkeyNode AimKey { get; set; } = Keys.RButton;
public HotkeyNode ContagionKey { get; set; } = Keys.Z;
public HotkeyNode EssenceDrainKey { get; set; } = Keys.R;
public RangeNode<int> AimRange { get; set; } = new RangeNode<int>(600, 1, 1000);
public RangeNode<int> AimLoopDelay { get; set; } = new RangeNode<int>(124, 1, 200);
public ToggleNode RMousePos { get; set; } = new ToggleNode(false);
public ToggleNode AimPlayers { get; set; } = new ToggleNode(true);
public ToggleNode DebugMonsterWeight { get; set; } = new ToggleNode(false);
public ToggleNode ShowAimRange { get; set; } = new ToggleNode(false);
public RangeNode<int> HasContagionWeight { get; set; } = new RangeNode<int>(20, -200, 200);
public RangeNode<int> UniqueRarityWeight { get; set; } = new RangeNode<int>(20, -200, 200);
public RangeNode<int> RareRarityWeight { get; set; } = new RangeNode<int>(15, -200, 200);
public RangeNode<int> MagicRarityWeight { get; set; } = new RangeNode<int>(10, -200, 200);
public RangeNode<int> NormalRarityWeight { get; set; } = new RangeNode<int>(5, -200, 200);
public RangeNode<int> CannotDieAura { get; set; } = new RangeNode<int>(100, -200, 200);
public RangeNode<int> capture_monster_trapped { get; set; } = new RangeNode<int>(200, -200, 200);
public RangeNode<int> capture_monster_enraged { get; set; } = new RangeNode<int>(-50, -200, 200);
public RangeNode<int> BeastHearts { get; set; } = new RangeNode<int>(80, -200, 200);
public RangeNode<int> TukohamaShieldTotem { get; set; } = new RangeNode<int>(70, -200, 200);
public RangeNode<int> StrongBoxMonster { get; set; } = new RangeNode<int>(25, -200, 200);
public RangeNode<int> RaisesUndead { get; set; } = new RangeNode<int>(30, -200, 200);
public RangeNode<int> SummonedSkeoton { get; set; } = new RangeNode<int>(-30, -200, 200);
public RangeNode<int> RaisedZombie { get; set; } = new RangeNode<int>(-30, -200, 200);
public RangeNode<int> LightlessGrub { get; set; } = new RangeNode<int>(-30, -200, 200);
public RangeNode<int> TaniwhaTail { get; set; } = new RangeNode<int>(-40, -200, 200);
public RangeNode<int> DiesAfterTime { get; set; } = new RangeNode<int>(-50, -200, 200);
public RangeNode<int> BreachMonsterWeight { get; set; } = new RangeNode<int>(50, -200, 200);
public RangeNode<int> HarbingerMinionWeight { get; set; } = new RangeNode<int>(50, -200, 200);
public ToggleNode Enable { get; set; } = new ToggleNode(true);
}
}
Loading

0 comments on commit d9adc39

Please sign in to comment.