Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
kart-records-site
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Rex James
kart-records-site
Commits
dc4fc81c
Commit
dc4fc81c
authored
5 years ago
by
James R.
Browse files
Options
Downloads
Patches
Plain Diff
Update replay format to Kart 1.1
parent
b08fcdb0
No related branches found
No related tags found
1 merge request
!1
Update replay parser to Kart 1.1 demo format
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/Services/ReplayParser.php
+59
-10
59 additions, 10 deletions
app/Services/ReplayParser.php
with
59 additions
and
10 deletions
app/Services/ReplayParser.php
+
59
−
10
View file @
dc4fc81c
...
...
@@ -30,7 +30,7 @@ class ReplayParser
'speed'
=>
$info
[
'kartspeed'
],
'weight'
=>
$info
[
'kartweight'
],
]);
$replay
=
new
Replay
([
'race_tics'
=>
$info
[
'racetime'
],
'lap_tics'
=>
$info
[
'laptime'
],
...
...
@@ -57,12 +57,47 @@ class ReplayParser
return
$checksum
;
}
protected
function
skipFileList
(
string
$p
,
int
$off
)
:
int
{
// PHP sucks and I don't like it.
$total
=
unpack
(
'C'
,
$p
,
$off
)[
1
];
for
(
$off
++
;
$total
--
;)
{
// file name
// Basically memchr to find the terminating byte.
if
((
$n
=
strpos
(
$p
,
"
\0
"
,
$off
)
-
$off
+
1
)
<
64
)
$off
+=
$n
;
else
$off
+=
64
;
$off
+=
16
;
// checksum
}
return
$off
;
}
protected
function
skipNetVars
(
string
$p
,
int
$off
)
:
int
{
$total
=
unpack
(
'v'
,
$p
,
$off
)[
1
];
for
(
$off
+=
2
;
$total
--
;)
{
// netid, string value, and stealth flag.
$off
=
(
strpos
(
$p
,
"
\0
"
,
$off
+
2
)
+
1
)
+
1
;
}
return
$off
;
}
protected
function
parseInfo
(
string
$replayContents
)
:
array
{
return
unpack
(
$this
->
replayFormat
(),
$replayContents
);
$header
=
unpack
(
$this
->
replayHeaderFormat
(),
$replayContents
);
$off
=
$this
->
skipFileList
(
$replayContents
,
120
);
$timing
=
unpack
(
$this
->
replayRecordFormat
(),
$replayContents
,
$off
);
// Skip Record Attack info, random seed and extrainfo offset.
// Also skip demo player number.
$off
=
$this
->
skipNetVars
(
$replayContents
,
$off
+
16
)
+
1
;
$player
=
unpack
(
$this
->
replayPlayerFormat
(),
$replayContents
,
$off
);
return
array_merge
(
$header
,
$timing
,
$player
);
}
protected
function
validateStructure
(
string
$header
,
string
$playString
,
int
$demoFlags
)
:
void
{
if
(
$header
!==
"
\xF0
"
.
'KartReplay'
.
"
\x0F
"
)
{
...
...
@@ -102,7 +137,7 @@ class ReplayParser
}
}
protected
function
replayFormat
()
:
string
protected
function
replay
Header
Format
()
:
string
{
$props
=
[
// Header - should equal "\xF0" "KartReplay" "\x0F"
...
...
@@ -112,6 +147,9 @@ class ReplayParser
'c'
.
'version'
,
'c'
.
'subversion'
,
'v'
.
'demoversion'
,
// Replay title, which we don't actually need.
'a64'
.
'UNUSED'
,
// Checksum
'a16'
.
'checksum'
,
...
...
@@ -127,21 +165,32 @@ class ReplayParser
// Demo flags - This % 6 == 2 or replay is invalid
'c'
.
'demoflags'
,
];
return
implode
(
'/'
,
$props
);
}
protected
function
replayRecordFormat
()
:
string
{
$props
=
[
// Time/lap
'V'
.
'racetime'
,
'V'
.
'laptime'
,
];
return
implode
(
'/'
,
$props
);
}
// Random seed. We don't care about this but it's in the way.
'V'
.
'UNUSED'
,
protected
function
replayPlayerFormat
()
:
string
{
$props
=
[
// Player attributes
'Z16'
.
'name'
,
'Z16'
.
'skin'
,
'Z16'
.
'color'
,
// S
tats that aren'
t rel
eva
nt for us
'
c5
'
.
'UNUSED'
,
// S
core; no
t rel
ave
nt for us
'
V
'
.
'UNUSED'
,
// Kart stats, to differentiate between characters with the same name and different stats.
'c'
.
'kartspeed'
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment