rbstarbound 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bc2319a0b69674dfcdccfd64791c37858fecc10f
4
+ data.tar.gz: 7fe512695536fd226115bc2116786145865f71c2
5
+ SHA512:
6
+ metadata.gz: 8a1fe19f1faa35fdaabe9e0bcd0ff1c2ba8f6cd9adb9f5a298efe9c15ced2c9596c02bcf2057e3750cd6f26c4e7f51f74a9522b5f23650fe307f31d5211fb38e
7
+ data.tar.gz: 86452ce8a5f13cd43bcdec1b217bcd7992a634226dfde90c8ae9dd405e39e618b84286da2902f4f5a90d81198c5161306abb6245e94e7eeae42d42d5eabee223
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Oleh Fedorenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # RBStarbound
2
+
3
+ This is a library to parse
4
+ [Starbound's](https://playstarbound.com/)
5
+ file formats which are used to store worlds, player characters, assets, etc.
6
+
7
+ Frankly, it's just a ruby version of
8
+ [py-starbound](https://github.com/blixt/py-starbound).
9
+ All thanks to
10
+ [blixt](https://github.com/blixt).
11
+
12
+ --------------------------------------------------------------------------------
13
+ ## Installation
14
+
15
+ #### I. option
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'rbstarbound'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install rbstarbound
30
+
31
+ #### II. option
32
+
33
+ You just
34
+
35
+ $ git clone https://github.com/JetPirate/rb-starbound.git
36
+ $ cd rb-starbound
37
+
38
+ --------------------------------------------------------------------------------
39
+
40
+ ## Usage
41
+
42
+ ### with executables
43
+
44
+ To get YAML file with all parsed player data:
45
+
46
+ **Attention: will be changed!**
47
+
48
+ $ ./bin/rbstarbound path/to/save/file path/to/output/file
49
+
50
+ ... will be added ...
51
+
52
+ ### with the gem/library
53
+
54
+ #### Exapmle 1: Get the player name
55
+
56
+ ```ruby
57
+
58
+ require 'rbstarbound'
59
+
60
+ path = 'path/to/your/save/file'
61
+ player = RBStarbound.parse_player_save_file(path)
62
+ # simple way
63
+ puts player.player_name
64
+ # advanced way
65
+ puts player['data']['identity']['name']
66
+
67
+ ```
68
+
69
+ ... will be added ...
70
+
71
+ --------------------------------------------------------------------------------
72
+
73
+ ## Development
74
+
75
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
76
+ `rake test` to run the tests. You can also run `bin/console` for an interactive
77
+ prompt that will allow you to experiment.
78
+
79
+ To install this gem onto your local machine, run `bundle exec rake install`.
80
+
81
+ ## Contributing
82
+
83
+ Feel free to contribute either via submitting pull requests or writing up
84
+ issues with suggestions and/or bugs.
85
+
86
+ Bug reports and pull requests are welcome on GitHub at
87
+ https://github.com/JetPirate/rb-starbound.
88
+ This project is intended to be a safe, welcoming space for collaboration, and
89
+ contributors are expected to adhere to the
90
+ [Contributor Covenant](http://contributor-covenant.org)
91
+ code of conduct.
92
+
93
+ --------------------------------------------------------------------------------
94
+
95
+ ## License
96
+
97
+ The gem is available as open source under the terms of the
98
+ [MIT License](https://opensource.org/licenses/MIT).
99
+
100
+ ## Code of Conduct
101
+
102
+ Everyone interacting in the RBStarbound project’s codebases, issue trackers,
103
+ chat rooms and mailing lists is expected to follow the
104
+ [code of conduct
105
+ ](https://github.com/JetPirate/rb-starbound/blob/master/CODE_OF_CONDUCT.md).
data/bin/rbstarbound ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rbstarbound'
4
+ require 'yaml'
5
+ unless ARGV.count == 2
6
+ puts 'You need to input file paths'
7
+ return
8
+ end
9
+ player = RBStarbound.parse_player_save_file(ARGV[0].to_s)
10
+ File.open(ARGV[1].to_s, 'w') do |file|
11
+ file.write(player['data'].to_yaml)
12
+ end
@@ -0,0 +1,5 @@
1
+ module RBStarbound
2
+ class NotImplementedError < StandardError; end
3
+ class SBVJ01Error < StandardError; end
4
+ class ValueError < StandardError; end
5
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBStarbound
4
+ module SBON
5
+ def self.read_varint(io)
6
+ value = 0
7
+ loop do
8
+ byte = io.readchar.ord
9
+ return value << 7 | byte if (byte & 0b10_00_00_00).zero?
10
+ value = value << 7 | (byte & 0b01_11_11_11)
11
+ end
12
+ end
13
+
14
+ def self.read_varint_signed(io)
15
+ value = read_varint(io)
16
+ # Least significant bit represents the sign.
17
+ return -(value >> 1) - 1 unless (value & 1).zero?
18
+ value >> 1
19
+ end
20
+
21
+ def self.read_bytes(io)
22
+ length = read_varint(io)
23
+ io.read(length)
24
+ end
25
+
26
+ def self.read_string(io)
27
+ read_bytes(io)
28
+ end
29
+
30
+ def self.read_list(io)
31
+ list = []
32
+ read_varint(io).times do
33
+ list << read_dynamic(io)
34
+ end
35
+ list
36
+ end
37
+
38
+ def self.read_map(io)
39
+ map = {}
40
+ read_varint(io).times do
41
+ key = read_string(io)
42
+ map[key] = read_dynamic(io)
43
+ end
44
+ map
45
+ end
46
+
47
+ def self.read_dynamic(io)
48
+ case read_ord(io)
49
+ when 1 then nil # nil value
50
+ when 2 then io.read(8).unpack('G')[0] # double; big-endian
51
+ when 3 then !read_ord(io).zero? # boolean value
52
+ when 4 then read_varint_signed(io) # VLQ; signed
53
+ when 5 then read_string(io) # string value
54
+ when 6 then read_list(io) # list value (array)
55
+ when 7 then read_map(io) # map value (hash)
56
+ else raise RBStarbound::ValueError, 'Unknown dynamic type'
57
+ end
58
+ end
59
+
60
+ def self.read_ord(io)
61
+ io.readchar.ord
62
+ end
63
+
64
+ class << self
65
+ private :read_ord
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBStarbound
4
+ module SBVJ01
5
+ Player = Struct.new(:name, :version, :data) do
6
+ def player_name
7
+ data['identity']['name']
8
+ end
9
+
10
+ def uuid
11
+ data['identity']['uuid']
12
+ end
13
+ end
14
+
15
+ def self.parse(io)
16
+ unless sbvj01_header?(io)
17
+ raise RBStarbound::SBVJ01Error, 'Not a SBVJ01 file'
18
+ end
19
+ get_player_data(io)
20
+ end
21
+
22
+ def self.write(io)
23
+ raise RBStarbound::NotImplementedError
24
+ end
25
+
26
+ def self.get_player_data(io)
27
+ name = RBStarbound::SBON.read_string(io)
28
+ version = 'None'
29
+ version = io.read(4).unpack('i>') if io.readchar.ord != 0
30
+ data = RBStarbound::SBON.read_dynamic(io)
31
+ Player.new(name, version, data)
32
+ end
33
+
34
+ def self.sbvj01_header?(io)
35
+ io.read(6) == 'SBVJ01'
36
+ end
37
+
38
+ class << self
39
+ private :write, :get_player_data, :sbvj01_header?
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBStarbound
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,21 @@
1
+ require 'rbstarbound/version'
2
+ require 'rbstarbound/exceptions'
3
+ require 'rbstarbound/sbvj01'
4
+ require 'rbstarbound/sbon'
5
+
6
+ module RBStarbound
7
+ def self.ping
8
+ puts 'Pong!'
9
+ end
10
+
11
+ def self.parse_player_save_file(path)
12
+ save_file = File.open(path, 'rb')
13
+ parsed_data = SBVJ01.parse(save_file)
14
+ rescue StandardError => e
15
+ puts 'An error occured: ' + e.message.split(' @ ').first
16
+ else
17
+ return parsed_data
18
+ ensure
19
+ save_file.close unless save_file.nil?
20
+ end
21
+ end
Binary file
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class RBStarboundTest < Minitest::Test
6
+ def test_that_it_has_a_version_number
7
+ refute_nil ::RBStarbound::VERSION
8
+ end
9
+
10
+ def test_it_does_ping
11
+ expected_output = "Pong!\n"
12
+ assert_output(expected_output) { ::RBStarbound.ping }
13
+ end
14
+
15
+ def test_it_parses_save_file
16
+ expected_output = 'PlayerEntity'
17
+ output = ::RBStarbound.parse_player_save_file(SAVE_FILE_PATH)['name']
18
+ assert_equal(expected_output, output)
19
+ end
20
+
21
+ def test_it_shows_error_when_no_file_or_dir
22
+ expected_output = ERROR_MSG + "No such file or directory\n"
23
+ assert_output(expected_output) { ::RBStarbound.parse_player_save_file('') }
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class SBVJ01Test < Minitest::Test
6
+ def test_it_raises_header_error
7
+ file = Tempfile.new('sbvj01_header_test_temp')
8
+ assert_raises RBStarbound::SBVJ01Error do
9
+ ::RBStarbound::SBVJ01.parse(file)
10
+ end
11
+ file.close
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+ require 'rbstarbound'
5
+
6
+ require 'minitest/autorun'
7
+
8
+ data_version = ENV['TEST_DATA_VERSION'] || '1.3.3'
9
+
10
+ SAVE_FILE_PATH = File.expand_path("test/data/#{data_version}/test.player")
11
+
12
+ ERROR_MSG = 'An error occured: '
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbstarbound
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Oleh Fedorenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description:
56
+ email:
57
+ - fpostoleh@gmail.com
58
+ executables:
59
+ - rbstarbound
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - LICENSE
64
+ - README.md
65
+ - bin/rbstarbound
66
+ - lib/rbstarbound.rb
67
+ - lib/rbstarbound/exceptions.rb
68
+ - lib/rbstarbound/sbon.rb
69
+ - lib/rbstarbound/sbvj01.rb
70
+ - lib/rbstarbound/version.rb
71
+ - test/data/1.3.3/test.player
72
+ - test/rbstarbound_test.rb
73
+ - test/sbvj01_test.rb
74
+ - test/test_helper.rb
75
+ homepage: https://github.com/JetPirate/rb-starbound
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.6.14
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: A simple gem/library for working with Starbound files.
99
+ test_files:
100
+ - test/sbvj01_test.rb
101
+ - test/data/1.3.3/test.player
102
+ - test/rbstarbound_test.rb
103
+ - test/test_helper.rb