Skip to content

Commit

Permalink
Merge pull request #25 from pardeike/1.3
Browse files Browse the repository at this point in the history
1.3
  • Loading branch information
pardeike authored Jul 5, 2021
2 parents b7901e2 + 9c21299 commit 618942f
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 116 deletions.
Binary file added 1.3/Assemblies/0MultiplayerAPI.dll
Binary file not shown.
Binary file added 1.3/Assemblies/AchtungMod.dll
Binary file not shown.
1 change: 1 addition & 0 deletions About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<li>1.0</li>
<li>1.1</li>
<li>1.2</li>
<li>1.3</li>
</supportedVersions>
<modDependencies>
<li>
Expand Down
3 changes: 2 additions & 1 deletion About/Manifest.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest>
<identifier>net.pardeike.rimworld.mod.achtung</identifier>
<version>3.1.7.0</version>
<version>3.2.0.0</version>
<targetVersions>
<li>1.0.0</li>
<li>1.1.0</li>
<li>1.2.0</li>
<li>1.3.0</li>
</targetVersions>
<dependencies>
</dependencies>
Expand Down
4 changes: 4 additions & 0 deletions LoadFolders.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
<li>/</li>
<li>1.2</li>
</v1.2>
<v1.3>
<li>/</li>
<li>1.3</li>
</v1.3>
</loadFolders>
12 changes: 6 additions & 6 deletions Source/Achtung.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<TargetFramework>net472</TargetFramework>
<LangVersion>8.0</LangVersion>
<PlatformTarget>x64</PlatformTarget>
<OutputPath>..\1.2\Assemblies\</OutputPath>
<OutputPath>..\1.3\Assemblies\</OutputPath>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<Version>3.1.7.0</Version>
<Version>3.2.0.0</Version>
<Copyright>© July, 2016</Copyright>
</PropertyGroup>

Expand All @@ -23,15 +23,15 @@

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<DefineConstants>RW12;TRACE;DEBUG</DefineConstants>
<DefineConstants>RW12;RW13;TRACE;DEBUG</DefineConstants>
<Optimize>false</Optimize>
<DebugType>portable</DebugType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Krafs.Rimworld.Ref" Version="1.2.2905" GeneratePathProperty="true" />
<PackageReference Include="Lib.Harmony" Version="2.0.4" ExcludeAssets="runtime" />
<PackageReference Include="Krafs.Rimworld.Ref" Version="1.3.0" GeneratePathProperty="true" />
<PackageReference Include="Lib.Harmony" Version="2.1.0" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.NETCore.Platforms" Version="5.0.2" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net472" Version="1.0.2">
<PrivateAssets>all</PrivateAssets>
Expand Down Expand Up @@ -75,7 +75,7 @@ if not errorlevel 1 (
ModBuilder XMLPut -file "$(SolutionDir)About\Manifest.xml" -xpath /Manifest/version -value "{{$(MSBuildProjectName)-version}}"
)
if defined INSTALL_MOD (
"%INSTALL_MOD%" "$(Configuration)" "$(SolutionDir)" "$(MSBuildProjectName)" "1.1 1.2 About Assemblies Languages Textures" "LoadFolders.xml"
"%INSTALL_MOD%" "$(Configuration)" "$(SolutionDir)" "$(MSBuildProjectName)" "1.1 1.2 1.3 About Assemblies Languages Textures" "LoadFolders.xml"
)
</PostBuildEvent>
<Company>Brrainz</Company>
Expand Down
4 changes: 2 additions & 2 deletions Source/Colonist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public IntVec3 UpdateOrderPos(Vector3 pos)

