Skip to content

Commit

Permalink
update rcheevos
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamiras committed Mar 2, 2024
1 parent a1aa95f commit 6d63ace
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 89 deletions.
12 changes: 6 additions & 6 deletions src/RA_Integration.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;RA_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
Expand All @@ -467,7 +467,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)'=='Analysis'">
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>NDEBUG;RA_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
Expand Down Expand Up @@ -497,7 +497,7 @@
<Optimization>Full</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PreprocessorDefinitions>NDEBUG;RA_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
Expand All @@ -516,7 +516,7 @@
<Optimization>Full</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PreprocessorDefinitions>NDEBUG;RA_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
Expand All @@ -535,7 +535,7 @@
<Optimization>Full</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PreprocessorDefinitions>NDEBUG;RA_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
Expand All @@ -555,7 +555,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<WholeProgramOptimization>true</WholeProgramOptimization>
<AdditionalIncludeDirectories>..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NDEBUG;RA_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
Expand Down
2 changes: 1 addition & 1 deletion src/base.props
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<ForcedIncludeFiles>pch.h</ForcedIncludeFiles>
<PreprocessorDefinitions>_ARCH=$(PlatformArchitecture);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_ARCH=$(PlatformArchitecture);RC_CLIENT_SUPPORTS_HASH;RA_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
</ClCompile>
Expand Down
8 changes: 4 additions & 4 deletions src/rcheevos.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;RC_DISABLE_LUA;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;RC_DISABLE_LUA;RC_CLIENT_SUPPORTS_HASH;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CompileAs>CompileAsC</CompileAs>
<AdditionalIncludeDirectories>$(SolutionDir)lua;$(SolutionDir)rcheevos\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ExceptionHandling>false</ExceptionHandling>
Expand All @@ -89,7 +89,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;RC_DISABLE_LUA;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;RC_DISABLE_LUA;RC_CLIENT_SUPPORTS_HASH;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CompileAs>CompileAsC</CompileAs>
<AdditionalIncludeDirectories>$(SolutionDir)lua;$(SolutionDir)rcheevos\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ExceptionHandling>false</ExceptionHandling>
Expand All @@ -112,7 +112,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;RC_DISABLE_LUA;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;RC_DISABLE_LUA;RC_CLIENT_SUPPORTS_HASH;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CompileAs>CompileAsC</CompileAs>
<AdditionalIncludeDirectories>$(SolutionDir)lua;$(SolutionDir)rcheevos\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ExceptionHandling>false</ExceptionHandling>
Expand All @@ -130,7 +130,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;RC_DISABLE_LUA;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;RC_DISABLE_LUA;RC_CLIENT_SUPPORTS_HASH;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CompileAs>CompileAsC</CompileAs>
<AdditionalIncludeDirectories>$(SolutionDir)lua;$(SolutionDir)rcheevos\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ExceptionHandling>false</ExceptionHandling>
Expand Down
8 changes: 4 additions & 4 deletions src/services/AchievementRuntimeExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,16 +463,16 @@ class AchievementRuntimeExports : private AchievementRuntime
return rc_client_progress_size(pClient.GetClient());
}

static int serialize_progress(uint8_t* buffer)
static int serialize_progress(uint8_t* buffer, size_t buffer_size)
{
const auto& pClient = ra::services::ServiceLocator::Get<ra::services::AchievementRuntime>();
return rc_client_serialize_progress(pClient.GetClient(), buffer);
return rc_client_serialize_progress_sized(pClient.GetClient(), buffer, buffer_size);
}

static int deserialize_progress(const uint8_t* buffer)
static int deserialize_progress(const uint8_t* buffer, size_t buffer_size)
{
auto& pClient = ra::services::ServiceLocator::GetMutable<ra::services::AchievementRuntime>();
return rc_client_deserialize_progress(pClient.GetClient(), buffer);
return rc_client_deserialize_progress_sized(pClient.GetClient(), buffer, buffer_size);
}

