Skip to content

Commit f2d87ce

Browse files
committed
Merge branch 'main' of https://github.com/shadps4-emu/shadPS4 into posixiofile
2 parents d866877 + 5b46216 commit f2d87ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+4785
-1253
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ set(COMMON src/common/logging/backend.cpp
679679
src/common/enum.h
680680
src/common/io_file.cpp
681681
src/common/io_file.h
682+
src/common/lru_cache.h
682683
src/common/error.cpp
683684
src/common/error.h
684685
src/common/scope_exit.h
@@ -768,6 +769,8 @@ set(CORE src/core/aerolib/stubs.cpp
768769
src/core/file_format/trp.h
769770
src/core/file_sys/fs.cpp
770771
src/core/file_sys/fs.h
772+
src/core/ipc/ipc.cpp
773+
src/core/ipc/ipc.h
771774
src/core/loader/dwarf.cpp
772775
src/core/loader/dwarf.h
773776
src/core/loader/elf.cpp
@@ -1087,6 +1090,9 @@ set(QT_GUI src/qt_gui/about_dialog.cpp
10871090
src/qt_gui/settings.h
10881091
src/qt_gui/sdl_event_wrapper.cpp
10891092
src/qt_gui/sdl_event_wrapper.h
1093+
src/qt_gui/hotkeys.h
1094+
src/qt_gui/hotkeys.cpp
1095+
src/qt_gui/hotkeys.ui
10901096
${EMULATOR}
10911097
${RESOURCE_FILES}
10921098
${TRANSLATIONS}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ The following firmware modules are supported and must be placed in shadPS4's `sy
133133
|-------------------------|-------------------------|-------------------------|-------------------------|
134134
| libSceCesCs.sprx | libSceFont.sprx | libSceFontFt.sprx | libSceFreeTypeOt.sprx |
135135
| libSceJson.sprx | libSceJson2.sprx | libSceLibcInternal.sprx | libSceNgs2.sprx |
136-
| libSceRtc.sprx | libSceUlt.sprx | | |
136+
| libSceUlt.sprx | | | |
137137

138138
</div>
139139

REUSE.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ path = [
7474
"src/images/website.svg",
7575
"src/images/youtube.svg",
7676
"src/images/trophy.wav",
77+
"src/images/hotkey.png",
7778
"src/shadps4.qrc",
7879
"src/shadps4.rc",
7980
"src/qt_gui/translations/update_translation.sh",

src/common/config.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static int specialPadClass = 1;
5757
static bool isMotionControlsEnabled = true;
5858
static bool useUnifiedInputConfig = true;
5959
static std::string micDevice = "Default Device";
60+
static std::string defaultControllerID = "";
6061

6162
// These two entries aren't stored in the config
6263
static bool overrideControllerColor = false;
@@ -612,6 +613,14 @@ void setPSNSignedIn(bool sign) {
612613
isPSNSignedIn = sign;
613614
}
614615

616+
std::string getDefaultControllerID() {
617+
return defaultControllerID;
618+
}
619+
620+
void setDefaultControllerID(std::string id) {
621+
defaultControllerID = id;
622+
}
623+
615624
void load(const std::filesystem::path& path) {
616625
// If the configuration file does not exist, create it and return
617626
std::error_code error;
@@ -656,6 +665,7 @@ void load(const std::filesystem::path& path) {
656665
isConnectedToNetwork =
657666
toml::find_or<bool>(general, "isConnectedToNetwork", isConnectedToNetwork);
658667
chooseHomeTab = toml::find_or<std::string>(general, "chooseHomeTab", chooseHomeTab);
668+
defaultControllerID = toml::find_or<std::string>(general, "defaultControllerID", "");
659669
}
660670

661671
if (data.contains("Input")) {
@@ -837,6 +847,7 @@ void save(const std::filesystem::path& path) {
837847
data["General"]["compatibilityEnabled"] = compatibilityData;
838848
data["General"]["checkCompatibilityOnStartup"] = checkCompatibilityOnStartup;
839849
data["General"]["isConnectedToNetwork"] = isConnectedToNetwork;
850+
data["General"]["defaultControllerID"] = defaultControllerID;
840851
data["Input"]["cursorState"] = cursorState;
841852
data["Input"]["cursorHideTimeout"] = cursorHideTimeout;
842853
data["Input"]["useSpecialPad"] = useSpecialPad;

src/common/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ bool isDevKitConsole(); // no set
107107
bool vkValidationGpuEnabled(); // no set
108108
bool getIsMotionControlsEnabled();
109109
void setIsMotionControlsEnabled(bool use);
110+
std::string getDefaultControllerID();
111+
void setDefaultControllerID(std::string id);
110112

111113
// TODO
112114
bool GetLoadGameSizeEnabled();

src/common/lru_cache.h

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
2+
// SPDX-License-Identifier: GPL-2.0-or-later
3+
4+
#pragma once
5+
6+
#include <deque>
7+
#include <type_traits>
8+
9+
#include "common/types.h"
10+
11+
namespace Common {
12+
13+
template <typename ObjectType, typename TickType>
14+
class LeastRecentlyUsedCache {
15+
struct Item {
16+
ObjectType obj;
17+
TickType tick;
18+
Item* next{};
19+
Item* prev{};
20+
};
21+
22+
public:
23+
LeastRecentlyUsedCache() : first_item{}, last_item{} {}
24+
~LeastRecentlyUsedCache() = default;
25+
26+
size_t Insert(ObjectType obj, TickType tick) {
27+
const auto new_id = Build();
28+
auto& item = item_pool[new_id];
29+
item.obj = obj;
30+
item.tick = tick;
31+
Attach(item);
32+
return new_id;
33+
}
34+
35+
void Touch(size_t id, TickType tick) {
36+
auto& item = item_pool[id];
37+
if (item.tick >= tick) {
38+
return;
39+
}
40+
item.tick = tick;
41+
if (&item == last_item) {
42+
return;
43+
}
44+
Detach(item);
45+
Attach(item);
46+
}
47+
48+
void Free(size_t id) {
49+
auto& item = item_pool[id];
50+
Detach(item);
51+
item.prev = nullptr;
52+
item.next = nullptr;
53+
free_items.push_back(id);
54+
}
55+
56+
template <typename Func>
57+
void ForEachItemBelow(TickType tick, Func&& func) {
58+
static constexpr bool RETURNS_BOOL =
59+
std::is_same_v<std::invoke_result<Func, ObjectType>, bool>;
60+
Item* iterator = first_item;
61+
while (iterator) {
62+
if (static_cast<s64>(tick) - static_cast<s64>(iterator->tick) < 0) {
63+
return;
64+
}
65+
Item* next = iterator->next;
66+
if constexpr (RETURNS_BOOL) {
67+
if (func(iterator->obj)) {
68+
return;
69+
}
70+
} else {
71+
func(iterator->obj);
72+
}
73+
iterator = next;
74+
}
75+
}
76+
77+
private:
78+
size_t Build() {
79+
if (free_items.empty()) {
80+
const size_t item_id = item_pool.size();
81+
auto& item = item_pool.emplace_back();
82+
item.next = nullptr;
83+
item.prev = nullptr;
84+
return item_id;
85+
}
86+
const size_t item_id = free_items.front();
87+
free_items.pop_front();
88+
auto& item = item_pool[item_id];
89+
item.next = nullptr;
90+
item.prev = nullptr;
91+
return item_id;
92+
}
93+
94+
void Attach(Item& item) {
95+
if (!first_item) {
96+
first_item = &item;
97+
}
98+
if (!last_item) {
99+
last_item = &item;
100+
} else {
101+
item.prev = last_item;
102+
last_item->next = &item;
103+
item.next = nullptr;
104+
last_item = &item;
105+
}
106+
}
107+
108+
void Detach(Item& item) {
109+
if (item.prev) {
110+
item.prev->next = item.next;
111+
}
112+
if (item.next) {
113+
item.next->prev = item.prev;
114+
}
115+
if (&item == first_item) {
116+
first_item = item.next;
117+
if (first_item) {
118+
first_item->prev = nullptr;
119+
}
120+
}
121+
if (&item == last_item) {
122+
last_item = item.prev;
123+
if (last_item) {
124+
last_item->next = nullptr;
125+
}
126+
}
127+
}
128+
129+
std::deque<Item> item_pool;
130+
std::deque<size_t> free_items;
131+
Item* first_item{};
132+
Item* last_item{};
133+
};
134+
135+
} // namespace Common

src/common/memory_patcher.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ EXPORT uintptr_t g_eboot_address;
2929
uint64_t g_eboot_image_size;
3030
std::string g_game_serial;
3131
std::string patchFile;
32+
bool patches_applied = false;
3233
std::vector<patchInfo> pending_patches;
3334

3435
std::string toHex(u64 value, size_t byteSize) {
@@ -119,6 +120,8 @@ std::string convertValueToHex(const std::string type, const std::string valueStr
119120
return result;
120121
}
121122

123+
void ApplyPendingPatches();
124+
122125
void OnGameLoaded() {
123126

124127
if (!patchFile.empty()) {
@@ -377,20 +380,26 @@ void OnGameLoaded() {
377380
}
378381

379382
void AddPatchToQueue(patchInfo patchToAdd) {
383+
if (patches_applied) {
384+
PatchMemory(patchToAdd.modNameStr, patchToAdd.offsetStr, patchToAdd.valueStr,
385+
patchToAdd.targetStr, patchToAdd.sizeStr, patchToAdd.isOffset,
386+
patchToAdd.littleEndian, patchToAdd.patchMask, patchToAdd.maskOffset);
387+
return;
388+
}
380389
pending_patches.push_back(patchToAdd);
381390
}
382391

383392
void ApplyPendingPatches() {
384-
393+
patches_applied = true;
385394
for (size_t i = 0; i < pending_patches.size(); ++i) {
386-
patchInfo currentPatch = pending_patches[i];
395+
const patchInfo& currentPatch = pending_patches[i];
387396

388-
if (currentPatch.gameSerial != g_game_serial)
397+
if (currentPatch.gameSerial != "*" && currentPatch.gameSerial != g_game_serial)
389398
continue;
390399

391-
PatchMemory(currentPatch.modNameStr, currentPatch.offsetStr, currentPatch.valueStr, "", "",
392-
currentPatch.isOffset, currentPatch.littleEndian, currentPatch.patchMask,
393-
currentPatch.maskOffset);
400+
PatchMemory(currentPatch.modNameStr, currentPatch.offsetStr, currentPatch.valueStr,
401+
currentPatch.targetStr, currentPatch.sizeStr, currentPatch.isOffset,
402+
currentPatch.littleEndian, currentPatch.patchMask, currentPatch.maskOffset);
394403
}
395404

396405
pending_patches.clear();

src/common/memory_patcher.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,18 @@ struct patchInfo {
3030
std::string modNameStr;
3131
std::string offsetStr;
3232
std::string valueStr;
33+
std::string targetStr;
34+
std::string sizeStr;
3335
bool isOffset;
3436
bool littleEndian;
3537
PatchMask patchMask;
3638
int maskOffset;
3739
};
3840

39-
extern std::vector<patchInfo> pending_patches;
40-
4141
std::string convertValueToHex(const std::string type, const std::string valueStr);
4242

4343
void OnGameLoaded();
4444
void AddPatchToQueue(patchInfo patchToAdd);
45-
void ApplyPendingPatches();
4645

4746
void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valueStr,
4847
std::string targetStr, std::string sizeStr, bool isOffset, bool littleEndian,

0 commit comments

Comments
 (0)