From 39197eb16687df4c7cc39c18f80ae1c82b6781d1 Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Thu, 10 May 2018 22:11:41 +0200 Subject: [PATCH 01/10] Initialize sub_4104F0 for hotkeys --- swep1rcr.exe/hotkey.c | 372 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 372 insertions(+) create mode 100644 swep1rcr.exe/hotkey.c diff --git a/swep1rcr.exe/hotkey.c b/swep1rcr.exe/hotkey.c new file mode 100644 index 0000000..615c5de --- /dev/null +++ b/swep1rcr.exe/hotkey.c @@ -0,0 +1,372 @@ +/* Code related to the menus */ + +// Research based on patched US version + +//----- (004104F0) -------------------------------------------------------- +void sub_4104F0() +{ + char *v0; // esi + int v1; // ecx + const char *v2; // eax + _DWORD *v3; // eax + int v4; // eax + bool v5; // zf + int v6; // edx + const char *v7; // eax + _DWORD *v8; // eax + int v9; // eax + _DWORD *v10; // eax + int v11; // eax + int v12; // [esp+10h] [ebp-24h] + int v13; // [esp+14h] [ebp-20h] + int v14; // [esp+18h] [ebp-1Ch] + int v15; // [esp+1Ch] [ebp-18h] + + if ( dword_4B5C40 ) + dword_4B5C40 = 0; + v12 = dword_E35A98[0]; + if ( sub_485880(88, 0) ) + sub_410430(); + if ( !sub_485880(29, 0) || !sub_485880(46, 0) || !sub_485880(21, 0) || *(_DWORD *)(dword_50C454 + 8) != 9 ) + { + if ( sub_485880(157, 0) && sub_485880(49, 0) && sub_485880(37, 0) && *(_DWORD *)(dword_50C454 + 8) == 9 ) + { + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + _cfltcvt_init_5(); + sub_440550(45); +LABEL_145: + if ( !dword_4D79EC ) + return; + goto LABEL_146; + } + if ( sub_485880(59, 0) ) + { + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + dword_EC83D0 = 1667458609; + goto LABEL_145; + } + if ( sub_485880(60, 0) ) + { + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + dword_EC83D0 = 1667458610; + goto LABEL_145; + } + if ( sub_485880(61, 0) ) + { + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + dword_EC83D0 = 1667458611; + goto LABEL_145; + } + if ( sub_485880(62, 0) ) + { + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + dword_EC83D0 = 1667458612; + if ( *(_DWORD *)(dword_50C454 + 8) == 7 && (sub_485880(42, 0) || sub_485880(54, 0)) && sub_485880(5, 0) ) + dword_E35A98[0] += 1000; + goto LABEL_145; + } + if ( sub_485880(58, 0) ) + { + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + v0 = sub_450B30(1248094053, 0); + if ( v0 ) + { + sub_440550(70); + v1 = *((_DWORD *)v0 + 73); + if ( dword_50CA18 <= 1 ) + { + *((_DWORD *)v0 + 73) = v1 + 1; + if ( v1 + 1 > 4 ) + *((_DWORD *)v0 + 73) = 0; + } + else + { + *((_DWORD *)v0 + 73) = v1 + 1; + if ( v1 + 1 > 7 ) + *((_DWORD *)v0 + 73) = 4; + } + } + goto LABEL_145; + } + if ( (sub_485880(184, 0) || sub_485880(56, 0)) && sub_485880(35, 0) ) + { + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + dword_EC83C8 = 1; + goto LABEL_145; + } + if ( dword_50C07C != 2 ) + goto LABEL_66; + if ( sub_485880(29, 0) || sub_485880(157, 0) ) + { + if ( sub_485880(68, 0) ) + { + if ( dword_4D79EC ) + goto LABEL_146; + if ( dword_4D5E00 ) + goto LABEL_134; + dword_50C048 ^= 4u; + sub_440550(40); +LABEL_65: + dword_4D79EC = 1; + goto LABEL_145; + } + } + else + { + if ( sub_485880(55, 0) && sub_485880(20, 0) ) + { + if ( !dword_4D5E00 ) + { + if ( dword_4D79EC ) + goto LABEL_146; + dword_50CB68 ^= 1u; + sub_440550(44); + dword_4D79EC = 1; + goto LABEL_145; + } + goto LABEL_66; + } + if ( sub_485880(23, 0) && sub_485880(33, 0) && sub_485880(38, 0) && sub_485880(21, 0) && !dword_4D5E00 ) + { + if ( dword_4D79EC ) + goto LABEL_146; + dword_50C048 ^= 0x2000u; + sub_440550(43); + goto LABEL_65; + } + } +LABEL_66: + if ( sub_485880(29, 0) || sub_485880(157, 0) ) + { + if ( sub_485880(36, 0) ) + { + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + if ( !dword_4B294C ) + { + v2 = sub_421360(aMondotextH0035); + goto LABEL_112; + } + if ( dword_4B2944 ) + { + strcat(&byte_4D78D0, sub_421360(aMondotextH0364)); + dword_4D79D0 = dword_4B2910; + if ( dword_4B2910 ) + sub_40A120(1); + dword_4B2910 = 0; + } + else + { + strcat(&byte_4D78D0, sub_421360(aMondotextH0363)); + dword_4B2910 = dword_4D79D0; + } + sub_440550(70); + dword_4B2944 = dword_4B2944 == 0; + if ( !dword_4B2940 ) + { + v3 = sub_414D90(0, 24); + sub_40B740(0, v3); + } + v4 = sub_411810(); + if ( !dword_4B2940 && v4 ) + { + v5 = *(_DWORD *)(v4 + 28) == 24; + goto LABEL_104; + } + goto LABEL_105; + } + if ( sub_485880(56, 0) && *(_DWORD *)(dword_50C454 + 8) == 13 ) + { + if ( sub_485880(184, 0) ) + { + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + if ( !dword_4D5E00 ) + { + v6 = dword_E996DC; + BYTE1(v6) |= 0x40u; + dword_E996DC = v6; + *(_BYTE *)(dword_50C454 + 110) = *(_BYTE *)(dword_50C454 + 110) == 0; + sub_440550(46); + } + goto LABEL_145; + } + if ( sub_485880(157, 0) ) + { + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + if ( !dword_4D5E00 ) + { + dword_E996DC &= 0xFFFFBFFF; + *(_BYTE *)(dword_50C454 + 110) = *(_BYTE *)(dword_50C454 + 110) == 0; + sub_440550(47); + } + goto LABEL_145; + } + } + if ( sub_485880(50, 0) ) + { + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + if ( !dword_4B2950 ) + { + v2 = sub_421360(aMondotextH0036); + goto LABEL_112; + } + if ( dword_4D6B38 ) + v7 = sub_421360(aMondotextH0366); + else + v7 = sub_421360(aMondotextH0365); + strcat(&byte_4D78D0, v7); + sub_440550(70); + dword_4D6B38 = dword_4D6B38 == 0; + if ( !dword_4B2940 ) + { + v8 = sub_414D90(0, 25); + sub_40B740(1, v8); + } + v9 = sub_411810(); + if ( !dword_4B2940 && v9 ) + { + v5 = *(_DWORD *)(v9 + 28) == 25; +LABEL_104: + if ( v5 ) + goto LABEL_145; + } +LABEL_105: + sub_406080((int)aCurrent); + goto LABEL_145; + } + if ( sub_485880(33, 0) ) + { + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + if ( dword_4B2914 ) + { + if ( dword_4D765C ) + { + if ( dword_4B2910 || !dword_4B4938 ) + { + strcat(&byte_4D78D0, sub_421360(aMondotextH0370)); + sub_40A120(1); + } + else + { + strcat(&byte_4D78D0, sub_421360(aMondotextH0369)); + } + sub_440550(70); + if ( dword_4B2910 || (dword_4B2910 = 1, !dword_4B4938) ) + dword_4B2910 = 0; + v10 = sub_414D90(0, 27); + sub_40C100(v10); + v11 = sub_411810(); + if ( dword_4B2940 || !v11 || *(_DWORD *)(v11 + 28) != 27 ) + sub_40AB80((int)aCurrent); + goto LABEL_145; + } + v2 = sub_421360(aMondotextH0368); + } + else + { + v2 = sub_421360(aMondotextH0042); + } +LABEL_112: + strcat(&byte_4D78D0, v2); + goto LABEL_145; + } + if ( sub_485880(16, 0) && dword_4D5E00 ) + { + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + v13 = 1348564851; + v14 = -1; + v15 = 1; + sub_450C50(1097624609, (int)&v13); + goto LABEL_145; + } + if ( sub_485880(87, 0) ) + { + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + dword_4D79DC = dword_4D79DC == 0; + goto LABEL_145; + } + } + if ( !sub_485880(65, 0) ) + { + if ( sub_485880(63, 0) || sub_485880(64, 0) ) + { + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79E0 = 1; + dword_4D79EC = 1; + } + else if ( sub_485880(70, 0) && sub_485880(199, 0) ) + { + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + if ( *(_DWORD *)(dword_50C454 + 8) == 9 ) + { + dword_50C048 ^= 0x40u; + sub_43D9A0(); + } + } + else + { + dword_4D79EC = 0; + } + goto LABEL_145; + } + if ( dword_4D79EC ) + goto LABEL_146; + sub_440550(70); + sub_41BDD0(); +LABEL_134: + dword_4D79EC = 1; + goto LABEL_145; + } + if ( !dword_4D79EC ) + { + dword_4D79EC = 1; + _cfltcvt_init_6(); + sub_440550(-1); + goto LABEL_145; + } +LABEL_146: + if ( byte_4D78D0 ) + { + sub_44FCE0((int)&byte_4D78D0, 2.0); + byte_4D78D0 = 0; + dword_4D5564 = 1074161254; + } + if ( v12 != dword_E35A98[0] ) + { + if ( dword_EC83CC >= 5000 ) + dword_E35A98[0] = v12; + else + dword_EC83CC += 1000; + } +} + From d9fc89ad81999e63f69a4f0e4ffee814c8db96c2 Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Thu, 10 May 2018 23:12:10 +0200 Subject: [PATCH 02/10] Replace key values with DirectInput names --- swep1rcr.exe/hotkey.c | 123 +++++++++++++++++++++++++++++++----------- 1 file changed, 91 insertions(+), 32 deletions(-) diff --git a/swep1rcr.exe/hotkey.c b/swep1rcr.exe/hotkey.c index 615c5de..6f82b12 100644 --- a/swep1rcr.exe/hotkey.c +++ b/swep1rcr.exe/hotkey.c @@ -25,57 +25,73 @@ void sub_4104F0() if ( dword_4B5C40 ) dword_4B5C40 = 0; v12 = dword_E35A98[0]; - if ( sub_485880(88, 0) ) + + // F12 + //FIXME: I believe this was screenshot? + if ( sub_485880(DIK_F12, 0) ) sub_410430(); - if ( !sub_485880(29, 0) || !sub_485880(46, 0) || !sub_485880(21, 0) || *(_DWORD *)(dword_50C454 + 8) != 9 ) + + // NOT [ Ctrl (Left) + C + Y ] + if ( !sub_485880(DIK_LCONTROL, 0) || !sub_485880(DIK_C, 0) || !sub_485880(DIK_Y, 0) || *(_DWORD *)(dword_50C454 + 8) != 9 ) { - if ( sub_485880(157, 0) && sub_485880(49, 0) && sub_485880(37, 0) && *(_DWORD *)(dword_50C454 + 8) == 9 ) + // Ctrl (Right) + N + K + if ( sub_485880(DIK_RCONTROL, 0) && sub_485880(DIK_N, 0) && sub_485880(DIK_K, 0) && *(_DWORD *)(dword_50C454 + 8) == 9 ) { if ( dword_4D79EC ) goto LABEL_146; dword_4D79EC = 1; - _cfltcvt_init_5(); + + // Enable Jinn Reeso + sub_44B530(); + sub_440550(45); LABEL_145: if ( !dword_4D79EC ) return; goto LABEL_146; } - if ( sub_485880(59, 0) ) + + if ( sub_485880(DIK_F1, 0) ) { if ( dword_4D79EC ) goto LABEL_146; dword_4D79EC = 1; - dword_EC83D0 = 1667458609; + dword_EC83D0 = 1667458609; // 'ccf1' goto LABEL_145; } - if ( sub_485880(60, 0) ) + + if ( sub_485880(DIK_F2, 0) ) { if ( dword_4D79EC ) goto LABEL_146; dword_4D79EC = 1; - dword_EC83D0 = 1667458610; + dword_EC83D0 = 1667458610; // 'ccf2' goto LABEL_145; } - if ( sub_485880(61, 0) ) + + if ( sub_485880(DIK_F3, 0) ) { if ( dword_4D79EC ) goto LABEL_146; dword_4D79EC = 1; - dword_EC83D0 = 1667458611; + dword_EC83D0 = 1667458611; // 'ccf3' goto LABEL_145; } - if ( sub_485880(62, 0) ) + + // Reward 1000 Truguts if F4 + Shift (left or right) + 4 are pressed + if ( sub_485880(DIK_F4, 0) ) { if ( dword_4D79EC ) goto LABEL_146; dword_4D79EC = 1; - dword_EC83D0 = 1667458612; - if ( *(_DWORD *)(dword_50C454 + 8) == 7 && (sub_485880(42, 0) || sub_485880(54, 0)) && sub_485880(5, 0) ) + dword_EC83D0 = 1667458612; // 'ccf4' + if ( *(_DWORD *)(dword_50C454 + 8) == 7 && (sub_485880(DIK_LSHIFT, 0) || sub_485880(DIK_RSHIFT, 0)) && sub_485880(DIK_4, 0) ) dword_E35A98[0] += 1000; goto LABEL_145; } - if ( sub_485880(58, 0) ) + + // Check for capslock + if ( sub_485880(DIK_CAPITAL, 0) ) { if ( dword_4D79EC ) goto LABEL_146; @@ -100,7 +116,10 @@ void sub_4104F0() } goto LABEL_145; } - if ( (sub_485880(184, 0) || sub_485880(56, 0)) && sub_485880(35, 0) ) + + // Alt (Right or Left) + H + //FIXME: What does this do?! + if ( (sub_485880(DIK_RMENU, 0) || sub_485880(DIK_LMENU, 0)) && sub_485880(DIK_H, 0) ) { if ( dword_4D79EC ) goto LABEL_146; @@ -108,11 +127,15 @@ void sub_4104F0() dword_EC83C8 = 1; goto LABEL_145; } + if ( dword_50C07C != 2 ) goto LABEL_66; - if ( sub_485880(29, 0) || sub_485880(157, 0) ) + + // Control (Left or Right) + if ( sub_485880(DIK_LCONTROL, 0) || sub_485880(DIK_RCONTROL, 0) ) { - if ( sub_485880(68, 0) ) + // F10 + if ( sub_485880(DIK_F10, 0) ) { if ( dword_4D79EC ) goto LABEL_146; @@ -127,7 +150,10 @@ void sub_4104F0() } else { - if ( sub_485880(55, 0) && sub_485880(20, 0) ) + + // Multiply (Numpad) + T + //FIXME What is this? + if ( sub_485880(DIK_MULTIPLY, 0) && sub_485880(DIK_T, 0) ) { if ( !dword_4D5E00 ) { @@ -140,7 +166,10 @@ void sub_4104F0() } goto LABEL_66; } - if ( sub_485880(23, 0) && sub_485880(33, 0) && sub_485880(38, 0) && sub_485880(21, 0) && !dword_4D5E00 ) + + // I + F + L + Y + //FIXME: What does this do? + if ( sub_485880(DIK_I, 0) && sub_485880(DIK_F, 0) && sub_485880(DIK_L, 0) && sub_485880(DIK_Y, 0) && !dword_4D5E00 ) { if ( dword_4D79EC ) goto LABEL_146; @@ -148,11 +177,16 @@ void sub_4104F0() sub_440550(43); goto LABEL_65; } + } LABEL_66: - if ( sub_485880(29, 0) || sub_485880(157, 0) ) + + // Control (Left or Right) + if ( sub_485880(DIK_LCONTROL, 0) || sub_485880(DIK_RCONTROL, 0) ) { - if ( sub_485880(36, 0) ) + + // J + if ( sub_485880(DIK_J, 0) ) { if ( dword_4D79EC ) goto LABEL_146; @@ -190,9 +224,13 @@ void sub_4104F0() } goto LABEL_105; } - if ( sub_485880(56, 0) && *(_DWORD *)(dword_50C454 + 8) == 13 ) + + // Alt (Left) + if ( sub_485880(DIK_LMENU, 0) && *(_DWORD *)(dword_50C454 + 8) == 13 ) { - if ( sub_485880(184, 0) ) + + // Alt (Right) + if ( sub_485880(DIK_RMENU, 0) ) { if ( dword_4D79EC ) goto LABEL_146; @@ -207,7 +245,9 @@ void sub_4104F0() } goto LABEL_145; } - if ( sub_485880(157, 0) ) + + // Control (Right) + if ( sub_485880(DIK_RCONTROL, 0) ) { if ( dword_4D79EC ) goto LABEL_146; @@ -221,7 +261,9 @@ void sub_4104F0() goto LABEL_145; } } - if ( sub_485880(50, 0) ) + + // M + if ( sub_485880(DIK_M, 0) ) { if ( dword_4D79EC ) goto LABEL_146; @@ -255,7 +297,9 @@ void sub_4104F0() sub_406080((int)aCurrent); goto LABEL_145; } - if ( sub_485880(33, 0) ) + + // F + if ( sub_485880(DIK_F, 0) ) { if ( dword_4D79EC ) goto LABEL_146; @@ -293,7 +337,9 @@ void sub_4104F0() strcat(&byte_4D78D0, v2); goto LABEL_145; } - if ( sub_485880(16, 0) && dword_4D5E00 ) + + // Q + if ( sub_485880(DIK_Q, 0) && dword_4D5E00 ) { if ( dword_4D79EC ) goto LABEL_146; @@ -304,7 +350,9 @@ void sub_4104F0() sub_450C50(1097624609, (int)&v13); goto LABEL_145; } - if ( sub_485880(87, 0) ) + + // F11 + if ( sub_485880(DIK_F11, 0) ) { if ( dword_4D79EC ) goto LABEL_146; @@ -313,16 +361,22 @@ void sub_4104F0() goto LABEL_145; } } - if ( !sub_485880(65, 0) ) + + // F7 + if ( !sub_485880(DIK_F7, 0) ) { - if ( sub_485880(63, 0) || sub_485880(64, 0) ) + + // F5 or F6 + if ( sub_485880(DIK_F5, 0) || sub_485880(DIK_F6, 0) ) { if ( dword_4D79EC ) goto LABEL_146; dword_4D79E0 = 1; dword_4D79EC = 1; } - else if ( sub_485880(70, 0) && sub_485880(199, 0) ) + // Scroll lock + Home + //FIXME: What does this do?! + else if ( sub_485880(DIK_SCROLL, 0) && sub_485880(DIK_HOME, 0) ) { if ( dword_4D79EC ) goto LABEL_146; @@ -347,13 +401,18 @@ void sub_4104F0() dword_4D79EC = 1; goto LABEL_145; } + if ( !dword_4D79EC ) { dword_4D79EC = 1; - _cfltcvt_init_6(); + + // Enable Cy Junga + sub_44B5E0(); + sub_440550(-1); goto LABEL_145; } + LABEL_146: if ( byte_4D78D0 ) { From e2a46591ec73ae440a26cd156c5a6f0b59e9456e Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Fri, 11 May 2018 13:20:31 +0200 Subject: [PATCH 03/10] Initialize sub_485880 --- swep1rcr.exe/input.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 swep1rcr.exe/input.c diff --git a/swep1rcr.exe/input.c b/swep1rcr.exe/input.c new file mode 100644 index 0000000..8850b35 --- /dev/null +++ b/swep1rcr.exe/input.c @@ -0,0 +1,28 @@ +/* Code related to the input subsystem */ + +// Research based on patched US version + + +//----- (00485880) -------------------------------------------------------- +int __cdecl sub_485880(int a1, _DWORD *a2) +{ + int result; // eax + + if ( a1 < 0 ) + return 0; + if ( dword_50FEB4 ) + { + if ( a2 ) + *a2 += dword_50F668[a1]; + if ( dword_50FEB0 && dword_50E868[a1] ) + dword_50FEB0 = 0; + result = dword_50E868[a1]; + } + else + { + if ( a2 ) + *a2 = 0; + result = 0; + } + return result; +} From fb2b0e9a67103f3b23c9634d42f4049e4e0b6a8c Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Fri, 11 May 2018 13:25:18 +0200 Subject: [PATCH 04/10] Document sub_485880 --- swep1rcr.exe/input.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/swep1rcr.exe/input.c b/swep1rcr.exe/input.c index 8850b35..e49935a 100644 --- a/swep1rcr.exe/input.c +++ b/swep1rcr.exe/input.c @@ -4,25 +4,34 @@ //----- (00485880) -------------------------------------------------------- -int __cdecl sub_485880(int a1, _DWORD *a2) -{ - int result; // eax +// Check the keyboard state for a specific key +// a1 = DirectInput DIK_* (keycode) +// a2 = Optional pointer to output value to which the state will be added +int __cdecl sub_485880(int32_t a1, uint32_t *a2) { - if ( a1 < 0 ) + // Don't allow a negative key index to be queried + if ( a1 < 0 ) { return 0; - if ( dword_50FEB4 ) - { - if ( a2 ) - *a2 += dword_50F668[a1]; - if ( dword_50FEB0 && dword_50E868[a1] ) - dword_50FEB0 = 0; - result = dword_50E868[a1]; } - else - { - if ( a2 ) + + // Early out if the keyboard is disabled? + if ( !dword_50FEB4 ) { + if ( a2 != NULL ) { *a2 = 0; - result = 0; + } + return 0; + } + + // Add the state to the optional output value + if ( a2 != NULL ) { + *a2 += dword_50F668[a1]; } - return result; + + //FIXME: Unknown + if ( dword_50FEB0 && dword_50E868[a1] ) { + dword_50FEB0 = 0; + } + + // Return the current state + return dword_50E868[a1]; } From 9654c48d8cc6079aca69f9e2478350fb6ea341e4 Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Fri, 11 May 2018 16:44:08 +0200 Subject: [PATCH 05/10] Initialize sub_410430 --- swep1rcr.exe/hotkey.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/swep1rcr.exe/hotkey.c b/swep1rcr.exe/hotkey.c index 6f82b12..d993733 100644 --- a/swep1rcr.exe/hotkey.c +++ b/swep1rcr.exe/hotkey.c @@ -2,6 +2,25 @@ // Research based on patched US version +//----- (00410430) -------------------------------------------------------- +int sub_410430() +{ + int result; // eax + + result = sub_485880(88, 0); + if ( !result || (result = dword_4D79E8) != 0 ) + { + dword_4D79E8 = 0; + } + else + { + sub_440550(70); + result = sub_410480((int)aSnap); + dword_4D79E8 = 1; + } + return result; +} + //----- (004104F0) -------------------------------------------------------- void sub_4104F0() { From 3fda6ab3ef9c85ad7df3ef79ad4e0ad6e81e15e4 Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Fri, 11 May 2018 16:55:49 +0200 Subject: [PATCH 06/10] Cleanup menu snapshot handler (sub_410430) --- swep1rcr.exe/hotkey.c | 48 +++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/swep1rcr.exe/hotkey.c b/swep1rcr.exe/hotkey.c index d993733..a851e45 100644 --- a/swep1rcr.exe/hotkey.c +++ b/swep1rcr.exe/hotkey.c @@ -3,27 +3,33 @@ // Research based on patched US version //----- (00410430) -------------------------------------------------------- -int sub_410430() -{ - int result; // eax +// Check if a screenshot should be taken, then take it +void sub_410430() { - result = sub_485880(88, 0); - if ( !result || (result = dword_4D79E8) != 0 ) - { - dword_4D79E8 = 0; - } - else - { + // Check if we hold F12 and it was released at least once, + // after the last screenshot was taken + if ( sub_485880(DIK_F12, 0) && (dword_4D79E8 != 0)) { + + // Play a sound to confirm taking the screenshot sub_440550(70); - result = sub_410480((int)aSnap); + + // Take screenshot + sub_410480((int)aSnap); + + // Mark F12 as held / pressed dword_4D79E8 = 1; + + } else { + + // Mark F12 as released + dword_4D79E8 = 0; + } - return result; + return; } //----- (004104F0) -------------------------------------------------------- -void sub_4104F0() -{ +void sub_4104F0() { char *v0; // esi int v1; // ecx const char *v2; // eax @@ -41,14 +47,20 @@ void sub_4104F0() int v14; // [esp+18h] [ebp-1Ch] int v15; // [esp+1Ch] [ebp-18h] - if ( dword_4B5C40 ) + //FIXME: What is this? + if ( dword_4B5C40 ) { dword_4B5C40 = 0; + } + + // Get the number of truguts v12 = dword_E35A98[0]; - // F12 - //FIXME: I believe this was screenshot? - if ( sub_485880(DIK_F12, 0) ) + // F12: Take a screenshot + //FIXME: Bug in game: F12 is checked in the called function anyway, + // no need to check it here + if ( sub_485880(DIK_F12, 0) ) { sub_410430(); + } // NOT [ Ctrl (Left) + C + Y ] if ( !sub_485880(DIK_LCONTROL, 0) || !sub_485880(DIK_C, 0) || !sub_485880(DIK_Y, 0) || *(_DWORD *)(dword_50C454 + 8) != 9 ) From bf99167f13bc7c92a6e9486262f6a16426d93093 Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Fri, 11 May 2018 16:57:07 +0200 Subject: [PATCH 07/10] Initialize sub_410480 for snapshots --- swep1rcr.exe/snapshot.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 swep1rcr.exe/snapshot.c diff --git a/swep1rcr.exe/snapshot.c b/swep1rcr.exe/snapshot.c new file mode 100644 index 0000000..88f25b3 --- /dev/null +++ b/swep1rcr.exe/snapshot.c @@ -0,0 +1,25 @@ +/* Code related to the snapshot / screenshot feature */ + +// Research based on patched US version + +//----- (00410480) -------------------------------------------------------- +signed int __cdecl sub_410480(int a1) +{ + int v1; // ecx + FILE *v2; // eax + FILE *v3; // esi + char v5; // [esp+8h] [ebp-50h] + + do + { + v1 = dword_4D79E4++; + sprintf(&v5, aS03dBmp, a1, v1); + v2 = fopen(&v5, aRb); + v3 = v2; + if ( !v2 ) + break; + fclose(v2); + } + while ( v3 ); + return sub_489D20((int)&v5); +} From a401c881f14c609578e04b44ea1873150da7cf50 Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Fri, 11 May 2018 17:06:49 +0200 Subject: [PATCH 08/10] Comment sub_410480 --- swep1rcr.exe/snapshot.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/swep1rcr.exe/snapshot.c b/swep1rcr.exe/snapshot.c index 88f25b3..0fb6e48 100644 --- a/swep1rcr.exe/snapshot.c +++ b/swep1rcr.exe/snapshot.c @@ -7,19 +7,29 @@ signed int __cdecl sub_410480(int a1) { int v1; // ecx FILE *v2; // eax - FILE *v3; // esi char v5; // [esp+8h] [ebp-50h] - do - { - v1 = dword_4D79E4++; + // Search for a free screenshot index + do { + + // Get index for this screenshot and construct filename + int v1 = dword_4D79E4++; sprintf(&v5, aS03dBmp, a1, v1); + + // Try to open the file (for read access) v2 = fopen(&v5, aRb); - v3 = v2; - if ( !v2 ) + + // If we were unable to open it, assume that it doesn't exist. + // This means we have found a free index, so we can leave the loop + if (v2 == NULL) { break; + } + + // If we opened the file successfully, close it fclose(v2); - } - while ( v3 ); + + } while ( v2 ); + + // Take the actual screenshot now return sub_489D20((int)&v5); } From 2341d93c36805c0d27c743601bb2408f8936af28 Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Fri, 11 May 2018 17:07:15 +0200 Subject: [PATCH 09/10] Initialize sub_48D4A0 and sub_489D20 --- swep1rcr.exe/snapshot.c | 134 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 131 insertions(+), 3 deletions(-) diff --git a/swep1rcr.exe/snapshot.c b/swep1rcr.exe/snapshot.c index 0fb6e48..1298205 100644 --- a/swep1rcr.exe/snapshot.c +++ b/swep1rcr.exe/snapshot.c @@ -2,10 +2,138 @@ // Research based on patched US version -//----- (00410480) -------------------------------------------------------- -signed int __cdecl sub_410480(int a1) + +//----- (0048D4A0) -------------------------------------------------------- +// Take a screenshot +// a1 = Path +// a2 = Unknown //FIXME +signed int __cdecl sub_48D4A0(int a1, _DWORD *a2) { - int v1; // ecx + _DWORD *v2; // esi + int v4; // ebp + int v5; // ebx + unsigned int v6; // edx + int v7; // ebp + unsigned int v8; // edi + _BYTE *v9; // ebx + int v10; // edi + int v11; // ecx + int v12; // eax + __int64 v13; // [esp+10h] [ebp-70h] + int v14; // [esp+18h] [ebp-68h] + int v15; // [esp+20h] [ebp-60h] + int v16; // [esp+24h] [ebp-5Ch] + int v17; // [esp+28h] [ebp-58h] + __int16 v18; // [esp+2Ch] [ebp-54h] + __int16 v19; // [esp+2Eh] [ebp-52h] + int v20; // [esp+30h] [ebp-50h] + unsigned int v21; // [esp+34h] [ebp-4Ch] + int v22; // [esp+38h] [ebp-48h] + int v23; // [esp+3Ch] [ebp-44h] + int v24; // [esp+48h] [ebp-38h] + int v25; // [esp+4Ch] [ebp-34h] + int v26; // [esp+50h] [ebp-30h] + int v27; // [esp+54h] [ebp-2Ch] + int v28; // [esp+58h] [ebp-28h] + int v29; // [esp+5Ch] [ebp-24h] + int v30; // [esp+60h] [ebp-20h] + int v31; // [esp+64h] [ebp-1Ch] + int v32; // [esp+88h] [ebp+8h] + + v2 = a2; + if ( !a2[8] ) + return 1; + v4 = a2[4]; + v5 = a2[3]; + v6 = (unsigned int)(v5 * v4 * a2[9]) >> 3; + HIDWORD(v13) = 0; + *(_DWORD *)((char *)&v13 + 2) = v6 + 54; + v14 = 0; + memset(&v15, 0, 0x28u); + v20 = 0; + v21 = v6; + LOWORD(v13) = 19778; // 'MB' (= 'B','M') + *(int *)((char *)&v14 + 2) = 54; + v15 = 40; + v16 = v5; + v17 = v4; + v18 = 1; + v19 = 24; + v22 = 2834; + v23 = 2834; + v7 = (*(int (__cdecl **)(int, char *))(dword_ECC420 + 48))(a1, aWb); + if ( !v7 ) + { + sub_484780(*(_DWORD *)(dword_ECC420 + 16), (int)aDDevelQa5PcGno_2, 506, aUnableToOpenFi, a1, 0, 0, 0); + return 1; + } + if ( (*(int (__cdecl **)(int, __int64 *, signed int))(dword_ECC420 + 64))(v7, &v13, 14) != 14 ) + { + sub_484780(*(_DWORD *)(dword_ECC420 + 16), (int)aDDevelQa5PcGno_2, 515, aErrorAttemptin, 14, a1, 0, 0); + (*(void (__cdecl **)(int))(dword_ECC420 + 52))(v7); + return 1; + } + if ( (*(int (__cdecl **)(int, int *, signed int))(dword_ECC420 + 64))(v7, &v15, 40) == 40 ) + { + v8 = 3 * a2[3]; + v32 = 3 * a2[3]; + v9 = (_BYTE *)(*(int (__cdecl **)(int))(dword_ECC420 + 32))(3 * v2[3]); + if ( !v9 ) + { + (*(void (__cdecl **)(int))(dword_ECC420 + 52))(v7); + return 1; + } + memset(v9, 0, v8); + v24 = 1; + v25 = 24; + v26 = 8; + v27 = 8; + v28 = 8; + v29 = 0; + v30 = 8; + v31 = 16; + sub_488370(v2); + v10 = v2[4] - 1; + if ( v10 < 0 ) + { +LABEL_15: + (*(void (__cdecl **)(_BYTE *))(dword_ECC420 + 36))(v9); + sub_4883C0(v2); + (*(void (__cdecl **)(int))(dword_ECC420 + 52))(v7); + return 0; + } + v11 = v2[3]; + while ( 1 ) + { + sub_48D1C0(v9, &v24, (unsigned __int8 *)(v2[22] + v2[6] * v10), v2 + 8, v11, 0, 0); + v12 = (*(int (__cdecl **)(int, _BYTE *, int))(dword_ECC420 + 64))(v7, v9, v32); + v11 = v2[3]; + if ( v12 != 3 * v11 ) + break; + if ( --v10 < 0 ) + goto LABEL_15; + } + sub_484780(*(_DWORD *)(dword_ECC420 + 16), (int)aDDevelQa5PcGno_2, 560, aErrorAttemptin, v32, a1, 0, 0); + (*(void (__cdecl **)(_BYTE *))(dword_ECC420 + 36))(v9); + } + else + { + sub_484780(*(_DWORD *)(dword_ECC420 + 16), (int)aDDevelQa5PcGno_2, 525, aErrorAttemptin, 40, a1, 0, 0); + } + (*(void (__cdecl **)(int))(dword_ECC420 + 52))(v7); + return 1; +} + +//----- (00489D20) -------------------------------------------------------- +// Take a screenshot +// a1 = Path to screenshot +signed int __cdecl sub_489D20(int a1) { + return sub_48D4A0(a1, &dword_EC8DA0); +} + +//----- (00410480) -------------------------------------------------------- +// a1 = Filename prefix (typically "snap_") +signed int __cdecl sub_410480(char* a1) { FILE *v2; // eax char v5; // [esp+8h] [ebp-50h] From 7f74b3ddf0f2bfb1783e8e52f1ce88467ff83a56 Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Fri, 11 May 2018 20:25:09 +0200 Subject: [PATCH 10/10] Restructure sub_4104F0 --- swep1rcr.exe/hotkey.c | 576 +++++++++++++++++++++--------------------- 1 file changed, 285 insertions(+), 291 deletions(-) diff --git a/swep1rcr.exe/hotkey.c b/swep1rcr.exe/hotkey.c index a851e45..722e837 100644 --- a/swep1rcr.exe/hotkey.c +++ b/swep1rcr.exe/hotkey.c @@ -1,4 +1,4 @@ -/* Code related to the menus */ +/* Code related to the hotkeys */ // Research based on patched US version @@ -29,6 +29,7 @@ void sub_410430() { } //----- (004104F0) -------------------------------------------------------- +// Do check for hotkeys void sub_4104F0() { char *v0; // esi int v1; // ecx @@ -43,9 +44,6 @@ void sub_4104F0() { _DWORD *v10; // eax int v11; // eax int v12; // [esp+10h] [ebp-24h] - int v13; // [esp+14h] [ebp-20h] - int v14; // [esp+18h] [ebp-1Ch] - int v15; // [esp+1Ch] [ebp-18h] //FIXME: What is this? if ( dword_4B5C40 ) { @@ -62,401 +60,397 @@ void sub_4104F0() { sub_410430(); } - // NOT [ Ctrl (Left) + C + Y ] - if ( !sub_485880(DIK_LCONTROL, 0) || !sub_485880(DIK_C, 0) || !sub_485880(DIK_Y, 0) || *(_DWORD *)(dword_50C454 + 8) != 9 ) - { + if ( sub_485880(DIK_LCONTROL, 0) && sub_485880(DIK_C, 0) && sub_485880(DIK_Y, 0) && *(_DWORD *)(dword_50C454 + 8) == 9 )) { + + // Ctrl (Left) + C + Y + //FIXME: What's the other condition? + + if ( dword_4D79EC ) + goto LABEL_146: + dword_4D79EC = 1; + + // Enable Cy Junga + sub_44B5E0(); + + sub_440550(-1); + } else if ( sub_485880(DIK_RCONTROL, 0) && sub_485880(DIK_N, 0) && sub_485880(DIK_K, 0) && *(_DWORD *)(dword_50C454 + 8) == 9 ) { + // Ctrl (Right) + N + K - if ( sub_485880(DIK_RCONTROL, 0) && sub_485880(DIK_N, 0) && sub_485880(DIK_K, 0) && *(_DWORD *)(dword_50C454 + 8) == 9 ) - { - if ( dword_4D79EC ) - goto LABEL_146; - dword_4D79EC = 1; + //FIXME: What's the other condition? + + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; - // Enable Jinn Reeso - sub_44B530(); + // Enable Jinn Reeso + sub_44B530(); - sub_440550(45); -LABEL_145: - if ( !dword_4D79EC ) - return; + sub_440550(45); + } else if ( sub_485880(DIK_F1, 0) ) { + if ( dword_4D79EC ) goto LABEL_146; - } + dword_4D79EC = 1; - if ( sub_485880(DIK_F1, 0) ) - { - if ( dword_4D79EC ) - goto LABEL_146; - dword_4D79EC = 1; - dword_EC83D0 = 1667458609; // 'ccf1' - goto LABEL_145; - } + dword_EC83D0 = 1667458609; // 'ccf1' + } else if ( sub_485880(DIK_F2, 0) ) { + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; - if ( sub_485880(DIK_F2, 0) ) - { - if ( dword_4D79EC ) - goto LABEL_146; - dword_4D79EC = 1; - dword_EC83D0 = 1667458610; // 'ccf2' - goto LABEL_145; - } + dword_EC83D0 = 1667458610; // 'ccf2' + } else if ( sub_485880(DIK_F3, 0) ) { + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; - if ( sub_485880(DIK_F3, 0) ) - { - if ( dword_4D79EC ) - goto LABEL_146; - dword_4D79EC = 1; - dword_EC83D0 = 1667458611; // 'ccf3' - goto LABEL_145; - } + dword_EC83D0 = 1667458611; // 'ccf3' + } else if ( sub_485880(DIK_F4, 0) ) { - // Reward 1000 Truguts if F4 + Shift (left or right) + 4 are pressed - if ( sub_485880(DIK_F4, 0) ) - { - if ( dword_4D79EC ) - goto LABEL_146; - dword_4D79EC = 1; - dword_EC83D0 = 1667458612; // 'ccf4' - if ( *(_DWORD *)(dword_50C454 + 8) == 7 && (sub_485880(DIK_LSHIFT, 0) || sub_485880(DIK_RSHIFT, 0)) && sub_485880(DIK_4, 0) ) - dword_E35A98[0] += 1000; - goto LABEL_145; + // F4 + + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + + dword_EC83D0 = 1667458612; // 'ccf4' + if ( *(_DWORD *)(dword_50C454 + 8) == 7 && (sub_485880(DIK_LSHIFT, 0) || sub_485880(DIK_RSHIFT, 0)) && sub_485880(DIK_4, 0) ) { + + //FIXME: What's the other condition? + // Shift (left or right) + 4 + + // Reward 1000 Truguts + dword_E35A98[0] += 1000; } + } else if ( sub_485880(DIK_CAPITAL, 0) ) { + // Check for capslock - if ( sub_485880(DIK_CAPITAL, 0) ) + + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + + v0 = sub_450B30(1248094053, 0); // 'Jdge' + if ( v0 ) { - if ( dword_4D79EC ) - goto LABEL_146; - dword_4D79EC = 1; - v0 = sub_450B30(1248094053, 0); - if ( v0 ) + sub_440550(70); + v1 = *((_DWORD *)v0 + 73); + if ( dword_50CA18 <= 1 ) { - sub_440550(70); - v1 = *((_DWORD *)v0 + 73); - if ( dword_50CA18 <= 1 ) - { - *((_DWORD *)v0 + 73) = v1 + 1; - if ( v1 + 1 > 4 ) - *((_DWORD *)v0 + 73) = 0; - } - else - { - *((_DWORD *)v0 + 73) = v1 + 1; - if ( v1 + 1 > 7 ) - *((_DWORD *)v0 + 73) = 4; - } + *((_DWORD *)v0 + 73) = v1 + 1; + if ( v1 + 1 > 4 ) + *((_DWORD *)v0 + 73) = 0; + } + else + { + *((_DWORD *)v0 + 73) = v1 + 1; + if ( v1 + 1 > 7 ) + *((_DWORD *)v0 + 73) = 4; } - goto LABEL_145; } + } else if ( (sub_485880(DIK_RMENU, 0) || sub_485880(DIK_LMENU, 0)) && sub_485880(DIK_H, 0) ) { + // Alt (Right or Left) + H + + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + //FIXME: What does this do?! - if ( (sub_485880(DIK_RMENU, 0) || sub_485880(DIK_LMENU, 0)) && sub_485880(DIK_H, 0) ) - { - if ( dword_4D79EC ) - goto LABEL_146; - dword_4D79EC = 1; - dword_EC83C8 = 1; - goto LABEL_145; - } + dword_EC83C8 = 1; + } else if ( dword_50C07C == 2 ) { - if ( dword_50C07C != 2 ) - goto LABEL_66; + // We are in the pause menu??? (or in a race???) + //FIXME: Not sure + + if ( sub_485880(DIK_LCONTROL, 0) || sub_485880(DIK_RCONTROL, 0) ) { + + // Control (Left or Right) + + if ( sub_485880(DIK_F10, 0) ) { + + // F10 - // Control (Left or Right) - if ( sub_485880(DIK_LCONTROL, 0) || sub_485880(DIK_RCONTROL, 0) ) - { - // F10 - if ( sub_485880(DIK_F10, 0) ) - { if ( dword_4D79EC ) goto LABEL_146; - if ( dword_4D5E00 ) - goto LABEL_134; - dword_50C048 ^= 4u; - sub_440550(40); -LABEL_65: + + //FIXME: What does this do? + if ( !dword_4D5E00 ) { + dword_50C048 ^= 4u; + sub_440550(40); + } + dword_4D79EC = 1; - goto LABEL_145; } - } - else - { + + } else if ( sub_485880(DIK_MULTIPLY, 0) && sub_485880(DIK_T, 0) ) { // Multiply (Numpad) + T - //FIXME What is this? - if ( sub_485880(DIK_MULTIPLY, 0) && sub_485880(DIK_T, 0) ) - { - if ( !dword_4D5E00 ) - { - if ( dword_4D79EC ) - goto LABEL_146; - dword_50CB68 ^= 1u; - sub_440550(44); - dword_4D79EC = 1; - goto LABEL_145; - } - goto LABEL_66; + + //FIXME: What does this do? + if ( !dword_4D5E00 ) { + if ( dword_4D79EC ) + goto LABEL_146; + + // Make the game very fast?! + dword_50CB68 ^= 1u; + sub_440550(44); + + dword_4D79EC = 1; } + } else if ( sub_485880(DIK_I, 0) && sub_485880(DIK_F, 0) && sub_485880(DIK_L, 0) && sub_485880(DIK_Y, 0)) { // I + F + L + Y - //FIXME: What does this do? - if ( sub_485880(DIK_I, 0) && sub_485880(DIK_F, 0) && sub_485880(DIK_L, 0) && sub_485880(DIK_Y, 0) && !dword_4D5E00 ) - { + + //FIXME: What does this do? + if (!dword_4D5E00 ) { if ( dword_4D79EC ) goto LABEL_146; + + //FIXME: What does this do? dword_50C048 ^= 0x2000u; sub_440550(43); - goto LABEL_65; - } + dword_4D79EC = 1; + } } -LABEL_66: + + } else if ( sub_485880(DIK_LCONTROL, 0) || sub_485880(DIK_RCONTROL, 0) ) { // Control (Left or Right) - if ( sub_485880(DIK_LCONTROL, 0) || sub_485880(DIK_RCONTROL, 0) ) - { + + if ( sub_485880(DIK_J, 0) ) { // J - if ( sub_485880(DIK_J, 0) ) - { - if ( dword_4D79EC ) - goto LABEL_146; - dword_4D79EC = 1; - if ( !dword_4B294C ) - { - v2 = sub_421360(aMondotextH0035); - goto LABEL_112; - } - if ( dword_4B2944 ) - { + + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + + if ( !dword_4B294C ) { + + v2 = sub_421360(aMondotextH0035); + strcat(&byte_4D78D0, v2); + + } else { + + if ( dword_4B2944 ) { strcat(&byte_4D78D0, sub_421360(aMondotextH0364)); dword_4D79D0 = dword_4B2910; if ( dword_4B2910 ) sub_40A120(1); dword_4B2910 = 0; - } - else - { + } else { strcat(&byte_4D78D0, sub_421360(aMondotextH0363)); dword_4B2910 = dword_4D79D0; } sub_440550(70); dword_4B2944 = dword_4B2944 == 0; - if ( !dword_4B2940 ) - { + if ( !dword_4B2940 ) { v3 = sub_414D90(0, 24); sub_40B740(0, v3); } + v4 = sub_411810(); - if ( !dword_4B2940 && v4 ) - { - v5 = *(_DWORD *)(v4 + 28) == 24; - goto LABEL_104; + if ( dword_4B2940 || !v4 || (*(_DWORD *)(v4 + 28) != 24)) { + sub_406080((int)aCurrent); } - goto LABEL_105; + } + } else if ( sub_485880(DIK_LMENU, 0) && *(_DWORD *)(dword_50C454 + 8) == 13 ) { // Alt (Left) - if ( sub_485880(DIK_LMENU, 0) && *(_DWORD *)(dword_50C454 + 8) == 13 ) - { + //FIXME: What's the other condition? + + if ( sub_485880(DIK_RMENU, 0) ) { // Alt (Right) - if ( sub_485880(DIK_RMENU, 0) ) + + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + if ( !dword_4D5E00 ) { - if ( dword_4D79EC ) - goto LABEL_146; - dword_4D79EC = 1; - if ( !dword_4D5E00 ) - { - v6 = dword_E996DC; - BYTE1(v6) |= 0x40u; - dword_E996DC = v6; - *(_BYTE *)(dword_50C454 + 110) = *(_BYTE *)(dword_50C454 + 110) == 0; - sub_440550(46); - } - goto LABEL_145; + v6 = dword_E996DC; + BYTE1(v6) |= 0x40u; + dword_E996DC = v6; + *(_BYTE *)(dword_50C454 + 110) = *(_BYTE *)(dword_50C454 + 110) == 0; + sub_440550(46); } + } else if ( sub_485880(DIK_RCONTROL, 0) ) { // Control (Right) - if ( sub_485880(DIK_RCONTROL, 0) ) - { - if ( dword_4D79EC ) - goto LABEL_146; - dword_4D79EC = 1; - if ( !dword_4D5E00 ) - { - dword_E996DC &= 0xFFFFBFFF; - *(_BYTE *)(dword_50C454 + 110) = *(_BYTE *)(dword_50C454 + 110) == 0; - sub_440550(47); - } - goto LABEL_145; - } - } - // M - if ( sub_485880(DIK_M, 0) ) - { if ( dword_4D79EC ) goto LABEL_146; dword_4D79EC = 1; - if ( !dword_4B2950 ) + if ( !dword_4D5E00 ) { - v2 = sub_421360(aMondotextH0036); - goto LABEL_112; + dword_E996DC &= 0xFFFFBFFF; + *(_BYTE *)(dword_50C454 + 110) = *(_BYTE *)(dword_50C454 + 110) == 0; + sub_440550(47); } - if ( dword_4D6B38 ) + } + } else if ( sub_485880(DIK_M, 0) ) { + + // M + + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + + if (!dword_4B2950 ) { + v2 = sub_421360(aMondotextH0036); + strcat(&byte_4D78D0, v2); + } else { + + if ( dword_4D6B38 ) { v7 = sub_421360(aMondotextH0366); - else + } else { v7 = sub_421360(aMondotextH0365); + } + strcat(&byte_4D78D0, v7); sub_440550(70); dword_4D6B38 = dword_4D6B38 == 0; - if ( !dword_4B2940 ) - { + if ( !dword_4B2940 ) { v8 = sub_414D90(0, 25); sub_40B740(1, v8); } + v9 = sub_411810(); - if ( !dword_4B2940 && v9 ) - { - v5 = *(_DWORD *)(v9 + 28) == 25; -LABEL_104: - if ( v5 ) - goto LABEL_145; + if ( dword_4B2940 || !v9 || ( *(_DWORD *)(v9 + 28) != 25 )) { + sub_406080((int)aCurrent); } -LABEL_105: - sub_406080((int)aCurrent); - goto LABEL_145; + } + } else if ( sub_485880(DIK_F, 0) ) { + // F - if ( sub_485880(DIK_F, 0) ) - { - if ( dword_4D79EC ) - goto LABEL_146; - dword_4D79EC = 1; - if ( dword_4B2914 ) - { - if ( dword_4D765C ) - { - if ( dword_4B2910 || !dword_4B4938 ) - { - strcat(&byte_4D78D0, sub_421360(aMondotextH0370)); - sub_40A120(1); - } - else - { - strcat(&byte_4D78D0, sub_421360(aMondotextH0369)); - } - sub_440550(70); - if ( dword_4B2910 || (dword_4B2910 = 1, !dword_4B4938) ) - dword_4B2910 = 0; - v10 = sub_414D90(0, 27); - sub_40C100(v10); - v11 = sub_411810(); - if ( dword_4B2940 || !v11 || *(_DWORD *)(v11 + 28) != 27 ) - sub_40AB80((int)aCurrent); - goto LABEL_145; - } - v2 = sub_421360(aMondotextH0368); + + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + + if ( !dword_4B2914 ) { + v2 = sub_421360(aMondotextH0042); // No device detected + strcat(&byte_4D78D0, v2); + } else if ( !dword_4D765C ) { + v2 = sub_421360(aMondotextH0368); // No force-effects loaded + strcat(&byte_4D78D0, v2); + } else { + + if ( dword_4B2910 || !dword_4B4938 ) { + strcat(&byte_4D78D0, sub_421360(aMondotextH0370)); + sub_40A120(1); + } else { + strcat(&byte_4D78D0, sub_421360(aMondotextH0369)); } - else - { - v2 = sub_421360(aMondotextH0042); + + sub_440550(70); + if ( dword_4B2910 || (dword_4B2910 = 1, !dword_4B4938) ) { + dword_4B2910 = 0; + } + + //FIXME: sub_414D90 is ran conditionally for mice and joysticks - why not here? + //FIXME: Bug in RE or game? + v10 = sub_414D90(0, 27); + sub_40C100(v10); + + v11 = sub_411810(); + if ( dword_4B2940 || !v11 || *(_DWORD *)(v11 + 28) != 27 ) { + sub_40AB80((int)aCurrent); } -LABEL_112: - strcat(&byte_4D78D0, v2); - goto LABEL_145; - } - // Q - if ( sub_485880(DIK_Q, 0) && dword_4D5E00 ) - { - if ( dword_4D79EC ) - goto LABEL_146; - dword_4D79EC = 1; - v13 = 1348564851; - v14 = -1; - v15 = 1; - sub_450C50(1097624609, (int)&v13); - goto LABEL_145; } + } else if ( sub_485880(DIK_Q, 0) && dword_4D5E00 ) { + + // Q (only in network mode) + + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + + // Send packet to network + uint32_t packet[3]; // [esp+14h] [ebp-20h] + packet[0] = 1348564851; // 'Paws' + packet[1] = -1; + packet[2] = 1; + sub_450C50(1097624609, packet); // 'All!' + + } else if ( sub_485880(DIK_F11, 0) ) { + // F11 - if ( sub_485880(DIK_F11, 0) ) - { - if ( dword_4D79EC ) - goto LABEL_146; - dword_4D79EC = 1; - dword_4D79DC = dword_4D79DC == 0; - goto LABEL_145; - } + + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + dword_4D79DC = dword_4D79DC == 0; } + } else if ( sub_485880(DIK_F7, 0) ) { + // F7 - if ( !sub_485880(DIK_F7, 0) ) - { - // F5 or F6 - if ( sub_485880(DIK_F5, 0) || sub_485880(DIK_F6, 0) ) - { - if ( dword_4D79EC ) - goto LABEL_146; - dword_4D79E0 = 1; - dword_4D79EC = 1; - } - // Scroll lock + Home - //FIXME: What does this do?! - else if ( sub_485880(DIK_SCROLL, 0) && sub_485880(DIK_HOME, 0) ) - { - if ( dword_4D79EC ) - goto LABEL_146; - dword_4D79EC = 1; - if ( *(_DWORD *)(dword_50C454 + 8) == 9 ) - { - dword_50C048 ^= 0x40u; - sub_43D9A0(); - } - } - else - { - dword_4D79EC = 0; - } - goto LABEL_145; - } if ( dword_4D79EC ) goto LABEL_146; sub_440550(70); sub_41BDD0(); -LABEL_134: dword_4D79EC = 1; - goto LABEL_145; - } + } else if ( sub_485880(DIK_F5, 0) || sub_485880(DIK_F6, 0) ) { + + // F5 or F6 - if ( !dword_4D79EC ) - { + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79E0 = 1; dword_4D79EC = 1; + } else if ( sub_485880(DIK_SCROLL, 0) && sub_485880(DIK_HOME, 0) ) { - // Enable Cy Junga - sub_44B5E0(); + // Scroll lock + Home - sub_440550(-1); - goto LABEL_145; + if ( dword_4D79EC ) + goto LABEL_146; + dword_4D79EC = 1; + + if ( *(_DWORD *)(dword_50C454 + 8) == 9 ) { + dword_50C048 ^= 0x40u; + + // Unlock all tracks and podracers + sub_43D9A0(); + } + + } else { + dword_4D79EC = 0; + } + + if ( !dword_4D79EC ) { + return; } LABEL_146: - if ( byte_4D78D0 ) - { - sub_44FCE0((int)&byte_4D78D0, 2.0); + if ( byte_4D78D0 ) { + sub_44FCE0((int)&byte_4D78D0, 2.0f); byte_4D78D0 = 0; - dword_4D5564 = 1074161254; + dword_4D5564 = 2.1f; } - if ( v12 != dword_E35A98[0] ) - { - if ( dword_EC83CC >= 5000 ) + + // Check if the cache value of truguts was changed + // (Happens when pressing Shift + F4 + 4) + if ( v12 != dword_E35A98[0] ) { + + //FIXME: What is dword_EC83CC ? + if ( dword_EC83CC >= 5000 ) { dword_E35A98[0] = v12; - else + } else { dword_EC83CC += 1000; + } + } + + return; }