From fad711364baec39e832ae198b35caacffabb9bc8 Mon Sep 17 00:00:00 2001 From: duncathan Date: Wed, 18 Dec 2024 15:04:11 -0600 Subject: [PATCH] add patch to read version from file --- .gitignore | 17 ++- caver/patcher.py | 4 +- .../VersionFromFile/version_from_file.txt | 103 ++++++++++++++++++ pre_edited_cs/freeware/Doukutsu.exe | Bin 1515520 -> 1515520 bytes pre_edited_cs/freeware/data/version.txt | 3 + pyproject.toml | 5 +- 6 files changed, 118 insertions(+), 14 deletions(-) create mode 100644 cs-hacks/VersionFromFile/version_from_file.txt create mode 100644 pre_edited_cs/freeware/data/version.txt diff --git a/.gitignore b/.gitignore index 2df8f60..7b29f11 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,6 @@ data/* notes/* -pre_edited_cs/Doukutsu\.exe\.blbkp - -pre_edited_cs/Profile* - -pre_edited_cs/window\.rect - *Copy/ venv/ @@ -17,9 +11,12 @@ dist/ cave_story_randomizer.egg-info/ -*/__pycache__ -caver/version.py +**/__pycache__ -pre_edited_cs/data/Stage/_version.txt +pre_edited_cs/**/Doukutsu\.exe\.blbkp +pre_edited_cs/**/Profile* +pre_edited_cs/**/window\.rect -pre_edited_cs/freeware/window.rect +pre_edited_cs/data/version.txt + +pre_edited_cs/freeware/Doukutsu_backup.exe diff --git a/caver/patcher.py b/caver/patcher.py index a50fab5..ac2055a 100644 --- a/caver/patcher.py +++ b/caver/patcher.py @@ -98,10 +98,10 @@ def patch_files( def ensure_base_files_exist(platform: CSPlatform, output_dir: Path) -> None: internal_copy = pre_edited_cs.get_path() - with internal_copy.joinpath("data", "Stage", "_version.txt").open() as version_file: + with internal_copy.joinpath("data", "version.txt").open() as version_file: latest_version = version_file.readline() - version = output_dir.joinpath("data", "Stage", "_version.txt") + version = output_dir.joinpath("data", "version.txt") current_version = "v0.0.0.0" if version.exists(): with version.open() as version_file: diff --git a/cs-hacks/VersionFromFile/version_from_file.txt b/cs-hacks/VersionFromFile/version_from_file.txt new file mode 100644 index 0000000..41e5ec0 --- /dev/null +++ b/cs-hacks/VersionFromFile/version_from_file.txt @@ -0,0 +1,103 @@ +; Reads version number from data\version.txt +; The file must start with the version string in the format shown at the bottom of this file +; Made by periwinkle + +#define +gDataPath=49E220 +gVersionString=48C2BC +sprintf=481010 +fopen=480FFD +rb=48C28C +fread=480F55 +fclose=480E1B +sscanf=4817E8 +call VirtualProtect=data ff 15 84 c0 48 00 +filePath=[ebp-114] +bufchk=[ebp-10] +tmp=[ebp-c] +oldProtect=[ebp-8] +fp=[ebp-4] +v1=[ebp+8] +v2=[ebp+c] +v3=[ebp+10] +v4=[ebp+14] +#enddefine + +offset 410990 ; GetCompileVersion +push ebp +mov ebp, esp +sub esp, 114 +mov eax, [498B20] +mov bufchk, eax + +; Get path to data\version.txt file +push gDataPath +push :VersionPath ; "%s\version.txt" +lea edx, filePath +push edx +call sprintf +add esp, c + +; Open file +push rb ; "rb" +lea ecx, filePath +push ecx +call fopen +add esp, 8 +test eax, eax +jz :ReadVersion +mov fp, eax + +; Mark gVersionString as read/write (it's normally in a read-only segment) +lea eax, oldProtect +push eax +push 4 ; PAGE_READWRITE +push 40 ; Max size of gVersionString (including null character) +push gVersionString +call VirtualProtect +test eax, eax +jz :CloseFile + +; Read contents of file into gVersionString +push fp + +push 3F ; count (excluding null character) +push 1 ; size +push gVersionString +call fread +add esp, 10 +mov byte [eax+gVersionString], 0 ; Write null terminator + +; Restore previous protection status +lea eax, tmp +push eax +push oldProtect +push 40 +push gVersionString +call VirtualProtect + +:CloseFile +push fp +call fclose +pop ecx + +:ReadVersion +; Parse the version string +push v4 +push v3 +push v2 +push v1 +push :VersionString +push gVersionString +call sscanf +add esp, 18 + +mov ecx, bufchk +call 480DC1 +leave +retn + +:VersionPath +data 25 73 5C 76 65 72 73 69 6F 6E 2E 74 78 74 00 00 ; "%s\version.txt" +:VersionString +data 76 25 64 2E 25 64 2E 25 64 2E 25 64 00 ; "v%d.%d.%d.%d" \ No newline at end of file diff --git a/pre_edited_cs/freeware/Doukutsu.exe b/pre_edited_cs/freeware/Doukutsu.exe index c3314fe66b57702afe9d405e67d862861db14fe0..1405395e31bc3f7b80759f8bf4ec816a0a867f08 100644 GIT binary patch delta 327 zcmZoT5YqreTNo#D)^|Q_d?Uihz_3uE+moTw^+SfjBTt45A1+6R-l=c?{r?~IB9e`r zq4@|;M$aJ+hTdL~Sl|mIuoy?{fs&w3*FU|kKLWB?vK%t@0G0d~Z8_k<0F=@HU-~D@ zK8q17`XYiAWQxGC29O$tUe_-H|4V;lIYc7q0jhuTgPENn@_(tw|5Abfr9A&jIWl5^ zPJtM)k{4uzM7QsU7v(@@Cl9L@$CRZO6=&w>>6KKJFff#tIF*6Xe z05K~NvjH*t_Dn90nx~8m?a$tG05K;Ja{)0o5c2>rFA(zqF+UIs0I?tt3jwh(5Q_k@ L==Nvt#iR@X8EKGP delta 327 zcmXxcy-LGS7zW^z+L|Aui9dC4>LNHecn!jVI0TYF2Ehwxi)%NFl~8K<$k4$H&Y7pe5ANfEQ#bO3*F2nB=*XRPi0Z%0AzP5EB=4pXKa#D4 z68VCTmHnb%%!r@J*F%lCAWKgc`14HM3{4ueGzluO0#&HND#&q5Q!d`5#$diwKm`rf YK!=44.0.0", "setuptools_scm[toml]>=3.4.3"] build-backend = "setuptools.build_meta" [tool.setuptools_scm] -version_file_template = "v{version_tuple[0]}.{version_tuple[1]}.{version_tuple[2]}.{scm_version.distance}\n2019/03/07 - {scm_version.node_date.year:04}/{scm_version.node_date.month:02}/{scm_version.node_date.day:02}\nduncathan_salt" +version_file_template = "v{scm_version.tag}.{scm_version.distance}\n2019/03/07 - {scm_version.node_date.year:04}/{scm_version.node_date.month:02}/{scm_version.node_date.day:02}\nduncathan_salt" local_scheme = "no-local-version" -version_file = "pre_edited_cs/data/Stage/_version.txt" +version_scheme = "no-guess-dev" +version_file = "pre_edited_cs/data/version.txt" [tool.ruff] line-length = 120