public static object GetFsmObject(this ActionData actionData, int index, int dataVersion) { BinaryReader r = new BinaryReader(new MemoryStream(actionData.byteData.ToArray())); //string actionName = actionData.actionNames[index]; ParamDataType paramDataType = actionData.paramDataType[index]; int paramDataPos = actionData.paramDataPos[index]; int paramByteDataSize = actionData.paramByteDataSize[index]; r.BaseStream.Position = paramDataPos; object ret; switch (paramDataType) { case ParamDataType.Integer: ret = r.ReadInt32(); break; case ParamDataType.FsmInt when dataVersion == 1: ret = new FsmInt() { value = r.ReadInt32() }; break; case ParamDataType.Enum: ret = r.ReadInt32(); //ret = ((Enum)AssemblyHelper.GetPublicFields(typeDef)[index])[ret]; break; case ParamDataType.Boolean: ret = r.ReadBoolean(); break; case ParamDataType.FsmBool when dataVersion == 1: ret = new FsmBool { value = r.ReadBoolean() }; break; case ParamDataType.Float: ret = r.ReadSingle(); break; case ParamDataType.FsmFloat when dataVersion == 1: ret = new FsmFloat { value = r.ReadSingle() }; break; case ParamDataType.String: ret = Encoding.UTF8.GetString(r.ReadBytes(paramByteDataSize)); break; case ParamDataType.FsmEvent when dataVersion == 1: ret = new FsmEvent { name = Encoding.UTF8.GetString(r.ReadBytes(paramByteDataSize)) }; break; case ParamDataType.Vector2: ret = new Vector2 { x = r.ReadSingle(), y = r.ReadSingle() }; break; case ParamDataType.FsmVector2 when dataVersion == 1: ret = new FsmVector2 { value = new Vector2 { x = r.ReadSingle(), y = r.ReadSingle() } }; break; case ParamDataType.Vector3: ret = new Vector3 { x = r.ReadSingle(), y = r.ReadSingle(), z = r.ReadSingle() }; break; case ParamDataType.FsmVector3 when dataVersion == 1: ret = new FsmVector3 { value = new Vector3 { x = r.ReadSingle(), y = r.ReadSingle(), z = r.ReadSingle() } }; break; case ParamDataType.Quaternion: ret = new Quaternion { x = r.ReadSingle(), y = r.ReadSingle(), z = r.ReadSingle(), w = r.ReadSingle() }; break; case ParamDataType.FsmQuaternion when dataVersion == 1: ret = new FsmQuaternion { value = new Quaternion { x = r.ReadSingle(), y = r.ReadSingle(), z = r.ReadSingle(), w = r.ReadSingle() } }; break; case ParamDataType.Color: ret = new UnityColor { r = r.ReadSingle(), g = r.ReadSingle(), b = r.ReadSingle(), a = r.ReadSingle() }; break; case ParamDataType.FsmColor when dataVersion == 1: ret = new FsmColor { value = new UnityColor { r = r.ReadSingle(), g = r.ReadSingle(), b = r.ReadSingle(), a = r.ReadSingle() } }; break; case ParamDataType.Rect: ret = new UnityRect { x = r.ReadSingle(), y = r.ReadSingle(), width = r.ReadSingle(), height = r.ReadSingle() }; break; case ParamDataType.FsmRect when dataVersion == 1: ret = new FsmRect { value = new UnityRect { x = r.ReadSingle(), y = r.ReadSingle(), width = r.ReadSingle(), height = r.ReadSingle() } }; break; ///////////////////////////////////////////////////////// case ParamDataType.FsmEnum when dataVersion > 1: ret = actionData.fsmEnumParams[paramDataPos]; break; case ParamDataType.FsmBool when dataVersion > 1: ret = actionData.fsmBoolParams[paramDataPos]; break; case ParamDataType.FsmInt when dataVersion > 1: ret = actionData.fsmIntParams[paramDataPos]; break; case ParamDataType.FsmFloat when dataVersion > 1: ret = actionData.fsmFloatParams[paramDataPos]; break; case ParamDataType.FsmVector2 when dataVersion > 1: ret = actionData.fsmVector2Params[paramDataPos]; break; case ParamDataType.FsmVector3 when dataVersion > 1: ret = actionData.fsmVector3Params[paramDataPos]; break; case ParamDataType.FsmQuaternion when dataVersion > 1: ret = actionData.fsmQuaternionParams[paramDataPos]; break; case ParamDataType.FsmColor when dataVersion > 1: ret = actionData.fsmColorParams[paramDataPos]; break; case ParamDataType.FsmRect when dataVersion > 1: ret = actionData.fsmRectParams[paramDataPos]; break; ///////////////////////////////////////////////////////// case ParamDataType.FsmGameObject: ret = actionData.fsmGameObjectParams[paramDataPos]; break; case ParamDataType.FsmOwnerDefault: ret = actionData.fsmOwnerDefaultParams[paramDataPos]; break; case ParamDataType.FsmObject: ret = actionData.fsmObjectParams[paramDataPos]; break; case ParamDataType.FsmVar: ret = actionData.fsmVarParams[paramDataPos]; break; case ParamDataType.FsmString: ret = actionData.fsmStringParams[paramDataPos]; break; case ParamDataType.FsmEvent: ret = actionData.stringParams[paramDataPos]; break; case ParamDataType.FsmEventTarget: ret = actionData.fsmEventTargetParams[paramDataPos]; break; case ParamDataType.FsmArray: ret = actionData.fsmArrayParams[paramDataPos]; break; case ParamDataType.ObjectReference: ret = $"ObjRef([{actionData.unityObjectParams[paramDataPos]}])"; break; case ParamDataType.FunctionCall: ret = actionData.functionCallParams[paramDataPos]; break; case ParamDataType.Array: ret = "[Array]"; break; default: ret = $"[{paramDataType.ToString()} not implemented]"; break; } if (dataVersion == 1 && ret is NamedVariable nv) { switch (paramDataType) { case ParamDataType.FsmInt: case ParamDataType.FsmBool: case ParamDataType.FsmFloat: case ParamDataType.FsmVector2: case ParamDataType.FsmVector3: case ParamDataType.FsmQuaternion: case ParamDataType.FsmColor: nv.useVariable = r.ReadBoolean(); int nameLength = paramByteDataSize - ((int)r.BaseStream.Position - paramDataPos); nv.name = Encoding.UTF8.GetString(r.ReadBytes(nameLength)); break; } } return(ret); }
public static string GetDisplayValue(AssetTypeValueField actionData, AssetsFileInstance inst, int version, ParamDataType type, int paramDataPos, int paramByteDataSize, BinaryReader reader) { string displayValue = "? " + type; if (version == 1 && !(type == ParamDataType.FsmString && paramByteDataSize == 0)) //read binary as normal { switch (type) { case ParamDataType.Integer: case ParamDataType.FsmInt: case ParamDataType.FsmEnum: { displayValue = reader.ReadInt32().ToString(); break; } case ParamDataType.Enum: { displayValue = "Enum " + reader.ReadInt32().ToString(); break; } case ParamDataType.Boolean: case ParamDataType.FsmBool: { displayValue = reader.ReadBoolean().ToString().ToLower(); break; } case ParamDataType.Float: case ParamDataType.FsmFloat: { displayValue = reader.ReadSingle().ToString(); break; } case ParamDataType.String: case ParamDataType.FsmString: case ParamDataType.FsmEvent: { displayValue = Encoding.ASCII.GetString(reader.ReadBytes(paramByteDataSize)); break; } case ParamDataType.Vector2: case ParamDataType.FsmVector2: { string x = reader.ReadSingle().ToString(); string y = reader.ReadSingle().ToString(); displayValue = x + ", " + y; break; } case ParamDataType.Vector3: case ParamDataType.FsmVector3: { string x = reader.ReadSingle().ToString(); string y = reader.ReadSingle().ToString(); string z = reader.ReadSingle().ToString(); displayValue = x + ", " + y + ", " + z; break; } } if (PossiblyHasName(type)) { int length = (paramByteDataSize + paramDataPos) - (int)reader.BaseStream.Position; if (length > 0) { byte hasName = reader.ReadByte(); if (hasName == 0x01) { string varName = Encoding.ASCII.GetString(reader.ReadBytes(length - 1)); if (varName != "") { displayValue = varName; } } } } } else //read from fsmXXXParams { AssetTypeValueField field = null; switch (type) { case ParamDataType.Integer: { displayValue = reader.ReadInt32().ToString(); break; } case ParamDataType.Enum: { displayValue = "Enum " + reader.ReadInt32().ToString(); break; } case ParamDataType.Boolean: { displayValue = reader.ReadBoolean().ToString().ToLower(); break; } case ParamDataType.Float: { displayValue = reader.ReadSingle().ToString(); break; } case ParamDataType.String: { displayValue = Encoding.ASCII.GetString(reader.ReadBytes(paramByteDataSize)); break; } case ParamDataType.Vector2: { string x = reader.ReadSingle().ToString(); string y = reader.ReadSingle().ToString(); displayValue = x + ", " + y; break; } case ParamDataType.Vector3: { string x = reader.ReadSingle().ToString(); string y = reader.ReadSingle().ToString(); string z = reader.ReadSingle().ToString(); displayValue = x + ", " + y + ", " + z; break; } case ParamDataType.FsmInt: { field = actionData.Get("fsmIntParams").Get((uint)paramDataPos); displayValue = field.Get("value").GetValue().AsInt().ToString(); break; } case ParamDataType.FsmEnum: { field = actionData.Get("fsmEnumParams").Get((uint)paramDataPos); string intValue = field.Get("intValue").GetValue().AsInt().ToString(); string enumName = field.Get("enumName").GetValue().AsString().ToString(); displayValue = $"{intValue} ({enumName})"; break; } case ParamDataType.FsmBool: { field = actionData.Get("fsmBoolParams").Get((uint)paramDataPos); displayValue = field.Get("value").GetValue().AsBool().ToString(); break; } case ParamDataType.FsmFloat: { field = actionData.Get("fsmFloatParams").Get((uint)paramDataPos); displayValue = field.Get("value").GetValue().AsFloat().ToString(); break; } case ParamDataType.FsmString: { field = actionData.Get("fsmStringParams").Get((uint)paramDataPos); displayValue = field.Get("value").GetValue().AsString(); break; } case ParamDataType.FsmEvent: { field = actionData.Get("stringParams").Get((uint)paramDataPos); displayValue = field.GetValue().AsString(); break; } case ParamDataType.FsmVector2: { field = actionData.Get("fsmVector2Params").Get((uint)paramDataPos); AssetTypeValueField value = field.Get("value"); string x = value.Get("x").GetValue().AsFloat().ToString(); string y = value.Get("y").GetValue().AsFloat().ToString(); displayValue = x + ", " + y; break; } case ParamDataType.FsmVector3: { field = actionData.Get("fsmVector3Params").Get((uint)paramDataPos); AssetTypeValueField value = field.Get("value"); string x = value.Get("x").GetValue().AsFloat().ToString(); string y = value.Get("y").GetValue().AsFloat().ToString(); string z = value.Get("z").GetValue().AsFloat().ToString(); displayValue = x + ", " + y + ", " + z; break; } default: { displayValue = "unknown type " + type.ToString(); break; } } if (PossiblyHasName(type) && UseVariable(field)) { string varName = field.Get("name").GetValue().AsString(); if (varName != "") { displayValue = varName; } } } //either version switch (type) { case ParamDataType.FsmGameObject: case ParamDataType.FsmOwnerDefault: { AssetTypeValueField gameObject; if (type == ParamDataType.FsmOwnerDefault) { AssetTypeValueField fsmOwnerDefaultParam = actionData.Get("fsmOwnerDefaultParams").Get((uint)paramDataPos); if (fsmOwnerDefaultParam["ownerOption"].GetValue().AsInt() == 0) { displayValue = "FSM Owner"; break; } gameObject = fsmOwnerDefaultParam.Get("gameObject"); } else { gameObject = actionData.Get("fsmGameObjectParams").Get((uint)paramDataPos); } string name = gameObject.Get("name").GetValue().AsString(); AssetTypeValueField value = gameObject.Get("value"); int m_FileID = value.Get("m_FileID").GetValue().AsInt(); long m_PathID = value.Get("m_PathID").GetValue().AsInt64(); if (name == "") { name += GetAssetNameFast(m_FileID, m_PathID, inst); } displayValue = name; if (m_PathID != 0) { if (name != "") { displayValue += " "; } displayValue += $"[{m_FileID},{m_PathID}]"; } break; } case ParamDataType.FsmObject: { AssetTypeValueField fsmObjectParam = actionData.Get("fsmObjectParams").Get((uint)paramDataPos); string name = fsmObjectParam.Get("name").GetValue().AsString(); string typeName = fsmObjectParam.Get("typeName").GetValue().AsString(); if (typeName.Contains(".")) { typeName = typeName.Substring(typeName.LastIndexOf(".") + 1); } AssetTypeValueField value = fsmObjectParam.Get("value"); int m_FileID = value.Get("m_FileID").GetValue().AsInt(); long m_PathID = value.Get("m_PathID").GetValue().AsInt64(); if (name == "") { name += GetAssetNameFast(m_FileID, m_PathID, inst); } displayValue = name; if (typeName != "") { if (name == "") { displayValue = typeName; } else { displayValue += ": " + typeName; } } if (m_PathID != 0) { displayValue += $" [{m_FileID},{m_PathID}]"; } break; } case ParamDataType.FunctionCall: { AssetTypeValueField functionCallParam = actionData.Get("functionCallParams").Get((uint)paramDataPos); string functionName = functionCallParam.Get("FunctionName").GetValue().AsString(); string parameterType = functionCallParam.Get("parameterType").GetValue().AsString(); AssetTypeValueField field = null; switch (parameterType) { case "bool": { field = functionCallParam.Get("BoolParameter"); displayValue = field.Get("value").GetValue().AsBool().ToString().ToLower(); goto NonPPtr; } case "float": { field = functionCallParam.Get("FloatParameter"); displayValue = field.Get("value").GetValue().AsFloat().ToString(); goto NonPPtr; } case "int": { field = functionCallParam.Get("IntParameter"); displayValue = field.Get("value").GetValue().AsInt().ToString(); goto NonPPtr; } case "GameObject": { field = functionCallParam.Get("GameObjectParameter"); goto PPtr; } case "Object": { field = functionCallParam.Get("ObjectParameter"); goto PPtr; } case "string": { field = functionCallParam.Get("StringParameter"); displayValue = field.Get("value").GetValue().AsString(); goto NonPPtr; } case "Vector2": { field = functionCallParam.Get("Vector2Parameter"); AssetTypeValueField value = field.Get("value"); string x = value.Get("x").GetValue().AsFloat().ToString(); string y = value.Get("y").GetValue().AsFloat().ToString(); displayValue = x + ", " + y; goto NonPPtr; } case "Vector3": { field = functionCallParam.Get("Vector3Parameter"); AssetTypeValueField value = field.Get("value"); string x = value.Get("x").GetValue().AsFloat().ToString(); string y = value.Get("y").GetValue().AsFloat().ToString(); string z = value.Get("z").GetValue().AsFloat().ToString(); displayValue = x + ", " + y + ", " + z; goto NonPPtr; } case "Rect": { field = functionCallParam.Get("RectParameter"); AssetTypeValueField value = field.Get("value"); string x = value.Get("x").GetValue().AsFloat().ToString(); string y = value.Get("y").GetValue().AsFloat().ToString(); string width = value.Get("width").GetValue().AsFloat().ToString(); string height = value.Get("height").GetValue().AsFloat().ToString(); displayValue = "[" + x + ", " + y + "], [" + width + ", " + height + "]"; goto NonPPtr; } case "Quaternion": { field = functionCallParam.Get("QuaternionParameter"); AssetTypeValueField value = field.Get("value"); string x = value.Get("x").GetValue().AsFloat().ToString(); string y = value.Get("y").GetValue().AsFloat().ToString(); string z = value.Get("z").GetValue().AsFloat().ToString(); string w = value.Get("w").GetValue().AsFloat().ToString(); displayValue = x + ", " + y + ", " + z + ", " + w; goto NonPPtr; } case "Material": { field = functionCallParam.Get("MaterialParameter"); goto PPtr; } case "Texture": { field = functionCallParam.Get("TextureParameter"); goto PPtr; } case "Color": { field = functionCallParam.Get("ColorParameter"); AssetTypeValueField value = field.Get("value"); string r = ((int)(value.Get("r").GetValue().AsFloat()) * 255).ToString("X2"); string g = ((int)(value.Get("g").GetValue().AsFloat()) * 255).ToString("X2"); string b = ((int)(value.Get("b").GetValue().AsFloat()) * 255).ToString("X2"); string a = ((int)(value.Get("a").GetValue().AsFloat()) * 255).ToString("X2"); displayValue = "#" + r + g + b + a; goto NonPPtr; } case "Enum": { field = functionCallParam.Get("EnumParameter"); string enumName = field.Get("enumName").GetValue().AsString(); if (enumName.Contains(".")) { enumName = enumName.Substring(enumName.LastIndexOf(".") + 1); } displayValue = field.Get("value").GetValue().AsInt() + " (" + enumName + ")"; goto NonPPtr; } case "Array": { field = functionCallParam.Get("ArrayParameter"); displayValue = ""; goto NonPPtr; } case "None": { displayValue = ""; goto NonPPtr; } PPtr: { string name = field.Get("name").GetValue().AsString(); AssetTypeValueField value = field.Get("value"); int m_FileID = value.Get("m_FileID").GetValue().AsInt(); long m_PathID = value.Get("m_PathID").GetValue().AsInt64(); displayValue = functionName + "(" + name; if (name == "") { name += GetAssetNameFast(m_FileID, m_PathID, inst); } if (m_PathID != 0) { if (name != "") { displayValue += " "; } displayValue += $"[{m_FileID},{m_PathID}])"; } break; } NonPPtr: { string name = ""; field?.Get("name").GetValue().AsString(); displayValue = name != "" ? $"{functionName}({name}: {displayValue})" : $"{functionName}({displayValue})"; break; } } break; } case ParamDataType.FsmEventTarget: { AssetTypeValueField fsmObjectParam = actionData.Get("fsmEventTargetParams").Get((uint)paramDataPos); EventTarget target = (EventTarget)fsmObjectParam.Get("target").GetValue().AsInt(); bool exclude = fsmObjectParam.Get("excludeSelf").Get("value").GetValue().AsBool(); displayValue = target.ToString() + (exclude ? "!" : ""); break; } case ParamDataType.Array: displayValue = ""; break; } return(displayValue); }