Detouring this

Started by CallMeDio, August 05, 2016, 10:36:21 AM

Previous topic - Next topic

1000101

Where are you getting the error?  It doesn't help if we don't know what method it's happening in.  :P

You may need a rubber duck.  Also, try some caveman debugging.
(2*b)||!(2*b) - That is the question.
There are 10 kinds of people in this world - those that understand binary and those that don't.

Powered By

CallMeDio

#16
No errors, I can compile it and run it. But when testing ingame the thing I added to the detoured method don't happen what means that the it was not detoured, what I guess means i corrupted memory with something there, probably the nulls that I pointed on my last post that i can't replace full file:

using RimWorld;
using System;
using System.Reflection;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Verse;
using Verse.AI;
namespace SC
{
    internal static class _Bill_Medical
    {
        internal static FieldInfo _Part;
        internal static FieldInfo _GiverPawn;
        internal static MethodInfo _Delete;
        internal static MethodInfo _GetPartsToApplyOn;
        internal static MethodInfo _recipe;


        internal static BodyPartRecord Part()
        {
           
             if( _Part == null )
            {
                _Part = typeof(BodyPartRecord).GetField("Part", BindingFlags.Instance | BindingFlags.Public);
            }
            return (BodyPartRecord)_Part.GetValue( null );
        }

        internal static Pawn GiverPawn()
        {

            if (_GiverPawn  == null)
            {
                _GiverPawn = typeof(Pawn).GetField("GiverPawn", BindingFlags.Instance | BindingFlags.NonPublic);
            }
            return (Pawn)_GiverPawn.GetValue(null);
        }

        internal static BillStack Delete(Bill bill)
        {

            if (_Delete == null)
            {
                _Delete = typeof(BillStack).GetMethod("Delete", BindingFlags.Instance | BindingFlags.Public);
            }
            return (BillStack)_Delete.Invoke(null, new object[] { bill});
        }

        internal static IEnumerable<BodyPartRecord> GetPartsToApplyOn(Pawn pawn, RecipeDef recipe)
        {

            if (_GetPartsToApplyOn == null)
            {
                _GetPartsToApplyOn = typeof(IEnumerable<BodyPartRecord>).GetMethod("GetPartsToApplyOn", BindingFlags.Instance | BindingFlags.Public);
            }
            return (IEnumerable<BodyPartRecord>)_GetPartsToApplyOn.Invoke(null, new object[] { pawn, recipe });
        }
       




        internal static void Notify_IterationCompleted(this Bill_Medical obj,Pawn billDoer, List<Thing> ingredients)
        {
            obj.Notify_IterationCompleted(billDoer, ingredients);
            Pawn giverPawn = GiverPawn();
            if (GetPartsToApplyOn(giverPawn, obj.recipe).Contains(Part()))
            {
                obj.recipe.Worker.ApplyOnPawn(giverPawn, Part(), billDoer, ingredients);
                giverPawn.health.AddHediff(HediffMaker.MakeHediff(HediffDefOf.FoodPoisoning, giverPawn, null), null, null);
                if (giverPawn.RaceProps.IsFlesh)
                {
                    giverPawn.records.Increment(RecordDefOf.OperationsReceived);
                    billDoer.records.Increment(RecordDefOf.OperationsPerformed);
                 
                }
            }
            Delete(obj);
        }

       

    }
}


QuoteYou may need a rubber duck.  Also, try some caveman debugging.

Released mods: No Mood Loss on Prisoner Sold or Died

1000101

If CCL didn't return an error on the detour, then it was detoured.

As I already suggested, stick in some log messages.
(2*b)||!(2*b) - That is the question.
There are 10 kinds of people in this world - those that understand binary and those that don't.

Powered By

CallMeDio

Sorry, I forgot, there it is the output log:

Initialize engine version: 5.3.4f1 (fdbb5133b820)
GfxDevice: creating device client; threaded=1
Direct3D:
    Version:  Direct3D 9.0c [aticfx32.dll 8.17.10.1474]
    Renderer: AMD Radeon (TM) R9 200 Series
    Vendor:   ATI
    VRAM:     2026 MB (via DXGI)
    Caps:     Shader=30 DepthRT=1 NativeDepth=1 NativeShadow=1 DF16=1 INTZ=1 NULL=1 RESZ=1 SlowINTZ=1
