public void SetActiveObject(GameObject active) { ActiveObject = active; ActiveOBJf = null; if (active.OBJ.UsesFnTable > 0) { ActiveOBJf = ActiveObject.Resource.Get <OBJf>(ActiveObject.OBJ.ChunkID); } IsOBJDFunc = (ActiveOBJf == null); TableCombo.SelectedIndex = (IsOBJDFunc) ? 0 : 1; RefreshView(); }
/// <summary> /// Finds and runs the init() function in this object's container (IFF) /// if the current object has one, or skips straight to the main function. /// </summary> private void RunInitFunction() { m_ExecutionStack = new Stack <IFFDecode>(m_CurrentObject.Master.InitialStackSize); //Initialize the stack-size from the OBJD and check to see if the IFF has //an OBJf with the same ID as the OBJD. foreach (OBJf ObjFunctions in m_CurrentObject.ObjectContainer.OBJfs) { if (ObjFunctions.ID == m_CurrentObject.Master.ChunkID) { m_CurrentObjectFunctions = ObjFunctions; } } if (m_CurrentObjectFunctions == null) { //OBJD doesn't link to an init function. m_CurrentState = VThreadState.Main; m_MainFuncID = m_CurrentObject.Master.MainFuncID; foreach (BHAV Function in m_CurrentObject.ObjectContainer.BHAVs) { if (Function.ChunkID == m_CurrentObject.Master.MainFuncID) { m_CurrentFunction = Function; } } if (m_CurrentObject.Master.InitialStackSize <= m_CurrentFunction.NumInstructions) { for (int i = m_CurrentObject.Master.InitialStackSize; i > 0; i--) { m_ExecutionStack.Push(new IFFDecode(m_CurrentFunction.Instructions[i])); } } else { for (int i = m_CurrentFunction.NumInstructions; i > 0; i--) { m_ExecutionStack.Push(new IFFDecode(m_CurrentFunction.Instructions[i])); } } } else //An associated OBJF was found, which links to an init() function! { int GuardFuncID = m_CurrentObjectFunctions.FunctionIDs[0].GuardFuncID; m_InitFuncID = m_CurrentObjectFunctions.FunctionIDs[0].FunctionID; m_MainFuncID = m_CurrentObjectFunctions.FunctionIDs[1].FunctionID; foreach (BHAV Function in m_CurrentObject.ObjectContainer.BHAVs) { if (Function.ChunkID == GuardFuncID) { m_CurrentFunction = Function; break; } } if (m_CurrentObject.Master.InitialStackSize <= m_CurrentFunction.NumInstructions) { for (int i = m_CurrentObject.Master.InitialStackSize; i > 0; i--) { m_ExecutionStack.Push(new IFFDecode(m_CurrentFunction.Instructions[i])); } } else { for (int i = m_CurrentFunction.NumInstructions; i > 0; i--) { m_ExecutionStack.Push(new IFFDecode(m_CurrentFunction.Instructions[i])); } } } }