Exemplo n.º 1
0
        public static WaymarkPreset Parse(GamePreset gamePreset)
        {
            WaymarkPreset newPreset = new WaymarkPreset();

            newPreset.A.X      = gamePreset.A.X / 1000.0f;
            newPreset.A.Y      = gamePreset.A.Y / 1000.0f;
            newPreset.A.Z      = gamePreset.A.Z / 1000.0f;
            newPreset.A.Active = gamePreset.ActiveMarkers[0];
            newPreset.A.ID     = 0;

            newPreset.B.X      = gamePreset.B.X / 1000.0f;
            newPreset.B.Y      = gamePreset.B.Y / 1000.0f;
            newPreset.B.Z      = gamePreset.B.Z / 1000.0f;
            newPreset.B.Active = gamePreset.ActiveMarkers[1];
            newPreset.B.ID     = 1;

            newPreset.C.X      = gamePreset.C.X / 1000.0f;
            newPreset.C.Y      = gamePreset.C.Y / 1000.0f;
            newPreset.C.Z      = gamePreset.C.Z / 1000.0f;
            newPreset.C.Active = gamePreset.ActiveMarkers[2];
            newPreset.C.ID     = 2;

            newPreset.D.X      = gamePreset.D.X / 1000.0f;
            newPreset.D.Y      = gamePreset.D.Y / 1000.0f;
            newPreset.D.Z      = gamePreset.D.Z / 1000.0f;
            newPreset.D.Active = gamePreset.ActiveMarkers[3];
            newPreset.D.ID     = 3;

            newPreset.One.X      = gamePreset.One.X / 1000.0f;
            newPreset.One.Y      = gamePreset.One.Y / 1000.0f;
            newPreset.One.Z      = gamePreset.One.Z / 1000.0f;
            newPreset.One.Active = gamePreset.ActiveMarkers[4];
            newPreset.One.ID     = 4;

            newPreset.Two.X      = gamePreset.Two.X / 1000.0f;
            newPreset.Two.Y      = gamePreset.Two.Y / 1000.0f;
            newPreset.Two.Z      = gamePreset.Two.Z / 1000.0f;
            newPreset.Two.Active = gamePreset.ActiveMarkers[5];
            newPreset.Two.ID     = 5;

            newPreset.Three.X      = gamePreset.Three.X / 1000.0f;
            newPreset.Three.Y      = gamePreset.Three.Y / 1000.0f;
            newPreset.Three.Z      = gamePreset.Three.Z / 1000.0f;
            newPreset.Three.Active = gamePreset.ActiveMarkers[6];
            newPreset.Three.ID     = 6;

            newPreset.Four.X      = gamePreset.Four.X / 1000.0f;
            newPreset.Four.Y      = gamePreset.Four.Y / 1000.0f;
            newPreset.Four.Z      = gamePreset.Four.Z / 1000.0f;
            newPreset.Four.Active = gamePreset.ActiveMarkers[7];
            newPreset.Four.ID     = 7;

            newPreset.MapID = gamePreset.ContentFinderConditionID;
            newPreset.Time  = DateTimeOffset.FromUnixTimeSeconds(gamePreset.UnixTime);

            return(newPreset);
        }
Exemplo n.º 2
0
        protected void OnTerritoryChanged(object sender, UInt16 ID)
        {
            ZoneInfo prevTerritoryTypeInfo = ZoneInfoHandler.GetZoneInfoFromTerritoryTypeID(CurrentTerritoryTypeID);
            ZoneInfo newTerritoryTypeInfo  = ZoneInfoHandler.GetZoneInfoFromTerritoryTypeID(ID);

            CurrentTerritoryTypeID = ID;
            mUI.SetCurrentTerritoryTypeID(ID);

            //	Auto-save presets on leaving instance.
            if (mConfiguration.AutoSavePresetsOnInstanceLeave && ZoneInfoHandler.IsKnownContentFinderID(prevTerritoryTypeInfo.ContentFinderConditionID))
            {
                for (uint i = 1; i <= MemoryHandler.MaxPresetSlotNum; ++i)
                {
                    try
                    {
                        var preset = WaymarkPreset.Parse(MemoryHandler.ReadSlot(i));
                        if (preset.MapID == prevTerritoryTypeInfo.ContentFinderConditionID && !mConfiguration.PresetLibrary.Presets.Any(x => x.Equals(preset)))
                        {
                            preset.Name = prevTerritoryTypeInfo.DutyName.ToString() + " - AutoImported";
                            mConfiguration.PresetLibrary.ImportPreset(preset);
                        }
                    }
                    catch (Exception e)
                    {
                        PluginLog.Log($"Error while attempting to auto-import game slot {i}: {e}");
                    }
                }

                mConfiguration.Save();
            }

            //	Auto-load presets on entering instance.
            if (mConfiguration.AutoPopulatePresetsOnEnterInstance && ZoneInfoHandler.IsKnownContentFinderID(newTerritoryTypeInfo.ContentFinderConditionID))
            {
                //*****TODO: Eventually maybe have this check for a "preferred" flag on the presets and use that to help select which five to use, rather than just the first five from the zone.
                var presetsToAutoLoad = mConfiguration.PresetLibrary.Presets.Where(x => x.MapID == newTerritoryTypeInfo.ContentFinderConditionID).Take(MemoryHandler.MaxPresetSlotNum).ToList();
                for (int i = 0; i < MemoryHandler.MaxPresetSlotNum; ++i)
                {
                    GamePreset gamePresetData = new GamePreset();

                    if (i < presetsToAutoLoad.Count)
                    {
                        var preset = presetsToAutoLoad[i];
                        gamePresetData = preset.GetAsGamePreset();
                    }

                    try
                    {
                        MemoryHandler.WriteSlot((uint)i + 1, gamePresetData);
                    }
                    catch (Exception e)
                    {
                        PluginLog.Log($"Error while auto copying preset data to game slot {i}: {e}");
                    }
                }
            }
        }