if (AchtungLoader.IsSameSpotInstalled)
{
if (cell.Standable(pawn.Map) && pawn.CanReach(cell, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn))
if (cell.Standable(pawn.Map) && ReachabilityUtility.CanReach(pawn, cell, PathEndMode.OnCell, Danger.Deadly))
{
designation = cell.ToVector3Shifted();
designation.y = Altitudes.AltitudeFor(AltitudeLayer.Pawn);
Expand Down Expand Up @@ -58,4 +58,4 @@ public void OrderTo(Vector3 pos)
}
}
}
}
}
108 changes: 59 additions & 49 deletions Source/CrossPromotion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ static void Page_ModsConfig_PostClose_Postfix()
static void WorkshopItems_Notify_Subscribed_Postfix(PublishedFileId_t pfid)
{
var longID = pfid.m_PublishedFileId;

if (subscribingMods.Contains(longID) == false)
return;
_ = subscribingMods.Remove(longID);
Expand All @@ -80,6 +81,7 @@ static void WorkshopItems_Notify_Subscribed_Postfix(PublishedFileId_t pfid)

ModsConfig.SetActive(mod, true);
ModsConfig.Save();

Find.WindowStack.Add(new MiniDialog(mod.Name + " added"));
});
}
Expand All @@ -91,16 +93,20 @@ static void WorkshopItems_Notify_Subscribed_Postfix(PublishedFileId_t pfid)
static IEnumerable<CodeInstruction> Page_ModsConfig_DoWindowContents_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
var list = instructions.ToList();

var beginGroupIndicies = list
.Select((instr, idx) => new Pair<int, CodeInstruction>(idx, instr))
.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 is MethodInfo mi && mi == m_EndGroup)
.Select(pair => pair.First).ToArray();

if (beginGroupIndicies.Length != 2 || endGroupIndicies.Length != 2)
return instructions;

var iBegin = beginGroupIndicies[1] - 1;
var iEnd = endGroupIndicies[0];

