Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Include the required headers from httpd */
- #include "httpd.h"
- #include "http_core.h"
- #include "http_protocol.h"
- #include "http_request.h"
- #include "apr_strings.h"
- #include "apr_network_io.h"
- #include "apr_md5.h"
- #include "apr_sha1.h"
- #include "apr_hash.h"
- #include "apr_base64.h"
- #include "apr_dbd.h"
- #include <apr_file_info.h>
- #include <apr_file_io.h>
- #include <apr_tables.h>
- #include "util_script.h"
- // byte-swapping functions
- // special thanks to: http://stackoverflow.com/a/2637138
- #include <stdint.h>
- /* Define prototypes of our functions in this module */
- static void register_hooks(apr_pool_t *pool);
- static int halo_filetypes_handler(request_rec *r);
- uint16_t swap_uint16(uint16_t val);
- int16_t swap_int16(int16_t val);
- uint32_t swap_uint32(uint32_t val);
- int32_t swap_int32(int32_t val);
- int64_t swap_int64(int64_t val);
- uint64_t swap_uint64(uint64_t val);
- //! Byte swap unsigned short
- uint16_t swap_uint16( uint16_t val )
- {
- return (val << 8) | (val >> 8 );
- }
- //! Byte swap short
- int16_t swap_int16( int16_t val )
- {
- return (val << 8) | ((val >> 8) & 0xFF);
- }
- //! Byte swap unsigned int
- uint32_t swap_uint32( uint32_t val )
- {
- val = ((val << 8) & 0xFF00FF00 ) | ((val >> 8) & 0xFF00FF );
- return (val << 16) | (val >> 16);
- }
- //! Byte swap int
- int32_t swap_int32( int32_t val )
- {
- val = ((val << 8) & 0xFF00FF00) | ((val >> 8) & 0xFF00FF );
- return (val << 16) | ((val >> 16) & 0xFFFF);
- }
- int64_t swap_int64( int64_t val )
- {
- val = ((val << 8) & 0xFF00FF00FF00FF00ULL ) | ((val >> 8) & 0x00FF00FF00FF00FFULL );
- val = ((val << 16) & 0xFFFF0000FFFF0000ULL ) | ((val >> 16) & 0x0000FFFF0000FFFFULL );
- return (val << 32) | ((val >> 32) & 0xFFFFFFFFULL);
- }
- uint64_t swap_uint64( uint64_t val )
- {
- val = ((val << 8) & 0xFF00FF00FF00FF00ULL ) | ((val >> 8) & 0x00FF00FF00FF00FFULL );
- val = ((val << 16) & 0xFFFF0000FFFF0000ULL ) | ((val >> 16) & 0x0000FFFF0000FFFFULL );
- return (val << 32) | (val >> 32);
- }
- // file format structures
- typedef struct {
- // 0, 36
- char *tagtype; // actr
- uint32_t random_number1;
- uint32_t header_size; // 64
- // 48, 8
- uint16_t tag_version; // 2
- uint16_t engine_version; // 255
- char *engine; // blam
- }header_actr;
- typedef struct {
- uint32_t flags_bf;
- uint32_t more_flags_bf;
- // 72, 12
- uint16_t actor_type_list;
- // 86, 2
- float perception_maximum_vision_distance;
- float perception_central_vision_angle_rad;
- float perception_maximum_vision_angle_rad;
- // 100, 4
- float perception_peripheral_vision_angle_rad;
- float perception_peripheral_distance;
- // 112, 4
- float perception_standing_gun_offset_i;
- float perception_standing_gun_offset_j;
- float perception_standing_gun_offset_k;
- float perception_crouching_gun_offset_i;
- float perception_crouching_gun_offset_j;
- float perception_crouching_gun_offset_k;
- float perception_hearing_distance;
- float perception_notice_projectile_chance;
- float perception_notice_vehicle_chance;
- // 152, 8
- float perception_combat_perception_time;
- float perception_guard_perception_time;
- float perception_non_combat_perception_time;
- // 172 -- 3 calculated float values, 0 until compiled, compiled defaults:
- float unknown_1; // 0.0555556
- float unknown_2; // 0.0238095
- float unknown_3; // 0.0166667 or 0
- // 184, 8
- float movement_dive_into_cover_chance;
- float movement_emerge_from_cover_chance;
- float movement_dive_from_grenade_chance;
- float movement_path_finding_radius;
- float movement_glass_ignorance_chance;
- float movement_stationary_movement_distance;
- float movement_free_flying_sidestep;
- float movement_begin_moving_angle_rad;
- // 224, 4
- float looking_maximum_aiming_deviation_yaw_rad;
- float looking_maximum_aiming_deviation_pitch_rad;
- float looking_maximum_looking_deviation_yaw_rad;
- float looking_maximum_looking_deviation_pitch_rad;
- float looking_non_combat_look_delta_left_rad;
- float looking_non_combat_look_delta_right_rad;
- float looking_combat_look_delta_left_rad;
- float looking_combat_look_delta_right_rad;
- float looking_idle_aiming_range_yaw_rad;
- float looking_idle_aiming_range_pitch_rad;
- float looking_idle_looking_range_yaw_rad;
- float looking_idle_looking_range_pitch_rad;
- float looking_event_look_time_modifier_from;
- float looking_event_look_time_modifier_to;
- float looking_non_combat_idle_facing_from;
- float looking_non_combat_idle_facing_to;
- float looking_non_combat_idle_aiming_from;
- float looking_non_combat_idle_aiming_to;
- float looking_non_combat_idle_looking_from;
- float looking_non_combat_idle_looking_to;
- float looking_guard_idle_facing_from;
- float looking_guard_idle_facing_to;
- float looking_guard_idle_aiming_from;
- float looking_guard_idle_aiming_to;
- float looking_guard_idle_looking_from;
- float looking_guard_idle_looking_to;
- float looking_combat_idle_facing_from;
- float looking_combat_idle_facing_to;
- float looking_combat_idle_aiming_from;
- float looking_combat_idle_aiming_to;
- float looking_combat_idle_looking_from;
- float looking_combat_idle_looking_to;
- // 356, 8
- // calculated values, 0 until compiled: 3 unknown values of the same data (0xb33bbd2e) followed by 1 float value of 0.5
- uint32_t unknown_4;
- uint32_t unknown_5;
- uint32_t unknown_6;
- float unknown_7;
- // dependency 1: looking -- DO NOT USE -- weap
- char *d1_tagclass;
- uint32_t d1_tagnamepointer;
- uint32_t d1_tagnamestringlength;
- uint32_t d1_tagid;
- // 396, 268
- // dependency 2: looking -- DO NOT USE -- proj
- char *d2_tagclass;
- uint32_t d2_tagnamepointer;
- uint32_t d2_tagnamestringlength;
- uint32_t d2_tagid;
- uint16_t unopposable_unreachable_danger_trigger_list;
- uint16_t unopposable_vehicle_danger_trigger_list;
- uint16_t unopposable_player_danger_trigger_list;
- // 686, 2
- float unopposable_danger_trigger_time_from;
- float unopposable_danger_trigger_time_to;
- uint16_t unopposable_friends_killed_trigger;
- uint16_t unopposable_friends_retreating_trigger;
- // 700, 12
- float unopposable_retreat_time_from;
- float unopposable_retreat_time_to;
- // 720, 8
- float panic_cowering_time_from;
- float panic_cowering_time_to;
- float panic_friend_killed_panic_chance;
- uint16_t panic_leader_type_list;
- // 742, 2
- float panic_leader_killed_panic_chance;
- float panic_panic_damage_threshold;
- float panic_surprise_distance;
- // 756, 28
- float defensive_hide_behind_cover_time_from;
- float defensive_hide_behind_cover_time_to;
- float defensive_hide_target_not_visible_time;
- float defensive_hide_shield_fraction;
- float defensive_attack_shield_fraction;
- float defensive_pursue_shield_fraction;
- // 808, 16
- uint16_t defensive_defensive_crouch_type_list;
- // 826, 2
- float defensive_attacking_crouch_threshold;
- float defensive_defending_crouch_threshold;
- float defensive_minimum_stand_time;
- float defensive_minimum_crouch_time;
- float defensive_defending_hide_time_modifier;
- float defensive_attacking_evasion_threshold;
- float defensive_defending_evasion_threshold;
- float defensive_evasion_seek_cover_chance;
- float defensive_evasion_delay_time;
- float defensive_maximum_seek_cover_distance;
- float defensive_cover_damage_threshold;
- float defensive_stalking_discovery_time;
- float defensive_stalking_maximum_distance;
- float defensive_stationary_facing_angle_rad;
- float defensive_change_facing_stand_time;
- // 888, 4
- float pursuit_uncover_delay_time_from;
- float pursuit_uncover_delay_time_to;
- float pursuit_target_search_time_from;
- float pursuit_target_search_time_to;
- float pursuit_pursuit_position_time_from;
- float pursuit_pursuit_position_time_to;
- uint16_t pursuit_num_positions_coord;
- uint16_t pursuit_num_positions_normal;
- // 920, 32
- float berserk_melee_attack_delay;
- float berserk_melee_fudge_factor;
- float berserk_melee_charge_time;
- float berserk_melee_leap_range_from;
- float berserk_melee_leap_range_to;
- float berserk_melee_leap_velocity;
- float berserk_melee_leap_chance;
- float berserk_melee_leap_ballistic;
- float berserk_berserk_damage_amount;
- float berserk_berserk_damage_threshold;
- float berserk_berserk_proximity;
- float berserk_suicide_sensing_distance;
- float berserk_berserk_grenade_chance;
- // 1004, 12
- float firing_positions_guard_position_time_from;
- float firing_positions_guard_position_time_to;
- float firing_positions_combat_position_time_from;
- float firing_positions_combat_position_time_to;
- float firing_positions_old_position_avoid_distance;
- float firing_positions_friend_avoid_distance;
- // 1040, 40
- float communication_non_combat_idle_speech_time_from;
- float communication_non_combat_idle_speech_time_to;
- float communication_combat_idle_speech_time_from;
- float communication_combat_idle_speech_time_to;
- // 1096, 176
- // dependency 3: communication -- DO NOT USE -- actr
- char *d3_tagclass;
- uint32_t d3_tagnamepointer;
- uint32_t d3_tagnamestringlength;
- uint32_t d3_tagid;
- // 1288, 48
- // 1336, tpns 1-3
- } meta_actr;
- /* Define our module as an entity and assign a function for registering hooks */
- module AP_MODULE_DECLARE_DATA halo_filetypes_module =
- {
- STANDARD20_MODULE_STUFF,
- NULL, // Per-directory configuration handler
- NULL, // Merge handler for per-directory configurations
- NULL, // Per-server configuration handler
- NULL, // Merge handler for per-server configurations
- NULL, // Any directives we may have for httpd
- register_hooks // Our hook registering function
- };
- /* register_hooks: Adds a hook to the httpd process */
- static void register_hooks(apr_pool_t *pool)
- {
- /* Hook the request handler */
- ap_hook_handler(halo_filetypes_handler, NULL, NULL, APR_HOOK_LAST);
- }
- /* The handler function for our module.
- * This is where all the fun happens!
- */
- static int halo_filetypes_handler(request_rec *r)
- {
- int rcheck, file_exists_nodir;
- apr_finfo_t finfo;
- apr_file_t* file;
- apr_status_t error;
- char *filename_localname;
- uint32_t filesize;
- apr_size_t readBytes;
- /* First off, we need to check if this is a call for the "example" handler.
- * If it is, we accept it and do our things, it not, we simply return DECLINED,
- * and Apache will try somewhere else.
- */
- if (!r->handler || strcmp(r->handler, "halo-filetypes-handler")) return (DECLINED);
- // check to see if file exists, it isn't a directory, and we have permissions to read it
- rcheck = apr_stat(&finfo, r->filename, APR_FINFO_MIN, r->pool);
- if (rcheck == APR_SUCCESS) {
- file_exists_nodir =
- (
- (finfo.filetype != APR_NOFILE)
- && !(finfo.filetype & APR_DIR)
- );
- if (!file_exists_nodir) return HTTP_NOT_FOUND; // Return a 404 if not found.
- }
- // If apr_stat failed, we're probably not allowed to check this file.
- //else return HTTP_FORBIDDEN;
- else return HTTP_NOT_FOUND;
- filename_localname = strstr(r->filename, "tags/");
- // The first thing we will do is write a simple "Hello, world!" back to the client.
- ap_set_content_type(r, "text/html");
- char *html_header = apr_pstrcat(r->pool, \
- "\
- <html>\n\
- <head>\n\
- <title>GXV INCY | ", filename_localname, "</title>\n\
- <link rel=\"stylesheet\" href=\"http://files.galaxyverge.com/styles/incy/main.css\">\n\
- </head>\n\
- <body>\n\
- ", NULL);
- char *html_body = "";
- char *html_footer = apr_pstrcat(r->pool, \
- "\
- </body>\n\
- </html>", NULL);
- //ap_rprintf(r, "The requested filename is:<br>%s", r->filename); // full path, e.g. "/home/vm_shared/http/incy/tags/sparky/sound/charity_ambience.sound"
- // check for valid file extension present and parse accordingly
- //if (strstr(r->filename,".actor_variant") != NULL)
- if (strcmp(".actor" , strstr(r->filename,".")) == 0)
- {
- // actor tag type
- header_actr *head = apr_pcalloc(r->pool, sizeof(header_actr));
- meta_actr *meta = apr_pcalloc(r->pool, sizeof(meta_actr));
- // open the file
- error = apr_file_open(&file, r->filename, APR_READ, APR_OS_DEFAULT, r->pool);
- // check for errors with the file opening attempt
- if (error == 0)
- {
- //ap_rprintf(r, "[successfully opened the tag file]");
- }
- else if (error == 404)
- {
- return HTTP_NOT_FOUND;
- }
- else
- {
- return error;
- }
- // get the file size
- //apr_stat(&finfo, r->filename, APR_FINFO_SIZE, r->pool);
- //ap_rprintf(r, "[The file is %u bytes.]", (uint32_t)finfo.size); // works fine
- // copy the file into a memory buffer
- readBytes = finfo.size;
- char memorybuffer[(uint32_t)readBytes];// = apr_pcalloc(r->pool, (uint32_t)finfo.size);
- apr_file_read(file, memorybuffer, &readBytes);
- // parse the memory buffer
- //ap_rprintf(r, "Memory buffer is %u bytes.", (uint32_t)sizeof(memorybuffer)); // works fine
- head->tagtype = apr_pstrndup(r->pool, &memorybuffer[36], 4);
- head->random_number1 = swap_uint32(*(uint32_t*)(void*)&memorybuffer[40]); // special thanks to nil
- // output the information
- html_body = apr_pstrcat(r->pool, \
- "<p>The <a href=\"http://halo.galaxyverge.com/index/FileFormats/Actor\">Actor</a> tag type stores information about basic character behavior for artificial intelligence. It is partnered with <a href=\"http://halo.galaxyverge.com/index/FileFormats/ActorVariant\">Actor Variant</a> which specifies behavior variations in greater detail.</p>\n\
- <div id=\"tag_header\">\n\
- <span class=\"section_name\">Information</span><br>\n\
- <span class=\"section_body\">\n\
- <span class=\"entry_name\">File Size on Server</span>\n <span class=\"entry_meta\">", apr_psprintf(r->pool, "%u", (uint32_t)finfo.size), " bytes</span>\n\
- <span class=\"entry_name\">Tag Class</span>\n <span class=\"entry_meta\">", apr_psprintf(r->pool, "%s", head->tagtype), "</span>\n\
- <span class=\"entry_name\">Tag Random ID</span>\n <span class=\"entry_meta\">", apr_psprintf(r->pool, "%#X", head->random_number1), "</span>\n\
- </span>\n\
- </div>\n", NULL);
- //ap_rprintf(r, "");
- }
- else if (strcmp(".actor_variant" , strstr(r->filename,".")) == 0)
- {
- // actor variant tag type
- ap_rprintf(r, "This is an <strong>actor variant</strong> tag type.");
- }
- ap_rprintf(r, "%s%s%s", html_header, html_body, html_footer);
- return OK;
- }
- /* Commands for incremental builds:
- cd /home/programs/apache_modules
- apxs -i -c -n mod_halo_filetypes mod_halo_filetypes.c
- service httpd restart
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement