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