Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions balatro-mobile-maker/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ internal static class Constants
public const string IosBaseLink = "https://github.com/blake502/balatro-apk-maker/releases/download/Additional-Tools-1.0/balatro-base.ipa";

//ADB
public const string PlatformToolsLink = "https://dl.google.com/android/repository/platform-tools-latest-windows.zip";
public const string PlatformToolsWindowsLink = "https://dl.google.com/android/repository/platform-tools-latest-windows.zip";
public const string PlatformToolsOSXLink = "https://dl.google.com/android/repository/platform-tools-latest-darwin.zip";
public const string PlatformToolsLinuxLink = "https://dl.google.com/android/repository/platform-tools-latest-linux.zip";

//OpenJDK Download Links
//TODO: Find JDK links for all platforms
Expand All @@ -28,4 +30,4 @@ internal static class Constants
//macOS
public const string OpenJDKOSXX64Link = "https://aka.ms/download-jdk/microsoft-jdk-21.0.3-macos-x64.tar.gz";
public const string OpenJDKOSXArm64Link = "https://aka.ms/download-jdk/microsoft-jdk-21.0.3-macos-aarch64.tar.gz";
}
}
36 changes: 24 additions & 12 deletions balatro-mobile-maker/Platform.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
Expand All @@ -15,25 +16,25 @@ internal class Platform
{
//I'm not sure which way will be easier to work with, so I'm doing both.
public static bool isWindows = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
private static bool isOSX = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
private static bool isLinux = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
public static bool isOSX = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
public static bool isLinux = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Linux);

private static bool isX64 = System.Runtime.InteropServices.RuntimeInformation.OSArchitecture == Architecture.X64;
private static bool isX86 = System.Runtime.InteropServices.RuntimeInformation.OSArchitecture == Architecture.X86;
private static bool isArm64 = System.Runtime.InteropServices.RuntimeInformation.OSArchitecture == Architecture.Arm64;
private static bool isArm = System.Runtime.InteropServices.RuntimeInformation.OSArchitecture == Architecture.Arm;

//Uses ADB with args
public static void useADB(string args)
public static Process useADB(string args, bool ignoreErrors=false)
{
if (isWindows)
RunCommand("platform-tools\\platform-tools\\adb.exe", args);
return RunCommand("platform-tools\\platform-tools\\adb.exe", args, ignoreErrors);

if (isOSX || isLinux)
RunCommand("chmod", "+x platform-tools/platform-tools/adb");
return RunCommand("platform-tools/platform-tools/adb", args, ignoreErrors);

//TODO: Implement ADB for OSX and Linux
if (isOSX) { /*...*/ }

if (isLinux) { /*...*/ }
return null;
}

//Uses Java with args
Expand Down Expand Up @@ -111,17 +112,28 @@ public static string getOpenJDKDownloadLink()
return Constants.OpenJDKLinuxArm64Link;
}


return "";
}

public static string getPlatformToolsDownloadLink()
{
if (isWindows)
return Constants.PlatformToolsWindowsLink;

if (isOSX)
return Constants.PlatformToolsOSXLink;

if (isLinux)
return Constants.PlatformToolsLinuxLink;

return "";
}

public static string getGameSaveLocation()
{
if (isWindows)
return Environment.GetEnvironmentVariable("AppData") + "\\Balatro";

//TODO: Test Linux location
if (isLinux)
return Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "/.local/share/Steam/steamapps/compatdata/2379780/pfx/drive_c/users/steamuser/AppData/Roaming/Balatro";

Expand All @@ -137,7 +149,7 @@ public static string getGameSaveLocation()
//If it does already exist, this returns true
public static bool gameExists()
{
if(isWindows)
if (isWindows)
return fileExists("Balatro.exe");


Expand Down Expand Up @@ -170,7 +182,7 @@ public static bool tryLocateGame()
if (isWindows)
location = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Balatro\\Balatro.exe";

//TODO: Test OSX and Linux locations!!!
//TODO: Test OSX locations!!!
if (isOSX)
location = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "/Library/Application Support/Steam/steamapps/common/Balatro/Balatro.app/Contents/Resources/Balatro.love";

Expand Down
27 changes: 23 additions & 4 deletions balatro-mobile-maker/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,26 @@ public static bool directoryExists(string path)
{
return Directory.Exists(path);
}


public static void directoryCopy(string source, string dest)
{
if (!directoryExists(source))
return;

if (directoryExists(dest))
tryDelete(dest);

foreach (string dirPath in Directory.GetDirectories(source, "*", SearchOption.AllDirectories))
{
Directory.CreateDirectory(dirPath.Replace(source, dest));
}

foreach (string newPath in Directory.GetFiles(source, "*.*",SearchOption.AllDirectories))
{
File.Copy(newPath, newPath.Replace(source, dest), true);
}
}

public static void fileMove(string source, string dest)
{
fileCopy(source, dest);
Expand Down Expand Up @@ -143,7 +162,7 @@ public static void Exit()
View.Cleanup();
Log("Press any key to exit...");
Console.ReadKey();
Environment.Exit(1);
Environment.Exit(0);
}

/// <summary>
Expand Down Expand Up @@ -172,7 +191,7 @@ private static void ProcessOutputHandler(object sender, DataReceivedEventArgs e)
/// </summary>
/// <param name="args">Command to pass to the shell</param>
/// <returns>Process, post finishing.</returns>
public static Process RunCommand(string command, string args)
public static Process RunCommand(string command, string args, bool ignoreErrors=false)
{
//Create a new cmd process
Process commandLineProcess = new Process();
Expand Down Expand Up @@ -200,7 +219,7 @@ public static Process RunCommand(string command, string args)
commandLineProcess.Exited += (_, _) =>
{
//Check for errors
if (commandLineProcess.ExitCode != 0)
if (commandLineProcess.ExitCode != 0 && !ignoreErrors)
{
//Error occurred
Log("An unexpected error occurred!");
Expand Down
134 changes: 67 additions & 67 deletions balatro-mobile-maker/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public void Begin()
_androidBuild = AskQuestion("Would you like to build for Android?");
_iosBuild = AskQuestion("Would you like to build for iOS (experimental)?");


if (_androidBuild || _iosBuild)
{
#region Download tools
Expand Down Expand Up @@ -245,7 +244,7 @@ public void Begin()
if (_iosBuild)
{
#region Packing IPA

Log("Repacking iOS app...");
ModifyZip();

Expand All @@ -257,8 +256,8 @@ public void Begin()
}
}

//TODO: Implement for OSX and Linux!!!
if ((!_iosBuild || _androidBuild) && Platform.isWindows)
//TODO: Implement for OSX!!!
if ((!_iosBuild || _androidBuild) && (Platform.isWindows || Platform.isLinux))
{
#region Android options
#region Auto-install
Expand All @@ -269,82 +268,78 @@ public void Begin()
Log("Attempting to install. If prompted, please allow the USB Debugging connection on your Android device.");

useTool(ProcessTools.ADB, "install balatro.apk");
useTool(ProcessTools.ADB, "kill-server");
}
#endregion

#region Save transfer

if (directoryExists(Environment.GetEnvironmentVariable("AppData") + "\\Balatro") && AskQuestion("Would you like to transfer saves from your Steam copy of Balatro to your Android device?"))
if (directoryExists(Platform.getGameSaveLocation()) && AskQuestion("Would you like to transfer saves from your Steam copy of Balatro to your Android device?"))
{
Log("Thanks to TheCatRiX for figuring out save transfers!");

PrepareAndroidPlatformTools();

Log("Attempting to transfer saves. If prompted, please allow the USB Debugging connection on your Android device.");

useTool(ProcessTools.ADB, "shell mkdir /data/local/tmp/balatro");
useTool(ProcessTools.ADB, "shell mkdir /data/local/tmp/balatro/files");
useTool(ProcessTools.ADB, "shell mkdir /data/local/tmp/balatro/files/save");
useTool(ProcessTools.ADB, "shell mkdir /data/local/tmp/balatro/balatro/files/save/game");
useTool(ProcessTools.ADB, "push \"" + Platform.getGameSaveLocation() + "\\.\" /data/local/tmp/balatro/files/save/game");
useTool(ProcessTools.ADB, "shell mkdir -p /data/local/tmp/balatro/balatro/files/save/game");

useTool(ProcessTools.ADB, "push \"" + Platform.getGameSaveLocation() + "\" /data/local/tmp/balatro/files/save/game");

useTool(ProcessTools.ADB, "shell am force-stop com.unofficial.balatro");
useTool(ProcessTools.ADB, "shell run-as com.unofficial.balatro cp -r /data/local/tmp/balatro/files .");
useTool(ProcessTools.ADB, "shell rm -r /data/local/tmp/balatro");
useTool(ProcessTools.ADB, "kill-server");
}
else
else if (AskQuestion("Would you like to pull saves from your Android device?"))
{
if (AskQuestion("Would you like to pull saves from your Android device?"))
{
Log("Warning! If Steam Cloud is enabled, it will overwrite the save you transfer!");
while (!AskQuestion("Have you backed up your saves?"))
Log("Please back up your saves! I am not responsible if your saves get deleted!");

PrepareAndroidPlatformTools();

Log("Backing up your files...");
if (!directoryExists(Platform.getGameSaveLocation() + "BACKUP"))
System.IO.Directory.CreateDirectory(Platform.getGameSaveLocation() + "BACKUP/");
//TODO: No xcopy
RunCommand("xcopy", "\"" + Platform.getGameSaveLocation() + "\" \"" + Platform.getGameSaveLocation() + "BACKUP\\\" /E /H /Y /V");
tryDelete(Platform.getGameSaveLocation());
System.IO.Directory.CreateDirectory(Platform.getGameSaveLocation());

Log("Attempting to pull save files from Android device.");

//This sure isn't pretty, but it should work!
useTool(ProcessTools.ADB, "shell rm -r /data/local/tmp/balatro");
useTool(ProcessTools.ADB, "shell mkdir /data/local/tmp/balatro/");
useTool(ProcessTools.ADB, "shell mkdir /data/local/tmp/balatro/files/");
useTool(ProcessTools.ADB, "shell mkdir /data/local/tmp/balatro/files/1/");
useTool(ProcessTools.ADB, "shell mkdir /data/local/tmp/balatro/files/2/");
useTool(ProcessTools.ADB, "shell mkdir /data/local/tmp/balatro/files/3/");
useTool(ProcessTools.ADB, "shell touch /data/local/tmp/balatro/files/settings.jkr");
useTool(ProcessTools.ADB, "shell \"run-as com.unofficial.balatro cat files/save/game/settings.jkr > /data/local/tmp/balatro/files/settings.jkr\"");
useTool(ProcessTools.ADB, "shell touch /data/local/tmp/balatro/files/1/profile.jkr");
useTool(ProcessTools.ADB, "shell \"run-as com.unofficial.balatro cat files/save/game/1/profile.jkr > /data/local/tmp/balatro/files/1/profile.jkr\"");
useTool(ProcessTools.ADB, "shell touch /data/local/tmp/balatro/files/1/meta.jkr");
useTool(ProcessTools.ADB, "shell \"run-as com.unofficial.balatro cat files/save/game/1/meta.jkr > /data/local/tmp/balatro/files/1/meta.jkr\"");
useTool(ProcessTools.ADB, "shell touch /data/local/tmp/balatro/files/1/save.jkr");
useTool(ProcessTools.ADB, "shell \"run-as com.unofficial.balatro cat files/save/game/1/save.jkr > /data/local/tmp/balatro/files/1/save.jkr\"");
useTool(ProcessTools.ADB, "shell touch /data/local/tmp/balatro/files/2/profile.jkr");
useTool(ProcessTools.ADB, "shell \"run-as com.unofficial.balatro cat files/save/game/2/profile.jkr > /data/local/tmp/balatro/files/2/profile.jkr\"");
useTool(ProcessTools.ADB, "shell touch /data/local/tmp/balatro/files/2/meta.jkr");
useTool(ProcessTools.ADB, "shell \"run-as com.unofficial.balatro cat files/save/game/2/meta.jkr > /data/local/tmp/balatro/files/2/meta.jkr\"");
useTool(ProcessTools.ADB, "shell touch /data/local/tmp/balatro/files/2/save.jkr");
useTool(ProcessTools.ADB, "shell \"run-as com.unofficial.balatro cat files/save/game/2/save.jkr > /data/local/tmp/balatro/files/2/save.jkr\"");
useTool(ProcessTools.ADB, "shell touch /data/local/tmp/balatro/files/3/profile.jkr");
useTool(ProcessTools.ADB, "shell \"run-as com.unofficial.balatro cat files/save/game/3/profile.jkr > /data/local/tmp/balatro/files/3/profile.jkr\"");
useTool(ProcessTools.ADB, "shell touch /data/local/tmp/balatro/files/3/meta.jkr");
useTool(ProcessTools.ADB, "shell \"run-as com.unofficial.balatro cat files/save/game/3/meta.jkr > /data/local/tmp/balatro/files/3/meta.jkr\"");
useTool(ProcessTools.ADB, "shell touch /data/local/tmp/balatro/files/3/save.jkr");
useTool(ProcessTools.ADB, "shell \"run-as com.unofficial.balatro cat files/save/game/3/save.jkr > /data/local/tmp/balatro/files/3/save.jkr\"");
useTool(ProcessTools.ADB, "shell find /data/local/tmp/balatro/files/ -maxdepth 2 -size 0c -exec rm '{}' \\;");
useTool(ProcessTools.ADB, "pull /data/local/tmp/balatro/files/. \"" + Platform.getGameSaveLocation() + "\"");

useTool(ProcessTools.ADB, "kill-server");
}
Log("Warning! If Steam Cloud is enabled, it will overwrite the save you transfer!");
while (!AskQuestion("Have you backed up your saves?"))
Log("Please back up your saves! I am not responsible if your saves get deleted!");

PrepareAndroidPlatformTools();

string backupSuffix = "BACKUP";

Log("Backing up your files...");
directoryCopy(Platform.getGameSaveLocation(), Platform.getGameSaveLocation() + backupSuffix);

// tryDelete(Platform.getGameSaveLocation());
System.IO.Directory.CreateDirectory(Platform.getGameSaveLocation());

Log("Attempting to pull save files from Android device.");

//This sure isn't pretty, but it should work!
useTool(ProcessTools.ADB, "shell rm -r /data/local/tmp/balatro");
useTool(ProcessTools.ADB, "shell mkdir -p /data/local/tmp/balatro/files/");

useTool(ProcessTools.ADB, "shell touch /data/local/tmp/balatro/files/settings.jkr");
useTool(ProcessTools.ADB, "shell \"run-as com.unofficial.balatro cat files/save/game/settings.jkr > /data/local/tmp/balatro/files/settings.jkr\"");

useTool(ProcessTools.ADB, "shell mkdir -p /data/local/tmp/balatro/files/1/");
useTool(ProcessTools.ADB, "shell touch /data/local/tmp/balatro/files/1/profile.jkr");
useTool(ProcessTools.ADB, "shell \"run-as com.unofficial.balatro cat files/save/game/1/profile.jkr > /data/local/tmp/balatro/files/1/profile.jkr\"");
useTool(ProcessTools.ADB, "shell touch /data/local/tmp/balatro/files/1/meta.jkr");
useTool(ProcessTools.ADB, "shell \"run-as com.unofficial.balatro cat files/save/game/1/meta.jkr > /data/local/tmp/balatro/files/1/meta.jkr\"");
useTool(ProcessTools.ADB, "shell touch /data/local/tmp/balatro/files/1/save.jkr");
useTool(ProcessTools.ADB, "shell \"run-as com.unofficial.balatro cat files/save/game/1/save.jkr > /data/local/tmp/balatro/files/1/save.jkr\"");

useTool(ProcessTools.ADB, "shell mkdir -p /data/local/tmp/balatro/files/2/");
useTool(ProcessTools.ADB, "shell touch /data/local/tmp/balatro/files/2/profile.jkr");
useTool(ProcessTools.ADB, "shell \"run-as com.unofficial.balatro cat files/save/game/2/profile.jkr > /data/local/tmp/balatro/files/2/profile.jkr\"");
useTool(ProcessTools.ADB, "shell touch /data/local/tmp/balatro/files/2/meta.jkr");
useTool(ProcessTools.ADB, "shell \"run-as com.unofficial.balatro cat files/save/game/2/meta.jkr > /data/local/tmp/balatro/files/2/meta.jkr\"");
useTool(ProcessTools.ADB, "shell touch /data/local/tmp/balatro/files/2/save.jkr");
useTool(ProcessTools.ADB, "shell \"run-as com.unofficial.balatro cat files/save/game/2/save.jkr > /data/local/tmp/balatro/files/2/save.jkr\"");

useTool(ProcessTools.ADB, "shell mkdir -p /data/local/tmp/balatro/files/3/");
useTool(ProcessTools.ADB, "shell touch /data/local/tmp/balatro/files/3/profile.jkr");
useTool(ProcessTools.ADB, "shell \"run-as com.unofficial.balatro cat files/save/game/3/profile.jkr > /data/local/tmp/balatro/files/3/profile.jkr\"");
useTool(ProcessTools.ADB, "shell touch /data/local/tmp/balatro/files/3/meta.jkr");
useTool(ProcessTools.ADB, "shell \"run-as com.unofficial.balatro cat files/save/game/3/meta.jkr > /data/local/tmp/balatro/files/3/meta.jkr\"");
useTool(ProcessTools.ADB, "shell touch /data/local/tmp/balatro/files/3/save.jkr");
useTool(ProcessTools.ADB, "shell \"run-as com.unofficial.balatro cat files/save/game/3/save.jkr > /data/local/tmp/balatro/files/3/save.jkr\"");

useTool(ProcessTools.ADB, "shell find /data/local/tmp/balatro/files/ -maxdepth 2 -size 0c -exec rm '{}' \\;");
useTool(ProcessTools.ADB, "pull /data/local/tmp/balatro/files/. \"" + Platform.getGameSaveLocation() + "\"");
}
#endregion
#endregion
Expand Down Expand Up @@ -397,14 +392,19 @@ void PrepareAndroidPlatformTools()
Log("Platform tools not found...");

if (!fileExists("platform-tools.zip"))
TryDownloadFile("platform-tools", PlatformToolsLink, "platform-tools.zip");
TryDownloadFile("platform-tools", Platform.getPlatformToolsDownloadLink(), "platform-tools.zip");

Log("Extracting platform-tools...");
extractZip("platform-tools.zip", "platform-tools");
}

//Prompt user
while (!AskQuestion("Is your Android device connected to the host with USB Debugging enabled?"))
Log("Please enable USB Debugging on your Android device, and connect it to the host.");
while(true)
{
Process p = Platform.useADB("shell whoami > /dev/null", true);
if (p.ExitCode == 0)
break;
Console.WriteLine("Android device not found. Please enable USB Debugging on your Android device, connect it to the host and press enter...");
Console.ReadLine();
}
}
}