rrb-common 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77d064b5d3c6ebddbf4758b0c4848f35159c8181c503cd8c8438390605e3071c
4
- data.tar.gz: 339bd670c3725bd9610ca0c247b3902c07bd8af7a6ad8bb894878dcf02ca8669
3
+ metadata.gz: 1e1063be8d2fdedff9c18342214732a264e406aaf0e9f88bc3a699f3ff8a85cd
4
+ data.tar.gz: ebd87f1f93863dc31cc24dba6b9bd26c01aa79b263cc160c0d02bd60d461c236
5
5
  SHA512:
6
- metadata.gz: 05c95f37e85863385d75c8bd9dca484a86a51bd45c84dab4e91abda6e948997c9bdaa21f96f8fa281d614644c21712497345a47f998cfa271e13059b524c73b9
7
- data.tar.gz: 86fe15955d0fc6c5c702e2b4cbe6109e97d5d3987612eb6510c513df7a47425bcaee14df391697163fd9fd5d6a106b568fae893afe714e9b53fabeb57ee01f14
6
+ metadata.gz: d4b29deb98f9c99c8b8af84c29b8e6c06fe30bf37810c768f4de3b5d9d74ec1af89e99d78e3dab9270a19c25d20d5da558b3b5afa996d2c4c26464d094eb77f7
7
+ data.tar.gz: 181a1537c93ea4708e755ac9976e9d5f3eea02c6a97854e0491538a84a52262382fc23f7e9aed59922721bbcb9c74960231fcb48a6dc486e83655ce0840344ff
@@ -51,7 +51,7 @@ module RuneRb::Core
51
51
  rem = @data_file.size - current_block * RuneRb::Core::DATA_SIZE
52
52
  size = rem if rem < RuneRb::Core::DATA_SIZE
53
53
 
54
- header = IO.read(@data_file.path, RuneRb::Core::DATA_HEADER_SIZE, current_block * RuneRb::Cache::DATA_SIZE)
54
+ header = IO.read(@data_file.path, RuneRb::Core::DATA_HEADER_SIZE, current_block * RuneRb::Core::DATA_SIZE)
55
55
  header_buffer = RuneRb::Core::Buffer.new(mode: 'r')
56
56
  header_buffer << header
57
57
 
@@ -26,7 +26,7 @@ module RuneRb::Core
26
26
  @randcnt = 256
27
27
  end
28
28
  @randcnt -= 1
29
- @randrsl[@randcnt].signed(:i)
29
+ @randrsl[@randcnt].int
30
30
  end
31
31
 
32
32
  private
@@ -1,6 +1,55 @@
1
1
  # A module adding overflow functions to integers to mimic the behavior of Java primitive overflow behavior.
2
2
  module RuneRb::Patches::IntegerRefinements
3
3
  refine Integer do
4
+ def overflow(i, e = 2 ** 31)
5
+ f = (Math.log(e) / Math.log(2)).to_i+1
6
+ g = (2 ** f) - 1
7
+
8
+ if i < -e
9
+ i & g
10
+ elsif i > e - 1
11
+ -(-(i) & g)
12
+ else
13
+ i
14
+ end
15
+ end
16
+
17
+ def nibble
18
+ overflow(self.to_i & 0xf, 2 ** 4)
19
+ end
20
+
21
+ def byte
22
+ overflow(self.to_i, 2 ** 7)
23
+ end
24
+
25
+ def ubyte
26
+ overflow(self.to_i & 0xff, 2 ** 8)
27
+ end
28
+
29
+ def short
30
+ overflow(self.to_i, 2 ** 15)
31
+ end
32
+
33
+ def ushort
34
+ overflow(self.to_i & 0xffff, 2 ** 16)
35
+ end
36
+
37
+ def int
38
+ overflow(self.to_i, 2 ** 31)
39
+ end
40
+
41
+ def uint
42
+ overflow(self.to_i & 0xffffffff, 2 ** 32)
43
+ end
44
+
45
+ def long
46
+ overflow(self.to_i, 2 ** 63)
47
+ end
48
+
49
+ def ulong
50
+ overflow(self.to_i & 0xffffffffffffffff, 2 ** 64)
51
+ end
52
+
4
53
  # Returns a binary representation in the form of an array of 1's and 0's in their respective digits.