static void set_raintegration_write_memory_function(rc_client_t* client, rc_client_raintegration_write_memory_func_t handler) noexcept
Expand Down
140 changes: 75 additions & 65 deletions src/ui/viewmodels/MemorySearchViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,7 @@ void MemorySearchViewModel::UpdateResults()
if (!pDesktop.IsOnUIThread())
{
m_bUpdateResultsPending = true;
pDesktop.InvokeOnUIThread([this]()
{
pDesktop.InvokeOnUIThread([this]() {
if (m_bUpdateResultsPending)
{
m_bUpdateResultsPending = false;
Expand All @@ -760,91 +759,102 @@ void MemorySearchViewModel::UpdateResults()
return;
}

std::lock_guard lock(m_oMutex);
// inlining this code was causing an analysis warning suggesting the lock was being released from
// the early returns above
DoUpdateResults();
}

if (m_vSearchResults.size() < 2)
return;
void MemorySearchViewModel::DoUpdateResults()
{
// intentionally release the lock before calling EndUpdate to ensure callbacks aren't within the lock scope
{
std::lock_guard lock(m_oMutex);

const auto& pCurrentResults = *m_vSearchResults.at(m_nSelectedSearchResult).get();
ra::services::SearchResults::Result pResult;
const auto nIndex = gsl::narrow_cast<gsl::index>(GetScrollOffset());
if (m_vSearchResults.size() < 2)
return;

const auto& vmBookmarks = ra::services::ServiceLocator::Get<ra::ui::viewmodels::WindowManager>().MemoryBookmarks;
const auto& pGameContext = ra::services::ServiceLocator::Get<ra::data::context::GameContext>();
const auto& pConsoleContext = ra::services::ServiceLocator::Get<ra::data::context::ConsoleContext>();
const auto& pEmulatorContext = ra::services::ServiceLocator::Get<ra::data::context::EmulatorContext>();
const auto* pCodeNotes = pGameContext.Assets().FindCodeNotes();
const auto& pCurrentResults = *m_vSearchResults.at(m_nSelectedSearchResult).get();
ra::services::SearchResults::Result pResult;
const auto nIndex = gsl::narrow_cast<gsl::index>(GetScrollOffset());

m_vResults.RemoveNotifyTarget(*this);
m_vResults.BeginUpdate();
const auto& vmBookmarks = ra::services::ServiceLocator::Get<ra::ui::viewmodels::WindowManager>().MemoryBookmarks;
const auto& pGameContext = ra::services::ServiceLocator::Get<ra::data::context::GameContext>();
const auto& pConsoleContext = ra::services::ServiceLocator::Get<ra::data::context::ConsoleContext>();
const auto& pEmulatorContext = ra::services::ServiceLocator::Get<ra::data::context::EmulatorContext>();
const auto* pCodeNotes = pGameContext.Assets().FindCodeNotes();

unsigned int nRow = 0;
while (nRow < SEARCH_ROWS_DISPLAYED)
{
if (!pCurrentResults.pResults.GetMatchingAddress(nIndex + nRow, pResult))
break;
m_vResults.RemoveNotifyTarget(*this);
m_vResults.BeginUpdate();

auto* pRow = m_vResults.GetItemAt(nRow);
if (pRow == nullptr)
unsigned int nRow = 0;
while (nRow < SEARCH_ROWS_DISPLAYED)
{
pRow = &m_vResults.Add();
Ensures(pRow != nullptr);
}
if (!pCurrentResults.pResults.GetMatchingAddress(nIndex + nRow, pResult))
break;

pRow->nAddress = pResult.nAddress;
auto* pRow = m_vResults.GetItemAt(nRow);
if (pRow == nullptr)
{
pRow = &m_vResults.Add();
Ensures(pRow != nullptr);
}

auto sAddress = ra::ByteAddressToString(pResult.nAddress);
switch (pResult.nSize)
{
case MemSize::Nibble_Lower:
sAddress.push_back('L');
pRow->nAddress <<= 1;
break;
pRow->nAddress = pResult.nAddress;

case MemSize::Nibble_Upper:
sAddress.push_back('U');
pRow->nAddress = (pRow->nAddress << 1) | 1;
break;
}
auto sAddress = ra::ByteAddressToString(pResult.nAddress);
switch (pResult.nSize)
{
case MemSize::Nibble_Lower:
sAddress.push_back('L');
pRow->nAddress <<= 1;
break;

pRow->SetAddress(ra::Widen(sAddress));
case MemSize::Nibble_Upper:
sAddress.push_back('U');
pRow->nAddress = (pRow->nAddress << 1) | 1;
break;
}

UpdateResult(*pRow, pCurrentResults.pResults, pResult, true, pEmulatorContext);
pRow->SetAddress(ra::Widen(sAddress));

const auto pCodeNote = (pCodeNotes != nullptr) ? pCodeNotes->FindCodeNote(pResult.nAddress, pResult.nSize) : std::wstring(L"");
if (!pCodeNote.empty())
{
pRow->bHasCodeNote = true;
pRow->SetDescription(pCodeNote);
pRow->SetDescriptionColor(ra::ui::Color(ra::to_unsigned(SearchResultViewModel::DescriptionColorProperty.GetDefaultValue())));
}
else
{
pRow->bHasCodeNote = false;
UpdateResult(*pRow, pCurrentResults.pResults, pResult, true, pEmulatorContext);

const auto* pRegion = pConsoleContext.GetMemoryRegion(pResult.nAddress);
if (pRegion)
const auto pCodeNote = (pCodeNotes != nullptr) ?
pCodeNotes->FindCodeNote(pResult.nAddress, pResult.nSize) : std::wstring(L"");
if (!pCodeNote.empty())
{
pRow->SetDescription(ra::Widen(pRegion->Description));
pRow->SetDescriptionColor(ra::ui::Color(0xFFA0A0A0));
pRow->bHasCodeNote = true;
pRow->SetDescription(pCodeNote);
pRow->SetDescriptionColor(ra::ui::Color(ra::to_unsigned(SearchResultViewModel::DescriptionColorProperty.GetDefaultValue())));
}
else
{
pRow->SetDescription(L"");
pRow->SetDescriptionColor(ra::ui::Color(ra::to_unsigned(SearchResultViewModel::DescriptionColorProperty.GetDefaultValue())));
pRow->bHasCodeNote = false;

const auto* pRegion = pConsoleContext.GetMemoryRegion(pResult.nAddress);
if (pRegion)
{
pRow->SetDescription(ra::Widen(pRegion->Description));
pRow->SetDescriptionColor(ra::ui::Color(0xFFA0A0A0));
}
else
{
pRow->SetDescription(L"");
pRow->SetDescriptionColor(ra::ui::Color(ra::to_unsigned(SearchResultViewModel::DescriptionColorProperty.GetDefaultValue())));
}
}
}

pRow->SetSelected(m_vSelectedAddresses.find(pRow->nAddress) != m_vSelectedAddresses.end());
pRow->SetSelected(m_vSelectedAddresses.find(pRow->nAddress) != m_vSelectedAddresses.end());

pRow->bHasBookmark = vmBookmarks.HasBookmark(pResult.nAddress);
pRow->bHasBeenModified = (pCurrentResults.vModifiedAddresses.find(pRow->nAddress) != pCurrentResults.vModifiedAddresses.end());
pRow->UpdateRowColor();
++nRow;
}
pRow->bHasBookmark = vmBookmarks.HasBookmark(pResult.nAddress);
pRow->bHasBeenModified = (pCurrentResults.vModifiedAddresses.find(pRow->nAddress) != pCurrentResults.vModifiedAddresses.end());
pRow->UpdateRowColor();
++nRow;
}

while (m_vResults.Count() > nRow)
m_vResults.RemoveAt(m_vResults.Count() - 1);
while (m_vResults.Count() > nRow)
m_vResults.RemoveAt(m_vResults.Count() - 1);
}

m_vResults.EndUpdate();
m_vResults.AddNotifyTarget(*this);
Expand Down
1 change: 1 addition & 0 deletions src/ui/viewmodels/MemorySearchViewModel.hh
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ private:
bool ParseFilterRange(_Out_ ra::ByteAddress& nStart, _Out_ ra::ByteAddress& nEnd);
void ApplyContinuousFilter();
void UpdateResults();
void DoUpdateResults();
void UpdateResult(SearchResultViewModel& pRow, const ra::services::SearchResults& pResults,
ra::services::SearchResults::Result& pResult, bool bForceFilterCheck,
const ra::data::context::EmulatorContext& pEmulatorContext);
Expand Down
Loading

0 comments on commit 6d63ace

Please sign in to comment.