Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Common/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ enum class Log {
IAP,
CwCheats,
Net, // Non-sce related networking logs.
Script,

sceAudio,
sceCtrl,
Expand Down
1 change: 1 addition & 0 deletions Common/Log/LogManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ static const char * const g_logTypeNames[] = {
"IAP",
"CWCHEATS",
"NET",
"SCRIPT",
"SCEAUDIO",
"SCECTRL",
"SCEDISP",
Expand Down
2 changes: 2 additions & 0 deletions Core/ConfigSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,6 @@ struct ConfigSetting {
// We only support transform for ints.
std::string (*translateTo_)(int) = nullptr;
int (*translateFrom_)(const std::string &) = nullptr;

static std::unordered_map<void*, ConfigSetting*> &getPtrLUT();
};
4 changes: 2 additions & 2 deletions Core/Debugger/SymbolMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,9 @@ std::vector<SymbolEntry> SymbolMap::GetAllActiveSymbols(SymbolType symmask) {

std::vector<SymbolEntry> result;

std::lock_guard<std::recursive_mutex> guard(lock_);

if (symmask & ST_FUNCTION) {
std::lock_guard<std::recursive_mutex> guard(lock_);
for (auto it = activeFunctions.begin(); it != activeFunctions.end(); it++) {
SymbolEntry entry;
entry.address = it->first;
Expand All @@ -496,7 +497,6 @@ std::vector<SymbolEntry> SymbolMap::GetAllActiveSymbols(SymbolType symmask) {
}

if (symmask & ST_DATA) {
std::lock_guard<std::recursive_mutex> guard(lock_);
for (auto it = activeData.begin(); it != activeData.end(); it++) {
SymbolEntry entry;
entry.address = it->first;
Expand Down
6 changes: 2 additions & 4 deletions Core/FileSystems/MetaFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ class MetaFileSystem : public IHandleAllocator, public IFileSystem {
IFileSystem *GetSystemFromFilename(std::string_view filename);
IFileSystem *GetHandleOwner(u32 handle) const;
FileSystemFlags FlagsFromFilename(std::string_view filename) {
IFileSystem *sys = GetSystemFromFilename(filename);
const IFileSystem *sys = GetSystemFromFilename(filename);
return sys ? sys->Flags() : FileSystemFlags::NONE;
}

void ThreadEnded(int threadID);
void Shutdown();

u32 GetNewHandle() override {
u32 res = current++;
const u32 res = current++;
if (current < 0) {
// Some code assumes it'll never become 0.
current = 1;
Expand All @@ -101,9 +101,7 @@ class MetaFileSystem : public IHandleAllocator, public IFileSystem {
int error = MapFilePath(inpath, outpath, &mountPoint);
if (error == 0) {
*system = mountPoint->system.get();
return error;
}

return error;
}

Expand Down
47 changes: 47 additions & 0 deletions Core/HLE/Plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
#include "Core/Config.h"
#include "Core/MemMap.h"
#include "Core/System.h"
#include "Core/LuaContext.h"
#include "Core/ELF/ParamSFO.h"
#include "Core/HLE/Plugins.h"
#include "Core/HLE/sceKernelModule.h"
#include "Core/FileSystems/MetaFileSystem.h"
#include "ext/sol/sol.hpp"

namespace HLEPlugins {

Expand All @@ -42,6 +45,12 @@ static bool anyEnabled = false;

static std::vector<PluginInfo> prxPlugins;

struct LuaPlugin {
std::string filename;
std::unique_ptr<LuaContext> context;
};
static std::vector<LuaPlugin> luaPlugins;

static PluginInfo ReadPluginIni(const std::string &subdir, IniFile &ini) {
PluginInfo info;

Expand All @@ -51,6 +60,10 @@ static PluginInfo ReadPluginIni(const std::string &subdir, IniFile &ini) {
if (options->Get("type", &value)) {
if (value == "prx") {
info.type = PluginType::PRX;
} else if (value == "lua") {
info.type = PluginType::LUA;
} else {
info.type = PluginType::INVALID;
}
}

Expand Down Expand Up @@ -177,6 +190,11 @@ void Init() {
if (plugin.type == PluginType::PRX) {
prxPlugins.push_back(plugin);
anyEnabled = true;
} else if (plugin.type == PluginType::LUA) {
luaPlugins.emplace_back(LuaPlugin{
plugin.filename, nullptr
});
anyEnabled = true;
}
}
}
Expand Down Expand Up @@ -214,6 +232,32 @@ bool Load(PSPModule *pluginWaitingModule, SceUID threadID) {
INFO_LOG(Log::System, "Loaded plugin: '%s'", plugin.name.c_str());
}

bool anyLua = false;

for (LuaPlugin &luaPlugin : luaPlugins) {
if (!g_Config.bEnablePlugins) {
WARN_LOG(Log::System, "Plugins are disabled, ignoring enabled Lua plugin %s", luaPlugin.filename.c_str());
continue;
}
luaPlugin.context.reset(new LuaContext());
luaPlugin.context->Init();
// Load the file and inject into the context.
std::vector<u8> luaCodeBytes;
if (pspFileSystem.ReadEntireFile(luaPlugin.filename, luaCodeBytes, false) == 0) {
// Loaded the code. Let's copy it to a string.
std::string s;
s.resize(luaCodeBytes.size());
memcpy(s.data(), luaCodeBytes.data(), luaCodeBytes.size());
luaPlugin.context->RunCode(s);

anyLua = true;
}
}

if (anyLua) {
g_OSD.Show(OSDType::MESSAGE_WARNING, "Lua plugins are EXPERIMENTAL and the lua API WILL CHANGE in future versions!", 4.0f);
}

std::lock_guard<std::mutex> guard(g_inputMutex);
PluginDataKeys.clear();
return started;
Expand All @@ -225,6 +269,7 @@ void Unload() {

void Shutdown() {
prxPlugins.clear();
luaPlugins.clear();
anyEnabled = false;
std::lock_guard<std::mutex> guard(g_inputMutex);
PluginDataKeys.clear();
Expand All @@ -237,6 +282,8 @@ void DoState(PointerWrap &p) {

// Remember if any were enabled.
Do(p, anyEnabled);

// Lua state needs to be serialized and reloaded. Ugh! Makes it hard to upgrade lua versions.
}

bool HasEnabled() {
Expand Down
1 change: 1 addition & 0 deletions Core/HLE/Plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ bool HasEnabled();
enum class PluginType {
INVALID = 0,
PRX,
LUA,
};

struct PluginInfo {
Expand Down
Loading
Loading