generated from karashiiro/DalamudPluginProjectTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathUiAreaMapHandler.cs
93 lines (84 loc) · 2.74 KB
/
UiAreaMapHandler.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// <copyright file="UiAreaMapHandler.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 System;
using Dalamud.Game.Addon.Lifecycle;
using Dalamud.Game.Addon.Lifecycle.AddonArgTypes;
using Dalamud.Memory;
using Echoglossian.EFCoreSqlite.Models.Journal;
using FFXIVClientStructs.FFXIV.Component.GUI;
using Humanizer;
namespace Echoglossian
{
public partial class Echoglossian
{
private unsafe void UiAreaMapHandler(AddonEvent type, AddonArgs args)
{
#if DEBUG
PluginLog.Debug($"UiAreaMapHandler AddonEvent: {type} {args.AddonName}");
#endif
if (!this.configuration.TranslateJournal)
{
return;
}
if (args is not AddonRefreshArgs setupArgs)
{
return;
}
var setupAtkValues = (AtkValue*)setupArgs.AtkValues;
if (setupAtkValues == null)
{
return;
}
try
{
if (setupAtkValues[142].Type != FFXIVClientStructs.FFXIV.Component.GUI.ValueType.String || setupAtkValues[142].String == null)
{
return;
}
var questNameText = MemoryHelper.ReadSeStringAsString(out _, (nint)setupAtkValues[142].String);
if (questNameText == string.Empty)
{
return;
}
QuestPlate questPlate = this.FormatQuestPlate(questNameText, string.Empty);
QuestPlate foundQuestPlate = this.FindQuestPlateByName(questPlate);
if (foundQuestPlate != null)
{
#if DEBUG
PluginLog.Debug($"Name from database: {questNameText} -> {foundQuestPlate.TranslatedQuestName}");
#endif
setupAtkValues[142].SetManagedString(foundQuestPlate.TranslatedQuestName);
}
else
{
var translatedNameText = this.Translate(questNameText);
#if DEBUG
PluginLog.Debug($"Name translated: {questNameText} -> {translatedNameText}");
#endif
QuestPlate translatedQuestPlate = new(
questNameText,
string.Empty,
ClientStateInterface.ClientLanguage.Humanize(),
translatedNameText,
string.Empty,
string.Empty,
langDict[languageInt].Code,
this.configuration.ChosenTransEngine,
DateTime.Now,
DateTime.Now);
string result = this.InsertQuestPlate(translatedQuestPlate);
#if DEBUG
PluginLog.Debug($"Using QuestPlate Replace - QuestPlate DB Insert operation result: {result}");
#endif
setupAtkValues[142].SetManagedString(translatedNameText);
}
}
catch (Exception e)
{
PluginLog.Error("Exception at UiAreaMapHandler: " + e);
}
}
}
}