mono::object CScriptbind_Entity::GetEntityLinks(IEntity *pEntity) { // the first link IEntityLink *pLink = pEntity->GetEntityLinks(); IMonoArray *pDynArray = CreateDynamicMonoArray(); while(pLink != nullptr) { pDynArray->InsertAny(reinterpret_cast<intptr_t>(pLink)); pLink = pLink->next; } return pDynArray->GetManagedObject(); }
void CMonoEntityExtension::RMIParams::SerializeWith(TSerialize ser) { IMonoArray *pArgs; int length; if(args != nullptr) { pArgs = *args; length = pArgs->GetSize(); } else length = 0; ser.Value("length", length); ser.Value("methodName", methodName); ser.Value("targetId", targetId, 'eid'); if(length > 0) { if(ser.IsWriting()) { for(int i = 0; i < length; i++) { IMonoObject *pItem = *pArgs->GetItem(i); pItem->GetAnyValue().SerializeWith(ser); SAFE_RELEASE(pItem); } } else { pArgs = g_pScriptSystem->GetScriptDomain()->CreateArray(length); for(int i = 0; i < length; i++) { MonoAnyValue value; value.SerializeWith(ser); pArgs->InsertAny(value, i); } args = pArgs->GetManagedObject(); } pArgs->Release(); } }
bool CScriptSystem::Reload() { if((!m_bFirstReload && g_pMonoCVars->mono_realtimeScripting == 0) || m_bReloading) return false; m_bReloading = true; if(!m_bFirstReload) { for each(auto listener in m_listeners) listener->OnReloadStart(); m_pScriptManager->CallMethod("Serialize"); } IMonoDomain *pScriptDomain = CreateDomain("ScriptDomain", nullptr, true); IMonoAssembly *pCryBraryAssembly = pScriptDomain->LoadAssembly(PathUtils::GetBinaryPath() + "CryBrary.dll"); IMonoArray *pCtorParams = CreateMonoArray(2); pCtorParams->InsertAny(m_bFirstReload); pCtorParams->InsertMonoString(ToMonoString(PathUtils::GetConfigPath())); IMonoObject *pScriptManager = *pCryBraryAssembly->GetClass("ScriptManager", "CryEngine.Initialization")->CreateInstance(pCtorParams); SAFE_RELEASE(pCtorParams); auto result = pScriptManager->CallMethod("Initialize", m_bFirstReload); if(result == nullptr) return false; IMonoObject *pResult = *result; auto reloadResult = pResult->Unbox<EScriptReloadResult>(); SAFE_RELEASE(pResult); switch(reloadResult) { case EScriptReloadResult_Success: { // revert previous domain if(!m_bFirstReload) m_pScriptDomain->Release(); m_pScriptDomain = pScriptDomain; m_pScriptManager = pScriptManager; m_pCryBraryAssembly = pCryBraryAssembly; CacheManagedResources(); if(!m_bFirstReload) m_pScriptManager->CallMethod("Deserialize"); // Set Network.Editor etc. IMonoClass *pClass = m_pCryBraryAssembly->GetClass("Game"); IMonoArray *pArgs = CreateMonoArray(2); pArgs->Insert(gEnv->IsEditor()); pArgs->Insert(gEnv->IsDedicated()); pClass->GetMethod("InitializeGameStatics", 2)->InvokeArray(nullptr, pArgs); SAFE_RELEASE(pArgs); m_pScriptManager->CallMethod("ProcessWaitingScripts", m_bFirstReload); for each(auto listener in m_listeners) listener->OnReloadComplete(); if(!m_bFirstReload && gEnv->IsEditor()) gEnv->pFlowSystem->ReloadAllNodeTypes(); m_bReloading = false; m_bDetectedChanges = false; return true; } break; case EScriptReloadResult_Retry: { m_bReloading = false; return Reload(); } case EScriptReloadResult_Revert: { pScriptDomain->Release(); m_pScriptDomain->SetActive(); m_bReloading = false; m_bDetectedChanges = false; return false; } break; case EScriptReloadResult_Abort: { gEnv->pSystem->Quit(); m_bReloading = false; } break; } return false; }