Debian Codegraph @

Descent3/d3serial.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/main/d3serial.cpp $
21 * $Revision: 15 $
22 * $Date: 5/13/99 11:18a $
23 * $Author: Matt $
24 *
25 * Functions to check the copy of the executable for expiration, registered name
26 *
27 * $Log: /DescentIII/main/d3serial.cpp $
28 *
29 * 15 5/13/99 11:18a Matt
30 * Added some text.
31 *
32 * 14 4/16/99 11:59a Matt
33 * Took out include of io.h, because it wasn't needed.
34 *
35 * 13 4/16/99 12:39a Matt
36 * Took out Linux ifdef around include of io.h, since it's a system header
37 * file and there's no harm in including it in the Windows version.
38 *
39 * 12 4/15/99 1:38a Jeff
40 * changes for linux compile
41 *
42 * 11 4/14/99 2:50a Jeff
43 * fixed some case mismatched #includes
44 *
45 * 10 2/17/99 3:06p Matt
46 * Updated copyrights.
47 *
48 * 9 10/18/98 9:12p Matt
49 * Use new symbolic constant for the program name.
50 *
51 * 8 10/13/98 2:30p Jeff
52 * changed serialization msg for demo
53 *
54 * 7 10/11/98 2:58a Jeff
55 * fixed serialization code
56 *
57 * 6 7/13/98 12:41p Jeff
58 * added serial number support
59 *
60 * 5 6/08/98 3:16p Matt
61 * Mucked with formatting & content of serialization message.
62 *
63 * 4 6/04/98 11:32a Jeff
64 * Better 'warning' box for the serialization
65 *
66 * 3 2/10/98 10:43a Jeff
67 * fixed it so a nonregistered version will run (to make development
68 * easier)
69 *
70 * 2 2/07/98 6:33p Jeff
71 * Initial Creation (Based on D2 serialization)
72 *
73 * $NoKeywords: $
74 */
75
76 #include <stdlib.h>
77 #include <string.h>
78 #include <stdio.h>
79
80 #include "d3serial.h"
81 #include "game.h"
82 #include "debug.h"
83 #include "descent.h"
84 #include <time.h>
85 #include "mono.h"
86 #include "cfile.h"
87 #include "program.h"
88
89 #include <fcntl.h>
90
91 #define SERIAL_NO_ERR 0
92 #define SERIAL_EXPIRED 1
93 #define SERIAL_BAD_CHECKSUM 2
94 #define SERIAL_UNREGISTERED 3
95
96 static char name_copy[DESC_ID_LEN];
97
98 static uint32_t d3_serialnum = 100000;
99
100 // checks the exectuable (serialization)
101 int SerialCheck(void) {
102 char name2[] = DESC_ID_TAG "0000000000000000000000000000000000000000";
103 char time_str[] = DESC_DEAD_TIME_TAG "00000000";
104 int i, found;
105 uint32_t *checksum, test_checksum;
106 uint32_t *serialnum;
107 time_t current_time, saved_time;
108
109 #ifdef DEMO
110 char regstr[] = "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! NOTICE "
111 "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
112 "\nThis Descent 3 Demo %s has been specially prepared for\n"
113 "\n"
114 "\t\t%s (Serial Num: %d)\n"
115 "\n"
116 " and is the Confidential Property of Outrage Entertainment, Inc.\n"
117 "\n"
118 "\n"
119 "\t\tDISTRIBUTION IS PROHIBITED\n"
120 "\n"
121 "\n"
122 " Descent 3 is Copyright (c) 1998,1999 Outrage Entertainment, Inc.\n"
123 "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
124 "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
125 #else
126 char regstr[] = "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! NOTICE "
127 "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
128 "\nThis pre-release version of Descent 3 has been specially prepared for\n"
129 "\n"
130 "\t\t%s (Serial Num: %d)\n"
131 "\n"
132 " and is the Confidential Property of Outrage Entertainment, Inc.\n"
133 "\n"
134 "\n"
135 "\t\tDISTRIBUTION IS PROHIBITED\n"
136 "\n"
137 "This version of Descent 3 should be used for evaluation and testing only.\n"
138 "Because the game is not yet complete, items may be missing the bugs may be\n"
139 "encountered.\n"
140 "\n"
141 " Descent 3 is Copyright (c) 1998,1999 Outrage Entertainment, Inc.\n"
142 "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
143 "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
144 #endif
145
146 // get the expiration time of the executable
147 char *start_time = &time_str[DESC_DEAD_TIME_TAG_LEN];
148 saved_time = (time_t)strtol(start_time, NULL, 16);
149 if (saved_time == (time_t)0)
150 // this guy has never been registered with the serialization program
151 return SERIAL_NO_ERR;
152
153 // adjust pointer, so it points to the registered name
154 char *name = name2 + DESC_ID_TAG_LEN;
155
156 // save for later use
157 strcpy(name_copy, name);
158
159 // get current date from the system
160 current_time = time(NULL);
161
162 // check to see if executable has expired
163 if (current_time >= saved_time) {
164 return SERIAL_EXPIRED;
165 }
166
167 // check the checksum created by the registered name
168 test_checksum = 0;
169 for (i = 0; i < (signed)strlen(name); i++) {
170 found = 0;
171 test_checksum += name[i];
172 if (((test_checksum / 2) * 2) != test_checksum)
173 found = 1;
174 test_checksum = test_checksum >> 1;
175 if (found)
176 test_checksum |= 0x80000000;
177 }
178 static char desc_id_checksum_str[] = DESC_CHKSUM_TAG "0000"; // 4-byte checksum
179 char *checksum_ptr = desc_id_checksum_str + DESC_CHKSUM_TAG_LEN;
180
181 // compare generated checksum with that in the executable
182 checksum = (uint32_t *)&(checksum_ptr[0]);
183 if (test_checksum != *checksum) {
184 return SERIAL_BAD_CHECKSUM;
185 }
186
187 static char desc_id_serialnum_str[] = DESC_SERIALNUM_TAG "0000"; // 4-byte serialnum
188 char *serialnum_ptr = desc_id_serialnum_str + DESC_SERIALNUM_TAG_LEN;
189
190 serialnum = (uint32_t *)&(serialnum_ptr[0]);
191 d3_serialnum = *serialnum;
192
193 // this guy is ok, we can exit clean now
194 char buffer[400];
195
196 #ifdef DEMO
197 char ver[10];
198 snprintf(ver, sizeof(ver), "Beta %d.%d.%d", D3_MAJORVER, D3_MINORVER, D3_BUILD);
199 snprintf(buffer, sizeof(buffer), regstr, ver, name, d3_serialnum);
200 #else
201 snprintf(buffer, sizeof(buffer), regstr, name, d3_serialnum);
202 #endif
203
204 Debug_MessageBox(OSMBOX_OK, PRODUCT_NAME, buffer);
205
206 return SERIAL_NO_ERR;
207 }
208
209 // displays an error box displaying what went wrong with serialization checking
210 void SerialError(int error) {
211 switch (error) {
212 case SERIAL_EXPIRED: {
213 Debug_MessageBox(OSMBOX_OK, PRODUCT_NAME, "Executable has expired");
214 break;
215 }
216 case SERIAL_BAD_CHECKSUM: {
217 Debug_MessageBox(OSMBOX_OK, PRODUCT_NAME, "Bad Checksum");
218 break;
219 }
220 case SERIAL_UNREGISTERED: {
221 Debug_MessageBox(OSMBOX_OK, PRODUCT_NAME, "This is unregistered, please serialize");
222 break;
223 }
224 }
225 }
226
227 uint32_t SerialGetSerialNum(void) { return d3_serialnum; }