Ejemplo n.º 1
0
 public static void OnSave(int slot, int backupSlot = -1)
 {
     if (Randomizer.Memory.PlayerStats.Health == 0)
     {
         DidWeJustDie = true;
         return; // the game saves right when you die, but we don't want to save progress when that happens.
     }
     if (slot == -1)
     {
         Randomizer.Log("Error: tried to save to empty slot");
         return;
     }
     if (slot != CurrentSlot)
     {
         // this is a slot swap and not a save
         CurrentSlot = slot;
         Data        = new SaveData(slot);
         Data.Load(backupSlot);
         if (Randomizer.InputUnlockCallback != null)
         {
             AHK.Print("Warning: Callback overwritten on slot change!", 240);
             Randomizer.InputUnlockCallback = null;
         }
         return;
     }
     Data.Save(backupSlot);
 }
        public static void ReadSeed()
        {
            var seedName = File.ReadAllText(Randomizer.SeedNameFile);

            if (seedName.Trim() != "")
            {
                pickupMap.Clear();
                foreach (var line in File.ReadLines(Randomizer.SeedFile))
                {
                    try {
                        var frags      = line.Split('|');
                        var uberId     = new UberId(int.Parse(frags[0]), int.Parse(frags[1]));
                        var pickupType = (PickupType)byte.Parse(frags[2]);
                        //                    Randomizer.Log($"uberId {uberId} -> {pickupType} {frags[3]}");
                        pickupMap[uberId] = BuildPickup(pickupType, frags[3]);
                    } catch (Exception e) {
                        Randomizer.Log($"Error parsing line: '{line}'\nError: {e.Message} \nStacktrace: {e.StackTrace}", false);
                    }
                }
                AHK.Print($"Seed {seedName} loaded", 300);
            }
            else
            {
                AHK.Print($"No seed loaded; Download a .wotwr file and double-click it to load one", 360);
            }
        }
        public static void OnUberState(UberState state)
        {
            var id = state.GetUberId();

            if (pickupMap.TryGetValue(id, out Pickup p))
            {
                AHK.Print(p.ToString());
                p.Grant();
                Randomizer.PleaseSave = true;
            }
        }
Ejemplo n.º 4
0
 public static void Log(string message, bool printIfDev = true, string level = "INFO")
 {
     if (AHK.IniFlag("MuteCSLogs"))
     {
         return;
     }
     logQueue.Add($"{DateTime.Now:[yyyy-MM-dd HH:mm:ss.fff]} [{level}]: {message}\n");
     if (Dev && printIfDev)
     {
         AHK.Print(message, 180, toMessageLog: false);
     }
 }
        public static void OnTree(AbilityType ability)
        {
            UberId fakeId = new UberId((int)FakeUberGroups.TREE, (int)ability);

            if (pickupMap.TryGetValue(fakeId, out Pickup p))
            {
                AHK.Print(p.ToString());
                p.Grant();
                Randomizer.PleaseSave = true;
            }
            else
            {
                Randomizer.Log($"Tree {ability} not found in seed. Get a seed from seedpack 10 or later.");
            }
        }
Ejemplo n.º 6
0
 public static void Log(string message, bool printIfDev = true, string level = "INFO")
 {
     if (AHK.IniFlag("MuteCSLogs"))
     {
         return;
     }
     if (level == "DEBUG" && !Dev)
     {
         return;
     }
     File.AppendAllText(LogFile, $"{DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss.fff]")} [{level}]: {message}\n");
     if (Dev && printIfDev)
     {
         AHK.Print(message, 180, false);
     }
 }
 public static void Log(string message, bool printIfDev = true)
 {
     if (AHK.IniFlag("MuteCSLogs"))
     {
         return;
     }
     if (LastMessage == message && message.Length > 60)
     {
         repeats++;
         if (repeats > 180)
         {
             repeats = 0;
             File.AppendAllText(LogFile, "suppressed repeats x180\n");
         }
         return;
     }
     LastMessage = message;
     File.AppendAllText(LogFile, message + "\n");
     if (Dev && printIfDev)
     {
         AHK.Print(message);
     }
 }
