Its working but more work is needed.

This commit is contained in:
louist103 2022-04-02 23:15:09 -04:00
commit ed929a2942
13 changed files with 208 additions and 17 deletions

View file

@ -29,26 +29,26 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>

View file

@ -1,3 +1,6 @@
#ifndef CONFIG_FILE_H
#define CONFIG_FILE_H
#pragma once #pragma once
#include <string> #include <string>
@ -35,3 +38,5 @@ namespace Ship {
mINI::INIFile File; mINI::INIFile File;
}; };
} }
#endif

View file

@ -1,3 +1,6 @@
#ifndef GAME_VERSION_H
#define GAME_VERSION_H
#pragma once #pragma once
#define OOT_NTSC_10 0xEC7011B7 #define OOT_NTSC_10 0xEC7011B7
@ -17,4 +20,6 @@
#define OOT_PAL_GC_MQ_DBG 0x917D18F6 #define OOT_PAL_GC_MQ_DBG 0x917D18F6
#define OOT_IQUE_TW 0x3D81FB3E #define OOT_IQUE_TW 0x3D81FB3E
#define OOT_IQUE_CN 0xB1E1E07B #define OOT_IQUE_CN 0xB1E1E07B
#define OOT_UNKNOWN 0xFFFFFFFF #define OOT_UNKNOWN 0xFFFFFFFF
#endif

View file

@ -1,3 +1,6 @@
#ifndef GLOBAL_CTX_2
#define GLOBAL_CTX_2
#pragma once #pragma once
#ifdef __cplusplus #ifdef __cplusplus
@ -38,4 +41,6 @@ namespace Ship {
std::string PatchesPath; std::string PatchesPath;
}; };
} }
#endif #endif
#endif

View file

@ -38,19 +38,19 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Testing|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Testing|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>

View file

@ -2405,6 +2405,7 @@ void Heaps_Free(void);
#ifdef __cplusplus #ifdef __cplusplus
}; };
#undef this
#endif #endif
#endif #endif

View file

@ -1,7 +1,12 @@
#ifndef STDDEF_H #ifndef STDDEF_H
#define STDDEF_H #define STDDEF_H
#ifndef __cplusplus
#define NULL ((void*)0) #define NULL ((void*)0)
#else
#define NULL nullptr
#endif
#if 0 #if 0
#define size_t unsigned long #define size_t unsigned long
#define ssize_t long #define ssize_t long

View file

@ -29,14 +29,14 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<EnableASAN>false</EnableASAN> <EnableASAN>false</EnableASAN>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<EnableASAN>false</EnableASAN> <EnableASAN>false</EnableASAN>
@ -44,13 +44,13 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
@ -180,6 +180,7 @@
<ClCompile Include="soh\Enhancements\debugger\debugSaveEditor.cpp" /> <ClCompile Include="soh\Enhancements\debugger\debugSaveEditor.cpp" />
<ClCompile Include="soh\Enhancements\debugger\ImGuiHelpers.cpp" /> <ClCompile Include="soh\Enhancements\debugger\ImGuiHelpers.cpp" />
<ClCompile Include="soh\Enhancements\gameconsole.c" /> <ClCompile Include="soh\Enhancements\gameconsole.c" />
<ClCompile Include="soh\Enhancements\savestates.cpp" />
<ClCompile Include="soh\GbiWrap.cpp" /> <ClCompile Include="soh\GbiWrap.cpp" />
<ClCompile Include="soh\gu_pc.c" /> <ClCompile Include="soh\gu_pc.c" />
<ClCompile Include="soh\OTRGlobals.cpp" /> <ClCompile Include="soh\OTRGlobals.cpp" />
@ -926,6 +927,7 @@
<ClInclude Include="soh\Enhancements\cvar.h" /> <ClInclude Include="soh\Enhancements\cvar.h" />
<ClInclude Include="soh\Enhancements\debugconsole.h" /> <ClInclude Include="soh\Enhancements\debugconsole.h" />
<ClInclude Include="soh\Enhancements\debugger\colViewer.h" /> <ClInclude Include="soh\Enhancements\debugger\colViewer.h" />
<ClInclude Include="soh\Enhancements\savestates.h" />
<ClInclude Include="soh\Enhancements\debugger\debugger.h" /> <ClInclude Include="soh\Enhancements\debugger\debugger.h" />
<ClInclude Include="soh\Enhancements\debugger\debugSaveEditor.h" /> <ClInclude Include="soh\Enhancements\debugger\debugSaveEditor.h" />
<ClInclude Include="soh\Enhancements\debugger\ImGuiHelpers.h" /> <ClInclude Include="soh\Enhancements\debugger\ImGuiHelpers.h" />

View file

