Corrected the key overriding mechanism and removed unused vKey argument from KeyPressedDelegate (from Mr.Stalin)

Changed the debug editor to require sfall debugging mode.
Some minor code edits.
This commit is contained in:
NovaRain
2018-10-29 11:04:51 +08:00
parent 88779c10e0
commit a10196e2ca
10 changed files with 24 additions and 40 deletions
+4 -3
View File
@@ -148,8 +148,9 @@ ItemFastMoveKey=29
;Requires ItemFastMoveKey to be enabled
FastMoveFromContainer=0
;A key to press to open a debug game editor (requires FalloutClient.exe from the modders pack)
;A key to press to open a debug game editor
;Set to 0 to disable, or a DX scancode otherwise
;Requires FalloutClient.exe from the modders pack and sfall debugging mode
DebugEditorKey=0
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
@@ -685,12 +686,12 @@ DebugMode=0
SkipCompatModeCheck=0
;Set to 1 to skip the executable file size check
;Does not require enabling sfall debugging mode
;Does not require sfall debugging mode
SkipSizeCheck=0
;If you're testing changes to the Fallout exe, you can override the CRC that sfall looks for here
;You can use several hex values, separated by commas
;Does not require enabling sfall debugging mode
;Does not require sfall debugging mode
;ExtraCRC=0x00000000,0x00000000
;Set to 1 to stop Fallout from deleting non readonly protos at startup
+5 -4
View File
@@ -25,10 +25,11 @@
#include "Logging.h"
#include "FalloutEngine\Fallout2.h"
#include "Modules\Graphics.h"
#include "Modules\HookScripts.h"
#include "InputFuncs.h"
namespace sfall
namespace sfall
{
bool useScrollWheel = true;
@@ -111,7 +112,7 @@ DWORD _stdcall KeyDown(DWORD key) {
return 0;
} else {
DWORD keyVK = 0;
if (keysDown[key]) { // confirm pressed state
if (keysDown[key]) { // confirm pressed state
keyVK = MapVirtualKeyEx(key, MAPVK_VSC_TO_VK, keyboardLayout);
if (keyVK) keysDown[key] = (GetAsyncKeyState(keyVK) & 0x8000);
}
@@ -276,10 +277,10 @@ public:
for (DWORD i = 0; i < *c; i++) {
DWORD dxKey = b[i].dwOfs;
DWORD state = b[i].dwData & 0x80;
onKeyPressed.invoke(&dxKey, (state > 0), MapVirtualKeyEx(dxKey, MAPVK_VSC_TO_VK, keyboardLayout));
HookScripts::KeyPressHook(&dxKey, (state > 0), MapVirtualKeyEx(dxKey, MAPVK_VSC_TO_VK, keyboardLayout));
if (dxKey != b[i].dwOfs && dxKey > 0) b[i].dwOfs = dxKey; // Override key
keysDown[b[i].dwOfs] = state;
onKeyPressed.invoke(b[i].dwOfs, (state > 0));
}
return hr;
}
+1 -1
View File
@@ -34,7 +34,7 @@ void SetMPos(int x, int y);
DWORD _stdcall KeyDown(DWORD key);
void _stdcall TapKey(DWORD key);
typedef Delegate<DWORD*, bool, DWORD> KeyPressedDelegate;
typedef Delegate<DWORD, bool> KeyPressedDelegate;
typedef Delegate<DWORD, bool> MouseClickedDelegate;
KeyPressedDelegate& OnKeyPressed();
+1 -2
View File
@@ -1824,8 +1824,7 @@ void BugFixes::init()
//if (GetConfigInt("Misc", "MultiHexPathingFix", 1)) {
dlog("Applying MultiHex Pathing Fix.", DL_INIT);
MakeCall(0x42901F, MultiHexFix);
MakeCall(0x429170, MultiHexFix);
MakeCalls(MultiHexFix, {0x42901F, 0x429170});
// Fix for multihex critters moving too close and overlapping their targets in combat
MakeCall(0x42A14F, MultiHexCombatRunFix);
SafeWrite8(0x42A154, 0x90);
+3 -2
View File
@@ -241,10 +241,11 @@ void RunDebugEditor() {
static DWORD debugEditorKey = 0;
void DebugEditor::init() {
if (!isDebug) return;
debugEditorKey = GetConfigInt("Input", "DebugEditorKey", 0);
if (debugEditorKey != 0) {
OnKeyPressed() += [](DWORD* scanCode, bool pressed, DWORD vkCode) {
if (*scanCode == debugEditorKey && pressed && IsMapLoaded()) {
OnKeyPressed() += [](DWORD scanCode, bool pressed) {
if (scanCode == debugEditorKey && pressed && IsMapLoaded()) {
RunDebugEditor();
}
};
+1 -15
View File
@@ -264,21 +264,7 @@ int CheckFile(char*FileName, DWORD *size_out) {
//-----------------------------------------
char _stdcall GetSex(void) {
using fo::STAT_gender;
char sex;
__asm {
mov edx, STAT_gender //sex stat ref
mov eax, dword ptr ds:[FO_VAR_obj_dude] //hero state structure
call fo::funcoffs::stat_level_ //get Player stat val
test eax, eax //male=0, female=1
jne Female
mov sex, 'M'
jmp EndFunc
Female:
mov sex, 'F'
EndFunc:
}
return sex;
return (fo::HeroIsFemale()) ? 'F' : 'M';
}
// functions to load and save appearance globals
+1 -2
View File
@@ -87,7 +87,7 @@ DWORD initingHookScripts;
// BEGIN HOOKS
void _stdcall KeyPressHook(DWORD* dxKey, bool pressed, DWORD vKey) {
void HookScripts::KeyPressHook(DWORD* dxKey, bool pressed, DWORD vKey) {
if (!IsMapLoaded()) {
return;
}
@@ -226,7 +226,6 @@ void _stdcall RunHookScriptsAtProc(DWORD procId) {
}
void HookScripts::init() {
OnKeyPressed() += KeyPressHook;
OnMouseClick() += MouseClickHook;
LoadGameHook::OnGameModeChange() += GameModeChangeHook;
LoadGameHook::OnAfterGameStarted() += SourceUseSkillOnInit;
+1
View File
@@ -76,6 +76,7 @@ public:
static bool injectAllHooks;
static void GameModeChangeHook(DWORD exit);
static void KeyPressHook(DWORD* dxKey, bool pressed, DWORD vKey);
};
DWORD _stdcall GetHSArgCount();
+4 -5
View File
@@ -25,12 +25,12 @@ DWORD cRetTmp; // how many return values were set by specific hook script (when
std::vector<HookScript> hooks[numHooks];
void LoadHookScript(const char* name, int id) {
if (id >= numHooks) return;
if (id >= numHooks || IsGameScript(name)) return;
char filename[MAX_PATH];
sprintf(filename, "scripts\\%s.int", name);
if (fo::func::db_access(filename) && !IsGameScript(name)) {
ScriptProgram prog;
ScriptProgram prog;
if (fo::func::db_access(filename)) {
dlog(">", DL_HOOK);
dlog(name, DL_HOOK);
LoadScriptProgram(prog, name);
@@ -42,12 +42,11 @@ void LoadHookScript(const char* name, int id) {
hook.isGlobalScript = false;
hooks[id].push_back(hook);
AddProgramToMap(prog);
if (!HookScripts::injectAllHooks) HookScripts::InjectingHook(id); // inject hook to engine code
} else {
dlogr(" Error!", DL_HOOK);
}
}
if (HookScripts::injectAllHooks) HookScripts::InjectingHook(id);
if (HookScripts::injectAllHooks || prog.ptr != nullptr) HookScripts::InjectingHook(id); // inject hook to engine code
}
void _stdcall BeginHook() {
+3 -6
View File
@@ -38,9 +38,9 @@ static DWORD reloadWeaponKey = 0;
static DWORD itemFastMoveKey = 0;
static DWORD skipFromContainer = 0;
void InventoryKeyPressedHook(DWORD* dxKey, bool pressed, DWORD vKey) {
void InventoryKeyPressedHook(DWORD dxKey, bool pressed) {
// TODO: move this out into a script
if (pressed && reloadWeaponKey && *dxKey == reloadWeaponKey && IsMapLoaded() && (GetLoopFlags() & ~(COMBAT | PCOMBAT)) == 0) {
if (pressed && reloadWeaponKey && dxKey == reloadWeaponKey && IsMapLoaded() && (GetLoopFlags() & ~(COMBAT | PCOMBAT)) == 0) {
DWORD maxAmmo, curAmmo;
fo::GameObject* item = fo::GetActiveItem();
maxAmmo = fo::func::item_w_max_ammo(item);
@@ -87,7 +87,6 @@ DWORD __stdcall sf_item_total_size(fo::GameObject* critter) {
/*static const DWORD ObjPickupFail=0x49B70D;
static const DWORD ObjPickupEnd=0x49B6F8;
static const DWORD size_limit;
static __declspec(naked) void ObjPickupHook() {
__asm {
cmp edi, ds:[FO_VAR_obj_dude];
@@ -836,7 +835,7 @@ void Inventory::init() {
// Move items out of bag/backpack and back into the main inventory list by dragging them to character's image
// (similar to Fallout 1 behavior)
HookCall(0x471457, &inven_pickup_hook);
HookCall(0x471457, inven_pickup_hook);
// Move items to player's main inventory instead of the opened bag/backpack when confirming a trade
SafeWrite32(0x475CF2, FO_VAR_stack);
@@ -853,6 +852,4 @@ Delegate<DWORD>& Inventory::OnAdjustFid() {
return onAdjustFid;
}
}