Merge pull request #20169 from hrydgard/initial-debug-console

First step of adding a lua console
This commit is contained in:
Henrik Rydgård 2025-03-27 15:48:47 +01:00 committed by GitHub
commit d07d7f7ec4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
32 changed files with 30912 additions and 10 deletions

View file

@ -638,6 +638,9 @@ set(CommonVR
)
include_directories(ext/OpenXR-SDK/include)
# For ext/sol includes, that are usually included as sol/*.hpp
include_directories(ext)
add_library(Common STATIC
${CommonX86}
${CommonARM}
@ -1526,6 +1529,8 @@ list(APPEND NativeAppSource
UI/ImDebugger/ImDebugger.h
UI/ImDebugger/ImGe.cpp
UI/ImDebugger/ImGe.h
UI/ImDebugger/ImConsole.cpp
UI/ImDebugger/ImConsole.h
UI/ImDebugger/ImDisasmView.cpp
UI/ImDebugger/ImDisasmView.h
UI/ImDebugger/ImMemView.cpp
@ -2048,6 +2053,8 @@ add_library(${CoreLibName} ${CoreLinkType}
Core/KeyMap.h
Core/KeyMapDefaults.cpp
Core/KeyMapDefaults.h
Core/LuaContext.cpp
Core/LuaContext.h
Core/RetroAchievements.h
Core/RetroAchievements.cpp
Core/ThreadEventQueue.h

View file

@ -447,6 +447,9 @@
<ClInclude Include="..\ext\lua\lzio.h" />
<ClInclude Include="..\ext\minimp3\minimp3.h" />
<ClInclude Include="..\ext\naett\naett.h" />
<ClInclude Include="..\ext\sol\config.hpp" />
<ClInclude Include="..\ext\sol\forward.hpp" />
<ClInclude Include="..\ext\sol\sol.hpp" />
<ClInclude Include="..\ext\vma\vk_mem_alloc.h" />
<ClInclude Include="ABI.h" />
<ClInclude Include="Arm64Emitter.h" />

View file

@ -682,6 +682,15 @@
<ClInclude Include="Net\SocketCompat.h">
<Filter>Net</Filter>
</ClInclude>
<ClInclude Include="..\ext\sol\config.hpp">
<Filter>ext\sol</Filter>
</ClInclude>
<ClInclude Include="..\ext\sol\forward.hpp">
<Filter>ext\sol</Filter>
</ClInclude>
<ClInclude Include="..\ext\sol\sol.hpp">
<Filter>ext\sol</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ABI.cpp" />
@ -1416,6 +1425,9 @@
<Filter Include="ext\lua">
<UniqueIdentifier>{71e2e5df-5cfb-41e6-97da-f71584a7394e}</UniqueIdentifier>
</Filter>
<Filter Include="ext\sol">
<UniqueIdentifier>{ec7d8691-bb7f-4689-b66a-cb60c1f48afd}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<Text Include="..\ext\libpng17\CMakeLists.txt">
@ -1469,4 +1481,4 @@
<Filter>ext\lua</Filter>
</None>
</ItemGroup>
</Project>
</Project>

View file

@ -31,7 +31,10 @@ void AttachThreadToJNI() {
if (g_attach) {
g_attach();
} else {
#if PPSSPP_PLATFORM(ANDROID)
// Not relevant on other platforms.
ERROR_LOG(Log::System, "Couldn't attach thread - g_attach not set");
#endif
}
}

View file

@ -589,6 +589,7 @@
<ClCompile Include="Instance.cpp" />
<ClCompile Include="KeyMap.cpp" />
<ClCompile Include="KeyMapDefaults.cpp" />
<ClCompile Include="LuaContext.cpp" />
<ClCompile Include="MemFault.cpp" />
<ClCompile Include="MIPS\ARM64\Arm64IRAsm.cpp" />
<ClCompile Include="MIPS\ARM64\Arm64IRCompALU.cpp" />
@ -1210,6 +1211,7 @@
<ClInclude Include="Instance.h" />
<ClInclude Include="KeyMap.h" />
<ClInclude Include="KeyMapDefaults.h" />
<ClInclude Include="LuaContext.h" />
<ClInclude Include="MemFault.h" />
<ClInclude Include="MIPS\ARM64\Arm64IRJit.h" />
<ClInclude Include="MIPS\ARM64\Arm64IRRegCache.h" />

View file

@ -1345,6 +1345,9 @@
<ClCompile Include="Util\RecentFiles.cpp">
<Filter>Util</Filter>
</ClCompile>
<ClCompile Include="LuaContext.cpp">
<Filter>Core</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ELF\ElfReader.h">
@ -2172,6 +2175,9 @@
<ClInclude Include="Util\RecentFiles.h">
<Filter>Util</Filter>
</ClInclude>
<ClInclude Include="LuaContext.h">
<Filter>Core</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\LICENSE.TXT" />
@ -2200,4 +2206,4 @@
<Filter>Ext</Filter>
</Text>
</ItemGroup>
</Project>
</Project>

View file

@ -43,13 +43,13 @@ struct DisassemblyLineInfo
u32 totalSize;
};
enum LineType { LINE_UP, LINE_DOWN, LINE_RIGHT };
enum DisasmLineType { LINE_UP, LINE_DOWN, LINE_RIGHT };
struct BranchLine
{
u32 first;
u32 second;
LineType type;
DisasmLineType type;
int laneIndex;
bool operator<(const BranchLine& other) const

View file

@ -54,6 +54,11 @@
#include "Core/Instance.h"
#include "proAdhoc.h"
#ifdef _WIN32
#undef errno
#define errno WSAGetLastError()
#endif
#if PPSSPP_PLATFORM(SWITCH) && !defined(INADDR_NONE)
// Missing toolchain define
#define INADDR_NONE 0xFFFFFFFF

View file

@ -41,6 +41,11 @@
#include "Core/Core.h"
#include "Core/HLE/proAdhocServer.h"
#ifdef _WIN32
#undef errno
#define errno WSAGetLastError()
#endif
// User Count
uint32_t _db_user_count = 0;

View file

@ -53,6 +53,10 @@
#include "Core/HLE/proAdhocServer.h"
#include "Core/HLE/KernelWaitHelpers.h"
#ifdef _WIN32
#undef errno
#define errno WSAGetLastError()
#endif
// shared in sceNetAdhoc.h since it need to be used from sceNet.cpp also
// TODO: Make accessor functions instead, and throw all this state in a struct.

141
Core/LuaContext.cpp Normal file
View file

@ -0,0 +1,141 @@
#include <string>
#include "Common/Log.h"
#include "Common/StringUtils.h"
#include "Core/LuaContext.h"
#include "Core/MemMap.h"
// Sol is expensive to include so we only do it here.
#include "ext/sol/sol.hpp"
LuaContext g_lua;
static bool IsProbablyExpression(std::string_view input) {
// Heuristic: If it's a single-line statement without assignment or keywords, assume it's an expression.
return !(input.find("=") != std::string_view::npos ||
input.find("function") != std::string_view::npos ||
input.find("do") != std::string_view::npos ||
input.find("end") != std::string_view::npos ||
input.find("return") != std::string_view::npos ||
input.find("local") != std::string_view::npos);
}
// Custom print function
static void print(const std::string& message) {
g_lua.Print(message);
}
// TODO: Should these also echo to the console?
static void debug(const std::string &message) {
DEBUG_LOG(Log::System, "%s", message.c_str());
}
static void info(const std::string &message) {
INFO_LOG(Log::System, "%s", message.c_str());
}
static void warn(const std::string &message) {
WARN_LOG(Log::System, "%s", message.c_str());
}
static void error(const std::string &message) {
ERROR_LOG(Log::System, "%s", message.c_str());
}
// TODO: We should probably disallow or at least discourage raw read/writes and instead
// only support read/writes that refer to the name of a memory region.
static int r32(int address) {
if (Memory::IsValid4AlignedAddress(address)) {
return Memory::Read_U32(address);
} else {
g_lua.Print(LogLineType::Error, StringFromFormat("r32: bad address %08x", address));
return 0;
}
}
static void w32(int address, int value) {
if (Memory::IsValid4AlignedAddress(address)) {
Memory::Write_U32(value, address); // NOTE: These are backwards for historical reasons.
} else {
g_lua.Print(LogLineType::Error, StringFromFormat("w32: bad address %08x trying to write %08x", address, value));
}
}
void LuaContext::Init() {
_dbg_assert_(lua_ == nullptr);
lua_.reset(new sol::state());
lua_->open_libraries(sol::lib::base);
lua_->open_libraries(sol::lib::table);
lua_->open_libraries(sol::lib::bit32);
lua_->open_libraries(sol::lib::string);
lua_->open_libraries(sol::lib::math);
extern const char *PPSSPP_GIT_VERSION;
lua_->set("ver", PPSSPP_GIT_VERSION);
lua_->set("print", &print);
lua_->set("debug", &debug);
lua_->set("info", &info);
lua_->set("warn", &warn);
lua_->set("error", &error);
lua_->set("r32", &r32);
}
void LuaContext::Shutdown() {
lua_.reset();
}
const char *SolTypeToString(sol::type type) {
switch (type) {
case sol::type::boolean: return "boolean";
default: return "other";
}
}
void LuaContext::Print(LogLineType type, std::string_view text) {
lines_.push_back(LuaLogLine{ type, std::string(text)});
}
void LuaContext::ExecuteConsoleCommand(std::string_view cmd) {
// TODO: Also rewrite expressions like:
// print "hello"
// to
// print("hello") ?
try {
std::string command;
if (IsProbablyExpression(cmd)) {
command = "return ";
command += cmd;
} else {
command = cmd;
}
auto result = lua_->script(command);
if (result.valid()) {
for (const sol::stack_proxy &item : result) {
switch (item.get_type()) {
case sol::type::number:
{
int num = item.get<int>();
lines_.push_back(LuaLogLine{ LogLineType::Integer, StringFromFormat("%08x (%d)", num, num), item.get<int>()});
break;
}
case sol::type::string:
{
// TODO: Linebreak multi-line strings.
lines_.push_back(LuaLogLine{ LogLineType::String, item.get<std::string>() });
break;
}
default:
break;
}
}
} else {
sol::error err = result;
lines_.push_back(LuaLogLine{ LogLineType::Error, std::string(err.what()) });
}
} catch (sol::error e) {
ERROR_LOG(Log::System, "Lua exception: %s", e.what());
lines_.push_back(LuaLogLine{ LogLineType::Error, std::string(e.what()) });
}
}

51
Core/LuaContext.h Normal file
View file

@ -0,0 +1,51 @@
#pragma once
#include <string_view>
#include <string>
#include <memory>
#include "ext/sol/forward.hpp"
struct lua_State;
enum class LogLineType {
Cmd,
String,
Integer,
Error,
External,
Url,
};
// A bit richer than regular log lines, so we can display them in color, and allow various UI tricks.
// All have a string, but some may also have a number or other value.
struct LuaLogLine {
LogLineType type;
std::string line;
int number;
};
class LuaContext {
public:
void Init();
void Shutdown();
const std::vector<LuaLogLine> GetLines() const {
return lines_;
}
void Clear() { lines_.clear(); }
void Print(LogLineType type, std::string_view text);
void Print(std::string_view text) {
Print(LogLineType::External, text);
}
// For the console.
void ExecuteConsoleCommand(std::string_view cmd);
private:
std::unique_ptr<sol::state> lua_;
std::vector<LuaLogLine> lines_;
};
extern LuaContext g_lua;

View file

@ -58,6 +58,7 @@
#include "Core/CoreTiming.h"
#include "Core/CoreParameter.h"
#include "Core/FileLoaders/RamCachingFileLoader.h"
#include "Core/LuaContext.h"
#include "Core/FileSystems/MetaFileSystem.h"
#include "Core/Loaders.h"
#include "Core/PSPLoaders.h"
@ -217,6 +218,8 @@ bool CPU_Init(std::string *errorString, FileLoader *loadedFile, IdentifiedFileTy
g_symbolMap = new SymbolMap();
g_lua.Init();
// Default memory settings
// Seems to be the safest place currently..
Memory::g_MemorySize = Memory::RAM_NORMAL_SIZE; // 32 MB of ram by default
@ -362,6 +365,8 @@ void CPU_Shutdown() {
delete g_symbolMap;
g_symbolMap = nullptr;
g_lua.Shutdown();
g_CoreParameter.mountIsoLoader = nullptr;
}

300
UI/ImDebugger/ImConsole.cpp Normal file
View file

@ -0,0 +1,300 @@
#pragma once
#include <cstdlib>
#include "ext/imgui/imgui.h"
#include "UI/ImDebugger/ImDebugger.h"
#include "UI/ImDebugger/ImConsole.h"
#include "Core/LuaContext.h"
#include "Common/StringUtils.h"
ImConsole::ImConsole() {
memset(InputBuf, 0, sizeof(InputBuf));
HistoryPos = -1;
// "CLASSIFY" is here to provide the test case where "C"+[tab] completes to "CL" and display multiple matches.
Commands.push_back("HELP");
Commands.push_back("HISTORY");
Commands.push_back("CLEAR");
AutoScroll = true;
ScrollToBottom = false;
}
ImConsole::~ImConsole() {
for (int i = 0; i < History.Size; i++)
ImGui::MemFree(History[i]);
}
// Portable helpers
static int Stricmp(const char* s1, const char* s2) { int d; while ((d = toupper(*s2) - toupper(*s1)) == 0 && *s1) { s1++; s2++; } return d; }
static int Strnicmp(const char* s1, const char* s2, int n) { int d = 0; while (n > 0 && (d = toupper(*s2) - toupper(*s1)) == 0 && *s1) { s1++; s2++; n--; } return d; }
static char* Strdup(const char* s) { IM_ASSERT(s); size_t len = strlen(s) + 1; void* buf = ImGui::MemAlloc(len); IM_ASSERT(buf); return (char*)memcpy(buf, (const void*)s, len); }
static void Strtrim(char* s) { char* str_end = s + strlen(s); while (str_end > s && str_end[-1] == ' ') str_end--; *str_end = 0; }
// In C++11 you'd be better off using lambdas for this sort of forwarding callbacks
static int TextEditCallbackStub(ImGuiInputTextCallbackData* data) {
ImConsole* console = (ImConsole*)data->UserData;
return console->TextEditCallback(data);
}
void ImConsole::Draw(ImConfig &cfg) {
ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver);
if (!ImGui::Begin("Lua Console", &cfg.luaConsoleOpen)) {
ImGui::End();
return;
}
if (ImGui::SmallButton("Clear")) {
g_lua.Clear();
}
ImGui::SameLine();
bool copy_to_clipboard = ImGui::SmallButton("Copy");
ImGui::Separator();
// Options menu
if (ImGui::BeginPopup("Options")) {
ImGui::Checkbox("Auto-scroll", &AutoScroll);
ImGui::EndPopup();
}
// Options, Filter
//ImGui::SetNextItemShortcut(ImGuiMod_Ctrl | ImGuiKey_O, ImGuiInputFlags_Tooltip);
if (ImGui::Button("Options"))
ImGui::OpenPopup("Options");
ImGui::SameLine();
Filter.Draw("Filter (\"incl,-excl\") (\"error\")", 180);
ImGui::Separator();
// Reserve enough left-over height for 1 separator + 1 input text
const float footer_height_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing();
if (ImGui::BeginChild("ScrollingRegion", ImVec2(0, -footer_height_to_reserve), ImGuiChildFlags_None, ImGuiWindowFlags_HorizontalScrollbar | ImGuiChildFlags_NavFlattened)) {
if (ImGui::BeginPopupContextWindow()) {
if (ImGui::Selectable("Clear"))
g_lua.Clear();
ImGui::EndPopup();
}
// Display every line as a separate entry so we can change their color or add custom widgets.
// If you only want raw text you can use ImGui::TextUnformatted(log.begin(), log.end());
// NB- if you have thousands of entries this approach may be too inefficient and may require user-side clipping
// to only process visible items. The clipper will automatically measure the height of your first item and then
// "seek" to display only items in the visible area.
// To use the clipper we can replace your standard loop:
// for (int i = 0; i < Items.Size; i++)
// With:
// ImGuiListClipper clipper;
// clipper.Begin(Items.Size);
// while (clipper.Step())
// for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
// - That your items are evenly spaced (same height)
// - That you have cheap random access to your elements (you can access them given their index,
// without processing all the ones before)
// You cannot this code as-is if a filter is active because it breaks the 'cheap random-access' property.
// We would need random-access on the post-filtered list.
// A typical application wanting coarse clipping and filtering may want to pre-compute an array of indices
// or offsets of items that passed the filtering test, recomputing this array when user changes the filter,
// and appending newly elements as they are inserted. This is left as a task to the user until we can manage
// to improve this example code!
// If your items are of variable height:
// - Split them into same height items would be simpler and facilitate random-seeking into your list.
// - Consider using manual call to IsRectVisible() and skipping extraneous decoration from your items.
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4, 1)); // Tighten spacing
if (copy_to_clipboard)
ImGui::LogToClipboard();
for (const auto &item : g_lua.GetLines()) {
if (!Filter.PassFilter(item.line.c_str()))
continue;
ImVec4 color;
bool has_color = true;
switch (item.type) {
case LogLineType::Cmd: color = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); break;
case LogLineType::Error: color = ImVec4(1.0f, 0.4f, 0.4f, 1.0f); break;
case LogLineType::External: color = ImVec4(0.8f, 0.8f, 1.0f, 1.0f); break;
case LogLineType::Integer: color = ImVec4(1.0f, 1.0f, 0.8f, 1.0f); break;
case LogLineType::String: color = ImVec4(0.8f, 1.0f, 0.8f, 1.0f); break;
default:
has_color = false;
break;
}
if (has_color)
ImGui::PushStyleColor(ImGuiCol_Text, color);
switch (item.type) {
case LogLineType::Url:
if (ImGui::TextLink(item.line.c_str())) {
System_LaunchUrl(LaunchUrlType::BROWSER_URL, item.line.c_str());
}
break;
default:
ImGui::TextUnformatted(item.line.data(), item.line.data() + item.line.size());
break;
}
if (has_color)
ImGui::PopStyleColor();
}
if (copy_to_clipboard)
ImGui::LogFinish();
// Keep up at the bottom of the scroll region if we were already at the bottom at the beginning of the frame.
// Using a scrollbar or mouse-wheel will take away from the bottom edge.
if (ScrollToBottom || (AutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY()))
ImGui::SetScrollHereY(1.0f);
ScrollToBottom = false;
ImGui::PopStyleVar();
}
ImGui::EndChild();
ImGui::Separator();
// Command-line
bool reclaim_focus = false;
ImGuiInputTextFlags input_text_flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_EscapeClearsAll | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory;
if (ImGui::InputText("Input", InputBuf, IM_ARRAYSIZE(InputBuf), input_text_flags, &TextEditCallbackStub, (void*)this)) {
char* s = InputBuf;
Strtrim(s);
if (s[0])
ExecCommand(s);
strcpy(s, "");
reclaim_focus = true;
}
// Auto-focus on window apparition
ImGui::SetItemDefaultFocus();
if (reclaim_focus)
ImGui::SetKeyboardFocusHere(-1); // Auto focus previous widget
ImGui::End();
}
void ImConsole::ExecCommand(const char* command_line) {
// Insert into history. First find match and delete it so it can be pushed to the back.
// This isn't trying to be smart or optimal.
HistoryPos = -1;
for (int i = History.Size - 1; i >= 0; i--)
if (Stricmp(History[i], command_line) == 0)
{
ImGui::MemFree(History[i]);
History.erase(History.begin() + i);
break;
}
History.push_back(Strdup(command_line));
g_lua.Print(LogLineType::Cmd, std::string(command_line));
// Process command
if (Stricmp(command_line, "clear") == 0) {
g_lua.Clear();
} else if (Stricmp(command_line, "help") == 0) {
g_lua.Print("Available non-Lua commands:");
for (int i = 0; i < Commands.Size; i++)
g_lua.Print(StringFromFormat("- %s", Commands[i]));
g_lua.Print("For Lua help:");
g_lua.Print(LogLineType::Url, "https://www.lua.org/manual/5.3/");
// TODO: Also print available Lua commands.
} else if (Stricmp(command_line, "history") == 0) {
int first = History.Size - 10;
for (int i = first > 0 ? first : 0; i < History.Size; i++)
g_lua.Print(StringFromFormat("%3d: %s", i, History[i]));
} else {
g_lua.ExecuteConsoleCommand(command_line);
}
// On command input, we scroll to bottom even if AutoScroll==false
ScrollToBottom = true;
}
int ImConsole::TextEditCallback(ImGuiInputTextCallbackData* data) {
//AddLog("cursor: %d, selection: %d-%d", data->CursorPos, data->SelectionStart, data->SelectionEnd);
switch (data->EventFlag) {
case ImGuiInputTextFlags_CallbackCompletion:
{
// Example of TEXT COMPLETION
// Locate beginning of current word
const char* word_end = data->Buf + data->CursorPos;
const char* word_start = word_end;
while (word_start > data->Buf)
{
const char c = word_start[-1];
if (c == ' ' || c == '\t' || c == ',' || c == ';')
break;
word_start--;
}
// Build a list of candidates
ImVector<const char*> candidates;
for (int i = 0; i < Commands.Size; i++)
if (Strnicmp(Commands[i], word_start, (int)(word_end - word_start)) == 0)
candidates.push_back(Commands[i]);
// TODO: Add lua globals to candidates!
if (candidates.Size == 0) {
// No match. TODO: Match against lua globals.
g_lua.Print(StringFromFormat("No match for \"%.*s\"!", (int)(word_end - word_start), word_start));
} else if (candidates.Size == 1) {
// Single match. Delete the beginning of the word and replace it entirely so we've got nice casing.
data->DeleteChars((int)(word_start - data->Buf), (int)(word_end - word_start));
data->InsertChars(data->CursorPos, candidates[0]);
data->InsertChars(data->CursorPos, " ");
} else {
// Multiple matches. Complete as much as we can..
// So inputing "C"+Tab will complete to "CL" then display "CLEAR" and "CLASSIFY" as matches.
int match_len = (int)(word_end - word_start);
for (;;) {
int c = 0;
bool all_candidates_matches = true;
for (int i = 0; i < candidates.Size && all_candidates_matches; i++)
if (i == 0)
c = toupper(candidates[i][match_len]);
else if (c == 0 || c != toupper(candidates[i][match_len]))
all_candidates_matches = false;
if (!all_candidates_matches)
break;
match_len++;
}
if (match_len > 0) {
data->DeleteChars((int)(word_start - data->Buf), (int)(word_end - word_start));
data->InsertChars(data->CursorPos, candidates[0], candidates[0] + match_len);
}
// List matches
g_lua.Print("Possible matches:");
for (int i = 0; i < candidates.Size; i++) {
g_lua.Print(StringFromFormat("- %s", candidates[i]));
}
}
break;
}
case ImGuiInputTextFlags_CallbackHistory:
{
// Example of HISTORY
const int prev_history_pos = HistoryPos;
if (data->EventKey == ImGuiKey_UpArrow) {
if (HistoryPos == -1)
HistoryPos = History.Size - 1;
else if (HistoryPos > 0)
HistoryPos--;
} else if (data->EventKey == ImGuiKey_DownArrow) {
if (HistoryPos != -1)
if (++HistoryPos >= History.Size)
HistoryPos = -1;
}
// A better implementation would preserve the data on the current input line along with cursor position.
if (prev_history_pos != HistoryPos) {
const char* history_str = (HistoryPos >= 0) ? History[HistoryPos] : "";
data->DeleteChars(0, data->BufTextLen);
data->InsertChars(0, history_str);
}
}
}
return 0;
}

