Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Config
- INDENT = " "
- PRINT_TO_CONSOLE = true -- only prints basic script info
- SAVE_DIRECTORY = "sapp\\map scripts" -- this sapp folder is located in the haloded.exe/haloceded.exe directory, not in your documents folder
- -- End of Config
- script_types = {
- [0] = "startup",
- [1] = "dormant",
- [2] = "continuous",
- [3] = "static",
- [4] = "stub"
- }
- return_types = {
- [0] = "unparsed",
- [1] = "\"special form\"",
- [2] = "\"function name\"",
- [3] = "passthrough",
- [4] = "void",
- [5] = "boolean",
- [6] = "real",
- [7] = "short",
- [8] = "long",
- [9] = "string",
- [10] = "script",
- [11] = "trigger_volume",
- [12] = "cutscene_flag",
- [13] = "cutscene_camera_point",
- [14] = "cutscene_title",
- [15] = "cutscene_recording",
- [16] = "device_group",
- [17] = "ai",
- [18] = "ai_command_list",
- [19] = "starting_profile",
- [20] = "conversation",
- [21] = "navpoint",
- [22] = "hud_message",
- [23] = "object_list",
- [24] = "sound",
- [25] = "effect",
- [26] = "damage",
- [27] = "looping_sound",
- [28] = "animation_graph",
- [29] = "actor_variant",
- [30] = "damage_effect",
- [31] = "object_definition",
- [32] = "game_difficulty",
- [33] = "team",
- [34] = "ai_default_state",
- [35] = "actor_type",
- [36] = "hud_corner",
- [37] = "object",
- [38] = "unit",
- [39] = "vehicle",
- [40] = "weapon",
- [41] = "device",
- [42] = "scenery",
- [43] = "object_name",
- [44] = "unit_name",
- [45] = "vehicle_name",
- [46] = "weapon_name",
- [47] = "device_name",
- [48] = "scenery_name"
- }
- script_syntax_nodes = {}
- script_string_offset = nil
- api_version = "1.9.0.0"
- function OnScriptLoad()
- register_callback(cb['EVENT_GAME_START'], "OnGameStart")
- end
- function OnGameStart()
- local map_name = get_var(0,"$map")
- local scenario_metaid = read_dword(0x40440004)
- local scenario_tag = lookup_tag(scenario_metaid)
- local scenario_data = read_dword(scenario_tag + 0x14)
- local globals_count = read_dword(scenario_data + 0x4A8)
- local scripts_count = read_dword(scenario_data + 0x49C)
- if(globals_count == 0 and scripts_count == 0) then
- if(PRINT_TO_CONSOLE) then
- cprint(string.format("No scenario scripts found in \"%s.map\"", map_name))
- end
- return
- end
- local file, error = io.open(SAVE_DIRECTORY .. "\\" .. map_name .. ".txt", "w")
- if(error) then
- os.execute("mkdir \"" .. SAVE_DIRECTORY .. "\"")
- file, error = io.open(SAVE_DIRECTORY .. "\\" .. map_name .. ".txt", "w")
- if(error) then
- if(PRINT_TO_CONSOLE) then
- cprint(error)
- end
- return
- end
- end
- script_string_offset = read_dword(scenario_data + 0x494)
- local script_syntax_data = read_dword(scenario_data + 0x480)
- local script_syntax_node_count = read_short(script_syntax_data + 0x2E)
- local script_syntax_node_data = script_syntax_data + 0x38
- for i=0,script_syntax_node_count-1 do
- script_syntax_nodes[i] = {
- ["salt"] = read_short(script_syntax_node_data + i*20),
- ["return_type"] = read_short(script_syntax_node_data + i*20 + 0x4),
- ["expression_type"] = read_short(script_syntax_node_data + i*20 + 0x6),
- ["sibling_id"] = read_int(script_syntax_node_data + i*20 + 0x8),
- ["sibling_index"] = read_short(script_syntax_node_data + i*20 + 0x8),
- ["sibling_salt"] = read_short(script_syntax_node_data + i*20 + 0xA),
- ["string_offset"] = read_dword(script_syntax_node_data + i*20 + 0xC),
- ["real"] = read_float(script_syntax_node_data + i*20 + 0x10),
- ["child_id"] = read_dword(script_syntax_node_data + i*20 + 0x10),
- ["child_index"] = read_short(script_syntax_node_data + i*20 + 0x10),
- ["child_salt"] = read_short(script_syntax_node_data + i*20 + 0x12)
- }
- end
- local globals_data = read_dword(scenario_data + 0x4AC)
- for i=0,globals_count-1 do
- local global_name = read_string(globals_data + i*92)
- local global_type = read_byte(globals_data + i*92 + 0x20)
- local global_init_index = read_short(globals_data + i*92 + 0x28)
- local global_data = get_syntax_node_data(global_init_index, 0, true)
- file:write(string.format("(global %s %s %s)", return_types[global_type], global_name, global_data))
- if(i ~= globals_count-1) then
- file:write("\n")
- end
- end
- local scripts_data = read_dword(scenario_data + 0x4A0)
- for i=0,scripts_count-1 do
- local script_name = read_string(scripts_data + i*92)
- local script_type = read_byte(scripts_data + i*92 + 0x20)
- local return_type = read_byte(scripts_data + i*92 + 0x22)
- local root_id = read_int(scripts_data + i*92 + 0x24)
- local root_index = read_short(scripts_data + i*92 + 0x24)
- local root_salt = read_short(scripts_data + i*92 + 0x26)
- local script_data = get_syntax_node_data(root_index, 1, false)
- if(script_type > 2) then -- static and stub
- if(PRINT_TO_CONSOLE) then
- cprint(string.format("[%s] \"%s\" - script type: %s %s", i, script_name, script_types[script_type], return_types[return_type]))
- end
- file:write(string.format("\n\n(script %s %s %s %s\n)", script_types[script_type], return_types[return_type], script_name, script_data))
- else
- if(PRINT_TO_CONSOLE) then
- cprint(string.format("[%s] \"%s\" - script type: %s", i, script_name, script_types[script_type]))
- end
- file:write(string.format("\n\n(script %s %s %s\n)", script_types[script_type], script_name, script_data))
- end
- end
- script_syntax_nodes = {}
- script_string_offset = nil
- file:close()
- end
- function get_syntax_node_data(Index, Indent, IsGlobal)
- local node = script_syntax_nodes[Index]
- local indent = ""
- for i=0,Indent-1 do
- indent = indent .. INDENT
- end
- local str = ""
- if(node["expression_type"] == 8) then
- if(IsGlobal) then
- str = "(" .. get_syntax_node_data(node["child_index"], Indent, IsGlobal) .. ")"
- else
- str = "\n" .. indent .. "(" .. get_syntax_node_data(node["child_index"], Indent+1, IsGlobal)
- local child_expressions = false
- local child_node = script_syntax_nodes[node["child_index"]]
- while(child_node["expression_type"] ~= 8 and child_node["sibling_id"] ~= -1) do
- local temp_node = script_syntax_nodes[child_node["sibling_index"]]
- if(temp_node["expression_type"] == 8) then
- child_expressions = true
- end
- child_node = temp_node
- end
- if(child_expressions) then
- str = str .. "\n" .. indent .. ")"
- else
- str = str .. ")"
- end
- end
- elseif(node["expression_type"] == 9) then
- if(return_types[node["return_type"]] == "boolean") then
- if(node["child_index"] == -256) then
- str = "false"
- elseif(node["child_index"] == -255) then
- str = "true"
- end
- elseif(return_types[node["return_type"]] == "real") then
- str = node["real"]
- elseif(return_types[node["return_type"]] == "short") then
- str = node["child_index"]
- elseif(return_types[node["return_type"]] == "long") then
- str = node["child_id"]
- elseif(return_types[node["return_type"]] == "string") then
- str = "\"" .. read_string(script_string_offset + node["string_offset"]) .. "\""
- elseif(return_types[node["return_type"]] ~= "void") then
- local temp_str = read_string(script_string_offset + node["string_offset"])
- if(temp_str:find(" ") or temp_str:len() == 0) then
- temp_str = "\"" .. temp_str .. "\""
- end
- str = temp_str
- end
- elseif(node["expression_type"] == 10) then
- if(node["child_salt"] ~= 0) then
- str = "\n" .. indent .. "(" .. get_syntax_node_data(node["child_index"], Indent, IsGlobal) .. ")"
- end
- elseif(node["expression_type"] == 13) then
- str = read_string(script_string_offset + node["string_offset"])
- end
- if(node["sibling_id"] ~= -1 and node["sibling_salt"] ~= 0) then
- str = str .. " " .. get_syntax_node_data(node["sibling_index"], Indent, IsGlobal)
- end
- return(str)
- end
- function OnScriptUnload() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement