Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Suyu
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
many-archive
Suyu
Commits
40284c68
There was an error fetching the commit references. Please try again later.
Commit
40284c68
authored
5 years ago
by
Zach Hilman
Browse files
Options
Downloads
Patches
Plain Diff
pl_u: Use OSS system archives if real archives don't exist
parent
920742d4
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/core/file_sys/system_archive/shared_font.cpp
+1
-2
1 addition, 2 deletions
src/core/file_sys/system_archive/shared_font.cpp
src/core/hle/service/ns/pl_u.cpp
+47
-110
47 additions, 110 deletions
src/core/hle/service/ns/pl_u.cpp
with
48 additions
and
112 deletions
src/core/file_sys/system_archive/shared_font.cpp
+
1
−
2
View file @
40284c68
...
@@ -23,8 +23,7 @@ VirtualFile PackBFTTF(const std::array<u8, Size>& data, const std::string& name)
...
@@ -23,8 +23,7 @@ VirtualFile PackBFTTF(const std::array<u8, Size>& data, const std::string& name)
std
::
vector
<
u8
>
bfttf
(
Size
+
sizeof
(
u64
));
std
::
vector
<
u8
>
bfttf
(
Size
+
sizeof
(
u64
));
u64
offset
=
0
;
Service
::
NS
::
EncryptSharedFont
(
vec
,
bfttf
);
Service
::
NS
::
EncryptSharedFont
(
vec
,
bfttf
,
offset
);
return
std
::
make_shared
<
VectorVfsFile
>
(
std
::
move
(
bfttf
),
name
);
return
std
::
make_shared
<
VectorVfsFile
>
(
std
::
move
(
bfttf
),
name
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/core/hle/service/ns/pl_u.cpp
+
47
−
110
View file @
40284c68
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
#include
"core/file_sys/nca_metadata.h"
#include
"core/file_sys/nca_metadata.h"
#include
"core/file_sys/registered_cache.h"
#include
"core/file_sys/registered_cache.h"
#include
"core/file_sys/romfs.h"
#include
"core/file_sys/romfs.h"
#include
"core/file_sys/system_archive/system_archive.h"
#include
"core/hle/ipc_helpers.h"
#include
"core/hle/ipc_helpers.h"
#include
"core/hle/kernel/shared_memory.h"
#include
"core/hle/kernel/shared_memory.h"
#include
"core/hle/service/filesystem/filesystem.h"
#include
"core/hle/service/filesystem/filesystem.h"
...
@@ -94,15 +95,16 @@ static void DecryptSharedFont(const std::vector<u32>& input, Kernel::PhysicalMem
...
@@ -94,15 +95,16 @@ static void DecryptSharedFont(const std::vector<u32>& input, Kernel::PhysicalMem
offset
+=
transformed_font
.
size
()
*
sizeof
(
u32
);
offset
+=
transformed_font
.
size
()
*
sizeof
(
u32
);
}
}
static
void
EncryptSharedFont
(
const
std
::
vector
<
u8
>&
input
,
Kernel
::
PhysicalMemory
&
output
,
static
void
EncryptSharedFont
(
const
std
::
vector
<
u8
>&
input
,
Kernel
::
PhysicalMemory
&
output
)
{
std
::
size_t
&
offset
)
{
ASSERT_MSG
(
input
.
size
()
*
sizeof
(
u32
)
<
SHARED_FONT_MEM_SIZE
,
"Shared fonts exceeds 17mb!"
);
ASSERT_MSG
(
offset
+
input
.
size
()
+
8
<
SHARED_FONT_MEM_SIZE
,
"Shared fonts exceeds 17mb!"
);
const
u32
KEY
=
EXPECTED_MAGIC
^
EXPECTED_RESULT
;
const
auto
key
=
Common
::
swap32
(
EXPECTED_RESULT
^
EXPECTED_MAGIC
);
std
::
memcpy
(
output
.
data
()
+
offset
,
&
EXPECTED_RESULT
,
sizeof
(
u32
));
// Magic header
std
::
vector
<
u32
>
transformed_font
(
input
.
size
()
+
2
);
const
u32
ENC_SIZE
=
static_cast
<
u32
>
(
input
.
size
())
^
KEY
;
transformed_font
[
0
]
=
Common
::
swap32
(
EXPECTED_MAGIC
);
std
::
memcpy
(
output
.
data
()
+
offset
+
sizeof
(
u32
),
&
ENC_SIZE
,
sizeof
(
u32
));
transformed_font
[
1
]
=
Common
::
swap32
(
input
.
size
()
*
sizeof
(
u32
))
^
key
;
std
::
memcpy
(
output
.
data
()
+
offset
+
(
sizeof
(
u32
)
*
2
),
input
.
data
(),
input
.
size
());
std
::
transform
(
input
.
begin
(),
input
.
end
(),
transformed_font
.
begin
()
+
2
,
offset
+=
input
.
size
()
+
(
sizeof
(
u32
)
*
2
);
[
key
](
u32
in
)
{
return
in
^
key
;
});
std
::
memcpy
(
output
.
data
(),
transformed_font
.
data
(),
transformed_font
.
size
()
*
sizeof
(
u32
));
}
}
// Helper function to make BuildSharedFontsRawRegions a bit nicer
// Helper function to make BuildSharedFontsRawRegions a bit nicer
...
@@ -168,114 +170,49 @@ PL_U::PL_U(Core::System& system)
...
@@ -168,114 +170,49 @@ PL_U::PL_U(Core::System& system)
// Attempt to load shared font data from disk
// Attempt to load shared font data from disk
const
auto
*
nand
=
fsc
.
GetSystemNANDContents
();
const
auto
*
nand
=
fsc
.
GetSystemNANDContents
();
std
::
size_t
offset
=
0
;
std
::
size_t
offset
=
0
;
// Rebuild shared fonts from data ncas
// Rebuild shared fonts from data ncas or synthesize
if
(
nand
->
HasEntry
(
static_cast
<
u64
>
(
FontArchives
::
Standard
),
FileSys
::
ContentRecordType
::
Data
))
{
impl
->
shared_font
=
std
::
make_shared
<
Kernel
::
PhysicalMemory
>
(
SHARED_FONT_MEM_SIZE
);
impl
->
shared_font
=
std
::
make_shared
<
Kernel
::
PhysicalMemory
>
(
SHARED_FONT_MEM_SIZE
);
for
(
auto
font
:
SHARED_FONTS
)
{
for
(
auto
font
:
SHARED_FONTS
)
{
FileSys
::
VirtualFile
romfs
;
const
auto
nca
=
const
auto
nca
=
nand
->
GetEntry
(
static_cast
<
u64
>
(
font
.
first
),
FileSys
::
ContentRecordType
::
Data
);
nand
->
GetEntry
(
static_cast
<
u64
>
(
font
.
first
),
FileSys
::
ContentRecordType
::
Data
);
if
(
!
nca
)
{
if
(
nca
)
{
LOG_ERROR
(
Service_NS
,
"Failed to find {:016X}! Skipping"
,
romfs
=
nca
->
GetRomFS
();
static_cast
<
u64
>
(
font
.
first
));
continue
;
}
const
auto
romfs
=
nca
->
GetRomFS
();
if
(
!
romfs
)
{
LOG_ERROR
(
Service_NS
,
"{:016X} has no RomFS! Skipping"
,
static_cast
<
u64
>
(
font
.
first
));
continue
;
}
const
auto
extracted_romfs
=
FileSys
::
ExtractRomFS
(
romfs
);
if
(
!
extracted_romfs
)
{
LOG_ERROR
(
Service_NS
,
"Failed to extract RomFS for {:016X}! Skipping"
,
static_cast
<
u64
>
(
font
.
first
));
continue
;
}
const
auto
font_fp
=
extracted_romfs
->
GetFile
(
font
.
second
);
if
(
!
font_fp
)
{
LOG_ERROR
(
Service_NS
,
"{:016X} has no file
\"
{}
\"
! Skipping"
,
static_cast
<
u64
>
(
font
.
first
),
font
.
second
);
continue
;
}
std
::
vector
<
u32
>
font_data_u32
(
font_fp
->
GetSize
()
/
sizeof
(
u32
));
font_fp
->
ReadBytes
<
u32
>
(
font_data_u32
.
data
(),
font_fp
->
GetSize
());
// We need to be BigEndian as u32s for the xor encryption
std
::
transform
(
font_data_u32
.
begin
(),
font_data_u32
.
end
(),
font_data_u32
.
begin
(),
Common
::
swap32
);
FontRegion
region
{
static_cast
<
u32
>
(
offset
+
8
),
static_cast
<
u32
>
((
font_data_u32
.
size
()
*
sizeof
(
u32
))
-
8
)};
// Font offset and size do not account for the header
DecryptSharedFont
(
font_data_u32
,
*
impl
->
shared_font
,
offset
);
impl
->
shared_font_regions
.
push_back
(
region
);
}
}
}
else
{
if
(
!
romfs
)
{
impl
->
shared_font
=
std
::
make_shared
<
Kernel
::
PhysicalMemory
>
(
romfs
=
FileSys
::
SystemArchive
::
SynthesizeSystemArchive
(
static_cast
<
u64
>
(
font
.
first
));
SHARED_FONT_MEM_SIZE
);
// Shared memory needs to always be allocated and a fixed size
}
const
std
::
string
user_path
=
FileUtil
::
GetUserPath
(
FileUtil
::
UserPath
::
SysDataDir
);
const
std
::
string
filepath
{
user_path
+
SHARED_FONT
};
// Create path if not already created
if
(
!
romfs
)
{
if
(
!
FileUtil
::
CreateFullPath
(
filepath
))
{
LOG_ERROR
(
Service_NS
,
"Failed to find or synthesize {:016X}! Skipping"
,
LOG_ERROR
(
Service_NS
,
"Failed to create sharedfonts path
\"
{}
\"
!"
,
filepath
);
static_cast
<
u64
>
(
font
.
first
)
);
return
;
continue
;
}
}
bool
using_ttf
=
false
;
const
auto
extracted_romfs
=
FileSys
::
ExtractRomFS
(
romfs
);
for
(
const
char
*
font_ttf
:
SHARED_FONTS_TTF
)
{
if
(
!
extracted_romfs
)
{
if
(
FileUtil
::
Exists
(
user_path
+
font_ttf
))
{
LOG_ERROR
(
Service_NS
,
"Failed to extract RomFS for {:016X}! Skipping"
,
using_ttf
=
true
;
static_cast
<
u64
>
(
font
.
first
));
FileUtil
::
IOFile
file
(
user_path
+
font_ttf
,
"rb"
);
continue
;
if
(
file
.
IsOpen
())
{
std
::
vector
<
u8
>
ttf_bytes
(
file
.
GetSize
());
file
.
ReadBytes
<
u8
>
(
ttf_bytes
.
data
(),
ttf_bytes
.
size
());
FontRegion
region
{
static_cast
<
u32
>
(
offset
+
8
),
static_cast
<
u32
>
(
ttf_bytes
.
size
())};
// Font offset and size do not account
// for the header
EncryptSharedFont
(
ttf_bytes
,
*
impl
->
shared_font
,
offset
);
impl
->
shared_font_regions
.
push_back
(
region
);
}
else
{
LOG_WARNING
(
Service_NS
,
"Unable to load font: {}"
,
font_ttf
);
}
}
else
if
(
using_ttf
)
{
LOG_WARNING
(
Service_NS
,
"Unable to find font: {}"
,
font_ttf
);
}
}
}
if
(
using_ttf
)
const
auto
font_fp
=
extracted_romfs
->
GetFile
(
font
.
second
);
return
;
if
(
!
font_fp
)
{
FileUtil
::
IOFile
file
(
filepath
,
"rb"
);
LOG_ERROR
(
Service_NS
,
"{:016X} has no file
\"
{}
\"
! Skipping"
,
static_cast
<
u64
>
(
font
.
first
),
font
.
second
);
if
(
file
.
IsOpen
())
{
continue
;
// Read shared font data
ASSERT
(
file
.
GetSize
()
==
SHARED_FONT_MEM_SIZE
);
file
.
ReadBytes
(
impl
->
shared_font
->
data
(),
impl
->
shared_font
->
size
());
impl
->
BuildSharedFontsRawRegions
(
*
impl
->
shared_font
);
}
else
{
LOG_WARNING
(
Service_NS
,
"Shared Font file missing. Loading open source replacement from memory"
);
// clang-format off
const
std
::
vector
<
std
::
vector
<
u8
>>
open_source_shared_fonts_ttf
=
{
{
std
::
begin
(
FontChineseSimplified
),
std
::
end
(
FontChineseSimplified
)},
{
std
::
begin
(
FontChineseTraditional
),
std
::
end
(
FontChineseTraditional
)},
{
std
::
begin
(
FontExtendedChineseSimplified
),
std
::
end
(
FontExtendedChineseSimplified
)},
{
std
::
begin
(
FontKorean
),
std
::
end
(
FontKorean
)},
{
std
::
begin
(
FontNintendoExtended
),
std
::
end
(
FontNintendoExtended
)},
{
std
::
begin
(
FontStandard
),
std
::
end
(
FontStandard
)},
};
// clang-format on
for
(
const
std
::
vector
<
u8
>&
font_ttf
:
open_source_shared_fonts_ttf
)
{
const
FontRegion
region
{
static_cast
<
u32
>
(
offset
+
8
),
static_cast
<
u32
>
(
font_ttf
.
size
())};
EncryptSharedFont
(
font_ttf
,
*
impl
->
shared_font
,
offset
);
impl
->
shared_font_regions
.
push_back
(
region
);
}
}
}
std
::
vector
<
u32
>
font_data_u32
(
font_fp
->
GetSize
()
/
sizeof
(
u32
));
font_fp
->
ReadBytes
<
u32
>
(
font_data_u32
.
data
(),
font_fp
->
GetSize
());
// We need to be BigEndian as u32s for the xor encryption
std
::
transform
(
font_data_u32
.
begin
(),
font_data_u32
.
end
(),
font_data_u32
.
begin
(),
Common
::
swap32
);
// Font offset and size do not account for the header
const
FontRegion
region
{
static_cast
<
u32
>
(
offset
+
8
),
static_cast
<
u32
>
((
font_data_u32
.
size
()
*
sizeof
(
u32
))
-
8
)};
DecryptSharedFont
(
font_data_u32
,
*
impl
->
shared_font
,
offset
);
impl
->
shared_font_regions
.
push_back
(
region
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment