generated from karashiiro/DalamudPluginProjectTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
UiJournalResultHandler.cs
101 lines (89 loc) · 3.12 KB
/
UiJournalResultHandler.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
94
95
96
97
98
99
100
101
// <copyright file="UiJournalResultHandler.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 UiJournalResultHandler(AddonEvent type, AddonArgs args)
{
if (!this.configuration.TranslateJournal)
{
return;
}
if (args is not AddonSetupArgs setupArgs)
{
return;
}
var setupAtkValues = (AtkValue*)setupArgs.AtkValues;
if (setupAtkValues == null)
{
return;
}
try
{
if (setupAtkValues[1].Type != FFXIVClientStructs.FFXIV.Component.GUI.ValueType.String || setupAtkValues[1].String == null)
{
return;
}
var questNameText = MemoryHelper.ReadSeStringAsString(out _, (nint)setupAtkValues[1].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
if (this.configuration.RemoveDiacriticsWhenUsingReplacementQuest)
{
foundQuestPlate.TranslatedQuestName = this.RemoveDiacritics(foundQuestPlate.TranslatedQuestName, this.SpecialCharsSupportedByGameFont);
}
setupAtkValues[1].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
if (this.configuration.RemoveDiacriticsWhenUsingReplacementQuest)
{
translatedNameText = this.RemoveDiacritics(translatedNameText, this.SpecialCharsSupportedByGameFont);
}
setupAtkValues[1].SetManagedString(translatedNameText);
}
}
catch (Exception e)
{
PluginLog.Error("UiJournalResultHandler Exception: " + e.StackTrace);
}
}
}
}