From a976b70528c9ad00cf58793b0c1946f1f2072e07 Mon Sep 17 00:00:00 2001
From: automatic9045 <67314487+automatic9045@users.noreply.github.com>
Date: Fri, 3 Jan 2025 19:05:43 +0900
Subject: [PATCH] =?UTF-8?q?feat:=20AtsEx.Caller=E3=81=8C=E8=AA=AD=E3=81=BF?=
=?UTF-8?q?=E8=BE=BC=E3=81=BE=E3=82=8C=E3=81=9F=E3=81=A8=E3=81=8D=E3=82=82?=
=?UTF-8?q?=E3=83=AC=E3=82=AC=E3=82=B7=E3=83=BC=E3=83=A2=E3=83=BC=E3=83=89?=
=?UTF-8?q?=E3=81=B8=E7=A7=BB=E8=A1=8C=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?=
=?UTF-8?q?=E3=81=AB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.github/workflows/build.yml | 1 +
BveEx.Launcher/BveEx.Launcher.csproj | 1 +
BveEx.Launcher/OldLauncherLoader.cs | 37 ++++++++++++++++++++++++++++
BveEx.Launcher/VersionSelector.cs | 6 +++++
BveEx/BveEx.csproj | 4 +++
BveEx/Main/BveEx.cs | 9 +++++++
6 files changed, 58 insertions(+)
create mode 100644 BveEx.Launcher/OldLauncherLoader.cs
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 2eaf0bc8..9df9626f 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -78,6 +78,7 @@ jobs:
run: |
mkdir Target\LocalReferences\Legacy
copy Legacy\AtsEx\bin\Release\AtsEx.dll Target\LocalReferences\Legacy\
+ copy Legacy\AtsEx.Launcher\bin\Release\AtsEx.Launcher.dll Target\LocalReferences\Legacy\
msbuild Target\BveEx.sln /p:Configuration=Release /p:DebugSymbols=false /p:DebugType=none
- name: Package
run: |
diff --git a/BveEx.Launcher/BveEx.Launcher.csproj b/BveEx.Launcher/BveEx.Launcher.csproj
index a9b96cc2..68f36ebc 100644
--- a/BveEx.Launcher/BveEx.Launcher.csproj
+++ b/BveEx.Launcher/BveEx.Launcher.csproj
@@ -74,6 +74,7 @@
+
diff --git a/BveEx.Launcher/OldLauncherLoader.cs b/BveEx.Launcher/OldLauncherLoader.cs
new file mode 100644
index 00000000..02ac72a1
--- /dev/null
+++ b/BveEx.Launcher/OldLauncherLoader.cs
@@ -0,0 +1,37 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BveEx.Launcher
+{
+ internal class OldLauncherLoader : IDisposable
+ {
+ private static readonly string FileName = "AtsEx.Launcher";
+ private readonly string OldLauncherPath;
+
+ public OldLauncherLoader()
+ {
+ string launcherPath = Assembly.GetExecutingAssembly().Location;
+ OldLauncherPath = Path.Combine(Path.GetDirectoryName(launcherPath), FileName + ".dll");
+
+ AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve;
+ }
+
+ public void Dispose()
+ {
+ AppDomain.CurrentDomain.AssemblyResolve -= OnAssemblyResolve;
+ }
+
+ private Assembly OnAssemblyResolve(object sender, ResolveEventArgs e)
+ {
+ AssemblyName assemblyName = new AssemblyName(e.Name);
+ if (assemblyName.Name != FileName) return null;
+ Assembly assembly = Assembly.LoadFrom(OldLauncherPath);
+ return assembly;
+ }
+ }
+}
diff --git a/BveEx.Launcher/VersionSelector.cs b/BveEx.Launcher/VersionSelector.cs
index 60fc3949..71edd664 100644
--- a/BveEx.Launcher/VersionSelector.cs
+++ b/BveEx.Launcher/VersionSelector.cs
@@ -34,9 +34,12 @@ static VersionSelector()
LegacyFilePath = Path.Combine(RootDirectory, ".LEGACY");
}
+
private readonly Process SplashProcess;
private readonly SplashFormInfo SplashForm;
+ private readonly OldLauncherLoader OldLauncherLoader;
+
public ICoreHost CoreHost { get; }
public VersionSelector(Assembly callerAssembly)
@@ -57,6 +60,8 @@ public VersionSelector(Assembly callerAssembly)
SplashProcess.Refresh();
}
+ OldLauncherLoader = new OldLauncherLoader();
+
SplashForm = (SplashFormInfo)Activator.GetObject(typeof(SplashFormInfo), $"ipc://{channelGuid}/{nameof(SplashFormInfo)}");
SplashForm.ProgressText = $"{productName} を探しています...";
@@ -157,6 +162,7 @@ public void Dispose()
}
catch { }
+ OldLauncherLoader.Dispose();
CoreHost.Dispose();
}
}
diff --git a/BveEx/BveEx.csproj b/BveEx/BveEx.csproj
index 27bc7470..e2347f9b 100644
--- a/BveEx/BveEx.csproj
+++ b/BveEx/BveEx.csproj
@@ -39,6 +39,10 @@
..\packages\Lib.Harmony.2.2.2\lib\net48\0Harmony.dll
+
+ ..\LocalReferences\Legacy\AtsEx.Launcher.dll
+ False
+
..\packages\Irony.1.1.0\lib\net40\Irony.dll
False
diff --git a/BveEx/Main/BveEx.cs b/BveEx/Main/BveEx.cs
index 784b4e15..84d364ce 100644
--- a/BveEx/Main/BveEx.cs
+++ b/BveEx/Main/BveEx.cs
@@ -65,6 +65,7 @@ static BveEx()
public BveEx(BveTypeSet bveTypes)
{
BveHacker = new BveHacker(bveTypes);
+ BveHacker.ScenarioCreated += OnScenarioCreated;
AppDomain.CurrentDomain.FirstChanceException += OnFirstChanceException;
ClassMemberSet mainFormMembers = bveTypes.GetClassInfoOf();
@@ -83,6 +84,14 @@ public BveEx(BveTypeSet bveTypes)
VersionFormProvider = CreateVersionFormProvider(Extensions);
}
+ private void OnScenarioCreated(ScenarioCreatedEventArgs e)
+ {
+ if (!(AtsEx.Launcher.CoreHost.VehicleConfigPath is null) || !(AtsEx.Launcher.CoreHost.VehicleConfigPath is null))
+ {
+ throw new LaunchModeException();
+ }
+ }
+
private VersionFormProvider CreateVersionFormProvider(IEnumerable extensions)
=> new VersionFormProvider(BveHacker.MainFormSource, extensions, Extensions.GetExtension());