Skip to content
Open
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: 0 additions & 2 deletions src/RA_Integration.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
<ClCompile Include="data\models\AchievementModel.cpp" />
<ClCompile Include="data\models\LeaderboardModel.cpp" />
<ClCompile Include="data\models\RichPresenceModel.cpp" />
<ClCompile Include="data\models\TriggerValidation.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
Expand Down Expand Up @@ -217,7 +216,6 @@
<ClInclude Include="data\models\AchievementModel.hh" />
<ClInclude Include="data\models\LeaderboardModel.hh" />
<ClInclude Include="data\models\RichPresenceModel.hh" />
<ClInclude Include="data\models\TriggerValidation.hh" />
<ClInclude Include="data\Types.hh" />
<ClInclude Include="Exports.hh" />
<ClInclude Include="pch.h" />
Expand Down
6 changes: 0 additions & 6 deletions src/RA_Integration.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,6 @@
<ClCompile Include="ui\viewmodels\IntegrationMenuViewModel.cpp">
<Filter>UI\ViewModels</Filter>
</ClCompile>
<ClCompile Include="data\models\TriggerValidation.cpp">
<Filter>Data\Models</Filter>
</ClCompile>
<ClCompile Include="ui\win32\NewAssetDialog.cpp">
<Filter>UI\Win32</Filter>
</ClCompile>
Expand Down Expand Up @@ -836,9 +833,6 @@
<ClInclude Include="ui\viewmodels\IntegrationMenuViewModel.hh">
<Filter>UI\ViewModels</Filter>
</ClInclude>
<ClInclude Include="data\models\TriggerValidation.hh">
<Filter>Data\Models</Filter>
</ClInclude>
<ClInclude Include="ui\win32\NewAssetDialog.hh">
<Filter>UI\Win32</Filter>
</ClInclude>
Expand Down
55 changes: 24 additions & 31 deletions src/data/context/GameContext.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#define RA_DATA_GAMECONTEXT_HH
#pragma once

#include "context/IGameContext.hh"

#include "services/ServiceLocator.hh"

#include "GameAssets.hh"