@ -2190,6 +2190,9 @@
<ClCompile Include="soh\Enhancements\debugger\ImGuiHelpers.cpp"> <ClCompile Include="soh\Enhancements\debugger\ImGuiHelpers.cpp">
<Filter>Source Files\soh\Enhancements\debugger</Filter> <Filter>Source Files\soh\Enhancements\debugger</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="soh\Enhancements\savestates.cpp">
<Filter>Source Files\soh\Enhancements</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="src\overlays\actors\ovl_kaleido_scope\z_kaleido_scope.h"> <ClInclude Include="src\overlays\actors\ovl_kaleido_scope\z_kaleido_scope.h">
@ -3740,6 +3743,9 @@
<ClInclude Include="soh\util.h"> <ClInclude Include="soh\util.h">
<Filter>Header Files\soh</Filter> <Filter>Header Files\soh</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="soh\Enhancements\savestates.h">
<Filter>Header Files\soh\Enhancements</Filter>
</ClInclude>
<ClInclude Include="soh\Enhancements\debugger\colViewer.h"> <ClInclude Include="soh\Enhancements\debugger\colViewer.h">
<Filter>Header Files\soh\Enhancements\debugger</Filter> <Filter>Header Files\soh\Enhancements\debugger</Filter>
</ClInclude> </ClInclude>

View file

@ -1,8 +1,11 @@
#include "debugconsole.h" #include "debugconsole.h"
#include "../libultraship/SohImGuiImpl.h" #include "../libultraship/SohImGuiImpl.h"
#include "savestates.h"
#include <vector> #include <vector>
#include <string> #include <string>
#define Path _Path #define Path _Path
#define PATH_HACK #define PATH_HACK
#include <Utils/StringHelper.h> #include <Utils/StringHelper.h>
@ -303,6 +306,17 @@ static bool EntranceHandler(const std::vector<std::string>& args) {
gSaveContext.nextTransition = 11; gSaveContext.nextTransition = 11;
} }
static bool SaveStateHandler(const std::vector<std::string>& args) {
SaveState::Save(0);
return CMD_SUCCESS;
}
static bool LoadStateHandler(const std::vector<std::string>& args) {
SaveState::Load(0);
return CMD_SUCCESS;
}
#define VARTYPE_INTEGER 0 #define VARTYPE_INTEGER 0
#define VARTYPE_FLOAT 1 #define VARTYPE_FLOAT 1
#define VARTYPE_STRING 2 #define VARTYPE_STRING 2
@ -416,11 +430,10 @@ void DebugConsole_Init(void) {
{ { "slot", ArgumentType::NUMBER }, { "item id", ArgumentType::NUMBER } } }); { { "slot", ArgumentType::NUMBER }, { "item id", ArgumentType::NUMBER } } });
CMD_REGISTER("entrance", CMD_REGISTER("entrance",
{ EntranceHandler, "Sends player to the entered entrance (hex)", { { "entrance", ArgumentType::NUMBER } } }); { EntranceHandler, "Sends player to the entered entrance (hex)", { { "entrance", ArgumentType::NUMBER } } });
}
template <typename Numeric> bool is_number(const std::string& s) { CMD_REGISTER("save_state", { SaveStateHandler, "Save a state." });
Numeric n; CMD_REGISTER("load_state", { LoadStateHandler, "Load a state." });
return ((std::istringstream(s) >> n >> std::ws).eof()); DebugConsole_LoadCVars();
} }
void DebugConsole_LoadCVars() void DebugConsole_LoadCVars()

View file

