58 constexpr int maxAttempts = 20;
59 constexpr unsigned long retryDelayMilliseconds = 50;
65 if (sprintf_s(newdate,
sizeof newdate,
"%s\n",
patchdate) < 0)
68 _get_doserrno(&osErrorCode);
72 const unsigned int bytesToWrite =
static_cast<unsigned int>(strlen(newdate) + 1);
73 for (
int attempt = 0; attempt < maxAttempts; ++attempt)
76 const errno_t openError = _sopen_s(&handle,
"patchdate.txt",
77 _O_WRONLY | _O_CREAT | _O_TRUNC | _O_TEXT, _SH_DENYNO, _S_IWRITE);
80 const int bytesWritten = _write(handle, newdate, bytesToWrite);
81 if (bytesWritten ==
static_cast<int>(bytesToWrite))
83 if (_close(handle) == 0)
87 _get_doserrno(&osErrorCode);
92 _get_doserrno(&osErrorCode);
98 errorCode = openError;
99 _get_doserrno(&osErrorCode);
102 if (attempt + 1 < maxAttempts)
103 Sleep(retryDelayMilliseconds);
237 _sopen_s(&config,
"Save\\client.cfg", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYNO, _S_IWRITE);
241 if (rename(
"client.cfg",
"Save\\client.cfg") == 0)
243 rename(
"waypoint.dat",
"Save\\waypoint.dat");
244 _sopen_s(&config,
"Save\\client.cfg", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYNO, _S_IWRITE);
248 unsigned char unused;
251 _lseek(config, 0L, SEEK_SET);
254 _read(config, &unused, 1);
255 _read(config, &unused, 1);
256 _read(config, &unused, 1);
257 _read(config, &unused, 1);
263 sprintf_s(msg,
sizeof msg,
264 "Your saved configuration (Save\\client.cfg) uses version %u, but this executable supports versions up to %u.\n\n"
265 "Please run an updated Rise executable. Your settings and bindings have not been changed.\n\n"
266 "Rise will close when you click OK.",
268 MessageBoxA(
nullptr, msg,
"Configuration version mismatch", MB_ICONERROR | MB_OK);
289 _lseek(config, 8L, SEEK_SET);
300 _lseek(config, 40L, SEEK_SET);
311 _lseek(config, 42L, SEEK_SET);
324 _lseek(config, 24L, SEEK_SET);
326 char encryptpass[16];
328 _lseek(config, 24L, SEEK_SET);
329 _write(config, encryptpass, 16);
333 char encryptpass[16];
334 _lseek(config, 24L, SEEK_SET);
335 _read(config, encryptpass, 16);
354 _lseek(config, 700L, SEEK_SET);
367 _lseek(config, 75L, SEEK_SET);
385 _lseek(config, 500L, SEEK_SET);
403 _lseek(config, 400L, SEEK_SET);
416 _lseek(config, 796L, SEEK_SET);
432 _lseek(config, 900L, SEEK_SET);
443 _lseek(config, 43L, SEEK_SET);
444 _read(config, &
scale, 4);
449 _unlink(
"Save/gui.cfg");
491 _lseek(config, 932L, SEEK_SET);
505 _lseek(config, 828L, SEEK_SET);
523 _lseek(config, 0L, SEEK_SET);
534 unsigned keyBindingCount, buttonBindingCount, povBindingCount;
535 _lseek(config, 62L, SEEK_SET);
536 _read(config, &keyBindingCount, 4);
537 _read(config, &buttonBindingCount, 4);
538 _read(config, &povBindingCount, 4);
539 _lseek(config, 1200L, SEEK_SET);
541 for (
size_t i = 0; i < keyBindingCount; i++)
544 _read(config, &keyBinding,
sizeof KeyBinding);
548 for (
size_t i = 0; i < buttonBindingCount; i++)
555 for (
size_t i = 0; i < povBindingCount; i++)
558 _read(config, &povBinding,
sizeof POVBinding);
578 const auto add = [&](
BindingEnum action,
short key,
bool shift) {
580 return b.function == action || (b.scancode == key && b.shift == shift);
583 if (!bound)
keyBindings.emplace_back(action,key,shift);
593 const auto retired = [](
const auto& b) {
604 unsigned char video[2]{};
605 _lseek(config, 47L, SEEK_SET);
606 _read(config, video,
sizeof video);
607 if (video[0] == 1 || video[0] == 2 || video[0] == 4 || video[0] == 8)
624 if (_access(
"Languages\\chinese.default", 0) != -1)
language = 1;
625 else if (_access(
"Languages\\dutch.default", 0) != -1)
language = 2;
626 else if (_access(
"Languages\\french.default", 0) != -1)
language = 3;
627 else if (_access(
"Languages\\german.default", 0) != -1)
language = 4;
628 else if (_access(
"Languages\\greek.default", 0) != -1)
language = 5;
629 else if (_access(
"Languages\\italian.default", 0) != -1)
language = 6;
630 else if (_access(
"Languages\\japanese.default", 0) != -1)
language = 7;
631 else if (_access(
"Languages\\korean.default", 0) != -1)
language = 8;
632 else if (_access(
"Languages\\portuguese.default", 0) != -1)
language = 9;
633 else if (_access(
"Languages\\russian.default", 0) != -1)
language = 10;
634 else if (_access(
"Languages\\spanish.default", 0) != -1)
language = 11;
652 _sopen_s(&config,
"Save\\client.cfg", _O_WRONLY | _O_CREAT | _O_BINARY | _O_SEQUENTIAL, _SH_DENYRW, _S_IWRITE);
656 sprintf_s(msg,
sizeof msg,
"Could not save to the \"Save\\client.cfg\" file: %i", errno);
657 MessageBoxA(
nullptr, msg,
"File system error!", MB_ICONERROR | MB_OK);
661 _lseek(config, 0L, SEEK_SET);
662 unsigned char unused[12];
663 ZeroMemory(unused, 12);
669 _write(config, &unused, 1);
670 _write(config, &unused, 1);
671 _write(config, &unused, 1);
672 _write(config, &unused, 1);
674 _write(config, &unused, 1);
676 _write(config, &unused, 1);
677 _write(config, &unused, 1);
678 _write(config, &unused, 1);
679 char encryptpass[16];
681 _write(config, encryptpass, 16);
683 _write(config, &unused, 1);
685 _write(config, &
scale, 4);
687 const unsigned char vsync =
videoVSync ? 1 : 2;
688 _write(config, &vsync, 1);
689 _write(config, &unused, 1);
690 _write(config, &unused, 12);
691 _write(config, &keyBindingCount, 4);
692 _write(config, &buttonBindingCount, 4);
693 _write(config, &povBindingCount, 4);
694 _write(config, &unused, 1);
697 _lseek(config, 400L, SEEK_SET);
702 _lseek(config, 500L, SEEK_SET);
710 _lseek(config, 700L, SEEK_SET);
718 _lseek(config, 900L, SEEK_SET);
724 _lseek(config, 1200L, SEEK_SET);
725 for (
size_t i = 0; i < keyBindingCount; i++)
727 for (
size_t i = 0; i < buttonBindingCount; i++)
729 for (
size_t i = 0; i < povBindingCount; i++)