Begin MonoManager ReloadAssembly
Platform assembly: E:\Jogos do E\RimWorld.Alpha.14e\RimWorld1249Win_Data\Managed\UnityEngine.dll (this message is harmless)
Loading E:\Jogos do E\RimWorld.Alpha.14e\RimWorld1249Win_Data\Managed\UnityEngine.dll into Unity Child Domain
Platform assembly: E:\Jogos do E\RimWorld.Alpha.14e\RimWorld1249Win_Data\Managed\Assembly-CSharp-firstpass.dll (this message is harmless)
Loading E:\Jogos do E\RimWorld.Alpha.14e\RimWorld1249Win_Data\Managed\Assembly-CSharp-firstpass.dll into Unity Child Domain
Platform assembly: E:\Jogos do E\RimWorld.Alpha.14e\RimWorld1249Win_Data\Managed\Assembly-CSharp.dll (this message is harmless)
Loading E:\Jogos do E\RimWorld.Alpha.14e\RimWorld1249Win_Data\Managed\Assembly-CSharp.dll into Unity Child Domain
Platform assembly: E:\Jogos do E\RimWorld.Alpha.14e\RimWorld1249Win_Data\Managed\UnityEngine.UI.dll (this message is harmless)
Loading E:\Jogos do E\RimWorld.Alpha.14e\RimWorld1249Win_Data\Managed\UnityEngine.UI.dll into Unity Child Domain
Platform assembly: E:\Jogos do E\RimWorld.Alpha.14e\RimWorld1249Win_Data\Managed\UnityEngine.Networking.dll (this message is harmless)
Loading E:\Jogos do E\RimWorld.Alpha.14e\RimWorld1249Win_Data\Managed\UnityEngine.Networking.dll into Unity Child Domain
Platform assembly: E:\Jogos do E\RimWorld.Alpha.14e\RimWorld1249Win_Data\Managed\System.Xml.Linq.dll (this message is harmless)
Loading E:\Jogos do E\RimWorld.Alpha.14e\RimWorld1249Win_Data\Managed\System.Xml.Linq.dll into Unity Child Domain
Platform assembly: E:\Jogos do E\RimWorld.Alpha.14e\RimWorld1249Win_Data\Managed\NAudio.dll (this message is harmless)
Loading E:\Jogos do E\RimWorld.Alpha.14e\RimWorld1249Win_Data\Managed\NAudio.dll into Unity Child Domain
Platform assembly: E:\Jogos do E\RimWorld.Alpha.14e\RimWorld1249Win_Data\Managed\NVorbis.dll (this message is harmless)
Loading E:\Jogos do E\RimWorld.Alpha.14e\RimWorld1249Win_Data\Managed\NVorbis.dll into Unity Child Domain
- Completed reload, in  0.046 seconds
Platform assembly: E:\Jogos do E\RimWorld.Alpha.14e\RimWorld1249Win_Data\Managed\System.Core.dll (this message is harmless)
Platform assembly: E:\Jogos do E\RimWorld.Alpha.14e\RimWorld1249Win_Data\Managed\System.dll (this message is harmless)
Platform assembly: E:\Jogos do E\RimWorld.Alpha.14e\RimWorld1249Win_Data\Managed\System.Xml.dll (this message is harmless)
<RI> Initializing input.

<RI> Input initialized.

desktop: 1280x1024 60Hz; virtual: 1280x1024 at 0,0
<RI> Initialized touch support.

UnloadTime: 0.562249 ms
RimWorld 0.14.1249 rev955

