Skip to content

Commit

Permalink
Merge pull request #11 from Jamiras/cfg_hardcore
Browse files Browse the repository at this point in the history
standardize "disable hardcore" warning across emulators
  • Loading branch information
Jamiras authored Sep 13, 2018
2 parents 5cfe78a + b3062d3 commit fbdaa67
Show file tree
Hide file tree
Showing 31 changed files with 159 additions and 297 deletions.
21 changes: 6 additions & 15 deletions RAGens/common/src/save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,7 @@ int load_Memstate()
{
// #RA
if( RA_HardcoreModeIsActive() )
{
MessageBox( HWnd, "Please disable Hardcore mode when using REWiND!", "Warning", MB_OK );
return 0;
}

if(memstateAllocated == 0)
return 0;
Expand Down Expand Up @@ -299,11 +296,8 @@ void Get_State_File_Name(char *name)
int Load_State(char *Name)
{
// #RA
if( RA_HardcoreModeIsActive() )
{
if( MessageBox( HWnd, "Hardcore mode is active. If you load a state, you will disable Hardcore Mode. Continue?", "Warning", MB_YESNO ) == IDNO )
return 0;
}
if (!RA_WarnDisableHardcore("load a state"))
return 0;

FILE *f;
unsigned char *buf;
Expand Down Expand Up @@ -435,6 +429,10 @@ int Load_Memstate(BYTE *memBuf)
RA_OnLoadNewRom( Rom_Data, 6*1024*1024 );
}
}
else
{
RA_OnLoadState( NULL );
}

//}

Expand All @@ -443,13 +441,6 @@ int Load_Memstate(BYTE *memBuf)

int Save_State(char *Name)
{
// #RA
if( RA_HardcoreModeIsActive() )
{
if( MessageBox( HWnd, "Hardcore mode is active. If you save a state, you will disable Hardcore Mode. Continue?", "Warning", MB_YESNO ) == IDNO )
return 0;
}

FILE *f;
unsigned char *buf;
int len;
Expand Down
2 changes: 2 additions & 0 deletions RAMeka/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ meka/Dist
*.opendb
*allegro*.zip
meka/srcs/projects/msvc/packages
meka/srcs/BuildVer.h
*.rap
/meka/srcs/projects/msvc/.vs/

#misc merge latest junk
meka/RA_Integration.dll
meka/RA_Integration_d.dll
meka/RAmeka.bsc
meka/RAmeka.exe
Expand Down
76 changes: 2 additions & 74 deletions RAMeka/meka/srcs/RA_Implementation.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "RA_Implementation.h"
#include "RA_Interface.h"
#include "BuildVer.h"
#include <windows.h>

//#ifdef ARCH_WIN32
Expand All @@ -9,8 +10,6 @@
#include "vmachine.h"

//Don't like using externs, but many of the corressponding header files don't agree well with inclusion here
//extern void Machine_UnPause(); //machine.c
//extern void Machine_Pause(); //machine.c
extern HWND ConsoleHWND(void); //message.c
extern void ConsolePrintf(const char *format, ...); //message.c

Expand All @@ -20,10 +19,6 @@ extern void ConsolePrintf(const char *format, ...); //message.c
#include "app_cheatfinder.h"
#include "debugger.h"

//extern t_memory_viewer *MemoryViewer_MainInstance;
//extern struct t_cheat_finder *g_CheatFinder_MainInstance;
//extern struct t_debugger Debugger;


//Required for new RA Memory Bank interface
//See: RA_MemManager.h _RAMByteReadFn _RAMByteWriteFn
Expand Down Expand Up @@ -136,7 +131,7 @@ void GetEstimatedGameTitle(char* sNameOut)
}


