示例#1
0
        public static void DropGear(Thing t, Pawn p)
        {
            use_native = true;
            try
            {
                RimLog.Message("thing : " + t);
                RimLog.Message("pawn : " + p);
                ThingWithComps thingWithComps = t as ThingWithComps;
                var            objects        = Find.Selector.SelectedObjects.ToArray();
                Rand.PushState(0);
                Find.Selector.ClearSelection();
                Find.Selector.Select(p, false, false);
                Rand.PopState();
                typeof(ITab_Pawn_Gear).GetMethod("InterfaceDrop", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(new ITab_Pawn_Gear(), new object[] { t });

                Rand.PushState(0);
                Find.Selector.ClearSelection();
                foreach (object o in objects)
                {
                    Find.Selector.Select(o, false, false);
                }
                Rand.PopState();
            }
            finally
            {
                use_native = false;
            }
        }
示例#2
0
        public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
        {
            /*
             * ISurrogateSelector _selector;
             * ISerializationSurrogate billmaker = selector.GetSurrogate(typeof(Bill), context, out _selector);
             * Bill b = (Bill)billmaker.SetObjectData(obj, info, context, _selector);
             * return (Bill_Production)b;*/
            string recipeDefName = info.GetString("recipedef");
            string loadID        = info.GetString("loadID");

            foreach (var b in BillUtility.GlobalBills())
            {
                if (b.GetUniqueLoadID() == loadID)
                {
                    return(b);
                }
            }

            foreach (var rec in DefDatabase <RecipeDef> .AllDefsListForReading)
            {
                if (rec.defName == recipeDefName)
                {
                    RimLog.Message("bill production restored via recipedef!");
                    Bill b = BillUtility.MakeNewBill(rec);
                    return(b);
                }
            }

            RimLog.Message("could not make bill_production!");
            return(null);
        }
示例#3
0
        public static void DumpFramelistData(System.IO.Stream s)
        {
            if (getValuePatch.diagnostics)
            {
                List <diagdata> fdls = framelistForTicks;
                RimLog.Message("framelistForTicks :: " + framelistForTicks.Count);

                PirateRPC.PirateRPC.SendInvocation(s, (u) =>
                {
                    Console.WriteLine("dumping data " + fdls.Count);

                    foreach (var kv in fdls)
                    {
                        if (!string.IsNullOrEmpty(kv.trace))
                        {
                            string str = kv.trace;

                            /*
                             * foreach (StackFrame sf in kv.trace)
                             * {
                             *  str += sf.ToString() + "\r\n";
                             * }*/

                            System.IO.File.AppendAllText("C:/CoopReplays/" + kv.clientID + "/" + kv.frame + "_" + kv.context + "_" + kv.iteration + ".txt", str);
                        }
                    }
                });
            }
        }
示例#4
0
            public static bool Prefix(string saveFileName)
            {
                string fileName    = saveFileName;
                string fileContent = System.IO.File.ReadAllText(GenFilePaths.FilePathForSavedGame(saveFileName));

                if (SyncTickData.cliendID == 0)
                {
                    PirateRPC.PirateRPC.SendInvocation(NetDemo.ns, u =>
                    {
                        NetDemo.SetSFD(new NetDemo.SaveFileData()
                        {
                            tcontext = fileContent, partial_name = fileName + "_received"
                        });

                        PirateRPC.PirateRPC.SendInvocation(u, uu => { NetDemo.LoadFromRemoteSFD(); });
                    });

                    LongEventHandler.QueueLongEvent(() =>
                    {
                        for (; NetDemo.GetSFD() == null;)
                        {
                        }
                    }, "Downloading savefile".Translate(), true, e => { RimLog.Error(e.ToString()); });
                }

                return(false);
            }
示例#5
0
        public override void Initialize()
        {
            inst = this;
            NetDemo.setupCallbacks();
            (typeof(Rand).GetField("random", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null) as RandomNumberGenerator).seed = 0;

            HarmonyInstance harmony = HarmonyInst;

            RimLog.Message(System.Diagnostics.Process.GetCurrentProcess().StartInfo.Arguments);
            List <Type> designatorInheritees = new List <Type>();

            InitBullshit();

            foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (Type t in a.GetTypes())
                {
                    if (!t.IsAbstract)
                    {
                        if (t.IsSubclassOf(typeof(Thing)))
                        {
                            MethodInfo    targetmethod = AccessTools.Method(t, "GetGizmos");
                            HarmonyMethod postfix      = new HarmonyMethod(typeof(CooperateRim.GenericGizmoPatch).GetMethod("Postfix"));
                            harmony.Patch(targetmethod, null, postfix, null);
                        }
                    }
                }
            }

            if (System.Diagnostics.Process.GetCurrentProcess().StartInfo.Arguments.Contains("network_launch"))
            {
                //harmony.PatchAll(Assembly.GetExecutingAssembly());
            }
        }
