Skip to content

Commit

Permalink
Add full support for MCH, SCH, and DRK pets with custom sizes.
Browse files Browse the repository at this point in the history
Tag player entries with their home world if different than local character's.
Fix accidental Thanos Snap while trying to redraw.
Prepare ritualistic sacrifice to ImGui Gods.
  • Loading branch information
Kurochi51 committed Jul 21, 2024
1 parent a2c22e0 commit 7b8ab80
Show file tree
Hide file tree
Showing 8 changed files with 329 additions and 105 deletions.
6 changes: 4 additions & 2 deletions PetScale/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Dalamud.Plugin;
using Dalamud.Configuration;
using PetScale.Structs;
using PetScale.Enums;

namespace PetScale;

Expand All @@ -13,6 +14,7 @@ public class Configuration : IPluginConfiguration
public int Version { get; set; } = 0;
public IList<PetStruct> PetData { get; set; } = [];
public int FairySize { get; set; } = 0;
public ushort HomeWorld { get; set; } = 0;
public bool UpdateNeeded { get; internal set; }

public void UpdateConfig()
Expand All @@ -21,9 +23,9 @@ public void UpdateConfig()
{
if (PetData[i].CharacterName.Equals(PetScale.Others, StringComparison.Ordinal))
{
PetData[i] = PetData[i] with { Generic = true, ContentId = PetScale.OthersContendId };
PetData[i] = PetData[i] with { Generic = true, ContentId = PetScale.OthersContendId, HomeWorld = PetScale.OthersHomeWorld };
}
else if (PetData[i].PetID is Enums.PetModel.AllPets)
else if (PetData[i].PetID is PetModel.AllPets)
{
PetData[i] = PetData[i] with { Generic = true };
}
Expand Down
19 changes: 19 additions & 0 deletions PetScale/Enums/PetEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public enum PetRow : uint
Eos = 6,
Selene = 7,
Seraph = 15,
// MCH Things
Rook = 8,
AutomatonQueen = 18,
// DRK Emo Clone
Esteem = 17,
}

/// <summary>
Expand All @@ -34,11 +39,25 @@ public enum PetModel
Eos = 407,
Selene = 408,
Seraph = 2619,
// MCH Things
Rook = 1027,
AutomatonQueen = 2618,
// DRK Emo Clone
Esteem = 2621,
}

public enum PetSize
{
SmallModelScale,
MediumModelScale,
LargeModelScale,
Custom,
}

public enum PetState
{
Off,
Self,
Others,
All,
}
1 change: 1 addition & 0 deletions PetScale/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
[assembly: SuppressMessage("Design", "MA0038:Make method static (deprecated, use CA1822 instead)", Justification = "Obsolete", Scope = "member", Target = "~M:PetScale.Helpers.Utilities.SetScale(FFXIVClientStructs.FFXIV.Client.Game.Character.BattleChara*,System.Single)")]
[assembly: SuppressMessage("Design", "MA0041:Make property static (deprecated, use CA1822 instead)", Justification = "Obsolete", Scope = "member", Target = "~P:PetScale.PetScale.BattleCharaSpan")]
[assembly: SuppressMessage("Design", "MA0016:Prefer using collection abstraction instead of implementation", Justification = "Not meant for public consumption", Scope = "member", Target = "~P:PetScale.Windows.ConfigWindow.petMap")]
[assembly: SuppressMessage("Design", "MA0016:Prefer using collection abstraction instead of implementation", Justification = "No", Scope = "member", Target = "~P:PetScale.Windows.ConfigWindow.otherPetMap")]
[assembly: SuppressMessage("Performance", "MA0066:Hash table unfriendly type is used in a hash table", Justification = "None", Scope = "member", Target = "~F:PetScale.PetScale.activePetDictionary")]
[assembly: SuppressMessage("Design", "MA0038:Make method static (deprecated, use CA1822 instead)", Justification = "Obsolete", Scope = "member", Target = "~M:PetScale.Helpers.Utilities.PetVisible(FFXIVClientStructs.FFXIV.Client.Game.Character.BattleChara*)~System.Boolean")]
48 changes: 38 additions & 10 deletions PetScale/Helpers/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@
using System.Collections.Generic;