27
UI/ImDebugger/ImConsole.h Normal file
View file

@ -0,0 +1,27 @@
#pragma once
#include <cstdlib>
#include <locale>
#include "ext/imgui/imgui.h"
// Adapted from the ImGui demo.
class ImConsole {
public:
ImConsole();
~ImConsole();
void Draw(ImConfig &cfg);
void ExecCommand(const char* command_line);
int TextEditCallback(ImGuiInputTextCallbackData* data);
private:
char InputBuf[256];
ImVector<const char*> Commands;
ImVector<char*> History;
int HistoryPos; // -1: new line, 0..History.Size-1 browsing history.
ImGuiTextFilter Filter;
bool AutoScroll;
bool ScrollToBottom;
};

View file

@ -1757,6 +1757,7 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug, GPUDebugInterface *gpuDebu
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Tools")) {
ImGui::MenuItem("Lua Console", nullptr, &cfg_.luaConsoleOpen);
ImGui::MenuItem("Debug stats", nullptr, &cfg_.debugStatsOpen);
ImGui::MenuItem("Struct viewer", nullptr, &cfg_.structViewerOpen);
ImGui::MenuItem("Log channels", nullptr, &cfg_.logConfigOpen);
@ -1958,6 +1959,9 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug, GPUDebugInterface *gpuDebu
case ImCmd::SHOW_IN_PIXEL_VIEWER:
break;
}
if (cfg_.luaConsoleOpen) {
luaConsole_.Draw(cfg_);
}
}
void ImDebugger::Snapshot(MIPSState *mips) {
@ -2317,6 +2321,7 @@ void ImConfig::SyncConfig(IniFile *ini, bool save) {
sync.Sync("internalsOpen", &internalsOpen, false);
sync.Sync("sasAudioOpen", &sasAudioOpen, false);
sync.Sync("logConfigOpen", &logConfigOpen, false);
sync.Sync("luaConsoleOpen", &luaConsoleOpen, false);
sync.Sync("utilityModulesOpen", &utilityModulesOpen, false);
for (int i = 0; i < 4; i++) {
char name[64];

View file

@ -20,6 +20,7 @@
#include "UI/ImDebugger/ImMemView.h"
#include "UI/ImDebugger/ImStructViewer.h"
#include "UI/ImDebugger/ImGe.h"
#include "UI/ImDebugger/ImConsole.h"
// This is the main state container of the whole Dear ImGUI-based in-game cross-platform debugger.
//
@ -115,7 +116,6 @@ class IniFile;
struct ImConfig {
// Defaults for saved settings are set in SyncConfig.
bool disasmOpen;
bool demoOpen;
bool gprOpen;
@ -152,6 +152,7 @@ struct ImConfig {
bool utilityModulesOpen;
bool atracToolOpen;
bool memViewOpen[4];
bool luaConsoleOpen;
// HLE explorer settings
// bool filterByUsed = true;
@ -246,6 +247,7 @@ private:
ImGePixelViewerWindow pixelViewer_;
ImMemDumpWindow memDumpWindow_;
ImAtracToolWindow atracToolWindow_;
ImConsole luaConsole_;
ImSnapshotState newSnapshot_;
ImSnapshotState snapshot_;

View file

@ -40,7 +40,6 @@
#include "Common/File/FileUtil.h"
#include "Common/TimeUtil.h"
#include "Common/StringUtils.h"
#include "Common/System/System.h"
#include "Common/System/OSD.h"
#include "Core/System.h"
#include "Core/Util/RecentFiles.h"

View file

@ -27,6 +27,7 @@
// Background worker threads should be spawned in NativeInit and joined
// in NativeShutdown.
#include <errno.h>
#include <clocale>
#include <algorithm>

View file

@ -51,6 +51,7 @@
<ClCompile Include="GameScreen.cpp" />
<ClCompile Include="GameSettingsScreen.cpp" />
<ClCompile Include="GPUDriverTestScreen.cpp" />
<ClCompile Include="ImDebugger\ImConsole.cpp" />
<ClCompile Include="ImDebugger\ImDebugger.cpp" />
<ClCompile Include="ImDebugger\ImDisasmView.cpp" />
<ClCompile Include="ImDebugger\ImGe.cpp" />
@ -96,6 +97,7 @@
<ClInclude Include="GameSettingsScreen.h" />
<ClInclude Include="CwCheatScreen.h" />
<ClInclude Include="GPUDriverTestScreen.h" />
<ClInclude Include="ImDebugger\ImConsole.h" />
<ClInclude Include="ImDebugger\ImDebugger.h" />
<ClInclude Include="ImDebugger\ImDisasmView.h" />
<ClInclude Include="ImDebugger\ImGe.h" />

View file

@ -113,6 +113,9 @@
<ClCompile Include="ImDebugger\ImMemView.cpp">
<Filter>ImDebugger</Filter>
</ClCompile>
<ClCompile Include="ImDebugger\ImConsole.cpp">
<Filter>ImDebugger</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="GameInfoCache.h" />
@ -226,6 +229,9 @@
<ClInclude Include="ImDebugger\ImMemView.h">
<Filter>ImDebugger</Filter>
</ClInclude>
<ClInclude Include="ImDebugger\ImConsole.h">
<Filter>ImDebugger</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Screens">
@ -238,4 +244,4 @@
<UniqueIdentifier>{fda6bc55-1386-4650-a274-44fac9605ea3}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>
</Project>

View file

@ -278,6 +278,7 @@
<ClInclude Include="..\..\Core\KeyMap.h" />
<ClInclude Include="..\..\Core\KeyMapDefaults.h" />
<ClInclude Include="..\..\Core\Loaders.h" />
<ClInclude Include="..\..\Core\LuaContext.h" />
<ClInclude Include="..\..\Core\MemFault.h" />
<ClInclude Include="..\..\Core\MemMap.h" />
<ClInclude Include="..\..\Core\MemMapHelpers.h" />
@ -539,6 +540,7 @@
<ClCompile Include="..\..\Core\KeyMap.cpp" />
<ClCompile Include="..\..\Core\KeyMapDefaults.cpp" />
<ClCompile Include="..\..\Core\Loaders.cpp" />
<ClCompile Include="..\..\Core\LuaContext.cpp" />
<ClCompile Include="..\..\Core\MemFault.cpp" />
<ClCompile Include="..\..\Core\MemMap.cpp" />
<ClCompile Include="..\..\Core\MemMapFunctions.cpp" />
@ -1032,6 +1034,9 @@
<ProjectReference Include="..\libchdr_UWP\libchdr_UWP.vcxproj">
<Project>{191b6f52-ad66-4172-bd20-733eeeceef8c}</Project>
</ProjectReference>
<ProjectReference Include="..\lua\lua.vcxproj">
<Project>{3cea9e74-a31d-4044-a378-ed2e485931f2}</Project>
</ProjectReference>
<ProjectReference Include="..\miniupnpc_UWP\miniupnpc_UWP.vcxproj">
<Project>{d31fd4f0-53eb-477c-9dc7-149796f628e2}</Project>
</ProjectReference>

View file

@ -1233,6 +1233,9 @@
</ClCompile>
<ClCompile Include="..\..\Core\HLE\SocketManager.cpp">
<Filter>HLE</Filter>
<ClCompile Include="..\..\Core\LuaContext.cpp" />
<Filter>Dialog</Filter>
</ClCompile>
</ClCompile>
<ClCompile Include="..\..\Core\Util\AtracTrack.cpp">
<Filter>Util</Filter>
@ -1964,10 +1967,13 @@
<ClInclude Include="..\..\Core\Util\RecentFiles.h">
<Filter>Util</Filter>
</ClInclude>
<ClInclude Include="..\..\Core\LuaContext.h" />
<Filter>Dialog</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\ext\gason\LICENSE">
<Filter>Ext\gason</Filter>
</None>
</ItemGroup>
</Project>
</Project>

View file

@ -126,6 +126,7 @@
<ClInclude Include="..\..\UI\GameScreen.h" />
<ClInclude Include="..\..\UI\GameSettingsScreen.h" />
<ClInclude Include="..\..\UI\GPUDriverTestScreen.h" />
<ClInclude Include="..\..\UI\ImDebugger\ImConsole.h" />
<ClInclude Include="..\..\UI\ImDebugger\ImDebugger.h" />
<ClInclude Include="..\..\UI\ImDebugger\ImDisasmView.h" />
<ClInclude Include="..\..\UI\ImDebugger\ImGe.h" />
@ -171,6 +172,7 @@
<ClCompile Include="..\..\UI\GameScreen.cpp" />
<ClCompile Include="..\..\UI\GameSettingsScreen.cpp" />
<ClCompile Include="..\..\UI\GPUDriverTestScreen.cpp" />
<ClCompile Include="..\..\UI\ImDebugger\ImConsole.cpp" />
<ClCompile Include="..\..\UI\ImDebugger\ImDebugger.cpp" />
<ClCompile Include="..\..\UI\ImDebugger\ImDisasmView.cpp" />
<ClCompile Include="..\..\UI\ImDebugger\ImGe.cpp" />
@ -204,6 +206,9 @@
<ProjectReference Include="..\CommonUWP\CommonUWP.vcxproj">
<Project>{acb316ca-3ecb-48e5-be0a-91e72d5b0f12}</Project>
</ProjectReference>
<ProjectReference Include="..\lua\lua.vcxproj">
<Project>{3cea9e74-a31d-4044-a378-ed2e485931f2}</Project>
</ProjectReference>
<ProjectReference Include="..\rcheevos_UWP\rcheevos_UWP.vcxproj">
<Project>{4c9d52d0-310a-4347-8991-e3788cb22169}</Project>
</ProjectReference>

View file

@ -54,6 +54,9 @@
<ClCompile Include="..\..\UI\ImDebugger\ImMemView.cpp">
<Filter>ImDebugger</Filter>
</ClCompile>
<ClCompile Include="..\..\UI\ImDebugger\ImConsole.cpp">
<Filter>ImDebugger</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
@ -109,10 +112,13 @@
<ClInclude Include="..\..\UI\ImDebugger\ImMemView.h">
<Filter>ImDebugger</Filter>
</ClInclude>
<ClInclude Include="..\..\UI\ImDebugger\ImConsole.h">
<Filter>ImDebugger</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="ImDebugger">
<UniqueIdentifier>{4013cb89-6145-451c-9cb1-d63d01f66bd5}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>
</Project>

View file

@ -497,6 +497,9 @@
<ProjectReference Include="libzstd_UWP\libzstd_UWP.vcxproj">
<Project>{75286959-e7a2-4cbe-8b95-bf05c9c540fe}</Project>
</ProjectReference>
<ProjectReference Include="lua\lua.vcxproj">
<Project>{3cea9e74-a31d-4044-a378-ed2e485931f2}</Project>
</ProjectReference>
<ProjectReference Include="SPIRVCross_UWP\SPIRVCross_UWP.vcxproj">
<Project>{2b2d16bd-1d37-46af-a3f8-552900951b26}</Project>
</ProjectReference>
@ -528,4 +531,4 @@
<Import Project="$(VSINSTALLDIR)\Common7\IDE\Extensions\Microsoft\VsGraphics\MeshContentTask.targets" />
<Import Project="$(VSINSTALLDIR)\Common7\IDE\Extensions\Microsoft\VsGraphics\ShaderGraphContentTask.targets" />
</ImportGroup>
</Project>
</Project>

View file

@ -601,6 +601,7 @@ EXEC_AND_LIB_FILES := \
$(SRC)/Core/Instance.cpp \
$(SRC)/Core/KeyMap.cpp \
$(SRC)/Core/KeyMapDefaults.cpp \
$(SRC)/Core/LuaContext.cpp \
$(SRC)/Core/Loaders.cpp \
$(SRC)/Core/PSPLoaders.cpp \
$(SRC)/Core/FileLoaders/CachingFileLoader.cpp \
@ -889,6 +890,7 @@ LOCAL_SRC_FILES := \
$(SRC)/android/jni/OpenSLContext.cpp \
$(SRC)/UI/ImDebugger/ImDebugger.cpp \
$(SRC)/UI/ImDebugger/ImGe.cpp \
$(SRC)/UI/ImDebugger/ImConsole.cpp \
$(SRC)/UI/ImDebugger/ImDisasmView.cpp \
$(SRC)/UI/ImDebugger/ImMemView.cpp \
$(SRC)/UI/ImDebugger/ImStructViewer.cpp \

View file

@ -189,6 +189,7 @@ ImGuiKey KeyCodeToImGui(InputKeyCode keyCode) {
case NKCODE_COMMA: return ImGuiKey_Comma;
case NKCODE_PERIOD: return ImGuiKey_Period;
case NKCODE_MINUS: return ImGuiKey_Minus;
case NKCODE_PLUS: return ImGuiKey_Equal; // Hmm
case NKCODE_EQUALS: return ImGuiKey_Equal;
case NKCODE_LEFT_BRACKET: return ImGuiKey_LeftBracket;
case NKCODE_RIGHT_BRACKET: return ImGuiKey_RightBracket;

53
ext/sol/config.hpp Normal file
View file

@ -0,0 +1,53 @@
// The MIT License (MIT)
// Copyright (c) 2013-2020 Rapptz, ThePhD and contributors
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This file was generated with a script.
// Generated 2022-06-25 08:14:19.336233 UTC
// This header was generated with sol v3.3.0 (revision eba86625)
// https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_CONFIG_HPP
#define SOL_SINGLE_CONFIG_HPP
// beginning of sol/config.hpp
/* Base, empty configuration file!
To override, place a file in your include paths of the form:
. (your include path here)
| sol (directory, or equivalent)
| config.hpp (your config.hpp file)
So that when sol2 includes the file
#include <sol/config.hpp>
it gives you the configuration values you desire. Configuration values can be
seen in the safety.rst of the doc/src, or at
https://sol2.readthedocs.io/en/latest/safety.html ! You can also pass them through
the build system, or the command line options of your compiler.
*/
// end of sol/config.hpp
#endif // SOL_SINGLE_CONFIG_HPP

1321
ext/sol/forward.hpp Normal file

File diff suppressed because it is too large Load diff

28913
ext/sol/sol.hpp Normal file

File diff suppressed because it is too large Load diff

View file

@ -652,6 +652,7 @@ SOURCES_CXX += \
$(COREDIR)/WaveFile.cpp \
$(COREDIR)/KeyMap.cpp \
$(COREDIR)/KeyMapDefaults.cpp \
$(COREDIR)/LuaContext.cpp \
$(COREDIR)/FileLoaders/HTTPFileLoader.cpp \
$(COREDIR)/FileLoaders/CachingFileLoader.cpp \
$(COREDIR)/FileLoaders/DiskCachingFileLoader.cpp \