| 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"cxx . . $ `<file>/Descent3/d3serial.h`/ |
| 81 | #include "game.h"cxx . . $ `<file>/Descent3/game.h`/ |
| 82 | #include "debug.h"cxx . . $ `<file>/ddebug/debug.h`/ |
| 83 | #include "descent.h"cxx . . $ `<file>/Descent3/descent.h`/ |
| 84 | #include <time.h> |
| 85 | #include "mono.h"cxx . . $ `<file>/ddebug/mono.h`/ |
| 86 | #include "cfile.h"cxx . . $ `<file>/cfile/cfile.h`/ |
| 87 | #include "program.h"cxx . . $ `<file>/Descent3/program.h`/ |
| 88 | |
| 89 | #include <fcntl.h> |
| 90 | |
| 91 | #define SERIAL_NO_ERRcxx . . $ `Descent3/d3serial.cpp:91:9`! 0 |
| 92 | #define SERIAL_EXPIREDcxx . . $ `Descent3/d3serial.cpp:92:9`! 1 |
| 93 | #define SERIAL_BAD_CHECKSUMcxx . . $ `Descent3/d3serial.cpp:93:9`! 2 |
| 94 | #define SERIAL_UNREGISTEREDcxx . . $ `Descent3/d3serial.cpp:94:9`! 3 |
| 95 | |
| 96 | static char name_copycxx . . $ name_copy.[DESC_ID_LENcxx . . $ `Descent3/d3serial.h:48:9`!]; |
| 97 | |
| 98 | static uint32_tcxx . . $ uint32_t# d3_serialnumcxx . . $ d3_serialnum. = 100000; |
| 99 | |
| 100 | // checks the exectuable (serialization) |
| 101 | int SerialCheckcxx . . $ SerialCheck(b126dc7c1de90089).(void) { |
| 102 | char name2[] = DESC_ID_TAGcxx . . $ `Descent3/d3serial.h:53:9`! "0000000000000000000000000000000000000000"; |
| 103 | char time_str[] = DESC_DEAD_TIME_TAGcxx . . $ `Descent3/d3serial.h:62:9`! "00000000"; |
| 104 | int i, found; |
| 105 | uint32_tcxx . . $ uint32_t# *checksum, test_checksum; |
| 106 | uint32_tcxx . . $ 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_LENcxx . . $ `Descent3/d3serial.h:63:9`!]; |
| 148 | saved_time = (time_t)strtolcxx . . $ strtol(8cc4c7acb13e570c).(start_time, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, 16); |
| 149 | if (saved_time == (time_t)0) |
| 150 | // this guy has never been registered with the serialization program |
| 151 | return SERIAL_NO_ERRcxx . . $ `Descent3/d3serial.cpp:91:9`!; |
| 152 | |
| 153 | // adjust pointer, so it points to the registered name |
| 154 | char *name = name2 + DESC_ID_TAG_LENcxx . . $ `Descent3/d3serial.h:54:9`!; |
| 155 | |
| 156 | // save for later use |
| 157 | strcpy(name_copycxx . . $ name_copy., name); |
| 158 | |
| 159 | // get current date from the system |
| 160 | current_time = time(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!); |
| 161 | |
| 162 | // check to see if executable has expired |
| 163 | if (current_time >= saved_time) { |
| 164 | return SERIAL_EXPIREDcxx . . $ `Descent3/d3serial.cpp:92:9`!; |
| 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_TAGcxx . . $ `Descent3/d3serial.h:56:9`! "0000"; // 4-byte checksum |
| 179 | char *checksum_ptr = desc_id_checksum_str + DESC_CHKSUM_TAG_LENcxx . . $ `Descent3/d3serial.h:57:9`!; |
| 180 | |
| 181 | // compare generated checksum with that in the executable |
| 182 | checksum = (uint32_tcxx . . $ uint32_t# *)&(checksum_ptr[0]); |
| 183 | if (test_checksum != *checksum) { |
| 184 | return SERIAL_BAD_CHECKSUMcxx . . $ `Descent3/d3serial.cpp:93:9`!; |
| 185 | } |
| 186 | |
| 187 | static char desc_id_serialnum_str[] = DESC_SERIALNUM_TAGcxx . . $ `Descent3/d3serial.h:59:9`! "0000"; // 4-byte serialnum |
| 188 | char *serialnum_ptr = desc_id_serialnum_str + DESC_SERIALNUM_TAG_LENcxx . . $ `Descent3/d3serial.h:60:9`!; |
| 189 | |
| 190 | serialnum = (uint32_tcxx . . $ uint32_t# *)&(serialnum_ptr[0]); |
| 191 | d3_serialnumcxx . . $ 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_serialnumcxx . . $ d3_serialnum.); |
| 202 | #endif |
| 203 | |
| 204 | Debug_MessageBoxcxx . . $ Debug_MessageBox(9ee5302023219b2d).(OSMBOX_OKcxx . . $ OSMBOX_OK., PRODUCT_NAMEcxx . . $ `Descent3/descent.h:140:9`!, buffer); |
| 205 | |
| 206 | return SERIAL_NO_ERRcxx . . $ `Descent3/d3serial.cpp:91:9`!; |
| 207 | } |
| 208 | |
| 209 | // displays an error box displaying what went wrong with serialization checking |
| 210 | void SerialErrorcxx . . $ SerialError(d4f767463ce0a6b3).(int error) { |
| 211 | switch (error) { |
| 212 | case SERIAL_EXPIREDcxx . . $ `Descent3/d3serial.cpp:92:9`!: { |
| 213 | Debug_MessageBoxcxx . . $ Debug_MessageBox(9ee5302023219b2d).(OSMBOX_OKcxx . . $ OSMBOX_OK., PRODUCT_NAMEcxx . . $ `Descent3/descent.h:140:9`!, "Executable has expired"); |
| 214 | break; |
| 215 | } |
| 216 | case SERIAL_BAD_CHECKSUMcxx . . $ `Descent3/d3serial.cpp:93:9`!: { |
| 217 | Debug_MessageBoxcxx . . $ Debug_MessageBox(9ee5302023219b2d).(OSMBOX_OKcxx . . $ OSMBOX_OK., PRODUCT_NAMEcxx . . $ `Descent3/descent.h:140:9`!, "Bad Checksum"); |
| 218 | break; |
| 219 | } |
| 220 | case SERIAL_UNREGISTEREDcxx . . $ `Descent3/d3serial.cpp:94:9`!: { |
| 221 | Debug_MessageBoxcxx . . $ Debug_MessageBox(9ee5302023219b2d).(OSMBOX_OKcxx . . $ OSMBOX_OK., PRODUCT_NAMEcxx . . $ `Descent3/descent.h:140:9`!, "This is unregistered, please serialize"); |
| 222 | break; |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | uint32_tcxx . . $ uint32_t# SerialGetSerialNumcxx . . $ SerialGetSerialNum(db52760e79bf9054).(void) { return d3_serialnumcxx . . $ d3_serialnum.; } |