Beispiel #1
0
        static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions)
        {
            CodeMatcher matcher = new CodeMatcher(instructions)
                                  .MatchForward(false,
                                                new CodeMatch(OpCodes.Ldc_R4),
                                                new CodeMatch(OpCodes.Ldarg_0),
                                                new CodeMatch(OpCodes.Ldfld),
                                                new CodeMatch(i =>
                                                              i.opcode == OpCodes.Callvirt && ((MethodInfo)i.operand).Name == "GetVeinsInAreaNonAlloc"))
                                  .SetInstructionAndAdvance(new CodeInstruction(OpCodes.Ldloc_3))
                                  .InsertAndAdvance(
                Transpilers.EmitDelegate <Func <BuildPreview, float> >(preview => DSPAdvancedMiner.getMinerRadius(preview.desc) + 4)
                ).MatchForward(true,
                               new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(Vector3), nameof(Vector3.Dot))),
                               new CodeMatch(OpCodes.Stloc_S),
                               new CodeMatch(OpCodes.Ldloc_S),
                               new CodeMatch(OpCodes.Ldc_R4))
                                  .SetInstructionAndAdvance(new CodeInstruction(OpCodes.Ldloc_3))
                                  .InsertAndAdvance(
                Transpilers.EmitDelegate <Func <BuildPreview, float> >(preview =>
            {
                float radius = DSPAdvancedMiner.getMinerRadius(preview.desc);
                return(radius * radius);
            })
                );

            return(matcher.InstructionEnumeration());
        }
Beispiel #2
0
 public static void Postfix(BuildGizmoDesc _desc, Transform ___minerFan)
 {
     if (_desc.desc.minerType == EMinerType.Vein)
     {
         float size = 2 * DSPAdvancedMiner.getMinerRadius(_desc.desc);
         ___minerFan.localScale       = new Vector3(size, size, size);
         ___minerFan.localEulerAngles = new Vector3(0f, 180f, 0f);
     }
 }
Beispiel #3
0
        public static bool Prefix(ref string filename)
        {
            if (filename.Contains("custommachines"))
            {
                filename = $"{DSPAdvancedMiner.vertaFolder}/{filename}";

                DSPAdvancedMiner.logDebug("Loading my verta file " + filename);
            }

            return(true);
        }
Beispiel #4
0
        public static void Postfix(ItemProto[,] ___protos)
        {
            DSPAdvancedMiner.logDebug("Patching UIBuildMenu");

            foreach (var kv in DSPAdvancedMiner.items)
            {
                int buildIndex = kv.Value.BuildIndex;
                if (buildIndex > 0)
                {
                    int num  = buildIndex / 100;
                    int num2 = buildIndex % 100;
                    if (num <= 12 && num2 <= 12)
                    {
                        ___protos[num, num2] = kv.Value;
                    }
                }
            }
        }
Beispiel #5
0
        public static bool Prefix(ref string path, Type systemTypeInstance, ref UnityEngine.Object __result)
        {
            if (path.Contains("custommachines"))
            {
                DSPAdvancedMiner.logDebug("Loading my asset " + path);
                if (DSPAdvancedMiner.bundle.Contains(path + ".prefab") && systemTypeInstance == typeof(GameObject))
                {
                    Material[]         mats     = DSPAdvancedMiner.modelMats[path];
                    UnityEngine.Object myPrefab = DSPAdvancedMiner.bundle.LoadAsset(path + ".prefab");
                    if (myPrefab != null)
                    {
                        MeshRenderer[] renderers = ((GameObject)myPrefab).GetComponentsInChildren <MeshRenderer>();
                        foreach (MeshRenderer renderer in renderers)
                        {
                            Material[] newMats = new Material[renderer.sharedMaterials.Length];
                            for (int i = 0; i < newMats.Length; i++)
                            {
                                newMats[i] = mats[i];
                            }

                            renderer.sharedMaterials = newMats;
                        }
                    }

                    __result = myPrefab;
                    return(false);
                }

                if (DSPAdvancedMiner.bundle.Contains(path + ".png"))
                {
                    UnityEngine.Object mySprite = DSPAdvancedMiner.bundle.LoadAsset(path + ".png", systemTypeInstance);
                    __result = mySprite;
                    return(false);
                }
            }

            return(true);
        }
Beispiel #6
0
        public static void Postfix(int id, ItemProto newProto, PlanetFactory __instance)
        {
            if (id == 0 || __instance.entityPool[id].id == 0)
            {
                return;
            }
            if (__instance.entityPool[id].minerId <= 0)
            {
                return;
            }
            MinerComponent component = __instance.factorySystem.minerPool[__instance.entityPool[id].minerId];

            if (component.type != EMinerType.Vein)
            {
                return;
            }

            PrefabDesc desc = newProto.prefabDesc;

            Pose pose;

            pose.position = __instance.entityPool[id].pos;
            pose.rotation = __instance.entityPool[id].rot;

            int[]   tmp_ids             = new int[256];
            Vector3 vector3             = pose.position + pose.forward * -1.2f;
            Vector3 rhs                 = -pose.forward;
            Vector3 up                  = pose.up;
            int     veinsInAreaNonAlloc =
                __instance.planet.physics.nearColliderLogic.GetVeinsInAreaNonAlloc(vector3, DSPAdvancedMiner.getMinerRadius(desc) + 4, tmp_ids);

            int[] refArray = new int[veinsInAreaNonAlloc];

            VeinData[] veinPool = __instance.planet.factory.veinPool;
            int        refCount = 0;

            for (int j = 0; j < veinsInAreaNonAlloc; j++)
            {
                if (tmp_ids[j] != 0 && veinPool[tmp_ids[j]].id == tmp_ids[j])
                {
                    if (veinPool[tmp_ids[j]].type != EVeinType.Oil)
                    {
                        Vector3 pos     = veinPool[tmp_ids[j]].pos;
                        Vector3 vector4 = pos - vector3;
                        float   num8    = Vector3.Dot(up, vector4);
                        vector4 -= up * num8;
                        float sqrMagnitude = vector4.sqrMagnitude;
                        float num9         = Vector3.Dot(vector4.normalized, rhs);
                        float radius       = DSPAdvancedMiner.getMinerRadius(desc);
                        if (sqrMagnitude <= radius * radius && num9 >= 0.73f && Mathf.Abs(num8) <= 2f)
                        {
                            refArray[refCount++] = tmp_ids[j];
                        }
                    }
                }
            }

            component.InitVeinArray(refCount);
            if (refCount > 0)
            {
                Array.Copy(refArray, component.veins, refCount);
            }

            for (int i = 0; i < component.veinCount; i++)
            {
                __instance.RefreshVeinMiningDisplay(component.veins[i], component.entityId, 0);
            }

            component.ArrageVeinArray();
            __instance.factorySystem.minerPool[__instance.entityPool[id].minerId] = component;
        }