tassadar 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.1.0
4
+
5
+ * Updates serialization strategy for SC2 1.5 compliance
6
+
3
7
  ## 0.0.2
4
8
 
5
9
  * Converts serialized strings ASCII-8BIT => UTF-8. This was the source of serious encoding problems in replay parsing.
6
10
 
7
11
  ## 0.0.1
8
12
 
9
- * Initial release
13
+ * Initial release
@@ -7,17 +7,16 @@ require 'tassadar/mpq/file_data'
7
7
  require 'tassadar/mpq/block_table'
8
8
  require 'tassadar/mpq/hash_table'
9
9
  require 'tassadar/mpq/block_encryptor'
10
-
11
10
  module Tassadar
12
11
  module MPQ
13
12
  class MPQ < BinData::Record
14
13
  endian :little
15
14
 
16
- string :magic, :length => 3, :check_value => "MPQ"
17
- int8 :magic_4, :check_value => 27
18
- int32 :user_data_size
19
- int32 :archive_header_offset
20
- string :user_data, :read_length => :user_data_size
15
+ string :user_magic, :length => 4
16
+ uint32 :user_data_max_length
17
+ uint32 :archive_header_offset
18
+ uint32 :user_data_length
19
+ string :user_data, :length => :user_data_length
21
20
 
22
21
  archive_header :archive_header, :adjust_offset => lambda { archive_header_offset }
23
22
  encrypted_block_table :block_table, :entries => lambda { archive_header.block_table_entries },
@@ -28,7 +27,6 @@ module Tassadar
28
27
  file_data_array :file_data, :blocks => lambda { block_table.blocks },
29
28
  :sector_size_shift => lambda { archive_header.sector_size_shift },
30
29
  :archive_header_offset => :archive_header_offset
31
-
32
30
  def files
33
31
  @files ||= read_file('(listfile)').split
34
32
  end
@@ -3,16 +3,12 @@ module Tassadar
3
3
  class ArchiveHeader < BinData::Record
4
4
  endian :little
5
5
 
6
- string :magic, :length => 3, :check_value => "MPQ"
7
- uint8 :magic_4, :check_value => 26
8
-
9
- uint32 :header_size, :check_value => 44
10
-
11
- # archive_size actually here, but not used and is computed from later data
12
- skip :length => 4
6
+ string :magic, :length => 4
7
+ uint32 :header_size
8
+ uint32 :archive_size
13
9
 
14
10
  uint16 :format_version
15
- uint8 :sector_size_shift, :check_value => 3
11
+ uint8 :sector_size_shift
16
12
  skip :length => 1
17
13
  uint32 :hash_table_offset
18
14
  uint32 :block_table_offset
@@ -22,10 +18,6 @@ module Tassadar
22
18
  uint16 :hash_table_offset_high
23
19
  uint16 :block_table_offset_high
24
20
 
25
- archive_size :archive_size, :hash_table_offset => :hash_table_offset,
26
- :hash_table_entries => :hash_table_entries,
27
- :block_table_offset => :block_table_offset,
28
- :block_table_entries => :block_table_entries
29
21
  end
30
22
  end
31
23
  end
@@ -5,16 +5,21 @@ module Tassadar
5
5
  key = io.readbytes(1).unpack("C").first
6
6
 
7
7
  case key
8
+ when 0
9
+ read_array(io)
8
10
  when 2
9
11
  read_byte_string(io)
12
+ when 3
13
+ flag = io.readbytes(1)
14
+ read_and_return_value(io)
10
15
  when 4
11
- read_array(io)
16
+ read_flag(io)
12
17
  when 5
13
18
  read_kvo(io)
14
19
  when 6
15
20
  read_small_int(io)
16
21
  when 7
17
- read_big_int(io)
22
+ io.readbytes(4)
18
23
  when 9
19
24
  read_vlf_int(io)
20
25
  else
@@ -55,17 +60,25 @@ module Tassadar
55
60
  (value & 1) == 1 ? -(value >> 1) : (value >> 1)
56
61
  end
57
62
 