(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

Non platform assembly: data-10E85B88 (this message is harmless)
Fallback handler could not load library E:/Jogos do E/RimWorld.Alpha.14e/RimWorld1249Win_Data/Mono/data-10E85B88.dll
Community Core Library :: v0.14.1

(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

Non platform assembly: data-10EEA390 (this message is harmless)
Fallback handler could not load library E:/Jogos do E/RimWorld.Alpha.14e/RimWorld1249Win_Data/Mono/data-10EEA390.dll
Community Core Library :: Queueing Library Initialization

(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

Community Core Library :: Library Core :: Validations :: Validated
ModHelperDef :: Community Core Library :: Passed validation, requesting v0.14.1


(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

Community Core Library :: Advanced Research :: Validations :: Validated


(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

Community Core Library :: Minimap Controller :: Validations :: Validated


(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

Community Core Library :: Injection Controller :: Initialization :: Initialized


(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

Community Core Library :: Advanced Research :: Initialization :: No advanced research defined, hybernating...

(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

Community Core Library :: Help System :: Completed in 00:00:00.2830162


(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

Community Core Library :: Help Generator :: Initialization :: Initialized

(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

Community Core Library :: Library Core :: Initialization :: Mod Configuration Menus initialized

(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

Community Core Library :: Minimap Controller :: Initialization :: Initialized


(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

Community Core Library :: Initialized

(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

Unloading 5 Unused Serialized files (Serialized files now loaded: 0)
UnloadTime: 1.113092 ms

Unloading 22 unused Assets to reduce memory usage. Loaded Objects now: 5937.
Total: 15.922208 ms (FindLiveObjects: 0.111369 ms CreateObjectMapping: 0.277372 ms MarkObjects: 15.508250 ms  DeleteObjects: 0.024915 ms)

Initializing map from file Rhine with mods Core, Community Core Library, and SC

(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

Community Core Library :: Injection Controller :: Update :: Updated


(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)


Everything seems fine to me in this log "Community Core Library :: Injection Controller :: Initialization :: Initialized".
I will quote your caveman debugging message on my sig, cause every time I remember it makes me laugh :)
QuoteYou may need a rubber duck.  Also, try some caveman debugging.

Released mods: No Mood Loss on Prisoner Sold or Died

CallMeDio

#19
edit: And any example on the ccl that detour something with a method inaccessible due to protection inside?

as for this attempt of detouring Im going to retire. detour 1 callmedio 0, no regrets.
QuoteYou may need a rubber duck.  Also, try some caveman debugging.

Released mods: No Mood Loss on Prisoner Sold or Died

CallMeDio

I gave up on the last and tried detouring something else... surprise,it also does nothing.  Do i need holy water and a priest or is there some basic usage of CCL that im skipping?
I added CCL in references, did the injector class on my namespace like a posted previously and I have CCL on my mod folder loading after Core.
QuoteYou may need a rubber duck.  Also, try some caveman debugging.

Released mods: No Mood Loss on Prisoner Sold or Died

1000101

I mean you should add your own caveman debugging messages.

Log.Message( "Method Entered" );
...
Log.Message( "Checking for foo" );
...
Log.Message( "Checked bar" );

etc
(2*b)||!(2*b) - That is the question.
There are 10 kinds of people in this world - those that understand binary and those that don't.

Powered By

CallMeDio

#22
Yea, I did some, one inside my custom method(didn't fired), other after injecting (didn't fired too)so i guess the injection returned false.

Edit: Forgot to mention i fixed some stupid errors I made, still not working, but no problem, I want to stop disturbing you guys, Im going to figure this sooner or later using caveman debugging and advanced guessing techniques.

QuoteYou may need a rubber duck.  Also, try some caveman debugging.

Released mods: No Mood Loss on Prisoner Sold or Died

CallMeDio

OMG...... The thing that was wrong (among some other small things of course) is so stupid that Im feeling a little bit embarassed to post this, but for use of everybody I must share. My mod didn't had a ModHelperDefs folder with the proper xml... just saw on skullywag's fabric reclaim that he said to look at... I made the folder and the file, and after that with some little fixes it finally worked! Now I have so many ideas, creative time! Thanks everybody!
QuoteYou may need a rubber duck.  Also, try some caveman debugging.

Released mods: No Mood Loss on Prisoner Sold or Died

1000101

No worries, we're all allowed a derpy moment once in a while.  ;)
(2*b)||!(2*b) - That is the question.
There are 10 kinds of people in this world - those that understand binary and those that don't.

Powered By