Controller ports properally show on RPC now (kinda, its hacky)

This commit is contained in:
Nayla Hanegan 2024-07-18 13:12:12 -04:00
commit f2c3a98f33
265 changed files with 491 additions and 298 deletions

View file

@ -1,15 +1,15 @@
#include "Discord.h"
#include "UICommon/DiscordPresence.h"
#include <Core/State.h>
#include "Core/Config/NetplaySettings.h"
#include "Core/Core.h"
#include "Core/IOS/DolphinDevice.h"
#include <Core/State.h>
#include "Core/System.h"
#include "UICommon/DiscordPresence.h"
bool mpn_update_discord()
{
//if (!Memory::IsInitialized())
// return false;
// if (!Memory::IsInitialized())
// return false;
DiscordRichPresence RichPresence = {};
@ -19,19 +19,33 @@ bool mpn_update_discord()
if (CurrentState.Scenes != NULL && CurrentState.Scene != NULL)
RichPresence.state = CurrentState.Scene->Name.c_str();
if (mpn_read_value(CurrentState.Addresses->CurrentTurn, 1) == (mpn_read_value(CurrentState.Addresses->TotalTurns, 1) + 1))
{
State::Save(Core::System::GetInstance(), 1);
}
if (CurrentState.Addresses != NULL)
{
if (mpn_read_value(CurrentState.Addresses->CurrentTurn, 1) ==
(mpn_read_value(CurrentState.Addresses->TotalTurns, 1) + 1))
{
State::Save(Core::System::GetInstance(), 1);
}
// Add controller port values
int value1 = mpn_read_value(CurrentState.Addresses->ControllerPortAddress1, 1);
int value2 = mpn_read_value(CurrentState.Addresses->ControllerPortAddress2, 1);
int value3 = mpn_read_value(CurrentState.Addresses->ControllerPortAddress3, 1);
int value4 = mpn_read_value(CurrentState.Addresses->ControllerPortAddress4, 1);
// Modify values based on the given conditions
value1 = (value1 == 0) ? 1 : 0;
value2 = (value2 == 0) ? 1 : 0;
value3 = (value3 == 0) ? 1 : 0;
value4 = (value4 == 0) ? 1 : 0;
int controller_port_sum = value1 + value2 + value3 + value4;
char Details[128] = "";
if (CurrentState.Boards && CurrentState.Board)
{
DiscordRichPresence discord_presence = {};
snprintf(Details, sizeof(Details), "Players: 1/4 Turn: %d/%d",
snprintf(Details, sizeof(Details), "Players: %d/4 Turn: %d/%d", controller_port_sum,
mpn_read_value(CurrentState.Addresses->CurrentTurn, 1),
mpn_read_value(CurrentState.Addresses->TotalTurns, 1));
@ -40,12 +54,19 @@ bool mpn_update_discord()
}
else
{
snprintf(Details, sizeof(Details), "Players: 1/4");
snprintf(Details, sizeof(Details), "Players: %d/4", controller_port_sum);
RichPresence.smallImageKey = "";
RichPresence.smallImageText = "";
}
RichPresence.details = Details;
}
else
{
// Handle the case where CurrentState.Addresses is NULL
RichPresence.details = "Invalid state: Addresses are NULL";
RichPresence.smallImageKey = "";
RichPresence.smallImageText = "";
}
RichPresence.startTimestamp = std::time(nullptr);
Discord_UpdatePresence(&RichPresence);

View file

@ -1,4 +1,4 @@
#include <discord_rpc.h>
#include "Gamestate.h"
bool mpn_update_discord();
#include <discord_rpc.h>
#include "Gamestate.h"
bool mpn_update_discord();

View file

@ -1,201 +1,201 @@
#include "Gamestate.h"
#include "Core/System.h"
mpn_state_t CurrentState;
bool mpn_init_state()
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
if (!memory.IsInitialized())
return false;
switch (mpn_read_value(0x00000000, 4))
{
case MPN_GAMEID_MP4:
CurrentState.Addresses = &MP4_ADDRESSES;
CurrentState.Boards = MP4_BOARDS;
CurrentState.Image = "box-mp4";
CurrentState.IsMarioParty = true;
CurrentState.Scenes = MP4_GAMESTATES;
CurrentState.Title = "Mario Party 4";
break;
case MPN_GAMEID_MP5:
CurrentState.Addresses = &MP5_ADDRESSES;
CurrentState.Boards = MP5_BOARDS;
CurrentState.Image = "box-mp5";
CurrentState.IsMarioParty = true;
CurrentState.Scenes = MP5_GAMESTATES;
CurrentState.Title = "Mario Party 5";
break;
case MPN_GAMEID_MP6:
CurrentState.Addresses = &MP6_ADDRESSES;
CurrentState.Boards = MP6_BOARDS;
CurrentState.Image = "box-mp6";
CurrentState.IsMarioParty = true;
CurrentState.Scenes = MP6_GAMESTATES;
CurrentState.Title = "Mario Party 6";
break;
case MPN_GAMEID_MP7:
CurrentState.Addresses = &MP7_ADDRESSES;
CurrentState.Boards = MP7_BOARDS;
CurrentState.Image = "box-mp7";
CurrentState.IsMarioParty = true;
CurrentState.Scenes = MP7_GAMESTATES;
CurrentState.Title = "Mario Party 7";
break;
case MPN_GAMEID_MP8:
CurrentState.Addresses = &MP8_ADDRESSES;
CurrentState.Boards = MP8_BOARDS;
CurrentState.Image = "box-mp8";
CurrentState.IsMarioParty = true;
CurrentState.Scenes = MP8_GAMESTATES;
CurrentState.Title = "Mario Party 8";
break;
case MPN_GAMEID_MP9: /* TODO */
default:
CurrentState.Addresses = NULL;
CurrentState.Boards = NULL;
CurrentState.Image = "box-mp9";
CurrentState.IsMarioParty = false;
CurrentState.Scenes = NULL;
}
return CurrentState.Scenes != NULL;
}
bool mpn_update_board()
{
uint8_t i;
if (CurrentState.Boards == NULL)
CurrentState.Board = NULL;
else if (CurrentState.CurrentSceneId != CurrentState.PreviousSceneId)
{
for (i = 0;; i++)
{
/* Unknown scene ID */
if (CurrentState.Boards[i].SceneId == NONE)
break;
if (CurrentState.Boards[i].SceneId == CurrentState.CurrentSceneId)
{
CurrentState.Board = &CurrentState.Boards[i];
return true;
}
}
}
return false;
}
uint8_t mpn_get_needs(uint16_t StateId, bool IsSceneId)
{
uint16_t i;
if (CurrentState.Scenes == NULL)
return MPN_NEEDS_NOTHING;
else if (CurrentState.CurrentSceneId != CurrentState.PreviousSceneId)
{
for (i = 0;; i++)
{
/* Unknown scene ID */
if (CurrentState.Scenes[i].SceneId == NONE)
return MPN_NEEDS_NOTHING;
/* Scene ID found in array */
if ((IsSceneId && StateId == CurrentState.Scenes[i].SceneId) ||
(StateId == CurrentState.Scenes[i].MiniGameId))
return CurrentState.Scenes[i].Needs;
}
}
return MPN_NEEDS_NOTHING;
}
void mpn_push_osd_message(const std::string& Message)
{
#ifdef MPN_USE_OSD
OSD::AddMessage(Message, OSD::Duration::SHORT, MPN_OSD_COLOR);
#endif
}
bool mpn_update_state()
{
if (CurrentState.Scenes == NULL && !mpn_init_state())
return false;
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
if (!memory.IsInitialized())
return false;
CurrentState.PreviousSceneId = CurrentState.CurrentSceneId;
CurrentState.CurrentSceneId = mpn_read_value(CurrentState.Addresses->SceneIdAddress, 2);
for (uint16_t i = 0;; i++)
{
if (CurrentState.Scenes[i].SceneId == NONE)
break;
if (CurrentState.CurrentSceneId == CurrentState.Scenes[i].SceneId)
{
CurrentState.Scene = &CurrentState.Scenes[i];
return true;
}
}
return false;
}
#define OSD_PUSH(a) mpn_push_osd_message("Adjusting #a for " + CurrentState.Scene->Name);
void mpn_per_frame()
{
uint8_t Needs = 0;
if (!mpn_update_state() || CurrentState.PreviousSceneId == CurrentState.CurrentSceneId)
return;
mpn_update_board();
mpn_update_discord();
Needs = mpn_get_needs(mpn_read_value(CurrentState.Addresses->SceneIdAddress, 2), true);
if (Needs != MPN_NEEDS_NOTHING)
{
if (Needs & MPN_NEEDS_SAFE_TEX_CACHE)
{
OSD_PUSH(GFX_SAFE_TEXTURE_CACHE_COLOR_SAMPLES)
Config::SetCurrent(Config::GFX_SAFE_TEXTURE_CACHE_COLOR_SAMPLES, 0);
}
else
Config::SetCurrent(Config::GFX_SAFE_TEXTURE_CACHE_COLOR_SAMPLES, 128);
if (Needs & MPN_NEEDS_NATIVE_RES)
{
OSD_PUSH(GFX_EFB_SCALE)
Config::SetCurrent(Config::GFX_EFB_SCALE, 1);
}
else
Config::SetCurrent(Config::GFX_EFB_SCALE, Config::GetBase(Config::GFX_EFB_SCALE));
if (Needs & MPN_NEEDS_EFB_TO_TEXTURE)
{
OSD_PUSH(GFX_HACK_SKIP_EFB_COPY_TO_RAM)
Config::SetCurrent(Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM, false);
}
else
Config::SetCurrent(Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM, true);
UpdateActiveConfig();
}
}
uint32_t mpn_read_value(uint32_t Address, uint8_t Size)
{
uint32_t Value = 0;
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
for (int8_t i = 0; i < Size; i++)
Value += memory.GetRAM()[Address + i] * pow(256, Size - i - 1);
return Value;
}
#include "Gamestate.h"
#include "Core/System.h"
mpn_state_t CurrentState;
bool mpn_init_state()
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
if (!memory.IsInitialized())
return false;
switch (mpn_read_value(0x00000000, 4))
{
case MPN_GAMEID_MP4:
CurrentState.Addresses = &MP4_ADDRESSES;
CurrentState.Boards = MP4_BOARDS;
CurrentState.Image = "box-mp4";
CurrentState.IsMarioParty = true;
CurrentState.Scenes = MP4_GAMESTATES;
CurrentState.Title = "Mario Party 4";
break;
case MPN_GAMEID_MP5:
CurrentState.Addresses = &MP5_ADDRESSES;
CurrentState.Boards = MP5_BOARDS;
CurrentState.Image = "box-mp5";
CurrentState.IsMarioParty = true;
CurrentState.Scenes = MP5_GAMESTATES;
CurrentState.Title = "Mario Party 5";
break;
case MPN_GAMEID_MP6:
CurrentState.Addresses = &MP6_ADDRESSES;
CurrentState.Boards = MP6_BOARDS;
CurrentState.Image = "box-mp6";
CurrentState.IsMarioParty = true;
CurrentState.Scenes = MP6_GAMESTATES;
CurrentState.Title = "Mario Party 6";
break;
case MPN_GAMEID_MP7:
CurrentState.Addresses = &MP7_ADDRESSES;
CurrentState.Boards = MP7_BOARDS;
CurrentState.Image = "box-mp7";
CurrentState.IsMarioParty = true;
CurrentState.Scenes = MP7_GAMESTATES;
CurrentState.Title = "Mario Party 7";
break;
case MPN_GAMEID_MP8:
CurrentState.Addresses = &MP8_ADDRESSES;
CurrentState.Boards = MP8_BOARDS;
CurrentState.Image = "box-mp8";
CurrentState.IsMarioParty = true;
CurrentState.Scenes = MP8_GAMESTATES;
CurrentState.Title = "Mario Party 8";
break;
case MPN_GAMEID_MP9: /* TODO */
default:
CurrentState.Addresses = NULL;
CurrentState.Boards = NULL;
CurrentState.Image = "box-mp9";
CurrentState.IsMarioParty = false;
CurrentState.Scenes = NULL;
}
return CurrentState.Scenes != NULL;
}
bool mpn_update_board()
{
uint8_t i;
if (CurrentState.Boards == NULL)
CurrentState.Board = NULL;
else if (CurrentState.CurrentSceneId != CurrentState.PreviousSceneId)
{
for (i = 0;; i++)
{
/* Unknown scene ID */
if (CurrentState.Boards[i].SceneId == NONE)
break;
if (CurrentState.Boards[i].SceneId == CurrentState.CurrentSceneId)
{
CurrentState.Board = &CurrentState.Boards[i];
return true;
}
}
}
return false;
}
uint8_t mpn_get_needs(uint16_t StateId, bool IsSceneId)
{
uint16_t i;
if (CurrentState.Scenes == NULL)
return MPN_NEEDS_NOTHING;
else if (CurrentState.CurrentSceneId != CurrentState.PreviousSceneId)
{
for (i = 0;; i++)
{
/* Unknown scene ID */
if (CurrentState.Scenes[i].SceneId == NONE)
return MPN_NEEDS_NOTHING;
/* Scene ID found in array */
if ((IsSceneId && StateId == CurrentState.Scenes[i].SceneId) ||
(StateId == CurrentState.Scenes[i].MiniGameId))
return CurrentState.Scenes[i].Needs;
}
}
return MPN_NEEDS_NOTHING;
}
void mpn_push_osd_message(const std::string& Message)
{
#ifdef MPN_USE_OSD
OSD::AddMessage(Message, OSD::Duration::SHORT, MPN_OSD_COLOR);
#endif
}
bool mpn_update_state()
{
if (CurrentState.Scenes == NULL && !mpn_init_state())
return false;
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
if (!memory.IsInitialized())
return false;
CurrentState.PreviousSceneId = CurrentState.CurrentSceneId;
CurrentState.CurrentSceneId = mpn_read_value(CurrentState.Addresses->SceneIdAddress, 2);
for (uint16_t i = 0;; i++)
{
if (CurrentState.Scenes[i].SceneId == NONE)
break;
if (CurrentState.CurrentSceneId == CurrentState.Scenes[i].SceneId)
{
CurrentState.Scene = &CurrentState.Scenes[i];
return true;
}
}
return false;
}
#define OSD_PUSH(a) mpn_push_osd_message("Adjusting #a for " + CurrentState.Scene->Name);
void mpn_per_frame()
{
uint8_t Needs = 0;
if (!mpn_update_state() || CurrentState.PreviousSceneId == CurrentState.CurrentSceneId)
return;
mpn_update_board();
mpn_update_discord();
Needs = mpn_get_needs(mpn_read_value(CurrentState.Addresses->SceneIdAddress, 2), true);
if (Needs != MPN_NEEDS_NOTHING)
{
if (Needs & MPN_NEEDS_SAFE_TEX_CACHE)
{
OSD_PUSH(GFX_SAFE_TEXTURE_CACHE_COLOR_SAMPLES)
Config::SetCurrent(Config::GFX_SAFE_TEXTURE_CACHE_COLOR_SAMPLES, 0);
}
else
Config::SetCurrent(Config::GFX_SAFE_TEXTURE_CACHE_COLOR_SAMPLES, 128);
if (Needs & MPN_NEEDS_NATIVE_RES)
{
OSD_PUSH(GFX_EFB_SCALE)
Config::SetCurrent(Config::GFX_EFB_SCALE, 1);
}
else
Config::SetCurrent(Config::GFX_EFB_SCALE, Config::GetBase(Config::GFX_EFB_SCALE));
if (Needs & MPN_NEEDS_EFB_TO_TEXTURE)
{
OSD_PUSH(GFX_HACK_SKIP_EFB_COPY_TO_RAM)
Config::SetCurrent(Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM, false);
}
else
Config::SetCurrent(Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM, true);
UpdateActiveConfig();
}
}
uint32_t mpn_read_value(uint32_t Address, uint8_t Size)
{
uint32_t Value = 0;
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
for (int8_t i = 0; i < Size; i++)
Value += memory.GetRAM()[Address + i] * pow(256, Size - i - 1);
return Value;
}

