Skip to content

Commit

Permalink
Added error output.
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankvdStam committed Mar 9, 2022
1 parent d65e9a2 commit 7515036
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 46 deletions.
Binary file modified Components/SoulMemory.dll
Binary file not shown.
Binary file modified Components/SoulSplitter.dll
Binary file not shown.
11 changes: 11 additions & 0 deletions Components/Updates.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<updates>
<update version="0.0.7">
<files>
<file path="Components/SoulMemory.dll" status="changed" />
<file path="Components/SoulSplitter.dll" status="changed" />
</files>
<changelog>
<change>Fixed horizontal layout</change>
<change>Added error output to help diagnose problems</change>
<change>Changed auto update URL</change>
</changelog>
</update>
<update version="0.0.6">
<files>
<file path="Components/SoulSplitter.dll" status="changed" />
Expand Down
1 change: 0 additions & 1 deletion SoulSplitter.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
LICENSE = LICENSE
Components\MaterialDesignColors.dll = Components\MaterialDesignColors.dll
README.md = README.md
EndProjectSection
EndProject
Expand Down
27 changes: 22 additions & 5 deletions src/SoulMemory/EldenRing/EldenRing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class EldenRing : ITimeable
public Exception Exception;

private Process _process = null;


private Pointer _igt;
private Pointer _playerIns;
Expand Down Expand Up @@ -45,9 +46,9 @@ private bool InitPointers()

return true;
}
catch (Exception ex)
catch (Exception e)
{
Exception = ex;
Exception = e;
return false;
}
}
Expand Down Expand Up @@ -103,27 +104,43 @@ public ScreenState GetScreenState()
}
return ScreenState.Unknown;
}

public void Refresh()

private bool _pointersInitialized = false;
public bool Refresh()
{
if (_process == null)
{
_process = Process.GetProcesses().FirstOrDefault(i => i.ProcessName.ToLower().StartsWith("eldenring"));
if (_process != null)
{
InitPointers();
if (InitPointers())
{
_pointersInitialized = true;
return true;
}
else
{
var pointerScanException = new Exception($"Pointer scan failed.\nIs EAC disabled?\n{Exception.Message}", Exception);
Exception = pointerScanException;
}
}

return false;
}
else
{
if (_process.HasExited)
{
_process = null;
_pointersInitialized = false;
ResetPointers();
}

return _pointersInitialized;
}
}

public bool Attached => _process != null;

