423 Commits

Author SHA1 Message Date
Alexander Batalov
9fb917c357 Bump version to 1.3.0 2024-04-21 12:46:24 +03:00
Alexander Batalov
aa31185b35 Update release workflow 2024-04-21 11:23:18 +03:00
Alexander Batalov
ec0685ea19 Normalize and resolve asset bundle paths 2024-04-06 16:41:49 +03:00
Alexander Batalov
2c7ab7f5c8 Detect alternative default music directory 2024-04-06 16:33:16 +03:00
Alexander Batalov
8de73ad774 Refactor file find
Fixes #352
2024-04-06 12:47:11 +03:00
Alexander Batalov
3ceacf1001 Fix warning 2024-04-06 12:01:48 +03:00
Alexander Batalov
31afb4d568 Bump actions to v4 2024-03-03 11:27:37 +03:00
Alexander Batalov
95cbba3920 Bump zlib to 1.3.1 2024-03-03 09:39:06 +03:00
sonilyan
16b044ae31 Fix obj_can_see_obj not working in release build (#350) 2024-02-15 05:04:57 +03:00
sonilyan
caea9cb4fb Fix yaam no damage (#351) 2024-02-15 05:02:56 +03:00
Alexander Batalov
8325823493 Expose game data files to iOS Files app
Fixes #343
2024-01-16 23:42:25 +03:00
Alexander Batalov
8e1e8d483c Review db_total
Fixes #327
2024-01-16 22:37:06 +03:00
Alexander Batalov
1b18c2baa3 Fix custom patch file name template
Follow-up to #309
2024-01-16 22:35:16 +03:00
Alexander Batalov
70d5830f00 Force LF on .mm 2024-01-16 19:04:14 +03:00
yabisiktir
401df384ef modernize-use-nullptr (#332) 2024-01-16 18:57:49 +03:00
Vlad
59af02cca9 Variable naming, part 2 (#320) 2024-01-16 16:33:08 +03:00
c6
c6565ac96a Sfall: add VersionString, ConfigFile, PatchFile (#309) 2024-01-16 15:56:21 +03:00
Jo
16f4ab7787 Improve pointer comparsion for Nevada and Sonora mods (#291) 2024-01-16 15:42:32 +03:00
Vasilii Rogin
e23c4eddda Use delay_ms instead of spinwait (#262) 2024-01-16 15:24:49 +03:00
λP.(P izzy)
601f0c7b44 fix CMake condition to allow build on OpenBSD & FreeBSD (#341) 2024-01-16 15:06:47 +03:00
sonilyan
f411d75643 Add overriddenSelf initialization for scriptRead (#329) 2023-10-31 13:46:25 +03:00
Vasilii Rogin
81fce5f4a2 Fix wrong pointer dereferecing in aiFindAttackers (#324) 2023-10-09 20:50:59 +03:00
Eir Nym
0e447c55a8 Upgrade zlib to 1.3 (#323) 2023-09-28 17:26:52 +03:00
Alexander Batalov
91806d8ccb Fix missing include 2023-09-03 22:31:52 +03:00
Alexander Batalov
a30fb4cfdd Add mapper_refresh_rotation 2023-09-03 22:21:14 +03:00
Alexander Batalov
def8effa9f Add handle_new_map 2023-09-03 21:42:17 +03:00
Alexander Batalov
d46ee07583 Add mapper_destroy_highlight_obj 2023-09-03 21:30:59 +03:00
Alexander Batalov
ee19238667 Add update_toolname 2023-09-03 20:48:23 +03:00
Alexander Batalov
0d83cff24e Add place_entrance_hex 2023-09-03 20:24:36 +03:00
Alexander Batalov
30a3bf9b71 Add pick_region 2023-09-03 20:23:50 +03:00
Alexander Batalov
8c61b0bd8c Add sort_rect 2023-09-03 19:15:50 +03:00
Alexander Batalov
6e9f1ae517 Add op_set_self 2023-09-03 18:23:19 +03:00
Alexander Batalov
ad3e0eb752 Add op_explosions_metarule 2023-09-03 16:51:29 +03:00
Alexander Batalov
b40bfcc64a Add some metarules 2023-09-03 16:26:52 +03:00
Alexander Batalov
b706756ec9 Add op_get_script 2023-09-03 13:34:16 +03:00
Alexander Batalov
427672741a Add op_list_as_array 2023-09-02 22:06:37 +03:00
Alexander Batalov
bb3513956c Add op_force_encounter 2023-09-02 21:34:41 +03:00
Alexander Batalov
84aecfa823 Add draw_rect 2023-09-02 20:07:02 +03:00
Alexander Batalov
7f920fe13b Add erase_rect 2023-09-02 19:57:14 +03:00
Alexander Batalov
9178abc53d Add toolbar_proto 2023-09-02 19:47:15 +03:00
Alexander Batalov
84288612ef Add map_toggle_block_obj_viewing_on 2023-09-02 19:43:56 +03:00
Alexander Batalov
4a94b19f60 Add proto_subdata_setup_pid_button 2023-09-02 19:36:17 +03:00
Alexander Batalov
b0b161ceb5 Add proto_subdata_setup_fid_button 2023-09-02 19:31:16 +03:00
Alexander Batalov
1c2fd05bcd Add proto_subdata_setup_int_button 2023-09-02 18:33:32 +03:00
Alexander Batalov
e0b18a8785 Add target_exit 2023-09-02 18:08:21 +03:00
Alexander Batalov
8929941d13 Add target_init 2023-09-02 18:07:37 +03:00
Alexander Batalov
8d2d5df65f Add target_new 2023-09-02 17:54:17 +03:00
Alexander Batalov
fe47d88035 Add target_remove_tid 2023-09-02 17:47:43 +03:00
Alexander Batalov
29e81f3bf4 Add target_remove 2023-09-02 17:37:21 +03:00
Alexander Batalov
05b4c125e6 Add target_save 2023-09-02 17:19:51 +03:00
Alexander Batalov
96573a7209 Add target_remove_all 2023-09-02 17:14:49 +03:00
Alexander Batalov
caf28a7286 Add target_tid_ptr 2023-09-02 17:07:43 +03:00
Alexander Batalov
25a3de62e7 Add target_ptr 2023-09-02 17:05:26 +03:00
Alexander Batalov
fd3cd887b6 Add target_load 2023-09-02 16:40:18 +03:00
Alexander Batalov
c3a6d07dc4 Add target_find_free_subnode 2023-09-02 16:24:07 +03:00
Alexander Batalov
ed7ffac816 Add target_header_load 2023-09-02 15:31:23 +03:00
Alexander Batalov
59c43590cc Add target_header_save 2023-09-02 15:29:59 +03:00
Alexander Batalov
f14f37f970 Add target_override_protection 2023-09-02 14:39:31 +03:00
Alexander Batalov
cba1fc8f61 Add map_scr_remove_spatial 2023-07-25 11:56:20 +03:00
Alexander Batalov
8329d2fcf6 Add map_scr_remove_all_spatials 2023-07-25 11:14:41 +03:00
Alexander Batalov
1de7ef0151 Add init_mapper_protos 2023-07-24 15:19:18 +03:00
Alexander Batalov
f1f4cac316 Add proto_choose_container_flags 2023-07-24 15:15:06 +03:00
Alexander Batalov
6ce6639f10 Add proto_wall_light_str 2023-07-24 10:57:31 +03:00
Alexander Batalov
c5ad0c294f Add proto_critter_flags_redraw 2023-07-24 10:53:04 +03:00
Alexander Batalov
f780969178 Add proto_critter_flags_modify 2023-07-24 10:46:31 +03:00
Alexander Batalov
f3f61abc18 Add critter_flag_unset 2023-07-24 09:07:02 +03:00
Alexander Batalov
369a54f836 Add critter_flag_set 2023-07-24 09:04:11 +03:00
Alexander Batalov
e9f3b34888 Add mp_pick_kill_type 2023-07-24 08:55:43 +03:00
Alexander Batalov
c1258cbb4c Add proto_pick_ai_packet 2023-07-24 08:43:27 +03:00
Alexander Batalov
49804a52e6 Add combat_ai_name 2023-07-24 08:29:19 +03:00
Alexander Batalov
e0e0db219c Add combat_ai_num 2023-07-24 08:27:42 +03:00
Alexander Batalov
f93aa710a4 Add target_pick_local_var 2023-07-24 08:20:15 +03:00
Alexander Batalov
ca206da4af Add target_pick_map_var 2023-07-24 08:17:04 +03:00
Alexander Batalov
f6461a44dc Add target_pick_global_var 2023-07-24 08:13:45 +03:00
Alexander Batalov
3a271a399f Add pick_rot 2023-07-24 08:10:46 +03:00
Alexander Batalov
ac1f4477ef Add target_make_path 2023-07-24 08:08:01 +03:00
Alexander Batalov
708862ca24 Add target_overriden 2023-07-24 08:03:25 +03:00
Alexander Batalov
57711cae5f Add mapper_edit_exit 2023-07-24 07:17:21 +03:00
Alexander Batalov
f6e9a9d975 Make MapDirErase public 2023-07-24 07:15:58 +03:00
Alexander Batalov
4cd40b33af Add mapper_edit_init 2023-07-24 06:50:07 +03:00
Alexander Batalov
053e70dde4 Add gmouse_set_mapper_mode 2023-07-23 14:27:52 +03:00
Alexander Batalov
4b51b2f29b Add tile_toggle_roof 2023-07-23 14:15:20 +03:00
Alexander Batalov
cdfd308193 Add mapper_main 2023-07-23 11:01:03 +03:00
Alexander Batalov
7327588fc3 Add MapperInit 2023-07-23 10:35:16 +03:00
Alexander Batalov
d16f0010ac Add bookmarkInit 2023-07-23 10:26:43 +03:00
Alexander Batalov
a27b2496d4 Add bookmarkExit 2023-07-23 10:25:58 +03:00
Alexander Batalov
a2d61dc7c4 Add bookmarkHide 2023-07-23 10:23:55 +03:00
Alexander Batalov
093d4f23d8 Add bookmarkUnHide 2023-07-23 10:22:42 +03:00
Alexander Batalov
3331ad02b0 Add categoryInit 2023-07-23 10:20:54 +03:00
Alexander Batalov
661c689029 Add categoryExit 2023-07-23 10:19:02 +03:00
Alexander Batalov
b1049fceb1 Add categoryToggleState 2023-07-23 10:17:52 +03:00
Alexander Batalov
f933bff8ae Add categoryHide 2023-07-23 10:16:59 +03:00
Alexander Batalov
9f08c73b3c Add categoryUnhide 2023-07-23 10:15:51 +03:00
Alexander Batalov
4eaea0e3c0 Add proto_user_is_librarian 2023-07-23 10:10:09 +03:00
Alexander Batalov
c652312157 Add print_toolbar_name 2023-07-23 10:01:58 +03:00
Alexander Batalov
8cc48cf52a Add update_high_obj_name 2023-07-23 09:55:58 +03:00
Alexander Batalov
9faa427a28 Add clear_toolname 2023-07-23 09:52:59 +03:00
Alexander Batalov
480094a3eb Add redraw_toolname 2023-07-23 09:49:22 +03:00
Alexander Batalov
1366b050b0 Add mapper_inven_unwield 2023-07-23 09:44:09 +03:00
Alexander Batalov
e68c2a4784 Add mapper_mark_exit_grid 2023-07-23 09:39:13 +03:00
Alexander Batalov
78ae0fb3bf Add mapper_mark_all_exit_grids 2023-07-23 09:25:56 +03:00
Alexander Batalov
127de14318 Add win_get_num_i 2023-07-23 07:20:56 +03:00
Alexander Batalov
28d1d410d5 Add get_num_i 2023-07-23 06:08:23 +03:00
Alexander Batalov
4b65bdf021 Add scripts_request_townmap 2023-07-22 17:09:19 +03:00
Alexander Batalov
cbb9cbc6fd Clarify some proto params 2023-07-22 17:00:24 +03:00
Alexander Batalov
c72d8778ba Add proto_new 2023-07-22 16:53:01 +03:00
Alexander Batalov
d6c3d74b3f Clarify proto_make_path address 2023-07-22 15:36:51 +03:00
Alexander Batalov
3c7248af5f Add proto_item_init 2023-07-22 15:34:32 +03:00
Alexander Batalov
fd9fa80204 Add proto_item_subdata_init 2023-07-22 15:22:05 +03:00
Alexander Batalov
3d5cb4c3f4 Add proto_scenery_init 2023-07-22 15:07:39 +03:00
Alexander Batalov
01a68af4a4 Add proto_scenery_subdata_init 2023-07-22 15:05:00 +03:00
Alexander Batalov
6a75ec07e9 Add proto_wall_init 2023-07-22 14:59:32 +03:00
Alexander Batalov
1d310eb626 Add proto_tile_init 2023-07-22 14:58:47 +03:00
Alexander Batalov
ffc440c809 Add proto_misc_init 2023-07-22 14:53:22 +03:00
Alexander Batalov
a4daffa30e Add proto_copy_proto 2023-07-22 14:49:56 +03:00
Alexander Batalov
ccabbd7688 Add proto_is_subtype 2023-07-22 14:46:51 +03:00
Alexander Batalov
d27eafe03a Fix win_get_str return code 2023-07-21 11:22:57 +03:00
Alexander Batalov
7a45ac72f0 Add reading mapper config 2023-07-21 11:10:15 +03:00
Alexander Batalov
f6cfc1fa3a Clarify GNW_check_menu_bars param 2023-07-21 11:02:54 +03:00
Alexander Batalov
6dcbcb97ad Add process_pull_down 2023-07-21 10:50:33 +03:00
Alexander Batalov
769599c463 Fix closing same file twice
Closes #318
2023-07-21 08:04:10 +03:00
Alexander Batalov
50d7c71db1 Clarify dragging flags 2023-07-20 11:13:01 +03:00
Alexander Batalov
b07a7bcefd Complete win_drag 2023-07-20 10:20:05 +03:00
Alexander Batalov
867d28ac62 Add rect_clip 2023-07-20 10:13:21 +03:00
Alexander Batalov
d9a173678a Cleanup timed msgs code 2023-07-20 09:39:15 +03:00
Alexander Batalov
dde3255b07 Fix endless loop while cleaning up timed msgs 2023-07-20 09:21:26 +03:00
Alexander Batalov
1506ae7048 Add win_timed_msg 2023-07-20 08:53:26 +03:00
Alexander Batalov
ce5d07e09c Add win_yes_no 2023-07-19 21:27:20 +03:00
Alexander Batalov
2d8a637f7d Force debug window font 2023-07-19 12:05:39 +03:00
Alexander Batalov
8414effc04 Fix GNW color indexes 2023-07-19 12:01:20 +03:00
Alexander Batalov
3a17818ceb Handle debug mode
Closes #298
2023-07-19 11:51:13 +03:00
Alexander Batalov
90d1545bb2 Uninline debug_register_func 2023-07-19 11:45:55 +03:00
Alexander Batalov
a7628ccaea Fix bufferDrawLine
Missing 1 pixel in the middle of the vertical line.
2023-07-19 11:43:10 +03:00
Alexander Batalov
3af2a49250 Review debug_register_log 2023-07-19 11:39:01 +03:00
Vlad
ffe90eef49 Improve code readability (#315) 2023-07-13 13:35:26 +03:00
Alexander Batalov
c4c2806071 Fix game time calculations (#307) 2023-07-13 13:04:31 +03:00
Alexander Batalov
fe035d8514 Improve loadsave.cc readability 2023-06-16 08:12:38 +03:00
c6
cf98070cd0 Add Sfall AutoQuickSave (#305) 2023-06-16 08:01:44 +03:00
Austin Hurst
0ffcb107af Implement SCALE_2X for Fallout 2 (#306) 2023-06-16 07:18:15 +03:00
Alexander Batalov
cf5f865a23 Add load/save global vars (#296) 2023-06-03 08:06:49 +03:00
Alexander Batalov
37e4822ed5 Add keyboard opcodes (#295) 2023-06-01 19:01:03 +03:00
Alexander Batalov
bf639a2c4a Fix copying files on case-sensitive file systems
Closes #273
2023-06-01 17:10:36 +03:00
Alexander Batalov
89839be3af Add global scripts (#294) 2023-05-31 21:48:44 +03:00
Alexander Batalov
ec722475b6 Add op_create_message_window
See #200
2023-05-30 14:21:50 +03:00
Alexander Batalov
32ed3c3271 Add FixNamespaceComments 2023-05-30 12:56:51 +03:00
Alexander Batalov
03bf507893 Add ini opcodes (#293) 2023-05-30 12:52:55 +03:00
Alexander Batalov
681b7c388b Fix sfall opcode comments 2023-05-30 09:12:51 +03:00
Vasilii Rogin
fe0d767521 Add SFall arrays (#269)
Co-authored-by: Alexander Batalov <alex.batalov@gmail.com>
2023-05-30 09:06:55 +03:00
Alexander Batalov
62c5c4757c Fix comparing pointers and integers
See #189
2023-05-24 21:52:50 +03:00
Vasilii Rogin
70b0b61664 Delete critter from combat during _partyFixMultipleMembers (#277)
Co-authored-by: Alexander Batalov <alex.batalov@gmail.com>
2023-05-24 21:32:09 +03:00
Vasilii Rogin
53a4437be9 Remove trailing comma after reading strParseIntWithKey (#259) 2023-05-23 23:51:04 +03:00
Vasilii Rogin
42c541012c Fix crash in _map_age_dead_critters (#258)
Co-authored-by: Alexander Batalov <alex.batalov@gmail.com>
2023-05-23 23:50:37 +03:00
Vlad
61293bd39c Fix ruined stack in rm_mult_objs_from_inven and name remaining opcodes (#289) 2023-05-23 23:45:18 +03:00
Alexander Batalov
d641fefc13 Fix open door sound
See alexbatalov/fallout1-ce#71
2023-05-23 23:43:00 +03:00
Alexander Batalov
666e5cf62d Fix mouse events processing
See alexbatalov/fallout1-ce#55
2023-05-23 23:32:11 +03:00
Alexander Batalov
2565900f90 Fix clang-format args
Looks like clang-format in Ubuntu does not recognize glob pattern as
macOS does. Previous solution without xargs reported status code of
find itself, not clang-format.
2023-05-18 23:32:16 +03:00
Alexander Batalov
6b6fa3f111 Fix code format check 2023-05-09 18:42:47 +03:00
Alexander Batalov
a06097aef5 Improve touch controls (#283) 2023-05-09 18:36:20 +03:00
Alexander Batalov
efdc2e0199 Bump setup-java to v3 (#278) 2023-05-01 07:54:14 +03:00
Alexander Batalov
d6a74468da Use Xcode for macOS builds (#275) 2023-05-01 07:10:04 +03:00
Alexander Batalov
fcf8a87603 Ignore channels in acm files (#274) 2023-04-27 10:14:41 +03:00
Alexander Batalov
a8815229a0 Add compat_access (#272) 2023-04-26 20:12:22 +03:00
Alexander Arkhipov
aa99b2e1d3 Convert file paths to correct case (#214) 2023-04-26 17:45:36 +03:00
Vasilii Rogin
63d8300c61 Add clang format (#270) 2023-04-26 15:35:02 +03:00
Alexander Batalov
81c3ff9b1a Improve iOS icon (#271) 2023-04-26 15:11:24 +03:00
Alexander Batalov
a0652e2646 Use Xcode for iOS builds (#267) 2023-04-26 14:11:26 +03:00
Alexander Batalov
df3ac30de6 Add blocking objects opcodes 2023-04-20 11:22:47 +03:00
Alexander Batalov
6ca1329720 Add op_get_attack_type 2023-04-20 10:51:20 +03:00
Alexander Batalov
129361836f Add op_get_mouse_buttons 2023-04-20 10:31:32 +03:00
Alexander Batalov
cf4921de1e Add op_tile_under_cursor 2023-04-20 10:25:13 +03:00
Alexander Batalov
ecc6a8679b Add math opcodes 2023-04-20 09:53:50 +03:00
Alexander Batalov
a39f149817 Add date/time opcodes 2023-04-19 19:10:09 +03:00
Alexander Batalov
540cc1e08b Add combat opcodes 2023-04-19 10:03:04 +03:00
Alexander Batalov
ef34fdb519 Add proto data opcodes 2023-04-19 09:21:38 +03:00
Alexander Batalov
9b02f600de Add worldmap opcodes 2023-04-19 09:09:17 +03:00
Alexander Batalov
0bb07dbd50 Add pc base stats opcodes 2023-04-19 09:02:54 +03:00
Vasilii Rogin
0a85ce520b Use stack on the heap for roof fill (#263) 2023-04-18 11:06:07 +03:00
Vasilii Rogin
99bc14cf3a Add sFall movie timer options (#261) 2023-04-14 19:03:21 +03:00
Vasilii Rogin
527e152297 Allow messageIndex to be zero (#264) 2023-04-14 18:40:37 +03:00
Alexander Batalov
c8d45854ba Normalize line endings when reading text files
Closes #250
2023-04-11 20:00:38 +03:00
Alexander Batalov
11472e8be9 Fix soundOpenData flags 2023-04-11 17:27:34 +03:00
Alexander Batalov
69e4adf5b3 Add HQ music support
See #239
2023-04-11 16:37:01 +03:00
Alexander Batalov
a2eabd668b Fix missing speech in some Russian localizations
Closes #246
2023-04-11 14:03:55 +03:00
Alexander Batalov
6d1273d325 Improve button functions readability 2023-04-11 09:01:14 +03:00
TomArnaez
e23b39abaa Fix crash in inventory list (#256) 2023-02-28 22:11:08 +03:00
Alexander Batalov
117b1d7b44 Fix iPad settings
Follow-up to alexbatalov/fallout1-ce#29
2023-02-28 20:31:19 +03:00
Alexander Batalov
6398f8a79e Fix itemDropAll
See #253
2023-02-28 16:11:48 +03:00
Alexander Batalov
81b9345303 Update config 2023-02-18 19:06:20 +03:00
Alexander Batalov
249892716e Get rid of mmx stuff 2023-02-18 18:14:30 +03:00
Alexander Batalov
3e8227a62b Extract mainmenu 2023-02-17 15:55:14 +03:00
Alexander Batalov
1570f860e8 Remove unnecessary calls 2023-02-17 15:53:42 +03:00
Alexander Batalov
d7c4589a55 Extract preferences 2023-02-17 12:33:26 +03:00
Alexander Batalov
0a9a1dc7ca Fix faulty frms
Closes #235
2023-02-16 15:46:49 +03:00
Alexander Batalov
42346f66b2 Update readme 2023-02-15 12:47:32 +03:00
Alexander Batalov
7ac651b736 Adjust modal dialogs position 2023-02-15 11:37:00 +03:00
Alexander Batalov
0bb822ba60 Fix "Affect player speed" font
Closes #245
2023-02-15 09:23:46 +03:00
Alexander Batalov
075de8f837 Review sound IO functions 2023-02-13 11:51:09 +03:00
Alexander Batalov
36b5ceba8a Improve sound_decoder.cc accuracy 2023-02-13 11:02:17 +03:00
Alexander Batalov
f5d3cfb5e3 Fix Fast Metabolism trait 2023-02-12 23:12:36 +03:00
Alexander Batalov
81210f46af Fix storing pointers in game global variables 2023-02-10 11:05:42 +03:00
Alexander Batalov
c14f671a0d Add object and string concatenation
Fixes #232
2023-02-10 09:27:10 +03:00
Alexander Batalov
33141672ed Use screen borders for scrolling worldmap 2023-02-10 09:00:59 +03:00
Alexander Batalov
28083cfea9 Fix talking head mood transition 2023-02-09 19:40:25 +03:00
Alexander Batalov
c9864741f3 Fix crash in artLockFrameDataReturningSize
Closes #231
2023-02-09 19:27:25 +03:00
Jiří Malák
5a230efd2b Properly handle path with spaces (#228) 2023-01-29 08:56:03 +03:00
Alexander Batalov
3aea6a98ef Fix loading custom interface frms 2023-01-21 15:24:18 +03:00
Alexander Batalov
ba49abcea6 Fix some scripts not being properly removed
Closes #224
2023-01-21 13:15:18 +03:00
Alexander Batalov
47f5be8340 Fix HP being used as AP 2023-01-20 14:16:43 +03:00
Alexander Batalov
d435185e9e Fix missing melee damage info 2023-01-20 14:12:03 +03:00
Alexander Batalov
dcd450a9b7 Bump version to 1.2.0 2023-01-20 10:02:02 +03:00
Alexander Batalov
bfbf692cc0 Add iOS release workflow 2023-01-20 09:57:52 +03:00
Alexander Batalov
2714dc1ea1 Fix memory alignment
See #135, #122
2023-01-19 20:27:22 +03:00
Alexander Batalov
8604d9c401 Fix check 2023-01-16 17:33:19 +03:00
Alexander Batalov
b9261c3da2 Fix directory name reading 2023-01-16 17:01:52 +03:00
Alexander Batalov
ed7176b796 Fix combatai_notify_onlookers 2023-01-16 16:55:31 +03:00
Alexander Batalov
6cac53d20b Rename critter maneuver flags 2023-01-16 16:49:50 +03:00
Alexander Batalov
ad3860790c Fix NPCs not joining combat 2023-01-16 16:42:50 +03:00
Alexander Batalov
bffe81d0b3 Improve cycle.cc readability 2023-01-05 11:29:00 +03:00
Alexander Batalov
6ab08bd22b Remove some unused db functions 2023-01-05 10:39:46 +03:00
Alexander Batalov
060c79fc20 Remove electronic registration 2023-01-05 10:27:16 +03:00
Alexander Batalov
ac64fde502 Fix object rendering
Previous solution did not work well on high resolutions due to
incorrect tile calculations - was not updating edges and sometimes
hanged in endless loop trying to find upper-left or bottom-right
tiles.

New solution follows Sfall's HRP implementation.
2023-01-05 05:59:45 +03:00
Alexander Batalov
7496afa4f8 Clarify textObjectAdd param 2023-01-05 04:06:18 +03:00
Alexander Batalov
66955f893a Review light.cc 2023-01-03 23:56:52 +03:00
Alexander Batalov
9ee4cb4a26 Refactor min/max usage 2023-01-03 23:00:38 +03:00
Alexander Batalov
a5cefd6c8b Clear dirty rect during map updates
Previous solution to replace squares was destructive in nature and
could possibly lead to unexpected things (especially with mods where
tile 0x293 might not be opaque black).

New solution follows mapper refresh routines where entire dirty rect
is reset to black as a preparation step.
2023-01-03 21:10:20 +03:00
Alexander Batalov
d040ea814a Fix objects being animated while playing movies 2023-01-02 21:15:43 +03:00
Alexander Batalov
03145e4fcd Fix endgame slideshow issues
See #3
Closes #215
2023-01-02 14:34:42 +03:00
Alexander Batalov
812079004c Make credits fullscreen
See #3, #215
2023-01-02 13:09:03 +03:00
Alexander Batalov
6224af6178 Fix help screen issues
Closes #179
2023-01-02 11:13:32 +03:00
Alexander Batalov
a8d3cdd148 Improve worldmap.cc readability 2022-12-31 14:12:04 +03:00
Alexander Batalov
95cc863fde Fix special encounter icon blinking 2022-12-30 16:45:49 +03:00
Alexander Batalov
cc1562b056 Add fading effects when moving to/from worldmap
Follow-up to #193
2022-12-30 00:41:29 +03:00
Alexander Batalov
07f3c82444 Fix map loading background
Integrated interface bar area remained visible during map loading.
2022-12-29 23:33:09 +03:00
Alexander Batalov
9976728e04 Fix worldmap background
Closes #193
2022-12-29 21:54:40 +03:00
Alexander Batalov
5922d15b1c Fix various dialog box issues
- Better vertical positioning (account for word wrapping)
- Better horizontal positioning (consider both right and left gaps for
calculating available width).
- Prevent vertical text overflow.
2022-12-29 13:02:59 +03:00
Alexander Batalov
248d6dfb92 Add shadow to city labels 2022-12-29 10:43:02 +03:00
Alexander Batalov
73cc93a3e4 Cleanup some interface bar functions 2022-12-29 10:21:15 +03:00
Alexander Batalov
34259269a4 Improve "Whomever is attacking me" targeting
Fixes #197
2022-12-29 09:37:51 +03:00
Alexander Batalov
11217974c6 Improve aiFindAttackers 2022-12-28 19:45:17 +03:00
Alexander Batalov
0e13989f9c Fix critter lists sorting functions 2022-12-28 17:54:09 +03:00
Alexander Batalov
57dcf42b5c Fix custom disposition button 2022-12-28 17:33:01 +03:00
Alexander Batalov
c2c26db5d9 Fix max throw range calculation 2022-12-28 12:33:10 +03:00
Alexander Batalov
b6ee5fcbe9 Fix configGetIntList 2022-12-28 09:14:30 +03:00
Alexander Batalov
0e11569397 Add ai_check_drugs fixes and improvements (#29) 2022-12-28 02:19:43 +03:00
Alexander Batalov
4b137dac5f Improve graphlib accuracy 2022-12-27 18:59:24 +03:00
Alexander Batalov
1f6d5ebbc9 Improve some color functions readability 2022-12-27 16:27:14 +03:00
Alexander Batalov
462baa0a04 Improve color tables accuracy 2022-12-27 15:51:43 +03:00
Alexander Batalov
b74f3c368b Fix warning 2022-12-26 12:03:14 +03:00
Alexander Batalov
a05ab09e1b Cleanup audio IO 2022-12-26 11:48:47 +03:00
Alexander Batalov
1b0cd6d757 Improve SoundDecoder readability 2022-12-25 22:30:31 +03:00
Alexander Batalov
b8dea116ee Improve Sound readability 2022-12-25 21:56:23 +03:00
Alexander Batalov
e11f1af9ae Improve combat_ai.cc readability 2022-12-24 14:30:03 +03:00
Alexander Batalov
9c34b26fec Improve animation.cc readability 2022-12-23 15:49:56 +03:00
Alexander Batalov
9a6d45541f Rename animationRegisterPing 2022-12-23 15:22:53 +03:00
Alexander Batalov
f4775775b8 Review dude move/run functions 2022-12-23 15:13:05 +03:00
Alexander Batalov
a48d744cde Improve actions.cc readability 2022-12-23 12:44:52 +03:00
Alexander Batalov
16dbe1122e Normalize gradlew.bat 2022-12-23 10:55:15 +03:00
Alexander Batalov
b0cb70ffa6 Fix file existence check 2022-12-23 10:34:20 +03:00
Alexander Batalov
512530c653 Fix building file list on non-Windows platforms 2022-12-23 10:33:16 +03:00
Alexander Batalov
982d4cc0f9 Truncate long names in file picker dialog 2022-12-23 10:30:31 +03:00
Alexander Batalov
3b951b8578 Add opSetWeaponAmmoPid 2022-12-22 20:36:31 +03:00
Alexander Batalov
17a4ee8a68 Add Sfall version opcodes (#200) 2022-12-22 20:18:07 +03:00
Alexander Batalov
c85cda4b48 Fix rare crash when using grenades
Closes #208
2022-12-22 19:54:04 +03:00
Alexander Batalov
c7ca358295 Rename OBJECT_NO_SAVE flag 2022-12-22 16:49:17 +03:00
Alexander Batalov
96296417c6 Rename OBJECT_NO_REMOVE flag 2022-12-22 16:47:11 +03:00
Alexander Batalov
737076a126 Fix getting elevation of freed object 2022-12-22 14:20:37 +03:00
Alexander Batalov
c0908cf14f Fix visual artifacts caused by null tiles 2022-12-21 09:18:29 +03:00
Alexander Batalov
343911f736 Fix floor lighting 2022-12-20 18:44:21 +03:00
Alexander Batalov
281c1aa82a Review tileRenderFloorsInRect 2022-12-20 16:22:56 +03:00
Alexander Batalov
18afce71b0 Review tile_fill_roof 2022-12-20 15:10:42 +03:00
Alexander Batalov
9599d63f45 Review roof_fill_off 2022-12-20 15:09:01 +03:00
Alexander Batalov
ce351988b5 Review roof_fill_on 2022-12-20 15:01:57 +03:00
Alexander Batalov
feb3821565 Fix multiple knockout effects 2022-12-13 23:59:45 +03:00
Alexander Batalov
54eaff26ea Fix partyMemberIncLevels 2022-12-13 23:35:15 +03:00
Alexander Batalov
5a7ffde45e Fix max party member level 2022-12-13 23:29:34 +03:00
Alexander Batalov
1c0385ad11 Remove _obj_fix_combat_cid_for_dude
The same cid-to-object conversion performed by `combatLoad`.
2022-12-13 23:06:52 +03:00
Alexander Batalov
0fe6d88a3a Review combatLoad 2022-12-13 23:03:42 +03:00
Alexander Batalov
7596d4d721 Fix combat_is_shot_blocked 2022-12-13 22:18:12 +03:00
Alexander Batalov
8333e553e2 Add SubtileFill 2022-12-13 22:11:37 +03:00
Alexander Batalov
6f62cfd466 Fix critters dying on exit grids 2022-12-13 16:33:19 +03:00
Alexander Batalov
280b55ab05 Add isExitGridPid 2022-12-13 14:34:49 +03:00
Alexander Batalov
e02dcdf69d Fix car disappearing when using town interface 2022-12-13 13:20:55 +03:00
Alexander Batalov
b5701fb9b9 Fix worldmap scroll down button 2022-12-13 12:45:39 +03:00
Alexander Batalov
c569b879f6 Fix opPrint 2022-12-13 11:35:07 +03:00
Alexander Batalov
b36ac50425 Review windowShow 2022-12-13 10:37:52 +03:00
Alexander Batalov
029a84a113 Review gWindowIndexes 2022-12-13 10:18:02 +03:00
Alexander Batalov
e6fddd6905 Rename window flags 2022-12-13 10:04:05 +03:00
Alexander Batalov
b0b69bd780 Fix wmMapIdxToName 2022-12-09 00:52:03 +03:00
Alexander Batalov
6de4ac87df Use snprintf 2022-12-08 23:05:50 +03:00
Alexander Batalov
502c920656 Add reportOverloaded 2022-12-08 22:05:54 +03:00
Alexander Batalov
c383fc6b95 Add mobile keyboard support (#206) 2022-12-08 20:41:59 +03:00
Alexander Batalov
4b03c714b4 Bump libsdl to 2.26.1 2022-12-08 19:48:53 +03:00
Alexander Batalov
0d93279a10 Fix missing include 2022-12-08 19:38:55 +03:00
Alexander Batalov
510d7bfe95 Reorganize includes 2022-12-08 19:18:39 +03:00
Alexander Batalov
19d0d2919f Remove unnecessary includes 2022-12-08 17:29:30 +03:00
Alexander Batalov
42f01c8d45 Remove unused 16bpp code 2022-12-08 17:26:28 +03:00
Alexander Batalov
0474199b5c Remove unnecessary include 2022-12-08 17:13:06 +03:00
Alexander Batalov
8a4ce6c658 Improve splash screen handling (#3)
* Fixes splash screens in Olympus
2022-12-08 16:41:55 +03:00
Alexander Batalov
884034f0bf Refactor stretching blitters
* Fixes skipped pixels
* Improves readability
2022-12-08 16:34:38 +03:00
Alexander Batalov
602ef7c1e1 Increase maps ambient sfx capacity 2022-12-08 14:10:31 +03:00
Alexander Batalov
897ff2bbd2 Add dialog options numbering 2022-12-08 10:58:54 +03:00
Alexander Batalov
9ade107e95 Rename Button fields 2022-12-07 16:42:37 +03:00
Alexander Batalov
1698cfa04b Rename Window fields 2022-12-07 16:39:30 +03:00
Alexander Batalov
59639c60a3 Cleanup 2022-12-07 10:17:48 +03:00
Alexander Batalov
f056f0e131 Add opGetGameMode (#200) 2022-12-06 17:46:52 +03:00
Alexander Batalov
dc90beb696 Add game mode tracking 2022-12-06 17:22:30 +03:00
Alexander Batalov
90da2164f2 Fix assignment 2022-12-06 17:13:48 +03:00
Alexander Batalov
9d9e09e80f Use MESSAGE_LIST_ITEM_FIELD_MAX_SIZE 2022-12-06 12:37:59 +03:00
sonilyan
cd51e0cdd7 Fix crash for msg limit (#203) 2022-12-06 12:32:21 +03:00
drjfaust
d49869f45c Fix several combat bugs (#204) 2022-12-06 12:17:11 +03:00
Alexander Batalov
3a541d4b67 Fix endurance label
Closes #201
2022-11-10 23:48:09 +03:00
Alexander Batalov
7471f9cdbe Fix palette fading 2022-11-10 23:43:18 +03:00
Alexander Batalov
fe9ba9171e Add custom message lists support
Closes #130
See #200
2022-11-10 18:07:23 +03:00
Alexander Batalov
6c03e4e293 Fix storing pointers in map global variables 2022-11-09 14:35:07 +03:00
Alexander Batalov
3f25c9265b Fix arguments order 2022-11-09 13:54:32 +03:00
Alexander Batalov
fa475c754e Add opReadByte
See #200
2022-11-09 13:09:56 +03:00
Alexander Batalov
5e9cf96106 Rename state structs
Fixes UB leading to crash when exiting the game
2022-11-09 11:41:53 +03:00
Alexander Batalov
a70912d311 Fix ini section parsing 2022-11-09 11:11:19 +03:00
Alexander Batalov
67351b8b09 Fix player model customization 2022-11-09 10:21:12 +03:00
Alexander Batalov
e0e0a1ee7d Add Sfall list functions
See #200
2022-11-08 22:55:25 +03:00
Alexander Batalov
fa11122f87 Make spatial script finders public 2022-11-08 22:45:30 +03:00
Alexander Batalov
ef54463fcc Add pc bonus stats opcodes
See #200
2022-11-08 18:59:14 +03:00
Alexander Batalov
2255481d50 Add missing header 2022-11-08 18:07:11 +03:00
Alexander Batalov
03a7e2e1b1 Add some Sfall global vars functions
See #200
2022-11-08 18:01:00 +03:00
Alexander Batalov
19bcfebe0d Add ammo/charges opcodes
See #200
2022-11-07 20:41:33 +03:00
Alexander Batalov
393d89f8c4 Add some Sfall opcodes
See #200
2022-11-07 20:03:04 +03:00
Alexander Batalov
9c6286f94a Increase number of opcodes 2022-11-07 19:06:37 +03:00
Alexander Batalov
fa058f24b4 Add interface bar side panels
See #3
2022-11-07 16:05:34 +03:00
Alexander Batalov
b2420bdc80 Refactor artLock with FrmImage 2022-11-07 13:55:05 +03:00
sonilyan
23bee9fd62 Add IFACE_BAR_WIDTH support (#188) 2022-11-07 13:35:22 +03:00
Alexander Batalov
3ec827d5c1 Fix worldmap position calculation
Closes #192
2022-11-07 10:59:16 +03:00
Alexander Batalov
c692fc91af Fix error check
Closes #196
2022-11-03 18:16:50 +03:00
Alexander Batalov
a38151bf2c Reorganize control flow in gdCustomSelect
Fixes #198
2022-11-03 18:08:49 +03:00
Alexander Batalov
b689b3a757 Fix combat control fields not being cleared
Closes #194
2022-11-03 17:48:34 +03:00
Alexander Batalov
e7d68c4f72 Get rid of PreferenceDescription packing
Fixes pointer alignment warnings.
2022-10-30 13:00:43 +03:00
Alexander Batalov
bc43bdc99c Rename some variables in objectSetLocation 2022-10-30 09:39:43 +03:00
Alexander Batalov
e5aa4a3518 Fix square tiles initial lookup 2022-10-30 09:31:09 +03:00
Alexander Batalov
4e98093d6c Fix crash when removing all scripts 2022-10-30 09:03:24 +03:00
Alexander Batalov
1342fd3ecf Fix warning 2022-10-30 08:45:04 +03:00
Alexander Batalov
3015f39368 Review interfaceFontGetStringWidthImpl 2022-10-30 08:41:00 +03:00
Alexander Batalov
37f7ecc1c3 Review SlotMap2Game 2022-10-29 21:27:08 +03:00
Alexander Batalov
bdf2c219ab Fix error check 2022-10-29 21:09:53 +03:00
Alexander Batalov
3488833c2e Use SDL for logging 2022-10-29 20:57:11 +03:00
Alexander Batalov
4821cab724 Review tileSetCenter flags 2022-10-29 18:52:22 +03:00
Alexander Batalov
0851354c8a Rename _square_y 2022-10-29 18:25:28 +03:00
Alexander Batalov
2f42818a33 Review square coords math 2022-10-29 18:23:53 +03:00
Alexander Batalov
12367acb33 Fix byte swapping warnings 2022-10-29 18:17:57 +03:00
Alexander Batalov
caa8b06d4f Fix UB when parsing encounter table 2022-10-29 18:14:49 +03:00
Alexander Batalov
2b63360b95 Fix memory alignment 2022-10-29 17:26:46 +03:00
Alexander Batalov
8dd8d1c312 Replace random generator 2022-10-29 17:21:54 +03:00
Alexander Batalov
8ee0f478ad Fix setting managed button procs 2022-10-28 11:02:53 +03:00
Alexander Batalov
9c6daa4abe Fix selecting managed window 2022-10-28 10:59:38 +03:00
Alexander Batalov
01f264e0c2 Fix color setters 2022-10-28 10:35:22 +03:00
Alexander Batalov
1bbd586cbb Fix trimming line ending in .lst files 2022-10-26 10:17:39 +03:00
Alexander Batalov
223930c464 Get rid of goto 2022-10-25 17:37:45 +03:00
Alexander Batalov
40510539ee Fix interface font loading 2022-10-25 15:57:31 +03:00
Alexander Batalov
c47113ca29 Force screen redraw after playing movies
Fixes #180
2022-10-25 13:05:09 +03:00
Alexander Batalov
ad9b8586e9 Fix testing pointers for nulls in Nevada
Closes #178
2022-10-25 09:57:13 +03:00
sonilyan
5b151634a5 Fix memory alignment (#187) 2022-10-25 09:12:54 +03:00
Martin Janiczek
7627092478 Make sfall key naming consistent (#172) 2022-10-25 09:05:09 +03:00
Martin Janiczek
b60fe43b06 Refactor: use enum instead of magic numbers (#176) 2022-10-25 09:04:42 +03:00
Alexander Batalov
21aec548af Add iOS support (#167) 2022-10-14 11:40:11 +03:00
Alexander Batalov
beb010cd0f Normalize fade duration
See #165
2022-10-11 17:58:02 +03:00
Alexander Batalov
b23d05f850 Fix called shot window freeze
See #165
2022-10-10 11:42:10 +03:00
Alexander Batalov
e16659d96d Fix key processing
Fixes buffer-underwrite crash on macOS when scancode is remapped to -1.
2022-10-08 12:32:50 +03:00
Alexander Batalov
4c1020af5f Fix path handling in _gsound_get_music_path 2022-10-08 10:56:46 +03:00
Alexander Batalov
a4105d5826 Decouple drawing and rendering (#165) 2022-10-08 00:54:27 +03:00
Alexander Batalov
ddae4df4ab Fix red dialog buttons 2022-10-07 23:31:17 +03:00
Alexander Batalov
74a9a9e530 Add audio engine initialization check
Fixes various bugs when movie system attemps to create audio buffer with
sound system being disabled via fallout2.cfg.
2022-10-07 15:17:07 +03:00
Alexander Batalov
223d214f57 Review lsgSaveGame
* Add scrolling
* Rename variables
2022-10-07 12:04:30 +03:00
Alexander Batalov
a52fd4e70a Review lsgLoadGame
* Add missing cleanup
* Fixes double click handling
* Rename variables
2022-10-07 11:28:42 +03:00
Alexander Batalov
266c727870 Extract renderPresent 2022-10-06 19:10:01 +03:00
Alexander Batalov
54d230432b Refactor game config with Settings (#164) 2022-10-06 16:32:46 +03:00
Alexander Batalov
9663532e44 Add missing elevator ids 2022-10-05 18:29:21 +03:00
Alexander Batalov
a4e9123bcc Fix crash in obj_use_item_on 2022-10-05 17:55:54 +03:00
Alexander Batalov
08691ce319 Fix incorrect death animation in opKillCritterType 2022-10-05 16:58:57 +03:00
Alexander Batalov
d03fd5e43f Review opGetMessageString 2022-10-05 16:07:55 +03:00
Alexander Batalov
7ddd8f2894 Fix itemGetQuantity 2022-10-05 15:44:00 +03:00
Alexander Batalov
93a341bbaa Fix arguments order 2022-10-05 14:59:00 +03:00
Alexander Batalov
d2c4538656 Fix obj_can_see_obj elevation check 2022-10-05 14:56:29 +03:00
Alexander Batalov
8a5c3bc97b Fix obj_can_hear_obj implementation 2022-10-05 14:38:19 +03:00
Alexander Batalov
db57fe6a5e Review isWithinPerception 2022-10-05 14:25:36 +03:00
Alexander Batalov
56d798dd12 Display encounter description in one line 2022-10-05 14:20:32 +03:00
Alexander Batalov
90942c46b2 Uninline obj_set_seen 2022-10-05 13:49:18 +03:00
Alexander Batalov
1cda2beef7 Fix looting corpses with NoSteal flag 2022-10-05 13:26:13 +03:00
Alexander Batalov
8754a5d6c9 Rename critter flags 2022-10-05 13:06:49 +03:00
Alexander Batalov
65f43804b3 Rename core 2022-10-05 10:35:05 +03:00
Alexander Batalov
9b150257fb Rename some input functions 2022-10-05 10:11:47 +03:00
Alexander Batalov
32c7883f82 Cleanup input.h 2022-10-05 09:54:46 +03:00
Alexander Batalov
1c73fb7240 Extract input 2022-10-05 09:23:27 +03:00
Alexander Batalov
cce1bb223e Handle window size change (#163) 2022-10-04 13:15:54 +03:00
Alexander Batalov
624076ae9b Fix Doctor skill usage 2022-10-04 09:23:17 +03:00
Alexander Batalov
8d61a19dbe Remove declarations 2022-10-03 18:11:55 +03:00
Alexander Batalov
0264c00ab8 Extract keyboard 2022-10-03 16:42:34 +03:00
Alexander Batalov
e1f22b8218 Review game state functions 2022-10-03 15:54:18 +03:00
Alexander Batalov
fe4c125474 Fix crash when dialog speaker destroys itself
See #162
2022-10-03 15:04:30 +03:00
Alexander Batalov
56d27400ac Add missing include 2022-10-03 14:52:47 +03:00
Alexander Batalov
b5681984cd Extract mouse 2022-10-03 12:41:33 +03:00
Alexander Batalov
a541d0f24a Fix type warnings 2022-10-03 10:19:22 +03:00
Alexander Batalov
20a41088c6 Remove trap.cc 2022-10-03 10:01:42 +03:00
Alexander Batalov
16ab9cb958 Fix lock check 2022-10-03 09:38:43 +03:00
Alexander Batalov
5f9ceb7f5d Extract vcr 2022-10-03 09:37:05 +03:00
Alexander Batalov
a1c1e03da0 Refactor artLockFrameData with FrmImage 2022-09-26 16:09:22 +03:00
Alexander Batalov
ac0a044a32 Refactor artLockFrameData with FrmImage 2022-09-26 15:17:22 +03:00
Alexander Batalov
4aae167bd8 Refactor artLockFrameData with FrmImage 2022-09-26 11:55:06 +03:00
Alexander Batalov
2e5be31ed4 Refactor artLockFrameData with FrmImage 2022-09-26 11:14:11 +03:00
Alexander Batalov
45278f66a5 Refactor artLockFrameData with FrmImage 2022-09-26 10:36:54 +03:00
Alexander Batalov
2205077d36 Refactor artLockFrameData with FrmImage 2022-09-26 10:28:44 +03:00
Alexander Batalov
67f966f7a9 Refactor artLockFrameData with FrmImage 2022-09-24 22:53:25 +03:00
Alexander Batalov
463968d798 Refactor artLockFrameData with FrmImage 2022-09-24 21:29:50 +03:00
Alexander Batalov
109dc6680c Refactor artLockFrameData with FrmImage 2022-09-24 21:22:40 +03:00
Alexander Batalov
23c5f070fa Refactor artLockFrameData with FrmImage 2022-09-24 21:04:32 +03:00
Alexander Batalov
fd9843f8dc Fix type warning 2022-09-24 19:43:27 +03:00
Alexander Batalov
443070226f Refactor artLockFrameData with FrmImage 2022-09-24 19:41:25 +03:00
Alexander Batalov
db63d8a085 Refactor artLockFrameData with FrmImage 2022-09-24 18:15:52 +03:00
Alexander Batalov
f203cfcc83 Refactor artLockFrameData with FrmImage 2022-09-24 17:31:13 +03:00
Alexander Batalov
9ceb490f72 Refactor artLockFrameData with FrmImage 2022-09-24 17:03:50 +03:00
Alexander Batalov
5b7a676b35 Refactor artLockFrameData with FrmImage 2022-09-24 16:51:16 +03:00
Alexander Batalov
e50e26cf87 Refactor artLockFrameData with FrmImage 2022-09-24 16:39:15 +03:00
Alexander Batalov
f59c072d68 Add FrmImage 2022-09-24 16:14:54 +03:00
Alexander Batalov
79c396c1a0 Uninline characterSelectorWindowFatalError 2022-09-24 10:28:30 +03:00
Alexander Batalov
9bb053b3ba Add namespace (#155) 2022-09-23 15:43:44 +03:00
Alexander Batalov
3168c2ec09 Improve some combat functions readability 2022-09-23 14:01:39 +03:00
300 changed files with 33132 additions and 20822 deletions

View File

@@ -1,2 +1,3 @@
BasedOnStyle: WebKit
AllowShortIfStatementsOnASingleLine: WithoutElse
FixNamespaceComments: true

1
.gitattributes vendored
View File

@@ -7,6 +7,7 @@
*.java text eol=lf
*.json text eol=lf
*.md text eol=lf
*.mm text eol=lf
*.plist text eol=lf
*.pro text eol=lf
*.properties text eol=lf

View File

@@ -26,11 +26,23 @@ jobs:
sudo apt install cppcheck
- name: Clone
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: cppcheck
run: cppcheck --std=c++17 src/
code-format:
name: Code format check
runs-on: ubuntu-latest
steps:
- name: Clone
uses: actions/checkout@v4
- name: clang-format
run: find src -type f -name \*.cc -o -name \*.h | xargs clang-format --dry-run --Werror
android:
name: Android
@@ -38,17 +50,17 @@ jobs:
steps:
- name: Clone
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 11
cache: gradle
- name: Cache cmake build
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: os/android/app/.cxx
key: android-cmake-v1
@@ -69,12 +81,58 @@ jobs:
./gradlew assembleDebug
- name: Upload
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: fallout2-ce-debug.apk
path: os/android/app/build/outputs/apk/debug/app-debug.apk
retention-days: 7
ios:
name: iOS
runs-on: macos-12
steps:
- name: Clone
uses: actions/checkout@v4
- name: Cache cmake build
uses: actions/cache@v4
with:
path: build
key: ios-cmake-v2
- name: Configure
run: |
cmake \
-B build \
-D CMAKE_TOOLCHAIN_FILE=cmake/toolchain/ios.toolchain.cmake \
-D ENABLE_BITCODE=0 \
-D PLATFORM=OS64 \
-G Xcode \
-D CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY='' \
# EOL
- name: Build
run: |
cmake \
--build build \
--config RelWithDebInfo \
-j $(sysctl -n hw.physicalcpu) \
# EOL
- name: Pack
run: |
cd build
cpack -C RelWithDebInfo
- name: Upload
uses: actions/upload-artifact@v4
with:
name: fallout2-ce.ipa
path: build/fallout2-ce.ipa
retention-days: 7
linux:
name: Linux (${{ matrix.arch }})
@@ -89,7 +147,7 @@ jobs:
steps:
- name: Clone
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Dependencies (x86)
if: matrix.arch == 'x86'
@@ -106,7 +164,7 @@ jobs:
sudo apt install libsdl2-dev zlib1g-dev
- name: Cache cmake build
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: build
key: linux-${{ matrix.arch }}-cmake-v1
@@ -136,7 +194,7 @@ jobs:
# EOL
- name: Upload
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: fallout2-ce-linux-${{ matrix.arch }}
path: build/fallout2-ce
@@ -149,34 +207,40 @@ jobs:
steps:
- name: Clone
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Cache cmake build
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: build
key: macos-cmake-v3
key: macos-cmake-v4
- name: Configure
run: |
cmake \
-B build \
-D CMAKE_BUILD_TYPE=RelWithDebInfo \
-G Xcode \
-D CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY='' \
# EOL
- name: Build
run: |
cmake \
--build build \
--config RelWithDebInfo \
-j $(sysctl -n hw.physicalcpu) \
--target package \
# EOL
- name: Pack
run: |
cd build
cpack -C RelWithDebInfo
- name: Upload
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: fallout2-ce-macos.dmg
path: build/fallout2-ce.dmg
path: build/Fallout II Community Edition.dmg
retention-days: 7
windows:
@@ -195,10 +259,10 @@ jobs:
steps:
- name: Clone
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Cache cmake build
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: build
key: windows-${{ matrix.arch }}-cmake-v1
@@ -219,7 +283,7 @@ jobs:
# EOL
- name: Upload
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: fallout2-ce-windows-${{ matrix.arch }}
path: build/RelWithDebInfo/fallout2-ce.exe

View File

@@ -17,17 +17,17 @@ jobs:
steps:
- name: Clone
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 11
cache: gradle
- name: Cache cmake build
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: os/android/app/.cxx
key: android-cmake-v1
@@ -51,11 +51,59 @@ jobs:
run: |
cd os/android/app/build/outputs/apk/release
cp app-release.apk fallout2-ce-android.apk
gh release upload ${{ github.ref_name }} fallout2-ce-android.apk
gh release upload ${{ github.event.release.tag_name }} fallout2-ce-android.apk
rm fallout2-ce-android.apk
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ios:
name: iOS
runs-on: macos-12
steps:
- name: Clone
uses: actions/checkout@v4
- name: Cache cmake build
uses: actions/cache@v4
with:
path: build
key: ios-cmake-v1
- name: Configure
run: |
cmake \
-B build \
-D CMAKE_TOOLCHAIN_FILE=cmake/toolchain/ios.toolchain.cmake \
-D ENABLE_BITCODE=0 \
-D PLATFORM=OS64 \
-G Xcode \
-D CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY='' \
# EOL
- name: Build
run: |
cmake \
--build build \
--config RelWithDebInfo \
-j $(sysctl -n hw.physicalcpu) \
# EOL
- name: Pack
run: |
cd build
cpack -C RelWithDebInfo
- name: Upload
run: |
cd build
cp fallout2-ce.ipa fallout2-ce-ios.ipa
gh release upload ${{ github.event.release.tag_name }} fallout2-ce-ios.ipa
rm fallout2-ce-ios.ipa
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
linux:
name: Linux (${{ matrix.arch }})
@@ -70,7 +118,7 @@ jobs:
steps:
- name: Clone
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Dependencies (x86)
if: matrix.arch == 'x86'
@@ -87,7 +135,7 @@ jobs:
sudo apt install libsdl2-dev zlib1g-dev
- name: Cache cmake build
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: build
key: linux-${{ matrix.arch }}-cmake-v1
@@ -120,7 +168,7 @@ jobs:
run: |
cd build
tar -czvf fallout2-ce-linux-${{ matrix.arch }}.tar.gz fallout2-ce
gh release upload ${{ github.ref_name }} fallout2-ce-linux-${{ matrix.arch }}.tar.gz
gh release upload ${{ github.event.release.tag_name }} fallout2-ce-linux-${{ matrix.arch }}.tar.gz
rm fallout2-ce-linux-${{ matrix.arch }}.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -132,16 +180,16 @@ jobs:
steps:
- name: Clone
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Import code signing certificates
uses: apple-actions/import-codesign-certs@v1
uses: apple-actions/import-codesign-certs@v2
with:
p12-file-base64: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_P12_FILE_BASE64 }}
p12-password: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_P12_PASSWORD }}
- name: Cache cmake build
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: build
key: macos-cmake-v3
@@ -150,41 +198,44 @@ jobs:
run: |
cmake \
-B build \
-D CMAKE_BUILD_TYPE=RelWithDebInfo \
-D CPACK_BUNDLE_APPLE_CERT_APP="${{ secrets.APPLE_DEVELOPER_CERTIFICATE_IDENTITY }}" \
-G Xcode \
-D CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY="${{ secrets.APPLE_DEVELOPER_CERTIFICATE_IDENTITY }}" \
-D CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_INJECT_BASE_ENTITLEMENTS="NO" \
-D CMAKE_XCODE_ATTRIBUTE_OTHER_CODE_SIGN_FLAGS="--options=runtime --timestamp" \
# EOL
- name: Build
run: |
cmake \
--build build \
--config RelWithDebInfo \
-j $(sysctl -n hw.physicalcpu) \
--target package \
# EOL
- name: Pack
run: |
cd build
cpack -C RelWithDebInfo
- name: Notarize
run: |
brew install mitchellh/gon/gon
cat << EOF > config.json
{
"notarize": {
"path": "build/fallout2-ce.dmg",
"bundle_id": "$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" build/fallout2-ce.app/Contents/Info.plist)",
"staple": true
}
}
EOF
gon config.json
rm config.json
env:
AC_USERNAME: ${{ secrets.APPLE_DEVELOPER_AC_USERNAME }}
AC_PASSWORD: ${{ secrets.APPLE_DEVELOPER_AC_PASSWORD }}
xcrun notarytool submit \
"build/Fallout II Community Edition.dmg" \
--apple-id "${{ secrets.APPLE_DEVELOPER_AC_USERNAME }}" \
--team-id "${{ secrets.APPLE_DEVELOPER_AC_TEAM }}" \
--password "${{ secrets.APPLE_DEVELOPER_AC_PASSWORD }}" \
--wait
- name: Staple
run: |
xcrun stapler staple \
"build/Fallout II Community Edition.dmg"
- name: Upload
run: |
cd build
cp fallout2-ce.dmg fallout2-ce-macos.dmg
gh release upload ${{ github.ref_name }} fallout2-ce-macos.dmg
cp "Fallout II Community Edition.dmg" fallout2-ce-macos.dmg
gh release upload ${{ github.event.release.tag_name }} fallout2-ce-macos.dmg
rm fallout2-ce-macos.dmg
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -205,10 +256,10 @@ jobs:
steps:
- name: Clone
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Cache cmake build
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: build
key: windows-${{ matrix.arch }}-cmake-v1
@@ -232,7 +283,7 @@ jobs:
run: |
cd build/RelWithDebInfo
7z a fallout2-ce-windows-${{ matrix.arch }}.zip fallout2-ce.exe
gh release upload ${{ github.ref_name }} fallout2-ce-windows-${{ matrix.arch }}.zip
gh release upload ${{ github.event.release.tag_name }} fallout2-ce-windows-${{ matrix.arch }}.zip
rm fallout2-ce-windows-${{ matrix.arch }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -4,9 +4,14 @@ set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(EXECUTABLE_NAME fallout2-ce)
if (APPLE)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11" CACHE STRING "")
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "")
if(APPLE)
if(IOS)
set(CMAKE_OSX_DEPLOYMENT_TARGET "11" CACHE STRING "")
set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE STRING "")
else()
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11" CACHE STRING "")
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "")
endif()
endif()
project(${EXECUTABLE_NAME})
@@ -15,7 +20,7 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)
if (ANDROID)
if(ANDROID)
add_library(${EXECUTABLE_NAME} SHARED)
else()
add_executable(${EXECUTABLE_NAME} WIN32 MACOSX_BUNDLE)
@@ -52,8 +57,6 @@ target_sources(${EXECUTABLE_NAME} PUBLIC
"src/combat.h"
"src/config.cc"
"src/config.h"
"src/core.cc"
"src/core.h"
"src/credits.cc"
"src/credits.h"
"src/critter.cc"
@@ -80,8 +83,6 @@ target_sources(${EXECUTABLE_NAME} PUBLIC
"src/display_monitor.h"
"src/draw.cc"
"src/draw.h"
"src/electronic_registration.cc"
"src/electronic_registration.h"
"src/elevator.cc"
"src/elevator.h"
"src/endgame.cc"
@@ -104,8 +105,6 @@ target_sources(${EXECUTABLE_NAME} PUBLIC
"src/game_mouse.h"
"src/game_movie.cc"
"src/game_movie.h"
"src/game_palette.cc"
"src/game_palette.h"
"src/game_sound.cc"
"src/game_sound.h"
"src/game_vars.h"
@@ -115,10 +114,10 @@ target_sources(${EXECUTABLE_NAME} PUBLIC
"src/geometry.h"
"src/graph_lib.cc"
"src/graph_lib.h"
"src/grayscale.cc"
"src/grayscale.h"
"src/heap.cc"
"src/heap.h"
"src/input.cc"
"src/input.h"
"src/interface.cc"
"src/interface.h"
"src/interpreter_extra.cc"
@@ -131,6 +130,8 @@ target_sources(${EXECUTABLE_NAME} PUBLIC
"src/inventory.h"
"src/item.cc"
"src/item.h"
"src/kb.cc"
"src/kb.h"
"src/light.cc"
"src/light.h"
"src/lips.cc"
@@ -139,6 +140,8 @@ target_sources(${EXECUTABLE_NAME} PUBLIC
"src/loadsave.h"
"src/main.cc"
"src/main.h"
"src/mainmenu.cc"
"src/mainmenu.h"
"src/map_defs.h"
"src/map.cc"
"src/map.h"
@@ -149,10 +152,10 @@ target_sources(${EXECUTABLE_NAME} PUBLIC
"src/memory.h"
"src/message.cc"
"src/message.h"
"src/mmx.cc"
"src/mmx.h"
"src/mouse_manager.cc"
"src/mouse_manager.h"
"src/mouse.cc"
"src/mouse.h"
"src/movie_effect.cc"
"src/movie_effect.h"
"src/movie_lib.cc"
@@ -214,6 +217,8 @@ target_sources(${EXECUTABLE_NAME} PUBLIC
"src/stat.h"
"src/string_parsers.cc"
"src/string_parsers.h"
"src/svga.cc"
"src/svga.h"
"src/text_font.cc"
"src/text_font.h"
"src/text_object.cc"
@@ -223,8 +228,8 @@ target_sources(${EXECUTABLE_NAME} PUBLIC
"src/trait_defs.h"
"src/trait.cc"
"src/trait.h"
"src/trap.cc"
"src/trap.h"
"src/vcr.cc"
"src/vcr.h"
"src/version.cc"
"src/version.h"
"src/widget.cc"
@@ -248,25 +253,53 @@ target_sources(${EXECUTABLE_NAME} PUBLIC
target_sources(${EXECUTABLE_NAME} PUBLIC
"src/audio_engine.cc"
"src/audio_engine.h"
"src/delay.cc"
"src/delay.h"
"src/fps_limiter.cc"
"src/fps_limiter.h"
"src/platform_compat.cc"
"src/platform_compat.h"
"src/pointer_registry.cc"
"src/pointer_registry.h"
"src/preferences.cc"
"src/preferences.h"
"src/settings.cc"
"src/settings.h"
"src/sfall_config.cc"
"src/sfall_config.h"
"src/sfall_global_vars.cc"
"src/sfall_global_vars.h"
"src/sfall_global_scripts.cc"
"src/sfall_global_scripts.h"
"src/sfall_ini.cc"
"src/sfall_ini.h"
"src/sfall_kb_helpers.cc"
"src/sfall_kb_helpers.h"
"src/sfall_lists.cc"
"src/sfall_lists.h"
"src/sfall_metarules.cc"
"src/sfall_metarules.h"
"src/sfall_opcodes.cc"
"src/sfall_opcodes.h"
"src/sfall_arrays.cc"
"src/sfall_arrays.h"
"src/touch.cc"
"src/touch.h"
)
if(IOS)
target_sources(${EXECUTABLE_NAME} PUBLIC
"src/platform/ios/paths.h"
"src/platform/ios/paths.mm"
)
endif()
if(WIN32)
target_compile_definitions(${EXECUTABLE_NAME} PUBLIC
_CRT_SECURE_NO_WARNINGS
_CRT_NONSTDC_NO_WARNINGS
)
else()
target_compile_definitions(${EXECUTABLE_NAME} PRIVATE
$<$<CONFIG:Debug>:_DEBUG>
$<$<CONFIG:RelWithDebInfo>:_DEBUG>
NOMINMAX
WIN32_LEAN_AND_MEAN
)
endif()
@@ -276,7 +309,7 @@ if(WIN32)
)
endif()
if (WIN32)
if(WIN32)
target_sources(${EXECUTABLE_NAME} PUBLIC
"os/windows/fallout2-ce.ico"
"os/windows/fallout2-ce.rc"
@@ -284,23 +317,54 @@ if (WIN32)
endif()
if(APPLE)
target_sources(${EXECUTABLE_NAME} PUBLIC "os/macos/fallout2-ce.icns")
set_source_files_properties("os/macos/fallout2-ce.icns" PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
if(IOS)
set(RESOURCES
"os/ios/AppIcon.xcassets"
"os/ios/LaunchScreen.storyboard"
)
target_sources(${EXECUTABLE_NAME} PUBLIC ${RESOURCES})
set_source_files_properties(${RESOURCES} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
set_target_properties(${EXECUTABLE_NAME} PROPERTIES
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_SOURCE_DIR}/os/ios/Info.plist"
XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_APPICON_NAME "AppIcon"
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.alexbatalov.fallout2-ce"
XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2"
)
set(MACOSX_BUNDLE_BUNDLE_NAME "${EXECUTABLE_NAME}")
set(MACOSX_BUNDLE_DISPLAY_NAME "Fallout 2")
else()
set(RESOURCES
"os/macos/fallout2-ce.icns"
)
target_sources(${EXECUTABLE_NAME} PUBLIC ${RESOURCES})
set_source_files_properties(${RESOURCES} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
set_target_properties(${EXECUTABLE_NAME} PROPERTIES
OUTPUT_NAME "Fallout II Community Edition"
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_SOURCE_DIR}/os/macos/Info.plist"
XCODE_ATTRIBUTE_EXECUTABLE_NAME "${EXECUTABLE_NAME}"
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.alexbatalov.fallout2-ce"
)
set(MACOSX_BUNDLE_ICON_FILE "fallout2-ce.icns")
set(MACOSX_BUNDLE_BUNDLE_NAME "Fallout II: Community Edition")
set(MACOSX_BUNDLE_DISPLAY_NAME "Fallout II")
endif()
set_target_properties(${EXECUTABLE_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_SOURCE_DIR}/os/macos/Info.plist")
set(MACOSX_BUNDLE_GUI_IDENTIFIER "com.alexbatalov.fallout2-ce")
set(MACOSX_BUNDLE_BUNDLE_NAME "${EXECUTABLE_NAME}")
set(MACOSX_BUNDLE_ICON_FILE "fallout2-ce.icns")
set(MACOSX_BUNDLE_DISPLAY_NAME "Fallout 2")
set(MACOSX_BUNDLE_SHORT_VERSION_STRING "1.1.0")
set(MACOSX_BUNDLE_BUNDLE_VERSION "1.1.0")
set(MACOSX_BUNDLE_SHORT_VERSION_STRING "1.3.0")
set(MACOSX_BUNDLE_BUNDLE_VERSION "1.3.0")
endif()
add_subdirectory("third_party/fpattern")
target_link_libraries(${EXECUTABLE_NAME} ${FPATTERN_LIBRARY})
target_include_directories(${EXECUTABLE_NAME} PRIVATE ${FPATTERN_INCLUDE_DIR})
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if((NOT ${CMAKE_SYSTEM_NAME} MATCHES "Linux") AND (NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") AND (NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD"))
add_subdirectory("third_party/zlib")
add_subdirectory("third_party/sdl2")
else()
@@ -315,23 +379,20 @@ target_link_libraries(${EXECUTABLE_NAME} ${SDL2_LIBRARIES})
target_include_directories(${EXECUTABLE_NAME} PRIVATE ${SDL2_INCLUDE_DIRS})
if(APPLE)
install(TARGETS ${EXECUTABLE_NAME} DESTINATION .)
install(CODE "
include(BundleUtilities)
fixup_bundle(${CMAKE_BINARY_DIR}/${MACOSX_BUNDLE_BUNDLE_NAME}.app \"\" \"\")
"
COMPONENT Runtime)
if(IOS)
install(TARGETS ${EXECUTABLE_NAME} DESTINATION "Payload")
if (CPACK_BUNDLE_APPLE_CERT_APP)
install(CODE "
execute_process(COMMAND codesign --deep --force --options runtime --sign \"${CPACK_BUNDLE_APPLE_CERT_APP}\" ${CMAKE_BINARY_DIR}/${MACOSX_BUNDLE_BUNDLE_NAME}.app)
"
COMPONENT Runtime)
set(CPACK_GENERATOR "ZIP")
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
set(CPACK_PACKAGE_FILE_NAME "fallout2-ce")
set(CPACK_ARCHIVE_FILE_EXTENSION "ipa")
else()
install(TARGETS ${EXECUTABLE_NAME} DESTINATION .)
set(CPACK_GENERATOR "DragNDrop")
set(CPACK_DMG_DISABLE_APPLICATIONS_SYMLINK ON)
set(CPACK_PACKAGE_FILE_NAME "Fallout II Community Edition")
endif()
set(CPACK_GENERATOR "DragNDrop")
set(CPACK_DMG_DISABLE_APPLICATIONS_SYMLINK ON)
set(CPACK_PACKAGE_FILE_NAME "fallout2-ce")
include(CPack)
endif()

View File

@@ -1,8 +1,14 @@
# Fallout 2 Community Edition
Fallout 2 Community Edition is a fully working re-implementation of Fallout 2, with the same original gameplay, engine bugfixes, and some quality of life improvements, that works (mostly) hassle-free on multiple platforms.
Popular Fallout 2 total conversion mods are partially supported. Original versions of Nevada and Sonora (that do not rely on extended features provided by Sfall) likely work, although there is no complete walkthrough confirmation yet. [Fallout 2 Restoration Project](https://github.com/BGforgeNet/Fallout2_Restoration_Project), [Fallout Et Tu](https://github.com/rotators/Fo1in2) and [Olympus 2207](https://olympus2207.com) are not yet supported. Other mods (particularly Resurrection and Yesterday) are not tested.
There is also [Fallout Community Edition](https://github.com/alexbatalov/fallout1-ce).
## Installation
You must own the game to play. Purchase your copy on [GOG](https://www.gog.com/game/fallout_2) or [Steam](https://store.steampowered.com/app/38410). Download latest release or build from source.
You must own the game to play. Purchase your copy on [GOG](https://www.gog.com/game/fallout_2) or [Steam](https://store.steampowered.com/app/38410). Download latest [release](https://github.com/alexbatalov/fallout2-ce/releases) or build from source. You can also check latest [debug](https://github.com/alexbatalov/fallout2-ce/actions) build intended for testers.
### Windows
@@ -36,13 +42,53 @@ $ sudo apt install libsdl2-2.0-0
### Android
> **NOTE**: Fallout 2 was designed with mouse in mind. There are many controls that require precise cursor positioning, which is not possible with fingers. When playing on Android you'll use fingers to move mouse cursor, not a character, or a map. Double tap to "click" left mouse button in the current cursor position, triple tap to "click" right mouse button. It might feel awkward at first, but it's super handy - you can play with just a thumb. This is not set in stone and might change in the future.
> **NOTE**: Fallout 2 was designed with mouse in mind. There are many controls that require precise cursor positioning, which is not possible with fingers. Current control scheme resembles trackpad usage:
- One finger moves mouse cursor around.
- Tap one finger for left mouse click.
- Tap two fingers for right mouse click (switches mouse cursor mode).
- Move two fingers to scroll current view (map view, worldmap view, inventory scrollers).
- Use Windows installation as a base - it contains data assets needed to play. Copy `Fallout2` folder to your device, for example to `Downloads`. You need `master.dat`, `critter.dat`, `patch000.dat`, and `data` folder.
> **NOTE**: From Android standpoint release and debug builds are different apps. Both apps require their own copy of game assets and have their own savegames. This is intentional. As a gamer just stick with release version and check for updates.
- Use Windows installation as a base - it contains data assets needed to play. Copy `Fallout2` folder to your device, for example to `Downloads`. You need `master.dat`, `critter.dat`, `patch000.dat`, and `data` folder. Watch for file names - keep (or make) them lowercased (see [Configuration](#configuration)).
- Download `fallout2-ce.apk` and copy it to your device. Open it with file explorer, follow instructions (install from unknown source).
- When you run the game for the first time it will immediately present file picker. Select the folder from the first step. Wait until this data is copied. A loading dialog will appear, just wait for about 30 seconds. The game will start automatically.
- When you run the game for the first time it will immediately present file picker. Select the folder from the first step. Wait until this data is copied. A loading dialog will appear, just wait for about 30 seconds. If you're installing total conversion mod or localized version with a large number of unpacked resources in `data` folder it can take up to 20 minutes. Once copied, the game will start automatically.
### iOS
> **NOTE**: See Android note on controls.
- Download `fallout2-ce.ipa`. Use sideloading applications ([AltStore](https://altstore.io/) or [Sideloadly](https://sideloadly.io/)) to install it to your device. Alternatively you can always build from source with your own signing certificate.
- Run the game once. You'll see error message saying "Couldn't find/load text fonts". This step is needed for iOS to expose the game via File Sharing feature.
- Use Finder (macOS Catalina and later) or iTunes (Windows and macOS Mojave or earlier) to copy `master.dat`, `critter.dat`, `patch000.dat`, and `data` folder to "Fallout 2" app ([how-to](https://support.apple.com/HT210598)). Watch for file names - keep (or make) them lowercased (see [Configuration](#configuration)).
## Configuration
The main configuration file is `fallout2.cfg`. There are several important settings you might need to adjust for your installation. Depending on your Fallout distribution main game assets `master.dat`, `critter.dat`, `patch000.dat`, and `data` folder might be either all lowercased, or all uppercased. You can either update `master_dat`, `critter_dat`, `master_patches` and `critter_patches` settings to match your file names, or rename files to match entries in your `fallout2.cfg`.
The `sound` folder (with `music` folder inside) might be located either in `data` folder, or be in the Fallout folder. Update `music_path1` setting to match your hierarchy, usually it's `data/sound/music/` or `sound/music/`. Make sure it matches your path exactly (so it might be `SOUND/MUSIC/` if you've installed Fallout from CD). Music files themselves (with `ACM` extension) should be all uppercased, regardless of `sound` and `music` folders.
The second configuration file is `f2_res.ini`. Use it to change game window size and enable/disable fullscreen mode.
```ini
[MAIN]
SCR_WIDTH=1280
SCR_HEIGHT=720
WINDOWED=1
```
Recommendations:
- **Desktops**: Use any size you see fit.
- **Tablets**: Set these values to logical resolution of your device, for example iPad Pro 11 is 1668x2388 (pixels), but it's logical resolution is 834x1194 (points).
- **Mobile phones**: Set height to 480, calculate width according to your device screen (aspect) ratio, for example Samsung S21 is 20:9 device, so the width should be 480 * 20 / 9 = 1067.
In time this stuff will receive in-game interface, right now you have to do it manually.
The third configuration file is `ddraw.ini` (part of Sfall). There are dozens of options that adjust or override engine behaviour and gameplay mechanics. This file is intended for modders and advanced users. Currently only a small subset of these settings are actually implemented.
## Contributing

File diff suppressed because it is too large Load Diff

View File

@@ -9,8 +9,8 @@ android {
applicationId 'com.alexbatalov.fallout2ce'
minSdk 21
targetSdk 32
versionCode 2
versionName '1.1.0'
versionCode 4
versionName '1.3.0'
externalNativeBuild {
cmake {
arguments '-DANDROID_STL=c++_static'

View File

@@ -15,13 +15,9 @@ import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@@ -37,11 +33,8 @@ import android.view.Display;
import android.view.Gravity;
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.PointerIcon;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
@@ -51,6 +44,7 @@ import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
@@ -65,6 +59,9 @@ import java.util.Locale;
*/
public class SDLActivity extends Activity implements View.OnSystemUiVisibilityChangeListener {
private static final String TAG = "SDL";
private static final int SDL_MAJOR_VERSION = 2;
private static final int SDL_MINOR_VERSION = 26;
private static final int SDL_MICRO_VERSION = 1;
/*
// Display InputType.SOURCE/CLASS of events and devices
//
@@ -213,7 +210,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
// Main components
protected static SDLActivity mSingleton;
protected static SDLSurface mSurface;
protected static View mTextEdit;
protected static DummyEdit mTextEdit;
protected static boolean mScreenKeyboardShown;
protected static ViewGroup mLayout;
protected static SDLClipboardHandler mClipboardHandler;
@@ -314,6 +311,10 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
mNextNativeState = NativeState.INIT;
mCurrentNativeState = NativeState.INIT;
}
protected SDLSurface createSDLSurface(Context context) {
return new SDLSurface(context);
}
// Setup
@Override
@@ -344,8 +345,18 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
errorMsgBrokenLib = e.getMessage();
}
if (mBrokenLibraries)
{
if (!mBrokenLibraries) {
String expected_version = String.valueOf(SDL_MAJOR_VERSION) + "." +
String.valueOf(SDL_MINOR_VERSION) + "." +
String.valueOf(SDL_MICRO_VERSION);
String version = nativeGetVersion();
if (!version.equals(expected_version)) {
mBrokenLibraries = true;
errorMsgBrokenLib = "SDL C/Java version mismatch (expected " + expected_version + ", got " + version + ")";
}
}
if (mBrokenLibraries) {
mSingleton = this;
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
dlgAlert.setMessage("An error occurred while trying to start the application. Please try again and/or reinstall."
@@ -382,7 +393,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
mHIDDeviceManager = HIDDeviceManager.acquire(this);
// Set up the surface
mSurface = new SDLSurface(getApplication());
mSurface = createSDLSurface(getApplication());
mLayout = new RelativeLayout(this);
mLayout.addView(mSurface);
@@ -886,6 +897,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
}
// C functions we call
public static native String nativeGetVersion();
public static native int nativeSetupJNI();
public static native int nativeRunMain(String library, String function, Object arguments);
public static native void nativeLowMemory();
@@ -1220,8 +1232,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
}
// This method is called by SDLControllerManager's API 26 Generic Motion Handler.
public static View getContentView()
{
public static View getContentView() {
return mLayout;
}
@@ -1292,6 +1303,77 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
return event.isPrintingKey() || event.getKeyCode() == KeyEvent.KEYCODE_SPACE;
}
public static boolean handleKeyEvent(View v, int keyCode, KeyEvent event, InputConnection ic) {
int deviceId = event.getDeviceId();
int source = event.getSource();
if (source == InputDevice.SOURCE_UNKNOWN) {
InputDevice device = InputDevice.getDevice(deviceId);
if (device != null) {
source = device.getSources();
}
}
// if (event.getAction() == KeyEvent.ACTION_DOWN) {
// Log.v("SDL", "key down: " + keyCode + ", deviceId = " + deviceId + ", source = " + source);
// } else if (event.getAction() == KeyEvent.ACTION_UP) {
// Log.v("SDL", "key up: " + keyCode + ", deviceId = " + deviceId + ", source = " + source);
// }
// Dispatch the different events depending on where they come from
// Some SOURCE_JOYSTICK, SOURCE_DPAD or SOURCE_GAMEPAD are also SOURCE_KEYBOARD
// So, we try to process them as JOYSTICK/DPAD/GAMEPAD events first, if that fails we try them as KEYBOARD
//
// Furthermore, it's possible a game controller has SOURCE_KEYBOARD and
// SOURCE_JOYSTICK, while its key events arrive from the keyboard source
// So, retrieve the device itself and check all of its sources
if (SDLControllerManager.isDeviceSDLJoystick(deviceId)) {
// Note that we process events with specific key codes here
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (SDLControllerManager.onNativePadDown(deviceId, keyCode) == 0) {
return true;
}
} else if (event.getAction() == KeyEvent.ACTION_UP) {
if (SDLControllerManager.onNativePadUp(deviceId, keyCode) == 0) {
return true;
}
}
}
if ((source & InputDevice.SOURCE_KEYBOARD) == InputDevice.SOURCE_KEYBOARD) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (isTextInputEvent(event)) {
if (ic != null) {
ic.commitText(String.valueOf((char) event.getUnicodeChar()), 1);
} else {
SDLInputConnection.nativeCommitText(String.valueOf((char) event.getUnicodeChar()), 1);
}
}
onNativeKeyDown(keyCode);
return true;
} else if (event.getAction() == KeyEvent.ACTION_UP) {
onNativeKeyUp(keyCode);
return true;
}
}
if ((source & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) {
// on some devices key events are sent for mouse BUTTON_BACK/FORWARD presses
// they are ignored here because sending them as mouse input to SDL is messy
if ((keyCode == KeyEvent.KEYCODE_BACK) || (keyCode == KeyEvent.KEYCODE_FORWARD)) {
switch (event.getAction()) {
case KeyEvent.ACTION_DOWN:
case KeyEvent.ACTION_UP:
// mark the event as handled or it will be handled by system
// handling KEYCODE_BACK by system will call onBackPressed()
return true;
}
}
}
return false;
}
/**
* This method is called by SDL using JNI.
*/
@@ -1809,455 +1891,6 @@ class SDLMain implements Runnable {
}
}
/**
SDLSurface. This is what we draw on, so we need to know when it's created
in order to do anything useful.
Because of this, that's where we set up the SDL thread
*/
class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
View.OnKeyListener, View.OnTouchListener, SensorEventListener {
// Sensors
protected SensorManager mSensorManager;
protected Display mDisplay;
// Keep track of the surface size to normalize touch events
protected float mWidth, mHeight;
// Is SurfaceView ready for rendering
public boolean mIsSurfaceReady;
// Startup
public SDLSurface(Context context) {
super(context);
getHolder().addCallback(this);
setFocusable(true);
setFocusableInTouchMode(true);
requestFocus();
setOnKeyListener(this);
setOnTouchListener(this);
mDisplay = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
setOnGenericMotionListener(SDLActivity.getMotionListener());
// Some arbitrary defaults to avoid a potential division by zero
mWidth = 1.0f;
mHeight = 1.0f;
mIsSurfaceReady = false;
}
public void handlePause() {
enableSensor(Sensor.TYPE_ACCELEROMETER, false);
}
public void handleResume() {
setFocusable(true);
setFocusableInTouchMode(true);
requestFocus();
setOnKeyListener(this);
setOnTouchListener(this);
enableSensor(Sensor.TYPE_ACCELEROMETER, true);
}
public Surface getNativeSurface() {
return getHolder().getSurface();
}
// Called when we have a valid drawing surface
@Override
public void surfaceCreated(SurfaceHolder holder) {
Log.v("SDL", "surfaceCreated()");
SDLActivity.onNativeSurfaceCreated();
}
// Called when we lose the surface
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
Log.v("SDL", "surfaceDestroyed()");
// Transition to pause, if needed
SDLActivity.mNextNativeState = SDLActivity.NativeState.PAUSED;
SDLActivity.handleNativeState();
mIsSurfaceReady = false;
SDLActivity.onNativeSurfaceDestroyed();
}
// Called when the surface is resized
@Override
public void surfaceChanged(SurfaceHolder holder,
int format, int width, int height) {
Log.v("SDL", "surfaceChanged()");
if (SDLActivity.mSingleton == null) {
return;
}
mWidth = width;
mHeight = height;
int nDeviceWidth = width;
int nDeviceHeight = height;
try
{
if (Build.VERSION.SDK_INT >= 17) {
DisplayMetrics realMetrics = new DisplayMetrics();
mDisplay.getRealMetrics( realMetrics );
nDeviceWidth = realMetrics.widthPixels;
nDeviceHeight = realMetrics.heightPixels;
}
} catch(Exception ignored) {
}
synchronized(SDLActivity.getContext()) {
// In case we're waiting on a size change after going fullscreen, send a notification.
SDLActivity.getContext().notifyAll();
}
Log.v("SDL", "Window size: " + width + "x" + height);
Log.v("SDL", "Device size: " + nDeviceWidth + "x" + nDeviceHeight);
SDLActivity.nativeSetScreenResolution(width, height, nDeviceWidth, nDeviceHeight, mDisplay.getRefreshRate());
SDLActivity.onNativeResize();
// Prevent a screen distortion glitch,
// for instance when the device is in Landscape and a Portrait App is resumed.
boolean skip = false;
int requestedOrientation = SDLActivity.mSingleton.getRequestedOrientation();
if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
if (mWidth > mHeight) {
skip = true;
}
} else if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
if (mWidth < mHeight) {
skip = true;
}
}
// Special Patch for Square Resolution: Black Berry Passport
if (skip) {
double min = Math.min(mWidth, mHeight);
double max = Math.max(mWidth, mHeight);
if (max / min < 1.20) {
Log.v("SDL", "Don't skip on such aspect-ratio. Could be a square resolution.");
skip = false;
}
}
// Don't skip in MultiWindow.
if (skip) {
if (Build.VERSION.SDK_INT >= 24) {
if (SDLActivity.mSingleton.isInMultiWindowMode()) {
Log.v("SDL", "Don't skip in Multi-Window");
skip = false;
}
}
}
if (skip) {
Log.v("SDL", "Skip .. Surface is not ready.");
mIsSurfaceReady = false;
return;
}
/* If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here */
SDLActivity.onNativeSurfaceChanged();
/* Surface is ready */
mIsSurfaceReady = true;
SDLActivity.mNextNativeState = SDLActivity.NativeState.RESUMED;
SDLActivity.handleNativeState();
}
// Key events
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
int deviceId = event.getDeviceId();
int source = event.getSource();
if (source == InputDevice.SOURCE_UNKNOWN) {
InputDevice device = InputDevice.getDevice(deviceId);
if (device != null) {
source = device.getSources();
}
}
// if (event.getAction() == KeyEvent.ACTION_DOWN) {
// Log.v("SDL", "key down: " + keyCode + ", deviceId = " + deviceId + ", source = " + source);
// } else if (event.getAction() == KeyEvent.ACTION_UP) {
// Log.v("SDL", "key up: " + keyCode + ", deviceId = " + deviceId + ", source = " + source);
// }
// Dispatch the different events depending on where they come from
// Some SOURCE_JOYSTICK, SOURCE_DPAD or SOURCE_GAMEPAD are also SOURCE_KEYBOARD
// So, we try to process them as JOYSTICK/DPAD/GAMEPAD events first, if that fails we try them as KEYBOARD
//
// Furthermore, it's possible a game controller has SOURCE_KEYBOARD and
// SOURCE_JOYSTICK, while its key events arrive from the keyboard source
// So, retrieve the device itself and check all of its sources
if (SDLControllerManager.isDeviceSDLJoystick(deviceId)) {
// Note that we process events with specific key codes here
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (SDLControllerManager.onNativePadDown(deviceId, keyCode) == 0) {
return true;
}
} else if (event.getAction() == KeyEvent.ACTION_UP) {
if (SDLControllerManager.onNativePadUp(deviceId, keyCode) == 0) {
return true;
}
}
}
if ((source & InputDevice.SOURCE_KEYBOARD) == InputDevice.SOURCE_KEYBOARD) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (SDLActivity.isTextInputEvent(event)) {
SDLInputConnection.nativeCommitText(String.valueOf((char) event.getUnicodeChar()), 1);
}
SDLActivity.onNativeKeyDown(keyCode);
return true;
} else if (event.getAction() == KeyEvent.ACTION_UP) {
SDLActivity.onNativeKeyUp(keyCode);
return true;
}
}
if ((source & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) {
// on some devices key events are sent for mouse BUTTON_BACK/FORWARD presses
// they are ignored here because sending them as mouse input to SDL is messy
if ((keyCode == KeyEvent.KEYCODE_BACK) || (keyCode == KeyEvent.KEYCODE_FORWARD)) {
switch (event.getAction()) {
case KeyEvent.ACTION_DOWN:
case KeyEvent.ACTION_UP:
// mark the event as handled or it will be handled by system
// handling KEYCODE_BACK by system will call onBackPressed()
return true;
}
}
}
return false;
}
// Touch events
@Override
public boolean onTouch(View v, MotionEvent event) {
/* Ref: http://developer.android.com/training/gestures/multi.html */
int touchDevId = event.getDeviceId();
final int pointerCount = event.getPointerCount();
int action = event.getActionMasked();
int pointerFingerId;
int i = -1;
float x,y,p;
/*
* Prevent id to be -1, since it's used in SDL internal for synthetic events
* Appears when using Android emulator, eg:
* adb shell input mouse tap 100 100
* adb shell input touchscreen tap 100 100
*/
if (touchDevId < 0) {
touchDevId -= 1;
}
// 12290 = Samsung DeX mode desktop mouse
// 12290 = 0x3002 = 0x2002 | 0x1002 = SOURCE_MOUSE | SOURCE_TOUCHSCREEN
// 0x2 = SOURCE_CLASS_POINTER
if (event.getSource() == InputDevice.SOURCE_MOUSE || event.getSource() == (InputDevice.SOURCE_MOUSE | InputDevice.SOURCE_TOUCHSCREEN)) {
int mouseButton = 1;
try {
Object object = event.getClass().getMethod("getButtonState").invoke(event);
if (object != null) {
mouseButton = (Integer) object;
}
} catch(Exception ignored) {
}
// We need to check if we're in relative mouse mode and get the axis offset rather than the x/y values
// if we are. We'll leverage our existing mouse motion listener
SDLGenericMotionListener_API12 motionListener = SDLActivity.getMotionListener();
x = motionListener.getEventX(event);
y = motionListener.getEventY(event);
SDLActivity.onNativeMouse(mouseButton, action, x, y, motionListener.inRelativeMode());
} else {
switch(action) {
case MotionEvent.ACTION_MOVE:
for (i = 0; i < pointerCount; i++) {
pointerFingerId = event.getPointerId(i);
x = event.getX(i) / mWidth;
y = event.getY(i) / mHeight;
p = event.getPressure(i);
if (p > 1.0f) {
// may be larger than 1.0f on some devices
// see the documentation of getPressure(i)
p = 1.0f;
}
SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_DOWN:
// Primary pointer up/down, the index is always zero
i = 0;
/* fallthrough */
case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_POINTER_DOWN:
// Non primary pointer up/down
if (i == -1) {
i = event.getActionIndex();
}
pointerFingerId = event.getPointerId(i);
x = event.getX(i) / mWidth;
y = event.getY(i) / mHeight;
p = event.getPressure(i);
if (p > 1.0f) {
// may be larger than 1.0f on some devices
// see the documentation of getPressure(i)
p = 1.0f;
}
SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
break;
case MotionEvent.ACTION_CANCEL:
for (i = 0; i < pointerCount; i++) {
pointerFingerId = event.getPointerId(i);
x = event.getX(i) / mWidth;
y = event.getY(i) / mHeight;
p = event.getPressure(i);
if (p > 1.0f) {
// may be larger than 1.0f on some devices
// see the documentation of getPressure(i)
p = 1.0f;
}
SDLActivity.onNativeTouch(touchDevId, pointerFingerId, MotionEvent.ACTION_UP, x, y, p);
}
break;
default:
break;
}
}
return true;
}
// Sensor events
public void enableSensor(int sensortype, boolean enabled) {
// TODO: This uses getDefaultSensor - what if we have >1 accels?
if (enabled) {
mSensorManager.registerListener(this,
mSensorManager.getDefaultSensor(sensortype),
SensorManager.SENSOR_DELAY_GAME, null);
} else {
mSensorManager.unregisterListener(this,
mSensorManager.getDefaultSensor(sensortype));
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// TODO
}
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
// Since we may have an orientation set, we won't receive onConfigurationChanged events.
// We thus should check here.
int newOrientation;
float x, y;
switch (mDisplay.getRotation()) {
case Surface.ROTATION_90:
x = -event.values[1];
y = event.values[0];
newOrientation = SDLActivity.SDL_ORIENTATION_LANDSCAPE;
break;
case Surface.ROTATION_270:
x = event.values[1];
y = -event.values[0];
newOrientation = SDLActivity.SDL_ORIENTATION_LANDSCAPE_FLIPPED;
break;
case Surface.ROTATION_180:
x = -event.values[0];
y = -event.values[1];
newOrientation = SDLActivity.SDL_ORIENTATION_PORTRAIT_FLIPPED;
break;
case Surface.ROTATION_0:
default:
x = event.values[0];
y = event.values[1];
newOrientation = SDLActivity.SDL_ORIENTATION_PORTRAIT;
break;
}
if (newOrientation != SDLActivity.mCurrentOrientation) {
SDLActivity.mCurrentOrientation = newOrientation;
SDLActivity.onNativeOrientationChanged(newOrientation);
}
SDLActivity.onNativeAccel(-x / SensorManager.GRAVITY_EARTH,
y / SensorManager.GRAVITY_EARTH,
event.values[2] / SensorManager.GRAVITY_EARTH);
}
}
// Captured pointer events for API 26.
public boolean onCapturedPointerEvent(MotionEvent event)
{
int action = event.getActionMasked();
float x, y;
switch (action) {
case MotionEvent.ACTION_SCROLL:
x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, 0);
y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, 0);
SDLActivity.onNativeMouse(0, action, x, y, false);
return true;
case MotionEvent.ACTION_HOVER_MOVE:
case MotionEvent.ACTION_MOVE:
x = event.getX(0);
y = event.getY(0);
SDLActivity.onNativeMouse(0, action, x, y, true);
return true;
case MotionEvent.ACTION_BUTTON_PRESS:
case MotionEvent.ACTION_BUTTON_RELEASE:
// Change our action value to what SDL's code expects.
if (action == MotionEvent.ACTION_BUTTON_PRESS) {
action = MotionEvent.ACTION_DOWN;
} else { /* MotionEvent.ACTION_BUTTON_RELEASE */
action = MotionEvent.ACTION_UP;
}
x = event.getX(0);
y = event.getY(0);
int button = event.getButtonState();
SDLActivity.onNativeMouse(button, action, x, y, true);
return true;
}
return false;
}
}
/* This is a fake invisible editor view that receives the input and defines the
* pan&scan region
*/
@@ -2278,21 +1911,7 @@ class DummyEdit extends View implements View.OnKeyListener {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
/*
* This handles the hardware keyboard input
*/
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (SDLActivity.isTextInputEvent(event)) {
ic.commitText(String.valueOf((char) event.getUnicodeChar()), 1);
return true;
}
SDLActivity.onNativeKeyDown(keyCode);
return true;
} else if (event.getAction() == KeyEvent.ACTION_UP) {
SDLActivity.onNativeKeyUp(keyCode);
return true;
}
return false;
return SDLActivity.handleKeyEvent(v, keyCode, event, ic);
}
//
@@ -2316,9 +1935,10 @@ class DummyEdit extends View implements View.OnKeyListener {
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
ic = new SDLInputConnection(this, true);
outAttrs.inputType = InputType.TYPE_CLASS_TEXT;
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI
| EditorInfo.IME_FLAG_NO_FULLSCREEN /* API 11 */;
outAttrs.inputType = InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_FLAG_MULTI_LINE;
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI |
EditorInfo.IME_FLAG_NO_FULLSCREEN /* API 11 */;
return ic;
}
@@ -2326,9 +1946,17 @@ class DummyEdit extends View implements View.OnKeyListener {
class SDLInputConnection extends BaseInputConnection {
protected EditText mEditText;
protected String mCommittedText = "";
public SDLInputConnection(View targetView, boolean fullEditor) {
super(targetView, fullEditor);
mEditText = new EditText(SDL.getContext());
}
@Override
public Editable getEditable() {
return mEditText.getEditableText();
}
@Override
@@ -2351,79 +1979,84 @@ class SDLInputConnection extends BaseInputConnection {
}
}
return super.sendKeyEvent(event);
}
@Override
public boolean commitText(CharSequence text, int newCursorPosition) {
/* Generate backspaces for the text we're going to replace */
final Editable content = getEditable();
if (content != null) {
int a = getComposingSpanStart(content);
int b = getComposingSpanEnd(content);
if (a == -1 || b == -1) {
a = Selection.getSelectionStart(content);
b = Selection.getSelectionEnd(content);
}
if (a < 0) a = 0;
if (b < 0) b = 0;
if (b < a) {
int tmp = a;
a = b;
b = tmp;
}
int backspaces = (b - a);
for (int i = 0; i < backspaces; i++) {
nativeGenerateScancodeForUnichar('\b');
}
if (!super.commitText(text, newCursorPosition)) {
return false;
}
for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
if (c == '\n') {
if (SDLActivity.onNativeSoftReturnKey()) {
return true;
}
}
nativeGenerateScancodeForUnichar(c);
}
SDLInputConnection.nativeCommitText(text.toString(), newCursorPosition);
return super.commitText(text, newCursorPosition);
updateText();
return true;
}
@Override
public boolean setComposingText(CharSequence text, int newCursorPosition) {
if (!super.setComposingText(text, newCursorPosition)) {
return false;
}
updateText();
return true;
}
nativeSetComposingText(text.toString(), newCursorPosition);
@Override
public boolean deleteSurroundingText(int beforeLength, int afterLength) {
if (!super.deleteSurroundingText(beforeLength, afterLength)) {
return false;
}
updateText();
return true;
}
return super.setComposingText(text, newCursorPosition);
protected void updateText() {
final Editable content = getEditable();
if (content == null) {
return;
}
String text = content.toString();
int compareLength = Math.min(text.length(), mCommittedText.length());
int matchLength, offset;
/* Backspace over characters that are no longer in the string */
for (matchLength = 0; matchLength < compareLength; ) {
int codePoint = mCommittedText.codePointAt(matchLength);
if (codePoint != text.codePointAt(matchLength)) {
break;
}
matchLength += Character.charCount(codePoint);
}
/* FIXME: This doesn't handle graphemes, like '🌬️' */
for (offset = matchLength; offset < mCommittedText.length(); ) {
int codePoint = mCommittedText.codePointAt(offset);
nativeGenerateScancodeForUnichar('\b');
offset += Character.charCount(codePoint);
}
if (matchLength < text.length()) {
String pendingText = text.subSequence(matchLength, text.length()).toString();
for (offset = 0; offset < pendingText.length(); ) {
int codePoint = pendingText.codePointAt(offset);
if (codePoint == '\n') {
if (SDLActivity.onNativeSoftReturnKey()) {
return;
}
}
/* Higher code points don't generate simulated scancodes */
if (codePoint < 128) {
nativeGenerateScancodeForUnichar((char)codePoint);
}
offset += Character.charCount(codePoint);
}
SDLInputConnection.nativeCommitText(pendingText, 0);
}
mCommittedText = text;
}
public static native void nativeCommitText(String text, int newCursorPosition);
public native void nativeGenerateScancodeForUnichar(char c);
public native void nativeSetComposingText(String text, int newCursorPosition);
@Override
public boolean deleteSurroundingText(int beforeLength, int afterLength) {
// Workaround to capture backspace key. Ref: http://stackoverflow.com/questions/14560344/android-backspace-in-webview-baseinputconnection
// and https://bugzilla.libsdl.org/show_bug.cgi?id=2265
if (beforeLength > 0 && afterLength == 0) {
// backspace(s)
while (beforeLength-- > 0) {
nativeGenerateScancodeForUnichar('\b');
}
return true;
}
return super.deleteSurroundingText(beforeLength, afterLength);
}
public static native void nativeGenerateScancodeForUnichar(char c);
}
class SDLClipboardHandler implements

View File

@@ -0,0 +1,405 @@
package org.libsdl.app;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Build;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.WindowManager;
/**
SDLSurface. This is what we draw on, so we need to know when it's created
in order to do anything useful.
Because of this, that's where we set up the SDL thread
*/
public class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
View.OnKeyListener, View.OnTouchListener, SensorEventListener {
// Sensors
protected SensorManager mSensorManager;
protected Display mDisplay;
// Keep track of the surface size to normalize touch events
protected float mWidth, mHeight;
// Is SurfaceView ready for rendering
public boolean mIsSurfaceReady;
// Startup
public SDLSurface(Context context) {
super(context);
getHolder().addCallback(this);
setFocusable(true);
setFocusableInTouchMode(true);
requestFocus();
setOnKeyListener(this);
setOnTouchListener(this);
mDisplay = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
setOnGenericMotionListener(SDLActivity.getMotionListener());
// Some arbitrary defaults to avoid a potential division by zero
mWidth = 1.0f;
mHeight = 1.0f;
mIsSurfaceReady = false;
}
public void handlePause() {
enableSensor(Sensor.TYPE_ACCELEROMETER, false);
}
public void handleResume() {
setFocusable(true);
setFocusableInTouchMode(true);
requestFocus();
setOnKeyListener(this);
setOnTouchListener(this);
enableSensor(Sensor.TYPE_ACCELEROMETER, true);
}
public Surface getNativeSurface() {
return getHolder().getSurface();
}
// Called when we have a valid drawing surface
@Override
public void surfaceCreated(SurfaceHolder holder) {
Log.v("SDL", "surfaceCreated()");
SDLActivity.onNativeSurfaceCreated();
}
// Called when we lose the surface
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
Log.v("SDL", "surfaceDestroyed()");
// Transition to pause, if needed
SDLActivity.mNextNativeState = SDLActivity.NativeState.PAUSED;
SDLActivity.handleNativeState();
mIsSurfaceReady = false;
SDLActivity.onNativeSurfaceDestroyed();
}
// Called when the surface is resized
@Override
public void surfaceChanged(SurfaceHolder holder,
int format, int width, int height) {
Log.v("SDL", "surfaceChanged()");
if (SDLActivity.mSingleton == null) {
return;
}
mWidth = width;
mHeight = height;
int nDeviceWidth = width;
int nDeviceHeight = height;
try
{
if (Build.VERSION.SDK_INT >= 17) {
DisplayMetrics realMetrics = new DisplayMetrics();
mDisplay.getRealMetrics( realMetrics );
nDeviceWidth = realMetrics.widthPixels;
nDeviceHeight = realMetrics.heightPixels;
}
} catch(Exception ignored) {
}
synchronized(SDLActivity.getContext()) {
// In case we're waiting on a size change after going fullscreen, send a notification.
SDLActivity.getContext().notifyAll();
}
Log.v("SDL", "Window size: " + width + "x" + height);
Log.v("SDL", "Device size: " + nDeviceWidth + "x" + nDeviceHeight);
SDLActivity.nativeSetScreenResolution(width, height, nDeviceWidth, nDeviceHeight, mDisplay.getRefreshRate());
SDLActivity.onNativeResize();
// Prevent a screen distortion glitch,
// for instance when the device is in Landscape and a Portrait App is resumed.
boolean skip = false;
int requestedOrientation = SDLActivity.mSingleton.getRequestedOrientation();
if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
if (mWidth > mHeight) {
skip = true;
}
} else if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
if (mWidth < mHeight) {
skip = true;
}
}
// Special Patch for Square Resolution: Black Berry Passport
if (skip) {
double min = Math.min(mWidth, mHeight);
double max = Math.max(mWidth, mHeight);
if (max / min < 1.20) {
Log.v("SDL", "Don't skip on such aspect-ratio. Could be a square resolution.");
skip = false;
}
}
// Don't skip in MultiWindow.
if (skip) {
if (Build.VERSION.SDK_INT >= 24) {
if (SDLActivity.mSingleton.isInMultiWindowMode()) {
Log.v("SDL", "Don't skip in Multi-Window");
skip = false;
}
}
}
if (skip) {
Log.v("SDL", "Skip .. Surface is not ready.");
mIsSurfaceReady = false;
return;
}
/* If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here */
SDLActivity.onNativeSurfaceChanged();
/* Surface is ready */
mIsSurfaceReady = true;
SDLActivity.mNextNativeState = SDLActivity.NativeState.RESUMED;
SDLActivity.handleNativeState();
}
// Key events
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
return SDLActivity.handleKeyEvent(v, keyCode, event, null);
}
// Touch events
@Override
public boolean onTouch(View v, MotionEvent event) {
/* Ref: http://developer.android.com/training/gestures/multi.html */
int touchDevId = event.getDeviceId();
final int pointerCount = event.getPointerCount();
int action = event.getActionMasked();
int pointerFingerId;
int i = -1;
float x,y,p;
/*
* Prevent id to be -1, since it's used in SDL internal for synthetic events
* Appears when using Android emulator, eg:
* adb shell input mouse tap 100 100
* adb shell input touchscreen tap 100 100
*/
if (touchDevId < 0) {
touchDevId -= 1;
}
// 12290 = Samsung DeX mode desktop mouse
// 12290 = 0x3002 = 0x2002 | 0x1002 = SOURCE_MOUSE | SOURCE_TOUCHSCREEN
// 0x2 = SOURCE_CLASS_POINTER
if (event.getSource() == InputDevice.SOURCE_MOUSE || event.getSource() == (InputDevice.SOURCE_MOUSE | InputDevice.SOURCE_TOUCHSCREEN)) {
int mouseButton = 1;
try {
Object object = event.getClass().getMethod("getButtonState").invoke(event);
if (object != null) {
mouseButton = (Integer) object;
}
} catch(Exception ignored) {
}
// We need to check if we're in relative mouse mode and get the axis offset rather than the x/y values
// if we are. We'll leverage our existing mouse motion listener
SDLGenericMotionListener_API12 motionListener = SDLActivity.getMotionListener();
x = motionListener.getEventX(event);
y = motionListener.getEventY(event);
SDLActivity.onNativeMouse(mouseButton, action, x, y, motionListener.inRelativeMode());
} else {
switch(action) {
case MotionEvent.ACTION_MOVE:
for (i = 0; i < pointerCount; i++) {
pointerFingerId = event.getPointerId(i);
x = event.getX(i) / mWidth;
y = event.getY(i) / mHeight;
p = event.getPressure(i);
if (p > 1.0f) {
// may be larger than 1.0f on some devices
// see the documentation of getPressure(i)
p = 1.0f;
}
SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_DOWN:
// Primary pointer up/down, the index is always zero
i = 0;
/* fallthrough */
case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_POINTER_DOWN:
// Non primary pointer up/down
if (i == -1) {
i = event.getActionIndex();
}
pointerFingerId = event.getPointerId(i);
x = event.getX(i) / mWidth;
y = event.getY(i) / mHeight;
p = event.getPressure(i);
if (p > 1.0f) {
// may be larger than 1.0f on some devices
// see the documentation of getPressure(i)
p = 1.0f;
}
SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
break;
case MotionEvent.ACTION_CANCEL:
for (i = 0; i < pointerCount; i++) {
pointerFingerId = event.getPointerId(i);
x = event.getX(i) / mWidth;
y = event.getY(i) / mHeight;
p = event.getPressure(i);
if (p > 1.0f) {
// may be larger than 1.0f on some devices
// see the documentation of getPressure(i)
p = 1.0f;
}
SDLActivity.onNativeTouch(touchDevId, pointerFingerId, MotionEvent.ACTION_UP, x, y, p);
}
break;
default:
break;
}
}
return true;
}
// Sensor events
public void enableSensor(int sensortype, boolean enabled) {
// TODO: This uses getDefaultSensor - what if we have >1 accels?
if (enabled) {
mSensorManager.registerListener(this,
mSensorManager.getDefaultSensor(sensortype),
SensorManager.SENSOR_DELAY_GAME, null);
} else {
mSensorManager.unregisterListener(this,
mSensorManager.getDefaultSensor(sensortype));
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// TODO
}
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
// Since we may have an orientation set, we won't receive onConfigurationChanged events.
// We thus should check here.
int newOrientation;
float x, y;
switch (mDisplay.getRotation()) {
case Surface.ROTATION_90:
x = -event.values[1];
y = event.values[0];
newOrientation = SDLActivity.SDL_ORIENTATION_LANDSCAPE;
break;
case Surface.ROTATION_270:
x = event.values[1];
y = -event.values[0];
newOrientation = SDLActivity.SDL_ORIENTATION_LANDSCAPE_FLIPPED;
break;
case Surface.ROTATION_180:
x = -event.values[0];
y = -event.values[1];
newOrientation = SDLActivity.SDL_ORIENTATION_PORTRAIT_FLIPPED;
break;
case Surface.ROTATION_0:
default:
x = event.values[0];
y = event.values[1];
newOrientation = SDLActivity.SDL_ORIENTATION_PORTRAIT;
break;
}
if (newOrientation != SDLActivity.mCurrentOrientation) {
SDLActivity.mCurrentOrientation = newOrientation;
SDLActivity.onNativeOrientationChanged(newOrientation);
}
SDLActivity.onNativeAccel(-x / SensorManager.GRAVITY_EARTH,
y / SensorManager.GRAVITY_EARTH,
event.values[2] / SensorManager.GRAVITY_EARTH);
}
}
// Captured pointer events for API 26.
public boolean onCapturedPointerEvent(MotionEvent event)
{
int action = event.getActionMasked();
float x, y;
switch (action) {
case MotionEvent.ACTION_SCROLL:
x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, 0);
y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, 0);
SDLActivity.onNativeMouse(0, action, x, y, false);
return true;
case MotionEvent.ACTION_HOVER_MOVE:
case MotionEvent.ACTION_MOVE:
x = event.getX(0);
y = event.getY(0);
SDLActivity.onNativeMouse(0, action, x, y, true);
return true;
case MotionEvent.ACTION_BUTTON_PRESS:
case MotionEvent.ACTION_BUTTON_RELEASE:
// Change our action value to what SDL's code expects.
if (action == MotionEvent.ACTION_BUTTON_PRESS) {
action = MotionEvent.ACTION_DOWN;
} else { /* MotionEvent.ACTION_BUTTON_RELEASE */
action = MotionEvent.ACTION_UP;
}
x = event.getX(0);
y = event.getY(0);
int button = event.getButtonState();
SDLActivity.onNativeMouse(button, action, x, y, true);
return true;
}
return false;
}
}

178
os/android/gradlew.bat vendored
View File

@@ -1,89 +1,89 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

Binary file not shown.

After

Width:  |  Height:  |  Size: 1009 KiB

View File

@@ -0,0 +1,14 @@
{
"images" : [
{
"filename" : "AppIcon.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}

52
os/ios/Info.plist Normal file
View File

@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>${MACOSX_BUNDLE_DISPLAY_NAME}</string>
<key>CFBundleExecutable</key>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
<key>CFBundleVersion</key>
<string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
<key>LSMinimumSystemVersion</key>
<string>11.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
<key>NSHighResolutionCapable</key>
<string>True</string>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UIFileSharingEnabled</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiresFullScreen</key>
<true/>
<key>UIStatusBarHidden</key>
<true/>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21225" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="834" height="1194"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<viewLayoutGuide key="safeArea" id="Bcu-3y-fUS"/>
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
</document>

View File

@@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>${MACOSX_BUNDLE_DISPLAY_NAME}</string>
<key>CFBundleExecutable</key>
@@ -28,6 +28,8 @@
<string>${MACOSX_BUNDLE_COPYRIGHT}</string>
<key>NSHighResolutionCapable</key>
<string>True</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.role-playing-games</string>
<key>LSMinimumSystemVersion</key>
<string>10.11</string>
<key>SDL_FILESYSTEM_BASE_DIR_TYPE</key>

File diff suppressed because it is too large Load Diff

View File

@@ -4,6 +4,10 @@
#include "combat_defs.h"
#include "obj_types.h"
namespace fallout {
extern int rotation;
int _action_attack(Attack* attack);
int _action_use_an_item_on_object(Object* a1, Object* a2, Object* a3);
int _action_use_an_object(Object* a1, Object* a2);
@@ -11,14 +15,16 @@ int actionPickUp(Object* critter, Object* item);
int _action_loot_container(Object* critter, Object* container);
int _action_skill_use(int a1);
int actionUseSkill(Object* a1, Object* a2, int skill);
bool _is_hit_from_front(Object* a1, Object* a2);
bool _is_hit_from_front(Object* attacker, Object* defender);
bool _can_see(Object* a1, Object* a2);
bool _action_explode_running();
int actionExplode(int tile, int elevation, int minDamage, int maxDamage, Object* a5, bool a6);
int actionExplode(int tile, int elevation, int minDamage, int maxDamage, Object* sourceObj, bool animate);
int actionTalk(Object* a1, Object* a2);
void actionDamage(int tile, int elevation, int minDamage, int maxDamage, int damageType, bool animated, bool bypassArmor);
bool actionCheckPush(Object* a1, Object* a2);
int actionPush(Object* a1, Object* a2);
int _action_can_talk_to(Object* a1, Object* a2);
} // namespace fallout
#endif /* ACTIONS_H */

File diff suppressed because it is too large Load Diff

View File

@@ -4,11 +4,13 @@
#include "combat_defs.h"
#include "obj_types.h"
namespace fallout {
typedef enum AnimationRequestOptions {
ANIMATION_REQUEST_UNRESERVED = 0x01,
ANIMATION_REQUEST_RESERVED = 0x02,
ANIMATION_REQUEST_NO_STAND = 0x04,
ANIMATION_REQUEST_0x100 = 0x100,
ANIMATION_REQUEST_PING = 0x100,
ANIMATION_REQUEST_INSIGNIFICANT = 0x200,
} AnimationRequestOptions;
@@ -90,7 +92,7 @@ typedef enum AnimationType {
LAST_SF_DEATH_ANIM = ANIM_FALL_FRONT_BLOOD_SF,
} AnimationType;
#define FID_ANIM_TYPE(value) ((value) & 0xFF0000) >> 16
#define FID_ANIM_TYPE(value) ((value)&0xFF0000) >> 16
// Signature of animation callback accepting 2 parameters.
typedef int(AnimationCallback)(void* a1, void* a2);
@@ -98,12 +100,12 @@ typedef int(AnimationCallback)(void* a1, void* a2);
// Signature of animation callback accepting 3 parameters.
typedef int(AnimationCallback3)(void* a1, void* a2, void* a3);
typedef struct STRUCT_530014_28 {
typedef struct StraightPathNode {
int tile;
int elevation;
int x;
int y;
} STRUCT_530014_28;
} StraightPathNode;
typedef Object* PathBuilderCallback(Object* object, int tile, int elevation);
@@ -140,15 +142,15 @@ int animationRegisterSetLightDistance(Object* owner, int lightDistance, int dela
int animationRegisterToggleOutline(Object* object, bool outline, int delay);
int animationRegisterPlaySoundEffect(Object* owner, const char* soundEffectName, int delay);
int animationRegisterAnimateForever(Object* owner, int anim, int delay);
int reg_anim_26(int a1, int a2);
int animationRegisterPing(int flags, int delay);
int _make_path(Object* object, int from, int to, unsigned char* a4, int a5);
int pathfinderFindPath(Object* object, int from, int to, unsigned char* rotations, int a5, PathBuilderCallback* callback);
int _make_straight_path(Object* a1, int from, int to, STRUCT_530014_28* pathNodes, Object** a5, int a6);
int _make_straight_path_func(Object* a1, int from, int to, STRUCT_530014_28* a4, Object** a5, int a6, Object* (*a7)(Object*, int, int));
int _make_straight_path(Object* object, int from, int to, StraightPathNode* straightPathNodeList, Object** obstaclePtr, int a6);
int _make_straight_path_func(Object* object, int from, int to, StraightPathNode* straightPathNodeList, Object** obstaclePtr, int a6, PathBuilderCallback* callback);
void _object_animate();
int _check_move(int* a1);
int _dude_move(int a1);
int _dude_run(int a1);
int _check_move(int* actionPointsPtr);
int _dude_move(int actionPoints);
int _dude_run(int actionPoints);
void _dude_fidget();
void _dude_stand(Object* obj, int rotation, int fid);
void _dude_standup(Object* a1);
@@ -156,4 +158,6 @@ void animationStop();
int animationRegisterSetLightIntensity(Object* owner, int lightDistance, int lightIntensity, int delay);
} // namespace fallout
#endif /* ANIMATION_H */

View File

@@ -8,12 +8,14 @@
#include "debug.h"
#include "draw.h"
#include "game.h"
#include "game_config.h"
#include "memory.h"
#include "object.h"
#include "proto.h"
#include "settings.h"
#include "sfall_config.h"
namespace fallout {
typedef struct ArtListDescription {
int flags;
char name[16];
@@ -32,8 +34,10 @@ static int artReadList(const char* path, char** out_arr, int* out_count);
static int artCacheGetFileSizeImpl(int a1, int* out_size);
static int artCacheReadDataImpl(int a1, int* a2, unsigned char* data);
static void artCacheFreeImpl(void* ptr);
static int artReadFrameData(unsigned char* data, File* stream, int count);
static int artReadFrameData(unsigned char* data, File* stream, int count, int* paddingPtr);
static int artReadHeader(Art* art, File* stream);
static int artGetDataSize(Art* art);
static int paddingForSize(int size);
// 0x5002D8
static char gDefaultJumpsuitMaleFileName[] = "hmjmps";
@@ -49,17 +53,17 @@ static char gDefaultTribalFemaleFileName[] = "hfprim";
// 0x510738
static ArtListDescription gArtListDescriptions[OBJ_TYPE_COUNT] = {
{ 0, "items", 0, 0, 0 },
{ 0, "critters", 0, 0, 0 },
{ 0, "scenery", 0, 0, 0 },
{ 0, "walls", 0, 0, 0 },
{ 0, "tiles", 0, 0, 0 },
{ 0, "misc", 0, 0, 0 },
{ 0, "intrface", 0, 0, 0 },
{ 0, "inven", 0, 0, 0 },
{ 0, "heads", 0, 0, 0 },
{ 0, "backgrnd", 0, 0, 0 },
{ 0, "skilldex", 0, 0, 0 },
{ 0, "items", nullptr, nullptr, 0 },
{ 0, "critters", nullptr, nullptr, 0 },
{ 0, "scenery", nullptr, nullptr, 0 },
{ 0, "walls", nullptr, nullptr, 0 },
{ 0, "tiles", nullptr, nullptr, 0 },
{ 0, "misc", nullptr, nullptr, 0 },
{ 0, "intrface", nullptr, nullptr, 0 },
{ 0, "inven", nullptr, nullptr, 0 },
{ 0, "heads", nullptr, nullptr, 0 },
{ 0, "backgrnd", nullptr, nullptr, 0 },
{ 0, "skilldex", nullptr, nullptr, 0 },
};
// This flag denotes that localized arts should be looked up first. Used
@@ -130,18 +134,14 @@ int artInit()
File* stream;
char string[200];
int cacheSize;
if (!configGetInt(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_ART_CACHE_SIZE_KEY, &cacheSize)) {
cacheSize = 8;
}
int cacheSize = settings.system.art_cache_size;
if (!cacheInit(&gArtCache, artCacheGetFileSizeImpl, artCacheReadDataImpl, artCacheFreeImpl, cacheSize << 20)) {
debugPrint("cache_init failed in art_init\n");
return -1;
}
char* language;
if (configGetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_LANGUAGE_KEY, &language) && compat_stricmp(language, ENGLISH) != 0) {
const char* language = settings.system.language.c_str();
if (compat_stricmp(language, ENGLISH) != 0) {
strcpy(gArtLanguage, language);
gArtLanguageInitialized = true;
}
@@ -149,32 +149,17 @@ int artInit()
bool critterDbSelected = false;
for (int objectType = 0; objectType < OBJ_TYPE_COUNT; objectType++) {
gArtListDescriptions[objectType].flags = 0;
sprintf(path, "%s%s%s\\%s.lst", _cd_path_base, "art\\", gArtListDescriptions[objectType].name, gArtListDescriptions[objectType].name);
int oldDb;
if (objectType == OBJ_TYPE_CRITTER) {
oldDb = _db_current();
critterDbSelected = true;
_db_select(_critter_db_handle);
}
snprintf(path, sizeof(path), "%s%s%s\\%s.lst", _cd_path_base, "art\\", gArtListDescriptions[objectType].name, gArtListDescriptions[objectType].name);
if (artReadList(path, &(gArtListDescriptions[objectType].fileNames), &(gArtListDescriptions[objectType].fileNamesLength)) != 0) {
debugPrint("art_read_lst failed in art_init\n");
if (critterDbSelected) {
_db_select(oldDb);
}
cacheFree(&gArtCache);
return -1;
}
if (objectType == OBJ_TYPE_CRITTER) {
critterDbSelected = false;
_db_select(oldDb);
}
}
_anon_alias = (int*)internal_malloc(sizeof(*_anon_alias) * gArtListDescriptions[OBJ_TYPE_CRITTER].fileNamesLength);
if (_anon_alias == NULL) {
if (_anon_alias == nullptr) {
gArtListDescriptions[OBJ_TYPE_CRITTER].fileNamesLength = 0;
debugPrint("Out of memory for anon_alias in art_init\n");
cacheFree(&gArtCache);
@@ -182,7 +167,7 @@ int artInit()
}
gArtCritterFidShoudRunData = (int*)internal_malloc(sizeof(*gArtCritterFidShoudRunData) * gArtListDescriptions[1].fileNamesLength);
if (gArtCritterFidShoudRunData == NULL) {
if (gArtCritterFidShoudRunData == nullptr) {
gArtListDescriptions[OBJ_TYPE_CRITTER].fileNamesLength = 0;
debugPrint("Out of memory for artCritterFidShouldRunData in art_init\n");
cacheFree(&gArtCache);
@@ -193,52 +178,52 @@ int artInit()
gArtCritterFidShoudRunData[critterIndex] = 0;
}
sprintf(path, "%s%s%s\\%s.lst", _cd_path_base, "art\\", gArtListDescriptions[OBJ_TYPE_CRITTER].name, gArtListDescriptions[OBJ_TYPE_CRITTER].name);
snprintf(path, sizeof(path), "%s%s%s\\%s.lst", _cd_path_base, "art\\", gArtListDescriptions[OBJ_TYPE_CRITTER].name, gArtListDescriptions[OBJ_TYPE_CRITTER].name);
stream = fileOpen(path, "rt");
if (stream == NULL) {
if (stream == nullptr) {
debugPrint("Unable to open %s in art_init\n", path);
cacheFree(&gArtCache);
return -1;
}
// SFALL: Modify player model settings.
char* jumpsuitMaleFileName = NULL;
char* jumpsuitMaleFileName = nullptr;
configGetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_DUDE_NATIVE_LOOK_JUMPSUIT_MALE_KEY, &jumpsuitMaleFileName);
if (jumpsuitMaleFileName == NULL || jumpsuitMaleFileName[0] == '\0') {
if (jumpsuitMaleFileName == nullptr || jumpsuitMaleFileName[0] == '\0') {
jumpsuitMaleFileName = gDefaultJumpsuitMaleFileName;
}
char* jumpsuitFemaleFileName = NULL;
char* jumpsuitFemaleFileName = nullptr;
configGetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_DUDE_NATIVE_LOOK_JUMPSUIT_FEMALE_KEY, &jumpsuitFemaleFileName);
if (jumpsuitFemaleFileName == NULL || jumpsuitFemaleFileName[0] == '\0') {
if (jumpsuitFemaleFileName == nullptr || jumpsuitFemaleFileName[0] == '\0') {
jumpsuitFemaleFileName = gDefaultJumpsuitFemaleFileName;
}
char* tribalMaleFileName = NULL;
char* tribalMaleFileName = nullptr;
configGetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_DUDE_NATIVE_LOOK_TRIBAL_MALE_KEY, &tribalMaleFileName);
if (tribalMaleFileName == NULL || tribalMaleFileName[0] == '\0') {
if (tribalMaleFileName == nullptr || tribalMaleFileName[0] == '\0') {
tribalMaleFileName = gDefaultTribalMaleFileName;
}
char* tribalFemaleFileName = NULL;
char* tribalFemaleFileName = nullptr;
configGetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_DUDE_NATIVE_LOOK_TRIBAL_FEMALE_KEY, &tribalFemaleFileName);
if (tribalFemaleFileName == NULL || tribalFemaleFileName[0] == '\0') {
if (tribalFemaleFileName == nullptr || tribalFemaleFileName[0] == '\0') {
tribalFemaleFileName = gDefaultTribalFemaleFileName;
}
char* critterFileNames = gArtListDescriptions[OBJ_TYPE_CRITTER].fileNames;
for (int critterIndex = 0; critterIndex < gArtListDescriptions[OBJ_TYPE_CRITTER].fileNamesLength; critterIndex++) {
if (compat_stricmp(critterFileNames, "hmjmps") == 0) {
if (compat_stricmp(critterFileNames, jumpsuitMaleFileName) == 0) {
_art_vault_person_nums[DUDE_NATIVE_LOOK_JUMPSUIT][GENDER_MALE] = critterIndex;
} else if (compat_stricmp(critterFileNames, "hfjmps") == 0) {
} else if (compat_stricmp(critterFileNames, jumpsuitFemaleFileName) == 0) {
_art_vault_person_nums[DUDE_NATIVE_LOOK_JUMPSUIT][GENDER_FEMALE] = critterIndex;
}
if (compat_stricmp(critterFileNames, "hmwarr") == 0) {
if (compat_stricmp(critterFileNames, tribalMaleFileName) == 0) {
_art_vault_person_nums[DUDE_NATIVE_LOOK_TRIBAL][GENDER_MALE] = critterIndex;
_art_vault_guy_num = critterIndex;
} else if (compat_stricmp(critterFileNames, "hfprim") == 0) {
} else if (compat_stricmp(critterFileNames, tribalFemaleFileName) == 0) {
_art_vault_person_nums[DUDE_NATIVE_LOOK_TRIBAL][GENDER_FEMALE] = critterIndex;
}
@@ -251,11 +236,11 @@ int artInit()
}
char* sep1 = strchr(string, ',');
if (sep1 != NULL) {
if (sep1 != nullptr) {
_anon_alias[critterIndex] = atoi(sep1 + 1);
char* sep2 = strchr(sep1 + 1, ',');
if (sep2 != NULL) {
if (sep2 != nullptr) {
gArtCritterFidShoudRunData[critterIndex] = atoi(sep2 + 1);
} else {
gArtCritterFidShoudRunData[critterIndex] = 0;
@@ -277,17 +262,17 @@ int artInit()
}
gHeadDescriptions = (HeadDescription*)internal_malloc(sizeof(*gHeadDescriptions) * gArtListDescriptions[OBJ_TYPE_HEAD].fileNamesLength);
if (gHeadDescriptions == NULL) {
if (gHeadDescriptions == nullptr) {
gArtListDescriptions[OBJ_TYPE_HEAD].fileNamesLength = 0;
debugPrint("Out of memory for head_info in art_init\n");
cacheFree(&gArtCache);
return -1;
}
sprintf(path, "%s%s%s\\%s.lst", _cd_path_base, "art\\", gArtListDescriptions[OBJ_TYPE_HEAD].name, gArtListDescriptions[OBJ_TYPE_HEAD].name);
snprintf(path, sizeof(path), "%s%s%s\\%s.lst", _cd_path_base, "art\\", gArtListDescriptions[OBJ_TYPE_HEAD].name, gArtListDescriptions[OBJ_TYPE_HEAD].name);
stream = fileOpen(path, "rt");
if (stream == NULL) {
if (stream == nullptr) {
debugPrint("Unable to open %s in art_init\n", path);
cacheFree(&gArtCache);
return -1;
@@ -299,14 +284,14 @@ int artInit()
}
char* sep1 = strchr(string, ',');
if (sep1 != NULL) {
if (sep1 != nullptr) {
*sep1 = '\0';
} else {
sep1 = string;
}
char* sep2 = strchr(sep1, ',');
if (sep2 != NULL) {
if (sep2 != nullptr) {
*sep2 = '\0';
} else {
sep2 = sep1;
@@ -315,7 +300,7 @@ int artInit()
gHeadDescriptions[headIndex].goodFidgetCount = atoi(sep1 + 1);
char* sep3 = strchr(sep2, ',');
if (sep3 != NULL) {
if (sep3 != nullptr) {
*sep3 = '\0';
} else {
sep3 = sep2;
@@ -324,7 +309,7 @@ int artInit()
gHeadDescriptions[headIndex].neutralFidgetCount = atoi(sep2 + 1);
char* sep4 = strpbrk(sep3 + 1, " ,;\t\n");
if (sep4 != NULL) {
if (sep4 != nullptr) {
*sep4 = '\0';
}
@@ -351,10 +336,10 @@ void artExit()
for (int index = 0; index < OBJ_TYPE_COUNT; index++) {
internal_free(gArtListDescriptions[index].fileNames);
gArtListDescriptions[index].fileNames = NULL;
gArtListDescriptions[index].fileNames = nullptr;
internal_free(gArtListDescriptions[index].field_18);
gArtListDescriptions[index].field_18 = NULL;
gArtListDescriptions[index].field_18 = nullptr;
}
internal_free(gHeadDescriptions);
@@ -363,7 +348,7 @@ void artExit()
// 0x418F1C
char* artGetObjectTypeName(int objectType)
{
return objectType >= OBJ_TYPE_ITEM && objectType < OBJ_TYPE_COUNT ? gArtListDescriptions[objectType].name : NULL;
return objectType >= OBJ_TYPE_ITEM && objectType < OBJ_TYPE_COUNT ? gArtListDescriptions[objectType].name : nullptr;
}
// 0x418F34
@@ -411,7 +396,7 @@ void artRender(int fid, unsigned char* dest, int width, int height, int pitch)
CacheEntry* handle;
Art* frm = artLock(fid, &handle);
if (frm == NULL) {
if (frm == nullptr) {
return;
}
@@ -453,14 +438,22 @@ void artRender(int fid, unsigned char* dest, int width, int height, int pitch)
artUnlock(handle);
}
// mapper2.exe: 0x40A03C
int art_list_str(int fid, char* name)
{
// TODO: Incomplete.
return -1;
}
// 0x419160
Art* artLock(int fid, CacheEntry** handlePtr)
{
if (handlePtr == NULL) {
return NULL;
if (handlePtr == nullptr) {
return nullptr;
}
Art* art = NULL;
Art* art = nullptr;
cacheLock(&gArtCache, fid, (void**)&art, handlePtr);
return art;
}
@@ -471,44 +464,44 @@ unsigned char* artLockFrameData(int fid, int frame, int direction, CacheEntry**
Art* art;
ArtFrame* frm;
art = NULL;
art = nullptr;
if (handlePtr) {
cacheLock(&gArtCache, fid, (void**)&art, handlePtr);
}
if (art != NULL) {
if (art != nullptr) {
frm = artGetFrame(art, frame, direction);
if (frm != NULL) {
if (frm != nullptr) {
return (unsigned char*)frm + sizeof(*frm);
}
}
return NULL;
return nullptr;
}
// 0x4191CC
unsigned char* artLockFrameDataReturningSize(int fid, CacheEntry** handlePtr, int* widthPtr, int* heightPtr)
{
*handlePtr = NULL;
*handlePtr = nullptr;
Art* art;
Art* art = nullptr;
cacheLock(&gArtCache, fid, (void**)&art, handlePtr);
if (art == NULL) {
return NULL;
if (art == nullptr) {
return nullptr;
}
// NOTE: Uninline.
*widthPtr = artGetWidth(art, 0, 0);
if (*widthPtr == -1) {
return NULL;
return nullptr;
}
// NOTE: Uninline.
*heightPtr = artGetHeight(art, 0, 0);
if (*heightPtr == -1) {
return NULL;
return nullptr;
}
// NOTE: Uninline.
@@ -641,33 +634,33 @@ char* artBuildFilePath(int fid)
type = FID_TYPE(v2);
if (v3 >= gArtListDescriptions[type].fileNamesLength) {
return NULL;
return nullptr;
}
if (type < OBJ_TYPE_ITEM || type >= OBJ_TYPE_COUNT) {
return NULL;
return nullptr;
}
v8 = v3 * 13;
if (type == 1) {
if (_art_get_code(v4, v5, &v11, &v12) == -1) {
return NULL;
return nullptr;
}
if (v10) {
sprintf(_art_name, "%s%s%s\\%s%c%c.fr%c", _cd_path_base, "art\\", gArtListDescriptions[1].name, gArtListDescriptions[1].fileNames + v8, v11, v12, v10 + 47);
snprintf(_art_name, sizeof(_art_name), "%s%s%s\\%s%c%c.fr%c", _cd_path_base, "art\\", gArtListDescriptions[1].name, gArtListDescriptions[1].fileNames + v8, v11, v12, v10 + 47);
} else {
sprintf(_art_name, "%s%s%s\\%s%c%c.frm", _cd_path_base, "art\\", gArtListDescriptions[1].name, gArtListDescriptions[1].fileNames + v8, v11, v12);
snprintf(_art_name, sizeof(_art_name), "%s%s%s\\%s%c%c.frm", _cd_path_base, "art\\", gArtListDescriptions[1].name, gArtListDescriptions[1].fileNames + v8, v11, v12);
}
} else if (type == 8) {
v9 = _head2[v4];
if (v9 == 'f') {
sprintf(_art_name, "%s%s%s\\%s%c%c%d.frm", _cd_path_base, "art\\", gArtListDescriptions[8].name, gArtListDescriptions[8].fileNames + v8, _head1[v4], 102, v5);
snprintf(_art_name, sizeof(_art_name), "%s%s%s\\%s%c%c%d.frm", _cd_path_base, "art\\", gArtListDescriptions[8].name, gArtListDescriptions[8].fileNames + v8, _head1[v4], 102, v5);
} else {
sprintf(_art_name, "%s%s%s\\%s%c%c.frm", _cd_path_base, "art\\", gArtListDescriptions[8].name, gArtListDescriptions[8].fileNames + v8, _head1[v4], v9);
snprintf(_art_name, sizeof(_art_name), "%s%s%s\\%s%c%c.frm", _cd_path_base, "art\\", gArtListDescriptions[8].name, gArtListDescriptions[8].fileNames + v8, _head1[v4], v9);
}
} else {
sprintf(_art_name, "%s%s%s\\%s", _cd_path_base, "art\\", gArtListDescriptions[type].name, gArtListDescriptions[type].fileNames + v8);
snprintf(_art_name, sizeof(_art_name), "%s%s%s\\%s", _cd_path_base, "art\\", gArtListDescriptions[type].name, gArtListDescriptions[type].fileNames + v8);
}
return _art_name;
@@ -678,7 +671,7 @@ char* artBuildFilePath(int fid)
static int artReadList(const char* path, char** artListPtr, int* artListSizePtr)
{
File* stream = fileOpen(path, "rt");
if (stream == NULL) {
if (stream == nullptr) {
return -1;
}
@@ -694,14 +687,14 @@ static int artReadList(const char* path, char** artListPtr, int* artListSizePtr)
char* artList = (char*)internal_malloc(13 * count);
*artListPtr = artList;
if (artList == NULL) {
if (artList == nullptr) {
fileClose(stream);
return -1;
}
while (fileReadString(string, sizeof(string), stream)) {
char* brk = strpbrk(string, " ,;\r\t\n");
if (brk != NULL) {
if (brk != nullptr) {
*brk = '\0';
}
@@ -719,7 +712,7 @@ static int artReadList(const char* path, char** artListPtr, int* artListSizePtr)
// 0x419760
int artGetFramesPerSecond(Art* art)
{
if (art == NULL) {
if (art == nullptr) {
return 10;
}
@@ -729,13 +722,13 @@ int artGetFramesPerSecond(Art* art)
// 0x419778
int artGetActionFrame(Art* art)
{
return art == NULL ? -1 : art->actionFrame;
return art == nullptr ? -1 : art->actionFrame;
}
// 0x41978C
int artGetFrameCount(Art* art)
{
return art == NULL ? -1 : art->frameCount;
return art == nullptr ? -1 : art->frameCount;
}
// 0x4197A0
@@ -744,7 +737,7 @@ int artGetWidth(Art* art, int frame, int direction)
ArtFrame* frm;
frm = artGetFrame(art, frame, direction);
if (frm == NULL) {
if (frm == nullptr) {
return -1;
}
@@ -757,7 +750,7 @@ int artGetHeight(Art* art, int frame, int direction)
ArtFrame* frm;
frm = artGetFrame(art, frame, direction);
if (frm == NULL) {
if (frm == nullptr) {
return -1;
}
@@ -770,23 +763,23 @@ int artGetSize(Art* art, int frame, int direction, int* widthPtr, int* heightPtr
ArtFrame* frm;
frm = artGetFrame(art, frame, direction);
if (frm == NULL) {
if (widthPtr != NULL) {
if (frm == nullptr) {
if (widthPtr != nullptr) {
*widthPtr = 0;
}
if (heightPtr != NULL) {
if (heightPtr != nullptr) {
*heightPtr = 0;
}
return -1;
}
if (widthPtr != NULL) {
if (widthPtr != nullptr) {
*widthPtr = frm->width;
}
if (heightPtr != NULL) {
if (heightPtr != nullptr) {
*heightPtr = frm->height;
}
@@ -799,7 +792,7 @@ int artGetFrameOffsets(Art* art, int frame, int direction, int* xPtr, int* yPtr)
ArtFrame* frm;
frm = artGetFrame(art, frame, direction);
if (frm == NULL) {
if (frm == nullptr) {
return -1;
}
@@ -812,7 +805,7 @@ int artGetFrameOffsets(Art* art, int frame, int direction, int* xPtr, int* yPtr)
// 0x41984C
int artGetRotationOffsets(Art* art, int rotation, int* xPtr, int* yPtr)
{
if (art == NULL) {
if (art == nullptr) {
return -1;
}
@@ -828,8 +821,8 @@ unsigned char* artGetFrameData(Art* art, int frame, int direction)
ArtFrame* frm;
frm = artGetFrame(art, frame, direction);
if (frm == NULL) {
return NULL;
if (frm == nullptr) {
return nullptr;
}
return (unsigned char*)frm + sizeof(*frm);
@@ -839,20 +832,20 @@ unsigned char* artGetFrameData(Art* art, int frame, int direction)
ArtFrame* artGetFrame(Art* art, int frame, int rotation)
{
if (rotation < 0 || rotation >= 6) {
return NULL;
return nullptr;
}
if (art == NULL) {
return NULL;
if (art == nullptr) {
return nullptr;
}
if (frame < 0 || frame >= art->frameCount) {
return NULL;
return nullptr;
}
ArtFrame* frm = (ArtFrame*)((unsigned char*)art + sizeof(*art) + art->dataOffsets[rotation]);
ArtFrame* frm = (ArtFrame*)((unsigned char*)art + sizeof(*art) + art->dataOffsets[rotation] + art->padding[rotation]);
for (int index = 0; index < frame; index++) {
frm = (ArtFrame*)((unsigned char*)frm + sizeof(*frm) + frm->size);
frm = (ArtFrame*)((unsigned char*)frm + sizeof(*frm) + frm->size + paddingForSize(frm->size));
}
return frm;
}
@@ -861,25 +854,15 @@ ArtFrame* artGetFrame(Art* art, int frame, int rotation)
bool artExists(int fid)
{
bool result = false;
int oldDb = -1;
if (FID_TYPE(fid) == OBJ_TYPE_CRITTER) {
oldDb = _db_current();
_db_select(_critter_db_handle);
}
char* filePath = artBuildFilePath(fid);
if (filePath != NULL) {
if (filePath != nullptr) {
int fileSize;
if (dbGetFileSize(filePath, &fileSize) != -1) {
result = true;
}
}
if (oldDb != -1) {
_db_select(oldDb);
}
return result;
}
@@ -889,25 +872,15 @@ bool artExists(int fid)
bool _art_fid_valid(int fid)
{
bool result = false;
int oldDb = -1;
if (FID_TYPE(fid) == OBJ_TYPE_CRITTER) {
oldDb = _db_current();
_db_select(_critter_db_handle);
}
char* filePath = artBuildFilePath(fid);
if (filePath != NULL) {
if (filePath != nullptr) {
int fileSize;
if (dbGetFileSize(filePath, &fileSize) != -1) {
result = true;
}
}
if (oldDb != -1) {
_db_select(oldDb);
}
return result;
}
@@ -954,47 +927,37 @@ int artAliasFid(int fid)
// 0x419A78
static int artCacheGetFileSizeImpl(int fid, int* sizePtr)
{
int oldDb = -1;
int result = -1;
if (FID_TYPE(fid) == OBJ_TYPE_CRITTER) {
oldDb = _db_current();
_db_select(_critter_db_handle);
}
char* artFilePath = artBuildFilePath(fid);
if (artFilePath != NULL) {
int fileSize;
if (artFilePath != nullptr) {
bool loaded = false;
File* stream = nullptr;
if (gArtLanguageInitialized) {
char* pch = strchr(artFilePath, '\\');
if (pch == NULL) {
if (pch == nullptr) {
pch = artFilePath;
}
char localizedPath[COMPAT_MAX_PATH];
sprintf(localizedPath, "art\\%s\\%s", gArtLanguage, pch);
snprintf(localizedPath, sizeof(localizedPath), "art\\%s\\%s", gArtLanguage, pch);
if (dbGetFileSize(localizedPath, &fileSize) == 0) {
loaded = true;
stream = fileOpen(localizedPath, "rb");
}
if (stream == nullptr) {
stream = fileOpen(artFilePath, "rb");
}
if (stream != nullptr) {
Art art;
if (artReadHeader(&art, stream) == 0) {
*sizePtr = artGetDataSize(&art);
result = 0;
}
fileClose(stream);
}
if (!loaded) {
if (dbGetFileSize(artFilePath, &fileSize) == 0) {
loaded = true;
}
}
if (loaded) {
*sizePtr = fileSize;
result = 0;
}
}
if (oldDb != -1) {
_db_select(oldDb);
}
return result;
@@ -1003,25 +966,19 @@ static int artCacheGetFileSizeImpl(int fid, int* sizePtr)
// 0x419B78
static int artCacheReadDataImpl(int fid, int* sizePtr, unsigned char* data)
{
int oldDb = -1;
int result = -1;
if (FID_TYPE(fid) == OBJ_TYPE_CRITTER) {
oldDb = _db_current();
_db_select(_critter_db_handle);
}
char* artFileName = artBuildFilePath(fid);
if (artFileName != NULL) {
if (artFileName != nullptr) {
bool loaded = false;
if (gArtLanguageInitialized) {
char* pch = strchr(artFileName, '\\');
if (pch == NULL) {
if (pch == nullptr) {
pch = artFileName;
}
char localizedPath[COMPAT_MAX_PATH];
sprintf(localizedPath, "art\\%s\\%s", gArtLanguage, pch);
snprintf(localizedPath, sizeof(localizedPath), "art\\%s\\%s", gArtLanguage, pch);
if (artRead(localizedPath, data) == 0) {
loaded = true;
@@ -1035,16 +992,11 @@ static int artCacheReadDataImpl(int fid, int* sizePtr, unsigned char* data)
}
if (loaded) {
// TODO: Why it adds 74?
*sizePtr = ((Art*)data)->field_3A + 74;
*sizePtr = artGetDataSize((Art*)data);
result = 0;
}
}
if (oldDb != -1) {
_db_select(oldDb);
}
return result;
}
@@ -1096,9 +1048,10 @@ out:
}
// 0x419D60
static int artReadFrameData(unsigned char* data, File* stream, int count)
static int artReadFrameData(unsigned char* data, File* stream, int count, int* paddingPtr)
{
unsigned char* ptr = data;
int padding = 0;
for (int index = 0; index < count; index++) {
ArtFrame* frame = (ArtFrame*)ptr;
@@ -1110,8 +1063,12 @@ static int artReadFrameData(unsigned char* data, File* stream, int count)
if (fileRead(ptr + sizeof(ArtFrame), frame->size, 1, stream) != 1) return -1;
ptr += sizeof(ArtFrame) + frame->size;
ptr += paddingForSize(frame->size);
padding += paddingForSize(frame->size);
}
*paddingPtr = padding;
return 0;
}
@@ -1125,16 +1082,55 @@ static int artReadHeader(Art* art, File* stream)
if (fileReadInt16List(stream, art->xOffsets, ROTATION_COUNT) == -1) return -1;
if (fileReadInt16List(stream, art->yOffsets, ROTATION_COUNT) == -1) return -1;
if (fileReadInt32List(stream, art->dataOffsets, ROTATION_COUNT) == -1) return -1;
if (fileReadInt32(stream, &(art->field_3A)) == -1) return -1;
if (fileReadInt32(stream, &(art->dataSize)) == -1) return -1;
// CE: Fix malformed `frm` files with `dataSize` set to 0 in Nevada.
if (art->dataSize == 0) {
art->dataSize = fileGetSize(stream);
}
return 0;
}
// NOTE: Original function was slightly different, but never used. Basically
// it's a memory allocating variant of `artRead` (which reads data into given
// buffer). This function is useful to load custom `frm` files since `Art` now
// needs more memory then it's on-disk size (due to memory padding).
//
// 0x419EC0
Art* artLoad(const char* path)
{
File* stream = fileOpen(path, "rb");
if (stream == nullptr) {
return nullptr;
}
Art header;
if (artReadHeader(&header, stream) != 0) {
fileClose(stream);
return nullptr;
}
fileClose(stream);
unsigned char* data = reinterpret_cast<unsigned char*>(internal_malloc(artGetDataSize(&header)));
if (data == nullptr) {
return nullptr;
}
if (artRead(path, data) != 0) {
internal_free(data);
return nullptr;
}
return reinterpret_cast<Art*>(data);
}
// 0x419FC0
int artRead(const char* path, unsigned char* data)
{
File* stream = fileOpen(path, "rb");
if (stream == NULL) {
if (stream == nullptr) {
return -2;
}
@@ -1144,9 +1140,16 @@ int artRead(const char* path, unsigned char* data)
return -3;
}
int currentPadding = paddingForSize(sizeof(Art));
int previousPadding = 0;
for (int index = 0; index < ROTATION_COUNT; index++) {
art->padding[index] = currentPadding;
if (index == 0 || art->dataOffsets[index - 1] != art->dataOffsets[index]) {
if (artReadFrameData(data + sizeof(Art) + art->dataOffsets[index], stream, art->frameCount) != 0) {
art->padding[index] += previousPadding;
currentPadding += previousPadding;
if (artReadFrameData(data + sizeof(Art) + art->dataOffsets[index] + art->padding[index], stream, art->frameCount, &previousPadding) != 0) {
fileClose(stream);
return -5;
}
@@ -1174,6 +1177,7 @@ int artWriteFrameData(unsigned char* data, File* stream, int count)
if (fileWrite(ptr + sizeof(ArtFrame), frame->size, 1, stream) != 1) return -1;
ptr += sizeof(ArtFrame) + frame->size;
ptr += paddingForSize(frame->size);
}
return 0;
@@ -1191,7 +1195,7 @@ int artWriteHeader(Art* art, File* stream)
if (fileWriteInt16List(stream, art->xOffsets, ROTATION_COUNT) == -1) return -1;
if (fileWriteInt16List(stream, art->yOffsets, ROTATION_COUNT) == -1) return -1;
if (fileWriteInt32List(stream, art->dataOffsets, ROTATION_COUNT) == -1) return -1;
if (fileWriteInt32(stream, art->field_3A) == -1) return -1;
if (fileWriteInt32(stream, art->dataSize) == -1) return -1;
return 0;
}
@@ -1201,12 +1205,12 @@ int artWriteHeader(Art* art, File* stream)
// 0x41A1E8
int artWrite(const char* path, unsigned char* data)
{
if (data == NULL) {
if (data == nullptr) {
return -1;
}
File* stream = fileOpen(path, "wb");
if (stream == NULL) {
if (stream == nullptr) {
return -1;
}
@@ -1218,7 +1222,7 @@ int artWrite(const char* path, unsigned char* data)
for (int index = 0; index < ROTATION_COUNT; index++) {
if (index == 0 || art->dataOffsets[index - 1] != art->dataOffsets[index]) {
if (artWriteFrameData(data + sizeof(Art) + art->dataOffsets[index], stream, art->frameCount) != 0) {
if (artWriteFrameData(data + sizeof(Art) + art->dataOffsets[index] + art->padding[index], stream, art->frameCount) != 0) {
fileClose(stream);
return -1;
}
@@ -1228,3 +1232,63 @@ int artWrite(const char* path, unsigned char* data)
fileClose(stream);
return 0;
}
static int artGetDataSize(Art* art)
{
int dataSize = sizeof(*art) + art->dataSize;
for (int index = 0; index < ROTATION_COUNT; index++) {
if (index == 0 || art->dataOffsets[index - 1] != art->dataOffsets[index]) {
// Assume worst case - every frame is unaligned and need
// max padding.
dataSize += (sizeof(int) - 1) * art->frameCount;
}
}
return dataSize;
}
static int paddingForSize(int size)
{
return (sizeof(int) - size % sizeof(int)) % sizeof(int);
}
FrmImage::FrmImage()
{
_key = nullptr;
_data = nullptr;
_width = 0;
_height = 0;
}
FrmImage::~FrmImage()
{
unlock();
}
bool FrmImage::lock(unsigned int fid)
{
if (isLocked()) {
return false;
}
_data = artLockFrameDataReturningSize(fid, &_key, &_width, &_height);
if (!_data) {
return false;
}
return true;
}
void FrmImage::unlock()
{
if (isLocked()) {
artUnlock(_key);
_key = nullptr;
_data = nullptr;
_width = 0;
_height = 0;
}
}
} // namespace fallout

View File

@@ -8,6 +8,8 @@
#include "platform_compat.h"
#include "proto_types.h"
namespace fallout {
typedef enum Head {
HEAD_INVALID,
HEAD_MARCUS,
@@ -65,7 +67,6 @@ typedef enum Background {
BACKGROUND_COUNT,
} Background;
#pragma pack(2)
typedef struct Art {
int field_0;
short framesPerSecond;
@@ -74,9 +75,9 @@ typedef struct Art {
short xOffsets[6];
short yOffsets[6];
int dataOffsets[6];
int field_3A;
int padding[6];
int dataSize;
} Art;
#pragma pack()
typedef struct ArtFrame {
short width;
@@ -122,6 +123,7 @@ char* artGetObjectTypeName(int objectType);
int artIsObjectTypeHidden(int objectType);
int artGetFidgetCount(int headFid);
void artRender(int fid, unsigned char* dest, int width, int height, int pitch);
int art_list_str(int fid, char* name);
Art* artLock(int fid, CacheEntry** cache_entry);
unsigned char* artLockFrameData(int fid, int frame, int direction, CacheEntry** out_cache_entry);
unsigned char* artLockFrameDataReturningSize(int fid, CacheEntry** out_cache_entry, int* widthPtr, int* heightPtr);
@@ -146,7 +148,30 @@ int _art_alias_num(int a1);
int artCritterFidShouldRun(int a1);
int artAliasFid(int fid);
int buildFid(int objectType, int frmId, int animType, int a4, int rotation);
Art* artLoad(const char* path);
int artRead(const char* path, unsigned char* data);
int artWrite(const char* path, unsigned char* data);
class FrmImage {
public:
FrmImage();
~FrmImage();
bool isLocked() const { return _key != nullptr; }
bool lock(unsigned int fid);
void unlock();
int getWidth() const { return _width; }
int getHeight() const { return _height; }
unsigned char* getData() const { return _data; }
private:
CacheEntry* _key;
unsigned char* _data;
int _width;
int _height;
};
} // namespace fallout
#endif

View File

@@ -7,103 +7,101 @@
#include "db.h"
#include "debug.h"
#include "memory_manager.h"
#include "pointer_registry.h"
#include "sound.h"
#include "sound_decoder.h"
static bool _defaultCompressionFunc(char* filePath);
static int audioSoundDecoderReadHandler(int fileHandle, void* buf, unsigned int size);
namespace fallout {
typedef enum AudioFlags {
AUDIO_IN_USE = 0x01,
AUDIO_COMPRESSED = 0x02,
} AudioFileFlags;
typedef struct Audio {
int flags;
File* stream;
SoundDecoder* soundDecoder;
int fileSize;
int sampleRate;
int channels;
int position;
} Audio;
static bool defaultCompressionFunc(char* filePath);
static int audioSoundDecoderReadHandler(void* data, void* buf, unsigned int size);
// 0x5108BC
static AudioFileIsCompressedProc* _queryCompressedFunc = _defaultCompressionFunc;
static AudioQueryCompressedFunc* queryCompressedFunc = defaultCompressionFunc;
// 0x56CB00
static int gAudioListLength;
// 0x56CB04
static AudioFile* gAudioList;
static Audio* gAudioList;
// 0x41A2B0
static bool _defaultCompressionFunc(char* filePath)
static bool defaultCompressionFunc(char* filePath)
{
char* pch = strrchr(filePath, '.');
if (pch != NULL) {
strcpy(pch + 1, "war");
if (pch != nullptr) {
strcpy(pch + 1, "raw");
}
return false;
}
// 0x41A2D0
static int audioSoundDecoderReadHandler(int fileHandle, void* buffer, unsigned int size)
static int audioSoundDecoderReadHandler(void* data, void* buffer, unsigned int size)
{
return fileRead(buffer, 1, size, (File*)intToPtr(fileHandle));
return fileRead(buffer, 1, size, reinterpret_cast<File*>(data));
}
// AudioOpen
// 0x41A2EC
int audioOpen(const char* fname, int flags, ...)
int audioOpen(const char* fname, int* sampleRate)
{
char path[80];
sprintf(path, "%s", fname);
snprintf(path, sizeof(path), "%s", fname);
int compression;
if (_queryCompressedFunc(path)) {
if (queryCompressedFunc(path)) {
compression = 2;
} else {
compression = 0;
}
char mode[4];
memset(mode, 0, 4);
// NOTE: Original implementation is slightly different, it uses separate
// variable to track index where to set 't' and 'b'.
char* pm = mode;
if (flags & 1) {
*pm++ = 'w';
} else if (flags & 2) {
*pm++ = 'w';
*pm++ = '+';
} else {
*pm++ = 'r';
}
if (flags & 0x100) {
*pm++ = 't';
} else if (flags & 0x200) {
*pm++ = 'b';
}
File* stream = fileOpen(path, mode);
if (stream == NULL) {
File* stream = fileOpen(path, "rb");
if (stream == nullptr) {
debugPrint("AudioOpen: Couldn't open %s for read\n", path);
return -1;
}
int index;
for (index = 0; index < gAudioListLength; index++) {
if ((gAudioList[index].flags & AUDIO_FILE_IN_USE) == 0) {
if ((gAudioList[index].flags & AUDIO_IN_USE) == 0) {
break;
}
}
if (index == gAudioListLength) {
if (gAudioList != NULL) {
gAudioList = (AudioFile*)internal_realloc_safe(gAudioList, sizeof(*gAudioList) * (gAudioListLength + 1), __FILE__, __LINE__); // "..\int\audio.c", 216
if (gAudioList != nullptr) {
gAudioList = (Audio*)internal_realloc_safe(gAudioList, sizeof(*gAudioList) * (gAudioListLength + 1), __FILE__, __LINE__); // "..\int\audio.c", 216
} else {
gAudioList = (AudioFile*)internal_malloc_safe(sizeof(*gAudioList), __FILE__, __LINE__); // "..\int\audio.c", 218
gAudioList = (Audio*)internal_malloc_safe(sizeof(*gAudioList), __FILE__, __LINE__); // "..\int\audio.c", 218
}
gAudioListLength++;
}
AudioFile* audioFile = &(gAudioList[index]);
audioFile->flags = AUDIO_FILE_IN_USE;
audioFile->fileHandle = ptrToInt(stream);
Audio* audioFile = &(gAudioList[index]);
audioFile->flags = AUDIO_IN_USE;
audioFile->stream = stream;
if (compression == 2) {
audioFile->flags |= AUDIO_FILE_COMPRESSED;
audioFile->soundDecoder = soundDecoderInit(audioSoundDecoderReadHandler, audioFile->fileHandle, &(audioFile->field_14), &(audioFile->field_10), &(audioFile->fileSize));
audioFile->flags |= AUDIO_COMPRESSED;
audioFile->soundDecoder = soundDecoderInit(audioSoundDecoderReadHandler, audioFile->stream, &(audioFile->channels), &(audioFile->sampleRate), &(audioFile->fileSize));
audioFile->fileSize *= 2;
*sampleRate = audioFile->sampleRate;
} else {
audioFile->fileSize = fileGetSize(stream);
}
@@ -114,30 +112,30 @@ int audioOpen(const char* fname, int flags, ...)
}
// 0x41A50C
int audioClose(int fileHandle)
int audioClose(int handle)
{
AudioFile* audioFile = &(gAudioList[fileHandle - 1]);
fileClose((File*)intToPtr(audioFile->fileHandle, true));
Audio* audioFile = &(gAudioList[handle - 1]);
fileClose(audioFile->stream);
if ((audioFile->flags & AUDIO_FILE_COMPRESSED) != 0) {
if ((audioFile->flags & AUDIO_COMPRESSED) != 0) {
soundDecoderFree(audioFile->soundDecoder);
}
memset(audioFile, 0, sizeof(AudioFile));
memset(audioFile, 0, sizeof(Audio));
return 0;
}
// 0x41A574
int audioRead(int fileHandle, void* buffer, unsigned int size)
int audioRead(int handle, void* buffer, unsigned int size)
{
AudioFile* audioFile = &(gAudioList[fileHandle - 1]);
Audio* audioFile = &(gAudioList[handle - 1]);
int bytesRead;
if ((audioFile->flags & AUDIO_FILE_COMPRESSED) != 0) {
if ((audioFile->flags & AUDIO_COMPRESSED) != 0) {
bytesRead = soundDecoderDecode(audioFile->soundDecoder, buffer, size);
} else {
bytesRead = fileRead(buffer, 1, size, (File*)intToPtr(audioFile->fileHandle));
bytesRead = fileRead(buffer, 1, size, audioFile->stream);
}
audioFile->position += bytesRead;
@@ -146,13 +144,13 @@ int audioRead(int fileHandle, void* buffer, unsigned int size)
}
// 0x41A5E0
long audioSeek(int fileHandle, long offset, int origin)
long audioSeek(int handle, long offset, int origin)
{
int pos;
unsigned char* buf;
int v10;
AudioFile* audioFile = &(gAudioList[fileHandle - 1]);
Audio* audioFile = &(gAudioList[handle - 1]);
switch (origin) {
case SEEK_SET:
@@ -168,11 +166,11 @@ long audioSeek(int fileHandle, long offset, int origin)
assert(false && "Should be unreachable");
}
if ((audioFile->flags & AUDIO_FILE_COMPRESSED) != 0) {
if ((audioFile->flags & AUDIO_COMPRESSED) != 0) {
if (pos < audioFile->position) {
soundDecoderFree(audioFile->soundDecoder);
fileSeek((File*)intToPtr(audioFile->fileHandle), 0, SEEK_SET);
audioFile->soundDecoder = soundDecoderInit(audioSoundDecoderReadHandler, audioFile->fileHandle, &(audioFile->field_14), &(audioFile->field_10), &(audioFile->fileSize));
fileSeek(audioFile->stream, 0, SEEK_SET);
audioFile->soundDecoder = soundDecoderInit(audioSoundDecoderReadHandler, audioFile->stream, &(audioFile->channels), &(audioFile->sampleRate), &(audioFile->fileSize));
audioFile->position = 0;
audioFile->fileSize *= 2;
@@ -180,11 +178,11 @@ long audioSeek(int fileHandle, long offset, int origin)
buf = (unsigned char*)internal_malloc_safe(4096, __FILE__, __LINE__); // "..\int\audio.c", 361
while (pos > 4096) {
pos -= 4096;
audioRead(fileHandle, buf, 4096);
audioRead(handle, buf, 4096);
}
if (pos != 0) {
audioRead(fileHandle, buf, pos);
audioRead(handle, buf, pos);
}
internal_free_safe(buf, __FILE__, __LINE__); // // "..\int\audio.c", 367
@@ -194,11 +192,11 @@ long audioSeek(int fileHandle, long offset, int origin)
v10 = audioFile->position - pos;
while (v10 > 1024) {
v10 -= 1024;
audioRead(fileHandle, buf, 1024);
audioRead(handle, buf, 1024);
}
if (v10 != 0) {
audioRead(fileHandle, buf, v10);
audioRead(handle, buf, v10);
}
// TODO: Probably leaks memory.
@@ -206,21 +204,21 @@ long audioSeek(int fileHandle, long offset, int origin)
return audioFile->position;
} else {
return fileSeek((File*)intToPtr(audioFile->fileHandle), offset, origin);
return fileSeek(audioFile->stream, offset, origin);
}
}
// 0x41A78C
long audioGetSize(int fileHandle)
long audioGetSize(int handle)
{
AudioFile* audioFile = &(gAudioList[fileHandle - 1]);
Audio* audioFile = &(gAudioList[handle - 1]);
return audioFile->fileSize;
}
// 0x41A7A8
long audioTell(int fileHandle)
long audioTell(int handle)
{
AudioFile* audioFile = &(gAudioList[fileHandle - 1]);
Audio* audioFile = &(gAudioList[handle - 1]);
return audioFile->position;
}
@@ -233,10 +231,10 @@ int audioWrite(int handle, const void* buf, unsigned int size)
}
// 0x41A7D4
int audioInit(AudioFileIsCompressedProc* isCompressedProc)
int audioInit(AudioQueryCompressedFunc* func)
{
_queryCompressedFunc = isCompressedProc;
gAudioList = NULL;
queryCompressedFunc = func;
gAudioList = nullptr;
gAudioListLength = 0;
return soundSetDefaultFileIO(audioOpen, audioClose, audioRead, audioWrite, audioSeek, audioTell, audioGetSize);
@@ -245,10 +243,12 @@ int audioInit(AudioFileIsCompressedProc* isCompressedProc)
// 0x41A818
void audioExit()
{
if (gAudioList != NULL) {
if (gAudioList != nullptr) {
internal_free_safe(gAudioList, __FILE__, __LINE__); // "..\int\audio.c", 406
}
gAudioListLength = 0;
gAudioList = NULL;
gAudioList = nullptr;
}
} // namespace fallout

View File

@@ -1,16 +1,20 @@
#ifndef AUDIO_H
#define AUDIO_H
#include "audio_file.h"
namespace fallout {
int audioOpen(const char* fname, int mode, ...);
int audioClose(int fileHandle);
int audioRead(int fileHandle, void* buffer, unsigned int size);
long audioSeek(int fileHandle, long offset, int origin);
long audioGetSize(int fileHandle);
long audioTell(int fileHandle);
typedef bool(AudioQueryCompressedFunc)(char* filePath);
int audioOpen(const char* fname, int* sampleRate);
int audioClose(int handle);
int audioRead(int handle, void* buffer, unsigned int size);
long audioSeek(int handle, long offset, int origin);
long audioGetSize(int handle);
long audioTell(int handle);
int audioWrite(int handle, const void* buf, unsigned int size);
int audioInit(AudioFileIsCompressedProc* isCompressedProc);
int audioInit(AudioQueryCompressedFunc* func);
void audioExit();
} // namespace fallout
#endif /* AUDIO_H */

View File

@@ -6,6 +6,8 @@
#include <SDL.h>
namespace fallout {
#define AUDIO_ENGINE_SOUND_BUFFERS 8
struct AudioEngineSoundBuffer {
@@ -32,6 +34,11 @@ static SDL_AudioSpec gAudioEngineSpec;
static SDL_AudioDeviceID gAudioEngineDeviceId = -1;
static AudioEngineSoundBuffer gAudioEngineSoundBuffers[AUDIO_ENGINE_SOUND_BUFFERS];
static bool audioEngineIsInitialized()
{
return gAudioEngineDeviceId != -1;
}
static bool soundBufferIsValid(int soundBufferIndex)
{
return soundBufferIndex >= 0 && soundBufferIndex < AUDIO_ENGINE_SOUND_BUFFERS;
@@ -99,7 +106,7 @@ bool audioEngineInit()
desiredSpec.samples = 1024;
desiredSpec.callback = audioEngineMixin;
gAudioEngineDeviceId = SDL_OpenAudioDevice(NULL, 0, &desiredSpec, &gAudioEngineSpec, SDL_AUDIO_ALLOW_ANY_CHANGE);
gAudioEngineDeviceId = SDL_OpenAudioDevice(nullptr, 0, &desiredSpec, &gAudioEngineSpec, SDL_AUDIO_ALLOW_ANY_CHANGE);
if (gAudioEngineDeviceId == -1) {
return false;
}
@@ -111,30 +118,36 @@ bool audioEngineInit()
void audioEngineExit()
{
if (gAudioEngineDeviceId != -1) {
if (audioEngineIsInitialized()) {
SDL_CloseAudioDevice(gAudioEngineDeviceId);
gAudioEngineDeviceId = -1;
}
SDL_QuitSubSystem(SDL_INIT_AUDIO);
if (SDL_WasInit(SDL_INIT_AUDIO)) {
SDL_QuitSubSystem(SDL_INIT_AUDIO);
}
}
void audioEnginePause()
{
if (gAudioEngineDeviceId != -1) {
if (audioEngineIsInitialized()) {
SDL_PauseAudioDevice(gAudioEngineDeviceId, 1);
}
}
void audioEngineResume()
{
if (gAudioEngineDeviceId != -1) {
if (audioEngineIsInitialized()) {
SDL_PauseAudioDevice(gAudioEngineDeviceId, 0);
}
}
int audioEngineCreateSoundBuffer(unsigned int size, int bitsPerSample, int channels, int rate)
{
if (!audioEngineIsInitialized()) {
return -1;
}
for (int index = 0; index < AUDIO_ENGINE_SOUND_BUFFERS; index++) {
AudioEngineSoundBuffer* soundBuffer = &(gAudioEngineSoundBuffers[index]);
std::lock_guard<std::recursive_mutex> lock(soundBuffer->mutex);
@@ -160,6 +173,10 @@ int audioEngineCreateSoundBuffer(unsigned int size, int bitsPerSample, int chann
bool audioEngineSoundBufferRelease(int soundBufferIndex)
{
if (!audioEngineIsInitialized()) {
return false;
}
if (!soundBufferIsValid(soundBufferIndex)) {
return false;
}
@@ -174,16 +191,20 @@ bool audioEngineSoundBufferRelease(int soundBufferIndex)
soundBuffer->active = false;
free(soundBuffer->data);
soundBuffer->data = NULL;
soundBuffer->data = nullptr;
SDL_FreeAudioStream(soundBuffer->stream);
soundBuffer->stream = NULL;
soundBuffer->stream = nullptr;
return true;
}
bool audioEngineSoundBufferSetVolume(int soundBufferIndex, int volume)
{
if (!audioEngineIsInitialized()) {
return false;
}
if (!soundBufferIsValid(soundBufferIndex)) {
return false;
}
@@ -202,6 +223,10 @@ bool audioEngineSoundBufferSetVolume(int soundBufferIndex, int volume)
bool audioEngineSoundBufferGetVolume(int soundBufferIndex, int* volumePtr)
{
if (!audioEngineIsInitialized()) {
return false;
}
if (!soundBufferIsValid(soundBufferIndex)) {
return false;
}
@@ -220,6 +245,10 @@ bool audioEngineSoundBufferGetVolume(int soundBufferIndex, int* volumePtr)
bool audioEngineSoundBufferSetPan(int soundBufferIndex, int pan)
{
if (!audioEngineIsInitialized()) {
return false;
}
if (!soundBufferIsValid(soundBufferIndex)) {
return false;
}
@@ -239,6 +268,10 @@ bool audioEngineSoundBufferSetPan(int soundBufferIndex, int pan)
bool audioEngineSoundBufferPlay(int soundBufferIndex, unsigned int flags)
{
if (!audioEngineIsInitialized()) {
return false;
}
if (!soundBufferIsValid(soundBufferIndex)) {
return false;
}
@@ -261,6 +294,10 @@ bool audioEngineSoundBufferPlay(int soundBufferIndex, unsigned int flags)
bool audioEngineSoundBufferStop(int soundBufferIndex)
{
if (!audioEngineIsInitialized()) {
return false;
}
if (!soundBufferIsValid(soundBufferIndex)) {
return false;
}
@@ -279,6 +316,10 @@ bool audioEngineSoundBufferStop(int soundBufferIndex)
bool audioEngineSoundBufferGetCurrentPosition(int soundBufferIndex, unsigned int* readPosPtr, unsigned int* writePosPtr)
{
if (!audioEngineIsInitialized()) {
return false;
}
if (!soundBufferIsValid(soundBufferIndex)) {
return false;
}
@@ -290,11 +331,11 @@ bool audioEngineSoundBufferGetCurrentPosition(int soundBufferIndex, unsigned int
return false;
}
if (readPosPtr != NULL) {
if (readPosPtr != nullptr) {
*readPosPtr = soundBuffer->pos;
}
if (writePosPtr != NULL) {
if (writePosPtr != nullptr) {
*writePosPtr = soundBuffer->pos;
if (soundBuffer->playing) {
@@ -310,6 +351,10 @@ bool audioEngineSoundBufferGetCurrentPosition(int soundBufferIndex, unsigned int
bool audioEngineSoundBufferSetCurrentPosition(int soundBufferIndex, unsigned int pos)
{
if (!audioEngineIsInitialized()) {
return false;
}
if (!soundBufferIsValid(soundBufferIndex)) {
return false;
}
@@ -328,6 +373,10 @@ bool audioEngineSoundBufferSetCurrentPosition(int soundBufferIndex, unsigned int
bool audioEngineSoundBufferLock(int soundBufferIndex, unsigned int writePos, unsigned int writeBytes, void** audioPtr1, unsigned int* audioBytes1, void** audioPtr2, unsigned int* audioBytes2, unsigned int flags)
{
if (!audioEngineIsInitialized()) {
return false;
}
if (!soundBufferIsValid(soundBufferIndex)) {
return false;
}
@@ -339,12 +388,12 @@ bool audioEngineSoundBufferLock(int soundBufferIndex, unsigned int writePos, uns
return false;
}
if (audioBytes1 == NULL) {
if (audioBytes1 == nullptr) {
return false;
}
if ((flags & AUDIO_ENGINE_SOUND_BUFFER_LOCK_FROM_WRITE_POS) != 0) {
if (!audioEngineSoundBufferGetCurrentPosition(soundBufferIndex, NULL, &writePos)) {
if (!audioEngineSoundBufferGetCurrentPosition(soundBufferIndex, nullptr, &writePos)) {
return false;
}
}
@@ -357,11 +406,11 @@ bool audioEngineSoundBufferLock(int soundBufferIndex, unsigned int writePos, uns
*(unsigned char**)audioPtr1 = (unsigned char*)soundBuffer->data + writePos;
*audioBytes1 = writeBytes;
if (audioPtr2 != NULL) {
*audioPtr2 = NULL;
if (audioPtr2 != nullptr) {
*audioPtr2 = nullptr;
}
if (audioBytes2 != NULL) {
if (audioBytes2 != nullptr) {
*audioBytes2 = 0;
}
} else {
@@ -369,11 +418,11 @@ bool audioEngineSoundBufferLock(int soundBufferIndex, unsigned int writePos, uns
*(unsigned char**)audioPtr1 = (unsigned char*)soundBuffer->data + writePos;
*audioBytes1 = soundBuffer->size - writePos;
if (audioPtr2 != NULL) {
if (audioPtr2 != nullptr) {
*(unsigned char**)audioPtr2 = (unsigned char*)soundBuffer->data;
}
if (audioBytes2 != NULL) {
if (audioBytes2 != nullptr) {
*audioBytes2 = writeBytes - (soundBuffer->size - writePos);
}
}
@@ -385,6 +434,10 @@ bool audioEngineSoundBufferLock(int soundBufferIndex, unsigned int writePos, uns
bool audioEngineSoundBufferUnlock(int soundBufferIndex, void* audioPtr1, unsigned int audioBytes1, void* audioPtr2, unsigned int audioBytes2)
{
if (!audioEngineIsInitialized()) {
return false;
}
if (!soundBufferIsValid(soundBufferIndex)) {
return false;
}
@@ -403,6 +456,10 @@ bool audioEngineSoundBufferUnlock(int soundBufferIndex, void* audioPtr1, unsigne
bool audioEngineSoundBufferGetStatus(int soundBufferIndex, unsigned int* statusPtr)
{
if (!audioEngineIsInitialized()) {
return false;
}
if (!soundBufferIsValid(soundBufferIndex)) {
return false;
}
@@ -414,7 +471,7 @@ bool audioEngineSoundBufferGetStatus(int soundBufferIndex, unsigned int* statusP
return false;
}
if (statusPtr == NULL) {
if (statusPtr == nullptr) {
return false;
}
@@ -430,3 +487,5 @@ bool audioEngineSoundBufferGetStatus(int soundBufferIndex, unsigned int* statusP
return true;
}
} // namespace fallout

View File

@@ -1,6 +1,8 @@
#ifndef AUDIO_ENGINE_H
#define AUDIO_ENGINE_H
namespace fallout {
#define AUDIO_ENGINE_SOUND_BUFFER_LOCK_FROM_WRITE_POS 0x00000001
#define AUDIO_ENGINE_SOUND_BUFFER_LOCK_ENTIRE_BUFFER 0x00000002
@@ -26,4 +28,6 @@ bool audioEngineSoundBufferLock(int soundBufferIndex, unsigned int writePos, uns
bool audioEngineSoundBufferUnlock(int soundBufferIndex, void* audioPtr1, unsigned int audioBytes1, void* audioPtr2, unsigned int audioBytes2);
bool audioEngineSoundBufferGetStatus(int soundBufferIndex, unsigned int* status);
} // namespace fallout
#endif /* AUDIO_ENGINE_H */

View File

@@ -7,14 +7,31 @@
#include "debug.h"
#include "memory_manager.h"
#include "platform_compat.h"
#include "pointer_registry.h"
#include "sound.h"
#include "sound_decoder.h"
static bool _defaultCompressionFunc__(char* filePath);
static int audioFileSoundDecoderReadHandler(int fileHandle, void* buffer, unsigned int size);
namespace fallout {
typedef enum AudioFileFlags {
AUDIO_FILE_IN_USE = 0x01,
AUDIO_FILE_COMPRESSED = 0x02,
} AudioFileFlags;
typedef struct AudioFile {
int flags;
FILE* stream;
SoundDecoder* soundDecoder;
int fileSize;
int sampleRate;
int channels;
int position;
} AudioFile;
static bool defaultCompressionFunc(char* filePath);
static int audioFileSoundDecoderReadHandler(void* data, void* buffer, unsigned int size);
// 0x5108C0
static AudioFileIsCompressedProc* _queryCompressedFunc_2 = _defaultCompressionFunc__;
static AudioFileQueryCompressedFunc* queryCompressedFunc = defaultCompressionFunc;
// 0x56CB10
static AudioFile* gAudioFileList;
@@ -23,58 +40,37 @@ static AudioFile* gAudioFileList;
static int gAudioFileListLength;
// 0x41A850
static bool _defaultCompressionFunc__(char* filePath)
static bool defaultCompressionFunc(char* filePath)
{
char* pch = strrchr(filePath, '.');
if (pch != NULL) {
strcpy(pch + 1, "war");
if (pch != nullptr) {
strcpy(pch + 1, "raw");
}
return false;
}
// 0x41A870
static int audioFileSoundDecoderReadHandler(int fileHandle, void* buffer, unsigned int size)
static int audioFileSoundDecoderReadHandler(void* data, void* buffer, unsigned int size)
{
return fread(buffer, 1, size, (FILE*)intToPtr(fileHandle));
return fread(buffer, 1, size, reinterpret_cast<FILE*>(data));
}
// 0x41A88C
int audioFileOpen(const char* fname, int flags, ...)
int audioFileOpen(const char* fname, int* sampleRate)
{
char path[COMPAT_MAX_PATH];
strcpy(path, fname);
int compression;
if (_queryCompressedFunc_2(path)) {
if (queryCompressedFunc(path)) {
compression = 2;
} else {
compression = 0;
}
char mode[4];
memset(mode, '\0', 4);
// NOTE: Original implementation is slightly different, it uses separate
// variable to track index where to set 't' and 'b'.
char* pm = mode;
if (flags & 0x01) {
*pm++ = 'w';
} else if (flags & 0x02) {
*pm++ = 'w';
*pm++ = '+';
} else {
*pm++ = 'r';
}
if (flags & 0x0100) {
*pm++ = 't';
} else if (flags & 0x0200) {
*pm++ = 'b';
}
FILE* stream = compat_fopen(path, mode);
if (stream == NULL) {
FILE* stream = compat_fopen(path, "rb");
if (stream == nullptr) {
return -1;
}
@@ -86,7 +82,7 @@ int audioFileOpen(const char* fname, int flags, ...)
}
if (index == gAudioFileListLength) {
if (gAudioFileList != NULL) {
if (gAudioFileList != nullptr) {
gAudioFileList = (AudioFile*)internal_realloc_safe(gAudioFileList, sizeof(*gAudioFileList) * (gAudioFileListLength + 1), __FILE__, __LINE__); // "..\int\audiof.c", 207
} else {
gAudioFileList = (AudioFile*)internal_malloc_safe(sizeof(*gAudioFileList), __FILE__, __LINE__); // "..\int\audiof.c", 209
@@ -96,12 +92,14 @@ int audioFileOpen(const char* fname, int flags, ...)
AudioFile* audioFile = &(gAudioFileList[index]);
audioFile->flags = AUDIO_FILE_IN_USE;
audioFile->fileHandle = ptrToInt(stream);
audioFile->stream = stream;
if (compression == 2) {
audioFile->flags |= AUDIO_FILE_COMPRESSED;
audioFile->soundDecoder = soundDecoderInit(audioFileSoundDecoderReadHandler, audioFile->fileHandle, &(audioFile->field_14), &(audioFile->field_10), &(audioFile->fileSize));
audioFile->soundDecoder = soundDecoderInit(audioFileSoundDecoderReadHandler, audioFile->stream, &(audioFile->channels), &(audioFile->sampleRate), &(audioFile->fileSize));
audioFile->fileSize *= 2;
*sampleRate = audioFile->sampleRate;
} else {
audioFile->fileSize = getFileSize(stream);
}
@@ -112,10 +110,10 @@ int audioFileOpen(const char* fname, int flags, ...)
}
// 0x41AAA0
int audioFileClose(int fileHandle)
int audioFileClose(int handle)
{
AudioFile* audioFile = &(gAudioFileList[fileHandle - 1]);
fclose((FILE*)intToPtr(audioFile->fileHandle, true));
AudioFile* audioFile = &(gAudioFileList[handle - 1]);
fclose(audioFile->stream);
if ((audioFile->flags & AUDIO_FILE_COMPRESSED) != 0) {
soundDecoderFree(audioFile->soundDecoder);
@@ -128,16 +126,16 @@ int audioFileClose(int fileHandle)
}
// 0x41AB08
int audioFileRead(int fileHandle, void* buffer, unsigned int size)
int audioFileRead(int handle, void* buffer, unsigned int size)
{
AudioFile* ptr = &(gAudioFileList[fileHandle - 1]);
AudioFile* ptr = &(gAudioFileList[handle - 1]);
int bytesRead;
if ((ptr->flags & AUDIO_FILE_COMPRESSED) != 0) {
bytesRead = soundDecoderDecode(ptr->soundDecoder, buffer, size);
} else {
bytesRead = fread(buffer, 1, size, (FILE*)intToPtr(ptr->fileHandle));
bytesRead = fread(buffer, 1, size, ptr->stream);
}
ptr->position += bytesRead;
@@ -146,13 +144,13 @@ int audioFileRead(int fileHandle, void* buffer, unsigned int size)
}
// 0x41AB74
long audioFileSeek(int fileHandle, long offset, int origin)
long audioFileSeek(int handle, long offset, int origin)
{
void* buf;
int remaining;
int a4;
AudioFile* audioFile = &(gAudioFileList[fileHandle - 1]);
AudioFile* audioFile = &(gAudioFileList[handle - 1]);
switch (origin) {
case SEEK_SET:
@@ -172,20 +170,20 @@ long audioFileSeek(int fileHandle, long offset, int origin)
if (a4 <= audioFile->position) {
soundDecoderFree(audioFile->soundDecoder);
fseek((FILE*)intToPtr(audioFile->fileHandle), 0, 0);
fseek(audioFile->stream, 0, 0);
audioFile->soundDecoder = soundDecoderInit(audioFileSoundDecoderReadHandler, audioFile->fileHandle, &(audioFile->field_14), &(audioFile->field_10), &(audioFile->fileSize));
audioFile->soundDecoder = soundDecoderInit(audioFileSoundDecoderReadHandler, audioFile->stream, &(audioFile->channels), &(audioFile->sampleRate), &(audioFile->fileSize));
audioFile->fileSize *= 2;
audioFile->position = 0;
if (a4) {
buf = internal_malloc_safe(4096, __FILE__, __LINE__); // "..\int\audiof.c", 364
while (a4 > 4096) {
audioFileRead(fileHandle, buf, 4096);
audioFileRead(handle, buf, 4096);
a4 -= 4096;
}
if (a4 != 0) {
audioFileRead(fileHandle, buf, a4);
audioFileRead(handle, buf, a4);
}
internal_free_safe(buf, __FILE__, __LINE__); // "..\int\audiof.c", 370
}
@@ -193,47 +191,47 @@ long audioFileSeek(int fileHandle, long offset, int origin)
buf = internal_malloc_safe(0x400, __FILE__, __LINE__); // "..\int\audiof.c", 316
remaining = audioFile->position - a4;
while (remaining > 1024) {
audioFileRead(fileHandle, buf, 1024);
audioFileRead(handle, buf, 1024);
remaining -= 1024;
}
if (remaining != 0) {
audioFileRead(fileHandle, buf, remaining);
audioFileRead(handle, buf, remaining);
}
// TODO: Obiously leaks memory.
}
return audioFile->position;
}
return fseek((FILE*)intToPtr(audioFile->fileHandle), offset, origin);
return fseek(audioFile->stream, offset, origin);
}
// 0x41AD20
long audioFileGetSize(int fileHandle)
long audioFileGetSize(int handle)
{
AudioFile* audioFile = &(gAudioFileList[fileHandle - 1]);
AudioFile* audioFile = &(gAudioFileList[handle - 1]);
return audioFile->fileSize;
}
// 0x41AD3C
long audioFileTell(int fileHandle)
long audioFileTell(int handle)
{
AudioFile* audioFile = &(gAudioFileList[fileHandle - 1]);
AudioFile* audioFile = &(gAudioFileList[handle - 1]);
return audioFile->position;
}
// AudiofWrite
// 0x41AD58
int audioFileWrite(int fileHandle, const void* buffer, unsigned int size)
int audioFileWrite(int handle, const void* buffer, unsigned int size)
{
debugPrint("AudiofWrite shouldn't be ever called\n");
return 0;
}
// 0x41AD68
int audioFileInit(AudioFileIsCompressedProc* isCompressedProc)
int audioFileInit(AudioFileQueryCompressedFunc* func)
{
_queryCompressedFunc_2 = isCompressedProc;
gAudioFileList = NULL;
queryCompressedFunc = func;
gAudioFileList = nullptr;
gAudioFileListLength = 0;
return soundSetDefaultFileIO(audioFileOpen, audioFileClose, audioFileRead, audioFileWrite, audioFileSeek, audioFileTell, audioFileGetSize);
@@ -242,10 +240,12 @@ int audioFileInit(AudioFileIsCompressedProc* isCompressedProc)
// 0x41ADAC
void audioFileExit()
{
if (gAudioFileList != NULL) {
if (gAudioFileList != nullptr) {
internal_free_safe(gAudioFileList, __FILE__, __LINE__); // "..\int\audiof.c", 405
}
gAudioFileListLength = 0;
gAudioFileList = NULL;
gAudioFileList = nullptr;
}
} // namespace fallout

View File

@@ -1,33 +1,20 @@
#ifndef AUDIO_FILE_H
#define AUDIO_FILE_H
#include "sound_decoder.h"
namespace fallout {
typedef enum AudioFileFlags {
AUDIO_FILE_IN_USE = 0x01,
AUDIO_FILE_COMPRESSED = 0x02,
} AudioFileFlags;
typedef bool(AudioFileQueryCompressedFunc)(char* filePath);
typedef struct AudioFile {
int flags;
int fileHandle;
SoundDecoder* soundDecoder;
int fileSize;
int field_10;
int field_14;
int position;
} AudioFile;
typedef bool(AudioFileIsCompressedProc)(char* filePath);
int audioFileOpen(const char* fname, int flags, ...);
int audioFileClose(int a1);
int audioFileRead(int a1, void* buf, unsigned int size);
int audioFileOpen(const char* fname, int* sampleRate);
int audioFileClose(int handle);
int audioFileRead(int handle, void* buf, unsigned int size);
long audioFileSeek(int handle, long offset, int origin);
long audioFileGetSize(int a1);
long audioFileTell(int a1);
long audioFileGetSize(int handle);
long audioFileTell(int handle);
int audioFileWrite(int handle, const void* buf, unsigned int size);
int audioFileInit(AudioFileIsCompressedProc* isCompressedProc);
int audioFileInit(AudioFileQueryCompressedFunc* func);
void audioFileExit();
} // namespace fallout
#endif /* AUDIO_FILE_H */

View File

@@ -8,23 +8,27 @@
#include "art.h"
#include "color.h"
#include "config.h"
#include "core.h"
#include "dbox.h"
#include "debug.h"
#include "draw.h"
#include "game.h"
#include "game_config.h"
#include "game_mouse.h"
#include "game_sound.h"
#include "graph_lib.h"
#include "input.h"
#include "item.h"
#include "kb.h"
#include "map.h"
#include "memory.h"
#include "object.h"
#include "platform_compat.h"
#include "settings.h"
#include "svga.h"
#include "text_font.h"
#include "window_manager.h"
namespace fallout {
#define AUTOMAP_OFFSET_COUNT (AUTOMAP_MAP_COUNT * ELEVATION_COUNT)
#define AUTOMAP_WINDOW_WIDTH (519)
@@ -267,12 +271,9 @@ int automapReset()
// 0x41B81C
void automapExit()
{
char* masterPatchesPath;
if (configGetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_MASTER_PATCHES_KEY, &masterPatchesPath)) {
char path[COMPAT_MAX_PATH];
sprintf(path, "%s\\%s\\%s", masterPatchesPath, "MAPS", AUTOMAP_DB);
compat_remove(path);
}
char path[COMPAT_MAX_PATH];
snprintf(path, sizeof(path), "%s\\%s\\%s", settings.system.master_patches_path.c_str(), "MAPS", AUTOMAP_DB);
compat_remove(path);
}
// 0x41B87C
@@ -296,18 +297,15 @@ int _automapDisplayMap(int map)
// 0x41B8BC
void automapShow(bool isInGame, bool isUsingScanner)
{
ScopedGameMode gm(GameMode::kAutomap);
int frmIds[AUTOMAP_FRM_COUNT];
memcpy(frmIds, gAutomapFrmIds, sizeof(gAutomapFrmIds));
unsigned char* frmData[AUTOMAP_FRM_COUNT];
CacheEntry* frmHandle[AUTOMAP_FRM_COUNT];
FrmImage frmImages[AUTOMAP_FRM_COUNT];
for (int index = 0; index < AUTOMAP_FRM_COUNT; index++) {
int fid = buildFid(OBJ_TYPE_INTERFACE, frmIds[index], 0, 0, 0);
frmData[index] = artLockFrameData(fid, 0, 0, &(frmHandle[index]));
if (frmData[index] == NULL) {
while (--index >= 0) {
artUnlock(frmHandle[index]);
}
if (!frmImages[index].lock(fid)) {
return;
}
}
@@ -325,19 +323,55 @@ void automapShow(bool isInGame, bool isUsingScanner)
int automapWindowX = (screenGetWidth() - AUTOMAP_WINDOW_WIDTH) / 2;
int automapWindowY = (screenGetHeight() - AUTOMAP_WINDOW_HEIGHT) / 2;
int window = windowCreate(automapWindowX, automapWindowY, AUTOMAP_WINDOW_WIDTH, AUTOMAP_WINDOW_HEIGHT, color, WINDOW_FLAG_0x10 | WINDOW_FLAG_0x04);
int window = windowCreate(automapWindowX, automapWindowY, AUTOMAP_WINDOW_WIDTH, AUTOMAP_WINDOW_HEIGHT, color, WINDOW_MODAL | WINDOW_MOVE_ON_TOP);
int scannerBtn = buttonCreate(window, 111, 454, 15, 16, -1, -1, -1, KEY_LOWERCASE_S, frmData[AUTOMAP_FRM_BUTTON_UP], frmData[AUTOMAP_FRM_BUTTON_DOWN], NULL, BUTTON_FLAG_TRANSPARENT);
int scannerBtn = buttonCreate(window,
111,
454,
15,
16,
-1,
-1,
-1,
KEY_LOWERCASE_S,
frmImages[AUTOMAP_FRM_BUTTON_UP].getData(),
frmImages[AUTOMAP_FRM_BUTTON_DOWN].getData(),
nullptr,
BUTTON_FLAG_TRANSPARENT);
if (scannerBtn != -1) {
buttonSetCallbacks(scannerBtn, _gsound_red_butt_press, _gsound_red_butt_release);
}
int cancelBtn = buttonCreate(window, 277, 454, 15, 16, -1, -1, -1, KEY_ESCAPE, frmData[AUTOMAP_FRM_BUTTON_UP], frmData[AUTOMAP_FRM_BUTTON_DOWN], NULL, BUTTON_FLAG_TRANSPARENT);
int cancelBtn = buttonCreate(window,
277,
454,
15,
16,
-1,
-1,
-1,
KEY_ESCAPE,
frmImages[AUTOMAP_FRM_BUTTON_UP].getData(),
frmImages[AUTOMAP_FRM_BUTTON_DOWN].getData(),
nullptr,
BUTTON_FLAG_TRANSPARENT);
if (cancelBtn != -1) {
buttonSetCallbacks(cancelBtn, _gsound_red_butt_press, _gsound_red_butt_release);
}
int switchBtn = buttonCreate(window, 457, 340, 42, 74, -1, -1, KEY_LOWERCASE_L, KEY_LOWERCASE_H, frmData[AUTOMAP_FRM_SWITCH_UP], frmData[AUTOMAP_FRM_SWITCH_DOWN], NULL, BUTTON_FLAG_TRANSPARENT | BUTTON_FLAG_0x01);
int switchBtn = buttonCreate(window,
457,
340,
42,
74,
-1,
-1,
KEY_LOWERCASE_L,
KEY_LOWERCASE_H,
frmImages[AUTOMAP_FRM_SWITCH_UP].getData(),
frmImages[AUTOMAP_FRM_SWITCH_DOWN].getData(),
nullptr,
BUTTON_FLAG_TRANSPARENT | BUTTON_FLAG_0x01);
if (switchBtn != -1) {
buttonSetCallbacks(switchBtn, _gsound_toggle_butt_press_, _gsound_toggle_butt_press_);
}
@@ -358,18 +392,20 @@ void automapShow(bool isInGame, bool isUsingScanner)
gAutomapFlags |= AUTOMAP_WITH_SCANNER;
}
automapRenderInMapWindow(window, elevation, frmData[AUTOMAP_FRM_BACKGROUND], gAutomapFlags);
automapRenderInMapWindow(window, elevation, frmImages[AUTOMAP_FRM_BACKGROUND].getData(), gAutomapFlags);
bool isoWasEnabled = isoDisable();
gameMouseSetCursor(MOUSE_CURSOR_ARROW);
bool done = false;
while (!done) {
sharedFpsLimiter.mark();
bool needsRefresh = false;
// FIXME: There is minor bug in the interface - pressing H/L to toggle
// high/low details does not update switch state.
int keyCode = _get_input();
int keyCode = inputGetInput();
switch (keyCode) {
case KEY_TAB:
case KEY_ESCAPE:
@@ -399,19 +435,19 @@ void automapShow(bool isInGame, bool isUsingScanner)
}
if ((gAutomapFlags & AUTOMAP_WITH_SCANNER) == 0) {
Object* scanner = NULL;
Object* scanner = nullptr;
Object* item1 = critterGetItem1(gDude);
if (item1 != NULL && item1->pid == PROTO_ID_MOTION_SENSOR) {
if (item1 != nullptr && item1->pid == PROTO_ID_MOTION_SENSOR) {
scanner = item1;
} else {
Object* item2 = critterGetItem2(gDude);
if (item2 != NULL && item2->pid == PROTO_ID_MOTION_SENSOR) {
if (item2 != nullptr && item2->pid == PROTO_ID_MOTION_SENSOR) {
scanner = item2;
}
}
if (scanner != NULL && miscItemGetCharges(scanner) > 0) {
if (scanner != nullptr && miscItemGetCharges(scanner) > 0) {
needsRefresh = true;
gAutomapFlags |= AUTOMAP_WITH_SCANNER;
miscItemConsumeCharge(scanner);
@@ -421,8 +457,8 @@ void automapShow(bool isInGame, bool isUsingScanner)
MessageListItem messageListItem;
// 17 - The motion sensor is not installed.
// 18 - The motion sensor has no charges remaining.
const char* title = getmsg(&gMiscMessageList, &messageListItem, scanner != NULL ? 18 : 17);
showDialogBox(title, NULL, 0, 165, 140, _colorTable[32328], NULL, _colorTable[32328], 0);
const char* title = getmsg(&gMiscMessageList, &messageListItem, scanner != nullptr ? 18 : 17);
showDialogBox(title, nullptr, 0, 165, 140, _colorTable[32328], nullptr, _colorTable[32328], 0);
}
}
@@ -442,9 +478,12 @@ void automapShow(bool isInGame, bool isUsingScanner)
}
if (needsRefresh) {
automapRenderInMapWindow(window, elevation, frmData[AUTOMAP_FRM_BACKGROUND], gAutomapFlags);
automapRenderInMapWindow(window, elevation, frmImages[AUTOMAP_FRM_BACKGROUND].getData(), gAutomapFlags);
needsRefresh = false;
}
renderPresent();
sharedFpsLimiter.throttle();
}
if (isoWasEnabled) {
@@ -453,10 +492,6 @@ void automapShow(bool isInGame, bool isUsingScanner)
windowDestroy(window);
fontSetCurrent(oldFont);
for (int index = 0; index < AUTOMAP_FRM_COUNT; index++) {
artUnlock(frmHandle[index]);
}
}
// Renders automap in Map window.
@@ -477,7 +512,7 @@ static void automapRenderInMapWindow(int window, int elevation, unsigned char* b
unsigned char* windowBuffer = windowGetBuffer(window);
blitBufferToBuffer(backgroundData, AUTOMAP_WINDOW_WIDTH, AUTOMAP_WINDOW_HEIGHT, AUTOMAP_WINDOW_WIDTH, windowBuffer, AUTOMAP_WINDOW_WIDTH);
for (Object* object = objectFindFirstAtElevation(elevation); object != NULL; object = objectFindNextAtElevation()) {
for (Object* object = objectFindFirstAtElevation(elevation); object != nullptr; object = objectFindNextAtElevation()) {
if (object->tile == -1) {
continue;
}
@@ -591,7 +626,7 @@ int automapRenderInPipboyWindow(int window, int map, int elevation)
unsigned char sceneryColor = _colorTable[480];
gAutomapEntry.data = (unsigned char*)internal_malloc(11024);
if (gAutomapEntry.data == NULL) {
if (gAutomapEntry.data == nullptr) {
debugPrint("\nAUTOMAP: Error allocating data buffer!\n");
return -1;
}
@@ -659,9 +694,9 @@ int automapSaveCurrent()
bool dataBuffersAllocated = false;
gAutomapEntry.data = (unsigned char*)internal_malloc(11024);
if (gAutomapEntry.data != NULL) {
if (gAutomapEntry.data != nullptr) {
gAutomapEntry.compressedData = (unsigned char*)internal_malloc(11024);
if (gAutomapEntry.compressedData != NULL) {
if (gAutomapEntry.compressedData != nullptr) {
dataBuffersAllocated = true;
}
}
@@ -674,10 +709,10 @@ int automapSaveCurrent()
// NOTE: Not sure about the size.
char path[256];
sprintf(path, "%s\\%s", "MAPS", AUTOMAP_DB);
snprintf(path, sizeof(path), "%s\\%s", "MAPS", AUTOMAP_DB);
File* stream1 = fileOpen(path, "r+b");
if (stream1 == NULL) {
if (stream1 == nullptr) {
debugPrint("\nAUTOMAP: Error opening automap database file!\n");
debugPrint("Error continued: automap_pip_save: path: %s", path);
internal_free(gAutomapEntry.data);
@@ -705,10 +740,10 @@ int automapSaveCurrent()
}
if (entryOffset != 0) {
sprintf(path, "%s\\%s", "MAPS", AUTOMAP_TMP);
snprintf(path, sizeof(path), "%s\\%s", "MAPS", AUTOMAP_TMP);
File* stream2 = fileOpen(path, "wb");
if (stream2 == NULL) {
if (stream2 == nullptr) {
debugPrint("\nAUTOMAP: Error creating temp file!\n");
internal_free(gAutomapEntry.data);
internal_free(gAutomapEntry.compressedData);
@@ -799,15 +834,9 @@ int automapSaveCurrent()
internal_free(gAutomapEntry.data);
internal_free(gAutomapEntry.compressedData);
char* masterPatchesPath;
if (!configGetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_MASTER_PATCHES_KEY, &masterPatchesPath)) {
debugPrint("\nAUTOMAP: Error reading config info!\n");
return -1;
}
// NOTE: Not sure about the size.
char automapDbPath[512];
sprintf(automapDbPath, "%s\\%s\\%s", masterPatchesPath, "MAPS", AUTOMAP_DB);
snprintf(automapDbPath, sizeof(automapDbPath), "%s\\%s\\%s", settings.system.master_patches_path.c_str(), "MAPS", AUTOMAP_DB);
if (compat_remove(automapDbPath) != 0) {
debugPrint("\nAUTOMAP: Error removing database!\n");
return -1;
@@ -815,7 +844,7 @@ int automapSaveCurrent()
// NOTE: Not sure about the size.
char automapTmpPath[512];
sprintf(automapTmpPath, "%s\\%s\\%s", masterPatchesPath, "MAPS", AUTOMAP_TMP);
snprintf(automapTmpPath, sizeof(automapTmpPath), "%s\\%s\\%s", settings.system.master_patches_path.c_str(), "MAPS", AUTOMAP_TMP);
if (compat_rename(automapTmpPath, automapDbPath) != 0) {
debugPrint("\nAUTOMAP: Error renaming database!\n");
return -1;
@@ -899,15 +928,15 @@ err:
// 0x41C8CC
static int automapLoadEntry(int map, int elevation)
{
gAutomapEntry.compressedData = NULL;
gAutomapEntry.compressedData = nullptr;
char path[COMPAT_MAX_PATH];
sprintf(path, "%s\\%s", "MAPS", AUTOMAP_DB);
snprintf(path, sizeof(path), "%s\\%s", "MAPS", AUTOMAP_DB);
bool success = true;
File* stream = fileOpen(path, "r+b");
if (stream == NULL) {
if (stream == nullptr) {
debugPrint("\nAUTOMAP: Error opening automap database file!\n");
debugPrint("Error continued: AM_ReadEntry: path: %s", path);
return -1;
@@ -941,7 +970,7 @@ static int automapLoadEntry(int map, int elevation)
if (gAutomapEntry.isCompressed == 1) {
gAutomapEntry.compressedData = (unsigned char*)internal_malloc(11024);
if (gAutomapEntry.compressedData == NULL) {
if (gAutomapEntry.compressedData == nullptr) {
debugPrint("\nAUTOMAP: Error allocating decompression buffer!\n");
fileClose(stream);
return -1;
@@ -974,7 +1003,7 @@ out:
return -1;
}
if (gAutomapEntry.compressedData != NULL) {
if (gAutomapEntry.compressedData != nullptr) {
internal_free(gAutomapEntry.compressedData);
}
@@ -1044,7 +1073,7 @@ static void _decode_map_data(int elevation)
_obj_process_seen();
Object* object = objectFindFirstAtElevation(elevation);
while (object != NULL) {
while (object != nullptr) {
if (object->tile != -1 && (object->flags & OBJECT_SEEN) != 0) {
int contentType;
@@ -1077,10 +1106,10 @@ static int automapCreate()
memcpy(gAutomapHeader.offsets, _defam, sizeof(_defam));
char path[COMPAT_MAX_PATH];
sprintf(path, "%s\\%s", "MAPS", AUTOMAP_DB);
snprintf(path, sizeof(path), "%s\\%s", "MAPS", AUTOMAP_DB);
File* stream = fileOpen(path, "wb");
if (stream == NULL) {
if (stream == nullptr) {
debugPrint("\nAUTOMAP: Error creating automap database file!\n");
return -1;
}
@@ -1100,7 +1129,7 @@ static int automapCreate()
static int _copy_file_data(File* stream1, File* stream2, int length)
{
void* buffer = internal_malloc(0xFFFF);
if (buffer == NULL) {
if (buffer == nullptr) {
return -1;
}
@@ -1132,10 +1161,10 @@ static int _copy_file_data(File* stream1, File* stream2, int length)
int automapGetHeader(AutomapHeader** automapHeaderPtr)
{
char path[COMPAT_MAX_PATH];
sprintf(path, "%s\\%s", "MAPS", AUTOMAP_DB);
snprintf(path, sizeof(path), "%s\\%s", "MAPS", AUTOMAP_DB);
File* stream = fileOpen(path, "rb");
if (stream == NULL) {
if (stream == nullptr) {
debugPrint("\nAUTOMAP: Error opening database file for reading!\n");
debugPrint("Error continued: ReadAMList: path: %s", path);
return -1;
@@ -1160,3 +1189,5 @@ void automapSetDisplayMap(int map, bool available)
_displayMapList[map] = available ? 0 : -1;
}
}
} // namespace fallout

View File

@@ -4,6 +4,8 @@
#include "db.h"
#include "map_defs.h"
namespace fallout {
#define AUTOMAP_DB ("AUTOMAP.DB")
#define AUTOMAP_TMP ("AUTOMAP.TMP")
@@ -56,4 +58,6 @@ int automapGetHeader(AutomapHeader** automapHeaderPtr);
void automapSetDisplayMap(int map, bool available);
} // namespace fallout
#endif /* AUTOMAP_H */

View File

@@ -1,8 +1,6 @@
#include "autorun.h"
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#endif
@@ -11,11 +9,13 @@
static HANDLE gInterplayGenericAutorunMutex;
#endif
namespace fallout {
// 0x4139C0
bool autorunMutexCreate()
{
#ifdef _WIN32
gInterplayGenericAutorunMutex = CreateMutexA(NULL, FALSE, "InterplayGenericAutorunMutex");
gInterplayGenericAutorunMutex = CreateMutexA(nullptr, FALSE, "InterplayGenericAutorunMutex");
if (GetLastError() == ERROR_ALREADY_EXISTS) {
CloseHandle(gInterplayGenericAutorunMutex);
return false;
@@ -29,8 +29,10 @@ bool autorunMutexCreate()
void autorunMutexClose()
{
#ifdef _WIN32
if (gInterplayGenericAutorunMutex != NULL) {
if (gInterplayGenericAutorunMutex != nullptr) {
CloseHandle(gInterplayGenericAutorunMutex);
}
#endif
}
} // namespace fallout

View File

@@ -1,7 +1,11 @@
#ifndef AUTORUN_H
#define AUTORUN_H
namespace fallout {
bool autorunMutexCreate();
void autorunMutexClose();
} // namespace fallout
#endif /* AUTORUN_H */

View File

@@ -9,6 +9,8 @@
#include "memory.h"
#include "sound.h"
namespace fallout {
// The initial number of cache entries in new cache.
#define CACHE_ENTRIES_INITIAL_CAPACITY (100)
@@ -49,7 +51,7 @@ bool cacheInit(Cache* cache, CacheSizeProc* sizeProc, CacheReadProc* readProc, C
cache->readProc = readProc;
cache->freeProc = freeProc;
if (cache->entries == NULL) {
if (cache->entries == nullptr) {
return false;
}
@@ -62,7 +64,7 @@ bool cacheInit(Cache* cache, CacheSizeProc* sizeProc, CacheReadProc* readProc, C
// 0x41FD50
bool cacheFree(Cache* cache)
{
if (cache == NULL) {
if (cache == nullptr) {
return false;
}
@@ -76,14 +78,14 @@ bool cacheFree(Cache* cache)
cache->entriesCapacity = 0;
cache->hits = 0;
if (cache->entries != NULL) {
if (cache->entries != nullptr) {
internal_free(cache->entries);
cache->entries = NULL;
cache->entries = nullptr;
}
cache->sizeProc = NULL;
cache->readProc = NULL;
cache->freeProc = NULL;
cache->sizeProc = nullptr;
cache->readProc = nullptr;
cache->freeProc = nullptr;
return true;
}
@@ -91,11 +93,11 @@ bool cacheFree(Cache* cache)
// 0x41FDE8
bool cacheLock(Cache* cache, int key, void** data, CacheEntry** cacheEntryPtr)
{
if (cache == NULL || data == NULL || cacheEntryPtr == NULL) {
if (cache == nullptr || data == nullptr || cacheEntryPtr == nullptr) {
return false;
}
*cacheEntryPtr = NULL;
*cacheEntryPtr = nullptr;
int index;
int rc = cacheFindIndexForKey(cache, key, &index);
@@ -146,7 +148,7 @@ bool cacheLock(Cache* cache, int key, void** data, CacheEntry** cacheEntryPtr)
// 0x4200B8
bool cacheUnlock(Cache* cache, CacheEntry* cacheEntry)
{
if (cache == NULL || cacheEntry == NULL) {
if (cache == nullptr || cacheEntry == nullptr) {
return false;
}
@@ -167,7 +169,7 @@ bool cacheUnlock(Cache* cache, CacheEntry* cacheEntry)
// 0x42012C
bool cacheFlush(Cache* cache)
{
if (cache == NULL) {
if (cache == nullptr) {
return false;
}
@@ -192,13 +194,13 @@ bool cacheFlush(Cache* cache)
}
// 0x42019C
bool cachePrintStats(Cache* cache, char* dest)
bool cachePrintStats(Cache* cache, char* dest, size_t size)
{
if (cache == NULL || dest == NULL) {
if (cache == nullptr || dest == nullptr) {
return false;
}
sprintf(dest, "Cache stats are disabled.%s", "\n");
snprintf(dest, size, "Cache stats are disabled.%s", "\n");
return true;
}
@@ -209,7 +211,7 @@ bool cachePrintStats(Cache* cache, char* dest)
static bool cacheFetchEntryForKey(Cache* cache, int key, int* indexPtr)
{
CacheEntry* cacheEntry = (CacheEntry*)internal_malloc(sizeof(*cacheEntry));
if (cacheEntry == NULL) {
if (cacheEntry == nullptr) {
return false;
}
@@ -374,7 +376,7 @@ static bool cacheEntryInit(CacheEntry* cacheEntry)
{
cacheEntry->key = 0;
cacheEntry->size = 0;
cacheEntry->data = NULL;
cacheEntry->data = nullptr;
cacheEntry->referenceCount = 0;
cacheEntry->hits = 0;
cacheEntry->flags = 0;
@@ -387,7 +389,7 @@ static bool cacheEntryInit(CacheEntry* cacheEntry)
// 0x420740
static bool cacheEntryFree(Cache* cache, CacheEntry* cacheEntry)
{
if (cacheEntry->data != NULL) {
if (cacheEntry->data != nullptr) {
heapBlockDeallocate(&(cache->heap), &(cacheEntry->heapHandleIndex));
}
@@ -418,12 +420,12 @@ static bool cacheClean(Cache* cache)
// 0x4207D4
static bool cacheResetStatistics(Cache* cache)
{
if (cache == NULL) {
if (cache == nullptr) {
return false;
}
CacheEntry** entries = (CacheEntry**)internal_malloc(sizeof(*entries) * cache->entriesLength);
if (entries == NULL) {
if (entries == nullptr) {
return false;
}
@@ -460,7 +462,7 @@ static bool cacheEnsureSize(Cache* cache, int size)
}
CacheEntry** entries = (CacheEntry**)internal_malloc(sizeof(*entries) * cache->entriesLength);
if (entries != NULL) {
if (entries != nullptr) {
memcpy(entries, cache->entries, sizeof(*entries) * cache->entriesLength);
qsort(entries, cache->entriesLength, sizeof(*entries), cacheEntriesCompareByUsage);
@@ -560,7 +562,7 @@ static bool cacheSetCapacity(Cache* cache, int newCapacity)
}
CacheEntry** entries = (CacheEntry**)internal_realloc(cache->entries, sizeof(*cache->entries) * newCapacity);
if (entries == NULL) {
if (entries == nullptr) {
return false;
}
@@ -613,3 +615,5 @@ static int cacheEntriesCompareByMostRecentHit(const void* a1, const void* a2)
return 0;
}
}
} // namespace fallout

View File

@@ -1,8 +1,12 @@
#ifndef CACHE_H
#define CACHE_H
#include <stddef.h>
#include "heap.h"
namespace fallout {
#define INVALID_CACHE_ENTRY ((CacheEntry*)-1)
typedef enum CacheEntryFlags {
@@ -64,6 +68,8 @@ bool cacheFree(Cache* cache);
bool cacheLock(Cache* cache, int key, void** data, CacheEntry** cacheEntryPtr);
bool cacheUnlock(Cache* cache, CacheEntry* cacheEntry);
bool cacheFlush(Cache* cache);
bool cachePrintStats(Cache* cache, char* dest);
bool cachePrintStats(Cache* cache, char* dest, size_t size);
} // namespace fallout
#endif /* CACHE_H */

File diff suppressed because it is too large Load Diff

View File

@@ -3,6 +3,8 @@
#include "db.h"
namespace fallout {
extern int gCharacterEditorRemainingCharacterPoints;
int characterEditorShow(bool isCreationMode);
@@ -13,4 +15,6 @@ int characterEditorSave(File* stream);
int characterEditorLoad(File* stream);
void characterEditorReset();
} // namespace fallout
#endif /* CHARACTER_EDITOR_H */

View File

@@ -9,28 +9,33 @@
#include "art.h"
#include "character_editor.h"
#include "color.h"
#include "core.h"
#include "critter.h"
#include "db.h"
#include "debug.h"
#include "draw.h"
#include "game.h"
#include "game_config.h"
#include "game_sound.h"
#include "input.h"
#include "kb.h"
#include "memory.h"
#include "message.h"
#include "mouse.h"
#include "object.h"
#include "options.h"
#include "palette.h"
#include "platform_compat.h"
#include "preferences.h"
#include "proto.h"
#include "settings.h"
#include "sfall_config.h"
#include "skill.h"
#include "stat.h"
#include "svga.h"
#include "text_font.h"
#include "trait.h"
#include "window_manager.h"
namespace fallout {
#define CS_WINDOW_WIDTH (640)
#define CS_WINDOW_HEIGHT (480)
@@ -81,6 +86,7 @@ static bool characterSelectorWindowRefresh();
static bool characterSelectorWindowRenderFace();
static bool characterSelectorWindowRenderStats();
static bool characterSelectorWindowRenderBio();
static bool characterSelectorWindowFatalError(bool result);
static void premadeCharactersLocalizePath(char* path);
@@ -101,100 +107,41 @@ static int gPremadeCharacterCount = PREMADE_CHARACTER_COUNT;
static int gCharacterSelectorWindow = -1;
// 0x51C7FC
static unsigned char* gCharacterSelectorWindowBuffer = NULL;
static unsigned char* gCharacterSelectorWindowBuffer = nullptr;
// 0x51C800
static unsigned char* gCharacterSelectorBackground = NULL;
static unsigned char* gCharacterSelectorBackground = nullptr;
// 0x51C804
static int gCharacterSelectorWindowPreviousButton = -1;
// 0x51C808
static CacheEntry* gCharacterSelectorWindowPreviousButtonUpFrmHandle = NULL;
// 0x51C80C
static CacheEntry* gCharacterSelectorWindowPreviousButtonDownFrmHandle = NULL;
// 0x51C810
static int gCharacterSelectorWindowNextButton = -1;
// 0x51C814
static CacheEntry* gCharacterSelectorWindowNextButtonUpFrmHandle = NULL;
// 0x51C818
static CacheEntry* gCharacterSelectorWindowNextButtonDownFrmHandle = NULL;
// 0x51C81C
static int gCharacterSelectorWindowTakeButton = -1;
// 0x51C820
static CacheEntry* gCharacterSelectorWindowTakeButtonUpFrmHandle = NULL;
// 0x51C824
static CacheEntry* gCharacterSelectorWindowTakeButtonDownFrmHandle = NULL;
// 0x51C828
static int gCharacterSelectorWindowModifyButton = -1;
// 0x51C82C
static CacheEntry* gCharacterSelectorWindowModifyButtonUpFrmHandle = NULL;
// 0x51C830
static CacheEntry* gCharacterSelectorWindowModifyButtonDownFrmHandle = NULL;
// 0x51C834
static int gCharacterSelectorWindowCreateButton = -1;
// 0x51C838
static CacheEntry* gCharacterSelectorWindowCreateButtonUpFrmHandle = NULL;
// 0x51C83C
static CacheEntry* gCharacterSelectorWindowCreateButtonDownFrmHandle = NULL;
// 0x51C840
static int gCharacterSelectorWindowBackButton = -1;
// 0x51C844
static CacheEntry* gCharacterSelectorWindowBackButtonUpFrmHandle = NULL;
// 0x51C848
static CacheEntry* gCharacterSelectorWindowBackButtonDownFrmHandle = NULL;
// 0x667764
static unsigned char* gCharacterSelectorWindowTakeButtonUpFrmData;
// 0x667768
static unsigned char* gCharacterSelectorWindowModifyButtonDownFrmData;
// 0x66776C
static unsigned char* gCharacterSelectorWindowBackButtonUpFrmData;
// 0x667770
static unsigned char* gCharacterSelectorWindowCreateButtonUpFrmData;
// 0x667774
static unsigned char* gCharacterSelectorWindowModifyButtonUpFrmData;
// 0x667778
static unsigned char* gCharacterSelectorWindowBackButtonDownFrmData;
// 0x66777C
static unsigned char* gCharacterSelectorWindowCreateButtonDownFrmData;
// 0x667780
static unsigned char* gCharacterSelectorWindowTakeButtonDownFrmData;
// 0x667784
static unsigned char* gCharacterSelectorWindowNextButtonDownFrmData;
// 0x667788
static unsigned char* gCharacterSelectorWindowNextButtonUpFrmData;
// 0x66778C
static unsigned char* gCharacterSelectorWindowPreviousButtonUpFrmData;
// 0x667790
static unsigned char* gCharacterSelectorWindowPreviousButtonDownFrmData;
static FrmImage _takeButtonNormalFrmImage;
static FrmImage _takeButtonPressedFrmImage;
static FrmImage _modifyButtonNormalFrmImage;
static FrmImage _modifyButtonPressedFrmImage;
static FrmImage _createButtonNormalFrmImage;
static FrmImage _createButtonPressedFrmImage;
static FrmImage _backButtonNormalFrmImage;
static FrmImage _backButtonPressedFrmImage;
static FrmImage _nextButtonNormalFrmImage;
static FrmImage _nextButtonPressedFrmImage;
static FrmImage _previousButtonNormalFrmImage;
static FrmImage _previousButtonPressedFrmImage;
static std::vector<PremadeCharacterDescription> gCustomPremadeCharacterDescriptions;
@@ -216,11 +163,13 @@ int characterSelectorOpen()
int rc = 0;
bool done = false;
while (!done) {
sharedFpsLimiter.mark();
if (_game_user_wants_to_quit != 0) {
break;
}
int keyCode = _get_input();
int keyCode = inputGetInput();
switch (keyCode) {
case KEY_MINUS:
@@ -290,6 +239,9 @@ int characterSelectorOpen()
characterSelectorWindowRefresh();
break;
}
renderPresent();
sharedFpsLimiter.throttle();
}
paletteFadeTo(gPaletteBlack);
@@ -305,9 +257,6 @@ int characterSelectorOpen()
// 0x4A7468
static bool characterSelectorWindowInit()
{
int backgroundFid;
unsigned char* backgroundFrmData;
if (gCharacterSelectorWindow != -1) {
return false;
}
@@ -316,22 +265,21 @@ static bool characterSelectorWindowInit()
int characterSelectorWindowY = (screenGetHeight() - CS_WINDOW_HEIGHT) / 2;
gCharacterSelectorWindow = windowCreate(characterSelectorWindowX, characterSelectorWindowY, CS_WINDOW_WIDTH, CS_WINDOW_HEIGHT, _colorTable[0], 0);
if (gCharacterSelectorWindow == -1) {
goto err;
return characterSelectorWindowFatalError(false);
}
gCharacterSelectorWindowBuffer = windowGetBuffer(gCharacterSelectorWindow);
if (gCharacterSelectorWindowBuffer == NULL) {
goto err;
if (gCharacterSelectorWindowBuffer == nullptr) {
return characterSelectorWindowFatalError(false);
}
CacheEntry* backgroundFrmHandle;
backgroundFid = buildFid(OBJ_TYPE_INTERFACE, 174, 0, 0, 0);
backgroundFrmData = artLockFrameData(backgroundFid, 0, 0, &backgroundFrmHandle);
if (backgroundFrmData == NULL) {
goto err;
FrmImage backgroundFrmImage;
int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, 174, 0, 0, 0);
if (!backgroundFrmImage.lock(backgroundFid)) {
return characterSelectorWindowFatalError(false);
}
blitBufferToBuffer(backgroundFrmData,
blitBufferToBuffer(backgroundFrmImage.getData(),
CS_WINDOW_WIDTH,
CS_WINDOW_HEIGHT,
CS_WINDOW_WIDTH,
@@ -339,31 +287,29 @@ static bool characterSelectorWindowInit()
CS_WINDOW_WIDTH);
gCharacterSelectorBackground = (unsigned char*)internal_malloc(CS_WINDOW_BACKGROUND_WIDTH * CS_WINDOW_BACKGROUND_HEIGHT);
if (gCharacterSelectorBackground == NULL)
goto err;
if (gCharacterSelectorBackground == nullptr)
return characterSelectorWindowFatalError(false);
blitBufferToBuffer(backgroundFrmData + CS_WINDOW_WIDTH * CS_WINDOW_BACKGROUND_Y + CS_WINDOW_BACKGROUND_X,
blitBufferToBuffer(backgroundFrmImage.getData() + CS_WINDOW_WIDTH * CS_WINDOW_BACKGROUND_Y + CS_WINDOW_BACKGROUND_X,
CS_WINDOW_BACKGROUND_WIDTH,
CS_WINDOW_BACKGROUND_HEIGHT,
CS_WINDOW_WIDTH,
gCharacterSelectorBackground,
CS_WINDOW_BACKGROUND_WIDTH);
artUnlock(backgroundFrmHandle);
backgroundFrmImage.unlock();
int fid;
// Setup "Previous" button.
fid = buildFid(OBJ_TYPE_INTERFACE, 122, 0, 0, 0);
gCharacterSelectorWindowPreviousButtonUpFrmData = artLockFrameData(fid, 0, 0, &gCharacterSelectorWindowPreviousButtonUpFrmHandle);
if (gCharacterSelectorWindowPreviousButtonUpFrmData == NULL) {
goto err;
if (!_previousButtonNormalFrmImage.lock(fid)) {
return characterSelectorWindowFatalError(false);
}
fid = buildFid(OBJ_TYPE_INTERFACE, 123, 0, 0, 0);
gCharacterSelectorWindowPreviousButtonDownFrmData = artLockFrameData(fid, 0, 0, &gCharacterSelectorWindowPreviousButtonDownFrmHandle);
if (gCharacterSelectorWindowPreviousButtonDownFrmData == NULL) {
goto err;
if (!_previousButtonPressedFrmImage.lock(fid)) {
return characterSelectorWindowFatalError(false);
}
gCharacterSelectorWindowPreviousButton = buttonCreate(gCharacterSelectorWindow,
@@ -375,27 +321,25 @@ static bool characterSelectorWindowInit()
-1,
-1,
500,
gCharacterSelectorWindowPreviousButtonUpFrmData,
gCharacterSelectorWindowPreviousButtonDownFrmData,
NULL,
_previousButtonNormalFrmImage.getData(),
_previousButtonPressedFrmImage.getData(),
nullptr,
0);
if (gCharacterSelectorWindowPreviousButton == -1) {
goto err;
return characterSelectorWindowFatalError(false);
}
buttonSetCallbacks(gCharacterSelectorWindowPreviousButton, _gsound_med_butt_press, _gsound_med_butt_release);
// Setup "Next" button.
fid = buildFid(OBJ_TYPE_INTERFACE, 124, 0, 0, 0);
gCharacterSelectorWindowNextButtonUpFrmData = artLockFrameData(fid, 0, 0, &gCharacterSelectorWindowNextButtonUpFrmHandle);
if (gCharacterSelectorWindowNextButtonUpFrmData == NULL) {
goto err;
if (!_nextButtonNormalFrmImage.lock(fid)) {
return characterSelectorWindowFatalError(false);
}
fid = buildFid(OBJ_TYPE_INTERFACE, 125, 0, 0, 0);
gCharacterSelectorWindowNextButtonDownFrmData = artLockFrameData(fid, 0, 0, &gCharacterSelectorWindowNextButtonDownFrmHandle);
if (gCharacterSelectorWindowNextButtonDownFrmData == NULL) {
goto err;
if (!_nextButtonPressedFrmImage.lock(fid)) {
return characterSelectorWindowFatalError(false);
}
gCharacterSelectorWindowNextButton = buttonCreate(gCharacterSelectorWindow,
@@ -407,27 +351,25 @@ static bool characterSelectorWindowInit()
-1,
-1,
501,
gCharacterSelectorWindowNextButtonUpFrmData,
gCharacterSelectorWindowNextButtonDownFrmData,
NULL,
_nextButtonNormalFrmImage.getData(),
_nextButtonPressedFrmImage.getData(),
nullptr,
0);
if (gCharacterSelectorWindowNextButton == -1) {
goto err;
return characterSelectorWindowFatalError(false);
}
buttonSetCallbacks(gCharacterSelectorWindowNextButton, _gsound_med_butt_press, _gsound_med_butt_release);
// Setup "Take" button.
fid = buildFid(OBJ_TYPE_INTERFACE, 8, 0, 0, 0);
gCharacterSelectorWindowTakeButtonUpFrmData = artLockFrameData(fid, 0, 0, &gCharacterSelectorWindowTakeButtonUpFrmHandle);
if (gCharacterSelectorWindowTakeButtonUpFrmData == NULL) {
goto err;
if (!_takeButtonNormalFrmImage.lock(fid)) {
return characterSelectorWindowFatalError(false);
}
fid = buildFid(OBJ_TYPE_INTERFACE, 9, 0, 0, 0);
gCharacterSelectorWindowTakeButtonDownFrmData = artLockFrameData(fid, 0, 0, &gCharacterSelectorWindowTakeButtonDownFrmHandle);
if (gCharacterSelectorWindowTakeButtonDownFrmData == NULL) {
goto err;
if (!_takeButtonPressedFrmImage.lock(fid)) {
return characterSelectorWindowFatalError(false);
}
gCharacterSelectorWindowTakeButton = buttonCreate(gCharacterSelectorWindow,
@@ -439,26 +381,24 @@ static bool characterSelectorWindowInit()
-1,
-1,
KEY_LOWERCASE_T,
gCharacterSelectorWindowTakeButtonUpFrmData,
gCharacterSelectorWindowTakeButtonDownFrmData,
NULL,
_takeButtonNormalFrmImage.getData(),
_takeButtonPressedFrmImage.getData(),
nullptr,
BUTTON_FLAG_TRANSPARENT);
if (gCharacterSelectorWindowTakeButton == -1) {
goto err;
return characterSelectorWindowFatalError(false);
}
buttonSetCallbacks(gCharacterSelectorWindowTakeButton, _gsound_red_butt_press, _gsound_red_butt_release);
// Setup "Modify" button.
fid = buildFid(OBJ_TYPE_INTERFACE, 8, 0, 0, 0);
gCharacterSelectorWindowModifyButtonUpFrmData = artLockFrameData(fid, 0, 0, &gCharacterSelectorWindowModifyButtonUpFrmHandle);
if (gCharacterSelectorWindowModifyButtonUpFrmData == NULL)
goto err;
if (!_modifyButtonNormalFrmImage.lock(fid))
return characterSelectorWindowFatalError(false);
fid = buildFid(OBJ_TYPE_INTERFACE, 9, 0, 0, 0);
gCharacterSelectorWindowModifyButtonDownFrmData = artLockFrameData(fid, 0, 0, &gCharacterSelectorWindowModifyButtonDownFrmHandle);
if (gCharacterSelectorWindowModifyButtonDownFrmData == NULL) {
goto err;
if (!_modifyButtonPressedFrmImage.lock(fid)) {
return characterSelectorWindowFatalError(false);
}
gCharacterSelectorWindowModifyButton = buttonCreate(gCharacterSelectorWindow,
@@ -470,27 +410,25 @@ static bool characterSelectorWindowInit()
-1,
-1,
KEY_LOWERCASE_M,
gCharacterSelectorWindowModifyButtonUpFrmData,
gCharacterSelectorWindowModifyButtonDownFrmData,
NULL,
_modifyButtonNormalFrmImage.getData(),
_modifyButtonPressedFrmImage.getData(),
nullptr,
BUTTON_FLAG_TRANSPARENT);
if (gCharacterSelectorWindowModifyButton == -1) {
goto err;
return characterSelectorWindowFatalError(false);
}
buttonSetCallbacks(gCharacterSelectorWindowModifyButton, _gsound_red_butt_press, _gsound_red_butt_release);
// Setup "Create" button.
fid = buildFid(OBJ_TYPE_INTERFACE, 8, 0, 0, 0);
gCharacterSelectorWindowCreateButtonUpFrmData = artLockFrameData(fid, 0, 0, &gCharacterSelectorWindowCreateButtonUpFrmHandle);
if (gCharacterSelectorWindowCreateButtonUpFrmData == NULL) {
goto err;
if (!_createButtonNormalFrmImage.lock(fid)) {
return characterSelectorWindowFatalError(false);
}
fid = buildFid(OBJ_TYPE_INTERFACE, 9, 0, 0, 0);
gCharacterSelectorWindowCreateButtonDownFrmData = artLockFrameData(fid, 0, 0, &gCharacterSelectorWindowCreateButtonDownFrmHandle);
if (gCharacterSelectorWindowCreateButtonDownFrmData == NULL) {
goto err;
if (!_createButtonPressedFrmImage.lock(fid)) {
return characterSelectorWindowFatalError(false);
}
gCharacterSelectorWindowCreateButton = buttonCreate(gCharacterSelectorWindow,
@@ -502,27 +440,25 @@ static bool characterSelectorWindowInit()
-1,
-1,
KEY_LOWERCASE_C,
gCharacterSelectorWindowCreateButtonUpFrmData,
gCharacterSelectorWindowCreateButtonDownFrmData,
NULL,
_createButtonNormalFrmImage.getData(),
_createButtonPressedFrmImage.getData(),
nullptr,
BUTTON_FLAG_TRANSPARENT);
if (gCharacterSelectorWindowCreateButton == -1) {
goto err;
return characterSelectorWindowFatalError(false);
}
buttonSetCallbacks(gCharacterSelectorWindowCreateButton, _gsound_red_butt_press, _gsound_red_butt_release);
// Setup "Back" button.
fid = buildFid(OBJ_TYPE_INTERFACE, 8, 0, 0, 0);
gCharacterSelectorWindowBackButtonUpFrmData = artLockFrameData(fid, 0, 0, &gCharacterSelectorWindowBackButtonUpFrmHandle);
if (gCharacterSelectorWindowBackButtonUpFrmData == NULL) {
goto err;
if (!_backButtonNormalFrmImage.lock(fid)) {
return characterSelectorWindowFatalError(false);
}
fid = buildFid(OBJ_TYPE_INTERFACE, 9, 0, 0, 0);
gCharacterSelectorWindowBackButtonDownFrmData = artLockFrameData(fid, 0, 0, &gCharacterSelectorWindowBackButtonDownFrmHandle);
if (gCharacterSelectorWindowBackButtonDownFrmData == NULL) {
goto err;
if (!_backButtonPressedFrmImage.lock(fid)) {
return characterSelectorWindowFatalError(false);
}
gCharacterSelectorWindowBackButton = buttonCreate(gCharacterSelectorWindow,
@@ -534,12 +470,12 @@ static bool characterSelectorWindowInit()
-1,
-1,
KEY_ESCAPE,
gCharacterSelectorWindowBackButtonUpFrmData,
gCharacterSelectorWindowBackButtonDownFrmData,
NULL,
_backButtonNormalFrmImage.getData(),
_backButtonPressedFrmImage.getData(),
nullptr,
BUTTON_FLAG_TRANSPARENT);
if (gCharacterSelectorWindowBackButton == -1) {
goto err;
return characterSelectorWindowFatalError(false);
}
buttonSetCallbacks(gCharacterSelectorWindowBackButton, _gsound_red_butt_press, _gsound_red_butt_release);
@@ -549,16 +485,10 @@ static bool characterSelectorWindowInit()
windowRefresh(gCharacterSelectorWindow);
if (!characterSelectorWindowRefresh()) {
goto err;
return characterSelectorWindowFatalError(false);
}
return true;
err:
characterSelectorWindowFree();
return false;
}
// 0x4A7AD4
@@ -573,106 +503,52 @@ static void characterSelectorWindowFree()
gCharacterSelectorWindowPreviousButton = -1;
}
if (gCharacterSelectorWindowPreviousButtonDownFrmData != NULL) {
artUnlock(gCharacterSelectorWindowPreviousButtonDownFrmHandle);
gCharacterSelectorWindowPreviousButtonDownFrmHandle = NULL;
gCharacterSelectorWindowPreviousButtonDownFrmData = NULL;
}
if (gCharacterSelectorWindowPreviousButtonUpFrmData != NULL) {
artUnlock(gCharacterSelectorWindowPreviousButtonUpFrmHandle);
gCharacterSelectorWindowPreviousButtonUpFrmHandle = NULL;
gCharacterSelectorWindowPreviousButtonUpFrmData = NULL;
}
_previousButtonNormalFrmImage.unlock();
_previousButtonPressedFrmImage.unlock();
if (gCharacterSelectorWindowNextButton != -1) {
buttonDestroy(gCharacterSelectorWindowNextButton);
gCharacterSelectorWindowNextButton = -1;
}
if (gCharacterSelectorWindowNextButtonDownFrmData != NULL) {
artUnlock(gCharacterSelectorWindowNextButtonDownFrmHandle);
gCharacterSelectorWindowNextButtonDownFrmHandle = NULL;
gCharacterSelectorWindowNextButtonDownFrmData = NULL;
}
if (gCharacterSelectorWindowNextButtonUpFrmData != NULL) {
artUnlock(gCharacterSelectorWindowNextButtonUpFrmHandle);
gCharacterSelectorWindowNextButtonUpFrmHandle = NULL;
gCharacterSelectorWindowNextButtonUpFrmData = NULL;
}
_nextButtonNormalFrmImage.unlock();
_nextButtonPressedFrmImage.unlock();
if (gCharacterSelectorWindowTakeButton != -1) {
buttonDestroy(gCharacterSelectorWindowTakeButton);
gCharacterSelectorWindowTakeButton = -1;
}
if (gCharacterSelectorWindowTakeButtonDownFrmData != NULL) {
artUnlock(gCharacterSelectorWindowTakeButtonDownFrmHandle);
gCharacterSelectorWindowTakeButtonDownFrmHandle = NULL;
gCharacterSelectorWindowTakeButtonDownFrmData = NULL;
}
if (gCharacterSelectorWindowTakeButtonUpFrmData != NULL) {
artUnlock(gCharacterSelectorWindowTakeButtonUpFrmHandle);
gCharacterSelectorWindowTakeButtonUpFrmHandle = NULL;
gCharacterSelectorWindowTakeButtonUpFrmData = NULL;
}
_takeButtonNormalFrmImage.unlock();
_takeButtonPressedFrmImage.unlock();
if (gCharacterSelectorWindowModifyButton != -1) {
buttonDestroy(gCharacterSelectorWindowModifyButton);
gCharacterSelectorWindowModifyButton = -1;
}
if (gCharacterSelectorWindowModifyButtonDownFrmData != NULL) {
artUnlock(gCharacterSelectorWindowModifyButtonDownFrmHandle);
gCharacterSelectorWindowModifyButtonDownFrmHandle = NULL;
gCharacterSelectorWindowModifyButtonDownFrmData = NULL;
}
if (gCharacterSelectorWindowModifyButtonUpFrmData != NULL) {
artUnlock(gCharacterSelectorWindowModifyButtonUpFrmHandle);
gCharacterSelectorWindowModifyButtonUpFrmHandle = NULL;
gCharacterSelectorWindowModifyButtonUpFrmData = NULL;
}
_modifyButtonNormalFrmImage.unlock();
_modifyButtonPressedFrmImage.unlock();
if (gCharacterSelectorWindowCreateButton != -1) {
buttonDestroy(gCharacterSelectorWindowCreateButton);
gCharacterSelectorWindowCreateButton = -1;
}
if (gCharacterSelectorWindowCreateButtonDownFrmData != NULL) {
artUnlock(gCharacterSelectorWindowCreateButtonDownFrmHandle);
gCharacterSelectorWindowCreateButtonDownFrmHandle = NULL;
gCharacterSelectorWindowCreateButtonDownFrmData = NULL;
}
if (gCharacterSelectorWindowCreateButtonUpFrmData != NULL) {
artUnlock(gCharacterSelectorWindowCreateButtonUpFrmHandle);
gCharacterSelectorWindowCreateButtonUpFrmHandle = NULL;
gCharacterSelectorWindowCreateButtonUpFrmData = NULL;
}
_createButtonNormalFrmImage.unlock();
_createButtonPressedFrmImage.unlock();
if (gCharacterSelectorWindowBackButton != -1) {
buttonDestroy(gCharacterSelectorWindowBackButton);
gCharacterSelectorWindowBackButton = -1;
}
if (gCharacterSelectorWindowBackButtonDownFrmData != NULL) {
artUnlock(gCharacterSelectorWindowBackButtonDownFrmHandle);
gCharacterSelectorWindowBackButtonDownFrmHandle = NULL;
gCharacterSelectorWindowBackButtonDownFrmData = NULL;
}
_backButtonNormalFrmImage.unlock();
_backButtonPressedFrmImage.unlock();
if (gCharacterSelectorWindowBackButtonUpFrmData != NULL) {
artUnlock(gCharacterSelectorWindowBackButtonUpFrmHandle);
gCharacterSelectorWindowBackButtonUpFrmHandle = NULL;
gCharacterSelectorWindowBackButtonUpFrmData = NULL;
}
if (gCharacterSelectorBackground != NULL) {
if (gCharacterSelectorBackground != nullptr) {
internal_free(gCharacterSelectorBackground);
gCharacterSelectorBackground = NULL;
gCharacterSelectorBackground = nullptr;
}
windowDestroy(gCharacterSelectorWindow);
@@ -683,7 +559,7 @@ static void characterSelectorWindowFree()
static bool characterSelectorWindowRefresh()
{
char path[COMPAT_MAX_PATH];
sprintf(path, "%s.gcd", gCustomPremadeCharacterDescriptions[gCurrentPremadeCharacter].fileName);
snprintf(path, sizeof(path), "%s.gcd", gCustomPremadeCharacterDescriptions[gCurrentPremadeCharacter].fileName);
premadeCharactersLocalizePath(path);
if (_proto_dude_init(path) == -1) {
@@ -715,18 +591,17 @@ static bool characterSelectorWindowRenderFace()
{
bool success = false;
CacheEntry* faceFrmHandle;
FrmImage faceFrmImage;
int faceFid = buildFid(OBJ_TYPE_INTERFACE, gCustomPremadeCharacterDescriptions[gCurrentPremadeCharacter].face, 0, 0, 0);
Art* frm = artLock(faceFid, &faceFrmHandle);
if (frm != NULL) {
unsigned char* data = artGetFrameData(frm, 0, 0);
if (data != NULL) {
int width = artGetWidth(frm, 0, 0);
int height = artGetHeight(frm, 0, 0);
if (faceFrmImage.lock(faceFid)) {
unsigned char* data = faceFrmImage.getData();
if (data != nullptr) {
int width = faceFrmImage.getWidth();
int height = faceFrmImage.getHeight();
blitBufferToBufferTrans(data, width, height, width, (gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * 23 + 27), CS_WINDOW_WIDTH);
success = true;
}
artUnlock(faceFrmHandle);
faceFrmImage.unlock();
}
return success;
@@ -762,13 +637,13 @@ static bool characterSelectorWindowRenderStats()
value = critterGetStat(gDude, STAT_STRENGTH);
str = statGetName(STAT_STRENGTH);
sprintf(text, "%s %02d", str, value);
snprintf(text, sizeof(text), "%s %02d", str, value);
length = fontGetStringWidth(text);
fontDrawText(gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * y + CS_WINDOW_PRIMARY_STAT_MID_X - length, text, length, CS_WINDOW_WIDTH, _colorTable[992]);
str = statGetValueDescription(value);
sprintf(text, " %s", str);
snprintf(text, sizeof(text), " %s", str);
length = fontGetStringWidth(text);
fontDrawText(gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * y + CS_WINDOW_PRIMARY_STAT_MID_X, text, length, CS_WINDOW_WIDTH, _colorTable[992]);
@@ -779,13 +654,13 @@ static bool characterSelectorWindowRenderStats()
value = critterGetStat(gDude, STAT_PERCEPTION);
str = statGetName(STAT_PERCEPTION);
sprintf(text, "%s %02d", str, value);
snprintf(text, sizeof(text), "%s %02d", str, value);
length = fontGetStringWidth(text);
fontDrawText(gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * y + CS_WINDOW_PRIMARY_STAT_MID_X - length, text, length, CS_WINDOW_WIDTH, _colorTable[992]);
str = statGetValueDescription(value);
sprintf(text, " %s", str);
snprintf(text, sizeof(text), " %s", str);
length = fontGetStringWidth(text);
fontDrawText(gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * y + CS_WINDOW_PRIMARY_STAT_MID_X, text, length, CS_WINDOW_WIDTH, _colorTable[992]);
@@ -794,15 +669,15 @@ static bool characterSelectorWindowRenderStats()
y += vh;
value = critterGetStat(gDude, STAT_ENDURANCE);
str = statGetName(STAT_PERCEPTION);
str = statGetName(STAT_ENDURANCE);
sprintf(text, "%s %02d", str, value);
snprintf(text, sizeof(text), "%s %02d", str, value);
length = fontGetStringWidth(text);
fontDrawText(gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * y + CS_WINDOW_PRIMARY_STAT_MID_X - length, text, length, CS_WINDOW_WIDTH, _colorTable[992]);
str = statGetValueDescription(value);
sprintf(text, " %s", str);
snprintf(text, sizeof(text), " %s", str);
length = fontGetStringWidth(text);
fontDrawText(gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * y + CS_WINDOW_PRIMARY_STAT_MID_X, text, length, CS_WINDOW_WIDTH, _colorTable[992]);
@@ -813,13 +688,13 @@ static bool characterSelectorWindowRenderStats()
value = critterGetStat(gDude, STAT_CHARISMA);
str = statGetName(STAT_CHARISMA);
sprintf(text, "%s %02d", str, value);
snprintf(text, sizeof(text), "%s %02d", str, value);
length = fontGetStringWidth(text);
fontDrawText(gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * y + CS_WINDOW_PRIMARY_STAT_MID_X - length, text, length, CS_WINDOW_WIDTH, _colorTable[992]);
str = statGetValueDescription(value);
sprintf(text, " %s", str);
snprintf(text, sizeof(text), " %s", str);
length = fontGetStringWidth(text);
fontDrawText(gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * y + CS_WINDOW_PRIMARY_STAT_MID_X, text, length, CS_WINDOW_WIDTH, _colorTable[992]);
@@ -830,13 +705,13 @@ static bool characterSelectorWindowRenderStats()
value = critterGetStat(gDude, STAT_INTELLIGENCE);
str = statGetName(STAT_INTELLIGENCE);
sprintf(text, "%s %02d", str, value);
snprintf(text, sizeof(text), "%s %02d", str, value);
length = fontGetStringWidth(text);
fontDrawText(gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * y + CS_WINDOW_PRIMARY_STAT_MID_X - length, text, length, CS_WINDOW_WIDTH, _colorTable[992]);
str = statGetValueDescription(value);
sprintf(text, " %s", str);
snprintf(text, sizeof(text), " %s", str);
length = fontGetStringWidth(text);
fontDrawText(gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * y + CS_WINDOW_PRIMARY_STAT_MID_X, text, length, CS_WINDOW_WIDTH, _colorTable[992]);
@@ -847,13 +722,13 @@ static bool characterSelectorWindowRenderStats()
value = critterGetStat(gDude, STAT_AGILITY);
str = statGetName(STAT_AGILITY);
sprintf(text, "%s %02d", str, value);
snprintf(text, sizeof(text), "%s %02d", str, value);
length = fontGetStringWidth(text);
fontDrawText(gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * y + CS_WINDOW_PRIMARY_STAT_MID_X - length, text, length, CS_WINDOW_WIDTH, _colorTable[992]);
str = statGetValueDescription(value);
sprintf(text, " %s", str);
snprintf(text, sizeof(text), " %s", str);
length = fontGetStringWidth(text);
fontDrawText(gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * y + CS_WINDOW_PRIMARY_STAT_MID_X, text, length, CS_WINDOW_WIDTH, _colorTable[992]);
@@ -864,13 +739,13 @@ static bool characterSelectorWindowRenderStats()
value = critterGetStat(gDude, STAT_LUCK);
str = statGetName(STAT_LUCK);
sprintf(text, "%s %02d", str, value);
snprintf(text, sizeof(text), "%s %02d", str, value);
length = fontGetStringWidth(text);
fontDrawText(gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * y + CS_WINDOW_PRIMARY_STAT_MID_X - length, text, length, CS_WINDOW_WIDTH, _colorTable[992]);
str = statGetValueDescription(value);
sprintf(text, " %s", str);
snprintf(text, sizeof(text), " %s", str);
length = fontGetStringWidth(text);
fontDrawText(gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * y + CS_WINDOW_PRIMARY_STAT_MID_X, text, length, CS_WINDOW_WIDTH, _colorTable[992]);
@@ -890,7 +765,7 @@ static bool characterSelectorWindowRenderStats()
fontDrawText(gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * y + CS_WINDOW_SECONDARY_STAT_MID_X - length, text, length, CS_WINDOW_WIDTH, _colorTable[992]);
value = critterGetStat(gDude, STAT_MAXIMUM_HIT_POINTS);
sprintf(text, " %d/%d", critterGetHitPoints(gDude), value);
snprintf(text, sizeof(text), " %d/%d", critterGetHitPoints(gDude), value);
length = fontGetStringWidth(text);
fontDrawText(gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * y + CS_WINDOW_SECONDARY_STAT_MID_X, text, length, CS_WINDOW_WIDTH, _colorTable[992]);
@@ -905,7 +780,7 @@ static bool characterSelectorWindowRenderStats()
fontDrawText(gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * y + CS_WINDOW_SECONDARY_STAT_MID_X - length, text, length, CS_WINDOW_WIDTH, _colorTable[992]);
value = critterGetStat(gDude, STAT_ARMOR_CLASS);
sprintf(text, " %d", value);
snprintf(text, sizeof(text), " %d", value);
length = fontGetStringWidth(text);
fontDrawText(gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * y + CS_WINDOW_SECONDARY_STAT_MID_X, text, length, CS_WINDOW_WIDTH, _colorTable[992]);
@@ -923,7 +798,7 @@ static bool characterSelectorWindowRenderStats()
fontDrawText(gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * y + CS_WINDOW_SECONDARY_STAT_MID_X - length, text, length, CS_WINDOW_WIDTH, _colorTable[992]);
value = critterGetStat(gDude, STAT_MAXIMUM_ACTION_POINTS);
sprintf(text, " %d", value);
snprintf(text, sizeof(text), " %d", value);
length = fontGetStringWidth(text);
fontDrawText(gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * y + CS_WINDOW_SECONDARY_STAT_MID_X, text, length, CS_WINDOW_WIDTH, _colorTable[992]);
@@ -931,14 +806,14 @@ static bool characterSelectorWindowRenderStats()
// MELEE DAMAGE
y += vh;
str = statGetName(STAT_ARMOR_CLASS);
str = statGetName(STAT_MELEE_DAMAGE);
strcpy(text, str);
length = fontGetStringWidth(text);
fontDrawText(gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * y + CS_WINDOW_SECONDARY_STAT_MID_X - length, text, length, CS_WINDOW_WIDTH, _colorTable[992]);
value = critterGetStat(gDude, STAT_ARMOR_CLASS);
sprintf(text, " %d", value);
value = critterGetStat(gDude, STAT_MELEE_DAMAGE);
snprintf(text, sizeof(text), " %d", value);
length = fontGetStringWidth(text);
fontDrawText(gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * y + CS_WINDOW_SECONDARY_STAT_MID_X, text, length, CS_WINDOW_WIDTH, _colorTable[992]);
@@ -959,7 +834,7 @@ static bool characterSelectorWindowRenderStats()
fontDrawText(gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * y + CS_WINDOW_SECONDARY_STAT_MID_X - length, text, length, CS_WINDOW_WIDTH, _colorTable[992]);
value = skillGetValue(gDude, skills[index]);
sprintf(text, " %d%%", value);
snprintf(text, sizeof(text), " %d%%", value);
length = fontGetStringWidth(text);
fontDrawText(gCharacterSelectorWindowBuffer + CS_WINDOW_WIDTH * y + CS_WINDOW_SECONDARY_STAT_MID_X, text, length, CS_WINDOW_WIDTH, _colorTable[992]);
@@ -991,11 +866,11 @@ static bool characterSelectorWindowRenderBio()
fontSetCurrent(101);
char path[COMPAT_MAX_PATH];
sprintf(path, "%s.bio", gCustomPremadeCharacterDescriptions[gCurrentPremadeCharacter].fileName);
snprintf(path, sizeof(path), "%s.bio", gCustomPremadeCharacterDescriptions[gCurrentPremadeCharacter].fileName);
premadeCharactersLocalizePath(path);
File* stream = fileOpen(path, "rt");
if (stream != NULL) {
if (stream != nullptr) {
int y = 40;
int lineHeight = fontGetLineHeight();
@@ -1013,28 +888,37 @@ static bool characterSelectorWindowRenderBio()
return true;
}
// NOTE: Inlined.
//
// 0x4A8BD0
static bool characterSelectorWindowFatalError(bool result)
{
characterSelectorWindowFree();
return result;
}
void premadeCharactersInit()
{
char* fileNamesString;
configGetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_PREMADE_CHARACTERS_FILE_NAMES_KEY, &fileNamesString);
if (fileNamesString != NULL && *fileNamesString == '\0') {
fileNamesString = NULL;
if (fileNamesString != nullptr && *fileNamesString == '\0') {
fileNamesString = nullptr;
}
char* faceFidsString;
configGetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_PREMADE_CHARACTERS_FACE_FIDS_KEY, &faceFidsString);
if (faceFidsString != NULL && *faceFidsString == '\0') {
faceFidsString = NULL;
if (faceFidsString != nullptr && *faceFidsString == '\0') {
faceFidsString = nullptr;
}
if (fileNamesString != NULL && faceFidsString != NULL) {
if (fileNamesString != nullptr && faceFidsString != nullptr) {
int fileNamesLength = 0;
for (char* pch = fileNamesString; pch != NULL; pch = strchr(pch + 1, ',')) {
for (char* pch = fileNamesString; pch != nullptr; pch = strchr(pch + 1, ',')) {
fileNamesLength++;
}
int faceFidsLength = 0;
for (char* pch = faceFidsString; pch != NULL; pch = strchr(pch + 1, ',')) {
for (char* pch = faceFidsString; pch != nullptr; pch = strchr(pch + 1, ',')) {
faceFidsLength++;
}
@@ -1045,7 +929,7 @@ void premadeCharactersInit()
char* pch;
pch = strchr(fileNamesString, ',');
if (pch != NULL) {
if (pch != nullptr) {
*pch = '\0';
}
@@ -1054,22 +938,22 @@ void premadeCharactersInit()
continue;
}
sprintf(gCustomPremadeCharacterDescriptions[index].fileName, "premade\\%s", fileNamesString);
snprintf(gCustomPremadeCharacterDescriptions[index].fileName, sizeof(gCustomPremadeCharacterDescriptions[index].fileName), "premade\\%s", fileNamesString);
if (pch != NULL) {
if (pch != nullptr) {
*pch = ',';
}
fileNamesString = pch + 1;
pch = strchr(faceFidsString, ',');
if (pch != NULL) {
if (pch != nullptr) {
*pch = '\0';
}
gCustomPremadeCharacterDescriptions[index].face = atoi(faceFidsString);
if (pch != NULL) {
if (pch != nullptr) {
*pch = ',';
}
@@ -1103,11 +987,7 @@ static void premadeCharactersLocalizePath(char* path)
return;
}
char* language;
if (!configGetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_LANGUAGE_KEY, &language)) {
return;
}
const char* language = settings.system.language.c_str();
if (compat_stricmp(language, ENGLISH) == 0) {
return;
}
@@ -1122,3 +1002,5 @@ static void premadeCharactersLocalizePath(char* path)
strcpy(path, localizedPath);
}
}
} // namespace fallout

View File

@@ -1,9 +1,13 @@
#ifndef CHARACTER_SELECTOR_H
#define CHARACTER_SELECTOR_H
namespace fallout {
int characterSelectorOpen();
void premadeCharactersInit();
void premadeCharactersExit();
} // namespace fallout
#endif /* CHARACTER_SELECTOR_H */

View File

@@ -5,7 +5,9 @@
#include <algorithm>
#include "core.h"
#include "svga.h"
namespace fallout {
#define COLOR_PALETTE_STACK_CAPACITY 16
@@ -49,7 +51,7 @@ static bool _colorsInited = false;
static double gBrightness = 1.0;
// 0x51DF20
static ColorTransitionCallback* gColorPaletteTransitionCallback = NULL;
static ColorTransitionCallback* gColorPaletteTransitionCallback = nullptr;
// 0x51DF24
static MallocProc* gColorPaletteMallocProc = colorPaletteMallocDefaultImpl;
@@ -61,7 +63,7 @@ static ReallocProc* gColorPaletteReallocProc = colorPaletteReallocDefaultImpl;
static FreeProc* gColorPaletteFreeProc = colorPaletteFreeDefaultImpl;
// 0x51DF30
static ColorFileNameManger* gColorFileNameMangler = NULL;
static ColorFileNameManger* gColorFileNameMangler = nullptr;
// 0x51DF34
unsigned char _cmap[768] = {
@@ -84,13 +86,13 @@ unsigned char* _blendTable[256];
unsigned char _mappedColor[256];
// 0x6738D0
unsigned char _colorMixAddTable[65536];
Color colorMixAddTable[256][256];
// 0x6838D0
unsigned char _intensityColorTable[65536];
Color intensityColorTable[256][256];
// 0x6938D0
unsigned char _colorMixMulTable[65536];
Color colorMixMulTable[256][256];
// 0x6A38D0
unsigned char _colorTable[32768];
@@ -112,7 +114,7 @@ static ColorPaletteFileOpenProc* gColorPaletteFileOpenProc;
// 0x4C7200
static int colorPaletteFileOpen(const char* filePath, int flags)
{
if (gColorPaletteFileOpenProc != NULL) {
if (gColorPaletteFileOpenProc != nullptr) {
return gColorPaletteFileOpenProc(filePath, flags);
}
@@ -124,7 +126,7 @@ static int colorPaletteFileOpen(const char* filePath, int flags)
// 0x4C7218
static int colorPaletteFileRead(int fd, void* buffer, size_t size)
{
if (gColorPaletteFileReadProc != NULL) {
if (gColorPaletteFileReadProc != nullptr) {
return gColorPaletteFileReadProc(fd, buffer, size);
}
@@ -136,7 +138,7 @@ static int colorPaletteFileRead(int fd, void* buffer, size_t size)
// 0x4C7230
static int colorPaletteFileClose(int fd)
{
if (gColorPaletteFileCloseProc != NULL) {
if (gColorPaletteFileCloseProc != nullptr) {
return gColorPaletteFileCloseProc(fd);
}
@@ -170,22 +172,19 @@ static void colorPaletteFreeDefaultImpl(void* ptr)
}
// 0x4C72B4
int _calculateColor(int a1, int a2)
int _calculateColor(int intensity, Color color)
{
int v1 = (a1 >> 9) + ((a2 & 0xFF) << 8);
return _intensityColorTable[v1];
return intensityColorTable[color][intensity / 512];
}
// 0x4C72E0
int _Color2RGB_(int a1)
int Color2RGB(Color c)
{
int v1, v2, v3;
int r = _cmap[3 * c] >> 1;
int g = _cmap[3 * c + 1] >> 1;
int b = _cmap[3 * c + 2] >> 1;
v1 = _cmap[3 * a1] >> 1;
v2 = _cmap[3 * a1 + 1] >> 1;
v3 = _cmap[3 * a1 + 2] >> 1;
return (((v1 << 5) | v2) << 5) | v3;
return (r << 10) | (g << 5) | b;
}
// Performs animated palette transition.
@@ -194,22 +193,29 @@ int _Color2RGB_(int a1)
void colorPaletteFadeBetween(unsigned char* oldPalette, unsigned char* newPalette, int steps)
{
for (int step = 0; step < steps; step++) {
sharedFpsLimiter.mark();
unsigned char palette[768];
for (int index = 0; index < 768; index++) {
palette[index] = oldPalette[index] - (oldPalette[index] - newPalette[index]) * step / steps;
}
if (gColorPaletteTransitionCallback != NULL) {
if (gColorPaletteTransitionCallback != nullptr) {
if (step % 128 == 0) {
gColorPaletteTransitionCallback();
}
}
_setSystemPalette(palette);
renderPresent();
sharedFpsLimiter.throttle();
}
sharedFpsLimiter.mark();
_setSystemPalette(newPalette);
renderPresent();
sharedFpsLimiter.throttle();
}
// 0x4C73D4
@@ -257,29 +263,28 @@ void _setSystemPaletteEntries(unsigned char* palette, int start, int end)
}
// 0x4C7550
static void _setIntensityTableColor(int a1)
static void _setIntensityTableColor(int cc)
{
int v1, v2, v3, v4, v5, v6, v7, v8, v9, v10;
v5 = 0;
v10 = a1 << 8;
int shift = 0;
for (int index = 0; index < 128; index++) {
v1 = (_Color2RGB_(a1) & 0x7C00) >> 10;
v2 = (_Color2RGB_(a1) & 0x3E0) >> 5;
v3 = (_Color2RGB_(a1) & 0x1F);
int r = (Color2RGB(cc) & 0x7C00) >> 10;
int g = (Color2RGB(cc) & 0x3E0) >> 5;
int b = (Color2RGB(cc) & 0x1F);
v4 = (((v1 * v5) >> 16) << 10) | (((v2 * v5) >> 16) << 5) | ((v3 * v5) >> 16);
_intensityColorTable[index + v10] = _colorTable[v4];
int darkerR = ((r * shift) >> 16);
int darkerG = ((g * shift) >> 16);
int darkerB = ((b * shift) >> 16);
int darkerColor = (darkerR << 10) | (darkerG << 5) | darkerB;
intensityColorTable[cc][index] = _colorTable[darkerColor];
v6 = v1 + (((0x1F - v1) * v5) >> 16);
v7 = v2 + (((0x1F - v2) * v5) >> 16);
v8 = v3 + (((0x1F - v3) * v5) >> 16);
int lighterR = r + (((0x1F - r) * shift) >> 16);
int lighterG = g + (((0x1F - g) * shift) >> 16);
int lighterB = b + (((0x1F - b) * shift) >> 16);
int lighterColor = (lighterR << 10) | (lighterG << 5) | lighterB;
intensityColorTable[cc][128 + index] = _colorTable[lighterColor];
v9 = (v6 << 10) | (v7 << 5) | v8;
_intensityColorTable[0x7F + index + 1 + v10] = _colorTable[v9];
v5 += 0x200;
shift += 512;
}
}
@@ -290,7 +295,7 @@ static void _setIntensityTables()
if (_mappedColor[index] != 0) {
_setIntensityTableColor(index);
} else {
memset(_intensityColorTable + index * 256, 0, 256);
memset(intensityColorTable[index], 0, 256);
}
}
}
@@ -299,20 +304,18 @@ static void _setIntensityTables()
static void _setMixTableColor(int a1)
{
int i;
int v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19;
int v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19;
int v20, v21, v22, v23, v24, v25, v26, v27, v28, v29;
v1 = a1 << 8;
for (i = 0; i < 256; i++) {
if (_mappedColor[a1] && _mappedColor[i]) {
v2 = (_Color2RGB_(a1) & 0x7C00) >> 10;
v3 = (_Color2RGB_(a1) & 0x3E0) >> 5;
v4 = (_Color2RGB_(a1) & 0x1F);
v2 = (Color2RGB(a1) & 0x7C00) >> 10;
v3 = (Color2RGB(a1) & 0x3E0) >> 5;
v4 = (Color2RGB(a1) & 0x1F);
v5 = (_Color2RGB_(i) & 0x7C00) >> 10;
v6 = (_Color2RGB_(i) & 0x3E0) >> 5;
v7 = (_Color2RGB_(i) & 0x1F);
v5 = (Color2RGB(i) & 0x7C00) >> 10;
v6 = (Color2RGB(i) & 0x3E0) >> 5;
v7 = (Color2RGB(i) & 0x1F);
v8 = v2 + v5;
v9 = v3 + v6;
@@ -357,29 +360,29 @@ static void _setMixTableColor(int a1)
v12 = _calculateColor(v19, v18);
}
_colorMixAddTable[v1 + i] = v12;
colorMixAddTable[a1][i] = v12;
v20 = (_Color2RGB_(a1) & 0x7C00) >> 10;
v21 = (_Color2RGB_(a1) & 0x3E0) >> 5;
v22 = (_Color2RGB_(a1) & 0x1F);
v20 = (Color2RGB(a1) & 0x7C00) >> 10;
v21 = (Color2RGB(a1) & 0x3E0) >> 5;
v22 = (Color2RGB(a1) & 0x1F);
v23 = (_Color2RGB_(i) & 0x7C00) >> 10;
v24 = (_Color2RGB_(i) & 0x3E0) >> 5;
v25 = (_Color2RGB_(i) & 0x1F);
v23 = (Color2RGB(i) & 0x7C00) >> 10;
v24 = (Color2RGB(i) & 0x3E0) >> 5;
v25 = (Color2RGB(i) & 0x1F);
v26 = (v20 * v23) >> 5;
v27 = (v21 * v24) >> 5;
v28 = (v22 * v25) >> 5;
v29 = (v26 << 10) | (v27 << 5) | v28;
_colorMixMulTable[v1 + i] = _colorTable[v29];
colorMixMulTable[a1][i] = _colorTable[v29];
} else {
if (_mappedColor[i]) {
_colorMixAddTable[v1 + i] = i;
_colorMixMulTable[v1 + i] = i;
colorMixAddTable[a1][i] = i;
colorMixMulTable[a1][i] = i;
} else {
_colorMixAddTable[v1 + i] = a1;
_colorMixMulTable[v1 + i] = a1;
colorMixAddTable[a1][i] = a1;
colorMixMulTable[a1][i] = a1;
}
}
}
@@ -388,7 +391,7 @@ static void _setMixTableColor(int a1)
// 0x4C78E4
bool colorPaletteLoad(const char* path)
{
if (gColorFileNameMangler != NULL) {
if (gColorFileNameMangler != nullptr) {
path = gColorFileNameMangler(path);
}
@@ -436,15 +439,15 @@ bool colorPaletteLoad(const char* path)
// NOTE: The value is "NEWC". Original code uses cmp opcode, not stricmp,
// or comparing characters one-by-one.
if (type == 0x4E455743) {
if (type == 'NEWC') {
// NOTE: Uninline.
colorPaletteFileRead(fd, _intensityColorTable, 0x10000);
colorPaletteFileRead(fd, intensityColorTable, sizeof(intensityColorTable));
// NOTE: Uninline.
colorPaletteFileRead(fd, _colorMixAddTable, 0x10000);
colorPaletteFileRead(fd, colorMixAddTable, sizeof(colorMixAddTable));
// NOTE: Uninline.
colorPaletteFileRead(fd, _colorMixMulTable, 0x10000);
colorPaletteFileRead(fd, colorMixMulTable, sizeof(colorMixMulTable));
} else {
_setIntensityTables();
@@ -477,9 +480,9 @@ static void _buildBlendTable(unsigned char* ptr, unsigned char ch)
beg = ptr;
r = (_Color2RGB_(ch) & 0x7C00) >> 10;
g = (_Color2RGB_(ch) & 0x3E0) >> 5;
b = (_Color2RGB_(ch) & 0x1F);
r = (Color2RGB(ch) & 0x7C00) >> 10;
g = (Color2RGB(ch) & 0x3E0) >> 5;
b = (Color2RGB(ch) & 0x1F);
for (i = 0; i < 256; i++) {
ptr[i] = i;
@@ -498,9 +501,9 @@ static void _buildBlendTable(unsigned char* ptr, unsigned char ch)
for (j = 0; j < 7; j++) {
for (i = 0; i < 256; i++) {
v12 = (_Color2RGB_(i) & 0x7C00) >> 10;
v14 = (_Color2RGB_(i) & 0x3E0) >> 5;
v16 = (_Color2RGB_(i) & 0x1F);
v12 = (Color2RGB(i) & 0x7C00) >> 10;
v14 = (Color2RGB(i) & 0x3E0) >> 5;
v16 = (Color2RGB(i) & 0x1F);
int index = 0;
index |= (r_2 + v12 * v31) / 7 << 10;
index |= (g_2 + v14 * v31) / 7 << 5;
@@ -544,7 +547,7 @@ unsigned char* _getColorBlendTable(int ch)
{
unsigned char* ptr;
if (_blendTable[ch] == NULL) {
if (_blendTable[ch] == nullptr) {
ptr = (unsigned char*)gColorPaletteMallocProc(4100);
*(int*)ptr = 1;
_blendTable[ch] = ptr + 4;
@@ -561,12 +564,12 @@ unsigned char* _getColorBlendTable(int ch)
void _freeColorBlendTable(int a1)
{
unsigned char* v2 = _blendTable[a1];
if (v2 != NULL) {
if (v2 != nullptr) {
int* count = (int*)(v2 - sizeof(int));
*count -= 1;
if (*count == 0) {
gColorPaletteFreeProc(count);
_blendTable[a1] = NULL;
_blendTable[a1] = nullptr;
}
}
}
@@ -633,7 +636,7 @@ bool colorPopColorPalette()
memcpy(_colorTable, entry->colorTable, sizeof(_colorTable));
free(entry);
gColorPaletteStack[gColorPaletteStackSize] = NULL;
gColorPaletteStack[gColorPaletteStackSize] = nullptr;
_setIntensityTables();
@@ -679,3 +682,5 @@ void _colorsClose()
gColorPaletteStackSize = 0;
}
} // namespace fallout

View File

@@ -3,6 +3,9 @@
#include "memory_defs.h"
namespace fallout {
typedef unsigned char Color;
typedef const char*(ColorFileNameManger)(const char*);
typedef void(ColorTransitionCallback)();
@@ -16,14 +19,14 @@ extern unsigned char _systemCmap[256 * 3];
extern unsigned char _currentGammaTable[64];
extern unsigned char* _blendTable[256];
extern unsigned char _mappedColor[256];
extern unsigned char _colorMixAddTable[65536];
extern unsigned char _intensityColorTable[65536];
extern unsigned char _colorMixMulTable[65536];
extern Color colorMixAddTable[256][256];
extern Color intensityColorTable[256][256];
extern Color colorMixMulTable[256][256];
extern unsigned char _colorTable[32768];
void colorPaletteSetFileIO(ColorPaletteFileOpenProc* openProc, ColorPaletteFileReadProc* readProc, ColorPaletteCloseProc* closeProc);
int _calculateColor(int a1, int a2);
int _Color2RGB_(int a1);
int _calculateColor(int intensity, Color color);
int Color2RGB(Color c);
void colorPaletteFadeBetween(unsigned char* oldPalette, unsigned char* newPalette, int steps);
void colorPaletteSetTransitionCallback(ColorTransitionCallback* callback);
void _setSystemPalette(unsigned char* palette);
@@ -40,4 +43,6 @@ bool colorPopColorPalette();
bool _initColors();
void _colorsClose();
} // namespace fallout
#endif /* COLOR_H */

File diff suppressed because it is too large Load Diff

View File

@@ -6,6 +6,8 @@
#include "obj_types.h"
#include "proto_types.h"
namespace fallout {
extern int _combatNumTurns;
extern unsigned int gCombatState;
@@ -17,8 +19,8 @@ void combatExit();
int _find_cid(int a1, int a2, Object** a3, int a4);
int combatLoad(File* stream);
int combatSave(File* stream);
bool _combat_safety_invalidate_weapon(Object* a1, Object* a2, int hitMode, Object* a4, int* a5);
bool _combatTestIncidentalHit(Object* a1, Object* a2, Object* a3, Object* a4);
bool _combat_safety_invalidate_weapon(Object* attacker, Object* weapon, int hitMode, Object* defender, int* safeDistancePtr);
bool _combatTestIncidentalHit(Object* attacker, Object* defender, Object* attackerFriend, Object* weapon);
Object* _combat_whose_turn();
void _combat_data_init(Object* obj);
Object* aiInfoGetFriendlyDead(Object* obj);
@@ -31,14 +33,14 @@ void _combat_update_critter_outline_for_los(Object* critter, bool a2);
void _combat_over_from_load();
void _combat_give_exps(int exp_points);
void _combat_turn_run();
void _combat(STRUCT_664980* attack);
void attackInit(Attack* attack, Object* a2, Object* a3, int a4, int a5);
int _combat_attack(Object* a1, Object* a2, int a3, int a4);
int _combat_bullet_start(const Object* a1, const Object* a2);
void _compute_explosion_on_extras(Attack* attack, int a2, bool isGrenade, int a4);
void _combat(CombatStartData* csd);
void attackInit(Attack* attack, Object* attacker, Object* defender, int hitMode, int hitLocation);
int _combat_attack(Object* attacker, Object* defender, int hitMode, int hitLocation);
int _combat_bullet_start(const Object* attacker, const Object* target);
void _compute_explosion_on_extras(Attack* attack, bool isFromAttacker, bool isGrenade, bool noDamage);
int _determine_to_hit(Object* a1, Object* a2, int hitLocation, int hitMode);
int _determine_to_hit_no_range(Object* a1, Object* a2, int a3, int a4, unsigned char* a5);
int _determine_to_hit_from_tile(Object* a1, int a2, Object* a3, int a4, int a5);
int _determine_to_hit_no_range(Object* attacker, Object* defender, int hitLocation, int hitMode, unsigned char* a5);
int _determine_to_hit_from_tile(Object* attacker, int tile, Object* defender, int hitLocation, int hitMode);
void attackComputeDeathFlags(Attack* attack);
void _apply_damage(Attack* attack, bool animated);
void _combat_display(Attack* attack);
@@ -46,16 +48,17 @@ void _combat_anim_begin();
void _combat_anim_finished();
int _combat_check_bad_shot(Object* attacker, Object* defender, int hitMode, bool aiming);
bool _combat_to_hit(Object* target, int* accuracy);
void _combat_attack_this(Object* a1);
void _combat_attack_this(Object* target);
void _combat_outline_on();
void _combat_outline_off();
void _combat_highlight_change();
bool _combat_is_shot_blocked(Object* a1, int from, int to, Object* a4, int* a5);
bool _combat_is_shot_blocked(Object* sourceObj, int from, int to, Object* targetObj, int* numCrittersOnLof);
int _combat_player_knocked_out_by();
int _combat_explode_scenery(Object* a1, Object* a2);
void _combat_delete_critter(Object* obj);
void _combatKillCritterOutsideCombat(Object* critter_obj, char* msg);
int combatGetTargetHighlight();
int criticalsGetValue(int killType, int hitLocation, int effect, int dataMember);
void criticalsSetValue(int killType, int hitLocation, int effect, int dataMember, int value);
void criticalsResetValue(int killType, int hitLocation, int effect, int dataMember);
@@ -68,6 +71,10 @@ int unarmedGetKickHitMode(bool isSecondary);
bool unarmedIsPenetrating(int hitMode);
bool damageModGetBonusHthDamageFix();
bool damageModGetDisplayBonusDamage();
int combat_get_hit_location_penalty(int hit_location);
void combat_set_hit_location_penalty(int hit_location, int penalty);
void combat_reset_hit_location_penalty();
Attack* combat_get_data();
static inline bool isInCombat()
{
@@ -81,4 +88,6 @@ static inline bool isUnarmedHitMode(int hitMode)
|| (hitMode >= FIRST_ADVANCED_UNARMED_HIT_MODE && hitMode <= LAST_ADVANCED_UNARMED_HIT_MODE);
}
} // namespace fallout
#endif /* COMBAT_H */

File diff suppressed because it is too large Load Diff

View File

@@ -6,6 +6,8 @@
#include "db.h"
#include "obj_types.h"
namespace fallout {
typedef enum AiMessageType {
AI_MESSAGE_TYPE_RUN,
AI_MESSAGE_TYPE_MOVE,
@@ -28,6 +30,8 @@ void aiReset();
int aiExit();
int aiLoad(File* stream);
int aiSave(File* stream);
int combat_ai_num();
char* combat_ai_name(int packet_num);
int aiGetAreaAttackMode(Object* obj);
int aiGetRunAwayMode(Object* obj);
int aiGetBestWeapon(Object* obj);
@@ -42,10 +46,10 @@ int aiSetAttackWho(Object* critter, int attackWho);
int aiSetChemUse(Object* critter, int chemUse);
int aiGetDisposition(Object* obj);
int aiSetDisposition(Object* obj, int a2);
int _caiSetupTeamCombat(Object* a1, Object* a2);
int _caiTeamCombatInit(Object** a1, int a2);
int _caiSetupTeamCombat(Object* attackerTeam, Object* defenderTeam);
int _caiTeamCombatInit(Object** crittersList, int crittersListLength);
void _caiTeamCombatExit();
Object* _ai_search_inven_weap(Object* critter, int a2, Object* a3);
Object* _ai_search_inven_weap(Object* critter, bool checkRequiredActionPoints, Object* defender);
Object* _ai_search_inven_armor(Object* critter);
int _cAIPrepWeaponItem(Object* critter, Object* item);
void aiAttemptWeaponReload(Object* critter, int animate);
@@ -57,13 +61,15 @@ bool _combatai_want_to_join(Object* a1);
bool _combatai_want_to_stop(Object* a1);
int critterSetTeam(Object* obj, int team);
int critterSetAiPacket(Object* object, int aiPacket);
int _combatai_msg(Object* a1, Attack* attack, int a3, int a4);
int _combatai_msg(Object* critter, Attack* attack, int type, int delay);
Object* _combat_ai_random_target(Attack* attack);
int _combatai_check_retaliation(Object* a1, Object* a2);
bool objectCanHearObject(Object* a1, Object* a2);
void _combatai_check_retaliation(Object* a1, Object* a2);
bool isWithinPerception(Object* a1, Object* a2);
void aiMessageListReloadIfNeeded();
void _combatai_notify_onlookers(Object* a1);
void _combatai_notify_friends(Object* a1);
void _combatai_delete_critter(Object* obj);
} // namespace fallout
#endif /* COMBAT_AI_H */

View File

@@ -1,6 +1,8 @@
#ifndef COMBAT_AI_DEFS_H
#define COMBAT_AI_DEFS_H
namespace fallout {
typedef enum AreaAttackMode {
AREA_ATTACK_MODE_ALWAYS,
AREA_ATTACK_MODE_SOMETIMES,
@@ -79,4 +81,6 @@ typedef enum HurtTooMuch {
HURT_COUNT,
} HurtTooMuch;
} // namespace fallout
#endif /* COMBAT_AI_DEFS_H */

View File

@@ -10,6 +10,8 @@
#define WEAPON_CRITICAL_FAILURE_TYPE_COUNT (7)
#define WEAPON_CRITICAL_FAILURE_EFFECT_COUNT (5)
namespace fallout {
typedef enum CombatState {
COMBAT_STATE_0x01 = 0x01,
COMBAT_STATE_0x02 = 0x02,
@@ -84,7 +86,7 @@ typedef enum HitLocation {
HIT_LOCATION_SPECIFIC_COUNT = HIT_LOCATION_COUNT - 1,
} HitLocation;
typedef struct STRUCT_664980 {
typedef struct CombatStartData {
Object* attacker;
Object* defender;
int actionPointsBonus;
@@ -92,10 +94,10 @@ typedef struct STRUCT_664980 {
int damageBonus;
int minDamage;
int maxDamage;
int field_1C; // probably bool, indicating field_20 and field_24 used
int field_20; // flags on attacker
int field_24; // flags on defender
} STRUCT_664980;
int overrideAttackResults;
int attackerResults;
int targetResults;
} CombatStartData;
typedef struct Attack {
Object* attacker;
@@ -169,4 +171,6 @@ typedef enum CombatBadShot {
COMBAT_BAD_SHOT_BOTH_ARMS_CRIPPLED = 7,
} CombatBadShot;
} // namespace fallout
#endif /* COMBAT_DEFS_H */

View File

@@ -11,6 +11,8 @@
#include "memory.h"
#include "platform_compat.h"
namespace fallout {
#define CONFIG_FILE_MAX_LINE_LENGTH (256)
// The initial number of sections (or key-value) pairs in the config.
@@ -29,11 +31,11 @@ static char gConfigLastSectionKey[CONFIG_FILE_MAX_LINE_LENGTH] = "unknown";
// 0x42BD90
bool configInit(Config* config)
{
if (config == NULL) {
if (config == nullptr) {
return false;
}
if (dictionaryInit(config, CONFIG_INITIAL_CAPACITY, sizeof(ConfigSection), NULL) != 0) {
if (dictionaryInit(config, CONFIG_INITIAL_CAPACITY, sizeof(ConfigSection), nullptr) != 0) {
return false;
}
@@ -43,7 +45,7 @@ bool configInit(Config* config)
// 0x42BDBC
void configFree(Config* config)
{
if (config == NULL) {
if (config == nullptr) {
return;
}
@@ -56,7 +58,7 @@ void configFree(Config* config)
char** value = (char**)keyValueEntry->value;
internal_free(*value);
*value = NULL;
*value = nullptr;
}
dictionaryFree(section);
@@ -76,7 +78,7 @@ void configFree(Config* config)
// 0x42BE38
bool configParseCommandLineArguments(Config* config, int argc, char** argv)
{
if (config == NULL) {
if (config == nullptr) {
return false;
}
@@ -86,7 +88,7 @@ bool configParseCommandLineArguments(Config* config, int argc, char** argv)
// Find opening bracket.
pch = strchr(string, '[');
if (pch == NULL) {
if (pch == nullptr) {
continue;
}
@@ -94,7 +96,7 @@ bool configParseCommandLineArguments(Config* config, int argc, char** argv)
// Find closing bracket.
pch = strchr(sectionKey, ']');
if (pch == NULL) {
if (pch == nullptr) {
continue;
}
@@ -118,7 +120,7 @@ bool configParseCommandLineArguments(Config* config, int argc, char** argv)
// 0x42BF48
bool configGetString(Config* config, const char* sectionKey, const char* key, char** valuePtr)
{
if (config == NULL || sectionKey == NULL || key == NULL || valuePtr == NULL) {
if (config == nullptr || sectionKey == nullptr || key == nullptr || valuePtr == nullptr) {
return false;
}
@@ -144,7 +146,7 @@ bool configGetString(Config* config, const char* sectionKey, const char* key, ch
// 0x42BF90
bool configSetString(Config* config, const char* sectionKey, const char* key, const char* value)
{
if (config == NULL || sectionKey == NULL || key == NULL || value == NULL) {
if (config == nullptr || sectionKey == nullptr || key == nullptr || value == nullptr) {
return false;
}
@@ -165,13 +167,13 @@ bool configSetString(Config* config, const char* sectionKey, const char* key, co
char** existingValue = (char**)keyValueEntry->value;
internal_free(*existingValue);
*existingValue = NULL;
*existingValue = nullptr;
dictionaryRemoveValue(section, key);
}
char* valueCopy = internal_strdup(value);
if (valueCopy == NULL) {
if (valueCopy == nullptr) {
return false;
}
@@ -186,7 +188,7 @@ bool configSetString(Config* config, const char* sectionKey, const char* key, co
// 0x42C05C
bool configGetInt(Config* config, const char* sectionKey, const char* key, int* valuePtr, unsigned char base /* = 0 */)
{
if (valuePtr == NULL) {
if (valuePtr == nullptr) {
return false;
}
@@ -218,7 +220,7 @@ bool configGetInt(Config* config, const char* sectionKey, const char* key, int*
// 0x42C090
bool configGetIntList(Config* config, const char* sectionKey, const char* key, int* arr, int count)
{
if (arr == NULL || count < 2) {
if (arr == nullptr || count < 2) {
return false;
}
@@ -232,7 +234,7 @@ bool configGetIntList(Config* config, const char* sectionKey, const char* key, i
while (1) {
char* pch = strchr(string, ',');
if (pch == NULL) {
if (pch == nullptr) {
break;
}
@@ -246,12 +248,14 @@ bool configGetIntList(Config* config, const char* sectionKey, const char* key, i
string = pch + 1;
}
if (count <= 1) {
// SFALL: Fix getting last item in a list if the list has less than the
// requested number of values (for `chem_primary_desire`).
if (count > 0) {
*arr = atoi(string);
return true;
count--;
}
return false;
return count == 0;
}
// 0x42C160
@@ -268,7 +272,7 @@ bool configSetInt(Config* config, const char* sectionKey, const char* key, int v
// 0x42C280
bool configRead(Config* config, const char* filePath, bool isDb)
{
if (config == NULL || filePath == NULL) {
if (config == nullptr || filePath == nullptr) {
return false;
}
@@ -276,24 +280,28 @@ bool configRead(Config* config, const char* filePath, bool isDb)
if (isDb) {
File* stream = fileOpen(filePath, "rb");
if (stream != NULL) {
while (fileReadString(string, sizeof(string), stream) != NULL) {
configParseLine(config, string);
}
fileClose(stream);
// CE: Return `false` if file does not exists in database.
if (stream == nullptr) {
return false;
}
while (fileReadString(string, sizeof(string), stream) != nullptr) {
configParseLine(config, string);
}
fileClose(stream);
} else {
FILE* stream = compat_fopen(filePath, "rt");
if (stream != NULL) {
while (fgets(string, sizeof(string), stream) != NULL) {
configParseLine(config, string);
}
fclose(stream);
// CE: Return `false` if file does not exists on the file system.
if (stream == nullptr) {
return false;
}
// FIXME: This function returns `true` even if the file was not actually
// read. I'm pretty sure it's bug.
while (compat_fgets(string, sizeof(string), stream) != nullptr) {
configParseLine(config, string);
}
fclose(stream);
}
return true;
@@ -304,13 +312,13 @@ bool configRead(Config* config, const char* filePath, bool isDb)
// 0x42C324
bool configWrite(Config* config, const char* filePath, bool isDb)
{
if (config == NULL || filePath == NULL) {
if (config == nullptr || filePath == nullptr) {
return false;
}
if (isDb) {
File* stream = fileOpen(filePath, "wt");
if (stream == NULL) {
if (stream == nullptr) {
return false;
}
@@ -330,7 +338,7 @@ bool configWrite(Config* config, const char* filePath, bool isDb)
fileClose(stream);
} else {
FILE* stream = compat_fopen(filePath, "wt");
if (stream == NULL) {
if (stream == nullptr) {
return false;
}
@@ -373,18 +381,33 @@ static bool configParseLine(Config* config, char* string)
// Find comment marker and truncate the string.
pch = strchr(string, ';');
if (pch != NULL) {
if (pch != nullptr) {
*pch = '\0';
}
// Find opening bracket.
pch = strchr(string, '[');
if (pch != NULL) {
char* sectionKey = pch + 1;
// CE: Original implementation treats any line with brackets as section key.
// The problem can be seen when loading Olympus settings (ddraw.ini), which
// contains the following line:
//
// ```ini
// VersionString=Olympus 2207 [Complete].
// ```
//
// It thinks that [Complete] is a start of new section, and puts remaining
// keys there.
// Skip leading whitespace.
while (isspace(static_cast<unsigned char>(*string))) {
string++;
}
// Check if it's a section key.
if (*string == '[') {
char* sectionKey = string + 1;
// Find closing bracket.
pch = strchr(sectionKey, ']');
if (pch != NULL) {
if (pch != nullptr) {
*pch = '\0';
strcpy(gConfigLastSectionKey, sectionKey);
return configTrimString(gConfigLastSectionKey);
@@ -408,13 +431,13 @@ static bool configParseLine(Config* config, char* string)
// 0x42C594
static bool configParseKeyValue(char* string, char* key, char* value)
{
if (string == NULL || key == NULL || value == NULL) {
if (string == nullptr || key == nullptr || value == nullptr) {
return false;
}
// Find equals character.
char* pch = strchr(string, '=');
if (pch == NULL) {
if (pch == nullptr) {
return false;
}
@@ -439,7 +462,7 @@ static bool configParseKeyValue(char* string, char* key, char* value)
// 0x42C638
static bool configEnsureSectionExists(Config* config, const char* sectionKey)
{
if (config == NULL || sectionKey == NULL) {
if (config == nullptr || sectionKey == nullptr) {
return false;
}
@@ -449,7 +472,7 @@ static bool configEnsureSectionExists(Config* config, const char* sectionKey)
}
ConfigSection section;
if (dictionaryInit(&section, CONFIG_INITIAL_CAPACITY, sizeof(char**), NULL) == -1) {
if (dictionaryInit(&section, CONFIG_INITIAL_CAPACITY, sizeof(char**), nullptr) == -1) {
return false;
}
@@ -465,11 +488,11 @@ static bool configEnsureSectionExists(Config* config, const char* sectionKey)
// 0x42C698
static bool configTrimString(char* string)
{
if (string == NULL) {
if (string == nullptr) {
return false;
}
int length = strlen(string);
size_t length = strlen(string);
if (length == 0) {
return true;
}
@@ -477,7 +500,7 @@ static bool configTrimString(char* string)
// Starting from the end of the string, loop while it's a whitespace and
// decrement string length.
char* pch = string + length - 1;
while (length != 0 && isspace(*pch)) {
while (length != 0 && isspace(static_cast<unsigned char>(*pch))) {
length--;
pch--;
}
@@ -488,7 +511,7 @@ static bool configTrimString(char* string)
// Starting from the beginning of the string loop while it's a whitespace
// and decrement string length.
pch = string;
while (isspace(*pch)) {
while (isspace(static_cast<unsigned char>(*pch))) {
pch++;
length--;
}
@@ -502,7 +525,7 @@ static bool configTrimString(char* string)
// 0x42C718
bool configGetDouble(Config* config, const char* sectionKey, const char* key, double* valuePtr)
{
if (valuePtr == NULL) {
if (valuePtr == nullptr) {
return false;
}
@@ -511,7 +534,7 @@ bool configGetDouble(Config* config, const char* sectionKey, const char* key, do
return false;
}
*valuePtr = strtod(stringValue, NULL);
*valuePtr = strtod(stringValue, nullptr);
return true;
}
@@ -520,7 +543,7 @@ bool configGetDouble(Config* config, const char* sectionKey, const char* key, do
bool configSetDouble(Config* config, const char* sectionKey, const char* key, double value)
{
char stringValue[32];
sprintf(stringValue, "%.6f", value);
snprintf(stringValue, sizeof(stringValue), "%.6f", value);
return configSetString(config, sectionKey, key, stringValue);
}
@@ -528,7 +551,7 @@ bool configSetDouble(Config* config, const char* sectionKey, const char* key, do
// NOTE: Boolean-typed variant of [configGetInt].
bool configGetBool(Config* config, const char* sectionKey, const char* key, bool* valuePtr)
{
if (valuePtr == NULL) {
if (valuePtr == nullptr) {
return false;
}
@@ -547,3 +570,5 @@ bool configSetBool(Config* config, const char* sectionKey, const char* key, bool
{
return configSetInt(config, sectionKey, key, value ? 1 : 0);
}
} // namespace fallout

View File

@@ -3,6 +3,8 @@
#include "dictionary.h"
namespace fallout {
// A representation of .INI file.
//
// It's implemented as a [Dictionary] whos keys are section names of .INI file,
@@ -31,4 +33,6 @@ bool configSetDouble(Config* config, const char* sectionKey, const char* key, do
bool configGetBool(Config* config, const char* sectionKey, const char* key, bool* valuePtr);
bool configSetBool(Config* config, const char* sectionKey, const char* key, bool value);
} // namespace fallout
#endif /* CONFIG_H */

View File

@@ -1,699 +0,0 @@
#ifndef CORE_H
#define CORE_H
#include <SDL.h>
#include "db.h"
#include "dinput.h"
#include "geometry.h"
#include "window.h"
#define MOUSE_DEFAULT_CURSOR_WIDTH 8
#define MOUSE_DEFAULT_CURSOR_HEIGHT 8
#define MOUSE_DEFAULT_CURSOR_SIZE (MOUSE_DEFAULT_CURSOR_WIDTH * MOUSE_DEFAULT_CURSOR_HEIGHT)
#define MOUSE_STATE_LEFT_BUTTON_DOWN 0x01
#define MOUSE_STATE_RIGHT_BUTTON_DOWN 0x02
#define MOUSE_EVENT_LEFT_BUTTON_DOWN 0x01
#define MOUSE_EVENT_RIGHT_BUTTON_DOWN 0x02
#define MOUSE_EVENT_LEFT_BUTTON_REPEAT 0x04
#define MOUSE_EVENT_RIGHT_BUTTON_REPEAT 0x08
#define MOUSE_EVENT_LEFT_BUTTON_UP 0x10
#define MOUSE_EVENT_RIGHT_BUTTON_UP 0x20
#define MOUSE_EVENT_ANY_BUTTON_DOWN (MOUSE_EVENT_LEFT_BUTTON_DOWN | MOUSE_EVENT_RIGHT_BUTTON_DOWN)
#define MOUSE_EVENT_ANY_BUTTON_REPEAT (MOUSE_EVENT_LEFT_BUTTON_REPEAT | MOUSE_EVENT_RIGHT_BUTTON_REPEAT)
#define MOUSE_EVENT_ANY_BUTTON_UP (MOUSE_EVENT_LEFT_BUTTON_UP | MOUSE_EVENT_RIGHT_BUTTON_UP)
#define MOUSE_EVENT_LEFT_BUTTON_DOWN_REPEAT (MOUSE_EVENT_LEFT_BUTTON_DOWN | MOUSE_EVENT_LEFT_BUTTON_REPEAT)
#define MOUSE_EVENT_RIGHT_BUTTON_DOWN_REPEAT (MOUSE_EVENT_RIGHT_BUTTON_DOWN | MOUSE_EVENT_RIGHT_BUTTON_REPEAT)
#define MOUSE_EVENT_WHEEL 0x40
#define BUTTON_REPEAT_TIME 250
#define KEY_STATE_UP 0
#define KEY_STATE_DOWN 1
#define KEY_STATE_REPEAT 2
#define MODIFIER_KEY_STATE_NUM_LOCK 0x01
#define MODIFIER_KEY_STATE_CAPS_LOCK 0x02
#define MODIFIER_KEY_STATE_SCROLL_LOCK 0x04
#define KEYBOARD_EVENT_MODIFIER_CAPS_LOCK 0x0001
#define KEYBOARD_EVENT_MODIFIER_NUM_LOCK 0x0002
#define KEYBOARD_EVENT_MODIFIER_SCROLL_LOCK 0x0004
#define KEYBOARD_EVENT_MODIFIER_LEFT_SHIFT 0x0008
#define KEYBOARD_EVENT_MODIFIER_RIGHT_SHIFT 0x0010
#define KEYBOARD_EVENT_MODIFIER_LEFT_ALT 0x0020
#define KEYBOARD_EVENT_MODIFIER_RIGHT_ALT 0x0040
#define KEYBOARD_EVENT_MODIFIER_LEFT_CONTROL 0x0080
#define KEYBOARD_EVENT_MODIFIER_RIGHT_CONTROL 0x0100
#define KEYBOARD_EVENT_MODIFIER_ANY_SHIFT (KEYBOARD_EVENT_MODIFIER_LEFT_SHIFT | KEYBOARD_EVENT_MODIFIER_RIGHT_SHIFT)
#define KEYBOARD_EVENT_MODIFIER_ANY_ALT (KEYBOARD_EVENT_MODIFIER_LEFT_ALT | KEYBOARD_EVENT_MODIFIER_RIGHT_ALT)
#define KEYBOARD_EVENT_MODIFIER_ANY_CONTROL (KEYBOARD_EVENT_MODIFIER_LEFT_CONTROL | KEYBOARD_EVENT_MODIFIER_RIGHT_CONTROL)
#define KEY_QUEUE_SIZE 64
typedef enum Key {
KEY_ESCAPE = '\x1b',
KEY_TAB = '\x09',
KEY_BACKSPACE = '\x08',
KEY_RETURN = '\r',
KEY_SPACE = ' ',
KEY_EXCLAMATION = '!',
KEY_QUOTE = '"',
KEY_NUMBER_SIGN = '#',
KEY_DOLLAR = '$',
KEY_PERCENT = '%',
KEY_AMPERSAND = '&',
KEY_SINGLE_QUOTE = '\'',
KEY_PAREN_LEFT = '(',
KEY_PAREN_RIGHT = ')',
KEY_ASTERISK = '*',
KEY_PLUS = '+',
KEY_COMMA = ',',
KEY_MINUS = '-',
KEY_DOT = '.',
KEY_SLASH = '/',
KEY_0 = '0',
KEY_1 = '1',
KEY_2 = '2',
KEY_3 = '3',
KEY_4 = '4',
KEY_5 = '5',
KEY_6 = '6',
KEY_7 = '7',
KEY_8 = '8',
KEY_9 = '9',
KEY_COLON = ':',
KEY_SEMICOLON = ';',
KEY_LESS = '<',
KEY_EQUAL = '=',
KEY_GREATER = '>',
KEY_QUESTION = '?',
KEY_AT = '@',
KEY_UPPERCASE_A = 'A',
KEY_UPPERCASE_B = 'B',
KEY_UPPERCASE_C = 'C',
KEY_UPPERCASE_D = 'D',
KEY_UPPERCASE_E = 'E',
KEY_UPPERCASE_F = 'F',
KEY_UPPERCASE_G = 'G',
KEY_UPPERCASE_H = 'H',
KEY_UPPERCASE_I = 'I',
KEY_UPPERCASE_J = 'J',
KEY_UPPERCASE_K = 'K',
KEY_UPPERCASE_L = 'L',
KEY_UPPERCASE_M = 'M',
KEY_UPPERCASE_N = 'N',
KEY_UPPERCASE_O = 'O',
KEY_UPPERCASE_P = 'P',
KEY_UPPERCASE_Q = 'Q',
KEY_UPPERCASE_R = 'R',
KEY_UPPERCASE_S = 'S',
KEY_UPPERCASE_T = 'T',
KEY_UPPERCASE_U = 'U',
KEY_UPPERCASE_V = 'V',
KEY_UPPERCASE_W = 'W',
KEY_UPPERCASE_X = 'X',
KEY_UPPERCASE_Y = 'Y',
KEY_UPPERCASE_Z = 'Z',
KEY_BRACKET_LEFT = '[',
KEY_BACKSLASH = '\\',
KEY_BRACKET_RIGHT = ']',
KEY_CARET = '^',
KEY_UNDERSCORE = '_',
KEY_GRAVE = '`',
KEY_LOWERCASE_A = 'a',
KEY_LOWERCASE_B = 'b',
KEY_LOWERCASE_C = 'c',
KEY_LOWERCASE_D = 'd',
KEY_LOWERCASE_E = 'e',
KEY_LOWERCASE_F = 'f',
KEY_LOWERCASE_G = 'g',
KEY_LOWERCASE_H = 'h',
KEY_LOWERCASE_I = 'i',
KEY_LOWERCASE_J = 'j',
KEY_LOWERCASE_K = 'k',
KEY_LOWERCASE_L = 'l',
KEY_LOWERCASE_M = 'm',
KEY_LOWERCASE_N = 'n',
KEY_LOWERCASE_O = 'o',
KEY_LOWERCASE_P = 'p',
KEY_LOWERCASE_Q = 'q',
KEY_LOWERCASE_R = 'r',
KEY_LOWERCASE_S = 's',
KEY_LOWERCASE_T = 't',
KEY_LOWERCASE_U = 'u',
KEY_LOWERCASE_V = 'v',
KEY_LOWERCASE_W = 'w',
KEY_LOWERCASE_X = 'x',
KEY_LOWERCASE_Y = 'y',
KEY_LOWERCASE_Z = 'z',
KEY_BRACE_LEFT = '{',
KEY_BAR = '|',
KEY_BRACE_RIGHT = '}',
KEY_TILDE = '~',
KEY_DEL = 127,
KEY_136 = 136,
KEY_146 = 146,
KEY_149 = 149,
KEY_150 = 150,
KEY_151 = 151,
KEY_152 = 152,
KEY_161 = 161,
KEY_163 = 163,
KEY_164 = 164,
KEY_166 = 166,
KEY_168 = 168,
KEY_167 = 167,
KEY_170 = 170,
KEY_172 = 172,
KEY_176 = 176,
KEY_178 = 178,
KEY_179 = 179,
KEY_180 = 180,
KEY_181 = 181,
KEY_186 = 186,
KEY_191 = 191,
KEY_196 = 196,
KEY_199 = 199,
KEY_209 = 209,
KEY_214 = 214,
KEY_215 = 215,
KEY_220 = 220,
KEY_223 = 223,
KEY_224 = 224,
KEY_228 = 228,
KEY_231 = 231,
KEY_232 = 232,
KEY_233 = 233,
KEY_241 = 241,
KEY_246 = 246,
KEY_247 = 247,
KEY_249 = 249,
KEY_252 = 252,
KEY_ALT_Q = 272,
KEY_ALT_W = 273,
KEY_ALT_E = 274,
KEY_ALT_R = 275,
KEY_ALT_T = 276,
KEY_ALT_Y = 277,
KEY_ALT_U = 278,
KEY_ALT_I = 279,
KEY_ALT_O = 280,
KEY_ALT_P = 281,
KEY_ALT_A = 286,
KEY_ALT_S = 287,
KEY_ALT_D = 288,
KEY_ALT_F = 289,
KEY_ALT_G = 290,
KEY_ALT_H = 291,
KEY_ALT_J = 292,
KEY_ALT_K = 293,
KEY_ALT_L = 294,
KEY_ALT_Z = 300,
KEY_ALT_X = 301,
KEY_ALT_C = 302,
KEY_ALT_V = 303,
KEY_ALT_B = 304,
KEY_ALT_N = 305,
KEY_ALT_M = 306,
KEY_CTRL_Q = 17,
KEY_CTRL_W = 23,
KEY_CTRL_E = 5,
KEY_CTRL_R = 18,
KEY_CTRL_T = 20,
KEY_CTRL_Y = 25,
KEY_CTRL_U = 21,
KEY_CTRL_I = 9,
KEY_CTRL_O = 15,
KEY_CTRL_P = 16,
KEY_CTRL_A = 1,
KEY_CTRL_S = 19,
KEY_CTRL_D = 4,
KEY_CTRL_F = 6,
KEY_CTRL_G = 7,
KEY_CTRL_H = 8,
KEY_CTRL_J = 10,
KEY_CTRL_K = 11,
KEY_CTRL_L = 12,
KEY_CTRL_Z = 26,
KEY_CTRL_X = 24,
KEY_CTRL_C = 3,
KEY_CTRL_V = 22,
KEY_CTRL_B = 2,
KEY_CTRL_N = 14,
KEY_CTRL_M = 13,
KEY_F1 = 315,
KEY_F2 = 316,
KEY_F3 = 317,
KEY_F4 = 318,
KEY_F5 = 319,
KEY_F6 = 320,
KEY_F7 = 321,
KEY_F8 = 322,
KEY_F9 = 323,
KEY_F10 = 324,
KEY_F11 = 389,
KEY_F12 = 390,
KEY_SHIFT_F1 = 340,
KEY_SHIFT_F2 = 341,
KEY_SHIFT_F3 = 342,
KEY_SHIFT_F4 = 343,
KEY_SHIFT_F5 = 344,
KEY_SHIFT_F6 = 345,
KEY_SHIFT_F7 = 346,
KEY_SHIFT_F8 = 347,
KEY_SHIFT_F9 = 348,
KEY_SHIFT_F10 = 349,
KEY_SHIFT_F11 = 391,
KEY_SHIFT_F12 = 392,
KEY_CTRL_F1 = 350,
KEY_CTRL_F2 = 351,
KEY_CTRL_F3 = 352,
KEY_CTRL_F4 = 353,
KEY_CTRL_F5 = 354,
KEY_CTRL_F6 = 355,
KEY_CTRL_F7 = 356,
KEY_CTRL_F8 = 357,
KEY_CTRL_F9 = 358,
KEY_CTRL_F10 = 359,
KEY_CTRL_F11 = 393,
KEY_CTRL_F12 = 394,
KEY_ALT_F1 = 360,
KEY_ALT_F2 = 361,
KEY_ALT_F3 = 362,
KEY_ALT_F4 = 363,
KEY_ALT_F5 = 364,
KEY_ALT_F6 = 365,
KEY_ALT_F7 = 366,
KEY_ALT_F8 = 367,
KEY_ALT_F9 = 368,
KEY_ALT_F10 = 369,
KEY_ALT_F11 = 395,
KEY_ALT_F12 = 396,
KEY_HOME = 327,
KEY_CTRL_HOME = 375,
KEY_ALT_HOME = 407,
KEY_PAGE_UP = 329,
KEY_CTRL_PAGE_UP = 388,
KEY_ALT_PAGE_UP = 409,
KEY_INSERT = 338,
KEY_CTRL_INSERT = 402,
KEY_ALT_INSERT = 418,
KEY_DELETE = 339,
KEY_CTRL_DELETE = 403,
KEY_ALT_DELETE = 419,
KEY_END = 335,
KEY_CTRL_END = 373,
KEY_ALT_END = 415,
KEY_PAGE_DOWN = 337,
KEY_ALT_PAGE_DOWN = 417,
KEY_CTRL_PAGE_DOWN = 374,
KEY_ARROW_UP = 328,
KEY_CTRL_ARROW_UP = 397,
KEY_ALT_ARROW_UP = 408,
KEY_ARROW_DOWN = 336,
KEY_CTRL_ARROW_DOWN = 401,
KEY_ALT_ARROW_DOWN = 416,
KEY_ARROW_LEFT = 331,
KEY_CTRL_ARROW_LEFT = 371,
KEY_ALT_ARROW_LEFT = 411,
KEY_ARROW_RIGHT = 333,
KEY_CTRL_ARROW_RIGHT = 372,
KEY_ALT_ARROW_RIGHT = 413,
KEY_CTRL_BACKSLASH = 192,
KEY_NUMBERPAD_5 = 332,
KEY_CTRL_NUMBERPAD_5 = 399,
KEY_ALT_NUMBERPAD_5 = 9999,
KEY_FIRST_INPUT_CHARACTER = KEY_SPACE,
KEY_LAST_INPUT_CHARACTER = KEY_LOWERCASE_Z,
} Key;
typedef enum KeyboardLayout {
KEYBOARD_LAYOUT_QWERTY,
KEYBOARD_LAYOUT_FRENCH,
KEYBOARD_LAYOUT_GERMAN,
KEYBOARD_LAYOUT_ITALIAN,
KEYBOARD_LAYOUT_SPANISH,
} KeyboardLayout;
#define VCR_BUFFER_CAPACITY 4096
typedef enum VcrState {
VCR_STATE_RECORDING,
VCR_STATE_PLAYING,
VCR_STATE_TURNED_OFF,
} VcrState;
#define VCR_STATE_STOP_REQUESTED 0x80000000
typedef enum VcrTerminationFlags {
// Specifies that VCR playback should stop if any key is pressed.
VCR_TERMINATE_ON_KEY_PRESS = 0x01,
// Specifies that VCR playback should stop if mouse is mouved.
VCR_TERMINATE_ON_MOUSE_MOVE = 0x02,
// Specifies that VCR playback should stop if any mouse button is pressed.
VCR_TERMINATE_ON_MOUSE_PRESS = 0x04,
} VcrTerminationFlags;
typedef enum VcrPlaybackCompletionReason {
VCR_PLAYBACK_COMPLETION_REASON_NONE = 0,
// Indicates that VCR playback completed normally.
VCR_PLAYBACK_COMPLETION_REASON_COMPLETED = 1,
// Indicates that VCR playback terminated according to termination flags.
VCR_PLAYBACK_COMPLETION_REASON_TERMINATED = 2,
} VcrPlaybackCompletionReason;
typedef enum VcrEntryType {
VCR_ENTRY_TYPE_NONE = 0,
VCR_ENTRY_TYPE_INITIAL_STATE = 1,
VCR_ENTRY_TYPE_KEYBOARD_EVENT = 2,
VCR_ENTRY_TYPE_MOUSE_EVENT = 3,
} VcrEntryType;
typedef struct STRUCT_6ABF50 {
// Time when appropriate key was pressed down or -1 if it's up.
int tick;
int repeatCount;
} STRUCT_6ABF50;
typedef struct InputEvent {
// This is either logical key or input event id, which can be either
// character code pressed or some other numbers used throughout the
// game interface.
int logicalKey;
int mouseX;
int mouseY;
} InputEvent;
typedef void(IdleFunc)();
typedef void(FocusFunc)(bool focus);
typedef void(TickerProc)();
typedef struct TickerListNode {
int flags;
TickerProc* proc;
struct TickerListNode* next;
} TickerListNode;
typedef struct VcrEntry {
unsigned int type;
unsigned int time;
unsigned int counter;
union {
struct {
int mouseX;
int mouseY;
int keyboardLayout;
} initial;
struct {
short key;
} keyboardEvent;
struct {
int dx;
int dy;
int buttons;
} mouseEvent;
};
} VcrEntry;
typedef struct LogicalKeyEntry {
short field_0;
short unmodified;
short shift;
short lmenu;
short rmenu;
short ctrl;
} LogicalKeyEntry;
typedef struct KeyboardEvent {
int scanCode;
unsigned short modifiers;
} KeyboardEvent;
typedef int(PauseHandler)();
typedef int(ScreenshotHandler)(int width, int height, unsigned char* buffer, unsigned char* palette);
typedef void(VcrPlaybackCompletionCallback)(int reason);
extern IdleFunc* _idle_func;
extern FocusFunc* _focus_func;
extern int gKeyboardKeyRepeatRate;
extern int gKeyboardKeyRepeatDelay;
extern bool _keyboard_hooked;
extern unsigned char gMouseDefaultCursor[MOUSE_DEFAULT_CURSOR_SIZE];
extern int _mouse_idling;
extern unsigned char* gMouseCursorData;
extern unsigned char* _mouse_shape;
extern unsigned char* _mouse_fptr;
extern double gMouseSensitivity;
extern unsigned int _ticker_;
extern int gMouseButtonsState;
extern void (*_update_palette_func)();
extern bool gMmxEnabled;
extern bool gMmxProbed;
extern unsigned char _kb_installed;
extern bool gKeyboardDisabled;
extern bool gKeyboardNumpadDisabled;
extern bool gKeyboardNumlockDisabled;
extern int gKeyboardEventQueueWriteIndex;
extern int gKeyboardEventQueueReadIndex;
extern short word_51E2E8;
extern int gModifierKeysState;
extern int (*_kb_scan_to_ascii)();
extern VcrEntry* _vcr_buffer;
extern int _vcr_buffer_index;
extern unsigned int gVcrState;
extern unsigned int _vcr_time;
extern unsigned int _vcr_counter;
extern unsigned int gVcrTerminateFlags;
extern int gVcrPlaybackCompletionReason;
extern unsigned int _vcr_start_time;
extern int _vcr_registered_atexit;
extern File* gVcrFile;
extern int _vcr_buffer_end;
extern VcrPlaybackCompletionCallback* gVcrPlaybackCompletionCallback;
extern unsigned int gVcrRequestedTerminationFlags;
extern int gVcrOldKeyboardLayout;
extern int gNormalizedQwertyKeys[SDL_NUM_SCANCODES];
extern InputEvent gInputEventQueue[40];
extern STRUCT_6ABF50 _GNW95_key_time_stamps[SDL_NUM_SCANCODES];
extern int _input_mx;
extern int _input_my;
extern bool gPaused;
extern int gScreenshotKeyCode;
extern int _using_msec_timer;
extern int gPauseKeyCode;
extern ScreenshotHandler* gScreenshotHandler;
extern int gInputEventQueueReadIndex;
extern unsigned char* gScreenshotBuffer;
extern PauseHandler* gPauseHandler;
extern int gInputEventQueueWriteIndex;
extern bool gRunLoopDisabled;
extern TickerListNode* gTickerListHead;
extern unsigned int gTickerLastTimestamp;
extern bool gCursorIsHidden;
extern int _raw_x;
extern int gMouseCursorHeight;
extern int _raw_y;
extern int _raw_buttons;
extern int gMouseCursorY;
extern int gMouseCursorX;
extern int _mouse_disabled;
extern int gMouseEvent;
extern unsigned int _mouse_speed;
extern int _mouse_curr_frame;
extern bool gMouseInitialized;
extern int gMouseCursorPitch;
extern int gMouseCursorWidth;
extern int _mouse_num_frames;
extern int _mouse_hoty;
extern int _mouse_hotx;
extern unsigned int _mouse_idle_start_time;
extern WindowDrawingProc2* _mouse_blit_trans;
extern WINDOWDRAWINGPROC _mouse_blit;
extern unsigned char _mouse_trans;
extern int gMouseRightButtonDownTimestamp;
extern int gMouseLeftButtonDownTimestamp;
extern int gMousePreviousEvent;
extern unsigned short gSixteenBppPalette[256];
extern Rect _scr_size;
extern int gRedMask;
extern int gGreenMask;
extern int gBlueMask;
extern int gBlueShift;
extern int gRedShift;
extern int gGreenShift;
extern void (*_scr_blit)(unsigned char* src, int src_pitch, int a3, int src_x, int src_y, int src_width, int src_height, int dest_x, int dest_y);
extern void (*_zero_mem)();
extern bool gMmxSupported;
extern unsigned char gLastVideoModePalette[268];
extern KeyboardEvent gKeyboardEventsQueue[KEY_QUEUE_SIZE];
extern LogicalKeyEntry gLogicalKeyEntries[SDL_NUM_SCANCODES];
extern unsigned char gPressedPhysicalKeys[SDL_NUM_SCANCODES];
extern unsigned int _kb_idle_start_time;
extern KeyboardEvent gLastKeyboardEvent;
extern int gKeyboardLayout;
extern unsigned char gPressedPhysicalKeysCount;
extern VcrEntry stru_6AD940;
extern SDL_Window* gSdlWindow;
extern SDL_Surface* gSdlSurface;
extern SDL_Renderer* gSdlRenderer;
extern SDL_Texture* gSdlTexture;
extern SDL_Surface* gSdlTextureSurface;
int coreInit(int a1);
void coreExit();
int _get_input();
void _process_bk();
void enqueueInputEvent(int a1);
int dequeueInputEvent();
void inputEventQueueReset();
void tickersExecute();
void tickersAdd(TickerProc* fn);
void tickersRemove(TickerProc* fn);
void tickersEnable();
void tickersDisable();
void pauseGame();
int pauseHandlerDefaultImpl();
void pauseHandlerConfigure(int keyCode, PauseHandler* fn);
void takeScreenshot();
void screenshotBlitter(unsigned char* src, int src_pitch, int a3, int x, int y, int width, int height, int dest_x, int dest_y);
int screenshotHandlerDefaultImpl(int width, int height, unsigned char* data, unsigned char* palette);
void screenshotHandlerConfigure(int keyCode, ScreenshotHandler* handler);
unsigned int _get_time();
void coreDelayProcessingEvents(unsigned int ms);
void coreDelay(unsigned int ms);
unsigned int getTicksSince(unsigned int a1);
unsigned int getTicksBetween(unsigned int a1, unsigned int a2);
unsigned int _get_bk_time();
void inputSetKeyboardKeyRepeatRate(int value);
int inputGetKeyboardKeyRepeatRate();
void inputSetKeyboardKeyRepeatDelay(int value);
int inputGetKeyboardKeyRepeatDelay();
void inputSetFocusFunc(FocusFunc* func);
FocusFunc* inputGetFocusFunc();
void inputSetIdleFunc(IdleFunc* func);
IdleFunc* inputGetIdleFunc();
void buildNormalizedQwertyKeys();
int _GNW95_input_init();
void _GNW95_process_message();
void _GNW95_clear_time_stamps();
void _GNW95_process_key(KeyboardData* data);
void _GNW95_lost_focus();
int mouseInit();
void mouseFree();
void mousePrepareDefaultCursor();
int mouseSetFrame(unsigned char* a1, int width, int height, int pitch, int a5, int a6, int a7);
void _mouse_anim();
void mouseShowCursor();
void mouseHideCursor();
void _mouse_info();
void _mouse_simulate_input(int delta_x, int delta_y, int buttons);
bool _mouse_in(int left, int top, int right, int bottom);
bool _mouse_click_in(int left, int top, int right, int bottom);
void mouseGetRect(Rect* rect);
void mouseGetPosition(int* out_x, int* out_y);
void _mouse_set_position(int a1, int a2);
void _mouse_clip();
int mouseGetEvent();
bool cursorIsHidden();
void _mouse_get_raw_state(int* out_x, int* out_y, int* out_buttons);
void mouseSetSensitivity(double value);
void mmxSetEnabled(bool a1);
int _init_mode_320_200();
int _init_mode_320_400();
int _init_mode_640_480_16();
int _init_mode_640_480();
int _init_mode_640_400();
int _init_mode_800_600();
int _init_mode_1024_768();
int _init_mode_1280_1024();
void _get_start_mode_();
void _zero_vid_mem();
int _GNW95_init_mode_ex(int width, int height, int bpp);
int _init_vesa_mode(int width, int height);
int _GNW95_init_window(int width, int height, bool fullscreen);
int getShiftForBitMask(int mask);
int directDrawInit(int width, int height, int bpp);
void directDrawFree();
void directDrawSetPaletteInRange(unsigned char* a1, int a2, int a3);
void directDrawSetPalette(unsigned char* palette);
unsigned char* directDrawGetPalette();
void _GNW95_ShowRect(unsigned char* src, int src_pitch, int a3, int src_x, int src_y, int src_width, int src_height, int dest_x, int dest_y);
void _GNW95_MouseShowRect16(unsigned char* src, int srcPitch, int a3, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY);
void _GNW95_ShowRect16(unsigned char* src, int srcPitch, int a3, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY);
void _GNW95_MouseShowTransRect16(unsigned char* src, int srcPitch, int a3, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, unsigned char keyColor);
void _GNW95_zero_vid_mem();
int keyboardInit();
void keyboardFree();
void keyboardReset();
int _kb_getch();
void keyboardDisable();
void keyboardEnable();
int keyboardIsDisabled();
void keyboardSetLayout(int new_language);
int keyboardGetLayout();
void _kb_simulate_key(KeyboardData* data);
int _kb_next_ascii_English_US();
int keyboardDequeueLogicalKeyCode();
void keyboardBuildQwertyConfiguration();
void keyboardBuildFrenchConfiguration();
void keyboardBuildGermanConfiguration();
void keyboardBuildItalianConfiguration();
void keyboardBuildSpanishConfiguration();
void _kb_init_lock_status();
int keyboardPeekEvent(int index, KeyboardEvent** keyboardEventPtr);
bool vcrRecord(const char* fileName);
bool vcrPlay(const char* fileName, unsigned int terminationFlags, VcrPlaybackCompletionCallback* callback);
void vcrStop();
int vcrGetState();
int vcrUpdate();
bool vcrInitBuffer();
bool vcrFreeBuffer();
bool vcrClear();
bool vcrDump();
bool vcrLoad();
bool vcrWriteEntry(VcrEntry* ptr, File* stream);
bool vcrReadEntry(VcrEntry* ptr, File* stream);
int screenGetWidth();
int screenGetHeight();
int screenGetVisibleHeight();
void mouseGetPositionInWindow(int win, int* x, int* y);
bool mouseHitTestInWindow(int win, int left, int top, int right, int bottom);
void mouseGetWheel(int* x, int* y);
void convertMouseWheelToArrowKey(int* keyCodePtr);
#endif /* CORE_H */

View File

@@ -2,24 +2,29 @@
#include <string.h>
#include <algorithm>
#include "art.h"
#include "color.h"
#include "core.h"
#include "cycle.h"
#include "db.h"
#include "debug.h"
#include "delay.h"
#include "draw.h"
#include "game_mouse.h"
#include "input.h"
#include "memory.h"
#include "message.h"
#include "mouse.h"
#include "palette.h"
#include "platform_compat.h"
#include "sound.h"
#include "svga.h"
#include "text_font.h"
#include "window_manager.h"
#define CREDITS_WINDOW_WIDTH (640)
#define CREDITS_WINDOW_HEIGHT (480)
namespace fallout {
#define CREDITS_WINDOW_SCROLLING_DELAY (38)
static bool creditsFileParseNextLine(char* dest, int* font, int* color);
@@ -61,9 +66,9 @@ void creditsOpen(const char* filePath, int backgroundFid, bool useReversedStyle)
soundContinueAll();
char localizedPath[COMPAT_MAX_PATH];
if (_message_make_path(localizedPath, filePath)) {
if (_message_make_path(localizedPath, sizeof(localizedPath), filePath)) {
gCreditsFile = fileOpen(localizedPath, "rt");
if (gCreditsFile != NULL) {
if (gCreditsFile != nullptr) {
soundContinueAll();
colorCycleDisable();
@@ -74,39 +79,35 @@ void creditsOpen(const char* filePath, int backgroundFid, bool useReversedStyle)
mouseShowCursor();
}
int creditsWindowX = (screenGetWidth() - CREDITS_WINDOW_WIDTH) / 2;
int creditsWindowY = (screenGetHeight() - CREDITS_WINDOW_HEIGHT) / 2;
int window = windowCreate(creditsWindowX, creditsWindowY, CREDITS_WINDOW_WIDTH, CREDITS_WINDOW_HEIGHT, _colorTable[0], 20);
int windowWidth = screenGetWidth();
int windowHeight = screenGetHeight();
int window = windowCreate(0, 0, windowWidth, windowHeight, _colorTable[0], 20);
soundContinueAll();
if (window != -1) {
unsigned char* windowBuffer = windowGetBuffer(window);
if (windowBuffer != NULL) {
unsigned char* backgroundBuffer = (unsigned char*)internal_malloc(CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT);
if (windowBuffer != nullptr) {
unsigned char* backgroundBuffer = (unsigned char*)internal_malloc(windowWidth * windowHeight);
if (backgroundBuffer) {
soundContinueAll();
memset(backgroundBuffer, _colorTable[0], CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT);
memset(backgroundBuffer, _colorTable[0], windowWidth * windowHeight);
if (backgroundFid != -1) {
CacheEntry* backgroundFrmHandle;
Art* frm = artLock(backgroundFid, &backgroundFrmHandle);
if (frm != NULL) {
int width = artGetWidth(frm, 0, 0);
int height = artGetHeight(frm, 0, 0);
unsigned char* backgroundFrmData = artGetFrameData(frm, 0, 0);
blitBufferToBuffer(backgroundFrmData,
width,
height,
width,
backgroundBuffer + CREDITS_WINDOW_WIDTH * ((CREDITS_WINDOW_HEIGHT - height) / 2) + (CREDITS_WINDOW_WIDTH - width) / 2,
CREDITS_WINDOW_WIDTH);
artUnlock(backgroundFrmHandle);
FrmImage backgroundFrmImage;
if (backgroundFrmImage.lock(backgroundFid)) {
blitBufferToBuffer(backgroundFrmImage.getData(),
backgroundFrmImage.getWidth(),
backgroundFrmImage.getHeight(),
backgroundFrmImage.getWidth(),
backgroundBuffer + windowWidth * ((windowHeight - backgroundFrmImage.getHeight()) / 2) + (windowWidth - backgroundFrmImage.getWidth()) / 2,
windowWidth);
backgroundFrmImage.unlock();
}
}
unsigned char* intermediateBuffer = (unsigned char*)internal_malloc(CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT);
if (intermediateBuffer != NULL) {
memset(intermediateBuffer, 0, CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT);
unsigned char* intermediateBuffer = (unsigned char*)internal_malloc(windowWidth * windowHeight);
if (intermediateBuffer != nullptr) {
memset(intermediateBuffer, 0, windowWidth * windowHeight);
fontSetCurrent(gCreditsWindowTitleFont);
int titleFontLineHeight = fontGetLineHeight();
@@ -114,22 +115,21 @@ void creditsOpen(const char* filePath, int backgroundFid, bool useReversedStyle)
fontSetCurrent(gCreditsWindowNameFont);
int nameFontLineHeight = fontGetLineHeight();
int lineHeight = nameFontLineHeight + (titleFontLineHeight >= nameFontLineHeight ? titleFontLineHeight - nameFontLineHeight : 0);
int stringBufferSize = CREDITS_WINDOW_WIDTH * lineHeight;
int lineHeight = std::max(titleFontLineHeight, nameFontLineHeight);
int stringBufferSize = windowWidth * lineHeight;
unsigned char* stringBuffer = (unsigned char*)internal_malloc(stringBufferSize);
if (stringBuffer != NULL) {
if (stringBuffer != nullptr) {
blitBufferToBuffer(backgroundBuffer,
CREDITS_WINDOW_WIDTH,
CREDITS_WINDOW_HEIGHT,
CREDITS_WINDOW_WIDTH,
windowWidth,
windowHeight,
windowWidth,
windowBuffer,
CREDITS_WINDOW_WIDTH);
windowWidth);
windowRefresh(window);
paletteFadeTo(_cmap);
unsigned char* v40 = intermediateBuffer + CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT - CREDITS_WINDOW_WIDTH;
char str[260];
int font;
int color;
@@ -138,47 +138,51 @@ void creditsOpen(const char* filePath, int backgroundFid, bool useReversedStyle)
while (creditsFileParseNextLine(str, &font, &color)) {
fontSetCurrent(font);
int v19 = fontGetStringWidth(str);
if (v19 >= CREDITS_WINDOW_WIDTH) {
int stringWidth = fontGetStringWidth(str);
if (stringWidth >= windowWidth) {
continue;
}
memset(stringBuffer, 0, stringBufferSize);
fontDrawText(stringBuffer, str, CREDITS_WINDOW_WIDTH, CREDITS_WINDOW_WIDTH, color);
fontDrawText(stringBuffer, str, windowWidth, windowWidth, color);
unsigned char* dest = intermediateBuffer + CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT - CREDITS_WINDOW_WIDTH + (CREDITS_WINDOW_WIDTH - v19) / 2;
unsigned char* dest = intermediateBuffer + windowWidth * windowHeight - windowWidth + (windowWidth - stringWidth) / 2;
unsigned char* src = stringBuffer;
for (int index = 0; index < lineHeight; index++) {
if (_get_input() != -1) {
sharedFpsLimiter.mark();
if (inputGetInput() != -1) {
stop = true;
break;
}
memmove(intermediateBuffer, intermediateBuffer + CREDITS_WINDOW_WIDTH, CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT - CREDITS_WINDOW_WIDTH);
memcpy(dest, src, v19);
memmove(intermediateBuffer, intermediateBuffer + windowWidth, windowWidth * windowHeight - windowWidth);
memcpy(dest, src, stringWidth);
blitBufferToBuffer(backgroundBuffer,
CREDITS_WINDOW_WIDTH,
CREDITS_WINDOW_HEIGHT,
CREDITS_WINDOW_WIDTH,
windowWidth,
windowHeight,
windowWidth,
windowBuffer,
CREDITS_WINDOW_WIDTH);
windowWidth);
blitBufferToBufferTrans(intermediateBuffer,
CREDITS_WINDOW_WIDTH,
CREDITS_WINDOW_HEIGHT,
CREDITS_WINDOW_WIDTH,
windowWidth,
windowHeight,
windowWidth,
windowBuffer,
CREDITS_WINDOW_WIDTH);
windowWidth);
while (getTicksSince(tick) < CREDITS_WINDOW_SCROLLING_DELAY) {
}
delay_ms(CREDITS_WINDOW_SCROLLING_DELAY - (getTicks() - tick));
tick = _get_time();
tick = getTicks();
windowRefresh(window);
src += CREDITS_WINDOW_WIDTH;
src += windowWidth;
sharedFpsLimiter.throttle();
renderPresent();
}
if (stop) {
@@ -187,34 +191,38 @@ void creditsOpen(const char* filePath, int backgroundFid, bool useReversedStyle)
}
if (!stop) {
for (int index = 0; index < CREDITS_WINDOW_HEIGHT; index++) {
if (_get_input() != -1) {
for (int index = 0; index < windowHeight; index++) {
sharedFpsLimiter.mark();
if (inputGetInput() != -1) {
break;
}
memmove(intermediateBuffer, intermediateBuffer + CREDITS_WINDOW_WIDTH, CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT - CREDITS_WINDOW_WIDTH);
memset(intermediateBuffer + CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT - CREDITS_WINDOW_WIDTH, 0, CREDITS_WINDOW_WIDTH);
memmove(intermediateBuffer, intermediateBuffer + windowWidth, windowWidth * windowHeight - windowWidth);
memset(intermediateBuffer + windowWidth * windowHeight - windowWidth, 0, windowWidth);
blitBufferToBuffer(backgroundBuffer,
CREDITS_WINDOW_WIDTH,
CREDITS_WINDOW_HEIGHT,
CREDITS_WINDOW_WIDTH,
windowWidth,
windowHeight,
windowWidth,
windowBuffer,
CREDITS_WINDOW_WIDTH);
windowWidth);
blitBufferToBufferTrans(intermediateBuffer,
CREDITS_WINDOW_WIDTH,
CREDITS_WINDOW_HEIGHT,
CREDITS_WINDOW_WIDTH,
windowWidth,
windowHeight,
windowWidth,
windowBuffer,
CREDITS_WINDOW_WIDTH);
windowWidth);
while (getTicksSince(tick) < CREDITS_WINDOW_SCROLLING_DELAY) {
}
delay_ms(CREDITS_WINDOW_SCROLLING_DELAY - (getTicks() - tick));
tick = _get_time();
tick = getTicks();
windowRefresh(window);
sharedFpsLimiter.throttle();
renderPresent();
}
}
@@ -274,3 +282,5 @@ static bool creditsFileParseNextLine(char* dest, int* font, int* color)
return false;
}
} // namespace fallout

View File

@@ -1,6 +1,10 @@
#ifndef CREDITS_H
#define CREDITS_H
namespace fallout {
void creditsOpen(const char* path, int fid, bool useReversedStyle);
} // namespace fallout
#endif /* CREDITS_H */

View File

@@ -31,6 +31,8 @@
#include "trait.h"
#include "worldmap.h"
namespace fallout {
// Maximum length of dude's name length.
#define DUDE_NAME_MAX_LENGTH (32)
@@ -133,7 +135,7 @@ static const int gRadiationEffectPenalties[RADIATION_LEVEL_COUNT][RADIATION_EFFE
};
// 0x518438
static Object* _critterClearObj = NULL;
static Object* _critterClearObj = nullptr;
// scrname.msg
//
@@ -169,13 +171,15 @@ int critterInit()
}
char path[COMPAT_MAX_PATH];
sprintf(path, "%sscrname.msg", asc_5186C8);
snprintf(path, sizeof(path), "%sscrname.msg", asc_5186C8);
if (!messageListLoad(&gCritterMessageList, path)) {
debugPrint("\nError: Loading critter name message file!");
return -1;
}
messageListRepositorySetStandardMessageList(STANDARD_MESSAGE_LIST_SCRNAME, &gCritterMessageList);
return 0;
}
@@ -191,6 +195,7 @@ void critterReset()
// 0x42D004
void critterExit()
{
messageListRepositorySetStandardMessageList(STANDARD_MESSAGE_LIST_SCRNAME, nullptr);
messageListFree(&gCritterMessageList);
}
@@ -242,7 +247,7 @@ char* critterGetName(Object* obj)
}
}
char* name = NULL;
char* name = nullptr;
if (obj->field_80 != -1) {
MessageListItem messageListItem;
messageListItem.num = 101 + obj->field_80;
@@ -251,7 +256,7 @@ char* critterGetName(Object* obj)
}
}
if (name == NULL || *name == '\0') {
if (name == nullptr || *name == '\0') {
name = protoGetName(obj->pid);
}
@@ -342,8 +347,8 @@ int critterAdjustPoison(Object* critter, int amount)
if (newPoison > 0) {
critter->data.critter.poison = newPoison;
_queue_clear_type(EVENT_TYPE_POISON, NULL);
queueAddEvent(10 * (505 - 5 * newPoison), gDude, NULL, EVENT_TYPE_POISON);
_queue_clear_type(EVENT_TYPE_POISON, nullptr);
queueAddEvent(10 * (505 - 5 * newPoison), gDude, nullptr, EVENT_TYPE_POISON);
// You have been poisoned!
messageListItem.num = 3000;
@@ -420,27 +425,27 @@ int critterAdjustRadiation(Object* obj, int amount)
}
if (amount > 0) {
proto->critter.data.flags |= CRITTER_FLAG_0x2;
proto->critter.data.flags |= CRITTER_RADIATED;
}
if (amount > 0) {
Object* geigerCounter = NULL;
Object* geigerCounter = nullptr;
Object* item1 = critterGetItem1(gDude);
if (item1 != NULL) {
if (item1 != nullptr) {
if (item1->pid == PROTO_ID_GEIGER_COUNTER_I || item1->pid == PROTO_ID_GEIGER_COUNTER_II) {
geigerCounter = item1;
}
}
Object* item2 = critterGetItem2(gDude);
if (item2 != NULL) {
if (item2 != nullptr) {
if (item2->pid == PROTO_ID_GEIGER_COUNTER_I || item2->pid == PROTO_ID_GEIGER_COUNTER_II) {
geigerCounter = item2;
}
}
if (geigerCounter != NULL) {
if (geigerCounter != nullptr) {
if (miscItemIsOn(geigerCounter)) {
if (amount > 5) {
// The geiger counter is clicking wildly.
@@ -487,7 +492,7 @@ int _critter_check_rads(Object* obj)
Proto* proto;
protoGetProto(obj->pid, &proto);
if ((proto->critter.data.flags & CRITTER_FLAG_0x2) == 0) {
if ((proto->critter.data.flags & CRITTER_RADIATED) == 0) {
return 0;
}
@@ -512,14 +517,14 @@ int _critter_check_rads(Object* obj)
else
radiationLevel = RADIATION_LEVEL_NONE;
if (statRoll(obj, STAT_ENDURANCE, gRadiationEnduranceModifiers[radiationLevel], NULL) <= ROLL_FAILURE) {
if (statRoll(obj, STAT_ENDURANCE, gRadiationEnduranceModifiers[radiationLevel], nullptr) <= ROLL_FAILURE) {
radiationLevel++;
}
if (radiationLevel > _old_rad_level) {
// Create timer event for applying radiation damage.
RadiationEvent* radiationEvent = (RadiationEvent*)internal_malloc(sizeof(*radiationEvent));
if (radiationEvent == NULL) {
if (radiationEvent == nullptr) {
return 0;
}
@@ -528,7 +533,7 @@ int _critter_check_rads(Object* obj)
queueAddEvent(GAME_TIME_TICKS_PER_HOUR * randomBetween(4, 18), obj, radiationEvent, EVENT_TYPE_RADIATION);
}
proto->critter.data.flags &= ~(CRITTER_FLAG_0x2);
proto->critter.data.flags &= ~CRITTER_RADIATED;
return 0;
}
@@ -625,7 +630,7 @@ int radiationEventProcess(Object* obj, void* data)
if (!radiationEvent->isHealing) {
// Schedule healing stats event in 7 days.
RadiationEvent* newRadiationEvent = (RadiationEvent*)internal_malloc(sizeof(*newRadiationEvent));
if (newRadiationEvent != NULL) {
if (newRadiationEvent != nullptr) {
_queue_clear_type(EVENT_TYPE_RADIATION, _clear_rad_damage);
newRadiationEvent->radiationLevel = radiationEvent->radiationLevel;
newRadiationEvent->isHealing = 1;
@@ -642,7 +647,7 @@ int radiationEventProcess(Object* obj, void* data)
int radiationEventRead(File* stream, void** dataPtr)
{
RadiationEvent* radiationEvent = (RadiationEvent*)internal_malloc(sizeof(*radiationEvent));
if (radiationEvent == NULL) {
if (radiationEvent == nullptr) {
return -1;
}
@@ -765,7 +770,7 @@ char* killTypeGetName(int killType)
MessageListItem messageListItem;
return getmsg(&gProtoMessageList, &messageListItem, 1450 + killType);
} else {
return NULL;
return nullptr;
}
} else {
return byte_501494;
@@ -780,7 +785,7 @@ char* killTypeGetDescription(int killType)
MessageListItem messageListItem;
return getmsg(&gProtoMessageList, &messageListItem, 1469 + killType);
} else {
return NULL;
return nullptr;
}
} else {
return byte_501494;
@@ -874,7 +879,7 @@ void critterKill(Object* critter, int anim, bool a3)
rectUnion(&updatedRect, &tempRect, &updatedRect);
}
if (!_critter_flag_check(critter->pid, CRITTER_FLAG_0x800)) {
if (!_critter_flag_check(critter->pid, CRITTER_FLAT)) {
critter->flags |= OBJECT_NO_BLOCK;
_obj_toggle_flat(critter, &tempRect);
}
@@ -922,7 +927,7 @@ int critterGetExp(Object* critter)
// 0x42DCDC
bool critterIsActive(Object* critter)
{
if (critter == NULL) {
if (critter == nullptr) {
return false;
}
@@ -944,7 +949,7 @@ bool critterIsActive(Object* critter)
// 0x42DD18
bool critterIsDead(Object* critter)
{
if (critter == NULL) {
if (critter == nullptr) {
return false;
}
@@ -966,7 +971,7 @@ bool critterIsDead(Object* critter)
// 0x42DD58
bool critterIsCrippled(Object* critter)
{
if (critter == NULL) {
if (critter == nullptr) {
return false;
}
@@ -980,7 +985,7 @@ bool critterIsCrippled(Object* critter)
// 0x42DD80
bool _critter_is_prone(Object* critter)
{
if (critter == NULL) {
if (critter == nullptr) {
return false;
}
@@ -991,15 +996,15 @@ bool _critter_is_prone(Object* critter)
int anim = FID_ANIM_TYPE(critter->fid);
return (critter->data.critter.combat.results & (DAM_KNOCKED_OUT | DAM_KNOCKED_DOWN)) != 0
|| (anim >= FIRST_KNOCKDOWN_AND_DEATH_ANIM && anim <= LAST_KNOCKDOWN_AND_DEATH_ANIM)
|| (anim >= FIRST_SF_DEATH_ANIM && anim <= LAST_SF_DEATH_ANIM);
|| (anim >= FIRST_KNOCKDOWN_AND_DEATH_ANIM && anim <= LAST_KNOCKDOWN_AND_DEATH_ANIM)
|| (anim >= FIRST_SF_DEATH_ANIM && anim <= LAST_SF_DEATH_ANIM);
}
// critter_body_type
// 0x42DDC4
int critterGetBodyType(Object* critter)
{
if (critter == NULL) {
if (critter == nullptr) {
debugPrint("\nError: critter_body_type: pobj was NULL!");
return 0;
}
@@ -1017,7 +1022,7 @@ int critterGetBodyType(Object* critter)
int gcdLoad(const char* path)
{
File* stream = fileOpen(path, "rb");
if (stream == NULL) {
if (stream == nullptr) {
return -1;
}
@@ -1089,7 +1094,7 @@ int protoCritterDataRead(File* stream, CritterProtoData* critterData)
int gcdSave(const char* path)
{
File* stream = fileOpen(path, "wb");
if (stream == NULL) {
if (stream == nullptr) {
return -1;
}
@@ -1161,7 +1166,7 @@ void dudeEnableState(int state)
proto->critter.data.flags |= (1 << state);
if (state == DUDE_STATE_SNEAKING) {
sneakEventProcess(NULL, NULL);
sneakEventProcess(nullptr, nullptr);
}
indicatorBarRefresh();
@@ -1192,7 +1197,7 @@ int sneakEventProcess(Object* obj, void* data)
int time;
int sneak = skillGetValue(gDude, SKILL_SNEAK);
if (skillRoll(gDude, SKILL_SNEAK, 0, NULL) < ROLL_SUCCESS) {
if (skillRoll(gDude, SKILL_SNEAK, 0, nullptr) < ROLL_SUCCESS) {
time = 600;
_sneak_working = false;
@@ -1213,7 +1218,7 @@ int sneakEventProcess(Object* obj, void* data)
_sneak_working = true;
}
queueAddEvent(time, gDude, NULL, EVENT_TYPE_SNEAK);
queueAddEvent(time, gDude, nullptr, EVENT_TYPE_SNEAK);
return 0;
}
@@ -1249,7 +1254,7 @@ int knockoutEventProcess(Object* obj, void* data)
obj->data.critter.combat.results |= DAM_KNOCKED_DOWN;
if (isInCombat()) {
obj->data.critter.combat.maneuver |= CRITTER_MANEUVER_0x01;
obj->data.critter.combat.maneuver |= CRITTER_MANEUVER_ENGAGING;
} else {
_dude_standup(obj);
}
@@ -1271,7 +1276,7 @@ int _critter_wake_clear(Object* obj, void* data)
obj->data.critter.combat.results &= ~(DAM_KNOCKED_OUT | DAM_KNOCKED_DOWN);
int fid = buildFid(FID_TYPE(obj->fid), obj->fid & 0xFFF, ANIM_STAND, (obj->fid & 0xF000) >> 12, obj->rotation + 1);
objectSetFid(obj, fid, 0);
objectSetFid(obj, fid, nullptr);
return 0;
}
@@ -1279,16 +1284,16 @@ int _critter_wake_clear(Object* obj, void* data)
// 0x42E4C0
int _critter_set_who_hit_me(Object* a1, Object* a2)
{
if (a1 == NULL) {
if (a1 == nullptr) {
return -1;
}
if (a2 != NULL && FID_TYPE(a2->fid) != OBJ_TYPE_CRITTER) {
if (a2 != nullptr && FID_TYPE(a2->fid) != OBJ_TYPE_CRITTER) {
return -1;
}
if (PID_TYPE(a1->pid) == OBJ_TYPE_CRITTER) {
if (a2 == NULL || a1->data.critter.combat.team != a2->data.critter.combat.team || (statRoll(a1, STAT_INTELLIGENCE, -1, NULL) < 2 && (!objectIsPartyMember(a1) || !objectIsPartyMember(a2)))) {
if (a2 == nullptr || a1->data.critter.combat.team != a2->data.critter.combat.team || (statRoll(a1, STAT_INTELLIGENCE, -1, nullptr) < 2 && (!objectIsPartyMember(a1) || !objectIsPartyMember(a2)))) {
a1->data.critter.combat.whoHitMe = a2;
if (a2 == gDude) {
reactionSetValue(a1, -3);
@@ -1368,7 +1373,7 @@ bool critterIsEncumbered(Object* critter)
// 0x42E690
bool critterIsFleeing(Object* critter)
{
return critter != NULL
return critter != nullptr
? (critter->data.critter.combat.maneuver & CRITTER_MANUEVER_FLEEING) != 0
: false;
}
@@ -1390,3 +1395,41 @@ bool _critter_flag_check(int pid, int flag)
protoGetProto(pid, &proto);
return (proto->critter.data.flags & flag) != 0;
}
// 0x42E6F0
void critter_flag_set(int pid, int flag)
{
Proto* proto;
if (pid == -1) {
return;
}
if (PID_TYPE(pid) != OBJ_TYPE_CRITTER) {
return;
}
protoGetProto(pid, &proto);
proto->critter.data.flags |= flag;
}
// 0x42E71C
void critter_flag_unset(int pid, int flag)
{
Proto* proto;
if (pid == -1) {
return;
}
if (PID_TYPE(pid) != OBJ_TYPE_CRITTER) {
return;
}
protoGetProto(pid, &proto);
proto->critter.data.flags &= ~flag;
}
} // namespace fallout

View File

@@ -5,6 +5,8 @@
#include "obj_types.h"
#include "proto_types.h"
namespace fallout {
typedef enum DudeState {
DUDE_STATE_SNEAKING = 0,
DUDE_STATE_LEVEL_UP_AVAILABLE = 3,
@@ -68,5 +70,9 @@ int critterGetMovementPointCostAdjustedForCrippledLegs(Object* critter, int a2);
bool critterIsEncumbered(Object* critter);
bool critterIsFleeing(Object* a1);
bool _critter_flag_check(int pid, int flag);
void critter_flag_set(int pid, int flag);
void critter_flag_unset(int pid, int flag);
} // namespace fallout
#endif /* CRITTER_H */

View File

@@ -1,14 +1,17 @@
#include "cycle.h"
#include "color.h"
#include "core.h"
#include "game_config.h"
#include "input.h"
#include "palette.h"
#include "settings.h"
#include "svga.h"
#define COLOR_CYCLE_PERIOD_1 (200U)
#define COLOR_CYCLE_PERIOD_2 (142U)
#define COLOR_CYCLE_PERIOD_3 (100U)
#define COLOR_CYCLE_PERIOD_4 (33U)
namespace fallout {
static constexpr unsigned int kSlowCyclePeriod = 1000 / 5;
static constexpr unsigned int kMediumCyclePeriod = 1000 / 7;
static constexpr unsigned int kFastCyclePeriod = 1000 / 10;
static constexpr unsigned int kVeryFastCyclePeriod = 1000 / 30;
// 0x51843C
static int gColorCycleSpeedFactor = 1;
@@ -19,7 +22,7 @@ static int gColorCycleSpeedFactor = 1;
// Green.
//
// 0x518440
static unsigned char _slime[12] = {
static unsigned char slime[12] = {
0, 108, 0,
11, 115, 7,
27, 123, 15,
@@ -29,7 +32,7 @@ static unsigned char _slime[12] = {
// Light gray?
//
// 0x51844C
static unsigned char _shoreline[18] = {
static unsigned char shoreline[18] = {
83, 63, 43,
75, 59, 43,
67, 55, 39,
@@ -41,7 +44,7 @@ static unsigned char _shoreline[18] = {
// Orange.
//
// 0x51845E
static unsigned char _fire_slow[15] = {
static unsigned char fire_slow[15] = {
255, 0, 0,
215, 0, 0,
147, 43, 11,
@@ -52,7 +55,7 @@ static unsigned char _fire_slow[15] = {
// Red.
//
// 0x51846D
static unsigned char _fire_fast[15] = {
static unsigned char fire_fast[15] = {
71, 0, 0,
123, 0, 0,
179, 0, 0,
@@ -63,7 +66,7 @@ static unsigned char _fire_fast[15] = {
// Light blue.
//
// 0x51847C
static unsigned char _monitors[15] = {
static unsigned char monitors[15] = {
107, 107, 111,
99, 103, 127,
87, 107, 143,
@@ -79,38 +82,17 @@ static bool gColorCycleInitialized = false;
// 0x518490
static bool gColorCycleEnabled = false;
// 0x518494
static int _slime_start = 0;
// 0x518498
static int _shoreline_start = 0;
// 0x51849C
static int _fire_slow_start = 0;
// 0x5184A0
static int _fire_fast_start = 0;
// 0x5184A4
static int _monitors_start = 0;
// 0x5184A8
static unsigned char _bobber_red = 0;
// 0x5184A9
static signed char _bobber_diff = -4;
// 0x56D7D0
static unsigned int gColorCycleTimestamp3;
static unsigned int last_cycle_fast;
// 0x56D7D4
static unsigned int gColorCycleTimestamp1;
static unsigned int last_cycle_slow;
// 0x56D7D8
static unsigned int gColorCycleTimestamp2;
static unsigned int last_cycle_medium;
// 0x56D7DC
static unsigned int gColorCycleTimestamp4;
static unsigned int last_cycle_very_fast;
// 0x42E780
void colorCycleInit()
@@ -119,33 +101,28 @@ void colorCycleInit()
return;
}
bool colorCycling;
if (!configGetBool(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_COLOR_CYCLING_KEY, &colorCycling)) {
colorCycling = true;
}
if (!colorCycling) {
if (!settings.system.color_cycling) {
return;
}
for (int index = 0; index < 12; index++) {
_slime[index] >>= 2;
slime[index] >>= 2;
}
for (int index = 0; index < 18; index++) {
_shoreline[index] >>= 2;
shoreline[index] >>= 2;
}
for (int index = 0; index < 15; index++) {
_fire_slow[index] >>= 2;
fire_slow[index] >>= 2;
}
for (int index = 0; index < 15; index++) {
_fire_fast[index] >>= 2;
fire_fast[index] >>= 2;
}
for (int index = 0; index < 15; index++) {
_monitors[index] >>= 2;
monitors[index] >>= 2;
}
tickersAdd(colorCycleTicker);
@@ -153,22 +130,17 @@ void colorCycleInit()
gColorCycleInitialized = true;
gColorCycleEnabled = true;
int cycleSpeedFactor;
if (!configGetInt(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_CYCLE_SPEED_FACTOR_KEY, &cycleSpeedFactor)) {
cycleSpeedFactor = 1;
}
cycleSetSpeedFactor(cycleSpeedFactor);
cycleSetSpeedFactor(settings.system.cycle_speed_factor);
}
// 0x42E8CC
void colorCycleReset()
{
if (gColorCycleInitialized) {
gColorCycleTimestamp1 = 0;
gColorCycleTimestamp2 = 0;
gColorCycleTimestamp3 = 0;
gColorCycleTimestamp4 = 0;
last_cycle_slow = 0;
last_cycle_medium = 0;
last_cycle_fast = 0;
last_cycle_very_fast = 0;
tickersAdd(colorCycleTicker);
gColorCycleEnabled = true;
}
@@ -206,12 +178,33 @@ bool colorCycleEnabled()
void cycleSetSpeedFactor(int value)
{
gColorCycleSpeedFactor = value;
configSetInt(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_CYCLE_SPEED_FACTOR_KEY, value);
settings.system.cycle_speed_factor = value;
}
// 0x42E97C
void colorCycleTicker()
{
// 0x518494
static int slime_start = 0;
// 0x518498
static int shoreline_start = 0;
// 0x51849C
static int fire_slow_start = 0;
// 0x5184A0
static int fire_fast_start = 0;
// 0x5184A4
static int monitors_start = 0;
// 0x5184A8
static unsigned char bobber_red = 0;
// 0x5184A9
static signed char bobber_diff = -4;
if (!gColorCycleEnabled) {
return;
}
@@ -219,111 +212,111 @@ void colorCycleTicker()
bool changed = false;
unsigned char* palette = _getSystemPalette();
unsigned int time = _get_time();
unsigned int time = getTicks();
if (getTicksBetween(time, gColorCycleTimestamp1) >= COLOR_CYCLE_PERIOD_1 * gColorCycleSpeedFactor) {
if (getTicksBetween(time, last_cycle_slow) >= kSlowCyclePeriod * gColorCycleSpeedFactor) {
changed = true;
gColorCycleTimestamp1 = time;
last_cycle_slow = time;
int paletteIndex = 229 * 3;
for (int index = _slime_start; index < 12; index++) {
palette[paletteIndex++] = _slime[index];
for (int index = slime_start; index < 12; index++) {
palette[paletteIndex++] = slime[index];
}
for (int index = 0; index < _slime_start; index++) {
palette[paletteIndex++] = _slime[index];
for (int index = 0; index < slime_start; index++) {
palette[paletteIndex++] = slime[index];
}
_slime_start -= 3;
if (_slime_start < 0) {
_slime_start = 9;
slime_start -= 3;
if (slime_start < 0) {
slime_start = 9;
}
paletteIndex = 248 * 3;
for (int index = _shoreline_start; index < 18; index++) {
palette[paletteIndex++] = _shoreline[index];
for (int index = shoreline_start; index < 18; index++) {
palette[paletteIndex++] = shoreline[index];
}
for (int index = 0; index < _shoreline_start; index++) {
palette[paletteIndex++] = _shoreline[index];
for (int index = 0; index < shoreline_start; index++) {
palette[paletteIndex++] = shoreline[index];
}
_shoreline_start -= 3;
if (_shoreline_start < 0) {
_shoreline_start = 15;
shoreline_start -= 3;
if (shoreline_start < 0) {
shoreline_start = 15;
}
paletteIndex = 238 * 3;
for (int index = _fire_slow_start; index < 15; index++) {
palette[paletteIndex++] = _fire_slow[index];
for (int index = fire_slow_start; index < 15; index++) {
palette[paletteIndex++] = fire_slow[index];
}
for (int index = 0; index < _fire_slow_start; index++) {
palette[paletteIndex++] = _fire_slow[index];
for (int index = 0; index < fire_slow_start; index++) {
palette[paletteIndex++] = fire_slow[index];
}
_fire_slow_start -= 3;
if (_fire_slow_start < 0) {
_fire_slow_start = 12;
fire_slow_start -= 3;
if (fire_slow_start < 0) {
fire_slow_start = 12;
}
}
if (getTicksBetween(time, gColorCycleTimestamp2) >= COLOR_CYCLE_PERIOD_2 * gColorCycleSpeedFactor) {
if (getTicksBetween(time, last_cycle_medium) >= kMediumCyclePeriod * gColorCycleSpeedFactor) {
changed = true;
gColorCycleTimestamp2 = time;
last_cycle_medium = time;
int paletteIndex = 243 * 3;
for (int index = _fire_fast_start; index < 15; index++) {
palette[paletteIndex++] = _fire_fast[index];
for (int index = fire_fast_start; index < 15; index++) {
palette[paletteIndex++] = fire_fast[index];
}
for (int index = 0; index < _fire_fast_start; index++) {
palette[paletteIndex++] = _fire_fast[index];
for (int index = 0; index < fire_fast_start; index++) {
palette[paletteIndex++] = fire_fast[index];
}
_fire_fast_start -= 3;
if (_fire_fast_start < 0) {
_fire_fast_start = 12;
fire_fast_start -= 3;
if (fire_fast_start < 0) {
fire_fast_start = 12;
}
}
if (getTicksBetween(time, gColorCycleTimestamp3) >= COLOR_CYCLE_PERIOD_3 * gColorCycleSpeedFactor) {
if (getTicksBetween(time, last_cycle_fast) >= kFastCyclePeriod * gColorCycleSpeedFactor) {
changed = true;
gColorCycleTimestamp3 = time;
last_cycle_fast = time;
int paletteIndex = 233 * 3;
for (int index = _monitors_start; index < 15; index++) {
palette[paletteIndex++] = _monitors[index];
for (int index = monitors_start; index < 15; index++) {
palette[paletteIndex++] = monitors[index];
}
for (int index = 0; index < _monitors_start; index++) {
palette[paletteIndex++] = _monitors[index];
for (int index = 0; index < monitors_start; index++) {
palette[paletteIndex++] = monitors[index];
}
_monitors_start -= 3;
monitors_start -= 3;
if (_monitors_start < 0) {
_monitors_start = 12;
if (monitors_start < 0) {
monitors_start = 12;
}
}
if (getTicksBetween(time, gColorCycleTimestamp4) >= COLOR_CYCLE_PERIOD_4 * gColorCycleSpeedFactor) {
if (getTicksBetween(time, last_cycle_very_fast) >= kVeryFastCyclePeriod * gColorCycleSpeedFactor) {
changed = true;
gColorCycleTimestamp4 = time;
last_cycle_very_fast = time;
if (_bobber_red == 0 || _bobber_red == 60) {
_bobber_diff = -_bobber_diff;
if (bobber_red == 0 || bobber_red == 60) {
bobber_diff = -bobber_diff;
}
_bobber_red += _bobber_diff;
bobber_red += bobber_diff;
int paletteIndex = 254 * 3;
palette[paletteIndex++] = _bobber_red;
palette[paletteIndex++] = bobber_red;
palette[paletteIndex++] = 0;
palette[paletteIndex++] = 0;
}
@@ -332,3 +325,5 @@ void colorCycleTicker()
paletteSetEntriesInRange(palette + 229 * 3, 229, 255);
}
}
} // namespace fallout

View File

@@ -1,6 +1,8 @@
#ifndef CYCLE_H
#define CYCLE_H
namespace fallout {
void colorCycleInit();
void colorCycleReset();
void colorCycleFree();
@@ -10,4 +12,6 @@ bool colorCycleEnabled();
void cycleSetSpeedFactor(int value);
void colorCycleTicker();
} // namespace fallout
#endif /* CYCLE_H */

View File

@@ -8,8 +8,10 @@
#include "pcx.h"
#include "platform_compat.h"
namespace fallout {
// 0x5184AC
DatafileLoader* gDatafileLoader = NULL;
DatafileLoader* gDatafileLoader = nullptr;
// 0x5184B0
DatafileNameMangler* gDatafileNameMangler = datafileDefaultNameManglerImpl;
@@ -88,24 +90,24 @@ unsigned char* datafileReadRaw(char* path, int* widthPtr, int* heightPtr)
{
char* mangledPath = gDatafileNameMangler(path);
char* dot = strrchr(mangledPath, '.');
if (dot != NULL) {
if (dot != nullptr) {
if (compat_stricmp(dot + 1, "pcx") == 0) {
return pcxRead(mangledPath, widthPtr, heightPtr, gDatafilePalette);
}
}
if (gDatafileLoader != NULL) {
if (gDatafileLoader != nullptr) {
return gDatafileLoader(mangledPath, gDatafilePalette, widthPtr, heightPtr);
}
return NULL;
return nullptr;
}
// 0x42EFCC
unsigned char* datafileRead(char* path, int* widthPtr, int* heightPtr)
{
unsigned char* v1 = datafileReadRaw(path, widthPtr, heightPtr);
if (v1 != NULL) {
if (v1 != nullptr) {
sub_42EE84(v1, gDatafilePalette, *widthPtr, *heightPtr);
}
return v1;
@@ -119,12 +121,12 @@ unsigned char* sub_42EFF4(char* path)
int width;
int height;
unsigned char* v3 = datafileReadRaw(path, &width, &height);
if (v3 != NULL) {
if (v3 != nullptr) {
internal_free_safe(v3, __FILE__, __LINE__); // "..\\int\\DATAFILE.C", 148
return gDatafilePalette;
}
return NULL;
return nullptr;
}
// NOTE: Unused.
@@ -175,17 +177,17 @@ unsigned char* datafileLoad(char* path, int* sizePtr)
{
const char* mangledPath = gDatafileNameMangler(path);
File* stream = fileOpen(mangledPath, "rb");
if (stream == NULL) {
return NULL;
if (stream == nullptr) {
return nullptr;
}
int size = fileGetSize(stream);
unsigned char* data = (unsigned char*)internal_malloc_safe(size, __FILE__, __LINE__); // "..\\int\\DATAFILE.C", 185
if (data == NULL) {
if (data == nullptr) {
// NOTE: This code is unreachable, internal_malloc_safe never fails.
// Otherwise it leaks stream.
*sizePtr = 0;
return NULL;
return nullptr;
}
fileRead(data, 1, size, stream);
@@ -193,3 +195,5 @@ unsigned char* datafileLoad(char* path, int* sizePtr)
*sizePtr = size;
return data;
}
} // namespace fallout

View File

@@ -1,6 +1,8 @@
#ifndef DATAFILE_H
#define DATAFILE_H
namespace fallout {
typedef unsigned char*(DatafileLoader)(char* path, unsigned char* palette, int* widthPtr, int* heightPtr);
typedef char*(DatafileNameMangler)(char* path);
@@ -21,4 +23,6 @@ void sub_42F024(unsigned char* data, int* widthPtr, int* heightPtr);
unsigned char* datafileGetPalette();
unsigned char* datafileLoad(char* path, int* sizePtr);
} // namespace fallout
#endif /* DATAFILE_H */

View File

@@ -7,6 +7,8 @@
#include "platform_compat.h"
#include "xfile.h"
namespace fallout {
typedef struct FileList {
XList xlist;
struct FileList* next;
@@ -17,7 +19,7 @@ static int _db_list_compare(const void* p1, const void* p2);
// Generic file progress report handler.
//
// 0x51DEEC
static FileReadProgressHandler* gFileReadProgressHandler = NULL;
static FileReadProgressHandler* gFileReadProgressHandler = nullptr;
// Bytes read so far while tracking progress.
//
@@ -48,41 +50,29 @@ static FileList* gFileListHead;
// 0x4C5D30
int dbOpen(const char* filePath1, int a2, const char* filePath2, int a4)
{
if (filePath1 != NULL) {
if (filePath1 != nullptr) {
if (!xbaseOpen(filePath1)) {
return -1;
}
}
if (filePath2 != NULL) {
if (filePath2 != nullptr) {
xbaseOpen(filePath2);
}
return 0;
}
// 0x4C5D54
int _db_select(int dbHandle)
{
return 0;
}
// NOTE: Uncollapsed 0x4C5D54.
int _db_current()
{
return 0;
}
// 0x4C5D58
int _db_total()
int db_total()
{
return 0;
return 1;
}
// 0x4C5D60
void dbExit()
{
xbaseReopenAll(NULL);
xbaseReopenAll(nullptr);
}
// TODO: sizePtr should be long*.
@@ -94,7 +84,7 @@ int dbGetFileSize(const char* filePath, int* sizePtr)
assert(sizePtr); // "de", "db.c", 109
File* stream = xfileOpen(filePath, "rb");
if (stream == NULL) {
if (stream == nullptr) {
return -1;
}
@@ -112,12 +102,12 @@ int dbGetFileContents(const char* filePath, void* ptr)
assert(ptr); // "buf", "db.c", 142
File* stream = xfileOpen(filePath, "rb");
if (stream == NULL) {
if (stream == nullptr) {
return -1;
}
long size = xfileGetSize(stream);
if (gFileReadProgressHandler != NULL) {
if (gFileReadProgressHandler != nullptr) {
unsigned char* byteBuffer = (unsigned char*)ptr;
long remainingSize = size;
@@ -176,7 +166,7 @@ int filePrintFormatted(File* stream, const char* format, ...)
// 0x4C5F24
int fileReadChar(File* stream)
{
if (gFileReadProgressHandler != NULL) {
if (gFileReadProgressHandler != nullptr) {
int ch = xfileReadChar(stream);
gFileReadProgressBytesRead++;
@@ -194,9 +184,9 @@ int fileReadChar(File* stream)
// 0x4C5F70
char* fileReadString(char* string, size_t size, File* stream)
{
if (gFileReadProgressHandler != NULL) {
if (xfileReadString(string, size, stream) == NULL) {
return NULL;
if (gFileReadProgressHandler != nullptr) {
if (xfileReadString(string, size, stream) == nullptr) {
return nullptr;
}
gFileReadProgressBytesRead += strlen(string);
@@ -220,7 +210,7 @@ int fileWriteString(const char* string, File* stream)
// 0x4C5FFC
size_t fileRead(void* ptr, size_t size, size_t count, File* stream)
{
if (gFileReadProgressHandler != NULL) {
if (gFileReadProgressHandler != nullptr) {
unsigned char* byteBuffer = (unsigned char*)ptr;
size_t totalBytesRead = 0;
@@ -336,7 +326,7 @@ int fileReadInt32(File* stream, int* valuePtr)
return -1;
}
*valuePtr = ((value >> 24) & 0xFF) | ((value >> 8) & 0xFF00) | ((value << 8) & 0xFF0000) | ((value << 24) & 0xFF000000);
*valuePtr = ((value & 0xFF000000) >> 24) | ((value & 0xFF0000) >> 8) | ((value & 0xFF00) << 8) | ((value & 0xFF) << 24);
return 0;
}
@@ -509,7 +499,7 @@ int fileReadInt32List(File* stream, int* arr, int count)
for (int index = 0; index < count; index++) {
int value = arr[index];
arr[index] = ((value >> 24) & 0xFF) | ((value >> 8) & 0xFF00) | ((value << 8) & 0xFF0000) | ((value << 24) & 0xFF000000);
arr[index] = ((value & 0xFF000000) >> 24) | ((value & 0xFF0000) >> 8) | ((value & 0xFF00) << 8) | ((value & 0xFF) << 24);
}
return 0;
@@ -612,7 +602,7 @@ int fileWriteUInt32List(File* stream, unsigned int* arr, int count)
int fileNameListInit(const char* pattern, char*** fileNameListPtr, int a3, int a4)
{
FileList* fileList = (FileList*)malloc(sizeof(*fileList));
if (fileList == NULL) {
if (fileList == nullptr) {
return 0;
}
@@ -643,17 +633,18 @@ int fileNameListInit(const char* pattern, char*** fileNameListPtr, int a3, int a
bool isWildcard = *pattern == '*';
for (int index = 0; index < fileNamesLength; index += 1) {
const char* name = xlist->fileNames[index];
char* name = xlist->fileNames[index];
char dir[COMPAT_MAX_DIR];
char fileName[COMPAT_MAX_FNAME];
char extension[COMPAT_MAX_EXT];
compat_splitpath(name, NULL, dir, fileName, extension);
compat_windows_path_to_native(name);
compat_splitpath(name, nullptr, dir, fileName, extension);
if (!isWildcard || *dir == '\0' || strchr(dir, '\\') == NULL) {
if (!isWildcard || *dir == '\0' || (strchr(dir, '\\') == nullptr && strchr(dir, '/') == nullptr)) {
// NOTE: Quick and dirty fix to buffer overflow. See RE to
// understand the problem.
char path[COMPAT_MAX_PATH];
sprintf(path, "%s%s", fileName, extension);
snprintf(path, sizeof(path), "%s%s", fileName, extension);
free(xlist->fileNames[length]);
xlist->fileNames[length] = compat_strdup(path);
length++;
@@ -672,7 +663,7 @@ int fileNameListInit(const char* pattern, char*** fileNameListPtr, int a3, int a
// 0x4C6868
void fileNameListFree(char*** fileNameListPtr, int a2)
{
if (gFileListHead == NULL) {
if (gFileListHead == nullptr) {
return;
}
@@ -681,7 +672,7 @@ void fileNameListFree(char*** fileNameListPtr, int a2)
while (*fileNameListPtr != currentFileList->xlist.fileNames) {
previousFileList = currentFileList;
currentFileList = currentFileList->next;
if (currentFileList == NULL) {
if (currentFileList == nullptr) {
return;
}
}
@@ -697,14 +688,6 @@ void fileNameListFree(char*** fileNameListPtr, int a2)
free(currentFileList);
}
// NOTE: This function does nothing. It was probably used to set memory procs
// for building file name list.
//
// 0x4C68B8
void _db_register_mem(MallocProc* mallocProc, StrdupProc* strdupProc, FreeProc* freeProc)
{
}
// TODO: Return type should be long.
//
// 0x4C68BC
@@ -716,25 +699,19 @@ int fileGetSize(File* stream)
// 0x4C68C4
void fileSetReadProgressHandler(FileReadProgressHandler* handler, int size)
{
if (handler != NULL && size != 0) {
if (handler != nullptr && size != 0) {
gFileReadProgressHandler = handler;
gFileReadProgressChunkSize = size;
} else {
gFileReadProgressHandler = NULL;
gFileReadProgressHandler = nullptr;
gFileReadProgressChunkSize = 0;
}
}
// NOTE: This function is called when fallout2.cfg has "hashing" enabled, but
// it does nothing. It's impossible to guess it's name.
//
// 0x4C68E4
void _db_enable_hash_table_()
{
}
// 0x4C68E8
int _db_list_compare(const void* p1, const void* p2)
{
return compat_stricmp(*(const char**)p1, *(const char**)p2);
}
} // namespace fallout

View File

@@ -3,17 +3,16 @@
#include <stddef.h>
#include "memory_defs.h"
#include "xfile.h"
namespace fallout {
typedef XFile File;
typedef void FileReadProgressHandler();
typedef char* StrdupProc(const char* string);
int dbOpen(const char* filePath1, int a2, const char* filePath2, int a4);
int _db_select(int dbHandle);
int _db_current();
int _db_total();
int db_total();
void dbExit();
int dbGetFileSize(const char* filePath, int* sizePtr);
int dbGetFileContents(const char* filePath, void* ptr);
@@ -61,9 +60,9 @@ int _db_fwriteLongCount(File* stream, int* arr, int count);
int fileWriteUInt32List(File* stream, unsigned int* arr, int count);
int fileNameListInit(const char* pattern, char*** fileNames, int a3, int a4);
void fileNameListFree(char*** fileNames, int a2);
void _db_register_mem(MallocProc* mallocProc, StrdupProc* strdupProc, FreeProc* freeProc);
int fileGetSize(File* stream);
void fileSetReadProgressHandler(FileReadProgressHandler* handler, int size);
void _db_enable_hash_table_();
} // namespace fallout
#endif /* DB_H */

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,8 @@
#ifndef DBOX_H
#define DBOX_H
namespace fallout {
typedef enum DialogBoxOptions {
DIALOG_BOX_LARGE = 0x01,
DIALOG_BOX_MEDIUM = 0x02,
@@ -14,4 +16,6 @@ int showDialogBox(const char* title, const char** body, int bodyLength, int x, i
int showLoadFileDialog(char* title, char** fileList, char* dest, int fileListLength, int x, int y, int flags);
int showSaveFileDialog(char* title, char** fileList, char* dest, int fileListLength, int x, int y, int flags);
} // namespace fallout
#endif /* DBOX_H */

View File

@@ -5,15 +5,14 @@
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#include <SDL.h>
#include "memory.h"
#include "platform_compat.h"
#include "window_manager_private.h"
namespace fallout {
static int _debug_puts(char* string);
static void _debug_clear();
static int _debug_mono(char* string);
@@ -23,7 +22,7 @@ static void _debug_putc(int ch);
static void _debug_scroll();
// 0x51DEF8
static FILE* _fd = NULL;
static FILE* _fd = nullptr;
// 0x51DEFC
static int _curx = 0;
@@ -32,7 +31,7 @@ static int _curx = 0;
static int _cury = 0;
// 0x51DF04
static DebugPrintProc* gDebugPrintProc = NULL;
static DebugPrintProc* gDebugPrintProc = nullptr;
// 0x4C6CD0
void _GNW_debug_init()
@@ -44,9 +43,9 @@ void _GNW_debug_init()
void _debug_register_mono()
{
if (gDebugPrintProc != _debug_mono) {
if (_fd != NULL) {
if (_fd != nullptr) {
fclose(_fd);
_fd = NULL;
_fd = nullptr;
}
gDebugPrintProc = _debug_mono;
@@ -57,8 +56,8 @@ void _debug_register_mono()
// 0x4C6D18
void _debug_register_log(const char* fileName, const char* mode)
{
if ((mode[0] == 'w' && mode[1] == 'a') && mode[1] == 't') {
if (_fd != NULL) {
if ((mode[0] == 'w' || mode[0] == 'a') && mode[1] == 't') {
if (_fd != nullptr) {
fclose(_fd);
}
@@ -71,9 +70,9 @@ void _debug_register_log(const char* fileName, const char* mode)
void _debug_register_screen()
{
if (gDebugPrintProc != _debug_screen) {
if (_fd != NULL) {
if (_fd != nullptr) {
fclose(_fd);
_fd = NULL;
_fd = nullptr;
}
gDebugPrintProc = _debug_screen;
@@ -84,12 +83,12 @@ void _debug_register_screen()
void _debug_register_env()
{
const char* type = getenv("DEBUGACTIVE");
if (type == NULL) {
if (type == nullptr) {
return;
}
char* copy = (char*)internal_malloc(strlen(type) + 1);
if (copy == NULL) {
if (copy == nullptr) {
return;
}
@@ -105,14 +104,8 @@ void _debug_register_env()
// NOTE: Uninline.
_debug_register_screen();
} else if (strcmp(copy, "gnw") == 0) {
if (gDebugPrintProc != _win_debug) {
if (_fd != NULL) {
fclose(_fd);
_fd = NULL;
}
gDebugPrintProc = _win_debug;
}
// NOTE: Uninline.
_debug_register_func(_win_debug);
}
internal_free(copy);
@@ -122,9 +115,9 @@ void _debug_register_env()
void _debug_register_func(DebugPrintProc* proc)
{
if (gDebugPrintProc != proc) {
if (_fd != NULL) {
if (_fd != nullptr) {
fclose(_fd);
_fd = NULL;
_fd = nullptr;
}
gDebugPrintProc = proc;
@@ -139,20 +132,14 @@ int debugPrint(const char* format, ...)
int rc;
if (gDebugPrintProc != NULL) {
if (gDebugPrintProc != nullptr) {
char string[260];
vsprintf(string, format, args);
vsnprintf(string, sizeof(string), format, args);
rc = gDebugPrintProc(string);
} else {
#ifdef _DEBUG
char string[260];
vsprintf(string, format, args);
#ifdef _WIN32
OutputDebugStringA(string);
#else
printf("%s", string);
#endif
SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, format, args);
#endif
rc = -1;
}
@@ -165,7 +152,7 @@ int debugPrint(const char* format, ...)
// 0x4C6F94
static int _debug_puts(char* string)
{
if (gDebugPrintProc != NULL) {
if (gDebugPrintProc != nullptr) {
return gDebugPrintProc(string);
}
@@ -179,7 +166,7 @@ static void _debug_clear()
int x;
int y;
buffer = NULL;
buffer = nullptr;
if (gDebugPrintProc == _debug_mono) {
buffer = (char*)0xB0000;
@@ -187,7 +174,7 @@ static void _debug_clear()
buffer = (char*)0xB8000;
}
if (buffer != NULL) {
if (buffer != nullptr) {
for (y = 0; y < 25; y++) {
for (x = 0; x < 80; x++) {
*buffer++ = ' ';
@@ -215,7 +202,7 @@ static int _debug_mono(char* string)
static int _debug_log(char* string)
{
if (gDebugPrintProc == _debug_log) {
if (_fd == NULL) {
if (_fd == nullptr) {
return -1;
}
@@ -313,7 +300,9 @@ static void _debug_scroll()
// 0x4C71E8
void _debug_exit(void)
{
if (_fd != NULL) {
if (_fd != nullptr) {
fclose(_fd);
}
}
} // namespace fallout

View File

@@ -1,6 +1,8 @@
#ifndef DEBUG_H
#define DEBUG_H
namespace fallout {
typedef int(DebugPrintProc)(char* string);
void _GNW_debug_init();
@@ -12,4 +14,6 @@ void _debug_register_func(DebugPrintProc* proc);
int debugPrint(const char* format, ...);
void _debug_exit(void);
} // namespace fallout
#endif /* DEBUG_H */

11
src/delay.cc Normal file
View File

@@ -0,0 +1,11 @@
#include "delay.h"
#include <SDL.h>
void delay_ms(int ms)
{
if (ms <= 0) {
return;
}
SDL_Delay(ms);
}

6
src/delay.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef DELAY_H
#define DELAY_H
void delay_ms(int ms);
#endif

View File

@@ -5,10 +5,14 @@
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <fpattern.h>
#include "platform_compat.h"
namespace fallout {
// The size of decompression buffer for reading compressed [DFile]s.
#define DFILE_DECOMPRESSION_BUFFER_SIZE (0x400)
@@ -47,14 +51,14 @@ DBase* dbaseOpen(const char* filePath)
assert(filePath); // "filename", "dfile.c", 74
FILE* stream = compat_fopen(filePath, "rb");
if (stream == NULL) {
return NULL;
if (stream == nullptr) {
return nullptr;
}
DBase* dbase = (DBase*)malloc(sizeof(*dbase));
if (dbase == NULL) {
if (dbase == nullptr) {
fclose(stream);
return NULL;
return nullptr;
}
memset(dbase, 0, sizeof(*dbase));
@@ -91,7 +95,7 @@ DBase* dbaseOpen(const char* filePath)
}
dbase->entries = (DBaseEntry*)malloc(sizeof(*dbase->entries) * dbase->entriesLength);
if (dbase->entries == NULL) {
if (dbase->entries == nullptr) {
goto err;
}
@@ -108,7 +112,7 @@ DBase* dbaseOpen(const char* filePath)
}
entry->path = (char*)malloc(pathLength + 1);
if (entry->path == NULL) {
if (entry->path == nullptr) {
break;
}
@@ -154,7 +158,7 @@ err:
fclose(stream);
return NULL;
return nullptr;
}
// Closes [dbase], all open file handles, frees all associated resources,
@@ -166,24 +170,24 @@ bool dbaseClose(DBase* dbase)
assert(dbase); // "dbase", "dfile.c", 173
DFile* curr = dbase->dfileHead;
while (curr != NULL) {
while (curr != nullptr) {
DFile* next = curr->next;
dfileClose(curr);
curr = next;
}
if (dbase->entries != NULL) {
if (dbase->entries != nullptr) {
for (int index = 0; index < dbase->entriesLength; index++) {
DBaseEntry* entry = &(dbase->entries[index]);
char* entryName = entry->path;
if (entryName != NULL) {
if (entryName != nullptr) {
free(entryName);
}
}
free(dbase->entries);
}
if (dbase->path != NULL) {
if (dbase->path != nullptr) {
free(dbase->path);
}
@@ -254,15 +258,15 @@ int dfileClose(DFile* stream)
}
}
if (stream->decompressionStream != NULL) {
if (stream->decompressionStream != nullptr) {
free(stream->decompressionStream);
}
if (stream->decompressionBuffer != NULL) {
if (stream->decompressionBuffer != nullptr) {
free(stream->decompressionBuffer);
}
if (stream->stream != NULL) {
if (stream->stream != nullptr) {
fclose(stream->stream);
}
@@ -271,8 +275,8 @@ int dfileClose(DFile* stream)
//
// NOTE: Compiled code is slightly different.
DFile* curr = stream->dbase->dfileHead;
DFile* prev = NULL;
while (curr != NULL) {
DFile* prev = nullptr;
while (curr != nullptr) {
if (curr == stream) {
break;
}
@@ -281,8 +285,8 @@ int dfileClose(DFile* stream)
curr = curr->next;
}
if (curr != NULL) {
if (prev == NULL) {
if (curr != nullptr) {
if (prev == nullptr) {
stream->dbase->dfileHead = stream->next;
} else {
prev->next = stream->next;
@@ -305,7 +309,7 @@ DFile* dfileOpen(DBase* dbase, const char* filePath, const char* mode)
assert(filePath); // dfile.c, 296
assert(mode); // dfile.c, 297
return dfileOpenInternal(dbase, filePath, mode, 0);
return dfileOpenInternal(dbase, filePath, mode, nullptr);
}
// [vfprintf].
@@ -359,7 +363,7 @@ char* dfileReadString(char* string, int size, DFile* stream)
assert(stream); // "stream", "dfile.c", 409
if ((stream->flags & DFILE_EOF) != 0 || (stream->flags & DFILE_ERROR) != 0) {
return NULL;
return nullptr;
}
char* pch = string;
@@ -387,7 +391,7 @@ char* dfileReadString(char* string, int size, DFile* stream)
if (pch == string) {
// No character was set into the buffer.
return NULL;
return nullptr;
}
*pch = '\0';
@@ -629,7 +633,7 @@ static int dbaseFindEntryByFilePath(const void* a1, const void* a2)
static DFile* dfileOpenInternal(DBase* dbase, const char* filePath, const char* mode, DFile* dfile)
{
DBaseEntry* entry = (DBaseEntry*)bsearch(filePath, dbase->entries, dbase->entriesLength, sizeof(*dbase->entries), dbaseFindEntryByFilePath);
if (entry == NULL) {
if (entry == nullptr) {
goto err;
}
@@ -637,10 +641,10 @@ static DFile* dfileOpenInternal(DBase* dbase, const char* filePath, const char*
goto err;
}
if (dfile == NULL) {
if (dfile == nullptr) {
dfile = (DFile*)malloc(sizeof(*dfile));
if (dfile == NULL) {
return NULL;
if (dfile == nullptr) {
return nullptr;
}
memset(dfile, 0, sizeof(*dfile));
@@ -652,9 +656,9 @@ static DFile* dfileOpenInternal(DBase* dbase, const char* filePath, const char*
goto err;
}
if (dfile->stream != NULL) {
if (dfile->stream != nullptr) {
fclose(dfile->stream);
dfile->stream = NULL;
dfile->stream = nullptr;
}
dfile->compressedBytesRead = 0;
@@ -666,7 +670,7 @@ static DFile* dfileOpenInternal(DBase* dbase, const char* filePath, const char*
// Open stream to .DAT file.
dfile->stream = compat_fopen(dbase->path, "rb");
if (dfile->stream == NULL) {
if (dfile->stream == nullptr) {
goto err;
}
@@ -680,14 +684,14 @@ static DFile* dfileOpenInternal(DBase* dbase, const char* filePath, const char*
// buffer. This step is not needed when previous instance of dfile is
// passed via parameter, which might already have stream and
// buffer allocated.
if (dfile->decompressionStream == NULL) {
if (dfile->decompressionStream == nullptr) {
dfile->decompressionStream = (z_streamp)malloc(sizeof(*dfile->decompressionStream));
if (dfile->decompressionStream == NULL) {
if (dfile->decompressionStream == nullptr) {
goto err;
}
dfile->decompressionBuffer = (unsigned char*)malloc(DFILE_DECOMPRESSION_BUFFER_SIZE);
if (dfile->decompressionBuffer == NULL) {
if (dfile->decompressionBuffer == nullptr) {
goto err;
}
}
@@ -705,14 +709,14 @@ static DFile* dfileOpenInternal(DBase* dbase, const char* filePath, const char*
// Entry is not compressed, there is no need to keep decompression
// stream and decompression buffer (in case [dfile] was passed via
// parameter).
if (dfile->decompressionStream != NULL) {
if (dfile->decompressionStream != nullptr) {
free(dfile->decompressionStream);
dfile->decompressionStream = NULL;
dfile->decompressionStream = nullptr;
}
if (dfile->decompressionBuffer != NULL) {
if (dfile->decompressionBuffer != nullptr) {
free(dfile->decompressionBuffer);
dfile->decompressionBuffer = NULL;
dfile->decompressionBuffer = nullptr;
}
}
@@ -724,11 +728,11 @@ static DFile* dfileOpenInternal(DBase* dbase, const char* filePath, const char*
err:
if (dfile != NULL) {
if (dfile != nullptr) {
dfileClose(dfile);
}
return NULL;
return nullptr;
}
// 0x4E5F9C
@@ -816,10 +820,7 @@ static bool dfileReadCompressed(DFile* stream, void* ptr, size_t size)
if (stream->decompressionStream->avail_in == 0) {
// No more unprocessed data, request next chunk.
size_t bytesToRead = stream->entry->dataSize - stream->compressedBytesRead;
if (bytesToRead > DFILE_DECOMPRESSION_BUFFER_SIZE) {
bytesToRead = DFILE_DECOMPRESSION_BUFFER_SIZE;
}
size_t bytesToRead = std::min(DFILE_DECOMPRESSION_BUFFER_SIZE, stream->entry->dataSize - stream->compressedBytesRead);
if (fread(stream->decompressionBuffer, bytesToRead, 1, stream->stream) != 1) {
break;
@@ -852,3 +853,5 @@ static void dfileUngetCompressed(DFile* stream, int ch)
stream->flags |= DFILE_HAS_COMPRESSED_UNGETC;
stream->position--;
}
} // namespace fallout

View File

@@ -7,6 +7,8 @@
#include "platform_compat.h"
namespace fallout {
typedef struct DBase DBase;
typedef struct DBaseEntry DBaseEntry;
typedef struct DFile DFile;
@@ -128,4 +130,6 @@ long dfileTell(DFile* stream);
void dfileRewind(DFile* stream);
int dfileEof(DFile* stream);
} // namespace fallout
#endif /* DFILE_H */

View File

@@ -2,13 +2,16 @@
#include <string.h>
#include "core.h"
#include "memory_manager.h"
#include "mouse.h"
#include "movie.h"
#include "platform_compat.h"
#include "svga.h"
#include "text_font.h"
#include "window_manager.h"
namespace fallout {
// 0x501623
const float flt_501623 = 31.0;
@@ -25,10 +28,10 @@ int _topDialogLine = 0;
int _topDialogReply = 0;
// 0x5184E4
DialogFunc1* _replyWinDrawCallback = NULL;
DialogFunc1* _replyWinDrawCallback = nullptr;
// 0x5184E8
DialogFunc2* _optionsWinDrawCallback = NULL;
DialogFunc2* _optionsWinDrawCallback = nullptr;
// 0x5184EC
int gDialogBorderX = 7;
@@ -168,7 +171,7 @@ STRUCT_56DAE0_FIELD_4* _getReply()
STRUCT_56DAE0_FIELD_4_FIELD_C* v1;
v0 = &(_dialog[_tods].field_4[_dialog[_tods].field_C]);
if (v0->field_C == NULL) {
if (v0->field_C == nullptr) {
v0->field_14 = 1;
v1 = (STRUCT_56DAE0_FIELD_4_FIELD_C*)internal_malloc_safe(sizeof(STRUCT_56DAE0_FIELD_4_FIELD_C), __FILE__, __LINE__); // "..\\int\\DIALOG.C", 789
} else {
@@ -192,20 +195,20 @@ void _replyAddOption(const char* a1, const char* a2, int a3)
v17 = v18->field_14 - 1;
v18->field_C[v17].kind = 2;
if (a1 != NULL) {
if (a1 != nullptr) {
v14 = (char*)internal_malloc_safe(strlen(a1) + 1, __FILE__, __LINE__); // "..\\int\\DIALOG.C", 805
strcpy(v14, a1);
v18->field_C[v17].field_0 = v14;
} else {
v18->field_C[v17].field_0 = NULL;
v18->field_C[v17].field_0 = nullptr;
}
if (a2 != NULL) {
if (a2 != nullptr) {
v15 = (char*)internal_malloc_safe(strlen(a2) + 1, __FILE__, __LINE__); // "..\\int\\DIALOG.C", 810
strcpy(v15, a2);
v18->field_C[v17].string = v15;
} else {
v18->field_C[v17].string = NULL;
v18->field_C[v17].string = nullptr;
}
v18->field_C[v17].field_18 = windowGetFont();
@@ -225,12 +228,12 @@ void _replyAddOptionProc(const char* a1, int a2, int a3)
v5->field_C[v13].kind = 1;
if (a1 != NULL) {
if (a1 != nullptr) {
v11 = (char*)internal_malloc_safe(strlen(a1) + 1, __FILE__, __LINE__); // "..\\int\\DIALOG.C", 830
strcpy(v11, a1);
v5->field_C[v13].field_0 = v11;
} else {
v5->field_C[v13].field_0 = NULL;
v5->field_C[v13].field_0 = nullptr;
}
v5->field_C[v13].proc = a2;
@@ -243,12 +246,12 @@ void _replyAddOptionProc(const char* a1, int a2, int a3)
// 0x42F714
void _optionFree(STRUCT_56DAE0_FIELD_4_FIELD_C* a1)
{
if (a1->field_0 != NULL) {
if (a1->field_0 != nullptr) {
internal_free_safe(a1->field_0, __FILE__, __LINE__); // "..\\int\\DIALOG.C", 844
}
if (a1->kind == 2) {
if (a1->string != NULL) {
if (a1->string != nullptr) {
internal_free_safe(a1->string, __FILE__, __LINE__); // "..\\int\\DIALOG.C", 846
}
}
@@ -266,7 +269,7 @@ void _replyFree()
for (i = 0; i < ptr->field_8; i++) {
v6 = &(_dialog[_tods].field_4[i]);
if (v6->field_C != NULL) {
if (v6->field_C != nullptr) {
for (j = 0; j < v6->field_14; j++) {
_optionFree(&(v6->field_C[j]));
}
@@ -274,20 +277,20 @@ void _replyFree()
internal_free_safe(v6->field_C, __FILE__, __LINE__); // "..\\int\\DIALOG.C", 857
}
if (v6->field_8 != NULL) {
if (v6->field_8 != nullptr) {
internal_free_safe(v6->field_8, __FILE__, __LINE__); // "..\\int\\DIALOG.C", 860
}
if (v6->field_4 != NULL) {
if (v6->field_4 != nullptr) {
internal_free_safe(v6->field_4, __FILE__, __LINE__); // "..\\int\\DIALOG.C", 862
}
if (v6->field_0 != NULL) {
if (v6->field_0 != nullptr) {
internal_free_safe(v6->field_0, __FILE__, __LINE__); // "..\\int\\DIALOG.C", 864
}
}
if (ptr->field_4 != NULL) {
if (ptr->field_4 != nullptr) {
internal_free_safe(ptr->field_4, __FILE__, __LINE__); // "..\\int\\DIALOG.C", 867
}
}
@@ -302,9 +305,9 @@ int _endDialog()
_topDialogReply = _dialog[_tods].field_10;
_replyFree();
if (gDialogReplyTitle != NULL) {
if (gDialogReplyTitle != nullptr) {
internal_free_safe(gDialogReplyTitle, __FILE__, __LINE__); // "..\\int\\DIALOG.C", 986
gDialogReplyTitle = NULL;
gDialogReplyTitle = nullptr;
}
--_tods;
@@ -411,7 +414,7 @@ int _dialogStart(Program* a1)
ptr = &(_dialog[_tods]);
ptr->field_0 = a1;
ptr->field_4 = 0;
ptr->field_4 = nullptr;
ptr->field_8 = 0;
ptr->field_C = -1;
ptr->field_10 = -1;
@@ -446,11 +449,11 @@ int _dialogGotoReply(const char* a1)
return 1;
}
if (a1 != NULL) {
if (a1 != nullptr) {
ptr = &(_dialog[_tods]);
for (i = 0; i < ptr->field_8; i++) {
v5 = &(ptr->field_4[i]);
if (v5->field_4 != NULL && compat_stricmp(v5->field_4, a1) == 0) {
if (v5->field_4 != nullptr && compat_stricmp(v5->field_4, a1) == 0) {
ptr->field_10 = i;
return 0;
}
@@ -467,15 +470,15 @@ int _dialogGotoReply(const char* a1)
// 0x430E84
int dialogSetReplyTitle(const char* a1)
{
if (gDialogReplyTitle != NULL) {
if (gDialogReplyTitle != nullptr) {
internal_free_safe(gDialogReplyTitle, __FILE__, __LINE__); // "..\\int\\DIALOG.C", 2561
}
if (a1 != NULL) {
if (a1 != nullptr) {
gDialogReplyTitle = (char*)internal_malloc_safe(strlen(a1) + 1, __FILE__, __LINE__); // "..\\int\\DIALOG.C", 2564
strcpy(gDialogReplyTitle, a1);
} else {
gDialogReplyTitle = NULL;
gDialogReplyTitle = nullptr;
}
return 0;
@@ -583,22 +586,22 @@ int _dialogSetScrollUp(int a1, int a2, char* a3, char* a4, char* a5, char* a6, i
_upButton = a1;
dword_56DBD8 = a2;
if (off_56DBE0 != NULL) {
if (off_56DBE0 != nullptr) {
internal_free_safe(off_56DBE0, __FILE__, __LINE__); // "..\\int\\DIALOG.C", 2750
}
off_56DBE0 = a3;
if (off_56DBE4 != NULL) {
if (off_56DBE4 != nullptr) {
internal_free_safe(off_56DBE4, __FILE__, __LINE__); // "..\\int\\DIALOG.C", 2752
}
off_56DBE4 = a4;
if (off_56DBE8 != NULL) {
if (off_56DBE8 != nullptr) {
internal_free_safe(off_56DBE8, __FILE__, __LINE__); // "..\\int\\DIALOG.C", 2754
}
off_56DBE8 = a5;
if (off_56DBEC != NULL) {
if (off_56DBEC != nullptr) {
internal_free_safe(off_56DBEC, __FILE__, __LINE__); // "..\\int\\DIALOG.C", 2756
}
off_56DBEC = a5;
@@ -614,22 +617,22 @@ int _dialogSetScrollDown(int a1, int a2, char* a3, char* a4, char* a5, char* a6,
_downButton = a1;
dword_56DBB8 = a2;
if (off_56DBC0 != NULL) {
if (off_56DBC0 != nullptr) {
internal_free_safe(off_56DBC0, __FILE__, __LINE__); // "..\\int\\DIALOG.C", 2765
}
off_56DBC0 = a3;
if (off_56DBC4 != NULL) {
if (off_56DBC4 != nullptr) {
internal_free_safe(off_56DBC4, __FILE__, __LINE__); // "..\\int\\DIALOG.C", 2767
}
off_56DBC4 = a4;
if (off_56DBC8 != NULL) {
if (off_56DBC8 != nullptr) {
internal_free_safe(off_56DBC8, __FILE__, __LINE__); // "..\\int\\DIALOG.C", 2769
}
off_56DBC8 = a5;
if (off_56DBCC != NULL) {
if (off_56DBCC != nullptr) {
internal_free_safe(off_56DBCC, __FILE__, __LINE__); // "..\\int\\DIALOG.C", 2771
}
off_56DBCC = a6;
@@ -750,3 +753,5 @@ int _dialogGetMediaFlag()
{
return _mediaFlag;
}
} // namespace fallout

View File

@@ -3,6 +3,8 @@
#include "interpreter.h"
namespace fallout {
typedef void DialogFunc1(int win);
typedef void DialogFunc2(int win);
@@ -131,4 +133,6 @@ void _dialogRegisterWinDrawCallbacks(DialogFunc1* a1, DialogFunc2* a2);
int _dialogToggleMediaFlag(int a1);
int _dialogGetMediaFlag();
} // namespace fallout
#endif /* DIALOG_H */

View File

@@ -6,6 +6,8 @@
#include "platform_compat.h"
namespace fallout {
// NOTE: I guess this marker is used as a type discriminator for implementing
// nested dictionaries. That's why every dictionary-related function starts
// with a check for this value.
@@ -50,11 +52,11 @@ int dictionaryInit(Dictionary* dictionary, int initialCapacity, size_t valueSize
dictionary->valueSize = valueSize;
dictionary->entriesLength = 0;
if (io != NULL) {
if (io != nullptr) {
memcpy(&(dictionary->io), io, sizeof(*io));
} else {
dictionary->io.readProc = NULL;
dictionary->io.writeProc = NULL;
dictionary->io.readProc = nullptr;
dictionary->io.writeProc = nullptr;
dictionary->io.field_8 = 0;
dictionary->io.field_C = 0;
}
@@ -63,11 +65,11 @@ int dictionaryInit(Dictionary* dictionary, int initialCapacity, size_t valueSize
if (initialCapacity != 0) {
dictionary->entries = (DictionaryEntry*)gDictionaryMallocProc(sizeof(*dictionary->entries) * initialCapacity);
if (dictionary->entries == NULL) {
if (dictionary->entries == nullptr) {
rc = -1;
}
} else {
dictionary->entries = NULL;
dictionary->entries = nullptr;
}
if (rc != -1) {
@@ -89,7 +91,7 @@ int dictionarySetCapacity(Dictionary* dictionary, int newCapacity)
}
DictionaryEntry* entries = (DictionaryEntry*)gDictionaryReallocProc(dictionary->entries, sizeof(*dictionary->entries) * newCapacity);
if (entries == NULL) {
if (entries == nullptr) {
return -1;
}
@@ -108,16 +110,16 @@ int dictionaryFree(Dictionary* dictionary)
for (int index = 0; index < dictionary->entriesLength; index++) {
DictionaryEntry* entry = &(dictionary->entries[index]);
if (entry->key != NULL) {
if (entry->key != nullptr) {
gDictionaryFreeProc(entry->key);
}
if (entry->value != NULL) {
if (entry->value != nullptr) {
gDictionaryFreeProc(entry->value);
}
}
if (dictionary->entries != NULL) {
if (dictionary->entries != nullptr) {
gDictionaryFreeProc(dictionary->entries);
}
@@ -222,23 +224,23 @@ int dictionaryAddValue(Dictionary* dictionary, const char* key, const void* valu
// Make a copy of the key.
char* keyCopy = (char*)gDictionaryMallocProc(strlen(key) + 1);
if (keyCopy == NULL) {
if (keyCopy == nullptr) {
return -1;
}
strcpy(keyCopy, key);
// Make a copy of the value.
void* valueCopy = NULL;
if (value != NULL && dictionary->valueSize != 0) {
void* valueCopy = nullptr;
if (value != nullptr && dictionary->valueSize != 0) {
valueCopy = gDictionaryMallocProc(dictionary->valueSize);
if (valueCopy == NULL) {
if (valueCopy == nullptr) {
gDictionaryFreeProc(keyCopy);
return -1;
}
}
if (valueCopy != NULL && dictionary->valueSize != 0) {
if (valueCopy != nullptr && dictionary->valueSize != 0) {
memcpy(valueCopy, value, dictionary->valueSize);
}
@@ -280,7 +282,7 @@ int dictionaryRemoveValue(Dictionary* dictionary, const char* key)
// Free key and value (which are copies).
gDictionaryFreeProc(entry->key);
if (entry->value != NULL) {
if (entry->value != nullptr) {
gDictionaryFreeProc(entry->value);
}
@@ -395,16 +397,16 @@ int dictionaryLoad(FILE* stream, Dictionary* dictionary, int a3)
for (int index = 0; index < dictionary->entriesLength; index++) {
DictionaryEntry* entry = &(dictionary->entries[index]);
if (entry->key != NULL) {
if (entry->key != nullptr) {
gDictionaryFreeProc(entry->key);
}
if (entry->value != NULL) {
if (entry->value != nullptr) {
gDictionaryFreeProc(entry->value);
}
}
if (dictionary->entries != NULL) {
if (dictionary->entries != nullptr) {
gDictionaryFreeProc(dictionary->entries);
}
@@ -412,21 +414,21 @@ int dictionaryLoad(FILE* stream, Dictionary* dictionary, int a3)
return -1;
}
dictionary->entries = NULL;
dictionary->entries = nullptr;
if (dictionary->entriesCapacity <= 0) {
return 0;
}
dictionary->entries = (DictionaryEntry*)gDictionaryMallocProc(sizeof(*dictionary->entries) * dictionary->entriesCapacity);
if (dictionary->entries == NULL) {
if (dictionary->entries == nullptr) {
return -1;
}
for (int index = 0; index < dictionary->entriesLength; index++) {
DictionaryEntry* entry = &(dictionary->entries[index]);
entry->key = NULL;
entry->value = NULL;
entry->key = nullptr;
entry->value = nullptr;
}
if (dictionary->entriesLength <= 0) {
@@ -441,21 +443,21 @@ int dictionaryLoad(FILE* stream, Dictionary* dictionary, int a3)
}
entry->key = (char*)gDictionaryMallocProc(keyLength + 1);
if (entry->key == NULL) {
if (entry->key == nullptr) {
return -1;
}
if (fgets(entry->key, keyLength, stream) == NULL) {
if (compat_fgets(entry->key, keyLength + 1, stream) == nullptr) {
return -1;
}
if (dictionary->valueSize != 0) {
entry->value = gDictionaryMallocProc(dictionary->valueSize);
if (entry->value == NULL) {
if (entry->value == nullptr) {
return -1;
}
if (dictionary->io.readProc != NULL) {
if (dictionary->io.readProc != nullptr) {
if (dictionary->io.readProc(stream, entry->value, dictionary->valueSize, a3) != 0) {
return -1;
}
@@ -521,7 +523,7 @@ int dictionaryWrite(FILE* stream, Dictionary* dictionary, int a3)
return -1;
}
if (dictionary->io.writeProc != NULL) {
if (dictionary->io.writeProc != nullptr) {
if (dictionary->valueSize != 0) {
if (dictionary->io.writeProc(stream, entry->value, dictionary->valueSize, a3) != 0) {
return -1;
@@ -542,7 +544,7 @@ int dictionaryWrite(FILE* stream, Dictionary* dictionary, int a3)
// 0x4DA498
void dictionarySetMemoryProcs(MallocProc* mallocProc, ReallocProc* reallocProc, FreeProc* freeProc)
{
if (mallocProc != NULL && reallocProc != NULL && freeProc != NULL) {
if (mallocProc != nullptr && reallocProc != nullptr && freeProc != nullptr) {
gDictionaryMallocProc = mallocProc;
gDictionaryReallocProc = reallocProc;
gDictionaryFreeProc = freeProc;
@@ -552,3 +554,5 @@ void dictionarySetMemoryProcs(MallocProc* mallocProc, ReallocProc* reallocProc,
gDictionaryFreeProc = dictionaryFreeDefaultImpl;
}
}
} // namespace fallout

View File

@@ -5,6 +5,8 @@
#include "memory_defs.h"
namespace fallout {
typedef int(DictionaryReadProc)(FILE* stream, void* buffer, unsigned int size, int a4);
typedef int(DictionaryWriteProc)(FILE* stream, void* buffer, unsigned int size, int a4);
@@ -63,4 +65,6 @@ int dictionaryWriteHeader(FILE* stream, Dictionary* dictionary);
int dictionaryWrite(FILE* stream, Dictionary* dictionary, int a3);
void dictionarySetMemoryProcs(MallocProc* mallocProc, ReallocProc* reallocProc, FreeProc* freeProc);
} // namespace fallout
#endif /* DICTIONARY_H */

View File

@@ -1,29 +1,10 @@
#include "dinput.h"
enum InputType {
INPUT_TYPE_MOUSE,
INPUT_TYPE_TOUCH,
} InputType;
static int gLastInputType = INPUT_TYPE_MOUSE;
static int gTouchMouseLastX = 0;
static int gTouchMouseLastY = 0;
static int gTouchMouseDeltaX = 0;
static int gTouchMouseDeltaY = 0;
static int gTouchFingers = 0;
static unsigned int gTouchGestureLastTouchDownTimestamp = 0;
static unsigned int gTouchGestureLastTouchUpTimestamp = 0;
static int gTouchGestureTaps = 0;
static bool gTouchGestureHandled = false;
namespace fallout {
static int gMouseWheelDeltaX = 0;
static int gMouseWheelDeltaY = 0;
extern int screenGetWidth();
extern int screenGetHeight();
// 0x4E0400
bool directInputInit()
{
@@ -69,49 +50,22 @@ bool mouseDeviceUnacquire()
// 0x4E053C
bool mouseDeviceGetData(MouseData* mouseState)
{
if (gLastInputType == INPUT_TYPE_TOUCH) {
mouseState->x = gTouchMouseDeltaX;
mouseState->y = gTouchMouseDeltaY;
mouseState->buttons[0] = 0;
mouseState->buttons[1] = 0;
mouseState->wheelX = 0;
mouseState->wheelY = 0;
gTouchMouseDeltaX = 0;
gTouchMouseDeltaY = 0;
// CE: This function is sometimes called outside loops calling `get_input`
// and subsequently `GNW95_process_message`, so mouse events might not be
// handled by SDL yet.
//
// TODO: Move mouse events processing into `GNW95_process_message` and
// update mouse position manually.
SDL_PumpEvents();
if (gTouchFingers == 0) {
if (SDL_GetTicks() - gTouchGestureLastTouchUpTimestamp > 150) {
if (!gTouchGestureHandled) {
if (gTouchGestureTaps == 2) {
mouseState->buttons[0] = 1;
gTouchGestureHandled = true;
} else if (gTouchGestureTaps == 3) {
mouseState->buttons[1] = 1;
gTouchGestureHandled = true;
}
}
}
} else if (gTouchFingers == 1) {
if (SDL_GetTicks() - gTouchGestureLastTouchDownTimestamp > 150) {
if (gTouchGestureTaps == 1) {
mouseState->buttons[0] = 1;
gTouchGestureHandled = true;
} else if (gTouchGestureTaps == 2) {
mouseState->buttons[1] = 1;
gTouchGestureHandled = true;
}
}
}
} else {
Uint32 buttons = SDL_GetRelativeMouseState(&(mouseState->x), &(mouseState->y));
mouseState->buttons[0] = (buttons & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0;
mouseState->buttons[1] = (buttons & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0;
mouseState->wheelX = gMouseWheelDeltaX;
mouseState->wheelY = gMouseWheelDeltaY;
Uint32 buttons = SDL_GetRelativeMouseState(&(mouseState->x), &(mouseState->y));
mouseState->buttons[0] = (buttons & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0;
mouseState->buttons[1] = (buttons & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0;
mouseState->wheelX = gMouseWheelDeltaX;
mouseState->wheelY = gMouseWheelDeltaY;
gMouseWheelDeltaX = 0;
gMouseWheelDeltaY = 0;
}
gMouseWheelDeltaX = 0;
gMouseWheelDeltaY = 0;
return true;
}
@@ -172,68 +126,6 @@ void handleMouseEvent(SDL_Event* event)
gMouseWheelDeltaX += event->wheel.x;
gMouseWheelDeltaY += event->wheel.y;
}
if (gLastInputType != INPUT_TYPE_MOUSE) {
// Reset touch data.
gTouchMouseLastX = 0;
gTouchMouseLastY = 0;
gTouchMouseDeltaX = 0;
gTouchMouseDeltaY = 0;
gTouchFingers = 0;
gTouchGestureLastTouchDownTimestamp = 0;
gTouchGestureLastTouchUpTimestamp = 0;
gTouchGestureTaps = 0;
gTouchGestureHandled = false;
gLastInputType = INPUT_TYPE_MOUSE;
}
}
void handleTouchEvent(SDL_Event* event)
{
int windowWidth = screenGetWidth();
int windowHeight = screenGetHeight();
if (event->tfinger.type == SDL_FINGERDOWN) {
gTouchFingers++;
gTouchMouseLastX = (int)(event->tfinger.x * windowWidth);
gTouchMouseLastY = (int)(event->tfinger.y * windowHeight);
gTouchMouseDeltaX = 0;
gTouchMouseDeltaY = 0;
if (event->tfinger.timestamp - gTouchGestureLastTouchDownTimestamp > 250) {
gTouchGestureTaps = 0;
gTouchGestureHandled = false;
}
gTouchGestureLastTouchDownTimestamp = event->tfinger.timestamp;
} else if (event->tfinger.type == SDL_FINGERMOTION) {
int prevX = gTouchMouseLastX;
int prevY = gTouchMouseLastY;
gTouchMouseLastX = (int)(event->tfinger.x * windowWidth);
gTouchMouseLastY = (int)(event->tfinger.y * windowHeight);
gTouchMouseDeltaX += gTouchMouseLastX - prevX;
gTouchMouseDeltaY += gTouchMouseLastY - prevY;
} else if (event->tfinger.type == SDL_FINGERUP) {
gTouchFingers--;
int prevX = gTouchMouseLastX;
int prevY = gTouchMouseLastY;
gTouchMouseLastX = (int)(event->tfinger.x * windowWidth);
gTouchMouseLastY = (int)(event->tfinger.y * windowHeight);
gTouchMouseDeltaX += gTouchMouseLastX - prevX;
gTouchMouseDeltaY += gTouchMouseLastY - prevY;
gTouchGestureTaps++;
gTouchGestureLastTouchUpTimestamp = event->tfinger.timestamp;
}
if (gLastInputType != INPUT_TYPE_TOUCH) {
// Reset mouse data.
SDL_GetRelativeMouseState(NULL, NULL);
gLastInputType = INPUT_TYPE_TOUCH;
}
}
} // namespace fallout

View File

@@ -3,6 +3,8 @@
#include <SDL.h>
namespace fallout {
typedef struct MouseData {
int x;
int y;
@@ -33,4 +35,6 @@ void keyboardDeviceFree();
void handleMouseEvent(SDL_Event* event);
void handleTouchEvent(SDL_Event* event);
} // namespace fallout
#endif /* DINPUT_H */

View File

@@ -7,17 +7,20 @@
#include "art.h"
#include "color.h"
#include "combat.h"
#include "core.h"
#include "draw.h"
#include "game_mouse.h"
#include "game_sound.h"
#include "geometry.h"
#include "input.h"
#include "interface.h"
#include "memory.h"
#include "sfall_config.h"
#include "svga.h"
#include "text_font.h"
#include "window_manager.h"
namespace fallout {
// The maximum number of lines display monitor can hold. Once this value
// is reached earlier messages are thrown away.
#define DISPLAY_MONITOR_LINES_CAPACITY (100)
@@ -27,7 +30,7 @@
#define DISPLAY_MONITOR_X (23)
#define DISPLAY_MONITOR_Y (24)
#define DISPLAY_MONITOR_WIDTH (167)
#define DISPLAY_MONITOR_WIDTH (167 + gInterfaceBarContentOffset)
#define DISPLAY_MONITOR_HEIGHT (60)
#define DISPLAY_MONITOR_HALF_HEIGHT (DISPLAY_MONITOR_HEIGHT / 2)
@@ -56,12 +59,7 @@ static bool gDisplayMonitorInitialized = false;
// The rectangle that display monitor occupies in the main interface window.
//
// 0x518510
static const Rect gDisplayMonitorRect = {
DISPLAY_MONITOR_X,
DISPLAY_MONITOR_Y,
DISPLAY_MONITOR_X + DISPLAY_MONITOR_WIDTH - 1,
DISPLAY_MONITOR_Y + DISPLAY_MONITOR_HEIGHT - 1,
};
static Rect gDisplayMonitorRect;
// 0x518520
static int gDisplayMonitorScrollDownButton = -1;
@@ -103,6 +101,13 @@ static int gConsoleFilePrintCount = 0;
int displayMonitorInit()
{
if (!gDisplayMonitorInitialized) {
gDisplayMonitorRect = {
DISPLAY_MONITOR_X,
DISPLAY_MONITOR_Y,
DISPLAY_MONITOR_X + DISPLAY_MONITOR_WIDTH - 1,
DISPLAY_MONITOR_Y + DISPLAY_MONITOR_HEIGHT - 1,
};
int oldFont = fontGetCurrent();
fontSetCurrent(DISPLAY_MONITOR_FONT);
@@ -113,29 +118,37 @@ int displayMonitorInit()
fontSetCurrent(oldFont);
gDisplayMonitorBackgroundFrmData = (unsigned char*)internal_malloc(DISPLAY_MONITOR_WIDTH * DISPLAY_MONITOR_HEIGHT);
if (gDisplayMonitorBackgroundFrmData == NULL) {
if (gDisplayMonitorBackgroundFrmData == nullptr) {
return -1;
}
CacheEntry* backgroundFrmHandle;
int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, 16, 0, 0, 0);
Art* backgroundFrm = artLock(backgroundFid, &backgroundFrmHandle);
if (backgroundFrm == NULL) {
internal_free(gDisplayMonitorBackgroundFrmData);
return -1;
if (gInterfaceBarIsCustom) {
_intface_full_width = gInterfaceBarWidth;
blitBufferToBuffer(customInterfaceBarGetBackgroundImageData() + gInterfaceBarWidth * DISPLAY_MONITOR_Y + DISPLAY_MONITOR_X,
DISPLAY_MONITOR_WIDTH,
DISPLAY_MONITOR_HEIGHT,
gInterfaceBarWidth,
gDisplayMonitorBackgroundFrmData,
DISPLAY_MONITOR_WIDTH);
} else {
FrmImage backgroundFrmImage;
int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, 16, 0, 0, 0);
if (!backgroundFrmImage.lock(backgroundFid)) {
internal_free(gDisplayMonitorBackgroundFrmData);
return -1;
}
unsigned char* backgroundFrmData = backgroundFrmImage.getData();
_intface_full_width = backgroundFrmImage.getWidth();
blitBufferToBuffer(backgroundFrmData + _intface_full_width * DISPLAY_MONITOR_Y + DISPLAY_MONITOR_X,
DISPLAY_MONITOR_WIDTH,
DISPLAY_MONITOR_HEIGHT,
_intface_full_width,
gDisplayMonitorBackgroundFrmData,
DISPLAY_MONITOR_WIDTH);
}
unsigned char* backgroundFrmData = artGetFrameData(backgroundFrm, 0, 0);
_intface_full_width = artGetWidth(backgroundFrm, 0, 0);
blitBufferToBuffer(backgroundFrmData + _intface_full_width * DISPLAY_MONITOR_Y + DISPLAY_MONITOR_X,
DISPLAY_MONITOR_WIDTH,
DISPLAY_MONITOR_HEIGHT,
_intface_full_width,
gDisplayMonitorBackgroundFrmData,
DISPLAY_MONITOR_WIDTH);
artUnlock(backgroundFrmHandle);
gDisplayMonitorScrollUpButton = buttonCreate(gInterfaceBarWindow,
DISPLAY_MONITOR_X,
DISPLAY_MONITOR_Y,
@@ -145,16 +158,16 @@ int displayMonitorInit()
-1,
-1,
-1,
NULL,
NULL,
NULL,
nullptr,
nullptr,
nullptr,
0);
if (gDisplayMonitorScrollUpButton != -1) {
buttonSetMouseCallbacks(gDisplayMonitorScrollUpButton,
displayMonitorScrollUpOnMouseEnter,
displayMonitorOnMouseExit,
displayMonitorScrollUpOnMouseDown,
NULL);
nullptr);
}
gDisplayMonitorScrollDownButton = buttonCreate(gInterfaceBarWindow,
@@ -166,16 +179,16 @@ int displayMonitorInit()
-1,
-1,
-1,
NULL,
NULL,
NULL,
nullptr,
nullptr,
nullptr,
0);
if (gDisplayMonitorScrollDownButton != -1) {
buttonSetMouseCallbacks(gDisplayMonitorScrollDownButton,
displayMonitorScrollDownOnMouseEnter,
displayMonitorOnMouseExit,
displayMonitorScrollDownOnMouseDown,
NULL);
nullptr);
}
gDisplayMonitorEnabled = true;
@@ -244,7 +257,7 @@ void displayMonitorAddMessage(char* str)
}
// TODO: Refactor these two loops.
char* v1 = NULL;
char* v1 = nullptr;
while (true) {
while (fontGetStringWidth(str) < DISPLAY_MONITOR_WIDTH - _max_disp - knobWidth) {
char* temp = gDisplayMonitorLines[_disp_start];
@@ -261,7 +274,7 @@ void displayMonitorAddMessage(char* str)
gDisplayMonitorLines[_disp_start][DISPLAY_MONITOR_LINE_LENGTH - 1] = '\0';
_disp_start = (_disp_start + 1) % gDisplayMonitorLinesCapacity;
if (v1 == NULL) {
if (v1 == nullptr) {
fontSetCurrent(oldFont);
_disp_curr = _disp_start;
displayMonitorRefresh();
@@ -270,20 +283,20 @@ void displayMonitorAddMessage(char* str)
str = v1 + 1;
*v1 = ' ';
v1 = NULL;
v1 = nullptr;
}
char* space = strrchr(str, ' ');
if (space == NULL) {
if (space == nullptr) {
break;
}
if (v1 != NULL) {
if (v1 != nullptr) {
*v1 = ' ';
}
v1 = space;
if (space != NULL) {
if (space != nullptr) {
*space = '\0';
}
}
@@ -334,7 +347,7 @@ static void displayMonitorRefresh()
}
unsigned char* buf = windowGetBuffer(gInterfaceBarWindow);
if (buf == NULL) {
if (buf == nullptr) {
return;
}
@@ -425,11 +438,11 @@ static void consoleFileInit()
{
char* consoleFilePath;
configGetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_CONSOLE_OUTPUT_FILE_KEY, &consoleFilePath);
if (consoleFilePath != NULL && *consoleFilePath == '\0') {
consoleFilePath = NULL;
if (consoleFilePath != nullptr && *consoleFilePath == '\0') {
consoleFilePath = nullptr;
}
if (consoleFilePath != NULL) {
if (consoleFilePath != nullptr) {
gConsoleFileStream.open(consoleFilePath);
}
}
@@ -468,3 +481,5 @@ static void consoleFileFlush()
gConsoleFileStream.flush();
}
}
} // namespace fallout

View File

@@ -1,6 +1,8 @@
#ifndef DISPLAY_MONITOR_H
#define DISPLAY_MONITOR_H
namespace fallout {
int displayMonitorInit();
int displayMonitorReset();
void displayMonitorExit();
@@ -8,4 +10,6 @@ void displayMonitorAddMessage(char* string);
void displayMonitorDisable();
void displayMonitorEnable();
} // namespace fallout
#endif /* DISPLAY_MONITOR_H */

View File

@@ -3,8 +3,9 @@
#include <string.h>
#include "color.h"
#include "core.h"
#include "mmx.h"
#include "svga.h"
namespace fallout {
// 0x4D2FC0
void bufferDrawLine(unsigned char* buf, int pitch, int x1, int y1, int x2, int y2, int color)
@@ -26,7 +27,7 @@ void bufferDrawLine(unsigned char* buf, int pitch, int x1, int y1, int x2, int y
p1 = buf + pitch * y1 + x1;
p2 = buf + pitch * y2 + x2;
while (p1 < p2) {
while (p1 <= p2) {
*p1 = color;
*p2 = color;
p1 += pitch;
@@ -150,87 +151,69 @@ void bufferDrawRectShadowed(unsigned char* buf, int pitch, int left, int top, in
// 0x4D33F0
void blitBufferToBufferStretch(unsigned char* src, int srcWidth, int srcHeight, int srcPitch, unsigned char* dest, int destWidth, int destHeight, int destPitch)
{
int heightRatio = (destHeight << 16) / srcHeight;
int widthRatio = (destWidth << 16) / srcWidth;
int stepX = (destWidth << 16) / srcWidth;
int stepY = (destHeight << 16) / srcHeight;
int v1 = 0;
int v2 = heightRatio;
for (int srcY = 0; srcY < srcHeight; srcY += 1) {
int v3 = widthRatio;
int v4 = (heightRatio * srcY) >> 16;
int v5 = v2 >> 16;
int v6 = 0;
int startDestY = (srcY * stepY) >> 16;
int endDestY = ((srcY + 1) * stepY) >> 16;
unsigned char* c = src + v1;
unsigned char* currSrc = src + srcPitch * srcY;
for (int srcX = 0; srcX < srcWidth; srcX += 1) {
int v7 = v3 >> 16;
int v8 = v6 >> 16;
int startDestX = (srcX * stepX) >> 16;
int endDestX = ((srcX + 1) * stepX) >> 16;
unsigned char* v9 = dest + destPitch * v4 + v8;
for (int destY = v4; destY < v5; destY += 1) {
for (int destX = v8; destX < v7; destX += 1) {
*v9++ = *c;
for (int destY = startDestY; destY < endDestY; destY += 1) {
unsigned char* currDest = dest + destPitch * destY + startDestX;
for (int destX = startDestX; destX < endDestX; destX += 1) {
*currDest++ = *currSrc;
}
v9 += destPitch;
}
v3 += widthRatio;
c++;
v6 += widthRatio;
currSrc++;
}
v1 += srcPitch;
v2 += heightRatio;
}
}
// 0x4D3560
void blitBufferToBufferStretchTrans(unsigned char* src, int srcWidth, int srcHeight, int srcPitch, unsigned char* dest, int destWidth, int destHeight, int destPitch)
{
int heightRatio = (destHeight << 16) / srcHeight;
int widthRatio = (destWidth << 16) / srcWidth;
int stepX = (destWidth << 16) / srcWidth;
int stepY = (destHeight << 16) / srcHeight;
int v1 = 0;
int v2 = heightRatio;
for (int srcY = 0; srcY < srcHeight; srcY += 1) {
int v3 = widthRatio;
int v4 = (heightRatio * srcY) >> 16;
int v5 = v2 >> 16;
int v6 = 0;
int startDestY = (srcY * stepY) >> 16;
int endDestY = ((srcY + 1) * stepY) >> 16;
unsigned char* c = src + v1;
unsigned char* currSrc = src + srcPitch * srcY;
for (int srcX = 0; srcX < srcWidth; srcX += 1) {
int v7 = v3 >> 16;
int v8 = v6 >> 16;
int startDestX = (srcX * stepX) >> 16;
int endDestX = ((srcX + 1) * stepX) >> 16;
if (*c != 0) {
unsigned char* v9 = dest + destPitch * v4 + v8;
for (int destY = v4; destY < v5; destY += 1) {
for (int destX = v8; destX < v7; destX += 1) {
*v9++ = *c;
if (*currSrc != 0) {
for (int destY = startDestY; destY < endDestY; destY += 1) {
unsigned char* currDest = dest + destPitch * destY + startDestX;
for (int destX = startDestX; destX < endDestX; destX += 1) {
*currDest++ = *currSrc;
}
v9 += destPitch;
}
}
v3 += widthRatio;
c++;
v6 += widthRatio;
currSrc++;
}
v1 += srcPitch;
v2 += heightRatio;
}
}
// 0x4D36D4
void blitBufferToBuffer(unsigned char* src, int width, int height, int srcPitch, unsigned char* dest, int destPitch)
{
mmxBlit(dest, destPitch, src, srcPitch, width, height);
srcCopy(dest, destPitch, src, srcPitch, width, height);
}
// 0x4D3704
void blitBufferToBufferTrans(unsigned char* src, int width, int height, int srcPitch, unsigned char* dest, int destPitch)
{
mmxBlitTrans(dest, destPitch, src, srcPitch, width, height);
transSrcCopy(dest, destPitch, src, srcPitch, width, height);
}
// 0x4D387C
@@ -257,8 +240,8 @@ void _lighten_buf(unsigned char* buf, int width, int height, int pitch)
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
unsigned char p = *buf;
*buf++ = _intensityColorTable[(p << 8) + 147];
unsigned char color = *buf;
*buf++ = intensityColorTable[color][147];
}
buf += skip;
}
@@ -326,3 +309,34 @@ void bufferOutline(unsigned char* buf, int width, int height, int pitch, int col
}
}
}
// 0x4E0DB0
void srcCopy(unsigned char* dest, int destPitch, unsigned char* src, int srcPitch, int width, int height)
{
for (int y = 0; y < height; y++) {
memcpy(dest, src, width);
dest += destPitch;
src += srcPitch;
}
}
// 0x4E0ED5
void transSrcCopy(unsigned char* dest, int destPitch, unsigned char* src, int srcPitch, int width, int height)
{
int destSkip = destPitch - width;
int srcSkip = srcPitch - width;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
unsigned char c = *src++;
if (c != 0) {
*dest = c;
}
dest++;
}
src += srcSkip;
dest += destSkip;
}
}
} // namespace fallout

View File

@@ -1,6 +1,8 @@
#ifndef DRAW_H
#define DRAW_H
namespace fallout {
void bufferDrawLine(unsigned char* buf, int pitch, int left, int top, int right, int bottom, int color);
void bufferDrawRect(unsigned char* buf, int a2, int a3, int a4, int a5, int a6, int a7);
void bufferDrawRectShadowed(unsigned char* buf, int a2, int a3, int a4, int a5, int a6, int a7, int a8);
@@ -13,5 +15,9 @@ void _buf_texture(unsigned char* buf, int width, int height, int pitch, void* a5
void _lighten_buf(unsigned char* buf, int width, int height, int pitch);
void _swap_color_buf(unsigned char* buf, int width, int height, int pitch, int color1, int color2);
void bufferOutline(unsigned char* buf, int width, int height, int pitch, int a5);
void srcCopy(unsigned char* dest, int destPitch, unsigned char* src, int srcPitch, int width, int height);
void transSrcCopy(unsigned char* dest, int destPitch, unsigned char* src, int srcPitch, int width, int height);
} // namespace fallout
#endif /* DRAW_H */

View File

@@ -1,47 +0,0 @@
#include "electronic_registration.h"
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#include "game_config.h"
#include "platform_compat.h"
// 0x440DD0
void runElectronicRegistration()
{
int timesRun = 0;
configGetInt(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_TIMES_RUN_KEY, &timesRun);
if (timesRun > 0 && timesRun < 5) {
#ifdef _WIN32
char path[COMPAT_MAX_PATH];
if (GetModuleFileNameA(NULL, path, sizeof(path)) != 0) {
char* pch = strrchr(path, '\\');
if (pch == NULL) {
pch = path;
}
strcpy(pch, "\\ereg");
STARTUPINFOA startupInfo;
memset(&startupInfo, 0, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
PROCESS_INFORMATION processInfo;
// FIXME: Leaking processInfo.hProcess and processInfo.hThread:
// https://docs.microsoft.com/en-us/cpp/code-quality/c6335.
if (CreateProcessA("ereg\\reg32a.exe", NULL, NULL, NULL, FALSE, 0, NULL, path, &startupInfo, &processInfo)) {
WaitForSingleObject(processInfo.hProcess, INFINITE);
}
}
#endif
configSetInt(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_TIMES_RUN_KEY, timesRun + 1);
} else {
if (timesRun == 0) {
configSetInt(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_TIMES_RUN_KEY, 1);
}
}
}

View File

@@ -1,6 +0,0 @@
#ifndef ELECTRONIC_REGISTRATION_H
#define ELECTRONIC_REGISTRATION_H
void runElectronicRegistration();
#endif /* ELECTRONIC_REGISTRATION_H */

View File

@@ -6,29 +6,28 @@
#include <algorithm>
#include "art.h"
#include "core.h"
#include "cycle.h"
#include "debug.h"
#include "delay.h"
#include "draw.h"
#include "game_mouse.h"
#include "game_sound.h"
#include "geometry.h"
#include "input.h"
#include "interface.h"
#include "kb.h"
#include "map.h"
#include "pipboy.h"
#include "scripts.h"
#include "sfall_config.h"
#include "svga.h"
#include "window_manager.h"
namespace fallout {
// The maximum number of elevator levels.
#define ELEVATOR_LEVEL_MAX (4)
// NOTE: There are two variables which hold background data used in the
// elevator window - [gElevatorBackgroundFrmData] and [gElevatorPanelFrmData].
// For unknown reason they are using -1 to denote that they are not set
// (instead of using NULL).
#define ELEVATOR_BACKGROUND_NULL ((unsigned char*)(-1))
// Max number of elevators that can be loaded from elevators.ini. This limit is
// emposed by Sfall.
#define ELEVATORS_MAX 50
@@ -320,47 +319,18 @@ static const char* gElevatorSoundEffects[ELEVATOR_LEVEL_MAX - 1][ELEVATOR_LEVEL_
},
};
// 0x570A2C
static Size gElevatorFrmSizes[ELEVATOR_FRM_COUNT];
// 0x570A44
static int gElevatorBackgroundFrmWidth;
// 0x570A48
static int gElevatorBackgroundFrmHeight;
// 0x570A4C
static int gElevatorPanelFrmWidth;
// 0x570A50
static int gElevatorPanelFrmHeight;
// 0x570A54
static int gElevatorWindow;
// 0x570A58
static CacheEntry* gElevatorFrmHandles[ELEVATOR_FRM_COUNT];
// 0x570A64
static CacheEntry* gElevatorBackgroundFrmHandle;
// 0x570A68
static CacheEntry* gElevatorPanelFrmHandle;
// 0x570A6C
static unsigned char* gElevatorWindowBuffer;
// 0x570A70
static bool gElevatorWindowIsoWasEnabled;
// 0x570A74
static unsigned char* gElevatorFrmData[ELEVATOR_FRM_COUNT];
// 0x570A80
static unsigned char* gElevatorBackgroundFrmData;
// 0x570A84
static unsigned char* gElevatorPanelFrmData;
static FrmImage _elevatorFrmImages[ELEVATOR_FRM_COUNT];
static FrmImage _elevatorBackgroundFrmImage;
static FrmImage _elevatorPanelFrmImage;
// Presents elevator dialog for player to pick a desired level.
//
@@ -411,21 +381,23 @@ int elevatorSelectLevel(int elevator, int* mapPtr, int* elevationPtr, int* tileP
debugPrint("\n the start elev level %d\n", *elevationPtr);
int v18 = (gElevatorFrmSizes[ELEVATOR_FRM_GAUGE].width * gElevatorFrmSizes[ELEVATOR_FRM_GAUGE].height) / 13;
int v18 = (_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getWidth() * _elevatorFrmImages[ELEVATOR_FRM_GAUGE].getHeight()) / 13;
float v42 = 12.0f / (float)(gElevatorLevels[elevator] - 1);
blitBufferToBuffer(
gElevatorFrmData[ELEVATOR_FRM_GAUGE] + v18 * (int)((float)(*elevationPtr) * v42),
gElevatorFrmSizes[ELEVATOR_FRM_GAUGE].width,
gElevatorFrmSizes[ELEVATOR_FRM_GAUGE].height / 13,
gElevatorFrmSizes[ELEVATOR_FRM_GAUGE].width,
gElevatorWindowBuffer + gElevatorBackgroundFrmWidth * 41 + 121,
gElevatorBackgroundFrmWidth);
_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getData() + v18 * (int)((float)(*elevationPtr) * v42),
_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getWidth(),
_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getHeight() / 13,
_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getWidth(),
gElevatorWindowBuffer + _elevatorBackgroundFrmImage.getWidth() * 41 + 121,
_elevatorBackgroundFrmImage.getWidth());
windowRefresh(gElevatorWindow);
bool done = false;
int keyCode;
while (!done) {
keyCode = _get_input();
sharedFpsLimiter.mark();
keyCode = inputGetInput();
if (keyCode == KEY_ESCAPE) {
done = true;
}
@@ -441,6 +413,9 @@ int elevatorSelectLevel(int elevator, int* mapPtr, int* elevationPtr, int* tileP
done = true;
}
}
renderPresent();
sharedFpsLimiter.throttle();
}
if (keyCode != KEY_ESCAPE) {
@@ -465,23 +440,27 @@ int elevatorSelectLevel(int elevator, int* mapPtr, int* elevationPtr, int* tileP
float v41 = (float)keyCode * v42;
float v44 = (float)(*elevationPtr) * v42;
do {
unsigned int tick = _get_time();
sharedFpsLimiter.mark();
unsigned int tick = getTicks();
v44 += v43;
blitBufferToBuffer(
gElevatorFrmData[ELEVATOR_FRM_GAUGE] + v18 * (int)v44,
gElevatorFrmSizes[ELEVATOR_FRM_GAUGE].width,
gElevatorFrmSizes[ELEVATOR_FRM_GAUGE].height / 13,
gElevatorFrmSizes[ELEVATOR_FRM_GAUGE].width,
gElevatorWindowBuffer + gElevatorBackgroundFrmWidth * 41 + 121,
gElevatorBackgroundFrmWidth);
_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getData() + v18 * (int)v44,
_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getWidth(),
_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getHeight() / 13,
_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getWidth(),
gElevatorWindowBuffer + _elevatorBackgroundFrmImage.getWidth() * 41 + 121,
_elevatorBackgroundFrmImage.getWidth());
windowRefresh(gElevatorWindow);
while (getTicksSince(tick) < delay) {
}
delay_ms(delay - (getTicks() - tick));
renderPresent();
sharedFpsLimiter.throttle();
} while ((v43 <= 0.0 || v44 < v41) && (v43 > 0.0 || v44 > v41));
coreDelayProcessingEvents(200);
inputPauseForTocks(200);
}
}
@@ -512,15 +491,14 @@ static int elevatorWindowInit(int elevator)
int index;
for (index = 0; index < ELEVATOR_FRM_COUNT; index++) {
int fid = buildFid(OBJ_TYPE_INTERFACE, gElevatorFrmIds[index], 0, 0, 0);
gElevatorFrmData[index] = artLockFrameDataReturningSize(fid, &(gElevatorFrmHandles[index]), &(gElevatorFrmSizes[index].width), &(gElevatorFrmSizes[index].height));
if (gElevatorFrmData[index] == NULL) {
if (!_elevatorFrmImages[index].lock(fid)) {
break;
}
}
if (index != ELEVATOR_FRM_COUNT) {
for (int reversedIndex = index - 1; reversedIndex >= 0; reversedIndex--) {
artUnlock(gElevatorFrmHandles[reversedIndex]);
_elevatorFrmImages[reversedIndex].unlock();
}
if (gElevatorWindowIsoWasEnabled) {
@@ -532,39 +510,27 @@ static int elevatorWindowInit(int elevator)
return -1;
}
gElevatorPanelFrmData = ELEVATOR_BACKGROUND_NULL;
gElevatorBackgroundFrmData = ELEVATOR_BACKGROUND_NULL;
const ElevatorBackground* elevatorBackground = &(gElevatorBackgrounds[elevator]);
bool backgroundsLoaded = true;
int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, elevatorBackground->backgroundFrmId, 0, 0, 0);
gElevatorBackgroundFrmData = artLockFrameDataReturningSize(backgroundFid, &gElevatorBackgroundFrmHandle, &gElevatorBackgroundFrmWidth, &gElevatorBackgroundFrmHeight);
if (gElevatorBackgroundFrmData != NULL) {
if (_elevatorBackgroundFrmImage.lock(backgroundFid)) {
if (elevatorBackground->panelFrmId != -1) {
int panelFid = buildFid(OBJ_TYPE_INTERFACE, elevatorBackground->panelFrmId, 0, 0, 0);
gElevatorPanelFrmData = artLockFrameDataReturningSize(panelFid, &gElevatorPanelFrmHandle, &gElevatorPanelFrmWidth, &gElevatorPanelFrmHeight);
if (gElevatorPanelFrmData == NULL) {
gElevatorPanelFrmData = ELEVATOR_BACKGROUND_NULL;
if (!_elevatorPanelFrmImage.lock(panelFid)) {
backgroundsLoaded = false;
}
}
} else {
gElevatorBackgroundFrmData = ELEVATOR_BACKGROUND_NULL;
backgroundsLoaded = false;
}
if (!backgroundsLoaded) {
if (gElevatorBackgroundFrmData != ELEVATOR_BACKGROUND_NULL) {
artUnlock(gElevatorBackgroundFrmHandle);
}
if (gElevatorPanelFrmData != ELEVATOR_BACKGROUND_NULL) {
artUnlock(gElevatorPanelFrmHandle);
}
_elevatorBackgroundFrmImage.unlock();
_elevatorPanelFrmImage.unlock();
for (int index = 0; index < ELEVATOR_FRM_COUNT; index++) {
artUnlock(gElevatorFrmHandles[index]);
_elevatorFrmImages[index].unlock();
}
if (gElevatorWindowIsoWasEnabled) {
@@ -576,26 +542,21 @@ static int elevatorWindowInit(int elevator)
return -1;
}
int elevatorWindowX = (screenGetWidth() - gElevatorBackgroundFrmWidth) / 2;
int elevatorWindowY = (screenGetHeight() - INTERFACE_BAR_HEIGHT - 1 - gElevatorBackgroundFrmHeight) / 2;
int elevatorWindowX = (screenGetWidth() - _elevatorBackgroundFrmImage.getWidth()) / 2;
int elevatorWindowY = (screenGetHeight() - INTERFACE_BAR_HEIGHT - 1 - _elevatorBackgroundFrmImage.getHeight()) / 2;
gElevatorWindow = windowCreate(
elevatorWindowX,
elevatorWindowY,
gElevatorBackgroundFrmWidth,
gElevatorBackgroundFrmHeight,
_elevatorBackgroundFrmImage.getWidth(),
_elevatorBackgroundFrmImage.getHeight(),
256,
WINDOW_FLAG_0x10 | WINDOW_FLAG_0x02);
WINDOW_MODAL | WINDOW_DONT_MOVE_TOP);
if (gElevatorWindow == -1) {
if (gElevatorBackgroundFrmData != ELEVATOR_BACKGROUND_NULL) {
artUnlock(gElevatorBackgroundFrmHandle);
}
if (gElevatorPanelFrmData != ELEVATOR_BACKGROUND_NULL) {
artUnlock(gElevatorPanelFrmHandle);
}
_elevatorBackgroundFrmImage.unlock();
_elevatorPanelFrmImage.unlock();
for (int index = 0; index < ELEVATOR_FRM_COUNT; index++) {
artUnlock(gElevatorFrmHandles[index]);
_elevatorFrmImages[index].unlock();
}
if (gElevatorWindowIsoWasEnabled) {
@@ -608,15 +569,15 @@ static int elevatorWindowInit(int elevator)
}
gElevatorWindowBuffer = windowGetBuffer(gElevatorWindow);
memcpy(gElevatorWindowBuffer, (unsigned char*)gElevatorBackgroundFrmData, gElevatorBackgroundFrmWidth * gElevatorBackgroundFrmHeight);
memcpy(gElevatorWindowBuffer, _elevatorBackgroundFrmImage.getData(), _elevatorBackgroundFrmImage.getWidth() * _elevatorBackgroundFrmImage.getHeight());
if (gElevatorPanelFrmData != ELEVATOR_BACKGROUND_NULL) {
blitBufferToBuffer((unsigned char*)gElevatorPanelFrmData,
gElevatorPanelFrmWidth,
gElevatorPanelFrmHeight,
gElevatorPanelFrmWidth,
gElevatorWindowBuffer + gElevatorBackgroundFrmWidth * (gElevatorBackgroundFrmHeight - gElevatorPanelFrmHeight),
gElevatorBackgroundFrmWidth);
if (_elevatorPanelFrmImage.isLocked()) {
blitBufferToBuffer(_elevatorPanelFrmImage.getData(),
_elevatorPanelFrmImage.getWidth(),
_elevatorPanelFrmImage.getHeight(),
_elevatorPanelFrmImage.getWidth(),
gElevatorWindowBuffer + _elevatorBackgroundFrmImage.getWidth() * (_elevatorBackgroundFrmImage.getHeight() - _elevatorPanelFrmImage.getHeight()),
_elevatorBackgroundFrmImage.getWidth());
}
int y = 40;
@@ -624,18 +585,18 @@ static int elevatorWindowInit(int elevator)
int btn = buttonCreate(gElevatorWindow,
13,
y,
gElevatorFrmSizes[ELEVATOR_FRM_BUTTON_DOWN].width,
gElevatorFrmSizes[ELEVATOR_FRM_BUTTON_DOWN].height,
_elevatorFrmImages[ELEVATOR_FRM_BUTTON_DOWN].getWidth(),
_elevatorFrmImages[ELEVATOR_FRM_BUTTON_DOWN].getHeight(),
-1,
-1,
-1,
500 + level,
gElevatorFrmData[ELEVATOR_FRM_BUTTON_UP],
gElevatorFrmData[ELEVATOR_FRM_BUTTON_DOWN],
NULL,
_elevatorFrmImages[ELEVATOR_FRM_BUTTON_UP].getData(),
_elevatorFrmImages[ELEVATOR_FRM_BUTTON_DOWN].getData(),
nullptr,
BUTTON_FLAG_TRANSPARENT);
if (btn != -1) {
buttonSetCallbacks(btn, _gsound_red_butt_press, NULL);
buttonSetCallbacks(btn, _gsound_red_butt_press, nullptr);
}
y += 60;
}
@@ -648,16 +609,11 @@ static void elevatorWindowFree()
{
windowDestroy(gElevatorWindow);
if (gElevatorBackgroundFrmData != ELEVATOR_BACKGROUND_NULL) {
artUnlock(gElevatorBackgroundFrmHandle);
}
if (gElevatorPanelFrmData != ELEVATOR_BACKGROUND_NULL) {
artUnlock(gElevatorPanelFrmHandle);
}
_elevatorBackgroundFrmImage.unlock();
_elevatorPanelFrmImage.unlock();
for (int index = 0; index < ELEVATOR_FRM_COUNT; index++) {
artUnlock(gElevatorFrmHandles[index]);
_elevatorFrmImages[index].unlock();
}
scriptsEnable();
@@ -694,18 +650,18 @@ void elevatorsInit()
{
char* elevatorsFileName;
configGetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_ELEVATORS_FILE_KEY, &elevatorsFileName);
if (elevatorsFileName != NULL && *elevatorsFileName == '\0') {
elevatorsFileName = NULL;
if (elevatorsFileName != nullptr && *elevatorsFileName == '\0') {
elevatorsFileName = nullptr;
}
if (elevatorsFileName != NULL) {
if (elevatorsFileName != nullptr) {
Config elevatorsConfig;
if (configInit(&elevatorsConfig)) {
if (configRead(&elevatorsConfig, elevatorsFileName, false)) {
char sectionKey[4];
char key[32];
for (int index = 0; index < ELEVATORS_MAX; index++) {
sprintf(sectionKey, "%d", index);
snprintf(sectionKey, sizeof(sectionKey), "%d", index);
if (index >= ELEVATOR_COUNT) {
int levels = 0;
@@ -717,13 +673,13 @@ void elevatorsInit()
configGetInt(&elevatorsConfig, sectionKey, "ButtonsFrm", &(gElevatorBackgrounds[index].panelFrmId));
for (int level = 0; level < ELEVATOR_LEVEL_MAX; level++) {
sprintf(key, "ID%d", level + 1);
snprintf(key, sizeof(key), "ID%d", level + 1);
configGetInt(&elevatorsConfig, sectionKey, key, &(gElevatorDescriptions[index][level].map));
sprintf(key, "Elevation%d", level + 1);
snprintf(key, sizeof(key), "Elevation%d", level + 1);
configGetInt(&elevatorsConfig, sectionKey, key, &(gElevatorDescriptions[index][level].elevation));
sprintf(key, "Tile%d", level + 1);
snprintf(key, sizeof(key), "Tile%d", level + 1);
configGetInt(&elevatorsConfig, sectionKey, key, &(gElevatorDescriptions[index][level].tile));
}
}
@@ -733,7 +689,7 @@ void elevatorsInit()
// value is then used in the certain places to remap from
// requested elevator to the new one.
for (int index = 0; index < ELEVATORS_MAX; index++) {
sprintf(sectionKey, "%d", index);
snprintf(sectionKey, sizeof(sectionKey), "%d", index);
int type;
if (configGetInt(&elevatorsConfig, sectionKey, "Image", &type)) {
@@ -751,3 +707,5 @@ void elevatorsInit()
}
}
}
} // namespace fallout

View File

@@ -1,6 +1,8 @@
#ifndef ELEVATOR_H
#define ELEVATOR_H
namespace fallout {
typedef enum Elevator {
ELEVATOR_BROTHERHOOD_OF_STEEL_MAIN,
ELEVATOR_BROTHERHOOD_OF_STEEL_SURFACE,
@@ -15,11 +17,24 @@ typedef enum Elevator {
ELEVATOR_SIERRA_1,
ELEVATOR_SIERRA_2,
ELEVATOR_SIERRA_SERVICE,
ELEVATOR_COUNT = 24,
ELEVATOR_KLAMATH_TOXIC_CAVES,
ELEVATOR_14,
ELEVATOR_VAULT_CITY,
ELEVATOR_VAULT_15_MAIN,
ELEVATOR_VAULT_15_SURFACE,
ELEVATOR_NAVARRO_NORTHERN,
ELEVATOR_NAVARRO_CENTER,
ELEVATOR_NAVARRO_LAB,
ELEVATOR_NAVARRO_CANTEEN,
ELEVATOR_SAN_FRANCISCO_SHI_TEMPLE,
ELEVATOR_REDDING_WANAMINGO_MINE,
ELEVATOR_COUNT,
} Elevator;
int elevatorSelectLevel(int elevator, int* mapPtr, int* elevationPtr, int* tilePtr);
void elevatorsInit();
} // namespace fallout
#endif /* ELEVATOR_H */

View File

@@ -8,7 +8,6 @@
#include "art.h"
#include "color.h"
#include "core.h"
#include "credits.h"
#include "cycle.h"
#include "db.h"
@@ -16,23 +15,28 @@
#include "debug.h"
#include "draw.h"
#include "game.h"
#include "game_config.h"
#include "game_mouse.h"
#include "game_movie.h"
#include "game_sound.h"
#include "input.h"
#include "map.h"
#include "memory.h"
#include "mouse.h"
#include "object.h"
#include "palette.h"
#include "pipboy.h"
#include "platform_compat.h"
#include "random.h"
#include "settings.h"
#include "stat.h"
#include "svga.h"
#include "text_font.h"
#include "window_manager.h"
#include "word_wrap.h"
#include "worldmap.h"
namespace fallout {
// The maximum number of subtitle lines per slide.
#define ENDGAME_ENDING_MAX_SUBTITLES (50)
@@ -79,9 +83,7 @@ static void _endgame_movie_bk_process();
static int endgameEndingInit();
static void endgameEndingFree();
static int endgameDeathEndingValidate(int* percentage);
// 0x50B00C
char _aEnglish_2[] = ENGLISH;
static void endgameEndingUpdateOverlay();
// The number of lines in current subtitles file.
//
@@ -110,7 +112,7 @@ static int _endgame_maybe_done = 0;
// enddeath.txt
//
// 0x518678
static EndgameDeathEnding* gEndgameDeathEndings = NULL;
static EndgameDeathEnding* gEndgameDeathEndings = nullptr;
// The number of death endings in [gEndgameDeathEndings] array.
//
@@ -203,6 +205,8 @@ static unsigned char* gEndgameEndingSlideshowWindowBuffer;
// 0x570BF4
static int gEndgameEndingSlideshowWindow;
static int gEndgameEndingOverlay;
// 0x43F788
void endgamePlaySlideshow()
{
@@ -236,7 +240,7 @@ void endgamePlayMovie()
tickersAdd(_endgame_movie_bk_process);
backgroundSoundSetEndCallback(_endgame_movie_callback);
backgroundSoundLoad("akiss", 12, 14, 15);
coreDelayProcessingEvents(3000);
inputPauseForTocks(3000);
// NOTE: Result is ignored. I guess there was some kind of switch for male
// vs. female ending, but it was not implemented.
@@ -244,7 +248,7 @@ void endgamePlayMovie()
creditsOpen("credits.txt", -1, false);
backgroundSoundDelete();
backgroundSoundSetEndCallback(NULL);
backgroundSoundSetEndCallback(nullptr);
tickersRemove(_endgame_movie_bk_process);
backgroundSoundDelete();
colorPaletteLoad("color.pal");
@@ -282,7 +286,7 @@ static int endgameEndingHandleContinuePlaying()
MessageListItem messageListItem;
messageListItem.num = 30;
if (messageListGetItem(&gMiscMessageList, &messageListItem)) {
rc = showDialogBox(messageListItem.text, NULL, 0, 169, 117, _colorTable[32328], NULL, _colorTable[32328], DIALOG_BOX_YES_NO);
rc = showDialogBox(messageListItem.text, nullptr, 0, 169, 117, _colorTable[32328], nullptr, _colorTable[32328], DIALOG_BOX_YES_NO);
if (rc == 0) {
_game_user_wants_to_quit = 2;
}
@@ -313,13 +317,16 @@ static void endgameEndingRenderPanningScene(int direction, const char* narratorF
CacheEntry* backgroundHandle;
Art* background = artLock(fid, &backgroundHandle);
if (background != NULL) {
if (background != nullptr) {
int width = artGetWidth(background, 0, 0);
int height = artGetHeight(background, 0, 0);
unsigned char* backgroundData = artGetFrameData(background, 0, 0);
bufferFill(gEndgameEndingSlideshowWindowBuffer, ENDGAME_ENDING_WINDOW_WIDTH, ENDGAME_ENDING_WINDOW_HEIGHT, ENDGAME_ENDING_WINDOW_WIDTH, _colorTable[0]);
endgameEndingLoadPalette(6, 327);
// CE: Update overlay.
endgameEndingUpdateOverlay();
unsigned char palette[768];
memcpy(palette, _cmap, 768);
@@ -355,6 +362,8 @@ static void endgameEndingRenderPanningScene(int direction, const char* narratorF
unsigned int since = 0;
while (start != end) {
sharedFpsLimiter.mark();
int v12 = 640 - v32;
// TODO: Complex math, setup scene in debugger.
@@ -367,7 +376,7 @@ static void endgameEndingRenderPanningScene(int direction, const char* narratorF
windowRefresh(gEndgameEndingSlideshowWindow);
since = _get_time();
since = getTicks();
bool v14;
double v31;
@@ -407,11 +416,14 @@ static void endgameEndingRenderPanningScene(int direction, const char* narratorF
soundContinueAll();
if (_get_input() != -1) {
if (inputGetInput() != -1) {
// NOTE: Uninline.
endgameEndingVoiceOverFree();
break;
}
renderPresent();
sharedFpsLimiter.throttle();
}
tickersEnable();
@@ -423,7 +435,12 @@ static void endgameEndingRenderPanningScene(int direction, const char* narratorF
}
while (mouseGetEvent() != 0) {
_get_input();
sharedFpsLimiter.mark();
inputGetInput();
renderPresent();
sharedFpsLimiter.throttle();
}
}
@@ -432,17 +449,20 @@ static void endgameEndingRenderStaticScene(int fid, const char* narratorFileName
{
CacheEntry* backgroundHandle;
Art* background = artLock(fid, &backgroundHandle);
if (background == NULL) {
if (background == nullptr) {
return;
}
unsigned char* backgroundData = artGetFrameData(background, 0, 0);
if (backgroundData != NULL) {
if (backgroundData != nullptr) {
blitBufferToBuffer(backgroundData, ENDGAME_ENDING_WINDOW_WIDTH, ENDGAME_ENDING_WINDOW_HEIGHT, ENDGAME_ENDING_WINDOW_WIDTH, gEndgameEndingSlideshowWindowBuffer, ENDGAME_ENDING_WINDOW_WIDTH);
windowRefresh(gEndgameEndingSlideshowWindow);
endgameEndingLoadPalette(FID_TYPE(fid), fid & 0xFFF);
// CE: Update overlay.
endgameEndingUpdateOverlay();
endgameEndingVoiceOverInit(narratorFileName);
unsigned int delay;
@@ -454,17 +474,19 @@ static void endgameEndingRenderStaticScene(int fid, const char* narratorFileName
paletteFadeTo(_cmap);
coreDelayProcessingEvents(500);
inputPauseForTocks(500);
// NOTE: Uninline.
endgameEndingVoiceOverReset();
unsigned int referenceTime = _get_time();
unsigned int referenceTime = getTicks();
tickersDisable();
int keyCode;
while (true) {
keyCode = _get_input();
sharedFpsLimiter.mark();
keyCode = inputGetInput();
if (keyCode != -1) {
break;
}
@@ -485,6 +507,9 @@ static void endgameEndingRenderStaticScene(int fid, const char* narratorFileName
endgameEndingRefreshSubtitles();
windowRefresh(gEndgameEndingSlideshowWindow);
soundContinueAll();
renderPresent();
sharedFpsLimiter.throttle();
}
tickersEnable();
@@ -495,13 +520,18 @@ static void endgameEndingRenderStaticScene(int fid, const char* narratorFileName
gEndgameEndingVoiceOverSubtitlesLoaded = false;
if (keyCode == -1) {
coreDelayProcessingEvents(500);
inputPauseForTocks(500);
}
paletteFadeTo(gPaletteBlack);
while (mouseGetEvent() != 0) {
_get_input();
sharedFpsLimiter.mark();
inputGetInput();
renderPresent();
sharedFpsLimiter.throttle();
}
}
@@ -534,6 +564,13 @@ static int endgameEndingSlideshowWindowInit()
paletteFadeTo(gPaletteBlack);
// CE: Every slide has a separate color palette which is incompatible with
// main color palette. Setup overlay to hide everything.
gEndgameEndingOverlay = windowCreate(0, 0, screenGetWidth(), screenGetHeight(), _colorTable[0], WINDOW_MOVE_ON_TOP);
if (gEndgameEndingOverlay == -1) {
return -1;
}
int windowEndgameEndingX = (screenGetWidth() - ENDGAME_ENDING_WINDOW_WIDTH) / 2;
int windowEndgameEndingY = (screenGetHeight() - ENDGAME_ENDING_WINDOW_HEIGHT) / 2;
gEndgameEndingSlideshowWindow = windowCreate(windowEndgameEndingX,
@@ -541,13 +578,13 @@ static int endgameEndingSlideshowWindowInit()
ENDGAME_ENDING_WINDOW_WIDTH,
ENDGAME_ENDING_WINDOW_HEIGHT,
_colorTable[0],
WINDOW_FLAG_0x04);
WINDOW_MOVE_ON_TOP);
if (gEndgameEndingSlideshowWindow == -1) {
return -1;
}
gEndgameEndingSlideshowWindowBuffer = windowGetBuffer(gEndgameEndingSlideshowWindow);
if (gEndgameEndingSlideshowWindowBuffer == NULL) {
if (gEndgameEndingSlideshowWindowBuffer == nullptr) {
return -1;
}
@@ -555,32 +592,25 @@ static int endgameEndingSlideshowWindowInit()
speechSetEndCallback(_endgame_voiceover_callback);
gEndgameEndingSubtitlesEnabled = false;
configGetBool(&gGameConfig, GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_SUBTITLES_KEY, &gEndgameEndingSubtitlesEnabled);
gEndgameEndingSubtitlesEnabled = settings.preferences.subtitles;
if (!gEndgameEndingSubtitlesEnabled) {
return 0;
}
char* language;
if (!configGetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_LANGUAGE_KEY, &language)) {
gEndgameEndingSubtitlesEnabled = false;
return 0;
}
sprintf(gEndgameEndingSubtitlesLocalizedPath, "text\\%s\\cuts\\", language);
snprintf(gEndgameEndingSubtitlesLocalizedPath, sizeof(gEndgameEndingSubtitlesLocalizedPath), "text\\%s\\cuts\\", settings.system.language.c_str());
gEndgameEndingSubtitles = (char**)internal_malloc(sizeof(*gEndgameEndingSubtitles) * ENDGAME_ENDING_MAX_SUBTITLES);
if (gEndgameEndingSubtitles == NULL) {
if (gEndgameEndingSubtitles == nullptr) {
gEndgameEndingSubtitlesEnabled = false;
return 0;
}
for (int index = 0; index < ENDGAME_ENDING_MAX_SUBTITLES; index++) {
gEndgameEndingSubtitles[index] = NULL;
gEndgameEndingSubtitles[index] = nullptr;
}
gEndgameEndingSubtitlesTimings = (unsigned int*)internal_malloc(sizeof(*gEndgameEndingSubtitlesTimings) * ENDGAME_ENDING_MAX_SUBTITLES);
if (gEndgameEndingSubtitlesTimings == NULL) {
if (gEndgameEndingSubtitlesTimings == nullptr) {
internal_free(gEndgameEndingSubtitles);
gEndgameEndingSubtitlesEnabled = false;
return 0;
@@ -598,7 +628,7 @@ static void endgameEndingSlideshowWindowFree()
internal_free(gEndgameEndingSubtitlesTimings);
internal_free(gEndgameEndingSubtitles);
gEndgameEndingSubtitles = NULL;
gEndgameEndingSubtitles = nullptr;
gEndgameEndingSubtitlesEnabled = false;
}
@@ -607,8 +637,9 @@ static void endgameEndingSlideshowWindowFree()
fontSetCurrent(gEndgameEndingSlideshowOldFont);
speechSetEndCallback(NULL);
speechSetEndCallback(nullptr);
windowDestroy(gEndgameEndingSlideshowWindow);
windowDestroy(gEndgameEndingOverlay);
if (!_endgame_mouse_state) {
mouseHideCursor();
@@ -638,7 +669,7 @@ static void endgameEndingVoiceOverInit(const char* fileBaseName)
gEndgameEndingVoiceOverSubtitlesLoaded = false;
// Build speech file path.
sprintf(path, "%s%s", "narrator\\", fileBaseName);
snprintf(path, sizeof(path), "%s%s", "narrator\\", fileBaseName);
if (speechLoad(path, 10, 14, 15) != -1) {
gEndgameEndingVoiceOverSpeechLoaded = true;
@@ -646,7 +677,7 @@ static void endgameEndingVoiceOverInit(const char* fileBaseName)
if (gEndgameEndingSubtitlesEnabled) {
// Build subtitles file path.
sprintf(path, "%s%s.txt", gEndgameEndingSubtitlesLocalizedPath, fileBaseName);
snprintf(path, sizeof(path), "%s%s.txt", gEndgameEndingSubtitlesLocalizedPath, fileBaseName);
if (endgameEndingSubtitlesLoad(path) != 0) {
return;
@@ -685,7 +716,7 @@ static void endgameEndingVoiceOverReset()
}
if (gEndgameEndingVoiceOverSubtitlesLoaded) {
gEndgameEndingSubtitlesReferenceTime = _get_time();
gEndgameEndingSubtitlesReferenceTime = getTicks();
}
}
@@ -710,13 +741,13 @@ static void endgameEndingLoadPalette(int type, int id)
// Remove extension from file name.
char* pch = strrchr(fileName, '.');
if (pch != NULL) {
if (pch != nullptr) {
*pch = '\0';
}
if (strlen(fileName) <= 8) {
char path[COMPAT_MAX_PATH];
sprintf(path, "%s\\%s.pal", "art\\intrface", fileName);
snprintf(path, sizeof(path), "%s\\%s.pal", "art\\intrface", fileName);
colorPaletteLoad(path);
}
}
@@ -735,7 +766,7 @@ static int endgameEndingSubtitlesLoad(const char* filePath)
endgameEndingSubtitlesFree();
File* stream = fileOpen(filePath, "rt");
if (stream == NULL) {
if (stream == nullptr) {
return -1;
}
@@ -747,14 +778,14 @@ static int endgameEndingSubtitlesLoad(const char* filePath)
// Find and clamp string at EOL.
pch = strchr(string, '\n');
if (pch != NULL) {
if (pch != nullptr) {
*pch = '\0';
}
// Find separator. The value before separator is ignored (as opposed to
// movie subtitles, where the value before separator is a timing).
pch = strchr(string, ':');
if (pch != NULL) {
if (pch != nullptr) {
if (gEndgameEndingSubtitlesLength < ENDGAME_ENDING_MAX_SUBTITLES) {
gEndgameEndingSubtitles[gEndgameEndingSubtitlesLength] = internal_strdup(pch + 1);
gEndgameEndingSubtitlesLength++;
@@ -786,7 +817,7 @@ static void endgameEndingRefreshSubtitles()
}
char* text = gEndgameEndingSubtitles[gEndgameEndingSubtitlesCurrentLine];
if (text == NULL) {
if (text == nullptr) {
return;
}
@@ -825,9 +856,9 @@ static void endgameEndingRefreshSubtitles()
static void endgameEndingSubtitlesFree()
{
for (int index = 0; index < gEndgameEndingSubtitlesLength; index++) {
if (gEndgameEndingSubtitles[index] != NULL) {
if (gEndgameEndingSubtitles[index] != nullptr) {
internal_free(gEndgameEndingSubtitles[index]);
gEndgameEndingSubtitles[index] = NULL;
gEndgameEndingSubtitles[index] = nullptr;
}
}
@@ -847,7 +878,7 @@ static void _endgame_movie_bk_process()
{
if (_endgame_maybe_done) {
backgroundSoundLoad("10labone", 11, 14, 16);
backgroundSoundSetEndCallback(NULL);
backgroundSoundSetEndCallback(nullptr);
tickersRemove(_endgame_movie_bk_process);
}
}
@@ -863,15 +894,15 @@ static int endgameEndingInit()
EndgameEnding* entries;
size_t narratorFileNameLength;
if (gEndgameEndings != NULL) {
if (gEndgameEndings != nullptr) {
internal_free(gEndgameEndings);
gEndgameEndings = NULL;
gEndgameEndings = nullptr;
}
gEndgameEndingsLength = 0;
stream = fileOpen("data\\endgame.txt", "rt");
if (stream == NULL) {
if (stream == nullptr) {
return -1;
}
@@ -886,28 +917,28 @@ static int endgameEndingInit()
}
tok = strtok(ch, delim);
if (tok == NULL) {
if (tok == nullptr) {
continue;
}
entry.gvar = atoi(tok);
tok = strtok(NULL, delim);
if (tok == NULL) {
tok = strtok(nullptr, delim);
if (tok == nullptr) {
continue;
}
entry.value = atoi(tok);
tok = strtok(NULL, delim);
if (tok == NULL) {
tok = strtok(nullptr, delim);
if (tok == nullptr) {
continue;
}
entry.art_num = atoi(tok);
tok = strtok(NULL, delim);
if (tok == NULL) {
tok = strtok(nullptr, delim);
if (tok == nullptr) {
continue;
}
@@ -918,15 +949,15 @@ static int endgameEndingInit()
entry.voiceOverBaseName[narratorFileNameLength - 1] = '\0';
}
tok = strtok(NULL, delim);
if (tok != NULL) {
tok = strtok(nullptr, delim);
if (tok != nullptr) {
entry.direction = atoi(tok);
} else {
entry.direction = 1;
}
entries = (EndgameEnding*)internal_realloc(gEndgameEndings, sizeof(*entries) * (gEndgameEndingsLength + 1));
if (entries == NULL) {
if (entries == nullptr) {
goto err;
}
@@ -952,9 +983,9 @@ err:
// 0x44095C
static void endgameEndingFree()
{
if (gEndgameEndings != NULL) {
if (gEndgameEndings != nullptr) {
internal_free(gEndgameEndings);
gEndgameEndings = NULL;
gEndgameEndings = nullptr;
}
gEndgameEndingsLength = 0;
@@ -976,7 +1007,7 @@ int endgameDeathEndingInit()
strcpy(gEndgameDeathEndingFileName, "narrator\\nar_5");
stream = fileOpen("data\\enddeath.txt", "rt");
if (stream == NULL) {
if (stream == nullptr) {
return -1;
}
@@ -991,49 +1022,49 @@ int endgameDeathEndingInit()
}
tok = strtok(ch, delim);
if (tok == NULL) {
if (tok == nullptr) {
continue;
}
entry.gvar = atoi(tok);
tok = strtok(NULL, delim);
if (tok == NULL) {
tok = strtok(nullptr, delim);
if (tok == nullptr) {
continue;
}
entry.value = atoi(tok);
tok = strtok(NULL, delim);
if (tok == NULL) {
tok = strtok(nullptr, delim);
if (tok == nullptr) {
continue;
}
entry.worldAreaKnown = atoi(tok);
tok = strtok(NULL, delim);
if (tok == NULL) {
tok = strtok(nullptr, delim);
if (tok == nullptr) {
continue;
}
entry.worldAreaNotKnown = atoi(tok);
tok = strtok(NULL, delim);
if (tok == NULL) {
tok = strtok(nullptr, delim);
if (tok == nullptr) {
continue;
}
entry.min_level = atoi(tok);
tok = strtok(NULL, delim);
if (tok == NULL) {
tok = strtok(nullptr, delim);
if (tok == nullptr) {
continue;
}
entry.percentage = atoi(tok);
tok = strtok(NULL, delim);
if (tok == NULL) {
tok = strtok(nullptr, delim);
if (tok == nullptr) {
continue;
}
@@ -1048,7 +1079,7 @@ int endgameDeathEndingInit()
}
entries = (EndgameDeathEnding*)internal_realloc(gEndgameDeathEndings, sizeof(*entries) * (gEndgameDeathEndingsLength + 1));
if (entries == NULL) {
if (entries == nullptr) {
goto err;
}
@@ -1072,9 +1103,9 @@ err:
// 0x440BA8
int endgameDeathEndingExit()
{
if (gEndgameDeathEndings != NULL) {
if (gEndgameDeathEndings != nullptr) {
internal_free(gEndgameDeathEndings);
gEndgameDeathEndings = NULL;
gEndgameDeathEndings = nullptr;
gEndgameDeathEndingsLength = 0;
}
@@ -1197,3 +1228,15 @@ char* endgameDeathEndingGetFileName()
return gEndgameDeathEndingFileName;
}
void endgameEndingUpdateOverlay()
{
bufferFill(windowGetBuffer(gEndgameEndingOverlay),
windowGetWidth(gEndgameEndingOverlay),
windowGetHeight(gEndgameEndingOverlay),
windowGetWidth(gEndgameEndingOverlay),
intensityColorTable[_colorTable[0]][0]);
windowRefresh(gEndgameEndingOverlay);
}
} // namespace fallout

View File

@@ -1,6 +1,8 @@
#ifndef ENDGAME_H
#define ENDGAME_H
namespace fallout {
typedef enum EndgameDeathEndingReason {
// Dude died.
ENDGAME_DEATH_ENDING_REASON_DEATH = 0,
@@ -18,4 +20,6 @@ int endgameDeathEndingExit();
void endgameSetupDeathEnding(int reason);
char* endgameDeathEndingGetFileName();
} // namespace fallout
#endif /* ENDGAME_H */

View File

@@ -7,6 +7,8 @@
#include "memory_manager.h"
#include "platform_compat.h"
namespace fallout {
typedef struct ExternalVariable {
char name[32];
char* programName;
@@ -59,7 +61,7 @@ ExternalProcedure* externalProcedureFind(const char* identifier)
unsigned int v2 = v1;
ExternalProcedure* externalProcedure = &(gExternalProcedures[v1]);
if (externalProcedure->program != NULL) {
if (externalProcedure->program != nullptr) {
if (compat_stricmp(externalProcedure->name, identifier) == 0) {
return externalProcedure;
}
@@ -72,14 +74,14 @@ ExternalProcedure* externalProcedureFind(const char* identifier)
}
externalProcedure = &(gExternalProcedures[v1]);
if (externalProcedure->program != NULL) {
if (externalProcedure->program != nullptr) {
if (compat_stricmp(externalProcedure->name, identifier) == 0) {
return externalProcedure;
}
}
} while (v1 != v2);
return NULL;
return nullptr;
}
// 0x441018
@@ -106,7 +108,7 @@ ExternalProcedure* externalProcedureAdd(const char* identifier)
}
} while (v1 != a2);
return NULL;
return nullptr;
}
// 0x4410AC
@@ -138,7 +140,7 @@ ExternalVariable* externalVariableFind(const char* identifier)
}
} while (v1 != v2);
return NULL;
return nullptr;
}
// 0x44118C
@@ -165,14 +167,14 @@ ExternalVariable* externalVariableAdd(const char* identifier)
}
} while (v1 != v2);
return NULL;
return nullptr;
}
// 0x44127C
int externalVariableSetValue(Program* program, const char* name, ProgramValue& programValue)
{
ExternalVariable* exportedVariable = externalVariableFind(name);
if (exportedVariable == NULL) {
if (exportedVariable == nullptr) {
return 1;
}
@@ -181,7 +183,7 @@ int externalVariableSetValue(Program* program, const char* name, ProgramValue& p
}
if ((programValue.opcode & VALUE_TYPE_MASK) == VALUE_TYPE_STRING) {
if (program != NULL) {
if (program != nullptr) {
const char* stringValue = programGetString(program, programValue.opcode, programValue.integerValue);
exportedVariable->value.opcode = VALUE_TYPE_DYNAMIC_STRING;
@@ -199,7 +201,7 @@ int externalVariableSetValue(Program* program, const char* name, ProgramValue& p
int externalVariableGetValue(Program* program, const char* name, ProgramValue& value)
{
ExternalVariable* exportedVariable = externalVariableFind(name);
if (exportedVariable == NULL) {
if (exportedVariable == nullptr) {
return 1;
}
@@ -219,7 +221,7 @@ int externalVariableCreate(Program* program, const char* identifier)
const char* programName = program->name;
ExternalVariable* exportedVariable = externalVariableFind(identifier);
if (exportedVariable != NULL) {
if (exportedVariable != nullptr) {
if (compat_stricmp(exportedVariable->programName, programName) != 0) {
return 1;
}
@@ -229,7 +231,7 @@ int externalVariableCreate(Program* program, const char* identifier)
}
} else {
exportedVariable = externalVariableAdd(identifier);
if (exportedVariable == NULL) {
if (exportedVariable == nullptr) {
return 1;
}
@@ -252,7 +254,7 @@ void _removeProgramReferences(Program* program)
ExternalProcedure* externalProcedure = &(gExternalProcedures[index]);
if (externalProcedure->program == program) {
externalProcedure->name[0] = '\0';
externalProcedure->program = NULL;
externalProcedure->program = nullptr;
}
}
}
@@ -283,12 +285,12 @@ void externalVariablesClear()
Program* externalProcedureGetProgram(const char* identifier, int* addressPtr, int* argumentCountPtr)
{
ExternalProcedure* externalProcedure = externalProcedureFind(identifier);
if (externalProcedure == NULL) {
return NULL;
if (externalProcedure == nullptr) {
return nullptr;
}
if (externalProcedure->program == NULL) {
return NULL;
if (externalProcedure->program == nullptr) {
return nullptr;
}
*addressPtr = externalProcedure->address;
@@ -301,13 +303,13 @@ Program* externalProcedureGetProgram(const char* identifier, int* addressPtr, in
int externalProcedureCreate(Program* program, const char* identifier, int address, int argumentCount)
{
ExternalProcedure* externalProcedure = externalProcedureFind(identifier);
if (externalProcedure != NULL) {
if (externalProcedure != nullptr) {
if (program != externalProcedure->program) {
return 1;
}
} else {
externalProcedure = externalProcedureAdd(identifier);
if (externalProcedure == NULL) {
if (externalProcedure == nullptr) {
return 1;
}
@@ -328,14 +330,14 @@ void _exportClearAllVariables()
ExternalVariable* exportedVariable = &(gExternalVariables[index]);
if (exportedVariable->name[0] != '\0') {
if ((exportedVariable->value.opcode & VALUE_TYPE_MASK) == VALUE_TYPE_STRING) {
if (exportedVariable->stringValue != NULL) {
if (exportedVariable->stringValue != nullptr) {
internal_free_safe(exportedVariable->stringValue, __FILE__, __LINE__); // "..\\int\\EXPORT.C", 387
}
}
if (exportedVariable->programName != NULL) {
if (exportedVariable->programName != nullptr) {
internal_free_safe(exportedVariable->programName, __FILE__, __LINE__); // "..\\int\\EXPORT.C", 393
exportedVariable->programName = NULL;
exportedVariable->programName = nullptr;
}
exportedVariable->name[0] = '\0';
@@ -343,3 +345,5 @@ void _exportClearAllVariables()
}
}
}
} // namespace fallout

View File

@@ -3,6 +3,8 @@
#include "interpreter.h"
namespace fallout {
int externalVariableSetValue(Program* program, const char* identifier, ProgramValue& value);
int externalVariableGetValue(Program* program, const char* name, ProgramValue& value);
int externalVariableCreate(Program* program, const char* identifier);
@@ -12,4 +14,6 @@ Program* externalProcedureGetProgram(const char* identifier, int* addressPtr, in
int externalProcedureCreate(Program* program, const char* identifier, int address, int argumentCount);
void _exportClearAllVariables();
} // namespace fallout
#endif /* EXPORT_H */

View File

@@ -5,6 +5,8 @@
#include <fpattern.h>
namespace fallout {
// 0x4E6380
bool fileFindFirst(const char* path, DirectoryFileFindData* findData)
{
@@ -14,33 +16,40 @@ bool fileFindFirst(const char* path, DirectoryFileFindData* findData)
return false;
}
#else
strcpy(findData->path, path);
char drive[COMPAT_MAX_DRIVE];
char dir[COMPAT_MAX_DIR];
compat_splitpath(path, drive, dir, NULL, NULL);
char fname[COMPAT_MAX_FNAME];
char ext[COMPAT_MAX_EXT];
compat_splitpath(path, drive, dir, fname, ext);
// Reassemble file name and extension to serve as a pattern. It has to be
// lowercased because underlying `fpattern` implementation uses lowercased
// char-by-char matching.
compat_makepath(findData->pattern, nullptr, nullptr, fname, ext);
compat_strlwr(findData->pattern);
char basePath[COMPAT_MAX_PATH];
compat_makepath(basePath, drive, dir, NULL, NULL);
compat_makepath(basePath, drive, dir, nullptr, nullptr);
findData->dir = opendir(basePath);
if (findData->dir == NULL) {
if (findData->dir == nullptr) {
return false;
}
findData->entry = readdir(findData->dir);
while (findData->entry != NULL) {
char entryPath[COMPAT_MAX_PATH];
compat_makepath(entryPath, drive, dir, fileFindGetName(findData), NULL);
if (fpattern_match(findData->path, entryPath)) {
while (findData->entry != nullptr) {
char entryName[COMPAT_MAX_FNAME];
strcpy(entryName, fileFindGetName(findData));
compat_strlwr(entryName);
if (fpattern_match(findData->pattern, entryName)) {
break;
}
findData->entry = readdir(findData->dir);
}
if (findData->entry == NULL) {
if (findData->entry == nullptr) {
closedir(findData->dir);
findData->dir = NULL;
findData->dir = nullptr;
return false;
}
#endif
@@ -56,23 +65,20 @@ bool fileFindNext(DirectoryFileFindData* findData)
return false;
}
#else
char drive[COMPAT_MAX_DRIVE];
char dir[COMPAT_MAX_DIR];
compat_splitpath(findData->path, drive, dir, NULL, NULL);
findData->entry = readdir(findData->dir);
while (findData->entry != NULL) {
char entryPath[COMPAT_MAX_PATH];
compat_makepath(entryPath, drive, dir, fileFindGetName(findData), NULL);
if (fpattern_match(findData->path, entryPath)) {
while (findData->entry != nullptr) {
char entryName[COMPAT_MAX_FNAME];
strcpy(entryName, fileFindGetName(findData));
compat_strlwr(entryName);
if (fpattern_match(findData->pattern, entryName)) {
break;
}
findData->entry = readdir(findData->dir);
}
if (findData->entry == NULL) {
if (findData->entry == nullptr) {
closedir(findData->dir);
findData->dir = NULL;
findData->dir = nullptr;
return false;
}
#endif
@@ -86,7 +92,7 @@ bool findFindClose(DirectoryFileFindData* findData)
#if defined(_MSC_VER)
FindClose(findData->hFind);
#else
if (findData->dir != NULL) {
if (findData->dir != nullptr) {
if (closedir(findData->dir) != 0) {
return false;
}
@@ -95,3 +101,5 @@ bool findFindClose(DirectoryFileFindData* findData)
return true;
}
} // namespace fallout

View File

@@ -2,8 +2,6 @@
#define FILE_FIND_H
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#else
#include <dirent.h>
@@ -11,6 +9,8 @@
#include "platform_compat.h"
namespace fallout {
// NOTE: This structure is significantly different from what was in the
// original code. Watcom provides opendir/readdir/closedir implementations,
// that use Win32 FindFirstFile/FindNextFile under the hood, which in turn
@@ -37,7 +37,7 @@ typedef struct DirectoryFileFindData {
#else
DIR* dir;
struct dirent* entry;
char path[COMPAT_MAX_PATH];
char pattern[COMPAT_MAX_FNAME];
#endif
} DirectoryFileFindData;
@@ -65,4 +65,6 @@ static inline char* fileFindGetName(DirectoryFileFindData* findData)
#endif
}
} // namespace fallout
#endif /* FILE_FIND_H */

View File

@@ -11,13 +11,15 @@
#include "platform_compat.h"
namespace fallout {
static void fileCopy(const char* existingFilePath, const char* newFilePath);
// 0x452740
int fileCopyDecompressed(const char* existingFilePath, const char* newFilePath)
{
FILE* stream = compat_fopen(existingFilePath, "rb");
if (stream == NULL) {
if (stream == nullptr) {
return -1;
}
@@ -30,7 +32,7 @@ int fileCopyDecompressed(const char* existingFilePath, const char* newFilePath)
gzFile inStream = compat_gzopen(existingFilePath, "rb");
FILE* outStream = compat_fopen(newFilePath, "wb");
if (inStream != NULL && outStream != NULL) {
if (inStream != nullptr && outStream != nullptr) {
for (;;) {
int ch = gzgetc(inStream);
if (ch == -1) {
@@ -43,11 +45,11 @@ int fileCopyDecompressed(const char* existingFilePath, const char* newFilePath)
gzclose(inStream);
fclose(outStream);
} else {
if (inStream != NULL) {
if (inStream != nullptr) {
gzclose(inStream);
}
if (outStream != NULL) {
if (outStream != nullptr) {
fclose(outStream);
}
@@ -64,7 +66,7 @@ int fileCopyDecompressed(const char* existingFilePath, const char* newFilePath)
int fileCopyCompressed(const char* existingFilePath, const char* newFilePath)
{
FILE* inStream = compat_fopen(existingFilePath, "rb");
if (inStream == NULL) {
if (inStream == nullptr) {
return -1;
}
@@ -80,7 +82,7 @@ int fileCopyCompressed(const char* existingFilePath, const char* newFilePath)
fileCopy(existingFilePath, newFilePath);
} else {
gzFile outStream = compat_gzopen(newFilePath, "wb");
if (outStream == NULL) {
if (outStream == nullptr) {
fclose(inStream);
return -1;
}
@@ -106,7 +108,7 @@ int fileCopyCompressed(const char* existingFilePath, const char* newFilePath)
int _gzdecompress_file(const char* existingFilePath, const char* newFilePath)
{
FILE* stream = compat_fopen(existingFilePath, "rb");
if (stream == NULL) {
if (stream == nullptr) {
return -1;
}
@@ -118,12 +120,12 @@ int _gzdecompress_file(const char* existingFilePath, const char* newFilePath)
// TODO: Is it broken?
if (magic[0] != 0x1F || magic[1] != 0x8B) {
gzFile gzstream = compat_gzopen(existingFilePath, "rb");
if (gzstream == NULL) {
if (gzstream == nullptr) {
return -1;
}
stream = compat_fopen(newFilePath, "wb");
if (stream == NULL) {
if (stream == nullptr) {
gzclose(gzstream);
return -1;
}
@@ -148,17 +150,9 @@ int _gzdecompress_file(const char* existingFilePath, const char* newFilePath)
static void fileCopy(const char* existingFilePath, const char* newFilePath)
{
char nativeExistingFilePath[COMPAT_MAX_PATH];
strcpy(nativeExistingFilePath, existingFilePath);
compat_windows_path_to_native(nativeExistingFilePath);
char nativeNewFilePath[COMPAT_MAX_PATH];
strcpy(nativeNewFilePath, newFilePath);
compat_windows_path_to_native(nativeNewFilePath);
FILE* in = fopen(nativeExistingFilePath, "rb");
FILE* out = fopen(nativeNewFilePath, "wb");
if (in != NULL && out != NULL) {
FILE* in = compat_fopen(existingFilePath, "rb");
FILE* out = compat_fopen(newFilePath, "wb");
if (in != nullptr && out != nullptr) {
std::vector<unsigned char> buffer(0xFFFF);
size_t bytesRead;
@@ -177,11 +171,13 @@ static void fileCopy(const char* existingFilePath, const char* newFilePath)
}
}
if (in != NULL) {
if (in != nullptr) {
fclose(in);
}
if (out != NULL) {
if (out != nullptr) {
fclose(out);
}
}
} // namespace fallout

View File

@@ -1,8 +1,12 @@
#ifndef FILE_UTILS_H
#define FILE_UTILS_H
namespace fallout {
int fileCopyDecompressed(const char* existingFilePath, const char* newFilePath);
int fileCopyCompressed(const char* existingFilePath, const char* newFilePath);
int _gzdecompress_file(const char* existingFilePath, const char* newFilePath);
} // namespace fallout
#endif /* FILE_UTILS_H */

View File

@@ -10,6 +10,8 @@
// The maximum number of interface fonts.
#define INTERFACE_FONT_MAX (16)
namespace fallout {
typedef struct InterfaceFontGlyph {
short width;
short height;
@@ -80,7 +82,7 @@ int interfaceFontsInit()
for (int font = 0; font < INTERFACE_FONT_MAX; font++) {
if (interfaceFontLoad(font) == -1) {
gInterfaceFontDescriptors[font].maxHeight = 0;
gInterfaceFontDescriptors[font].data = NULL;
gInterfaceFontDescriptors[font].data = nullptr;
} else {
++gInterfaceFontsLength;
@@ -105,7 +107,7 @@ int interfaceFontsInit()
void interfaceFontsExit()
{
for (int font = 0; font < INTERFACE_FONT_MAX; font++) {
if (gInterfaceFontDescriptors[font].data != NULL) {
if (gInterfaceFontDescriptors[font].data != nullptr) {
internal_free_safe(gInterfaceFontDescriptors[font].data, __FILE__, __LINE__); // FONTMGR.C, 124
}
}
@@ -117,64 +119,89 @@ static int interfaceFontLoad(int font_index)
InterfaceFontDescriptor* fontDescriptor = &(gInterfaceFontDescriptors[font_index]);
char path[56];
sprintf(path, "font%d.aaf", font_index);
snprintf(path, sizeof(path), "font%d.aaf", font_index);
File* stream = fileOpen(path, "rb");
if (stream == NULL) {
return false;
if (stream == nullptr) {
return -1;
}
int fileSize = fileGetSize(stream);
int sig;
if (fileRead(&sig, 4, 1, stream) != 1) goto err;
if (fileRead(&sig, 4, 1, stream) != 1) {
fileClose(stream);
return -1;
}
interfaceFontByteSwapInt32(&sig);
if (sig != 0x41414646) goto err;
if (sig != 0x41414646) {
fileClose(stream);
return -1;
}
if (fileRead(&(fontDescriptor->maxHeight), 2, 1, stream) != 1) goto err;
if (fileRead(&(fontDescriptor->maxHeight), 2, 1, stream) != 1) {
fileClose(stream);
return -1;
}
interfaceFontByteSwapInt16(&(fontDescriptor->maxHeight));
if (fileRead(&(fontDescriptor->letterSpacing), 2, 1, stream) != 1) goto err;
if (fileRead(&(fontDescriptor->letterSpacing), 2, 1, stream) != 1) {
fileClose(stream);
return -1;
}
interfaceFontByteSwapInt16(&(fontDescriptor->letterSpacing));
if (fileRead(&(fontDescriptor->wordSpacing), 2, 1, stream) != 1) goto err;
if (fileRead(&(fontDescriptor->wordSpacing), 2, 1, stream) != 1) {
fileClose(stream);
return -1;
}
interfaceFontByteSwapInt16(&(fontDescriptor->wordSpacing));
if (fileRead(&(fontDescriptor->lineSpacing), 2, 1, stream) != 1) goto err;
if (fileRead(&(fontDescriptor->lineSpacing), 2, 1, stream) != 1) {
fileClose(stream);
return -1;
}
interfaceFontByteSwapInt16(&(fontDescriptor->lineSpacing));
for (int index = 0; index < 256; index++) {
InterfaceFontGlyph* glyph = &(fontDescriptor->glyphs[index]);
if (fileRead(&(glyph->width), 2, 1, stream) != 1) goto err;
if (fileRead(&(glyph->width), 2, 1, stream) != 1) {
fileClose(stream);
return -1;
}
interfaceFontByteSwapInt16(&(glyph->width));
if (fileRead(&(glyph->height), 2, 1, stream) != 1) goto err;
if (fileRead(&(glyph->height), 2, 1, stream) != 1) {
fileClose(stream);
return -1;
}
interfaceFontByteSwapInt16(&(glyph->height));
if (fileRead(&(glyph->offset), 4, 1, stream) != 1) goto err;
if (fileRead(&(glyph->offset), 4, 1, stream) != 1) {
fileClose(stream);
return -1;
}
interfaceFontByteSwapInt32(&(glyph->offset));
}
fileSize -= sizeof(InterfaceFontDescriptor);
int glyphDataSize = fileSize - 2060;
fontDescriptor->data = (unsigned char*)internal_malloc_safe(fileSize, __FILE__, __LINE__); // FONTMGR.C, 259
if (fontDescriptor->data == NULL) goto err;
fontDescriptor->data = (unsigned char*)internal_malloc_safe(glyphDataSize, __FILE__, __LINE__); // FONTMGR.C, 259
if (fontDescriptor->data == nullptr) {
fileClose(stream);
return -1;
}
if (fileRead(fontDescriptor->data, fileSize, 1, stream) != 1) {
if (fileRead(fontDescriptor->data, glyphDataSize, 1, stream) != 1) {
internal_free_safe(fontDescriptor->data, __FILE__, __LINE__); // FONTMGR.C, 268
goto err;
fileClose(stream);
return -1;
}
fileClose(stream);
return 0;
err:
fileClose(stream);
return -1;
}
// 0x442120
@@ -186,7 +213,7 @@ static void interfaceFontSetCurrentImpl(int font)
font -= 100;
if (gInterfaceFontDescriptors[font].data != NULL) {
if (gInterfaceFontDescriptors[font].data != nullptr) {
gCurrentInterfaceFont = font;
gCurrentInterfaceFontDescriptor = &(gInterfaceFontDescriptors[font]);
}
@@ -209,26 +236,22 @@ static int interfaceFontGetStringWidthImpl(const char* string)
return 0;
}
const char* pch = string;
int width = 0;
int stringWidth = 0;
while (*pch != '\0') {
int v3;
int v4;
while (*string != '\0') {
unsigned char ch = static_cast<unsigned char>(*string++);
if (*pch == ' ') {
v3 = gCurrentInterfaceFontDescriptor->letterSpacing;
v4 = gCurrentInterfaceFontDescriptor->wordSpacing;
int characterWidth;
if (ch == ' ') {
characterWidth = gCurrentInterfaceFontDescriptor->wordSpacing;
} else {
v3 = gCurrentInterfaceFontDescriptor->glyphs[*pch & 0xFF].width;
v4 = gCurrentInterfaceFontDescriptor->letterSpacing;
characterWidth = gCurrentInterfaceFontDescriptor->glyphs[ch].width;
}
width += v3 + v4;
pch++;
stringWidth += characterWidth + gCurrentInterfaceFontDescriptor->letterSpacing;
}
return width;
return stringWidth;
}
// 0x4421DC
@@ -320,13 +343,13 @@ static void interfaceFontDrawImpl(unsigned char* buf, const char* string, int le
unsigned char* ptr = buf;
while (*string != '\0') {
char ch = *string++;
unsigned char ch = static_cast<unsigned char>(*string++);
int characterWidth;
if (ch == ' ') {
characterWidth = gCurrentInterfaceFontDescriptor->wordSpacing;
} else {
characterWidth = gCurrentInterfaceFontDescriptor->glyphs[ch & 0xFF].width;
characterWidth = gCurrentInterfaceFontDescriptor->glyphs[ch].width;
}
unsigned char* end;
@@ -341,7 +364,7 @@ static void interfaceFontDrawImpl(unsigned char* buf, const char* string, int le
break;
}
InterfaceFontGlyph* glyph = &(gCurrentInterfaceFontDescriptor->glyphs[ch & 0xFF]);
InterfaceFontGlyph* glyph = &(gCurrentInterfaceFontDescriptor->glyphs[ch]);
unsigned char* glyphDataPtr = gCurrentInterfaceFontDescriptor->data + glyph->offset;
// Skip blank pixels (difference between font's line height and glyph height).
@@ -405,3 +428,5 @@ static void interfaceFontByteSwapInt16(short* value)
{
interfaceFontByteSwapUInt16((unsigned short*)value);
}
} // namespace fallout

View File

@@ -3,9 +3,13 @@
#include "text_font.h"
namespace fallout {
extern FontManager gModernFontManager;
int interfaceFontsInit();
void interfaceFontsExit();
} // namespace fallout
#endif /* FONT_MANAGER_H */

View File

@@ -2,7 +2,9 @@
#include <SDL.h>
FpsLimiter::FpsLimiter(std::size_t fps)
namespace fallout {
FpsLimiter::FpsLimiter(unsigned int fps)
: _fps(fps)
, _ticks(0)
{
@@ -19,3 +21,5 @@ void FpsLimiter::throttle() const
SDL_Delay(1000 / _fps - (SDL_GetTicks() - _ticks));
}
}
} // namespace fallout

View File

@@ -1,17 +1,19 @@
#ifndef FPS_LIMITER_H
#define FPS_LIMITER_H
#include <cstddef>
namespace fallout {
class FpsLimiter {
public:
FpsLimiter(std::size_t fps = 60);
FpsLimiter(unsigned int fps = 60);
void mark();
void throttle() const;
private:
const std::size_t _fps;
std::size_t _ticks;
const unsigned int _fps;
unsigned int _ticks;
};
} // namespace fallout
#endif /* FPS_LIMITER_H */

View File

@@ -3,12 +3,6 @@
#include <stdio.h>
#include <string.h>
#ifdef _WIN32
#include <io.h>
#else
#include <unistd.h> // access
#endif
#include "actions.h"
#include "animation.h"
#include "art.h"
@@ -18,7 +12,6 @@
#include "color.h"
#include "combat.h"
#include "combat_ai.h"
#include "core.h"
#include "critter.h"
#include "cycle.h"
#include "db.h"
@@ -26,21 +19,22 @@
#include "debug.h"
#include "display_monitor.h"
#include "draw.h"
#include "electronic_registration.h"
#include "endgame.h"
#include "font_manager.h"
#include "game_config.h"
#include "game_dialog.h"
#include "game_memory.h"
#include "game_mouse.h"
#include "game_movie.h"
#include "game_sound.h"
#include "input.h"
#include "interface.h"
#include "inventory.h"
#include "item.h"
#include "kb.h"
#include "loadsave.h"
#include "map.h"
#include "memory.h"
#include "mouse.h"
#include "movie.h"
#include "movie_effect.h"
#include "object.h"
@@ -50,22 +44,32 @@
#include "perk.h"
#include "pipboy.h"
#include "platform_compat.h"
#include "preferences.h"
#include "proto.h"
#include "queue.h"
#include "random.h"
#include "scripts.h"
#include "settings.h"
#include "sfall_arrays.h"
#include "sfall_config.h"
#include "sfall_global_scripts.h"
#include "sfall_global_vars.h"
#include "sfall_ini.h"
#include "sfall_lists.h"
#include "skill.h"
#include "skilldex.h"
#include "stat.h"
#include "svga.h"
#include "text_font.h"
#include "tile.h"
#include "trait.h"
#include "trap.h"
#include "version.h"
#include "window_manager.h"
#include "window_manager_private.h"
#include "worldmap.h"
namespace fallout {
#define HELP_SCREEN_WIDTH (640)
#define HELP_SCREEN_HEIGHT (480)
@@ -90,13 +94,13 @@ static char _aDec11199816543[] = VERSION_BUILD_TIME;
static bool gGameUiDisabled = false;
// 0x5186B8
static int _game_state_cur = GAME_STATE_0;
static int gGameState = GAME_STATE_0;
// 0x5186BC
static bool gIsMapper = false;
// 0x5186C0
int* gGameGlobalVars = NULL;
int* gGameGlobalVars = nullptr;
// 0x5186C4
int gGameGlobalVarsLength = 0;
@@ -112,15 +116,8 @@ int _game_user_wants_to_quit = 0;
// 0x58E940
MessageList gMiscMessageList;
// master.dat loading result
//
// 0x58E948
int _master_db_handle;
// critter.dat loading result
//
// 0x58E94C
int _critter_db_handle;
// CE: Sonora folks like to store objects in global variables.
static void** gGameGlobalPointers = nullptr;
// 0x442580
int gameInitWithOptions(const char* windowTitle, bool isMapper, int font, int a4, int argc, char** argv)
@@ -135,32 +132,33 @@ int gameInitWithOptions(const char* windowTitle, bool isMapper, int font, int a4
// override it's file name.
sfallConfigInit(argc, argv);
gameConfigInit(isMapper, argc, argv);
settingsInit(isMapper, argc, argv);
gIsMapper = isMapper;
if (gameDbInit() == -1) {
gameConfigExit(false);
settingsExit(false);
sfallConfigExit();
return -1;
}
runElectronicRegistration();
// Message list repository is considered a specialized file manager, so
// it should be initialized early in the process.
messageListRepositoryInit();
programWindowSetTitle(windowTitle);
_initWindow(1, a4);
paletteInit();
char* language;
if (configGetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_LANGUAGE_KEY, &language)) {
if (compat_stricmp(language, FRENCH) == 0) {
keyboardSetLayout(KEYBOARD_LAYOUT_FRENCH);
} else if (compat_stricmp(language, GERMAN) == 0) {
keyboardSetLayout(KEYBOARD_LAYOUT_GERMAN);
} else if (compat_stricmp(language, ITALIAN) == 0) {
keyboardSetLayout(KEYBOARD_LAYOUT_ITALIAN);
} else if (compat_stricmp(language, SPANISH) == 0) {
keyboardSetLayout(KEYBOARD_LAYOUT_SPANISH);
}
const char* language = settings.system.language.c_str();
if (compat_stricmp(language, FRENCH) == 0) {
keyboardSetLayout(KEYBOARD_LAYOUT_FRENCH);
} else if (compat_stricmp(language, GERMAN) == 0) {
keyboardSetLayout(KEYBOARD_LAYOUT_GERMAN);
} else if (compat_stricmp(language, ITALIAN) == 0) {
keyboardSetLayout(KEYBOARD_LAYOUT_ITALIAN);
} else if (compat_stricmp(language, SPANISH) == 0) {
keyboardSetLayout(KEYBOARD_LAYOUT_SPANISH);
}
// SFALL: Allow to skip splash screen
@@ -171,14 +169,26 @@ int gameInitWithOptions(const char* windowTitle, bool isMapper, int font, int a4
showSplash();
}
_trap_init();
// CE: Handle debug mode (exactly as seen in `mapper2.exe`).
const char* debugMode = settings.debug.mode.c_str();
if (compat_stricmp(debugMode, "environment") == 0) {
_debug_register_env();
} else if (compat_stricmp(debugMode, "screen") == 0) {
_debug_register_screen();
} else if (compat_stricmp(debugMode, "log") == 0) {
_debug_register_log("debug.log", "wt");
} else if (compat_stricmp(debugMode, "mono") == 0) {
_debug_register_mono();
} else if (compat_stricmp(debugMode, "gnw") == 0) {
_debug_register_func(_win_debug);
}
interfaceFontsInit();
fontManagerAdd(&gModernFontManager);
fontSetCurrent(font);
screenshotHandlerConfigure(KEY_F12, gameTakeScreenshot);
pauseHandlerConfigure(-1, NULL);
pauseHandlerConfigure(-1, nullptr);
tileDisable();
@@ -313,7 +323,7 @@ int gameInitWithOptions(const char* windowTitle, bool isMapper, int font, int a4
debugPrint(">message_init\t");
sprintf(path, "%s%s", asc_5186C8, "misc.msg");
snprintf(path, sizeof(path), "%s%s", asc_5186C8, "misc.msg");
if (!messageListLoad(&gMiscMessageList, path)) {
debugPrint("Failed on message_load\n");
@@ -346,6 +356,32 @@ int gameInitWithOptions(const char* windowTitle, bool isMapper, int font, int a4
// SFALL
premadeCharactersInit();
if (!sfall_gl_vars_init()) {
debugPrint("Failed on sfall_gl_vars_init");
return -1;
}
if (!sfallListsInit()) {
debugPrint("Failed on sfallListsInit");
return -1;
}
if (!sfallArraysInit()) {
debugPrint("Failed on sfallArraysInit");
return -1;
}
if (!sfall_gl_scr_init()) {
debugPrint("Failed on sfall_gl_scr_init");
return -1;
}
char* customConfigBasePath;
configGetString(&gSfallConfig, SFALL_CONFIG_SCRIPTS_KEY, SFALL_CONFIG_INI_CONFIG_FOLDER, &customConfigBasePath);
sfall_ini_set_base_path(customConfigBasePath);
messageListRepositorySetStandardMessageList(STANDARD_MESSAGE_LIST_MISC, &gMiscMessageList);
return 0;
}
@@ -386,6 +422,13 @@ void gameReset()
_game_user_wants_to_quit = 0;
automapReset();
_init_options_menu();
// SFALL
sfall_gl_vars_reset();
sfallListsReset();
messageListRepositoryReset();
sfallArraysReset();
sfall_gl_scr_reset();
}
// 0x442C34
@@ -394,9 +437,14 @@ void gameExit()
debugPrint("\nGame Exit\n");
// SFALL
sfall_gl_scr_exit();
sfallArraysExit();
sfallListsExit();
sfall_gl_vars_exit();
premadeCharactersExit();
tileDisable();
messageListRepositorySetStandardMessageList(STANDARD_MESSAGE_LIST_MISC, nullptr);
messageListFree(&gMiscMessageList);
combatExit();
gameDialogExit();
@@ -429,10 +477,10 @@ void gameExit()
partyMembersExit();
endgameDeathEndingExit();
interfaceFontsExit();
_trap_init();
_windowClose();
messageListRepositoryExit();
dbExit();
gameConfigExit(true);
settingsExit(true);
sfallConfigExit();
}
@@ -440,7 +488,7 @@ void gameExit()
int gameHandleKey(int eventCode, bool isInCombatMode)
{
// NOTE: Uninline.
if (_game_state() == GAME_STATE_5) {
if (gameGetState() == GAME_STATE_5) {
_gdialogSystemEnter();
}
@@ -551,7 +599,7 @@ int gameHandleKey(int eventCode, bool isInCombatMode)
case KEY_LOWERCASE_A:
if (interfaceBarEnabled()) {
if (!isInCombatMode) {
_combat(NULL);
_combat(nullptr);
}
}
break;
@@ -613,7 +661,7 @@ int gameHandleKey(int eventCode, bool isInCombatMode)
MessageListItem messageListItem;
char title[128];
strcpy(title, getmsg(&gMiscMessageList, &messageListItem, 7));
showDialogBox(title, NULL, 0, 192, 116, _colorTable[32328], NULL, _colorTable[32328], 0);
showDialogBox(title, nullptr, 0, 192, 116, _colorTable[32328], nullptr, _colorTable[32328], 0);
} else {
soundPlayFile("ib1p1xx1");
pipboyOpen(PIPBOY_OPEN_INTENT_UNSPECIFIED);
@@ -681,7 +729,7 @@ int gameHandleKey(int eventCode, bool isInCombatMode)
MessageListItem messageListItem;
char title[128];
strcpy(title, getmsg(&gMiscMessageList, &messageListItem, 7));
showDialogBox(title, NULL, 0, 192, 116, _colorTable[32328], NULL, _colorTable[32328], 0);
showDialogBox(title, nullptr, 0, 192, 116, _colorTable[32328], nullptr, _colorTable[32328], 0);
} else {
soundPlayFile("ib1p1xx1");
pipboyOpen(PIPBOY_OPEN_INTENT_REST);
@@ -694,7 +742,7 @@ int gameHandleKey(int eventCode, bool isInCombatMode)
}
if (gIsMapper) {
tileSetCenter(gDude->tile, TILE_SET_CENTER_FLAG_0x01);
tileSetCenter(gDude->tile, TILE_SET_CENTER_REFRESH_WINDOW);
} else {
_tile_scroll_to(gDude->tile, 2);
}
@@ -799,7 +847,7 @@ int gameHandleKey(int eventCode, bool isInCombatMode)
MessageList messageList;
if (messageListInit(&messageList)) {
char path[COMPAT_MAX_PATH];
sprintf(path, "%s%s", asc_5186C8, "editor.msg");
snprintf(path, sizeof(path), "%s%s", asc_5186C8, "editor.msg");
if (messageListLoad(&messageList, path)) {
MessageListItem messageListItem;
@@ -808,7 +856,7 @@ int gameHandleKey(int eventCode, bool isInCombatMode)
char* time = gameTimeGetTimeString();
char date[128];
sprintf(date, "%s: %d/%d %s", messageListItem.text, day, year, time);
snprintf(date, sizeof(date), "%s: %d/%d %s", messageListItem.text, day, year, time);
displayMonitorAddMessage(date);
}
@@ -877,7 +925,7 @@ int gameHandleKey(int eventCode, bool isInCombatMode)
soundPlayFile("ib1p1xx1");
char version[VERSION_MAX];
versionGetVersion(version);
versionGetVersion(version, sizeof(version));
displayMonitorAddMessage(version);
displayMonitorAddMessage(_aDec11199816543);
}
@@ -961,9 +1009,9 @@ int gameSetGlobalVar(int var, int value)
if (diff != 0) {
char formattedMessage[80];
if (diff > 0) {
sprintf(formattedMessage, "You gained %d karma.", diff);
snprintf(formattedMessage, sizeof(formattedMessage), "You gained %d karma.", diff);
} else {
sprintf(formattedMessage, "You lost %d karma.", -diff);
snprintf(formattedMessage, sizeof(formattedMessage), "You lost %d karma.", -diff);
}
displayMonitorAddMessage(formattedMessage);
}
@@ -979,7 +1027,18 @@ int gameSetGlobalVar(int var, int value)
// 0x443CC8
static int gameLoadGlobalVars()
{
return globalVarsRead("data\\vault13.gam", "GAME_GLOBAL_VARS:", &gGameGlobalVarsLength, &gGameGlobalVars);
if (globalVarsRead("data\\vault13.gam", "GAME_GLOBAL_VARS:", &gGameGlobalVarsLength, &gGameGlobalVars) != 0) {
return -1;
}
gGameGlobalPointers = reinterpret_cast<void**>(internal_malloc(sizeof(*gGameGlobalPointers) * gGameGlobalVarsLength));
if (gGameGlobalPointers == nullptr) {
return -1;
}
memset(gGameGlobalPointers, 0, sizeof(*gGameGlobalPointers) * gGameGlobalVarsLength);
return 0;
}
// 0x443CE8
@@ -988,18 +1047,18 @@ int globalVarsRead(const char* path, const char* section, int* variablesListLeng
_inven_reset_dude();
File* stream = fileOpen(path, "rt");
if (stream == NULL) {
if (stream == nullptr) {
return -1;
}
if (*variablesListLengthPtr != 0) {
internal_free(*variablesListPtr);
*variablesListPtr = NULL;
*variablesListPtr = nullptr;
*variablesListLengthPtr = 0;
}
char string[260];
if (section != NULL) {
if (section != nullptr) {
while (fileReadString(string, 258, stream)) {
if (strncmp(string, section, 16) == 0) {
break;
@@ -1017,19 +1076,19 @@ int globalVarsRead(const char* path, const char* section, int* variablesListLeng
}
char* semicolon = strchr(string, ';');
if (semicolon != NULL) {
if (semicolon != nullptr) {
*semicolon = '\0';
}
*variablesListLengthPtr = *variablesListLengthPtr + 1;
*variablesListPtr = (int*)internal_realloc(*variablesListPtr, sizeof(int) * *variablesListLengthPtr);
if (*variablesListPtr == NULL) {
if (*variablesListPtr == nullptr) {
exit(1);
}
char* equals = strchr(string, '=');
if (equals != NULL) {
if (equals != nullptr) {
sscanf(equals + 1, "%d", *variablesListPtr + *variablesListLengthPtr - 1);
} else {
*variablesListPtr[*variablesListLengthPtr - 1] = 0;
@@ -1042,48 +1101,48 @@ int globalVarsRead(const char* path, const char* section, int* variablesListLeng
}
// 0x443E2C
int _game_state()
int gameGetState()
{
return _game_state_cur;
return gGameState;
}
// 0x443E34
int _game_state_request(int a1)
int gameRequestState(int newGameState)
{
if (a1 == GAME_STATE_0) {
a1 = GAME_STATE_1;
} else if (a1 == GAME_STATE_2) {
a1 = GAME_STATE_3;
} else if (a1 == GAME_STATE_4) {
a1 = GAME_STATE_5;
switch (newGameState) {
case GAME_STATE_0:
newGameState = GAME_STATE_1;
break;
case GAME_STATE_2:
newGameState = GAME_STATE_3;
break;
case GAME_STATE_4:
newGameState = GAME_STATE_5;
break;
}
if (_game_state_cur != GAME_STATE_4 || a1 != GAME_STATE_5) {
_game_state_cur = a1;
return 0;
if (gGameState == GAME_STATE_4 && newGameState == GAME_STATE_5) {
return -1;
}
return -1;
gGameState = newGameState;
return 0;
}
// 0x443E90
void _game_state_update()
void gameUpdateState()
{
int v0;
v0 = _game_state_cur;
switch (_game_state_cur) {
switch (gGameState) {
case GAME_STATE_1:
v0 = GAME_STATE_0;
gGameState = GAME_STATE_0;
break;
case GAME_STATE_3:
v0 = GAME_STATE_2;
gGameState = GAME_STATE_2;
break;
case GAME_STATE_5:
v0 = GAME_STATE_4;
gGameState = GAME_STATE_4;
break;
}
_game_state_cur = v0;
}
// 0x443EF0
@@ -1116,15 +1175,22 @@ static int gameTakeScreenshot(int width, int height, unsigned char* buffer, unsi
static void gameFreeGlobalVars()
{
gGameGlobalVarsLength = 0;
if (gGameGlobalVars != NULL) {
if (gGameGlobalVars != nullptr) {
internal_free(gGameGlobalVars);
gGameGlobalVars = NULL;
gGameGlobalVars = nullptr;
}
if (gGameGlobalPointers != nullptr) {
internal_free(gGameGlobalPointers);
gGameGlobalPointers = nullptr;
}
}
// 0x443F74
static void showHelp()
{
ScopedGameMode gm(GameMode::kHelp);
bool isoWasEnabled = isoDisable();
gameMouseObjectsHide();
@@ -1133,34 +1199,56 @@ static void showHelp()
bool colorCycleWasEnabled = colorCycleEnabled();
colorCycleDisable();
// CE: Help screen uses separate color palette which is incompatible with
// colors in other windows. Setup overlay to hide everything.
int overlay = windowCreate(0, 0, screenGetWidth(), screenGetHeight(), 0, WINDOW_HIDDEN | WINDOW_MOVE_ON_TOP);
int helpWindowX = (screenGetWidth() - HELP_SCREEN_WIDTH) / 2;
int helpWindowY = (screenGetHeight() - HELP_SCREEN_HEIGHT) / 2;
int win = windowCreate(helpWindowX, helpWindowY, HELP_SCREEN_WIDTH, HELP_SCREEN_HEIGHT, 0, WINDOW_HIDDEN | WINDOW_FLAG_0x04);
int win = windowCreate(helpWindowX, helpWindowY, HELP_SCREEN_WIDTH, HELP_SCREEN_HEIGHT, 0, WINDOW_HIDDEN | WINDOW_MOVE_ON_TOP);
if (win != -1) {
unsigned char* windowBuffer = windowGetBuffer(win);
if (windowBuffer != NULL) {
if (windowBuffer != nullptr) {
FrmImage backgroundFrmImage;
int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, 297, 0, 0, 0);
CacheEntry* backgroundHandle;
unsigned char* backgroundData = artLockFrameData(backgroundFid, 0, 0, &backgroundHandle);
if (backgroundData != NULL) {
if (backgroundFrmImage.lock(backgroundFid)) {
paletteSetEntries(gPaletteBlack);
blitBufferToBuffer(backgroundData, HELP_SCREEN_WIDTH, HELP_SCREEN_HEIGHT, HELP_SCREEN_WIDTH, windowBuffer, HELP_SCREEN_WIDTH);
artUnlock(backgroundHandle);
windowUnhide(win);
blitBufferToBuffer(backgroundFrmImage.getData(), HELP_SCREEN_WIDTH, HELP_SCREEN_HEIGHT, HELP_SCREEN_WIDTH, windowBuffer, HELP_SCREEN_WIDTH);
colorPaletteLoad("art\\intrface\\helpscrn.pal");
paletteSetEntries(_cmap);
while (_get_input() == -1 && _game_user_wants_to_quit == 0) {
// CE: Fill overlay with darkest color in the palette. It might
// not be completely black, but at least it's uniform.
bufferFill(windowGetBuffer(overlay),
screenGetWidth(),
screenGetHeight(),
screenGetWidth(),
intensityColorTable[_colorTable[0]][0]);
windowShow(overlay);
windowShow(win);
while (inputGetInput() == -1 && _game_user_wants_to_quit == 0) {
sharedFpsLimiter.mark();
renderPresent();
sharedFpsLimiter.throttle();
}
while (mouseGetEvent() != 0) {
_get_input();
sharedFpsLimiter.mark();
inputGetInput();
renderPresent();
sharedFpsLimiter.throttle();
}
paletteSetEntries(gPaletteBlack);
}
}
windowDestroy(overlay);
windowDestroy(win);
colorPaletteLoad("color.pal");
paletteSetEntries(_cmap);
@@ -1207,7 +1295,7 @@ int showQuitConfirmationDialog()
MessageListItem messageListItem;
messageListItem.num = 0;
if (messageListGetItem(&gMiscMessageList, &messageListItem)) {
rc = showDialogBox(messageListItem.text, 0, 0, 169, 117, _colorTable[32328], NULL, _colorTable[32328], DIALOG_BOX_YES_NO);
rc = showDialogBox(messageListItem.text, nullptr, 0, 169, 117, _colorTable[32328], nullptr, _colorTable[32328], DIALOG_BOX_YES_NO);
if (rc != 0) {
_game_user_wants_to_quit = 2;
}
@@ -1235,62 +1323,64 @@ int showQuitConfirmationDialog()
// 0x44418C
static int gameDbInit()
{
int hashing;
char* main_file_name;
char* patch_file_name;
const char* main_file_name;
const char* patch_file_name;
int patch_index;
char filename[COMPAT_MAX_PATH];
hashing = 0;
main_file_name = NULL;
patch_file_name = NULL;
main_file_name = nullptr;
patch_file_name = nullptr;
if (configGetInt(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_HASHING_KEY, &hashing)) {
_db_enable_hash_table_();
}
configGetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_MASTER_DAT_KEY, &main_file_name);
main_file_name = settings.system.master_dat_path.c_str();
if (*main_file_name == '\0') {
main_file_name = NULL;
main_file_name = nullptr;
}
configGetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_MASTER_PATCHES_KEY, &patch_file_name);
patch_file_name = settings.system.master_patches_path.c_str();
if (*patch_file_name == '\0') {
patch_file_name = NULL;
patch_file_name = nullptr;
}
_master_db_handle = dbOpen(main_file_name, 0, patch_file_name, 1);
if (_master_db_handle == -1) {
int master_db_handle = dbOpen(main_file_name, 0, patch_file_name, 1);
if (master_db_handle == -1) {
showMesageBox("Could not find the master datafile. Please make sure the FALLOUT CD is in the drive and that you are running FALLOUT from the directory you installed it to.");
return -1;
}
configGetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_CRITTER_DAT_KEY, &main_file_name);
main_file_name = settings.system.critter_dat_path.c_str();
if (*main_file_name == '\0') {
main_file_name = NULL;
main_file_name = nullptr;
}
configGetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_CRITTER_PATCHES_KEY, &patch_file_name);
patch_file_name = settings.system.critter_patches_path.c_str();
if (*patch_file_name == '\0') {
patch_file_name = NULL;
patch_file_name = nullptr;
}
_critter_db_handle = dbOpen(main_file_name, 0, patch_file_name, 1);
if (_critter_db_handle == -1) {
_db_select(_master_db_handle);
int critter_db_handle = dbOpen(main_file_name, 0, patch_file_name, 1);
if (critter_db_handle == -1) {
showMesageBox("Could not find the critter datafile. Please make sure the FALLOUT CD is in the drive and that you are running FALLOUT from the directory you installed it to.");
return -1;
}
for (patch_index = 0; patch_index < 1000; patch_index++) {
sprintf(filename, "patch%03d.dat", patch_index);
// SFALL: custom patch file name.
char* path_file_name_template = nullptr;
configGetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_PATCH_FILE, &path_file_name_template);
if (path_file_name_template == nullptr || *path_file_name_template == '\0') {
path_file_name_template = "patch%03d.dat";
}
if (access(filename, 0) == 0) {
dbOpen(filename, 0, NULL, 1);
for (patch_index = 0; patch_index < 1000; patch_index++) {
snprintf(filename, sizeof(filename), path_file_name_template, patch_index);
if (compat_access(filename, 0) == 0) {
dbOpen(filename, 0, nullptr, 1);
}
}
_db_select(_master_db_handle);
if (compat_access("f2_res.dat", 0) == 0) {
dbOpen("f2_res.dat", 0, nullptr, 1);
}
return 0;
}
@@ -1298,23 +1388,22 @@ static int gameDbInit()
// 0x444384
static void showSplash()
{
int splash;
configGetInt(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_SPLASH_KEY, &splash);
int splash = settings.system.splash;
char path[64];
char* language;
if (configGetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_LANGUAGE_KEY, &language) && compat_stricmp(language, ENGLISH) != 0) {
sprintf(path, "art\\%s\\splash\\", language);
const char* language = settings.system.language.c_str();
if (compat_stricmp(language, ENGLISH) != 0) {
snprintf(path, sizeof(path), "art\\%s\\splash\\", language);
} else {
sprintf(path, "art\\splash\\");
snprintf(path, sizeof(path), "art\\splash\\");
}
File* stream;
for (int index = 0; index < SPLASH_COUNT; index++) {
char filePath[64];
sprintf(filePath, "%ssplash%d.rix", path, splash);
snprintf(filePath, sizeof(filePath), "%ssplash%d.rix", path, splash);
stream = fileOpen(filePath, "rb");
if (stream != NULL) {
if (stream != nullptr) {
break;
}
@@ -1325,18 +1414,31 @@ static void showSplash()
}
}
if (stream == NULL) {
if (stream == nullptr) {
return;
}
unsigned char* palette = (unsigned char*)internal_malloc(768);
if (palette == NULL) {
unsigned char* palette = reinterpret_cast<unsigned char*>(internal_malloc(768));
if (palette == nullptr) {
fileClose(stream);
return;
}
unsigned char* data = (unsigned char*)internal_malloc(SPLASH_WIDTH * SPLASH_HEIGHT);
if (data == NULL) {
int version;
fileReadInt32(stream, &version);
if (version != 'RIX3') {
fileClose(stream);
return;
}
short width;
fileRead(&width, sizeof(width), 1, stream);
short height;
fileRead(&height, sizeof(height), 1, stream);
unsigned char* data = reinterpret_cast<unsigned char*>(internal_malloc(width * height));
if (data == nullptr) {
internal_free(palette);
fileClose(stream);
return;
@@ -1345,18 +1447,63 @@ static void showSplash()
paletteSetEntries(gPaletteBlack);
fileSeek(stream, 10, SEEK_SET);
fileRead(palette, 1, 768, stream);
fileRead(data, 1, SPLASH_WIDTH * SPLASH_HEIGHT, stream);
fileRead(data, 1, width * height, stream);
fileClose(stream);
int splashWindowX = (screenGetWidth() - SPLASH_WIDTH) / 2;
int splashWindowY = (screenGetHeight() - SPLASH_HEIGHT) / 2;
_scr_blit(data, SPLASH_WIDTH, SPLASH_HEIGHT, 0, 0, SPLASH_WIDTH, SPLASH_HEIGHT, splashWindowX, splashWindowY);
paletteFadeTo(palette);
int size = 0;
// TODO: Move to settings.
Config config;
if (configInit(&config)) {
if (configRead(&config, "f2_res.ini", false)) {
configGetInt(&config, "STATIC_SCREENS", "SPLASH_SCRN_SIZE", &size);
}
configFree(&config);
}
int screenWidth = screenGetWidth();
int screenHeight = screenGetHeight();
if (size != 0 || screenWidth < width || screenHeight < height) {
int scaledWidth;
int scaledHeight;
if (size == 2) {
scaledWidth = screenWidth;
scaledHeight = screenHeight;
} else {
if (screenHeight * width >= screenWidth * height) {
scaledWidth = screenWidth;
scaledHeight = screenWidth * height / width;
} else {
scaledWidth = screenHeight * width / height;
scaledHeight = screenHeight;
}
}
unsigned char* scaled = reinterpret_cast<unsigned char*>(internal_malloc(scaledWidth * scaledHeight));
if (scaled != nullptr) {
blitBufferToBufferStretch(data, width, height, width, scaled, scaledWidth, scaledHeight, scaledWidth);
int x = screenWidth > scaledWidth ? (screenWidth - scaledWidth) / 2 : 0;
int y = screenHeight > scaledHeight ? (screenHeight - scaledHeight) / 2 : 0;
_scr_blit(scaled, scaledWidth, scaledHeight, 0, 0, scaledWidth, scaledHeight, x, y);
paletteFadeTo(palette);
internal_free(scaled);
}
} else {
int x = (screenWidth - width) / 2;
int y = (screenHeight - height) / 2;
_scr_blit(data, width, height, 0, 0, width, height, x, y);
paletteFadeTo(palette);
}
internal_free(data);
internal_free(palette);
configSetInt(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_SPLASH_KEY, splash + 1);
settings.system.splash = splash + 1;
}
int gameShowDeathDialog(const char* message)
@@ -1385,7 +1532,7 @@ int gameShowDeathDialog(const char* message)
int oldUserWantsToQuit = _game_user_wants_to_quit;
_game_user_wants_to_quit = 0;
int rc = showDialogBox(message, 0, 0, 169, 117, _colorTable[32328], NULL, _colorTable[32328], DIALOG_BOX_LARGE);
int rc = showDialogBox(message, nullptr, 0, 169, 117, _colorTable[32328], nullptr, _colorTable[32328], DIALOG_BOX_LARGE);
_game_user_wants_to_quit = oldUserWantsToQuit;
@@ -1405,3 +1552,55 @@ int gameShowDeathDialog(const char* message)
return rc;
}
void* gameGetGlobalPointer(int var)
{
if (var < 0 || var >= gGameGlobalVarsLength) {
debugPrint("ERROR: attempt to reference global pointer out of range: %d", var);
return nullptr;
}
return gGameGlobalPointers[var];
}
int gameSetGlobalPointer(int var, void* value)
{
if (var < 0 || var >= gGameGlobalVarsLength) {
debugPrint("ERROR: attempt to reference global var out of range: %d", var);
return -1;
}
gGameGlobalPointers[var] = value;
return 0;
}
int GameMode::currentGameMode = 0;
void GameMode::enterGameMode(int gameMode)
{
currentGameMode |= gameMode;
}
void GameMode::exitGameMode(int gameMode)
{
currentGameMode &= ~gameMode;
}
bool GameMode::isInGameMode(int gameMode)
{
return (currentGameMode & gameMode) != 0;
}
ScopedGameMode::ScopedGameMode(int gameMode)
{
this->gameMode = gameMode;
GameMode::enterGameMode(gameMode);
}
ScopedGameMode::~ScopedGameMode()
{
GameMode::exitGameMode(gameMode);
}
} // namespace fallout

View File

@@ -4,6 +4,8 @@
#include "game_vars.h"
#include "message.h"
namespace fallout {
typedef enum GameState {
GAME_STATE_0,
GAME_STATE_1,
@@ -19,8 +21,6 @@ extern const char* asc_5186C8;
extern int _game_user_wants_to_quit;
extern MessageList gMiscMessageList;
extern int _master_db_handle;
extern int _critter_db_handle;
int gameInitWithOptions(const char* windowTitle, bool isMapper, int a3, int a4, int argc, char** argv);
void gameReset();
@@ -32,11 +32,59 @@ bool gameUiIsDisabled();
int gameGetGlobalVar(int var);
int gameSetGlobalVar(int var, int value);
int globalVarsRead(const char* path, const char* section, int* variablesListLengthPtr, int** variablesListPtr);
int _game_state();
int _game_state_request(int a1);
void _game_state_update();
int gameGetState();
int gameRequestState(int newGameState);
void gameUpdateState();
int showQuitConfirmationDialog();
int gameShowDeathDialog(const char* message);
void* gameGetGlobalPointer(int var);
int gameSetGlobalPointer(int var, void* value);
class GameMode {
public:
enum Flags {
kWorldmap = 0x1,
kDialog = 0x4,
kOptions = 0x8,
kSaveGame = 0x10,
kLoadGame = 0x20,
kCombat = 0x40,
kPreferences = 0x80,
kHelp = 0x100,
kEditor = 0x200,
kPipboy = 0x400,
kPlayerTurn = 0x800,
kInventory = 0x1000,
kAutomap = 0x2000,
kSkilldex = 0x4000,
kUseOn = 0x8000,
kLoot = 0x10000,
kBarter = 0x20000,
kHero = 0x40000,
kDialogReview = 0x80000,
kCounter = 0x100000,
kSpecial = 0x80000000,
};
static void enterGameMode(int gameMode);
static void exitGameMode(int gameMode);
static bool isInGameMode(int gameMode);
static int getCurrentGameMode() { return currentGameMode; }
private:
static int currentGameMode;
};
class ScopedGameMode {
public:
ScopedGameMode(int gameMode);
~ScopedGameMode();
private:
int gameMode;
};
} // namespace fallout
#endif /* GAME_H */

View File

@@ -1,11 +1,17 @@
#include "game_config.h"
#include "sfall_config.h"
#include <stdio.h>
#include <string.h>
#include "db.h"
#include "main.h"
#include "platform_compat.h"
namespace fallout {
static void gameConfigResolvePath(const char* section, const char* key);
// A flag indicating if [gGameConfig] was initialized.
//
// 0x5186D0
@@ -118,15 +124,55 @@ bool gameConfigInit(bool isMapper, int argc, char** argv)
configSetInt(&gGameConfig, GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_SORT_SCRIPT_LIST_KEY, 0);
}
// CE: Detect alternative default music directory.
char alternativeMusicPath[COMPAT_MAX_PATH];
strcpy(alternativeMusicPath, "data\\sound\\music\\*.acm");
compat_windows_path_to_native(alternativeMusicPath);
compat_resolve_path(alternativeMusicPath);
char** acms;
int acmsLength = fileNameListInit(alternativeMusicPath, &acms, 0, 0);
if (acmsLength != -1) {
if (acmsLength > 0) {
configSetString(&gGameConfig, GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MUSIC_PATH1_KEY, "data\\sound\\music\\");
configSetString(&gGameConfig, GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MUSIC_PATH2_KEY, "data\\sound\\music\\");
}
fileNameListFree(&acms, 0);
}
// SFALL: Custom config file name.
char* customConfigFileName = nullptr;
configGetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_CONFIG_FILE, &customConfigFileName);
const char* configFileName = customConfigFileName != nullptr && *customConfigFileName != '\0'
? customConfigFileName
: DEFAULT_GAME_CONFIG_FILE_NAME;
// Make `fallout2.cfg` file path.
char* executable = argv[0];
char* ch = strrchr(executable, '\\');
if (ch != NULL) {
if (ch != nullptr) {
*ch = '\0';
sprintf(gGameConfigFilePath, "%s\\%s", executable, GAME_CONFIG_FILE_NAME);
if (isMapper) {
snprintf(gGameConfigFilePath,
sizeof(gGameConfigFilePath),
"%s\\%s",
executable,
MAPPER_CONFIG_FILE_NAME);
} else {
snprintf(gGameConfigFilePath,
sizeof(gGameConfigFilePath),
"%s\\%s",
executable,
configFileName);
}
*ch = '\\';
} else {
strcpy(gGameConfigFilePath, GAME_CONFIG_FILE_NAME);
if (isMapper) {
strcpy(gGameConfigFilePath, MAPPER_CONFIG_FILE_NAME);
} else {
strcpy(gGameConfigFilePath, configFileName);
}
}
// Read contents of `fallout2.cfg` into config. The values from the file
@@ -137,6 +183,15 @@ bool gameConfigInit(bool isMapper, int argc, char** argv)
// whatever was loaded from `fallout2.cfg`.
configParseCommandLineArguments(&gGameConfig, argc, argv);
// CE: Normalize and resolve asset bundle paths.
gameConfigResolvePath(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_MASTER_DAT_KEY);
gameConfigResolvePath(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_MASTER_PATCHES_KEY);
gameConfigResolvePath(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_CRITTER_DAT_KEY);
gameConfigResolvePath(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_CRITTER_PATCHES_KEY);
gameConfigResolvePath(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_CRITTER_PATCHES_KEY);
gameConfigResolvePath(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MUSIC_PATH1_KEY);
gameConfigResolvePath(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MUSIC_PATH2_KEY);
gGameConfigInitialized = true;
return true;
@@ -181,3 +236,13 @@ bool gameConfigExit(bool shouldSave)
return result;
}
static void gameConfigResolvePath(const char* section, const char* key)
{
char* path;
configGetString(&gGameConfig, section, key, &path);
compat_windows_path_to_native(path);
compat_resolve_path(path);
}
} // namespace fallout

View File

@@ -3,8 +3,10 @@
#include "config.h"
// The file name of the main config file.
#define GAME_CONFIG_FILE_NAME "fallout2.cfg"
namespace fallout {
#define DEFAULT_GAME_CONFIG_FILE_NAME "fallout2.cfg"
#define MAPPER_CONFIG_FILE_NAME "mapper2.cfg"
#define GAME_CONFIG_SYSTEM_KEY "system"
#define GAME_CONFIG_PREFERENCES_KEY "preferences"
@@ -120,4 +122,6 @@ bool gameConfigInit(bool isMapper, int argc, char** argv);
bool gameConfigSave();
bool gameConfigExit(bool shouldSave);
} // namespace fallout
#endif /* GAME_CONFIG_H */

File diff suppressed because it is too large Load Diff

View File

@@ -4,6 +4,8 @@
#include "interpreter.h"
#include "obj_types.h"
namespace fallout {
extern Object* gGameDialogSpeaker;
extern bool gGameDialogSpeakerIsPartyMember;
extern int gGameDialogHeadFid;
@@ -13,7 +15,7 @@ int gameDialogInit();
int gameDialogReset();
int gameDialogExit();
bool _gdialogActive();
void gameDialogEnter(Object* a1, int a2);
void gameDialogEnter(Object* speaker, int a2);
void _gdialogSystemEnter();
void gameDialogStartLips(const char* a1);
int gameDialogEnable();
@@ -37,4 +39,6 @@ void gameDialogSetBarterModifier(int modifier);
int gameDialogBarter(int modifier);
void _barter_end_to_talk_to();
} // namespace fallout
#endif /* GAME_DIALOG_H */

Some files were not shown because too many files have changed in this diff Show More