stoneage8.5/石器时代8.5客户端最新源代码/石器源码/system/savedata.cpp

499 lines
10 KiB
C++
Raw Permalink Normal View History

2020-06-23 15:53:23 +08:00
#include <stdio.h>
2020-06-23 15:27:59 +08:00
#include <string.h>
//#include <util.h>
#include "../systeminc/version.h"
#include "../systeminc/tool.h"
#include "../systeminc/system.h"
#include "../systeminc/pc.h"
#include "../systeminc/t_music.h"
#include "../systeminc/chat.h"
#include "../systeminc/menu.h"
#include "../systeminc/lssproto_cli.h"
#include"../systeminc/netmain.h"
#include "../systeminc/savedata.h"
// ?????? //
//
2020-06-23 15:53:23 +08:00
// ?????
2020-06-23 15:27:59 +08:00
// SAVEDATA_VER ????????????(4 byte)
// CDKEY CD??(12 byte)
// PASSWORD ?????(12 byte)
2020-06-23 15:53:23 +08:00
// BA_SEL_PEN ·卯??向?▔??︻????????
// ·卯???????? 叉
// Bit 0 ... ·卯??向?▔??守
// Bit 1 ... ·卯?????
2020-06-23 15:27:59 +08:00
// Bit 2 ... ???????
2020-06-23 15:53:23 +08:00
// STEREO_FLAG_SIZE ???????????▔?
2020-06-23 15:27:59 +08:00
// SE_VOL ???????
// BGM_VOL ????????
2020-06-23 15:53:23 +08:00
// BGM_PITCH ???????阪?
// CHAT_COLOR ????更?
2020-06-23 15:27:59 +08:00
// CHAT_LINE ??????
2020-06-23 15:53:23 +08:00
// CHAT_AREA_SIZE ?????束???吳?
// MOUSE_CUR_SEL ????????︻?
2020-06-23 15:27:59 +08:00
// ???
enum
{
SAVEDATA_VER_SIZE = 2,
CDKEY_SIZE = 12,
PASSWORD_SIZE = 12,
BA_SEL_PEN_SIZE = 1,
STEREO_FLAG_SIZE = 1,
SE_VOL_SIZE = 1,
BGM_VOL_SIZE = 1,
BGM_PITCH_SIZE = 16,
CHAT_COLOR_SIZE = 1,
CHAT_LINE_SIZE = 1,
CHAT_AREA_SIZE = 1,
MOUSE_CUR_SEL_SIZE = 1
};
2020-06-23 15:53:23 +08:00
// ?
2020-06-23 15:27:59 +08:00
enum
{
SAVEDATA_VER = 0,
CDKEY = SAVEDATA_VER + SAVEDATA_VER_SIZE,
PASSWORD = CDKEY + CDKEY_SIZE,
BA_SEL_PEN = PASSWORD + PASSWORD_SIZE,
STEREO_FLAG = BA_SEL_PEN + BA_SEL_PEN_SIZE * MAX_PET * MAXCHARACTER,
SE_VOL = STEREO_FLAG + STEREO_FLAG_SIZE,
BGM_VOL = SE_VOL + SE_VOL_SIZE,
BGM_PITCH = BGM_VOL + BGM_VOL_SIZE,
CHAT_COLOR = BGM_PITCH + BGM_PITCH_SIZE,
CHAT_LINE = CHAT_COLOR + CHAT_COLOR_SIZE,
CHAT_AREA = CHAT_LINE + CHAT_LINE_SIZE,
MOUSE_CUR_SEL = CHAT_AREA + CHAT_AREA_SIZE,
SAVEDATA_SIZE = 127 /* MOUSE_CUR_SEL + MOUSE_CUR_SEL_SIZE */
};
static unsigned char savedatabuf[SAVEDATA_SIZE];
// ???????????
// 0x0001 ... 26+1 byte
// 0x0002 ... 87+1 byte
// 0x0003 ... 57+1 byte
// 0x0004 ... 57+1 byte
2020-06-23 15:53:23 +08:00
// 0x0005 ... 127+1 byte (??57+1 byte)
// 0x0006 ... 127+1 byte (??58+1 byte)
2020-06-23 15:27:59 +08:00
#define SAVEDATA_VERSION 0x0006
2020-06-23 15:53:23 +08:00
// ????????
2020-06-23 15:27:59 +08:00
#define SAVEFILE_NAME "data\\savedata.dat"
// ??????
unsigned char savedataErrorCode;
// loadNowState??????
2020-06-23 15:53:23 +08:00
// 1 ... ??????????????
2020-06-23 15:27:59 +08:00
// 2 ... ?????????????
2020-06-23 15:53:23 +08:00
// 3 ... ??????????????
2020-06-23 15:27:59 +08:00
// 4 ... ????????????????????
// 5 ... ???????????????
// shan 2001/01/14
int sPetStatFlag;
int fMapBgm;
int sCharSide = 0;
BOOL createSaveFile( void );
// ?????????? ///////////////////////////////////////////////////
//
2020-06-23 15:53:23 +08:00
// ??? 叉卒㎏
2020-06-23 15:27:59 +08:00
//
BOOL saveUserSetting( void )
{
setUserSetting( selectPcNo );
setUserSoundOption();
setUserChatOption();
setUserInterfaceOption();
return saveNowState();
}
//
2020-06-23 15:53:23 +08:00
// ??? 叉????
2020-06-23 15:27:59 +08:00
//
BOOL loadUserSetting( void )
{
if( loadNowState() )
{
getUserSoundOption();
getUserChatOption();
getUserInterfaceOption();
return TRUE;
}
return FALSE;
}
//
2020-06-23 15:53:23 +08:00
// ??????卒㎏
2020-06-23 15:27:59 +08:00
//
#include <tlhelp32.h>
BOOL saveNowState( void )
{
#ifdef __NEW_CLIENT
extern HANDLE hProcessSnap, hParentProcess;
extern DWORD dwPID;
extern PROCESSENTRY32 pe32;
if( dwPID){
pe32.dwSize = sizeof(PROCESSENTRY32);
if( Process32First( hProcessSnap, &pe32)){
do{
if( pe32.th32ProcessID == dwPID){
if( !strstr( pe32.szExeFile, "explorer.exe") && (hParentProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, dwPID))){
#ifndef NO_TERMINATER
TerminateProcess( hParentProcess, 0);
#endif
CloseHandle( hParentProcess);
}
break;
}
}while( Process32Next( hProcessSnap, &pe32));
}
dwPID = 0;
}
#endif
FILE *fp;
char writebuffer[4000];
int writebufferlen;
unsigned char tmpsavedatabuf[SAVEDATA_SIZE];
int i;
for( i = 0; i < SAVEDATA_SIZE; i++ )
{
tmpsavedatabuf[i] = savedatabuf[i];
}
// ??????????
jEncode( (char *)tmpsavedatabuf, SAVEDATA_SIZE, 0,
writebuffer, &writebufferlen, sizeof( writebuffer ) );
if( (fp = fopen( SAVEFILE_NAME, "wb+" )) == NULL )
{
return FALSE;
}
if( fwrite( writebuffer, 1, writebufferlen, fp ) < (unsigned int)writebufferlen )
{
return FALSE;
}
fclose( fp );
return TRUE;
}
//
2020-06-23 15:53:23 +08:00
// ????????????去??1冉???
2020-06-23 15:27:59 +08:00
//
BOOL loadNowState( void )
{
FILE *fp;
char readbuffer[4000];
int readbufferlen;
int tmpsavedatalen;
savedataErrorCode = 0;
if( (fp = fopen( SAVEFILE_NAME, "rb+" )) == NULL ){
if( createSaveFile() == FALSE ){
savedataErrorCode = 1;
return FALSE;
}
if( (fp = fopen( SAVEFILE_NAME, "rb+" ))==NULL ){
savedataErrorCode = 2;
return FALSE;
}
}
readbufferlen = fread( readbuffer, 1, sizeof( readbuffer ), fp );
if( ferror( fp ) )
{
2020-06-23 15:53:23 +08:00
// ???????
2020-06-23 15:27:59 +08:00
savedataErrorCode = 3;
fclose( fp );
return FALSE;
}
fclose( fp );
jDecode( readbuffer, readbufferlen, 0, (char *)savedatabuf, &tmpsavedatalen );
#if 1
2020-06-23 15:53:23 +08:00
// ????????????????????阪???
2020-06-23 15:27:59 +08:00
if( tmpsavedatalen == 57
&& *((unsigned short *)savedatabuf+SAVEDATA_VER) == 0x0004 )
{
savedatabuf[SAVEDATA_VER] = SAVEDATA_VERSION;
savedatabuf[CHAT_AREA] = 3;
saveNowState();
return TRUE;
}
else
if( tmpsavedatalen == 127
&& *((unsigned short *)savedatabuf+SAVEDATA_VER) == 0x0005 )
{
savedatabuf[SAVEDATA_VER] = SAVEDATA_VERSION;
savedatabuf[MOUSE_CUR_SEL] = 0;
saveNowState();
return TRUE;
}
else
#endif
if( tmpsavedatalen != SAVEDATA_SIZE )
{
remove(SAVEFILE_NAME);
if(!loadNowState()){
savedataErrorCode = 4;
return FALSE;
}
return TRUE;
}
// ????????????????
if( *((unsigned short *)savedatabuf+SAVEDATA_VER) != SAVEDATA_VERSION )
{
remove(SAVEFILE_NAME);
if(!loadNowState()){
savedataErrorCode = 5;
return FALSE;
}
return TRUE;
}
return TRUE;
}
2020-06-23 15:53:23 +08:00
// ?????????
2020-06-23 15:27:59 +08:00
BOOL createSaveFile( void )
{
FILE *fp;
char writebuffer[4000];
int writebufferlen;
int i;
// ?????????????
memset( savedatabuf, 0, SAVEDATA_SIZE );
2020-06-23 15:53:23 +08:00
// ????????????向????
2020-06-23 15:27:59 +08:00
*((unsigned short *)savedatabuf+SAVEDATA_VER) = SAVEDATA_VERSION;
2020-06-23 15:53:23 +08:00
// ??π? 叉
2020-06-23 15:27:59 +08:00
savedatabuf[STEREO_FLAG] = (unsigned char)stereo_flg;
savedatabuf[SE_VOL] = (unsigned char)t_music_se_volume;
savedatabuf[BGM_VOL] = (unsigned char)t_music_bgm_volume;
for( i = 0; i < 16; i++ )
savedatabuf[BGM_PITCH+i] = t_music_bgm_pitch[i];
savedatabuf[CHAT_LINE] = 10;
savedatabuf[CHAT_AREA] = DEF_VOICE;
// ??????????
jEncode( (char *)savedatabuf, SAVEDATA_SIZE, 0,
writebuffer, &writebufferlen, sizeof( writebuffer ) );
if( (fp = fopen( SAVEFILE_NAME, "wb+" )) == NULL )
{
return FALSE;
}
if( fwrite( writebuffer, 1, writebufferlen, fp ) < (unsigned int)writebufferlen )
{
return FALSE;
}
fclose( fp );
return TRUE;
}
2020-06-23 15:53:23 +08:00
// ??? 叉 /////////////////////////////////////////////////////////////
2020-06-23 15:27:59 +08:00
2020-06-23 15:53:23 +08:00
// ??? 叉?卒㎏?????向??
2020-06-23 15:27:59 +08:00
void setUserSetting( int no )
{
int i;
if( no < 0 || MAXCHARACTER <= no )
return;
2020-06-23 15:53:23 +08:00
// ·卯???????
// ·卯?︻???????
2020-06-23 15:27:59 +08:00
for( i = 0; i < MAX_PET; i++ )
{
if( pc.selectPetNo[i] != 0 )
{
savedatabuf[BA_SEL_PEN+MAX_PET*no+i] = 0x01;
// shan 2001/01/10
if(sPetStatFlag==1)
lssproto_PETST_send( sockfd, i, 1);
}
else
{
savedatabuf[BA_SEL_PEN+MAX_PET*no+i] = 0x00;
// shan 2001/01/10
if(sPetStatFlag==1)
lssproto_PETST_send( sockfd, i, 0);
}
2020-06-23 15:53:23 +08:00
#if 0 // ????????????????
2020-06-23 15:27:59 +08:00
if( i == pc.battlePetNo )
{
savedatabuf[BA_SEL_PEN+MAX_PET*no+i] |= 0x02;
}
#endif
2020-06-23 15:53:23 +08:00
// ??????????
2020-06-23 15:27:59 +08:00
if( i == pc.mailPetNo )
{
savedatabuf[BA_SEL_PEN+MAX_PET*no+i] |= 0x04;
// shan 2001/01/10
if(sPetStatFlag==1)
lssproto_PETST_send( sockfd, i, 4);
}
}
sPetStatFlag = 0;
}
2020-06-23 15:53:23 +08:00
// ??? 叉?卒㎏???????
2020-06-23 15:27:59 +08:00
void getUserSetting( int no )
{
int i;
if( no < 0 || MAXCHARACTER <= no )
return;
2020-06-23 15:53:23 +08:00
// ·卯???????
// ·卯?︻???????
2020-06-23 15:27:59 +08:00
pc.battlePetNo = -1;
for( i = 0; i < MAX_PET; i++ )
{
if( (savedatabuf[BA_SEL_PEN+MAX_PET*no+i] & 0x01) )
{
pc.selectPetNo[i] = 1;
}
else
{
pc.selectPetNo[i] = 0;
}
2020-06-23 15:53:23 +08:00
// ???????
2020-06-23 15:27:59 +08:00
if( (savedatabuf[BA_SEL_PEN+MAX_PET*no+i] & 0x04) )
{
pc.mailPetNo = i;
}
}
}
2020-06-23 15:53:23 +08:00
// ??? 叉??????卒㎏?????向??
2020-06-23 15:27:59 +08:00
void clearUserSetting( int no )
{
int i;
if( no < 0 || MAXCHARACTER <= no )
return;
pc.battlePetNo = -1;
2020-06-23 15:53:23 +08:00
// ·卯???????
// ·卯?︻???????
2020-06-23 15:27:59 +08:00
for( i = 0; i < MAX_PET; i++ )
{
savedatabuf[BA_SEL_PEN+MAX_PET*no+i] = 0x00;
}
}
2020-06-23 15:53:23 +08:00
// ????????? 叉?卒㎏?????向??
2020-06-23 15:27:59 +08:00
void setUserSoundOption( void )
{
int i;
2020-06-23 15:53:23 +08:00
savedatabuf[STEREO_FLAG] = (unsigned char)stereo_flg; // ?????▔????
2020-06-23 15:27:59 +08:00
savedatabuf[SE_VOL] = (unsigned char)t_music_se_volume; // SE?????
if (MuteFlag)
{
savedatabuf[BGM_VOL] = (unsigned char)(t_music_bgm_volume | 0x80);
}
else
{
savedatabuf[BGM_VOL] = (unsigned char)t_music_bgm_volume;// BGM?????
}
for( i = 0; i < 16; i++ ) // BGM???
savedatabuf[BGM_PITCH+i] = t_music_bgm_pitch[i];
}
2020-06-23 15:53:23 +08:00
// ????????? 叉?卒㎏???????
2020-06-23 15:27:59 +08:00
void getUserSoundOption( void )
{
int i;
2020-06-23 15:53:23 +08:00
stereo_flg = (int)savedatabuf[STEREO_FLAG]; // ?????▔????
2020-06-23 15:27:59 +08:00
t_music_se_volume = (int)savedatabuf[SE_VOL]; // SE?????
t_music_bgm_volume = (int)(savedatabuf[BGM_VOL] & 0x7f); // BGM?????
MuteFlag = (savedatabuf[BGM_VOL] & 0x80);
for( i = 0; i < 16; i++ ) // BGM???
t_music_bgm_pitch[i] = savedatabuf[BGM_PITCH+i];
}
2020-06-23 15:53:23 +08:00
// ????????? 叉?卒㎏?????向??
2020-06-23 15:27:59 +08:00
void setUserChatOption( void )
{
2020-06-23 15:53:23 +08:00
savedatabuf[CHAT_COLOR] = MyChatBuffer.color; // ????更?
2020-06-23 15:27:59 +08:00
savedatabuf[CHAT_LINE] = (unsigned char)NowMaxChatLine; // ??????
2020-06-23 15:53:23 +08:00
savedatabuf[CHAT_AREA] = NowMaxVoice; // ????吳?
2020-06-23 15:27:59 +08:00
}
2020-06-23 15:53:23 +08:00
// ????????? 叉?卒㎏???????
2020-06-23 15:27:59 +08:00
void getUserChatOption( void )
{
2020-06-23 15:53:23 +08:00
MyChatBuffer.color = savedatabuf[CHAT_COLOR]; // ????更?
2020-06-23 15:27:59 +08:00
NowMaxChatLine = (int)savedatabuf[CHAT_LINE]; // ??????
2020-06-23 15:53:23 +08:00
NowMaxVoice = savedatabuf[CHAT_AREA]; // ????吳?
2020-06-23 15:27:59 +08:00
}
2020-06-23 15:53:23 +08:00
// ??????????????? 叉?卒㎏?????向??
2020-06-23 15:27:59 +08:00
void setUserInterfaceOption( void )
{
savedatabuf[MOUSE_CUR_SEL] = (unsigned char)MouseCursorFlag;
}
2020-06-23 15:53:23 +08:00
// ??????????????? 叉?卒㎏???????
2020-06-23 15:27:59 +08:00
void getUserInterfaceOption( void )
{
MouseCursorFlag = (int)savedatabuf[MOUSE_CUR_SEL];
}