-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<ModMetaData> | ||
<name>BetterLoading</name> | ||
<author>Samboy063</author> | ||
<url></url> | ||
<targetVersion>1.0</targetVersion> | ||
<description>An enhanced loading screen.</description> | ||
|
||
</ModMetaData> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Boolean x:Key="/Default/CodeStyle/Naming/CSharpAutoNaming/IsNotificationDisabled/@EntryValue">True</s:Boolean> | ||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/AutoDetectedNamingRules/=TypesAndNamespaces/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></s:String> | ||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/AutoDetectedNamingRules/=PublicFields/@EntryIndexedValue"><Policy Inspect="True" Prefix="num" Suffix="" Style="AaBb"><ExtraRule Prefix="" Suffix="" Style="aaBb" /></Policy></s:String> | ||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/AutoDetectedNamingRules/=Parameters/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></s:String> | ||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/AutoDetectedNamingRules/=EnumMember/@EntryIndexedValue"><Policy Inspect="False" Prefix="" Suffix="" Style="AaBb" /></s:String> | ||
<s:Boolean x:Key="/Default/CodeStyle/Naming/CSharpNaming/ApplyAutoDetectedRules/@EntryValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/CodeStyle/Naming/CSharpAutoNaming/IsNamingAutoDetectionCompleted/@EntryValue">True</s:Boolean></wpf:ResourceDictionary> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{E08CFC22-1BA8-41FE-A60B-491C308B8B65}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>DebugUtil</RootNamespace> | ||
<AssemblyName>BetterLoading</AssemblyName> | ||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>..\Assemblies\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>..\Assemblies</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="0Harmony, Version=1.2.0.1, Culture=neutral, PublicKeyToken=null"> | ||
<HintPath>Deps\0Harmony.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Assembly-CSharp, Version=1.0.6955.24033, Culture=neutral, PublicKeyToken=null"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\Assembly-CSharp.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\UnityEngine.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="BetterLoadingMain.cs" /> | ||
<Compile Include="LoadingScreenManager.cs" /> | ||
<Compile Include="LoadingStage.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Xml; | ||
using Harmony; | ||
using JetBrains.Annotations; | ||
using RimWorld; | ||
using UnityEngine; | ||
using Verse; | ||
|
||
namespace BetterLoading | ||
{ | ||
public class BetterLoadingMain : Mod | ||
{ | ||
public static LoadingScreenManager Manager; | ||
|
||
public BetterLoadingMain(ModContentPack content) : base(content) | ||
{ | ||
Manager = Camera.main.gameObject.AddComponent<LoadingScreenManager>(); | ||
var inst = HarmonyInstance.Create("me.samboycoding.blm"); | ||
inst.PatchAll(Assembly.GetExecutingAssembly()); | ||
} | ||
|
||
[HarmonyPatch(typeof(LoadedModManager))] | ||
[HarmonyPatch(nameof(LoadedModManager.LoadModXML))] | ||
[UsedImplicitly] | ||
public class LoadModXmlPatch | ||
{ | ||
[UsedImplicitly] | ||
public static void Prefix() | ||
{ | ||
Log.Message("Loading Screen Manager :: Read XML Files :: Start"); | ||
Manager.currentStage = LoadingStage.ReadXMLFiles; | ||
Manager.totalLoadedContentPacks = LoadedModManager.RunningMods.Count(); | ||
Manager.numContentPacksLoaded = 0; | ||
} | ||
} | ||
|
||
[HarmonyPatch(typeof(ModContentPack))] | ||
[HarmonyPatch(nameof(ModContentPack.LoadDefs))] | ||
[UsedImplicitly] | ||
public class LoadDefsPatch | ||
{ | ||
[UsedImplicitly] | ||
public static void Prefix(ModContentPack __instance) | ||
{ | ||
Manager.numContentPacksLoaded += 1; | ||
Manager.currentlyLoadingDefsFrom = __instance; | ||
} | ||
} | ||
|
||
[HarmonyPatch(typeof(LoadedModManager))] | ||
[HarmonyPatch(nameof(LoadedModManager.CombineIntoUnifiedXML))] | ||
[UsedImplicitly] | ||
public class CombineXmlPatch | ||
{ | ||
[UsedImplicitly] | ||
public static void Prefix() | ||
{ | ||
Log.Message("Loading Screen Manager :: Unify XML Tree :: Start"); | ||
Manager.currentStage = LoadingStage.UnifyXML; | ||
} | ||
} | ||
|
||
[HarmonyPatch(typeof(LoadedModManager))] | ||
[HarmonyPatch(nameof(LoadedModManager.ApplyPatches))] | ||
[UsedImplicitly] | ||
public class ApplyPatchesPatch | ||
{ | ||
[UsedImplicitly] | ||
public static void Prefix() | ||
{ | ||
Log.Message("Loading Screen Manager :: Apply XML Patches :: Start"); | ||
Manager.numPatchesToLoad = LoadedModManager.RunningMods.Count(); | ||
Manager.currentStage = LoadingStage.ApplyPatches; | ||
} | ||
} | ||
|
||
[HarmonyPatch(typeof(ModContentPack))] | ||
[HarmonyPatch("LoadPatches")] | ||
[UsedImplicitly] | ||
public class GetPatchesPatch | ||
{ | ||
[UsedImplicitly] | ||
public static void Prefix(ModContentPack __instance) | ||
{ | ||
Manager.currentlyPatching = __instance; | ||
Manager.numPatchesLoaded++; | ||
} | ||
} | ||
|
||
[HarmonyPatch(typeof(LoadedModManager))] | ||
[HarmonyPatch(nameof(LoadedModManager.ParseAndProcessXML))] | ||
[UsedImplicitly] | ||
public class PAndPXmlPatch | ||
{ | ||
[UsedImplicitly] | ||
public static void Prefix(XmlDocument xmlDoc) | ||
{ | ||
Log.Message("Loading Screen Manager :: Pre-Parse XML Tree :: Start"); | ||
Manager.numDefsToProcess = xmlDoc.DocumentElement.ChildNodes.Count; | ||
|
||
Manager.numDefsToPreProcess = 0; | ||
var enumerator = xmlDoc.DocumentElement.ChildNodes.GetEnumerator(); | ||
while (enumerator.MoveNext()) | ||
{ | ||
if (((XmlNode) enumerator.Current).NodeType == XmlNodeType.Element) Manager.numDefsToPreProcess++; | ||
} | ||
|
||
Manager.currentStage = LoadingStage.ParseProcessXMLStage1; | ||
} | ||
} | ||
|
||
[HarmonyPatch(typeof(XmlInheritance))] | ||
[HarmonyPatch(nameof(XmlInheritance.TryRegister))] | ||
[UsedImplicitly] | ||
public class TryRegisterInheritancePatch | ||
{ | ||
[UsedImplicitly] | ||
public static void Prefix() | ||
{ | ||
if (Manager.currentStage == LoadingStage.ParseProcessXMLStage1) | ||
Manager.numDefsPreProcessed++; | ||
} | ||
} | ||
|
||
[HarmonyPatch(typeof(XmlInheritance))] | ||
[HarmonyPatch(nameof(XmlInheritance.Resolve))] | ||
[UsedImplicitly] | ||
public class ResolveInheritancePatch | ||
{ | ||
[UsedImplicitly] | ||
public static void Prefix() | ||
{ | ||
if (Manager.currentStage == LoadingStage.ParseProcessXMLStage1) | ||
{ | ||
Log.Message("Loading Screen Manager :: Process XML Tree :: Start"); | ||
Manager.currentStage = LoadingStage.ParseProcessXMLStage2; | ||
} | ||
} | ||
} | ||
|
||
[HarmonyPatch(typeof(DirectXmlLoader))] | ||
[HarmonyPatch(nameof(DirectXmlLoader.DefFromNode))] | ||
[UsedImplicitly] | ||
public class DefFromNodePatch | ||
{ | ||
[UsedImplicitly] | ||
public static void Prefix() | ||
{ | ||
Manager.numDefsProcessed++; | ||
} | ||
} | ||
|
||
[HarmonyPatch(typeof(GenGeneric))] | ||
[HarmonyPatch("MethodOnGenericType")] | ||
[HarmonyPatch(new[] {typeof(Type), typeof(Type), typeof(string)})] | ||
[UsedImplicitly] | ||
public class DefDatabaseReferencesPatch | ||
{ | ||
[UsedImplicitly] | ||
public static void Prefix(Type genericParam, string methodName) | ||
{ | ||
if ((Manager.currentStage == LoadingStage.ParseProcessXMLStage2 || | ||
Manager.currentStage == LoadingStage.ResolveReferences) | ||
&& genericParam.IsSubclassOf(typeof(Def)) | ||
&& methodName == "ResolveAllReferences") | ||
{ | ||
Manager.currentDatabaseResolving = genericParam; | ||
Manager.numDatabasesReloaded++; | ||
|
||
if (Manager.currentStage != LoadingStage.ResolveReferences) | ||
{ | ||
Log.Message("Loading Screen Manager :: Resolve References :: Start"); | ||
Manager.numDefDatabases = typeof(Def).AllSubclasses().Count() - 1; //-1 because Def subclasses Def. Or something. | ||
Manager.currentStage = LoadingStage.ResolveReferences; | ||
} | ||
} | ||
} | ||
} | ||
|
||
[HarmonyPatch(typeof(StaticConstructorOnStartupUtility))] | ||
[HarmonyPatch(nameof(StaticConstructorOnStartupUtility.CallAll))] | ||
[UsedImplicitly] | ||
public class FinishUpPatch | ||
{ | ||
[UsedImplicitly] | ||
public static void Prefix() | ||
{ | ||
Log.Message("Loading Screen Manager :: Call Static CCtors :: Start"); | ||
Manager.currentStage = LoadingStage.FinishUp; | ||
Manager.numStaticConstructorsToCall = | ||
GenTypes.AllTypesWithAttribute<StaticConstructorOnStartup>().Count(); | ||
} | ||
} | ||
|
||
[HarmonyPatch(typeof(RuntimeHelpers))] | ||
[HarmonyPatch(nameof(RuntimeHelpers.RunClassConstructor))] | ||
[HarmonyPatch(new [] {typeof(RuntimeTypeHandle)})] | ||
[UsedImplicitly] | ||
public class RunClassConstructorPatch | ||
{ | ||
[UsedImplicitly] | ||
public static void Prefix(RuntimeTypeHandle type) | ||
{ | ||
//This patch is really sketchy as it's more than possible that this could be called in a million and one places. | ||
//Need to safeguard as much as is humanly possible. | ||
if (Manager.currentStage != LoadingStage.FinishUp) return; | ||
var typeImpl = Type.GetTypeFromHandle(type); | ||
if(typeImpl.TryGetAttribute(out StaticConstructorOnStartup attrib)) | ||
{ | ||
//We are calling the constructor of a StaticConstructorOnStartup-Annotated class. In theory. | ||
Manager.currentStaticConstructor = typeImpl; | ||
Manager.numStaticConstructorsCalled++; | ||
} | ||
} | ||
} | ||
} | ||
} |