The Long Dark Modding Wiki
Advertisement

Here we have code snippets to reference[]

*Time Acceleration[]

Credit TTR:

this might be interesting to someone -> when you use time acceleration, like sleep, pass time, actions, or console command, all Update() functions will be triggered, but in end, there is TodMaterial.UpdateAll() also, which will recalculate "things" based on how much time was skipped

so, eg, when you patch fire.update() to change burning time, and skip time, this will get nasty

in vanilla (or by TodMaterial.UpdateAll()) embers (max) where not calculated but burn time was, and then normal update will kick int to decide to what to do now, if your patched update does something like calculate burn time based on temerature, ember storage that time will be removed twice.

bottom line, passing/acceleration of time and update patches doe not go well together

if (GameManager.GetTimeOfDayComponent().IsTimeLapseActive())
{
    if (!FADForceReload)
    {
        FADForceReload = true;
    }
}
else
{
    if (FADForceReload)
    {
        applyStoredFAD(__instance, guid);
        FADForceReload = false;
    }
    // rest of code
}

someone might find this usefull

*[]

Credit:Leonardevvil and ds5678

private const string IMPROVISED_NAME = "GEAR_LeatherHide";
       private const string HUNTING_NAME = "GEAR_Leather";
       private const string SCRAP_METAL_NAME = "GEAR_ScrapMetal";
       private const string SCRAP_METAL_CRAFTING_ICON_NAME = "ico_CraftItem__ScrapMetal";
       private const int SCRAP_METAL_NEEDED = 2;
       private const int CRAFTING_TIME = 360;

       [HarmonyPatch(typeof(GameManager), "Awake")]

       private static class AddBreakDownRecipe
       {
           internal static void Postfix()
           {
               BlueprintItem blueprint = GameManager.GetBlueprints().AddComponent<BlueprintItem>();

               // Inputs

               blueprint.m_RequiredGear = new Il2CppReferenceArray<GearItem>(1) { [0] = GetGearItemPrefab(IMPROVISED_NAME) };
               blueprint.m_RequiredGearUnits = new Il2CppStructArray<int>(1) { [0] = 1  };
               blueprint.m_KeroseneLitersRequired = 0f;
               blueprint.m_GunpowderKGRequired = 0f;
               blueprint.m_RequiredTool = null;
               blueprint.m_OptionalTools = new Il2CppReferenceArray<ToolsItem>(0);

               // Outputs

               blueprint.m_CraftedResult = GetGearItemPrefab(HUNTING_NAME);
               blueprint.m_CraftedResultCount = 2;

               // Process

               blueprint.m_Locked = false;
               blueprint.m_AppearsInStoryOnly = false;
               blueprint.m_RequiresLight = true;
               blueprint.m_RequiresLitFire = false;
               blueprint.m_RequiredCraftingLocation = CraftingLocation.Anywhere;
               blueprint.m_DurationMinutes = CRAFTING_TIME;
               blueprint.m_CraftingAudio = "PLAY_CRAFTINGGENERIC";
               blueprint.m_AppliedSkill = SkillType.None;
               blueprint.m_ImprovedSkill = SkillType.None;

           }

           private static GearItem GetGearItemPrefab(string name) => Resources.Load(name).Cast<GameObject>().GetComponent<GearItem>();

this code snnipet is for adding item in the game

*[]

Credits:Filigrani

bool axe = GameManager.GetInventoryComponent().HasNonRuinedItem("GEAR_Hatchet"); // Axe
                bool f_axe = GameManager.GetInventoryComponent().HasNonRuinedItem("GEAR_FireAxe"); // Fire axe
                bool h_axe = GameManager.GetInventoryComponent().HasNonRuinedItem("GEAR_HatchetImprovised"); // Handmade axe

                if (axe == true || f_axe == true || h_axe) // If have any axe
                {
                    MyHasAxe = true;
                }else
                {
                    MyHasAxe = false;
                }

Credits:Filigrani

MyHasAxe = GameManager.GetInventoryComponent().HasNonRuinedItem("GEAR_Hatchet");

Credits:Filigrani

 //Get movement speed.
            if(MyAnimState == "Run" || MyAnimState == "Walk")
            {
                Vector3 pastV3 = GameManager.GetPlayerTransform().position;
                float pastTime = Time.time;


                if(Time.time > pastTime)
                {
                    float distance = Vector3.Distance(pastV3, GameManager.GetPlayerTransform().position); // distance player has run.
                    float dif = Time.time - pastTime;
                    float speed = dif / distance;
                }
            }
 [HarmonyPatch(typeof(SaveGameSystem),"LoadSceneData")]
        internal static class clearCubeList
        {
            private static void Postfix()
            {
                BlockPlacement.cubelist = new Il2CppSystem.Collections.Generic.List<GameObject>(0);
            }
        }
  Vector3 SnappedPosition(Vector3 pointToSnap, Vector3 blockCenterPosition)
        {
            Vector3 relativePosition = pointToSnap - blockCenterPosition;

            if (relativePosition.x == 0.5f) return blockCenterPosition + Vector3.right;
            else if (relativePosition.x == -0.5f) return blockCenterPosition + Vector3.left;
            else if (relativePosition.y == 0.5f) return blockCenterPosition + Vector3.up;
            else if (relativePosition.y == -0.5f) return blockCenterPosition + Vector3.down;
            else if (relativePosition.z == 0.5f) return blockCenterPosition + Vector3.forward;
            else if (relativePosition.z == -0.5f) return blockCenterPosition + Vector3.back;
            else return Vector3.zero;  // error (should not occur)
        }
if (InputManager.GetKeyDown(InputManager.m_CurrentContext, KeyCode.B))
            {
                RaycastHit hitInfo;
                if (Physics.Raycast(GameManager.GetMainCamera().transform.position, GameManager.GetMainCamera().transform.forward, out hitInfo, 50))
                {
                    Vector3 instantiatePosition = SnappedPosition(hitInfo.point, hitInfo.collider.transform.position);

                    GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    cube.transform.position = instantiatePosition;
                }
            }


Advertisement