-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
955 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
/bin/ | ||
/obj/ | ||
/*.DotSettings.user | ||
/*.otf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System.Text.Json; | ||
using Il2CppSystem.IO; | ||
using Il2CppSystem.Text; | ||
|
||
namespace IMYSHook; | ||
|
||
public class IMYSConfig | ||
{ | ||
public static double Speed; | ||
public static int FPS; | ||
public static bool TranslationEnabled; | ||
|
||
public static void Read() | ||
{ | ||
if (File.Exists("./BepInEx/plugins/config.json")) | ||
{ | ||
var content = File.InternalReadAllText("./BepInEx/plugins/config.json", Encoding.UTF8); | ||
var doc = JsonDocument.Parse(content); | ||
var config = doc.RootElement; | ||
|
||
var needWrite = false; | ||
|
||
if (config.TryGetProperty("speed", out var sValue)) | ||
{ | ||
Speed = sValue.GetDouble(); | ||
} | ||
else | ||
{ | ||
Speed = 0.5; | ||
needWrite = true; | ||
} | ||
|
||
if (config.TryGetProperty("fps", out var fValue)) | ||
{ | ||
FPS = fValue.GetInt32(); | ||
} | ||
else | ||
{ | ||
FPS = 60; | ||
needWrite = true; | ||
} | ||
|
||
if (config.TryGetProperty("translation", out var tValue)) | ||
{ | ||
TranslationEnabled = tValue.GetBoolean(); | ||
} | ||
else | ||
{ | ||
TranslationEnabled = true; | ||
needWrite = true; | ||
} | ||
|
||
if (needWrite) WriteJsonFile(Speed, FPS, TranslationEnabled); | ||
|
||
Plugin.Global.Log.LogInfo("Current setting:"); | ||
Plugin.Global.Log.LogInfo("Game speed(each step): " + Speed); | ||
Plugin.Global.Log.LogInfo("FPS: " + FPS); | ||
Plugin.Global.Log.LogInfo("Translation: " + (TranslationEnabled ? "Enabled" : "Disabled")); | ||
} | ||
else | ||
{ | ||
Plugin.Global.Log.LogWarning("config.json not found!!!"); | ||
Plugin.Global.Log.LogWarning("Using default config."); | ||
Speed = 0.5; | ||
FPS = 60; | ||
TranslationEnabled = true; | ||
|
||
// Create default JSON file | ||
WriteJsonFile(0.5, 60, true); | ||
} | ||
} | ||
|
||
public static void WriteJsonFile(double speed, int fps, bool enabled) | ||
{ | ||
var config = new config | ||
{ | ||
speed = speed, | ||
fps = fps, | ||
translation = enabled | ||
}; | ||
|
||
var json = JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true }); | ||
File.WriteAllText("./BepInEx/plugins/config.json", json); | ||
} | ||
|
||
public class config | ||
{ | ||
public double speed { get; set; } | ||
public int fps { get; set; } | ||
public bool translation { get; set; } | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.7.34031.279 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IMYSHook", "IMYSHook.csproj", "{ECCA29DF-52F0-47C8-B3EF-2E9072DC696B}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{ECCA29DF-52F0-47C8-B3EF-2E9072DC696B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{ECCA29DF-52F0-47C8-B3EF-2E9072DC696B}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{ECCA29DF-52F0-47C8-B3EF-2E9072DC696B}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{ECCA29DF-52F0-47C8-B3EF-2E9072DC696B}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {FFF19899-6EE7-4266-9123-87E30E6015B7} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Diagnostics; | ||
|
||
namespace IMYSHook; | ||
|
||
public class Notification | ||
{ | ||
public static void Popup(string title, string text) | ||
{ | ||
var script = string.Format("$headlineText = '{0}';", title) + | ||
string.Format("$bodyText = '{0}';", text) + | ||
"$ToastText02 = [Windows.UI.Notifications.ToastTemplateType, Windows.UI.Notifications, ContentType = WindowsRuntime]::ToastText02;" + | ||
"$TemplateContent = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::GetTemplateContent($ToastText02);" + | ||
"$TemplateContent.SelectSingleNode('//text[@id=\"1\"]').InnerText = $headlineText;" + | ||
"$TemplateContent.SelectSingleNode('//text[@id=\"2\"]').InnerText = $bodyText;" + | ||
"$AppId = 'Iris Mysteria';" + | ||
"[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($AppId).Show($TemplateContent);"; | ||
|
||
var start = new ProcessStartInfo("powershell.exe") | ||
{ | ||
UseShellExecute = false, | ||
Arguments = script | ||
}; | ||
Process.Start(start); | ||
} | ||
|
||
public static void SsPopup(string location) | ||
{ | ||
var scriptArgs = "-F ./BepInEx/plugins/SS_Notification.ps1 " + location + ""; | ||
|
||
var start = new ProcessStartInfo("powershell.exe") | ||
{ | ||
UseShellExecute = false, | ||
Arguments = scriptArgs | ||
}; | ||
Process.Start(start); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
using System.Text.RegularExpressions; | ||
using BepInEx; | ||
using Hachiroku.Novel; | ||
using Hachiroku.Novel.UI; | ||
using HarmonyLib; | ||
using Il2CppSystem.IO; | ||
using TMPro; | ||
using UnityEngine; | ||
|
||
namespace IMYSHook; | ||
|
||
public class Patch | ||
{ | ||
private static string currentAdvId; | ||
public static string fontName = "notosanscjktc"; | ||
public static TMP_FontAsset TMPTranslateFont; | ||
|
||
public static void Initialize() | ||
{ | ||
Harmony.CreateAndPatchAll(typeof(Patch)); | ||
} | ||
|
||
[HarmonyPostfix] | ||
[HarmonyPatch(typeof(NovelRoot), "Start")] | ||
public static void NovelStart(ref NovelRoot __instance) | ||
{ | ||
if (!IMYSConfig.TranslationEnabled) return; | ||
|
||
if (TMPTranslateFont == null && File.Exists($"{Paths.PluginPath}/font/{fontName}")) | ||
{ | ||
var ab = AssetBundle.LoadFromFile($"{Paths.PluginPath}/font/{fontName}"); | ||
TMPTranslateFont = ab.LoadAsset<TMP_FontAsset>(fontName + " SDF"); | ||
ab.Unload(false); | ||
} | ||
|
||
currentAdvId = __instance.Linker.ScenarioId; | ||
|
||
if (!Translation.chapterDicts.ContainsKey(currentAdvId)) Translation.FetchChapterTranslation(currentAdvId); | ||
Plugin.Global.Log.LogInfo(currentAdvId); | ||
} | ||
|
||
// Message | ||
[HarmonyPrefix] | ||
[HarmonyPatch(typeof(BurikoParseScript), "_SetMssageCommand")] | ||
public static void Novel_SetMssageCommand(ref int lineNum, ref string line, ref bool isSelectedCaseArea, | ||
ref int caseCount) | ||
{ | ||
if (!IMYSConfig.TranslationEnabled) return; | ||
|
||
if (Translation.chapterDicts.ContainsKey(currentAdvId) && line.Contains("「")) | ||
{ | ||
var idx = line.IndexOf('「'); | ||
var name = line.Substring(0, idx); | ||
var text = line.Substring(idx); | ||
|
||
var full = ""; | ||
|
||
string name_replace; | ||
if (Translation.nameDicts.TryGetValue(name, out name_replace)) | ||
full = name_replace.IsNullOrWhiteSpace() ? text : name_replace; | ||
|
||
string text_replace; | ||
if (Translation.chapterDicts[currentAdvId].TryGetValue(text, out text_replace)) | ||
full += text_replace.IsNullOrWhiteSpace() ? text : text_replace; | ||
|
||
line = full; | ||
} | ||
else | ||
{ | ||
string text_replace; | ||
if (Translation.chapterDicts.ContainsKey(currentAdvId) && | ||
Translation.chapterDicts[currentAdvId].TryGetValue(line, out text_replace)) | ||
line = text_replace.IsNullOrWhiteSpace() ? line : text_replace; | ||
} | ||
} | ||
|
||
// Option | ||
[HarmonyPrefix] | ||
[HarmonyPatch(typeof(BurikoParseScript), "_ToParamList")] | ||
public static void Novel_ToParamList(ref string param) | ||
{ | ||
if (!IMYSConfig.TranslationEnabled) return; | ||
|
||
var re = new Regex(@"{(.*)}"); | ||
var match = re.Match(param); | ||
if (match.Success) | ||
for (var i = 0; i < match.Groups.Count; i++) | ||
{ | ||
var options = match.Groups[i].Value.Split(","); | ||
|
||
for (var i2 = 0; i2 < options.Length; i2++) | ||
{ | ||
string text_replace; | ||
if (Translation.chapterDicts.ContainsKey(currentAdvId) && Translation.chapterDicts[currentAdvId] | ||
.TryGetValue(options[i2], out text_replace)) | ||
{ | ||
var option_tr = text_replace.IsNullOrWhiteSpace() ? options[i2] : text_replace; | ||
param = param.Replace(options[i2], option_tr); | ||
} | ||
} | ||
} | ||
} | ||
|
||
[HarmonyPrefix] | ||
[HarmonyPatch(typeof(MessageScrollView), "CreateItem")] | ||
public static void CreateItem(ref MessageScrollViewItem item) | ||
{ | ||
if (!IMYSConfig.TranslationEnabled) return; | ||
|
||
if (TMPTranslateFont != null) | ||
{ | ||
item._name.font = TMPTranslateFont; | ||
item._message.font = TMPTranslateFont; | ||
} | ||
} | ||
|
||
[HarmonyPostfix] | ||
[HarmonyPatch(typeof(ChoicesContent), "SetChoiceButtonText")] | ||
public static void SetChoiceButtonText(ref ChoicesContent __instance) | ||
{ | ||
if (!IMYSConfig.TranslationEnabled) return; | ||
|
||
if (TMPTranslateFont != null) | ||
for (var i = 0; i < __instance.choiceTextList.Length; i++) | ||
__instance.choiceTextList[i].font = TMPTranslateFont; | ||
} | ||
|
||
[HarmonyPostfix] | ||
[HarmonyPatch(typeof(TextRoot), "DeleteRuby")] | ||
public static void DeleteRuby(ref TextRoot __instance) | ||
{ | ||
if (!IMYSConfig.TranslationEnabled) return; | ||
|
||
if (TMPTranslateFont != null) | ||
{ | ||
if (__instance.CharaName) __instance.CharaName.font = TMPTranslateFont; | ||
if (__instance.Message) __instance.Message.font = TMPTranslateFont; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Text; | ||
using BepInEx; | ||
using BepInEx.Logging; | ||
using BepInEx.Unity.IL2CPP; | ||
using Il2CppSystem.IO; | ||
|
||
namespace IMYSHook; | ||
|
||
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)] | ||
public class Plugin : BasePlugin | ||
{ | ||
public override void Load() | ||
{ | ||
Console.OutputEncoding = Encoding.UTF8; | ||
|
||
if (File.Exists("IMYSProxy.exe")) | ||
{ | ||
if (Process.GetProcessesByName("IMYSProxy").Length == 0) | ||
{ | ||
var start = new ProcessStartInfo("IMYSProxy.exe") | ||
{ | ||
UseShellExecute = true, | ||
CreateNoWindow = false, | ||
WindowStyle = ProcessWindowStyle.Normal | ||
}; | ||
Process.Start(start); | ||
} | ||
|
||
Environment.SetEnvironmentVariable("http_proxy", "http://127.0.0.1:8765", | ||
EnvironmentVariableTarget.Process); | ||
Environment.SetEnvironmentVariable("https_proxy", "http://127.0.0.1:8765", | ||
EnvironmentVariableTarget.Process); | ||
} | ||
else | ||
{ | ||
Environment.SetEnvironmentVariable("http_proxy", "http://127.0.0.1:5678", | ||
EnvironmentVariableTarget.Process); | ||
Environment.SetEnvironmentVariable("https_proxy", "http://127.0.0.1:5678", | ||
EnvironmentVariableTarget.Process); | ||
} | ||
|
||
|
||
var log = Log; | ||
Global.Log = log; | ||
Log.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} is loaded!"); | ||
|
||
IMYSConfig.Read(); | ||
Translation.Init(); | ||
Patch.Initialize(); | ||
|
||
AddComponent<PluginBehavior>(); | ||
} | ||
|
||
public class Global | ||
{ | ||
public static ManualLogSource Log { get; set; } | ||
} | ||
} |
Oops, something went wrong.