#region Timeable
public int GetInGameTimeMilliseconds()
Expand Down
4 changes: 2 additions & 2 deletions src/SoulMemory/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.5")]
[assembly: AssemblyFileVersion("0.0.5")]
[assembly: AssemblyVersion("0.0.7")]
[assembly: AssemblyFileVersion("0.0.7")]
8 changes: 4 additions & 4 deletions src/SoulSplitter/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("LiveSplit.DarkSouls2")]
[assembly: AssemblyTitle("SoulMemory")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LiveSplit.DarkSouls2")]
[assembly: AssemblyProduct("SoulMemory")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.6")]
[assembly: AssemblyFileVersion("0.0.6")]
[assembly: AssemblyVersion("0.0.7")]
[assembly: AssemblyFileVersion("0.0.7")]
100 changes: 68 additions & 32 deletions src/SoulSplitter/SoulComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Threading;
using System.Xml;
using System.Xml.Serialization;
using LiveSplit.Web;
using SoulSplitter.Splits;
using SoulSplitter.Splitters;
using SoulSplitter.UI;
using SoulSplitter.UI.ViewModel;
using Brushes = System.Drawing.Brushes;

namespace SoulSplitter
{
Expand All @@ -37,15 +40,42 @@ public SoulComponent(LiveSplitState state = null)

public void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode)
{
_splitter.Update(MainControlFormsWrapper.MainViewModel.EldenRingViewModel);

//HorizontalWidth = width;
//VerticalHeight = height;
_liveSplitState = state;

if (_redraw)
try
{
invalidator?.Invalidate(0, 0, width, height);
_splitter.Update(MainControlFormsWrapper.MainViewModel.EldenRingViewModel);

//HorizontalWidth = width;
//VerticalHeight = height;
//if (mode == LayoutMode.Vertical)
//{
// HorizontalWidth = width;
// VerticalHeight = 0;
//}
//else
//{
// HorizontalWidth = 0;
// VerticalHeight = height;
//}

_liveSplitState = state;

if (_splitter.Exception != null)
{
WriteDebug(_splitter.Exception.Message);
}
else
{
WriteDebug("");
}

if (_redraw)
{
invalidator?.Invalidate(0, 0, 1, 1);
}
}
catch (Exception e)
{
WriteDebug(e.Message);
}
}

Expand All @@ -62,39 +92,45 @@ public void DrawVertical(Graphics g, LiveSplitState state, float width, Region c
{
Draw(g);
}

private readonly SimpleLabel _label = new SimpleLabel()
{
IsMonospaced = true,
Brush = Brushes.Crimson,
HorizontalAlignment = StringAlignment.Near,
};


private void WriteDebug(string s)
{
_redraw = true;
_debugOutput = s;

if (_debugOutput != s)
{
_redraw = true;
_debugOutput = s;
}
}

private string _debugOutput = " ";
private string _debugOutput = "";
private bool _redraw = true;

private DispatcherTimer _clearDebugOutputTimer = new DispatcherTimer();

public void Draw(Graphics g)
{
VerticalHeight = g.MeasureString(_debugOutput, _liveSplitState.LayoutSettings.TextFont).Height;
DrawBackground(g);
_label.Text = _debugOutput;
_label.Brush = new SolidBrush(_liveSplitState.LayoutSettings.TextColor);
_label.Font = _liveSplitState.LayoutSettings.TextFont;
_label.Width = HorizontalWidth;
_label.Height = VerticalHeight;
_label.Draw(g);
}
if (string.IsNullOrWhiteSpace(_debugOutput))
{
VerticalHeight = 0;
HorizontalWidth = 0;
}
else
{
VerticalHeight = g.MeasureString(_debugOutput, _liveSplitState.LayoutSettings.TextFont).Height + 2 * InternalPadding;

private void DrawBackground(Graphics g)
{
g.FillRectangle(new SolidBrush(_liveSplitState.LayoutSettings.BackgroundColor), 0, 0, HorizontalWidth, VerticalHeight);
//Get longest string to base the width on
var longestStr = _debugOutput.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList().OrderByDescending(i => i.Length).FirstOrDefault();
HorizontalWidth = g.MeasureString(longestStr, _liveSplitState.LayoutSettings.TextFont).Width + 2 * InternalPadding;

g.FillRectangle(new SolidBrush(_liveSplitState.LayoutSettings.BackgroundColor), 0, 0, HorizontalWidth, VerticalHeight);
g.DrawString(_debugOutput, _liveSplitState.LayoutSettings.TextFont, Brushes.Crimson, InternalPadding, InternalPadding);
}

_redraw = false;
}


private const float InternalPadding = 7f;

public string ComponentName => Name;
public float HorizontalWidth { get; private set; } = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/SoulSplitter/SoulComponentFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class SoulComponentFactory : IComponentFactory

public string UpdateURL => "https://raw.githubusercontent.com/FrankvdStam/SoulSplitter/main/";

public Version Version => new Version(0, 0, 6);
public Version Version => new Version(0, 0, 7);

public IComponent Create(LiveSplitState state)
{
Expand Down
34 changes: 33 additions & 1 deletion src/SoulSplitter/Splitters/EldenRingSplitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace SoulSplitter.Splitters
{
internal class EldenRingSplitter : ISplitter
{
public Exception Exception;

private SplitterState _splitterState;
private EldenRing _eldenRing;
private LiveSplitState _liveSplitState;
Expand All @@ -31,12 +33,42 @@ public void Update(object eldenRingViewModel)
var viewModel = (EldenRingViewModel)eldenRingViewModel;

//Refresh attachment to ER process
_eldenRing.Refresh();
RefreshEldenRing();

//Update the timer
_timer.Update(viewModel.TimingMethod, viewModel.StartAutomatically);

//TODO: run auto splitter state machine
}

public void RefreshEldenRing()
{
try
{
if (!_eldenRing.Refresh())
{
if (!_eldenRing.Attached)
{
Exception = new Exception("eldenring.exe not running");
}
else if (_eldenRing.Exception != null)
{
Exception = _eldenRing.Exception;
}
else
{
Exception = new Exception("unable to refresh eldenring");
}
}
else
{
Exception = null;
}
}
catch (Exception e)
{
Exception = e;
}
}
}
}

0 comments on commit 7515036

Please sign in to comment.