public static Event Deserialize(string s, MovesetNode node) { if (String.IsNullOrEmpty(s)) { return(null); } try { string[] lines = s.Split('|'); if (lines[0].Length != 8) { return(null); } Event newEv = new Event(); string id = lines[0]; uint idNumber = Convert.ToUInt32(id, 16); newEv.EventID = idNumber; uint _event = newEv.EventID; EventInformation info = newEv.Info; for (int i = 0; i < newEv._numArgs; i++) { string[] pLines = lines[i + 1].Split('\\'); int type = int.Parse(pLines[0]); if (type == 2) //Offset { string[] oLines = pLines[1].Split(','); int list = int.Parse(oLines[0]), type2 = int.Parse(oLines[1]), index = int.Parse(oLines[2]); ScriptOffsetInfo w = new ScriptOffsetInfo((ListValue)list, (TypeValue)type2, index); EventOffset o = (EventOffset)newEv.NewParam(i, 0, ParamType.Offset); o._script = node.GetScript(w); o._offsetInfo = w; } else { int value = int.Parse(pLines[1]); newEv.NewParam(i, value, type); } } return(newEv); } catch { return(null); } }
/// <summary> /// Returns the script at the given location. /// </summary> public Script GetScript(ScriptOffsetInfo info) { ListValue list = info.list; TypeValue type = info.type; int index = info.index; if ((list > ListValue.References && _dataCommon == null) || list == ListValue.Null || index == -1) { return(null); } switch (list) { case ListValue.Actions: if ((type == TypeValue.Entry || type == TypeValue.Exit) && index >= 0 && index < Actions.Count) { return((Script)Actions[index].GetWithType((int)type)); } break; case ListValue.SubActions: if (_data != null && index >= 0 && index < _data.SubActions.Count) { return((Script)_data.SubActions[index].GetWithType((int)type)); } break; case ListValue.SubRoutines: if (index >= 0 && index < _subRoutines.Count) { return((Script)_subRoutines[index]); } break; case ListValue.FlashOverlays: if (_dataCommon != null && index >= 0 && index < _dataCommon.FlashOverlays.Count) { return((Script)_dataCommon.FlashOverlays[index]); } break; case ListValue.ScreenTints: if (_dataCommon != null && index >= 0 && index < _dataCommon.ScreenTints.Count) { return((Script)_dataCommon.ScreenTints[index]); } break; } return(null); }
public override void PostParse() { //Get script node using raw offset //This happens in post parse so that all scripts have been parsed already MovesetNode node = (MovesetNode)_root; SakuraiEntryNode e = _root.GetEntry(RawOffset); bool exist = e != null && e is Event; _offsetInfo = node.GetScriptLocation(RawOffset); Script a; if (_offsetInfo._list == ListValue.Null && !exist) { node.SubRoutines.Add(a = Parse <Script>(RawOffset)); } else if (_offsetInfo._list != ListValue.References) { a = node.GetScript(_offsetInfo); } else { if (_externalEntry == null && _offsetInfo._index >= 0 && _offsetInfo._index < _root.ReferenceList.Count) { _externalEntry = _root.ReferenceList[_offsetInfo._index]; _externalEntry.References.Add(this); } return; } if (a == null) { a = GetScript(); } if (a != null) { a._actionRefs.Add(this); } else { throw new Exception("Script not found."); } _script = a; }
internal void LinkScript() { MovesetNode node = (MovesetNode)_root; SakuraiEntryNode e = _root.GetEntry(RawOffset); bool exist = e != null && e is Event; _offsetInfo = node.GetScriptLocation(RawOffset); Script a; if (_offsetInfo.list == ListValue.Null && !exist) { node.SubRoutines.Add(a = Parse <Script>(RawOffset)); } else if (_offsetInfo.list != ListValue.References) { a = node.GetScript(_offsetInfo); } else { if (_externalEntry == null && _offsetInfo.index >= 0 && _offsetInfo.index < _root.ReferenceList.Count) { _externalEntry = _root.ReferenceList[_offsetInfo.index]; _externalEntry.References.Add(this); } return; } if (a == null) { a = GetScript(); } if (a != null) { a._actionRefs.Add(this); } else { throw new Exception("Script not found."); } _script = a; }
/// <summary> /// Use this only when parsing. /// </summary> internal ScriptOffsetInfo GetScriptLocation(int offset) { if (!_initializing) { throw new Exception("Error: Not initializing."); } //Create new offset info ScriptOffsetInfo info = new ScriptOffsetInfo(); //Check if the offset is legit if (offset <= 0) { return(info); } info.list = ListValue.Actions; //Search action offsets for (info.type = 0; (int)info.type < 2; info.type++) { if ((info.index = _scriptOffsets[(int)info.list][(int)info.type].IndexOf(offset)) != -1) { return(info); } } info.list++; //Search subaction offsets for (info.type = 0; (int)info.type < 4; info.type++) { if ((info.index = _scriptOffsets[(int)info.list][(int)info.type].IndexOf(offset)) != -1) { return(info); } } info.type = TypeValue.None; info.list++; //Search subroutine offsets if ((info.index = _scriptOffsets[(int)info.list][0].IndexOf(offset)) != -1) { return(info); } info.list++; //Search reference entry offsets MovesetEntry e = GetEntry(offset); if (e is ExternalEntry && e != null) { info.index = e.Index; return(info); } //Set values to null info.list++; info.type = TypeValue.None; info.index = -1; //Continue searching dataCommon if (_dataCommon != null) { info.list++; //Search screen tint offsets if ((info.index = _scriptOffsets[3][0].IndexOf(offset)) != -1) { return(info); } info.list++; //Search flash overlay offsets if ((info.index = _scriptOffsets[4][0].IndexOf(offset)) != -1) { return(info); } info.list = ListValue.Null; } return(info); }