Skip to content

Commit

Permalink
v4.0: Dynamic Premium Patching Method, Disable Patching and Reset Dat…
Browse files Browse the repository at this point in the history
…a Options
  • Loading branch information
whoeevee committed May 28, 2024
1 parent fb8a974 commit 171af9c
Show file tree
Hide file tree
Showing 18 changed files with 1,985 additions and 272 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ xcuserdata/

._*
.theos
.swiftpm
/packages
.theos/
packages/
Expand Down
215 changes: 0 additions & 215 deletions Sources/EeveeSpotify/CustomLyrics.x.swift

This file was deleted.

135 changes: 135 additions & 0 deletions Sources/EeveeSpotify/DataLoaderServiceHooks.x.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import Foundation
import Orion

class SPTDataLoaderServiceHook: ClassHook<NSObject> {

static let targetName = "SPTDataLoaderService"

func URLSession(
_ session: URLSession,
task: URLSessionDataTask,
didCompleteWithError error: Error?
) {
if let url = task.currentRequest?.url {
if url.isLyrics || (UserDefaults.patchType == .requests && url.isCustomize) {
return
}
}
orig.URLSession(session, task: task, didCompleteWithError: error)
}

func URLSession(
_ session: URLSession,
dataTask task: URLSessionDataTask,
didReceiveResponse response: HTTPURLResponse,
completionHandler handler: Any
) {
let url = response.url!

if url.isLyrics, response.statusCode != 200 {

let okResponse = HTTPURLResponse(
url: url,
statusCode: 200,
httpVersion: "2.0",
headerFields: [:]
)!

do {
let lyricsData = try getCurrentTrackLyricsData()

orig.URLSession(
session,
dataTask: task,
didReceiveResponse: okResponse,
completionHandler: handler
)

orig.URLSession(session, dataTask: task, didReceiveData: lyricsData)
orig.URLSession(session, task: task, didCompleteWithError: nil)

return
}
catch {
NSLog("[EeveeSpotify] Unable to load lyrics: \(error)")
orig.URLSession(session, task: task, didCompleteWithError: error)

return
}
}

orig.URLSession(
session,
dataTask: task,
didReceiveResponse: response,
completionHandler: handler
)
}

func URLSession(
_ session: URLSession,
dataTask task: URLSessionDataTask,
didReceiveData data: Data
) {
guard
let request = task.currentRequest,
let response = task.response,
let url = request.url
else {
return
}

if url.isLyrics {

do {
orig.URLSession(
session,
dataTask: task,
didReceiveData: try getCurrentTrackLyricsData()
)

orig.URLSession(session, task: task, didCompleteWithError: nil)
return
}
catch {
NSLog("[EeveeSpotify] Unable to load lyrics: \(error)")
orig.URLSession(session, task: task, didCompleteWithError: error)

return
}
}

if url.isCustomize && UserDefaults.patchType == .requests {

do {
guard let buffer = OfflineHelper.appendDataAndReturnIfFull(
data,
response: response
) else {
return
}

OfflineHelper.dataBuffer = Data()

var customizeMessage = try CustomizeMessage(serializedData: buffer)
modifyAttributes(&customizeMessage.response.attributes.accountAttributes)

orig.URLSession(
session,
dataTask: task,
didReceiveData: try customizeMessage.serializedData()
)

orig.URLSession(session, task: task, didCompleteWithError: nil)

NSLog("[EeveeSpotify] Modified customize data")
return
}
catch {
NSLog("[EeveeSpotify] Unable to modify customize data: \(error)")
}
}

orig.URLSession(session, dataTask: task, didReceiveData: data)
}
}
Loading

0 comments on commit 171af9c

Please sign in to comment.