58
- def read_array(io)
59
- result = []
60
- 2.times { io.readbytes(1).unpack("C").first }
63
+ def read_flag(io)
64
+ switch = io.readbytes(1).unpack("C").first
61
65
 
62
- num_elements = io.readbytes(1).unpack("C").first >> 1
66
+ if switch == 1
67
+ read_and_return_value(io)
68
+ else
69
+ return 0
70
+ end
71
+ end
63
72
 
64
- num_elements.times do
65
- result << read_and_return_value(io)
73
+ def read_array(io)
74
+ entries = read_vlf_int(io)
75
+ results = []
76
+
77
+ entries.times do
78
+ results << read_and_return_value(io)
66
79
  end
67
80
 
68
- result
81
+ results
69
82
  end
70
83
 
71
84
  def read_kvo(io)
@@ -1,3 +1,3 @@
1
1
  module Tassadar
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -15,14 +15,6 @@ describe Tassadar::MPQ::ArchiveHeader do
15
15
  end
16
16
  end
17
17
 
18
- it "should read the magic header" do
19
- @archive_header.magic.should == "MPQ"
20
- end
21
-
22
- it "should read magic 4" do
23
- @archive_header.magic_4.should == 26
24
- end
25
-
26
18
  it "should read the header size" do
27
19
  @archive_header.header_size.should == 44
28
20
  end
@@ -2,15 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  describe Tassadar::MPQ::MPQ do
4
4
  before(:each) do
5
- @mpq = Tassadar::MPQ::MPQ.read(File.read("spec/replays/Delta\ Quadrant.SC2Replay"))
6
- end
7
-
8
- it "should have a valid magic string" do
9
- @mpq.magic.should == "MPQ"
5
+ @mpq = Tassadar::MPQ::MPQ.read(File.read("spec/replays/patch150.SC2Replay"))
10
6
  end
11
7
 
12
8
  it "should read the user data size" do
13
- @mpq.user_data_size.should == 512
9
+ @mpq.user_data_length.should == 60
14
10
  end
15
11
 
16
12
  it "should have block_table entries" do
@@ -2,19 +2,19 @@ require 'spec_helper'
2
2
 
3
3
  describe Tassadar::SC2::Game do
4
4
  before(:each) do
5
- @replay = Tassadar::SC2::Replay.new("spec/replays/Delta\ Quadrant.SC2Replay")
5
+ @replay = Tassadar::SC2::Replay.new("spec/replays/patch150.SC2Replay")
6
6
  end
7
7
 
8
8
  it "should set the winner" do
9
- @replay.game.winner.name.should == "redgar"
9
+ @replay.game.winner.name.should == "Ratbaxter"
10
10
  end
11
11
 
12
12
  it "should set the map" do
13
- @replay.game.map.should == "Delta Quadrant"
13
+ @replay.game.map.should == "Scorched Haven"
14
14
  end
15
15
 
16
16
  it "should set the time" do
17
- @replay.game.time.should == Time.new(2011, 07, 05, 17, 01, 8, "-05:00")
17
+ @replay.game.time.should == Time.new(2012, 8, 2, 11, 00, 33, "-05:00")
18
18
  end
19
19
 
20
20
  it "should set the speed" do
@@ -22,7 +22,7 @@ describe Tassadar::SC2::Game do
22
22
  end
23
23
 
24
24
  it "should set the game type" do
25
- @replay.game.type.should == "1v1"
25
+ @replay.game.type.should == "2v2"
26
26
  end
27
27
 
28
28
  it "should set the category" do
@@ -4,16 +4,16 @@ require 'spec_helper'
4
4
  describe Tassadar::SC2::Player do
5
5
  context 'NA Sc2 Replay' do
6
6
  before(:each) do
7
- @replay = Tassadar::SC2::Replay.new("spec/replays/Delta\ Quadrant.SC2Replay")
8
- @player = @replay.players.first
7
+ @replay = Tassadar::SC2::Replay.new("spec/replays/OhanaLE.SC2Replay")
8
+ @player = @replay.players.last
9
9
  end
10
10
 
11
11
  it "should set the name" do
12
- @player.name.should == "guitsaru"
12
+ @player.name.should == "MLGLogan"
13
13
  end
14
14
 
15
15
  it "should set the id" do
16
- @player.id.should == 1918894
16
+ @player.id.should == 1485031
17
17
  end
18
18
 
19
19
  it "should tell if the player won" do
@@ -21,20 +21,15 @@ describe Tassadar::SC2::Player do
21
21
  end
22
22
 
23
23
  it "should have a color" do
24
- @player.color.should == {:alpha => 255, :red => 180, :green => 20, :blue => 30}
25
- end
26
-
27
- it "should have a chosen race" do
28
- @player.chosen_race.should == "Terran"
24
+ @player.color.should == {:alpha => 255, :red => 0, :green => 66, :blue => 255}
29
25
  end
30
26
 
31
27
  it "should have random as the chosen race if random" do
32
- replay = Tassadar::SC2::Replay.new("spec/replays/random.sc2replay")
33
- replay.players.last.chosen_race.should == "Random"
28
+ @player.chosen_race.should == "Random"
34
29
  end
35
30
 
36
31
  it "should have an actual race" do
37
- @player.actual_race.should == "Terran"
32
+ @player.actual_race.should == "Protoss"
38
33
  end
39
34
 
40
35
  it "should have a handicap" do
@@ -21,4 +21,5 @@ Gem::Specification.new do |s|
21
21
 
22
22
  s.add_dependency("bindata")
23
23
  s.add_dependency("bzip2-ruby")
24
+ s.add_development_dependency("pry")
24
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tassadar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-05-04 00:00:00.000000000Z
13
+ date: 2012-08-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bindata
17
- requirement: &70239924932500 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,15 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70239924932500
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
26
31
  - !ruby/object:Gem::Dependency
27
32
  name: bzip2-ruby
28
- requirement: &70239924854920 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
29
34
  none: false
30
35
  requirements:
31
36
  - - ! '>='
@@ -33,7 +38,28 @@ dependencies:
33
38
  version: '0'
34
39
  type: :runtime
35
40
  prerelease: false
36
- version_requirements: *70239924854920
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: pry
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
37
63
  description: Pure ruby MPQ and SC2 Replay parser
38
64
  email:
39
65
  - mpruitt@agoragames.com
@@ -72,7 +98,9 @@ files:
72
98
  - spec/mpq/block_table_spec.rb
73
99
  - spec/mpq_spec.rb
74
100
  - spec/replays/Delta Quadrant.SC2Replay
101
+ - spec/replays/OhanaLE.SC2Replay
75
102
  - spec/replays/eu_replay.SC2Replay
103
+ - spec/replays/patch150.sc2replay
76
104
  - spec/replays/random.sc2replay
77
105
  - spec/sc2/game_spec.rb
78
106
  - spec/sc2/player_spec.rb
@@ -93,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
121
  version: '0'
94
122
  segments:
95
123
  - 0
96
- hash: -1060130835485239362
124
+ hash: -1764239395588821646
97
125
  required_rubygems_version: !ruby/object:Gem::Requirement
98
126
  none: false
99
127
  requirements:
@@ -102,10 +130,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
130
  version: '0'
103
131
  segments:
104
132
  - 0
105
- hash: -1060130835485239362
133
+ hash: -1764239395588821646
106
134
  requirements: []
107
135
  rubyforge_project: tassadar
108
- rubygems_version: 1.8.10
136
+ rubygems_version: 1.8.24
109
137
  signing_key:
110
138
  specification_version: 3
111
139
  summary: Pure ruby MPQ and SC2 Replay parser
@@ -114,7 +142,9 @@ test_files:
114
142
  - spec/mpq/block_table_spec.rb
115
143
  - spec/mpq_spec.rb
116
144
  - spec/replays/Delta Quadrant.SC2Replay
145
+ - spec/replays/OhanaLE.SC2Replay
117
146
  - spec/replays/eu_replay.SC2Replay
147
+ - spec/replays/patch150.sc2replay
118
148
  - spec/replays/random.sc2replay
119
149
  - spec/sc2/game_spec.rb
120
150
  - spec/sc2/player_spec.rb