Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API 8 tag added to json #13

Open
wants to merge 186 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
186 commits
Select commit Hold shift + click to select a range
c0f4339
compatibility with API v6
Pilzinsel64 May 11, 2022
cab8de1
revert links in PlayerTags.json
Pilzinsel64 May 11, 2022
b43935f
disable context menu on all places (keep in settings back-end)
Pilzinsel64 May 29, 2022
14899c6
updated version and description
Pilzinsel64 Jun 15, 2022
4a68edd
fix wrong version in plugin info
Pilzinsel64 Jun 15, 2022
342cb79
use Dalamud's ContextMenu
Pilzinsel64 Jun 15, 2022
5d6a8f5
fix plugin info
Pilzinsel64 Jun 15, 2022
dc9e17a
keep original author
Pilzinsel64 Jun 15, 2022
3a524f1
fix plugin info again
Pilzinsel64 Jun 15, 2022
894bb08
change names of image files and remove some
Pilzinsel64 Jun 16, 2022
9e15f02
remove ImageURLs in plugin info
Pilzinsel64 Jun 16, 2022
7e28f02
use Dalamug.ContextMenu
Pilzinsel64 Jun 16, 2022
08ddc9a
plish up & don't use sub items in context menu
Pilzinsel64 Jun 17, 2022
5dde457
Merge branch 'new-context-menu-integration'
Pilzinsel64 Jun 17, 2022
617d666
cahnge version to v1.3
Pilzinsel64 Jun 17, 2022
28d56fe
increase default window size
Pilzinsel64 Jun 18, 2022
5085502
add german translation
Pilzinsel64 Jun 18, 2022
cb81c54
Create README.md
Pilzinsel64 Jun 29, 2022
a3b482d
use Hook<T>.FromAddress() instead of new Hook<T>()
Pilzinsel64 Jul 13, 2022
3ea1f8f
use PluginInterface.AssemblyLocation & move paths to resource file
Pilzinsel64 Jul 14, 2022
90c6af7
Merge branch 'main' of https://github.com/Pilzinsel64/PlayerTags
Pilzinsel64 Jul 14, 2022
8472e5c
change version to v1.4
Pilzinsel64 Jul 14, 2022
25103c0
Update README.md
Pilzinsel64 Aug 2, 2022
c35e4e4
Add how to combine with PartyIcons
Pilzinsel64 Aug 6, 2022
95d36c1
disable NULL value warnings
Pilzinsel64 Aug 24, 2022
f810dea
target .NET 6
Pilzinsel64 Aug 24, 2022
3a11764
update NuGet packages
Pilzinsel64 Aug 24, 2022
69a0bd5
use new DalamudContextMenu instead of DalamudContextMenuBase
Pilzinsel64 Aug 24, 2022
9c76b29
change version to v1.5
Pilzinsel64 Aug 24, 2022
a033ee6
Fix naming of how to documentation
Pilzinsel64 Aug 24, 2022
3ba38ad
Merge branch 'main' of https://github.com/Pilzinsel64/PlayerTags
Pilzinsel64 Aug 24, 2022
306d7f1
prepair project for api7 branche
Pilzinsel64 Aug 24, 2022
0be77a2
minor fixes
Pilzinsel64 Aug 24, 2022
86e8d2d
use seperated ActivityContextManager class & pre-pair testing stuff f…
Pilzinsel64 Aug 29, 2022
499d3c1
revert any self linking chat fix changes
Pilzinsel64 Sep 1, 2022
c3ddd05
revert last changes
Pilzinsel64 Sep 1, 2022
7a37aa6
add backend possiblity to define general settings per ActivityContext…
Pilzinsel64 Sep 2, 2022
3dc7e93
add backend possiblity to define general settings per ActivityContext…
Pilzinsel64 Sep 2, 2022
ae9e7dc
Merge branch 'main' of https://github.com/Pilzinsel64/PlayerTags
Pilzinsel64 Sep 2, 2022
1c0564b
some more work moving settings around
Pilzinsel64 Sep 2, 2022
39b49fb
disable writing Text color in TagTargetFeature, it's working out of t…
Pilzinsel64 Sep 2, 2022
e0718ac
optimize code for coloring names
Pilzinsel64 Sep 3, 2022
0f80e54
Add chinese translation
Pilzinsel64 Sep 3, 2022
4b60fa1
add ui option for activity context profiles
Pilzinsel64 Sep 3, 2022
8d40744
update translation files
Pilzinsel64 Sep 3, 2022
c63998e
change version to v1.6
Pilzinsel64 Sep 3, 2022
5007e22
adjust default options (show icon and color in nameplate except on fr…
Pilzinsel64 Sep 3, 2022
4ed9cac
fix typo
Pilzinsel64 Sep 3, 2022
bec210b
change version to v1.6.1
Pilzinsel64 Sep 3, 2022
3ac85bd
don't show color by default on nameplate name
Pilzinsel64 Sep 3, 2022
4a3c712
enable text coloring again for player tag
Pilzinsel64 Sep 3, 2022
d4a15bd
change version to v1.6.2
Pilzinsel64 Sep 3, 2022
e01a3bc
revert default option
Pilzinsel64 Sep 3, 2022
4cd90a8
disable glow color for whole text again
Pilzinsel64 Sep 3, 2022
2cf5f83
update spanish translation
Pilzinsel64 Sep 4, 2022
ae2f191
change version to v1.6.3
Pilzinsel64 Sep 4, 2022
2a16aa1
Add current translation contributors to README
Pilzinsel64 Sep 4, 2022
2c2286a
Update README.md
Pilzinsel64 Sep 4, 2022
3a3db49
Update README.md
Pilzinsel64 Sep 4, 2022
59fc6d4
LinkSelfInChatFeature: fix right content of message gets chropped and…
Pilzinsel64 Sep 5, 2022
e5bcd4a
Merge branch 'main' of https://github.com/Pilzinsel64/PlayerTags
Pilzinsel64 Sep 5, 2022
a3197d8
change version to v1.6.4
Pilzinsel64 Sep 5, 2022
cd4ccac
use RawPayload.LinkTerminator to terminate PlayerPayload
Pilzinsel64 Sep 6, 2022
d03c91e
use Dalamud language for Localizer
Pilzinsel64 Sep 11, 2022
3f21931
change version to v1.6.5
Pilzinsel64 Sep 11, 2022
1392a9d
use SignatureHelper for Hook
Pilzinsel64 Sep 12, 2022
078649b
update icon
Pilzinsel64 Sep 15, 2022
8d15040
change plugin name to "PlayerTags" (remove whitespace)
Pilzinsel64 Sep 15, 2022
248ef42
keep TextPayload in LinkSelfInChatFeature if ChatTwo is installed
Pilzinsel64 Sep 15, 2022
0ffc845
fully fix PlayerPayload problem for own character
Pilzinsel64 Sep 15, 2022
9e3cfa8
change version to v1.6.6
Pilzinsel64 Sep 15, 2022
2911e5b
more comments and no linkterminator for linkselfinchatfeature
Pilzinsel64 Sep 16, 2022
35ce56a
move things inside of the if in linkselfinchatfeature
Pilzinsel64 Sep 16, 2022
072702f
remove obsulate event
Pilzinsel64 Sep 16, 2022
d04418f
improve position and coloring of party number prefix
Pilzinsel64 Sep 16, 2022
4eee0df
insert tag and icon before party number in chat
Pilzinsel64 Sep 16, 2022
a6c88be
add new options, but not use them yet
Pilzinsel64 Sep 16, 2022
71b9f0f
disable nameplate category in tag properties again for now
Pilzinsel64 Sep 16, 2022
983b090
update translation files
Pilzinsel64 Sep 16, 2022
11619f9
merge self linking feature into ChatTagTargetFeature
Pilzinsel64 Sep 16, 2022
15d5f34
change version to v1.6.7.0
Pilzinsel64 Sep 16, 2022
8993da8
handle "insert behind number prefix"
Pilzinsel64 Sep 16, 2022
b78a54c
change version to v1.7
Pilzinsel64 Sep 17, 2022
f53df97
update translation files
Pilzinsel64 Sep 18, 2022
0a7a76a
change version to v1.7.1
Pilzinsel64 Sep 18, 2022
d42095f
build abbreviated own username in chat self
Pilzinsel64 Sep 18, 2022
111682b
Add info about french translation
Pilzinsel64 Sep 19, 2022
8cb900d
change version to v1.7.2
Pilzinsel64 Sep 19, 2022
152a381
Merge branch 'main' of https://github.com/Pilzinsel64/PlayerTags
Pilzinsel64 Sep 19, 2022
0c89d94
optimize handling in groups and allicance chat
Pilzinsel64 Sep 20, 2022
d6e4b2c
change version to v1.7.3
Pilzinsel64 Sep 20, 2022
feea8fb
add comment
Pilzinsel64 Sep 21, 2022
08a3d37
fix: falsly inserted own player name one index postion to low
Pilzinsel64 Sep 21, 2022
3f0a533
always remove own player link terminator & workaround for List<Payloa…
Pilzinsel64 Sep 21, 2022
525eccf
update some comments
Pilzinsel64 Sep 21, 2022
6612c13
add more comments
Pilzinsel64 Sep 21, 2022
71d0c9e
change version to v1.7.4
Pilzinsel64 Sep 21, 2022
84332da
rename plugin to "PlayerTags"
Pilzinsel64 Sep 21, 2022
aab6cb7
rename plugin to "PlayerTags"
Pilzinsel64 Sep 21, 2022
c6a4891
sd
Pilzinsel64 Sep 21, 2022
b0210a9
ensure +1 with number prefix at own name
Pilzinsel64 Sep 21, 2022
2a18141
simplyfy Nameplate_PlayerNameplateUpdated
Pilzinsel64 Sep 25, 2022
299c741
force custom tag color in chat for name
Pilzinsel64 Sep 25, 2022
755faa6
fix not inserting at number prefix for custom tags
Pilzinsel64 Sep 25, 2022
6784cd3
change version to v1.7.5
Pilzinsel64 Sep 25, 2022
4542318
completely remove ChatTwo references
Pilzinsel64 Oct 30, 2022
2d485b5
rename plugin to "Player Tags" for better searchability
Pilzinsel64 Oct 30, 2022
75d12c9
change version to v1.7.5.1
Pilzinsel64 Oct 30, 2022
ae5f2b8
change title to "Player Tags" in readme
Pilzinsel64 Oct 30, 2022
8e1567a
adjust "name" in PlayerTags.json
Pilzinsel64 Oct 30, 2022
2acda54
Merge branch 'main' of https://github.com/Pilzinsel64/PlayerTags
Pilzinsel64 Oct 30, 2022
d19dbe4
remove unused delegate
Pilzinsel64 Nov 2, 2022
74ddb9e
integrate new ActivityContext
Pilzinsel64 Nov 5, 2022
b81fe05
remove obsulate default constants
Pilzinsel64 Nov 5, 2022
5343b59
merge branche master into v1.8
Pilzinsel64 Nov 5, 2022
1b67251
fix merge conflicts
Pilzinsel64 Nov 5, 2022
d38d974
initialize Pilz.Dalamud lib
Pilzinsel64 Nov 5, 2022
6644b1e
some work
Pilzinsel64 Nov 5, 2022
4025887
some more teststing code
Pilzinsel64 Nov 5, 2022
1629b97
use pluginservices initialise again
Pilzinsel64 Nov 5, 2022
c4baba3
integrate new StringUpdateFactory and NameplateUpdateFactory
Pilzinsel64 Nov 5, 2022
1e3380c
implement job icon feature
Pilzinsel64 Nov 6, 2022
9c927d9
set some json attributes for eventually changes of configuraiton in t…
Pilzinsel64 Nov 8, 2022
2770797
remove currently unneeded configuration
Pilzinsel64 Nov 8, 2022
c2b2fa8
maybe fix wrong(?) operator
Pilzinsel64 Nov 8, 2022
5501d1e
add settings for chat target types (broken state yet)
Pilzinsel64 Nov 9, 2022
fb4ffd3
fix settings finally
Pilzinsel64 Nov 9, 2022
5ee2ad6
add settings ui for status icon priorizer settings
Pilzinsel64 Nov 10, 2022
1d69893
implement Default Plugin Data Templates
Pilzinsel64 Nov 10, 2022
c8a3f75
implement UI for default plugin data template
Pilzinsel64 Nov 10, 2022
e17b884
v1.8
Pilzinsel64 Nov 10, 2022
3e347e2
put Pilz.Dalamud and replace NuGet package with
Pilzinsel64 Nov 13, 2022
1014fcc
handle depricated properties for "IsIconVisibleInChat" and "IsIconVis…
Pilzinsel64 Nov 13, 2022
972f9e8
change version to v1.8.0.1
Pilzinsel64 Nov 13, 2022
3849644
add dead player handling (backend)
Pilzinsel64 Nov 15, 2022
2fa6d6b
fix not using icon set from tag
Pilzinsel64 Nov 15, 2022
4764a35
fix status icon is visible if tag is not
Pilzinsel64 Nov 15, 2022
649c75a
fix status icon priorizing doesn't work
Pilzinsel64 Nov 15, 2022
5eaa7d1
add ui for dead player handling
Pilzinsel64 Nov 15, 2022
6ec3a1a
version 1.8.0.2
Pilzinsel64 Nov 15, 2022
8573555
finally fix status icon priorizing & add new option
Pilzinsel64 Nov 15, 2022
dc365bf
v1.8.0.3
Pilzinsel64 Nov 15, 2022
17fff44
fix naming
Pilzinsel64 Nov 15, 2022
14bb07f
use gray color at text formatting applying
Pilzinsel64 Nov 16, 2022
164f611
use gray color at text formatting applying
Pilzinsel64 Nov 16, 2022
cce0f95
v1.8.0.4 testing
Pilzinsel64 Nov 17, 2022
01385d8
Merge branch 'v1.8' of https://github.com/Pilzinsel64/PlayerTags into…
Pilzinsel64 Nov 17, 2022
103a826
optimize dead player handling a bit
Pilzinsel64 Nov 17, 2022
cfbe84d
v1.8.0.5 Testing
Pilzinsel64 Nov 17, 2022
dcecc83
update translation files
Pilzinsel64 Nov 17, 2022
8f74555
change version to v1.8.0.6
Pilzinsel64 Nov 20, 2022
f9436e9
Merge pull request #15 from Pilzinsel64/v1.8
Pilzinsel64 Nov 20, 2022
399766a
fix conifg backward-compatibility due private fields
Pilzinsel64 Nov 21, 2022
ecde52a
v1.8.0.7
Pilzinsel64 Nov 21, 2022
8e28a60
finally fix config backward-compatibility
Pilzinsel64 Nov 21, 2022
6a7e336
v1.8.0.8
Pilzinsel64 Nov 21, 2022
1a8fbf5
IsIconVisibleInNameplates old config fix - no clue why
Pilzinsel64 Nov 21, 2022
48973ae
v1.8.0.9
Pilzinsel64 Nov 21, 2022
d5248e0
fix ignoring Target Chat Type
Pilzinsel64 Nov 22, 2022
4cebded
v1.8.1
Pilzinsel64 Nov 23, 2022
2b61a57
update translation files
Pilzinsel64 Nov 23, 2022
dfda152
fix typos
Pilzinsel64 Nov 23, 2022
65d5dad
fix typos
Pilzinsel64 Nov 23, 2022
30ae07b
fix typo
Pilzinsel64 Nov 23, 2022
df74b2d
update translation files
Pilzinsel64 Nov 23, 2022
e9617b6
v1.8.2
Pilzinsel64 Nov 27, 2022
c0eb7b7
change & to && isTagEnabled()
Pilzinsel64 Dec 7, 2022
8c8683c
enable tags on ALL chat messages, regardless if the Chat Type is defined
Pilzinsel64 Dec 7, 2022
16b0d1f
add option to also include undefined chat types
Pilzinsel64 Dec 7, 2022
5bb3335
v1.8.3
Pilzinsel64 Dec 7, 2022
7527e4f
update translation files
Pilzinsel64 Dec 10, 2022
5734e0d
v1.8.3.1
Pilzinsel64 Dec 10, 2022
32b73aa
a few hight-DPI improvements
Pilzinsel64 Dec 19, 2022
89c0f21
simplyfy GetIdentity
Pilzinsel64 Dec 19, 2022
078bb3a
v1.8.4.0
Pilzinsel64 Dec 19, 2022
be9a450
use ImGuiHelper
Pilzinsel64 Dec 19, 2022
6589412
v1.8.4.1
Pilzinsel64 Dec 19, 2022
61ea6f4
Update README.md
Pilzinsel64 Jan 1, 2023
ab48338
Update README.md
Pilzinsel64 Jan 1, 2023
d13672b
Add Japanese by Refer to README.md
Pilzinsel64 Jan 7, 2023
4673928
update translation files
Pilzinsel64 Jan 7, 2023
1757665
Merge branch 'main' of https://github.com/Pilzinsel64/PlayerTags
Pilzinsel64 Jan 7, 2023
bde3726
adjust for API 8
Pilzinsel64 Jan 9, 2023
fa567b5
adjust for API8 also for Pilz.Dalamud
Pilzinsel64 Jan 9, 2023
c24d7f3
minimal polishing up
Pilzinsel64 Jan 11, 2023
ee18346
Update PlayerTags.json
RaylaValdez Jan 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Pilz.Dalamud/ActivityContexts/ActivityContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pilz.Dalamud.ActivityContexts
{
public class ActivityContext
{
public ActivityType ActivityType { get; init; }
public ZoneType ZoneType { get; init; }

public ActivityContext(ActivityType activityType, ZoneType zoneType)
{
ActivityType = activityType;
ZoneType = zoneType;
}

public bool IsInDuty
{
get => ZoneType != ZoneType.Overworld;
}
}
}
85 changes: 85 additions & 0 deletions Pilz.Dalamud/ActivityContexts/ActivityContextManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using Dalamud.Logging;
using Lumina.Excel;
using Lumina.Excel.GeneratedSheets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pilz.Dalamud.ActivityContexts
{
public class ActivityContextManager : IDisposable
{
public delegate void ActivityContextChangedEventHandler(ActivityContextManager sender, ActivityContext activityContext);
public event ActivityContextChangedEventHandler ActivityContextChanged;

private readonly ExcelSheet<ContentFinderCondition> contentFinderConditionsSheet;

public ActivityContext CurrentActivityContext { get; protected set; }

public ActivityContextManager()
{
// Get condition sheet
contentFinderConditionsSheet = PluginServices.DataManager.GameData.GetExcelSheet<ContentFinderCondition>();

// Checks current territory type (if enabled/installed during a dutiy e.g.)
CheckCurrentTerritory();

// Enable event for automatic checks
PluginServices.ClientState.TerritoryChanged += ClientState_TerritoryChanged;
}

public void Dispose()
{
PluginServices.ClientState.TerritoryChanged -= ClientState_TerritoryChanged;
}

private void ClientState_TerritoryChanged(object? sender, ushort e)
{
CheckCurrentTerritory();
}

private void CheckCurrentTerritory()
{
var content = contentFinderConditionsSheet.FirstOrDefault(c => c.TerritoryType.Row == PluginServices.ClientState.TerritoryType);
ActivityType newActivityContext;
ZoneType newZoneType;

if (content == null)
{
// No content found, so we must be on the overworld
newActivityContext = ActivityType.None;
newZoneType = ZoneType.Overworld;
}
else
{
// Check for ActivityContext
if (content.PvP)
newActivityContext = ActivityType.PvpDuty;
else
newActivityContext = ActivityType.PveDuty;

// Find correct member type
var memberType = content.ContentMemberType.Row;
if (content.RowId == 16 || content.RowId == 15)
memberType = 2; // Praetorium and Castrum Meridianum
else if (content.RowId == 735 || content.RowId == 778)
memberType = 127; // Bozja

// Check for ZoneType
newZoneType = memberType switch
{
2 => ZoneType.Dungeon,
3 => ZoneType.Raid,
4 => ZoneType.AllianceRaid,
127 => ZoneType.Foray,
_ => ZoneType.Dungeon,
};
}

CurrentActivityContext = new(newActivityContext, newZoneType);
ActivityContextChanged?.Invoke(this, CurrentActivityContext);
}
}
}
18 changes: 18 additions & 0 deletions Pilz.Dalamud/ActivityContexts/ActivityType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pilz.Dalamud.ActivityContexts
{
[JsonConverter(typeof(StringEnumConverter))]
public enum ActivityType
{
None = 0x0,
PveDuty = 0x1,
PvpDuty = 0x2
}
}
20 changes: 20 additions & 0 deletions Pilz.Dalamud/ActivityContexts/ZoneType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pilz.Dalamud.ActivityContexts
{
[JsonConverter(typeof(StringEnumConverter))]
public enum ZoneType
{
Overworld,
Dungeon,
Raid,
AllianceRaid,
Foray
}
}
41 changes: 41 additions & 0 deletions Pilz.Dalamud/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Dalamud.Game.Text.SeStringHandling;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pilz.Dalamud
{
public static class Extensions
{
/// <summary>
/// Removes a Payload from a given SeString.
/// Using <code>SeString.Payloads.Remove()</code> does not use the reference to compare for some reason. Tis is a workaround.
/// </summary>
/// <param name="seString"></param>
/// <param name="payload"></param>
public static void Remove(this SeString seString, Payload payload)
{
Remove(seString.Payloads, payload);
}

/// <summary>
/// Removes a Payload from a given list.
/// Using <code>List.Remove()</code> does not use the reference to compare for some reason. Tis is a workaround.
/// </summary>
/// <param name="seString"></param>
/// <param name="payload"></param>
public static void Remove(this List<Payload> payloads, Payload payload)
{
for (int i = 0; i < payloads.Count; i++)
{
if (ReferenceEquals(payloads[i], payload))
{
payloads.RemoveAt(i);
break;
}
}
}
}
}
153 changes: 153 additions & 0 deletions Pilz.Dalamud/GameInterfaceHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
using Dalamud.Game.Text.SeStringHandling;
using FFXIVClientStructs.FFXIV.Client.System.Memory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Pilz.Dalamud
{
public static class GameInterfaceHelper
{
public static SeString ReadSeString(IntPtr ptr)
{
if (ptr == IntPtr.Zero)
{
return new SeString();
}

if (TryReadStringBytes(ptr, out var bytes) && bytes != null)
{
return SeString.Parse(bytes);
}

return new SeString();
}

public static bool TryReadSeString(IntPtr ptr, out SeString? seString)
{
seString = null;
if (ptr == IntPtr.Zero)
{
return false;
}

if (TryReadStringBytes(ptr, out var bytes) && bytes != null)
{
seString = SeString.Parse(bytes);
return true;
}

return false;
}

public static string? ReadString(IntPtr ptr)
{
if (ptr == IntPtr.Zero)
{
return null;
}

if (TryReadStringBytes(ptr, out var bytes) && bytes != null)
{
return Encoding.UTF8.GetString(bytes);
}

return null;
}

public static bool TryReadString(IntPtr ptr, out string? str)
{
str = null;
if (ptr == IntPtr.Zero)
{
return false;
}

if (TryReadStringBytes(ptr, out var bytes) && bytes != null)
{
str = Encoding.UTF8.GetString(bytes);
return true;
}

return false;
}

public static bool TryReadStringBytes(IntPtr ptr, out byte[]? bytes)
{
bytes = null;
if (ptr == IntPtr.Zero)
{
return false;
}

var size = 0;
while (Marshal.ReadByte(ptr, size) != 0)
{
size++;
}

bytes = new byte[size];
Marshal.Copy(ptr, bytes, 0, size);

return true;
}

public static IntPtr PluginAllocate(byte[] bytes)
{
IntPtr pointer = Marshal.AllocHGlobal(bytes.Length + 1);
Marshal.Copy(bytes, 0, pointer, bytes.Length);
Marshal.WriteByte(pointer, bytes.Length, 0);

return pointer;
}

public static IntPtr PluginAllocate(SeString seString)
{
return PluginAllocate(seString.Encode());
}

public static void PluginFree(IntPtr ptr)
{
Marshal.FreeHGlobal(ptr);
}

public static void PluginFree(ref IntPtr ptr)
{
PluginFree(ptr);
ptr = IntPtr.Zero;
}

public static byte[] NullTerminate(this byte[] bytes)
{
if (bytes.Length == 0 || bytes[bytes.Length - 1] != 0)
{
var newBytes = new byte[bytes.Length + 1];
Array.Copy(bytes, newBytes, bytes.Length);
newBytes[^1] = 0;

return newBytes;
}

return bytes;
}

public static unsafe IntPtr GameUIAllocate(ulong size)
{
return (IntPtr)IMemorySpace.GetUISpace()->Malloc(size, 0);
}

public static unsafe void GameFree(ref IntPtr ptr, ulong size)
{
if (ptr == IntPtr.Zero)
{
return;
}

IMemorySpace.Free((void*)ptr, size);
ptr = IntPtr.Zero;
}
}
}
27 changes: 27 additions & 0 deletions Pilz.Dalamud/Icons/JobIconSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Pilz.Dalamud.Icons
{
public class JobIconSet
{
private readonly int[] icons;

public float IconScale { get; init; }

public JobIconSet(int[] icons, float iconScale)
{
this.icons = icons;
IconScale = iconScale;
}

public int GetIcon(uint jobID)
{
return icons[jobID - 1];
}
}
}
Loading