Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro
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
REIKAI
ygopro
Commits
f548456a
Commit
f548456a
authored
Aug 09, 2017
by
mercury233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test
parent
8d0c7b3b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
90 deletions
+73
-90
gframe/replay.cpp
gframe/replay.cpp
+73
-90
No files found.
gframe/replay.cpp
View file @
f548456a
...
...
@@ -3,7 +3,6 @@
#include "../ocgcore/card.h"
#include <algorithm>
#include "lzma/LzmaLib.h"
#include <sstream>
namespace
ygo
{
...
...
@@ -20,157 +19,141 @@ Replay::~Replay() {
delete
[]
replay_data
;
delete
[]
comp_data
;
}
std
::
wstring
SA2W
(
std
::
string
&
strA
)
{
setlocale
(
LC_ALL
,
"chs"
);
const
char
*
_Source
=
strA
.
c_str
();
size_t
_Dsize
=
strA
.
size
()
+
1
;
wchar_t
*
_Dest
=
new
wchar_t
[
_Dsize
];
wmemset
(
_Dest
,
0
,
_Dsize
);
mbstowcs
(
_Dest
,
_Source
,
_Dsize
);
std
::
wstring
result
=
_Dest
;
delete
[]
_Dest
;
setlocale
(
LC_ALL
,
"C"
);
return
result
;
}
void
Replay
::
BeginRecord
()
{
if
(
ygo
::
replay_mode
>
0
)
{
#ifdef YGOPRO_SERVER_MODE
if
(
ygo
::
replay_mode
==
0
)
return
;
#endif //YGOPRO_SERVER_MODE
#ifdef _WIN32
if
(
is_recording
)
CloseHandle
(
recording_fp
);
std
::
stringstream
ss
;
ss
<<
ygo
::
aServerPort
;
std
::
string
ssss
;
ssss
=
ss
.
str
();
std
::
wstring
comPrefix
=
L"./replay/"
;
std
::
wstring
comID
=
comPrefix
+
SA2W
(
ssss
)
+
L"Replay.yrp"
;
recording_fp
=
CreateFileW
(
comID
.
c_str
(),
GENERIC_WRITE
,
0
,
NULL
,
CREATE_ALWAYS
,
FILE_FLAG_WRITE_THROUGH
,
NULL
);
if
(
recording_fp
==
INVALID_HANDLE_VALUE
)
return
;
if
(
is_recording
)
CloseHandle
(
recording_fp
);
time_t
nowtime
=
time
(
NULL
);
struct
tm
*
localedtime
=
localtime
(
&
nowtime
);
wchar_t
tmppath
[
80
];
wcsftime
(
tmppath
,
80
,
"./replay/%Y-%m-%d %H-%M-%S %%u.yrp"
,
localedtime
);
wchar_t
path
[
80
];
myswprintf
(
path
,
tmppath
,
ygo
::
aServerPort
);
recording_fp
=
CreateFileW
(
path
,
GENERIC_WRITE
,
0
,
NULL
,
CREATE_ALWAYS
,
FILE_FLAG_WRITE_THROUGH
,
NULL
);
if
(
recording_fp
==
INVALID_HANDLE_VALUE
)
return
;
#else
if
(
is_recording
)
fclose
(
fp
);
time_t
nowtime
=
time
(
NULL
);
struct
tm
*
localedtime
=
localtime
(
&
nowtime
);
char
tmppath
[
40
];
strftime
(
tmppath
,
40
,
"./replay/%Y-%m-%d %H-%M-%S %%u.yrp"
,
localedtime
);
char
path
[
40
];
sprintf
(
path
,
tmppath
,
ygo
::
aServerPort
);
fp
=
fopen
(
path
,
"wb"
);
if
(
!
fp
)
return
;
if
(
is_recording
)
fclose
(
fp
);
time_t
nowtime
=
time
(
NULL
);
struct
tm
*
localedtime
=
localtime
(
&
nowtime
);
char
tmppath
[
40
];
strftime
(
tmppath
,
40
,
"./replay/%Y-%m-%d %H-%M-%S %%u.yrp"
,
localedtime
);
char
path
[
40
];
sprintf
(
path
,
tmppath
,
ygo
::
aServerPort
);
fp
=
fopen
(
path
,
"wb"
);
if
(
!
fp
)
return
;
#endif
}
pdata
=
replay_data
;
is_recording
=
true
;
}
void
Replay
::
WriteHeader
(
ReplayHeader
&
header
)
{
pheader
=
header
;
if
(
ygo
::
replay_mode
>
0
)
{
#ifdef YGOPRO_SERVER_MODE
if
(
ygo
::
replay_mode
==
0
)
return
;
#endif //YGOPRO_SERVER_MODE
#ifdef _WIN32
DWORD
size
;
WriteFile
(
recording_fp
,
&
header
,
sizeof
(
header
),
&
size
,
NULL
);
DWORD
size
;
WriteFile
(
recording_fp
,
&
header
,
sizeof
(
header
),
&
size
,
NULL
);
#else
fwrite
(
&
header
,
sizeof
(
header
),
1
,
fp
);
fflush
(
fp
);
fwrite
(
&
header
,
sizeof
(
header
),
1
,
fp
);
fflush
(
fp
);
#endif
}
}
void
Replay
::
WriteData
(
const
void
*
data
,
unsigned
int
length
,
bool
flush
)
{
if
(
!
is_recording
)
return
;
memcpy
(
pdata
,
data
,
length
);
pdata
+=
length
;
if
(
ygo
::
replay_mode
>
0
)
{
#ifdef YGOPRO_SERVER_MODE
if
(
ygo
::
replay_mode
==
0
)
return
;
#endif //YGOPRO_SERVER_MODE
#ifdef _WIN32
DWORD
size
;
WriteFile
(
recording_fp
,
data
,
length
,
&
size
,
NULL
);
DWORD
size
;
WriteFile
(
recording_fp
,
data
,
length
,
&
size
,
NULL
);
#else
fwrite
(
data
,
length
,
1
,
fp
);
if
(
flush
)
fflush
(
fp
);
fwrite
(
data
,
length
,
1
,
fp
);
if
(
flush
)
fflush
(
fp
);
#endif
}
}
void
Replay
::
WriteInt32
(
int
data
,
bool
flush
)
{
if
(
!
is_recording
)
return
;
*
((
int
*
)(
pdata
))
=
data
;
pdata
+=
4
;
if
(
ygo
::
replay_mode
>
0
)
{
#ifdef YGOPRO_SERVER_MODE
if
(
ygo
::
replay_mode
==
0
)
return
;
#endif //YGOPRO_SERVER_MODE
#ifdef _WIN32
DWORD
size
;
WriteFile
(
recording_fp
,
&
data
,
sizeof
(
int
),
&
size
,
NULL
);
DWORD
size
;
WriteFile
(
recording_fp
,
&
data
,
sizeof
(
int
),
&
size
,
NULL
);
#else
fwrite
(
&
data
,
sizeof
(
int
),
1
,
fp
);
if
(
flush
)
fflush
(
fp
);
fwrite
(
&
data
,
sizeof
(
int
),
1
,
fp
);
if
(
flush
)
fflush
(
fp
);
#endif
}
}
void
Replay
::
WriteInt16
(
short
data
,
bool
flush
)
{
if
(
!
is_recording
)
return
;
*
((
short
*
)(
pdata
))
=
data
;
pdata
+=
2
;
if
(
ygo
::
replay_mode
>
0
)
{
#ifdef YGOPRO_SERVER_MODE
if
(
ygo
::
replay_mode
==
0
)
return
;
#endif //YGOPRO_SERVER_MODE
#ifdef _WIN32
DWORD
size
;
WriteFile
(
recording_fp
,
&
data
,
sizeof
(
short
),
&
size
,
NULL
);
DWORD
size
;
WriteFile
(
recording_fp
,
&
data
,
sizeof
(
short
),
&
size
,
NULL
);
#else
fwrite
(
&
data
,
sizeof
(
short
),
1
,
fp
);
if
(
flush
)
fflush
(
fp
);
fwrite
(
&
data
,
sizeof
(
short
),
1
,
fp
);
if
(
flush
)
fflush
(
fp
);
#endif
}
}
void
Replay
::
WriteInt8
(
char
data
,
bool
flush
)
{
if
(
!
is_recording
)
return
;
*
pdata
=
data
;
pdata
++
;
if
(
ygo
::
replay_mode
>
0
)
{
#ifdef YGOPRO_SERVER_MODE
if
(
ygo
::
replay_mode
==
0
)
return
;
#endif //YGOPRO_SERVER_MODE
#ifdef _WIN32
DWORD
size
;
WriteFile
(
recording_fp
,
&
data
,
sizeof
(
char
),
&
size
,
NULL
);
DWORD
size
;
WriteFile
(
recording_fp
,
&
data
,
sizeof
(
char
),
&
size
,
NULL
);
#else
fwrite
(
&
data
,
sizeof
(
char
),
1
,
fp
);
if
(
flush
)
fflush
(
fp
);
fwrite
(
&
data
,
sizeof
(
char
),
1
,
fp
);
if
(
flush
)
fflush
(
fp
);
#endif
}
}
void
Replay
::
Flush
()
{
if
(
!
is_recording
)
return
;
if
(
ygo
::
replay_mode
>
0
)
{
#ifdef YGOPRO_SERVER_MODE
if
(
ygo
::
replay_mode
==
0
)
return
;
#endif //YGOPRO_SERVER_MODE
#ifdef _WIN32
#else
fflush
(
fp
);
fflush
(
fp
);
#endif
}
}
void
Replay
::
EndRecord
()
{
if
(
!
is_recording
)
return
;
if
(
ygo
::
replay_mode
>
0
)
{
#ifdef YGOPRO_SERVER_MODE
if
(
ygo
::
replay_mode
==
0
)
return
;
#endif //YGOPRO_SERVER_MODE
#ifdef _WIN32
CloseHandle
(
recording_fp
);
CloseHandle
(
recording_fp
);
#else
fclose
(
fp
);
fclose
(
fp
);
#endif
}
pheader
.
datasize
=
pdata
-
replay_data
;
pheader
.
flag
|=
REPLAY_COMPRESSED
;
size_t
propsize
=
5
;
...
...
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