Skip to content

Commit 98a4ced

Browse files
committed
Add support for DIL Light placement
1 parent 4de6173 commit 98a4ced

File tree

5 files changed

+85
-65
lines changed

5 files changed

+85
-65
lines changed

Diff for: csv.c

+21-19
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,10 @@ void handleTable() {
232232
} else if (!strcmp(type, "TiltSwitch")) {
233233
copyInteger(); // Switch index
234234
} else if (!strcmp(type, "Dil")) {
235-
const char* resourceName = parseString();
236-
unsigned int always0 = parseInteger();
237-
assert(always0 == 0);
238-
putNull();
235+
startObject();
236+
putKey("resource"); copyString();
237+
putKey("index"); copyInteger();
238+
endObject();
239239
} else if (!strcmp(type, "Controls")) {
240240
putNull();
241241
} else if (!strcmp(type, "Gravity")) {
@@ -272,13 +272,16 @@ void handleTable() {
272272
}
273273
putNull();
274274
} else if (!strcmp(type, "LightingData")) {
275-
const char* resourceName = parseString();
276-
unsigned int unk0 = parseInteger();
275+
startObject();
276+
putKey("resource"); copyString();
277+
putKey("index"); copyInteger();
278+
putKey("lights"); startArray();
277279
while(1) {
278280
const char* lightType = parseString();
279281
if(!strcmp(lightType, "EndLightingData")) {
280282
break;
281283
}
284+
startObject();
282285
if(!strcmp(lightType, "LightON")) {
283286
} else if(!strcmp(lightType, "LightLamp")) {
284287
} else if(!strcmp(lightType, "LightFlasher")) {
@@ -290,16 +293,17 @@ void handleTable() {
290293
} else {
291294
printf("Unknown light type '%s'\n", lightType);
292295
}
293-
int lightIndex = parseInteger();
294-
const char* name = parseString();
295-
unsigned int unk0 = parseInteger(); // Index of some sorts?!
296-
float unk1 = parseFloat();
297-
float unk2 = parseFloat();
298-
float unk3 = parseFloat();
299-
float unk4 = parseFloat();
300-
float unk5 = parseFloat();
296+
putKey("type"); putString(lightType);
297+
putKey("index"); copyInteger(); // Called "num" in PBA files
298+
putKey("dilName"); copyString();
299+
putKey("dilIndex"); copyInteger();
300+
putKey("color"); copyFloats(3);
301+
putKey("unk0"); copyFloat();
302+
putKey("brightness"); copyFloat();
303+
endObject();
301304
}
302-
putNull();
305+
endArray();
306+
endObject();
303307
} else {
304308
printf("Unknown PBTable type: '%s'\n", type);
305309
putNull();
@@ -327,10 +331,8 @@ void handleTable() {
327331
endObject();
328332
} else if (!strcmp(type, "DilPos")) {
329333
startObject();
330-
putKey("variable"); copyString();
331-
unsigned int always0 = parseInteger();
332-
putKey("always0"); putInteger(always0);
333-
assert(always0 == 0);
334+
putKey("dilName"); copyString();
335+
putKey("dilIndex"); copyInteger();
334336
endObject();
335337
} else if (!strcmp(type, "Solenoid")) {
336338
copyInteger();

Diff for: format002A.c

+6-37
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <assert.h>
77
#include <stdio.h>
88
#include <stdlib.h>
9+
#include <string.h>
910

1011
FILE* out = NULL;
1112

@@ -35,7 +36,7 @@ union {
3536
*/
3637
// objectCount = sizeof(unk)
3738
// 41 = 168 (not sure which game, but 2007-0 / totan?!)
38-
// 120 = 168 (not sure which game, but 2007-1 / totan?!)
39+
// 120 = ~~168~~ 484 (not sure which game, but 2007-1 / totan?!) [168 is actually garbage which was probably left in mem during resource creation?!]
3940
// 67 = 272 BK2K
4041
// 89 = 360 TAF PC
4142
} Header;
@@ -77,45 +78,13 @@ int main(int argc, char* argv[]) {
7778
putKey("sourceFile"); putString(header.sourceFile);
7879
putKey("sourcePath"); putString(header.sourcePath);
7980

80-
uint32_t t = header.unk0;
81-
size_t l = 0;
82-
switch(t) {
83-
case 0x08EB89D0: l = 324; break;
84-
case 0x076D4E88: l = 164; break;
85-
case 0x00BAB748: l = 164; break;
86-
case 0x0554B640: l = 232; break;
87-
case 0x05C5DE08: l = 176; break;
88-
case 0x04DFFE58: l = 328; break;
89-
case 0x069AC2F0: l = 216; break;
90-
case 0x08F3C4F0: l = 156; break;
91-
case 0x080739A8: l = 260; break;
92-
case 0x05D170F8: l = 268; break;
93-
case 0x08393130: l = 356; break;
94-
case 0x08EB3288: l = 308; break;
95-
case 0x0A236268: l = 232; break;
96-
97-
// DX11
98-
case 0x06B82EF8: l = 232; break;
99-
case 0x062DF990: l = 268; break;
100-
case 0x064CB3A0: l = 308; break;
101-
102-
103-
default:
104-
printf(" case 0x%08X: l = ; break;\n", t);
105-
assert(false);
106-
break;
107-
}
81+
printf("Type: 0x%08X, Object count: %d\n", header.unk0, header.objectCount);
10882

109-
printf("using l = %d, from: 0x%08X, %d\n", l, t, header.objectCount);
110-
for(unsigned int i = 0; i < l / 4; i++) {
83+
// FIXME: Pretty sure that all of this data is garbage. no idea why it is allocated..
84+
for(unsigned int i = 0; i < header.objectCount; i++) {
11185
uint32_t u;
11286
fread(&u,4,1,in);
113-
114-
printf("[%d] = 0x%08X (%f), %d (%d)\n",
115-
i,
116-
u, *(float*)&u,
117-
u % 512, 512 - (u % 512));
118-
87+
printf("[%d] = 0x%08X (%f)\n", i, u, *(float*)&u);
11988
}
12089

12190
putKey("objects");

Diff for: scripts/blender.py

+55-6
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,16 @@ def fileContents(filename):
4444

4545
enums = json.loads(fileContents(os.path.join(data_path, "./enums.json"))) # Load _Enums file [as json]
4646
objs = json.loads(fileContents(os.path.join(data_path, "./table.json"))) # Load table file [as json]
47-
dil = json.loads(fileContents(os.path.join(data_path, "./dil.json"))) # Load Placement file [as json]
47+
dil0 = json.loads(fileContents(os.path.join(data_path, "./dil0.json"))) # Load Visual Placement file [as json]
48+
dil1 = json.loads(fileContents(os.path.join(data_path, "./dil1.json"))) # Load Light Placement file [as json]
4849

4950
def resourceIndexFromName(name):
5051
return enums[name]['index']
5152

52-
def placementFromName(name):
53+
def resourcePath(resource, extension):
54+
return str(resourceIndexFromName(resource['resource'])) + "-" + str(resource['index']) + "." + extension
55+
56+
def placementFromName(dil, name):
5357
for placement in dil['objects']:
5458
a = placement['name']
5559
b = name
@@ -124,20 +128,65 @@ def dilPlace(imported, obj):
124128
else:
125129
#FIXME: TODO
126130
print("pos: " + str(dilPos) + " for " + str(obj))
127-
var = placementFromName(dilPos['variable'])
131+
var = placementFromName(dil0, dilPos['dilName'])
128132
if var == None:
129133
#FIXME: Delete object now?!
130134
return
131135
placements = var['placements']
132136
for placement in placements:
133137
print("Want this at " + str(placement))
134138
# FIXME: Place this object at all locations?!
135-
placement = placements[0]
139+
placement = placements[dilPos['dilIndex']]
136140
dilPlaceInstance(imported, placement)
137141

138142
#print(objs)
139143

140144

145+
# Load lights from PBTable
146+
for key in objs:
147+
obj = objs[key]
148+
if obj['type'] != "PBTable":
149+
continue
150+
obj = obj['data']
151+
152+
for d in obj:
153+
154+
if d['type'] == "Dil":
155+
visualDil = d['data']
156+
157+
if d['type'] == "LightingData":
158+
lightDil = d['data'] # FIXME: Remove anything but "name" and "index" ?!
159+
lights = d['data']['lights']
160+
161+
162+
print("Would be using " + resourcePath(visualDil, "json") + " as DIL Visual placement")
163+
print("Would be using " + resourcePath(lightDil, "json") + " as DIL Light placement")
164+
165+
# Place lights!
166+
if True:
167+
for light in lights:
168+
var = placementFromName(dil1, light['dilName'])
169+
if var == None:
170+
#FIXME: Delete object now?!
171+
continue
172+
173+
print(var)
174+
placement = var['placements'][light['dilIndex']]
175+
176+
# What about angle and scale?!
177+
p = placement['position']
178+
xyz = (f * p[0], f * p[1], f * p[2])
179+
180+
bpy.ops.object.lamp_add(type='POINT', radius=1, view_align=False, location=xyz, layers=[True] * 20)
181+
bpy.context.object.data.name = light['dilName'] + ";" + str(light['dilIndex']) + ";" + light['type'] + ";" + str(light['index'])
182+
bpy.context.object.data.color = light['color'] # RGB Color (FIXME: Normalize?!)
183+
#FIXME: unk0
184+
bpy.context.object.data.energy = light['brightness'] * 0.001 # Brightness [and a hacky factor I came up with]
185+
# bpy.context.object.data.falloff_type = 'CONSTANT' # Falloff mode
186+
# bpy.context.object.data.distance = 5.05 # Falloff style
187+
# bpy.context.object.data.use_sphere = True # Use bounding sphere for lamp influence
188+
189+
141190
# Iterate over objects and find PBObject entries
142191
for key in objs:
143192
obj = objs[key]
@@ -309,8 +358,8 @@ def dilPlace(imported, obj):
309358
# Only show visuals
310359
scene.layers = [True] * 10 + [False] * 10
311360

312-
print("dir: " + str(scene.game_settings.gravity))
313-
print("used: " + str(scene.use_gravity))
361+
#print("dir: " + str(scene.game_settings.gravity))
362+
#print("used: " + str(scene.use_gravity))
314363
#scene.game_settings.physics_gravity = (0.0, -0.5, -10.0) # Bugs out!
315364

316365
if False:

Diff for: scripts/convert.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ for filename in $inPath/*.0025; do
5454
$BIN_DIR/format0025 "$filename" "$outPath/$(basename "$filename" .0025).wav"
5555
done
5656

57-
# FIXME: Only using -0.002A because -1.002A might be broken PS4 DILs
58-
for filename in $inPath/*-0.002A; do
57+
for filename in $inPath/*.002A; do
5958
echo "$filename"
6059
$BIN_DIR/format002A "$filename" "$outPath/$(basename "$filename" .002A).json"
6160
done

Diff for: scripts/table.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ echo "$SCRIPT_DIR/convert.sh $outPath/unpacked $outPath/converted"
2323
bash $SCRIPT_DIR/convert.sh $outPath/unpacked $outPath/converted
2424

2525
# Extra copy of the placement and table file [a bit hacky..]
26-
$BIN_DIR/format002A $outPath/unpacked/*-0.002A $outPath/dil.json
26+
$BIN_DIR/format002A $outPath/unpacked/*-0.002A $outPath/dil0.json
27+
$BIN_DIR/format002A $outPath/unpacked/*-1.002A $outPath/dil1.json
2728
$BIN_DIR/pba-csv $outPath/converted/$tmpHack-1.csv $outPath/table.json
2829

2930
echo "blender --python $SCRIPT_DIR/blender.py -- $outPath"

0 commit comments

Comments
 (0)