mirror of
https://github.com/yuzu-emu/discord-rpc
synced 2024-11-26 10:17:48 +00:00
Unity il2cpp support (#249)
* Initial il2cpp support attempts * Fix crashes * Different variable name * Fix indenting * Change back unneeded stuff - callbackCalls didnt seem to do anything
This commit is contained in:
parent
2fec0b6dec
commit
e6390c8c41
2 changed files with 27 additions and 29 deletions
|
@ -14,7 +14,6 @@ public class DiscordController : MonoBehaviour
|
||||||
public DiscordRpc.RichPresence presence = new DiscordRpc.RichPresence();
|
public DiscordRpc.RichPresence presence = new DiscordRpc.RichPresence();
|
||||||
public string applicationId;
|
public string applicationId;
|
||||||
public string optionalSteamId;
|
public string optionalSteamId;
|
||||||
public int callbackCalls;
|
|
||||||
public int clickCounter;
|
public int clickCounter;
|
||||||
public DiscordRpc.DiscordUser joinRequest;
|
public DiscordRpc.DiscordUser joinRequest;
|
||||||
public UnityEngine.Events.UnityEvent onConnect;
|
public UnityEngine.Events.UnityEvent onConnect;
|
||||||
|
@ -52,41 +51,35 @@ public class DiscordController : MonoBehaviour
|
||||||
|
|
||||||
public void ReadyCallback(ref DiscordRpc.DiscordUser connectedUser)
|
public void ReadyCallback(ref DiscordRpc.DiscordUser connectedUser)
|
||||||
{
|
{
|
||||||
++callbackCalls;
|
|
||||||
Debug.Log(string.Format("Discord: connected to {0}#{1}: {2}", connectedUser.username, connectedUser.discriminator, connectedUser.userId));
|
Debug.Log(string.Format("Discord: connected to {0}#{1}: {2}", connectedUser.username, connectedUser.discriminator, connectedUser.userId));
|
||||||
onConnect.Invoke();
|
onConnect.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DisconnectedCallback(int errorCode, string message)
|
public void DisconnectedCallback(int errorCode, string message)
|
||||||
{
|
{
|
||||||
++callbackCalls;
|
|
||||||
Debug.Log(string.Format("Discord: disconnect {0}: {1}", errorCode, message));
|
Debug.Log(string.Format("Discord: disconnect {0}: {1}", errorCode, message));
|
||||||
onDisconnect.Invoke();
|
onDisconnect.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ErrorCallback(int errorCode, string message)
|
public void ErrorCallback(int errorCode, string message)
|
||||||
{
|
{
|
||||||
++callbackCalls;
|
|
||||||
Debug.Log(string.Format("Discord: error {0}: {1}", errorCode, message));
|
Debug.Log(string.Format("Discord: error {0}: {1}", errorCode, message));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void JoinCallback(string secret)
|
public void JoinCallback(string secret)
|
||||||
{
|
{
|
||||||
++callbackCalls;
|
|
||||||
Debug.Log(string.Format("Discord: join ({0})", secret));
|
Debug.Log(string.Format("Discord: join ({0})", secret));
|
||||||
onJoin.Invoke(secret);
|
onJoin.Invoke(secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SpectateCallback(string secret)
|
public void SpectateCallback(string secret)
|
||||||
{
|
{
|
||||||
++callbackCalls;
|
|
||||||
Debug.Log(string.Format("Discord: spectate ({0})", secret));
|
Debug.Log(string.Format("Discord: spectate ({0})", secret));
|
||||||
onSpectate.Invoke(secret);
|
onSpectate.Invoke(secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RequestCallback(ref DiscordRpc.DiscordUser request)
|
public void RequestCallback(ref DiscordRpc.DiscordUser request)
|
||||||
{
|
{
|
||||||
++callbackCalls;
|
|
||||||
Debug.Log(string.Format("Discord: join request {0}#{1}: {2}", request.username, request.discriminator, request.userId));
|
Debug.Log(string.Format("Discord: join request {0}#{1}: {2}", request.username, request.discriminator, request.userId));
|
||||||
joinRequest = request;
|
joinRequest = request;
|
||||||
onJoinRequest.Invoke(request);
|
onJoinRequest.Invoke(request);
|
||||||
|
@ -104,10 +97,8 @@ public class DiscordController : MonoBehaviour
|
||||||
void OnEnable()
|
void OnEnable()
|
||||||
{
|
{
|
||||||
Debug.Log("Discord: init");
|
Debug.Log("Discord: init");
|
||||||
callbackCalls = 0;
|
|
||||||
|
|
||||||
handlers = new DiscordRpc.EventHandlers();
|
handlers = new DiscordRpc.EventHandlers();
|
||||||
handlers.readyCallback = ReadyCallback;
|
handlers.readyCallback += ReadyCallback;
|
||||||
handlers.disconnectedCallback += DisconnectedCallback;
|
handlers.disconnectedCallback += DisconnectedCallback;
|
||||||
handlers.errorCallback += ErrorCallback;
|
handlers.errorCallback += ErrorCallback;
|
||||||
handlers.joinCallback += JoinCallback;
|
handlers.joinCallback += JoinCallback;
|
||||||
|
|
|
@ -2,35 +2,42 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using AOT;
|
||||||
|
|
||||||
public class DiscordRpc
|
public class DiscordRpc
|
||||||
{
|
{
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
[MonoPInvokeCallback(typeof(OnReadyInfo))]
|
||||||
public delegate void ReadyCallback(ref DiscordUser connectedUser);
|
public static void ReadyCallback(ref DiscordUser connectedUser) { }
|
||||||
|
public delegate void OnReadyInfo(ref DiscordUser connectedUser);
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
[MonoPInvokeCallback(typeof(OnDisconnectedInfo))]
|
||||||
public delegate void DisconnectedCallback(int errorCode, string message);
|
public static void DisconnectedCallback(int errorCode, string message) { }
|
||||||
|
public delegate void OnDisconnectedInfo(int errorCode, string message);
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
[MonoPInvokeCallback(typeof(OnErrorInfo))]
|
||||||
public delegate void ErrorCallback(int errorCode, string message);
|
public static void ErrorCallback(int errorCode, string message) { }
|
||||||
|
public delegate void OnErrorInfo(int errorCode, string message);
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
[MonoPInvokeCallback(typeof(OnJoinInfo))]
|
||||||
public delegate void JoinCallback(string secret);
|
public static void JoinCallback(string secret) { }
|
||||||
|
public delegate void OnJoinInfo(string secret);
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
[MonoPInvokeCallback(typeof(OnSpectateInfo))]
|
||||||
public delegate void SpectateCallback(string secret);
|
public static void SpectateCallback(string secret) { }
|
||||||
|
public delegate void OnSpectateInfo(string secret);
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
[MonoPInvokeCallback(typeof(OnRequestInfo))]
|
||||||
public delegate void RequestCallback(ref DiscordUser request);
|
public static void RequestCallback(ref DiscordUser request) { }
|
||||||
|
public delegate void OnRequestInfo(ref DiscordUser request);
|
||||||
|
|
||||||
public struct EventHandlers
|
public struct EventHandlers
|
||||||
{
|
{
|
||||||
public ReadyCallback readyCallback;
|
public OnReadyInfo readyCallback;
|
||||||
public DisconnectedCallback disconnectedCallback;
|
public OnDisconnectedInfo disconnectedCallback;
|
||||||
public ErrorCallback errorCallback;
|
public OnErrorInfo errorCallback;
|
||||||
public JoinCallback joinCallback;
|
public OnJoinInfo joinCallback;
|
||||||
public SpectateCallback spectateCallback;
|
public OnSpectateInfo spectateCallback;
|
||||||
public RequestCallback requestCallback;
|
public OnRequestInfo requestCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, StructLayout(LayoutKind.Sequential)]
|
[Serializable, StructLayout(LayoutKind.Sequential)]
|
||||||
|
@ -160,7 +167,7 @@ public class DiscordRpc
|
||||||
var buffer = Marshal.AllocHGlobal(convbytecnt + 1);
|
var buffer = Marshal.AllocHGlobal(convbytecnt + 1);
|
||||||
for (int i = 0; i < convbytecnt + 1; i++)
|
for (int i = 0; i < convbytecnt + 1; i++)
|
||||||
{
|
{
|
||||||
Marshal.WriteByte(buffer, i , 0);
|
Marshal.WriteByte(buffer, i, 0);
|
||||||
}
|
}
|
||||||
_buffers.Add(buffer);
|
_buffers.Add(buffer);
|
||||||
Marshal.Copy(Encoding.UTF8.GetBytes(input), 0, buffer, convbytecnt);
|
Marshal.Copy(Encoding.UTF8.GetBytes(input), 0, buffer, convbytecnt);
|
||||||
|
|
Loading…
Reference in a new issue