shithub: cstory

Download patch

ref: 9fb2e33e17c0e3266c37654fda110f79e63c3779
parent: 3aed029174f4bbbe42d99d68f0db2625643d8e81
author: cuckydev <cuckydev@users.noreply.github.com>
date: Fri Feb 1 10:56:19 EST 2019

Profile saving stuff

binary files /dev/null b/build/Profile - Copy.dat differ
--- a/src/Profile.cpp
+++ b/src/Profile.cpp
@@ -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 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 @@
 	}
 	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 @@
 
 	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);
--- a/src/Profile.h
+++ b/src/Profile.h
@@ -1,6 +1,7 @@
 #pragma once
 #include <stdint.h>
 #include "ArmsItem.h"
+#include "SelStage.h"
 
 struct PROFILE
 {
@@ -21,7 +22,7 @@
 	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];
--- a/src/SelStage.cpp
+++ b/src/SelStage.cpp
@@ -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;
--- a/src/SelStage.h
+++ b/src/SelStage.h
@@ -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);
--- a/src/Stage.h
+++ b/src/Stage.h
@@ -13,6 +13,7 @@
 };
 
 extern int gStageNo;
+extern int gMusicNo;
 
 bool TransferStage(int no, int w, int x, int y);
 void ChangeMusic(int no);
--- a/src/TextScr.cpp
+++ b/src/TextScr.cpp
@@ -678,6 +678,7 @@
 						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);
--