Skip to content

Commit

Permalink
WIP: Add deterministic netplay plugin support to core and associated …
Browse files Browse the repository at this point in the history
…UI elements
  • Loading branch information
CEnnis91 committed May 10, 2018
1 parent 4967242 commit 05ec864
Show file tree
Hide file tree
Showing 38 changed files with 1,548 additions and 140 deletions.
8 changes: 8 additions & 0 deletions Source/Project64-core/AppInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ void SetTraceModuleNames(void)
TraceSetModuleName(TraceAudioPlugin, "Audio Plugin");
TraceSetModuleName(TraceControllerPlugin, "Controller Plugin");
TraceSetModuleName(TraceRSPPlugin, "RSP Plugin");
TraceSetModuleName(TraceNetplayPlugin, "Netplay Plugin");
TraceSetModuleName(TraceNetplay, "Netplay");
TraceSetModuleName(TraceRSP, "RSP");
TraceSetModuleName(TraceAudio, "Audio");
TraceSetModuleName(TraceRegisterCache, "Register Cache");
Expand All @@ -88,6 +90,8 @@ void UpdateTraceLevel(void * /*NotUsed*/)
g_ModuleLogLevel[TraceAudioPlugin] = (uint8_t)g_Settings->LoadDword(Debugger_TraceAudioPlugin);
g_ModuleLogLevel[TraceControllerPlugin] = (uint8_t)g_Settings->LoadDword(Debugger_TraceControllerPlugin);
g_ModuleLogLevel[TraceRSPPlugin] = (uint8_t)g_Settings->LoadDword(Debugger_TraceRSPPlugin);
g_ModuleLogLevel[TraceNetplayPlugin] = (uint8_t)g_Settings->LoadDword(Debugger_TraceNetplayPlugin);
g_ModuleLogLevel[TraceNetplay] = (uint8_t)g_Settings->LoadDword(Debugger_TraceNetplay);
g_ModuleLogLevel[TraceRSP] = (uint8_t)g_Settings->LoadDword(Debugger_TraceRSP);
g_ModuleLogLevel[TraceAudio] = (uint8_t)g_Settings->LoadDword(Debugger_TraceAudio);
g_ModuleLogLevel[TraceRegisterCache] = (uint8_t)g_Settings->LoadDword(Debugger_TraceRegisterCache);
Expand Down Expand Up @@ -116,6 +120,8 @@ void SetupTrace(void)
g_Settings->RegisterChangeCB(Debugger_TraceAudioPlugin, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
g_Settings->RegisterChangeCB(Debugger_TraceControllerPlugin, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
g_Settings->RegisterChangeCB(Debugger_TraceRSPPlugin, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
g_Settings->RegisterChangeCB(Debugger_TraceNetplayPlugin, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
g_Settings->RegisterChangeCB(Debugger_TraceNetplay, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
g_Settings->RegisterChangeCB(Debugger_TraceRSP, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
g_Settings->RegisterChangeCB(Debugger_TraceAudio, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
g_Settings->RegisterChangeCB(Debugger_TraceRegisterCache, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
Expand Down Expand Up @@ -148,6 +154,8 @@ void CleanupTrace(void)
g_Settings->UnregisterChangeCB(Debugger_TraceAudioPlugin, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
g_Settings->UnregisterChangeCB(Debugger_TraceControllerPlugin, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
g_Settings->UnregisterChangeCB(Debugger_TraceRSPPlugin, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
g_Settings->UnregisterChangeCB(Debugger_TraceNetplayPlugin, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
g_Settings->UnregisterChangeCB(Debugger_TraceNetplay, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
g_Settings->UnregisterChangeCB(Debugger_TraceRSP, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
g_Settings->UnregisterChangeCB(Debugger_TraceAudio, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
g_Settings->UnregisterChangeCB(Debugger_TraceRegisterCache, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
Expand Down
5 changes: 5 additions & 0 deletions Source/Project64-core/Multilanguage.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ enum LanguageStringID
MENU_RECENT_ROM = 107,
MENU_RECENT_DIR = 108,
MENU_EXIT = 109,
MENU_NETPLAY = 110,

//System Menu
MENU_SYSTEM = 120,
Expand Down Expand Up @@ -93,6 +94,7 @@ enum LanguageStringID
MENU_CONFG_RSP = 146,
MENU_SHOW_CPU = 147,
MENU_SETTINGS = 148,
MENU_CONFG_NET = 149,

//Debugger Menu
MENU_DEBUGGER = 160,
Expand Down Expand Up @@ -180,6 +182,7 @@ enum LanguageStringID
MENUDES_GAME_INFO = 284,
MENUDES_GAME_SETTINGS = 285,
MENUDES_GAME_CHEATS = 286,
MENUDES_CONFG_NET = 287,

/*********************************************************************************
* Rom Browser *
Expand Down Expand Up @@ -240,6 +243,7 @@ enum LanguageStringID
PLUG_HLE_GFX = 425,
PLUG_HLE_AUDIO = 426,
PLUG_DEFAULT = 427,
PLUG_NET = 428,

//Directory Dialog
DIR_PLUGIN = 440,
Expand Down Expand Up @@ -549,6 +553,7 @@ enum LanguageStringID
MSG_SET_LLE_GFX_MSG = 2055,
MSG_SET_HLE_AUD_TITLE = 2056,
MSG_SET_HLE_AUD_MSG = 2057,
MSG_CLOSE_NETPLAY = 2058,

/*********************************************************************************
* Android *
Expand Down
6 changes: 5 additions & 1 deletion Source/Project64-core/Multilanguage/LanguageClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ void CLanguage::LoadDefaultStrings(void)
DEF_STR(MENU_REFRESH, "Refresh ROM List");
DEF_STR(MENU_RECENT_ROM, "Recent ROM");
DEF_STR(MENU_RECENT_DIR, "Recent ROM Directories");
DEF_STR(MENU_NETPLAY, "Start &Netplay...");
DEF_STR(MENU_EXIT, "E&xit");

//System Menu
Expand Down Expand Up @@ -98,6 +99,7 @@ void CLanguage::LoadDefaultStrings(void)
DEF_STR(MENU_CONFG_AUDIO, "Configure Audio Plugin...");
DEF_STR(MENU_CONFG_CTRL, "Configure Controller Plugin...");
DEF_STR(MENU_CONFG_RSP, "Configure RSP Plugin...");
DEF_STR(MENU_CONFG_NET, "Configure Netplay Plugin...");
DEF_STR(MENU_SHOW_CPU, "Show CPU Usage");
DEF_STR(MENU_SETTINGS, "&Settings...");

Expand Down Expand Up @@ -205,6 +207,7 @@ void CLanguage::LoadDefaultStrings(void)
DEF_STR(PLUG_GFX, " Video (graphics) plugin: ");
DEF_STR(PLUG_AUDIO, " Audio (sound) plugin: ");
DEF_STR(PLUG_CTRL, " Input (controller) plugin: ");
DEF_STR(PLUG_NET, " Netplay (online) plugin: ");
DEF_STR(PLUG_HLE_GFX, "Graphics HLE");
DEF_STR(PLUG_HLE_AUDIO, "Audio HLE");
DEF_STR(PLUG_DEFAULT, "** Use System Plugin **");
Expand Down Expand Up @@ -517,6 +520,7 @@ void CLanguage::LoadDefaultStrings(void)
DEF_STR(MSG_SET_LLE_GFX_MSG, "Graphics LLE is not for general use!!!\nIt is advisable that you only use this for testing and not for playing games.\n\nChange to graphics LLE?");
DEF_STR(MSG_SET_HLE_AUD_TITLE, "Audio High-Level Emulation");
DEF_STR(MSG_SET_HLE_AUD_MSG, "Audio HLE requires a third-party plugin!!!\nIf you do not use a third-party audio plugin that supports HLE, you will hear no sound.\n\nChange to audio HLE?");
DEF_STR(MSG_CLOSE_NETPLAY, "Please close the Netplay window first");

/*********************************************************************************
* Android *
Expand Down Expand Up @@ -823,4 +827,4 @@ const std::wstring wGS(LanguageStringID StringID)
{
return stdstr(g_Lang->GetString(StringID)).ToUTF16();
}
#endif
#endif
22 changes: 20 additions & 2 deletions Source/Project64-core/N64System/CheatClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <Project64-core/Plugins/AudioPlugin.h>
#include <Project64-core/Plugins/RSPPlugin.h>
#include <Project64-core/Plugins/ControllerPlugin.h>
#include <Project64-core/Plugins/NetplayPlugin.h>
#include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/N64System/Recompiler/RecompilerClass.h>
#include <stdlib.h>
Expand Down Expand Up @@ -101,6 +102,10 @@ bool CCheats::LoadCode(const stdstr & CheatEntry, SettingID ExtensionSetting, in
}

m_Codes.push_back(Code);

if (g_Settings->LoadBool(Plugin_NET_Running))
g_Plugins->Netplay()->LoadCode(Code);

return true;
}

Expand Down Expand Up @@ -148,6 +153,11 @@ void CCheats::LoadPermCheats(CPlugins * Plugins)
LoadEntry = true;
break;
}
if (Plugins->Netplay() != NULL && strstr(Plugins->Netplay()->PluginName(), PluginName.c_str()) != NULL)
{
LoadEntry = true;
break;
}
}
}

Expand Down Expand Up @@ -221,9 +231,17 @@ uint16_t ConvertXP64Value(uint16_t Value)

void CCheats::ApplyCheats()
{
for (size_t CurrentCheat = 0; CurrentCheat < m_Codes.size(); CurrentCheat++)
if (g_Settings->LoadBool(Plugin_NET_Running))
ApplyCheatsArray(g_Plugins->Netplay()->GetCodes());
else
ApplyCheatsArray(m_Codes);
}

void CCheats::ApplyCheatsArray(CODES_ARRAY Codes)
{
for (size_t CurrentCheat = 0; CurrentCheat < Codes.size(); CurrentCheat++)
{
CODES & CodeEntry = m_Codes[CurrentCheat];
CODES & CodeEntry = Codes[CurrentCheat];
for (size_t CurrentEntry = 0; CurrentEntry < CodeEntry.size();)
{
ApplyCheatEntry(CodeEntry, CurrentEntry);
Expand Down
3 changes: 3 additions & 0 deletions Source/Project64-core/N64System/CheatClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class CCheats
static bool IsValid16BitCode(const char * CheatString);

private:
friend class CNetplay_Plugin;

struct GAMESHARK_CODE
{
uint32_t Command;
Expand All @@ -55,6 +57,7 @@ class CCheats
typedef std::map<uint32_t, MEM_VALUE16> ORIGINAL_VALUES16;
typedef std::map<uint32_t, MEM_VALUE8> ORIGINAL_VALUES8;

void ApplyCheatsArray(CODES_ARRAY Codes);
void LoadPermCheats(CPlugins * Plugins);
int32_t EntrySize(const CODES & CodeEntry, int32_t CurrentEntry);

Expand Down
6 changes: 6 additions & 0 deletions Source/Project64-core/N64System/Mips/Eeprom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ void CEeprom::EepromCommand(uint8_t * Command)

void CEeprom::LoadEeprom()
{
if (g_Settings->LoadBool(Plugin_NET_Running) && ! g_Settings->LoadBool(Plugin_NET_CanSave))
{
WriteTrace(TraceNetplayPlugin, TraceInfo, "Loading Sram is disabled during Netplay");
return;
}

memset(m_EEPROM, 0xFF, sizeof(m_EEPROM));

CPath FileName(g_Settings->LoadStringVal(Directory_NativeSave).c_str(), stdstr_f("%s.eep", g_Settings->LoadStringVal(Game_GameName).c_str()).c_str());
Expand Down
6 changes: 6 additions & 0 deletions Source/Project64-core/N64System/Mips/FlashRam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ uint32_t CFlashram::ReadFromFlashStatus(uint32_t PAddr)

bool CFlashram::LoadFlashram()
{
if (g_Settings->LoadBool(Plugin_NET_Running) && ! g_Settings->LoadBool(Plugin_NET_CanSave))
{
WriteTrace(TraceNetplayPlugin, TraceInfo, "Loading Flashram is disabled during Netplay");
return false;
}

CPath FileName(g_Settings->LoadStringVal(Directory_NativeSave).c_str(), stdstr_f("%s.fla", g_Settings->LoadStringVal(Game_GameName).c_str()).c_str());
if (g_Settings->LoadBool(Setting_UniqueSaveDir))
{
Expand Down
51 changes: 45 additions & 6 deletions Source/Project64-core/N64System/Mips/PifRam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,15 @@ void CPifRam::PifRamRead()
return;
}

CONTROL * Controllers = g_Plugins->Control()->PluginControllers();
CONTROL * Controllers;
if (g_Settings->LoadBool(Plugin_NET_Running))
{
Controllers = g_Plugins->Netplay()->PluginControllers();
}
else
{
Controllers = g_Plugins->Control()->PluginControllers();
}

int32_t Channel = 0;
for (int32_t CurPos = 0; CurPos < 0x40; CurPos++)
Expand All @@ -102,9 +110,16 @@ void CPifRam::PifRamRead()
{
if (Controllers[Channel].Present && Controllers[Channel].RawData)
{
if (g_Plugins->Control()->ReadController)
if (g_Settings->LoadBool(Plugin_NET_Running))
{
g_Plugins->Control()->ReadController(Channel, &m_PifRam[CurPos]);
g_Plugins->Netplay()->ReadController(Channel, &m_PifRam[CurPos]);
}
else
{
if (g_Plugins->Control()->ReadController)
{
g_Plugins->Control()->ReadController(Channel, &m_PifRam[CurPos]);
}
}
}
else
Expand Down Expand Up @@ -134,7 +149,15 @@ void CPifRam::PifRamRead()

void CPifRam::PifRamWrite()
{
CONTROL * Controllers = g_Plugins->Control()->PluginControllers();
CONTROL * Controllers;
if (g_Settings->LoadBool(Plugin_NET_Running))
{
Controllers = g_Plugins->Netplay()->PluginControllers();
}
else
{
Controllers = g_Plugins->Control()->PluginControllers();
}
int32_t Channel = 0, CurPos;

if (m_PifRam[0x3F] > 0x1)
Expand Down Expand Up @@ -433,7 +456,15 @@ void CPifRam::SI_DMA_WRITE()

void CPifRam::ProcessControllerCommand(int32_t Control, uint8_t * Command)
{
CONTROL * Controllers = g_Plugins->Control()->PluginControllers();
CONTROL * Controllers;
if (g_Settings->LoadBool(Plugin_NET_Running))
{
Controllers = g_Plugins->Netplay()->PluginControllers();
}
else
{
Controllers = g_Plugins->Control()->PluginControllers();
}

switch (Command[2])
{
Expand Down Expand Up @@ -572,7 +603,15 @@ void CPifRam::ProcessControllerCommand(int32_t Control, uint8_t * Command)

void CPifRam::ReadControllerCommand(int32_t Control, uint8_t * Command)
{
CONTROL * Controllers = g_Plugins->Control()->PluginControllers();
CONTROL * Controllers;
if (g_Settings->LoadBool(Plugin_NET_Running))
{
Controllers = g_Plugins->Netplay()->PluginControllers();
}
else
{
Controllers = g_Plugins->Control()->PluginControllers();
}

switch (Command[2])
{
Expand Down
6 changes: 6 additions & 0 deletions Source/Project64-core/N64System/Mips/Sram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ CSram::~CSram()

bool CSram::LoadSram()
{
if (g_Settings->LoadBool(Plugin_NET_Running) && ! g_Settings->LoadBool(Plugin_NET_CanSave))
{
WriteTrace(TraceNetplayPlugin, TraceInfo, "Loading Sram is disabled during Netplay");
return false;
}

CPath FileName(g_Settings->LoadStringVal(Directory_NativeSave).c_str(), stdstr_f("%s.sra", g_Settings->LoadStringVal(Game_GameName).c_str()).c_str());
if (g_Settings->LoadBool(Setting_UniqueSaveDir))
{
Expand Down
39 changes: 27 additions & 12 deletions Source/Project64-core/N64System/Mips/SystemEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ void CSystemEvents::ExecuteEvents()
m_Events.clear();
}

bool NetplayRunning = g_Settings->LoadBool(Plugin_NET_Running);
bool NetplayCanPause = g_Settings->LoadBool(Plugin_NET_CanPause);

bool bPause = false, bLoadedSave = false;
for (EventList::const_iterator iter = Events.begin(); !bLoadedSave && iter != Events.end(); iter++)
{
Expand Down Expand Up @@ -196,17 +199,23 @@ void CSystemEvents::ExecuteEvents()
case SysEvent_PauseCPU_AppLostFocus:
if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
{
g_Settings->SaveBool(GameRunning_CPU_Paused, true);
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_AppLostFocus);
bPause = true;
if (!NetplayRunning || (NetplayRunning && NetplayCanPause))
{
g_Settings->SaveBool(GameRunning_CPU_Paused, true);
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_AppLostFocus);
bPause = true;
}
}
break;
case SysEvent_PauseCPU_AppLostActive:
if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
{
g_Settings->SaveBool(GameRunning_CPU_Paused, true);
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_AppLostActive);
bPause = true;
if (!NetplayRunning || (NetplayRunning && NetplayCanPause))
{
g_Settings->SaveBool(GameRunning_CPU_Paused, true);
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_AppLostActive);
bPause = true;
}
}
break;
case SysEvent_PauseCPU_SaveGame:
Expand Down Expand Up @@ -244,17 +253,23 @@ void CSystemEvents::ExecuteEvents()
case SysEvent_PauseCPU_Settings:
if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
{
g_Settings->SaveBool(GameRunning_CPU_Paused, true);
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_Settings);
bPause = true;
if (!NetplayRunning || (NetplayRunning && NetplayCanPause))
{
g_Settings->SaveBool(GameRunning_CPU_Paused, true);
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_Settings);
bPause = true;
}
}
break;
case SysEvent_PauseCPU_Cheats:
if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
{
g_Settings->SaveBool(GameRunning_CPU_Paused, true);
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_Cheats);
bPause = true;
if (!NetplayRunning || (NetplayRunning && NetplayCanPause))
{
g_Settings->SaveBool(GameRunning_CPU_Paused, true);
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_Cheats);
bPause = true;
}
}
break;
case SysEvent_ResetRecompilerCode:
Expand Down
Loading

0 comments on commit 05ec864

Please sign in to comment.