@@ -18,8 +18,10 @@ public class SpotifyProcess extends WinProcess {
1818 // Spotify track id
1919 private static final String PREFIX_SPOTIFY_TRACK = "spotify:track:" ;
2020 private static final long [] OFFSETS_TRACK_ID = {
21- 0x14C9F0 , // 64-Bit
22- 0x102178 , // 32-Bit
21+ 0x14FA30 , // 64-Bit (1.2.21.1104.g42cf0a50)
22+ 0x106198 , // 32-Bit (1.2.21.1104.g42cf0a50)
23+ 0x14C9F0 , // 64-Bit (Old)
24+ 0x102178 , // 32-Bit (Old)
2325 0x1499F0 , // 64-Bit (Old)
2426 0xFEFE8 // 32-Bit (Old)
2527 };
@@ -62,14 +64,36 @@ private long findTrackIdAddress() {
6264
6365 // Check all offsets for valid track id
6466 long addressTrackId = -1 ;
67+ long minTrackIdOffset = Long .MAX_VALUE ;
68+ long maxTrackIdOffset = Long .MIN_VALUE ;
6569 for (long trackIdOffset : OFFSETS_TRACK_ID ) {
66- addressTrackId = chromeElfAddress + trackIdOffset ;
67- if (addressTrackId != -1 && this .isTrackIdValid (this .readTrackId (addressTrackId ))) {
70+ // Get min and max of hardcoded offset
71+ minTrackIdOffset = Math .min (minTrackIdOffset , trackIdOffset );
72+ maxTrackIdOffset = Math .max (maxTrackIdOffset , trackIdOffset );
73+
74+ // Check if the hardcoded offset is valid
75+ long targetAddressTrackId = chromeElfAddress + trackIdOffset ;
76+ if (this .isTrackIdValid (this .readTrackId (targetAddressTrackId ))) {
6877 // If the offset works, exit the loop
78+ addressTrackId = targetAddressTrackId ;
6979 break ;
7080 }
7181 }
7282
83+ // If the hardcoded offsets are not valid, try to find it dynamically
84+ if (addressTrackId == -1 ) {
85+ if (DEBUG ) {
86+ System .out .println ("Could not find track id with hardcoded offsets. Trying to find it dynamically..." );
87+ }
88+
89+ long threshold = (maxTrackIdOffset - minTrackIdOffset ) * 3 ;
90+ long scanAddressFrom = chromeElfAddress + minTrackIdOffset - threshold ;
91+ long scanAddressTo = chromeElfAddress + maxTrackIdOffset + threshold ;
92+ addressTrackId = this .findAddressOfText (scanAddressFrom , scanAddressTo , "spotify:track:" , (address , index ) -> {
93+ return this .isTrackIdValid (this .readTrackId (address ));
94+ });
95+ }
96+
7397 if (addressTrackId == -1 ) {
7498 throw new IllegalStateException ("Could not find track id in memory" );
7599 }
@@ -87,10 +111,22 @@ private long findTrackIdAddress() {
87111 }
88112
89113 private PlaybackAccessor findPlaybackAccessor () {
90- // Find addresses of playback states
114+ // Find addresses of playback states when playing a playlist
91115 long addressPlayBack = this .findAddressOfText (0 , 0x0FFFFFFF , "playlist" , (address , index ) -> {
92- return this .hasText (address + 408 , "context" , "autoplay" );
116+ return this .hasText (address + 408 , "context" , "autoplay" )
117+ && this .hasText (address + 128 , "your_library" , "home" )
118+ && new MemoryPlaybackAccessor (this , address ).isValid ();
93119 });
120+
121+ if (addressPlayBack == -1 ) {
122+ // Find addresses of playback states when playing an album
123+ addressPlayBack = this .findAddressOfText (0 , 0x0FFFFFFF , "album" , (address , index ) -> {
124+ return this .hasText (address + 408 , "context" , "autoplay" )
125+ && this .hasText (address + 128 , "your_library" , "home" )
126+ && new MemoryPlaybackAccessor (this , address ).isValid ();
127+ });
128+ }
129+
94130 if (addressPlayBack == -1 ) {
95131 if (DEBUG ) {
96132 System .out .println ("Could not find playback address in memory" );
@@ -175,7 +211,7 @@ public long getAddressTrackId() {
175211 */
176212 public boolean isTrackIdValid (String trackId ) {
177213 for (char c : trackId .toCharArray ()) {
178- if (c == 0 ) {
214+ if (! Character . isLetterOrDigit ( c ) ) {
179215 return false ;
180216 }
181217 }
0 commit comments