Skip to content

Commit

Permalink
Supports RimWorld 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike committed Feb 23, 2020
1 parent 12e1f15 commit 9d9b5c8
Show file tree
Hide file tree
Showing 21 changed files with 2,632 additions and 234 deletions.
6 changes: 5 additions & 1 deletion About/About.xml
Expand Up @@ -2,7 +2,11 @@
<ModMetaData>
<name>MOD-E</name>
<author>Andreas Pardeike</author>
<targetVersion>1.0.0</targetVersion>
<supportedVersions>
<li>1.0</li>
<li>1.1</li>
</supportedVersions>
<packageId>brrainz.mode</packageId>
<description>If your current mod list can satisfy a loading game, this mod will ask you to reconfigure your current mod list to match the loading game automatically. After a restart, you are good to go!

Installation: Put it at the TOP of the mod list. Above the Core mod.
Expand Down
2 changes: 1 addition & 1 deletion About/Manifest.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest>
<identifier>net.pardeike.rimworld.mod.mod-e</identifier>
<version>1.0.9.0</version>
<version>2.0.0.1</version>
<targetVersions>
<li>0.19.0</li>
<li>1.0.0</li>
Expand Down
2 changes: 1 addition & 1 deletion About/ModSync.xml
Expand Up @@ -2,7 +2,7 @@
<ModSyncNinjaData>
<ID>4e6082da-1178-4f64-a444-9a32aab3b4f1</ID>
<ModName>MOD-E</ModName>
<Version>1.0.9.0</Version>
<Version>2.0.0.1</Version>
<SaveBreaking>False</SaveBreaking>
<Host name="Github">
<Owner>pardeike</Owner>
Expand Down
Binary file modified About/Preview.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions LoadFolders.xml
@@ -0,0 +1,6 @@
<loadFolders>
<v1.1>
<li>/</li>
<li>v1.1</li>
</v1.1>
</loadFolders>
73 changes: 37 additions & 36 deletions Source/CrossPromotion.cs
@@ -1,4 +1,4 @@
using Harmony;
using HarmonyLib;
using RimWorld;
using Steamworks;
using System;
Expand All @@ -12,7 +12,7 @@
using Verse;
using Verse.Steam;

