Commit b7506b7f authored by Spencer Alves's avatar Spencer Alves

Better variable reference resoultion

Still not perfect, but I don't think I'm going to get it any better
parent ce4c794f
......@@ -62,6 +62,8 @@ namespace Altar.Decomp
var offTotal = (long)defs[i].FirstOffset;
var addr = (AnyInstruction*)GMFile.PtrFromOffset(content, offTotal);
if (defs[i].Occurrences != 0) defs[i].VariableType = (VariableType)(((uint*)addr)[1] >> 24);
for (int j = 0; j < defs[i].Occurrences /*&& curOffset != 0*/; j++)
{
ret.Add((IntPtr)addr, i);
......
......@@ -1144,7 +1144,8 @@ namespace Altar.Repack
{
Name = "arguments",
InstanceType = InstanceType.Local,
Instance = f.Code[i].Name
Instance = f.Code[i].Name,
VariableType = VariableType.Normal
}, 0xFFFFFFFF));
}
AddReferencesOffset(variableReferences, f.Code[i].variableReferences, data.Buffer.Position);
......@@ -1168,7 +1169,8 @@ namespace Altar.Repack
{
Name = "arguments",
InstanceType = InstanceType.Local,
Instance = f.Code[i].Name
Instance = f.Code[i].Name,
VariableType = VariableType.Normal
}, 0xFFFFFFFF));
}
AddReferencesOffset(variableReferences, f.Code[i].variableReferences, data.Buffer.Position);
......@@ -1195,9 +1197,10 @@ namespace Altar.Repack
var v = variableStartOffsetsAndCounts[i];
if (i < f.RefData.Variables.Length &&
v.Name == f.RefData.Variables[i].Name &&
v.InstanceType == f.RefData.Variables[i].InstanceType)
(v.InstanceType == f.RefData.Variables[i].InstanceType || v.InstanceType >= InstanceType.StackTopOrGlobal))
{
v.unknown2 = f.RefData.Variables[i].unknown2;
//v.InstanceType = f.RefData.Variables[i].InstanceType;
variableStartOffsetsAndCounts[i] = v;
}
}
......@@ -1207,7 +1210,7 @@ namespace Altar.Repack
Functions = functionStartOffsetsAndCounts.ToArray(),
Variables = variableStartOffsetsAndCounts.ToArray()
};
data.OffsetOffsets = allOffs.ToArray();
return stringOffsetOffsets;
......@@ -1228,22 +1231,33 @@ namespace Altar.Repack
uint count = 0;
var targetRef = references[i].Item1;
var start = references[i].Item2;
if (targetRef.InstanceType >= InstanceType.StackTopOrGlobal)
if (targetRef.InstanceType >= InstanceType.StackTopOrGlobal && extended)
{
targetRef.InstanceType = InstanceType.Self; // ??
for (int j = i + 1; j < references.Count; j++)
for (InstanceType possibleInstanceType = InstanceType.Self; possibleInstanceType >= InstanceType.Local; possibleInstanceType--)
{
if (references[j].Item1.Name == targetRef.Name &&
references[j].Item1.InstanceType < InstanceType.StackTopOrGlobal)
for (int j = i + 1; j < references.Count; j++)
{
if (references[j].Item1.Name == targetRef.Name &&
references[j].Item1.InstanceType == possibleInstanceType)
{
targetRef.InstanceType = references[j].Item1.InstanceType;
targetRef.Instance = references[j].Item1.Instance;
break;
}
}
if (targetRef.InstanceType < InstanceType.StackTopOrGlobal)
{
targetRef = references[j].Item1;
break;
}
}
if (targetRef.InstanceType >= InstanceType.StackTopOrGlobal)
{
targetRef.InstanceType = InstanceType.Self; // ??
}
}
if (targetRef.InstanceType == InstanceType.Local && targetRef.Name == "arguments")
{
localCount = 0;
//localCount = 0;
}
if (start != 0xFFFFFFFF)
{
......@@ -1251,9 +1265,12 @@ namespace Altar.Repack
for (int j = i + 1; j < references.Count;)
{
if (references[j].Item1.Name == targetRef.Name &&
(!extended || (references[j].Item1.InstanceType >= InstanceType.StackTopOrGlobal) ||
(references[j].Item1.InstanceType == targetRef.InstanceType &&
(references[j].Item1.InstanceType != InstanceType.Local || (references[j].Item1.Instance == targetRef.Instance)))))
(!extended ||
(references[j].Item1.InstanceType >= InstanceType.StackTopOrGlobal) ||
(references[j].Item1.InstanceType == targetRef.InstanceType &&
//references[j].Item1.VariableType == targetRef.VariableType &&
(references[j].Item1.InstanceType != InstanceType.Local ||
references[j].Item1.Instance == targetRef.Instance))))
{
diff = (references[j].Item2 - last.Item2) & 0xFFFFFF;
data.Buffer.Position = (int)last.Item2 + 4;
......@@ -1282,7 +1299,8 @@ namespace Altar.Repack
Occurrences = count,
unknown2 = targetRef.InstanceType == InstanceType.Local ?
localCount : targetRef.VariableType == VariableType.StackTop ?
nonLocalCount : - 6
nonLocalCount : - 6,
VariableType = targetRef.VariableType
});
if (targetRef.InstanceType == InstanceType.Local)
{
......
......@@ -15,6 +15,7 @@ namespace Altar
public bool HasExtra;
public InstanceType InstanceType;
public int unknown2;
public VariableType VariableType;
}
[StructLayout(LayoutKind.Sequential)]
......
......@@ -756,6 +756,7 @@ namespace Altar.Unpack
ret.HasExtra = true;
ret.InstanceType = (Decomp.InstanceType)rde->InstanceType;
ret.unknown2 = rde->_pad1;
ret.VariableType = Decomp.VariableType.Normal;
return ret;
});
......
......@@ -438,7 +438,7 @@ namespace Altar.Unpack
r["views"] = SerializeArray(room.Views , v => SerializeRoomView(v, objs));
r["objs" ] = SerializeArray(room.Objects , o => SerializeRoomObj (o, objs));
r["tiles"] = SerializeArray(room.Tiles , t => SerializeRoomTile(t, bgs ));
r["objinst"] = SerializeArray(room.ObjInst , i => SerializeRoomObjInst(i));
if (room.ObjInst != null) r["objinst"] = SerializeArray(room.ObjInst, i => SerializeRoomObjInst(i));
return r;
}
......@@ -477,6 +477,7 @@ namespace Altar.Unpack
r["name"] = rd.Name;
//r["occurrences"] = rd.Occurrences;
//r["type"] = rd.VariableType.ToString();
//if (rd.FirstOffset != 0xFFFFFFFF)
// r["firstoffset"] = rd.FirstOffset;
if (rd.HasExtra)
......
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