Skip to content

Commit

Permalink
v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
antipatico committed Apr 18, 2024
1 parent 7b4b556 commit fee7deb
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 28 deletions.
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"
Binary file added balatromobile/artifacts/nunito-font.tty
Binary 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
22 changes: 22 additions & 0 deletions balatromobile/patches/portmaster-no-background.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name = "portmaster-no-background"
description = "Disable background animations and effects. From PortMaster"
authors = ["nkahoang","rancossack"]
supported_platforms = ["android", "ios"]


[[versions.v0]]
target_file = "globals.lua"
supported_hashes = ["skip"]
search_string = "self.DEBUG = false"
patch_content = """
self.DEBUG = false
self.debug_background_toggle = true
"""

[[versions.v0]]
target_file = "game.lua"
supported_hashes = ["skip"]
search_string = "love.graphics.clear({0,1,0,1})"
patch_content = """
love.graphics.clear(mix_colours(G.C.DYN_UI.DARK, {0.17,0.35,0.26,1}, 0.4))
"""
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"
45 changes: 45 additions & 0 deletions balatromobile/patches/portmaster-simple-fx.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name = "portmaster-simple-fx"
description = "Disable gameplay visible behind menu background, shadows, and bloom effects. From PortMaster"
authors = ["nkahoang","rancossack"]
supported_platforms = ["android", "ios"]


[[versions.v0]]
target_file = "globals.lua"
supported_hashes = ["skip"]
search_string = "bloom = 1"
patch_content = """
bloom = 0,
"""

[[versions.v0]]
target_file = "globals.lua"
supported_hashes = ["skip"]
search_string = "shadows = 'On'"
patch_content = """
shadows = 'Off',
"""

[[versions.v0]]
target_file = "globals.lua"
supported_hashes = ["skip"]
search_string = "self.F_HIDE_BG = false"
patch_content = """
self.F_HIDE_BG = true
"""

[[versions.v0]]
target_file = "globals.lua"
supported_hashes = ["skip"]
search_string = "self.TILE_W = self.F_MOBILE_UI and 11.5 or 20"
patch_content = """
self.TILE_W = 20
"""

[[versions.v0]]
target_file = "globals.lua"
supported_hashes = ["skip"]
search_string = "self.TILE_H = self.F_MOBILE_UI and 20 or 11.5"
patch_content = """
self.TILE_H = 11.5
"""
49 changes: 49 additions & 0 deletions balatromobile/patches/portmaster-square-display.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name = "portmaster-square-display"
description = "Optimize for square and square-like displays. From PortMaster"
authors = ["nkahoang", "rancossack"]
supported_platforms = ["android", "ios"]


[[versions.v0]]
target_file = "functions/common_events.lua"
supported_hashes = ["skip"]
search_string = "bloom = 1"
patch_content = """"
bloom = 0
"""

# move the hands a bit to the right
[[versions.v0]]
target_file = "functions/common_events.lua"
supported_hashes = ["skip"]
search_string = "G.hand.T.x = G.TILE_W - G.hand.T.w - 2.85"
patch_content = """
G.hand.T.x = G.TILE_W - G.hand.T.w - 1
"""

# then move the playing area up
[[versions.v0]]
target_file = "functions/common_events.lua"
supported_hashes = ["skip"]
search_string = "G.play.T.y = G.hand.T.y - 3.6"
patch_content = """
G.play.T.y = G.hand.T.y - 4.5
"""

# move the decks to the right
[[versions.v0]]
target_file = "functions/common_events.lua"
supported_hashes = ["skip"]
search_string = "G.deck.T.x = G.TILE_W - G.deck.T.w - 0.5"
patch_content = """
G.deck.T.x = G.TILE_W - G.deck.T.w + 0.85
"""

# move the jokers to the left
[[versions.v0]]
target_file = "functions/common_events.lua"
supported_hashes = ["skip"]
search_string = "G.jokers.T.x = G.hand.T.x - 0.1"
patch_content = """
G.jokers.T.x = G.hand.T.x - 0.2
"""
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 fee7deb

Please sign in to comment.