Ejemplo n.º 1
0
 private static void InitBaseModContext()
 {
     m_baseContext = new MyModContext();
     m_baseContext.ModName = null;
     m_baseContext.ModPath = MyFileSystem.ContentPath;
     m_baseContext.ModPathData = Path.Combine(m_baseContext.ModPath, "Data");
 }
Ejemplo n.º 2
0
 public void Init(MyModContext context)
 {
     ModName = context.ModName;
     ModPath = context.ModPath;
     ModPathData = context.ModPathData;
     CurrentFile = context.CurrentFile;
 }
Ejemplo n.º 3
0
 public void Add(MyModContext context, MyDefinitionId obj)
 {
     Debug.Assert(context != null);
     if (context == null)
     {
         MyLog.Default.WriteLine("Writing to scripted group definition without context");
         return;
     }
     m_scriptedObjects.Add(obj);
 }
 public void Add(MyModContext context, MyDefinitionId obj)
 {
     Debug.Assert(context != null);
     if (context == null)
     {
         MyLog.Default.WriteLine("Writing to scripted group definition without context");
         return;
     }
     m_scriptedObjects.Add(obj);
 }
Ejemplo n.º 5
0
 public void Add(MyModContext context, MyDefinitionId obj)
 {
     if (context == null)
     {
         MyLog.Default.WriteLine("Writing to scripted group definition without context");
     }
     else
     {
         this.m_scriptedObjects.Add(obj);
     }
 }
 public void AddDefinitionSafe <T>(T definition, MyModContext context, string file)
     where T : MyDefinitionBase, V
 {
     if (definition.Id.TypeId != MyObjectBuilderType.Invalid)
     {
         this[definition.Id] = definition;
     }
     else
     {
         MyDefinitionErrors.Add(context, "Invalid definition id", ErrorSeverity.Error);
     }
 }
Ejemplo n.º 7
0
 public void Init(MyObjectBuilder_DefinitionBase builder, MyModContext modContext)
 {
     Context = modContext;
     Init(builder);
 }
