public void Read(byte[] bytes) { int bytei = BitConverter.ToInt32(bytes, 0); bool flag; switch (rs) { // Checking for Magic bytes at the start of the file // There are two magic bytes 0x00000001. After them, the file starts. case ReaderState.MagicBytesCheck: switch (bytei) { case 0: break; case 1: remainingMagicBytes--; break; default: Logger.Error("Wrong magic byte : " + bytei + ", needed " + remainingMagicBytes + " more"); break; } if (remainingMagicBytes == 0) { rs = ReaderState.AssetID; } break; // Reading the Unity Asset ID of the ESM case ReaderState.AssetID: esmAssetID = bytei; rs = ReaderState.ESMNameL; break; // Reading the length of the ESM name case ReaderState.ESMNameL: if (bytei == 0) { break; } sr = new StringReader(bytei); rs = ReaderState.ESMName; break; // Reading the ESM Name case ReaderState.ESMName: flag = sr.Add(bytes); if (flag) { esmName = sr.Read(); rs = ReaderState.ESCount; } break; // Reading the amount of Entity States case ReaderState.ESCount: entityStates = new JObject(); remainingESs = bytei; rs = ReaderState.ESNameL; break; // Reading the next Entity State name length case ReaderState.ESNameL: if (bytei == 0) { break; } sr = new StringReader(bytei); rs = ReaderState.ESName; break; // Reading the next Entity State name case ReaderState.ESName: flag = sr.Add(bytes); if (flag) { esName = sr.Read(); rs = ReaderState.ESACount; } break; // Reading the next Entity State Attribute count case ReaderState.ESACount: esAttributes = new JObject(); remainingAttributes = bytei; if (remainingAttributes == 0) { rs = ReaderState.ESNameL; } else { rs = ReaderState.ESANameL; } break; // Reading the next Entity State Attribute name length case ReaderState.ESANameL: if (bytei == 0) { break; } sr = new StringReader(bytei); rs = ReaderState.ESAName; break; // Reading the next Entity State Attribute name case ReaderState.ESAName: flag = sr.Add(bytes); if (flag) { esaName = sr.Read(); rs = ReaderState.ESAType; } break; // Reading the next Entity State Attribute type case ReaderState.ESAType: switch (bytei) { case 1: esaType = ESAType.Int; break; case 2: esaType = ESAType.Float; break; case 3: esaType = ESAType.String; break; case 4: esaType = ESAType.UnityObject; break; case 5: esaType = ESAType.Boolean; break; case 6: esaType = ESAType.AnimationCurve; break; case 7: esaType = ESAType.Vector3; break; default: esaType = ESAType.Unknown; break; } esaBytes = new List <byte[]>(); eoaState = EOAState.Viewed0; rs = ReaderState.ESAValue; break; // Reading the next Entity State Attribute value case ReaderState.ESAValue: esaBytes.Add(bytes); eoaState = Util.NextEOAState(eoaState, bytei); if (eoaState == EOAState.EndOfAttribute) { // Remove EOA bytes esaBytes.RemoveRange(esaBytes.Count - 6, 6); Util.AddValue(esAttributes, esaName, esaType, esaBytes); remainingAttributes--; if (remainingAttributes > 0) { rs = ReaderState.ESANameL; } else { entityStates[esName] = esAttributes; remainingESs--; rs = ReaderState.ESNameL; } } break; } }
public static void AddValue(JObject esAttributes, string esaName, ESAType esaType, List <byte[]> esaBytes) { int length = esaBytes.Count; switch (esaType) { case ESAType.Int: if (length == 0) { esAttributes[esaName] = 0; } else { int bytei = BitConverter.ToInt32(esaBytes[0], 0); if (bytei != 0) { esAttributes[esaName] = bytei; } else { esaBytes.RemoveAt(0); AddValue(esAttributes, esaName, esaType, esaBytes); } } break; case ESAType.Float: if (length == 0) { esAttributes[esaName] = 0; } else { float bytef = BitConverter.ToSingle(esaBytes[0], 0); if (bytef != 0) { esAttributes[esaName] = bytef; } else { esaBytes.RemoveAt(0); AddValue(esAttributes, esaName, esaType, esaBytes); } } break; case ESAType.String: if (length == 0) { esAttributes[esaName] = ""; } else { int bytei = BitConverter.ToInt32(esaBytes[0], 0); if (bytei != 0) { StringReader sr = new StringReader(bytei); bool flag = false; for (int i = 1; !flag && i < length; i++) { flag = sr.Add(esaBytes[i]); } esAttributes[esaName] = sr.Read(); } else { esaBytes.RemoveAt(0); AddValue(esAttributes, esaName, esaType, esaBytes); } } break; case ESAType.UnityObject: if (length == 0) { esAttributes[esaName] = "Unknown UnityObject"; } else { int bytei = BitConverter.ToInt32(esaBytes[0], 0); if (bytei != 0) { esAttributes[esaName] = "UnityObject (PathID : " + bytei + ")"; } else { esaBytes.RemoveAt(0); AddValue(esAttributes, esaName, esaType, esaBytes); } } break; case ESAType.Boolean: if (length == 0) { esAttributes[esaName] = false; } else { bool byteb = BitConverter.ToBoolean(esaBytes[0], 0); if (byteb) { esAttributes[esaName] = true; } else { esaBytes.RemoveAt(0); AddValue(esAttributes, esaName, esaType, esaBytes); } } break; case ESAType.AnimationCurve: esAttributes[esaName] = "AnimationCurve"; break; case ESAType.Vector3: esAttributes[esaName] = "Vector3"; break; case ESAType.Unknown: esAttributes[esaName] = "ERROR"; break; } }