Skip to content

Commit

Permalink
Various minor fixes after game update
Browse files Browse the repository at this point in the history
  • Loading branch information
Osmodium committed Jun 29, 2024
1 parent 7df2c87 commit bf0c61b
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 50 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
By [Osmodium](https://github.com/Osmodium)

## This mod is made for Warhammer 40K: Rogue Trader and introduces TTS (TextToSpeech) in most places.
Version: 0.9.6
Version: 0.9.7

**Disclaimer: UNDER DEVELOPMENT**

Expand Down
2 changes: 1 addition & 1 deletion SpeechMod/Configuration/UI/OwlcatUITools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static class OwlcatUITools
{
public static UISettingsGroup MakeSettingsGroup(string key, string name, params UISettingsEntityBase[] settings)
{
UISettingsGroup group = ScriptableObject.CreateInstance<UISettingsGroup>();
var group = ScriptableObject.CreateInstance<UISettingsGroup>();
group.name = key;
group.Title = ModLocalizationManager.CreateString(key, name);

Expand Down
5 changes: 3 additions & 2 deletions SpeechMod/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.IO;
using System;
using System;
using System.IO;

namespace SpeechMod;

Expand All @@ -12,6 +12,7 @@ public static class Constants
public const string BREAK_TOKEN_SHORT = " _speechmod_break_short_ ";
public const string BREAK_TOKEN_MEDIUM = " _speechmod_break_medium_ ";
public const string BREAK_TOKEN_LONG = " _speechmod_break_long_ ";
public const string NARRATOR_COLOR_CODE = "3c2d0a";

public static readonly string LOCAL_LOW_PATH = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)) + "Low";
}
2 changes: 1 addition & 1 deletion SpeechMod/Info.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"AssemblyName": "W40KRTSpeechMod.dll",
"EntryMethod": "SpeechMod.Main.Load",
"HomePage": "https://www.nexusmods.com/warhammer40kroguetrader/mods/75",
"Version": "0.9.6"
"Version": "0.9.7"
}
4 changes: 2 additions & 2 deletions SpeechMod/Keybinds/PlaybackStop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private static class Patches
private static void Add(CommonPCView __instance)
{
#if DEBUG
Debug.Log($"{nameof(CommonPCView)}_{nameof(CommonPCView.BindViewImplementation)}_Postfix");
Debug.Log($"{nameof(CommonPCView)}_{nameof(CommonPCView.BindViewImplementation)}_Postfix : {BIND_NAME}");
#endif
__instance?.AddDisposable(Game.Instance!.Keyboard!.Bind(BIND_NAME, delegate { StopPlayback(__instance); }));
}
Expand All @@ -41,7 +41,7 @@ private static void StopPlayback(CommonPCView instance)
if (!Main.Speech?.IsSpeaking() == true)
return;

if (instance != null && instance.m_WarningsTextView != null)
if (instance.m_WarningsTextView != null)
{
if (!LocalizationManager.Instance!.CurrentPack!.TryGetText("osmodium.speechmod.feature.playback.stop.notification", out string text, false))
text = "SpeechMod: Playback stopped!";
Expand Down
6 changes: 3 additions & 3 deletions SpeechMod/Patches/CharInfoSummaryPCView_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public static void HookStatusEffects(CharInfoStatusEffectsView __instance)

__instance.m_StatusEffectsTitle.HookupTextToSpeech();
__instance.m_NoStatusEffectsLabel.HookupTextToSpeech();
__instance.m_WidgetEntityView?.m_Description.HookupTextToSpeech();
//__instance.m_WidgetEntityView?.m_Description.HookupTextToSpeech();
__instance.m_WidgetEntityView?.m_DisplayName.HookupTextToSpeech();
__instance.m_WidgetEntityView?.m_FactDescription.HookupTextToSpeech();
__instance.m_WidgetEntityView?.m_RankText.HookupTextToSpeech();
//__instance.m_WidgetEntityView?.m_FactDescription.HookupTextToSpeech();
//__instance.m_WidgetEntityView?.m_RankText.HookupTextToSpeech();
}

[HarmonyPatch(typeof(CharInfoProfitFactorItemPCView), "BindViewImplementation")]
Expand Down
3 changes: 1 addition & 2 deletions SpeechMod/Patches/MessageBoxPCView_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace SpeechMod.Patches;
[HarmonyPatch(typeof(MessageBoxPCView), "BindViewImplementation")]
public class MessageBoxPCView_Patch
{
private const string MESSAGE_BOX_TEXT_PATH = "/CommonPCView(Clone)/CommonCanvas/MessageBoxPCView/CommonModalWindow/Panel/Content/Layout/Label_Message";
private const string INPUT_BOX_TEXT_PATH = "/MainMenuPCView(Clone)/UICanvas/CharGenContextPCView/CharGenPCView/Content/PhaseDetailedViews/CharGenShipPhaseDetailedPCView/CharGenChangeNameMessageBoxPCView/CommonModalWindow/Panel/Content/Layout/Label_Message";

public static void Postfix(MessageBoxPCView __instance)
Expand All @@ -22,7 +21,7 @@ public static void Postfix(MessageBoxPCView __instance)
Debug.Log($"{nameof(MessageBoxPCView)}_BindViewImplementation_Postfix");
#endif

Hooks.HookUpTextToSpeechOnTransformWithPath(MESSAGE_BOX_TEXT_PATH);
__instance.m_MessageText.HookupTextToSpeech();
if (__instance.m_InputField.IsActive())
{
Hooks.HookUpTextToSpeechOnTransformWithPath(INPUT_BOX_TEXT_PATH);
Expand Down
16 changes: 11 additions & 5 deletions SpeechMod/Patches/NewGamePhaseStoryBaseView_Patch.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
using HarmonyLib;
using Kingmaker.Code.UI.MVVM.View.NewGame.Base;
using SpeechMod.Unity.Extensions;
using UnityEngine.UI;
#if DEBUG
using UnityEngine;
#endif

namespace SpeechMod.Patches;

[HarmonyPatch(typeof(NewGamePhaseStoryBaseView), "BindViewImplementation")]
[HarmonyPatch]
public class NewGamePhaseStoryBaseView_Patch
{
private const string NEWGAME_STORY_INTRODUCTION_PATH = "/MainMenuPCView(Clone)/UICanvas/NewGamePCView/Device/Background (1)/Background/ContentGroup/NewGameTabGameModePCView/PaperGroup/Paper/Content/Description/ServiceWindowStandartScrollVew/Viewport/Content/Text (TMP)";

public static void Postfix()
private const string NEWGAME_STORY_FRAME_PATH = "/MainMenuPCView(Clone)/UICanvas/NewGamePCView/Device/Background (1)/Background/ContentGroup/NewGameTabGameModePCView/Screen_view/ItemView (1)/Description/ServiceWindowStandartScrollVew/Viewport/Content/Frame";
[HarmonyPatch(typeof(NewGamePhaseStoryBaseView), "BindViewImplementation")]
[HarmonyPostfix]
public static void Postfix(NewGamePhaseStoryBaseView __instance)
{
if (!Main.Enabled)
return;
Expand All @@ -21,6 +23,10 @@ public static void Postfix()
Debug.Log($"{nameof(NewGamePhaseStoryBaseView)}_BindViewImplementation_Postfix");
#endif

Hooks.HookUpTextToSpeechOnTransformWithPath(NEWGAME_STORY_INTRODUCTION_PATH);
UIHelper.TryFind(NEWGAME_STORY_FRAME_PATH)?
.GetComponent<Image>()?
.SetRaycastTarget(false);

__instance.m_StoryDescription.HookupTextToSpeech();
}
}
5 changes: 2 additions & 3 deletions SpeechMod/Patches/TooltipEngine_Patch.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using HarmonyLib;
using Kingmaker.Code.UI.MVVM.View.InfoWindow;
using Kingmaker.Code.UI.MVVM.View.Tooltip.Bricks;
using Kingmaker.Code.UI.MVVM.VM.InfoWindow;
using Owlcat.Runtime.UI.Controls.Button;
using Owlcat.Runtime.UI.Tooltips;
using SpeechMod.Unity.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using Kingmaker.Code.UI.MVVM.View.Tooltip.Bricks;
using Kingmaker.Utility;
using Owlcat.Runtime.UI.Controls.Button;
using TMPro;
using UnityEngine;

Expand Down
6 changes: 3 additions & 3 deletions SpeechMod/Unity/AppleVoiceUnity.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Kingmaker;
using Kingmaker.Blueprints.Base;
using SpeechMod.Unity.Extensions;
using System;
using System.Diagnostics;
using System.Text.RegularExpressions;
using SpeechMod.Unity.Extensions;
using UnityEngine;

namespace SpeechMod.Unity;
Expand Down Expand Up @@ -64,9 +64,9 @@ public static void SpeakDialog(string text, float delay = 0f)
text = text.Replace("\\n", " ");
text = text.Replace("\n", " ");
text = text.Replace(";", "");
while (text.IndexOf("<color=#544709>", StringComparison.InvariantCultureIgnoreCase) != -1)
while (text.IndexOf($"<color=#{Constants.NARRATOR_COLOR_CODE}>", StringComparison.InvariantCultureIgnoreCase) != -1)
{
int position = text.IndexOf("<color=#544709>", StringComparison.InvariantCultureIgnoreCase);
int position = text.IndexOf($"<color=#{Constants.NARRATOR_COLOR_CODE}>", StringComparison.InvariantCultureIgnoreCase);
if (position != 0)
{
string argumentsPart = text.Substring(0, position);
Expand Down
9 changes: 5 additions & 4 deletions SpeechMod/Unity/WindowsVoiceUnity.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System;
using SpeechMod.Unity.Extensions;
using System;
using System.Linq;
using System.Runtime.InteropServices;
using SpeechMod.Unity.Extensions;
using UnityEngine;

namespace SpeechMod.Unity;

public class WindowsVoiceUnity : MonoBehaviour
{
enum WindowsVoiceStatus { Uninitialized, Ready, Speaking, Terminated, Error }
public enum WindowsVoiceStatus { Uninitialized, Ready, Speaking, Terminated, Error }

[DllImport(Constants.WINDOWS_VOICE_DLL)]
private static extern void initSpeech(int rate, int volume);
Expand All @@ -33,6 +33,7 @@ enum WindowsVoiceStatus { Uninitialized, Ready, Speaking, Terminated, Error }
private static int m_CurrentWordCount;

public static bool IsSpeaking => getSpeechState() == WindowsVoiceStatus.Speaking;
public static WindowsVoiceStatus VoiceStatus => getSpeechState();

private static void Init()
{
Expand Down Expand Up @@ -67,7 +68,7 @@ public static string[] GetAvailableVoices()
string voicesDelim = getVoicesAvailable();
if (string.IsNullOrWhiteSpace(voicesDelim))
return Array.Empty<string>();
string[] voices = voicesDelim.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
string[] voices = voicesDelim.Split(['\n'], StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < voices.Length; ++i)
{
if (!voices[i].Contains('-'))
Expand Down
24 changes: 5 additions & 19 deletions SpeechMod/Voice/WindowsSpeech.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Linq;
using System.Text.RegularExpressions;
using Kingmaker;
using Kingmaker;
using Kingmaker.Blueprints.Base;
using SpeechMod.Unity;
using System;
using System.Linq;
using System.Text.RegularExpressions;

namespace SpeechMod.Voice;

Expand Down Expand Up @@ -59,7 +59,7 @@ public static int Length(string text)

private string FormatGenderSpecificVoices(string text)
{
text = text.Replace("<i><color=#544709>", $"</voice>{CombinedNarratorVoiceStart}");
text = text.Replace($"<i><color=#{Constants.NARRATOR_COLOR_CODE}>", $"</voice>{CombinedNarratorVoiceStart}");
text = text.Replace("</color></i>", $"</voice>{CombinedDialogVoiceStart}");

if (text.StartsWith("</voice>"))
Expand Down Expand Up @@ -112,31 +112,17 @@ public void SpeakPreview(string text, VoiceType voiceType)

public string PrepareSpeechText(string text)
{
//if (Main.Settings?.LogVoicedLines == true)
// UnityEngine.Debug.Log(text);

text = new Regex("<[^>]+>").Replace(text, "");
text = text.PrepareText();
text = $"{CombinedNarratorVoiceStart}{text}</voice>";

//if (Main.Settings?.LogVoicedLines == true)
// UnityEngine.Debug.Log(text);

return text;
}

public string PrepareDialogText(string text)
{
//if (Main.Settings?.LogVoicedLines == true)
// UnityEngine.Debug.Log(text);

text = text.PrepareText();
text = new Regex("<b><color[^>]+><link([^>]+)?>([^<>]*)</link></color></b>").Replace(text, "$2");
text = FormatGenderSpecificVoices(text);

//if (Main.Settings?.LogVoicedLines == true)
// UnityEngine.Debug.Log(text);

return text;
}

Expand Down
1 change: 1 addition & 0 deletions Todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

✅ Campaign/DLC description when starting a new game
/MainMenuPCView(Clone)/UICanvas/NewGamePCView/Device/Background (1)/Background/ContentGroup/NewGameTabGameModePCView/PaperGroup/Paper/Content/Description/ServiceWindowStandartScrollVew/Viewport/Content/Text (TMP)
/MainMenuPCView(Clone)/UICanvas/NewGamePCView/Device/Background (1)/Background/ContentGroup/NewGameTabGameModePCView/Screen_view/ItemView (1)/Description/ServiceWindowStandartScrollVew/Viewport/Content/Text (TMP)

✅ Custom Character Creation
/MainMenuPCView(Clone)/UICanvas/CharGenContextPCView/CharGenPCView/Content/PhaseDetailedViews/CharGenPregenPhaseDetailedView/DeviceParent/Tablet/Screen_view/ItemView/InfoSection/ScrollView/ViewPort/Content/BodyContainer/TooltipBrickTextView(Clone)/Text
Expand Down
7 changes: 3 additions & 4 deletions WindowsVoice/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ namespace WindowsVoice
{
const LPSTR pText = 0;

::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), pText, 0, nullptr);
::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,nullptr, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), pText, 0, nullptr);
LocalFree(pText);
theStatusMessage = L"Error: Failed to create Voice instance.";
speechState = speech_state_enum::error;
Expand All @@ -48,9 +47,9 @@ namespace WindowsVoice

pVoice->SetRate(rate);
pVoice->SetVolume(volume);

SPVOICESTATUS voiceStatus;
wchar_t* priorText = nullptr;
const wchar_t* priorText = nullptr;
while (!shouldTerminate)
{
pVoice->GetStatus(&voiceStatus, 0);
Expand Down

0 comments on commit bf0c61b

Please sign in to comment.