5
54
  # @return [Array] the binary representation
6
55
  def binary_representation
@@ -22,39 +71,6 @@ module RuneRb::Patches::IntegerRefinements
22
71
 
23
72
  alias_method :from_brep, :from_binary_rep
24
73
 
25
- # Adjusts the value of the Integer to be unsigned.
26
- # @param type [Symbol] the type of primitive the value will be returned as
27
- def unsigned(type)
28
- return 0 if negative?
29
- case type
30
- when :Byte, :byte, :b, :B then to_i > 0xFF ? 0xFF : to_i
31
- when :Short, :short, :s, :S then to_i > 0xFFFF ? 0xFFFF : to_i
32
- when :Integer, :Int, :int, :integer, :i, :I then to_i > 0xFFFFFFFF ? 0xFFFFFFFF : to_i
33
- when :Long, :long, :l, :L then to_i > 0xFFFFFFFFFFFFFFFF ? 0xFFFFFFFFFFFFFFFF : to_i
34
- else unsigned(:int)
35
- end
36
- end
37
-
38
- alias_method :u, :unsigned
39
-
40
- # Adjusts the value of the Integer to be signed.
41
- # @param type [Symbol] the type of primitive the value will be returned as
42
- def signed(type)
43
- case type
44
- when :Byte, :byte, :b, :B then adjust(:byte)
45
- when :Short, :short, :s, :S then adjust(:short)
46
- when :Integer, :Int, :int, :integer, :i, :I then adjust(:integer)
47
- when :Long, :long, :l, :L then adjust(:long)
48
- else adjust(:integer)
49
- end
50
- end
51
-
52
- alias_method :s, :signed
53
-
54
- def nibble
55
- adjust(:nibble)
56
- end
57
-
58
74
  # Returns a string with a formatted representation of the Integer as a timestamp.
59
75
  def to_ftime
60
76
  mm, ss = divmod(60)
@@ -63,61 +79,6 @@ module RuneRb::Patches::IntegerRefinements
63
79
  format('%d days, %d hours, %d minutes, and %d seconds', dd, hh, mm, ss)
64
80
  end
65
81
 
66
- private
67
-
68
- # Adjusts the integer based on the passed type
69
- # @param type [Symbol] the type of adjustment to make to the integer.
70
- def adjust(type)
71
- case type
72
- when :Byte, :byte, :b, :B
73
- primitive_max = 2**7 - 1
74
- primitive_min = -2**7
75
- when :Short, :short, :s, :S
76
- primitive_max = 2**15 - 1
77
- primitive_min = -2**15
78
- when :Integer, :Int, :int, :i, :I
79
- primitive_max = 2**31 - 1
80
- primitive_min = -2**31
81
- when :Long, :long, :l, :L
82
- primitive_max = 2**63 - 1
83
- primitive_min = -2**63
84
- when :Nibble, :nibble, :n, :N
85
- primitive_max = 2**4
86
- primitive_min = -2**4
87
- else
88
- primitive_max = 2**31 - 1
89
- primitive_min = -2**31
90
- end
91
- self < -primitive_max ? -1 * (-self & primitive_max) : self
92
- self > primitive_min ? (self & primitive_max) : self
93
- end
82
+ alias_method :ftime, :to_ftime
94
83
  end
95
- end
96
-
97
- # Copyright (c) 2021, Patrick W.
98
- # All rights reserved.
99
- #
100
- # Redistribution and use in source and binary forms, with or without
101
- # modification, are permitted provided that the following conditions are met:
102
- #
103
- # * Redistributions of source code must retain the above copyright notice, this
104
- # list of conditions and the following disclaimer.
105
- #
106
- # * Redistributions in binary form must reproduce the above copyright notice,
107
- # this list of conditions and the following disclaimer in the documentation
108
- # and/or other materials provided with the distribution.
109
- #
110
- # * Neither the name of the copyright holder nor the names of its
111
- # contributors may be used to endorse or promote products derived from
112
- # this software without specific prior written permission.
113
- #
114
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
115
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
116
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
117
- # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
118
- # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
119
- # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
120
- # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
121
- # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
122
- # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
123
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
84
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rrb-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick W.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-11 00:00:00.000000000 Z
11
+ date: 2023-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv