Skip to content

Commit

Permalink
Add letter list glitch button
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Canann committed Mar 17, 2023
1 parent 957c5c2 commit 10962dd
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 12 deletions.
34 changes: 34 additions & 0 deletions GES/Source/InventoryViewer/InventoryViewerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ private InventoryViewerViewModel() : base("Inventory Viewer")
this.CopyRawAddressCommand = new RelayCommand<Object>((obj) => this.CopyRawAddress(obj));
this.EditItemCommand = new RelayCommand<Object>((obj) => this.EditItem(obj));
this.ApplyArtifactsCommand = new RelayCommand<Object>((obj) => this.ApplyArtifacts(obj));
this.ApplyLetterListGlitchCommand = new RelayCommand<Object>((obj) => this.ApplyLetterListGlitch(obj));

this.PlayerSlots = new FullyObservableCollection<PlayerSlotDataView>();
this.DisplayPlayerToSlotMap = new Dictionary<Int32, Int32>();
Expand Down Expand Up @@ -206,6 +207,8 @@ private InventoryViewerViewModel() : base("Inventory Viewer")

public ICommand ApplyArtifactsCommand { get; private set; }

public ICommand ApplyLetterListGlitchCommand { get; private set; }

public UInt16 SelectedItem { get; set; }

public String CopyArtifactListToClipboardToolTip
Expand Down Expand Up @@ -238,6 +241,23 @@ public String ApplyArtifactsToolTip
}
}

public String LetterListGlitchToolTip
{
get
{
if (MainViewModel.GetInstance().SelectedLanguage == MainViewModel.LanguageJPN)
{
return "レターリストの不具合を適用する (間違ったメニューの不具合で無効なレターを開く)";
}
else
{
return "Apply Letter List Glitch (Open invalid letter via wrong menu glitch)";
}
}
}



private void OnAppExit(object sender, ExitEventArgs e)
{
this.CanUpdate = false;
Expand Down Expand Up @@ -635,6 +655,20 @@ private void ApplyArtifacts(Object itemObj)
}
}

private void ApplyLetterListGlitch(Object itemObj)
{
if (itemObj is RawItemEntry)
{
RawItemEntry itemEntry = itemObj as RawItemEntry;
Window mainWindow = Application.Current.MainWindow;

MemoryWriter.Instance.Write<UInt16>(
SessionManager.Session.OpenedProcess,
itemEntry.RawAddress,
BinaryPrimitives.ReverseEndianness((UInt16)(itemEntry.ItemId | (UInt16)0x8000)));
}
}

private static readonly ItemToNameConverter ItemToNameConverter = new ItemToNameConverter();

private List<String> GetArtifactNames(Int32 index, Boolean allowSetE)
Expand Down
16 changes: 8 additions & 8 deletions GES/Source/ItemCatalogViewer/ItemCatalogData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,19 +401,19 @@ public void Refresh(UInt64 address, UInt64 rawAddress, Byte[] bytes)
if (false
// || this.rawItems[entryIndex].ClavatCraftedItem == 0x21A
|| this.rawItems[entryIndex].LiltyCraftedItem == 0x21A
// || this.rawItems[entryIndex].YukeCraftedItem == 0x21A
// || this.rawItems[entryIndex].SelkieCraftedItem == 0x21A
|| this.rawItems[entryIndex].YukeCraftedItem == 0x21A
|| this.rawItems[entryIndex].SelkieCraftedItem == 0x21A
)
{
int bp = 5;
}

// Hastega (Dev)
if (false
// || this.rawItems[entryIndex].ClavatCraftedItem == 0x22D
|| this.rawItems[entryIndex].ClavatCraftedItem == 0x22D
|| this.rawItems[entryIndex].LiltyCraftedItem == 0x22D
// || this.rawItems[entryIndex].YukeCraftedItem == 0x22D
// || this.rawItems[entryIndex].SelkieCraftedItem == 0x22D
|| this.rawItems[entryIndex].YukeCraftedItem == 0x22D
|| this.rawItems[entryIndex].SelkieCraftedItem == 0x22D
)
{
int bp = 5;
Expand All @@ -433,9 +433,9 @@ public void Refresh(UInt64 address, UInt64 rawAddress, Byte[] bytes)
// LizWar
if (false
// || this.rawItems[entryIndex].ClavatCraftedItem == 0x216
|| this.rawItems[entryIndex].LiltyCraftedItem == 0x216
// || this.rawItems[entryIndex].YukeCraftedItem == 0x216
// || this.rawItems[entryIndex].SelkieCraftedItem == 0x216
// || this.rawItems[entryIndex].LiltyCraftedItem == 0x216
|| this.rawItems[entryIndex].YukeCraftedItem == 0x216
|| this.rawItems[entryIndex].SelkieCraftedItem == 0x216
)
{
int bp = 5;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
namespace GES.Source.Mvvm.Converters
{
using GES.Source.InventoryViewer;
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

/// <summary>
/// Converts an Int32 value to a hexedecimal value.
/// </summary>
public class LetterListGlitchVisibilityConverter : IValueConverter
{
/// <summary>
/// Converts an Int32 to a Hex string.
/// </summary>
/// <param name="value">Value to be converted.</param>
/// <param name="targetType">Type to convert to.</param>
/// <param name="parameter">Optional conversion parameter.</param>
/// <param name="culture">Globalization info.</param>
/// <returns>A hex string. If conversion cannot take place, returns null.</returns>
public Object Convert(Object value, Type targetType, Object parameter, CultureInfo culture)
{
if (value == null || !(parameter is String))
{
return String.Empty;
}

if (value is UInt32)
{
UInt32 address = (UInt32)value;

return this.GetLetterListGlitchVisibility(address);
}

return Visibility.Hidden;
}

const Int32 SlotDataSize = 3120; // Slot data are UInt16

public Visibility GetLetterListGlitchVisibility(UInt32 address)
{
address -= 0x80000000; ;
UInt32[] inventoryAddresses = InventoryViewerViewModel.GetInstance().GetInventoryAddresses();

if (inventoryAddresses != null)
{
// Inventory items take 2 bytes each, thus two addresses. Floor to nearest even address.
UInt32 inventoryAddress = address & ~(UInt32)0x1;

for (Int32 inventoryIndex = 0; inventoryIndex < 8; inventoryIndex++)
{
if (inventoryAddress < inventoryAddresses[inventoryIndex] || inventoryAddress >= inventoryAddresses[inventoryIndex] + SlotDataSize)
{
continue;
}

UInt32 offset = (inventoryAddress - inventoryAddresses[inventoryIndex]) / 2;

// Next slot range
if (offset >= 3 && offset <= 381 && (offset - 3) % 6 == 0)
{
return Visibility.Visible;
}

// Current slot range
if (offset >= 411 && (offset - 411) % 6 == 0) // 412+
{
if (offset >= 1452)
{
return Visibility.Visible;
}
else
{
return Visibility.Visible;
}
}
}
}

return Visibility.Hidden;
}

/// <summary>
/// Hex string to an Int32.
/// </summary>
/// <param name="value">Value to be converted.</param>
/// <param name="targetType">Type to convert to.</param>
/// <param name="parameter">Optional conversion parameter.</param>
/// <param name="culture">Globalization info.</param>
/// <returns>An Int32. If conversion cannot take place, returns 0.</returns>
public Object ConvertBack(Object value, Type targetType, Object parameter, CultureInfo culture)
{
return 0;
}
}
//// End class
}
//// End namespace
33 changes: 29 additions & 4 deletions GES/View/Templates/InventoryView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<converters:IntToBinaryConverter x:Key="IntToBinaryConverter" />
<converters:ArtifactGlitchVisibilityConverter x:Key="ArtifactGlitchVisibilityConverter" />
<converters:LetterListGlitchIconConverter x:Key="LetterListGlitchIconConverter" />
<converters:LetterListGlitchVisibilityConverter x:Key="LetterListGlitchVisibilityConverter" />
<converters:ItemToIconConverter x:Key="ItemToIconConverter" />
<converters:AlternatingColorConverter x:Key="AlternatingColorConverter" />

Expand Down Expand Up @@ -173,6 +174,34 @@
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn
Width="Auto"
Header="LLG"
IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Border Background="{Binding Path=Index, Converter={StaticResource AlternatingColorConverter}}">
<StackPanel Orientation="Horizontal">
<MenuItem
Height="16"
Command="{Binding InventoryViewerViewModel.ApplyLetterListGlitchCommand, Source={StaticResource ViewModelLocator}}"
CommandParameter="{Binding .}"
ToolTip="{Binding InventoryViewerViewModel.LetterListGlitchToolTip, Source={StaticResource ViewModelLocator}}"
Visibility="{Binding Path=Address, Converter={StaticResource LetterListGlitchVisibilityConverter}, ConverterParameter=0}"
WindowChrome.IsHitTestVisibleInChrome="True">
<MenuItem.Header>
<Image
Width="16"
Height="16"
Margin="-4"
Source="{Binding Path=Address, Converter={StaticResource LetterListGlitchIconConverter}, ConverterParameter=0}" />
</MenuItem.Header>
</MenuItem>
</StackPanel>
</Border>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn
Width="Auto"
Header="Artifact Glitch Pattern (CLES)"
Expand Down Expand Up @@ -385,10 +414,6 @@
<DataTemplate>
<Border Background="{Binding Path=Index, Converter={StaticResource AlternatingColorConverter}}">
<StackPanel Orientation="Horizontal">
<Image
Width="16"
Height="16"
Source="{Binding Path=Address, Converter={StaticResource LetterListGlitchIconConverter}, ConverterParameter=0}" />
<TextBlock Text="{Binding Path=Address, Converter={StaticResource AddressToNotesConverter}}" />
</StackPanel>
</Border>
Expand Down

0 comments on commit 10962dd

Please sign in to comment.