Skip to content

Commit

Permalink
feat: AtsEx.Callerが読み込まれたときもレガシーモードへ移行するように
Browse files Browse the repository at this point in the history
  • Loading branch information
automatic9045 committed Jan 3, 2025
1 parent b5702fa commit a976b70
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
1 change: 1 addition & 0 deletions BveEx.Launcher/BveEx.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<Compile Include="InputEventArgs.cs" />
<Compile Include="LauncherVersionChecker.cs" />
<Compile Include="LegacyCoreHost.cs" />
<Compile Include="OldLauncherLoader.cs" />
<Compile Include="Resources.cs" />
<Compile Include="VersionSelector.cs" />
<Compile Include="Hosting\TargetBveFinder.cs" />
Expand Down
37 changes: 37 additions & 0 deletions BveEx.Launcher/OldLauncherLoader.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
6 changes: 6 additions & 0 deletions BveEx.Launcher/VersionSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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} を探しています...";

Expand Down Expand Up @@ -157,6 +162,7 @@ public void Dispose()
}
catch { }

OldLauncherLoader.Dispose();
CoreHost.Dispose();
}
}
Expand Down
4 changes: 4 additions & 0 deletions BveEx/BveEx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
<Reference Include="0Harmony, Version=2.2.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Lib.Harmony.2.2.2\lib\net48\0Harmony.dll</HintPath>
</Reference>
<Reference Include="AtsEx.Launcher">
<HintPath>..\LocalReferences\Legacy\AtsEx.Launcher.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Irony, Version=1.1.0.0, Culture=neutral, PublicKeyToken=ca48ace7223ead47, processorArchitecture=MSIL">
<HintPath>..\packages\Irony.1.1.0\lib\net40\Irony.dll</HintPath>
<Private>False</Private>
Expand Down
9 changes: 9 additions & 0 deletions BveEx/Main/BveEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MainForm>();
Expand All @@ -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<PluginBase> extensions)
=> new VersionFormProvider(BveHacker.MainFormSource, extensions, Extensions.GetExtension<IContextMenuHacker>());

Expand Down

0 comments on commit a976b70

Please sign in to comment.