Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
YGOMobile
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
fallenstardust
YGOMobile
Commits
93ac168e
Commit
93ac168e
authored
Aug 22, 2021
by
fallenstardust
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sync gframe
parent
9810e1b2
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
168 additions
and
95 deletions
+168
-95
Classes/gframe/config.h
Classes/gframe/config.h
+2
-0
Classes/gframe/data_manager.cpp
Classes/gframe/data_manager.cpp
+5
-1
Classes/gframe/deck_con.cpp
Classes/gframe/deck_con.cpp
+11
-11
Classes/gframe/deck_con.h
Classes/gframe/deck_con.h
+2
-2
Classes/gframe/duelclient.cpp
Classes/gframe/duelclient.cpp
+20
-7
Classes/gframe/duelclient.h
Classes/gframe/duelclient.h
+1
-1
Classes/gframe/event_handler.cpp
Classes/gframe/event_handler.cpp
+4
-4
Classes/gframe/menu_handler.cpp
Classes/gframe/menu_handler.cpp
+6
-1
Classes/gframe/myfilesystem.h
Classes/gframe/myfilesystem.h
+1
-0
Classes/gframe/replay.cpp
Classes/gframe/replay.cpp
+48
-17
Classes/gframe/replay.h
Classes/gframe/replay.h
+21
-5
Classes/gframe/replay_mode.cpp
Classes/gframe/replay_mode.cpp
+20
-5
Classes/gframe/single_duel.cpp
Classes/gframe/single_duel.cpp
+11
-15
Classes/gframe/single_mode.cpp
Classes/gframe/single_mode.cpp
+5
-4
Classes/gframe/tag_duel.cpp
Classes/gframe/tag_duel.cpp
+11
-22
No files found.
Classes/gframe/config.h
View file @
93ac168e
...
...
@@ -15,6 +15,7 @@
#ifdef _WIN32
#include <WinSock2.h>
#define NOMINMAX
#include <windows.h>
#include <ws2tcpip.h>
...
...
@@ -39,6 +40,7 @@
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#include <locale.h>
#define SD_BOTH 2
#define SOCKET int
...
...
Classes/gframe/data_manager.cpp
View file @
93ac168e
...
...
@@ -67,7 +67,11 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
cd
.
race
=
sqlite3_column_int
(
pStmt
,
8
);
cd
.
attribute
=
sqlite3_column_int
(
pStmt
,
9
);
cd
.
category
=
sqlite3_column_int
(
pStmt
,
10
);
_datas
.
insert
(
std
::
make_pair
(
cd
.
code
,
cd
));
auto
it
=
_datas
.
find
(
cd
.
code
);
if
(
it
!=
_datas
.
end
())
it
->
second
=
cd
;
else
_datas
.
insert
(
std
::
make_pair
(
cd
.
code
,
cd
));
if
(
const
char
*
text
=
(
const
char
*
)
sqlite3_column_text
(
pStmt
,
12
))
{
BufferIO
::
DecodeUTF8
(
text
,
strBuffer
);
cs
.
name
=
strBuffer
;
...
...
Classes/gframe/deck_con.cpp
View file @
93ac168e
#include "config.h"
#include "deck_con.h"
#include "data_manager.h"
...
...
@@ -83,6 +82,7 @@ void DeckBuilder::Initialize() {
filterList
=
deckManager
.
_lfList
[
0
].
content
;
mainGame
->
cbLFList
->
setSelected
(
0
);
ClearSearch
();
rnd
.
reset
((
unsigned
int
)
time
(
nullptr
));
mouse_pos
.
set
(
0
,
0
);
hovered_code
=
0
;
hovered_pos
=
0
;
...
...
@@ -183,7 +183,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
break
;
}
case
BUTTON_SHUFFLE_DECK
:
{
std
::
random_shuffle
(
deckManager
.
current_deck
.
main
.
begin
(),
deckManager
.
current_deck
.
main
.
end
()
);
rnd
.
shuffle_vector
(
deckManager
.
current_deck
.
main
);
break
;
}
case
BUTTON_SAVE_DECK
:
{
...
...
@@ -417,7 +417,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
int
catesel
=
mainGame
->
lstCategories
->
getSelected
();
if
(
catesel
!=
2
)
mainGame
->
cbDMCategory
->
addItem
(
dataManager
.
GetSysString
(
1452
));
for
(
int
i
=
4
;
i
<
mainGame
->
lstCategories
->
getItemCount
();
i
++
)
{
for
(
int
i
=
4
;
i
<
(
int
)
mainGame
->
lstCategories
->
getItemCount
();
i
++
)
{
if
(
i
!=
catesel
)
mainGame
->
cbDMCategory
->
addItem
(
mainGame
->
lstCategories
->
getListItem
(
i
));
}
...
...
@@ -434,7 +434,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
int
catesel
=
mainGame
->
lstCategories
->
getSelected
();
if
(
catesel
!=
2
)
mainGame
->
cbDMCategory
->
addItem
(
dataManager
.
GetSysString
(
1452
));
for
(
int
i
=
4
;
i
<
mainGame
->
lstCategories
->
getItemCount
();
i
++
)
{
for
(
int
i
=
4
;
i
<
(
int
)
mainGame
->
lstCategories
->
getItemCount
();
i
++
)
{
if
(
i
!=
catesel
)
mainGame
->
cbDMCategory
->
addItem
(
mainGame
->
lstCategories
->
getListItem
(
i
));
}
...
...
@@ -453,7 +453,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
mainGame
->
lstCategories
->
addItem
(
catename
);
catesel
=
mainGame
->
lstCategories
->
getItemCount
()
-
1
;
}
else
{
for
(
int
i
=
3
;
i
<
mainGame
->
lstCategories
->
getItemCount
();
i
++
)
{
for
(
int
i
=
3
;
i
<
(
int
)
mainGame
->
lstCategories
->
getItemCount
();
i
++
)
{
if
(
!
wcsncasecmp
(
mainGame
->
lstCategories
->
getListItem
(
i
),
catename
,
256
))
{
catesel
=
i
;
mainGame
->
stACMessage
->
setText
(
dataManager
.
GetSysString
(
1474
));
...
...
@@ -483,7 +483,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
catesel
=
mainGame
->
lstCategories
->
getItemCount
()
-
1
;
}
else
{
catesel
=
0
;
for
(
int
i
=
3
;
i
<
mainGame
->
lstCategories
->
getItemCount
();
i
++
)
{
for
(
int
i
=
3
;
i
<
(
int
)
mainGame
->
lstCategories
->
getItemCount
();
i
++
)
{
if
(
!
wcsncasecmp
(
mainGame
->
lstCategories
->
getListItem
(
i
),
newcatename
,
256
))
{
catesel
=
i
;
mainGame
->
stACMessage
->
setText
(
dataManager
.
GetSysString
(
1474
));
...
...
@@ -534,7 +534,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
RefreshDeckList
();
ChangeCategory
(
mainGame
->
lstCategories
->
getSelected
());
}
for
(
int
i
=
0
;
i
<
mainGame
->
lstDecks
->
getItemCount
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
mainGame
->
lstDecks
->
getItemCount
();
i
++
)
{
if
(
!
wcsncasecmp
(
mainGame
->
lstDecks
->
getListItem
(
i
),
deckname
,
256
))
{
deckManager
.
LoadDeck
(
filepath
);
prev_deck
=
i
;
...
...
@@ -568,7 +568,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
}
RefreshDeckList
();
ChangeCategory
(
catesel
);
for
(
int
i
=
0
;
i
<
mainGame
->
lstDecks
->
getItemCount
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
mainGame
->
lstDecks
->
getItemCount
();
i
++
)
{
if
(
!
wcsncasecmp
(
mainGame
->
lstDecks
->
getListItem
(
i
),
newdeckname
,
256
))
{
deckManager
.
LoadDeck
(
newfilepath
);
prev_deck
=
i
;
...
...
@@ -632,7 +632,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
RefreshDeckList
();
mainGame
->
cbDBCategory
->
setSelected
(
catesel
);
ChangeCategory
(
catesel
);
for
(
int
i
=
0
;
i
<
mainGame
->
lstDecks
->
getItemCount
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
mainGame
->
lstDecks
->
getItemCount
();
i
++
)
{
if
(
!
wcsncasecmp
(
mainGame
->
lstDecks
->
getListItem
(
i
),
deckname
,
256
))
{
deckManager
.
LoadDeck
(
newfilepath
);
prev_deck
=
i
;
...
...
@@ -670,7 +670,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
RefreshDeckList
();
mainGame
->
cbDBCategory
->
setSelected
(
catesel
);
ChangeCategory
(
catesel
);
for
(
int
i
=
0
;
i
<
mainGame
->
lstDecks
->
getItemCount
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
mainGame
->
lstDecks
->
getItemCount
();
i
++
)
{
if
(
!
wcsncasecmp
(
mainGame
->
lstDecks
->
getListItem
(
i
),
deckname
,
256
))
{
deckManager
.
LoadDeck
(
newfilepath
);
prev_deck
=
i
;
...
...
@@ -1538,7 +1538,7 @@ void DeckBuilder::FilterCards() {
SortList
();
}
void
DeckBuilder
::
InstantSearch
()
{
if
(
mainGame
->
gameConf
.
auto_search_limit
>=
0
&&
(
wcslen
(
mainGame
->
ebCardName
->
getText
())
>=
mainGame
->
gameConf
.
auto_search_limit
))
if
(
mainGame
->
gameConf
.
auto_search_limit
>=
0
&&
(
(
int
)
wcslen
(
mainGame
->
ebCardName
->
getText
())
>=
mainGame
->
gameConf
.
auto_search_limit
))
StartFilter
();
}
void
DeckBuilder
::
ClearSearch
()
{
...
...
Classes/gframe/deck_con.h
View file @
93ac168e
...
...
@@ -5,8 +5,7 @@
#include <unordered_map>
#include <vector>
#include "client_card.h"
#include "config.h"
#include "../ocgcore/mtrandom.h"
#ifdef _IRR_ANDROID_PLATFORM_
#include <android/TouchEventTransferAndroid.h>
#include <android/android_tools.h>
...
...
@@ -79,6 +78,7 @@ public:
int
prev_sel
;
bool
is_modified
;
bool
readonly
;
mt19937
rnd
;
std
::
unordered_map
<
int
,
int
>*
filterList
;
std
::
vector
<
code_pointer
>
results
;
...
...
Classes/gframe/duelclient.cpp
View file @
93ac168e
...
...
@@ -31,7 +31,7 @@ int DuelClient::last_select_hint = 0;
char
DuelClient
::
last_successful_msg
[
0x2000
];
unsigned
int
DuelClient
::
last_successful_msg_length
=
0
;
wchar_t
DuelClient
::
event_string
[
256
];
mt
random
DuelClient
::
rnd
;
mt
19937
DuelClient
::
rnd
;
bool
DuelClient
::
is_refreshing
=
false
;
int
DuelClient
::
match_kill
=
0
;
...
...
@@ -60,7 +60,7 @@ bool DuelClient::StartClient(unsigned int ip, unsigned short port, bool create_g
return
false
;
}
connect_state
=
0x1
;
rnd
.
reset
(
time
(
0
));
rnd
.
reset
(
(
unsigned
int
)
time
(
nullptr
));
if
(
!
create_game
)
{
timeval
timeout
=
{
5
,
0
};
event
*
resp_event
=
event_new
(
client_base
,
0
,
EV_TIMEOUT
,
ConnectTimeout
,
0
);
...
...
@@ -691,7 +691,12 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
char
*
prep
=
pdata
;
Replay
new_replay
;
memcpy
(
&
new_replay
.
pheader
,
prep
,
sizeof
(
ReplayHeader
));
time_t
starttime
=
new_replay
.
pheader
.
seed
;
time_t
starttime
;
if
(
new_replay
.
pheader
.
flag
&
REPLAY_UNIFORM
)
starttime
=
new_replay
.
pheader
.
start_time
;
else
starttime
=
new_replay
.
pheader
.
seed
;
tm
*
localedtime
=
localtime
(
&
starttime
);
wchar_t
timetext
[
40
];
wcsftime
(
timetext
,
40
,
L"%Y-%m-%d %H-%M-%S"
,
localedtime
);
...
...
@@ -718,7 +723,8 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
new_replay
.
comp_size
=
len
-
sizeof
(
ReplayHeader
)
-
1
;
if
(
mainGame
->
actionParam
)
new_replay
.
SaveReplay
(
mainGame
->
ebRSName
->
getText
());
else
new_replay
.
SaveReplay
(
L"_LastReplay"
);
else
new_replay
.
SaveReplay
(
L"_LastReplay"
);
}
break
;
}
...
...
@@ -1661,7 +1667,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
SetResponseI
(
-
1
);
mainGame
->
dField
.
ClearChainSelect
();
if
(
mainGame
->
chkWaitChain
->
isChecked
()
&&
!
mainGame
->
ignore_chain
)
{
mainGame
->
WaitFrameSignal
(
rnd
.
real
()
*
20
+
20
);
mainGame
->
WaitFrameSignal
(
rnd
.
get_random_integer
(
20
,
40
)
);
}
DuelClient
::
SendResponse
();
return
true
;
...
...
@@ -1761,7 +1767,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
if
(
!
pzone
)
{
if
(
mainGame
->
chkRandomPos
->
isChecked
())
{
do
{
respbuf
[
2
]
=
rnd
.
real
()
*
7
;
respbuf
[
2
]
=
rnd
.
get_random_integer
(
0
,
6
)
;
}
while
(
!
(
filter
&
(
1
<<
respbuf
[
2
])));
}
else
{
if
(
filter
&
0x40
)
respbuf
[
2
]
=
6
;
...
...
@@ -3719,7 +3725,14 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
int
chtype
=
BufferIO
::
ReadInt8
(
pbuf
);
int
value
=
BufferIO
::
ReadInt32
(
pbuf
);
auto
&
player_desc_hints
=
mainGame
->
dField
.
player_desc_hints
[
player
];
if
(
chtype
==
PHINT_DESC_ADD
)
{
if
(
value
==
CARD_QUESTION
&&
player
==
0
)
{
if
(
chtype
==
PHINT_DESC_ADD
)
{
mainGame
->
dField
.
cant_check_grave
=
true
;
}
else
if
(
chtype
==
PHINT_DESC_REMOVE
)
{
mainGame
->
dField
.
cant_check_grave
=
false
;
}
}
else
if
(
chtype
==
PHINT_DESC_ADD
)
{
player_desc_hints
[
value
]
++
;
}
else
if
(
chtype
==
PHINT_DESC_REMOVE
)
{
player_desc_hints
[
value
]
--
;
...
...
Classes/gframe/duelclient.h
View file @
93ac168e
...
...
@@ -36,7 +36,7 @@ private:
static
char
last_successful_msg
[
0x2000
];
static
unsigned
int
last_successful_msg_length
;
static
wchar_t
event_string
[
256
];
static
mt
random
rnd
;
static
mt
19937
rnd
;
public:
static
bool
StartClient
(
unsigned
int
ip
,
unsigned
short
port
,
bool
create_game
=
true
);
static
void
ConnectTimeout
(
evutil_socket_t
fd
,
short
events
,
void
*
arg
);
...
...
Classes/gframe/event_handler.cpp
View file @
93ac168e
...
...
@@ -396,7 +396,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
case
BUTTON_ANNUMBER_11
:
case
BUTTON_ANNUMBER_12
:
{
mainGame
->
soundManager
->
PlaySoundEffect
(
SoundManager
::
SFX
::
BUTTON
);
for
(
int
i
=
0
;
i
<
mainGame
->
cbANNumber
->
getItemCount
();
++
i
)
{
for
(
int
i
=
0
;
i
<
(
int
)
mainGame
->
cbANNumber
->
getItemCount
();
++
i
)
{
if
(
id
-
BUTTON_ANNUMBER_1
+
1
==
mainGame
->
cbANNumber
->
getItemData
(
i
))
{
mainGame
->
cbANNumber
->
setSelected
(
i
);
break
;
...
...
@@ -1436,11 +1436,11 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
clicked_card
->
is_selected
=
true
;
selected_cards
.
push_back
(
clicked_card
);
}
if
(
selected_cards
.
size
()
>=
select_max
)
{
if
(
(
int
)
selected_cards
.
size
()
>=
select_max
)
{
SetResponseSelectedCards
();
ShowCancelOrFinishButton
(
0
);
DuelClient
::
SendResponse
();
}
else
if
(
selected_cards
.
size
()
>=
select_min
)
{
}
else
if
(
(
int
)
selected_cards
.
size
()
>=
select_min
)
{
if
(
selected_cards
.
size
()
==
selectable_cards
.
size
())
{
SetResponseSelectedCards
();
ShowCancelOrFinishButton
(
0
);
...
...
@@ -1799,7 +1799,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
ShowLocationCard
();
}
}
break
;
break
;
}
case
irr
:
:
EMIE_RMOUSE_PRESSED_DOWN
:
{
if
(
!
mainGame
->
dInfo
.
isStarted
)
...
...
Classes/gframe/menu_handler.cpp
View file @
93ac168e
...
...
@@ -6,6 +6,7 @@
#include "replay_mode.h"
#include "single_mode.h"
#include "image_manager.h"
#include "sound_manager.h"
#include "game.h"
namespace
ygo
{
...
...
@@ -540,7 +541,11 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break
;
wchar_t
infobuf
[
256
];
std
::
wstring
repinfo
;
time_t
curtime
=
ReplayMode
::
cur_replay
.
pheader
.
seed
;
time_t
curtime
;
if
(
ReplayMode
::
cur_replay
.
pheader
.
flag
&
REPLAY_UNIFORM
)
curtime
=
ReplayMode
::
cur_replay
.
pheader
.
start_time
;
else
curtime
=
ReplayMode
::
cur_replay
.
pheader
.
seed
;
tm
*
st
=
localtime
(
&
curtime
);
wcsftime
(
infobuf
,
256
,
L"%Y/%m/%d %H:%M:%S
\n
"
,
st
);
repinfo
.
append
(
infobuf
);
...
...
Classes/gframe/myfilesystem.h
View file @
93ac168e
...
...
@@ -14,6 +14,7 @@
#ifdef _WIN32
#define NOMINMAX
#include <Windows.h>
class
FileSystem
{
...
...
Classes/gframe/replay.cpp
View file @
93ac168e
...
...
@@ -2,15 +2,16 @@
#include "../ocgcore/ocgapi.h"
#include "../ocgcore/common.h"
#include "lzma/LzmaLib.h"
#include "myfilesystem.h"
namespace
ygo
{
Replay
::
Replay
()
{
is_recording
=
false
;
is_replaying
=
false
;
replay_data
=
new
unsigned
char
[
0x20000
];
comp_data
=
new
unsigned
char
[
0x2000
];
Replay
::
Replay
()
:
fp
(
nullptr
),
pheader
(),
pdata
(
nullptr
),
replay_size
(
0
),
comp_size
(
0
),
is_recording
(
false
),
is_replaying
(
false
)
{
#ifdef _WIN32
recording_fp
=
nullptr
;
#endif
replay_data
=
new
unsigned
char
[
MAX_REPLAY_SIZE
];
comp_data
=
new
unsigned
char
[
MAX_COMP_SIZE
];
}
Replay
::~
Replay
()
{
delete
[]
replay_data
;
...
...
@@ -33,6 +34,9 @@ void Replay::BeginRecord() {
return
;
#endif
pdata
=
replay_data
;
replay_size
=
0
;
comp_size
=
0
;
is_replaying
=
false
;
is_recording
=
true
;
}
void
Replay
::
WriteHeader
(
ReplayHeader
&
header
)
{
...
...
@@ -45,9 +49,11 @@ void Replay::WriteHeader(ReplayHeader& header) {
fflush
(
fp
);
#endif
}
void
Replay
::
WriteData
(
const
void
*
data
,
unsigned
int
length
,
bool
flush
)
{
void
Replay
::
WriteData
(
const
void
*
data
,
int
length
,
bool
flush
)
{
if
(
!
is_recording
)
return
;
if
(
length
<
0
||
(
pdata
-
replay_data
)
+
length
>
MAX_REPLAY_SIZE
)
return
;
memcpy
(
pdata
,
data
,
length
);
pdata
+=
length
;
#ifdef _WIN32
...
...
@@ -62,6 +68,8 @@ void Replay::WriteData(const void* data, unsigned int length, bool flush) {
void
Replay
::
WriteInt32
(
int
data
,
bool
flush
)
{
if
(
!
is_recording
)
return
;
if
((
pdata
-
replay_data
)
+
4
>
MAX_REPLAY_SIZE
)
return
;
*
((
int
*
)(
pdata
))
=
data
;
pdata
+=
4
;
#ifdef _WIN32
...
...
@@ -76,6 +84,8 @@ void Replay::WriteInt32(int data, bool flush) {
void
Replay
::
WriteInt16
(
short
data
,
bool
flush
)
{
if
(
!
is_recording
)
return
;
if
((
pdata
-
replay_data
)
+
2
>
MAX_REPLAY_SIZE
)
return
;
*
((
short
*
)(
pdata
))
=
data
;
pdata
+=
2
;
#ifdef _WIN32
...
...
@@ -90,6 +100,8 @@ void Replay::WriteInt16(short data, bool flush) {
void
Replay
::
WriteInt8
(
char
data
,
bool
flush
)
{
if
(
!
is_recording
)
return
;
if
((
pdata
-
replay_data
)
+
1
>
MAX_REPLAY_SIZE
)
return
;
*
pdata
=
data
;
pdata
++
;
#ifdef _WIN32
...
...
@@ -117,11 +129,19 @@ void Replay::EndRecord() {
#else
fclose
(
fp
);
#endif
pheader
.
datasize
=
pdata
-
replay_data
;
if
(
pdata
-
replay_data
>
0
&&
pdata
-
replay_data
<=
MAX_REPLAY_SIZE
)
replay_size
=
pdata
-
replay_data
;
else
replay_size
=
0
;
pheader
.
datasize
=
replay_size
;
pheader
.
flag
|=
REPLAY_COMPRESSED
;
size_t
propsize
=
5
;
comp_size
=
0x1000
;
LzmaCompress
(
comp_data
,
&
comp_size
,
replay_data
,
pdata
-
replay_data
,
pheader
.
props
,
&
propsize
,
5
,
1
<<
24
,
3
,
0
,
2
,
32
,
1
);
comp_size
=
MAX_COMP_SIZE
;
int
ret
=
LzmaCompress
(
comp_data
,
&
comp_size
,
replay_data
,
replay_size
,
pheader
.
props
,
&
propsize
,
5
,
1
<<
24
,
3
,
0
,
2
,
32
,
1
);
if
(
ret
!=
SZ_OK
)
{
*
((
int
*
)(
comp_data
))
=
ret
;
comp_size
=
sizeof
(
ret
);
}
is_recording
=
false
;
}
void
Replay
::
SaveReplay
(
const
wchar_t
*
name
)
{
...
...
@@ -163,22 +183,33 @@ bool Replay::OpenReplay(const wchar_t* name) {
}
if
(
!
fp
)
return
false
;
pdata
=
replay_data
;
is_recording
=
false
;
is_replaying
=
false
;
replay_size
=
0
;
comp_size
=
0
;
if
(
fread
(
&
pheader
,
sizeof
(
pheader
),
1
,
fp
)
<
1
)
{
fclose
(
fp
);
return
false
;
}
if
(
pheader
.
flag
&
REPLAY_COMPRESSED
)
{
comp_size
=
fread
(
comp_data
,
1
,
0x1000
,
fp
);
comp_size
=
fread
(
comp_data
,
1
,
MAX_COMP_SIZE
,
fp
);
fclose
(
fp
);
if
((
int
)
pheader
.
datasize
<
0
&&
(
int
)
pheader
.
datasize
>
MAX_REPLAY_SIZE
)
return
false
;
replay_size
=
pheader
.
datasize
;
if
(
LzmaUncompress
(
replay_data
,
&
replay_size
,
comp_data
,
&
comp_size
,
pheader
.
props
,
5
)
!=
SZ_OK
)
if
(
LzmaUncompress
(
replay_data
,
&
replay_size
,
comp_data
,
&
comp_size
,
pheader
.
props
,
5
)
!=
SZ_OK
)
return
false
;
if
(
replay_size
!=
pheader
.
datasize
)
{
replay_size
=
0
;
return
false
;
}
}
else
{
comp_size
=
fread
(
replay_data
,
1
,
0x20000
,
fp
);
replay_size
=
fread
(
replay_data
,
1
,
MAX_REPLAY_SIZE
,
fp
);
fclose
(
fp
);
replay_size
=
comp_size
;
comp_size
=
0
;
}
pdata
=
replay_data
;
is_replaying
=
true
;
return
true
;
}
...
...
@@ -197,7 +228,7 @@ bool Replay::CheckReplay(const wchar_t* name) {
ReplayHeader
rheader
;
size_t
count
=
fread
(
&
rheader
,
sizeof
(
ReplayHeader
),
1
,
rfp
);
fclose
(
rfp
);
return
count
==
1
&&
rheader
.
id
==
0x31707279
&&
rheader
.
version
>=
0x12d0
;
return
count
==
1
&&
rheader
.
id
==
0x31707279
&&
rheader
.
version
>=
0x12d0
u
;
}
bool
Replay
::
DeleteReplay
(
const
wchar_t
*
name
)
{
wchar_t
fname
[
256
];
...
...
@@ -246,7 +277,7 @@ void Replay::ReadName(wchar_t* data) {
ReadData
(
buffer
,
40
);
BufferIO
::
CopyWStr
(
buffer
,
data
,
20
);
}
void
Replay
::
ReadData
(
void
*
data
,
unsigned
int
length
)
{
void
Replay
::
ReadData
(
void
*
data
,
int
length
)
{
if
(
!
is_replaying
)
return
;
memcpy
(
data
,
pdata
,
length
);
...
...
Classes/gframe/replay.h
View file @
93ac168e
...
...
@@ -6,10 +6,16 @@
namespace
ygo
{
// replay flag
#define REPLAY_COMPRESSED 0x1
#define REPLAY_TAG 0x2
#define REPLAY_DECODED 0x4
#define REPLAY_SINGLE_MODE 0x8
#define REPLAY_UNIFORM 0x10
// max size
#define MAX_REPLAY_SIZE 0x20000
#define MAX_COMP_SIZE 0x2000
struct
ReplayHeader
{
unsigned
int
id
;
...
...
@@ -17,23 +23,30 @@ struct ReplayHeader {
unsigned
int
flag
;
unsigned
int
seed
;
unsigned
int
datasize
;
unsigned
int
hash
;
unsigned
int
start_time
;
unsigned
char
props
[
8
];
ReplayHeader
()
:
id
(
0
),
version
(
0
),
flag
(
0
),
seed
(
0
),
datasize
(
0
),
start_time
(
0
),
props
{
0
}
{}
};
class
Replay
{
public:
Replay
();
~
Replay
();
// record
void
BeginRecord
();
void
WriteHeader
(
ReplayHeader
&
header
);
void
WriteData
(
const
void
*
data
,
unsigned
int
length
,
bool
flush
=
true
);
void
WriteData
(
const
void
*
data
,
int
length
,
bool
flush
=
true
);
void
WriteInt32
(
int
data
,
bool
flush
=
true
);
void
WriteInt16
(
short
data
,
bool
flush
=
true
);
void
WriteInt8
(
char
data
,
bool
flush
=
true
);
void
Flush
();
void
EndRecord
();
void
SaveReplay
(
const
wchar_t
*
name
);
// play
bool
OpenReplay
(
const
wchar_t
*
name
);
static
bool
CheckReplay
(
const
wchar_t
*
name
);
static
bool
DeleteReplay
(
const
wchar_t
*
name
);
...
...
@@ -41,22 +54,25 @@ public:
bool
ReadNextResponse
(
unsigned
char
resp
[
64
]);
void
ReadName
(
wchar_t
*
data
);
void
ReadHeader
(
ReplayHeader
&
header
);
void
ReadData
(
void
*
data
,
unsigned
int
length
);
void
ReadData
(
void
*
data
,
int
length
);
int
ReadInt32
();
short
ReadInt16
();
char
ReadInt8
();
void
Rewind
();
FILE
*
fp
;
ReplayHeader
pheader
;
#ifdef _WIN32
HANDLE
recording_fp
;
#endif
ReplayHeader
pheader
;
unsigned
char
*
replay_data
;
unsigned
char
*
comp_data
;
unsigned
char
*
pdata
;
size_t
replay_size
;
size_t
comp_size
;
private:
unsigned
char
*
pdata
;
bool
is_recording
;
bool
is_replaying
;
};
...
...
Classes/gframe/replay_mode.cpp
View file @
93ac168e
...
...
@@ -138,13 +138,23 @@ int ReplayMode::ReplayThread() {
mainGame
->
gMutex
.
unlock
();
}
EndDuel
();
pduel
=
0
;
is_continuing
=
true
;
is_closing
=
false
;
is_pausing
=
false
;
is_paused
=
false
;
is_swaping
=
false
;
is_restarting
=
false
;
exit_pending
=
false
;
skip_turn
=
0
;
current_step
=
0
;
skip_step
=
0
;
return
0
;
}
bool
ReplayMode
::
StartDuel
()
{
const
ReplayHeader
&
rh
=
cur_replay
.
pheader
;
mtrandom
rnd
;
int
seed
=
rh
.
seed
;
rnd
.
reset
(
seed
);
unsigned
int
seed
=
rh
.
seed
;
std
::
mt19937
rnd
(
seed
);
if
(
mainGame
->
dInfo
.
isTag
)
{
cur_replay
.
ReadName
(
mainGame
->
dInfo
.
hostname
);
cur_replay
.
ReadName
(
mainGame
->
dInfo
.
hostname_tag
);
...
...
@@ -154,7 +164,7 @@ bool ReplayMode::StartDuel() {
cur_replay
.
ReadName
(
mainGame
->
dInfo
.
hostname
);
cur_replay
.
ReadName
(
mainGame
->
dInfo
.
clientname
);
}
pduel
=
create_duel
(
rnd
.
rand
());
pduel
=
create_duel
(
rnd
());
int
start_lp
=
cur_replay
.
ReadInt32
();
int
start_hand
=
cur_replay
.
ReadInt32
();
int
draw_count
=
cur_replay
.
ReadInt32
();
...
...
@@ -214,13 +224,18 @@ bool ReplayMode::StartDuel() {
}
}
else
{
char
filename
[
256
];
size_t
slen
=
cur_replay
.
ReadInt16
();
int
slen
=
cur_replay
.
ReadInt16
();
if
(
slen
<
0
||
slen
>
255
)
{
return
false
;
}
cur_replay
.
ReadData
(
filename
,
slen
);
filename
[
slen
]
=
0
;
if
(
!
preload_script
(
pduel
,
filename
,
0
))
{
return
false
;
}
}
if
(
!
(
rh
.
flag
&
REPLAY_UNIFORM
))
opt
|=
DUEL_OLD_REPLAY
;
start_duel
(
pduel
,
opt
);
return
true
;
}
...
...
Classes/gframe/single_duel.cpp
View file @
93ac168e
...
...
@@ -288,7 +288,8 @@ void SingleDuel::UpdateDeck(DuelPlayer* dp, void* pdata, unsigned int len) {
int
mainc
=
BufferIO
::
ReadInt32
(
deckbuf
);
int
sidec
=
BufferIO
::
ReadInt32
(
deckbuf
);
// verify data
if
((
unsigned
)
mainc
+
(
unsigned
)
sidec
>
(
len
-
8
)
/
4
)
{
const
unsigned
int
possibleMaxLength
=
(
len
-
8
)
/
4
;
if
((
unsigned
)
mainc
>
possibleMaxLength
||
(
unsigned
)
sidec
>
possibleMaxLength
||
(
unsigned
)
mainc
+
(
unsigned
)
sidec
>
possibleMaxLength
)
{
STOC_ErrorMsg
scem
;
scem
.
msg
=
ERRMSG_DECKERROR
;
scem
.
code
=
0
;
...
...
@@ -395,7 +396,6 @@ void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
return
;
duel_stage
=
DUEL_STAGE_DUELING
;
bool
swapped
=
false
;
mtrandom
rnd
;
pplayer
[
0
]
=
players
[
0
];
pplayer
[
1
]
=
players
[
1
];
if
((
tp
&&
dp
->
type
==
1
)
||
(
!
tp
&&
dp
->
type
==
0
))
{
...
...
@@ -410,34 +410,30 @@ void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
swapped
=
true
;
}
dp
->
state
=
CTOS_RESPONSE
;
std
::
random_device
rd
;
unsigned
int
seed
=
rd
();
mt19937
rnd
(
seed
);
unsigned
int
duel_seed
=
rnd
.
rand
();
ReplayHeader
rh
;
rh
.
id
=
0x31707279
;
rh
.
version
=
PRO_VERSION
;
rh
.
flag
=
0
;
time_t
seed
=
time
(
0
);
rh
.
flag
=
REPLAY_UNIFORM
;
rh
.
seed
=
seed
;
rh
.
start_time
=
(
unsigned
int
)
time
(
nullptr
);
last_replay
.
BeginRecord
();
last_replay
.
WriteHeader
(
rh
);
rnd
.
reset
(
seed
);
last_replay
.
WriteData
(
players
[
0
]
->
name
,
40
,
false
);
last_replay
.
WriteData
(
players
[
1
]
->
name
,
40
,
false
);
if
(
!
host_info
.
no_shuffle_deck
)
{
for
(
size_t
i
=
pdeck
[
0
].
main
.
size
()
-
1
;
i
>
0
;
--
i
)
{
int
swap
=
rnd
.
real
()
*
(
i
+
1
);
std
::
swap
(
pdeck
[
0
].
main
[
i
],
pdeck
[
0
].
main
[
swap
]);
}
for
(
size_t
i
=
pdeck
[
1
].
main
.
size
()
-
1
;
i
>
0
;
--
i
)
{
int
swap
=
rnd
.
real
()
*
(
i
+
1
);
std
::
swap
(
pdeck
[
1
].
main
[
i
],
pdeck
[
1
].
main
[
swap
]);
}
rnd
.
shuffle_vector
(
pdeck
[
0
].
main
);
rnd
.
shuffle_vector
(
pdeck
[
1
].
main
);
}
time_limit
[
0
]
=
host_info
.
time_limit
;
time_limit
[
1
]
=
host_info
.
time_limit
;
set_script_reader
((
script_reader
)
DataManager
::
ScriptReaderEx
);
set_card_reader
((
card_reader
)
DataManager
::
CardReader
);
set_message_handler
((
message_handler
)
SingleDuel
::
MessageHandler
);
rnd
.
reset
(
seed
);
pduel
=
create_duel
(
rnd
.
rand
());
pduel
=
create_duel
(
duel_seed
);
set_player_info
(
pduel
,
0
,
host_info
.
start_lp
,
host_info
.
start_hand
,
host_info
.
draw_count
);
set_player_info
(
pduel
,
1
,
host_info
.
start_lp
,
host_info
.
start_hand
,
host_info
.
draw_count
);
int
opt
=
(
int
)
host_info
.
duel_rule
<<
16
;
...
...
Classes/gframe/single_mode.cpp
View file @
93ac168e
...
...
@@ -33,9 +33,9 @@ int SingleMode::SinglePlayThread() {
const
int
start_hand
=
5
;
const
int
draw_count
=
1
;
const
int
opt
=
0
;
mtrandom
rn
d
;
time_t
seed
=
time
(
0
);
rnd
.
reset
(
seed
);
std
::
random_device
r
d
;
unsigned
int
seed
=
rd
(
);
mt19937
rnd
(
seed
);
set_script_reader
((
script_reader
)
DataManager
::
ScriptReaderEx
);
set_card_reader
((
card_reader
)
DataManager
::
CardReader
);
set_message_handler
((
message_handler
)
MessageHandler
);
...
...
@@ -65,8 +65,9 @@ int SingleMode::SinglePlayThread() {
ReplayHeader
rh
;
rh
.
id
=
0x31707279
;
rh
.
version
=
PRO_VERSION
;
rh
.
flag
=
REPLAY_SINGLE_MODE
;
rh
.
flag
=
REPLAY_
UNIFORM
|
REPLAY_
SINGLE_MODE
;
rh
.
seed
=
seed
;
rh
.
start_time
=
(
unsigned
int
)
time
(
nullptr
);
mainGame
->
gMutex
.
lock
();
mainGame
->
HideElement
(
mainGame
->
wSinglePlay
);
mainGame
->
ClearCardInfo
();
...
...
Classes/gframe/tag_duel.cpp
View file @
93ac168e
...
...
@@ -356,7 +356,6 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
return
;
duel_stage
=
DUEL_STAGE_DUELING
;
bool
swapped
=
false
;
mtrandom
rnd
;
pplayer
[
0
]
=
players
[
0
];
pplayer
[
1
]
=
players
[
1
];
pplayer
[
2
]
=
players
[
2
];
...
...
@@ -376,44 +375,34 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
cur_player
[
0
]
=
players
[
0
];
cur_player
[
1
]
=
players
[
3
];
dp
->
state
=
CTOS_RESPONSE
;
std
::
random_device
rd
;
unsigned
int
seed
=
rd
();
mt19937
rnd
(
seed
);
unsigned
int
duel_seed
=
rnd
.
rand
();
ReplayHeader
rh
;
rh
.
id
=
0x31707279
;
rh
.
version
=
PRO_VERSION
;
rh
.
flag
=
REPLAY_TAG
;
time_t
seed
=
time
(
0
);
rh
.
flag
=
REPLAY_UNIFORM
|
REPLAY_TAG
;
rh
.
seed
=
seed
;
rh
.
start_time
=
(
unsigned
int
)
time
(
nullptr
);
last_replay
.
BeginRecord
();
last_replay
.
WriteHeader
(
rh
);
rnd
.
reset
(
seed
);
last_replay
.
WriteData
(
players
[
0
]
->
name
,
40
,
false
);
last_replay
.
WriteData
(
players
[
1
]
->
name
,
40
,
false
);
last_replay
.
WriteData
(
players
[
2
]
->
name
,
40
,
false
);
last_replay
.
WriteData
(
players
[
3
]
->
name
,
40
,
false
);
if
(
!
host_info
.
no_shuffle_deck
)
{
for
(
size_t
i
=
pdeck
[
0
].
main
.
size
()
-
1
;
i
>
0
;
--
i
)
{
int
swap
=
rnd
.
real
()
*
(
i
+
1
);
std
::
swap
(
pdeck
[
0
].
main
[
i
],
pdeck
[
0
].
main
[
swap
]);
}
for
(
size_t
i
=
pdeck
[
1
].
main
.
size
()
-
1
;
i
>
0
;
--
i
)
{
int
swap
=
rnd
.
real
()
*
(
i
+
1
);
std
::
swap
(
pdeck
[
1
].
main
[
i
],
pdeck
[
1
].
main
[
swap
]);
}
for
(
size_t
i
=
pdeck
[
2
].
main
.
size
()
-
1
;
i
>
0
;
--
i
)
{
int
swap
=
rnd
.
real
()
*
(
i
+
1
);
std
::
swap
(
pdeck
[
2
].
main
[
i
],
pdeck
[
2
].
main
[
swap
]);
}
for
(
size_t
i
=
pdeck
[
3
].
main
.
size
()
-
1
;
i
>
0
;
--
i
)
{
int
swap
=
rnd
.
real
()
*
(
i
+
1
);
std
::
swap
(
pdeck
[
3
].
main
[
i
],
pdeck
[
3
].
main
[
swap
]);
}
rnd
.
shuffle_vector
(
pdeck
[
0
].
main
);
rnd
.
shuffle_vector
(
pdeck
[
1
].
main
);
rnd
.
shuffle_vector
(
pdeck
[
2
].
main
);
rnd
.
shuffle_vector
(
pdeck
[
3
].
main
);
}
time_limit
[
0
]
=
host_info
.
time_limit
;
time_limit
[
1
]
=
host_info
.
time_limit
;
set_script_reader
((
script_reader
)
DataManager
::
ScriptReaderEx
);
set_card_reader
((
card_reader
)
DataManager
::
CardReader
);
set_message_handler
((
message_handler
)
TagDuel
::
MessageHandler
);
rnd
.
reset
(
seed
);
pduel
=
create_duel
(
rnd
.
rand
());
pduel
=
create_duel
(
duel_seed
);
set_player_info
(
pduel
,
0
,
host_info
.
start_lp
,
host_info
.
start_hand
,
host_info
.
draw_count
);
set_player_info
(
pduel
,
1
,
host_info
.
start_lp
,
host_info
.
start_hand
,
host_info
.
draw_count
);
int
opt
=
(
int
)
host_info
.
duel_rule
<<
16
;
...
...
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