Skip to content
This repository has been archived by the owner on May 12, 2023. It is now read-only.

Commit

Permalink
Give users options (pick folder, pick lock pack).
Browse files Browse the repository at this point in the history
  • Loading branch information
seilfx committed Dec 30, 2022
1 parent 0264e4f commit 29d0e0c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,6 @@
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "B23166F4-7507-4507-81BE-0AE0BDC420E1"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "TrollMods/Mods/TrollLock/TrollLock.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "60"
endingLineNumber = "60"
landmarkName = "TrollLockReplace(path:)"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
Expand All @@ -30,9 +14,9 @@
filePath = "TrollMods/Mods/TrollLock/TrollLock.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "54"
endingLineNumber = "54"
landmarkName = "TrollLockReplace(path:)"
startingLineNumber = "61"
endingLineNumber = "61"
landmarkName = "TrollLockReplace(path:targetLockPath:)"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
Expand All @@ -48,7 +32,7 @@
endingColumnNumber = "9223372036854775807"
startingLineNumber = "108"
endingLineNumber = "108"
landmarkName = "TrollLockReplace(path:)"
landmarkName = "TrollLockReplace(path:targetLockPath:)"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
Expand Down
68 changes: 41 additions & 27 deletions TrollMods/Mods/TrollLock/TrollLock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ import SwiftUI
import Zip

private let trollLockVersion: String = "v1.0";
private let globalLockPaths: [String] = [
"3x-d73",
"3x-896h",
"3x-812h",
"2x-896h",
"2x-812h",
];
private let deviceLockPath: [String: String] = [
"iPhone15,3": "3x-896h", // iPhone 14 Pro Max 3x-d73
"iPhone15,3": "3x-896h", // iPhone 14 Pro Max 3x-d73?
"iPhone15,2": "3x-d73", // iPhone 14 Pro
"iPhone14,7": "3x-812h", // iPhone 14

Expand Down Expand Up @@ -51,24 +58,17 @@ extension UIDevice {
}
}

