Skip to content

Commit

Permalink
Small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Tirlititi committed Nov 11, 2022
1 parent 3567b31 commit caa3e4c
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,12 @@ public Int32 DoEventCode()
UInt32 menuId = Convert.ToUInt32(this.getv1());
UInt32 subId = Convert.ToUInt32(this.getv1());
if (Configuration.Hacks.DisableNameChoice && menuId == 1)
{
CharacterId charId = this.chr2slot((Int32)subId);
if (charId != CharacterId.NONE && NameSettingUI.IsDefaultName(charId))
this._ff9.GetPlayer(charId).Name = FF9TextTool.CharacterDefaultName(charId);
return 0;
}
EventService.StartMenu(menuId, subId);
PersistenSingleton<UIManager>.Instance.MenuOpenEvent();
return 1;
Expand Down
5 changes: 5 additions & 0 deletions Assembly-CSharp/Global/NameSettingUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public sealed class NameSettingUI : UIScene
private Int32 _currentCharId;
private Int32 _currentSlotId;

public static Boolean IsDefaultName(CharacterId subNo)
{
return (Int32)subNo < 12;
}

public CharacterId SubNo
{
get => (CharacterId)_subNumber;
Expand Down
7 changes: 6 additions & 1 deletion Assembly-CSharp/Global/ff9feqp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@

public static class ff9feqp
{
public static UInt64 GetCharacterEquipMaskFromId(CharacterId id)
{
return (Int32)id <= 11 ? 1ul << (11 - (Int32)id) : 1ul << (Int32)id;
}

public static UInt64 GetCharacterEquipMask(PLAYER player)
{
return (Int32)player.Index <= 11 ? 1ul << (11 - (Int32)player.Index) : 1ul << (Int32)player.Index;
return GetCharacterEquipMaskFromId(player.Index);
}

public static void FF9FEqp_UpdatePlayer(PLAYER play)
Expand Down
1 change: 1 addition & 0 deletions Assembly-CSharp/Memoria/Assets/Text/DataResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static class Items
public static String ItemEffectsFile => "ItemEffects.csv";
public static String ShopItems => "ShopItems.csv";
public static String InitialItemsFile => "InitialItems.csv";
public static String ItemEquipPatchFile => "ItemEquipPatch.txt";

public static String ModDirectory(String modFolder)
{
Expand Down
86 changes: 79 additions & 7 deletions Assembly-CSharp/Memoria/Data/ff9item.2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Memoria.Data;
using Memoria.Prime;
using Memoria.Prime.CSV;
using Memoria.Prime.Text;

// ReSharper disable FieldCanBeMadeReadOnly.Global
// ReSharper disable UnusedMember.Global
Expand Down Expand Up @@ -57,6 +58,14 @@ static ff9item()
{
_FF9Item_Data = LoadItems();
_FF9Item_Info = LoadItemEffects();
PatchItemEquipability(_FF9Item_Data);
}

public static void FF9Item_Init()
{
FF9Item_InitNormal();
FF9Item_InitImportant();
LoadInitialItems();
}

private static FF9ITEM_DATA[] LoadItems()
Expand Down Expand Up @@ -90,6 +99,24 @@ private static FF9ITEM_DATA[] LoadItems()
}
}

private static void PatchItemEquipability(FF9ITEM_DATA[] itemDatabase)
{
try
{
String inputPath;
for (Int32 i = AssetManager.Folder.Length - 1; i >= 0; --i)
{
inputPath = DataResources.Items.ModDirectory(AssetManager.Folder[i].FolderPath) + DataResources.Items.ItemEquipPatchFile;
if (File.Exists(inputPath))
ApplyItemEquipabilityPatchFile(itemDatabase, File.ReadAllLines(inputPath));
}
}
catch (Exception ex)
{
Log.Error(ex, "[ff9item] Patch item equipability failed.");
}
}

private static ITEM_DATA[] LoadItemEffects()
{
try
Expand Down Expand Up @@ -144,13 +171,6 @@ private static void LoadInitialItems()
}
}

public static void FF9Item_Init()
{
FF9Item_InitNormal();
FF9Item_InitImportant();
LoadInitialItems();
}

public static void FF9Item_InitNormal()
{
for (Int32 index = 0; index < 256; ++index)
Expand Down Expand Up @@ -387,4 +407,56 @@ public static Int32 DecreaseMoonStoneCount()
FF9StateSystem.Achievement.EvtReservedArray[0] = num;
return num;
}

private static void ApplyItemEquipabilityPatchFile(FF9ITEM_DATA[] itemDatabase, String[] allLines)
{
foreach (String line in allLines)
{
// eg.: Garnet Add 1 2 Remove 56
// (allows Garnet to equip Dagger and Mage Masher but disallows her to equip Tiger Racket)
if (String.IsNullOrEmpty(line) || line.Trim().StartsWith("//"))
continue;
String[] allWords = line.Trim().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
if (allWords.Length < 3)
continue;
Int32 charId;
if (!Int32.TryParse(allWords[0], out charId))
{
CharacterId charIdAsStr;
if (!allWords[0].TryEnumParse(out charIdAsStr))
continue;
charId = (Int32)charIdAsStr;
}
Boolean isAdd = false;
Boolean isRemove = false;
Int32 itemId;
UInt64 charMask = ff9feqp.GetCharacterEquipMaskFromId((CharacterId)charId);
for (Int32 wordIndex = 1; wordIndex < allWords.Length; wordIndex++)
{
String word = allWords[wordIndex].Trim();
if (String.Compare(word, "Add") == 0)
{
isAdd = true;
isRemove = false;
}
else if (String.Compare(word, "Remove") == 0)
{
isAdd = false;
isRemove = true;
}
else if (isAdd)
{
if (!Int32.TryParse(word, out itemId) || itemId < 0 || itemId >= itemDatabase.Length)
continue;
itemDatabase[itemId].equip |= charMask;
}
else if (isRemove)
{
if (!Int32.TryParse(word, out itemId) || itemId < 0 || itemId >= itemDatabase.Length)
continue;
itemDatabase[itemId].equip &= ~charMask;
}
}
}
}
}

1 comment on commit caa3e4c

@Tirlititi
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • DisableNameChoice now updates the character's name to the default one when it should (eg. Garnet renaming herself "Dagger" instead of keeping "Garnet").
  • Equipability can now be modified by an external mod file Data/Items/ItemEquipPatch.txt on top of the Items.csv. This is for improving mod compatibilities and logically tie equipability to the datas of the characters instead of tying it solely to item datas.

Please sign in to comment.