Expand All @@ -121,8 +127,7 @@ static IEnumerable<CodeInstruction> Page_ModsConfig_DoWindowContents_Transpiler(
internal static string ModPreviewPath(ulong modID)
{
var dir = Path.GetTempPath() + "BrrainzMods" + Path.DirectorySeparatorChar;
if (Directory.Exists(dir) == false)
_ = Directory.CreateDirectory(dir);
if (Directory.Exists(dir) == false) _ = Directory.CreateDirectory(dir);
return dir + modID + "-preview.jpg";
}

Expand All @@ -146,12 +151,15 @@ internal static Texture2D PreviewForMod(ulong modID)
{
if (previewTextures.TryGetValue(modID, out var texture))
return texture;

var path = ModPreviewPath(modID);
if (File.Exists(path) == false)
return null;

texture = new Texture2D(1, 1, TextureFormat.ARGB32, false);
if (texture.LoadImage(SafeRead(path)))
previewTextures[modID] = texture;

return texture;
}

Expand Down Expand Up @@ -189,66 +197,65 @@ public static void FetchPromotionMods()
return;

var rimworldID = SteamUtils.GetAppID();
unchecked
{
var aID = new AccountID_t((uint)userID);
var itemQuery = SteamUGC.CreateQueryUserUGCRequest(aID,
var aID = new AccountID_t(unchecked((uint)userID));

var itemQuery = SteamUGC.CreateQueryUserUGCRequest(aID,
EUserUGCList.k_EUserUGCList_Published, EUGCMatchingUGCType.k_EUGCMatchingUGCType_UsableInGame,
EUserUGCListSortOrder.k_EUserUGCListSortOrder_VoteScoreDesc, rimworldID, rimworldID,
1);
_ = SteamUGC.SetReturnLongDescription(itemQuery, true);
_ = SteamUGC.SetRankedByTrendDays(itemQuery, 7);
AsyncUserModsQuery(itemQuery, (result, failure) =>
{
for (uint i = 0; i < result.m_unNumResultsReturned; i++)
if (SteamUGC.GetQueryUGCResult(result.m_handle, i, out var mod))
if (promotionMods.Any(m => m.m_nPublishedFileId.m_PublishedFileId == mod.m_nPublishedFileId.m_PublishedFileId) == false)
{
promotionMods.Add(mod);
var modID = mod.m_nPublishedFileId.m_PublishedFileId;
EUserUGCListSortOrder.k_EUserUGCListSortOrder_VoteScoreDesc, rimworldID, rimworldID, 1);

var path = ModPreviewPath(modID);
if (File.Exists(path) == false || new FileInfo(path).Length != mod.m_nPreviewFileSize)
{
AsyncDownloadQuery(mod.m_hPreviewFile, path, (result2, failure2) =>
{
if (File.Exists(path))
{
if (previewTextures.ContainsKey(modID))
_ = previewTextures.Remove(modID);
}
});
}
_ = SteamUGC.SetReturnLongDescription(itemQuery, true);
_ = SteamUGC.SetRankedByTrendDays(itemQuery, 7);

UpdateVotingStatus(modID, (result2, failure2) =>
AsyncUserModsQuery(itemQuery, (result, failure) =>
{
for (var i = (uint)0; i < result.m_unNumResultsReturned; i++)
if (SteamUGC.GetQueryUGCResult(result.m_handle, i, out var mod))
if (promotionMods.Any(m => m.m_nPublishedFileId.m_PublishedFileId == mod.m_nPublishedFileId.m_PublishedFileId) == false)
{
promotionMods.Add(mod);
var modID = mod.m_nPublishedFileId.m_PublishedFileId;

var path = ModPreviewPath(modID);
if (File.Exists(path) == false || new FileInfo(path).Length != mod.m_nPreviewFileSize)
{
AsyncDownloadQuery(mod.m_hPreviewFile, path, (result2, failure2) =>
{
allVoteStati[modID] = (result2.m_eResult == EResult.k_EResultOK) ? result2.m_bVotedUp : (bool?)null;
if (File.Exists(path))
{
if (previewTextures.ContainsKey(modID))
_ = previewTextures.Remove(modID);
}
});
}
});
}

UpdateVotingStatus(modID, (result2, failure2) =>
{
allVoteStati[modID] = (result2.m_eResult == EResult.k_EResultOK) ? result2.m_bVotedUp : (bool?)null;
});
}
});
}
}

[StaticConstructorOnStartup]
internal class PromotionLayout
{
static readonly AccessTools.FieldRef<WorkshopItemHook, CSteamID> ref_steamAuthor = AccessTools.FieldRefAccess<WorkshopItemHook, CSteamID>("steamAuthor");
internal static bool Promotion(Rect mainRect, Page_ModsConfig page)
{
if (SteamManager.Initialized == false)
return false;

var mod = page.selectedMod;
if (mod == null
|| ref_steamAuthor(mod.GetWorkshopItemHook()).m_SteamID != CrossPromotion.userID
|| mod.GetWorkshopItemHook().steamAuthor.m_SteamID != CrossPromotion.userID
|| CrossPromotion.promotionMods.Count == 0)
return false;

var leftColumn = mainRect.width * 2 / 3;
var rightColumn = mainRect.width - leftColumn - 10f;

GUI.BeginGroup(mainRect);

try
{
ContentPart(mainRect, leftColumn, mod, page);
Expand All @@ -259,6 +266,7 @@ internal static bool Promotion(Rect mainRect, Page_ModsConfig page)
GUI.EndGroup();
return false;
}

GUI.EndGroup();
return true;
}
Expand Down Expand Up @@ -289,7 +297,8 @@ static void ContentPart(Rect mainRect, float leftColumn, ModMetaData mod, Page_M
{
CrossPromotion.allVoteStati[promoMod.m_nPublishedFileId.m_PublishedFileId] = (result2.m_eResult == EResult.k_EResultOK) ? result2.m_bVotedUp : (bool?)null;
});
}).Start();
})
.Start();
}

