pgtools 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +25 -25
  3. data/bin/bxm_decoder +2 -2
  4. data/bin/bxm_encoder +2 -2
  5. data/bin/clh_convert +2 -2
  6. data/bin/clp_convert +2 -2
  7. data/bin/clw_convert +2 -2
  8. data/bin/dat_creator +2 -2
  9. data/bin/dat_extractor +2 -2
  10. data/bin/dat_ls +2 -2
  11. data/bin/eff_idd_creator +2 -2
  12. data/bin/eff_idd_extractor +2 -2
  13. data/bin/exp_convert_wiiu_pc +2 -2
  14. data/bin/exp_tool +2 -2
  15. data/bin/mot_convert_wiiu_pc +2 -2
  16. data/bin/mot_tool +2 -2
  17. data/bin/pkz_extractor +2 -2
  18. data/bin/scr_creator +2 -2
  19. data/bin/scr_extractor +2 -2
  20. data/bin/wmb_cleanup +2 -2
  21. data/bin/wmb_common_bones +2 -2
  22. data/bin/wmb_convert_pc_switch +2 -2
  23. data/bin/wmb_convert_wiiu_pc +2 -2
  24. data/bin/wmb_export_assimp +2 -2
  25. data/bin/wmb_get_bone_map +2 -2
  26. data/bin/wmb_import_assimp +2 -2
  27. data/bin/wmb_import_nier +2 -2
  28. data/bin/wmb_import_wiiu +2 -2
  29. data/bin/wtb_convert_wiiu_pc +2 -2
  30. data/bin/wtx_creator +2 -2
  31. data/bin/wtx_extractor +2 -2
  32. data/lib/bayonetta/alignment.rb +0 -0
  33. data/lib/bayonetta/bone.rb +0 -0
  34. data/lib/bayonetta/bxm.rb +180 -180
  35. data/lib/bayonetta/clh.rb +159 -159
  36. data/lib/bayonetta/clp.rb +212 -212
  37. data/lib/bayonetta/clw.rb +166 -166
  38. data/lib/bayonetta/dat.rb +261 -261
  39. data/lib/bayonetta/eff.rb +314 -314
  40. data/lib/bayonetta/endianness.rb +0 -0
  41. data/lib/bayonetta/exp.rb +768 -768
  42. data/lib/bayonetta/linalg.rb +416 -416
  43. data/lib/bayonetta/material_database.yaml +2581 -2581
  44. data/lib/bayonetta/mot.rb +763 -763
  45. data/lib/bayonetta/pkz.rb +63 -63
  46. data/lib/bayonetta/scr.rb +0 -0
  47. data/lib/bayonetta/tools/bxm_decoder.rb +23 -23
  48. data/lib/bayonetta/tools/bxm_encoder.rb +37 -37
  49. data/lib/bayonetta/tools/clh_convert.rb +60 -60
  50. data/lib/bayonetta/tools/clp_convert.rb +70 -70
  51. data/lib/bayonetta/tools/clw_convert.rb +60 -60
  52. data/lib/bayonetta/tools/dat_creator.rb +57 -57
  53. data/lib/bayonetta/tools/dat_extractor.rb +94 -94
  54. data/lib/bayonetta/tools/dat_ls.rb +106 -106
  55. data/lib/bayonetta/tools/eff_idd_creator.rb +66 -66
  56. data/lib/bayonetta/tools/eff_idd_extractor.rb +73 -73
  57. data/lib/bayonetta/tools/exp_convert_wiiu_pc.rb +33 -33
  58. data/lib/bayonetta/tools/exp_tool.rb +48 -48
  59. data/lib/bayonetta/tools/mot_convert_wiiu_pc.rb +33 -33
  60. data/lib/bayonetta/tools/mot_tool.rb +0 -0
  61. data/lib/bayonetta/tools/pkz_extractor.rb +75 -75
  62. data/lib/bayonetta/tools/scr_creator.rb +63 -63
  63. data/lib/bayonetta/tools/scr_extractor.rb +78 -78
  64. data/lib/bayonetta/tools/wmb_cleanup.rb +250 -250
  65. data/lib/bayonetta/tools/wmb_common_bones.rb +45 -45
  66. data/lib/bayonetta/tools/wmb_convert_pc_switch.rb +35 -35
  67. data/lib/bayonetta/tools/wmb_convert_wiiu_pc.rb +33 -33
  68. data/lib/bayonetta/tools/wmb_export_assimp.rb +479 -479
  69. data/lib/bayonetta/tools/wmb_get_bone_map.rb +50 -50
  70. data/lib/bayonetta/tools/wmb_import_assimp.rb +735 -735
  71. data/lib/bayonetta/tools/wmb_import_geometry_wiiu_pc.rb +472 -472
  72. data/lib/bayonetta/tools/wmb_import_nier.rb +309 -309
  73. data/lib/bayonetta/tools/wtb_convert_wiiu_pc.rb +95 -95
  74. data/lib/bayonetta/tools/wtb_import_textures.rb +103 -103
  75. data/lib/bayonetta/tools/wtx_creator.rb +69 -69
  76. data/lib/bayonetta/tools/wtx_extractor.rb +85 -85
  77. data/lib/bayonetta/vertex_types.yaml +0 -0
  78. data/lib/bayonetta/vertex_types2.yaml +0 -0
  79. data/lib/bayonetta/vertex_types_nier.yaml +145 -145
  80. data/lib/bayonetta/wmb.rb +2455 -2443
  81. data/lib/bayonetta/wmb3.rb +759 -759
  82. data/lib/bayonetta/wtb.rb +481 -481
  83. data/lib/bayonetta.rb +60 -60
  84. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e36398b3fbef0f7e869fce605df24a9cd6e22ac5c6b391f49254474d129d942
