Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Chasmical committed Jul 7, 2021
1 parent b6283d8 commit 2f446c4
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions RogueLibsCore.Test/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions RogueLibsCore.Test/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@
<data name="Duplicator" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Duplicator.bin;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="LootBox1" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\LootBox1.bin;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<data name="LootBox" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\LootBox.bin;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="LootBox2" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\LootBox2.bin;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
Expand Down
2 changes: 1 addition & 1 deletion RogueLibsCore.Test/RogueLibsCore.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<None Include="Resources\Batteries.bin" />
<None Include="Resources\Converter.bin" />
<None Include="Resources\Duplicator.bin" />
<None Include="Resources\LootBox1.bin" />
<None Include="Resources\LootBox.bin" />
<None Include="Resources\LootBox2.bin" />
<None Include="Resources\LootBox3.bin" />
<None Include="Resources\NuclearBriefcase.bin" />
Expand Down
5 changes: 3 additions & 2 deletions RogueLibsCore.Test/Tests/LootBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public static void Test()
RogueLibs.CreateCustomItem<LootBox>()
.WithName(new CustomNameInfo("Loot Box"))
.WithDescription(new CustomNameInfo("Gives you a random item."))
.WithSprite(Properties.Resources.LootBox)
.WithUnlock(new ItemUnlock { UnlockCost = 10, CharacterCreationCost = 3, LoadoutCost = 3 });

RogueLibs.CreateCustomSprite("LootBox1", SpriteScope.Items, Properties.Resources.LootBox1);
RogueLibs.CreateCustomSprite("LootBox2", SpriteScope.Items, Properties.Resources.LootBox2);
RogueLibs.CreateCustomSprite("LootBox3", SpriteScope.Items, Properties.Resources.LootBox3);
}
Expand All @@ -32,7 +32,8 @@ public override void SetupDetails()
Item.cantBeCloned = true;

int rnd = new Random().Next(3) + 1;
Item.LoadItemSprite($"LootBox{rnd}");
if (rnd != 1)
Item.LoadItemSprite($"LootBox{rnd}");
}
public bool UseItem()
{
Expand Down
20 changes: 12 additions & 8 deletions RogueLibsCore/Patches/Patches_Unlocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public void PatchUnlocks()
Patcher.Postfix(typeof(Unlocks), nameof(Unlocks.AddUnlock),
new Type[] { typeof(string), typeof(string), typeof(bool), typeof(int), typeof(int), typeof(int), typeof(Unlock) });

Patcher.Prefix(typeof(Unlocks), nameof(Unlocks.LoadInitialUnlocks), nameof(Unlocks_LoadInitialUnlocks_Prefix));
// replace the entire foreach loop in the end
// pseudo-prefix + replace the entire foreach loop in the end
Patcher.Transpiler(typeof(Unlocks), nameof(Unlocks.LoadInitialUnlocks));

Patcher.Prefix(typeof(Unlocks), nameof(Unlocks.CanDoUnlocks));
Expand All @@ -33,7 +32,7 @@ public void PatchUnlocks()
RogueLibs.CreateCustomName("UnlockFor", "Unlock", new CustomNameInfo
{
English = "Unlock for",
Russian = "Разблокировать за"
Russian = "Разблокировать за",
});
}

Expand All @@ -47,13 +46,19 @@ public static void Unlocks_AddUnlock(Unlock createdUnlock, Unlock __result)
}
}

public static void Unlocks_LoadInitialUnlocks_Prefix(bool ___loadedInitialUnlocks)
private static void UnlocksClearHelper(bool dontClear)
{
if (___loadedInitialUnlocks) return;
if (dontClear) return;
RogueFramework.Unlocks.Clear();
}
public static IEnumerable<CodeInstruction> Unlocks_LoadInitialUnlocks(IEnumerable<CodeInstruction> codeEnumerable)
=> codeEnumerable.ReplaceRegion(
=> new CodeInstruction[]
{
new CodeInstruction(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(Unlocks), "loadedInitialUnlocks")),
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(RogueLibsPlugin), nameof(UnlocksClearHelper))),
}
.Concat(codeEnumerable.ReplaceRegion(
new Func<CodeInstruction, bool>[]
{
i => i.opcode == OpCodes.Callvirt && i.Calls(List_Unlock_GetEnumerator)
Expand All @@ -66,8 +71,7 @@ public static IEnumerable<CodeInstruction> Unlocks_LoadInitialUnlocks(IEnumerabl
{
new CodeInstruction(OpCodes.Pop),
new CodeInstruction(OpCodes.Call, typeof(RogueLibsPlugin).GetMethod(nameof(LoadUnlockWrappersAndCategorize)))
}
);
}));
private static readonly MethodInfo List_Unlock_GetEnumerator = typeof(List<Unlock>).GetMethod("GetEnumerator");
public static void LoadUnlockWrappersAndCategorize()
{
Expand Down
2 changes: 1 addition & 1 deletion RogueLibsCore/Utilities/RoguePatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void LogResults()
$" | {time.Elapsed.TotalMilliseconds,4:####}ms |");
total += time.Elapsed;
}
log.LogDebug("Total: {total,5:#####}ms");
log.LogDebug($"Total: {total,5:#####}ms");
}

public bool Prefix(Type targetType, string targetMethod, Type[] targetParameterTypes = null)
Expand Down

0 comments on commit 2f446c4

Please sign in to comment.