示例#6
0
        public static void GenerateWorld()
        {
            ThingIDMakerPatch.stopID = true;

            ThinkTreeKeyAssigner.Reset();

            foreach (var def in DefDatabase <ThinkTreeDef> .AllDefsListForReading)
            {
                ThinkTreeKeyAssigner.AssignKeys(def.thinkRoot, 0);
            }


            if (SyncTickData.cliendID == 0)
            {
                Find.WindowStack.Add(new Dialog_SaveFileList_Load());
            }
            else
            {
                LongEventHandler.QueueLongEvent(() =>
                {
                    NetDemo.LoadFromRemoteSFD();
                    for (; NetDemo.GetSFD() == null;)
                    {
                    }
                }, "Downloading savefile".Translate(), true, e => { RimLog.Error(e.ToString()); });
            }
        }
示例#7
0
        public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
        {
            string  billGiverID = info.GetString("billgiverID");
            IntVec3 pos         = (IntVec3)info.GetValue("thingPos", typeof(IntVec3));

            RimLog.Message("bill stack surrogate obj " + (obj == null ? "null" : "not null"));
            RimLog.Message("looking for issuer at " + pos);
            List <Thing>[] things = (List <Thing>[])Find.CurrentMap.thingGrid.GetType().GetField("thingGrid", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(Find.CurrentMap.thingGrid);

            foreach (var aa in things)
            {
                foreach (var issuer in aa)
                {
                    if (issuer.Position == pos)
                    {
                        RimLog.Message(issuer.ThingID + " :+: " + billGiverID);
                    }
                    if (issuer.ThingID == billGiverID)
                    {
                        RimLog.Message(issuer.ThingID + " :: " + billGiverID);
                        RimLog.Message("returning billstack ? " + ((issuer as IBillGiver).BillStack == null ? "null" : "not null"));
                        return((issuer as IBillGiver).BillStack);
                    }
                }
            }

            RimLog.Message("could not locate bill giver");
            return(null);
        }
        public static bool Prefix(Bill_Production bill)
        {
            List <FloatMenuOption> list = new List <FloatMenuOption>();

            list.Add(new FloatMenuOption(BillRepeatModeDefOf.RepeatCount.LabelCap, delegate()
            {
                RimLog.Message("le fuq is dis 1");
                SetBillRepeatType(bill, BillRepeatModeDefOf.RepeatCount);
            }, MenuOptionPriority.Default, null, null, 0f, null, null));
            FloatMenuOption item = new FloatMenuOption(BillRepeatModeDefOf.TargetCount.LabelCap, delegate()
            {
                if (!bill.recipe.WorkerCounter.CanCountProducts(bill))
                {
                    Messages.Message("RecipeCannotHaveTargetCount".Translate(), MessageTypeDefOf.RejectInput, false);
                }
                else
                {
                    RimLog.Message("le fuq is dis 2");
                    SetBillRepeatType(bill, BillRepeatModeDefOf.TargetCount);
                }
            }, MenuOptionPriority.Default, null, null, 0f, null, null);

            list.Add(item);
            list.Add(new FloatMenuOption(BillRepeatModeDefOf.Forever.LabelCap, delegate()
            {
                RimLog.Message("le fuq is dis 3");
                SetBillRepeatType(bill, BillRepeatModeDefOf.Forever);
            }, MenuOptionPriority.Default, null, null, 0f, null, null));
            Find.WindowStack.Add(new FloatMenu(list));
            return(false);
        }
示例#9
0
        public void AcceptResult()
        {
            int lockD = 0;

            try
            {
                Zone oldZone = Find.Selector.SelectedZone;

                lockD = 21;


                if (serializationServiceData.Length > 0)
                {
                    foreach (var sd in SerializationService.DeserializeFrom(serializationServiceData))
                    {
                        if (sd.methodContext > -1)
                        {
                            AvoidLoop = true;
                            try
                            {
                                ParrotWrapper.IndexedCall(sd.methodContext, sd.dataObjects.ToArray());
                            }
                            catch (Exception ee)
                            {
                                RimLog.Message("Indexed call exception for " + sd.methodContext + "\r\n" + ee.ToString());

                                int i = 0;
                                foreach (object o in sd.dataObjects)
                                {
                                    RimLog.Message((i++) + " :." + o + ".:");
                                }
                            }
                            AvoidLoop = false;
                        }
                    }
                }

                lockD = 22;
                Find.CurrentMap.zoneManager.AllZones.ForEach(u => { u.Cells.GetEnumerator(); });

                Zone zz = Find.Selector.SelectedZone;

                if (zz != null)
                {
                    zz.Cells.GetEnumerator();//failsafe for release mode
                    if (oldZone != zz)
                    {
                        Find.Selector.SelectedZone = oldZone;
                    }
                }
            }
            catch (Exception ee)
            {
                RimLog.Message("sync tick data exception at stage " + lockD + "\r\n" + ee.ToString());
            }
            AvoidLoop = false;
        }
示例#10
0
        public static bool FlushSyncTickData(int tickNum)
        {
            /*if (new System.Collections.ICollection[]
             * {
             *  singleton.jobsToSerialize,
             *  singleton.jobPriorities,
             *  singleton.designations,
             *  singleton.designatorCellCalls,
             *  singleton.designatorMultiCellCalls,
             *  singleton.ForbiddenCallDataCall
             * }.Any(u => { return u.Count > 0; }))*/
            {
                try
                {
#if FILE_TRANSFER
                    string s = @"D:\CoopReplays\_" + tickNum + "client_" + cliendID + ".xml";

                    //RimLog.Message("Written : " + s);
                    BinaryFormatter ser      = new BinaryFormatter();
                    var             fs       = System.IO.File.OpenWrite(s);
                    SyncTickData    buffered = singleton;
                    singleton = new SyncTickData();
                    ser.Serialize(fs, buffered);
                    fs.Flush();
                    fs.Close();
                    System.IO.File.WriteAllText(s + ".sync", "");
#else
                    if (cliendID > -1)
                    {
                        singleton.randomToVerify = new int[] { Verse.Rand.Int };
                        var colonists = Find.ColonistBar.GetColonistsInOrder();
                        singleton.colonistJobsToVerify     = colonists == null ? new List <string> {
                        } : colonists.ConvertAll <string>(u => u.CurJobDef == null ? u.ThingID + "::" + "<null>" : u.ThingID + "::" + u.CurJobDef.defName);
                        singleton.serializationServiceData = SerializationService.Flush();
                        BinaryFormatter ser = new BinaryFormatter()
                        {
                            TypeFormat = System.Runtime.Serialization.Formatters.FormatterTypeStyle.TypesWhenNeeded
                        };
                        SyncTickData buffered = singleton;
                        MemoryStream fs       = new MemoryStream();
                        singleton = new SyncTickData();
                        //RimLog.Message("sending data for tick " + tickNum);
                        NetDemo.PushStateToDirectory(cliendID, tickNum, buffered, 0);
                        fs.Close();
                        return(true);
                    }
                    return(false);
#endif
                }
                catch (Exception ee)
                {
                    RimLog.Error(ee.ToString());
                    return(false);
                }
            }
        }
示例#11
0
        public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
        {
            int   idNumber = info.GetInt32("pawn_thingid");
            Thing t        = ThingRegistry.tryGetThing(idNumber);

            if (t == null)
            {
                RimLog.Message("Could not locate a pawn with thingid " + idNumber);
            }
            return(t);
        }
示例#12
0
 static void GenerateMap()
 {
     if (Find.Root)
     {
         //Find.Root.Start();
     }
     else
     {
         RimLog.Message("Null root");
     }
 }
示例#13
0
        static DesignationDef DefFromString(string name)
        {
            foreach (var fi in typeof(RimWorld.DesignationDefOf).GetFields())
            {
                if (fi.GetValue(null).ToString() == name)
                {
                    return(fi.GetValue(null) as DesignationDef);
                }
            }

            RimLog.Message("could not locate designation def : " + name);
            return(null);
        }
示例#14
0
            public static void postfix(Pawn p)
            {
                StackTrace st = new StackTrace();

                RimLog.Message("==========");
                foreach (var a in st.GetFrames())
                {
                    RimLog.Message(a.GetMethod().Name + "::" + a.GetMethod().DeclaringType);
                }

                RimLog.Message("pawn added to world : " + p);
                RimLog.Message("///==========");
            }
示例#15
0
 public static bool prefix_designate_thing(Thing t)
 {
     if (use_native)
     {
         RimLog.Message("+cancel on thing " + t.ThingID);
         return(true);
     }
     else
     {
         RimLog.Message("-cancel on thing " + t.ThingID);
         parrot_designate_thing(t);
         return(false);
     }
 }
示例#16
0
    public static bool prefix_designate_multicell(IEnumerable <IntVec3> cells, Designator_ZoneAdd __instance)
    {
        if (use_native)
        {
            return(true);
        }
        else
        {
            System.Type t = __instance.GetType();
            Zone        z = Find.Selector.SelectedZone;
            RimLog.Message("zone type : " + __instance.GetType());

            {
                parrot_designate_multicell(cells, __instance.GetType(), z);
            }
            return(false);
        }
    }
示例#17
0
        public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
        {
            string    recipeDefName = info.GetString("recipedef");
            BillStack st            = (BillStack)info.GetValue("bill_stack", typeof(BillStack));

            RimLog.Message("bill lacks pawn restriction in surrogate!");
            RimLog.Message("billstack is null ? " + (st == null ? "yes" : "no"));
            RimLog.Message("bill giver as thing : " + (st.billGiver as Thing));
            RimLog.Message("bill giver def as thing : " + (st.billGiver as Thing).def);

            foreach (var rec in (st.billGiver as Thing).def.recipes)
            {
                if (rec.defName == recipeDefName)
                {
                    return(BillUtility.MakeNewBill(rec));
                }
            }

            RimLog.Message("could not make bill!");
            return(null);
        }
示例#18
0
    public static void WaitForConnection(string host)
    {
        tc = new TcpClient();
        tc.Client.NoDelay = true;
        tc.Connect(host, 12345);
        ns               = tc.GetStream();
        hasClientID      = false;
        forcedDisconnect = false;
        try
        {
            LongEventHandler.QueueLongEvent(() =>
            {
                PirateRPC.PirateRPC.SendInvocation(ns, u =>
                {
                    int cid = SyncTickData.cliendID;
                    Interlocked.Increment(ref SyncTickData.cliendID);
                    NetDemo.ServerHandlePlayerJoined(cid, u);
                });

                for (; !hasClientID && !forcedDisconnect;)
                {
                }
            }, "Waiting for server".Translate(), true, e => { RimLog.Error(e.ToString()); });
        }
        catch (Exception ee)
        {
            log(ee.ToString());
        }

        Thread t = new Thread(() =>
        {
            for (;  ;)
            {
                PirateRPC.PirateRPC.ReceiveInvocation(ns);
            }
        });

        t.Start();
    }
示例#19
0
 public static void parrot_designate_single_cell(IntVec3 c, Rot4 placingRot, Thing thingToInstall)
 {
     use_native = true;
     try
     {
         var sel = Find.Selector.SelectedObjects;
         Find.Selector.ClearSelection();
         Designator_Install ins = (Designator_Install)DesignatorUtility.FindAllowedDesignator <Designator_Install>();
         var field = ins.GetType().GetField("placingRot", BindingFlags.NonPublic | BindingFlags.Instance);
         RimLog.Message("thing : " + thingToInstall);
         RimLog.Message("field : " + field);
         field.SetValue(ins, placingRot);
         Rand.PushState(0);
         Find.Selector.Select(thingToInstall, false, false);
         ins.DesignateSingleCell(c);
         Find.Selector.ClearSelection();
         sel.ForEach(u => Find.Selector.Select(u, false, false));
     }
     finally
     {
         use_native = false;
     }
 }
示例#20
0
 public CooperateRimming()
 {
     RimLog.Init(this.Logger);
 }
示例#21
0
 static void ErrorHandler(System.Exception ex)
 {
     RimLog.Message(ex.ToString());
 }
示例#22
0
 public static void SetClientID(int id)
 {
     RimLog.Message("RECEIVED CLIENT ID = " + id);
     cliendID = id;
 }
示例#23
0
        public static bool Prefix(ref int ___ticksGameInt, ref TickManager __instance)
        {
            Rand.PushState(___ticksGameInt);
            getValuePatch.SendDiagDataToServer();
            getValuePatch.diagData.Clear();
            CooperateRimming.dumpRand = true;

            if (sw == null)
            {
                sw    = new Stopwatch();
                ACKSW = new Stopwatch();
                sw.Start();
                ACKSW.Start();

                /*fix for newly loaded game*/
                TickManagerPatch.nextCommunicationTick = Verse.Find.TickManager.TicksGame;
                TickManagerPatch.nextProcessionTick    = Verse.Find.TickManager.TicksGame;

                if (!imInSync)
                {
                    if (nextCommunicationTick == Verse.Find.TickManager.TicksGame)
                    {
                        imInSync = SyncTickData.FlushSyncTickData(nextProcessionTick + syncRoundLength * syncTickRoundOffset);
                    }
                }

                if (cachedData == null)
                {
                    return(false);
                }
                //for (; cachedData == null;)
                {
                }
            }
            shouldReallyTick = false;

            if (NetDemo.HasAllDataForFrame(Verse.Find.TickManager.TicksGame))
            {
                NetDemo.Receive();
            }

            if (sw.ElapsedMilliseconds > (1000 / ticksPerSecond) && !__instance.Paused)
            {
                sw.Reset();
                sw.Start();
                bool canNormallyTick = nextProcessionTick > Verse.Find.TickManager.TicksGame;

                //RimLog.Message("Tick " + ___ticksGameInt + " canNormallyTick " + canNormallyTick + "| comm " + nextCommunicationTick + " | " + nextProcessionTick);

                if (canNormallyTick)
                {
                    //Utilities.RimLog.Message("normal tick at " + Verse.Find.TickManager.TicksGame + " nsync " + nextSyncTickValue);
                    ulong i = 0;
                    foreach (var act in RandContextCounter.replacement_seed)
                    {
                        act((ulong)___ticksGameInt + (i++));
                    }
                    __instance.DoSingleTick();
                }

                if (SyncTickData.cliendID > -1 && ACKSW.ElapsedMilliseconds > 50)
                {
                    ACKSW.Reset();
                    ACKSW.Start();
                    //RimLog.Message("Sending state request for " + nextSyncTickValue);
                    //NetDemo.SendStateRequest(nextSyncTickValue, SyncTickData.cliendID);
                }


                if (!imInSync)
                {
                    if (nextCommunicationTick == Verse.Find.TickManager.TicksGame)
                    {
                        imInSync = SyncTickData.FlushSyncTickData(nextProcessionTick + syncRoundLength * syncTickRoundOffset);
                    }
                }

                {
                    if (nextProcessionTick == Verse.Find.TickManager.TicksGame)
                    {
#if FILE_TRANSFER
                        bool allSyncDataAvailable = SyncTickData.tickFileNames(___ticksGameInt).All(u => System.IO.File.Exists(u + ".sync"));
#else
#endif

                        //RimLog.Message("Frame " + ___ticksGameInt + " : " + " ::: " + allSyncDataAvailable + "[" + ___ticksGameInt + "] :: " + nextSyncTickValue + " [is synced : ] " + imInSync);

                        Action onA = LocalDB.OnApply;

                        if (cachedData != null)
                        {
                            IsSyncTick = true;

                            //RimLog.Message("Synctick happened at " + ___ticksGameInt);

                            SyncTickData.IsDeserializing = true;
                            //JobTrackerPatch.FlushCData();
                            shouldReallyTick = true;
                            streamholder.WriteLine("pre-deserialize tick at " + Verse.Find.TickManager.TicksGame, "tickstate");
                            streamholder.WriteLine("data applied at " + Verse.Find.TickManager.TicksGame, "tickstate");

                            //lock (LocalDB.OnApply)
                            {
                                Rand.PushState(___ticksGameInt);
                                try
                                {
                                    //RimLog.Message("applying at tick " + Verse.Find.TickManager.TicksGame);

                                    var cd = cachedData;
                                    cachedData = null;

                                    ulong i = 0;
                                    foreach (var act in RandContextCounter.replacement_seed)
                                    {
                                        act((ulong)___ticksGameInt + (i++));
                                    }

                                    foreach (var a in cd)
                                    {
                                        a.AcceptResult();
                                    }

                                    TickManagerPatch.SetSyncTickValue(nextProcessionTick + syncRoundLength);
                                    nextCommunicationTick += syncRoundLength;
                                    //Interlocked.Exchange(ref LocalDB.OnApply, null);
                                    //LocalDB.clientLocalStorage.ForEach(u => u.Value.AcceptResult());

                                    //nextSyncTickValue = Verse.Find.TickManager.TicksGame + syncRoundLength;
                                }
                                catch (Exception ee)
                                {
                                    RimLog.Message(ee.ToString());
                                }
                                Rand.PopState();

                                LocalDB.clientLocalStorage.Clear();
                            }
                            //SyncTickData.Apply(___ticksGameInt);
                            //__instance.DoSingleTick();

                            imInSync = false;
                        }
                    }
                }
            }

            //ReferenceTranspilerMethod(ref ___ticksGameInt);
            Rand.PopState();
            return(false);
        }