Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
SRB2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
John Peter Sa
SRB2
Commits
834c3257
Commit
834c3257
authored
1 year ago
by
Lactozilla
Browse files
Options
Downloads
Patches
Plain Diff
Add 'CHARNAME' and 'PLAYERNAME' control codes
parent
e8b96f6d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/p_dialog.c
+75
-7
75 additions, 7 deletions
src/p_dialog.c
with
75 additions
and
7 deletions
src/p_dialog.c
+
75
−
7
View file @
834c3257
...
...
@@ -439,9 +439,46 @@ enum
TP_OP_NAME
,
TP_OP_ICON
,
TP_OP_CHARNAME
,
TP_OP_PLAYERNAME
,
TP_OP_CONTROL
=
0xFF
};
static
boolean
ProcessInstruction
(
dialog_t
*
dialog
,
UINT8
**
cptr
,
UINT8
**
buffer
,
size_t
*
buffer_pos
,
size_t
*
buffer_capacity
)
{
UINT8
*
code
=
*
cptr
;
if
(
*
code
++
!=
TP_OP_CONTROL
)
return
false
;
player_t
*
player
=
dialog
->
callplayer
;
switch
(
*
code
)
{
case
TP_OP_CHARNAME
:
{
char
charname
[
256
];
strlcpy
(
charname
,
skins
[
player
->
skin
]
->
realname
,
sizeof
(
charname
));
M_BufferMemWrite
((
UINT8
*
)
charname
,
strlen
(
charname
),
buffer
,
buffer_pos
,
buffer_capacity
);
break
;
}
case
TP_OP_PLAYERNAME
:
{
char
playername
[
256
];
if
(
netgame
)
strlcpy
(
playername
,
player_names
[
player
-
players
],
sizeof
(
playername
));
else
strlcpy
(
playername
,
skins
[
player
->
skin
]
->
realname
,
sizeof
(
playername
));
M_BufferMemWrite
((
UINT8
*
)
playername
,
strlen
(
playername
),
buffer
,
buffer_pos
,
buffer_capacity
);
break
;
}
default:
return
false
;
}
*
cptr
=
code
;
return
true
;
}
static
const
UINT8
*
InterpretBytecode
(
const
UINT8
*
code
,
dialog_t
*
dialog
,
textwriter_t
*
writer
)
{
int
num
=
0
;
...
...
@@ -474,6 +511,10 @@ static const UINT8 *InterpretBytecode(const UINT8 *code, dialog_t *dialog, textw
Z_Free
(
icon
);
}
break
;
case
TP_OP_CHARNAME
:
case
TP_OP_PLAYERNAME
:
// Ignore
break
;
}
}
...
...
@@ -495,6 +536,10 @@ static int SkipBytecode(const UINT8 *code)
UINT8
n
=
*
code
++
;
code
+=
n
;
break
;
case
TP_OP_CHARNAME
:
case
TP_OP_PLAYERNAME
:
// Nothing else to read
break
;
}
}
...
...
@@ -611,13 +656,28 @@ static void P_DialogSetDisplayText(dialog_t *dialog)
V_WordWrapInPlace
(
geo
.
textx
,
geo
.
textr
,
0
,
dialog
->
disptext
);
}
static
char
*
P_ProcessPageText
(
char
*
pagetext
,
size_t
textlength
,
size_t
*
outlength
)
static
char
*
P_ProcessPageText
(
dialog_t
*
dialog
,
UINT8
*
pagetext
,
size_t
textlength
,
size_t
*
outlength
)
{
*
outlength
=
textlength
;
char
*
buf
=
Z_Calloc
(
textlength
+
1
,
PU_STATIC
,
NULL
);
memcpy
(
buf
,
pagetext
,
textlength
);
buf
[
textlength
]
=
'\0'
;
return
buf
;
size_t
buffer_pos
=
0
;
size_t
buffer_capacity
=
0
;
UINT8
*
buf
=
NULL
;
UINT8
*
text
=
pagetext
;
UINT8
*
end
=
pagetext
+
textlength
;
while
(
text
<
end
)
{
if
(
!
ProcessInstruction
(
dialog
,
&
text
,
&
buf
,
&
buffer_pos
,
&
buffer_capacity
))
{
M_StringBufferWrite
(
*
text
,
(
char
**
)
&
buf
,
&
buffer_pos
,
&
buffer_capacity
);
text
++
;
}
}
*
outlength
=
buffer_pos
;
return
(
char
*
)
buf
;
}
void
P_DialogSetText
(
dialog_t
*
dialog
,
char
*
pagetext
,
size_t
textlength
)
...
...
@@ -625,7 +685,7 @@ void P_DialogSetText(dialog_t *dialog, char *pagetext, size_t textlength)
Z_Free
(
dialog
->
pagetext
);
if
(
pagetext
&&
pagetext
[
0
])
dialog
->
pagetext
=
P_ProcessPageText
(
pagetext
,
textlength
,
&
dialog
->
pagetextlength
);
dialog
->
pagetext
=
P_ProcessPageText
(
dialog
,
(
UINT8
*
)
pagetext
,
textlength
,
&
dialog
->
pagetextlength
);
else
{
dialog
->
pagetextlength
=
0
;
...
...
@@ -2237,6 +2297,14 @@ static void InterpretControlCode(char **input, UINT8 **buf, size_t *buffer_pos,
else
EXPECTED_PARAM
(
"ICON"
);
}
else
if
(
MatchControlCode
(
"CHARNAME"
,
input
))
{
WRITE_OP
(
TP_OP_CHARNAME
);
}
else
if
(
MatchControlCode
(
"PLAYERNAME"
,
input
))
{
WRITE_OP
(
TP_OP_PLAYERNAME
);
}
}
static
boolean
InterpretCutsceneControlCode
(
UINT8
chr
,
UINT8
**
buf
,
size_t
*
buffer_pos
,
size_t
*
buffer_capacity
)
...
...
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