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
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
Commits
00db8d75
Commit
00db8d75
authored
Oct 09, 2024
by
wind2009
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'salix5/patch-readdb' into develop
parents
9d2aa9a8
54b1534a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
43 deletions
+49
-43
gframe/data_manager.cpp
gframe/data_manager.cpp
+46
-42
gframe/data_manager.h
gframe/data_manager.h
+3
-1
No files found.
gframe/data_manager.cpp
View file @
00db8d75
...
@@ -16,40 +16,20 @@ DataManager::DataManager() : _datas(16384), _strings(16384) {
...
@@ -16,40 +16,20 @@ DataManager::DataManager() : _datas(16384), _strings(16384) {
strings_end
=
_strings
.
end
();
strings_end
=
_strings
.
end
();
extra_setcode
=
{
{
8512558u
,
{
0x8f
,
0x54
,
0x59
,
0x82
,
0x13a
}},
};
extra_setcode
=
{
{
8512558u
,
{
0x8f
,
0x54
,
0x59
,
0x82
,
0x13a
}},
};
}
}
bool
DataManager
::
LoadDB
(
const
wchar_t
*
wfile
)
{
bool
DataManager
::
ReadDB
(
sqlite3
*
pDB
)
{
char
file
[
256
];
sqlite3_stmt
*
pStmt
{};
BufferIO
::
EncodeUTF8
(
wfile
,
file
);
#ifdef _WIN32
IReadFile
*
reader
=
FileSystem
->
createAndOpenFile
(
wfile
);
#else
IReadFile
*
reader
=
FileSystem
->
createAndOpenFile
(
file
);
#endif
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'
;
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"
;
const
char
*
sql
=
"select * from datas,texts where datas.id=texts.id"
;
if
(
sqlite3_prepare_v2
(
pDB
,
sql
,
-
1
,
&
pStmt
,
0
)
!=
SQLITE_OK
)
if
(
sqlite3_prepare_v2
(
pDB
,
sql
,
-
1
,
&
pStmt
,
0
)
!=
SQLITE_OK
)
return
Error
(
&
db
);
return
Error
(
pDB
);
wchar_t
strBuffer
[
4096
];
wchar_t
strBuffer
[
4096
];
int
step
=
0
;
int
step
=
0
;
do
{
do
{
CardDataC
cd
;
CardDataC
cd
;
CardString
cs
;
CardString
cs
;
step
=
sqlite3_step
(
pStmt
);
step
=
sqlite3_step
(
pStmt
);
if
(
step
==
SQLITE_BUSY
||
step
==
SQLITE_ERROR
||
step
==
SQLITE_MISUSE
)
if
(
step
==
SQLITE_BUSY
||
step
==
SQLITE_ERROR
||
step
==
SQLITE_MISUSE
)
return
Error
(
&
db
,
pStmt
);
return
Error
(
pDB
,
pStmt
);
else
if
(
step
==
SQLITE_ROW
)
{
else
if
(
step
==
SQLITE_ROW
)
{
cd
.
code
=
sqlite3_column_int
(
pStmt
,
0
);
cd
.
code
=
sqlite3_column_int
(
pStmt
,
0
);
cd
.
ot
=
sqlite3_column_int
(
pStmt
,
1
);
cd
.
ot
=
sqlite3_column_int
(
pStmt
,
1
);
cd
.
alias
=
sqlite3_column_int
(
pStmt
,
2
);
cd
.
alias
=
sqlite3_column_int
(
pStmt
,
2
);
...
@@ -69,10 +49,11 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
...
@@ -69,10 +49,11 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
cd
.
type
=
sqlite3_column_int
(
pStmt
,
4
);
cd
.
type
=
sqlite3_column_int
(
pStmt
,
4
);
cd
.
attack
=
sqlite3_column_int
(
pStmt
,
5
);
cd
.
attack
=
sqlite3_column_int
(
pStmt
,
5
);
cd
.
defense
=
sqlite3_column_int
(
pStmt
,
6
);
cd
.
defense
=
sqlite3_column_int
(
pStmt
,
6
);
if
(
cd
.
type
&
TYPE_LINK
)
{
if
(
cd
.
type
&
TYPE_LINK
)
{
cd
.
link_marker
=
cd
.
defense
;
cd
.
link_marker
=
cd
.
defense
;
cd
.
defense
=
0
;
cd
.
defense
=
0
;
}
else
}
else
cd
.
link_marker
=
0
;
cd
.
link_marker
=
0
;
unsigned
int
level
=
sqlite3_column_int
(
pStmt
,
7
);
unsigned
int
level
=
sqlite3_column_int
(
pStmt
,
7
);
cd
.
level
=
level
&
0xff
;
cd
.
level
=
level
&
0xff
;
...
@@ -82,32 +63,57 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
...
@@ -82,32 +63,57 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
cd
.
attribute
=
sqlite3_column_int
(
pStmt
,
9
);
cd
.
attribute
=
sqlite3_column_int
(
pStmt
,
9
);
cd
.
category
=
sqlite3_column_int
(
pStmt
,
10
);
cd
.
category
=
sqlite3_column_int
(
pStmt
,
10
);
_datas
[
cd
.
code
]
=
cd
;
_datas
[
cd
.
code
]
=
cd
;
if
(
const
char
*
text
=
(
const
char
*
)
sqlite3_column_text
(
pStmt
,
12
))
{
if
(
const
char
*
text
=
(
const
char
*
)
sqlite3_column_text
(
pStmt
,
12
))
{
BufferIO
::
DecodeUTF8
(
text
,
strBuffer
);
BufferIO
::
DecodeUTF8
(
text
,
strBuffer
);
cs
.
name
=
strBuffer
;
cs
.
name
=
strBuffer
;
}
}
if
(
const
char
*
text
=
(
const
char
*
)
sqlite3_column_text
(
pStmt
,
13
))
{
if
(
const
char
*
text
=
(
const
char
*
)
sqlite3_column_text
(
pStmt
,
13
))
{
BufferIO
::
DecodeUTF8
(
text
,
strBuffer
);
BufferIO
::
DecodeUTF8
(
text
,
strBuffer
);
cs
.
text
=
strBuffer
;
cs
.
text
=
strBuffer
;
}
}
for
(
int
i
=
0
;
i
<
16
;
++
i
)
{
for
(
int
i
=
0
;
i
<
16
;
++
i
)
{
if
(
const
char
*
text
=
(
const
char
*
)
sqlite3_column_text
(
pStmt
,
i
+
14
))
{
if
(
const
char
*
text
=
(
const
char
*
)
sqlite3_column_text
(
pStmt
,
i
+
14
))
{
BufferIO
::
DecodeUTF8
(
text
,
strBuffer
);
BufferIO
::
DecodeUTF8
(
text
,
strBuffer
);
cs
.
desc
[
i
]
=
strBuffer
;
cs
.
desc
[
i
]
=
strBuffer
;
}
}
}
}
_strings
[
cd
.
code
]
=
cs
;
_strings
[
cd
.
code
]
=
cs
;
}
}
}
while
(
step
!=
SQLITE_DONE
);
}
while
(
step
!=
SQLITE_DONE
);
sqlite3_finalize
(
pStmt
);
spmemvfs_close_db
(
&
db
);
spmemvfs_env_fini
();
datas_begin
=
_datas
.
begin
();
datas_begin
=
_datas
.
begin
();
datas_end
=
_datas
.
end
();
datas_end
=
_datas
.
end
();
strings_begin
=
_strings
.
begin
();
strings_begin
=
_strings
.
begin
();
strings_end
=
_strings
.
end
();
strings_end
=
_strings
.
end
();
sqlite3_finalize
(
pStmt
);
return
true
;
return
true
;
}
}
bool
DataManager
::
LoadDB
(
const
wchar_t
*
wfile
)
{
char
file
[
256
];
BufferIO
::
EncodeUTF8
(
wfile
,
file
);
#ifdef _WIN32
IReadFile
*
reader
=
FileSystem
->
createAndOpenFile
(
wfile
);
#else
IReadFile
*
reader
=
FileSystem
->
createAndOpenFile
(
file
);
#endif
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'
;
bool
ret
{};
if
(
spmemvfs_open_db
(
&
db
,
file
,
mem
)
!=
SQLITE_OK
)
ret
=
Error
(
db
.
handle
);
else
ret
=
ReadDB
(
db
.
handle
);
spmemvfs_close_db
(
&
db
);
spmemvfs_env_fini
();
return
ret
;
}
bool
DataManager
::
LoadStrings
(
const
char
*
file
)
{
bool
DataManager
::
LoadStrings
(
const
char
*
file
)
{
FILE
*
fp
=
fopen
(
file
,
"r"
);
FILE
*
fp
=
fopen
(
file
,
"r"
);
if
(
!
fp
)
if
(
!
fp
)
...
@@ -167,13 +173,11 @@ void DataManager::ReadStringConfLine(const char* linebuf) {
...
@@ -167,13 +173,11 @@ void DataManager::ReadStringConfLine(const char* linebuf) {
_setnameStrings
[
value
]
=
strBuffer
;
_setnameStrings
[
value
]
=
strBuffer
;
}
}
}
}
bool
DataManager
::
Error
(
s
pmemvfs_db_t
*
pDB
,
sqlite3_stmt
*
pStmt
)
{
bool
DataManager
::
Error
(
s
qlite3
*
pDB
,
sqlite3_stmt
*
pStmt
)
{
wchar_t
strBuffer
[
4096
]
;
std
::
strncpy
(
errmsg
,
sqlite3_errmsg
(
pDB
),
sizeof
errmsg
)
;
BufferIO
::
DecodeUTF8
(
sqlite3_errmsg
(
pDB
->
handle
),
strBuffer
);
BufferIO
::
NullTerminate
(
errmsg
);
if
(
pStmt
)
if
(
pStmt
)
sqlite3_finalize
(
pStmt
);
sqlite3_finalize
(
pStmt
);
spmemvfs_close_db
(
pDB
);
spmemvfs_env_fini
();
return
false
;
return
false
;
}
}
bool
DataManager
::
GetData
(
unsigned
int
code
,
CardData
*
pData
)
const
{
bool
DataManager
::
GetData
(
unsigned
int
code
,
CardData
*
pData
)
const
{
...
...
gframe/data_manager.h
View file @
00db8d75
...
@@ -14,11 +14,12 @@ namespace ygo {
...
@@ -14,11 +14,12 @@ namespace ygo {
class
DataManager
{
class
DataManager
{
public:
public:
DataManager
();
DataManager
();
bool
ReadDB
(
sqlite3
*
pDB
);
bool
LoadDB
(
const
wchar_t
*
wfile
);
bool
LoadDB
(
const
wchar_t
*
wfile
);
bool
LoadStrings
(
const
char
*
file
);
bool
LoadStrings
(
const
char
*
file
);
bool
LoadStrings
(
IReadFile
*
reader
);
bool
LoadStrings
(
IReadFile
*
reader
);
void
ReadStringConfLine
(
const
char
*
linebuf
);
void
ReadStringConfLine
(
const
char
*
linebuf
);
bool
Error
(
s
pmemvfs_db_t
*
pDB
,
sqlite3_stmt
*
pStmt
=
0
);
bool
Error
(
s
qlite3
*
pDB
,
sqlite3_stmt
*
pStmt
=
nullptr
);
bool
GetData
(
unsigned
int
code
,
CardData
*
pData
)
const
;
bool
GetData
(
unsigned
int
code
,
CardData
*
pData
)
const
;
code_pointer
GetCodePointer
(
unsigned
int
code
)
const
;
code_pointer
GetCodePointer
(
unsigned
int
code
)
const
;
string_pointer
GetStringPointer
(
unsigned
int
code
)
const
;
string_pointer
GetStringPointer
(
unsigned
int
code
)
const
;
...
@@ -55,6 +56,7 @@ public:
...
@@ -55,6 +56,7 @@ public:
wchar_t
tpBuffer
[
128
]{};
wchar_t
tpBuffer
[
128
]{};
wchar_t
scBuffer
[
128
]{};
wchar_t
scBuffer
[
128
]{};
wchar_t
lmBuffer
[
32
]{};
wchar_t
lmBuffer
[
32
]{};
char
errmsg
[
512
]{};
static
byte
scriptBuffer
[
0x20000
];
static
byte
scriptBuffer
[
0x20000
];
static
const
wchar_t
*
unknown_string
;
static
const
wchar_t
*
unknown_string
;
...
...
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