mirror of
https://github.com/LazyDuchess/OpenTS2.git
synced 2025-01-22 16:21:47 -05:00
SimAntics: Implement Semi-Attributes, fix Attribute count
This commit is contained in:
parent
561917e60d
commit
dab570aef4
2 changed files with 33 additions and 3 deletions
|
@ -27,6 +27,7 @@ namespace OpenTS2.SimAntics
|
||||||
{
|
{
|
||||||
VMDataSource.Globals => VM.GetGlobal((ushort)dataIndex),
|
VMDataSource.Globals => VM.GetGlobal((ushort)dataIndex),
|
||||||
VMDataSource.MyObjectsAttributes => Entity.Attributes[dataIndex],
|
VMDataSource.MyObjectsAttributes => Entity.Attributes[dataIndex],
|
||||||
|
VMDataSource.MyObjectsSemiAttributes => Entity.SemiAttributes[dataIndex],
|
||||||
VMDataSource.MyObject => Entity.ObjectData[dataIndex],
|
VMDataSource.MyObject => Entity.ObjectData[dataIndex],
|
||||||
VMDataSource.StackObject => StackObjectEntity.ObjectData[dataIndex],
|
VMDataSource.StackObject => StackObjectEntity.ObjectData[dataIndex],
|
||||||
VMDataSource.Literal => dataIndex,
|
VMDataSource.Literal => dataIndex,
|
||||||
|
@ -38,10 +39,12 @@ namespace OpenTS2.SimAntics
|
||||||
VMDataSource.Local => StackFrame.Locals[dataIndex],
|
VMDataSource.Local => StackFrame.Locals[dataIndex],
|
||||||
VMDataSource.StackObjectsDefinition => (short)StackObjectEntity.ObjectDefinition.Fields[dataIndex],
|
VMDataSource.StackObjectsDefinition => (short)StackObjectEntity.ObjectDefinition.Fields[dataIndex],
|
||||||
VMDataSource.StackObjectsAttributes => StackObjectEntity.Attributes[dataIndex],
|
VMDataSource.StackObjectsAttributes => StackObjectEntity.Attributes[dataIndex],
|
||||||
|
VMDataSource.StackObjectsSemiAttributes => StackObjectEntity.SemiAttributes[dataIndex],
|
||||||
|
VMDataSource.StackObjectsSemiAttributeByParam => StackObjectEntity.SemiAttributes[StackFrame.Arguments[dataIndex]],
|
||||||
_ => throw new SimAnticsException($"Attempted to retrieve a variable from an out of range data source ({source}[{dataIndex}]).", StackFrame)
|
_ => throw new SimAnticsException($"Attempted to retrieve a variable from an out of range data source ({source}[{dataIndex}]).", StackFrame)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
catch (ArgumentOutOfRangeException)
|
catch (IndexOutOfRangeException)
|
||||||
{
|
{
|
||||||
throw new SimAnticsException($"Attempted to retrieve a variable from an out of range data index ({source}[{dataIndex}]).", StackFrame);
|
throw new SimAnticsException($"Attempted to retrieve a variable from an out of range data index ({source}[{dataIndex}]).", StackFrame);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
using OpenTS2.Content.DBPF;
|
using OpenTS2.Common;
|
||||||
|
using OpenTS2.Content;
|
||||||
|
using OpenTS2.Content.DBPF;
|
||||||
using OpenTS2.Files.Formats.DBPF;
|
using OpenTS2.Files.Formats.DBPF;
|
||||||
|
using OpenTS2.Lua.Disassembly.OpCodes;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -21,6 +24,7 @@ namespace OpenTS2.SimAntics
|
||||||
public VM VM;
|
public VM VM;
|
||||||
public ObjectDefinitionAsset ObjectDefinition;
|
public ObjectDefinitionAsset ObjectDefinition;
|
||||||
public short[] Attributes;
|
public short[] Attributes;
|
||||||
|
public short[] SemiAttributes;
|
||||||
public short[] ObjectData = new short[114];
|
public short[] ObjectData = new short[114];
|
||||||
public uint PrivateGroupID => ObjectDefinition.GlobalTGI.GroupID;
|
public uint PrivateGroupID => ObjectDefinition.GlobalTGI.GroupID;
|
||||||
public uint SemiGlobalGroupID
|
public uint SemiGlobalGroupID
|
||||||
|
@ -42,7 +46,30 @@ namespace OpenTS2.SimAntics
|
||||||
public VMEntity(ObjectDefinitionAsset objectDefinition) : this()
|
public VMEntity(ObjectDefinitionAsset objectDefinition) : this()
|
||||||
{
|
{
|
||||||
ObjectDefinition = objectDefinition;
|
ObjectDefinition = objectDefinition;
|
||||||
Attributes = new short[objectDefinition.NumAttributes];
|
Attributes = new short[GetNumberOfAttributes()];
|
||||||
|
SemiAttributes = new short[GetNumberOfSemiGlobalAttributes()];
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Verify these two methods below are right. Sometimes objdefs have 0 attributes but do have attribute labels and get/set their attributes.
|
||||||
|
private int GetNumberOfAttributes()
|
||||||
|
{
|
||||||
|
var objDefAttributes = ObjectDefinition.NumAttributes;
|
||||||
|
var attrLabels = ContentManager.Instance.GetAsset<StringSetAsset>(new ResourceKey(0x100, PrivateGroupID, TypeIDs.STR));
|
||||||
|
if (attrLabels == null)
|
||||||
|
return objDefAttributes;
|
||||||
|
var attrLabelsCount = attrLabels.StringData.Strings[Languages.USEnglish].Count;
|
||||||
|
return attrLabelsCount > objDefAttributes ? attrLabelsCount : objDefAttributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int GetNumberOfSemiGlobalAttributes()
|
||||||
|
{
|
||||||
|
var semiGlobal = ObjectDefinition.SemiGlobal;
|
||||||
|
if (semiGlobal == null)
|
||||||
|
return 0;
|
||||||
|
var semiAttributeLabels = ContentManager.Instance.GetAsset<StringSetAsset>(new ResourceKey(0x100, semiGlobal.SemiGlobalGroupID, TypeIDs.STR));
|
||||||
|
if (semiAttributeLabels == null)
|
||||||
|
return 0;
|
||||||
|
return semiAttributeLabels.StringData.Strings[Languages.USEnglish].Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public short GetObjectData(VMObjectData field)
|
public short GetObjectData(VMObjectData field)
|
||||||
|
|
Loading…
Reference in a new issue