Commit 27f61783 authored by Spencer Alves's avatar Spencer Alves

Fix comparison and push-double instructions

parent 58e117e5
......@@ -540,7 +540,7 @@ namespace Altar.Decomp
v = *(long*)rest;
break;
case DataType.String:
v = SectionReader.GetStringInfo(content, ps.ValueRest);
v = SectionReader.GetStringInfo(content, (uint)ps.ValueRest);
break;
}
#endregion
......
......@@ -290,7 +290,7 @@ namespace Altar.Decomp
public DataType Type;
public OpCodes OpCode;
public uint ValueRest;
public UInt64 ValueRest;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct CallInstruction
......
......@@ -206,7 +206,7 @@ namespace Altar.Decomp
sb.Append(((long*)&pp->ValueRest)->ToString(CultureInfo.InvariantCulture));
break;
case DataType.String:
sb.Append(SectionReader.GetStringInfo(content, p.ValueRest).Escape());
sb.Append(SectionReader.GetStringInfo(content, (uint)p.ValueRest).Escape());
break;
}
break;
......
......@@ -420,7 +420,11 @@ namespace Altar.Repack
{
throw new InvalidDataException("Unknown code format for '" + filename + "'");
}
return DeserializeAssembly(instructions, bcv, strings);
}
private static CodeInfo DeserializeAssembly(IEnumerable<Instruction> instructions, uint bcv, string[] strings)
{
IDictionary<string, uint> stringIndices = new Dictionary<string, uint>(strings.Length);
for (uint i = 0; i < strings.Length; i++) stringIndices[strings[i]] = i;
......@@ -471,16 +475,12 @@ namespace Altar.Repack
bp.ValueRest = (uint)(long)p.Value;
break;
case DataType.Double:
bp.ValueRest = BitConverter.ToUInt32(BitConverter.GetBytes(Convert.ToDouble(p.Value)), 0);
break;
case DataType.Single:
bp.ValueRest = BitConverter.ToUInt32(BitConverter.GetBytes((float)Convert.ToDouble(p.Value)), 0);
bp.ValueRest = BitConverter.ToUInt64(BitConverter.GetBytes(Convert.ToDouble(p.Value)), 0);
break;
case DataType.Int32:
bp.ValueRest = BitConverter.ToUInt32(BitConverter.GetBytes((int)unchecked((long)(p.Value))), 0);
break;
case DataType.Int64:
bp.ValueRest = BitConverter.ToUInt32(BitConverter.GetBytes(unchecked((long)(p.Value))), 0);
bp.ValueRest = BitConverter.ToUInt64(BitConverter.GetBytes(unchecked((long)(p.Value))), 0);
break;
case DataType.String:
bp.ValueRest = stringIndices[(string)p.Value];
......@@ -515,6 +515,11 @@ namespace Altar.Repack
OpCode = op,
Types = new TypePair(doubleinst.Type1, doubleinst.Type2)
};
if (inst is Compare)
{
var cmpinst = (Compare)inst;
bininst.DoubleType.ComparisonType = cmpinst.ComparisonType;
}
break;
case InstructionKind.SingleType:
var singleinst = (SingleType)inst;
......
......@@ -953,7 +953,7 @@ namespace Altar.Repack
return stringOffsetOffsets.ToArray();
}
public static void Reassemble(BBData data, Decomp.AnyInstruction[] instructions, uint bytecodeVersion)
public static void WriteCodeBlock(BBData data, Decomp.AnyInstruction[] instructions, uint bytecodeVersion)
{
foreach (var inst in instructions)
{
......@@ -968,7 +968,7 @@ namespace Altar.Repack
}
}
private static void WriteCode(BBData data, CodeInfo ci, IDictionary<string, int> stringOffsets, uint bytecodeVersion)
private static void WriteCodeInfo(BBData data, CodeInfo ci, IDictionary<string, int> stringOffsets, uint bytecodeVersion)
{
data.Buffer.Write(stringOffsets[ci.Name]);
data.Buffer.Write(ci.Size);
......@@ -978,12 +978,12 @@ namespace Altar.Repack
data.Buffer.Write(8);
data.Buffer.Write(0);
}
Reassemble(data, ci.InstructionsCopy, bytecodeVersion);
WriteCodeBlock(data, ci.InstructionsCopy, bytecodeVersion);
}
public static int[] WriteCodes(BBData data, GMFile f, IDictionary<string, int> stringOffsets)
{
var offsets = WriteList(data, f.Code, (fd, ci) => WriteCode(fd, ci, stringOffsets, f.General.BytecodeVersion));
var offsets = WriteList(data, f.Code, (fd, ci) => WriteCodeInfo(fd, ci, stringOffsets, f.General.BytecodeVersion));
var stringOffsetOffsets = new int[f.Code.Length];
for (int i = 0; i < f.Code.Length; i++)
{
......
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