Profile saving stuff

This commit is contained in:
cuckydev 2019-02-01 15:56:19 -05:00
parent 3aed029174
commit 9fb2e33e17
7 changed files with 95 additions and 11 deletions

BIN
build/Profile - Copy.dat Normal file

Binary file not shown.

View file

@ -12,6 +12,7 @@
#include "MiniMap.h"
#include "MyChar.h"
#include "Frame.h"
#include "SelStage.h"
#include "ValueView.h"
#include "Stage.h"
#include "Game.h"
@ -36,7 +37,80 @@ bool IsProfile()
bool SaveProfile(char *name)
{
return false;
//Get path
char path[PATH_LENGTH];
if ( name )
sprintf(path, "%s/%s", gModulePath, name);
else
sprintf(path, "%s/%s", gModulePath, gDefaultName);
//Open file
PROFILE profile;
SDL_RWops *fp = SDL_RWFromFile(path, "wb");
if (!fp)
return false;
//Set up profile
memset(&profile, 0, sizeof(PROFILE));
memcpy(profile.code, gProfileCode, sizeof(profile.code));
memcpy(profile.FLAG, "FLAG", sizeof(profile.FLAG));
profile.stage = gStageNo;
profile.music = gMusicNo;
profile.x = gMC.x;
profile.y = gMC.y;
profile.direct = gMC.direct;
profile.max_life = gMC.max_life;
profile.life = gMC.life;
profile.star = gMC.star;
profile.select_arms = gSelectedArms;
profile.select_item = gSelectedItem;
profile.equip = gMC.equip;
profile.unit = gMC.unit;
profile.counter = gCounter;
memcpy(profile.arms, gArmsData, sizeof(profile.arms));
memcpy(profile.items, gItemData, sizeof(profile.items));
memcpy(profile.permitstage, gPermitStage, sizeof(profile.permitstage));
memcpy(profile.permit_mapping, gMapping, sizeof(profile.permit_mapping));
memcpy(profile.flags, gFlagNPC, sizeof(profile.flags));
//Write to file
SDL_RWwrite(fp, profile.code, 8, 1);
SDL_WriteLE32(fp, profile.stage);
SDL_WriteLE32(fp, profile.music);
SDL_WriteLE32(fp, profile.x);
SDL_WriteLE32(fp, profile.y);
SDL_WriteLE32(fp, profile.direct);
SDL_WriteLE16(fp, profile.max_life);
SDL_WriteLE16(fp, profile.star);
SDL_WriteLE16(fp, profile.life);
SDL_WriteLE16(fp, profile.a);
SDL_WriteLE32(fp, profile.select_arms);
SDL_WriteLE32(fp, profile.select_item);
SDL_WriteLE32(fp, profile.equip);
SDL_WriteLE32(fp, profile.unit);
SDL_WriteLE32(fp, profile.counter);
for (int arm = 0; arm < 8; arm++)
{
SDL_WriteLE32(fp, profile.arms[arm].code);
SDL_WriteLE32(fp, profile.arms[arm].level);
SDL_WriteLE32(fp, profile.arms[arm].exp);
SDL_WriteLE32(fp, profile.arms[arm].max_num);
SDL_WriteLE32(fp, profile.arms[arm].num);
}
for (int item = 0; item < 32; item++)
SDL_WriteLE32(fp, profile.items[item].code);
for (int stage = 0; stage < 8; stage++)
{
SDL_WriteLE32(fp, profile.permitstage[stage].index);
SDL_WriteLE32(fp, profile.permitstage[stage].event);
}
SDL_RWwrite(fp, profile.permit_mapping, 0x80, 1);
SDL_RWwrite(fp, "FLAG", 4, 1);
SDL_RWwrite(fp, profile.flags, 1000, 1);
SDL_RWclose(fp);
return true;
}
bool LoadProfile(char *name)
@ -88,7 +162,11 @@ bool LoadProfile(char *name)
}
for (int item = 0; item < 32; item++)
profile.items[item].code = SDL_ReadLE32(fp);
SDL_RWread(fp, profile.permitstage, 8, 8);
for (int stage = 0; stage < 8; stage++)
{
profile.permitstage[stage].index = SDL_ReadLE32(fp);
profile.permitstage[stage].event = SDL_ReadLE32(fp);
}
SDL_RWread(fp, profile.permit_mapping, 0x80, 1);
SDL_RWread(fp, profile.FLAG, 4, 1);
SDL_RWread(fp, profile.flags, 1000, 1);
@ -101,9 +179,9 @@ bool LoadProfile(char *name)
memcpy(gArmsData, profile.arms, sizeof(gArmsData));
memcpy(gItemData, profile.items, sizeof(gItemData));
//memcpy(gPermitStage, profile.permitstage, 0x40u);
memcpy(gMapping, profile.permit_mapping, 0x80);
memcpy(gFlagNPC, profile.flags, 1000);
memcpy(gPermitStage, profile.permitstage, sizeof(gPermitStage));
memcpy(gMapping, profile.permit_mapping, sizeof(gMapping));
memcpy(gFlagNPC, profile.flags, sizeof(gFlagNPC));
//Load stage
ChangeMusic(profile.music);

View file

@ -1,6 +1,7 @@
#pragma once
#include <stdint.h>
#include "ArmsItem.h"
#include "SelStage.h"
struct PROFILE
{
@ -21,7 +22,7 @@ struct PROFILE
int counter;
ARMS arms[8];
ITEM items[32];
char permitstage[8][8];
PERMIT_STAGE permitstage[8];
char permit_mapping[0x80];
char FLAG[4];
uint8_t flags[1000];

View file

@ -10,11 +10,7 @@
#include "Sound.h"
#include "WindowsWrapper.h"
static struct
{
int index;
int event;
} gPermitStage[8];
PERMIT_STAGE gPermitStage[8];
static int gSelectedStage;
static int gStageSelectTitleY;

View file

@ -1,4 +1,11 @@
#pragma once
struct PERMIT_STAGE
{
int index;
int event;
};
extern PERMIT_STAGE gPermitStage[8];
void ClearPermitStage(void);
bool AddPermitStage(int index, int event);

View file

@ -13,6 +13,7 @@ struct STAGE_TABLE
};
extern int gStageNo;
extern int gMusicNo;
bool TransferStage(int no, int w, int x, int y);
void ChangeMusic(int no);

View file

@ -678,6 +678,7 @@ int TextScriptProc()
y = GetTextScriptNo(gTS.p_read + 9);
AddPermitStage(x, y);
gTS.p_read += 13;
}
else if (IS_COMMAND('M','P','+'))
{
x = GetTextScriptNo(gTS.p_read + 4);