-
-
Save jankowskib/f886f087d9cb1f578284 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby | |
# dump_cubemain.rb | |
# | |
# Copyright 2015 Bartosz Jankowski | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License") | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http:#www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# | |
require 'bindata' | |
class CubeMainInput < BinData::Record # size 0x08 | |
uint8 :input_flags #0x00 | |
uint8 :item_type #0x01 | |
uint16le :item #0x02 | |
uint16le :item_id #0x04 | |
uint8 :quality #0x06 | |
uint8 :quantity #0x07 | |
end | |
class CubeMainOutputMod < BinData::Record # size 0xC | |
uint32le :mod #0x00 | |
uint16le :mod_param #0x04 | |
uint16le :mod_min #0x06 | |
uint16le :mod_max #0x08 | |
uint16le :mod_chance #0x0a | |
end | |
class CubeMainOutput < BinData::Record # size 0x54 | |
uint8 :item_flags #0x00 | |
uint8 :item_type #0x01 | |
uint16le :item #0x02 | |
uint16le :item_id #0x04 | |
uint16le :param #0x06 | |
uint8 :type #0x08 | |
uint8 :lvl #0x09 | |
uint8 :p_lvl #0x0a | |
uint8 :i_lvl #0x0b | |
array :prefix_id, :type => :uint16le, :initial_length => 3 #0x0c | |
array :suffix_id, :type => :uint16le, :initial_length => 3 #0x12 | |
array :mods, :type => :cube_main_output_mod, :initial_length => 5 #0x18 | |
end | |
class CubeMainBinRecord < BinData::Record # size 0x148 | |
uint8 :enabled #0x00 | |
uint8 :ladder #0x01 | |
uint8 :mindiff #0x02 | |
uint8 :class_id #0x03 | |
uint32le :op #0x04 | |
uint32le :param #0x08 | |
uint32le :value_id #0x0c | |
uint16le :numinputs #0x10 | |
uint16le :version #0x12 | |
array :inputs, :type => :cube_main_input, :initial_length => 7 | |
array :outputs, :type => :cube_main_output, :initial_length => 3 | |
end | |
class CubeMainBin < BinData::Record # size 4+ | |
uint32le :record_count | |
array :records, :type => :cube_main_bin_record, :initial_length => :record_count | |
end | |
begin | |
f = ARGV[0] unless ARGV[0].nil? | |
bin = File.read(f) | |
CubeMainBin.read(bin).records.each_with_index do |rec, num| | |
puts "Record #{num} #{rec.to_binary_s.length}" | |
p rec | |
end | |
end |
cubdcode.rb:44:in class:CubeMainOutput': field 'type' is a reserved name in CubeMainOutput (NameError)
Same. Changed uint8 :type #0x08
to uint8 :type_unknown #0x08
and got this running with
% ruby --version
ruby 2.7.7p221 (2022-11-24 revision 168ec2b1e5) [arm64-darwin24]
No luck getting this running on Windows, but I've haven't done development on a Windows machine in 10 years.
I'm not a Ruby dev, and Cursor should get me through the rest of this. I'll post a gist after I have this writing to a cubemain.txt file to disk.
Unfortunately, getting from .bin back to the same format of the .txt file it was created from is rather involved.
I got this script to at least generate .json files that you can then consume in any language of your choice.
https://gist.github.com/ryandagg/5d993bd4ecaa8c0afa0b1e533bc15a2f
There is my problem:
C:\Program Files\Ruby26-x64\bin>ruby.exe cubdcode.rb cubemain.bin
'Traceback (most recent call last):
6: from cubdcode.rb:38:in
<main>' 5: from cubdcode.rb:44:in
class:CubeMainOutput'4: from C:/Program Files/Ruby26-x64/lib/ruby/gems/2.6.0/gems/bindata-2.4.8/lib/bindata/dsl.rb:46:in
method_missing' 3: from C:/Program Files/Ruby26-x64/lib/ruby/gems/2.6.0/gems/bindata-2.4.8/lib/bindata/dsl.rb:120:in
method_missing'2: from C:/Program Files/Ruby26-x64/lib/ruby/gems/2.6.0/gems/bindata-2.4.8/lib/bindata/dsl.rb:183:in
parse_and_append_field' 1: from C:/Program Files/Ruby26-x64/lib/ruby/gems/2.6.0/gems/bindata-2.4.8/lib/bindata/dsl.rb:417:in
validate_field'C:/Program Files/Ruby26-x64/lib/ruby/gems/2.6.0/gems/bindata-2.4.8/lib/bindata/dsl.rb:435:in
ensure_valid_name': field 'type' is a reserved name (NameError) 1: from cubdcode.rb:38:in
cubdcode.rb:44:in `class:CubeMainOutput': field 'type' is a reserved name in CubeMainOutput (NameError)