Skip to content

Commit

Permalink
Merge pull request #58 from SheepGoMeh/API9
Browse files Browse the repository at this point in the history
[PR] API9
  • Loading branch information
SheepGoMeh authored Oct 3, 2023
2 parents 47babfc + 165e0f5 commit 6fe8d4a
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 163 deletions.
4 changes: 2 additions & 2 deletions Visibility/Api/VisibilityApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void AddToVoidList(string name, uint worldId, string reason)
{
this.CheckInitialised();

var world = VisibilityPlugin.DataManager.GetExcelSheet<World>()?.SingleOrDefault(x => x.RowId == worldId);
var world = Service.DataManager.GetExcelSheet<World>()?.SingleOrDefault(x => x.RowId == worldId);

if (world == null)
{
Expand Down Expand Up @@ -92,7 +92,7 @@ public void AddToWhitelist(string name, uint worldId, string reason)
{
this.CheckInitialised();

var world = VisibilityPlugin.DataManager.GetExcelSheet<World>()?.SingleOrDefault(x => x.RowId == worldId);
var world = Service.DataManager.GetExcelSheet<World>()?.SingleOrDefault(x => x.RowId == worldId);

if (world == null)
{
Expand Down
4 changes: 2 additions & 2 deletions Visibility/Configuration/VisibilityConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public void Init(ushort territoryType)
}
};

var valueTuples = VisibilityPlugin.DataManager.GameData.Excel.GetSheet<TerritoryType>()!
var valueTuples = Service.DataManager.GameData.Excel.GetSheet<TerritoryType>()!
.Where(
x => (x.TerritoryIntendedUse is 0 or 1 or 13 or 19 or 21 or 23 or 44 or 46 or 47 ||
this.TerritoryTypeWhitelist.Contains((ushort)x.RowId)) && !string.IsNullOrEmpty(x.Name) &&
Expand Down Expand Up @@ -362,7 +362,7 @@ public void UpdateCurrentConfig(ushort territoryType, bool edit = false)

public void Save()
{
VisibilityPlugin.PluginInterface.SavePluginConfig(this);
Service.PluginInterface.SavePluginConfig(this);
}
}
}
15 changes: 5 additions & 10 deletions Visibility/ContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ namespace Visibility
public class ContextMenu : IDisposable
{
private bool enabled;
private readonly DalamudContextMenu dalamudContextMenu;

public ContextMenu()
{
this.dalamudContextMenu = new DalamudContextMenu();
}
private readonly DalamudContextMenu dalamudContextMenu = new(Service.PluginInterface);

public void Toggle()
{
Expand Down Expand Up @@ -117,7 +112,7 @@ private static void OnOpenContextMenu(GameObjectContextMenuOpenArgs args)

private static void AddToVoidList(GameObjectContextMenuItemSelectedArgs args)
{
var world = VisibilityPlugin.DataManager.GetExcelSheet<World>()?
var world = Service.DataManager.GetExcelSheet<World>()?
.SingleOrDefault(x => x.RowId == args.ObjectWorld);

if (world == null)
Expand Down Expand Up @@ -157,12 +152,12 @@ private static void RemoveFromVoidList(GameObjectContextMenuItemSelectedArgs arg
VisibilityPlugin.Instance.RemoveChecked(entry.Name);
VisibilityPlugin.Instance.ShowPlayer(entry.Name);
}
VisibilityPlugin.ChatGui.Print(message);
Service.ChatGui.Print(message);
}

private static void AddToWhitelist(GameObjectContextMenuItemSelectedArgs args)
{
var world = VisibilityPlugin.DataManager.GetExcelSheet<World>()?
var world = Service.DataManager.GetExcelSheet<World>()?
.SingleOrDefault(x => x.RowId == args.ObjectWorld);

if (world == null)
Expand Down Expand Up @@ -200,7 +195,7 @@ private static void RemoveFromWhitelist(GameObjectContextMenuItemSelectedArgs ar
{
VisibilityPlugin.Instance.RemoveChecked(entry.Name);
}
VisibilityPlugin.ChatGui.Print(message);
Service.ChatGui.Print(message);
}
}
}
32 changes: 16 additions & 16 deletions Visibility/Ipc/VisibilityProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,90 +34,90 @@ public VisibilityProvider(IVisibilityApi api)

try
{
this.ProviderApiVersion = VisibilityPlugin.PluginInterface.GetIpcProvider<int>(LabelProviderApiVersion);
this.ProviderApiVersion = Service.PluginInterface.GetIpcProvider<int>(LabelProviderApiVersion);
this.ProviderApiVersion.RegisterFunc(() => api.ApiVersion);
}
catch (Exception e)
{
PluginLog.Error($"Error registering IPC provider for {LabelProviderApiVersion}:\n{e}");
Service.PluginLog.Error($"Error registering IPC provider for {LabelProviderApiVersion}:\n{e}");
}

try
{
this.ProviderGetVoidListEntries =
VisibilityPlugin.PluginInterface.GetIpcProvider<IEnumerable<string>>(LabelProviderGetVoidListEntries);
Service.PluginInterface.GetIpcProvider<IEnumerable<string>>(LabelProviderGetVoidListEntries);
this.ProviderGetVoidListEntries.RegisterFunc(api.GetVoidListEntries);
}
catch (Exception e)
{
PluginLog.Error($"Error registering IPC provider for {LabelProviderGetVoidListEntries}:\n{e}");
Service.PluginLog.Error($"Error registering IPC provider for {LabelProviderGetVoidListEntries}:\n{e}");
}

try
{
this.ProviderAddToVoidList =
VisibilityPlugin.PluginInterface.GetIpcProvider<string, uint, string, object>(LabelProviderAddToVoidList);
Service.PluginInterface.GetIpcProvider<string, uint, string, object>(LabelProviderAddToVoidList);
this.ProviderAddToVoidList.RegisterAction(api.AddToVoidList);
}
catch (Exception e)
{
PluginLog.Error($"Error registering IPC provider for {LabelProviderAddToVoidList}:\n{e}");
Service.PluginLog.Error($"Error registering IPC provider for {LabelProviderAddToVoidList}:\n{e}");
}

try
{
this.ProviderRemoveFromVoidList =
VisibilityPlugin.PluginInterface.GetIpcProvider<string, uint, object>(LabelProviderRemoveFromVoidList);
Service.PluginInterface.GetIpcProvider<string, uint, object>(LabelProviderRemoveFromVoidList);
this.ProviderRemoveFromVoidList.RegisterAction(api.RemoveFromVoidList);
}
catch (Exception e)
{
PluginLog.Error($"Error registering IPC provider for {LabelProviderRemoveFromVoidList}:\n{e}");
Service.PluginLog.Error($"Error registering IPC provider for {LabelProviderRemoveFromVoidList}:\n{e}");
}

try
{
this.ProviderGetWhitelistEntries =
VisibilityPlugin.PluginInterface.GetIpcProvider<IEnumerable<string>>(LabelProviderGetWhitelistEntries);
Service.PluginInterface.GetIpcProvider<IEnumerable<string>>(LabelProviderGetWhitelistEntries);
this.ProviderGetWhitelistEntries.RegisterFunc(api.GetWhitelistEntries);
}
catch (Exception e)
{
PluginLog.Error($"Error registering IPC provider for {LabelProviderGetWhitelistEntries}:\n{e}");
Service.PluginLog.Error($"Error registering IPC provider for {LabelProviderGetWhitelistEntries}:\n{e}");
}

try
{
this.ProviderAddToWhitelist =
VisibilityPlugin.PluginInterface.GetIpcProvider<string, uint, string, object>(LabelProviderAddToWhitelist);
Service.PluginInterface.GetIpcProvider<string, uint, string, object>(LabelProviderAddToWhitelist);
this.ProviderAddToWhitelist.RegisterAction(api.AddToWhitelist);
}
catch (Exception e)
{
PluginLog.Error($"Error registering IPC provider for {LabelProviderAddToWhitelist}:\n{e}");
Service.PluginLog.Error($"Error registering IPC provider for {LabelProviderAddToWhitelist}:\n{e}");
}

try
{
this.ProviderRemoveFromWhitelist =
VisibilityPlugin.PluginInterface.GetIpcProvider<string, uint, object>(LabelProviderRemoveFromWhitelist);
Service.PluginInterface.GetIpcProvider<string, uint, object>(LabelProviderRemoveFromWhitelist);
this.ProviderRemoveFromWhitelist.RegisterAction(api.RemoveFromWhitelist);
}
catch (Exception e)
{
PluginLog.Error($"Error registering IPC provider for {LabelProviderRemoveFromWhitelist}:\n{e}");
Service.PluginLog.Error($"Error registering IPC provider for {LabelProviderRemoveFromWhitelist}:\n{e}");
}

try
{
this.ProviderEnable =
VisibilityPlugin.PluginInterface.GetIpcProvider<bool, object>(LabelProviderEnable);
Service.PluginInterface.GetIpcProvider<bool, object>(LabelProviderEnable);
this.ProviderEnable.RegisterAction(api.Enable);
this.ProviderEnable?.SendMessage(true);
}
catch (Exception e)
{
PluginLog.Error($"Error registering IPC provider for {LabelProviderEnable}:\n{e}");
Service.PluginLog.Error($"Error registering IPC provider for {LabelProviderEnable}:\n{e}");
}
}

Expand Down
38 changes: 38 additions & 0 deletions Visibility/Service.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Dalamud.IoC;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;

namespace Visibility;

public class Service
{
[PluginService]
public static DalamudPluginInterface PluginInterface { get; set; } = null!;

[PluginService]
public static ICommandManager CommandManager { get; set; } = null!;

[PluginService]
public static IChatGui ChatGui { get; set; } = null!;

[PluginService]
public static IDataManager DataManager { get; set; } = null!;

[PluginService]
public static IGameGui GameGui { get; set; } = null!;

[PluginService]
public static IClientState ClientState { get; set; } = null!;

[PluginService]
public static IFramework Framework { get; set; } = null!;

[PluginService]
public static IObjectTable ObjectTable { get; set; } = null!;

[PluginService]
public static ICondition Condition { get; set; } = null!;

[PluginService]
public static IPluginLog PluginLog { get; set; } = null!;
}
24 changes: 12 additions & 12 deletions Visibility/Utils/FrameworkHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,21 @@ public unsafe void Update()
{
var localPlayerGameObject =
FFXIVClientStructs.FFXIV.Client.Game.Object.GameObjectManager.GetGameObjectByIndex(0);
var namePlateWidget = VisibilityPlugin.GameGui.GetAddonByName("NamePlate");
var namePlateWidget = Service.GameGui.GetAddonByName("NamePlate");

if (namePlateWidget == nint.Zero ||
(!((AtkUnitBase*)namePlateWidget)->IsVisible && !VisibilityPlugin.Condition[ConditionFlag.Performing]) ||
(!((AtkUnitBase*)namePlateWidget)->IsVisible && !Service.Condition[ConditionFlag.Performing]) ||
localPlayerGameObject == null || localPlayerGameObject->ObjectID == 0xE0000000 ||
VisibilityPlugin.Instance.Disable || this.isChangingTerritory)
{
return;
}

var isBound = (VisibilityPlugin.Condition[ConditionFlag.BoundByDuty] &&
var isBound = (Service.Condition[ConditionFlag.BoundByDuty] &&
localPlayerGameObject->EventId.Type != EventHandlerType.TreasureHuntDirector)
|| VisibilityPlugin.Condition[ConditionFlag.BetweenAreas]
|| VisibilityPlugin.Condition[ConditionFlag.WatchingCutscene]
|| VisibilityPlugin.Condition[ConditionFlag.DutyRecorderPlayback];
|| Service.Condition[ConditionFlag.BetweenAreas]
|| Service.Condition[ConditionFlag.WatchingCutscene]
|| Service.Condition[ConditionFlag.DutyRecorderPlayback];

var localPlayer = (Character*)localPlayerGameObject;

Expand Down Expand Up @@ -134,7 +134,7 @@ public unsafe void Update()
: // Earthly Star
{
if (VisibilityPlugin.Instance.Configuration is { Enabled: true, HideStar: true }
&& VisibilityPlugin.Condition[ConditionFlag.InCombat]
&& Service.Condition[ConditionFlag.InCombat]
&& characterPtr->GameObject.OwnerID != localPlayer->GameObject.ObjectID
&& !this.containers[UnitType.Players][ContainerType.Party]
.ContainsKey(characterPtr->GameObject.OwnerID))
Expand Down Expand Up @@ -207,7 +207,7 @@ private unsafe void PlayerHandler(Character* characterPtr, Character* localPlaye
}

if (isBound && !VisibilityPlugin.Instance.Configuration.TerritoryTypeWhitelist.Contains(
VisibilityPlugin.ClientState.TerritoryType))
Service.ClientState.TerritoryType))
{
return;
}
Expand Down Expand Up @@ -514,7 +514,7 @@ private static unsafe bool IsObjectIdInParty(uint objectId)
return false;
}

foreach (var group in infoProxyCrossRealm->CrossRealmGroupSpan)
foreach (var group in infoProxyCrossRealm->CrossRealmGroupArraySpan)
{
if (group.GroupMemberCount == 0)
{
Expand All @@ -523,7 +523,7 @@ private static unsafe bool IsObjectIdInParty(uint objectId)

for (var i = 0; i < group.GroupMemberCount; ++i)
{
if (group.GroupMemberSpan[i].ObjectId == objectId)
if (group.GroupMembersSpan[i].ObjectId == objectId)
{
return true;
}
Expand Down Expand Up @@ -605,12 +605,12 @@ public void OnTerritoryChanged()

public unsafe void ShowAll()
{
if (VisibilityPlugin.ClientState.LocalPlayer == null)
if (Service.ClientState.LocalPlayer == null)
{
return;
}

foreach (var actor in VisibilityPlugin.ObjectTable)
foreach (var actor in Service.ObjectTable)
{
var thisPtr = (Character*)actor.Address;

Expand Down
6 changes: 3 additions & 3 deletions Visibility/Visibility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<LangVersion>default</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable>
<AssemblyVersion>1.1.5.1</AssemblyVersion>
<AssemblyVersion>1.1.6.0</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<IsPackable>false</IsPackable>
<Authors>SheepGoMeh</Authors>
Expand Down Expand Up @@ -61,8 +61,8 @@
</Reference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Dalamud.ContextMenu" Version="1.2.3" />
<PackageReference Include="DalamudPackager" Version="2.1.11" />
<PackageReference Include="Dalamud.ContextMenu" Version="1.3.1" />
<PackageReference Include="DalamudPackager" Version="2.1.12" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\Resources.Designer.cs">
Expand Down
Loading

0 comments on commit 6fe8d4a

Please sign in to comment.