Skip to content

Commit

Permalink
portmaster-patches
Browse files Browse the repository at this point in the history
  • Loading branch information
antipatico committed Apr 18, 2024
1 parent 7b4b556 commit 775b67e
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 51 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.jar filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.xcf filter=lfs diff=lfs merge=lfs -text
*.tty filter=lfs diff=lfs merge=lfs -text
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Create a mobile version of Balatro from the Windows base version of the game.

Python fork of [balatro-apk-maker](https://github.com/blake502/balatro-apk-maker) by [blake502](https://github.com/blake502) and friends. Compared to the original one, it is *NIX friendly, more modular, has patch versioning and does not need to download tools from the internet.
Python rewrite of [balatro-apk-maker](https://github.com/blake502/balatro-apk-maker) by [blake502](https://github.com/blake502) and friends. Compared to the original one, it is *NIX friendly, more modular, has patch versioning and does not try to download and install tools from the internet.

As of today, it only supports Android, but estending it to iOS should be trivial.

Expand Down Expand Up @@ -46,14 +46,18 @@ A refactor is needed to make the version system make sense.
You can list the available patches using the `list-patches` command:
```
$ balatromobile list-patches
Name Description Platforms
---------------- ----------------------------------------------------------------------------------------------- -----------
basic Basic set of patches needed to make the game run on mobile android
landscape Forces the game to always stay in landscape mode, ignoring the screeen orentation of the device android,ios
landscape-hidpi Forces the game to always stay in landscape mode and apply hidpi fix for iOS ios
crt Disable CRT effect [Fixes blackscreen bug on Pixels and other devices] android,ios
fps Cap the FPS limit to the FPS limit of the screen android,ios
external-storage Save game files under /sdcard/Android [Works well for Android < 13] android
Name Description Platforms
------------------------- ----------------------------------------------------------------------------------------------- -----------
basic Basic set of patches needed to make the game run on mobile android
landscape Forces the game to always stay in landscape mode, ignoring the screeen orentation of the device android,ios
landscape-hidpi Forces the game to always stay in landscape mode and apply hidpi fix for iOS ios
crt Disable CRT effect [Fixes blackscreen bug on Pixels and other devices] android,ios
fps Cap the FPS limit to the FPS limit of the screen android,ios
external-storage Save game files under /sdcard/Android [Works well for Android < 13] android
portmaster-simple-fx Disable gameplay visible behind menu background, shadows, and bloom effects. From PortMaster android,ios
portmaster-no-background Disable background animations and effects. From PortMaster android,ios
portmaster-square-display Optimize for square and square-like displays. From PortMaster android,ios
portmaster-nunito-font Replace the main font used with nunito, optimized for smaller displays. From PortMaster android,ios
```
It is possible to specify the list of patches you want to apply by supplying a comma-separated list of patches, for example:
```bash
Expand Down Expand Up @@ -93,4 +97,6 @@ I worked on a [patch of GameActivity.java](https://gist.github.com/antipatico/73
Do you have any suggestion? Open an issue / PR!

## Credits
This software is a rewrite of [balatro-apk-maker](https://github.com/blake502/balatro-apk-maker). It uses [APKEditor](https://github.com/REAndroid/APKEditor), [Uber Apk Signer](https://github.com/patrickfav/uber-apk-signer) and [Love Android](https://github.com/love2d/love-android).
This software is a rewrite of [balatro-apk-maker](https://github.com/blake502/balatro-apk-maker). It uses [APKEditor](https://github.com/REAndroid/APKEditor), [Uber Apk Signer](https://github.com/patrickfav/uber-apk-signer), [Love Android](https://github.com/love2d/love-android) and [Nunito Font](https://fonts.google.com/specimen/Nunito). Moreover, some patches were ported from [nkaHong's fork of PortMaster](https://github.com/nkahoang/PortMaster-nkaHoang).

Thanks for everybody contributing to this project.
2 changes: 1 addition & 1 deletion balatromobile/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__="0.1.1"
__version__="0.2.0"
3 changes: 3 additions & 0 deletions balatromobile/artifacts/nunito-font.tty
Git LFS file not shown
33 changes: 17 additions & 16 deletions balatromobile/patcher.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import base64
import tomllib
from pathlib import Path
from argparse import Namespace
from hashlib import sha256
from .resources import get_patch
from .resources import get_patch, get_artifact

DEFAULT_PATCHES = "basic,landscape,crt,fps"

Expand All @@ -12,11 +10,10 @@ class Patch:
def __init__(self, patch: dict):
self.target_file = patch["target_file"]
self.hashes = patch["supported_hashes"]
self.search_string = patch["search_string"]
self.content = patch["patch_content"]
self.binary_replace = None
if "binary_replace" in patch:
self.binary_replace = patch["binary_replace"]
self.search_string = patch.get("search_string", None)
self.content = patch.get("patch_content", None)
artifact_name = patch.get("artifact", None)
self.artifact = get_artifact(artifact_name) if artifact_name is not None else None

def check_checksum(self, balatro: Path):
target = balatro / Path(self.target_file)
Expand All @@ -29,8 +26,8 @@ def check_checksum(self, balatro: Path):

def apply(self, balatro: Path):
target = balatro / Path(self.target_file)
if self.binary_replace:
target.write_bytes(base64.b64decode(self.binary_replace))
if self.artifact is not None:
target.write_bytes(self.artifact.read_bytes())
return
patched = "\n".join([l if self.search_string not in l else self.content for l in target.read_text().splitlines()])
target.write_text(patched)
Expand Down Expand Up @@ -90,12 +87,16 @@ def all_patches() -> list[PatchFile]:
PatchFile("crt.toml"),
PatchFile("fps.toml"),
PatchFile("external-storage.toml"),
PatchFile("simple-fx.toml"),
PatchFile("no-background.toml"),
PatchFile("square-display.toml"),
PatchFile("nunito-font.toml"),
PatchFile("portmaster-simple-fx.toml"),
PatchFile("portmaster-no-background.toml"),
PatchFile("portmaster-square-display.toml"),
PatchFile("portmaster-nunito-font.toml"),
]

def select_patches(patches: str) -> list[PatchFile]:
patches = patches.split(",")
return list(filter(lambda p: p.name in patches, all_patches()))
desired_patches = patches.split(",")
patch_files : list[PatchFile] = list(filter(lambda p: p.name in desired_patches, all_patches()))
if len(desired_patches) != len(patch_files):
missing_patches = [p for p in desired_patches if p not in [P.name for P in patch_files]]
raise ValueError(f'One or more patches not found: {",".join(missing_patches)}')
return patch_files
12 changes: 0 additions & 12 deletions balatromobile/patches/nunito-font.toml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "no-background"
description = "Disable background animations and effects."
authors = ["blake502","rancossack"]
name = "portmaster-no-background"
description = "Disable background animations and effects. From PortMaster"
authors = ["nkahoang","rancossack"]
supported_platforms = ["android", "ios"]


Expand Down
11 changes: 11 additions & 0 deletions balatromobile/patches/portmaster-nunito-font.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name = "portmaster-nunito-font"
description = "Replace the main font used with nunito, optimized for smaller displays. From PortMaster"
authors = ["nkahoang", "rancossack"]
supported_platforms = ["android", "ios"]

[[versions.v0]]
target_file = "resources/fonts/m6x11plus.ttf"
supported_hashes = ["skip"]
search_string = "skip"
patch_content = "skip"
artifact = "nunito-font.tty"
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name = "simple-fx"
description = "Disable gameplay visible behind menu background, shadows, and bloom effects."
authors = ["blake502","rancossack"]
name = "portmaster-simple-fx"
description = "Disable gameplay visible behind menu background, shadows, and bloom effects. From PortMaster"
authors = ["nkahoang","rancossack"]
supported_platforms = ["android", "ios"]
# Adapted from https://github.com/nkahoang/PortMaster-nkaHoang


[[versions.v0]]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name = "square-display"
description = "Optimize for square and square-like displays."
authors = ["blake502", "rancossack"]
name = "portmaster-square-display"
description = "Optimize for square and square-like displays. From PortMaster"
authors = ["nkahoang", "rancossack"]
supported_platforms = ["android", "ios"]
# Adapted from https://github.com/nkahoang/PortMaster-nkaHoang


[[versions.v0]]
Expand Down
2 changes: 1 addition & 1 deletion balatromobile/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
def get_resorce(basepath: str | Path, name: str | Path):
with importlib.resources.as_file(importlib.resources.files(__package__)) as f:
res = f / basepath / name
if not res.exists():
if name is None or not res.exists():
raise Exception(f'Missing resource: "{name}" in "{res.absolute()}"')
return res

Expand Down

0 comments on commit 775b67e

Please sign in to comment.