namespace CameraPlus
namespace CrossPromotionModule
{
[StaticConstructorOnStartup]
static class CrossPromotion
Expand All @@ -28,34 +28,35 @@ static class CrossPromotion

static CrossPromotion()
{
var instance = HarmonyInstance.Create(_crosspromotion);
if (instance.HasAnyPatches(_crosspromotion))
if (Harmony.HasAnyPatches(_crosspromotion))
return;

instance.Patch(
SymbolExtensions.GetMethodInfo(() => MainMenuDrawer.Init()),
postfix: new HarmonyMethod(SymbolExtensions.GetMethodInfo(() => MainMenuDrawer_Init_Postfix()))
var instance = new Harmony(_crosspromotion);

_ = instance.Patch(
SymbolExtensions.GetMethodInfo(() => ModLister.RebuildModList()),
postfix: new HarmonyMethod(SymbolExtensions.GetMethodInfo(() => ModLister_RebuildModList_Postfix()))
);

instance.Patch(
_ = instance.Patch(
AccessTools.DeclaredMethod(typeof(Page_ModsConfig), nameof(Page_ModsConfig.PostClose)),
postfix: new HarmonyMethod(SymbolExtensions.GetMethodInfo(() => Page_ModsConfig_PostClose_Postfix()))
);

instance.Patch(
_ = instance.Patch(
AccessTools.DeclaredMethod(typeof(WorkshopItems), "Notify_Subscribed"),
postfix: new HarmonyMethod(SymbolExtensions.GetMethodInfo(() => WorkshopItems_Notify_Subscribed_Postfix(new PublishedFileId_t(0))))
);

instance.Patch(
_ = instance.Patch(
AccessTools.DeclaredMethod(typeof(Page_ModsConfig), nameof(Page_ModsConfig.DoWindowContents)),
transpiler: new HarmonyMethod(SymbolExtensions.GetMethodInfo(() => Page_ModsConfig_DoWindowContents_Transpiler(null, null)))
);
}

static void MainMenuDrawer_Init_Postfix()
static void ModLister_RebuildModList_Postfix()
{
ModPreviewPath(0);
_ = ModPreviewPath(0);
new Thread(() => { FetchPromotionMods(); }).Start();
}

Expand All @@ -69,7 +70,7 @@ static void WorkshopItems_Notify_Subscribed_Postfix(PublishedFileId_t pfid)
var longID = pfid.m_PublishedFileId;
if (subscribingMods.Contains(longID) == false)
return;
subscribingMods.Remove(longID);
_ = subscribingMods.Remove(longID);

LongEventHandler.ExecuteWhenFinished(() =>
{
Expand All @@ -92,11 +93,11 @@ static IEnumerable<CodeInstruction> Page_ModsConfig_DoWindowContents_Transpiler(
var list = instructions.ToList();
var beginGroupIndicies = list
.Select((instr, idx) => new Pair<int, CodeInstruction>(idx, instr))
.Where(pair => pair.Second.operand == m_BeginGroup)
.Where(pair => pair.Second.operand is MethodInfo mi && mi == m_BeginGroup)
.Select(pair => pair.First).ToArray();
var endGroupIndicies = list
.Select((instr, idx) => new Pair<int, CodeInstruction>(idx, instr))
.Where(pair => pair.Second.operand == m_EndGroup)
.Where(pair => pair.Second.operand is MethodInfo mi && mi == m_EndGroup)
.Select(pair => pair.First).ToArray();
if (beginGroupIndicies.Length != 2 || endGroupIndicies.Length != 2)
return instructions;
Expand All @@ -121,7 +122,7 @@ internal static string ModPreviewPath(ulong modID)
{
var dir = Path.GetTempPath() + "BrrainzMods" + Path.DirectorySeparatorChar;
if (Directory.Exists(dir) == false)
Directory.CreateDirectory(dir);
_ = Directory.CreateDirectory(dir);
return dir + modID + "-preview.jpg";
}

Expand Down Expand Up @@ -151,7 +152,7 @@ static void AsyncUserModsQuery(UGCQueryHandle_t query, Action<SteamUGCQueryCompl
var callDelegate = new CallResult<SteamUGCQueryCompleted_t>.APIDispatchDelegate((result, failure) =>
{
callback(result, failure);
SteamUGC.ReleaseQueryUGCRequest(query);
_ = SteamUGC.ReleaseQueryUGCRequest(query);
});
var call = SteamUGC.SendQueryUGCRequest(query);
var resultHandle = CallResult<SteamUGCQueryCompleted_t>.Create(callDelegate);
Expand All @@ -166,7 +167,7 @@ static void AsyncDownloadQuery(UGCHandle_t content, string path, Action<RemoteSt
resultHandle.Set(call, null);
}

internal static void FetchPromotionMods()
public static void FetchPromotionMods()
{
if (SteamManager.Initialized == false)
return;
Expand All @@ -179,8 +180,8 @@ internal static void FetchPromotionMods()
EUserUGCList.k_EUserUGCList_Published, EUGCMatchingUGCType.k_EUGCMatchingUGCType_UsableInGame,
EUserUGCListSortOrder.k_EUserUGCListSortOrder_VoteScoreDesc, rimworldID, rimworldID,
1);
SteamUGC.SetReturnLongDescription(itemQuery, true);
SteamUGC.SetRankedByTrendDays(itemQuery, 7);
_ = SteamUGC.SetReturnLongDescription(itemQuery, true);
_ = SteamUGC.SetRankedByTrendDays(itemQuery, 7);
AsyncUserModsQuery(itemQuery, (result, failure) =>
{
for (uint i = 0; i < result.m_unNumResultsReturned; i++)
Expand All @@ -198,7 +199,7 @@ internal static void FetchPromotionMods()
if (File.Exists(path))
{
if (previewTextures.ContainsKey(modID))
previewTextures.Remove(modID);
_ = previewTextures.Remove(modID);
}
});
}
Expand Down Expand Up @@ -249,7 +250,7 @@ static void ContentPart(Rect mainRect, float leftColumn, ModMetaData mod, Page_M
var mainModID = mod.GetPublishedFileId().m_PublishedFileId;
var promoMods = CrossPromotion.promotionMods.ToArray();
var thisMod = promoMods.FirstOrDefault(m => m.m_nPublishedFileId.m_PublishedFileId == mainModID);
var isLocalFile = ModLister.AllInstalledMods.Any(meta => meta.GetPublishedFileId().m_PublishedFileId == mainModID && meta.Source == ContentSource.LocalFolder);
var isLocalFile = ModLister.AllInstalledMods.Any(meta => meta.GetPublishedFileId().m_PublishedFileId == mainModID && meta.Source == ContentSource.ModsFolder);
var isSubbed = workshopMods.Contains(mainModID);

if (CrossPromotion.lastPresentedMod != mainModID)
Expand All @@ -274,11 +275,11 @@ static void ContentPart(Rect mainRect, float leftColumn, ModMetaData mod, Page_M

var outRect = new Rect(0f, 0f, leftColumn, mainRect.height);
var width = outRect.width - 20f;
var imageRect = new Rect(0f, 0f, width, width * mod.previewImage.height / mod.previewImage.width);
var imageRect = new Rect(0f, 0f, width, width * mod.PreviewImage.height / mod.PreviewImage.width);
var textRect = new Rect(0f, 24f + 10f + imageRect.height, width, Text.CalcHeight(description, width));
var innerRect = new Rect(0f, 0f, width, imageRect.height + 20f + 8f + 10f + textRect.height);
Widgets.BeginScrollView(outRect, ref leftScroll, innerRect, true);
GUI.DrawTexture(imageRect, mod.previewImage, ScaleMode.ScaleToFit);
GUI.DrawTexture(imageRect, mod.PreviewImage, ScaleMode.ScaleToFit);
var widgetRow = new WidgetRow(imageRect.xMax, imageRect.yMax + 8f, UIDirection.LeftThenDown, width, 8f);
if (isLocalFile == false)
{
Expand All @@ -289,8 +290,8 @@ static void ContentPart(Rect mainRect, float leftColumn, ModMetaData mod, Page_M
mod.enabled = false;
new Thread(() =>
{
AccessTools.Method(typeof(Workshop), "Unsubscribe").Invoke(null, new object[] { mod });
AccessTools.Method(typeof(Page_ModsConfig), "Notify_SteamItemUnsubscribed").Invoke(page, new object[] { mainModID });
_ = AccessTools.Method(typeof(Workshop), "Unsubscribe").Invoke(null, new object[] { mod });
_ = AccessTools.Method(typeof(Page_ModsConfig), "Notify_SteamItemUnsubscribed").Invoke(page, new object[] { mainModID });
}).Start();
}, true, null));
}
Expand All @@ -306,7 +307,7 @@ static void ContentPart(Rect mainRect, float leftColumn, ModMetaData mod, Page_M
if (widgetRow.ButtonText("Upload", null, true, true))
Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmSteamWorkshopUpload".Translate(), delegate
{
AccessTools.Method(typeof(Workshop), "Upload").Invoke(null, new object[] { mod });
_ = AccessTools.Method(typeof(Workshop), "Upload").Invoke(null, new object[] { mod });
}, true, null));
}

Expand Down Expand Up @@ -336,9 +337,9 @@ static void PromotionPart(Rect mainRect, float leftColumn, float rightColumn, Mo
foreach (var promoMod in promoMods)
{
var myModID = promoMod.m_nPublishedFileId.m_PublishedFileId;
var isLocalFile = ModLister.AllInstalledMods.Any(meta => meta.GetPublishedFileId().m_PublishedFileId == myModID && meta.Source == ContentSource.LocalFolder);
var isLocalFile = ModLister.AllInstalledMods.Any(meta => meta.GetPublishedFileId().m_PublishedFileId == myModID && meta.Source == ContentSource.ModsFolder);
var isSubbed = workshopMods.Contains(myModID);
CrossPromotion.allVoteStati.TryGetValue(myModID, out var voteStatus);
_ = CrossPromotion.allVoteStati.TryGetValue(myModID, out var voteStatus);

if (height > 0)
height += 10f;
Expand All @@ -357,10 +358,10 @@ static void PromotionPart(Rect mainRect, float leftColumn, float rightColumn, Mo
foreach (var promoMod in promoMods)
{
var myModID = promoMod.m_nPublishedFileId.m_PublishedFileId;
var isLocalFile = ModLister.AllInstalledMods.Any(meta => meta.GetPublishedFileId().m_PublishedFileId == myModID && meta.Source == ContentSource.LocalFolder);
var isLocalFile = ModLister.AllInstalledMods.Any(meta => meta.GetPublishedFileId().m_PublishedFileId == myModID && meta.Source == ContentSource.ModsFolder);
var isSubbed = workshopMods.Contains(myModID);
var isActive = activeMods.Contains(myModID);
CrossPromotion.allVoteStati.TryGetValue(myModID, out var voteStatus);
_ = CrossPromotion.allVoteStati.TryGetValue(myModID, out var voteStatus);

if (firstTime == false)
modRect.y += 10f;
Expand Down Expand Up @@ -400,17 +401,17 @@ void actionButtonAction()
{
if (isSubbed || isLocalFile)
{
var orderedMods = (IEnumerable<ModMetaData>)AccessTools.Method(typeof(Page_ModsConfig), "ModsInListOrder").Invoke(page, new object[0]);
var orderedMods = (IEnumerable<ModMetaData>)AccessTools.Method(typeof(Page_ModsConfig), "ModsInListOrder").Invoke(page, Array.Empty<object>());
page.selectedMod = orderedMods.FirstOrDefault(meta => meta.GetPublishedFileId().m_PublishedFileId == myModID);
var modsBefore = orderedMods.FirstIndexOf(m => m == page.selectedMod);
if (modsBefore >= 0)
Traverse.Create(page).Field("modListScrollPosition").SetValue(new Vector2(0f, modsBefore * 26f + 4f));
_ = Traverse.Create(page).Field("modListScrollPosition").SetValue(new Vector2(0f, modsBefore * 26f + 4f));
}
else
new Thread(() =>
{
CrossPromotion.subscribingMods.Add(myModID);
SteamUGC.SubscribeItem(new PublishedFileId_t(myModID));
_ = SteamUGC.SubscribeItem(new PublishedFileId_t(myModID));
}).Start();
}
var infoWindow = new Dialog_MessageBox(description, "Close".Translate(), null, actionButton, actionButtonAction, null, false, null, null);
Expand All @@ -431,7 +432,7 @@ void actionButtonAction()
new Thread(() =>
{
CrossPromotion.subscribingMods.Add(myModID);
SteamUGC.SubscribeItem(new PublishedFileId_t(myModID));
_ = SteamUGC.SubscribeItem(new PublishedFileId_t(myModID));
}).Start();
}
else if (voteStatus != null && voteStatus == false)
Expand All @@ -442,7 +443,7 @@ void actionButtonAction()
new Thread(() =>
{
CrossPromotion.allVoteStati[myModID] = true;
SteamUGC.SetUserItemVote(new PublishedFileId_t(myModID), true);
_ = SteamUGC.SetUserItemVote(new PublishedFileId_t(myModID), true);
}).Start();
}
}
Expand Down
6 changes: 6 additions & 0 deletions Source/GlobalSuppressions.cs
@@ -0,0 +1,6 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "<Pending>", Scope = "member", Target = "~M:ModCounter.Trigger")]

0 comments on commit 9d9b5c8

Please sign in to comment.