From 10fec893e40816f7c09100dce3eff4d25028ef28 Mon Sep 17 00:00:00 2001 From: syeyoung Date: Sat, 19 Nov 2022 22:15:23 +0900 Subject: - Yeah, I'm removing all the callbacks - Make RichPresenceManager finish gracefully - Refresh EventListener cache Signed-off-by: syeyoung --- .../kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java | 9 +++++++++ .../dungeonsguide/mod/discord/gamesdk/GameSDK.java | 17 +++++++++++++---- .../mod/discord/rpc/RichPresenceManager.java | 3 ++- 3 files changed, 24 insertions(+), 5 deletions(-) (limited to 'mod/src/main/java/kr/syeyoung') diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java index 5ef83afa..ea05603f 100755 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java @@ -69,6 +69,8 @@ import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.client.event.GuiOpenEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.ProgressManager; +import net.minecraftforge.fml.common.eventhandler.EventBus; +import net.minecraftforge.fml.common.eventhandler.ListenerList; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.relauncher.ReflectionHelper; import org.apache.logging.log4j.LogManager; @@ -289,6 +291,13 @@ public class DungeonsGuide implements DGInterface { for (Object registeredListener : registeredListeners) { MinecraftForge.EVENT_BUS.unregister(registeredListener); } + List all = ReflectionHelper.getPrivateValue(ListenerList.class, null, "allLists"); + int busId = ReflectionHelper.getPrivateValue(EventBus.class, MinecraftForge.EVENT_BUS, "busID"); + for (ListenerList listenerList : all) { + listenerList.getListeners(busId); // refresh cache. + } + + Set commands = ReflectionHelper.getPrivateValue(CommandHandler.class, ClientCommandHandler.instance, "commandSet"); for (ICommand registeredCommand : registeredCommands) { diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/gamesdk/GameSDK.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/gamesdk/GameSDK.java index c6fecb33..0a48ad21 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/gamesdk/GameSDK.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/gamesdk/GameSDK.java @@ -74,12 +74,21 @@ public class GameSDK { } public static void cleanup() { -// com.sun.jna.CallbackReference has reference of DiscordCallback. idk how i should approach fixing this -> I would better write native lib myself later. - if (System.getProperty("dg.safe") == null) return; - Map infos = ReflectionHelper.getPrivateValue(Structure.class, null, "layoutInfo"); - infos.clear(); + nativeGameSDK = null; Map options = ReflectionHelper.getPrivateValue(Native.class, null, "options"); options.clear(); + try { + Map callbackMap = ReflectionHelper.getPrivateValue( + (Class) Class.forName("com.sun.jna.CallbackReference"), + null, + "callbackMap" + ); + callbackMap.clear(); + } catch (ClassNotFoundException e) { + } + + Map infos = ReflectionHelper.getPrivateValue(Structure.class, null, "layoutInfo"); + infos.clear(); Map alignments = ReflectionHelper.getPrivateValue(Native.class, null, "alignments"); alignments.clear(); Map typeMapperMap = ReflectionHelper.getPrivateValue(Native.class, null, "typeMappers"); diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/rpc/RichPresenceManager.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/rpc/RichPresenceManager.java index 135716f9..1ea17cfe 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/rpc/RichPresenceManager.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/rpc/RichPresenceManager.java @@ -223,7 +223,6 @@ public class RichPresenceManager implements Runnable { }); } } - @Override public void run() { boolean setup = true; @@ -250,5 +249,7 @@ public class RichPresenceManager implements Runnable { Thread.sleep(16L); } catch (Exception e) {e.printStackTrace();} } + if (iDiscordCore != null) + iDiscordCore.Destroy.destroy(iDiscordCore); } } -- cgit