var description = thisMod.m_rgchDescription;
Expand All @@ -301,21 +310,23 @@ static void ContentPart(Rect mainRect, float leftColumn, ModMetaData mod, Page_M
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);
var widgetRow = new WidgetRow(imageRect.xMax, imageRect.yMax + 8f, UIDirection.LeftThenDown, width, 8f);
if (isLocalFile == false)
{
if (widgetRow.ButtonText("Unsubscribe".Translate(), null, true, true))
{
Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmUnsubscribe".Translate(mod.Name), delegate
Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmUnsubscribe".Translate(mod.Name), () =>
{
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 });
}).Start();
Workshop.Unsubscribe(mod);
page.Notify_SteamItemUnsubscribed(new PublishedFileId_t(mainModID));
})
.Start();
}, true, null));
}
}
Expand All @@ -328,10 +339,7 @@ static void ContentPart(Rect mainRect, float leftColumn, ModMetaData mod, Page_M
{
widgetRow = new WidgetRow(imageRect.xMin, imageRect.yMax + 8f, UIDirection.RightThenDown, width, 8f);
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 });
}, true, null));
Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmSteamWorkshopUpload".Translate(), () => Workshop.Upload(mod), true, null));
}

Widgets.Label(textRect, description);
Expand All @@ -346,7 +354,7 @@ static void PromotionPart(Rect mainRect, float leftColumn, float rightColumn, Mo
var headerHeight = 30f;
var headerRect = new Rect(leftColumn + 10f, -4f, rightColumn - 20f, headerHeight);
Text.Anchor = TextAnchor.UpperCenter;
Widgets.Label(headerRect, "Mods of " + mod.Author.Replace("Andreas Pardeike", "Brrainz") + ":".Truncate(headerRect.width, null));
Widgets.Label(headerRect, "Mods of " + mod.AuthorsString.Replace("Andreas Pardeike", "Brrainz") + ":".Truncate(headerRect.width, null));
Text.Anchor = TextAnchor.UpperLeft;

var outRect = new Rect(leftColumn + 10f, headerHeight - 4f, rightColumn, mainRect.height - (headerHeight - 4f));
Expand All @@ -366,6 +374,7 @@ static void PromotionPart(Rect mainRect, float leftColumn, float rightColumn, Mo

if (height > 0)
height += 10f;

var preview = CrossPromotion.PreviewForMod(promoMod.m_nPublishedFileId.m_PublishedFileId);
if (preview != null)
{
Expand Down Expand Up @@ -424,7 +433,7 @@ void actionButtonAction()
{
if (isSubbed || isLocalFile)
{
var orderedMods = (IEnumerable<ModMetaData>)AccessTools.Method(typeof(Page_ModsConfig), "ModsInListOrder").Invoke(page, Array.Empty<object>());
var orderedMods = page.ModsInListOrder();
page.selectedMod = orderedMods.FirstOrDefault(meta => meta.GetPublishedFileId().m_PublishedFileId == myModID);
var modsBefore = orderedMods.ToList().FindIndex(m => m == page.selectedMod);
if (modsBefore >= 0)
Expand All @@ -435,7 +444,8 @@ void actionButtonAction()
{
CrossPromotion.subscribingMods.Add(myModID);
_ = SteamUGC.SubscribeItem(new PublishedFileId_t(myModID));
}).Start();
})
.Start();
}
var infoWindow = new Dialog_MessageBox(description, "Close".Translate(), null, actionButton, actionButtonAction, null, false, null, null);
Find.WindowStack.Add(infoWindow);
Expand Down Expand Up @@ -507,4 +517,4 @@ internal MiniDialog(string text, string buttonAText = null, Action buttonAAction

public override Vector2 InitialSize => new Vector2(320, 240);
}
}
}
20 changes: 7 additions & 13 deletions Source/ForcedFloatMenuOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ForcedMultiFloatMenuOption : ForcedFloatMenuOption
{
public List<ForcedFloatMenuOption> options;

public ForcedMultiFloatMenuOption(string label) : base(label, null, MenuOptionPriority.Default, null, null, 0f, null, null) { }
public ForcedMultiFloatMenuOption(string label) : base(label, null, MenuOptionPriority.Default, null, null, 0f, null, null, false, 0) { }

public override bool ForceAction()
{
Expand Down Expand Up @@ -81,28 +81,22 @@ public static float ButtonWidth
}
}

