void CFlowManager::RegisterNode(mono::string monoTypeName) { IFlowSystem *pFlowSystem = gEnv->pGameFramework->GetIFlowSystem(); if(!pFlowSystem) return; const char *typeName = ToCryString(monoTypeName); CFlowManager *pFlowManager = g_pScriptSystem->GetFlowManager(); if(!pFlowManager) { MonoWarning("Aborting registration of node type %s, flow manager was null!", typeName); return; } pFlowSystem->RegisterType(typeName, (IFlowNodeFactoryPtr)pFlowManager); }
mono::object CScriptDomain::BoxAnyValue(MonoAnyValue &any) { switch(any.type) { case eMonoAnyType_Boolean: return (mono::object)mono_value_box(m_pDomain, mono_get_boolean_class(), &any.b); case eMonoAnyType_Integer: return (mono::object)mono_value_box(m_pDomain, mono_get_int32_class(), &any.i); case eMonoAnyType_UnsignedInteger: return (mono::object)mono_value_box(m_pDomain, mono_get_uint32_class(), &any.u); case eMonoAnyType_EntityId: { IMonoClass *pEntityIdClass = g_pScriptSystem->GetCryBraryAssembly()->GetClass("EntityId"); return pEntityIdClass->BoxObject(&mono::entityId(any.u), this)->GetManagedObject(); } case eMonoAnyType_Short: return (mono::object)mono_value_box(m_pDomain, mono_get_int16_class(), &any.i); case eMonoAnyType_UnsignedShort: return (mono::object)mono_value_box(m_pDomain, mono_get_uint16_class(), &any.u); case eMonoAnyType_Float: return (mono::object)mono_value_box(m_pDomain, mono_get_single_class(), &any.f); case eMonoAnyType_String: MonoWarning("IMonoConverter::BoxAnyValue does not support strings, utilize ToMonoString instead"); case eMonoAnyType_Vec3: { IMonoClass *pVec3Class = g_pScriptSystem->GetCryBraryAssembly()->GetClass("Vec3"); Vec3 vec3(any.vec4.x, any.vec4.y, any.vec4.z); return pVec3Class->BoxObject(&vec3, this)->GetManagedObject(); } break; case eMonoAnyType_Quat: { IMonoClass *pQuatClass = g_pScriptSystem->GetCryBraryAssembly()->GetClass("Quat"); return pQuatClass->BoxObject(&any.vec4, this)->GetManagedObject(); } break; } return nullptr; }
void CScriptbind_ActorSystem::RegisterActorClass(mono::string name, bool isNative, bool isAI) { const char *className = ToCryString(name); if(!isNative) { if(gEnv->pEntitySystem->GetClassRegistry()->FindClass(className)) { MonoWarning("Aborting registration of actor class %s, a class with the same name already exists", className); return; } if(isAI) static_cast<CScriptSystem *>(GetMonoScriptSystem())->GetIGameFramework()->RegisterFactory(className, (CMonoAIActor *)0, true, (CMonoAIActor *)0); else static_cast<CScriptSystem *>(GetMonoScriptSystem())->GetIGameFramework()->RegisterFactory(className, (CMonoActor *)0, false, (CMonoActor *)0); } m_monoActorClasses.insert(TActorClasses::value_type(className, isNative ? EMonoActorType_Native : EMonoActorType_Managed)); }
void CCryScriptInstance::OnReloadComplete() { if(m_scriptId == 0) return; IMonoObject *pScriptManager = g_pScriptSystem->GetScriptManager(); IMonoArray *pArgs = CreateMonoArray(2); pArgs->Insert(m_scriptId); pArgs->Insert(m_flags); if(mono::object result = pScriptManager->GetClass()->InvokeArray(pScriptManager->GetManagedObject(), "GetScriptInstanceById", pArgs)) { SetManagedObject((MonoObject *)result, true); } else MonoWarning("Failed to locate script instance %i after reload!", m_scriptId); pArgs->Release(); }
bool CScriptbind_Entity::RegisterEntityClass(SEntityRegistrationParams params) { const char *className = ToCryString(params.Name); if(gEnv->pEntitySystem->GetClassRegistry()->FindClass(className)) { MonoWarning("Aborting registration of entity class %s, a class with the same name already exists", className); return false; } int numProperties = 0; SMonoEntityPropertyInfo *pProperties; if(params.Properties != nullptr) { IMonoArray *pPropertyArray = *params.Properties; numProperties = pPropertyArray->GetSize(); pProperties = new SMonoEntityPropertyInfo[numProperties]; for (int iProperty = 0; iProperty < numProperties; iProperty++) { mono::object propertyObject = pPropertyArray->GetItem(iProperty); if(propertyObject == nullptr) continue; auto property = *(SMonoEntityProperty *)mono_object_unbox((MonoObject *)propertyObject); SMonoEntityPropertyInfo propertyInfo; propertyInfo.info.name = ToCryString(property.name); propertyInfo.info.description = ToCryString(property.description); propertyInfo.info.editType = ToCryString(property.editType); propertyInfo.info.type = property.type; propertyInfo.info.limits.min = property.limits.min; propertyInfo.info.limits.max = property.limits.max; propertyInfo.defaultValue = ToCryString(property.defaultValue); pProperties[iProperty] = propertyInfo; } } IEntityClassRegistry::SEntityClassDesc entityClassDesc; entityClassDesc.flags = params.Flags; entityClassDesc.sName = className; entityClassDesc.editorClassInfo.sCategory = ToCryString(params.Category); if(params.EditorHelper != nullptr) entityClassDesc.editorClassInfo.sHelper = ToCryString(params.EditorHelper); if(params.EditorIcon != nullptr) entityClassDesc.editorClassInfo.sIcon = ToCryString(params.EditorIcon); m_monoEntityClasses.push_back(className); bool result = gEnv->pEntitySystem->GetClassRegistry()->RegisterClass(new CEntityClass(entityClassDesc, pProperties, numProperties)); static SMonoEntityCreator creator; static_cast<CScriptSystem *>(GetMonoScriptSystem())->GetIGameFramework()->GetIGameObjectSystem()->RegisterExtension(className, &creator, nullptr); return result; }
_declspec(dllexport) void __cdecl Warning(const char *msg) { MonoWarning(msg); }
IMonoMethod *CScriptClass::GetMethod(const char *name, IMonoArray *pArgs, bool throwOnFail) { MonoMethodSignature *pSignature = nullptr; void *pIterator = 0; MonoClass *pClass = (MonoClass *)m_pObject; MonoType *pClassType = mono_class_get_type(pClass); MonoMethod *pCurMethod = nullptr; int suppliedArgsCount = pArgs ? pArgs->GetSize() : 0; while (pClass != nullptr) { pCurMethod = mono_class_get_methods(pClass, &pIterator); if(pCurMethod == nullptr) { pClass = mono_class_get_parent(pClass); if(pClass == mono_get_object_class()) break; pIterator = 0; continue; } pSignature = mono_method_signature(pCurMethod); int signatureParamCount = mono_signature_get_param_count(pSignature); bool bCorrectName = !strcmp(mono_method_get_name(pCurMethod), name); if(bCorrectName && signatureParamCount == 0 && suppliedArgsCount == 0) return new CScriptMethod(pCurMethod); else if(bCorrectName && signatureParamCount >= suppliedArgsCount && suppliedArgsCount != 0) { //if(bStatic != (mono_method_get_flags(pCurMethod, nullptr) & METHOD_ATTRIBUTE_STATIC) > 0) //continue; void *pIter = nullptr; MonoType *pType = nullptr; for(int i = 0; i < signatureParamCount; i++) { pType = mono_signature_get_params(pSignature, &pIter); if(mono::object item = pArgs->GetItem(i)) { MonoClass *pItemClass = mono_object_get_class((MonoObject *)item); MonoType *pItemType = mono_class_get_type(pItemClass); MonoTypeEnum itemMonoType = (MonoTypeEnum)mono_type_get_type(pItemType); MonoTypeEnum monoType = (MonoTypeEnum)mono_type_get_type(pType); if(itemMonoType != monoType) { // exceptions: // Anything can be treated as object. if(monoType == MONO_TYPE_OBJECT) {} // The runtime confuses things with value types a lot, so ignore parameters that appear with that type. else if(itemMonoType == MONO_TYPE_VALUETYPE || monoType == MONO_TYPE_VALUETYPE) {} else { if(MonoClass *pMethodParameterClass = mono_type_get_class(pType)) { MonoWarning("Parameter mismatch when searching for method %s in class %s.%s, on parameter %i: Provided type %s.%s does not match expected parameter type %s.%s.", name, mono_class_get_namespace(pClass), mono_class_get_name(pClass), i + 1, mono_class_get_namespace(pItemClass), mono_class_get_name(pItemClass), mono_class_get_namespace(pMethodParameterClass), mono_class_get_name(pMethodParameterClass)); } else { MonoWarning("Parameter mismatch when searching for method %s in class %s.%s, on parameter %i: Provided type %s.%s does not match parameter type.", name, mono_class_get_namespace(pClass), mono_class_get_name(pClass), i + 1, mono_class_get_namespace(pItemClass), mono_class_get_name(pItemClass)); } break; } } } if(i + 1 == suppliedArgsCount) return new CScriptMethod(pCurMethod); } } } if(throwOnFail) { if(IMonoException *pException = GetMonoScriptSystem()->GetCorlibAssembly()->GetException("System", "MissingMethodException", "Failed to locate method %s in class %s", name, GetName())) pException->Throw(); } return nullptr; }
bool CScriptbind_Entity::RegisterEntityClass(SEntityRegistrationParams params) { const char *className = ToCryString(params.Name); if(gEnv->pEntitySystem->GetClassRegistry()->FindClass(className)) { MonoWarning("Aborting registration of entity class %s, a class with the same name already exists", className); return false; } std::vector<IEntityPropertyHandler::SPropertyInfo> properties; if(params.Folders != nullptr) { IMonoArray *pFolderArray = *params.Folders; int numFolders = pFolderArray->GetSize(); for (int iFolder = 0; iFolder < numFolders; ++iFolder) { IMonoObject *pFolderObject = pFolderArray->GetItem(iFolder); if(!pFolderObject) continue; auto folder = pFolderObject->Unbox<SMonoEntityPropertyFolder>(); if(folder.properties == nullptr) continue; bool bDefaultFolder = !strcmp(ToCryString(folder.name), "Default") && iFolder == 0; if(!bDefaultFolder) // first element contains properties not organized into folders { IEntityPropertyHandler::SPropertyInfo folderInfo; folderInfo.name = ToCryString(folder.name); folderInfo.type = IEntityPropertyHandler::FolderBegin; properties.push_back(folderInfo); } IMonoArray *pPropertyArray = *folder.properties; for(int iProperty = 0; iProperty < pPropertyArray->GetSize(); iProperty++) { IMonoObject *pPropertyObject = pPropertyArray->GetItem(iProperty); if(pPropertyObject == nullptr) continue; auto property = pPropertyObject->Unbox<SMonoEntityProperty>(); IEntityPropertyHandler::SPropertyInfo propertyInfo; propertyInfo.name = ToCryString(property.name); propertyInfo.description = ToCryString(property.description); propertyInfo.editType = ToCryString(property.editType); propertyInfo.type = property.type; propertyInfo.limits.min = property.limits.min; propertyInfo.limits.max = property.limits.max; properties.push_back(propertyInfo); } if(!bDefaultFolder) { IEntityPropertyHandler::SPropertyInfo folderInfo; folderInfo.name = ToCryString(folder.name); folderInfo.type = IEntityPropertyHandler::FolderEnd; properties.push_back(folderInfo); } } } IEntityClassRegistry::SEntityClassDesc entityClassDesc; entityClassDesc.flags = params.Flags; entityClassDesc.sName = className; entityClassDesc.editorClassInfo.sCategory = ToCryString(params.Category); if(params.EditorHelper != nullptr) entityClassDesc.editorClassInfo.sHelper = ToCryString(params.EditorHelper); if(params.EditorIcon != nullptr) entityClassDesc.editorClassInfo.sIcon = ToCryString(params.EditorIcon); m_monoEntityClasses.push_back(className); bool result = gEnv->pEntitySystem->GetClassRegistry()->RegisterClass(new CEntityClass(entityClassDesc, properties)); static SMonoEntityCreator creator; gEnv->pGameFramework->GetIGameObjectSystem()->RegisterExtension(className, &creator, nullptr); return result; }