添加自动切换游戏路径和强制刷新过滤的功能

This commit is contained in:
Taskeren 2024-04-19 17:09:34 +08:00
parent 0a0061ca8c
commit 4ffaed2825
No known key found for this signature in database
GPG Key ID: BC3749B9DFBE1F00
10 changed files with 127 additions and 19 deletions

View File

@ -16,6 +16,12 @@
<setting name="AllocConsole" serializeAs="String">
<value>False</value>
</setting>
<setting name="ForceCreateNewFilter" serializeAs="String">
<value>True</value>
</setting>
<setting name="AutoUpdateGamePath" serializeAs="String">
<value>True</value>
</setting>
</FinalSolution.Properties.Settings>
</userSettings>
</configuration>

View File

@ -18,7 +18,14 @@ namespace FinalSolution
{
if (File.Exists(path))
{
return _instance = JsonConvert.DeserializeObject<ConfigData>(File.ReadAllText(path));
var data = JsonConvert.DeserializeObject<ConfigData>(File.ReadAllText(path));
// check if the currently running game path is equal to the config-ed one.
// need manually enable in the FinalSolution.exe.config!
// require ForceCreateNewFilter to work as intended!!
VerifyGamePath(data);
return _instance = data;
}
MessageBox.Show(Resources.Config_ReadConfig_Awareness, Resources.Config_ReadConfig_Awareness_Title);
@ -81,12 +88,25 @@ namespace FinalSolution
Console.WriteLine(dialog.FileName);
appPath = dialog.FileName;
}
private static void VerifyGamePath(ConfigData data)
{
if (!Settings.Default.AutoUpdateGamePath) return;
// if the game path is not set; this must be something wrong!
if (data.Destiny2Path == null) return;
var curr = FindGameRunning();
if (curr == null || curr == data.Destiny2Path) return;
Console.WriteLine(Resources.Config_VerifyGamePath, data.Destiny2Path, curr);
data.Destiny2Path = curr;
}
}
public class ConfigData
{
public string Destiny2Path;
public Dictionary<string, string> Hotkeys;
public bool ShouldAllocConsole = false;
}
}

View File

@ -186,10 +186,12 @@ namespace FinalSolution
//
// positionWorker
//
this.positionWorker.WorkerSupportsCancellation = true;
this.positionWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(this.positionWorker_DoWork);
//
// timerWorker
//
this.timerWorker.WorkerSupportsCancellation = true;
this.timerWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(this.timerWorker_DoWork);
//
// MainForm

View File

