Skip to content

Commit

Permalink
Merge pull request SapphireServer#48 from takhlaq/master
Browse files Browse the repository at this point in the history
6.30 support
  • Loading branch information
SapphireMordred committed Feb 2, 2023
2 parents 20a575b + efb3d15 commit ea6b04e
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 35 deletions.
20 changes: 11 additions & 9 deletions FFXIVMonReborn/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,26 @@ public static FilterSet[] Parse(string input)
{
Debug.WriteLine(input);
List<FilterSet> output = new List<FilterSet>();

if (input.Length == 0)
return output.ToArray();

for (int i = 0; i < input.Length; i++ )

string[] args = input.Split(';');
for (int i = 0; i < args.Length; i++ )
{
string thisFilter = "";
FilterType type;

thisFilter = input.Substring(0, input.IndexOf(";") + 1);
input = input.Replace(thisFilter, "");
thisFilter = args[i];

if (thisFilter.Length <= 1)
break;

object value;
if (thisFilter[0] != '_')
{
type = FilterType.Message;
string vstring = thisFilter.Substring(0, thisFilter.Length - 1);
string vstring = thisFilter.Substring(0, thisFilter.Length);
value = vstring;
}
// _A(ActorControlType)
Expand Down Expand Up @@ -157,7 +160,7 @@ public static FilterSet[] Parse(string input)
else
{
type = FilterType.Message;
string vstring = thisFilter.Substring(0, thisFilter.Length - 1);
string vstring = thisFilter.Substring(0, thisFilter.Length);
value = int.Parse(vstring, NumberStyles.HexNumber);
}

Expand All @@ -167,8 +170,7 @@ public static FilterSet[] Parse(string input)

Debug.WriteLine(input.Length);

if (input.Length <= 1)
break;

}

return output.ToArray();
Expand Down
2 changes: 1 addition & 1 deletion FFXIVMonReborn/MachinaCaptureWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void Run()
monitor.MessageReceivedEventHandler = MessageReceived;
monitor.MessageSentEventHandler = MessageSent;

monitor.OodleImplementation = OodleImplementation.Ffxiv;
monitor.OodleImplementation = OodleImplementation.FfxivUdp;

// GamePath points to sqpack
monitor.OodlePath = GetOodlePath();
Expand Down
17 changes: 16 additions & 1 deletion FFXIVMonReborn/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,23 @@
</MenuItem>
</Menu>


<TabControl x:Name="MainTabControl" SelectionChanged="MainTabControl_OnSelectionChanged"> <!--MouseDoubleClick="MainTabControl_OnMouseDoubleClick" TODO:This makes every double click in XivMonTab spawn a new tab - investigate better methods -->
<TabControl.ItemContainerStyle>
<TabControl.Template>
<ControlTemplate TargetType="{x:Type TabControl}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
<TabPanel x:Name="HeaderPanel" IsItemsHost="True" Margin="0,4,0,0"/>
</ScrollViewer>
<ContentPresenter x:Name="PART_SelectedContentHost" Margin="4" ContentSource="SelectedContent" Grid.Row="1"/>
</Grid>
</ControlTemplate>
</TabControl.Template>
<TabControl.ItemContainerStyle>
<Style TargetType="{x:Type TabItem}">
<Setter Property="ContextMenu">
<Setter.Value>
Expand Down
104 changes: 86 additions & 18 deletions FFXIVMonReborn/Views/XivMonTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
using Capture = FFXIVMonReborn.DataModel.Capture;
using Color = System.Windows.Media.Color;
using FFXIVMonReborn.Database.GitHub;
using Newtonsoft.Json.Bson;
using System.Text.Unicode;
using System.Runtime.InteropServices;
using System.Text;

namespace FFXIVMonReborn.Views
{
Expand All @@ -53,6 +57,7 @@ public partial class XivMonTab : UserControl
private string _currentFilePath = "";

private bool _wasCapturedMs = false;
private uint _selfCharaId = 0x0;

private FilterSet[] _filters;

Expand Down Expand Up @@ -606,7 +611,12 @@ public void AddPacketToListView(PacketEntry item, bool silent = false)
}
}

item.IsForSelf = BitConverter.ToUInt32(item.Data, 0x04) == BitConverter.ToUInt32(item.Data, 0x08);
uint tmpCharaId = BitConverter.ToUInt32(item.Data, 0x04);
item.IsForSelf = tmpCharaId == BitConverter.ToUInt32(item.Data, 0x08);

if (item.IsForSelf)
_selfCharaId = tmpCharaId;

item.Category = item.Set.ToString();

if (_mainWindow.RunScriptsOnNewCheckBox.IsChecked)
Expand Down Expand Up @@ -748,31 +758,28 @@ public void LoadCapture()
_filterString = "";

OpenFileDialog openFileDialog = new OpenFileDialog();


openFileDialog.Multiselect = true;
openFileDialog.Filter = @"XML/Pcap|*.xml;*.pcap;*.pcapng";
openFileDialog.Title = @"Select Capture file(s)";

if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
MessageBoxResult res = MessageBox.Show("No to open in current, Yes to open in new tab.", "Open in new tab?", MessageBoxButton.YesNoCancel);
if (res == MessageBoxResult.Yes)
if (openFileDialog.FileNames.Length > 1)
{
foreach (var filename in openFileDialog.FileNames)
_mainWindow.AddTab(filename);
return;
}
else if (res == MessageBoxResult.No)
{
foreach (var filename in openFileDialog.FileNames)
LoadCapture(openFileDialog.FileName);
}
else
{
return;
}
MessageBoxResult res = MessageBox.Show("No to open in current, Yes to open in new tab.", "Open in new tab?", MessageBoxButton.YesNoCancel);

if (res == MessageBoxResult.Yes)
_mainWindow.AddTab(openFileDialog.FileName);
else
LoadCapture(openFileDialog.FileName);
}
}

UpdateInfoLabel();
}

Expand Down Expand Up @@ -906,11 +913,60 @@ public void LoadCapture(PacketEntry[] packets)
}
#endregion

byte[] ModifyPacket(byte[] packet, bool censorSelfId, string censorName)
{
//uint censoredId = 0xEFBEADDE;
//ulong censoredContentId = 0xEDEEEEEED1EFEEBE;

byte[] ret = new byte[packet.Length];
packet.CopyTo(ret, 0);

string paddedName = null;
if (!string.IsNullOrWhiteSpace(censorName))
paddedName = censorName.PadRight(31, '\0');

if (censorSelfId)
{
for (int i = 0; i < ret.Length; ++i)
{
if (i + 3 < ret.Length && BitConverter.ToUInt32(ret, i) == _selfCharaId)
{
ret[i] = 0xDE;
ret[i + 1] = 0xAD;
ret[i + 2] = 0xBE;
ret[i + 3] = 0xEF;
i += 3;
}
else if (i + 31 < ret.Length && !string.IsNullOrWhiteSpace(paddedName))
{
string foundName = Encoding.ASCII.GetString(ret, i, 31);
if (foundName == paddedName)
{
Array.Clear(ret, i, foundName.Length);
Encoding.ASCII.GetBytes("Player One").CopyTo(ret, i);
i += 31;
}
}
}
}
return ret;
}

