From d471c602c703e085e760e16aef0e395396a59fc9 Mon Sep 17 00:00:00 2001 From: Matthew Bowra-Dean Date: Fri, 19 Mar 2010 17:50:27 +1300 Subject: [PATCH] Assembly resolving, fixes to crate dropping. --- OpenRA.FileFormats/FileSystem.cs | 30 +++++++++++++++++++++++++++++ OpenRA.Game/Game.cs | 1 + OpenRA.Mods.RA-NG/CrateDrop.cs | 7 +++++-- OpenRA.Mods.RA/Effects/Parachute.cs | 11 +++++++++-- 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/OpenRA.FileFormats/FileSystem.cs b/OpenRA.FileFormats/FileSystem.cs index 0e1d7672e3..3f5c605029 100644 --- a/OpenRA.FileFormats/FileSystem.cs +++ b/OpenRA.FileFormats/FileSystem.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Reflection; namespace OpenRA.FileFormats { @@ -134,5 +135,34 @@ namespace OpenRA.FileFormats return false; } + + static Dictionary assemblyCache = new Dictionary(); + + public static Assembly ResolveAssembly(object sender, ResolveEventArgs e) + { + foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) + { + if (assembly.FullName == e.Name) + return assembly; + } + + string[] frags = e.Name.Split(','); + var filename = frags[0] + ".dll"; + Assembly a; + if (assemblyCache.TryGetValue(filename, out a)) + return a; + + if (FileSystem.Exists(filename)) + using (Stream s = FileSystem.Open(filename)) + { + byte[] buf = new byte[s.Length]; + s.Read(buf, 0, buf.Length); + a = Assembly.Load(buf); + assemblyCache.Add(filename, a); + return a; + } + + return null; + } } } diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index eca6dd5da2..67def27f91 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -348,6 +348,7 @@ namespace OpenRA public static void PreInit(Settings settings) { + AppDomain.CurrentDomain.AssemblyResolve += FileSystem.ResolveAssembly; while (!Directory.Exists("mods")) { var current = Directory.GetCurrentDirectory(); diff --git a/OpenRA.Mods.RA-NG/CrateDrop.cs b/OpenRA.Mods.RA-NG/CrateDrop.cs index ba980cb529..f09c73da86 100644 --- a/OpenRA.Mods.RA-NG/CrateDrop.cs +++ b/OpenRA.Mods.RA-NG/CrateDrop.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using OpenRA.Mods.RA; using OpenRA.Traits; +using OpenRA.Traits.Activities; namespace OpenRA.Mods.RA_NG { @@ -72,9 +73,11 @@ namespace OpenRA.Mods.RA_NG { self.World.AddFrameEndTask(w => { - var crate = new Actor(w, "crate", new int2(0, 0), self.Owner); + var crate = new Actor(w, "crate", new int2(0, 0), w.NeutralPlayer); crates.Add(crate); - var plane = w.CreateActor("BADR", w.ChooseRandomEdgeCell(), self.Owner); + var plane = w.CreateActor("BADR", w.ChooseRandomEdgeCell(), w.NeutralPlayer); + plane.CancelActivity(); + plane.QueueActivity(new FlyCircle(p)); plane.traits.Get().SetLZ(p); plane.traits.Get().Load(plane, crate); }); diff --git a/OpenRA.Mods.RA/Effects/Parachute.cs b/OpenRA.Mods.RA/Effects/Parachute.cs index 162f1a7a2c..98d43d33f7 100644 --- a/OpenRA.Mods.RA/Effects/Parachute.cs +++ b/OpenRA.Mods.RA/Effects/Parachute.cs @@ -65,9 +65,16 @@ namespace OpenRA.Mods.RA.Effects world.AddFrameEndTask(w => { w.Remove(this); - w.Add(cargo); + int2 loc = ((1 / 24f) * location).ToInt2(); cargo.CancelActivity(); - cargo.traits.Get().TeleportTo(cargo, ((1 / 24f) * location).ToInt2()); + if (cargo.traits.Contains()) + cargo.traits.Get().TeleportTo(cargo, loc); + else + { + cargo.Location = loc; + cargo.CenterLocation = Util.CenterOfCell(loc); + } + w.Add(cargo); }); }