Skip to content

Commit

Permalink
Merge pull request #3330 from CombatExtended-Continued/updated-loader
Browse files Browse the repository at this point in the history
Updated loader
  • Loading branch information
perkinslr authored Aug 17, 2024
2 parents 773cdc8 + ff1adff commit 3915b41
Show file tree
Hide file tree
Showing 33 changed files with 171 additions and 323 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ UnityEngine.dll


.idea/
__pycache__
ModPatches/*/Assemblies/
Binary file removed Assemblies/0CombatExtendedLoader.dll
Binary file not shown.
Binary file added Assemblies/CombatExtendedLoader.dll
Binary file not shown.
15 changes: 14 additions & 1 deletion BuildCompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from subprocess import Popen
import re
import sys
from xml.dom.minidom import parse as XMLOpen

tm = '-m' in sys.argv

Expand Down Expand Up @@ -37,8 +38,20 @@ def system(*cmd):
if tm and name not in sys.argv: continue
csproj = csproj.replace('\\', '/').split('/')
csproj = FilePath("Source").descendant(csproj)
print(f"Building {name}")
output = FilePath("AssembliesCompat").child(name+".dll")
with XMLOpen(csproj.path) as cpath:
op = cpath.getElementsByTagName("OutputPath")
if op:
op = op[0].firstChild.data
if 'ModPatches' in op:
op = op.rsplit("..\\ModPatches", 1)[-1].replace('\\', '/').split('/')
if op:
od = FilePath("ModPatches").descendant(op)
if not od.exists():
od.makedirs()
output = od.child(name+".dll")

print(f"Building {name}")
system("python3", "Make.py", "--csproj", csproj.path, "--output", output.path, DOWNLOAD_LIBS, "--all-libs", "--publicizer", PUBLICIZER, "--", "-r:Assemblies/CombatExtended.dll")

for t in tasks:
Expand Down
50 changes: 50 additions & 0 deletions DupeFinder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from xml.dom.minidom import parse as XMLOpen
from twisted.python.filepath import FilePath
import sys
err = "-c" not in sys.argv

used = {}
mods = set()
ContentRoot = FilePath(".")
ec = 0

def process(node):
global ec
mod = c.getAttribute("IfModActive")
if not mod:
mod = "CETeam.CombatExtended"
dp = c.firstChild.data.replace(''', "'")
if (mod, dp) in mods:
ec += 1
msg = f"Mod {mod} is listed in LoadFolders.xml twice, both pointing to {c.firstChild.data}"
if err:
raise RuntimeError(msg)
else:
print(msg)
mods.add((mod, dp))
root = FilePath("./" + dp)
if not ContentRoot in root.parents():
return
for fd in root.walk():
if fd.isdir():
continue
if not fd.basename().endswith(".xml"):
continue
relative = tuple(fd.segmentsFrom(root))
if relative in used:
msg = f"""Relative paths collision found: {str.join("/", fd.segmentsFrom(ContentRoot))} overrides {str.join("/", used[relative].segmentsFrom(ContentRoot))}"""
if err:
raise RuntimeError(msg)
else:
ec += 1
print(msg)
used[relative] = fd

with XMLOpen("LoadFolders.xml") as x:
v1_5 = x.getElementsByTagName("v1.5")
for n in v1_5:
for c in n.getElementsByTagName("li"):
process(c)


raise SystemExit(ec)
4 changes: 3 additions & 1 deletion LoadFolders.xml
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,6 @@
<li IfModActive="CP.RimmuNation.Security">ModPatches/Rimmu-Nation - Security</li>
<li IfModActive="CP.RimmuNation.Weapons">ModPatches/Rimmu-Nation - Weapons</li>
<li IfModActive="Rimsenal.Spacer">ModPatches/Rimsenal - Spacer Faction Pack</li>
<li IfModActive="Rimsenal.Spacer">ModPatches/Rimsenal - Spacer Faction Pack</li>
<li IfModActive="rimsenal.core">ModPatches/Rimsenal Core</li>
<li IfModActive="rimsenal.EVP">ModPatches/Rimsenal Enhanced Vanilla</li>
<li IfModActive="Bonible.rimsenalfactions">ModPatches/Rimsenal Factions</li>
Expand Down Expand Up @@ -610,5 +609,8 @@
<li IfModActive="pphhyy.ExpandedMechsScyther">ModPatches/pphhyy Expanded Scythers</li>
<li IfModActive="pphhyy.SanguinaryAnimals">ModPatches/pphhyy Sanguinary Animals</li>
<li IfModActive="pphhyy.LightlessEmpyrean">ModPatches/pphhyy's Lightless Empyrean</li>
<li IfModActive="SmashPhil.VehicleFramework">ModPatches/VehicleFramework</li>
<li IfModActive="rwmt.Multiplayer">ModPatches/Multiplayer</li>
<li IfModActive="smashphil.neceros.srtsexpanded">ModPatches/SRTS</li>
</v1.5>
</loadFolders>
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PUBLICIZER := /tmp/AssemblyPublicizer


all: Assemblies/0CombatExtendedLoader.dll Assemblies/CombatExtended.dll CompatAssemblies AssembliesCompat $(PUBLICIZER)
all: Assemblies/CombatExtended.dll CompatAssemblies AssembliesCompat $(PUBLICIZER)

$(PUBLICIZER):
git clone https://github.com/CombatExtended-Continued/AssemblyPublicizer --depth=1 $(PUBLICIZER)
Expand All @@ -12,10 +12,10 @@ $(PUBLICIZER):
AssembliesCompat: $(PUBLICIZER)
mkdir -p AssembliesCompat

Assemblies/0CombatExtendedLoader.dll: Source/Loader/Loader.csproj $(wildcard Source/Loader/Loader/*.cs) $(PUBLICIZER)
python3 Make.py --csproj Source/Loader/Loader.csproj --output Assemblies/0CombatExtendedLoader.dll --reference /tmp/rwreference --all-libs $(DOWNLOAD_LIBS)
Assemblies/CombatExtendedLoader.dll: Source/Loader/Loader.csproj $(wildcard Source/Loader/Loader/*.cs) $(PUBLICIZER)
python3 Make.py --csproj Source/Loader/Loader.csproj --output Assemblies/CombatExtendedLoader.dll --reference /tmp/rwreference --all-libs $(DOWNLOAD_LIBS)

Assemblies/CombatExtended.dll: Assemblies/0CombatExtendedLoader.dll Source/CombatExtended/CombatExtended.csproj $(wildcard Source/CombatExtended/*/*.cs) $(wildcard Source/CombatExtended/*/*/*.cs) $(PUBLICIZER)
Assemblies/CombatExtended.dll: Source/CombatExtended/CombatExtended.csproj $(wildcard Source/CombatExtended/*/*.cs) $(wildcard Source/CombatExtended/*/*/*.cs) $(PUBLICIZER)
python3 Make.py --csproj Source/CombatExtended/CombatExtended.csproj --output Assemblies/CombatExtended.dll --reference /tmp/rwreference --all-libs $(DOWNLOAD_LIBS) --publicizer $(PUBLICIZER)


Expand Down
10 changes: 2 additions & 8 deletions Source/BetterTurretsCompat/BetterTurretsCompat.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>..\..\AssembliesCompat\</OutputPath>
<OutputPath>..\..\ModPatches\BetterTurrets\Assemblies\</OutputPath>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<LangVersion>8.0</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>..\..\AssembliesCompat\</OutputPath>
<OutputPath>..\..\ModPatches\BetterTurrets\Assemblies\</OutputPath>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
Expand All @@ -34,12 +34,6 @@
<ItemGroup>
<Folder Include="BetterTurretsCompat" />
</ItemGroup>
<ItemGroup>
<Reference Include="0CombatExtendedLoader">
<HintPath>..\..\Assemblies\0CombatExtendedLoader.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CombatExtended\CombatExtended.csproj">
<Private>False</Private>
Expand Down
6 changes: 0 additions & 6 deletions Source/CombatExtended/CombatExtended.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,6 @@
<ItemGroup>
<None Include="CombatExtended\ThinkNodes\ThinkNode_ConditionalNoJob.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="0CombatExtendedLoader">
<HintPath>..\..\Assemblies\0CombatExtendedLoader.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Reference Include="Rimatomics">
<HintPath>..\packages\Rimatomics-reference.dll</HintPath>
Expand Down
87 changes: 72 additions & 15 deletions Source/CombatExtended/CombatExtended/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,95 @@
using RimWorld;
using Verse;
using UnityEngine;
using System.Reflection;
using System.IO;
using CombatExtended.HarmonyCE;
using CombatExtended.Compatibility;
using CombatExtended.Loader;

namespace CombatExtended
{
public class Controller : IModPart
/*
This class handles initializing the different components of CombatExtended. The LoadFolders
system is responsible for loading the assemblies, this gives an opportunity to run any
post-load sanity checking, and is responsible for rendering any sub-mod settings as required.
*/
public class Controller : Mod
{
public static List<ISettingsCE> settingList = new List<ISettingsCE>();
public static Settings settings;
public static Controller instant;
public static Controller instance;
public static ModContentPack content;
private static Patches patches;
private Vector2 scrollPosition;

public Type GetSettingsType()
public override void DoSettingsWindowContents(Rect inRect)
{
return typeof(Settings);
Rect inner = inRect.ContractedBy(20f);
inner.height = 800f;
inner.x += 10f;
Widgets.BeginScrollView(inRect, ref this.scrollPosition, inner, true);
Listing_Standard list = new Listing_Standard();
list.ColumnWidth = (inner.width - 17) / 2; // Subtract 17 for gap between columns
list.Begin(inner);

foreach (ISettingsCE settings in settingList)
{
settings.DoWindowContents(list);
}
list.End();
Widgets.EndScrollView();
}

public Controller()
public Controller(ModContentPack content) : base(content)
{
patches = new Patches();
Controller.instance = this;
Controller.content = content;
Controller.settings = GetSettings<Settings>();
settingList.Add(Controller.settings);
PostLoad();
}

public IEnumerable<string> GetCompatList()
{
return patches.GetCompatList();
}

public void PostLoad(ModContentPack content, ISettingsCE settings)
public void PostLoad()
{
Controller.instant = this;
Controller.content = content;
Controller.settings = (Settings)settings;

// Apply Harmony patches
HarmonyBase.InitPatches();

Queue<Assembly> toProcess = new Queue<Assembly>(content.assemblies.loadedAssemblies);
List<IModPart> modParts = new List<IModPart>();
while (toProcess.Any())
{
Assembly assembly = toProcess.Dequeue();

foreach (Type t in assembly.GetTypes().Where(x => typeof(IModPart).IsAssignableFrom(x) && !x.IsAbstract))
{
IModPart imp = ((IModPart)t.GetConstructor(new Type[] { }).Invoke(new object[] { }));
modParts.Add(imp);
}
}
foreach (IModPart modPart in modParts)
{
Log.Message("CE: Loading Mod Part");
Type settingsType = modPart.GetSettingsType();
ISettingsCE settings = null;
if (settingsType != null)
{
if (typeof(ModSettings).IsAssignableFrom(settingsType))
{
settings = (ISettingsCE)typeof(Controller).GetMethod(nameof(Controller.GetSettings)).MakeGenericMethod(settingsType).Invoke(instance, null);
}
else
{
settings = (ISettingsCE)settingsType.GetConstructor(new Type[] { }).Invoke(new object[] { });
}
settingList.Add(settings);
}

modPart.PostLoad(content, settings);

}

// Initialize loadout generator
LongEventHandler.QueueLongEvent(LoadoutPropertiesExtension.Reset, "CE_LongEvent_LoadoutProperties", false, null);

Expand All @@ -66,6 +118,11 @@ public void PostLoad(ModContentPack content, ISettingsCE settings)

}

public override string SettingsCategory()
{
return "Combat Extended";
}

private static void DoTutorialPopup()
{
var enableAction = new Action(() =>
Expand Down
7 changes: 0 additions & 7 deletions Source/CombatExtended/Compatibility/BetterTurrets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,5 @@ public void Install()
{
Log.Message("Combat Extended :: Installing Better Turrets");
}
public IEnumerable<string> GetCompatList()
{
yield return "BetterTurretsCompat";
}



}
}
5 changes: 0 additions & 5 deletions Source/CombatExtended/Compatibility/EDShields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ public void Install()
HitSoundDef = (SoundDef)t.GetField("HitSoundDef", BindingFlags.Static | BindingFlags.Public).GetValue(null);
}


public IEnumerable<string> GetCompatList()
{
yield break;
}
public static bool CheckForCollisionBetweenCallback(ProjectileCE projectile, Vector3 from, Vector3 to)
{
/* Check if an active shield can block this projectile
Expand Down
1 change: 0 additions & 1 deletion Source/CombatExtended/Compatibility/IPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ public interface IPatch
{
public bool CanInstall();
public void Install();
public IEnumerable<string> GetCompatList();
}
}
8 changes: 0 additions & 8 deletions Source/CombatExtended/Compatibility/MiscTurrets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,5 @@ public void Install()
{
Log.Message("Combat Extended :: Installing Misc Turrets");
}

public IEnumerable<string> GetCompatList()
{
yield return "MiscTurretsCompat";
}



}
}
5 changes: 0 additions & 5 deletions Source/CombatExtended/Compatibility/Multiplayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ public void Install()
isMultiplayerActive = true;
}

public IEnumerable<string> GetCompatList()
{
yield return "MultiplayerCompat";
}

public static bool InMultiplayer
{
get
Expand Down
14 changes: 0 additions & 14 deletions Source/CombatExtended/Compatibility/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,6 @@ public static IEnumerable<ThingDef> GetUsedAmmo()
}
}

public IEnumerable<string> GetCompatList()
{
foreach (IPatch patch in patches)
{
if (patch.CanInstall())
{
foreach (string s in patch.GetCompatList())
{
yield return s;
}
}
}
}

private static bool _gcbfactive = false;

public static void RegisterCollisionBodyFactorCallback(Func<Pawn, Tuple<bool, Vector2>> f)
Expand Down
5 changes: 0 additions & 5 deletions Source/CombatExtended/Compatibility/ProjectRimFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ public void Install()
{
Building_FuelingMachine.RegisterRefuelable(typeof(Building_TurretGunCE), FindCompAmmoUser, TestAmmo, ReloadAction);
}
public IEnumerable<string> GetCompatList()
{
yield break;
}

private static int TestAmmo(object compObject, Thing ammo)
{
var comp = compObject as CompAmmoUser;
Expand Down
5 changes: 0 additions & 5 deletions Source/CombatExtended/Compatibility/Rimatomics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ public void Install()
BlockerRegistry.RegisterShieldZonesCallback(Rimatomics.ShieldZonesCallback);
}

public IEnumerable<string> GetCompatList()
{
yield break;
}

public static bool CheckForCollisionBetweenCallback(ProjectileCE projectile, Vector3 from, Vector3 to)
{
Map map = projectile.Map;
Expand Down
Loading

0 comments on commit 3915b41

Please sign in to comment.