Mercurial > msvpvf
comparison src/gui.c @ 6:d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Wed, 26 Jan 2022 20:25:08 -0500 |
parents | |
children | d2cd8c5672fa |
comparison
equal
deleted
inserted
replaced
5:92ec47e63923 | 6:d1e5b8390cd3 |
---|---|
1 #include <stdio.h> | |
2 #include <windows.h> | |
3 #include <stdint.h> | |
4 #include <stdbool.h> | |
5 #include <commdlg.h> | |
6 #include "../include/common.h" | |
7 #define OPEN_FILE_BUTTON 0 | |
8 #define COMBOBOX 1 | |
9 #define LISTBOX 2 | |
10 #define SAVE_FILE_BUTTON 3 | |
11 | |
12 HWND hWndListBox, hWndComboBox; | |
13 int16_t version = 11, type = 1; /* type: 0 is vf, 1 is veg */ | |
14 char* file_name = " "; /* initialize as a space, a filename cannot literally just be a space */ | |
15 | |
16 void set_data(unsigned char magic[], uint16_t version, FILE* target) { | |
17 int i; | |
18 fseek(target, 0x46, SEEK_SET); | |
19 fputc(version, target); | |
20 for (i=0; i<=sizeof(*magic); ++i) { | |
21 fseek(target, 0x18+i, SEEK_SET); | |
22 fputc(magic[i], target); | |
23 } | |
24 } | |
25 | |
26 int copy_file(char* source_file, char* target_file) { | |
27 FILE *source, *target; | |
28 | |
29 source = fopen(source_file, "rb"); | |
30 if (source == NULL) return 1; | |
31 target = fopen(target_file, "wb"); | |
32 if (target == NULL) { | |
33 fclose(source); | |
34 return 1; | |
35 } | |
36 | |
37 size_t n, m; | |
38 unsigned char buff[8192]; | |
39 do { | |
40 n = fread(buff, 1, sizeof(buff), source); | |
41 if (n) m = fwrite(buff, 1, n, target); | |
42 else m = 0; | |
43 } while ((n > 0) && (n == m)); | |
44 | |
45 fclose(target); | |
46 fclose(source); | |
47 return 0; | |
48 } | |
49 | |
50 void display_file(char* path) { | |
51 /* Read the file to memory */ | |
52 FILE* file; | |
53 file = fopen(path, "rb"); | |
54 fseek(file, 0, SEEK_END); | |
55 int _size = ftell(file); | |
56 rewind(file); | |
57 char* data = calloc(_size+1, sizeof(char*)); | |
58 fread(data, _size, 1, file); | |
59 data[_size] = '\0'; | |
60 | |
61 free(data); | |
62 fclose(file); | |
63 } | |
64 | |
65 char* open_file(HWND hWnd) { | |
66 OPENFILENAME ofn; | |
67 char filename[127]; | |
68 | |
69 ZeroMemory(&ofn, sizeof(OPENFILENAME)); | |
70 ofn.lStructSize = sizeof(OPENFILENAME); | |
71 ofn.hwndOwner = hWnd; | |
72 ofn.lpstrFile = filename; | |
73 ofn.lpstrFile[0] = '\0'; | |
74 ofn.nMaxFile = 127; | |
75 ofn.lpstrFilter = "Project files\0*.veg;*.vf\0All files\0*.*\0"; | |
76 ofn.nFilterIndex = 1; | |
77 | |
78 GetOpenFileName(&ofn); | |
79 | |
80 display_file(filename); | |
81 | |
82 return _strdup(filename); | |
83 } | |
84 | |
85 void save_file(HWND hWnd, char* input_file) { | |
86 if (strcmp(input_file, " ") == 0) { | |
87 MessageBoxW(hWnd, L"Please open a file first!", L"Invalid input file!", MB_ICONEXCLAMATION); | |
88 return; | |
89 } | |
90 OPENFILENAME ofn; | |
91 char output_file[127]; | |
92 | |
93 ZeroMemory(&ofn, sizeof(OPENFILENAME)); | |
94 ofn.lStructSize = sizeof(OPENFILENAME); | |
95 ofn.hwndOwner = hWnd; | |
96 ofn.lpstrFile = output_file; | |
97 ofn.lpstrFile[0] = '\0'; | |
98 ofn.nMaxFile = 127; | |
99 ofn.lpstrFilter = "Project files\0*.veg\0All files\0*.*\0"; | |
100 ofn.nFilterIndex = 1; | |
101 | |
102 GetSaveFileName(&ofn); | |
103 | |
104 copy_file(input_file, output_file); | |
105 FILE* output = fopen(output_file, "r+b"); | |
106 if (output == NULL) { | |
107 MessageBoxW(hWnd, L"Failed to save project file!", L"Saving project failed!", MB_ICONEXCLAMATION); | |
108 return; | |
109 } | |
110 | |
111 if (type == 1) { | |
112 unsigned char magic[] = {0xEF, 0x29, 0xC4, 0x46, 0x4A, 0x90, 0xD2, 0x11, 0x87, 0x22, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A}; | |
113 set_data(magic, version, output); | |
114 } else { | |
115 unsigned char magic[] = {0xF6, 0x1B, 0x3C, 0x53, 0x35, 0xD6, 0xF3, 0x43, 0x8A, 0x90, 0x64, 0xB8, 0x87, 0x23, 0x1F, 0x7F}; | |
116 set_data(magic, version, output); | |
117 } | |
118 | |
119 fclose(output); | |
120 } | |
121 | |
122 void AddControls(HWND hWnd) { | |
123 /* versions */ | |
124 hWndComboBox = CreateWindowW(L"ComboBox", NULL, CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD | WS_VISIBLE | WS_OVERLAPPED | WS_VSCROLL, (int)((225 - 50)/2), 30, 50, 200, hWnd, (HMENU)COMBOBOX, NULL, NULL); | |
125 TCHAR versions[][10] = {TEXT("8"), TEXT("9"), TEXT("10"), TEXT("11"), TEXT("12"), TEXT("13"), TEXT("14"), TEXT("15"), TEXT("16"), TEXT("17"), TEXT("18"), TEXT("19")}; | |
126 | |
127 TCHAR A[16]; | |
128 | |
129 memset(&A,0,sizeof(A)); | |
130 int i = 0; | |
131 for (i = 0; i <= 11; i++) { | |
132 wcscpy_s((WCHAR*)A, sizeof(A)/sizeof(TCHAR), (WCHAR*)versions[i]); | |
133 SendMessage(hWndComboBox, (UINT)CB_ADDSTRING, (WPARAM)0, (LPARAM)A); | |
134 } | |
135 SendMessage(hWndComboBox, CB_SETCURSEL, (WPARAM)3, (LPARAM)0); | |
136 /* open file */ | |
137 HWND open_button = CreateWindowW(L"Button", L"Open", WS_VISIBLE | WS_CHILD, (int)((225 - 50)/2), 5, 50, 20, hWnd, (HMENU)OPEN_FILE_BUTTON, NULL, NULL); | |
138 /* type */ | |
139 TCHAR listbox_items[][13] = {TEXT("VEGAS Pro"), TEXT("Movie Studio")}; | |
140 hWndListBox = CreateWindowW(L"Listbox", NULL, WS_VISIBLE | WS_CHILD | LBS_STANDARD | LBS_NOTIFY, (int)((225 - 100)/2), 55, 100, 40, hWnd, (HMENU)LISTBOX, NULL, NULL); | |
141 for (i = 0; i < ARRAYSIZE(listbox_items); i++) { | |
142 int pos = (int)SendMessage(hWndListBox, LB_ADDSTRING, i, (LPARAM) listbox_items[i]); | |
143 SendMessage(hWndListBox, LB_SETITEMDATA, pos, (LPARAM) i); | |
144 } | |
145 SendMessage(hWndListBox, LB_SETCURSEL, (WPARAM)0, (LPARAM)0); | |
146 /* save file */ | |
147 HWND save_button = CreateWindowW(L"Button", L"Save", WS_VISIBLE | WS_CHILD, (int)((225 - 50)/2), 90, 50, 20, hWnd, (HMENU)SAVE_FILE_BUTTON, NULL, NULL); | |
148 if (open_button == NULL || save_button == NULL || hWndListBox == NULL || hWndComboBox == NULL) | |
149 MessageBoxW(hWnd, L"how did you even trigger this", L"GUI could not be initialized!", MB_ICONEXCLAMATION); | |
150 } | |
151 | |
152 bool CALLBACK SetFont(HWND child, LPARAM font) { | |
153 SendMessage(child, WM_SETFONT, font, true); | |
154 return true; | |
155 } | |
156 | |
157 LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { | |
158 switch(msg) { | |
159 case WM_COMMAND: | |
160 if(HIWORD(wParam) == CBN_SELCHANGE) { | |
161 if (LOWORD(wParam) == COMBOBOX) | |
162 version = (int16_t)(8+SendMessage((HWND) lParam, (UINT) CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0)); | |
163 if (LOWORD(wParam) == LISTBOX) | |
164 type = SendMessage((HWND) lParam, (UINT) LB_GETCURSEL, (WPARAM) 0, (LPARAM) 0); | |
165 } | |
166 switch(wParam) { | |
167 case OPEN_FILE_BUTTON: | |
168 file_name = open_file(hWnd); | |
169 break; | |
170 case COMBOBOX: | |
171 break; /* NOTE: remove these 4 lines if we don't end up doing anything with them */ | |
172 case LISTBOX: | |
173 break; | |
174 case SAVE_FILE_BUTTON: | |
175 save_file(hWnd, file_name); | |
176 break; | |
177 } | |
178 break; | |
179 case WM_CREATE: { | |
180 AddControls(hWnd); | |
181 EnumChildWindows(hWnd, (WNDENUMPROC)SetFont, (LPARAM)GetStockObject(DEFAULT_GUI_FONT)); | |
182 break; | |
183 } | |
184 case WM_DESTROY: | |
185 PostQuitMessage(0); | |
186 break; | |
187 default: | |
188 return DefWindowProcW(hWnd, msg, wParam, lParam); | |
189 } | |
190 return false; | |
191 } | |
192 | |
193 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR args, int ncmdshow) { | |
194 WNDCLASSW wc = {0}; | |
195 | |
196 wc.hbrBackground = (HBRUSH)COLOR_WINDOW; | |
197 wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |
198 wc.hInstance = hInstance; | |
199 wc.lpszClassName = L"msvpvf"; | |
200 wc.lpfnWndProc = WindowProcedure; | |
201 | |
202 if (!RegisterClassW(&wc)) return -1; | |
203 | |
204 CreateWindowW(L"msvpvf", L"Movie Studio / Vegas Pro version spoofer", WS_OVERLAPPED | WS_VISIBLE | WS_MINIMIZEBOX | WS_SYSMENU, 100, 100, 225, 200, NULL, NULL, hInstance, NULL); | |
205 | |
206 MSG msg = {0}; | |
207 | |
208 while (GetMessage(&msg, NULL, 0, 0)) { | |
209 TranslateMessage(&msg); | |
210 DispatchMessage(&msg); | |
211 } | |
212 } |