Exemplo n.º 3
0
 public GameWaymarks(GamePreset preset)
 {
     A     = new GameWaymark(preset.A, preset.ActiveMarkers[0]);
     B     = new GameWaymark(preset.B, preset.ActiveMarkers[1]);
     C     = new GameWaymark(preset.C, preset.ActiveMarkers[2]);
     D     = new GameWaymark(preset.D, preset.ActiveMarkers[3]);
     One   = new GameWaymark(preset.One, preset.ActiveMarkers[4]);
     Two   = new GameWaymark(preset.Two, preset.ActiveMarkers[5]);
     Three = new GameWaymark(preset.Three, preset.ActiveMarkers[6]);
     Four  = new GameWaymark(preset.Four, preset.ActiveMarkers[7]);
 }
Exemplo n.º 4
0
 private static void DirectPlacePreset(GamePreset preset)
 {
     if (IsSafeToDirectPlacePreset())
     {
         GamePreset_Placement placementStruct = new GamePreset_Placement(preset);
         unsafe
         {
             mdDirectPlacePreset.Invoke(mpWaymarksObj, new IntPtr(&placementStruct));
         }
     }
 }
Exemplo n.º 5
0
 public static void PlacePreset(GamePreset preset, bool allowClientSide = false)
 {
     if (allowClientSide && InOverworldZone())
     {
         PlacePreset_ClientSide(preset);
     }
     else
     {
         DirectPlacePreset(preset);
     }
 }
 public int ImportPreset(GamePreset gamePresetData)
 {
     try
     {
         WaymarkPreset importedPreset = WaymarkPreset.Parse(gamePresetData);
         importedPreset.Name = "Imported";
         Presets.Add(importedPreset);
         return(Presets.Count - 1);
     }
     catch
     {
         return(-1);
     }
 }
Exemplo n.º 7
0
        public GamePreset GetAsGamePreset()
        {
            GamePreset preset = new GamePreset();

            preset.ActiveMarkers[0] = A.Active;
            preset.A.X = A.Active ? (int)(A.X * 1000.0) : 0;
            preset.A.Y = A.Active ? (int)(A.Y * 1000.0) : 0;
            preset.A.Z = A.Active ? (int)(A.Z * 1000.0) : 0;

            preset.ActiveMarkers[1] = B.Active;
            preset.B.X = B.Active ? (int)(B.X * 1000.0) : 0;
            preset.B.Y = B.Active ? (int)(B.Y * 1000.0) : 0;
            preset.B.Z = B.Active ? (int)(B.Z * 1000.0) : 0;

            preset.ActiveMarkers[2] = C.Active;
            preset.C.X = C.Active ? (int)(C.X * 1000.0) : 0;
            preset.C.Y = C.Active ? (int)(C.Y * 1000.0) : 0;
            preset.C.Z = C.Active ? (int)(C.Z * 1000.0) : 0;

            preset.ActiveMarkers[3] = D.Active;
            preset.D.X = D.Active ? (int)(D.X * 1000.0) : 0;
            preset.D.Y = D.Active ? (int)(D.Y * 1000.0) : 0;
            preset.D.Z = D.Active ? (int)(D.Z * 1000.0) : 0;

            preset.ActiveMarkers[4] = One.Active;
            preset.One.X            = One.Active ? (int)(One.X * 1000.0) : 0;
            preset.One.Y            = One.Active ? (int)(One.Y * 1000.0) : 0;
            preset.One.Z            = One.Active ? (int)(One.Z * 1000.0) : 0;

            preset.ActiveMarkers[5] = Two.Active;
            preset.Two.X            = Two.Active ? (int)(Two.X * 1000.0) : 0;
            preset.Two.Y            = Two.Active ? (int)(Two.Y * 1000.0) : 0;
            preset.Two.Z            = Two.Active ? (int)(Two.Z * 1000.0) : 0;

            preset.ActiveMarkers[6] = Three.Active;
            preset.Three.X          = Three.Active ? (int)(Three.X * 1000.0) : 0;
            preset.Three.Y          = Three.Active ? (int)(Three.Y * 1000.0) : 0;
            preset.Three.Z          = Three.Active ? (int)(Three.Z * 1000.0) : 0;

            preset.ActiveMarkers[7] = Four.Active;
            preset.Four.X           = Four.Active ? (int)(Four.X * 1000.0) : 0;
            preset.Four.Y           = Four.Active ? (int)(Four.Y * 1000.0) : 0;
            preset.Four.Z           = Four.Active ? (int)(Four.Z * 1000.0) : 0;

            preset.ContentFinderConditionID = MapID;
            preset.UnixTime = (int)Time.ToUnixTimeSeconds();

            return(preset);
        }
