From c1b7e729a80ce3c6b684892eb7431f9c6749976c Mon Sep 17 00:00:00 2001 From: NovaRain Date: Fri, 14 Aug 2020 00:39:09 +0800 Subject: [PATCH] Reorganized KeyPress hook & related code * now it should work in exactly the same way as 4.x. Improved the key press behavior for Debug Editor. Implemented ScriptListInfoItem struct from 4.x. --- sfall/DebugEditor.cpp | 16 +- sfall/DebugEditor.h | 2 +- sfall/FalloutEngine.cpp | 444 +++++++++++++++++++-------------------- sfall/FalloutEngine.h | 2 +- sfall/FalloutStructs.h | 6 + sfall/HookScripts.cpp | 12 +- sfall/HookScripts.h | 2 +- sfall/InputFuncs.cpp | 35 +-- sfall/InputFuncs.h | 1 + sfall/ScriptExtender.cpp | 2 +- 10 files changed, 271 insertions(+), 251 deletions(-) diff --git a/sfall/DebugEditor.cpp b/sfall/DebugEditor.cpp index 50a7ac43..944aaf82 100644 --- a/sfall/DebugEditor.cpp +++ b/sfall/DebugEditor.cpp @@ -21,10 +21,13 @@ #include "main.h" #include "FalloutEngine.h" #include "Arrays.h" -#include "DebugEditor.h" #include "Graphics.h" +#include "InputFuncs.h" +#include "LoadGameHook.h" #include "ScriptExtender.h" +#include "DebugEditor.h" + enum DECode { CODE_SET_GLOBAL = 0, CODE_SET_MAPVAR = 1, @@ -45,6 +48,8 @@ enum DECode { static const char* debugLog = "LOG"; static const char* debugGnw = "GNW"; +static DWORD debugEditorKey = 0; + struct sArray { DWORD id; long isMap; @@ -224,6 +229,7 @@ static void RunEditorInternal(SOCKET &s) { delete[] sglobals; delete[] arrays; + FlushInputBuffer(); *(DWORD*)_script_engine_running = 1; } @@ -404,4 +410,12 @@ void DebugEditorInit() { if (!isDebug) return; DontDeleteProtosPatch(); + + debugEditorKey = GetConfigInt("Input", "DebugEditorKey", 0); +} + +void DebugEditorKeyPressedHook(DWORD scanCode, bool pressed) { + if (debugEditorKey != 0 && scanCode == debugEditorKey && pressed && IsGameLoaded()) { + RunDebugEditor(); + } } diff --git a/sfall/DebugEditor.h b/sfall/DebugEditor.h index 22f17dec..fe4de3a3 100644 --- a/sfall/DebugEditor.h +++ b/sfall/DebugEditor.h @@ -1,4 +1,4 @@ #pragma once void DebugEditorInit(); -void RunDebugEditor(); +void DebugEditorKeyPressedHook(DWORD scanCode, bool pressed); diff --git a/sfall/FalloutEngine.cpp b/sfall/FalloutEngine.cpp index 9dbbc05f..8a9f5db1 100644 --- a/sfall/FalloutEngine.cpp +++ b/sfall/FalloutEngine.cpp @@ -22,229 +22,229 @@ #include "Logging.h" // global variables -long* ptr_pc_traits = reinterpret_cast(_pc_trait); // 2 of them +long* ptr_pc_traits = reinterpret_cast(_pc_trait); // 2 of them -DWORD* ptr_aiInfoList = reinterpret_cast(_aiInfoList); -DWORD* ptr_ambient_light = reinterpret_cast(_ambient_light); -sArt* ptr_art = reinterpret_cast(_art); // array of 11 sArt -DWORD* ptr_art_name = reinterpret_cast(_art_name); -DWORD* ptr_art_vault_guy_num = reinterpret_cast(_art_vault_guy_num); -DWORD* ptr_art_vault_person_nums = reinterpret_cast(_art_vault_person_nums); -DWORD* ptr_background_volume = reinterpret_cast(_background_volume); -BYTE** ptr_bckgnd = reinterpret_cast(_bckgnd); -DWORD* ptr_black_palette = reinterpret_cast(_black_palette); -BYTE* ptr_BlueColor = reinterpret_cast(_BlueColor); -DWORD* ptr_bottom_line = reinterpret_cast(_bottom_line); -DWORD* ptr_btable = reinterpret_cast(_btable); -DWORD* ptr_btncnt = reinterpret_cast(_btncnt); -DWORD* ptr_CarCurrArea = reinterpret_cast(_CarCurrArea); -DWORD* ptr_cmap = reinterpret_cast(_cmap); -DWORD* ptr_colorTable = reinterpret_cast(_colorTable); -DWORD* ptr_combat_free_move = reinterpret_cast(_combat_free_move); -DWORD* ptr_combat_list = reinterpret_cast(_combat_list); -DWORD* ptr_combat_state = reinterpret_cast(_combat_state); -DWORD* ptr_combat_turn_running = reinterpret_cast(_combat_turn_running); -DWORD* ptr_combatNumTurns = reinterpret_cast(_combatNumTurns); -DWORD* ptr_crit_succ_eff = reinterpret_cast(_crit_succ_eff); -PathNode** ptr_critter_db_handle = reinterpret_cast(_critter_db_handle); -DWORD* ptr_critterClearObj = reinterpret_cast(_critterClearObj); -DWORD* ptr_crnt_func = reinterpret_cast(_crnt_func); -DWORD* ptr_curr_font_num = reinterpret_cast(_curr_font_num); -DWORD* ptr_curr_pc_stat = reinterpret_cast(_curr_pc_stat); -DWORD* ptr_curr_stack = reinterpret_cast(_curr_stack); -TProgram** ptr_currentProgram = reinterpret_cast(_currentProgram); -DWORD* ptr_cursor_line = reinterpret_cast(_cursor_line); -BYTE* ptr_DARK_GREY_Color = reinterpret_cast(_DARK_GREY_Color); -BYTE* ptr_DarkGreenColor = reinterpret_cast(_DarkGreenColor); -BYTE* ptr_DarkGreenGreyColor = reinterpret_cast(_DarkGreenGreyColor); -TGameObj** ptr_dialog_target = reinterpret_cast(_dialog_target); -DWORD* ptr_dialog_target_is_party = reinterpret_cast(_dialog_target_is_party); -const DWORD* ptr_dialogueBackWindow = reinterpret_cast(_dialogueBackWindow); -DWORD* ptr_drugInfoList = reinterpret_cast(_drugInfoList); -BYTE* ptr_DullPinkColor = reinterpret_cast(_DullPinkColor); -const DWORD* ptr_edit_win = reinterpret_cast(_edit_win); -DWORD* ptr_Educated = reinterpret_cast(_Educated); -DWORD* ptr_elevation = reinterpret_cast(_elevation); -DWORD* ptr_endgame_subtitle_done = reinterpret_cast(_endgame_subtitle_done); -DWORD* ptr_Experience_ = reinterpret_cast(_Experience_); -DWORD* ptr_fallout_game_time = reinterpret_cast(_fallout_game_time); -DWORD* ptr_fidgetFID = reinterpret_cast(_fidgetFID); -DWORD* ptr_flptr = reinterpret_cast(_flptr); -DWORD* ptr_folder_card_desc = reinterpret_cast(_folder_card_desc); -DWORD* ptr_folder_card_fid = reinterpret_cast(_folder_card_fid); -DWORD* ptr_folder_card_title = reinterpret_cast(_folder_card_title); -DWORD* ptr_folder_card_title2 = reinterpret_cast(_folder_card_title2); -DWORD* ptr_frame_time = reinterpret_cast(_frame_time); -char* ptr_free_perk = reinterpret_cast(_free_perk); -long** ptr_game_global_vars = reinterpret_cast(_game_global_vars); // dynamic array of size == num_game_global_vars -DWORD* ptr_game_user_wants_to_quit = reinterpret_cast(_game_user_wants_to_quit); -CombatGcsd** ptr_gcsd = reinterpret_cast(_gcsd); -DWORD* ptr_gdBarterMod = reinterpret_cast(_gdBarterMod); -DWORD* ptr_gdNumOptions = reinterpret_cast(_gdNumOptions); -DWORD* ptr_gIsSteal = reinterpret_cast(_gIsSteal); -DWORD* ptr_glblmode = reinterpret_cast(_glblmode); -long* ptr_gmouse_current_cursor = reinterpret_cast(_gmouse_current_cursor); -DWORD* ptr_gmovie_played_list = reinterpret_cast(_gmovie_played_list); -BYTE* ptr_GoodColor = reinterpret_cast(_GoodColor); -BYTE* ptr_GreenColor = reinterpret_cast(_GreenColor); -DWORD* ptr_gsound_initialized = reinterpret_cast(_gsound_initialized); -long* ptr_hit_location_penalty = reinterpret_cast(_hit_location_penalty); -DWORD* ptr_holo_flag = reinterpret_cast(_holo_flag); -DWORD* ptr_holopages = reinterpret_cast(_holopages); -DWORD* ptr_hot_line_count = reinterpret_cast(_hot_line_count); -DWORD* ptr_i_fid = reinterpret_cast(_i_fid); -TGameObj** ptr_i_lhand = reinterpret_cast(_i_lhand); -TGameObj** ptr_i_rhand = reinterpret_cast(_i_rhand); -const DWORD* ptr_i_wid = reinterpret_cast(_i_wid); -TGameObj** ptr_i_worn = reinterpret_cast(_i_worn); -void** ptr_idle_func = reinterpret_cast(_idle_func); -DWORD* ptr_In_WorldMap = reinterpret_cast(_In_WorldMap); // moving in WorldMap -DWORD* ptr_info_line = reinterpret_cast(_info_line); -const DWORD* ptr_interfaceWindow = reinterpret_cast(_interfaceWindow); -DWORD* ptr_intfaceEnabled = reinterpret_cast(_intfaceEnabled); -DWORD* ptr_intotal = reinterpret_cast(_intotal); -TGameObj** ptr_inven_dude = reinterpret_cast(_inven_dude); -DWORD* ptr_inven_pid = reinterpret_cast(_inven_pid); -DWORD* ptr_inven_scroll_dn_bid = reinterpret_cast(_inven_scroll_dn_bid); -DWORD* ptr_inven_scroll_up_bid = reinterpret_cast(_inven_scroll_up_bid); -MSGList* ptr_inventry_message_file = reinterpret_cast(_inventry_message_file); -ItemButtonItem* ptr_itemButtonItems = reinterpret_cast(_itemButtonItems); // array of 2 ItemButtonItem -long* ptr_itemCurrentItem = reinterpret_cast(_itemCurrentItem); // 0 - left, 1 - right -DWORD* ptr_kb_lock_flags = reinterpret_cast(_kb_lock_flags); -DWORD* ptr_last_buttons = reinterpret_cast(_last_buttons); -DWORD* ptr_last_button_winID = reinterpret_cast(_last_button_winID); -DWORD* ptr_last_level = reinterpret_cast(_last_level); -DWORD* ptr_Level_ = reinterpret_cast(_Level_); -DWORD* ptr_Lifegiver = reinterpret_cast(_Lifegiver); -BYTE* ptr_LIGHT_GREY_Color = reinterpret_cast(_LIGHT_GREY_Color); -DWORD* ptr_lipsFID = reinterpret_cast(_lipsFID); -DWORD* ptr_list_com = reinterpret_cast(_list_com); -DWORD* ptr_list_total = reinterpret_cast(_list_total); -DWORD* ptr_loadingGame = reinterpret_cast(_loadingGame); -DWORD* ptr_LSData = reinterpret_cast(_LSData); -DWORD* ptr_lsgwin = reinterpret_cast(_lsgwin); -TComputeAttack* ptr_main_ctd = reinterpret_cast(_main_ctd); -DWORD* ptr_main_death_voiceover_done = reinterpret_cast(_main_death_voiceover_done); -DWORD* ptr_main_window = reinterpret_cast(_main_window); -DWORD* ptr_map_elevation = reinterpret_cast(_map_elevation); -long** ptr_map_global_vars = reinterpret_cast(_map_global_vars); // array -DWORD* ptr_map_number = reinterpret_cast(_map_number); -PathNode** ptr_master_db_handle = reinterpret_cast(_master_db_handle); -DWORD* ptr_master_volume = reinterpret_cast(_master_volume); -DWORD* ptr_max = reinterpret_cast(_max); -long* ptr_maxScriptNum = reinterpret_cast(_maxScriptNum); -bool* ptr_Meet_Frank_Horrigan = reinterpret_cast(_Meet_Frank_Horrigan); -const char** ptr_movie_list = reinterpret_cast(_movie_list); // array of 17 char* -DWORD* ptr_mouse_hotx = reinterpret_cast(_mouse_hotx); -DWORD* ptr_mouse_hoty = reinterpret_cast(_mouse_hoty); -DWORD* ptr_mouse_is_hidden = reinterpret_cast(_mouse_is_hidden); -DWORD* ptr_mouse_x_ = reinterpret_cast(_mouse_x_); -DWORD* ptr_mouse_y = reinterpret_cast(_mouse_y); -DWORD* ptr_mouse_y_ = reinterpret_cast(_mouse_y_); -DWORD* ptr_Mutate_ = reinterpret_cast(_Mutate_); -DWORD* ptr_name_color = reinterpret_cast(_name_color); -DWORD* ptr_name_font = reinterpret_cast(_name_font); -DWORD* ptr_name_sort_list = reinterpret_cast(_name_sort_list); -DWORD* ptr_num_game_global_vars = reinterpret_cast(_num_game_global_vars); -DWORD* ptr_num_map_global_vars = reinterpret_cast(_num_map_global_vars); -DWORD* ptr_num_windows = reinterpret_cast(_num_windows); -TGameObj** ptr_obj_dude = reinterpret_cast(_obj_dude); -DWORD* ptr_objectTable = reinterpret_cast(_objectTable); -DWORD* ptr_objItemOutlineState = reinterpret_cast(_objItemOutlineState); -DWORD* ptr_optionRect = reinterpret_cast(_optionRect); -DWORD* ptr_optionsButtonDown = reinterpret_cast(_optionsButtonDown); -DWORD* ptr_optionsButtonDown1 = reinterpret_cast(_optionsButtonDown1); -DWORD* ptr_optionsButtonDownKey = reinterpret_cast(_optionsButtonDownKey); -DWORD* ptr_optionsButtonUp = reinterpret_cast(_optionsButtonUp); -DWORD* ptr_optionsButtonUp1 = reinterpret_cast(_optionsButtonUp1); -DWORD* ptr_optionsButtonUpKey = reinterpret_cast(_optionsButtonUpKey); -const DWORD* ptr_optnwin = reinterpret_cast(_optnwin); -DWORD* ptr_outlined_object = reinterpret_cast(_outlined_object); -DWORD* ptr_partyMemberAIOptions = reinterpret_cast(_partyMemberAIOptions); -DWORD* ptr_partyMemberCount = reinterpret_cast(_partyMemberCount); -DWORD** ptr_partyMemberLevelUpInfoList = reinterpret_cast(_partyMemberLevelUpInfoList); -DWORD** ptr_partyMemberList = reinterpret_cast(_partyMemberList); // each struct - 4 integers, first integer - objPtr -DWORD* ptr_partyMemberMaxCount = reinterpret_cast(_partyMemberMaxCount); -DWORD** ptr_partyMemberPidList = reinterpret_cast(_partyMemberPidList); -char** ptr_patches = reinterpret_cast(_patches); -PathNode** ptr_paths = reinterpret_cast(_paths); // array -DWORD* ptr_pc_crit_succ_eff = reinterpret_cast(_pc_crit_succ_eff); -DWORD* ptr_pc_kill_counts = reinterpret_cast(_pc_kill_counts); -char* ptr_pc_name = reinterpret_cast(_pc_name); -DWORD* ptr_pc_proto = reinterpret_cast(_pc_proto); -BYTE* ptr_PeanutButter = reinterpret_cast(_PeanutButter); -DWORD* ptr_perk_data = reinterpret_cast(_perk_data); -int** ptr_perkLevelDataList = reinterpret_cast(_perkLevelDataList); -const DWORD* ptr_pip_win = reinterpret_cast(_pip_win); -DWORD* ptr_pipboy_message_file = reinterpret_cast(_pipboy_message_file); -DWORD* ptr_pipmesg = reinterpret_cast(_pipmesg); -DWORD* ptr_preload_list_index = reinterpret_cast(_preload_list_index); -const char** ptr_procTableStrs = reinterpret_cast(_procTableStrs); // table of procId (from define.h) => procName map -MSGList* ptr_proto_main_msg_file = reinterpret_cast(_proto_main_msg_file); -MSGList* ptr_proto_msg_files = reinterpret_cast(_proto_msg_files); // array of 6 elements -DWORD* ptr_ptable = reinterpret_cast(_ptable); -DWORD* ptr_pud = reinterpret_cast(_pud); -DWORD* ptr_queue = reinterpret_cast(_queue); -DWORD* ptr_quick_done = reinterpret_cast(_quick_done); -DWORD* ptr_read_callback = reinterpret_cast(_read_callback); -BYTE* ptr_RedColor = reinterpret_cast(_RedColor); -DWORD* ptr_retvals = reinterpret_cast(_retvals); -DWORD* ptr_rotation = reinterpret_cast(_rotation); -BoundRect* ptr_scr_size = reinterpret_cast(_scr_size); -DWORD* ptr_scriptListInfo = reinterpret_cast(_scriptListInfo); -DWORD* ptr_skill_data = reinterpret_cast(_skill_data); -const DWORD* ptr_skldxwin = reinterpret_cast(_skldxwin); -DWORD* ptr_slot_cursor = reinterpret_cast(_slot_cursor); -DWORD* ptr_sndfx_volume = reinterpret_cast(_sndfx_volume); -DWORD* ptr_sneak_working = reinterpret_cast(_sneak_working); // DWORD var -char** ptr_sound_music_path1 = reinterpret_cast(_sound_music_path1); -char** ptr_sound_music_path2 = reinterpret_cast(_sound_music_path2); -DWORD* ptr_speech_volume = reinterpret_cast(_speech_volume); -DWORD* ptr_square = reinterpret_cast(_square); -DWORD* ptr_squares = reinterpret_cast(_squares); -DWORD* ptr_stack = reinterpret_cast(_stack); -DWORD* ptr_stack_offset = reinterpret_cast(_stack_offset); -DWORD* ptr_stat_data = reinterpret_cast(_stat_data); -DWORD* ptr_stat_flag = reinterpret_cast(_stat_flag); -DWORD* ptr_sWindows = reinterpret_cast(_sWindows); // total 16 sWindow struct -DWORD* ptr_Tag_ = reinterpret_cast(_Tag_); -DWORD* ptr_tag_skill = reinterpret_cast(_tag_skill); -DWORD* ptr_target_curr_stack = reinterpret_cast(_target_curr_stack); -DWORD** ptr_target_pud = reinterpret_cast(_target_pud); -DWORD* ptr_target_stack = reinterpret_cast(_target_stack); // array of 10 DWORD -DWORD* ptr_target_stack_offset = reinterpret_cast(_target_stack_offset); // array of 10 DWORD -DWORD* ptr_target_str = reinterpret_cast(_target_str); -DWORD* ptr_target_xpos = reinterpret_cast(_target_xpos); -DWORD* ptr_target_ypos = reinterpret_cast(_target_ypos); -DWORD* ptr_text_char_width = reinterpret_cast(_text_char_width); -DWORD* ptr_text_height = reinterpret_cast(_text_height); -DWORD* ptr_text_max = reinterpret_cast(_text_max); -DWORD* ptr_text_mono_width = reinterpret_cast(_text_mono_width); -DWORD* ptr_text_object_index = reinterpret_cast(_text_object_index); -FloatText** ptr_text_object_list = reinterpret_cast(_text_object_list); // array of 20 FloatText* -DWORD* ptr_text_spacing = reinterpret_cast(_text_spacing); -DWORD* ptr_text_to_buf = reinterpret_cast(_text_to_buf); -DWORD* ptr_text_width = reinterpret_cast(_text_width); -DWORD* ptr_tile = reinterpret_cast(_tile); -DWORD* ptr_title_color = reinterpret_cast(_title_color); -DWORD* ptr_title_font = reinterpret_cast(_title_font); -DWORD* ptr_trait_data = reinterpret_cast(_trait_data); -DWORD* ptr_view_page = reinterpret_cast(_view_page); -DWORD* ptr_wd_obj = reinterpret_cast(_wd_obj); -WINinfo** ptr_window = reinterpret_cast(_window); // array of 50 WINinfo* -BYTE* ptr_WhiteColor = reinterpret_cast(_WhiteColor); -DWORD* ptr_wmAreaInfoList = reinterpret_cast(_wmAreaInfoList); -const DWORD* ptr_wmBkWin = reinterpret_cast(_wmBkWin); -BYTE** ptr_wmBkWinBuf = reinterpret_cast(_wmBkWinBuf); -DWORD* ptr_wmLastRndTime = reinterpret_cast(_wmLastRndTime); -MSGList* ptr_wmMsgFile = reinterpret_cast(_wmMsgFile); -DWORD* ptr_wmNumHorizontalTiles = reinterpret_cast(_wmNumHorizontalTiles); -long* ptr_wmWorldOffsetX = reinterpret_cast(_wmWorldOffsetX); -long* ptr_wmWorldOffsetY = reinterpret_cast(_wmWorldOffsetY); -DWORD* ptr_world_xpos = reinterpret_cast(_world_xpos); -DWORD* ptr_world_ypos = reinterpret_cast(_world_ypos); -DWORD* ptr_WorldMapCurrArea = reinterpret_cast(_WorldMapCurrArea); -BYTE* ptr_YellowColor = reinterpret_cast(_YellowColor); +DWORD* ptr_aiInfoList = reinterpret_cast(_aiInfoList); +DWORD* ptr_ambient_light = reinterpret_cast(_ambient_light); +sArt* ptr_art = reinterpret_cast(_art); // array of 11 sArt +DWORD* ptr_art_name = reinterpret_cast(_art_name); +DWORD* ptr_art_vault_guy_num = reinterpret_cast(_art_vault_guy_num); +DWORD* ptr_art_vault_person_nums = reinterpret_cast(_art_vault_person_nums); +DWORD* ptr_background_volume = reinterpret_cast(_background_volume); +BYTE** ptr_bckgnd = reinterpret_cast(_bckgnd); +DWORD* ptr_black_palette = reinterpret_cast(_black_palette); +BYTE* ptr_BlueColor = reinterpret_cast(_BlueColor); +DWORD* ptr_bottom_line = reinterpret_cast(_bottom_line); +DWORD* ptr_btable = reinterpret_cast(_btable); +DWORD* ptr_btncnt = reinterpret_cast(_btncnt); +DWORD* ptr_CarCurrArea = reinterpret_cast(_CarCurrArea); +DWORD* ptr_cmap = reinterpret_cast(_cmap); +DWORD* ptr_colorTable = reinterpret_cast(_colorTable); +DWORD* ptr_combat_free_move = reinterpret_cast(_combat_free_move); +DWORD* ptr_combat_list = reinterpret_cast(_combat_list); +DWORD* ptr_combat_state = reinterpret_cast(_combat_state); +DWORD* ptr_combat_turn_running = reinterpret_cast(_combat_turn_running); +DWORD* ptr_combatNumTurns = reinterpret_cast(_combatNumTurns); +DWORD* ptr_crit_succ_eff = reinterpret_cast(_crit_succ_eff); +PathNode** ptr_critter_db_handle = reinterpret_cast(_critter_db_handle); +DWORD* ptr_critterClearObj = reinterpret_cast(_critterClearObj); +DWORD* ptr_crnt_func = reinterpret_cast(_crnt_func); +DWORD* ptr_curr_font_num = reinterpret_cast(_curr_font_num); +DWORD* ptr_curr_pc_stat = reinterpret_cast(_curr_pc_stat); +DWORD* ptr_curr_stack = reinterpret_cast(_curr_stack); +TProgram** ptr_currentProgram = reinterpret_cast(_currentProgram); +DWORD* ptr_cursor_line = reinterpret_cast(_cursor_line); +BYTE* ptr_DARK_GREY_Color = reinterpret_cast(_DARK_GREY_Color); +BYTE* ptr_DarkGreenColor = reinterpret_cast(_DarkGreenColor); +BYTE* ptr_DarkGreenGreyColor = reinterpret_cast(_DarkGreenGreyColor); +TGameObj** ptr_dialog_target = reinterpret_cast(_dialog_target); +DWORD* ptr_dialog_target_is_party = reinterpret_cast(_dialog_target_is_party); +const DWORD* ptr_dialogueBackWindow = reinterpret_cast(_dialogueBackWindow); +DWORD* ptr_drugInfoList = reinterpret_cast(_drugInfoList); +BYTE* ptr_DullPinkColor = reinterpret_cast(_DullPinkColor); +const DWORD* ptr_edit_win = reinterpret_cast(_edit_win); +DWORD* ptr_Educated = reinterpret_cast(_Educated); +DWORD* ptr_elevation = reinterpret_cast(_elevation); +DWORD* ptr_endgame_subtitle_done = reinterpret_cast(_endgame_subtitle_done); +DWORD* ptr_Experience_ = reinterpret_cast(_Experience_); +DWORD* ptr_fallout_game_time = reinterpret_cast(_fallout_game_time); +DWORD* ptr_fidgetFID = reinterpret_cast(_fidgetFID); +DWORD* ptr_flptr = reinterpret_cast(_flptr); +DWORD* ptr_folder_card_desc = reinterpret_cast(_folder_card_desc); +DWORD* ptr_folder_card_fid = reinterpret_cast(_folder_card_fid); +DWORD* ptr_folder_card_title = reinterpret_cast(_folder_card_title); +DWORD* ptr_folder_card_title2 = reinterpret_cast(_folder_card_title2); +DWORD* ptr_frame_time = reinterpret_cast(_frame_time); +char* ptr_free_perk = reinterpret_cast(_free_perk); +long** ptr_game_global_vars = reinterpret_cast(_game_global_vars); // dynamic array of size == num_game_global_vars +DWORD* ptr_game_user_wants_to_quit = reinterpret_cast(_game_user_wants_to_quit); +CombatGcsd** ptr_gcsd = reinterpret_cast(_gcsd); +DWORD* ptr_gdBarterMod = reinterpret_cast(_gdBarterMod); +DWORD* ptr_gdNumOptions = reinterpret_cast(_gdNumOptions); +DWORD* ptr_gIsSteal = reinterpret_cast(_gIsSteal); +DWORD* ptr_glblmode = reinterpret_cast(_glblmode); +long* ptr_gmouse_current_cursor = reinterpret_cast(_gmouse_current_cursor); +DWORD* ptr_gmovie_played_list = reinterpret_cast(_gmovie_played_list); +BYTE* ptr_GoodColor = reinterpret_cast(_GoodColor); +BYTE* ptr_GreenColor = reinterpret_cast(_GreenColor); +DWORD* ptr_gsound_initialized = reinterpret_cast(_gsound_initialized); +long* ptr_hit_location_penalty = reinterpret_cast(_hit_location_penalty); +DWORD* ptr_holo_flag = reinterpret_cast(_holo_flag); +DWORD* ptr_holopages = reinterpret_cast(_holopages); +DWORD* ptr_hot_line_count = reinterpret_cast(_hot_line_count); +DWORD* ptr_i_fid = reinterpret_cast(_i_fid); +TGameObj** ptr_i_lhand = reinterpret_cast(_i_lhand); +TGameObj** ptr_i_rhand = reinterpret_cast(_i_rhand); +const DWORD* ptr_i_wid = reinterpret_cast(_i_wid); +TGameObj** ptr_i_worn = reinterpret_cast(_i_worn); +void** ptr_idle_func = reinterpret_cast(_idle_func); +DWORD* ptr_In_WorldMap = reinterpret_cast(_In_WorldMap); // moving in WorldMap +DWORD* ptr_info_line = reinterpret_cast(_info_line); +const DWORD* ptr_interfaceWindow = reinterpret_cast(_interfaceWindow); +DWORD* ptr_intfaceEnabled = reinterpret_cast(_intfaceEnabled); +DWORD* ptr_intotal = reinterpret_cast(_intotal); +TGameObj** ptr_inven_dude = reinterpret_cast(_inven_dude); +DWORD* ptr_inven_pid = reinterpret_cast(_inven_pid); +DWORD* ptr_inven_scroll_dn_bid = reinterpret_cast(_inven_scroll_dn_bid); +DWORD* ptr_inven_scroll_up_bid = reinterpret_cast(_inven_scroll_up_bid); +MSGList* ptr_inventry_message_file = reinterpret_cast(_inventry_message_file); +ItemButtonItem* ptr_itemButtonItems = reinterpret_cast(_itemButtonItems); // array of 2 ItemButtonItem +long* ptr_itemCurrentItem = reinterpret_cast(_itemCurrentItem); // 0 - left, 1 - right +DWORD* ptr_kb_lock_flags = reinterpret_cast(_kb_lock_flags); +DWORD* ptr_last_buttons = reinterpret_cast(_last_buttons); +DWORD* ptr_last_button_winID = reinterpret_cast(_last_button_winID); +DWORD* ptr_last_level = reinterpret_cast(_last_level); +DWORD* ptr_Level_ = reinterpret_cast(_Level_); +DWORD* ptr_Lifegiver = reinterpret_cast(_Lifegiver); +BYTE* ptr_LIGHT_GREY_Color = reinterpret_cast(_LIGHT_GREY_Color); +DWORD* ptr_lipsFID = reinterpret_cast(_lipsFID); +DWORD* ptr_list_com = reinterpret_cast(_list_com); +DWORD* ptr_list_total = reinterpret_cast(_list_total); +DWORD* ptr_loadingGame = reinterpret_cast(_loadingGame); +DWORD* ptr_LSData = reinterpret_cast(_LSData); +DWORD* ptr_lsgwin = reinterpret_cast(_lsgwin); +TComputeAttack* ptr_main_ctd = reinterpret_cast(_main_ctd); +DWORD* ptr_main_death_voiceover_done = reinterpret_cast(_main_death_voiceover_done); +DWORD* ptr_main_window = reinterpret_cast(_main_window); +DWORD* ptr_map_elevation = reinterpret_cast(_map_elevation); +long** ptr_map_global_vars = reinterpret_cast(_map_global_vars); // array +DWORD* ptr_map_number = reinterpret_cast(_map_number); +PathNode** ptr_master_db_handle = reinterpret_cast(_master_db_handle); +DWORD* ptr_master_volume = reinterpret_cast(_master_volume); +DWORD* ptr_max = reinterpret_cast(_max); +long* ptr_maxScriptNum = reinterpret_cast(_maxScriptNum); +bool* ptr_Meet_Frank_Horrigan = reinterpret_cast(_Meet_Frank_Horrigan); +const char** ptr_movie_list = reinterpret_cast(_movie_list); // array of 17 char* +DWORD* ptr_mouse_hotx = reinterpret_cast(_mouse_hotx); +DWORD* ptr_mouse_hoty = reinterpret_cast(_mouse_hoty); +DWORD* ptr_mouse_is_hidden = reinterpret_cast(_mouse_is_hidden); +DWORD* ptr_mouse_x_ = reinterpret_cast(_mouse_x_); +DWORD* ptr_mouse_y = reinterpret_cast(_mouse_y); +DWORD* ptr_mouse_y_ = reinterpret_cast(_mouse_y_); +DWORD* ptr_Mutate_ = reinterpret_cast(_Mutate_); +DWORD* ptr_name_color = reinterpret_cast(_name_color); +DWORD* ptr_name_font = reinterpret_cast(_name_font); +DWORD* ptr_name_sort_list = reinterpret_cast(_name_sort_list); +DWORD* ptr_num_game_global_vars = reinterpret_cast(_num_game_global_vars); +DWORD* ptr_num_map_global_vars = reinterpret_cast(_num_map_global_vars); +DWORD* ptr_num_windows = reinterpret_cast(_num_windows); +TGameObj** ptr_obj_dude = reinterpret_cast(_obj_dude); +DWORD* ptr_objectTable = reinterpret_cast(_objectTable); +DWORD* ptr_objItemOutlineState = reinterpret_cast(_objItemOutlineState); +DWORD* ptr_optionRect = reinterpret_cast(_optionRect); +DWORD* ptr_optionsButtonDown = reinterpret_cast(_optionsButtonDown); +DWORD* ptr_optionsButtonDown1 = reinterpret_cast(_optionsButtonDown1); +DWORD* ptr_optionsButtonDownKey = reinterpret_cast(_optionsButtonDownKey); +DWORD* ptr_optionsButtonUp = reinterpret_cast(_optionsButtonUp); +DWORD* ptr_optionsButtonUp1 = reinterpret_cast(_optionsButtonUp1); +DWORD* ptr_optionsButtonUpKey = reinterpret_cast(_optionsButtonUpKey); +const DWORD* ptr_optnwin = reinterpret_cast(_optnwin); +DWORD* ptr_outlined_object = reinterpret_cast(_outlined_object); +DWORD* ptr_partyMemberAIOptions = reinterpret_cast(_partyMemberAIOptions); +DWORD* ptr_partyMemberCount = reinterpret_cast(_partyMemberCount); +DWORD** ptr_partyMemberLevelUpInfoList = reinterpret_cast(_partyMemberLevelUpInfoList); +DWORD** ptr_partyMemberList = reinterpret_cast(_partyMemberList); // each struct - 4 integers, first integer - objPtr +DWORD* ptr_partyMemberMaxCount = reinterpret_cast(_partyMemberMaxCount); +DWORD** ptr_partyMemberPidList = reinterpret_cast(_partyMemberPidList); +char** ptr_patches = reinterpret_cast(_patches); +PathNode** ptr_paths = reinterpret_cast(_paths); // array +DWORD* ptr_pc_crit_succ_eff = reinterpret_cast(_pc_crit_succ_eff); +DWORD* ptr_pc_kill_counts = reinterpret_cast(_pc_kill_counts); +char* ptr_pc_name = reinterpret_cast(_pc_name); +DWORD* ptr_pc_proto = reinterpret_cast(_pc_proto); +BYTE* ptr_PeanutButter = reinterpret_cast(_PeanutButter); +DWORD* ptr_perk_data = reinterpret_cast(_perk_data); +int** ptr_perkLevelDataList = reinterpret_cast(_perkLevelDataList); +const DWORD* ptr_pip_win = reinterpret_cast(_pip_win); +DWORD* ptr_pipboy_message_file = reinterpret_cast(_pipboy_message_file); +DWORD* ptr_pipmesg = reinterpret_cast(_pipmesg); +DWORD* ptr_preload_list_index = reinterpret_cast(_preload_list_index); +const char** ptr_procTableStrs = reinterpret_cast(_procTableStrs); // table of procId (from define.h) => procName map +MSGList* ptr_proto_main_msg_file = reinterpret_cast(_proto_main_msg_file); +MSGList* ptr_proto_msg_files = reinterpret_cast(_proto_msg_files); // array of 6 elements +DWORD* ptr_ptable = reinterpret_cast(_ptable); +DWORD* ptr_pud = reinterpret_cast(_pud); +DWORD* ptr_queue = reinterpret_cast(_queue); +DWORD* ptr_quick_done = reinterpret_cast(_quick_done); +DWORD* ptr_read_callback = reinterpret_cast(_read_callback); +BYTE* ptr_RedColor = reinterpret_cast(_RedColor); +DWORD* ptr_retvals = reinterpret_cast(_retvals); +DWORD* ptr_rotation = reinterpret_cast(_rotation); +BoundRect* ptr_scr_size = reinterpret_cast(_scr_size); +ScriptListInfoItem** ptr_scriptListInfo = reinterpret_cast(_scriptListInfo); // dynamic array +DWORD* ptr_skill_data = reinterpret_cast(_skill_data); +const DWORD* ptr_skldxwin = reinterpret_cast(_skldxwin); +DWORD* ptr_slot_cursor = reinterpret_cast(_slot_cursor); +DWORD* ptr_sndfx_volume = reinterpret_cast(_sndfx_volume); +DWORD* ptr_sneak_working = reinterpret_cast(_sneak_working); // DWORD var +char** ptr_sound_music_path1 = reinterpret_cast(_sound_music_path1); +char** ptr_sound_music_path2 = reinterpret_cast(_sound_music_path2); +DWORD* ptr_speech_volume = reinterpret_cast(_speech_volume); +DWORD* ptr_square = reinterpret_cast(_square); +DWORD* ptr_squares = reinterpret_cast(_squares); +DWORD* ptr_stack = reinterpret_cast(_stack); +DWORD* ptr_stack_offset = reinterpret_cast(_stack_offset); +DWORD* ptr_stat_data = reinterpret_cast(_stat_data); +DWORD* ptr_stat_flag = reinterpret_cast(_stat_flag); +DWORD* ptr_sWindows = reinterpret_cast(_sWindows); // total 16 sWindow struct +DWORD* ptr_Tag_ = reinterpret_cast(_Tag_); +DWORD* ptr_tag_skill = reinterpret_cast(_tag_skill); +DWORD* ptr_target_curr_stack = reinterpret_cast(_target_curr_stack); +DWORD** ptr_target_pud = reinterpret_cast(_target_pud); +DWORD* ptr_target_stack = reinterpret_cast(_target_stack); // array of 10 DWORD +DWORD* ptr_target_stack_offset = reinterpret_cast(_target_stack_offset); // array of 10 DWORD +DWORD* ptr_target_str = reinterpret_cast(_target_str); +DWORD* ptr_target_xpos = reinterpret_cast(_target_xpos); +DWORD* ptr_target_ypos = reinterpret_cast(_target_ypos); +DWORD* ptr_text_char_width = reinterpret_cast(_text_char_width); +DWORD* ptr_text_height = reinterpret_cast(_text_height); +DWORD* ptr_text_max = reinterpret_cast(_text_max); +DWORD* ptr_text_mono_width = reinterpret_cast(_text_mono_width); +DWORD* ptr_text_object_index = reinterpret_cast(_text_object_index); +FloatText** ptr_text_object_list = reinterpret_cast(_text_object_list); // array of 20 FloatText* +DWORD* ptr_text_spacing = reinterpret_cast(_text_spacing); +DWORD* ptr_text_to_buf = reinterpret_cast(_text_to_buf); +DWORD* ptr_text_width = reinterpret_cast(_text_width); +DWORD* ptr_tile = reinterpret_cast(_tile); +DWORD* ptr_title_color = reinterpret_cast(_title_color); +DWORD* ptr_title_font = reinterpret_cast(_title_font); +DWORD* ptr_trait_data = reinterpret_cast(_trait_data); +DWORD* ptr_view_page = reinterpret_cast(_view_page); +DWORD* ptr_wd_obj = reinterpret_cast(_wd_obj); +WINinfo** ptr_window = reinterpret_cast(_window); // array of 50 WINinfo* +BYTE* ptr_WhiteColor = reinterpret_cast(_WhiteColor); +DWORD* ptr_wmAreaInfoList = reinterpret_cast(_wmAreaInfoList); +const DWORD* ptr_wmBkWin = reinterpret_cast(_wmBkWin); +BYTE** ptr_wmBkWinBuf = reinterpret_cast(_wmBkWinBuf); +DWORD* ptr_wmLastRndTime = reinterpret_cast(_wmLastRndTime); +MSGList* ptr_wmMsgFile = reinterpret_cast(_wmMsgFile); +DWORD* ptr_wmNumHorizontalTiles = reinterpret_cast(_wmNumHorizontalTiles); +long* ptr_wmWorldOffsetX = reinterpret_cast(_wmWorldOffsetX); +long* ptr_wmWorldOffsetY = reinterpret_cast(_wmWorldOffsetY); +DWORD* ptr_world_xpos = reinterpret_cast(_world_xpos); +DWORD* ptr_world_ypos = reinterpret_cast(_world_ypos); +DWORD* ptr_WorldMapCurrArea = reinterpret_cast(_WorldMapCurrArea); +BYTE* ptr_YellowColor = reinterpret_cast(_YellowColor); /** diff --git a/sfall/FalloutEngine.h b/sfall/FalloutEngine.h index ac678915..1f9fb33c 100644 --- a/sfall/FalloutEngine.h +++ b/sfall/FalloutEngine.h @@ -487,7 +487,7 @@ extern DWORD* ptr_retvals; extern DWORD* ptr_rotation; extern DWORD* ptr_sad; extern BoundRect* ptr_scr_size; -extern DWORD* ptr_scriptListInfo; +extern ScriptListInfoItem** ptr_scriptListInfo; // dynamic array extern DWORD* ptr_skill_data; extern const DWORD* ptr_skldxwin; extern DWORD* ptr_slot_cursor; diff --git a/sfall/FalloutStructs.h b/sfall/FalloutStructs.h index 45989133..470bc69b 100644 --- a/sfall/FalloutStructs.h +++ b/sfall/FalloutStructs.h @@ -455,6 +455,12 @@ struct PremadeChar { char unknown[20]; }; +#pragma pack(1) +struct ScriptListInfoItem { + char fileName[16]; + long numLocalVars; +}; + //for holding window info #pragma pack(1) struct WINinfo { diff --git a/sfall/HookScripts.cpp b/sfall/HookScripts.cpp index 1912b45c..ab5e3645 100644 --- a/sfall/HookScripts.cpp +++ b/sfall/HookScripts.cpp @@ -22,7 +22,6 @@ #include "main.h" #include "FalloutEngine.h" #include "HookScripts.h" -#include "Inventory.h" #include "LoadGameHook.h" #include "Logging.h" #include "PartyControl.h" @@ -876,21 +875,18 @@ skip: } } -DWORD __stdcall KeyPressHook(DWORD dxKey, bool pressed, DWORD vKey) { +void __stdcall KeyPressHook(DWORD* dxKey, bool pressed, DWORD vKey) { if (!IsGameLoaded()) { - return 0; + return; } - DWORD result = 0; BeginHook(); argCount = 3; args[0] = (DWORD)pressed; - args[1] = dxKey; + args[1] = *dxKey; args[2] = vKey; RunHookScript(HOOK_KEYPRESS); - if (cRet != 0) dxKey = result = rets[0]; - InventoryKeyPressedHook(dxKey, pressed); + if (cRet != 0) *dxKey = rets[0]; EndHook(); - return result; } void __stdcall MouseClickHook(DWORD button, bool pressed) { diff --git a/sfall/HookScripts.h b/sfall/HookScripts.h index 6b8c90c1..f8139ea8 100644 --- a/sfall/HookScripts.h +++ b/sfall/HookScripts.h @@ -66,7 +66,7 @@ extern DWORD initingHookScripts; int __fastcall AmmoCostHook_Script(DWORD hookType, TGameObj* weapon, DWORD &rounds); void __stdcall RunHookScriptsAtProc(DWORD procId); -DWORD __stdcall KeyPressHook(DWORD dxKey, bool pressed, DWORD vKey); +void __stdcall KeyPressHook(DWORD* dxKey, bool pressed, DWORD vKey); void __stdcall MouseClickHook(DWORD button, bool pressed); long __stdcall CorrectFidForRemovedItem_wHook(TGameObj* critter, TGameObj* item, long flags); diff --git a/sfall/InputFuncs.cpp b/sfall/InputFuncs.cpp index 3c7a8502..50177498 100644 --- a/sfall/InputFuncs.cpp +++ b/sfall/InputFuncs.cpp @@ -23,14 +23,15 @@ #include #include "main.h" - -#include "FalloutEngine.h" -#include "Graphics.h" -#include "ScriptExtender.h" -#include "HookScripts.h" -#include "InputFuncs.h" -#include "DebugEditor.h" #include "Logging.h" +#include "FalloutEngine.h" +#include "DebugEditor.h" +#include "Graphics.h" +#include "HookScripts.h" +#include "Inventory.h" +#include "ScriptExtender.h" + +#include "InputFuncs.h" typedef HRESULT (__stdcall *DInputCreateProc)(HINSTANCE a,DWORD b,IDirectInputA** c,IUnknown* d); @@ -58,8 +59,6 @@ static int mouseY; static DWORD forcingGraphicsRefresh = 0; -static DWORD debugEditorKey = 0; - void __stdcall ForceGraphicsRefresh(DWORD d) { forcingGraphicsRefresh = (d == 0) ? 0 : 1; } @@ -90,6 +89,11 @@ void SetMPos(int x, int y) { MPMouseY = y; } +void FlushInputBuffer() { + while (!bufferedPresses.empty()) bufferedPresses.pop(); + __asm call kb_clear_; +} + DWORD __stdcall KeyDown(DWORD key) { if ((key & 0x80000000) > 0) { // special flag to check by VK code directly return GetAsyncKeyState(key & 0xFFFF) & 0x8000; @@ -262,20 +266,21 @@ public: if (!buf || bufferedPresses.empty() || (d & DIGDD_PEEK)) { HRESULT hr = RealDevice->GetDeviceData(a, buf, count, d); if (FAILED(hr) || !buf || !(*count)) return hr; - DWORD keyOverride; for (DWORD i = 0; i < *count; i++) { DWORD dxKey = buf[i].dwOfs; DWORD state = buf[i].dwData & 0x80; DWORD oldState = keysDown[dxKey]; keysDown[dxKey] = state; - keyOverride = KeyPressHook(dxKey, (state > 0), MapVirtualKeyEx(dxKey, MAPVK_VSC_TO_VK, keyboardLayout)); - if (keyOverride != 0) { + KeyPressHook(&dxKey, (state > 0), MapVirtualKeyEx(dxKey, MAPVK_VSC_TO_VK, keyboardLayout)); + if (dxKey > 0 && dxKey != buf[i].dwOfs) { keysDown[buf[i].dwOfs] = oldState; - buf[i].dwOfs = keyOverride; + buf[i].dwOfs = dxKey; // Override key keysDown[buf[i].dwOfs] = state; } + // OnKeyPressed + InventoryKeyPressedHook(buf[i].dwOfs, (state > 0)); + DebugEditorKeyPressedHook(buf[i].dwOfs, (state > 0)); } - if (keysDown[debugEditorKey]) RunDebugEditor(); return hr; } //Despite passing an array of 32 data objects, fallout cant seem to cope with a key being pressed and released in the same frame... @@ -428,8 +433,6 @@ HRESULT __stdcall FakeDirectInputCreate(HINSTANCE a, DWORD b, IDirectInputA** c, backgroundKeyboard = GetConfigInt("Input", "BackgroundKeyboard", 0) != 0; backgroundMouse = GetConfigInt("Input", "BackgroundMouse", 0) != 0; - if (isDebug) debugEditorKey = GetConfigInt("Input", "DebugEditorKey", 0); - keyboardLayout = GetKeyboardLayout(0); return hr; diff --git a/sfall/InputFuncs.h b/sfall/InputFuncs.h index 1ab40c4d..1d5a65a0 100644 --- a/sfall/InputFuncs.h +++ b/sfall/InputFuncs.h @@ -26,6 +26,7 @@ extern bool middleMouseDown; void SetMDown(bool down, bool right); void SetMPos(int x, int y); +void FlushInputBuffer(); DWORD __stdcall KeyDown(DWORD key); void __stdcall TapKey(DWORD key); diff --git a/sfall/ScriptExtender.cpp b/sfall/ScriptExtender.cpp index 1b0b410b..b8cae85b 100644 --- a/sfall/ScriptExtender.cpp +++ b/sfall/ScriptExtender.cpp @@ -1303,7 +1303,7 @@ sScriptProgram* GetGlobalScriptProgram(DWORD scriptPtr) { bool __stdcall IsGameScript(const char* filename) { for (int i = 0; filename[i]; ++i) if (i > 8) return false; for (int i = 0; i < *ptr_maxScriptNum; i++) { - if (strcmp(filename, (char*)(*ptr_scriptListInfo + i * 20)) == 0) return true; + if (strcmp(filename, (*ptr_scriptListInfo)[i].fileName) == 0) return true; } return false; }