View file

@ -65,6 +65,10 @@ typedef struct mpn_addresses_t
uint32_t TotalTurns;
uint32_t MinigameIdAddress;
uint32_t SceneIdAddress;
uint32_t ControllerPortAddress1;
uint32_t ControllerPortAddress2;
uint32_t ControllerPortAddress3;
uint32_t ControllerPortAddress4;
} mpn_addresses_t;
typedef struct mpn_player_t
@ -112,7 +116,16 @@ bool mpn_update_state();
/* ============================================================================
Mario Party 4 metadata
============================================================================ */
const mpn_addresses_t MP4_ADDRESSES = {0x0018FCFC, 0x0018FCFD, 0x0018FD2C, 0x001D3CE2};
const mpn_addresses_t MP4_ADDRESSES = {
0x0018FCFC, // Current Turns
0x0018FCFD, // Total Turns
0x0018FD2C, // Mini ID
0x001D3CE2, // Scene ID
0x0018FC19, // Controller Port A
0x0018FC23, // Controller Port B
0x0018FC2D, // Controller Port C
0x0018FC37 // Controller Port D
};
const mpn_board_t MP4_BOARDS[] = {{1, 0x59, {"Toad's Midway Madness"}, {"mp4-toad"}},
{2, 0x5A, {"Goomba's Greedy Gala"}, {"mp4-goomba"}},
@ -213,7 +226,11 @@ const mpn_addresses_t MP5_ADDRESSES = {
0x0022A494, // Current Turns
0x0022A495, // Total Turns
0x0022A4C4, // Mini ID
0x00288862 // Scene ID
0x00288862, // Scene ID
0x0022A05B, // Controller Port A
0x0022A051, // Controller Port B
0x0022A065, // Controller Port C
0x0022A06F // Controller Port D
};
const mpn_board_t MP5_BOARDS[] = {{1, 0x76, {"Toy Dream"}, {"mp5-toy"}},
@ -333,8 +350,11 @@ const mpn_addresses_t MP6_ADDRESSES = {
0x00265B74, // Current Turns
0x00265B75, // Total Turns
0x00265BA8, // Mini ID
0x002C0256 // Scene ID
};
0x002C0256, // Scene ID
0x00265745, // Controller Port A
0x00265731, // Controller Port B
0x0026574F, // Controller Port C
0x0026573B}; // Controller Port D
const mpn_board_t MP6_BOARDS[] = {{1, 0x7B, {"Towering Treetop"}, {"mp6-treetop"}},
{2, 0x7C, {"E. Gadd's Garage"}, {"mp6-garage"}},
@ -460,7 +480,20 @@ const mpn_scene_t MP6_GAMESTATES[] = {{NONE, 0x01, {"Title Screen"}, 0},
Mario Party 7 metadata
============================================================================ */
const mpn_addresses_t MP7_ADDRESSES = {0x0029151C, 0x0029151D, 0x00291558, 0x002F2F3E};
const mpn_addresses_t MP7_ADDRESSES = {
0x0029151C, // Current Turns
0x0029151D, // Total Turns
0x00291558, // Mini ID
0x002F2F3E, // Scene ID
0x00290C51, // Controller Port A
0x00290C5B, // Controller Port B
0x00290C65, // Controller Port C
0x00290C6F // Controller Port D
//0x00290C79, // Controller Port E
//0x00290C83, // Controller Port F
//0x00290C8D, // Controller Port G
//0x00290C97 // Controller Port H
};
const mpn_board_t MP7_BOARDS[] = {{1, 0x7A, {"Grand Canal"}, {"mp7-canal"}},
{2, 0x7B, {"Pagoda Peak"}, {"mp7-peak"}},

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<LocalDebuggerCommand>$(BinaryOutputDir)$(TargetFileName)</LocalDebuggerCommand>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<LocalDebuggerCommand>$(BinaryOutputDir)$(TargetFileName)</LocalDebuggerCommand>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
</Project>