-
Notifications
You must be signed in to change notification settings - Fork 1
Patcher improvements #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| { | ||
| "target_folder_path": "FA-Binary-Patches", | ||
| "input_exe_path": "ForgedAlliance_base.exe", | ||
| "output_exe_path": "C:\\ProgramData\\FAForever\\bin\\ForgedAlliance_exxt.exe", | ||
| "clang": "clang++.exe", | ||
| "gcc": "g++.exe", | ||
| "linker": "ld.exe", | ||
| "clang_flags": [ | ||
| "-pipe", | ||
| "-m32", | ||
| "-O3", | ||
| "-nostdlib", | ||
| "-Werror", | ||
| "-masm=intel", | ||
| "-std=c++20", | ||
| "-march=core2" | ||
| ], | ||
| "gcc_flags": [ | ||
| "-pipe", | ||
| "-m32", | ||
| "-Os", | ||
| "-fno-exceptions", | ||
| "-nostdlib", | ||
| "-nostartfiles", | ||
| "-fpermissive", | ||
| "-masm=intel", | ||
| "-std=c++20", | ||
| "-march=core2", | ||
| "-mfpmath=both" | ||
| ], | ||
| "asm_flags": [ | ||
| "-pipe", | ||
| "-m32", | ||
| "-Os", | ||
| "-fno-exceptions", | ||
| "-nostdlib", | ||
| "-nostartfiles", | ||
| "-w", | ||
| "-fpermissive", | ||
| "-masm=intel", | ||
| "-std=c++20", | ||
| "-march=core2", | ||
| "-mfpmath=both" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,6 @@ | |
|
|
||
| if __name__ == "__main__": | ||
| start = time.time() | ||
| patcher.patch(*sys.argv) | ||
| patcher.patch(*sys.argv[1:]) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Argument unpacking may cause errors with the new single-argument signature. The The pipeline failure shows the old invocation style being used: Proposed fix - accept only the first argument if __name__ == "__main__":
start = time.time()
- patcher.patch(*sys.argv[1:])
+ if len(sys.argv) < 2:
+ print("Usage: python main.py <config_path>")
+ sys.exit(1)
+ patcher.patch(sys.argv[1])
end = time.time()
print(f"Patched in {end-start:.2f}s")🤖 Prompt for AI Agents |
||
| end = time.time() | ||
| print(f"Patched in {end-start:.2f}s") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import json | ||
| from pathlib import Path | ||
| from dataclasses import dataclass, field | ||
| from typing import Self | ||
|
|
||
|
|
||
| @dataclass | ||
| class Config: | ||
| path: Path | ||
| target_folder_path: Path | ||
| build_folder_path: Path | ||
| input_exe_path: Path = "ForgedAlliance_base.exe" | ||
| output_exe_path: Path = "ForgedAlliance_exxt.exe" | ||
|
|
||
| clang_path: Path = "clang++" | ||
| gcc_path: Path = "g++" | ||
| linker_path: Path = "ld" | ||
|
|
||
| clang_flags: tuple[str] = () | ||
| gcc_flags: tuple[str] = () | ||
| asm_flags: tuple[str] = () | ||
|
|
||
| @classmethod | ||
| def load_from_json(cls, path: Path) -> Self: | ||
| path = Path(path).resolve() | ||
| with open(path, 'r') as f: | ||
| config = json.load(f) | ||
|
|
||
| return cls( | ||
| path=path, | ||
| target_folder_path=config.get("target_folder_path", path.parent), | ||
| build_folder_path=config.get("build_folder_path"), | ||
| input_exe_path=config.get("input_exe_path", Config.input_exe_path), | ||
| output_exe_path=config.get( | ||
| "output_exe_path", Config.output_exe_path), | ||
| clang_path=config.get("clang", Config.clang_path), | ||
| gcc_path=config.get("gcc", Config.gcc_path), | ||
| linker_path=config.get("linker", Config.linker_path), | ||
| clang_flags=config.get("clang_flags", Config.clang_flags), | ||
| gcc_flags=config.get("gcc_flags", Config.gcc_flags), | ||
| asm_flags=config.get("asm_flags", Config.asm_flags), | ||
| ) | ||
|
|
||
| def __post_init__(self): | ||
| self.target_folder_path = Path(self.target_folder_path) | ||
| self.input_exe_path = Path(self.input_exe_path) | ||
| self.output_exe_path = Path(self.output_exe_path) | ||
|
|
||
| if not self.target_folder_path.is_absolute(): | ||
| self.target_folder_path = self.path.parent / self.target_folder_path | ||
|
|
||
| self.build_folder_path = Path(self.build_folder_path)\ | ||
| if self.build_folder_path \ | ||
| else self.target_folder_path / "build" | ||
|
|
||
| self.clang_path = Path(self.clang_path) | ||
| self.gcc_path = Path(self.gcc_path) | ||
| self.linker_path = Path(self.linker_path) | ||
|
|
||
| if not self.build_folder_path.is_absolute(): | ||
| raise ValueError( | ||
| "build_folder_path must be an absolute path to folder") | ||
|
|
||
| @property | ||
| def input_path(self) -> Path: | ||
| if self.input_exe_path.is_absolute(): | ||
| return self.input_exe_path | ||
| return self.target_folder_path / self.input_exe_path | ||
|
|
||
| @property | ||
| def output_path(self) -> Path: | ||
| if self.output_exe_path.is_absolute(): | ||
| return self.output_exe_path | ||
| return self.build_folder_path / self.output_exe_path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON example contains invalid syntax that will cause parse errors.
The JSON example includes
//comments and a trailing comma (line 71), both of which are invalid JSON syntax. Users copying this example will encounter parse errors.Consider either:
Suggested fix - use jsonc identifier
🤖 Prompt for AI Agents