#include <string>
Expand All @@ -15,10 +19,13 @@ namespace ra {
namespace data {
namespace context {

class GameContext
class GameContext : public ra::context::IGameContext
{
public:
GSL_SUPPRESS_F6 GameContext() = default;
GSL_SUPPRESS_F6 GameContext()
: m_IGameContextOverride(this)
{
}
virtual ~GameContext() noexcept = default;
GameContext(const GameContext&) noexcept = delete;
GameContext& operator=(const GameContext&) noexcept = delete;
Expand Down Expand Up @@ -47,11 +54,6 @@ public:
/// </summary>
bool IsGameLoading() const noexcept { return m_nLoadCount != 0; }

/// <summary>
/// Gets the unique identifier of the currently loaded game.
/// </summary>
unsigned int GameId() const noexcept { return m_nGameId; }

/// <summary>
/// Gets the unique identifier of the currently loaded subset game.
/// </summary>
Expand Down Expand Up @@ -135,27 +137,6 @@ public:
GameAssets& Assets() noexcept { return m_vAssets; }
const GameAssets& Assets() const noexcept { return m_vAssets; }

class NotifyTarget
{
public:
NotifyTarget() noexcept = default;
virtual ~NotifyTarget() noexcept = default;
NotifyTarget(const NotifyTarget&) noexcept = delete;
NotifyTarget& operator=(const NotifyTarget&) noexcept = delete;
NotifyTarget(NotifyTarget&&) noexcept = default;
NotifyTarget& operator=(NotifyTarget&&) noexcept = default;

virtual void OnBeforeActiveGameChanged() noexcept(false) {}
virtual void OnActiveGameChanged() noexcept(false) {}
virtual void OnBeginGameLoad() noexcept(false) {}
virtual void OnEndGameLoad() noexcept(false) {}
virtual void OnMemoryNoteChanged(ra::data::ByteAddress, const std::wstring&) noexcept(false) {}
virtual void OnMemoryNoteMoved(ra::data::ByteAddress, ra::data::ByteAddress, const std::wstring&) noexcept(false) {}
};

void AddNotifyTarget(NotifyTarget& pTarget) noexcept { m_vNotifyTargets.Add(pTarget); }
void RemoveNotifyTarget(NotifyTarget& pTarget) noexcept { m_vNotifyTargets.Remove(pTarget); }

void DoFrame();

enum SubsetType
Expand Down Expand Up @@ -194,6 +175,17 @@ public:
void InitializeSubsets(const rc_api_fetch_game_sets_response_t* game_data_response);
uint32_t GetGameId(uint32_t nSubsetId) const noexcept;

ra::data::models::MemoryNotesModel& MemoryNotes() override
{
auto* pNotes = m_vAssets.FindMemoryNotes();
return pNotes ? *pNotes : m_oDefaultNotes;
}
const ra::data::models::MemoryNotesModel& MemoryNotes() const override
{
auto* pNotes = m_vAssets.FindMemoryNotes();
return pNotes ? *pNotes : m_oDefaultNotes;
}

private:
void FinishLoadGame(int nResult, const char* sErrorMessage, bool bWasPaused);
void MigrateSubsetUserFiles();
Expand All @@ -210,7 +202,6 @@ protected:
void BeginLoad();
void EndLoad();

unsigned int m_nGameId = 0;
unsigned int m_nActiveGameId = 0;
std::wstring m_sGameTitle;
std::string m_sGameHash;
Expand All @@ -219,14 +210,16 @@ protected:
std::vector<Subset> m_vSubsets;

private:
NotifyTargetSet<NotifyTarget> m_vNotifyTargets;

GameAssets m_vAssets;

std::atomic<int> m_nLoadCount = 0;
int m_nMasteryPopupId = 0;

std::mutex m_mLoadMutex;

// use the mock helper to register as both GameContext and IGameContext
ra::services::ServiceLocator::ServiceOverride<ra::context::IGameContext> m_IGameContextOverride;
ra::data::models::MemoryNotesModel m_oDefaultNotes;
};

} // namespace context
Expand Down
3 changes: 3 additions & 0 deletions src/devkit/RADevKit.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<ClCompile Include="data\models\MemoryNoteModel.cpp" />
<ClCompile Include="data\models\MemoryNotesModel.cpp" />
<ClCompile Include="data\models\MemoryRegionsModel.cpp" />
<ClCompile Include="data\models\TriggerValidation.cpp" />
<ClCompile Include="data\Value.cpp" />
<ClCompile Include="services\Http.cpp" />
<ClCompile Include="ui\ImageReference.cpp" />
Expand All @@ -82,6 +83,7 @@
<ClCompile Include="util\Tokenizer.cpp" />
<ClInclude Include="context\IConsoleContext.hh" />
<ClInclude Include="context\IEmulatorMemoryContext.hh" />
<ClInclude Include="context\IGameContext.hh" />
<ClInclude Include="context\impl\ConsoleContext.hh" />
<ClInclude Include="context\impl\EmulatorMemoryContext.hh" />
<ClInclude Include="context\impl\RcClient.hh" />
Expand All @@ -102,6 +104,7 @@
<ClInclude Include="data\models\MemoryNoteModel.hh" />
<ClInclude Include="data\models\MemoryNotesModel.hh" />
<ClInclude Include="data\models\MemoryRegionsModel.hh" />
<ClInclude Include="data\models\TriggerValidation.hh" />
<ClInclude Include="data\NotifyTargetSet.hh" />
<ClInclude Include="data\Value.hh" />
<ClInclude Include="services\Http.hh" />
Expand Down
3 changes: 3 additions & 0 deletions src/devkit/RADevKit.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@
</ClInclude>
<ClInclude Include="ui\IImageRepository.hh" />
<ClInclude Include="ui\ImageReference.hh" />
<ClInclude Include="context\IGameContext.hh" />
<ClInclude Include="data\models\TriggerValidation.hh" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="util\GSL.cpp">
Expand Down Expand Up @@ -248,5 +250,6 @@
<Filter>data\models</Filter>
</ClCompile>
<ClCompile Include="ui\ImageReference.cpp" />
<ClCompile Include="data\models\TriggerValidation.cpp" />
</ItemGroup>
</Project>
67 changes: 67 additions & 0 deletions src/devkit/context/IGameContext.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#ifndef RA_CONTEXT_IGAMECONTEXT_HH
#define RA_CONTEXT_IGAMECONTEXT_HH
#pragma once

#include "data/Memory.hh"
#include "data/NotifyTargetSet.hh"

#include <string>

namespace ra {

namespace data {
namespace models {
class MemoryNotesModel;
} // namespace models
} // namespace data

namespace context {

class IGameContext
{
public:
IGameContext() noexcept = default;
virtual ~IGameContext() noexcept = default;
IGameContext(const IGameContext&) noexcept = delete;
IGameContext& operator=(const IGameContext&) noexcept = delete;
IGameContext(IGameContext&&) noexcept = delete;
IGameContext& operator=(IGameContext&&) noexcept = delete;

/// <summary>
/// Gets the unique identifier of the currently loaded game.
/// </summary>
unsigned int GameId() const noexcept { return m_nGameId; }

class NotifyTarget
{
public:
NotifyTarget() noexcept = default;
virtual ~NotifyTarget() noexcept = default;
NotifyTarget(const NotifyTarget&) noexcept = delete;
NotifyTarget& operator=(const NotifyTarget&) noexcept = delete;
NotifyTarget(NotifyTarget&&) noexcept = default;
NotifyTarget& operator=(NotifyTarget&&) noexcept = default;

virtual void OnBeforeActiveGameChanged() noexcept(false) {}
virtual void OnActiveGameChanged() noexcept(false) {}
virtual void OnBeginGameLoad() noexcept(false) {}
virtual void OnEndGameLoad() noexcept(false) {}
virtual void OnMemoryNoteChanged(ra::data::ByteAddress, const std::wstring&) noexcept(false) {}
virtual void OnMemoryNoteMoved(ra::data::ByteAddress, ra::data::ByteAddress, const std::wstring&) noexcept(false) {}
};

void AddNotifyTarget(NotifyTarget& pTarget) noexcept { m_vNotifyTargets.Add(pTarget); }
void RemoveNotifyTarget(NotifyTarget& pTarget) noexcept { m_vNotifyTargets.Remove(pTarget); }

virtual ra::data::models::MemoryNotesModel& MemoryNotes() noexcept(false) = 0;
virtual const ra::data::models::MemoryNotesModel& MemoryNotes() const noexcept(false) = 0;

protected:
unsigned int m_nGameId = 0;
ra::data::NotifyTargetSet<NotifyTarget> m_vNotifyTargets;
};

} // namespace context
} // namespace ra

#endif // !RA_CONTEXT_IGAMECONTEXT_HH
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#include "TriggerValidation.hh"

#include "context/IConsoleContext.hh"
#include "context/IEmulatorMemoryContext.hh"
#include "context/IGameContext.hh"

#include "data/models/MemoryNotesModel.hh"

#include "services/ServiceLocator.hh"

#include "util/Strings.hh"

#include "data/context/GameContext.hh"

#include <rcheevos/src/rcheevos/rc_validate.h>
#include <rcheevos/src/rcheevos/rc_internal.h>

Expand Down Expand Up @@ -115,7 +117,7 @@ static bool ValidateMemoryNotesOperand(const rc_operand_t& pOperand, const ra::d
if (nStartAddress != nAddress)
{
sError.append(L" at ");
sError.append(ra::util::String::Widen(pMemoryContext.FormatAddress(nStartAddress).substr(2)));
sError.append(pMemoryContext.FormatAddress(nStartAddress).substr(2));
}

return false;
Expand Down Expand Up @@ -166,14 +168,12 @@ static bool ValidateMemoryNotesCondSet(const rc_condset_t* pCondSet, const ra::d

static bool ValidateMemoryNotes(const rc_trigger_t* pTrigger, std::wstring& sError)
{
if (!ra::services::ServiceLocator::Exists<ra::data::context::GameContext>())
if (!ra::services::ServiceLocator::Exists<ra::context::IGameContext>())
return true;

const auto* pNotes = ra::services::ServiceLocator::Get<ra::data::context::GameContext>().Assets().FindMemoryNotes();
if (!pNotes)
return true;
const auto& pNotes = ra::services::ServiceLocator::Get<ra::context::IGameContext>().MemoryNotes();

if (!ValidateMemoryNotesCondSet(pTrigger->requirement, *pNotes, sError))
if (!ValidateMemoryNotesCondSet(pTrigger->requirement, pNotes, sError))
{
if (pTrigger->alternative)
sError = L"Core " + sError;
Expand All @@ -185,7 +185,7 @@ static bool ValidateMemoryNotes(const rc_trigger_t* pTrigger, std::wstring& sErr
for (; pCondSet; pCondSet = pCondSet->next)
{
nIndex++;
if (!ValidateMemoryNotesCondSet(pCondSet, *pNotes, sError))
if (!ValidateMemoryNotesCondSet(pCondSet, pNotes, sError))
{
sError = ra::util::String::Printf(L"Alt%u %s", nIndex, sError);
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef RA_DATA_TRIGGER_VALIDATION_H
#define RA_DATA_TRIGGER_VALIDATION_H
#ifndef RA_DATA_MODELS_TRIGGERVALIDATION_H
#define RA_DATA_MODELS_TRIGGERVALIDATION_H
#pragma once

#include "data\models\AssetModelBase.hh"
Expand All @@ -18,4 +18,4 @@ public:
} // namespace data
} // namespace ra

#endif RA_DATA_TRIGGER_VALIDATION_H
#endif RA_DATA_MODELS_TRIGGERVALIDATION_H
2 changes: 0 additions & 2 deletions tests/RA_Integration.Tests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
<ClCompile Include="..\src\data\models\AchievementModel.cpp" />
<ClCompile Include="..\src\data\models\LeaderboardModel.cpp" />
<ClCompile Include="..\src\data\models\RichPresenceModel.cpp" />
<ClCompile Include="..\src\data\models\TriggerValidation.cpp" />
<ClCompile Include="..\src\pch.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
Expand Down Expand Up @@ -159,7 +158,6 @@
<ClCompile Include="data\models\AchievementModel_Tests.cpp" />
<ClCompile Include="data\models\LeaderboardModel_Tests.cpp" />
<ClCompile Include="data\models\RichPresenceModel_Tests.cpp" />
<ClCompile Include="data\models\TriggerValidation_Tests.cpp" />
<ClCompile Include="devkit\context\mocks\MockEmulatorMemoryContext.cpp" />
<ClCompile Include="devkit\context\mocks\MockRcClient.cpp" />
<ClCompile Include="Exports_Tests.cpp" />
Expand Down
6 changes: 0 additions & 6 deletions tests/RA_Integration.Tests.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,6 @@
<ClCompile Include="ui\viewmodels\IntegrationMenuViewModel_Tests.cpp">
<Filter>Tests\UI\ViewModels</Filter>
</ClCompile>
<ClCompile Include="..\src\data\models\TriggerValidation.cpp">
<Filter>Code</Filter>
</ClCompile>
<ClCompile Include="data\models\TriggerValidation_Tests.cpp">
<Filter>Tests\Data\Models</Filter>
</ClCompile>
<ClCompile Include="..\src\ui\viewmodels\NewAssetViewModel.cpp">
<Filter>Code</Filter>
</ClCompile>
Expand Down
2 changes: 2 additions & 0 deletions tests/data/context/GameAssets_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "data\models\LocalBadgesModel.hh"

#include "tests\RA_UnitTestHelpers.h"
#include "tests\devkit\context\mocks\MockEmulatorMemoryContext.hh"
#include "tests\devkit\context\mocks\MockRcClient.hh"
#include "tests\devkit\services\mocks\MockLocalStorage.hh"
#include "tests\devkit\testutil\AssetAsserts.hh"
Expand All @@ -30,6 +31,7 @@ TEST_CLASS(GameAssets_Tests)
class GameAssetsHarness : public GameAssets
{
public:
ra::context::mocks::MockEmulatorMemoryContext mockEmulatorMemoryContext;
ra::context::mocks::MockRcClient mockRcClient;
ra::data::context::mocks::MockGameContext mockGameContext;
ra::services::mocks::MockAchievementRuntime mockRuntime;
Expand Down
Loading
Loading