1.More rewrites.

2,Give detailed message when mod's assemblies can't load.
This commit is contained in:
yangzhi 2020-02-14 17:49:37 +08:00
parent 6ff2db235a
commit 7005836fa7
6 changed files with 97 additions and 6 deletions

View File

@ -110,13 +110,30 @@ namespace StardewModdingAPI.Framework.ModLoading
// detect broken assembly reference
foreach (AssemblyNameReference reference in assembly.Definition.MainModule.AssemblyReferences)
{
if (!(reference.Name.StartsWith("System.") || reference.Name.Equals("System")) && !this.IsAssemblyLoaded(reference))
try {
if (!this.IsAssemblyLoaded(reference))
{
this.Monitor.LogOnce(loggedMessages, $" Broken code in {assembly.File.Name}: reference to missing assembly '{reference.FullName}'.");
if (!assumeCompatible)
throw new IncompatibleInstructionException($"Found a reference to missing assembly '{reference.FullName}' while loading assembly {assembly.File.Name}.");
mod.SetWarning(ModWarning.BrokenCodeLoaded);
break;
}
}
catch
{
this.Monitor.LogOnce(loggedMessages, $" Broken code in {assembly.File.Name}: reference to missing assembly '{reference.FullName}'.");
if (!assumeCompatible)
throw new IncompatibleInstructionException($"Found a reference to missing assembly '{reference.FullName}' while loading assembly {assembly.File.Name}.");
mod.SetWarning(ModWarning.BrokenCodeLoaded);
break;
if (!reference.Name.StartsWith("System."))
{
this.Monitor.LogOnce(loggedMessages, $" Broken code in {assembly.File.Name}: reference to missing assembly '{reference.FullName}'.");
if (!assumeCompatible)
throw new IncompatibleInstructionException($"Found a reference to missing assembly '{reference.FullName}' while loading assembly {assembly.File.Name}.");
mod.SetWarning(ModWarning.BrokenCodeLoaded);
break;
}
else
{
this.Monitor.LogOnce(loggedMessages, $" Probably broken code in {assembly.File.Name}: reference to missing assembly '{reference.FullName}'.");
}
}
}

View File

@ -0,0 +1,12 @@
using StardewValley.Menus;
namespace StardewModdingAPI.Framework.RewriteFacades
{
public class DialogueBoxMethods : DialogueBox
{
public DialogueBoxMethods(string dialogue)
: base(dialogue)
{
}
}
}

View File

@ -18,5 +18,51 @@ namespace StardewModdingAPI.Framework.RewriteFacades
{
return base.rightClick(x, y, toAddTo, playSound);
}
public List<ClickableComponent> GetBorder(BorderSide side)
{
List<ClickableComponent> clickableComponentList = new List<ClickableComponent>();
int num = this.capacity / this.rows;
switch (side)
{
case BorderSide.Top:
for (int index = 0; index < this.inventory.Count; ++index)
{
if (index < num)
clickableComponentList.Add(this.inventory[index]);
}
break;
case BorderSide.Left:
for (int index = 0; index < this.inventory.Count; ++index)
{
if (index % num == 0)
clickableComponentList.Add(this.inventory[index]);
}
break;
case BorderSide.Right:
for (int index = 0; index < this.inventory.Count; ++index)
{
if (index % num == num - 1)
clickableComponentList.Add(this.inventory[index]);
}
break;
case BorderSide.Bottom:
for (int index = 0; index < this.inventory.Count; ++index)
{
if (index >= this.actualInventory.Count - num)
clickableComponentList.Add(this.inventory[index]);
}
break;
}
return clickableComponentList;
}
public enum BorderSide
{
Top,
Left,
Right,
Bottom,
}
}
}

View File

@ -63,6 +63,18 @@ namespace StardewModdingAPI.Framework.RewriteFacades
typeof(ShopMenu).GetField("categoriesToSellHere", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).SetValue(this, value);
}
}
public Dictionary<ISalable, int[]> ItemPriceAndStockProp
{
get
{
return (Dictionary<ISalable, int[]>)typeof(ShopMenu).GetField("itemPriceAndStock", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(this);
}
set
{
typeof(ShopMenu).GetField("itemPriceAndStock", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).SetValue(this, value);
}
}
public ShopMenuMethods(Dictionary<ISalable, int[]> itemPriceAndStock, int currency = 0, string who = null, Func<ISalable, Farmer, int, bool> on_purchase = null, Func<ISalable, bool> on_sell = null, string context = null) : base(itemPriceAndStock, currency, who, on_purchase, on_sell, context)
{
}

View File

@ -60,11 +60,13 @@ namespace StardewModdingAPI.Metadata
yield return new TypeFieldToAnotherTypePropertyRewriter(typeof(ShopMenu), typeof(ShopMenuMethods), "hoverPrice", "HoverPriceProp");
yield return new TypeFieldToAnotherTypePropertyRewriter(typeof(ShopMenu), typeof(ShopMenuMethods), "hoverText", "HoverTextProp");
yield return new TypeFieldToAnotherTypePropertyRewriter(typeof(ShopMenu), typeof(ShopMenuMethods), "categoriesToSellHere", "CategoriesToSellHereProp");
yield return new TypeFieldToAnotherTypePropertyRewriter(typeof(ShopMenu), typeof(ShopMenuMethods), "itemPriceAndStock", "ItemPriceAndStockProp");
yield return new TypeFieldToAnotherTypePropertyRewriter(typeof(MenuWithInventory), typeof(MenuWithInventoryMethods), "trashCan", "TrashCanProp");
yield return new TypeFieldToAnotherTypePropertyRewriter(typeof(ItemGrabMenu), typeof(ItemGrabMenuMethods), "fillStacksButton", "FillStacksButtonProp");
// Rewrite Missing Type
yield return new TypeReferenceRewriter("StardewValley.Menus.CraftingPage", typeof(CraftingPageMobile));
yield return new TypeReferenceRewriter("StardewValley.Menus.InventoryMenu/BorderSide", typeof(InventoryMenuMethods.BorderSide));
//Method Rewrites
yield return new MethodParentRewriter(typeof(Game1), typeof(Game1Methods));
@ -87,6 +89,7 @@ namespace StardewModdingAPI.Metadata
yield return new MethodParentRewriter(typeof(MenuWithInventory), typeof(MenuWithInventoryMethods));
yield return new MethodParentRewriter(typeof(GameMenu), typeof(GameMenuMethods));
yield return new MethodParentRewriter(typeof(CraftingPageMobile), typeof(CraftingPageMobileMethods));
yield return new MethodParentRewriter(typeof(DialogueBox), typeof(DialogueBoxMethods));
//Field Rewriters
yield return new FieldReplaceRewriter(typeof(ItemGrabMenu), "context", "specialObject");

View File

@ -265,6 +265,7 @@
<Compile Include="Framework\RewriteFacades\InventoryMenuMethods.cs" />
<Compile Include="Framework\RewriteFacades\DiscreteColorPickerMethods.cs" />
<Compile Include="Framework\RewriteFacades\CraftingPageMobileMethods.cs" />
<Compile Include="Framework\RewriteFacades\DialogueBoxMethods.cs" />
<Compile Include="Framework\RewriteFacades\ShopMenuMethods.cs" />
<Compile Include="Framework\RewriteFacades\FarmerMethods.cs" />
<Compile Include="Framework\RewriteFacades\FarmerRenderMethods.cs" />