From c223c9bf3900ae113303fbc12fcb58751992a58d Mon Sep 17 00:00:00 2001 From: Sarah Engel <45071533+PrincessAkira@users.noreply.github.com> Date: Thu, 7 Sep 2023 15:35:32 +0200 Subject: [PATCH 1/4] Fix invalid Offsets on the Scoop Version of Spotify --- .../platform/windows/api/spotify/SpotifyProcess.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/labystudio/spotifyapi/platform/windows/api/spotify/SpotifyProcess.java b/src/main/java/de/labystudio/spotifyapi/platform/windows/api/spotify/SpotifyProcess.java index bca70ab..178046b 100644 --- a/src/main/java/de/labystudio/spotifyapi/platform/windows/api/spotify/SpotifyProcess.java +++ b/src/main/java/de/labystudio/spotifyapi/platform/windows/api/spotify/SpotifyProcess.java @@ -17,7 +17,7 @@ public class SpotifyProcess extends WinProcess { // Spotify track id private static final String PREFIX_SPOTIFY_TRACK = "spotify:track:"; - private static final long ADDRESS_OFFSET_TRACK_ID = 0x1499F0; + private static long ADDRESS_OFFSET_TRACK_ID = 0x1499F0; //FEFE8 private final long addressTrackId; private final PlaybackAccessor playbackAccessor; @@ -57,7 +57,13 @@ private long findTrackIdAddress() { long addressTrackId = chromeElfAddress + ADDRESS_OFFSET_TRACK_ID; if (addressTrackId == -1 || !this.isTrackIdValid(this.readTrackId(addressTrackId))) { - throw new IllegalStateException("Could not find track id in memory"); + if(ADDRESS_OFFSET_TRACK_ID == 0x1499F0) { + ADDRESS_OFFSET_TRACK_ID = 0xFEFE8; + throw new IllegalStateException("Could not find track id in memory, trying different Address Offset"); + } else { + ADDRESS_OFFSET_TRACK_ID = 0x1499F0; + throw new IllegalStateException("Could not find track id in memory"); + } } if (DEBUG) { From c075e5ccc91731e9ebfb01bad5acd8f8f8633910 Mon Sep 17 00:00:00 2001 From: Sarah Engel <45071533+PrincessAkira@users.noreply.github.com> Date: Thu, 7 Sep 2023 20:27:05 +0200 Subject: [PATCH 2/4] Rewrote Scoop fix to make it more robust and look better in general --- .../windows/api/spotify/SpotifyProcess.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/labystudio/spotifyapi/platform/windows/api/spotify/SpotifyProcess.java b/src/main/java/de/labystudio/spotifyapi/platform/windows/api/spotify/SpotifyProcess.java index 178046b..48f83e7 100644 --- a/src/main/java/de/labystudio/spotifyapi/platform/windows/api/spotify/SpotifyProcess.java +++ b/src/main/java/de/labystudio/spotifyapi/platform/windows/api/spotify/SpotifyProcess.java @@ -54,16 +54,15 @@ private long findTrackIdAddress() { // Find address of track id (Located in the chrome_elf.dll module) long chromeElfAddress = chromeElfModule.getBaseOfDll(); + + if(this.findInMemory(0, 0x0FFFFFFF, "Scoop Apps".getBytes()) != -1) { + ADDRESS_OFFSET_TRACK_ID = 0xFEFE8; + } + long addressTrackId = chromeElfAddress + ADDRESS_OFFSET_TRACK_ID; if (addressTrackId == -1 || !this.isTrackIdValid(this.readTrackId(addressTrackId))) { - if(ADDRESS_OFFSET_TRACK_ID == 0x1499F0) { - ADDRESS_OFFSET_TRACK_ID = 0xFEFE8; - throw new IllegalStateException("Could not find track id in memory, trying different Address Offset"); - } else { - ADDRESS_OFFSET_TRACK_ID = 0x1499F0; - throw new IllegalStateException("Could not find track id in memory"); - } + throw new IllegalStateException("Could not find track id in memory"); } if (DEBUG) { From 8ee6bf5ac2c654eb5dd3a86ea4d53f854ae38692 Mon Sep 17 00:00:00 2001 From: LabyStudio Date: Fri, 8 Sep 2023 12:40:09 +0200 Subject: [PATCH 3/4] use array of offsets instead --- .../windows/api/spotify/SpotifyProcess.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/labystudio/spotifyapi/platform/windows/api/spotify/SpotifyProcess.java b/src/main/java/de/labystudio/spotifyapi/platform/windows/api/spotify/SpotifyProcess.java index 48f83e7..c4aad75 100644 --- a/src/main/java/de/labystudio/spotifyapi/platform/windows/api/spotify/SpotifyProcess.java +++ b/src/main/java/de/labystudio/spotifyapi/platform/windows/api/spotify/SpotifyProcess.java @@ -17,7 +17,10 @@ public class SpotifyProcess extends WinProcess { // Spotify track id private static final String PREFIX_SPOTIFY_TRACK = "spotify:track:"; - private static long ADDRESS_OFFSET_TRACK_ID = 0x1499F0; //FEFE8 + private static final long[] ADDRESSES_OFFSET_TRACK_ID = { + 0x1499F0, // Vanilla + 0xFEFE8 // Scoop + }; private final long addressTrackId; private final PlaybackAccessor playbackAccessor; @@ -55,14 +58,14 @@ private long findTrackIdAddress() { // Find address of track id (Located in the chrome_elf.dll module) long chromeElfAddress = chromeElfModule.getBaseOfDll(); - if(this.findInMemory(0, 0x0FFFFFFF, "Scoop Apps".getBytes()) != -1) { - ADDRESS_OFFSET_TRACK_ID = 0xFEFE8; - } - - long addressTrackId = chromeElfAddress + ADDRESS_OFFSET_TRACK_ID; - - if (addressTrackId == -1 || !this.isTrackIdValid(this.readTrackId(addressTrackId))) { - throw new IllegalStateException("Could not find track id in memory"); + // Check all offsets for valid track id + long addressTrackId = -1; + for (long trackIdOffset : ADDRESSES_OFFSET_TRACK_ID) { + addressTrackId = chromeElfAddress + trackIdOffset; + if (addressTrackId == -1 || !this.isTrackIdValid(this.readTrackId(addressTrackId))) { + throw new IllegalStateException("Could not find track id in memory"); + } + break; } if (DEBUG) { From 4d881f5791a3baf7d823e757cf91412b0c94e90e Mon Sep 17 00:00:00 2001 From: LabyStudio Date: Fri, 8 Sep 2023 12:42:55 +0200 Subject: [PATCH 4/4] let's just call it offsets --- .../platform/windows/api/spotify/SpotifyProcess.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/labystudio/spotifyapi/platform/windows/api/spotify/SpotifyProcess.java b/src/main/java/de/labystudio/spotifyapi/platform/windows/api/spotify/SpotifyProcess.java index c4aad75..9fa3523 100644 --- a/src/main/java/de/labystudio/spotifyapi/platform/windows/api/spotify/SpotifyProcess.java +++ b/src/main/java/de/labystudio/spotifyapi/platform/windows/api/spotify/SpotifyProcess.java @@ -17,7 +17,7 @@ public class SpotifyProcess extends WinProcess { // Spotify track id private static final String PREFIX_SPOTIFY_TRACK = "spotify:track:"; - private static final long[] ADDRESSES_OFFSET_TRACK_ID = { + private static final long[] OFFSETS_TRACK_ID = { 0x1499F0, // Vanilla 0xFEFE8 // Scoop }; @@ -60,7 +60,7 @@ private long findTrackIdAddress() { // Check all offsets for valid track id long addressTrackId = -1; - for (long trackIdOffset : ADDRESSES_OFFSET_TRACK_ID) { + for (long trackIdOffset : OFFSETS_TRACK_ID) { addressTrackId = chromeElfAddress + trackIdOffset; if (addressTrackId == -1 || !this.isTrackIdValid(this.readTrackId(addressTrackId))) { throw new IllegalStateException("Could not find track id in memory");