Quellcode durchsuchen

[ScrapYard] [2.0.3.6] destroy world and logs

Zariteis vor 4 Jahren
Ursprung
Commit
21333f3dff

+ 33 - 0
ScrapYard/Patches/Patch_Chunk_OnDestroy.cs

@@ -0,0 +1,33 @@
+using GadgetCore.API;
+using HarmonyLib;
+using UnityEngine;
+
+namespace ScrapYard.Patches
+{
+  [HarmonyPatch(typeof(Chunk))]
+  [HarmonyPatch("OnDestroy")]
+  [HarmonyGadget("ScrapYard")]
+  static class Patch_Chunk_OnDestroy
+  {
+    [HarmonyPrefix]
+    public static void Prefix(ref GameObject[] ___networkStuff)
+    {
+      if (___networkStuff.Length > 40)
+      {
+        Core.logger.Log("Destroying large Planet");
+        if (Network.isServer)
+        {
+          for (int i = 0; i < ___networkStuff.Length; i++)
+          {
+            if (___networkStuff[i])
+            {
+              Network.RemoveRPCs(___networkStuff[i].GetComponent<NetworkView>().viewID);
+              Network.Destroy(___networkStuff[i].gameObject);
+            }
+          }
+        }
+        ___networkStuff = new GameObject[40];
+      }
+    }
+  }
+}

+ 1 - 0
ScrapYard/Patches/Patch_GameScript_Talk.cs

@@ -15,6 +15,7 @@ namespace ScrapYard.Patches
       if (a < 0)
       {
         __instance.StartCoroutine(__instance.ExitTalking());
+        Core.logger.Log("Stop talking");
         return false;
       }
       return true;

+ 1 - 0
ScrapYard/Patches/Patch_KylockeStand_Awake.cs

@@ -22,6 +22,7 @@ namespace ScrapYard.Patches
       yield return new WaitForSeconds(2f);
       if (instance.itemID >= 2000 && instance.itemID < 2500 || instance.itemID == ItemRegistry.GetItemIDByRegistryName("Gadget Core:Crafter Block"))
       {
+        Core.logger.Log("Hiding a Default Stand with Item " + instance.itemID);
         instance.gameObject.SetActive(false);
       }
       yield break;

+ 26 - 5
ScrapYard/ScrapYard.cs

@@ -10,7 +10,7 @@ namespace ScrapYard
   [Gadget("ScrapYard")]
   public class ScrapYard : Gadget<ScrapYard>
   {
-    public const string MOD_VERSION = "1.0"; // Set this to the version of your mod.
+    public const string MOD_VERSION = "1.2"; // Set this to the version of your mod.
     public const string CONFIG_VERSION = "1.0"; // Increment this whenever you change your mod's config file.
 
     protected override void LoadConfig()
@@ -61,6 +61,8 @@ namespace ScrapYard
 
       Texture2D textureScrapTrophy = GadgetCoreAPI.LoadTexture2D("iScrapTrophy.png");
 
+      Logger.Log("Loaded Textures");
+
       PlanetInfo scrapYardPlanet = new PlanetInfo(PlanetType.SPECIAL, "Scrap Yard", new GadgetCore.Util.Tuple<int, int>[] { new GadgetCore.Util.Tuple<int, int>(1, 100) });
       scrapYardPlanet.SetPortalInfo(texturePortalSign, texturePlanetPrevIcon, texturePlanetIcon);
       scrapYardPlanet.SetBackgroundInfo(textureParalex, textureParalex0, textureParalex1, textureParalex2, textureParalex3);
@@ -71,6 +73,8 @@ namespace ScrapYard
 
       scrapYardPlanet.PortalUses = -1;
 
+      Logger.Log("Created Planet");
+
       new ItemInfo(ItemType.GENERIC, "Scrap Trophy", "A rusty trophy.\nUsed for purchasing\nspecial items.", textureScrapTrophy).Register("Scrap Trophy");
 
       { // Scrap Yard Bulding
@@ -247,6 +251,8 @@ namespace ScrapYard
         tile.OnInteract += OnInteractStand;
       }
 
+      Logger.Log("Created Prefabes");
+
       // Setting up default shop platforms
       new ShopPlatform("Default Objects", ShopPlatformSpacingType.Near).Register();
       new ShopPlatform("Default Blocks", ShopPlatformSpacingType.Near).Register();
@@ -273,7 +279,11 @@ namespace ScrapYard
 
       ShopPlatform.DefaultWalls.AddShopPlatformEntry(new ShopPlatformEntry(2200, 50));
 
+      Logger.Log("Added Default Objects to the Planet");
+
       SceneManager.sceneLoaded += OnSceneLoaded;
+
+      Logger.Log("Added Scene Hook");
     }
 
     internal static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
@@ -283,6 +293,7 @@ namespace ScrapYard
         try
         {
           var storageMenu = GameObject.Find("Ship").transform.Find("SHIPPLACES").transform.Find("mech").localPosition = new Vector3(-130f, -5.23f, 0.6f);
+          Core.logger.Log("Moved the Mech");
         }
         catch (System.Exception e) { Core.logger.LogError(e.Message); }
       }
@@ -293,10 +304,20 @@ namespace ScrapYard
 
     private IEnumerator OnInteractStand()
     {
-      PlayerScript.curInteractObj.SendMessage("Request");
-      canInteractField.SetValue(InstanceTracker.PlayerScript, true);
-      interactingField.SetValue(InstanceTracker.PlayerScript, false);
-      InstanceTracker.PlayerScript.w.SetActive(true);
+      Core.logger.Log("Start Interaction Stand");
+      try
+      {
+        PlayerScript.curInteractObj.SendMessage("Request");
+        Core.logger.Log("Requested Item");
+        canInteractField.SetValue(InstanceTracker.PlayerScript, true);
+        interactingField.SetValue(InstanceTracker.PlayerScript, false);
+        InstanceTracker.PlayerScript.w.SetActive(true);
+        Core.logger.Log("Finished Interaction Stand");
+      }
+      catch(System.Exception e)
+      {
+        Core.logger.Log(e);
+      }
       yield break;
     }
 

+ 1 - 1
ScrapYard/ScrapYardGenerator.cs

@@ -65,7 +65,7 @@ namespace ScrapYard
 
     public static void PopulateTown(Chunk chunk)
     {
-      var networkStuff = new GameObject[40];
+      var networkStuff = new GameObject[400];
       networkStuffField.SetValue(chunk, networkStuff);
 
       try

+ 6 - 0
ScrapYard/ScrapYardShopStandScript.cs

@@ -115,14 +115,19 @@ namespace ScrapYard
 
     private void Request()
     {
+      Core.logger.Log("Requesting Item in Stand");
       var gameScript = (GameScript)Camera.main.GetComponent("GameScript");
       int num = GetItemAmount(gameScript, currencyItemID);
 
+
+      Core.logger.Log("Got a Price for the Stand: " + num);
+
       if (num >= price)
       {
         base.GetComponent<AudioSource>().PlayOneShot((AudioClip)Resources.Load("Au/purchase"), Menuu.soundLevel / 10f);
         RemoveItemAmount(gameScript, currencyItemID, price);
         Item item = new Item(itemID, quantity, 0, 0, 0, new int[3], new int[3]);
+        Core.logger.Log("Spawn item");
         GadgetCoreAPI.SpawnItem(base.transform.position, item);
       }
       else if (itemID != 0)
@@ -131,6 +136,7 @@ namespace ScrapYard
         GameObject gameObject = (GameObject)Object.Instantiate(Resources.Load("txtError"), MenuScript.player.transform.position, Quaternion.identity);
         gameObject.SendMessage("InitError", "Insufficient Currency!");
       }
+      Core.logger.Log("End Shop request");
     }
 
     public int itemID = 1;