diff --git a/rpcs3/Gui/FnIdGenerator.cpp b/rpcs3/Gui/FnIdGenerator.cpp new file mode 100644 index 0000000000..aabfe9766c --- /dev/null +++ b/rpcs3/Gui/FnIdGenerator.cpp @@ -0,0 +1,102 @@ +#include "stdafx.h" +#include "FnIdGenerator.h" + +FnIdGenerator::FnIdGenerator(wxWindow* parent) + : wxDialog(parent, wxID_ANY, "FunctionID Generator", wxDefaultPosition) + , m_list(nullptr) +{ + wxBoxSizer* s_panel(new wxBoxSizer(wxHORIZONTAL)); + wxBoxSizer* s_subpanel(new wxBoxSizer(wxVERTICAL)); + wxBoxSizer* s_subpanel2(new wxBoxSizer(wxHORIZONTAL)); + + m_list = new wxListView(this, wxID_ANY, wxDefaultPosition, wxSize(300, 450)); + m_list->InsertColumn(0, "Function Name", 0, 200); + m_list->InsertColumn(1, "Function ID", 0, 100); + + wxButton *b_input_name = new wxButton(this, wxID_ANY, "Input Function Name", wxDefaultPosition, wxSize(140, -1)); + wxButton *b_clear = new wxButton(this, wxID_ANY, "Clear List", wxDefaultPosition, wxSize(140, -1)); + + s_subpanel2->Add(b_input_name); + s_subpanel2->AddSpacer(10); + s_subpanel2->Add(b_clear); + + s_subpanel->AddSpacer(5); + s_subpanel->Add(m_list); + s_subpanel->AddSpacer(5); + s_subpanel->Add(s_subpanel2); + + s_panel->AddSpacer(5); + s_panel->Add(s_subpanel); + s_panel->AddSpacer(5); + + this->SetSizerAndFit(s_panel); + + Connect(b_input_name->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(FnIdGenerator::OnInput)); + Connect(b_clear->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(FnIdGenerator::OnClear)); +} + +FnIdGenerator::~FnIdGenerator() +{ + m_func_name.Clear(); + m_func_id.Clear(); + delete m_list; +} + +void FnIdGenerator::OnInput(wxCommandEvent &event) +{ + PrintId(); + event.Skip(); +} + +void FnIdGenerator::OnClear(wxCommandEvent &event) +{ + m_list->DeleteAllItems(); + m_func_name.Clear(); + m_func_id.Clear(); + event.Skip(); +} + +u32 FnIdGenerator::GenerateFnId(const std::string& func_name) +{ + static const char* suffix = "\x67\x59\x65\x99\x04\x25\x04\x90\x56\x64\x27\x49\x94\x89\x74\x1A"; //symbol name suffix + std::string input = func_name + suffix; + unsigned char output[20]; + + sha1((unsigned char*)input.c_str(), input.length(), output); //compute SHA-1 hash + + return (be_t&) output[0]; +} + +void FnIdGenerator::PrintId() +{ + const std::string temp; + TextInputDialog dial(0, temp, "Please input function name"); + if (dial.ShowModal() == wxID_OK) + { + dial.GetResult(); + } + + const std::string& func_name = dial.GetResult(); + + if (func_name.length() == 0) + return; + + const be_t result = GenerateFnId(func_name); + m_func_name.AddCpy(func_name); + m_func_id.AddCpy(result); + + ConLog.Write("Function: %s, Id: 0x%08x ", func_name.c_str(), result); + UpdateInformation(); +} + +void FnIdGenerator::UpdateInformation() +{ + m_list->DeleteAllItems(); + + for(u32 i = 0; i < m_func_name.GetCount(); i++) + { + m_list->InsertItem(m_func_name.GetCount(), wxEmptyString); + m_list->SetItem(i, 0, m_func_name[i]); + m_list->SetItem(i, 1, wxString::Format("0x%08x", re(m_func_id[i]))); + } +} \ No newline at end of file diff --git a/rpcs3/Gui/FnIdGenerator.h b/rpcs3/Gui/FnIdGenerator.h new file mode 100644 index 0000000000..4f9eebcf9f --- /dev/null +++ b/rpcs3/Gui/FnIdGenerator.h @@ -0,0 +1,21 @@ +#include "TextInputDialog.h" +#include "../Crypto/aes.h" +#include "../Crypto/sha1.h" + +class FnIdGenerator : public wxDialog +{ +private: + Array m_func_name; + Array m_func_id; + wxListView* m_list; + +public: + FnIdGenerator(wxWindow* parent); + ~FnIdGenerator(); + + void OnInput(wxCommandEvent &event); + void OnClear(wxCommandEvent &event); + u32 GenerateFnId(const std::string& func_name); + void UpdateInformation(); + void PrintId(); +}; \ No newline at end of file diff --git a/rpcs3/Gui/MainFrame.cpp b/rpcs3/Gui/MainFrame.cpp index c84ff1e539..27617f42e4 100644 --- a/rpcs3/Gui/MainFrame.cpp +++ b/rpcs3/Gui/MainFrame.cpp @@ -4,6 +4,7 @@ #include "MemoryViewer.h" #include "RSXDebugger.h" #include "PADManager.h" +#include "FnIdGenerator.h" #include "git-version.h" #include "Ini.h" @@ -35,6 +36,7 @@ enum IDs id_tools_compiler, id_tools_memory_viewer, id_tools_rsx_debugger, + id_tools_fnid_generator, id_help_about, id_update_dbg, }; @@ -88,6 +90,7 @@ MainFrame::MainFrame() menu_tools.Append(id_tools_compiler, "ELF Compiler"); menu_tools.Append(id_tools_memory_viewer, "Memory Viewer"); menu_tools.Append(id_tools_rsx_debugger, "RSX Debugger"); + menu_tools.Append(id_tools_fnid_generator, "FunctionID Generator"); wxMenu& menu_help(*new wxMenu()); menubar.Append(&menu_help, "Help"); @@ -122,6 +125,7 @@ MainFrame::MainFrame() Connect( id_tools_compiler, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OpenELFCompiler)); Connect( id_tools_memory_viewer, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OpenMemoryViewer)); Connect( id_tools_rsx_debugger, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OpenRSXDebugger)); + Connect(id_tools_fnid_generator, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OpenFnIdGenerator)); Connect( id_help_about, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::AboutDialogHandler) ); @@ -583,6 +587,12 @@ void MainFrame::OpenRSXDebugger(wxCommandEvent& WXUNUSED(event)) (new RSXDebugger(this)) -> Show(); } +void MainFrame::OpenFnIdGenerator(wxCommandEvent& WXUNUSED(event)) +{ + FnIdGenerator(this).ShowModal(); +} + + void MainFrame::AboutDialogHandler(wxCommandEvent& WXUNUSED(event)) { AboutDialog(this).ShowModal(); diff --git a/rpcs3/Gui/MainFrame.h b/rpcs3/Gui/MainFrame.h index af1cc69419..4ea1d2b2f7 100644 --- a/rpcs3/Gui/MainFrame.h +++ b/rpcs3/Gui/MainFrame.h @@ -37,6 +37,7 @@ private: void OpenELFCompiler(wxCommandEvent& evt); void OpenMemoryViewer(wxCommandEvent& evt); void OpenRSXDebugger(wxCommandEvent& evt); + void OpenFnIdGenerator(wxCommandEvent& evt); void AboutDialogHandler(wxCommandEvent& event); void UpdateUI(wxCommandEvent& event); void OnKeyDown(wxKeyEvent& event); diff --git a/rpcs3/Gui/PADManager.cpp b/rpcs3/Gui/PADManager.cpp index 72c3613546..957458c606 100644 --- a/rpcs3/Gui/PADManager.cpp +++ b/rpcs3/Gui/PADManager.cpp @@ -5,13 +5,12 @@ PADManager::PADManager(wxWindow* parent) : wxDialog(parent, wxID_ANY, "PAD Settings", wxDefaultPosition) , m_button_id(0) , m_key_pressed(false) + , m_emu_paused(false) { - bool paused = false; - if(Emu.IsRunning()) { Emu.Pause(); - paused = true; + m_emu_paused = true; } wxBoxSizer* s_panel(new wxBoxSizer(wxHORIZONTAL)); @@ -246,8 +245,6 @@ PADManager::PADManager(wxWindow* parent) Connect(b_ok->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(PADManager::OnButtonClicked)); Connect(b_reset->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(PADManager::OnButtonClicked)); Connect(b_cancel->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(PADManager::OnButtonClicked)); - - if(paused) Emu.Resume(); } void PADManager::OnKeyDown(wxKeyEvent &keyEvent) diff --git a/rpcs3/Gui/PADManager.h b/rpcs3/Gui/PADManager.h index 61d2520991..49e7d51943 100644 --- a/rpcs3/Gui/PADManager.h +++ b/rpcs3/Gui/PADManager.h @@ -82,13 +82,11 @@ private: AppConnector m_app_connector; u32 m_seconds; u32 m_button_id; - bool m_key_pressed; + bool m_key_pressed, m_emu_paused; public: PADManager(wxWindow* parent); - ~PADManager() - { - } + ~PADManager() { if(m_emu_paused) Emu.Resume(); } void OnKeyDown(wxKeyEvent &keyEvent); void OnKeyUp(wxKeyEvent &keyEvent); diff --git a/rpcs3/Gui/TextInputDialog.cpp b/rpcs3/Gui/TextInputDialog.cpp index cd5047c815..d4a42d99e7 100644 --- a/rpcs3/Gui/TextInputDialog.cpp +++ b/rpcs3/Gui/TextInputDialog.cpp @@ -1,8 +1,8 @@ #include "stdafx.h" #include "TextInputDialog.h" -TextInputDialog::TextInputDialog(wxWindow* parent, const std::string& defvalue) - : wxDialog(parent, wxID_ANY, "Input text", wxDefaultPosition) +TextInputDialog::TextInputDialog(wxWindow* parent, const std::string& defvalue, const std::string& label) + : wxDialog(parent, wxID_ANY, label, wxDefaultPosition) { m_tctrl_text = new wxTextCtrl(this, wxID_ANY, fmt::ToUTF8(defvalue)); diff --git a/rpcs3/Gui/TextInputDialog.h b/rpcs3/Gui/TextInputDialog.h index bc04510a53..9a5b70532a 100644 --- a/rpcs3/Gui/TextInputDialog.h +++ b/rpcs3/Gui/TextInputDialog.h @@ -6,7 +6,7 @@ class TextInputDialog : public wxDialog std::string m_result; public: - TextInputDialog(wxWindow* parent, const std::string& defvalue = ""); + TextInputDialog(wxWindow* parent, const std::string& defvalue = "", const std::string& label = "Input text"); void OnOk(wxCommandEvent& event); std::string GetResult(); diff --git a/rpcs3/rpcs3.vcxproj b/rpcs3/rpcs3.vcxproj index 820ef36698..aa8bf61a22 100644 --- a/rpcs3/rpcs3.vcxproj +++ b/rpcs3/rpcs3.vcxproj @@ -334,6 +334,7 @@ + @@ -504,6 +505,7 @@ + diff --git a/rpcs3/rpcs3.vcxproj.filters b/rpcs3/rpcs3.vcxproj.filters index 9684d4dc1a..8776fa3b4a 100644 --- a/rpcs3/rpcs3.vcxproj.filters +++ b/rpcs3/rpcs3.vcxproj.filters @@ -370,6 +370,9 @@ Gui + + Gui + Gui @@ -582,6 +585,9 @@ Gui + + Gui + Gui