[1.5] HugsLib (11.0.3) Lightweight modding library

Started by UnlimitedHugs, December 15, 2016, 02:20:14 PM

Previous topic - Next topic

System.Linq

#45
It would appear that, when you detour a method that a class inherits from its parent, but doesn't actually override, it detours the parent's method instead. Any way around this?

e: Also, it's a shame there's no documentation for UpdateFeatureDef.

UnlimitedHugs

Quote from: Psychology on December 30, 2016, 05:08:27 AM
It would appear that, when you detour a method that a class inherits from its parent, but doesn't actually override, it detours the parent's method instead. Any way around this?

I don't quite see the problem here. Would you rather have it generate an error?

Quote from: Psychology on December 30, 2016, 05:08:27 AM
e: Also, it's a shame there's no documentation for UpdateFeatureDef.

Yeah, I've been meaning to add a page about that. Gotta wait for inspiration to hit, though.
In the meantime, The code of UpdateFeatureDef has some comments on the formatting options. Also, Allow Tool and Defensive Positions both make use of this system if you're looking for practical examples.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

Trinan

Hello I have this problem, since English is not my native language. Maybe you can help me. Hugsmod comes directly to Core

[HugsLib] Exception during ApplyNewDetours: System.TypeLoadException: Could not load type 'System.Runtime.Serialization.DataContractAttribute' from assembly 'System.Runtime.Serialization, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
  at (wrapper managed-to-native) System.Reflection.MonoMethodInfo:get_method_info (intptr,System.Reflection.MonoMethodInfo&)
  at System.Reflection.MonoMethodInfo.GetMethodInfo (IntPtr handle) [0x00000] in <filename unknown>:0
  at System.Reflection.MonoMethod.GetPseudoCustomAttributes () [0x00000] in <filename unknown>:0
  at System.MonoCustomAttrs.GetPseudoCustomAttributes (ICustomAttributeProvider obj, System.Type attributeType) [0x00000] in <filename unknown>:0
  at System.MonoCustomAttrs.GetCustomAttributesBase (ICustomAttributeProvider obj, System.Type attributeType) [0x00000] in <filename unknown>:0
  at System.MonoCustomAttrs.GetCustomAttributes (ICustomAttributeProvider obj, System.Type attributeType, Boolean inherit) [0x00000] in <filename unknown>:0
  at System.Reflection.MonoMethod.GetCustomAttributes (System.Type attributeType, Boolean inherit) [0x00000] in <filename unknown>:0
  at Verse.GenAttribute.TryGetAttribute[DetourMethodAttribute] (System.Reflection.MemberInfo memberInfo, HugsLib.Source.Detour.DetourMethodAttribute& customAttribute) [0x00000] in <filename unknown>:0
  at Verse.GenAttribute.HasAttribute[DetourMethodAttribute] (System.Reflection.MemberInfo memberInfo) [0x00000] in <filename unknown>:0
  at HugsLib.Source.Detour.Helpers.<DoDetours>b__8 (System.Reflection.MethodInfo m) [0x00000] in <filename unknown>:0
  at System.Linq.Enumerable+<CreateWhereIterator>c__Iterator1D`1[System.Reflection.MethodInfo].MoveNext () [0x00000] in <filename unknown>:0
  at HugsLib.Source.Detour.Helpers.DoDetours () [0x00000] in <filename unknown>:0
  at HugsLib.HugsLibController.ApplyNewDetours () [0x00000] in <filename unknown>:0
Verse.Log:Error(String)
HugsLib.Utils.ModLogger:ReportException(Exception, String, Boolean, String)
HugsLib.HugsLibController:ApplyNewDetours()
HugsLib.HugsLibController:LoadReloadInitialize()
HugsLib.HugsLibController:Initalize()
HugsLib.Core.UnityProxyComponent:Start()

UnlimitedHugs

Updated to 2.2.2

@Trinan
I've added some more safety checks to the detouring system that should solve this issue.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

Trinan


System.Linq

Quote from: UnlimitedHugs on December 30, 2016, 07:17:18 AM
I don't quite see the problem here. Would you rather have it generate an error?

I'd rather have it detour the method in the class I'm trying to detour it in, rather than having the detoured code apply to all of that parent's children. Hence why I asked if there was a different way to do that.

Zhentar

So Class A is inherited by Classes B and C. You want to detour a method only for Class B, but that method is defined in Class A and not overridden in Class B.

In that case, the answer is no, you cannot; that goes far beyond the capabilities of the current detouring code. While it is technically not impossible, it would be extremely difficult to implement.

System.Linq

Alright, figured as much. I solved the problem by using _this.GetType() == typeof(ClassIWant).

lllMWNlll

I got a lot of log problems!

https://gist.github.com/d2d4baf2a35a61278be070b38b8bff15

I just updated. I'm using several mods, some of them are 15 yet this are the "15" ones:
A Dog Said...
CorePanda
Efficient Light 
Extended Medicine
Extended Fabrics
Expanded Power
Cupro's Drinks 
DE Surgeries   
RimFridge     
TrueMods   
Misc Mods
{ Core, Robots, RobotsX, RobotsXX

Hope i did help in something.

UnlimitedHugs

#54
Quote from: lllMWNlll on December 30, 2016, 07:57:16 PM
- snip -

I can't help you if you are using A15 mods on A16. Also, please make sure your game language is set to English when you submit your log- that makes it much easier to read.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

rawrfisher

Does Anyone know what this error means?

Got ThingsListAt out of bounds: (400, 0, 221)
Verse.Log:Error(String)
Verse.Log:ErrorOnce(String, Int32)
Verse.ThingGrid:ThingsListAt(IntVec3)
Verse.GridsUtility:GetThingList(IntVec3, Map)
Blueprints.BuildableInfo:CanPlace(IntVec3)
Blueprints.BuildableInfo:DrawGhost(IntVec3)
Blueprints.Blueprint:DrawGhost(IntVec3)
Blueprints.Designator_Blueprint:SelectedUpdate()
Verse.DesignatorManager:DesignatorManagerUpdate()
RimWorld.MapInterface:MapInterfaceUpdate()
RimWorld.UIRoot_Play:UIRootUpdate()
Verse.Root:Update()
Verse.Root_Play:Update()
Professional jerk
Want something broken let me know

System.Linq

It means that your game is trying to load a specific Thing from the Things list, but there aren't that many Things in the list. You're going to need to provide more context.

rawrfisher

Professional jerk
Want something broken let me know

RawCode

Quote from: Zhentar on December 30, 2016, 06:03:55 PM
So Class A is inherited by Classes B and C. You want to detour a method only for Class B, but that method is defined in Class A and not overridden in Class B.

In that case, the answer is no, you cannot; that goes far beyond the capabilities of the current detouring code. While it is technically not impossible, it would be extremely difficult to implement.

StackTrace st = new StackTrace ();
MethodBase calle = st.GetFrames () [1].GetMethod ();


if specialequals(callee, specificmethodreferencelist)
do x
else
do y


it's not ever close to "difficult", you just need to think self and not rely on random not very wise tutorials scattered all over the forum.
and yes, you will need to set injection whitelist SELF and reimplement entire vanilla method or copy x86 or assemble trampoline code.




UnlimitedHugs

Quote from: rawrfisher on December 31, 2016, 08:21:48 PM
Does Anyone know what this error means?

Seems like this was caused by the Blueprints mod. Perhaps caused by an attempt to place a large blueprint on a smaller map.
It's a good idea to report this in Fluffy's thread.

Quote from: RawCode on January 01, 2017, 02:10:10 AM
- snip -

Not sure I understand your solution.
As Zhentar said, we can't detour a method that does not exist. Perhaps an override could be created using DynamicMethod, but I wouldn't trust that enough to put it in the library.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam