#include "StdAfx.h" #define ATOI_KLUDGE #include "GlobalFunc.h" #include "T2Archive.h" #include "T2GlobalData.h" #include "T2MovieParamArray.h" #include "T2SerialDialog.h" T2GlobalData::T2GlobalData() { mChanged = false; m1stCinemaDate = 0; mMovieParamArray = NULL; for (int i = 0; i < 20; i++) mSerial[i] = 0; T2Archive file; CString filename = GetTowerDirectory() + "T2Pref.dat"; if (file.OpenAsReadMode(filename)) { Read(file); file.Close(); } else { T2SerialDialog *theSerialDialog = new T2SerialDialog(NULL); if (theSerialDialog->DoModal() == 1) { theSerialDialog->GetSerial(mSerial); if (IsCheckSerial()) { file.OpenAsWriteMode(filename); Write(file); file.Close(); } } delete theSerialDialog; } } /*virtual*/ T2GlobalData::~T2GlobalData() { if (mChanged) { T2Archive file; CString filename = GetTowerDirectory() + "T2Pref.dat"; file.OpenAsWriteMode(filename); Write(file); file.Close(); } } void T2GlobalData::Set1stCinemaDate(int inDate) { if (m1stCinemaDate == 0) { m1stCinemaDate = inDate; mChanged = true; } } void T2GlobalData::RegistMovie(DWORD inCode, int inValue) { if (!mMovieParamArray) { mMovieParamArray = new T2MovieParamArray; mChanged = true; } if (mMovieParamArray->Regist(inCode, inValue)) mChanged = true; } int T2GlobalData::GetMovieParam(DWORD inCode) { if (!mMovieParamArray) return 0; return mMovieParamArray->GetParam(inCode); } void T2GlobalData::Read(T2Archive& inArchive) { for (int i = 0; i < 20; i++) inArchive >> mSerial[i]; inArchive >> m1stCinemaDate; mMovieParamArray = T2MovieParamArray::ReadMovieParamArray(inArchive); } void T2GlobalData::Write(T2Archive& inArchive) { for (int i = 0; i < 20; i++) inArchive << mSerial[i]; inArchive << m1stCinemaDate; T2MovieParamArray::WriteMovieParamArray(mMovieParamArray, inArchive); } BOOL T2GlobalData::IsCheckSerial() { return Check_Serial(mSerial); } BOOL T2GlobalData::Check_Serial(char* inSerial) { unsigned short array[256]; array[0] = 0; array[1] = 0x1189; array[2] = 0x2312; array[3] = 0x329b; array[4] = 0x4624; array[5] = 0x57ad; array[6] = 0x6536; array[7] = 0x74bf; array[8] = 0x8c48; array[9] = 0x9dc1; array[10] = 0xaf5a; array[11] = 0xbed3; array[12] = 0xca6c; array[13] = 0xdbe5; array[14] = 0xe97e; array[15] = 0xf8f7; array[16] = 0x1081; array[17] = 0x0108; array[18] = 0x3393; array[19] = 0x221a; array[20] = 0x56a5; array[21] = 0x472c; array[22] = 0x75b7; array[23] = 0x643e; array[24] = 0x9cc9; array[25] = 0x8d40; array[26] = 0xbfdb; array[27] = 0xae52; array[28] = 0xdaed; array[29] = 0xcb64; array[30] = 0xf9ff; array[31] = 0xe876; array[32] = 0x2102; array[33] = 0x308b; array[34] = 0x0210; array[35] = 0x1399; array[36] = 0x6726; array[37] = 0x76af; array[38] = 0x4434; array[39] = 0x55bd; array[40] = 0xad4a; array[41] = 0xbcc3; array[42] = 0x8e58; array[43] = 0x9fd1; array[44] = 0xeb6e; array[45] = 0xfae7; array[46] = 0xc87c; array[47] = 0xd9f5; array[48] = 0x3183; array[49] = 0x200a; array[50] = 0x1291; array[51] = 0x0318; array[52] = 0x77a7; array[53] = 0x662e; array[54] = 0x54b5; array[55] = 0x453c; array[56] = 0xbdcb; array[57] = 0xac42; array[58] = 0x9ed9; array[59] = 0x8f50; array[60] = 0xfbef; array[61] = 0xea66; array[62] = 0xd8fd; array[63] = 0xc974; array[64] = 0x4204; array[65] = 0x538d; array[66] = 0x6116; array[67] = 0x709f; array[68] = 0x0420; array[69] = 0x15a9; array[70] = 0x2732; array[71] = 0x36bb; array[72] = 0xce4c; array[73] = 0xdfc5; array[74] = 0xed5e; array[75] = 0xfcd7; array[76] = 0x8868; array[77] = 0x99e1; array[78] = 0xab7a; array[79] = 0xbaf3; array[80] = 0x5285; array[81] = 0x430c; array[82] = 0x7197; array[83] = 0x601e; array[84] = 0x14a1; array[85] = 0x0528; array[86] = 0x37b3; array[87] = 0x263a; array[88] = 0xdecd; array[89] = 0xcf44; array[90] = 0xfddf; array[91] = 0xec56; array[92] = 0x98e9; array[93] = 0x8960; array[94] = 0xbbfb; array[95] = 0xaa72; array[96] = 0x6306; array[97] = 0x728f; array[98] = 0x4014; array[99] = 0x519d; array[100] = 0x2522; array[101] = 0x34ab; array[102] = 0x0630; array[103] = 0x17b9; array[104] = 0xef4e; array[105] = 0xfec7; array[106] = 0xcc5c; array[107] = 0xddd5; array[108] = 0xa96a; array[109] = 0xb8e3; array[110] = 0x8a78; array[111] = 0x9bf1; array[112] = 0x7387; array[113] = 0x620e; array[114] = 0x5095; array[115] = 0x411c; array[116] = 0x35a3; array[117] = 0x242a; array[118] = 0x16b1; array[119] = 0x0738; array[120] = 0xffcf; array[121] = 0xee46; array[122] = 0xdcdd; array[123] = 0xcd54; array[124] = 0xb9eb; array[125] = 0xa862; array[126] = 0x9af9; array[127] = 0x8b70; array[128] = 0x8408; array[129] = 0x9581; array[130] = 0xa71a; array[131] = 0xb693; array[132] = 0xc22c; array[133] = 0xd3a5; array[134] = 0xe13e; array[135] = 0xf0b7; array[136] = 0x0840; array[137] = 0x19c9; array[138] = 0x2b52; array[139] = 0x3adb; array[140] = 0x4e64; array[141] = 0x5fed; array[142] = 0x6d76; array[143] = 0x7cff; array[144] = 0x9489; array[145] = 0x8500; array[146] = 0xb79b; array[147] = 0xa612; array[148] = 0xd2ad; array[149] = 0xc324; array[150] = 0xf1bf; array[151] = 0xe036; array[152] = 0x18c1; array[153] = 0x0948; array[154] = 0x3bd3; array[155] = 0x2a5a; array[156] = 0x5ee5; array[157] = 0x4f6c; array[158] = 0x7df7; array[159] = 0x6c7e; array[160] = 0xa50a; array[161] = 0xb483; array[162] = 0x8618; array[163] = 0x9791; array[164] = 0xe32e; array[165] = 0xf2a7; array[166] = 0xc03c; array[167] = 0xd1b5; array[168] = 0x2942; array[169] = 0x38cb; array[170] = 0x0a50; array[171] = 0x1bd9; array[172] = 0x6f66; array[173] = 0x7eef; array[174] = 0x4c74; array[175] = 0x5dfd; array[176] = 0xb58b; array[177] = 0xa402; array[178] = 0x9699; array[179] = 0x8710; array[180] = 0xf3af; array[181] = 0xe226; array[182] = 0xd0bd; array[183] = 0xc134; array[184] = 0x39c3; array[185] = 0x284a; array[186] = 0x1ad1; array[187] = 0x0b58; array[188] = 0x7fe7; array[189] = 0x6e6e; array[190] = 0x5cf5; array[191] = 0x4d7c; array[192] = 0xc60c; array[193] = 0xd785; array[194] = 0xe51e; array[195] = 0xf497; array[196] = 0x8028; array[197] = 0x91a1; array[198] = 0xa33a; array[199] = 0xb2b3; array[200] = 0x4a44; array[201] = 0x5bcd; array[202] = 0x6956; array[203] = 0x78df; array[204] = 0x0c60; array[205] = 0x1de9; array[206] = 0x2f72; array[207] = 0x3efb; array[208] = 0xd68d; array[209] = 0xc704; array[210] = 0xf59f; array[211] = 0xe416; array[212] = 0x90a9; array[213] = 0x8120; array[214] = 0xb3bb; array[215] = 0xa232; array[216] = 0x5ac5; array[217] = 0x4b4c; array[218] = 0x79d7; array[219] = 0x685e; array[220] = 0x1ce1; array[221] = 0x0d68; array[222] = 0x3ff3; array[223] = 0x2e7a; array[224] = 0xe70e; array[225] = 0xf687; array[226] = 0xc41c; array[227] = 0xd595; array[228] = 0xa12a; array[229] = 0xb0a3; array[230] = 0x8238; array[231] = 0x93b1; array[232] = 0x6b46; array[233] = 0x7acf; array[234] = 0x4854; array[235] = 0x59dd; array[236] = 0x2d62; array[237] = 0x3ceb; array[238] = 0x0e70; array[239] = 0x1ff9; array[240] = 0xf78f; array[241] = 0xe606; array[242] = 0xd49d; array[243] = 0xc514; array[244] = 0xb1ab; array[245] = 0xa022; array[246] = 0x92b9; array[247] = 0x8330; array[248] = 0x7bc7; array[249] = 0x6a4e; array[250] = 0x58d5; array[251] = 0x495c; array[252] = 0x3de3; array[253] = 0x2c6a; array[254] = 0x1ef1; array[255] = 0x0f78; BOOL isValid = false; char *serial = inSerial; if (strlen(serial) != 16) return false; if (memcmp(serial, "1320", 4) != 0) return false; int i = strlen(serial) - 4; unsigned short work = 0xFFFF; while (--i >= 0) { work = (work >> 8) ^ array[((unsigned char) work & 0xFF) ^ *inSerial]; inSerial++; } if (((work ^ 0xFFFF) % 10000) == atoi(&serial[12])) isValid = true; else isValid = false; return isValid; }