@ -1,5 +1,7 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using FinalSolution.Properties;
using NetLimiter.Service;
namespace FinalSolution
@ -27,15 +29,7 @@ namespace FinalSolution
{
var cli = GetClient();
var name = GetFilterNameFor(portName, upload);
var filter = cli.Filters.FirstOrDefault(f => f.Name == name) ??
cli.AddFilter(new Filter(name)
{
Functions =
{
new FFPathEqual(Config.Instance.Destiny2Path),
new FFRemotePortInRange(new PortRangeFilterValue(portStart, portEnd))
}
});
var filter = GetOrCreateFilter(name, new PortRangeFilterValue(portStart, portEnd));
var hotkey = Config.Instance.Hotkeys[name];
return new FilterHandle(name, filter, cli, upload, 1, hotkey);
@ -45,18 +39,39 @@ namespace FinalSolution
{
var cli = GetClient();
var name = GetFilterNameFor("fg");
var filter = cli.Filters.FirstOrDefault(f => f.Name == name)
??
cli.AddFilter(new Filter(name)
{
Functions = { new FFPathEqual(Config.Instance.Destiny2Path) }
});
var filter = GetOrCreateFilter(name, null);
var hotkey = Config.Instance.Hotkeys[name];
return new FilterHandle(name, filter, cli, false, 811, hotkey);
}
private static Filter GetOrCreateFilter(string name, PortRangeFilterValue port)
{
var existing = GetClient().Filters.FirstOrDefault(f => f.Name == name);
// remove existing filter if required, or return
if (existing != null && Settings.Default.ForceCreateNewFilter) GetClient().RemoveFilter(existing);
else return existing;
if (port == null) // if port is null, create a full game filter
{
return GetClient().AddFilter(new Filter(name)
{
Functions = { new FFPathContains(Config.Instance.Destiny2Path) }
});
}
return GetClient().AddFilter(new Filter(name)
{
Functions =
{
new FFPathContains(Config.Instance.Destiny2Path),
new FFRemotePortInRange(port)
}
});
}
public static readonly FilterHandle F3074;
public static readonly FilterHandle F3074Ul;
public static readonly FilterHandle F7500;
@ -66,6 +81,11 @@ namespace FinalSolution
static NetLimiterBridge()
{
if (Settings.Default.ForceCreateNewFilter)
{
Console.WriteLine(Resources.NetLimiterBridge_NetLimiterBridge_ForceNewFilter);
}
F3074 = CreateFilter("3074", 3074, 3074);
F3074Ul = CreateFilter("3074", 3074, 3074, true);
F7500 = CreateFilter("7500", 7500, 7509);

View File

@ -16,7 +16,7 @@ namespace FinalSolution
[STAThread]
static void Main()
{
if (Config.Instance.ShouldAllocConsole || Settings.Default.AllocConsole) // should open a console box
if (Settings.Default.AllocConsole) // should open a console box
{
NativeUtils.AllocConsole();
Console.WriteLine(@"Hello from the Children of Planet Earth!");

View File

@ -112,6 +112,24 @@ namespace FinalSolution.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Updated Game Path from {0} to {1}.
/// </summary>
internal static string Config_VerifyGamePath {
get {
return ResourceManager.GetString("Config_VerifyGamePath", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Forcedly Create New Filters.
/// </summary>
internal static string NetLimiterBridge_NetLimiterBridge_ForceNewFilter {
get {
return ResourceManager.GetString("NetLimiterBridge_NetLimiterBridge_ForceNewFilter", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Unexpected error occurred while you using Final Solution! A debug information is generated to {0}.
/// </summary>

View File

@ -140,4 +140,10 @@ Finally, Final Solution is closed-sourced but free-to-use. If you bought it from
<data name="Program_Main_Crash_Dialog" xml:space="preserve">
<value>Unexpected error occurred while you using Final Solution! A debug information is generated to {0}</value>
</data>
<data name="NetLimiterBridge_NetLimiterBridge_ForceNewFilter" xml:space="preserve">
<value>Forcedly Create New Filters</value>
</data>
<data name="Config_VerifyGamePath" xml:space="preserve">
<value>Updated Game Path from {0} to {1}</value>
</data>
</root>

View File

@ -37,4 +37,10 @@
<data name="Program_Main_Crash_Dialog" xml:space="preserve">
<value>执行最终解决方案时发生了未知错误,崩溃信息存储在{0}。</value>
</data>
<data name="NetLimiterBridge_NetLimiterBridge_ForceNewFilter" xml:space="preserve">
<value>强制创建新过滤规则</value>
</data>
<data name="Config_VerifyGamePath" xml:space="preserve">
<value>更新了游戏路劲,旧路径 {0},新路径 {1}</value>
</data>
</root>

View File

@ -33,5 +33,29 @@ namespace FinalSolution.Properties {
this["AllocConsole"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("True")]
public bool ForceCreateNewFilter {
get {
return ((bool)(this["ForceCreateNewFilter"]));
}
set {
this["ForceCreateNewFilter"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("True")]
public bool AutoUpdateGamePath {
get {
return ((bool)(this["AutoUpdateGamePath"]));
}
set {
this["AutoUpdateGamePath"] = value;
}
}
}
}

View File

@ -7,6 +7,12 @@
<Setting Name="AllocConsole" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="ForceCreateNewFilter" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="AutoUpdateGamePath" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>