Exemplo n.º 8
0
        public static bool WriteSlot(uint slotNum, GamePreset preset)
        {
            IntPtr pWaymarkData = GetGameWaymarkDataPointerForSlot(slotNum);

            if (pWaymarkData != IntPtr.Zero)
            {
                //	Don't catch exceptions here; better to have the caller do it probably.
                lock (mPresetMemoryLockObject) Marshal.StructureToPtr(preset, pWaymarkData, false);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 9
0
        public static GamePreset ReadSlot(uint slotNum)
        {
            IntPtr     pWaymarkData = GetGameWaymarkDataPointerForSlot(slotNum);
            GamePreset preset       = new GamePreset();

            if (pWaymarkData != IntPtr.Zero)
            {
                //	Don't catch exceptions here; better to have the caller do it probably.
                lock (mPresetMemoryLockObject) preset = (GamePreset)Marshal.PtrToStructure(pWaymarkData, typeof(GamePreset));
            }
            else
            {
                throw new ArgumentOutOfRangeException($"Error in \"WaymarkPresetPlugin.MemoryHandler.ReadSlot()\": Slot number ({slotNum}) was either invalid, or pointer for valid slot number could not be located.");
            }

            return(preset);
        }
Exemplo n.º 10
0
        private static void PlacePreset_ClientSide(GamePreset preset)
        {
            //	Check whether we shouldn't be doing this.
            if (!IsSafeToClientPlace())
            {
                return;
            }

            //	Find where we will be overwriting the waymarks.
            IntPtr pClientSideWaymarks = new IntPtr(mpWaymarksObj.ToInt64() + mClientSideWaymarksOffset.ToInt64());

            //*****TODO: Should we instead read in the extant data and only overwrite the floats?
            //GameWaymarks waymarkData = (GameWaymarks)Marshal.PtrToStructure( pClientSideWaymarks, typeof( GameWaymarks ) );
            //Write float coords and flags and send back out.
            //Marshal.StructureToPtr( waymarkData, pClientSideWaymarks, false );

            //	Do the actual writing.
            Marshal.StructureToPtr(new GameWaymarks(preset), pClientSideWaymarks, false);
        }
Exemplo n.º 11
0
        public GamePreset_Placement(GamePreset preset)
        {
            Active = new GamePreset_Placement_AxisActive(preset.ActiveMarkers);

            X = new GamePreset_Placement_AxisCoords();
            Y = new GamePreset_Placement_AxisCoords();
            Z = new GamePreset_Placement_AxisCoords();

            X.A = preset.A.X;
            Y.A = preset.A.Y;
            Z.A = preset.A.Z;

            X.B = preset.B.X;
            Y.B = preset.B.Y;
            Z.B = preset.B.Z;

            X.C = preset.C.X;
            Y.C = preset.C.Y;
            Z.C = preset.C.Z;

            X.D = preset.D.X;
            Y.D = preset.D.Y;
            Z.D = preset.D.Z;

            X.One = preset.One.X;
            Y.One = preset.One.Y;
            Z.One = preset.One.Z;

            X.Two = preset.Two.X;
            Y.Two = preset.Two.Y;
            Z.Two = preset.Two.Z;

            X.Three = preset.Three.X;
            Y.Three = preset.Three.Y;
            Z.Three = preset.Three.Z;

            X.Four = preset.Four.X;
            Y.Four = preset.Four.Y;
            Z.Four = preset.Four.Z;
        }
Exemplo n.º 12
0
        public static bool GetCurrentWaymarksAsPresetData(ref GamePreset rPresetData)
        {
            if (mPluginInterface != null && FoundDirectSaveSigs())
            {
                byte currentContentLinkType = mdGetCurrentContentFinderLinkType.Invoke();
                if (currentContentLinkType >= 0 && currentContentLinkType < 4)                  //	Same as the game check, but let it do overworld maps too.
                {
                    GamePreset_Placement rawWaymarkData = new GamePreset_Placement();
                    unsafe
                    {
                        mdGetCurrentWaymarkData.Invoke(mpWaymarksObj, new IntPtr(&rawWaymarkData));
                    }

                    rPresetData = new GamePreset(rawWaymarkData);
                    rPresetData.ContentFinderConditionID = ZoneInfoHandler.GetContentFinderIDFromTerritoryTypeID(mPluginInterface.ClientState.TerritoryType);                           //*****TODO: How do we get this as a territory type for non-instanced zones? The return type might need to be changed, or pass in another ref paramter or something. *****
                    rPresetData.UnixTime = (Int32)DateTimeOffset.UtcNow.ToUnixTimeSeconds();
                    return(true);
                }
            }

            return(false);
        }