Ejemplo n.º 8
0
 public static void OnLoad(int slot, int backupSlot = -1)
 {
     try {
         if (slot != CurrentSlot)
         {
             if (Randomizer.InputUnlockCallback != null)
             {
                 AHK.Print("Warning: Callback overwritten on slot change!", 240);
                 Randomizer.InputUnlockCallback = null;
             }
             // slot swap
             CurrentSlot = slot;
             Data        = new SaveData(slot);
         }
         UberStateController.SkipListenersNextUpdate = true;
         Data.Load(backupSlot);
         if (DidWeJustDie)
         {
             InterOp.magic_function();
         }
     }
     catch (Exception e) { Randomizer.Error("SaveCont.OnLoad", e); }
 }
Ejemplo n.º 9
0
        public static bool Initialize()
        {
            try {
                if (logThread == null)
                {
                    logThread = new Thread(() => {
                        while (true)
                        {
                            try {
                                var txt = logQueue.Take();
                                while (logQueue.TryTake(out var line))
                                {
                                    txt += line;
                                }
                                File.AppendAllText(LogFile, txt);
                            } catch (Exception e) {
                                if (Dev)
                                {
                                    AHK.Print($"error logging: {e}", toMessageLog: false);
                                }
                            }
                        }
                    });
                    logThread.Start();
                }

                BasePath = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(InterOp.get_base_path());
                Debug($"Init: set base path to {BasePath}");

                if (!Directory.Exists(SaveFolder))
                {
                    Directory.CreateDirectory(SaveFolder);
                }

                if (!File.Exists(SeedPathFile))
                {
                    File.WriteAllText(SeedPathFile, BasePath + ".currentseed");
                }

                foreach (var fileName in new string[] { LogFile, MessageLog })
                {
                    if (!File.Exists(fileName))
                    {
                        File.WriteAllText(fileName, "");
                        Log($"Wrote blank {fileName} (normal for first-time init)");
                    }
                }

                AHK.Init();
                SeedController.ReadSeed(true);

                Client.UberStateRegistered = UberStateController.RegisterSyncedUberState;
                DiscordController.Initialize();

                Debug("Init: Complete", false);
                return(true);
            } catch (Exception e) {
                Log($"init error: {e.Message}\n{e.StackTrace}");
                return(true);
            }
        }
        public static void NewGameInit()
        {
            if (!InterOp.is_loading_game())
            {
                InterOp.clear_quest_messages();
                Randomizer.Log($"New Game Init - {SeedController.SeedName}", false);
                ShopController.SetCostsAfterInit();

                foreach (UberState s in DefaultUberStates)
                {
                    s.Write();
                }
                foreach (UberState s in Kuberstates)
                {
                    s.Write();
                }
                foreach (UberState s in DialogAndRumors)
                {
                    s.Write();
                }

                if (SeedController.KSDoorsOpen)
                {
                    foreach (UberState s in KeystoneDoors)
                    {
                        s.Write();
                    }
                }

                if (!AHK.IniFlag("ShowShortCutscenes"))
                {
                    foreach (UberState s in ShortCutscenes)
                    {
                        s.Write();
                    }
                }

                if (!AHK.IniFlag("ShowLongCutscenes"))
                {
                    foreach (UberState s in LongCutscenes)
                    {
                        s.Write();
                    }
                }

                InterOp.discover_everything();
                if (SeedController.Settings.LegacySeedgen && !SeedController.Flags.Contains(Flag.NOSWORD))
                {
                    SaveController.SetAbility(AbilityType.SpiritEdge);
                    var slotRaw = AHK.IniString("Misc", "SpawnSlot");
                    var slot    = 0;
                    if (slotRaw != string.Empty)
                    {
                        slot = slotRaw.ParseToInt("Spawn Slot Ini") - 1;
                        if (slot > 2 || slot < 0)
                        {
                            AHK.Print($"Ignoring invalid slot specifier {slotRaw}", toMessageLog: false);
                            slot = 0;
                        }
                    }
                    InterOp.bind(slot, 1002);
                }
                if (PsuedoLocs.GAME_START.Pickup().NonEmpty)
                {
                    Randomizer.InputUnlockCallback = () => {
                        MapController.UpdateReachable(2000);
                        PsuedoLocs.GAME_START.OnCollect();
                        InterOp.save();
                    };
                }
                else
                {
                    MapController.UpdateReachable();
                }
                InterOp.set_shard_slots(3);
                InterOp.save();

                NeedsNewGameInit = false;
            }
        }