Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
R
rd-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
苍蓝
rd-ygopro
Commits
62dd6c6e
Commit
62dd6c6e
authored
Mar 27, 2019
by
nanahira
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'test' of github.com:mercury233/ygopro
parents
39b8e65a
4166c835
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
738 additions
and
63 deletions
+738
-63
gframe/data_manager.cpp
gframe/data_manager.cpp
+75
-43
gframe/data_manager.h
gframe/data_manager.h
+6
-3
gframe/game.cpp
gframe/game.cpp
+39
-10
gframe/game.h
gframe/game.h
+4
-1
gframe/gframe.cpp
gframe/gframe.cpp
+2
-6
gframe/spmemvfs.c
gframe/spmemvfs.c
+548
-0
gframe/spmemvfs.h
gframe/spmemvfs.h
+64
-0
No files found.
gframe/data_manager.cpp
View file @
62dd6c6e
...
...
@@ -7,23 +7,37 @@ namespace ygo {
const
wchar_t
*
DataManager
::
unknown_string
=
L"???"
;
wchar_t
DataManager
::
strBuffer
[
4096
];
byte
DataManager
::
scriptBuffer
[
0x20000
];
IFileSystem
*
DataManager
::
FileSystem
;
DataManager
dataManager
;
bool
DataManager
::
LoadDB
(
const
char
*
file
)
{
sqlite3
*
pDB
;
if
(
sqlite3_open_v2
(
file
,
&
pDB
,
SQLITE_OPEN_READONLY
,
0
)
!=
SQLITE_OK
)
return
Error
(
pDB
);
bool
DataManager
::
LoadDB
(
const
wchar_t
*
wfile
)
{
IReadFile
*
reader
=
FileSystem
->
createAndOpenFile
(
wfile
);
if
(
reader
==
NULL
)
return
false
;
spmemvfs_db_t
db
;
spmembuffer_t
*
mem
=
(
spmembuffer_t
*
)
calloc
(
sizeof
(
spmembuffer_t
),
1
);
spmemvfs_env_init
();
mem
->
total
=
mem
->
used
=
reader
->
getSize
();
mem
->
data
=
(
char
*
)
malloc
(
mem
->
total
+
1
);
reader
->
read
(
mem
->
data
,
mem
->
total
);
reader
->
drop
();
(
mem
->
data
)[
mem
->
total
]
=
'\0'
;
char
file
[
256
];
BufferIO
::
EncodeUTF8
(
wfile
,
file
);
if
(
spmemvfs_open_db
(
&
db
,
file
,
mem
)
!=
SQLITE_OK
)
return
Error
(
&
db
);
sqlite3
*
pDB
=
db
.
handle
;
sqlite3_stmt
*
pStmt
;
const
char
*
sql
=
"select * from datas,texts where datas.id=texts.id"
;
if
(
sqlite3_prepare_v2
(
pDB
,
sql
,
-
1
,
&
pStmt
,
0
)
!=
SQLITE_OK
)
return
Error
(
pDB
);
return
Error
(
&
db
);
CardDataC
cd
;
CardString
cs
;
int
step
=
0
;
do
{
step
=
sqlite3_step
(
pStmt
);
if
(
step
==
SQLITE_BUSY
||
step
==
SQLITE_ERROR
||
step
==
SQLITE_MISUSE
)
return
Error
(
pDB
,
pStmt
);
return
Error
(
&
db
,
pStmt
);
else
if
(
step
==
SQLITE_ROW
)
{
cd
.
code
=
sqlite3_column_int
(
pStmt
,
0
);
cd
.
ot
=
sqlite3_column_int
(
pStmt
,
1
);
...
...
@@ -63,7 +77,8 @@ bool DataManager::LoadDB(const char* file) {
}
}
while
(
step
!=
SQLITE_DONE
);
sqlite3_finalize
(
pStmt
);
sqlite3_close
(
pDB
);
spmemvfs_close_db
(
&
db
);
spmemvfs_env_fini
();
return
true
;
}
bool
DataManager
::
LoadStrings
(
const
char
*
file
)
{
...
...
@@ -71,11 +86,34 @@ bool DataManager::LoadStrings(const char* file) {
if
(
!
fp
)
return
false
;
char
linebuf
[
256
];
char
strbuf
[
256
];
int
value
;
while
(
fgets
(
linebuf
,
256
,
fp
))
{
ReadStringConfLine
(
linebuf
);
}
fclose
(
fp
);
for
(
int
i
=
0
;
i
<
255
;
++
i
)
myswprintf
(
numStrings
[
i
],
L"%d"
,
i
);
return
true
;
}
bool
DataManager
::
LoadStrings
(
IReadFile
*
reader
)
{
char
ch
[
2
]
=
" "
;
char
linebuf
[
256
]
=
""
;
while
(
reader
->
read
(
&
ch
[
0
],
1
))
{
if
(
ch
[
0
]
==
'\0'
)
break
;
strcat
(
linebuf
,
ch
);
if
(
ch
[
0
]
==
'\n'
)
{
ReadStringConfLine
(
linebuf
);
linebuf
[
0
]
=
'\0'
;
}
}
reader
->
drop
();
return
true
;
}
void
DataManager
::
ReadStringConfLine
(
const
char
*
linebuf
)
{
if
(
linebuf
[
0
]
!=
'!'
)
continue
;
return
;
char
strbuf
[
256
];
int
value
;
sscanf
(
linebuf
,
"!%s"
,
strbuf
);
if
(
!
strcmp
(
strbuf
,
"system"
))
{
sscanf
(
&
linebuf
[
7
],
"%d %240[^
\n
]"
,
&
value
,
strbuf
);
...
...
@@ -94,17 +132,13 @@ bool DataManager::LoadStrings(const char* file) {
BufferIO
::
DecodeUTF8
(
strbuf
,
strBuffer
);
_setnameStrings
[
value
]
=
strBuffer
;
}
}
fclose
(
fp
);
for
(
int
i
=
0
;
i
<
255
;
++
i
)
myswprintf
(
numStrings
[
i
],
L"%d"
,
i
);
return
true
;
}
bool
DataManager
::
Error
(
s
qlite3
*
pDB
,
sqlite3_stmt
*
pStmt
)
{
BufferIO
::
DecodeUTF8
(
sqlite3_errmsg
(
pDB
),
strBuffer
);
bool
DataManager
::
Error
(
s
pmemvfs_db_t
*
pDB
,
sqlite3_stmt
*
pStmt
)
{
BufferIO
::
DecodeUTF8
(
sqlite3_errmsg
(
pDB
->
handle
),
strBuffer
);
if
(
pStmt
)
sqlite3_finalize
(
pStmt
);
sqlite3_close
(
pDB
);
spmemvfs_close_db
(
pDB
);
spmemvfs_env_fini
();
return
false
;
}
bool
DataManager
::
GetData
(
int
code
,
CardData
*
pData
)
{
...
...
@@ -335,21 +369,19 @@ byte* DataManager::ScriptReaderExSingle(const char* path, const char* script_nam
return
ScriptReader
(
sname
,
slen
);
}
byte
*
DataManager
::
ScriptReader
(
const
char
*
script_name
,
int
*
slen
)
{
FILE
*
fp
;
#ifdef _WIN32
wchar_t
fname
[
256
];
BufferIO
::
DecodeUTF8
(
script_name
,
fname
);
fp
=
_wfopen
(
fname
,
L"rb"
);
#else
fp
=
fopen
(
script_name
,
"rb"
);
#endif
if
(
!
fp
)
IReadFile
*
reader
=
FileSystem
->
createAndOpenFile
(
fname
);
if
(
reader
==
NULL
)
return
0
;
int
len
=
fread
(
scriptBuffer
,
1
,
sizeof
(
scriptBuffer
),
fp
);
fclose
(
fp
);
if
(
len
>=
sizeof
(
scriptBuffer
))
size_t
size
=
reader
->
getSize
(
);
if
(
size
>
sizeof
(
scriptBuffer
))
{
reader
->
drop
();
return
0
;
*
slen
=
len
;
}
reader
->
read
(
scriptBuffer
,
size
);
reader
->
drop
();
*
slen
=
size
;
return
scriptBuffer
;
}
...
...
gframe/data_manager.h
View file @
62dd6c6e
...
...
@@ -3,6 +3,7 @@
#include "config.h"
#include "sqlite3.h"
#include "spmemvfs.h"
#include "client_card.h"
#include <unordered_map>
...
...
@@ -11,9 +12,11 @@ namespace ygo {
class
DataManager
{
public:
DataManager
()
:
_datas
(
8192
),
_strings
(
8192
)
{}
bool
LoadDB
(
const
char
*
file
);
bool
LoadDB
(
const
wchar_t
*
w
file
);
bool
LoadStrings
(
const
char
*
file
);
bool
Error
(
sqlite3
*
pDB
,
sqlite3_stmt
*
pStmt
=
0
);
bool
LoadStrings
(
IReadFile
*
reader
);
void
ReadStringConfLine
(
const
char
*
linebuf
);
bool
Error
(
spmemvfs_db_t
*
pDB
,
sqlite3_stmt
*
pStmt
=
0
);
bool
GetData
(
int
code
,
CardData
*
pData
);
code_pointer
GetCodePointer
(
int
code
);
bool
GetString
(
int
code
,
CardString
*
pStr
);
...
...
@@ -55,7 +58,7 @@ public:
static
byte
*
ScriptReaderEx
(
const
char
*
script_name
,
int
*
slen
);
static
byte
*
ScriptReaderExSingle
(
const
char
*
path
,
const
char
*
script_name
,
int
*
slen
,
int
pre_len
=
1
);
static
byte
*
ScriptReader
(
const
char
*
script_name
,
int
*
slen
);
static
IFileSystem
*
FileSystem
;
};
extern
DataManager
dataManager
;
...
...
gframe/game.cpp
View file @
62dd6c6e
...
...
@@ -78,9 +78,10 @@ bool Game::Initialize() {
ErrorLog
(
"Failed to load textures!"
);
return
false
;
}
LoadExpansionDB
();
if
(
dataManager
.
LoadDB
(
GetLocaleDir
(
"cards.cdb"
)))
{}
else
if
(
!
dataManager
.
LoadDB
(
"cards.cdb"
))
{
dataManager
.
FileSystem
=
device
->
getFileSystem
();
LoadExpansions
();
if
(
dataManager
.
LoadDB
(
GetLocaleDirWide
(
"cards.cdb"
)))
{}
else
if
(
!
dataManager
.
LoadDB
(
L"cards.cdb"
))
{
ErrorLog
(
"Failed to load card database (cards.cdb)!"
);
return
false
;
}
...
...
@@ -981,14 +982,37 @@ void Game::SetStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth, irr::gu
dataManager
.
strBuffer
[
pbuffer
]
=
0
;
pControl
->
setText
(
dataManager
.
strBuffer
);
}
void
Game
::
LoadExpansion
DB
()
{
FileSystem
::
TraversalDir
(
"./expansions"
,
[](
const
char
*
name
,
bool
isdir
)
{
if
(
!
isdir
&&
strrchr
(
name
,
'.'
)
&&
!
mystrncasecmp
(
strrchr
(
name
,
'.'
),
".cdb"
,
4
))
{
char
fpath
[
1024
];
sprintf
(
fpath
,
"./expansions/%
s"
,
name
);
void
Game
::
LoadExpansion
s
()
{
FileSystem
::
TraversalDir
(
L"./expansions"
,
[](
const
wchar_t
*
name
,
bool
isdir
)
{
if
(
!
isdir
&&
wcsrchr
(
name
,
'.'
)
&&
!
mywcsncasecmp
(
wcsrchr
(
name
,
'.'
),
L
".cdb"
,
4
))
{
wchar_t
fpath
[
1024
];
myswprintf
(
fpath
,
L"./expansions/%l
s"
,
name
);
dataManager
.
LoadDB
(
fpath
);
}
if
(
!
isdir
&&
wcsrchr
(
name
,
'.'
)
&&
!
mywcsncasecmp
(
wcsrchr
(
name
,
'.'
),
L".zip"
,
4
))
{
wchar_t
fpath
[
1024
];
myswprintf
(
fpath
,
L"./expansions/%ls"
,
name
);
dataManager
.
FileSystem
->
addFileArchive
(
fpath
,
true
,
false
);
}
});
for
(
u32
i
=
0
;
i
<
DataManager
::
FileSystem
->
getFileArchiveCount
();
++
i
)
{
const
IFileList
*
archive
=
DataManager
::
FileSystem
->
getFileArchive
(
i
)
->
getFileList
();
for
(
u32
j
=
0
;
j
<
archive
->
getFileCount
();
++
j
)
{
#ifdef _WIN32
const
wchar_t
*
fname
=
archive
->
getFullFileName
(
j
).
c_str
();
#else
wchar_t
fname
[
1024
];
const
char
*
uname
=
archive
->
getFullFileName
(
j
).
c_str
();
BufferIO
::
DecodeUTF8
(
uname
,
fname
);
#endif
if
(
wcsrchr
(
fname
,
'.'
)
&&
!
mywcsncasecmp
(
wcsrchr
(
fname
,
'.'
),
L".cdb"
,
4
))
dataManager
.
LoadDB
(
fname
);
if
(
wcsrchr
(
fname
,
'.'
)
&&
!
mywcsncasecmp
(
wcsrchr
(
fname
,
'.'
),
L".conf"
,
5
))
{
IReadFile
*
reader
=
DataManager
::
FileSystem
->
createAndOpenFile
(
fname
);
dataManager
.
LoadStrings
(
reader
);
}
}
}
}
void
Game
::
RefreshDeck
(
irr
::
gui
::
IGUIComboBox
*
cbDeck
)
{
cbDeck
->
clear
();
...
...
@@ -2130,13 +2154,18 @@ bool Game::CheckRegEx(const std::wstring& text, const std::wstring& exp, bool ex
const
char
*
Game
::
GetLocaleDir
(
const
char
*
dir
)
{
if
(
!
gameConf
.
locale
||
!
wcscmp
(
gameConf
.
locale
,
L"default"
))
return
dir
;
wchar_t
locale_buf
[
256
];
wchar_t
orig_dir
[
64
];
BufferIO
::
DecodeUTF8
(
dir
,
orig_dir
);
myswprintf
(
locale_buf
,
L"locales/%ls/%ls"
,
gameConf
.
locale
,
orig_dir
);
BufferIO
::
EncodeUTF8
(
locale_buf
,
locale_buf_utf8
);
return
locale_buf_utf8
;
}
const
wchar_t
*
Game
::
GetLocaleDirWide
(
const
char
*
dir
)
{
BufferIO
::
DecodeUTF8
(
dir
,
orig_dir
);
if
(
!
gameConf
.
locale
||
!
wcscmp
(
gameConf
.
locale
,
L"default"
))
return
orig_dir
;
myswprintf
(
locale_buf
,
L"locales/%ls/%ls"
,
gameConf
.
locale
,
orig_dir
);
return
locale_buf
;
}
void
Game
::
SetCursor
(
ECURSOR_ICON
icon
)
{
ICursorControl
*
cursor
=
mainGame
->
device
->
getCursorControl
();
if
(
cursor
->
getActiveIcon
()
!=
icon
)
{
...
...
gframe/game.h
View file @
62dd6c6e
...
...
@@ -129,7 +129,7 @@ public:
void
BuildProjectionMatrix
(
irr
::
core
::
matrix4
&
mProjection
,
f32
left
,
f32
right
,
f32
bottom
,
f32
top
,
f32
znear
,
f32
zfar
);
void
InitStaticText
(
irr
::
gui
::
IGUIStaticText
*
pControl
,
u32
cWidth
,
u32
cHeight
,
irr
::
gui
::
CGUITTFont
*
font
,
const
wchar_t
*
text
);
void
SetStaticText
(
irr
::
gui
::
IGUIStaticText
*
pControl
,
u32
cWidth
,
irr
::
gui
::
CGUITTFont
*
font
,
const
wchar_t
*
text
,
u32
pos
=
0
);
void
LoadExpansion
DB
();
void
LoadExpansion
s
();
void
RefreshDeck
(
irr
::
gui
::
IGUIComboBox
*
cbDeck
);
void
RefreshReplay
();
void
RefreshSingleplay
();
...
...
@@ -170,6 +170,7 @@ public:
int
LocalPlayer
(
int
player
);
const
wchar_t
*
LocalName
(
int
local_player
);
const
char
*
GetLocaleDir
(
const
char
*
dir
);
const
wchar_t
*
GetLocaleDirWide
(
const
char
*
dir
);
bool
CheckRegEx
(
const
std
::
wstring
&
text
,
const
std
::
wstring
&
exp
,
bool
exact
=
false
);
bool
HasFocus
(
EGUI_ELEMENT_TYPE
type
)
const
{
...
...
@@ -250,6 +251,8 @@ public:
float
yScale
;
CGUISkinSystem
*
skinSystem
;
wchar_t
locale_buf
[
256
];
wchar_t
orig_dir
[
64
];
char
locale_buf_utf8
[
256
];
ClientField
dField
;
...
...
gframe/gframe.cpp
View file @
62dd6c6e
...
...
@@ -78,17 +78,13 @@ int main(int argc, char* argv[]) {
bool
keep_on_return
=
false
;
for
(
int
i
=
1
;
i
<
wargc
;
++
i
)
{
if
(
wargv
[
i
][
0
]
==
L'-'
&&
wargv
[
i
][
1
]
==
L'e'
&&
wargv
[
i
][
2
]
!=
L'\0'
)
{
char
param
[
128
];
BufferIO
::
EncodeUTF8
(
&
wargv
[
i
][
2
],
param
);
ygo
::
dataManager
.
LoadDB
(
param
);
ygo
::
dataManager
.
LoadDB
(
&
wargv
[
i
][
2
]);
continue
;
}
if
(
!
wcscmp
(
wargv
[
i
],
L"-e"
))
{
// extra database
++
i
;
if
(
i
<
wargc
)
{
char
param
[
128
];
BufferIO
::
EncodeUTF8
(
wargv
[
i
],
param
);
ygo
::
dataManager
.
LoadDB
(
param
);
ygo
::
dataManager
.
LoadDB
(
wargv
[
i
]);
}
continue
;
}
else
if
(
!
wcscmp
(
wargv
[
i
],
L"-n"
))
{
// nickName
...
...
gframe/spmemvfs.c
0 → 100644
View file @
62dd6c6e
This diff is collapsed.
Click to expand it.
gframe/spmemvfs.h
0 → 100644
View file @
62dd6c6e
/*
* BSD 2-Clause License
*
* Copyright 2009 Stephen Liu
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __spmemvfs_h__
#define __spmemvfs_h__
#ifdef __cplusplus
extern
"C"
{
#endif
#include "sqlite3.h"
#define SPMEMVFS_NAME "spmemvfs"
typedef
struct
spmembuffer_t
{
char
*
data
;
int
used
;
int
total
;
}
spmembuffer_t
;
typedef
struct
spmemvfs_db_t
{
sqlite3
*
handle
;
spmembuffer_t
*
mem
;
}
spmemvfs_db_t
;
int
spmemvfs_env_init
();
void
spmemvfs_env_fini
();
int
spmemvfs_open_db
(
spmemvfs_db_t
*
db
,
const
char
*
path
,
spmembuffer_t
*
mem
);
int
spmemvfs_close_db
(
spmemvfs_db_t
*
db
);
#ifdef __cplusplus
}
#endif
#endif
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