1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
#!/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"]
alpha_tex = Texture.new
alpha_bitmap = System::Drawing::Bitmap.new("#{path}/images/alphaBlender.png")
alpha_tex.images = System::Array[System::Drawing::Bitmap].new([alpha_bitmap])
alpha_tex.format = TextureFormat.RGB5A3
brres.get_texture_group.add 'alphaBlender', alpha_tex
# yay
#model.shapes["World2_PathsPlumbing__World2_PathsPlumbing"].clr_data[0].raw_data = System::Array[Byte].new([255, 255, 255, 128])
# 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
tc = DisplayListWriter.new
[0xE2,0xE3,0xE4,0xE5,0xE6,0xE7].each_slice(2) do |first, second|
tc.load_b_p_reg first << 24
3.times { tc.load_b_p_reg second << 24 }
end
tc.add_padding 4
(0xE0..0xE5).each {|bit| tc.load_b_p_reg (bit << 24) | 0x800000}
tc.load_b_p_reg 0xE688F000
tc.load_b_p_reg 0xE7800000
tc.pad_to_size 0x80
tc.end
mat.tev_color_d_l = tc.get_buffer
end
final_data = BrresWriter.write_file(brres)
System::IO::File.write_all_bytes("#{path}/MMFullWorld_mod.brres", final_data)
|