void Machine_Reset(); //machine.c
extern void Machine_Reset(); //machine.c
void ResetEmulation()
{
Machine_Reset(); // FCEUI_ResetNES();
Expand Down Expand Up @@ -208,27 +203,12 @@ void RAMeka_InstallRA() {
RA_Init(ConsoleHWND(), RA_Meka, RAMEKA_VERSION);

RA_InitShared();
RA_InitDirectX();
RA_UpdateAppTitle("RAMEKA");

RebuildMenu();
RA_HandleHTTPResults();
RA_AttemptLogin(true);
RebuildMenu();

}

//Silently disable Hardcore Mode if any of several Meka dialogs is active.
void RAMeka_ValidateHardcoreMode() {

//If either the Memory_Viewer (allows editing), or the CheatFinder (is cheating),
//or the Debugger are active, hardcore mode must be disabled
if (MemoryViewer_MainInstance->active || Debugger.active /*|| g_CheatFinder_MainInstance->active*/ ) {

RA_OnSaveState( "" ); // Needs better function for disabling hardcore from emulator.
//Silently disable Hardcore mode if any of these are active at startup
//(Will also need code to disable when they are activated as well)
}
}

//Performs needed procedures for shutting down achievement system
Expand Down Expand Up @@ -309,58 +289,6 @@ void RAMeka_RA_MountROM( ConsoleID consoleID ) {
chdir( Meka_currDir );
}


//Check if hardcore mode is active, and if so, warns that current feature will be disabled
bool RAMeka_HardcoreIsActiveCheck(RAMeka_Softcore_Feature current_feature) {

const char *disabling_feature_messages[] = {
"Hardcore Mode active. Disabling Memory Editor",
"Hardcore Mode active. Disabling Debugger",
"Hardcore Mode active. Disabling CheatFinder",
"Hardcore Mode active. Disabling Save/Load states" //not actually used
// "Hardcore Mode active. Disabling Load states", //not actually used
// "Hardcore Mode active. Disabling Save states", //not actually used
};

if (RA_HardcoreModeIsActive()) {
const char *warning_message = disabling_feature_messages[current_feature];
MessageBox(NULL, warning_message, "Warning!", MB_ICONWARNING);
return true;
}
else {
return false;
}

}

//If harcore mode is active, request explicit user confirmation before deactivating it
bool RAMeka_HardcoreDeactivateConfirm(RAMeka_Softcore_Feature current_feature) {

const char *deactivation_confirm_messages[] = {
"Hardcore mode is active. If you enable the Memory Editor, Hardcore Mode will be disabled. Continue?",
"Hardcore mode is active. If you enable the Debugger, Hardcore Mode will be disabled. Continue?",
"Hardcore mode is active. If you enable the Cheat Finder, Hardcore Mode will be disabled. Continue?", //strictly nessesary?
"Hardcore mode is active. If you Save/Load a state, Hardcore Mode will be disabled. Continue?"
// "Hardcore mode is active. If you Load a state, Hardcore Mode will be disabled. Continue?",
// "Hardcore mode is active. If you Save a state, Hardcore Mode will be disabled. Continue?",
};

if (!RA_HardcoreModeIsActive()) {
return true; //no need to ask for confirmation
}
else {
const char *warning_message = deactivation_confirm_messages[current_feature];
bool user_confirmation_response =
(MessageBox(NULL, warning_message, "Warning", (MB_YESNO | MB_SETFOREGROUND)) == IDYES);

if (user_confirmation_response == true) {
RA_OnSaveState( "" );
}
return user_confirmation_response;
}

}

//Code to handle reading RAMeka specific configuration variables
void RAMeka_Config_Load_Line(char *var, char *value) {

Expand Down
21 changes: 0 additions & 21 deletions RAMeka/meka/srcs/RA_Implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ extern void RA_InitShared();
// Emulator RA Integration Wrapper Functions |
//-----------------------------------------------------------------------

//Most of the other emulators define their version in their MakeBuildVer.bat scripts.
//But we're using NuGet/Allegro/VS2015 so nothing here is "straightforward"
#define RAMEKA_VERSION "0.021"

#include <windows.h> //for WPARAM (kind of wasteful really)
#include "RA_Interface.h"

Expand All @@ -65,32 +61,15 @@ void RAMeka_RA_SetPaused(bool bIsPaused);
void RAMeka_RA_OnSaveStateLoad(char* filename);
void RAMeka_RA_OnSaveStateSave(char* filename);

void RAMeka_RA_MountMasterSystemROM();
void RAMeka_RA_MountROM( ConsoleID consoleID );


void RAMeka_MakePlaceholderRAMenu();
void RAMeka_InstallRA();

void RAMeka_ValidateHardcoreMode();

void RAMeka_RA_AchievementsFrameCheck();


enum RAMeka_Softcore_Feature {
SCF_MEMORY_EDITOR,
SCF_DEBUGGER,
SCF_CHEAT_FINDER,
SCF_SAVE_LOAD,
// SCF_LOAD,
// SCF_SAVE,
SCF_UNKNOWN
};

bool RAMeka_HardcoreIsActiveCheck(RAMeka_Softcore_Feature current_feature);
bool RAMeka_HardcoreDeactivateConfirm(RAMeka_Softcore_Feature current_feature);


void RAMeka_Config_Load_Line(char *var, char *value);
//void RAMeka_Configs_Save(void *Write_Line_func, void *Write_Int_func, void *Write_Str_func);

Expand Down
4 changes: 2 additions & 2 deletions RAMeka/meka/srcs/app_cheatfinder.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,8 @@ void CheatFinder_SwitchMainInstance()

//Not sure if hardcore deactivation is really required in case of cheat finder alone
//if (!app->active) {
// if (!RAMeka_HardcoreDeactivateConfirm(SCF_CHEAT_FINDER)) {
// return; //user did not agree to a hardcore mode deactivation, abandon debugger activation
// if (!RA_WarnDisableHardcore("find cheats")) {
// return; //user did not agree to a hardcore mode deactivation, abandon cheat finder activation
// }
//}

Expand Down
4 changes: 2 additions & 2 deletions RAMeka/meka/srcs/app_memview.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ static void MemoryViewer_Update(t_memory_viewer* app)
return;
}

if (RAMeka_HardcoreIsActiveCheck(SCF_MEMORY_EDITOR)) {
if (RA_HardcoreModeIsActive()) {
MemoryViewer_SwitchMainInstance();
return;
}
Expand Down Expand Up @@ -646,7 +646,7 @@ void MemoryViewer_SwitchMainInstance()
t_memory_viewer* app = MemoryViewer_MainInstance;

if (!app->active) {
if (!RAMeka_HardcoreDeactivateConfirm(SCF_MEMORY_EDITOR)) {
if (!RA_WarnDisableHardcore("view memory")) {
return; //user did not agree to a hardcore mode deactivation, abandon debugger activation
}
}
Expand Down
4 changes: 2 additions & 2 deletions RAMeka/meka/srcs/debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ void Debugger_Update()
{
if (Debugger.active)
{
if (RAMeka_HardcoreIsActiveCheck(SCF_DEBUGGER)) {
if (RA_HardcoreModeIsActive()) {
Debugger_Switch();
return;
}
Expand Down Expand Up @@ -1866,7 +1866,7 @@ void Debugger_Switch()
return;

if (!Debugger.active) {
if (! RAMeka_HardcoreDeactivateConfirm(SCF_DEBUGGER)) {
if (!RA_WarnDisableHardcore("debug")) {
return; //user did not agree to a hardcore mode deactivation, abandon debugger activation
}
}
Expand Down
3 changes: 3 additions & 0 deletions RAMeka/meka/srcs/machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,9 @@ void Machine_Reset(void)
#ifdef MEKA_Z80_DEBUGGER
Debugger_MachineReset();
#endif

// RA
RA_OnReset();
}

//-----------------------------------------------------------------------------
14 changes: 10 additions & 4 deletions RAMeka/meka/srcs/meka.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,16 @@ int main(int argc, char **argv)
Init_GUI (); // Initialize Graphical User Interface
FB_Init_2 (); // Finish initializing the file browser

//RA
RAMeka_ValidateHardcoreMode (); // Disable Hardcore mode if required


// RA
if (RA_HardcoreModeIsActive())
{
if (MemoryViewer_MainInstance->active)
gui_box_show(MemoryViewer_MainInstance->box, FALSE, FALSE);
if (Debugger.enabled)
Debugger_Close();
if (g_CheatFinder_MainInstance->active)
gui_box_show(g_CheatFinder_MainInstance->box, FALSE, FALSE);
}

// Load ROM from command line if necessary
Load_ROM_Command_Line();
Expand Down
33 changes: 33 additions & 0 deletions RAMeka/meka/srcs/projects/msvc/MakeBuildVer.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@echo off

git describe --tags --match "RAMeka.*" > Temp.txt
set /p ACTIVE_TAG=<Temp.txt
set VERSION_NUM=%ACTIVE_TAG:~7,3%
set VERSION_REVISION=%ACTIVE_TAG:~11,-9%
if "%VERSION_REVISION%"=="" set VERSION_REVISION=0

setlocal
git diff HEAD > Temp.txt
for /F "usebackq" %%A in ('"Temp.txt"') do set DIFF_FILE_SIZE=%%~zA
if %DIFF_FILE_SIZE% GTR 0 (
set ACTIVE_TAG=Unstaged changes
set VERSION_MODIFIED=1
) else (
set VERSION_MODIFIED=0
)

@echo Tag: %ACTIVE_TAG% (%VERSION_NUM%)
@echo #define RAMEKA_VERSION "0.%VERSION_NUM%.%VERSION_REVISION%.%VERSION_MODIFIED%" > BuildVer2.h

if not exist ..\..\BuildVer.h goto nonexistant
fc ..\..\BuildVer.h BuildVer2.h > nul
if errorlevel 1 goto different
del BuildVer2.h
goto done
:different
del ..\..\BuildVer.h
:nonexistant
move BuildVer2.h ..\..\BuildVer.h > nul
:done

del Temp.txt
6 changes: 6 additions & 0 deletions RAMeka/meka/srcs/projects/msvc/Meka.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@
<EnableDpiAwareness>true</EnableDpiAwareness>
</Manifest>
<PostBuildEvent />
<PreBuildEvent>
<Command>$(ProjectDir)MakeBuildVer.bat</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Midl>
Expand Down Expand Up @@ -182,6 +185,9 @@
<CustomBuildStep />
<Manifest />
<PostBuildEvent />
<PreBuildEvent>
<Command>$(ProjectDir)MakeBuildVer.bat</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<None Include="..\..\..\meka.blt" />
Expand Down
8 changes: 2 additions & 6 deletions RAMeka/meka/srcs/projects/msvc/Meka.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,7 @@
<ClCompile Include="..\..\RA_Implementation.cpp">
<Filter>RA_Implementation</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\..\RA_Integration\RA_Interface.cpp">
<Filter>RA_Implementation</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\..\RA_Integration\src\RA_Interface.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\allegro4to5.h">
Expand Down Expand Up @@ -789,9 +787,7 @@
<ClInclude Include="..\..\RA_Implementation.h">
<Filter>RA_Implementation</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\..\RA_Integration\RA_Interface.h">
<Filter>RA_Implementation</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\..\RA_Integration\src\RA_Interface.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Meka.rc">
Expand Down
Loading

0 comments on commit fbdaa67

Please sign in to comment.