Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract achievement serialization logic into service #1132

Merged
merged 3 commits into from
Dec 21, 2024
Merged
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
2 changes: 2 additions & 0 deletions src/RA_Integration.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<ClCompile Include="RA_Json.cpp" />
<ClCompile Include="RA_md5factory.cpp" />
<ClCompile Include="RA_StringUtils.cpp" />
<ClCompile Include="services\AchievementLogicSerializer.cpp" />
<ClCompile Include="services\AchievementRuntime.cpp" />
<ClCompile Include="services\AchievementRuntimeExports.cpp" />
<ClCompile Include="services\FrameEventQueue.cpp" />
Expand Down Expand Up @@ -232,6 +233,7 @@
<ClInclude Include="RA_md5factory.h" />
<ClInclude Include="RA_Resource.h" />
<ClInclude Include="RA_StringUtils.h" />
<ClInclude Include="services\AchievementLogicSerializer.hh" />
<ClInclude Include="services\AchievementRuntime.hh" />
<ClInclude Include="services\AchievementRuntimeExports.hh" />
<ClInclude Include="services\FrameEventQueue.hh" />
Expand Down
6 changes: 6 additions & 0 deletions src/RA_Integration.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,9 @@
<ClCompile Include="data\models\CodeNoteModel.cpp">
<Filter>Data\Models</Filter>
</ClCompile>
<ClCompile Include="services\AchievementLogicSerializer.cpp">
<Filter>Services</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="RA_Resource.h">
Expand Down Expand Up @@ -977,6 +980,9 @@
<ClInclude Include="data\models\CodeNoteModel.hh">
<Filter>Data\Models</Filter>
</ClInclude>
<ClInclude Include="services\AchievementLogicSerializer.hh">
<Filter>Services</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="RA_Shared.rc">
Expand Down
9 changes: 9 additions & 0 deletions src/RA_StringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ bool ParseHex(const std::wstring& sValue, unsigned int nMaximumValue, unsigned i
return false;
}

_Use_decl_annotations_
bool ParseNumeric(const std::wstring& sValue, _Out_ unsigned int& nValue, _Out_ std::wstring& sError)
{
if (sValue.length() > 2 && sValue.at(1) == 'x')
return ra::ParseHex(sValue, 0xFFFFFFFF, nValue, sError);

return ra::ParseUnsignedInt(sValue, 0xFFFFFFFF, nValue, sError);
}

_Use_decl_annotations_
bool ParseFloat(const std::wstring& sValue, float& fValue, std::wstring& sError)
{
Expand Down
1 change: 1 addition & 0 deletions src/RA_StringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ _NODISCARD std::string Narrow(_In_ const std::string& wstr);

bool ParseUnsignedInt(const std::wstring& sValue, unsigned int nMaximumValue, _Out_ unsigned int& nValue, _Out_ std::wstring& sError);
bool ParseHex(const std::wstring& sValue, unsigned int nMaximumValue, _Out_ unsigned int& nValue, _Out_ std::wstring& sError);
bool ParseNumeric(const std::wstring& sValue, _Out_ unsigned int& nValue, _Out_ std::wstring& sError);
bool ParseFloat(const std::wstring& sValue, _Out_ float& fValue, _Out_ std::wstring& sError);

/// <summary>
Expand Down
65 changes: 65 additions & 0 deletions src/data/context/ConsoleContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,71 @@ ra::ByteAddress ConsoleContext::ByteAddressFromRealAddress(ra::ByteAddress nReal
return 0xFFFFFFFF;
}

ra::ByteAddress ConsoleContext::RealAddressFromByteAddress(ra::ByteAddress nByteAddress) const noexcept
{
for (const auto& pRegion : m_vRegions)
{
if (pRegion.EndAddress >= nByteAddress && pRegion.StartAddress <= nByteAddress)
return nByteAddress + pRegion.RealAddress;
}

return 0xFFFFFFFF;
}

bool ConsoleContext::GetRealAddressConversion(MemSize* nReadSize, uint32_t* nMask, uint32_t* nOffset) const
{
Expects(nReadSize != nullptr);
Expects(nMask != nullptr);
Expects(nOffset != nullptr);

switch (m_nId)
{
case ConsoleID::Dreamcast:
case ConsoleID::DSi:
case ConsoleID::PlayStation:
*nReadSize = MemSize::TwentyFourBit;
*nMask = 0xFFFFFFFF;
*nOffset = 0;
return true;

case ConsoleID::GameCube:
case ConsoleID::WII:
*nReadSize = MemSize::ThirtyTwoBitBigEndian;
*nMask = 0x01FFFFFF;
*nOffset = 0;
return true;

case ConsoleID::PlayStation2:
case ConsoleID::PSP:
*nReadSize = MemSize::ThirtyTwoBit;
*nMask = 0x01FFFFFF;
*nOffset = 0;
return true;

default:
for (const auto& pRegion : m_vRegions)
{
if (pRegion.Type == AddressType::SystemRAM)
{
*nOffset = (pRegion.RealAddress - pRegion.StartAddress);
*nMask = 0xFFFFFFFF;

if (m_nMaxAddress > 0x00FFFFFF)
*nReadSize = MemSize::ThirtyTwoBit;
else if (m_nMaxAddress > 0x0000FFFF)
*nReadSize = MemSize::TwentyFourBit;
else if (m_nMaxAddress > 0x000000FF)
*nReadSize = MemSize::SixteenBit;
else
*nReadSize = MemSize::EightBit;

return true;
}
}
return false;
}
}

} // namespace context
} // namespace data
} // namespace ra
16 changes: 16 additions & 0 deletions src/data/context/ConsoleContext.hh
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ public:
/// <returns>Converted address, or <c>0xFFFFFFFF</c> if conversion could not be completed.
ra::ByteAddress ByteAddressFromRealAddress(ra::ByteAddress nRealAddress) const noexcept;

/// <summary>
/// Converts an "RetroAchievements" address into a real address where the data might be found.
/// </summary>
/// <returns>Converted address, or <c>0xFFFFFFFF</c> if conversion could not be completed.
ra::ByteAddress RealAddressFromByteAddress(ra::ByteAddress nRealAddress) const noexcept;

/// <summary>
/// Gets the read size and mask to use for reading a pointer from memory and converting it to
/// a RetroAchievements address.
/// </summary>
/// <param name="nReadSize">[out] the size to read.</param>
/// <param name="nMask">[out] the mask to apply (if 0xFFFFFFFF, no mask is necessary).</param>
/// <param name="nOffset">[out] the offset to apply (if 0, no offset is necessary).</param>
/// <returns><c>true<c> if a mapping was found, <c>false</c> if not.</returns>
bool GetRealAddressConversion(MemSize* nReadSize, uint32_t* nMask, uint32_t* nOffset) const;

/// <summary>
/// Gets the maximum valid address for the console.
/// </summary>
Expand Down
Loading
Loading