Skip to content

Commit

Permalink
Ping filter improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tremwil committed May 11, 2021
1 parent abf4588 commit 07fd86e
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 61 deletions.
6 changes: 6 additions & 0 deletions DS3ConnectionInfo/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@
</ArrayOfString>
</value>
</setting>
<setting name="MaxAbsPing" serializeAs="String">
<value>250</value>
</setting>
<setting name="SpamRedEyeOrb" serializeAs="String">
<value>False</value>
</setting>
</DS3ConnectionInfo.Settings>
</userSettings>
<applicationSettings>
Expand Down
115 changes: 109 additions & 6 deletions DS3ConnectionInfo/DS3Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using DS3ConnectionInfo.WinAPI;
Expand Down Expand Up @@ -35,20 +36,96 @@ public enum NetStatus
}

/// <summary>
/// BaseB (WorldChrMan) address
/// Ways of joining a DS3 online session.
/// </summary>
public const long BaseB = 0x144768E78;
public enum JoinMethod
{
None,
Arena,
Convenant,
RedEyeOrb,
WhiteSign,
RedSign
}

private static readonly JoinMethod[] invTypeToJoinMethod = new JoinMethod[22]
{
JoinMethod.None,
JoinMethod.WhiteSign,
JoinMethod.RedSign,
JoinMethod.RedEyeOrb,
JoinMethod.WhiteSign,
JoinMethod.None, // 5 Missing from TGA list
JoinMethod.Convenant,
JoinMethod.Convenant,
JoinMethod.None, // (Guardian of Rosaria)
JoinMethod.Convenant,
JoinMethod.Convenant,
JoinMethod.None, // (Avatar)
JoinMethod.Arena,
JoinMethod.None, // (Umbasa White)
JoinMethod.WhiteSign,
JoinMethod.RedSign,
JoinMethod.RedSign,
JoinMethod.RedEyeOrb,
JoinMethod.RedEyeOrb,
JoinMethod.None, // (Force Join Session)
JoinMethod.None, // (Red Hunter)
JoinMethod.Convenant
};

public struct SpEffect
{
public int id;
public float durationLeft;
public float duration;
public float interval;
}

[StructLayout(LayoutKind.Explicit)]
private struct SpEffectInternal
{
[FieldOffset(0x00)]
public float durationLeft;
[FieldOffset(0x04)]
public float duration;
[FieldOffset(0x08)]
public float interval;
[FieldOffset(0x60)]
public int id;
[FieldOffset(0x78)]
public long ptrNext;
public SpEffect ToSpEffect()
{
return new SpEffect { id = id, duration = duration, durationLeft = durationLeft, interval = interval };
}
}

/// <summary>
/// SprjSessionManager address
/// BaseA (Game) address
/// </summary>
public const long SprjSession = 0x144780990;
public const long BaseA = 0x144740178;

/// <summary>
/// BaseB (WorldChrMan) address
/// </summary>
public const long BaseB = 0x144768E78;

/// <summary>
/// BaseC (GameOptionMan) address
/// </summary>
public const long BaseC = 0x144743AB0;

/// <summary>
/// FRPGNet address
/// </summary>
public const long BaseE = 0x14473FD08;

/// <summary>
/// SprjSessionManager address
/// </summary>
public const long SprjSession = 0x144780990;

/// <summary>
/// DS3.exe Base Address
/// </summary>
Expand Down Expand Up @@ -127,8 +204,6 @@ public static bool TryAttach()
if (pArr.Length == 0) return false;

Process = pArr[0];
for (int i = 1; i < pArr.Length; i++) pArr[i].Dispose();

ProcHandle = Kernel32.OpenProcess(ProcessAccessFlags.AllAccess, false, Process.Id);
if (ProcHandle == IntPtr.Zero) Detach();
return ProcHandle != IntPtr.Zero;
Expand Down Expand Up @@ -212,5 +287,33 @@ public static bool IsMyWorld()
{
return MemoryManager.ReadGenericPtr<int>(ProcHandle, BaseC, 0xB1E) == 1;
}

public static IEnumerable<SpEffect> ActiveSpEffects()
{
long addrNext = MemoryManager.ReadGenericPtr<long>(ProcHandle, BaseA, 0x10, 0x920, 0x8);

while (addrNext != 0)
{
SpEffectInternal fx = MemoryManager.ReadGeneric<SpEffectInternal>(ProcHandle, addrNext);
addrNext = fx.ptrNext;
yield return fx.ToSpEffect();
}
}

public static bool IsSearchingInvasion()
{
foreach (SpEffect fx in ActiveSpEffects())
{
if (fx.id == 9200) return true;
}
return false;
}