4
- data.tar.gz: 92d27315789a8c08f6dcefa721bf32a1af992bb4b848e1597b402494208bbe5e
3
+ metadata.gz: b93db3608af5f88382180905f15693b4b892a8123609b9bf2763e540ab54d771
4
+ data.tar.gz: 88b27f7585d3f49eaaf5e32d00b825eea2144d6af8ba94c7b21c4b983acb6dc2
5
5
  SHA512:
6
- metadata.gz: 904a07ac609d5d594d80f94e9611dd48ac747dca93407188081e1e678b82a0084592d039cfbad5082670223e09a068ae844fd2b536b148fcad6ace8eb54f2a62
7
- data.tar.gz: 2767aca08e04ec6a22de97726bd482c59d90aeea08349a102902139c80e6168ab5032443d043da2664c519be935714f4293dc77900c615d7cdbc7e7d07e60d2e
6
+ metadata.gz: 0fbe72c0bf9c198551af629a6bb6ab8a991d4c9a2379065ab4b915ac65eccd77007cf24b9e302ea0063ae6ef544a13039ee7764135a84ec8f4bb4e47585e5b7e
7
+ data.tar.gz: 7a240821e4053eabb8d7b20e93ee06bcc3a76fbc366b452fd829bc2b446ca55b34dafbb4e905f1a7f91e3978df474d8485474249b51ebe4b0b35f08d757e01ee
data/LICENSE CHANGED
@@ -1,25 +1,25 @@
1
- BSD 2-Clause License
2
-
3
- Copyright (c) 2017-2021, Brice Videau
4
- All rights reserved.
5
-
6
- Redistribution and use in source and binary forms, with or without
7
- modification, are permitted provided that the following conditions are met:
8
-
9
- * Redistributions of source code must retain the above copyright notice, this
10
- list of conditions and the following disclaimer.
11
-
12
- * Redistributions in binary form must reproduce the above copyright notice,
13
- this list of conditions and the following disclaimer in the documentation
14
- and/or other materials provided with the distribution.
15
-
16
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1
+ BSD 2-Clause License
2
+
3
+ Copyright (c) 2017-2021, Brice Videau
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/bin/bxm_decoder CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/bxm_decoder'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/bxm_decoder'
data/bin/bxm_encoder CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/bxm_encoder'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/bxm_encoder'
data/bin/clh_convert CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/clh_convert'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/clh_convert'
data/bin/clp_convert CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/clp_convert'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/clp_convert'
data/bin/clw_convert CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/clw_convert'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/clw_convert'
data/bin/dat_creator CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/dat_creator'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/dat_creator'
data/bin/dat_extractor CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/dat_extractor'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/dat_extractor'
data/bin/dat_ls CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/dat_ls'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/dat_ls'
data/bin/eff_idd_creator CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/eff_idd_creator'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/eff_idd_creator'
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/eff_idd_extractor'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/eff_idd_extractor'
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/exp_convert_wiiu_pc'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/exp_convert_wiiu_pc'
data/bin/exp_tool CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/exp_tool'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/exp_tool'
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/mot_convert_wiiu_pc'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/mot_convert_wiiu_pc'
data/bin/mot_tool CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/mot_tool'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/mot_tool'
data/bin/pkz_extractor CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/pkz_extractor'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/pkz_extractor'
data/bin/scr_creator CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/scr_creator'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/scr_creator'
data/bin/scr_extractor CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/scr_extractor'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/scr_extractor'
data/bin/wmb_cleanup CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/wmb_cleanup'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/wmb_cleanup'
data/bin/wmb_common_bones CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/wmb_common_bones'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/wmb_common_bones'
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/wmb_convert_pc_switch'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/wmb_convert_pc_switch'
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/wmb_convert_wiiu_pc'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/wmb_convert_wiiu_pc'
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/wmb_export_assimp'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/wmb_export_assimp'
data/bin/wmb_get_bone_map CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/wmb_get_bone_map'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/wmb_get_bone_map'
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/wmb_import_assimp'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/wmb_import_assimp'
data/bin/wmb_import_nier CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/wmb_import_nier'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/wmb_import_nier'
data/bin/wmb_import_wiiu CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/wmb_import_geometry_wiiu_pc'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/wmb_import_geometry_wiiu_pc'
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/wtb_convert_wiiu_pc'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/wtb_convert_wiiu_pc'
data/bin/wtx_creator CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/wtx_creator'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/wtx_creator'
data/bin/wtx_extractor CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require 'bayonetta/tools/wtx_extractor'
1
+ #!/usr/bin/env ruby
2
+ require 'bayonetta/tools/wtx_extractor'
File without changes
File without changes
data/lib/bayonetta/bxm.rb CHANGED
@@ -1,180 +1,180 @@
1
- require 'nokogiri'
2
- require 'set'
3
-
4
- module Bayonetta
5
- #=begin
6
- class BXMFile < LibBin::Structure
7
-
8
- class Datum < LibBin::Structure
9
- uint16 :name_offset
10
- int16 :value_offset
11
- end
12
-
13
- class Node < LibBin::Structure
14
- uint16 :child_count
15
- uint16 :first_child_index
16
- uint16 :attribute_count
17
- uint16 :datum_index
18
- end
19
-
20
- class Header < LibBin::Structure
21
- string :id, 4
22
- uint32 :unknown
23
- uint16 :node_count
24
- uint16 :datum_count
25
- uint32 :data_size
26
- end
27
-
28
- register_field :header, Header
29
- register_field :nodes, Node, count: 'header\node_count'
30
- register_field :datums, Datum, count: 'header\datum_count'
31
- string :data, 'header\data_size'
32
-
33
- def get_data_strings
34
- io = StringIO::new(data, "rb")
35
- pos = 0
36
- data_strings = {-1 => nil}
37
- while (l = io.gets("\0"))
38
- data_strings[pos] = l.unpack("Z*").first
39
- pos = io.tell
40
- end
41
- data_strings
42
- end
43
-
44
- def get_datas
45
- data_strings = get_data_strings
46
- datums.collect { |d| [data_strings[d.name_offset], data_strings[d.value_offset]] }
47
- end
48
-
49
- def build_xml_tree(doc, index, datas)
50
- node = nodes[index]
51
- name, value = datas[node.datum_index]
52
- n = Nokogiri::XML::Node.new(name, doc)
53
- n.content = value if value
54
- node.attribute_count.times { |i|
55
- name, value = datas[node.datum_index + i + 1]
56
- n[name] = value
57
- }
58
- node.child_count.times { |i|
59
- n << build_xml_tree(doc, node.first_child_index + i, datas)
60
- }
61
- n
62
- end
63
-
64
- def to_xml
65
- datas = get_datas
66
- doc = Nokogiri::XML::Document::new
67
- doc << build_xml_tree(doc, 0, datas) if header.node_count > 0
68
- doc
69
- end
70
-
71
- def process_node(node, index, next_node_index)
72
- name = node.name
73
- children = node.elements
74
- value = node.content if children.empty?
75
- value = value.strip if value
76
- value = nil if value == ''
77
- attributes = node.attributes
78
-
79
- n = Node.new
80
- n.child_count = children.size
81
- n.first_child_index = next_node_index
82
- n.attribute_count = attributes.size
83
- nodes[index] = n
84
-
85
- node_datums = [[name, value]]
86
- attributes.each { |k, v| node_datums.push [k, v.value] }
87
- datum_index = datums.each_cons(node_datums.size).find_index { |sub| sub == node_datums }
88
- if datum_index
89
- n.datum_index = datum_index
90
- else
91
- n.datum_index = datums.size
92
- datums.push *node_datums
93
- node_datums.flatten.each { |v| data.add v if v }
94
- end
95
- next_node_index += children.size
96
- children.each_with_index { |c, i|
97
- next_node_index = process_node(c, n.first_child_index + i, next_node_index)
98
- }
99
- next_node_index
100
- end
101
-
102
- def from_xml(xml, tag)
103
- @header = Header.new
104
- @nodes = []
105
- @datums = []
106
- @data = Set.new
107
- header.id = tag
108
- header.unknown = 0
109
- process_node(xml.children.first, 0, 1)
110
- header.node_count = nodes.length
111
- header.datum_count = datums.length
112
- io = StringIO::new("", "wb")
113
- data_map = data.collect { |d|
114
- pos = io.tell
115
- io.write(d, "\0")
116
- [d, pos]
117
- }.to_h
118
- data_map[nil] = -1
119
- datums.collect! { |n, v|
120
- d = Datum.new
121
- d.name_offset = data_map[n]
122
- d.value_offset = data_map[v]
123
- d
124
- }
125
- @data = io.string
126
- header.data_size = data.bytesize
127
- self
128
- end
129
-
130
- def self.from_xml(xml, tag="BXM\x00".b)
131
- bxm = self.new
132
- bxm.from_xml(xml, tag)
133
- end
134
-
135
- def self.is_big?(f)
136
- true
137
- end
138
-
139
- def self.load(input_name)
140
- if input_name.respond_to?(:read) && input_name.respond_to?(:seek)
141
- input = input_name
142
- else
143
- File.open(input_name, "rb") { |f|
144
- input = StringIO::new(f.read, "rb")
145
- }
146
- end
147
- tag = input.read(4).unpack("a4").first
148
- raise "invalid file type #{tag}!" if tag != "XML\x00".b && tag != "BXM\x00".b
149
- input.rewind
150
- bxm = self.new
151
- big = input_big = is_big?(input)
152
- bxm.instance_variable_set(:@__was_big, big)
153
- bxm.__load(input, big)
154
- input.close unless input_name.respond_to?(:read) && input_name.respond_to?(:seek)
155
- bxm
156
- end
157
-
158
- def dump(output_name, output_big = true)
159
- if output_name.respond_to?(:write) && output_name.respond_to?(:seek)
160
- output = output_name
161
- else
162
- output = StringIO::new("".b, "wb")
163
- end
164
-
165
- __set_dump_state(output, output_big, nil, nil)
166
- __dump_fields
167
- __unset_dump_state
168
-
169
- unless output_name.respond_to?(:write) && output_name.respond_to?(:seek)
170
- File.open(output_name, "wb") { |f|
171
- f.write output.string
172
- }
173
- output.close
174
- end
175
- self
176
- end
177
-
178
- end
179
-
180
- end
1
+ require 'nokogiri'
2
+ require 'set'
3
+
4
+ module Bayonetta
5
+ #=begin
6
+ class BXMFile < LibBin::Structure
7
+
8
+ class Datum < LibBin::Structure
9
+ uint16 :name_offset
10
+ int16 :value_offset
11
+ end
12
+
13
+ class Node < LibBin::Structure
14
+ uint16 :child_count
15
+ uint16 :first_child_index
16
+ uint16 :attribute_count
17
+ uint16 :datum_index
18
+ end
19
+
20
+ class Header < LibBin::Structure
21
+ string :id, 4
22
+ uint32 :unknown
23
+ uint16 :node_count
24
+ uint16 :datum_count
25
+ uint32 :data_size
26
+ end
27
+
28
+ register_field :header, Header
29
+ register_field :nodes, Node, count: 'header\node_count'
30
+ register_field :datums, Datum, count: 'header\datum_count'
31
+ string :data, 'header\data_size'
32
+
33
+ def get_data_strings
34
+ io = StringIO::new(data, "rb")
35
+ pos = 0
36
+ data_strings = {-1 => nil}
37
+ while (l = io.gets("\0"))
38
+ data_strings[pos] = l.unpack("Z*").first
39
+ pos = io.tell
40
+ end
41
+ data_strings
42
+ end
43
+
44
+ def get_datas
45
+ data_strings = get_data_strings
46
+ datums.collect { |d| [data_strings[d.name_offset], data_strings[d.value_offset]] }
47
+ end
48
+
49
+ def build_xml_tree(doc, index, datas)
50
+ node = nodes[index]
51
+ name, value = datas[node.datum_index]
52
+ n = Nokogiri::XML::Node.new(name, doc)
53
+ n.content = value if value
54
+ node.attribute_count.times { |i|
55
+ name, value = datas[node.datum_index + i + 1]
56
+ n[name] = value
57
+ }
58
+ node.child_count.times { |i|
59
+ n << build_xml_tree(doc, node.first_child_index + i, datas)
60
+ }
61
+ n
62
+ end
63
+
64
+ def to_xml
65
+ datas = get_datas
66
+ doc = Nokogiri::XML::Document::new
67
+ doc << build_xml_tree(doc, 0, datas) if header.node_count > 0
68
+ doc
69
+ end
70
+
71
+ def process_node(node, index, next_node_index)
72
+ name = node.name
73
+ children = node.elements
74
+ value = node.content if children.empty?
75
+ value = value.strip if value
76
+ value = nil if value == ''
77
+ attributes = node.attributes
78
+
79
+ n = Node.new
80
+ n.child_count = children.size
81
+ n.first_child_index = next_node_index
82
+ n.attribute_count = attributes.size
83
+ nodes[index] = n
84
+
85
+ node_datums = [[name, value]]
86
+ attributes.each { |k, v| node_datums.push [k, v.value] }
87
+ datum_index = datums.each_cons(node_datums.size).find_index { |sub| sub == node_datums }
88
+ if datum_index
89
+ n.datum_index = datum_index
90
+ else
91
+ n.datum_index = datums.size
92
+ datums.push *node_datums
93
+ node_datums.flatten.each { |v| data.add v if v }
94
+ end
95
+ next_node_index += children.size
96
+ children.each_with_index { |c, i|
97
+ next_node_index = process_node(c, n.first_child_index + i, next_node_index)
98
+ }
99
+ next_node_index
100
+ end
101
+
102
+ def from_xml(xml, tag)
103
+ @header = Header.new
104
+ @nodes = []
105
+ @datums = []
106
+ @data = Set.new
107
+ header.id = tag
108
+ header.unknown = 0
109
+ process_node(xml.children.first, 0, 1)
110
+ header.node_count = nodes.length
111
+ header.datum_count = datums.length
112
+ io = StringIO::new("", "wb")
113
+ data_map = data.collect { |d|
114
+ pos = io.tell
115
+ io.write(d, "\0")
116
+ [d, pos]
117
+ }.to_h
118
+ data_map[nil] = -1
119
+ datums.collect! { |n, v|
120
+ d = Datum.new
121
+ d.name_offset = data_map[n]
122
+ d.value_offset = data_map[v]
123
+ d
124
+ }
125
+ @data = io.string
126
+ header.data_size = data.bytesize
127
+ self
128
+ end
129
+
130
+ def self.from_xml(xml, tag="BXM\x00".b)
131
+ bxm = self.new
132
+ bxm.from_xml(xml, tag)
133
+ end
134
+
135
+ def self.is_big?(f)
136
+ true
137
+ end
138
+
139
+ def self.load(input_name)
140
+ if input_name.respond_to?(:read) && input_name.respond_to?(:seek)
141
+ input = input_name
142
+ else
143
+ File.open(input_name, "rb") { |f|
144
+ input = StringIO::new(f.read, "rb")
145
+ }
146
+ end
147
+ tag = input.read(4).unpack("a4").first
148
+ raise "invalid file type #{tag}!" if tag != "XML\x00".b && tag != "BXM\x00".b
149
+ input.rewind
150
+ bxm = self.new
151
+ big = input_big = is_big?(input)
152
+ bxm.instance_variable_set(:@__was_big, big)
153
+ bxm.__load(input, big)
154
+ input.close unless input_name.respond_to?(:read) && input_name.respond_to?(:seek)
155
+ bxm
156
+ end
157
+
158
+ def dump(output_name, output_big = true)
159
+ if output_name.respond_to?(:write) && output_name.respond_to?(:seek)
160
+ output = output_name
161
+ else
162
+ output = StringIO::new("".b, "wb")
163
+ end
164
+
165
+ __set_dump_state(output, output_big, nil, nil)
166
+ __dump_fields
167
+ __unset_dump_state
168
+
169
+ unless output_name.respond_to?(:write) && output_name.respond_to?(:seek)
170
+ File.open(output_name, "wb") { |f|
171
+ f.write output.string
172
+ }
173
+ output.close
174
+ end
175
+ self
176
+ end
177
+
178
+ end
179
+
180
+ end