Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FFXIV Chinese version (6.5) support #76

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions FetchDependencies/FetchDependencies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ namespace FetchDependencies;

public class FetchDependencies
{
private const string VersionUrlGlobal = "https://www.iinact.com/updater/version";
private const string VersionUrlChinese = "https://cninact.diemoe.net/CN解析/版本.txt";
private const string PluginUrlGlobal = "https://www.iinact.com/updater/download";
private const string PluginUrlChinese = "https://cninact.diemoe.net/CN解析/FFXIV_ACT_Plugin.dll";

private Version PluginVersion { get; }
private string DependenciesDir { get; }
private bool IsChinese { get; }
private HttpClient HttpClient { get; }

public FetchDependencies(Version version, string assemblyDir, HttpClient httpClient)
public FetchDependencies(Version version, string assemblyDir, bool isChinese, HttpClient httpClient)
{
PluginVersion = version;
DependenciesDir = assemblyDir;
IsChinese = isChinese;
HttpClient = httpClient;
}

Expand All @@ -23,22 +30,25 @@ public void GetFfxivPlugin()
if (!NeedsUpdate(pluginPath))
return;

if (!File.Exists(pluginZipPath))
DownloadPlugin(pluginZipPath);

try
{
ZipFile.ExtractToDirectory(pluginZipPath, DependenciesDir, true);
}
catch (InvalidDataException)
if (IsChinese)
DownloadFile(PluginUrlChinese, pluginPath);
else
{
if (!File.Exists(pluginZipPath))
DownloadFile(PluginUrlGlobal, pluginZipPath);
try
{
ZipFile.ExtractToDirectory(pluginZipPath, DependenciesDir, true);
}
catch (InvalidDataException)
{
File.Delete(pluginZipPath);
DownloadFile(PluginUrlGlobal, pluginZipPath);
ZipFile.ExtractToDirectory(pluginZipPath, DependenciesDir, true);
}
File.Delete(pluginZipPath);
DownloadPlugin(pluginZipPath);
ZipFile.ExtractToDirectory(pluginZipPath, DependenciesDir, true);
}

File.Delete(pluginZipPath);

var patcher = new Patcher(PluginVersion, DependenciesDir);
patcher.MainPlugin();
patcher.LogFilePlugin();
Expand All @@ -57,7 +67,7 @@ private bool NeedsUpdate(string dllPath)

using var cancelAfterDelay = new CancellationTokenSource(TimeSpan.FromSeconds(3));
var remoteVersionString = HttpClient
.GetStringAsync("https://www.iinact.com/updater/version",
.GetStringAsync(IsChinese ? VersionUrlChinese : VersionUrlGlobal,
cancelAfterDelay.Token).Result;
var remoteVersion = new Version(remoteVersionString);
return remoteVersion > plugin.Version;
Expand All @@ -68,11 +78,11 @@ private bool NeedsUpdate(string dllPath)
}
}

private void DownloadPlugin(string path)
private void DownloadFile(string url, string path)
{
using var cancelAfterDelay = new CancellationTokenSource(TimeSpan.FromSeconds(30));
using var downloadStream = HttpClient
.GetStreamAsync("https://www.iinact.com/updater/download",
.GetStreamAsync(url,
cancelAfterDelay.Token).Result;
using var zipFileStream = new FileStream(path, FileMode.Create);
downloadStream.CopyTo(zipFileStream);
Expand Down
8 changes: 6 additions & 2 deletions IINACT/FfxivActPluginWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ public unsafe FfxivActPluginWrapper(

ffxivActPlugin = new FFXIV_ACT_Plugin.FFXIV_ACT_Plugin();
ffxivActPlugin.ConfigureIOC();
OpcodeManager.Instance.SetRegion(GameRegion.Global);
if (dalamudClientLanguage.ToString() == "ChineseSimplified") {
OpcodeManager.Instance.SetRegion(GameRegion.Chinese);
} else {
OpcodeManager.Instance.SetRegion(GameRegion.Global);
}

iocContainer = ffxivActPlugin._iocContainer;
iocContainer.Resolve<ResourceManager>().LoadResources();
Expand Down Expand Up @@ -143,7 +147,7 @@ public unsafe FfxivActPluginWrapper(
Dalamud.ClientLanguage.English => Language.English,
Dalamud.ClientLanguage.German => Language.German,
Dalamud.ClientLanguage.French => Language.French,
_ => Language.English
_ => dalamudClientLanguage.ToString() == "ChineseSimplified" ? Language.Chinese : Language.English
};

public void Dispose()
Expand Down
2 changes: 1 addition & 1 deletion IINACT/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public Plugin([RequiredVersion("1.0")] DalamudPluginInterface pluginInterface,

var fetchDeps =
new FetchDependencies.FetchDependencies(Version, PluginInterface.AssemblyLocation.Directory!.FullName,
HttpClient);
DataManager.Language.ToString() == "ChineseSimplified", HttpClient);

fetchDeps.GetFfxivPlugin();

Expand Down
2 changes: 1 addition & 1 deletion machina
Loading