public static JoinMethod GetJoinMethod()
{
int invType = MemoryManager.ReadGenericPtr<int>(ProcHandle, BaseC, 0xC54);
if (invType > 0 || invType < -21) return JoinMethod.None;
else return invTypeToJoinMethod[-invType];
}
}
}
55 changes: 36 additions & 19 deletions DS3ConnectionInfo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@
<Setter Property="Foreground" Value="Orange"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding Source={x:Static local:Settings.Default}, Path=UsePingFilter}" Value="True">
<Setter Property="Text" Value="{Binding Source={x:Static local:Settings.Default}, Path=MaxAvgPing, StringFormat=PING FILTER: {0}}"></Setter>
<Setter Property="Text">
<Setter.Value>
<MultiBinding StringFormat="PING FILTER: {0}/{1}">
<Binding Source="{x:Static local:Settings.Default}" Path="MaxAvgPing"></Binding>
<Binding Source="{x:Static local:Settings.Default}" Path="MaxAbsPing"></Binding>
</MultiBinding>
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="LawnGreen"></Setter>
</DataTrigger>
</Style.Triggers>
Expand Down Expand Up @@ -89,8 +96,8 @@
<StackPanel Margin="10">
<Label FontWeight="Bold" Content="WARNING: This ping filter is very crude, and WILL increase the time it takes to find online activity."/>
<Label>
<TextBlock>When the ping filter is on, the matchmaking hotkeys below will auto reset if the party's
<LineBreak/>average ping is too high. For more info, read the FAQ on the
<TextBlock>When the ping filter is on, invasions and red/white summon signs will cancel and auto reset
<LineBreak/>if the average and/or per player ping is too high. For more info, read the FAQ on the
<Hyperlink NavigateUri="https://github.com/tremwil/DS3ConnectionInfo" RequestNavigate="webLink_RequestNavigate">
Github page</Hyperlink>.
</TextBlock>
Expand Down Expand Up @@ -120,6 +127,8 @@
<RowDefinition Height="5"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="5"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="5"></RowDefinition>
</Grid.RowDefinitions>
<Label Content="Ping Filter" Grid.Row="0" Grid.Column="0"></Label>
<mah:ToggleSwitch Grid.Row="0" Grid.Column="1" IsOn="{Binding Source={x:Static local:Settings.Default}, Path=UsePingFilter}"
Expand All @@ -129,17 +138,20 @@
<Label Content="Max Average Ping" Grid.Row="4" Grid.Column="0"></Label>
<mah:NumericUpDown Grid.Row="4" Grid.Column="1" Value="{Binding Source={x:Static local:Settings.Default}, Path=MaxAvgPing}"
Minimum="0" Interval="10" ParsingNumberStyle="Number"/>
<Label Content="REO Hotkey" Grid.Row="6" Grid.Column="0"></Label>
<mah:HotKeyBox Grid.Row="6" Grid.Column="1" HotKey="{Binding Source={x:Static local:Settings.Default}, Path=REOHotkey, Converter={StaticResource HotkeyConverter}}"/>
<Label Content="RSD Hotkey " Grid.Row="8" Grid.Column="0"></Label>
<mah:HotKeyBox Grid.Row="8" Grid.Column="1" HotKey="{Binding Source={x:Static local:Settings.Default}, Path=RSDHotkey, Converter={StaticResource HotkeyConverter}}"/>
<Label Content="WSD Hotkey " Grid.Row="10" Grid.Column="0"></Label>
<mah:HotKeyBox Grid.Row="10" Grid.Column="1" HotKey="{Binding Source={x:Static local:Settings.Default}, Path=WSDHotkey, Converter={StaticResource HotkeyConverter}}"/>
<Label Content="Leave Session Hotkey" Grid.Row="12" Grid.Column="0"></Label>
<mah:HotKeyBox Grid.Row="12" Grid.Column="1" HotKey="{Binding Source={x:Static local:Settings.Default}, Path=LeaveSessionHotkey, Converter={StaticResource HotkeyConverter}}"/>
<Label Grid.Row="14" Grid.Column="0" Content="Filter Delay (s)"></Label>
<mah:NumericUpDown Grid.Row="14" Grid.Column="1" Value="{Binding Source={x:Static local:Settings.Default}, Path=SamplingDelay}"
<Label Content="Max Absolute Ping" Grid.Row="6" Grid.Column="0"></Label>
<mah:NumericUpDown Grid.Row="6" Grid.Column="1" Value="{Binding Source={x:Static local:Settings.Default}, Path=MaxAbsPing}"
Minimum="0" Interval="10" ParsingNumberStyle="Number"/>
<Label Grid.Row="8" Grid.Column="0" Content="Filter Delay (s)"></Label>
<mah:NumericUpDown Grid.Row="8" Grid.Column="1" Value="{Binding Source={x:Static local:Settings.Default}, Path=SamplingDelay}"
Minimum="0" Maximum="10" Interval="1" ParsingNumberStyle="Float"/>
<Label Content="REO Hotkey" Grid.Row="10" Grid.Column="0"></Label>
<mah:HotKeyBox Grid.Row="10" Grid.Column="1" HotKey="{Binding Source={x:Static local:Settings.Default}, Path=REOHotkey, Converter={StaticResource HotkeyConverter}}"/>
<Label Content="RSD Hotkey " Grid.Row="12" Grid.Column="0"></Label>
<mah:HotKeyBox Grid.Row="12" Grid.Column="1" HotKey="{Binding Source={x:Static local:Settings.Default}, Path=RSDHotkey, Converter={StaticResource HotkeyConverter}}"/>
<Label Content="WSD Hotkey " Grid.Row="14" Grid.Column="0"></Label>
<mah:HotKeyBox Grid.Row="14" Grid.Column="1" HotKey="{Binding Source={x:Static local:Settings.Default}, Path=WSDHotkey, Converter={StaticResource HotkeyConverter}}"/>
<Label Content="Leave Session Hotkey" Grid.Row="16" Grid.Column="0"></Label>
<mah:HotKeyBox Grid.Row="16" Grid.Column="1" HotKey="{Binding Source={x:Static local:Settings.Default}, Path=LeaveSessionHotkey, Converter={StaticResource HotkeyConverter}}"/>
<!--<Label Grid.Row="16" Grid.Column="0" Content="Sampling Period (s)"></Label>
<mah:NumericUpDown Grid.Row="16" Grid.Column="1" Value="{Binding Source={x:Static local:Settings.Default}, Path=SamplingPeriod}"
Minimum="2" Maximum="10" Interval="1" ParsingNumberStyle="Float"/>-->
Expand All @@ -148,16 +160,21 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="5"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" FontWeight="Bold">Show/Hide Session Info Columns:</Label>
<ComboBox Grid.Row="1" Grid.Column="0" SelectedIndex="0" Name="cbColName" SelectionChanged="cbColName_SelectionChanged">

<Label Content="REO Hotkey Effect" Grid.Row="0" Grid.Column="0"></Label>
<mah:ToggleSwitch Grid.Row="0" Margin="10 0" Grid.Column="1" IsOn="{Binding Source={x:Static local:Settings.Default}, Path=SpamRedEyeOrb}"
OnContent="Spam" OffContent="Normal"></mah:ToggleSwitch>
<Label Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" FontWeight="Bold">Show/Hide Session Info Columns:</Label>
<ComboBox Grid.Row="3" Grid.Column="0" SelectedIndex="0" Name="cbColName" SelectionChanged="cbColName_SelectionChanged">
<ComboBoxItem>Slot</ComboBoxItem>
<ComboBoxItem>Char. Name</ComboBoxItem>
<ComboBoxItem>Team</ComboBoxItem>
Expand All @@ -170,11 +187,11 @@
<ComboBoxItem>Late Packet %</ComboBoxItem>
<ComboBoxItem>Location</ComboBoxItem>
</ComboBox>
<mah:ToggleSwitch Margin="10 0" Grid.Row="1" Grid.Column="1" IsOn="True" OnContent="Shown" OffContent="Hidden" Name="swColVisible" Toggled="swColVisible_Toggled"></mah:ToggleSwitch>
<Label Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" Width="{Binding ElementName=gridSessInfoSettings, Path=ActualWidth}">
<mah:ToggleSwitch Margin="10 0" Grid.Row="3" Grid.Column="1" IsOn="True" OnContent="Shown" OffContent="Hidden" Name="swColVisible" Toggled="swColVisible_Toggled"></mah:ToggleSwitch>
<Label Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" Width="{Binding ElementName=gridSessInfoSettings, Path=ActualWidth}">
<TextBlock TextWrapping="Wrap" Name="textColDesc" FontStyle="Italic">DESC</TextBlock>
</Label>
<DockPanel Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" LastChildFill="False" Margin="0 5" HorizontalAlignment="Left">
<DockPanel Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" LastChildFill="False" Margin="0 5" HorizontalAlignment="Left">
<Button DockPanel.Dock="Bottom" Name="btnResetSettings" Click="btnResetSettings_Click" Height="40" FontSize="14" Width="200">Reset All Settings</Button>
</DockPanel>
</Grid>
Expand Down
Loading

0 comments on commit 07fd86e

Please sign in to comment.