project64/Source/Project64/UserInterface/EnhancementUI.cpp

845 lines
26 KiB
C++
Raw Normal View History

2021-01-17 03:17:58 +00:00
#include "stdafx.h"
2022-09-21 05:16:07 +00:00
2021-02-28 21:32:50 +00:00
#include <Project64-core/N64System/Enhancement/Enhancements.h>
2022-09-26 02:31:54 +00:00
#include <Project64\UserInterface\EnhancementUI.h>
2021-01-17 03:17:58 +00:00
class CEditEnhancement :
2022-09-26 02:31:54 +00:00
public CDialogImpl<CEditEnhancement>
2021-01-17 03:17:58 +00:00
{
public:
BEGIN_MSG_MAP_EX(CEditEnhancement)
2022-09-26 02:31:54 +00:00
{
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog);
COMMAND_HANDLER_EX(IDC_GAMESHARK, BN_CLICKED, OnGamesharkBtn);
COMMAND_HANDLER_EX(IDC_OVERCLOCK, BN_CLICKED, OnOverClockBtn);
COMMAND_ID_HANDLER(IDC_BTN_GAMESHARK, OnEditGameshark);
COMMAND_ID_HANDLER(IDOK, OnOkCmd);
COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd);
}
2021-01-17 03:17:58 +00:00
END_MSG_MAP()
2022-09-26 02:31:54 +00:00
enum
{
IDD = IDD_Enhancement_Edit
};
2021-01-17 03:17:58 +00:00
CEditEnhancement(CEnhancementUI & EnhancementUI, CEnhancement * Enhancement);
private:
CEditEnhancement(void);
2022-09-26 02:31:54 +00:00
CEditEnhancement(const CEditEnhancement &);
CEditEnhancement & operator=(const CEditEnhancement &);
2021-01-17 03:17:58 +00:00
2022-09-26 02:31:54 +00:00
LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled);
2021-01-17 03:17:58 +00:00
LRESULT OnGamesharkBtn(UINT Code, int id, HWND ctl);
2021-03-10 07:39:01 +00:00
LRESULT OnOverClockBtn(UINT Code, int id, HWND ctl);
2022-09-26 02:31:54 +00:00
LRESULT OnEditGameshark(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled);
LRESULT OnOkCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled);
LRESULT OnCloseCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled);
2021-01-17 03:17:58 +00:00
CEnhancementUI & m_EnhancementUI;
CEnhancement::CodeEntries m_Entries;
2021-02-11 11:26:09 +00:00
CEnhancement::PluginList m_PluginList;
2021-01-17 03:17:58 +00:00
CEnhancement * m_EditEnhancement;
};
class CEditGS :
2021-02-11 11:26:09 +00:00
public CDialogImpl<CEditGS>
2021-01-17 03:17:58 +00:00
{
public:
BEGIN_MSG_MAP_EX(CEditGS)
2022-09-26 02:31:54 +00:00
{
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog);
COMMAND_HANDLER(IDC_CHEAT_CODES, EN_CHANGE, OnCheatChanged);
COMMAND_HANDLER_EX(IDC_CHK_LIMIT_PLUGINS, BN_CLICKED, OnPluginBtn);
COMMAND_ID_HANDLER(IDC_BTN_PLUGIN, OnEditPlugins);
COMMAND_ID_HANDLER(IDOK, OnOkCmd);
COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd);
}
2021-01-17 03:17:58 +00:00
END_MSG_MAP()
2022-09-26 02:31:54 +00:00
enum
{
IDD = IDD_Enhancement_GS
};
2021-01-17 03:17:58 +00:00
2021-02-11 11:26:09 +00:00
CEditGS(CEnhancement::CodeEntries & Entries, CEnhancement::PluginList & PluginList);
2021-01-17 03:17:58 +00:00
private:
CEditGS();
2022-09-26 02:31:54 +00:00
CEditGS(const CEditGS &);
CEditGS & operator=(const CEditGS &);
2021-01-17 03:17:58 +00:00
2022-09-26 02:31:54 +00:00
LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled);
2021-02-11 11:26:09 +00:00
LRESULT OnPluginBtn(UINT Code, int id, HWND ctl);
2022-09-26 02:31:54 +00:00
LRESULT OnEditPlugins(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled);
2021-01-17 03:17:58 +00:00
LRESULT OnCloseCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled);
LRESULT OnOkCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled);
LRESULT OnCheatChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled);
bool CheatCode(CEnhancement::CodeEntries & Entries);
CEnhancement::CodeEntries & m_Entries;
2021-02-11 11:26:09 +00:00
CEnhancement::PluginList & m_PluginList;
};
class CEditPluginList :
public CDialogImpl<CEditPluginList>
{
public:
BEGIN_MSG_MAP_EX(CEditPluginList)
2022-09-26 02:31:54 +00:00
{
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog);
COMMAND_ID_HANDLER(IDC_ADD, OnAddBtn);
COMMAND_ID_HANDLER(IDC_REMOVE, OnRemoveBtn);
COMMAND_ID_HANDLER(IDOK, OnOkCmd);
COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd);
}
2021-02-11 11:26:09 +00:00
END_MSG_MAP()
2022-09-26 02:31:54 +00:00
enum
{
IDD = IDD_Enhancement_Plugins
};
2021-02-11 11:26:09 +00:00
CEditPluginList(CEnhancement::PluginList & List);
private:
CEditPluginList();
2022-09-26 02:31:54 +00:00
CEditPluginList(const CEditPluginList &);
CEditPluginList & operator=(const CEditPluginList &);
2021-02-11 11:26:09 +00:00
2022-09-26 02:31:54 +00:00
LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled);
LRESULT OnAddBtn(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled);
LRESULT OnRemoveBtn(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled);
2021-02-11 11:26:09 +00:00
LRESULT OnCloseCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled);
LRESULT OnOkCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled);
2022-09-26 02:31:54 +00:00
2021-02-11 11:26:09 +00:00
CListBox m_PluginListBox;
CEnhancement::PluginList & m_PluginList;
2021-01-17 03:17:58 +00:00
};
CEnhancementUI::CEnhancementUI(void) :
2021-04-12 11:35:39 +00:00
m_hSelectedItem(nullptr),
2021-02-02 03:25:28 +00:00
m_bModal(false)
2021-01-17 03:17:58 +00:00
{
}
void CEnhancementUI::Display(HWND hParent, bool BlockExecution)
{
if (g_BaseSystem)
{
g_BaseSystem->ExternalEvent(SysEvent_PauseCPU_Enhancement);
}
if (BlockExecution)
{
m_bModal = true;
DoModal(hParent);
}
2021-04-12 11:35:39 +00:00
else if (m_hWnd != nullptr)
2021-01-17 03:17:58 +00:00
{
SetFocus();
}
else
{
m_bModal = false;
Create(hParent);
}
}
2022-09-26 02:31:54 +00:00
LRESULT CEnhancementUI::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
2021-01-17 03:17:58 +00:00
{
SetWindowText(wGS(ENHANCEMENT_TITLE).c_str());
2021-01-17 03:17:58 +00:00
m_TreeList.Attach(GetDlgItem(IDC_ENHANCEMENTLIST));
LONG Style = m_TreeList.GetWindowLong(GWL_STYLE);
m_TreeList.SetWindowLong(GWL_STYLE, TVS_CHECKBOXES | TVS_SHOWSELALWAYS | Style);
HIMAGELIST hImageList = ImageList_Create(16, 16, ILC_COLOR | ILC_MASK, 40, 40);
2021-04-12 11:35:39 +00:00
HBITMAP hBmp = LoadBitmap(GetModuleHandle(nullptr), MAKEINTRESOURCE(IDB_TRI_STATE));
2021-01-17 03:17:58 +00:00
ImageList_AddMasked(hImageList, hBmp, RGB(255, 0, 255));
DeleteObject(hBmp);
m_TreeList.SetImageList(hImageList, TVSIL_STATE);
2021-03-23 02:11:18 +00:00
g_Enhancements->Load();
2021-01-17 03:17:58 +00:00
m_Enhancements = g_Enhancements->Enhancements();
CRect rcDlg, rcParent;
GetWindowRect(&rcDlg);
GetParent().GetWindowRect(&rcParent);
int32_t DlgWidth = rcDlg.Width();
int32_t DlgHeight = rcDlg.Height();
int32_t X = (((rcParent.Width()) - DlgWidth) / 2) + rcParent.left;
int32_t Y = (((rcParent.Height()) - DlgHeight) / 2) + rcParent.top;
2021-04-12 11:35:39 +00:00
SetWindowPos(nullptr, X, Y, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
2022-09-26 02:31:54 +00:00
2021-01-17 03:17:58 +00:00
RefreshList();
ShowWindow(SW_SHOW);
return TRUE;
}
LRESULT CEnhancementUI::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{
m_TreeList.Detach();
return 0;
}
2022-09-26 02:31:54 +00:00
LRESULT CEnhancementUI::OnCloseCmd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{
if (g_BaseSystem)
{
g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_Enhancement);
}
if (m_bModal)
{
EndDialog(0);
}
else
{
DestroyWindow();
}
2021-01-17 03:17:58 +00:00
return TRUE;
}
2022-09-26 02:31:54 +00:00
LRESULT CEnhancementUI::OnEditEnhancement(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
2021-01-17 03:17:58 +00:00
{
2022-09-26 02:31:54 +00:00
TVITEM item = {0};
item.mask = TVIF_PARAM;
item.hItem = m_hSelectedItem;
if (!m_TreeList.GetItem(&item) || item.lParam == NULL)
{
return 0;
}
CEditEnhancement(*this, (CEnhancement *)item.lParam).DoModal(m_hWnd);
2021-01-17 03:17:58 +00:00
return TRUE;
}
2022-09-26 02:31:54 +00:00
LRESULT CEnhancementUI::OnAddEnhancement(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
2021-01-17 03:17:58 +00:00
{
CEditEnhancement(*this, nullptr).DoModal(m_hWnd);
RefreshList();
return TRUE;
}
2022-09-26 02:31:54 +00:00
LRESULT CEnhancementUI::OnEnhancementListClicked(NMHDR * lpnmh)
{
uint32_t dwpos = GetMessagePos();
2022-09-26 02:31:54 +00:00
TVHITTESTINFO ht = {0};
ht.pt.x = GET_X_LPARAM(dwpos);
ht.pt.y = GET_Y_LPARAM(dwpos);
::MapWindowPoints(HWND_DESKTOP, lpnmh->hwndFrom, &ht.pt, 1);
TreeView_HitTest(lpnmh->hwndFrom, &ht);
if (TVHT_ONITEMSTATEICON & ht.flags)
{
switch (TV_GetCheckState(ht.hItem))
{
case TV_STATE_CLEAR:
case TV_STATE_INDETERMINATE:
TV_SetCheckState(ht.hItem, TV_STATE_CHECKED);
ChangeChildrenStatus(ht.hItem, true);
CheckParentStatus(m_TreeList.GetParentItem(ht.hItem));
break;
case TV_STATE_CHECKED:
TV_SetCheckState(ht.hItem, TV_STATE_CLEAR);
ChangeChildrenStatus(ht.hItem, false);
CheckParentStatus(m_TreeList.GetParentItem(ht.hItem));
break;
}
switch (TV_GetCheckState(ht.hItem))
{
case TV_STATE_CHECKED: TV_SetCheckState(ht.hItem, TV_STATE_INDETERMINATE); break;
case TV_STATE_CLEAR: TV_SetCheckState(ht.hItem, TV_STATE_CHECKED); break;
case TV_STATE_INDETERMINATE: TV_SetCheckState(ht.hItem, TV_STATE_CLEAR); break;
}
if (g_Enhancements != nullptr)
{
g_Enhancements->UpdateCheats();
}
}
return 0;
}
2022-09-26 02:31:54 +00:00
LRESULT CEnhancementUI::OnPopupDelete(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled)
2022-01-27 03:32:32 +00:00
{
int Response = MessageBox(wGS(MSG_DEL_SURE).c_str(), wGS(MSG_DEL_TITLE).c_str(), MB_YESNO | MB_ICONQUESTION);
if (Response != IDYES)
{
return 0;
}
2022-09-26 02:31:54 +00:00
TVITEM item = {0};
2022-01-27 03:32:32 +00:00
item.hItem = m_hSelectedItem;
item.mask = TVIF_PARAM;
m_TreeList.GetItem(&item);
ChangeChildrenStatus(TVI_ROOT, false);
for (CEnhancementList::iterator itr = m_Enhancements.begin(); itr != m_Enhancements.end(); itr++)
{
if (item.lParam != (LPARAM)&itr->second)
{
continue;
}
m_Enhancements.erase(itr);
g_Enhancements->UpdateEnhancements(m_Enhancements);
break;
}
RefreshList();
return 0;
2022-01-27 03:32:32 +00:00
}
2022-09-26 02:31:54 +00:00
LRESULT CEnhancementUI::OnEnhancementListRClicked(NMHDR * pNMHDR)
2021-01-17 03:17:58 +00:00
{
2022-09-26 02:31:54 +00:00
TVHITTESTINFO ht = {0};
2021-01-17 03:17:58 +00:00
uint32_t dwpos = GetMessagePos();
ht.pt.x = GET_X_LPARAM(dwpos);
ht.pt.y = GET_Y_LPARAM(dwpos);
::MapWindowPoints(HWND_DESKTOP, pNMHDR->hwndFrom, &ht.pt, 1);
TreeView_HitTest(pNMHDR->hwndFrom, &ht);
m_hSelectedItem = ht.hItem;
POINT Mouse;
GetCursorPos(&Mouse);
2021-04-12 11:35:39 +00:00
HMENU hMenu = LoadMenu(GetModuleHandle(nullptr), MAKEINTRESOURCE(IDR_ENHANCEMENT_MENU));
2021-01-17 03:17:58 +00:00
HMENU hPopupMenu = GetSubMenu(hMenu, 0);
2021-04-12 11:35:39 +00:00
if (m_hSelectedItem == nullptr)
2021-01-17 03:17:58 +00:00
{
RemoveMenu(hPopupMenu, 3, MF_BYPOSITION);
RemoveMenu(hPopupMenu, 2, MF_BYPOSITION);
RemoveMenu(hPopupMenu, 1, MF_BYPOSITION);
}
2021-04-12 11:35:39 +00:00
TrackPopupMenu(hPopupMenu, 0, Mouse.x, Mouse.y, 0, m_hWnd, nullptr);
2021-01-17 03:17:58 +00:00
DestroyMenu(hMenu);
return TRUE;
}
2021-02-23 09:46:00 +00:00
LRESULT CEnhancementUI::OnEnhancementListDClicked(NMHDR * lpnmh)
2021-01-17 03:17:58 +00:00
{
uint32_t dwpos = GetMessagePos();
2022-09-26 02:31:54 +00:00
TVHITTESTINFO ht = {0};
2021-01-17 03:17:58 +00:00
ht.pt.x = GET_X_LPARAM(dwpos);
ht.pt.y = GET_Y_LPARAM(dwpos);
2021-02-23 09:46:00 +00:00
::MapWindowPoints(HWND_DESKTOP, lpnmh->hwndFrom, &ht.pt, 1);
2021-01-17 03:17:58 +00:00
2021-02-23 09:46:00 +00:00
TreeView_HitTest(lpnmh->hwndFrom, &ht);
2021-01-17 03:17:58 +00:00
if ((ht.flags & TVHT_ONITEMLABEL) == 0 || ht.hItem == 0)
{
return 0;
}
2022-09-26 02:31:54 +00:00
TVITEM item = {0};
2021-01-17 03:17:58 +00:00
item.mask = TVIF_PARAM;
item.hItem = (HTREEITEM)ht.hItem;
if (!m_TreeList.GetItem(&item) || item.lParam == NULL)
{
return 0;
}
CEditEnhancement(*this, (CEnhancement *)item.lParam).DoModal(m_hWnd);
RefreshList();
return 0;
}
LRESULT CEnhancementUI::OnEnhancementListSelChanged(NMHDR * /*lpnmh*/)
2021-02-23 09:46:00 +00:00
{
HTREEITEM hItem = m_TreeList.GetSelectedItem();
GetDlgItem(IDC_NOTES).SetWindowText(L"");
if (m_TreeList.GetChildItem(hItem) == nullptr)
{
2022-09-26 02:31:54 +00:00
TVITEM item = {0};
2021-02-23 09:46:00 +00:00
item.mask = TVIF_PARAM;
item.hItem = hItem;
m_TreeList.GetItem(&item);
if (item.lParam != NULL)
{
CEnhancement * Enhancement = (CEnhancement *)item.lParam;
GetDlgItem(IDC_NOTES).SetWindowText(stdstr(Enhancement->GetNote()).ToUTF16().c_str());
}
}
return 0;
}
2021-01-17 03:17:58 +00:00
void CEnhancementUI::AddCodeLayers(LPARAM Enhancement, const std::wstring & Name, HTREEITEM hParent, bool Active)
{
TV_INSERTSTRUCT tv;
wchar_t Text[500], Item[500];
2022-09-26 02:31:54 +00:00
if (Name.length() > ((sizeof(Text) / sizeof(Text[0])) - 5))
{
g_Notify->BreakPoint(__FILE__, __LINE__);
}
2021-01-17 03:17:58 +00:00
wcscpy(Text, Name.c_str());
2022-09-26 02:31:54 +00:00
if (wcschr(Text, L'\\') > 0)
{
*wcschr(Text, L'\\') = 0;
}
2021-01-17 03:17:58 +00:00
tv.item.mask = TVIF_TEXT;
tv.item.pszText = Item;
tv.item.cchTextMax = sizeof(Item);
tv.item.hItem = m_TreeList.GetChildItem(hParent);
while (tv.item.hItem)
{
m_TreeList.GetItem(&tv.item);
if (wcscmp(Text, Item) == 0)
{
TV_CHECK_STATE State = TV_GetCheckState(tv.item.hItem);
if ((Active && State == TV_STATE_CLEAR) || (!Active && State == TV_STATE_CHECKED))
{
TV_SetCheckState(tv.item.hItem, TV_STATE_INDETERMINATE);
}
size_t StartPos = wcslen(Text) + 1;
std::wstring TempCheatName;
if (StartPos < Name.length())
{
TempCheatName = Name.substr(StartPos);
}
AddCodeLayers(Enhancement, TempCheatName, tv.item.hItem, Active);
return;
}
tv.item.hItem = m_TreeList.GetNextSiblingItem(tv.item.hItem);
}
tv.hInsertAfter = TVI_SORT;
tv.item.mask = TVIF_TEXT | TVIF_PARAM;
tv.item.pszText = Text;
tv.item.lParam = Enhancement;
tv.hParent = hParent;
hParent = m_TreeList.InsertItem(&tv);
TV_SetCheckState(hParent, Active ? TV_STATE_CHECKED : TV_STATE_CLEAR);
2022-09-26 02:31:54 +00:00
if (wcscmp(Text, Name.c_str()) == 0)
{
return;
}
2021-01-17 03:17:58 +00:00
AddCodeLayers(Enhancement, Name.substr(wcslen(Text) + 1), hParent, Active);
}
void CEnhancementUI::ChangeChildrenStatus(HTREEITEM hParent, bool Checked)
{
2022-09-26 02:31:54 +00:00
HTREEITEM hItem = m_TreeList.GetChildItem(hParent);
;
2021-04-12 11:35:39 +00:00
if (hItem == nullptr)
{
2022-09-26 02:31:54 +00:00
if (hParent == TVI_ROOT)
{
return;
}
2022-09-26 02:31:54 +00:00
TVITEM item = {0};
item.mask = TVIF_PARAM;
item.hItem = hParent;
m_TreeList.GetItem(&item);
if (item.lParam == NULL)
{
return;
}
CEnhancement * Enhancement = (CEnhancement *)item.lParam;
if (Checked && Enhancement->CodeOptionSize() != 0 && Enhancement->GetOptions().size() > 0 && !Enhancement->OptionSelected())
{
return;
}
TV_SetCheckState(hParent, Checked ? TV_STATE_CHECKED : TV_STATE_CLEAR);
Enhancement->SetActive(Checked);
if (g_Enhancements != nullptr)
{
g_Enhancements->UpdateCheats();
}
return;
}
TV_CHECK_STATE state = TV_STATE_UNKNOWN;
2021-04-12 11:35:39 +00:00
while (hItem != nullptr)
{
TV_CHECK_STATE ChildState = TV_GetCheckState(hItem);
2022-09-26 02:31:54 +00:00
if ((ChildState != TV_STATE_CHECKED || !Checked) && (ChildState != TV_STATE_CLEAR || Checked))
{
ChangeChildrenStatus(hItem, Checked);
}
ChildState = TV_GetCheckState(hItem);
2022-09-26 02:31:54 +00:00
if (state == TV_STATE_UNKNOWN)
{
state = ChildState;
}
if (state != ChildState)
{
state = TV_STATE_INDETERMINATE;
}
hItem = m_TreeList.GetNextSiblingItem(hItem);
}
if (state != TV_STATE_UNKNOWN)
{
TV_SetCheckState(hParent, state);
}
}
void CEnhancementUI::CheckParentStatus(HTREEITEM hParent)
{
2021-04-12 11:35:39 +00:00
if (hParent == nullptr)
{
return;
}
HTREEITEM hItem = m_TreeList.GetChildItem(hParent);
TV_CHECK_STATE InitialState = TV_GetCheckState(hParent);
TV_CHECK_STATE CurrentState = TV_GetCheckState(hItem);
2021-04-12 11:35:39 +00:00
while (hItem != nullptr)
{
if (TV_GetCheckState(hItem) != CurrentState)
{
CurrentState = TV_STATE_INDETERMINATE;
break;
}
hItem = m_TreeList.GetNextSiblingItem(hItem);
}
TV_SetCheckState(hParent, CurrentState);
if (InitialState != CurrentState)
{
CheckParentStatus(m_TreeList.GetParentItem(hParent));
}
}
2021-01-17 03:17:58 +00:00
void CEnhancementUI::RefreshList()
{
m_TreeList.DeleteAllItems();
for (CEnhancementList::iterator itr = m_Enhancements.begin(); itr != m_Enhancements.end(); itr++)
{
std::string Name = itr->second.GetNameAndExtension();
if (Name.length() == 0)
{
continue;
}
AddCodeLayers((LPARAM)&itr->second, stdstr(Name).ToUTF16(), TVI_ROOT, itr->second.Active());
}
}
CEnhancementUI::TV_CHECK_STATE CEnhancementUI::TV_GetCheckState(HTREEITEM hItem)
{
2022-09-26 02:31:54 +00:00
TVITEM tvItem = {0};
2021-01-17 03:17:58 +00:00
tvItem.mask = TVIF_HANDLE | TVIF_STATE;
tvItem.hItem = hItem;
tvItem.stateMask = TVIS_STATEIMAGEMASK;
m_TreeList.GetItem(&tvItem);
switch (tvItem.state >> 12)
{
case 1: return TV_STATE_CHECKED;
case 2: return TV_STATE_CLEAR;
case 3: return TV_STATE_INDETERMINATE;
}
return TV_STATE_UNKNOWN;
}
bool CEnhancementUI::TV_SetCheckState(HTREEITEM hItem, TV_CHECK_STATE state)
{
2022-09-26 02:31:54 +00:00
TVITEM tvItem = {0};
2021-01-17 03:17:58 +00:00
tvItem.mask = TVIF_HANDLE | TVIF_STATE;
tvItem.hItem = (HTREEITEM)hItem;
tvItem.stateMask = TVIS_STATEIMAGEMASK;
switch (state)
{
case TV_STATE_CHECKED: tvItem.state = INDEXTOSTATEIMAGEMASK(1); break;
case TV_STATE_CLEAR: tvItem.state = INDEXTOSTATEIMAGEMASK(2); break;
case TV_STATE_INDETERMINATE: tvItem.state = INDEXTOSTATEIMAGEMASK(3); break;
default: tvItem.state = INDEXTOSTATEIMAGEMASK(0); break;
}
return m_TreeList.SetItem(&tvItem) != 0;
}
CEditEnhancement::CEditEnhancement(CEnhancementUI & EnhancementUI, CEnhancement * Enhancement) :
m_EnhancementUI(EnhancementUI),
m_EditEnhancement(Enhancement)
{
}
2022-09-26 02:31:54 +00:00
LRESULT CEditEnhancement::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
2021-01-17 03:17:58 +00:00
{
m_Entries = m_EditEnhancement != nullptr ? m_EditEnhancement->GetEntries() : CEnhancement::CodeEntries();
2021-02-11 11:26:09 +00:00
m_PluginList = m_EditEnhancement != nullptr ? m_EditEnhancement->GetPluginList() : CEnhancement::PluginList();
2021-01-17 03:17:58 +00:00
GetDlgItem(IDC_CODE_NAME).SetWindowText(m_EditEnhancement != nullptr ? stdstr(m_EditEnhancement->GetName()).ToUTF16().c_str() : L"");
2021-07-12 22:47:16 +00:00
GetDlgItem(IDC_CODE_AUTHOR).SetWindowText(m_EditEnhancement != nullptr ? stdstr(m_EditEnhancement->GetAuthor()).ToUTF16().c_str() : L"");
2021-01-17 03:17:58 +00:00
GetDlgItem(IDC_NOTES).SetWindowText(m_EditEnhancement != nullptr ? stdstr(m_EditEnhancement->GetNote()).ToUTF16().c_str() : L"");
CButton(GetDlgItem(IDC_AUTOON)).SetCheck(m_EditEnhancement != nullptr ? (m_EditEnhancement->GetOnByDefault() ? BST_CHECKED : BST_UNCHECKED) : BST_UNCHECKED);
CButton(GetDlgItem(IDC_GAMESHARK)).SetCheck(m_Entries.size() > 0 ? BST_CHECKED : BST_UNCHECKED);
2021-03-10 07:39:01 +00:00
CButton(GetDlgItem(IDC_OVERCLOCK)).SetCheck(m_EditEnhancement != nullptr ? (m_EditEnhancement->OverClock() ? BST_CHECKED : BST_UNCHECKED) : BST_UNCHECKED);
2022-09-26 02:31:54 +00:00
GetDlgItem(IDC_OVER_CLOCK_MODIFIER).SetWindowText(m_EditEnhancement != nullptr ? stdstr_f("%d", m_EditEnhancement->OverClockModifier()).ToUTF16().c_str() : L"1");
2021-03-10 07:39:01 +00:00
GetDlgItem(IDC_OVER_CLOCK_MODIFIER).EnableWindow(m_EditEnhancement != nullptr ? m_EditEnhancement->OverClock() : false);
2021-01-17 03:17:58 +00:00
return TRUE;
}
LRESULT CEditEnhancement::OnGamesharkBtn(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{
CButton(GetDlgItem(IDC_GAMESHARK)).SetCheck(m_Entries.size() > 0 ? BST_CHECKED : BST_UNCHECKED);
2021-02-11 11:26:09 +00:00
CEditGS(m_Entries, m_PluginList).DoModal(m_hWnd);
2021-01-17 03:17:58 +00:00
CButton(GetDlgItem(IDC_GAMESHARK)).SetCheck(m_Entries.size() > 0 ? BST_CHECKED : BST_UNCHECKED);
return 0;
}
2021-03-10 07:39:01 +00:00
LRESULT CEditEnhancement::OnOverClockBtn(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{
GetDlgItem(IDC_OVER_CLOCK_MODIFIER).EnableWindow(CButton(GetDlgItem(IDC_OVERCLOCK)).GetCheck() == BST_CHECKED);
return 0;
}
2022-09-26 02:31:54 +00:00
LRESULT CEditEnhancement::OnEditGameshark(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
2021-01-17 03:17:58 +00:00
{
OnGamesharkBtn(0, 0, 0);
return TRUE;
}
2022-09-26 02:31:54 +00:00
LRESULT CEditEnhancement::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
2021-01-17 03:17:58 +00:00
{
EndDialog(wID);
return TRUE;
}
2022-09-26 02:31:54 +00:00
LRESULT CEditEnhancement::OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
2021-01-17 03:17:58 +00:00
{
2021-03-10 07:39:01 +00:00
CEnhancement TempEnhancement(CEnhancement::EnhancementIdent);
CEnhancement & Enhancement = m_EditEnhancement != nullptr ? *m_EditEnhancement : TempEnhancement;
Enhancement.SetName(GetCWindowText(GetDlgItem(IDC_CODE_NAME)).c_str());
2021-07-12 22:47:16 +00:00
Enhancement.SetAuthor(GetCWindowText(GetDlgItem(IDC_CODE_AUTHOR)).c_str());
2021-03-10 07:39:01 +00:00
Enhancement.SetOnByDefault(CButton(GetDlgItem(IDC_AUTOON)).GetCheck() == BST_CHECKED);
Enhancement.SetOverClock(CButton(GetDlgItem(IDC_OVERCLOCK)).GetCheck() == BST_CHECKED, atoi(GetCWindowText(GetDlgItem(IDC_OVER_CLOCK_MODIFIER)).c_str()));
Enhancement.SetEntries(m_Entries);
Enhancement.SetPluginList(m_PluginList);
Enhancement.SetNote(GetCWindowText(GetDlgItem(IDC_NOTES)).c_str());
2021-01-17 03:17:58 +00:00
CEnhancementList & Enhancements = m_EnhancementUI.m_Enhancements;
2021-03-10 07:39:01 +00:00
if (m_EditEnhancement == nullptr)
2021-01-17 03:17:58 +00:00
{
2021-03-10 07:39:01 +00:00
Enhancements.AddItem(TempEnhancement);
2021-01-17 03:17:58 +00:00
}
g_Enhancements->UpdateEnhancements(Enhancements);
m_EnhancementUI.RefreshList();
EndDialog(wID);
return TRUE;
}
2021-02-11 11:26:09 +00:00
CEditGS::CEditGS(CEnhancement::CodeEntries & Entries, CEnhancement::PluginList & PluginList) :
m_Entries(Entries),
m_PluginList(PluginList)
2021-01-17 03:17:58 +00:00
{
}
2022-09-26 02:31:54 +00:00
LRESULT CEditGS::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
2021-01-17 03:17:58 +00:00
{
stdstr Buffer;
for (size_t i = 0, n = m_Entries.size(); i < n; i++)
{
const CEnhancement::CodeEntry Entry = m_Entries[i];
if (!Buffer.empty())
{
Buffer.append("\r\n");
}
Buffer += stdstr_f("%08X %s", Entry.Command, Entry.Value.c_str());
}
CEdit CheatCodes(GetDlgItem(IDC_CHEAT_CODES));
CheatCodes.SetWindowText(Buffer.ToUTF16().c_str());
2021-02-11 11:26:09 +00:00
CButton(GetDlgItem(IDC_CHK_LIMIT_PLUGINS)).SetCheck(m_PluginList.size() > 0 ? BST_CHECKED : BST_UNCHECKED);
2021-01-17 03:17:58 +00:00
return TRUE;
}
2021-02-11 11:26:09 +00:00
LRESULT CEditGS::OnPluginBtn(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{
CButton(GetDlgItem(IDC_CHK_LIMIT_PLUGINS)).SetCheck(m_PluginList.size() > 0 ? BST_CHECKED : BST_UNCHECKED);
CEditPluginList(m_PluginList).DoModal(m_hWnd);
CButton(GetDlgItem(IDC_CHK_LIMIT_PLUGINS)).SetCheck(m_PluginList.size() > 0 ? BST_CHECKED : BST_UNCHECKED);
return 0;
}
2022-09-26 02:31:54 +00:00
LRESULT CEditGS::OnEditPlugins(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
2021-02-11 11:26:09 +00:00
{
OnPluginBtn(0, 0, 0);
return 0;
}
2022-09-26 02:31:54 +00:00
LRESULT CEditGS::OnCheatChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
2021-01-17 03:17:58 +00:00
{
CEnhancement::CodeEntries Entries;
GetDlgItem(IDOK).EnableWindow(CheatCode(Entries));
return true;
}
2022-09-26 02:31:54 +00:00
LRESULT CEditGS::OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
2021-01-17 03:17:58 +00:00
{
CEnhancement::CodeEntries Entries;
if (CheatCode(Entries))
{
m_Entries = Entries;
EndDialog(wID);
}
return TRUE;
}
2022-09-26 02:31:54 +00:00
LRESULT CEditGS::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
2021-01-17 03:17:58 +00:00
{
EndDialog(wID);
return TRUE;
}
bool CEditGS::CheatCode(CEnhancement::CodeEntries & Entries)
{
Entries.clear();
bool ValidCode = true;
CEdit CheatCodes(GetDlgItem(IDC_CHEAT_CODES));
uint32_t numlines = CheatCodes.GetLineCount();
for (uint32_t line = 0; line < numlines; line++)
{
const char * formatnormal = "XXXXXXXX XXXX";
2022-09-26 02:31:54 +00:00
wchar_t wstr[128] = {0};
2021-01-17 03:17:58 +00:00
*(LPWORD)wstr = sizeof(wstr) / sizeof(wstr[0]);
uint32_t len = CheatCodes.GetLine(line, wstr);
wstr[len] = 0;
2022-09-26 02:31:54 +00:00
if (len <= 0)
{
continue;
}
2021-01-17 03:17:58 +00:00
std::string str = stdstr().FromUTF16(wstr);
2022-09-26 02:31:54 +00:00
char tempformat[128] = {0};
2021-01-17 03:17:58 +00:00
for (uint32_t i = 0; i < sizeof(tempformat); i++)
{
if (isxdigit(str[i]))
{
tempformat[i] = 'X';
}
if (str[i] == ' ')
{
tempformat[i] = str[i];
}
2022-09-26 02:31:54 +00:00
if (str[i] == 0)
{
break;
}
2021-01-17 03:17:58 +00:00
}
if (strcmp(tempformat, formatnormal) == 0)
{
CEnhancement::CodeEntry Entry;
Entry.Command = strtoul(str.c_str(), 0, 16);
const char * ReadPos = strchr(str.c_str(), ' ');
if (ReadPos != nullptr)
{
Entry.Value = ReadPos + 1;
Entries.push_back(Entry);
}
else
{
ValidCode = false;
break;
}
}
else
{
ValidCode = false;
break;
}
}
if (ValidCode && Entries.size() > 0)
{
CEnhancement Item("");
Item.SetName("Test");
Item.SetEntries(Entries);
if (!Item.Valid() || Item.CodeOptionSize() != 0)
{
return false;
}
}
return ValidCode;
}
2021-02-11 11:26:09 +00:00
CEditPluginList::CEditPluginList(CEnhancement::PluginList & List) :
m_PluginList(List)
{
}
2022-09-26 02:31:54 +00:00
LRESULT CEditPluginList::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
2021-02-11 11:26:09 +00:00
{
m_PluginListBox.Attach(GetDlgItem(IDC_PLUGIN_LIST));
for (size_t i = 0, n = m_PluginList.size(); i < n; i++)
{
m_PluginListBox.AddString(stdstr(m_PluginList[i]).ToUTF16().c_str());
}
return TRUE;
}
LRESULT CEditPluginList::OnAddBtn(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{
2022-09-26 02:31:54 +00:00
CWindow hEdit = GetDlgItem(IDC_ADD_EDIT);
2021-02-11 11:26:09 +00:00
stdstr PluginName = stdstr(GetCWindowText(hEdit)).Trim();
std::wstring wPluginName = PluginName.ToUTF16();
if (PluginName.empty())
{
return 0;
}
for (int i = 0, n = m_PluginListBox.GetCount(); i < n; i++)
{
int nLen = m_PluginListBox.GetTextLen(i);
if (nLen == 0)
{
continue;
}
std::wstring WindowText;
WindowText.resize(nLen + 1);
m_PluginListBox.GetText(i, (wchar_t *)WindowText.c_str());
if (strcmp(stdstr().FromUTF16(WindowText.c_str()).c_str(), PluginName.c_str()) == 0)
{
return 0;
}
}
hEdit.SetWindowText(L"");
m_PluginListBox.AddString(wPluginName.c_str());
return 0;
}
LRESULT CEditPluginList::OnRemoveBtn(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{
int index = m_PluginListBox.GetCurSel();
if (index >= 0)
{
m_PluginListBox.DeleteString(index);
}
return 0;
}
LRESULT CEditPluginList::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{
EndDialog(wID);
return 0;
}
LRESULT CEditPluginList::OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{
CEnhancement::PluginList PluginList;
for (int i = 0, n = m_PluginListBox.GetCount(); i < n; i++)
{
int nLen = m_PluginListBox.GetTextLen(i);
if (nLen == 0)
{
continue;
}
std::wstring WindowText;
WindowText.resize(nLen + 1);
m_PluginListBox.GetText(i, (wchar_t *)WindowText.c_str());
PluginList.push_back(stdstr().FromUTF16(WindowText.c_str()));
}
m_PluginList = PluginList;
EndDialog(wID);
return 0;
2021-03-17 08:28:53 +00:00
}