| 548 | } |
| 549 | |
| 550 | void ScriptingEngineNet::RegisterEntityScript(Entity& entity) |
| 551 | { |
| 552 | if (!isInitialized) |
| 553 | { |
| 554 | return; |
| 555 | } |
| 556 | |
| 557 | if (!entity.IsValid()) |
| 558 | { |
| 559 | Logger::Log("Failed to register entity .net script: Entity not valid.", ".net", CRITICAL); |
| 560 | return; |
| 561 | } |
| 562 | |
| 563 | if (!entity.HasComponent<NetScriptComponent>()) |
| 564 | { |
| 565 | Logger::Log("Failed to register entity .net script: Entity doesn't have a .net script component.", ".net", CRITICAL); |
| 566 | return; |
| 567 | } |
| 568 | |
| 569 | auto& component = entity.GetComponent<NetScriptComponent>(); |
| 570 | |
| 571 | const auto& filePath = component.ScriptPath; |
| 572 | |
| 573 | std::string className; |
| 574 | if (String::EndsWith(filePath, ".cs")) |
| 575 | { |
| 576 | className = FindClassNameInScript(filePath); |
| 577 | } |
| 578 | else |
| 579 | { |
| 580 | className = filePath; |
| 581 | } |
| 582 | |
| 583 | if(gameEntityTypes.find(className) == gameEntityTypes.end()) |
| 584 | { |
| 585 | // The class name parsed in the file was not found in the game's DLL. |
| 586 | const std::string& msg = "Skipped .net entity script: \n Class: " + |
| 587 | className + " not found in " + std::string(gameAssembly.GetName()); |
| 588 | Logger::Log(msg, ".net", CRITICAL); |
| 589 | return; |
| 590 | } |
| 591 | |
| 592 | auto classInstance = gameEntityTypes[className].coralType->CreateInstance(); |
| 593 | |
| 594 | int handle = entity.GetHandle(); |
| 595 | int id = entity.GetID(); |
| 596 | classInstance.SetPropertyValue("ECSHandle", handle); |
| 597 | classInstance.SetPropertyValue("ID", id); |
| 598 | |
| 599 | if (entity.HasComponent<BSPBrushComponent>()) |
| 600 | { |
| 601 | BSPBrushComponent& brushComponent = entity.GetComponent<BSPBrushComponent>(); |
| 602 | } |
| 603 | |
| 604 | std::vector<std::string> detectedExposedVar; |
| 605 | detectedExposedVar.reserve(std::size(gameEntityTypes[className].exposedVars)); |
| 606 | // Update new default values if they have changed in the code. |
| 607 | for (auto& exposedVar : gameEntityTypes[className].exposedVars) |