lolreplay 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.
@@ -0,0 +1,10 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ json (1.6.3)
5
+
6
+ PLATFORMS
7
+ ruby
8
+
9
+ DEPENDENCIES
10
+ json
@@ -0,0 +1,231 @@
1
+ # LoL Replay Library
2
+
3
+ Greetings, summoners! (too cheesy?)
4
+
5
+ This is a Ruby library for accessing the end game metadata in .lrf files (LoL
6
+ Replay files). It's pretty small and simple at the moment and just makes life a
7
+ bit easier if you want to run some stats analysis on your LoL Replay files.
8
+
9
+ # Installation
10
+
11
+ Provided you have Ruby with RubyGems installed, installation is the standard gem
12
+ one liner:
13
+
14
+ $ gem install lolreplay
15
+
16
+ # Usage
17
+
18
+ The program under the bin directory should give you a little idea as to how this
19
+ library works. Here's another short example:
20
+
21
+ ``` ruby
22
+ game = LolReplay::Game.new "path/to/lrffile.lrf"
23
+
24
+ samwho = game.player "Samwho"
25
+
26
+ samwho.kills
27
+ #=> the number of kills I had
28
+
29
+ samwho.largest_crit
30
+ #=> the largest crit I did
31
+
32
+ samwho.gold
33
+ #=> the amount of gold I earned
34
+
35
+ samwho.killing_spree
36
+ #=> the largest killing spree I had
37
+ ```
38
+
39
+ LoL Replay files contain JSON metadata in them, all this library
40
+ does is read that metadata and expose it through some classes. I took a bit of a
41
+ shortcut when exposing the JSON data and made the method names the hash keys. So
42
+ there isn't a single method for each bit of data, the method names are
43
+ dynamically translated from underscored_names to camelCase and then fed to the
44
+ hash as a key.
45
+
46
+ The upside is that the library should stand the test of time. Provided the guys
47
+ at LoL Replay don't change where the JSON data is located in the file, this
48
+ library should be able to get at any new metadata added to the files.
49
+
50
+ The downside is that RDocs won't represent the library very well. So I'll
51
+ explain how to know where to find the data you want.
52
+
53
+ # What data can I access?
54
+
55
+ Here's some JSON output of a recent game I had:
56
+
57
+ ``` json
58
+ {
59
+ "accountID": 12345678,
60
+ "clientHash": "6f7t2dcaga7hfg64g9433408s8defy6y",
61
+ "clientVersion": "1.0.0.130",
62
+ "dataIndex": [
63
+ {
64
+ "Key": "stream",
65
+ "Value": {
66
+ "offset": 0,
67
+ "size": 4367077
68
+ }
69
+ },
70
+ {
71
+ "Key": "s0",
72
+ "Value": {
73
+ "offset": 4367077,
74
+ "size": 84609
75
+ }
76
+ },
77
+ {
78
+ "Key": "s1",
79
+ "Value": {
80
+ "offset": 4451686,
81
+ "size": 109687
82
+ }
83
+ },
84
+ {
85
+ "Key": "s2",
86
+ "Value": {
87
+ "offset": 4561373,
88
+ "size": 112188
89
+ }
90
+ },
91
+ {
92
+ "Key": "s3",
93
+ "Value": {
94
+ "offset": 4673561,
95
+ "size": 132680
96
+ }
97
+ },
98
+ {
99
+ "Key": "s4",
100
+ "Value": {
101
+ "offset": 4806241,
102
+ "size": 93201
103
+ }
104
+ },
105
+ {
106
+ "Key": "s5",
107
+ "Value": {
108
+ "offset": 4899442,
109
+ "size": 107907
110
+ }
111
+ },
112
+ {
113
+ "Key": "s6",
114
+ "Value": {
115
+ "offset": 5007349,
116
+ "size": 113622
117
+ }
118
+ }
119
+ ],
120
+ "encryptionKey": "tPsrrs4l8e0qqe3ly6ouut4p",
121
+ "firstWinBonus": 0,
122
+ "gameMode": 1,
123
+ "map": 2,
124
+ "matchID": 263521613,
125
+ "matchLength": 1849,
126
+ "matchType": 3,
127
+ "name": "YouSummonerName - ChampionName",
128
+ "players": [
129
+ {
130
+ "accountID": 23608408,
131
+ "assists": 8,
132
+ "barracks": 0,
133
+ "champion": "XinZhao",
134
+ "damageDealt": 49554,
135
+ "damageTaken": 22591,
136
+ "deaths": 7,
137
+ "elo": 0,
138
+ "eloChange": 0,
139
+ "gold": 5860,
140
+ "healed": 3375,
141
+ "item1": 1055,
142
+ "item2": 3006,
143
+ "item3": 3072,
144
+ "item4": 3086,
145
+ "killingSpree": 2,
146
+ "kills": 2,
147
+ "largestCrit": 389,
148
+ "largestMultiKill": 1,
149
+ "leaver": false,
150
+ "leaves": 8,
151
+ "level": 13,
152
+ "losses": 143,
153
+ "magicDamageDealt": 965,
154
+ "magicDamageTaken": 8270,
155
+ "minions": 69,
156
+ "neutralMinionsKilled": 6,
157
+ "physicalDamageDealt": 48589,
158
+ "physicalDamageTaken": 13535,
159
+ "profileIconId": 23,
160
+ "spell1": 3,
161
+ "spell2": 4,
162
+ "summoner": "ASummonerName",
163
+ "summonerLevel": 30,
164
+ "team": 2,
165
+ "timeDead": 195,
166
+ "turrets": 0,
167
+ "wins": 153,
168
+ "won": false
169
+ }],
170
+ "queueType": "NORMAL",
171
+ "ranked": false,
172
+ "region": "EUW",
173
+ "replayID": -1,
174
+ "replayVersion": "0.7.4.12",
175
+ "screenshots": [
176
+ {
177
+ "name": "s0",
178
+ "timestamp": 30052,
179
+ "type": ".jpg"
180
+ },
181
+ {
182
+ "name": "s1",
183
+ "timestamp": 329992,
184
+ "type": ".jpg"
185
+ },
186
+ {
187
+ "name": "s2",
188
+ "timestamp": 630036,
189
+ "type": ".jpg"
190
+ },
191
+ {
192
+ "name": "s3",
193
+ "timestamp": 930077,
194
+ "type": ".jpg"
195
+ },
196
+ {
197
+ "name": "s4",
198
+ "timestamp": 1230186,
199
+ "type": ".jpg"
200
+ },
201
+ {
202
+ "name": "s5",
203
+ "timestamp": 1530203,
204
+ "type": ".jpg"
205
+ },
206
+ {
207
+ "name": "s6",
208
+ "timestamp": 1830247,
209
+ "type": ".jpg"
210
+ }
211
+ ],
212
+ "serverAddress": "31.186.224.155",
213
+ "serverPort": 5158,
214
+ "spectatorMode": false,
215
+ "summonerName": "YourSummerName",
216
+ "teams": null,
217
+ "timestamp": 1323233142,
218
+ "winningTeam": 1
219
+ }
220
+ ```
221
+
222
+ I've scrubbed any sensitive data and the names and timestamps have all been
223
+ changed, just in case I get in trouble.
224
+
225
+ Basically, you can access all of this. The LolReplay::Game object you create
226
+ will have this JSON inside it and whenever a method comes in, it will convert
227
+ the method name from an underscore_name to a camelCase name and use it as a key
228
+ to this hash.
229
+
230
+ To access the players, use the `players` method. Then you can access all of the
231
+ stuff you see for the example player up there. That's all there is to it :)
@@ -0,0 +1,5 @@
1
+ # Require all files in the main lib directory
2
+ Dir[File.dirname(__FILE__) + '/lolreplay/**/*.rb'].each do |file|
3
+ require file
4
+ end
5
+
@@ -0,0 +1,38 @@
1
+ require File.dirname(__FILE__) + '/hash_method_accessor'
2
+ require 'json'
3
+
4
+ module LolReplay
5
+ class Game
6
+ include ::HashMethodAccessor
7
+ attr_accessor :json, :path, :players
8
+
9
+ # Constructor takes a path to a .lrf file. The file path that it is given
10
+ # is read and the meta data is extracted for later use.
11
+ def initialize path
12
+ @path = path
13
+
14
+ @data = File.open(path) do |f|
15
+ f.read(4) # skip first four bytes
16
+ size = f.read(4).unpack("L").first
17
+ JSON.parse f.read(size), symbolize_names: true
18
+ end
19
+
20
+ @players = @data[:players].map { |p| Player.new p }
21
+ end
22
+
23
+ # Gets a player by name. If the player was not present in this game, nil
24
+ # is returned.
25
+ #
26
+ # Example:
27
+ #
28
+ # puts game.player "Samwho"
29
+ # #=> #<LolReplay::Player:0x8317074>
30
+ def player name
31
+ @players.each do |player|
32
+ return player if player.name == name
33
+ end
34
+
35
+ nil
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,10 @@
1
+ module HashMethodAccessor
2
+ def method_missing id, *args
3
+ hash_key = id.to_s.gsub(/_./) { $&[1].chr.upcase }.to_sym
4
+ if @data[hash_key].nil?
5
+ super
6
+ else
7
+ @data[hash_key]
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,30 @@
1
+ require File.dirname(__FILE__) + '/hash_method_accessor'
2
+
3
+ module LolReplay
4
+ class Player
5
+ include ::HashMethodAccessor
6
+
7
+ def initialize data
8
+ @data = data
9
+ end
10
+
11
+ # Alias for summoner
12
+ def name
13
+ @data[:summoner]
14
+ end
15
+
16
+ # Alias for leaver
17
+ def leaver?
18
+ @data[:leaver]
19
+ end
20
+
21
+ # Alias for won
22
+ def won?
23
+ @data[:won]
24
+ end
25
+
26
+ def to_s
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ class String
2
+
3
+ end
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{lolreplay}
3
+ s.version = "0.1"
4
+ s.date = %q{2011-12-11}
5
+ s.authors = ["Sam Rose"]
6
+ s.email = %q{samwho@lbak.co.uk}
7
+ s.summary = %q{A library for accessing the metadata of LoL Replay .lrf files.}
8
+ s.homepage = %q{http://github.com/samwho/lolreplay}
9
+ s.description = %q{Allows for access of the metadata in a LoL Replay .lrf file.}
10
+ s.required_ruby_version = '>= 1.9.2'
11
+ s.license = 'GPL-2'
12
+
13
+ # Add all files to the files parameter.
14
+ s.files = []
15
+ Dir["**/*.*"].each { |path| s.files.push path }
16
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lolreplay
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sam Rose
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-11 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Allows for access of the metadata in a LoL Replay .lrf file.
15
+ email: samwho@lbak.co.uk
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lolreplay.gemspec
21
+ - README.md
22
+ - lib/lolreplay/game.rb
23
+ - lib/lolreplay/string.rb
24
+ - lib/lolreplay/player.rb
25
+ - lib/lolreplay/hash_method_accessor.rb
26
+ - lib/lolreplay.rb
27
+ - lolreplay-0.1.gem
28
+ - Gemfile.lock
29
+ homepage: http://github.com/samwho/lolreplay
30
+ licenses:
31
+ - GPL-2
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: 1.9.2
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 1.8.6
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: A library for accessing the metadata of LoL Replay .lrf files.
54
+ test_files: []