generated from karashiiro/DalamudPluginProjectTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
UICharacterWindowHandler.cs
75 lines (61 loc) · 2.58 KB
/
UICharacterWindowHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// <copyright file="UICharacterWindowHandler.cs" company="lokinmodar">
// Copyright (c) lokinmodar. All rights reserved.
// Licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License license.
// </copyright>
using Dalamud.Memory;
using FFXIVClientStructs.FFXIV.Component.GUI;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType;
namespace Echoglossian
{
public partial class Echoglossian
{
public bool GatheringCharacterWindowAtkValuesComplete = false;
public Dictionary<int, string> CharacterWindowAtkValues = new Dictionary<int, string>();
public string CharacterWindowAtkValuesString = string.Empty; // New string to store the concatenated output
private unsafe void TranslateCharacterWindow()
{
var atkStg = AtkStage.Instance();
var characterWB = atkStg->RaptureAtkUnitManager->GetAddonByName("Character");
if (characterWB == null || !characterWB->IsVisible)
{
return;
}
var cwAtkVals = characterWB->AtkValues;
var cwAtkValsCount = characterWB->AtkValuesCount;
if (cwAtkVals == null)
{
return;
}
// Use LINQ to gather values into the dictionary
this.CharacterWindowAtkValues = Enumerable.Range(0, cwAtkValsCount)
.Where(i => cwAtkVals[i].Type == ValueType.String || cwAtkVals[i].Type == ValueType.String8)
.Select(i => new
{
Index = i,
Value = MemoryHelper.ReadSeStringAsString(out _, (nint)cwAtkVals[i].String),
})
.Where(x => x.Value != null)
.ToDictionary(x => x.Index, x => x.Value);
if (this.CharacterWindowAtkValues.Count > 0)
{
string jsonOutput = JsonConvert.SerializeObject(this.CharacterWindowAtkValues, Formatting.Indented);
PluginLog.Debug($"Character window AtkValues: {jsonOutput}");
// Concatenate key-value pairs into a single string
this.CharacterWindowAtkValuesString = string.Join("|", this.CharacterWindowAtkValues.Select(kvp => $"{kvp.Key}|{kvp.Value}"));
}
bool isGatheringComplete = this.CharacterWindowAtkValues.Count > 0;
this.GatheringCharacterWindowAtkValuesComplete = isGatheringComplete;
if (isGatheringComplete)
{
PluginLog.Debug("Finished gathering all Character window AtkValues.");
PluginLog.Debug($"Character window AtkValues string: {this.CharacterWindowAtkValuesString}");
}
}
}
}