Mercurial > codedump
annotate win95kggui/src/win95kggui.c @ 123:9ebe8785cc21
Add systemd service for kmbscreens bot
committer: GitHub <noreply@github.com>
author | Paper <37962225+mrpapersonic@users.noreply.github.com> |
---|---|
date | Sun, 23 Apr 2023 16:29:48 -0400 |
parents | 677f84ada082 |
children |
rev | line source |
---|---|
64 | 1 /** |
2 * Windows 95 Keygen (Windows GUI ver.) | |
3 * Copyright (c) Paper 2022 | |
4 * | |
5 * Permission is hereby granted, free of charge, to any person obtaining a copy | |
6 * of this software and associated documentation files (the "Software"), to deal | |
7 * in the Software without restriction, including without limitation the rights | |
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
9 * copies of the Software, and to permit persons to whom the Software is | |
10 * furnished to do so, subject to the following conditions: | |
11 * | |
12 * The above copyright notice and this permission notice shall be included in all | |
13 * copies or substantial portions of the Software. | |
14 * | |
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
21 * SOFTWARE. | |
22 **/ | |
23 #include <stdio.h> | |
24 #include <windows.h> | |
25 #include <stdint.h> | |
26 #include <stdbool.h> | |
27 #include <commdlg.h> | |
28 #include <math.h> | |
29 #include <time.h> | |
75 | 30 #include "../sub/ft2play/pmplay.h" |
64 | 31 #include <resource.h> |
75 | 32 #include "bergsm.h" |
33 #ifndef WIN32_LEAN_AND_MEAN | |
34 #define WIN32_LEAN_AND_MEAN | |
35 #endif | |
64 | 36 #define _WIN32_WINNT 0x0400 |
37 #define ARRAYSIZE(a) \ | |
38 sizeof(a)/sizeof(a[0]) | |
39 #define CONCAT_INTS(x, y) \ | |
40 x * pow(10, log10(y)+1) + y | |
41 #ifdef _MSC_VER | |
42 #define strdup(p) _strdup(p) | |
43 #endif | |
44 #define GENERATE_KEY 1 | |
45 #define LISTBOX 2 | |
46 #define KEY 3 | |
47 int type; | |
48 HWND hWndListBox, key_box; | |
49 | |
50 int get_sum(int n) { | |
51 int sum; | |
52 for (sum = 0; n > 0; sum += n % 10, n /= 10); // copied this from google. sorry not sorry | |
53 return sum; | |
54 } | |
55 | |
56 int win95_nt4_prefix() { | |
57 int num = rand() % 999; | |
58 while ((num == 333) || (num == 444) || (num == 555) || (num == 666) || (num == 777) || (num == 888) || (num == 999)) { | |
59 num = num + 1; | |
60 } | |
61 return num; | |
62 } | |
63 | |
64 int win95_suffix(bool is_oem) { | |
111
677f84ada082
Update win95kggui.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
75
diff
changeset
|
65 int first_digits, last_digit, second_segment; |
677f84ada082
Update win95kggui.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
75
diff
changeset
|
66 do { |
64 | 67 if (is_oem == false) { |
68 first_digits = rand() % 999999; | |
69 } else { | |
70 first_digits = rand() % 9999; | |
71 } | |
72 last_digit = rand() % 9; | |
73 while ((last_digit == 0) || (last_digit >= 8)) { | |
74 last_digit = rand() % 9; | |
75 } | |
76 second_segment = CONCAT_INTS(first_digits, last_digit); | |
111
677f84ada082
Update win95kggui.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
75
diff
changeset
|
77 } while (get_sum(second_segment) % 7 != 0); |
64 | 78 return second_segment; |
79 } | |
80 | |
81 int office_prefix() { | |
111
677f84ada082
Update win95kggui.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
75
diff
changeset
|
82 int new_site, ez_pwned; |
677f84ada082
Update win95kggui.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
75
diff
changeset
|
83 do { |
64 | 84 new_site = rand() % 99; |
85 ez_pwned = (new_site % 10) + 2; | |
86 if (ez_pwned >= 10) { | |
87 ez_pwned -= 10; | |
88 } | |
111
677f84ada082
Update win95kggui.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
75
diff
changeset
|
89 } while (CONCAT_INTS(new_site, ez_pwned) == 0); |
64 | 90 return CONCAT_INTS(new_site, ez_pwned); |
91 } | |
92 | |
93 int oem_prefix() { | |
94 const char* years[] = { | |
95 "95", | |
96 "96", | |
97 "97", | |
98 "98", | |
99 "99", | |
100 "00", | |
101 "01", | |
102 "02", | |
103 "03" | |
104 }; | |
105 char buf[6]; | |
106 sprintf(buf, "%03d", (rand() % 366) + 1); | |
107 strcat(buf, years[rand() % 9]); | |
108 int buf2 = atoi(buf); | |
109 return buf2; | |
110 } | |
111 | |
112 void AddControls(HWND hWnd) { | |
113 int i = 0; | |
114 /* Open File */ | |
115 HWND gen_button = CreateWindowA("Button", "Generate Key", WS_VISIBLE | WS_CHILD, (int)((225 - 100)/2), 5, 100, 20, hWnd, (HMENU)GENERATE_KEY, NULL, NULL); | |
116 /* Type */ | |
117 TCHAR listbox_items[][22] = {"Windows 95 / NT 4 RTM", "Windows 95 OEM", "Office 97"}; | |
118 hWndListBox = CreateWindowA("Listbox", NULL, WS_VISIBLE | WS_CHILD | LBS_STANDARD | LBS_NOTIFY, (int)((225 - 150)/2), 30, 150, 60, hWnd, (HMENU)LISTBOX, NULL, NULL); | |
119 for (i = 0; i < ARRAYSIZE(listbox_items); i++) { | |
120 int pos = (int)SendMessage(hWndListBox, LB_ADDSTRING, i, (LPARAM) listbox_items[i]); | |
121 SendMessage(hWndListBox, LB_SETITEMDATA, pos, (LPARAM) i); | |
122 } | |
123 SendMessage(hWndListBox, LB_SETCURSEL, (WPARAM)0, (LPARAM)0); | |
124 // idk | |
125 key_box = CreateWindowA("Edit", "", WS_VISIBLE | WS_CHILD | WS_BORDER | ES_READONLY | ES_CENTER | ES_MULTILINE | SS_CENTER, (int)((225 - 150)/2), 100, 150, 40, hWnd, (HMENU)KEY, NULL, NULL); | |
126 if (gen_button == NULL || hWndListBox == NULL || key_box == NULL) | |
127 MessageBoxA(hWnd, "how did you even trigger this", "GUI could not be initialized!", MB_ICONEXCLAMATION); | |
128 } | |
129 | |
130 bool CALLBACK SetFont(HWND child, LPARAM font) { | |
131 SendMessage(child, WM_SETFONT, font, true); | |
132 return true; | |
133 } | |
134 | |
135 LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { | |
136 switch(msg) { | |
137 case WM_COMMAND: | |
138 if(HIWORD(wParam) == CBN_SELCHANGE) { | |
139 if (LOWORD(wParam) == LISTBOX) | |
140 type = SendMessageA((HWND) lParam, (UINT) LB_GETCURSEL, (WPARAM) 0, (LPARAM) 0); | |
141 } | |
142 switch(wParam) { | |
143 case GENERATE_KEY: { | |
144 char* p = calloc(24, sizeof(char)); | |
145 switch(type) { | |
146 case 0: | |
147 snprintf(p, 24, "%04d-%07d", office_prefix(), win95_suffix(false)); | |
148 SendMessageA(key_box, WM_SETTEXT, (WPARAM)0, (LPARAM)p); | |
149 break; | |
150 case 2: | |
151 snprintf(p, 24, "%05d-OEM-%07d-%05d", oem_prefix(), win95_suffix(true), (rand() % 100000)); | |
152 SendMessageA(key_box, WM_SETTEXT, (WPARAM)0, (LPARAM)p); | |
153 break; | |
154 case 1: | |
155 snprintf(p, 24, "%03d-%07d", win95_nt4_prefix(), win95_suffix(false)); | |
156 SendMessageA(key_box, WM_SETTEXT, (WPARAM)0, (LPARAM)p); | |
157 break; | |
158 } | |
159 } | |
160 case LISTBOX: | |
161 break; | |
162 case KEY: | |
163 break; | |
164 } | |
165 break; | |
166 case WM_CREATE: { | |
75 | 167 /* freq, buf, inter, ramp */ |
168 if (!initMusic(44100, 1024, false, true)) { | |
169 printf("init music\n"); | |
64 | 170 EndDialog(hWnd, 0); |
171 break; | |
172 } | |
173 AddControls(hWnd); | |
174 EnumChildWindows(hWnd, (WNDENUMPROC)SetFont, (LPARAM)GetStockObject(DEFAULT_GUI_FONT)); | |
75 | 175 if (!loadMusicFromData(hdata, ARRAYSIZE(hdata))) { |
176 printf("load music\n"); | |
177 EndDialog(hWnd, 0); | |
178 break; | |
179 } | |
180 if (!startMusic()) | |
181 { | |
182 printf("start music\n"); | |
183 freeMusic(); | |
184 EndDialog(hWnd, 0); | |
185 break; | |
186 } | |
187 startPlaying(); | |
64 | 188 break; |
189 } | |
190 case WM_DESTROY: | |
75 | 191 stopMusic(); |
192 freeMusic(); | |
64 | 193 PostQuitMessage(0); |
194 break; | |
195 default: | |
196 return DefWindowProcA(hWnd, msg, wParam, lParam); | |
197 } | |
198 return false; | |
199 } | |
200 | |
201 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR args, int ncmdshow) { | |
202 srand((unsigned) time(NULL)); // magic rand() stuff :p | |
203 WNDCLASSA wc = {0}; | |
204 | |
205 wc.hbrBackground = (HBRUSH)COLOR_WINDOW; | |
206 wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |
207 wc.hInstance = hInstance; | |
208 wc.lpszClassName = "win95kg"; | |
209 wc.lpfnWndProc = WindowProcedure; | |
210 wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(PEED)); | |
211 | |
212 if (!RegisterClassA(&wc)) return -1; | |
213 | |
214 CreateWindowA("win95kg", "Windows 95 Keygen", WS_OVERLAPPED | WS_VISIBLE | WS_MINIMIZEBOX | WS_SYSMENU, 100, 100, 225, 200, NULL, NULL, hInstance, NULL); | |
215 | |
216 MSG msg = {0}; | |
217 | |
218 while (GetMessage(&msg, NULL, 0, 0)) { | |
219 TranslateMessage(&msg); | |
220 DispatchMessage(&msg); | |
221 } | |
222 return 0; | |
223 } |