Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
Neos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Neos
Commits
26075736
Commit
26075736
authored
Jul 28, 2024
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix ctos chat
parent
54942b5d
Pipeline
#28741
passed with stages
in 10 minutes and 34 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
2 deletions
+32
-2
src/api/ocgcore/ocgAdapter/ctos/ctosChat.ts
src/api/ocgcore/ocgAdapter/ctos/ctosChat.ts
+2
-2
src/api/ocgcore/ocgAdapter/util.ts
src/api/ocgcore/ocgAdapter/util.ts
+30
-0
No files found.
src/api/ocgcore/ocgAdapter/ctos/ctosChat.ts
View file @
26075736
import
{
ygopro
}
from
"
../../idl/ocgcore
"
;
import
{
YgoProPacket
}
from
"
../packet
"
;
import
{
CTOS_CHAT
}
from
"
../protoDecl
"
;
import
{
strEncodeUTF16
}
from
"
../util
"
;
import
{
strEncodeUTF16
Fixed
}
from
"
../util
"
;
/*
* CTOS Chat
...
...
@@ -12,7 +12,7 @@ import { strEncodeUTF16 } from "../util";
export
default
class
CtosChat
extends
YgoProPacket
{
constructor
(
pb
:
ygopro
.
YgoCtosMsg
)
{
const
message
=
pb
.
ctos_chat
.
message
;
const
exData
=
strEncodeUTF16
(
message
);
const
exData
=
strEncodeUTF16
Fixed
(
message
);
super
(
exData
.
length
+
1
,
CTOS_CHAT
,
exData
);
}
...
...
src/api/ocgcore/ocgAdapter/util.ts
View file @
26075736
...
...
@@ -61,6 +61,36 @@ export function strEncodeUTF16(str: string) {
return
new
Uint8Array
(
buf
);
}
/* 不定长的`utf8`到`utf16`转换 */
export
function
strEncodeUTF16Fixed
(
str
:
string
):
Uint8Array
{
const
utf16Array
:
number
[]
=
[];
for
(
let
i
=
0
;
i
<
str
.
length
;
i
++
)
{
const
codePoint
=
str
.
codePointAt
(
i
)
!
;
if
(
codePoint
>
0xffff
)
{
// Handle surrogate pairs
utf16Array
.
push
(((
codePoint
-
0x10000
)
>>
10
)
+
0xd800
);
utf16Array
.
push
(((
codePoint
-
0x10000
)
&
0x3ff
)
+
0xdc00
);
i
++
;
// Skip the next code unit in the surrogate pair
}
else
{
// Handle BMP code units
utf16Array
.
push
(
codePoint
);
}
}
// Convert to Uint8Array
//
// Must ended with zero because `ygopro` require this.
const
byteArray
=
new
Uint8Array
((
utf16Array
.
length
+
1
)
*
2
);
for
(
let
i
=
0
;
i
<
utf16Array
.
length
;
i
++
)
{
byteArray
[
i
*
2
]
=
utf16Array
[
i
]
&
0xff
;
// Low byte
byteArray
[
i
*
2
+
1
]
=
(
utf16Array
[
i
]
>>
8
)
&
0xff
;
// High byte
}
return
byteArray
;
}
// currently not used, but remain.
export
function
utf8ArrayToStr
(
array
:
Uint8Array
)
{
let
out
,
i
,
len
,
c
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment