#!/usr/bin/mono /home/me/Packages/IronLanguages-main-ba2094c/bin/Release/ir.exe ## Requires IronRuby $: << "/home/me/Dev/NW4RTools/NW4RTools/bin/Release" require 'NW4RTools' require 'System.Drawing' include System include NW4RTools include NW4RTools::Models brres = ResFile.new models = brres.create_model_group path = '/home/me/Games/Newer/ModelRev' reader = System::IO::StreamReader.new("#{path}/fullworld-Z20nvrc.obj") ObjImporter.ImportModel(path, reader, brres, "WorldBase", ObjImporter::LightmapType.Map) model = models["WorldBase"] # move paths into DrawXlu opa = model.bytecode["DrawOpa"] if model.bytecode.contains_key("DrawXlu") xlu = model.bytecode["DrawXlu"] else xlu = ByteCode.new xlu.instructions = System::Collections::Generic::List[ByteCode::Instruction].new xlu.instructions << ByteCode::DoneInstruction.new model.bytecode["DrawXlu"] = xlu end shape_array = model.shapes.to_a to_be_moved = opa.instructions.select do |insn| insn.is_a?(ByteCode::DrawShapeInstruction) and shape_array[insn.shape_i_d].key =~ /path/i end to_be_moved.each do |insn| opa.instructions.remove insn xlu.instructions.insert 0, insn end # how's this for hackiness? model.materials.each do |kvp| next unless kvp.key =~ /path/i mat = kvp.value pix = DisplayListWriter.new pix.load_b_p_reg 0xF33F0000 pix.load_b_p_reg 0x40000017 pix.load_b_p_reg 0xFE00FFE3 # Blend Mode: logicmode: LO_SET, subtract: 0, srcfactor: SRCALPHA, dstfactor: INVSRCALPHA, # alphaupdate: 0, colorupdate: 0, dither: 0, logicopenable: 0, blendenable: 1 pix.load_b_p_reg 0x4100F4A1 pix.load_b_p_reg 0x42000000 pix.end mat.pix_d_l = pix.get_buffer end final_data = BrresWriter.write_file(brres) System::IO::File.write_all_bytes("#{path}/MMFullWorld_mod.brres", final_data)