public static FloatMenuOption CreateForcedMenuItem(string label, Action action, MenuOptionPriority priority, Action mouseoverGuiAction, Thing revalidateClickTarget, float extraPartWidth, Func<Rect, bool> extraPartOnGUI, WorldObject revalidateWorldClickTarget, Pawn pawn, IntVec3 clickCell, WorkGiver_Scanner workgiver)
public static FloatMenuOption CreateForcedMenuItem(string label, Action action, MenuOptionPriority priority, Action<Rect> mouseoverGuiAction, Thing revalidateClickTarget, float extraPartWidth, Func<Rect, bool> extraPartOnGUI, WorldObject revalidateWorldClickTarget, bool playSelectionSound, int orderInPriority, Pawn pawn, Vector3 clickPos, WorkGiver_Scanner workgiver)
{
if (action == null)
return new FloatMenuOption(label, action, priority, mouseoverGuiAction, revalidateClickTarget, extraPartWidth, extraPartOnGUI, revalidateWorldClickTarget);
return new FloatMenuOption(label, action, priority, mouseoverGuiAction, revalidateClickTarget, extraPartWidth, extraPartOnGUI, revalidateWorldClickTarget, playSelectionSound, orderInPriority);

var option = new ForcedFloatMenuOption(label, action, priority, mouseoverGuiAction, revalidateClickTarget, extraPartWidth, extraPartOnGUI, revalidateWorldClickTarget) { };
var option = new ForcedFloatMenuOption(label, action, priority, mouseoverGuiAction, revalidateClickTarget, extraPartWidth, extraPartOnGUI, revalidateWorldClickTarget, playSelectionSound, orderInPriority) { };
option.forcePawn = pawn;
option.forceCell = clickCell;
option.forceCell = IntVec3.FromVector3(clickPos);
option.forceWorkgiver = workgiver;
option.extraPartOnGUI = extraPartRect => option.RenderExtraPartOnGui(extraPartRect);

return option;
}

public static FloatMenuOption CreateForcedMenuItemNew(string label, Action action, MenuOptionPriority priority, Action mouseoverGuiAction, Thing revalidateClickTarget, float extraPartWidth, Func<Rect, bool> extraPartOnGUI, WorldObject revalidateWorldClickTarget, Pawn pawn, Vector3 clickPos, WorkGiver_Scanner workgiver)
{
var clickCell = IntVec3.FromVector3(clickPos);
return CreateForcedMenuItem(label, action, priority, mouseoverGuiAction, revalidateClickTarget, extraPartWidth, extraPartOnGUI, revalidateWorldClickTarget, pawn, clickCell, workgiver);
}

public ForcedFloatMenuOption(string label, Action action, MenuOptionPriority priority, Action mouseoverGuiAction, Thing revalidateClickTarget, float extraPartWidth, Func<Rect, bool> extraPartOnGUI, WorldObject revalidateWorldClickTarget)
: base(label, action, priority, mouseoverGuiAction, revalidateClickTarget, extraPartWidth, extraPartOnGUI, revalidateWorldClickTarget)
public ForcedFloatMenuOption(string label, Action action, MenuOptionPriority priority, Action<Rect> mouseoverGuiAction, Thing revalidateClickTarget, float extraPartWidth, Func<Rect, bool> extraPartOnGUI, WorldObject revalidateWorldClickTarget, bool playSelectionSound, int orderInPriority)
: base(label, action, priority, mouseoverGuiAction, revalidateClickTarget, extraPartWidth, extraPartOnGUI, revalidateWorldClickTarget, playSelectionSound, orderInPriority)
{
// somehow necessary or else 'extraPartWidth' will be 0
base.extraPartWidth = buttonSpace + ButtonWidth;
Expand Down
Loading

0 comments on commit 618942f

Please sign in to comment.