-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.rb
108 lines (104 loc) · 4.83 KB
/
parse.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
require "pp"
require "base64"
read = File.read(ARGV[0], encoding: "CP1251").encode "utf-8", "cp1251"
magic = ([*?a..?z].product([*?a..?z]) - read.chars.each_cons(2).to_a).first.join
all = read.gsub("\r\n", "\n").gsub(/<<END\n(.*?)\nEND/m){ |_| magic + Base64.strict_encode64(_) }.split(/^\[.*/).drop(1).map do |item|
item.scan(/.+/).map do |line|
case line # parsing with no errors
when /\A; \S/, /\A;{67}\z/
when "section_name = smart_terrain" ; break []
when "section_name = actor" ; break []
when "section_name = lights_hanging_lamp" ; break []
when "section_name = device_torch" ; break []
when "section_name = harmonica_a" ; break []
when "section_name = explosive_barrel" ; break []
when "section_name = zone_flame_small" ; break [] # campfire
when "section_name = level_changer" ; break []
when "section_name = helicopter" ; break []
when "section_name = device_pda" ; break []
when "visual_name = physics\\decor\\vedro_01" ; break []
when "visual_name = physics\\large_trash\\poddon" ; break []
when "visual_name = physics\\balon\\bochka_close_1" ; break []
when "visual_name = physics\\decor\\prt\\bottle_bar_1_prt0" ; break []
when "visual_name = physics\\decor\\ventilator_01" ; break []
when "visual_name = physics\\decor\\priemnik_gorizont" ; break []
when "name = esc_matugalnik" ; break []
when /\Aname = trader_physic_object\d+\z/ ; break []
when /\Aname = meshes\\brkbl#\d+\.ogf\z/ ; break []
when /\Aname = clmbl#\d\d?\z/ ; break []
when "name = rostok_cheat _sound_restrictor" ; break []
when "name = yan_attack zombies_space_restrictor" ; break []
when "s_gameid = 0x1"
when /\Ajob_online_condlist = \{+[a-z_\d]+\}\z/
when /\Abone_\d\d?:[a-z_]+ = \S/
when /\Ashape_1?\d:[a-z_]+ = \S/
when /\Ajob_\d\d?:[a-z_]+ = \S/
when /\Aupd:ammo_ids =( 0, 0)?\z/
when /\AstateBegin = [\d:]+\z/
when /\Ainfo_\d\d?:[A-Za-z_]+ = [\d:]+\z/
when /\A(name) = ([a-z_][a-z_\d\.-]*)\z/ ; [$1, $2]
when /\A(visual_name) = ([A-Za-z_\d\\-]+)\z/ ; [$1, $2.downcase]
when /\A(character_profile) = ([A-Za-z_\d]+)\z/ ; [$1, $2]
when /\A(specific_character) = ([A-Za-z_\d]+)\z/ ; [$1, $2]
when /\A(character_name) = ([cА-Яа-яё "\.]+)\z/ ; [$1, $2]
when /\A(section_name) = ([a-z_\d\.-]+)\z/ ; [$1, $2]
when /\A(dest_level_name) = ([A-Za-z_\d]+)\z/ ; [$1, $2.downcase]
when /\A(custom_data) = (cond = 0\.2)\z/ ; [$1, $2]
when /\A(custom_data) = (\[(?:dont_spawn_character_supplies|ph_heavy|arena_zone)\])\z/
when /\Asquad_id = \S/
when /\Avisual_flags = 0x1\z/
when /\Aspawned_obj = (\d+(, \d+)*)?\z/
when "upd:quaternion = -1, -1, 1, -1"
when /\A[a-z_:]+ = ?\z/
when /\A([a-z_:]+) = (\S.*)/
next if %w{
s_flags object_flags light_flags
bones_mask bbox_min bbox_max upd:timestamp s_gameid physic_type fixed_bones main_color_animator glow_texture ambient_texture
equipment_preferences main_weapon_preferences
s_rp upd:num_items upd:creature_flags artefact_position_offset dest_graph_point
duration_end motion_name engine_sound main_color
base_in_restrictors base_out_restrictors
job_online_condlist skeleton_name
}.include? $1
[$1, case v = $2
when /\A\d+\z/ ; v.to_i
when /\A-?\d+\.\d+\z/ ; v.to_f
when /\A[a-z_-]+\z/ ; v
when /\A(-?\d+(?:\.\d+(?:e-\d+)?)?), (-?\d+(?:\.\d+(?:e[-+]\d+)?)?), (-?\d+(\.\d+(e-\d+)?)?)\z/ ; [$1.to_f, $2.to_f, $3.to_f]
when /\A#{magic}/
data = Base64.strict_decode64(v[2..-1])
break [] if [
"<<END\n[collide]\nignore_static\nEND",
"<<END\n[collide]\nignore_static\n\n[logic]\ncfg = scripts\\door_metal_small.ltx\nEND",
"<<END\n[collide]\nignore_static\n\n[logic]\ncfg = scripts\\door_metal_small_unlocked.ltx\nEND",
].include? data
data[6..-4].scan(/\[([^\]]*)\]\n(.*?)\n(?=\[|\z)/m).map do |name, data|
[name, data.split(?\n)]
end
else ; fail line.inspect
end ]
else ; fail line.inspect
end
end.compact.to_h.reject do |k,| # rejecting parsed but not interesting data
%w{
condition
version script_version
distance shapes restrictor_type direction mass
game_vertex_id level_vertex_id
offline_interactive_radius skeleton_flags root_bone bones_count
spawn_id upd:torch_flags max_power artefact_spawn_count
g_team g_group g_squad
ammo_current ammo_elapsed ammo_left
enabled_time disabled_time start_time_shift
reputation money rank
smart_terrain_id smart_terrain_task_active job_online
spawned_obj trader_flags
base_out_restrictors weapon_state
}.include? k or /\Aupd:/ =~ k && k != "upd:health"
end
end - [{}]
require "yaml"
puts YAML.dump all
require "mll"
PP.pp MLL::tally[all.flat_map &:keys].sort_by(&:last), STDERR
STDERR.puts "OK"