Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
inv: add version string
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Apr 26, 2024
1 parent 17f963f commit a62d96f
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 26 deletions.
3 changes: 2 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ if host_machine.system() == 'windows'
endif

exe_sources = [
init,
'src/main_exe.c',
exe_resources,
]

dll_sources = [
init,
'src/decomp/decomp.c',
'src/filesystem.c',
'src/game/box.c',
Expand All @@ -92,6 +92,7 @@ dll_sources = [
'src/game/shell.c',
'src/game/sound.c',
'src/game/text.c',
'src/global/vars.c',
'src/inject_exec.c',
'src/inject_util.c',
'src/lib/winmm.c',
Expand Down
27 changes: 22 additions & 5 deletions src/game/inventory.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#include "game/inventory.h"

#include "game/text.h"
#include "global/const.h"
#include "global/funcs.h"
#include "global/types.h"
#include "global/vars.h"

#define TITLE_RING_OBJECTS 3
#define OPTION_RING_OBJECTS 3

static TEXTSTRING *m_VersionText = NULL;

void __cdecl Inv_Construct(void)
{
S_SetupAboveWater(0);
Expand All @@ -20,13 +27,23 @@ void __cdecl Inv_Construct(void)
g_IsInventoryActive = 1;
g_InventoryChosen = 0;

for (int i = 0; i < 8; i++) {
g_InventoryExtraData[i] = 0;
if (g_InventoryMode == INV_TITLE_MODE) {
g_InvOptionObjectsCount = TITLE_RING_OBJECTS;
if (g_GameFlow.gym_enabled) {
g_InvOptionObjectsCount++;
}
m_VersionText = Text_Create(-20, -18, 0, g_TR2XVersion);
Text_AlignRight(m_VersionText, 1);
Text_AlignBottom(m_VersionText, 1);
Text_SetScale(m_VersionText, PHD_ONE * 0.5, PHD_ONE * 0.5);
} else {
g_InvOptionObjectsCount = OPTION_RING_OBJECTS;
Text_Remove(m_VersionText);
m_VersionText = NULL;
}

g_InvOptionObjectsCount = 3; // TODO: don't hardcode me
if (g_InventoryMode == INV_TITLE_MODE && g_GameFlow.gym_enabled) {
g_InvOptionObjectsCount++;
for (int i = 0; i < 8; i++) {
g_InventoryExtraData[i] = 0;
}

for (int32_t i = 0; i < g_InvMainObjectsCount; i++) {
Expand Down
5 changes: 5 additions & 0 deletions src/global/vars.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "global/vars.h"

#ifndef MESON_BUILD
const char *g_TR2XVersion = "TR2X (non-Docker build)";
#endif
2 changes: 2 additions & 0 deletions src/global/vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "inject_util.h"

// clang-format off

extern const char *g_TR2XVersion;
#define g_IID_IDirectDrawSurface3 (*(GUID*)0x00463150)
#define g_PerspectiveDistance (*(uint32_t*)0x00464060) // = 0x3000000
#define g_PolyDrawRoutines (*((void(__cdecl *(*)[9])(const int16_t *))0x00464068))
Expand Down
9 changes: 5 additions & 4 deletions tools/generate_funcs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Symbol:

@property
def offset_str(self) -> str:
return f'0x{self.offset:08X}'
return f"0x{self.offset:08X}"


@dataclass
Expand Down Expand Up @@ -128,7 +128,7 @@ def make_var_pointer_define(variable: Symbol) -> str:
func_name = match.group("func_name")
args = match.group("args")
if array_def:
return f'#define {func_name} (*(({ret_type}({call_type} *(*){array_def})({args})){variable.offset_str}))'
return f"#define {func_name} (*(({ret_type}({call_type} *(*){array_def})({args})){variable.offset_str}))"
else:
return f"#define {func_name} (*({ret_type}({call_type}**)({args})){variable.offset_str})"

Expand All @@ -148,7 +148,7 @@ def make_var_pointer_define(variable: Symbol) -> str:
array_def = match.group("array_def")
value_def = match.group("value_def")
comment = match.group("comment")
if not array_def and not value_def and comment == 'no-dereferencing':
if not array_def and not value_def and comment == "no-dereferencing":
return f"#define {var_name} (({ret_type}){variable.offset_str})"
if array_def:
return f"#define {var_name} (*({ret_type}(*){array_def}){variable.offset_str})"
Expand All @@ -157,7 +157,7 @@ def make_var_pointer_define(variable: Symbol) -> str:
else:
return f"#define {var_name} (*({ret_type}*){variable.offset_str})"

print('warn: unrecognized signature', variable.signature)
print("warn: unrecognized signature", variable.signature)
return ""


Expand Down Expand Up @@ -187,6 +187,7 @@ def make_vars_h(variables: list[Symbol]) -> None:
'#include "inject_util.h"',
"",
"// clang-format off",
"extern const char *g_TR2XVersion;",
]
footer = ["// clang-format on"]

Expand Down
27 changes: 12 additions & 15 deletions tools/generate_init
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
#!/usr/bin/env python3
import argparse
import io
from pathlib import Path

BODY = """
const char *g_TR2XVersion = "{version}";
"""
from shared.versioning import generate_version

TEMPLATE = """
const char *g_TR2XVersion = "TR2X {version}";
""".lstrip()


def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument("--version-file", type=Path)
parser.add_argument("-o", "--output", type=Path)
return parser.parse_args()


def get_init_c(version: str) -> str:
with io.StringIO() as handle:
print(BODY.format(version=version).lstrip(), file=handle)
return handle.getvalue()
def get_init_c() -> str:
return TEMPLATE.format(version=generate_version())


def update_init_c(output_path: Path, version: str) -> None:
new_text = get_init_c(version=version)
def update_init_c(output_path: Path) -> None:
new_text = get_init_c()
if not output_path.exists() or output_path.read_text() != new_text:
output_path.write_text(new_text)


def main() -> None:
args = parse_args()
if args.version_file and args.version_file.exists():
version = args.version_file.read_text().strip()
if args.output:
update_init_c(output_path=args.output)
else:
version = ""
update_init_c(output_path=args.output, version=version)
print(args.outptu)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion tools/shared/versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ def get_branch_version(branch: str | None) -> str:

def generate_version() -> str:
version = get_branch_version(None)
return f'TR2X {version or "?"}'
return version or "?"

0 comments on commit a62d96f

Please sign in to comment.