generated from karashiiro/DalamudPluginProjectTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
UiJournalAcceptHandler.cs
107 lines (94 loc) · 3.54 KB
/
UiJournalAcceptHandler.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
102
103
104
105
106
107
// <copyright file="UiJournalAcceptHandler.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 UiJournalAcceptHandler(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
{
string questName = MemoryHelper.ReadSeStringAsString(out _, (nint)setupAtkValues[5].String);
string questMessage = MemoryHelper.ReadSeStringAsString(out _, (nint)setupAtkValues[12].String);
#if DEBUG
PluginLog.Debug($"Language: {ClientStateInterface.ClientLanguage.Humanize()}");
PluginLog.Debug($"Quest name: {questName}");
PluginLog.Debug($"Quest message: {questMessage}");
#endif
QuestPlate questPlate = this.FormatQuestPlate(questName, questMessage);
QuestPlate foundQuestPlate = this.FindQuestPlate(questPlate);
string translatedQuestName;
string translatedQuestMessage;
// If the quest is not saved
if (foundQuestPlate == null)
{
translatedQuestName = this.Translate(questName);
translatedQuestMessage = this.Translate(questMessage);
#if DEBUG
PluginLog.Debug($"Translated quest name: {translatedQuestName}");
PluginLog.Debug($"Translated quest message: {translatedQuestMessage}");
#endif
QuestPlate translatedQuestPlate = new(
questName,
questMessage,
ClientStateInterface.ClientLanguage.Humanize(),
translatedQuestName,
translatedQuestMessage,
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
}
else
{ // if the data is already in the DB
translatedQuestName = foundQuestPlate.TranslatedQuestName;
translatedQuestMessage = foundQuestPlate.TranslatedQuestMessage;
#if DEBUG
PluginLog.Debug($"From database - Name: {translatedQuestName}, Message: {translatedQuestMessage}");
#endif
}
#if DEBUG
PluginLog.Debug($"Using QuestPlate Replace - {translatedQuestName}: {translatedQuestMessage}");
#endif
if (this.configuration.RemoveDiacriticsWhenUsingReplacementQuest)
{
translatedQuestName = this.RemoveDiacritics(translatedQuestName, this.SpecialCharsSupportedByGameFont);
translatedQuestMessage = this.RemoveDiacritics(translatedQuestMessage, this.SpecialCharsSupportedByGameFont);
}
setupAtkValues[5].SetManagedString(translatedQuestName);
setupAtkValues[12].SetManagedString(translatedQuestMessage);
}
catch (Exception e)
{
PluginLog.Error("Exception: " + e.StackTrace);
}
}
}
}