Created
July 9, 2015 19:56
-
-
Save jankowskib/f886f087d9cb1f578284 to your computer and use it in GitHub Desktop.
decode Diablo II's CubeMain.bin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cubdcode.rb:44:in class:CubeMainOutput': field 'type' is a reserved name in CubeMainOutput (NameError)
Same. Changed
uint8 :type #0x08
touint8 :type_unknown #0x08
and got this running withNo 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.