Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro-proxy
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
MyCard
ygopro-proxy
Commits
18ea4825
Commit
18ea4825
authored
Sep 11, 2022
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update transform.go
parent
8029316a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
10 deletions
+55
-10
DarkNeos/transform.go
DarkNeos/transform.go
+55
-10
No files found.
DarkNeos/transform.go
View file @
18ea4825
...
@@ -16,6 +16,32 @@ const (
...
@@ -16,6 +16,32 @@ const (
RawBufToProtobuf
=
2
RawBufToProtobuf
=
2
)
)
const
(
CtosProtoPlayerInfo
=
16
CtosProtoJoinGame
=
18
)
type
YgoPacket
struct
{
PacketLen
uint16
Proto
uint8
Exdata
[]
byte
}
func
packetToBuffer
(
pkt
YgoPacket
)
[]
byte
{
buf
:=
make
([]
byte
,
0
)
// packet len
buf
=
append
(
buf
,
byte
(
pkt
.
PacketLen
),
byte
(
pkt
.
PacketLen
>>
8
))
// proto
buf
=
append
(
buf
,
byte
(
pkt
.
Proto
))
// exdata
for
_
,
v
:=
range
pkt
.
Exdata
{
buf
=
append
(
buf
,
v
)
}
return
buf
}
func
Transform
(
src
[]
byte
,
tranformType
int
)
([]
byte
,
error
)
{
func
Transform
(
src
[]
byte
,
tranformType
int
)
([]
byte
,
error
)
{
if
tranformType
==
ProtobufToRawBuf
{
if
tranformType
==
ProtobufToRawBuf
{
message
:=
&
ygopropb
.
YgoCtosMsg
{}
message
:=
&
ygopropb
.
YgoCtosMsg
{}
...
@@ -24,14 +50,18 @@ func Transform(src []byte, tranformType int) ([]byte, error) {
...
@@ -24,14 +50,18 @@ func Transform(src []byte, tranformType int) ([]byte, error) {
return
nil
,
err
return
nil
,
err
}
}
var
packet
YgoPacket
switch
message
.
Msg
.
(
type
)
{
switch
message
.
Msg
.
(
type
)
{
case
*
(
ygopropb
.
YgoCtosMsg_CtosPlayerInfo
)
:
case
*
(
ygopropb
.
YgoCtosMsg_CtosPlayerInfo
)
:
return
transformPlayerInfo
(
message
.
GetCtosPlayerInfo
()),
nil
packet
=
transformPlayerInfo
(
message
.
GetCtosPlayerInfo
())
case
*
(
ygopropb
.
YgoCtosMsg_CtosJoinGame
)
:
case
*
(
ygopropb
.
YgoCtosMsg_CtosJoinGame
)
:
return
transformJoinGame
(
message
.
GetCtosJoinGame
()),
nil
packet
=
transformJoinGame
(
message
.
GetCtosJoinGame
())
default
:
default
:
return
nil
,
errors
.
New
(
"Unhandled YgoCtosMsg type"
)
return
nil
,
errors
.
New
(
"Unhandled YgoCtosMsg type"
)
}
}
return
packetToBuffer
(
packet
),
nil
}
else
if
tranformType
==
RawBufToProtobuf
{
}
else
if
tranformType
==
RawBufToProtobuf
{
return
nil
,
errors
.
New
(
"Unhandled tranformType"
)
return
nil
,
errors
.
New
(
"Unhandled tranformType"
)
}
else
{
}
else
{
...
@@ -39,25 +69,40 @@ func Transform(src []byte, tranformType int) ([]byte, error) {
...
@@ -39,25 +69,40 @@ func Transform(src []byte, tranformType int) ([]byte, error) {
}
}
}
}
func
transformPlayerInfo
(
pb
*
ygopropb
.
CtosPlayerInfo
)
[]
byte
{
// todo: use interface
// @Name: [uint16, 20]
func
transformPlayerInfo
(
pb
*
ygopropb
.
CtosPlayerInfo
)
YgoPacket
{
buf
:=
strToUtf16Buffer
(
pb
.
Name
)
buf
:=
strToUtf16Buffer
(
pb
.
Name
)
exdata
:=
uint16BufToByteBuf
(
buf
)
return
uint16BufToByteBuf
(
buf
)
return
YgoPacket
{
PacketLen
:
uint16
(
len
(
exdata
))
+
1
,
Proto
:
CtosProtoPlayerInfo
,
Exdata
:
exdata
,
}
}
}
func
transformJoinGame
(
pb
*
ygopropb
.
CtosJoinGame
)
[]
byte
{
// @Version: uint16
buf
:=
make
([]
byte
,
0
)
// @Gameid: uint32
// @Passwd: [uint16, 20]
func
transformJoinGame
(
pb
*
ygopropb
.
CtosJoinGame
)
YgoPacket
{
exdata
:=
make
([]
byte
,
0
)
version
:=
uint16
(
pb
.
Version
)
version
:=
uint16
(
pb
.
Version
)
buf
=
append
(
buf
,
byte
(
version
),
byte
(
pb
.
V
ersion
>>
8
),
0
,
0
)
exdata
=
append
(
exdata
,
byte
(
version
),
byte
(
v
ersion
>>
8
),
0
,
0
)
buf
=
append
(
buf
,
byte
(
pb
.
Gameid
),
byte
(
pb
.
Gameid
>>
8
),
byte
(
pb
.
Gameid
>>
16
),
byte
(
pb
.
Gameid
>>
24
))
exdata
=
append
(
exdata
,
byte
(
pb
.
Gameid
),
byte
(
pb
.
Gameid
>>
8
),
byte
(
pb
.
Gameid
>>
16
),
byte
(
pb
.
Gameid
>>
24
))
for
_
,
v
:=
range
uint16BufToByteBuf
(
strToUtf16Buffer
(
pb
.
Passwd
))
{
for
_
,
v
:=
range
uint16BufToByteBuf
(
strToUtf16Buffer
(
pb
.
Passwd
))
{
buf
=
append
(
buf
,
v
)
exdata
=
append
(
exdata
,
v
)
}
}
return
buf
return
YgoPacket
{
PacketLen
:
uint16
(
len
(
exdata
))
+
1
,
Proto
:
CtosProtoJoinGame
,
Exdata
:
exdata
,
}
}
}
func
strToUtf16Buffer
(
s
string
)
[]
uint16
{
func
strToUtf16Buffer
(
s
string
)
[]
uint16
{
...
...
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