Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
W
windbot
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
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
nanahira
windbot
Commits
674785f1
Commit
674785f1
authored
Jun 21, 2025
by
mercury233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add WriteUnicodeAutoLength, update WriteUnicode
parent
8e4d611a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
4 deletions
+28
-4
Game/GameClient.cs
Game/GameClient.cs
+1
-2
YGOSharp.Network/Utils/BinaryExtensions.cs
YGOSharp.Network/Utils/BinaryExtensions.cs
+27
-2
No files found.
Game/GameClient.cs
View file @
674785f1
...
...
@@ -84,9 +84,8 @@ namespace WindBot.Game
public
void
Chat
(
string
message
)
{
byte
[]
content
=
Encoding
.
Unicode
.
GetBytes
(
message
+
"\0"
);
BinaryWriter
chat
=
GamePacketFactory
.
Create
(
CtosMessage
.
Chat
);
chat
.
Write
(
content
);
chat
.
Write
UnicodeAutoLength
(
message
,
255
);
Connection
.
Send
(
chat
);
}
...
...
YGOSharp.Network/Utils/BinaryExtensions.cs
View file @
674785f1
...
...
@@ -6,15 +6,40 @@ namespace YGOSharp.Network.Utils
{
public
static
class
BinaryExtensions
{
// fixed length strings
public
static
void
WriteUnicode
(
this
BinaryWriter
writer
,
string
text
,
int
len
)
{
byte
[]
unicode
=
Encoding
.
Unicode
.
GetBytes
(
text
);
byte
[]
result
=
new
byte
[
len
*
2
];
int
max
=
len
*
2
-
2
;
Array
.
Copy
(
unicode
,
result
,
unicode
.
Length
>
max
?
max
:
unicode
.
Length
);
int
copy
=
unicode
.
Length
;
if
(
unicode
.
Length
>
len
*
2
-
2
)
{
copy
=
len
*
2
-
2
;
#if DEBUG
throw
new
ArgumentException
(
"String '"
+
text
+
"' is too long for fixed length "
+
len
+
"."
);
#endif
}
Array
.
Copy
(
unicode
,
result
,
copy
);
writer
.
Write
(
result
);
}
// variable length strings
public
static
void
WriteUnicodeAutoLength
(
this
BinaryWriter
writer
,
string
text
,
int
maxlen
)
{
byte
[]
result
=
Encoding
.
Unicode
.
GetBytes
(
text
+
"\0"
);
int
len
=
result
.
Length
/
2
;
if
(
len
>
maxlen
)
{
len
=
maxlen
;
result
[
len
*
2
-
2
]
=
0
;
result
[
len
*
2
-
1
]
=
0
;
#if DEBUG
throw
new
ArgumentException
(
"String '"
+
text
+
"' is too long for max length "
+
maxlen
+
"."
);
#endif
}
writer
.
Write
(
result
,
0
,
len
*
2
);
}
public
static
string
ReadUnicode
(
this
BinaryReader
reader
,
int
len
)
{
byte
[]
unicode
=
reader
.
ReadBytes
(
len
*
2
);
...
...
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