#region PacketExporting
private void ExportSelectedPacketToDat(object sender, RoutedEventArgs e)
{
var items = PacketListView.SelectedItems;

string censorSelfName = null;
bool censorSelfIds = false;
var res = MessageBox.Show("Would you like to censor your Character ID to DE AD BE EF (NOT Content ID)?\n\n" +
"WARNING: This will not censor IDs of other players you may come across or your GUID/Content ID.\n" +
"Content ID needs detecting and censoring manually, usually found in PlayerSetup/InitUI packet.",
"Censor?", MessageBoxButton.YesNo);
censorSelfIds = res == MessageBoxResult.Yes;
if (censorSelfIds)
censorSelfName = Microsoft.VisualBasic.Interaction.InputBox("Enter your character name (will be replaced with Player One)", "Censor character name", null);

if (items.Count == 0)
{
MessageBox.Show("No packet selected.", "Error", MessageBoxButton.OK,
Expand All @@ -924,10 +980,11 @@ private void ExportSelectedPacketToDat(object sender, RoutedEventArgs e)
var fileDialog = new SaveFileDialog { Filter = @"DAT|*.dat" };

var result = fileDialog.ShowDialog();
var data = ModifyPacket(packet.Data, censorSelfIds, censorSelfName);

if (result == DialogResult.OK)
{
File.WriteAllBytes(fileDialog.FileName, InjectablePacketBuilder.BuildSingle(packet.Data));
File.WriteAllBytes(fileDialog.FileName, InjectablePacketBuilder.BuildSingle(data));
MessageBox.Show($"Packet saved to {fileDialog.FileName}.", "FFXIVMon Reborn", MessageBoxButton.OK, MessageBoxImage.Asterisk);
}
}
Expand All @@ -940,8 +997,9 @@ private void ExportSelectedPacketToDat(object sender, RoutedEventArgs e)
int count = 0;
foreach (PacketEntry item in items)
{
var data = ModifyPacket(item.Data, censorSelfIds, censorSelfName);
File.WriteAllBytes(System.IO.Path.Combine(dialog.SelectedPath, $"{item.Message}-{String.Join("_", item.Timestamp.Split(System.IO.Path.GetInvalidFileNameChars(), StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.')}-No{count}.dat"),
InjectablePacketBuilder.BuildSingle(item.Data));
InjectablePacketBuilder.BuildSingle(data));

count++;
}
Expand Down Expand Up @@ -1022,6 +1080,16 @@ private void ExportSelectedPacketSetToDat(object sender, RoutedEventArgs e)
{
var items = PacketListView.SelectedItems;

string censorSelfName = null;
bool censorSelfIds = false;
var res = MessageBox.Show("Would you like to censor your Character ID to DE AD BE EF (NOT Content ID)?\n\n" +
"WARNING: This will not censor IDs of other players you may come across or your GUID/Content ID.\n" +
"Content ID needs detecting and censoring manually, usually found in PlayerSetup/InitUI packet.",
"Censor?", MessageBoxButton.YesNo);
censorSelfIds = res == MessageBoxResult.Yes;
if (censorSelfIds)
censorSelfName = Microsoft.VisualBasic.Interaction.InputBox("Enter your character name (will be replaced with Player One)", "Censor character name", null);

if (items.Count == 0)
{
MessageBox.Show("No packet selected.", "Error", MessageBoxButton.OK,
Expand All @@ -1033,13 +1101,13 @@ private void ExportSelectedPacketSetToDat(object sender, RoutedEventArgs e)
var startPacket = (PacketEntry)PacketListView.SelectedItem;

List<byte[]> packets = new List<byte[]>();
packets.Add(startPacket.Data);
packets.Add(ModifyPacket(startPacket.Data, censorSelfIds, censorSelfName));

int at = Packets.IndexOf(startPacket) - 1;
while (true)
{
if (((PacketEntry)Packets[at]).Set == startPacket.Set)
packets.Insert(0, ((PacketEntry)Packets[at]).Data);
packets.Insert(0, ModifyPacket(((PacketEntry)Packets[at]).Data, censorSelfIds, censorSelfName));
else
break;
at--;
Expand All @@ -1049,7 +1117,7 @@ private void ExportSelectedPacketSetToDat(object sender, RoutedEventArgs e)
while (true)
{
if (((PacketEntry)Packets[at]).Set == startPacket.Set)
packets.Add(((PacketEntry)Packets[at]).Data);
packets.Add(ModifyPacket(((PacketEntry)Packets[at]).Data, censorSelfIds, censorSelfName));
else
break;
at++;
Expand Down
11 changes: 6 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ version: 1.0.{build}
image: Visual Studio 2022
configuration: Release
platform: x64
install:
- git submodule update --init --recursive
before_build:
- cmd: >-
git submodule update --init
nuget restore
- nuget restore
build:
project: FFXIVMonReborn.sln
parallel: true
verbosity: normal
verbosity: normal
artifacts:
- path: bin

0 comments on commit ea6b04e

Please sign in to comment.