Skip to content

Commit 7ec97bf

Browse files
committed
implement special return buffer
1 parent 7f45f7d commit 7ec97bf

18 files changed

Lines changed: 22 additions & 11 deletions

BepInEx.Core/Bootstrap/BaseChainloader.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,11 @@ private static bool IsAssemblySafe(string assemblyPath)
486486
return false;
487487
}
488488

489-
if (module.Attributes.Has(ModuleAttributes.ILOnly) == false)
489+
// TODO: better unsafe blocking
490+
/*if (!module.Attributes.Has(ModuleAttributes.ILOnly))
490491
{
491492
return false;
492-
}
493+
}*/
493494

494495
if (!method.HasBody) continue;
495496

Runtimes/Unity/BepInEx.Unity.IL2CPP/BepInEx.Unity.IL2CPP.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
<ItemGroup>
1818
<PackageReference Include="Disarm" Version="2022.1.0-master.99" />
1919
<PackageReference Include="HarmonyX" Version="2.16.0" />
20-
<PackageReference Include="Il2CppInterop.Generator" Version="1.5.2-data-hook" />
21-
<PackageReference Include="Il2CppInterop.HarmonySupport" Version="1.5.2-data-hook" />
20+
<PackageReference Include="Il2CppInterop.Generator" Version="1.5.2-ci.star.5" />
21+
<PackageReference Include="Il2CppInterop.HarmonySupport" Version="1.5.2-ci.star.5" />
2222
<PackageReference Include="Il2CppInterop.ReferenceLibs" Version="1.0.0" IncludeAssets="compile" PrivateAssets="all"/>
23-
<PackageReference Include="Il2CppInterop.Runtime" Version="1.5.2-data-hook" />
23+
<PackageReference Include="Il2CppInterop.Runtime" Version="1.5.2-ci.star.5" />
2424
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" IncludeAssets="compile" PrivateAssets="all"/>
2525
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" IncludeAssets="compile" PrivateAssets="all"/>
2626
<PackageReference Include="MonoMod.Core" Version="1.3.4-star" />

Runtimes/Unity/BepInEx.Unity.IL2CPP/Hook/NativeDetour.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ public unsafe class NativeDetour : IDetour
99
public IntPtr Target { get; }
1010
public IntPtr Detour { get; }
1111
public bool UnityFunction { get; }
12+
public bool SpecialReturnBuffer { get; }
1213
public IntPtr OriginalTrampoline { get; private set; }
1314

1415
public NativeDetour(IntPtr target, Delegate detour)
15-
: this(target, detour, false)
16+
: this(target, detour, false, false)
1617
{
1718
}
1819

19-
public NativeDetour(IntPtr target, Delegate detour, bool unityFunction)
20+
public NativeDetour(IntPtr target, Delegate detour, bool unityFunction, bool specialReturnBuffer)
2021
{
2122
Target = target;
2223
Detour = Marshal.GetFunctionPointerForDelegate(detour);
2324
UnityFunction = unityFunction;
25+
SpecialReturnBuffer = specialReturnBuffer;
2426
Apply();
2527
}
2628

@@ -30,7 +32,7 @@ public void Apply()
3032
{
3133
return;
3234
}
33-
OriginalTrampoline = StarlightInterop.hook(Target, Detour, UnityFunction);
35+
OriginalTrampoline = StarlightInterop.hook(Target, Detour, UnityFunction, SpecialReturnBuffer);
3436
}
3537

3638
public void Dispose()

Runtimes/Unity/BepInEx.Unity.IL2CPP/Hook/NativeDetourProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ namespace BepInEx.Unity.IL2CPP.Hook;
55

66
public class NativeDetourProvider : IDetourProvider
77
{
8-
public IDetour Create<TDelegate>(IntPtr original, TDelegate target, bool unityFunction) where TDelegate : Delegate
8+
public IDetour Create<TDelegate>(IntPtr original, TDelegate target, bool unityFunction, bool specialReturnBuffer) where TDelegate : Delegate
99
{
10-
var detour = new NativeDetour(original, target, unityFunction);
10+
var detour = new NativeDetour(original, target, unityFunction, specialReturnBuffer);
1111
return new CacheDetourWrapper(detour, target);
1212
}
1313
}

Runtimes/Unity/BepInEx.Unity.IL2CPP/IL2CPPChainloader.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using BepInEx.Unity.IL2CPP.Hook;
1212
using BepInEx.Unity.IL2CPP.Logging;
1313
using BepInEx.Unity.IL2CPP.Utils;
14+
using Il2CppInterop.HarmonySupport;
1415
using Il2CppInterop.Runtime.InteropTypes;
1516
using Logger = BepInEx.Logging.Logger;
1617

@@ -76,6 +77,8 @@ public override void Execute()
7677
{
7778
try
7879
{
80+
BridgeInterop.Initialize();
81+
StarlightInterop.init_bridge_helper(BridgeInterop.LibraryPath);
7982
StarlightInterop.set_loading(true);
8083

8184
var paths = new Dictionary<string, bool>

Runtimes/Unity/BepInEx.Unity.IL2CPP/StarlightInterop.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ internal static partial class StarlightInterop
1313
public static unsafe partial void write_log([MarshalAs(UnmanagedType.LPStr)] string message);
1414

1515
[LibraryImport(LIBRARY_NAME)]
16-
public static unsafe partial IntPtr hook(IntPtr target, IntPtr detour, [MarshalAs(UnmanagedType.I1)] bool unityFunction);
16+
public static unsafe partial void init_bridge_helper([MarshalAs(UnmanagedType.LPStr)] string bridgeLibPath);
17+
18+
[LibraryImport(LIBRARY_NAME)]
19+
public static unsafe partial IntPtr hook(IntPtr target, IntPtr detour,
20+
[MarshalAs(UnmanagedType.I1)] bool unityFunction,
21+
[MarshalAs(UnmanagedType.I1)] bool specialReturnBuffer);
1722

1823
[LibraryImport(LIBRARY_NAME)]
1924
public static unsafe partial void unhook(IntPtr target);
26 MB
Binary file not shown.
40.8 KB
Binary file not shown.
-40.8 KB
Binary file not shown.
271 KB
Binary file not shown.

0 commit comments

Comments
 (0)