using Lumina.Excel;
using Lumina.Excel.GeneratedSheets2;
using Dalamud.Game;
using Dalamud.Utility;
using Dalamud.Plugin.Services;
using Dalamud.Game.ClientState.Objects.Types;
using FFXIVClientStructs.FFXIV.Client.Game.Character;
using FFXIVClientStructs.FFXIV.Client.Game.Object;
using FFXIVClientStructs.Interop;
using PetScale.Enums;

namespace PetScale.Helpers;

public class Utilities(IDataManager _dataManager, IPluginLog _pluginLog)
public class Utilities(IDataManager _dataManager, IPluginLog _pluginLog, ClientLanguage _language)
{
private readonly IDataManager dataManager = _dataManager;
private readonly IPluginLog log = _pluginLog;
private readonly ClientLanguage language = _language;
private ExcelSheet<World>? worldSheet = null;

/// <summary>
/// Attempt to retrieve an <see cref="ExcelSheet{T}"/>, optionally in a specific <paramref name="language"/>.
Expand Down Expand Up @@ -56,19 +61,19 @@ public unsafe void SetScale(BattleChara* pet, float scale)
}
}

private static unsafe DrawState* ActorDrawState(GameObject* actor)
=> (DrawState*)&actor->RenderFlags;
private static unsafe DrawState* ActorDrawState(IGameObject actor)
=> (DrawState*)&((GameObject*)actor.Address)->RenderFlags;

public static unsafe void ToggleVisibility(GameObject* actor)
public static unsafe void ToggleVisibility(IGameObject actor)
{
if (actor is null || actor->EntityId is 0xE0000000)
if (actor is null || actor.EntityId is 0xE0000000)
{
return;
}
*ActorDrawState(actor) ^= DrawState.Invisibility;
}

public unsafe void CachePlayerList(uint playerEntityId, Queue<(string, ulong)> queue, Span<Pointer<BattleChara>> CharacterSpan)
public unsafe void CachePlayerList(uint playerEntityId, ushort homeWorld, Queue<(string, ulong)> queue, Span<Pointer<BattleChara>> CharacterSpan)
{
foreach (var chara in CharacterSpan)
{
Expand All @@ -82,14 +87,16 @@ public unsafe void CachePlayerList(uint playerEntityId, Queue<(string, ulong)> q
}
if (chara.Value->Character.GameObject.EntityId != playerEntityId)
{
queue.Enqueue((chara.Value->Character.NameString, chara.Value->ContentId));
var world = string.Empty;
if (homeWorld is not 0 && homeWorld != chara.Value->Character.HomeWorld && !GetHomeWorldName(chara.Value->Character.HomeWorld).IsNullOrWhitespace())
{
world = "@" + GetHomeWorldName(chara.Value->Character.HomeWorld);
}
queue.Enqueue((chara.Value->Character.NameString + world, chara.Value->ContentId));
}
}
}

public static bool IsFairy(int modelId)
=> (PetModel)modelId is PetModel.Eos or PetModel.Selene;

public unsafe bool PetVisible(BattleChara* pet)
{
if (pet is null || pet->Character.GameObject.GetDrawObject() is null)
Expand All @@ -98,4 +105,25 @@ public unsafe bool PetVisible(BattleChara* pet)
}
return pet->Character.GameObject.GetDrawObject()->IsVisible;
}

public static float GetMinSize(PetModel pet)
{
return pet switch
{
PetModel.Seraph => 1.25f,
PetModel.AutomatonQueen => 1.3f,
_ => 1f,
};
}

public string GetHomeWorldName(ushort id)
{
worldSheet ??= GetSheet<World>(language);
if (worldSheet is not null)
{
var world = worldSheet.GetRow(id);
return world?.Name ?? string.Empty;
}
return string.Empty;
}
}
Loading

0 comments on commit 7b8ab80

Please sign in to comment.