@ -0,0 +1,84 @@
#include "savestates.h"
#include "GameVersions.h"
#include <variables.h>
//#include "global.h"
//#include <soh/OTRGlobals.h>
std::array<SaveState*, 3> gSaveStates;
SaveState::SaveState() {
}
#if 0
SaveState::~SaveState() {
}
#endif
void SaveState::Init(void) {
gSaveStates[0] = nullptr;
gSaveStates[1] = nullptr;
gSaveStates[2] = nullptr;
}
void SaveState::WriteHeader(SaveStateHeader& header) {
//OTRGlobals::Instance->context->GetResourceManager()->GetGameVersion();
// header.gameVersion = ResourceMgr_GetGameVersion();
}
extern "C" MtxF* sMatrixStack; // "Matrix_stack"
extern "C" MtxF* sCurrentMatrix; // "Matrix_now"
extern "C" LightsBuffer sLightsBuffer;
extern "C" SaveStateReturn SaveState::Save(unsigned int slot) {
if (slot > 2) {
return SaveStateReturn::FAIL_INVALID_SLOT;
}
if (gSaveStates[slot] == nullptr) {
gSaveStates[slot] = new SaveState;
if (gSaveStates[slot] == nullptr) {
return SaveStateReturn::FAIL_NO_MEMORY;
}
}
gSaveStates[slot]->stateHeader.gameVersion = 0;
gSaveStates[slot]->stateHeader.stateVersion = 0;
memcpy(&gSaveStates[slot]->sysHeapCopy, &gSystemHeap, 1024 * 1024 * 4 /* sizeof(gSystemHeap) */);
memcpy(&gSaveStates[slot]->saveContextCopy, &gSaveContext, sizeof(gSaveContext));
memcpy(&gSaveStates[slot]->gameInfoCopy, gGameInfo, sizeof(*gGameInfo));
// memcpy(&gSaveStates[slot]->audioContextCopy, &gAudioContext, sizeof(AudioContext));
memcpy(&gSaveStates[slot]->lightBufferCopy, &sLightsBuffer, sizeof(sLightsBuffer));
memcpy(&gSaveStates[slot]->mtxStackCopy, &sMatrixStack, sizeof(MtxF) * 20);
memcpy(&gSaveStates[slot]->currentMtxCopy, &sCurrentMatrix, sizeof(MtxF));
//TODO RNG seed
return SaveStateReturn::SUCCESS;
}
SaveStateReturn SaveState::Load(unsigned int slot) {
if (slot > 2) {
return SaveStateReturn::FAIL_INVALID_SLOT;
}
if (gSaveStates[slot] == nullptr) {
return SaveStateReturn::FAIL_STATE_EMPTY;
}
//gSaveStates[slot]->stateHeader.gameVersion = 0;
//gSaveStates[slot]->stateHeader.stateVersion = 0;
memcpy(&gSystemHeap, &gSaveStates[slot]->sysHeapCopy, 1024 * 1024 * 4);
memcpy(&gSaveContext, &gSaveStates[slot]->saveContextCopy, sizeof(gSaveContext));
memcpy(gGameInfo, &gSaveStates[slot]->gameInfoCopy, sizeof(*gGameInfo));
//memcpy(&gAudioContext, &gSaveStates[slot]->audioContextCopy, sizeof(AudioContext));
memcpy(&sLightsBuffer, &gSaveStates[slot]->lightBufferCopy, sizeof(sLightsBuffer));
memcpy(&sMatrixStack, &gSaveStates[slot]->mtxStackCopy, sizeof(MtxF) * 20);
memcpy(&sCurrentMatrix, &gSaveStates[slot]->currentMtxCopy, sizeof(MtxF));
//TODO RNG seed
return SaveStateReturn::SUCCESS;
}

View file

@ -0,0 +1,60 @@
#ifndef SAVE_STATES_H
#define SAVE_STATES_H
#include "z64.h"
#include "z64save.h"
#include <cstdint>
#include <array>
// FROM z_lights.c
// I didn't feel like moving it into a header file.
#define LIGHTS_BUFFER_SIZE 32
//#define LIGHTS_BUFFER_SIZE 1024 // Kill me
typedef struct {
/* 0x000 */ s32 numOccupied;
/* 0x004 */ s32 searchIndex;
/* 0x008 */ LightNode buf[LIGHTS_BUFFER_SIZE];
} LightsBuffer; // size = 0x188
enum class SaveStateReturn {
SUCCESS,
FAIL_INVALID_SLOT,
FAIL_NO_MEMORY,
FAIL_STATE_EMPTY,
};
typedef struct SaveStateHeader {
uint32_t stateVersion;
uint32_t gameVersion;
} SaveStateHeader;
class SaveState {
public:
SaveState();
~SaveState() = delete;
SaveState& operator=(const SaveState& rhs) = delete;
SaveState(const SaveState& rhs) = delete;
void Init(void);
static SaveStateReturn Save(unsigned int slot);
static SaveStateReturn Load(unsigned int slot);
private:
static void WriteHeader(SaveStateHeader& header);
static void ReadHeader(SaveStateHeader& header);
SaveStateHeader stateHeader;
unsigned char sysHeapCopy[1024 * 1024 * 4]; //TODO, make a macro for this
SaveContext saveContextCopy;
GameInfo gameInfoCopy;
LightsBuffer lightBufferCopy;
//AudioContext audioContextCopy;
std::array<MtxF,20> mtxStackCopy; // always 20 matricies
MtxF currentMtxCopy;
uint32_t rngSeed;
};
#endif

View file

@ -1,3 +1,6 @@
#ifndef OTR_GLOBALS_H
#define OTR_GLOBALS_H
#pragma once #pragma once
#include "GlobalCtx2.h" #include "GlobalCtx2.h"
@ -68,3 +71,5 @@ void AudioPlayer_Play(const uint8_t* buf, uint32_t len);
void AudioMgr_CreateNextAudioBuffer(s16* samples, u32 num_samples); void AudioMgr_CreateNextAudioBuffer(s16* samples, u32 num_samples);
int Controller_ShouldRumble(size_t i); int Controller_ShouldRumble(size_t i);
#endif #endif
#endif