func TrollLockReplace(path: URL) {
func TrollLockReplace(path: URL, targetLockPath: String) {
DispatchQueue.global(qos: .userInteractive).async {
let targetLockPath = deviceLockPath[UIDevice.current.modelName];

guard targetLockPath != nil else {
debugPrint(targetLockPath ?? "NONE");
return print("Device (\(UIDevice.current.modelName)) unsupported!");
}

// /var/mobile/Containers/Data/Application//Documents/TrollLock/main.caml
let sourceFilePath = path.appendingPathComponent("main.caml");
print(sourceFilePath);

let targetPath = "/System/Library/PrivateFrameworks/SpringBoardUIServices.framework/lock@\(targetLockPath!).ca/main.caml";
let targetPath = "/System/Library/PrivateFrameworks/SpringBoardUIServices.framework/lock@\(targetLockPath).ca/main.caml";
debugPrint(targetPath);

do {
let files = try FileManager.default.contentsOfDirectory(atPath: "/System/Library/PrivateFrameworks/SpringBoardUIServices.framework/lock@\(targetLockPath!).ca/");
let files = try FileManager.default.contentsOfDirectory(atPath: "/System/Library/PrivateFrameworks/SpringBoardUIServices.framework/lock@\(targetLockPath).ca/");
debugPrint(files);

let mainCamlContents = try String(contentsOf: URL.init(fileURLWithPath: targetPath), encoding: .utf8);
Expand All @@ -82,14 +82,14 @@ func TrollLockReplace(path: URL) {


/* TODO: Load custom animation file from lockpack.zip
var lockPackCamlContents: Data;
do {
lockPackCamlContents = try Data(contentsOf: path.appendingPathComponent("main.caml"));
} catch {
lockPackCamlContents = mainCaml.data(using: .utf8)!
}
*/
var lockPackCamlContents: Data;
do {
lockPackCamlContents = try Data(contentsOf: path.appendingPathComponent("main.caml"));
} catch {
lockPackCamlContents = mainCaml.data(using: .utf8)!
}
*/


let lockPackCamlContents = TrollLockInjectIntoAnimation(lockPack: path);
Expand All @@ -105,7 +105,7 @@ func TrollLockReplace(path: URL) {
print("Success: \(success)");

do {
let files = try FileManager.default.contentsOfDirectory(atPath: "/System/Library/PrivateFrameworks/SpringBoardUIServices.framework/lock@\(targetLockPath!).ca/");
let files = try FileManager.default.contentsOfDirectory(atPath: "/System/Library/PrivateFrameworks/SpringBoardUIServices.framework/lock@\(targetLockPath).ca/");
debugPrint(files);

let mainCamlContents = try String(contentsOf: URL.init(fileURLWithPath: targetPath), encoding: .utf8);
Expand Down Expand Up @@ -138,7 +138,7 @@ func TrollLockInjectIntoAnimation(lockPack: URL) -> String {
return xCaml;
}

func TrollLockLoadAndReplace(url: String) {
func TrollLockLoadAndReplace(url: String, targetLockPath: String) {
let task = URLSession.shared.downloadTask(with: URL(string: url)!) { data, response, error in
if let data = data {
debugPrint(data);
Expand All @@ -161,7 +161,7 @@ func TrollLockLoadAndReplace(url: String) {
try Zip.unzipFile(dataZip, destination: filePath, overwrite: true, password: nil);
print("Unzipped!");

TrollLockReplace(path: filePath);
TrollLockReplace(path: filePath, targetLockPath: targetLockPath);
} catch {
debugPrint("Failed to move or unzip file: \(error)");
}
Expand All @@ -175,11 +175,14 @@ func TrollLockLoadAndReplace(url: String) {
struct TrollLockView: View {
@State private var showInfoPrompt = false;
@State private var showTweakPrompt = false;
@State private var showFolderPrompt = false;
@State private var showCustomPackPrompt = false;
@State private var showLoadCustomPackPrompt = false;

@State private var customPackURL = "https://github.com/Gluki0/icons-for-TrollLock/releases/download/icons/windowshello.zip";

@State private var targetLockPath = deviceLockPath[UIDevice.current.modelName];

var body: some View {
VStack {
Image("TrollLock")
Expand All @@ -203,19 +206,30 @@ struct TrollLockView: View {
secondaryButton: .destructive(
Text("Begin"),
action: {
showLoadCustomPackPrompt = true; //showCustomPackPrompt = true;
showFolderPrompt = true;
}
)
)
}
/*.alert("Which lock pack to use?", isPresented: $showCustomPackPrompt) {
.confirmationDialog("Devices have multiple lock folders, but only one must be modified. Based on your device the best choice is \(targetLockPath ?? "unknown. Try each folder and respring between each try until you find the one that works for you").",
isPresented: $showFolderPrompt,
titleVisibility: .visible,
actions: {
ForEach(globalLockPaths, id: \.self) { folder in
Button(folder, action: {
targetLockPath = folder;
showCustomPackPrompt = true;
});
}
})
.alert("Which lock pack to use?", isPresented: $showCustomPackPrompt) {
//Button("Use last", action: { showCustomPackPrompt = false })
Button("Use custom from URL", action: { showLoadCustomPackPrompt = true })
// Button("Use default (Trollface)", action: { TrollLockReplace(path: ) })
}*/
Button("Use default (Trollface)", action: { TrollLockReplace(path: Bundle.main.resourceURL!, targetLockPath: targetLockPath!) })
}
.alert("Load lock pack from URL", isPresented: $showLoadCustomPackPrompt, actions: {
TextField("Pack URL", text: $customPackURL)
Button("Load", action: { TrollLockLoadAndReplace(url: customPackURL) })
Button("Load", action: { TrollLockLoadAndReplace(url: customPackURL, targetLockPath: targetLockPath!) })
Button("Cancel", role: .cancel, action: {})
})
}
Expand Down
1 change: 0 additions & 1 deletion TrollMods/TrollMods-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
//

#import "vm_unaligned_copy_switch_race.h"
#import "TrollLockCopy.h"

0 comments on commit 29d0e0c

Please sign in to comment.