-
Notifications
You must be signed in to change notification settings - Fork 11
Add support for reading TMN ESWC replays #6
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: master
Are you sure you want to change the base?
Changes from 2 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 |
|---|---|---|
|
|
@@ -21,6 +21,18 @@ def event_to_analog_value(event: ControlEntry): | |
| val >>= int32(8) | ||
| return -val | ||
|
|
||
| def clean_duplicate_events(events: list): | ||
| """ | ||
| ESWC events seem a bit janky. Try to get rid of that by removing 'duplicate' | ||
| events. Take the latest one | ||
| """ | ||
| events_cleaned = [] | ||
| for i in range(0, (len(events)-1)): | ||
| if int(events[i+1].time / 10) * 10 != int(events[i].time / 10) * 10: | ||
|
||
| events_cleaned.append(events[i]) | ||
| events_cleaned.append(events[-1]) | ||
| return events_cleaned | ||
|
|
||
| def partition_steer_events(events: list, sample_period: int): | ||
| p = [] | ||
| current = [] | ||
|
|
@@ -56,6 +68,24 @@ def try_parse_old_ghost(g: Gbx): | |
|
|
||
| return None | ||
|
|
||
| def try_parse_nations_eswc_ghost(g: Gbx): | ||
| ghost = CGameCtnGhost(0) | ||
| ghost.login = "" # unavailable in ESWC? | ||
|
|
||
| parser = g.find_raw_chunk_id(0x3f00dff) | ||
| if parser: | ||
| parser.seen_loopback = True | ||
| g.read_ghost_events(ghost, parser, 0x3f00dff) | ||
| return ghost | ||
|
|
||
| parser = g.find_raw_chunk_id(0x3f00dfa) | ||
| if parser: | ||
| parser.seen_loopback = True | ||
| g.read_ghost_events(ghost, parser, 0x3f00dfa) | ||
| return ghost | ||
|
|
||
| return None | ||
|
|
||
| def analyze_replay(path: str): | ||
| try: | ||
| g = Gbx(path) | ||
|
|
@@ -67,16 +97,18 @@ def analyze_replay(path: str): | |
| if not ghosts: | ||
| ghost = try_parse_old_ghost(g) | ||
| if not ghost: | ||
| print('Error: no ghosts') | ||
| return None | ||
| ghost = try_parse_nations_eswc_ghost(g) | ||
| if not ghost: | ||
| print('Error: no ghosts') | ||
| return None | ||
| ghost.control_entries = clean_duplicate_events(ghost.control_entries) | ||
|
|
||
| if not ghost.control_entries: | ||
| print('Error: no control entries') | ||
| return None | ||
| else: | ||
| ghost = ghosts[0] | ||
|
|
||
| ghost = ghosts[0] | ||
| results = {'version': ghost.game_version, 'login': ghost.login, 'max_spikes': 0, 'spikes': 0} | ||
|
|
||
| partitions = partition_steer_events(ghost.control_entries, TIME_PERIOD) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,6 +54,18 @@ def event_to_analog_value(event: ControlEntry): | |
| val >>= int32(8) | ||
| return -val | ||
|
|
||
| def clean_duplicate_events(events: list): | ||
|
||
| """ | ||
| ESWC events seem a bit janky. Try to get rid of that by removing 'duplicate' | ||
| events. Take the latest one | ||
| """ | ||
| events_cleaned = [] | ||
| for i in range(0, (len(events)-1)): | ||
| if int(events[i+1].time / 10) * 10 != int(events[i].time / 10) * 10: | ||
| events_cleaned.append(events[i]) | ||
| events_cleaned.append(events[-1]) | ||
| return events_cleaned | ||
|
|
||
| def try_parse_old_ghost(g: Gbx): | ||
| ghost = CGameCtnGhost(0) | ||
|
|
||
|
|
@@ -69,6 +81,24 @@ def try_parse_old_ghost(g: Gbx): | |
|
|
||
| return None | ||
|
|
||
| def try_parse_nations_eswc_ghost(g: Gbx): | ||
| ghost = CGameCtnGhost(0) | ||
| ghost.login = "" # unavailable in ESWC? | ||
|
|
||
| parser = g.find_raw_chunk_id(0x3f00dff) | ||
| if parser: | ||
| parser.seen_loopback = True | ||
| g.read_ghost_events(ghost, parser, 0x3f00dff) | ||
| return ghost | ||
|
|
||
| parser = g.find_raw_chunk_id(0x3f00dfa) | ||
| if parser: | ||
| parser.seen_loopback = True | ||
| g.read_ghost_events(ghost, parser, 0x3f00dfa) | ||
| return ghost | ||
|
|
||
| return None | ||
|
|
||
| def try_extract_2020(g: Gbx): | ||
| cbp = g.find_raw_chunk_id(0x0309201D) | ||
| if not cbp: | ||
|
|
@@ -181,6 +211,12 @@ def process_path(path, write_func): | |
| ghosts = g.get_classes_by_ids([GbxType.CTN_GHOST, GbxType.CTN_GHOST_OLD]) | ||
| if not ghosts: | ||
| ghost = try_parse_old_ghost(g) | ||
| if not ghost: | ||
| ghost = try_parse_nations_eswc_ghost(g) | ||
| if not ghost: | ||
| print('Error: no ghosts') | ||
| return None | ||
| ghost.control_entries = clean_duplicate_events(ghost.control_entries) | ||
| else: | ||
| ghost = ghosts[0] | ||
|
|
||
|
|
||
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.
Please annotate that this also returns list.
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.
done