Commit c1d5af73 authored by Spencer Alves's avatar Spencer Alves

Fix Room and Object export/import

parent b7506b7f
......@@ -203,7 +203,8 @@ namespace Altar
{
EnableViews = 1,
ShowColour = 2,
ClearDisplayBuffer = 4 // clear display buffer with window colour
ClearDisplayBuffer = 4, // clear display buffer with window colour
Unknown = 0x20000 // probably signals the extra 32 bytes at the end
// isometric?
// clearViewBg?
......@@ -432,9 +433,9 @@ namespace Altar
LinearDamping,
AngularDamping,
Unknown0,
Friction,
Unknown1,
Kinematic;
Friction;
public int Unknown1;
public float Kinematic;
}
[StructLayout(LayoutKind.Explicit, Pack = 1)]
public unsafe struct ObjectRest
......
......@@ -630,9 +630,9 @@ namespace Altar
SectionWriter.WriteFonts(chunk, f.Fonts, stringOffsets, texPagOffsets,
out chunkStringOffsetOffsets, out chunkTexpOffsetOffsets);
break;
/*case SectionHeaders.Objects:
case SectionHeaders.Objects:
chunkStringOffsetOffsets = SectionWriter.WriteObjects(chunk, f.Objects, stringOffsets);
break;*/
break;
case SectionHeaders.Rooms:
chunkStringOffsetOffsets = SectionWriter.WriteRooms(chunk, f.Rooms, stringOffsets);
break;
......
......@@ -120,7 +120,7 @@ namespace Altar.Repack
Friction = (float)j["friction"],
Kinematic = (float)j["kinematic"],
Unknown0 = (float)j["unk0"],
Unknown1 = (float)j["unk1"]
Unknown1 = (int)j["unk1"]
};
#endregion
......@@ -155,8 +155,10 @@ namespace Altar.Repack
{
Index = (uint)j["index"],
Instances = DeserializeArray(j["instances"], i => (uint)i),
ObjName = (string)j["obj"],
Unk2 = (uint)j["unk2"]
Name = (string)j["name"],
Unk1 = (uint)j["unk1"],
Unk2 = (uint)j["unk2"],
Unk3 = (uint)j["unk3"]
};
}
......@@ -361,7 +363,10 @@ namespace Altar.Repack
CollisionShape = (CollisionShape)Enum.Parse(typeof(CollisionShape), (string)j["colshape"], true),
OtherFloats = DeserializeArray(j["data"], (Func<dynamic, float>)(d => (float)d)),
ShapePoints = DeserializeArray(j["points"], (Func<dynamic, Point>)(d => DeserializePoint(d)))
ShapePoints = DeserializeArray(j["points"],
(Func<dynamic, int[][]>)(d => DeserializeArray(d,
(Func<dynamic, int[]>)(e => DeserializeArray(e,
(Func<dynamic, int>)(f => (int)f))))))
};
}
#region public static RoomInfo DeserializeRoom(JsonData j, BackgroundInfo[] bgs, ObjectInfo[] objs)
......@@ -373,6 +378,7 @@ namespace Altar.Repack
EnableViews = (bool)j["enableviews"],
ShowColour = (bool)j["showcolour"],
ClearDisplayBuffer = (bool)j["clearbuf"],
UnknownFlag = (bool)j["flag"],
World = (uint)j["world"],
MetresPerPixel = (float)j["metresperpx"],
DrawBackgroundColour = (bool)j["drawbgcol"],
......@@ -738,6 +744,22 @@ namespace Altar.Repack
f.Audio[i] = audioinfo;
}
}
if (projFile.Has("sprites"))
{
Console.Write("Loading sprites... ");
var cl = Console.CursorLeft;
var ct = Console.CursorTop;
var sprites = projFile["sprites"].ToArray();
f.Sprites = new SpriteInfo[sprites.Length];
for (int i = 0; i < sprites.Length; i++)
{
Console.SetCursorPosition(cl, ct);
Console.WriteLine(O_PAREN + (i + 1) + SLASH + sprites.Length + C_PAREN);
f.Sprites[i] = DeserializeSprite(JsonMapper.ToObject(File.ReadAllText(Path.Combine(baseDir, (string)(sprites[i])))));
f.Sprites[i].Name = Path.GetFileNameWithoutExtension((string)(sprites[i]));
}
}
if (projFile.Has("objs"))
{
Console.Write("Loading objects... ");
......@@ -792,22 +814,6 @@ namespace Altar.Repack
f.Sound[i].Name = Path.GetFileNameWithoutExtension((string)(sounds[i]));
}
}
if (projFile.Has("sprites"))
{
Console.Write("Loading sprites... ");
var cl = Console.CursorLeft;
var ct = Console.CursorTop;
var sprites = projFile["sprites"].ToArray();
f.Sprites = new SpriteInfo[sprites.Length];
for (int i = 0; i < sprites.Length; i++)
{
Console.SetCursorPosition(cl, ct);
Console.WriteLine(O_PAREN + (i + 1) + SLASH + sprites.Length + C_PAREN);
f.Sprites[i] = DeserializeSprite(JsonMapper.ToObject(File.ReadAllText(Path.Combine(baseDir, (string)(sprites[i])))));
f.Sprites[i].Name = Path.GetFileNameWithoutExtension((string)(sprites[i]));
}
}
if (projFile.Has("bg"))
{
Console.WriteLine("Loading backgrounds...");
......
This diff is collapsed.
......@@ -154,7 +154,7 @@ namespace Altar
public ObjectPhysics? Physics;
public float[] OtherFloats;
public Point[] ShapePoints;
public int[][][] ShapePoints;
}
[StructLayout(LayoutKind.Sequential)]
public struct RoomInfo
......@@ -172,6 +172,7 @@ namespace Altar
public bool EnableViews;
public bool ShowColour;
public bool ClearDisplayBuffer;
public bool UnknownFlag;
public uint World;
public BoundingBox Bounding;
......@@ -264,9 +265,11 @@ namespace Altar
[StructLayout(LayoutKind.Sequential)]
public struct RoomObjInst
{
public string ObjName;
public string Name;
public uint Index;
public uint Unk1;
public uint Unk2;
public uint Unk3;
public uint[] Instances;
}
......
......@@ -152,8 +152,10 @@ namespace Altar.Unpack
var entry = (RoomObjInstEntry*)p;
var oi = new RoomObjInst();
oi.Index = entry->Index;
oi.ObjName = StringFromOffset(content, entry->Name);
oi.Name = StringFromOffset(content, entry->Name);
oi.Unk1 = entry->Unk1;
oi.Unk2 = entry->Unk2;
oi.Unk3 = entry->Unk3;
oi.Instances = new uint[entry->InstCount];
for (uint i = 0; i < oi.Instances.Length; i++)
{
......@@ -496,30 +498,42 @@ namespace Altar.Unpack
}
else
{
ret.ShapePoints = new Point[shapeCop->Count >> 1];
ret.ShapePoints = new int[shapeCop->Count][][];
for (uint i = 0; i < (shapeCop->Count >> 1); i++)
for (uint i = 0; i < (shapeCop->Count); i++)
{
uint xoff = (&shapeCop->Offsets)[ i << 1 ],
yoff = (&shapeCop->Offsets)[(i << 1) + 1];
uint shapePointOff = (&shapeCop->Offsets)[i];
int* xptr = (int*)GMFile.PtrFromOffset(content, xoff),
yptr = (int*)GMFile.PtrFromOffset(content, yoff);
uint* shapePointPtr = (uint*)GMFile.PtrFromOffset(content, shapePointOff);
//Console.WriteLine(((IntPtr)xoff).ToString(SR.HEX_FM8) + SR.SPACE_S + ((IntPtr)yoff).ToString(SR.HEX_FM8));
if (((xoff | yoff) & 0xFF000000) != 0 || xptr == null || yptr == null)
if ((shapePointOff & 0xFF000000) != 0 || shapePointPtr == null)
{
Console.WriteLine($"Warning: shape point coord {i} of object {id} is bogus, ignoring...");
ret.ShapePoints[i] = new Point(-0xDEAD, -0xC0DE);
continue;
}
ret.ShapePoints[i] = new Point(
*(int*)GMFile.PtrFromOffset(content, xoff),
*(int*)GMFile.PtrFromOffset(content, yoff)
);
uint shapePointPointCount = *shapePointPtr;
uint* shapePointPointOffsets = shapePointPtr+1;
ret.ShapePoints[i] = new int[shapePointPointCount][];
for (uint j = 0; j < shapePointPointCount; j++)
{
uint shapePointPointOff = shapePointPointOffsets[j];
int* shapePointPointPtr = (int*)GMFile.PtrFromOffset(content, shapePointPointOff);
// TODO: fixed size, but mostly the same across
// entries. Probably structure of some sort.
// Index 1/2 look like count/offset, but count is
// always 1 and offset is always +4.
uint pointpointlen = 17;
ret.ShapePoints[i][j] = new int[pointpointlen];
for (uint k = 0; k < ret.ShapePoints[i][j].Length; k++)
{
ret.ShapePoints[i][j][k] = shapePointPointPtr[k];
}
}
}
}
......@@ -547,6 +561,7 @@ namespace Altar.Unpack
ret.EnableViews = (re->Flags & RoomEntryFlags.EnableViews ) != 0;
ret.ShowColour = (re->Flags & RoomEntryFlags.ShowColour ) != 0;
ret.ClearDisplayBuffer = (re->Flags & RoomEntryFlags.ClearDisplayBuffer) != 0;
ret.UnknownFlag = (re->Flags & RoomEntryFlags.Unknown ) != 0;
ret.World = re->World ;
ret.Bounding = re->Bounding ;
......@@ -568,6 +583,12 @@ namespace Altar.Unpack
}
}
// TODO: There's an extra 32 bytes at the end of each room entry in
// JetBoy, and they are important! I got a different background
// color and some motion blur effects when I set them to dummy
// values.
// background color is 16 bytes in
return ret;
}
public static TexturePageInfo GetTexPageInfo(GMFileContent content, uint id)
......
......@@ -230,9 +230,11 @@ namespace Altar.Unpack
static JsonData SerializeRoomObjInst(RoomObjInst oi)
{
var r = CreateObj();
r["obj" ] = oi.ObjName;
r["name" ] = oi.Name;
r["index" ] = oi.Index;
r["unk1" ] = oi.Unk1;
r["unk2" ] = oi.Unk2;
r["unk3" ] = oi.Unk3;
r["instances"] = SerializeArray(oi.Instances, Utils.Identity);
return r;
}
......@@ -410,7 +412,7 @@ namespace Altar.Unpack
r["data" ] = SerializeArray(objt.OtherFloats, Utils.Identity);
if (objt.ShapePoints != null)
r["points"] = SerializeArray(objt.ShapePoints, SerializePoint);
r["points"] = SerializeArray(objt.ShapePoints, x => SerializeArray(x, y => SerializeArray(y, Utils.Identity)));
return r;
}
......@@ -426,6 +428,7 @@ namespace Altar.Unpack
r["enableviews"] = room.EnableViews;
r["showcolour" ] = room.ShowColour;
r["clearbuf" ] = room.ClearDisplayBuffer;
r["flag" ] = room.UnknownFlag;
r["world" ] = room.World;
r["bounding" ] = SerializeRect(room.Bounding);
r["gravity" ] = SerializePoint(room.Gravity);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment