Skip to content

Commit 109acff

Browse files
committed
Update style guide and DLL C stubs to follow new format
1 parent d2d1447 commit 109acff

3 files changed

Lines changed: 246 additions & 105 deletions

File tree

dino.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,14 @@ def setup(self):
433433
print()
434434
print(f"Done! Run '{self.__get_invoked_as()} build' to build the ROM.")
435435

436-
def setup_dll(self, number: int, dll_dir: str):
436+
def setup_dll(self, number: int, file: str, prefix: str | None):
437+
filepath = Path(file)
438+
if len(filepath.suffix) == 0:
439+
print(f"Filepath option must be a path to a C file.")
440+
sys.exit(1)
441+
dll_dir = filepath.parent.as_posix()
442+
filename = filepath.name
443+
437444
dlls_txt_path = SRC_PATH.joinpath("dlls/dlls.txt")
438445
assert dlls_txt_path.exists(), f"Missing dlls.txt file at {dlls_txt_path.absolute()}"
439446

@@ -466,7 +473,7 @@ def setup_dll(self, number: int, dll_dir: str):
466473

467474
# Extract DLL
468475
print("Extracting DLL...")
469-
self.__extract_dlls([number], quiet=True)
476+
self.__setup_dll(number, filename, prefix)
470477

471478
# Re-configure build script
472479
self.configure()
@@ -555,9 +562,30 @@ def __extract_dlls(self, dlls: "list[str | int]"=[], quiet: bool=False, disassem
555562
if disassemble_all:
556563
args.append("--disassemble-all")
557564

565+
args.append("split")
558566
args.extend([str(dll) for dll in dlls])
559567

560568
self.__run_cmd(args)
569+
570+
def __setup_dll(self, dll: str | int, filename: str, prefix: str | None):
571+
args = [
572+
sys.executable, str(DLL_SPLIT_PY),
573+
"--base-dir", str(SCRIPT_DIR),
574+
"--quiet"
575+
]
576+
577+
if self.verbose:
578+
args.append("--verbose")
579+
580+
args.extend([
581+
"split-single", str(dll),
582+
"--filename", filename
583+
])
584+
585+
if prefix != None:
586+
args.extend(["--prefix", prefix])
587+
588+
self.__run_cmd(args)
561589

562590
def __get_invoked_as(self):
563591
invoked_as = sys.argv[0]
@@ -577,7 +605,8 @@ def main():
577605

578606
setup_dll_cmd = subparsers.add_parser("setup-dll", help="Set up a new environment for decomping a DLL.")
579607
setup_dll_cmd.add_argument("number", type=int, help="The number of the DLL.")
580-
setup_dll_cmd.add_argument("dir", type=str, help="Directory name to set up the DLL under.")
608+
setup_dll_cmd.add_argument("file", type=str, help="Path to the DLL C file.")
609+
setup_dll_cmd.add_argument("--prefix", type=str, help="Function prefix.")
581610

582611
extract_cmd = subparsers.add_parser("extract", help="Split ROM and extract DLLs.")
583612
extract_cmd.add_argument("--use-cache", action="store_true", dest="use_cache", help="Only split changed segments in splat config.", default=False)
@@ -631,7 +660,7 @@ def main():
631660
if cmd == "setup":
632661
runner.setup()
633662
elif cmd == "setup-dll":
634-
runner.setup_dll(number=args.number, dll_dir=args.dir)
663+
runner.setup_dll(number=args.number, file=args.file, prefix=args.prefix)
635664
elif cmd == "extract":
636665
runner.extract(core_only=False, use_cache=args.use_cache, disassemble_all=args.disassemble_all)
637666
elif cmd == "extract-core":

docs/StyleGuide.md

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
The Dinosaur Planet decompilation style guide.
44

5+
For cases not covered by this guide, prefer the existing style currently used throughout the codebase.
6+
57
- [Naming](#naming)
6-
- [Global Functions (core code)](#global-functions-core-code)
7-
- [Global Functions (DLL code)](#global-functions-dll-code)
8-
- [Static Functions](#static-functions)
8+
- [Functions (core code)](#functions-core-code)
9+
- [Functions (DLL code)](#functions-dll-code)
910
- [Variables](#variables)
1011
- [Types](#types)
1112
- [Macros/Defines](#macrosdefines)
@@ -15,7 +16,7 @@ The Dinosaur Planet decompilation style guide.
1516

1617
## Naming
1718

18-
### Global Functions (core code)
19+
### Functions (core code)
1920

2021
`camelCase` with a prefix. The prefix should be short and identify the subsystem/file.
2122

@@ -24,34 +25,34 @@ Examples:
2425
- `texLoadTexture`
2526
- `mainGetBits`
2627

27-
Official function names and prefixes should be used where possible. These will be in the same style. If an official name is particularly confusing, a custom name may be used instead.
28+
Official function names and prefixes should be used where possible. For global functions these will be in the same style. If an official name is particularly confusing, a custom name may be used instead.
29+
30+
Note that **static** functions should also start with a prefix, **except** for:
31+
- Library code (use the official function names regardless of format).
32+
- Functions where the official name is known (if the official name is not particularly unique, a custom prefixed name may be used instead.)
2833

29-
### Global Functions (DLL code)
34+
### Functions (DLL code)
3035

31-
Exports:
32-
`<prefix>[_subPrefix]_<FuncName>` where:
33-
- `prefix` - A (generally) `camelCase` prefix that represents the name of the DLL (this is similar to core code global functions). Example: `amSfx`.
36+
**Exports:** `<prefix>[_subPrefix]_<FuncName>` where:
37+
- `prefix` - A prefix that represents the name of the DLL (this is similar to core code global functions). Example: `amSfx`. May be `PascalCase`.
3438
- `_subPrefix`- For exports that implement a nested interface (i.e. a more generic interface not specific to that DLL), the sub prefix is a `camelCase` prefix identifying that interface. Examples: `_obj`, `_vehicle`.
3539
- `FuncName` - The rest of the function name in `PascalCase`.
3640
- Examples:
37-
- `amSfx_Play` (self interface)
38-
- `BWlog_obj_Setup` (object interface)
39-
- `BWlog_vehicle_GetRacePosition` (vehicle interface)
41+
- `amSfx_Play` (own interface)
42+
- `BWlog_obj_Setup` (generic object interface)
43+
- `BWlog_vehicle_GetRacePosition` (generic vehicle interface)
4044

41-
Constructors/destructors:
42-
`<prefix>_<ctor or dtor>`.
45+
**Constructors/destructors:** `<prefix>_<ctor or dtor>`.
4346
- `prefix` - The same prefix used by exports.
4447
- Examples: `amSfx_ctor`, `amSfx_dtor`.
4548

46-
Global DLL functions are special as they represent DLL constructors, destructors, and exports. Export functions implement a DLL interface and as such the name of the interface should be included in the function name. In cases where an export implements a nested interface, an identifier for that interface is also included.
47-
48-
Official function names should be adapted to this format where possible. For example: `amSfxPlay` (official) -> `amSfx_Play`.
49-
50-
### Static Functions
49+
**Statics:** `<prefix>_<funcName>` where:
50+
- `prefix` - The same prefix used by exports.
51+
- `funcName` - The rest of the function name in `camelCase`. Note that static functions start this segment with a lowercase character and global (export) functions start with an uppercase character.
5152

52-
`camelCase` *without* a prefix. Avoid starting the name with a word that may collide with the prefix of global functions (e.g. don't start a static function name with `obj`).
53+
Global DLL functions are special as they represent DLL constructors, destructors, and exports. Export functions implement a DLL interface and as such the naming convention states which interface is being implemented when relevant (i.e. when not a DLL's own interface).
5354

54-
Note that for core code, it is generally not recommended to mark functions as static even if the function logically should be static. In those cases, the global function naming style should be preferred, unless the official function name is known.
55+
Official function names should be adapted to this format where possible. For example: `amSfxPlay` (official, export) -> `amSfx_Play`.
5556

5657
### Variables
5758

0 commit comments

Comments
 (0)