Ejemplo n.º 8
0
        private void TryAddEntityScripts(Assembly assembly)
        {
            var gameLogicType = typeof(MyGameLogicComponent);
            var builderType = typeof(MyObjectBuilder_Base);
            foreach (var type in assembly.GetTypes())
            {
                var descriptorArray = type.GetCustomAttributes(typeof(MyEntityComponentDescriptor), false);
                if (descriptorArray != null && descriptorArray.Length > 0)
                {
                    var descriptor = (MyEntityComponentDescriptor)descriptorArray[0];
                    try
                    {
                        var component = (MyGameLogicComponent)Activator.CreateInstance(type);

                        if (descriptor.EntityBuilderSubTypeNames != null && descriptor.EntityBuilderSubTypeNames.Length > 0)
                        {
                            foreach (string subTypeName in descriptor.EntityBuilderSubTypeNames)
                            {
                                if (gameLogicType.IsAssignableFrom(type) && builderType.IsAssignableFrom(descriptor.EntityBuilderType))
                                {
                                    if (!SubEntityScripts.ContainsKey(new Tuple<Type, string>(descriptor.EntityBuilderType, subTypeName)))
                                    {
                                        SubEntityScripts.Add(new Tuple<Type, string>(descriptor.EntityBuilderType, subTypeName), new HashSet<Type>());
                                    }
                                    else
                                    {
                                        var c = new MyModContext();
                                        c.Init(assembly.FullName, assembly.FullName);
                                        MyDefinitionErrors.Add(c, "Possible entity type script logic collision", ErrorSeverity.Warning);
                                    }

                                    SubEntityScripts[new Tuple<Type, string>(descriptor.EntityBuilderType, subTypeName)].Add(type);
                                }
                            }
                        }
                        else
                        {
                            if (gameLogicType.IsAssignableFrom(type) && builderType.IsAssignableFrom(descriptor.EntityBuilderType))
                            {
                                if (!EntityScripts.ContainsKey(descriptor.EntityBuilderType))
                                {
                                    EntityScripts.Add(descriptor.EntityBuilderType, new HashSet<Type>());
                                }
                                else
                                {
                                    var c = new MyModContext();
                                    c.Init(assembly.FullName, assembly.FullName);
                                    MyDefinitionErrors.Add(c, "Possible entity type script logic collision", ErrorSeverity.Warning);
                                }

                                EntityScripts[descriptor.EntityBuilderType].Add(type);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        MySandboxGame.Log.WriteLine("Exception during loading of type : " + type.Name);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        private void Compile(IEnumerable<string> scriptFiles, string assemblyName, bool zipped)
        {
            Assembly assembly = null;
            var c = new MyModContext();
            c.Init(assemblyName, assemblyName);
            if (zipped)
            {
                var tmp = Path.GetTempPath();
                foreach (var file in scriptFiles)
                {
                    try
                    {
                        var newPath = string.Format("{0}{1}", tmp, Path.GetFileName(file));
                        var stream = MyFileSystem.OpenRead(file);
                        using (var sr = new StreamReader(stream))
                        {
                            stream = MyFileSystem.OpenWrite(newPath);// (newPath);
                            using (var sw = new StreamWriter(stream))
                            {
                                sw.Write(sr.ReadToEnd()); //create file in tmp for debugging
                            }
                        }
                        m_cachedFiles.Add(newPath);
                    }
                    catch (Exception e)
                    {
                        MySandboxGame.Log.WriteLine(e);
                        MyDefinitionErrors.Add(c, string.Format("Cannot load {0}",Path.GetFileName(file)) , ErrorSeverity.Error);
                        MyDefinitionErrors.Add(c, e.Message, ErrorSeverity.Error);
                    }
                }
                IlCompiler.CompileFileModAPI(assemblyName, m_cachedFiles.ToArray(), out assembly, m_errors);
            }
            else
            {
                IlCompiler.CompileFileModAPI(assemblyName, scriptFiles.ToArray(), out assembly, m_errors);
            }
            if(assembly != null)
                AddAssembly(MyStringId.GetOrCompute(assemblyName), assembly);
            else
            {
                MyDefinitionErrors.Add(c, string.Format("Compilation of {0} failed:", assemblyName), ErrorSeverity.Error);
                MySandboxGame.Log.IncreaseIndent();
				foreach (var error in m_errors)
				{
					MyDefinitionErrors.Add(c, error.ToString(), ErrorSeverity.Error);
					Debug.Assert(false, error.ToString());
				}
                MySandboxGame.Log.DecreaseIndent();
                m_errors.Clear();
            }
            m_cachedFiles.Clear();
        }
Ejemplo n.º 10
0
 public void Init(MyObjectBuilder_DefinitionBase builder, MyModContext modContext)
 {
     Context = modContext;
     Init(builder);
 }
Ejemplo n.º 11
0
 private void TryAddEntityScripts(Assembly assembly)
 {
     var gameLogicType = typeof(MyGameLogicComponent);
     var builderType = typeof(MyObjectBuilder_Base);
     foreach (var type in assembly.GetTypes())
     {
         var descriptorArray = type.GetCustomAttributes(typeof(MyEntityComponentDescriptor), false);
         if (descriptorArray != null && descriptorArray.Length > 0)
         {
             var descriptor = (MyEntityComponentDescriptor)descriptorArray[0];
             var component = (MyGameLogicComponent)Activator.CreateInstance(type);
             if (gameLogicType.IsAssignableFrom(type) && builderType.IsAssignableFrom(descriptor.EntityBuilderType))
             {
                 if (EntityScripts.Remove(descriptor.EntityBuilderType))
                 {
                     var msg = string.Format("Entity script overwritten: {0}", descriptor.EntityBuilderType.Name);
                     Debug.Fail(msg);
                     var c = new MyModContext();
                     c.Init(assembly.FullName, assembly.FullName);
                     MyDefinitionErrors.Add(c, msg, ErrorSeverity.Notice);
                 }
                 EntityScripts.Add(descriptor.EntityBuilderType, type);
             }
         }
     }
 }