-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Merge targets * Merge branch 'v1-dev' into fork/Menci/merge-targets * [O] Move Shim to AquaMai.Helpers
- Loading branch information
Showing
4 changed files
with
94 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using System.Reflection; | ||
using HarmonyLib; | ||
using MAI2.Util; | ||
using Manager; | ||
using Net.Packet; | ||
using Net.Packet.Mai2; | ||
|
||
namespace AquaMai.Helpers; | ||
|
||
public static class Shim | ||
{ | ||
public delegate string GetAccessTokenMethod(int index); | ||
public static readonly GetAccessTokenMethod GetAccessToken = new Func<GetAccessTokenMethod>(() => { | ||
var tOperationManager = Traverse.Create(Singleton<OperationManager>.Instance); | ||
var tGetAccessToken = tOperationManager.Method("GetAccessToken", [typeof(int)]); | ||
if (!tGetAccessToken.MethodExists()) | ||
{ | ||
return (index) => throw new MissingMethodException("No matching OperationManager.GetAccessToken() method found"); | ||
} | ||
return (index) => tGetAccessToken.GetValue<string>(index); | ||
})(); | ||
|
||
public delegate PacketUploadUserPlaylog PacketUploadUserPlaylogCreator(int index, UserData src, int trackNo, Action<int> onDone, Action<PacketStatus> onError = null); | ||
public static readonly PacketUploadUserPlaylogCreator CreatePacketUploadUserPlaylog = new Func<PacketUploadUserPlaylogCreator>(() => { | ||
var type = typeof(PacketUploadUserPlaylog); | ||
if (type.GetConstructor([typeof(int), typeof(UserData), typeof(int), typeof(Action<int>), typeof(Action<PacketStatus>)]) is ConstructorInfo ctor1) { | ||
return (index, src, trackNo, onDone, onError) => { | ||
var args = new object[] {index, src, trackNo, "", onDone, onError}; | ||
return (PacketUploadUserPlaylog)ctor1.Invoke(args); | ||
}; | ||
} | ||
else if (type.GetConstructor([typeof(int), typeof(UserData), typeof(int), typeof(string), typeof(Action<int>), typeof(Action<PacketStatus>)]) is ConstructorInfo ctor2) { | ||
return (index, src, trackNo, onDone, onError) => { | ||
var accessToken = GetAccessToken(index); | ||
var args = new object[] {index, src, trackNo, accessToken, onDone, onError}; | ||
return (PacketUploadUserPlaylog)ctor2.Invoke(args); | ||
}; | ||
} | ||
else | ||
{ | ||
throw new MissingMethodException("No matching PacketUploadUserPlaylog constructor found"); | ||
} | ||
})(); | ||
|
||
public delegate PacketUpsertUserAll PacketUpsertUserAllCreator(int index, UserData src, Action<int> onDone, Action<PacketStatus> onError = null); | ||
public static readonly PacketUpsertUserAllCreator CreatePacketUpsertUserAll = new Func<PacketUpsertUserAllCreator>(() => { | ||
var type = typeof(PacketUpsertUserAll); | ||
if (type.GetConstructor([typeof(int), typeof(UserData), typeof(Action<int>), typeof(Action<PacketStatus>)]) is ConstructorInfo ctor1) { | ||
return (index, src, onDone, onError) => { | ||
var args = new object[] {index, src, "", onDone, onError}; | ||
return (PacketUpsertUserAll)ctor1.Invoke(args); | ||
}; | ||
} | ||
else if (type.GetConstructor([typeof(int), typeof(UserData), typeof(string), typeof(Action<int>), typeof(Action<PacketStatus>)]) is ConstructorInfo ctor2) { | ||
return (index, src, onDone, onError) => { | ||
var accessToken = GetAccessToken(index); | ||
var args = new object[] {index, src, accessToken, onDone, onError}; | ||
return (PacketUpsertUserAll)ctor2.Invoke(args); | ||
}; | ||
} | ||
else | ||
{ | ||
throw new MissingMethodException("No matching PacketUpsertUserAll constructor found"); | ||
} | ||
})(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters