mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-08-22 06:13:45 -07:00
parent
c80f9fbd57
commit
ad8d37ab2d
4 changed files with 100 additions and 4 deletions
|
@ -58,6 +58,9 @@ namespace Ship {
|
||||||
(*this)["ARCHIVE"]["Main Archive"] = "oot.otr";
|
(*this)["ARCHIVE"]["Main Archive"] = "oot.otr";
|
||||||
(*this)["ARCHIVE"]["Patches Directory"] = "";
|
(*this)["ARCHIVE"]["Patches Directory"] = "";
|
||||||
|
|
||||||
|
(*this)["SAVE"]["Save Filename"] = "oot_save.sav";
|
||||||
|
(*this)["SAVE"]["Save File Directory"] = "";
|
||||||
|
|
||||||
(*this)["CONTROLLERS"]["CONTROLLER 1"] = "Auto";
|
(*this)["CONTROLLERS"]["CONTROLLER 1"] = "Auto";
|
||||||
(*this)["CONTROLLERS"]["CONTROLLER 2"] = "Unplugged";
|
(*this)["CONTROLLERS"]["CONTROLLER 2"] = "Unplugged";
|
||||||
(*this)["CONTROLLERS"]["CONTROLLER 3"] = "Unplugged";
|
(*this)["CONTROLLERS"]["CONTROLLER 3"] = "Unplugged";
|
||||||
|
|
|
@ -343,6 +343,7 @@ extern "C" int ResourceMgr_OTRSigCheck(char* imgData)
|
||||||
{
|
{
|
||||||
uintptr_t i = (uintptr_t)(imgData);
|
uintptr_t i = (uintptr_t)(imgData);
|
||||||
|
|
||||||
|
|
||||||
if (i == 0xD9000000 || i == 0xE7000000 || (i & 0xF0000000) == 0xF0000000)
|
if (i == 0xD9000000 || i == 0xE7000000 || (i & 0xF0000000) == 0xF0000000)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -373,6 +374,7 @@ extern "C" AnimationHeaderCommon* ResourceMgr_LoadAnimByName(char* path) {
|
||||||
for (int i = 0; i < res->rotationValues.size(); i++)
|
for (int i = 0; i < res->rotationValues.size(); i++)
|
||||||
animNormal->frameData[i] = res->rotationValues[i];
|
animNormal->frameData[i] = res->rotationValues[i];
|
||||||
|
|
||||||
|
|
||||||
animNormal->jointIndices = (JointIndex*)malloc(res->rotationIndices.size() * sizeof(Vec3s));
|
animNormal->jointIndices = (JointIndex*)malloc(res->rotationIndices.size() * sizeof(Vec3s));
|
||||||
|
|
||||||
for (int i = 0; i < res->rotationIndices.size(); i++) {
|
for (int i = 0; i < res->rotationIndices.size(); i++) {
|
||||||
|
@ -617,6 +619,27 @@ extern "C" s32* ResourceMgr_LoadCSByName(char* path)
|
||||||
return (s32*)res->commands.data();
|
return (s32*)res->commands.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Remember to free after use of value */
|
||||||
|
extern "C" char* Config_getValue(char* category, char* key)
|
||||||
|
{
|
||||||
|
std::shared_ptr<Ship::ConfigFile> pConf = OTRGlobals::Instance->context->GetConfig();
|
||||||
|
Ship::ConfigFile& Conf = *pConf.get();
|
||||||
|
|
||||||
|
std::string data = Conf.get(std::string(category)).get(std::string(key));
|
||||||
|
char* retval = (char*)malloc(data.length()+1);
|
||||||
|
strcpy(retval, data.c_str());
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" bool Config_setValue(char* category, char* key, char* value)
|
||||||
|
{
|
||||||
|
std::shared_ptr<Ship::ConfigFile> pConf = OTRGlobals::Instance->context->GetConfig();
|
||||||
|
Ship::ConfigFile& Conf = *pConf.get();
|
||||||
|
Conf[std::string(category)][std::string(key)] = std::string(value);
|
||||||
|
return Conf.Save();
|
||||||
|
}
|
||||||
|
|
||||||
std::wstring StringToU16(const std::string& s) {
|
std::wstring StringToU16(const std::string& s) {
|
||||||
std::vector<unsigned long> result;
|
std::vector<unsigned long> result;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|
|
@ -40,6 +40,8 @@ Gfx* ResourceMgr_LoadGfxByName(char* path);
|
||||||
Vtx* ResourceMgr_LoadVtxByCRC(uint64_t crc);
|
Vtx* ResourceMgr_LoadVtxByCRC(uint64_t crc);
|
||||||
Vtx* ResourceMgr_LoadVtxByName(char* path);
|
Vtx* ResourceMgr_LoadVtxByName(char* path);
|
||||||
CollisionHeader* ResourceMgr_LoadColByName(char* path);
|
CollisionHeader* ResourceMgr_LoadColByName(char* path);
|
||||||
|
char* Config_getValue(char* category, char* key);
|
||||||
|
bool Config_setValue(char* category, char* key, char* value);
|
||||||
uint64_t GetPerfCounter();
|
uint64_t GetPerfCounter();
|
||||||
struct SkeletonHeader* ResourceMgr_LoadSkeletonByName(char* path);
|
struct SkeletonHeader* ResourceMgr_LoadSkeletonByName(char* path);
|
||||||
int ResourceMgr_OTRSigCheck(char* imgData);
|
int ResourceMgr_OTRSigCheck(char* imgData);
|
||||||
|
|
|
@ -2,7 +2,15 @@
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#if defined(WIN32)
|
||||||
|
#define DIR_SEPARATOR '\\'
|
||||||
|
#else
|
||||||
|
#define DIR_SEPARATOR '/'
|
||||||
|
#endif
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -56,15 +64,71 @@ void SsSram_Dma(void* dramAddr, size_t size, s32 direction) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//https://stackoverflow.com/a/15019112
|
||||||
|
void combineDirectoryAndFileName(char* destination, char* directory, char* fileName)
|
||||||
|
{
|
||||||
|
if(directory && *directory) {
|
||||||
|
int len = strlen(directory);
|
||||||
|
strcpy(destination, directory);
|
||||||
|
|
||||||
|
if (destination[len - 1] == DIR_SEPARATOR)
|
||||||
|
{
|
||||||
|
if (fileName && *fileName)
|
||||||
|
{
|
||||||
|
strcpy(destination + len, (*fileName == DIR_SEPARATOR) ? (fileName + 1) : fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(fileName && *fileName)
|
||||||
|
{
|
||||||
|
if (*fileName == DIR_SEPARATOR)
|
||||||
|
{
|
||||||
|
strcpy(destination + len, fileName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
destination[len] = DIR_SEPARATOR;
|
||||||
|
strcpy(destination + len + 1, fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(fileName && *fileName)
|
||||||
|
{
|
||||||
|
strcpy(destination, fileName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
destination[0] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SsSram_ReadWrite(uintptr_t addr, void* dramAddr, size_t size, s32 direction) {
|
void SsSram_ReadWrite(uintptr_t addr, void* dramAddr, size_t size, s32 direction) {
|
||||||
osSyncPrintf("ssSRAMReadWrite:%08x %08x %08x %d\n", addr, (uintptr_t)dramAddr, size, direction);
|
osSyncPrintf("ssSRAMReadWrite:%08x %08x %08x %d\n", addr, (uintptr_t)dramAddr, size, direction);
|
||||||
|
|
||||||
|
char* directory = Config_getValue("SAVE", "Save File Directory");
|
||||||
|
char* fileName = Config_getValue("SAVE", "Save Filename");
|
||||||
|
|
||||||
|
// This only happens if a user deletes the default filename and doesn't replace it
|
||||||
|
if(fileName[0] == '\0')
|
||||||
|
{
|
||||||
|
Config_setValue("SAVE", "Save Filename", "oot_save.sav");
|
||||||
|
free(fileName);
|
||||||
|
fileName = malloc(sizeof("oot_save.sav")+1);
|
||||||
|
strcpy(fileName, "oot_save.sav");
|
||||||
|
}
|
||||||
|
|
||||||
|
char* file = malloc(strlen(directory) + strlen(fileName) + 2);
|
||||||
|
combineDirectoryAndFileName(file, directory, fileName);
|
||||||
|
|
||||||
//Check to see if the file exists
|
//Check to see if the file exists
|
||||||
FILE* saveFile;
|
FILE* saveFile;
|
||||||
saveFile = fopen("oot_save.sav", "rb");
|
saveFile = fopen(file, "rb");
|
||||||
|
|
||||||
if (saveFile == NULL) {
|
if (saveFile == NULL) {
|
||||||
|
|
||||||
saveFile = fopen("oot_save.sav", "wb");
|
saveFile = fopen(file, "wb");
|
||||||
fseek(saveFile, 0, SEEK_SET);
|
fseek(saveFile, 0, SEEK_SET);
|
||||||
assert(saveFile != NULL); // OTRTODO LOG
|
assert(saveFile != NULL); // OTRTODO LOG
|
||||||
uint8_t zero = 0;
|
uint8_t zero = 0;
|
||||||
|
@ -78,14 +142,14 @@ void SsSram_ReadWrite(uintptr_t addr, void* dramAddr, size_t size, s32 direction
|
||||||
}
|
}
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case OS_WRITE: {
|
case OS_WRITE: {
|
||||||
saveFile = fopen("oot_save.sav", "r+b");
|
saveFile = fopen(file, "r+b");
|
||||||
rewind(saveFile);
|
rewind(saveFile);
|
||||||
fseek(saveFile, addr, SEEK_SET);
|
fseek(saveFile, addr, SEEK_SET);
|
||||||
fwrite(dramAddr, size, 1, saveFile);
|
fwrite(dramAddr, size, 1, saveFile);
|
||||||
fclose(saveFile);
|
fclose(saveFile);
|
||||||
} break;
|
} break;
|
||||||
case OS_READ: {
|
case OS_READ: {
|
||||||
saveFile = fopen("oot_save.sav", "rb+");
|
saveFile = fopen(file, "rb+");
|
||||||
rewind(saveFile);
|
rewind(saveFile);
|
||||||
fseek(saveFile, addr, SEEK_SET);
|
fseek(saveFile, addr, SEEK_SET);
|
||||||
fread(dramAddr, size, 1, saveFile);
|
fread(dramAddr, size, 1, saveFile);
|
||||||
|
@ -94,4 +158,8 @@ void SsSram_ReadWrite(uintptr_t addr, void* dramAddr, size_t size, s32 direction
|
||||||
}
|
}
|
||||||
//SsSram_Init(addr, DEVICE_TYPE_SRAM, PI_DOMAIN2, 5, 0xD, 2, 0xC, 0);
|
//SsSram_Init(addr, DEVICE_TYPE_SRAM, PI_DOMAIN2, 5, 0xD, 2, 0xC, 0);
|
||||||
//SsSram_Dma(dramAddr, size, direction);
|
//SsSram_Dma(dramAddr, size, direction);
|
||||||
|
|
||||||
|
free(file);
|
||||||
|
free(directory);
|
||||||
|
free(fileName);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue