Exemplo n.º 1
0
    public static string GetFirstPlayerTownName(IRAMReadWriter rw)
    {
        ulong address = OffsetHelper.getPlayerIdAddress(SysBotController.CurrentOffsetFirstPlayerUInt) - 0xB8 + 0x04;

        byte[] tName = rw.ReadBytes(address, 20);
        return(StringUtil.GetString(tName, 0, 10));
    }
Exemplo n.º 2
0
        internal Dictionary <SlotType, List <InventoryData> > GetInventory()
        {
            Dictionary <SlotType, List <InventoryData> > inventory = new Dictionary <SlotType, List <InventoryData> >();

            var barItems = GetBarItems();

            inventory.Add(SlotType.Bar, barItems);

            var diffOffset = OffsetHelper.CalcOffsetDiffInventory(barItems);
            var invItems   = GetInvItems(diffOffset);

            inventory.Add(SlotType.Inv, invItems);

            diffOffset += OffsetHelper.CalcOffsetDiffInventory(invItems);
            var moneyItems = GetMoneyItems(diffOffset);

            inventory.Add(SlotType.Money, moneyItems);

            diffOffset += OffsetHelper.CalcOffsetDiffInventory(moneyItems);
            var ammoItems = GetAmmoItems(diffOffset);

            inventory.Add(SlotType.Ammo, ammoItems);

            OffsetHelper.InventoryLength = diffOffset + OffsetHelper.CalcOffsetDiffInventory(ammoItems);
            return(inventory);
        }
Exemplo n.º 3
0
        ///// <summary>
        ///// Initializes a new instance of the <see cref="PriceableFxSpotRate"/> class.
        ///// </summary>
        ///// <param name="baseDate">The base date.</param>
        ///// <param name="spotDateOffset">The business day adjustments.</param>
        ///// <param name="fxRateAsset"></param>
        ///// <param name="fxForward">The forward points.</param>
        //public PriceableFxTNRate(DateTime baseDate, RelativeDateOffset spotDateOffset, FxRateAsset fxRateAsset, BasicQuotation fxForward)
        //    : this(1.0m, baseDate, fxRateAsset,
        //           spotDateOffset, fxForward)
        //{}

        /// <summary>
        /// Initializes a new instance of the <see cref="PriceableFxSpotRate"/> class.
        /// </summary>
        /// <param name="notionalAmount">The notional.</param>
        /// <param name="baseDate">The base date.</param>
        /// <param name="nodeStruct">The nodeStruct.</param>
        /// <param name="fxRateAsset">The asset itself</param>
        /// <param name="fixingCalendar">The fixing Calendar.</param>
        /// <param name="paymentCalendar">The payment Calendar.</param>
        /// <param name="fxForward">The forward points.</param>
        public PriceableFxTNRate(DateTime baseDate, decimal notionalAmount, FxSpotNodeStruct nodeStruct,
                                 FxRateAsset fxRateAsset, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation fxForward)
            : base(baseDate, "1D", notionalAmount, nodeStruct, fxRateAsset, fixingCalendar, paymentCalendar, fxForward)
        {
            AdjustedStartDate = baseDate;
            //AdjustedEffectiveDate = fixingCalendar.Advance(AdjustedStartDate, OffsetHelper.FromInterval(Tenor, DayTypeEnum.Business), SpotDateOffset.businessDayConvention);
            RiskMaturityDate = fixingCalendar.Advance(AdjustedStartDate, OffsetHelper.FromInterval(Tenor, DayTypeEnum.Business), SpotDateOffset.businessDayConvention);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Deal settle.
        /// </summary>
        /// <param name="dealDate"></param>
        /// <param name="settC"></param>
        /// <param name="hols"></param>
        /// <returns></returns>
        public static DateTime SettFromDeal(DateTime dealDate, BondSettlementEnum settC,
                                            IBusinessCalendar hols)
        {
            switch (settC)
            {
            case BondSettlementEnum.SC_dealDate: return(dealDate);

            case BondSettlementEnum.SC_1bd: return(hols.Advance(dealDate, OffsetHelper.FromInterval(IntervalHelper.FromDays(1), DayTypeEnum.Business), BusinessDayConventionEnum.FOLLOWING));

            case BondSettlementEnum.SC_2bd: return(hols.Advance(dealDate, OffsetHelper.FromInterval(IntervalHelper.FromDays(2), DayTypeEnum.Business), BusinessDayConventionEnum.FOLLOWING));

            case BondSettlementEnum.SC_1b1cd: return(hols.Advance(dealDate, OffsetHelper.FromInterval(IntervalHelper.FromDays(1), DayTypeEnum.Business), BusinessDayConventionEnum.FOLLOWING).AddDays(1));

            case BondSettlementEnum.SC_3bd:
            case BondSettlementEnum.SC_3bd_6bdLO: return(hols.Advance(dealDate, OffsetHelper.FromInterval(IntervalHelper.FromDays(3), DayTypeEnum.Business), BusinessDayConventionEnum.FOLLOWING));

            case BondSettlementEnum.SC_3b1cd: return(hols.Advance(dealDate, OffsetHelper.FromInterval(IntervalHelper.FromDays(3), DayTypeEnum.Business), BusinessDayConventionEnum.FOLLOWING).AddDays(1));

            case BondSettlementEnum.SC_4bd:
            case BondSettlementEnum.SC_4bd_6bdLO: return(hols.Advance(dealDate, OffsetHelper.FromInterval(IntervalHelper.FromDays(4), DayTypeEnum.Business), BusinessDayConventionEnum.FOLLOWING));

            case BondSettlementEnum.SC_5bd: return(hols.Advance(dealDate, OffsetHelper.FromInterval(IntervalHelper.FromDays(5), DayTypeEnum.Business), BusinessDayConventionEnum.FOLLOWING));

            case BondSettlementEnum.SC_7bd: return(hols.Advance(dealDate, OffsetHelper.FromInterval(IntervalHelper.FromDays(7), DayTypeEnum.Business), BusinessDayConventionEnum.FOLLOWING));

            case BondSettlementEnum.SC_3d: return(hols.Roll(dealDate.AddDays(3), BusinessDayConventionEnum.FOLLOWING));

            case BondSettlementEnum.SC_7d: return(hols.Roll(dealDate.AddDays(7), BusinessDayConventionEnum.FOLLOWING));

            case BondSettlementEnum.SC_7c1bd: return(hols.Advance(dealDate, OffsetHelper.FromInterval(IntervalHelper.FromDays(7), DayTypeEnum.Business), BusinessDayConventionEnum.FOLLOWING));

            case BondSettlementEnum.SC_3cd: return(hols.Roll(dealDate.AddDays(3), BusinessDayConventionEnum.FOLLOWING));

            //               case BondSettlementHelper.BondSettlementEnum.SC_Canada:
            //                   return

            default: return(hols.Advance(dealDate, OffsetHelper.FromInterval(IntervalHelper.FromDays(1), DayTypeEnum.Business), BusinessDayConventionEnum.FOLLOWING));
            }

            /*           switch (settC)
             *         {
             *             case SC_Canada:
             *                 CalendarDate(ym, mm, dm, maturityDate);
             *                 return TCs->NextBizDay(dealDate, 2 + (dealDate <= UnadjustedDate(ym - 3, mm, dm)));
             *
             *             case SC_Austria: return TCs->NextBizDay(dealDate + 15 - DayOfWeek(dealDate), 0);
             *
             *             case SC_Australia:
             *                 CalendarDate(ym, mm, dm, maturityDate);
             *                 return TCs->NextBizDay(dealDate, dealDate > UnadjustedDate(ym, mm - 6, dm) ? 1 : 3);
             *
             *             case SC_SouthAfrica:
             *                 settDate = dealDate + 15 - DayOfWeek(dealDate + 4);
             *                 if (!TCs->IsBizDay(settDate + 1)) settDate--;
             *                 return settDate;
             *         }
             *         return dealDate;*/
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PriceableCash"/> class.
 /// </summary>
 /// <param name="baseDate"></param>
 /// <param name="cash">The deposit.</param>
 /// <param name="amount">The cah amount.</param>
 /// <param name="term">The term of the cash flow.</param>
 /// <param name="businessDayAdjustments">The business day adjustments.</param>
 /// <param name="fixedRate">The fixed rate.</param>
 /// <param name="paymentCalendar">The payment Calendar.</param>
 protected PriceableCash(DateTime baseDate, Asset cash, Decimal amount, Period term, IBusinessCalendar paymentCalendar,
                         BusinessDayAdjustments businessDayAdjustments, BasicQuotation fixedRate)
     : base(cash.id, baseDate, amount, businessDayAdjustments, fixedRate)
 {
     Term             = term;
     RiskMaturityDate =
         paymentCalendar.Advance(BaseDate, OffsetHelper.FromInterval(Term, DayTypeEnum.Calendar),
                                 BusinessDayAdjustments.businessDayConvention);
     YearFraction = (decimal)Actual365.Instance.YearFraction(BaseDate, RiskMaturityDate);
 }
        /// <summary>
        /// Advances the specified calendars.
        /// </summary>
        /// <param name="businessCalendar">The calendars.</param>
        /// <param name="date">The date.</param>
        /// <param name="dayTypeString">The day type string.</param>
        /// <param name="periodInterval">The period interval.</param>
        /// <param name="businessDayConvention">The business day convention.</param>
        /// <returns></returns>
        public static DateTime Advance(IBusinessCalendar businessCalendar, DateTime date, string dayTypeString, string periodInterval, string businessDayConvention)
        {
            //IBusinessCalendar calendar = GetCalendar(calendars, ruleFullFilePath);
            Period interval = PeriodHelper.Parse(periodInterval);
            var    dayType  = DayTypeEnum.Calendar;

            if (dayTypeString.Length > 0)
            {
                dayType = (DayTypeEnum)Enum.Parse(typeof(DayTypeEnum), dayTypeString, true);
            }
            Offset offset = OffsetHelper.FromInterval(interval, dayType);
            BusinessDayConventionEnum dayConvention = BusinessDayConventionHelper.Parse(businessDayConvention);

            return(businessCalendar.Advance(date, offset, dayConvention));
        }
Exemplo n.º 7
0
    public static string[] FetchPlayerNames(IRAMReadWriter rw)
    {
        List <string> toRet = new List <string>();

        for (int i = 0; i < 8; ++i)
        {
            ulong  address = OffsetHelper.getPlayerIdAddress(SysBotController.CurrentOffsetFirstPlayerUInt) - 0xB8 + 0x20 + (OffsetHelper.PlayerSize * (ulong)i);
            byte[] pName   = rw.ReadBytes((uint)address, 20);
            string name    = string.Empty;
            if (!isZeroArray(pName))
            {
                name = StringUtil.GetString(pName, 0, 10);
            }
            toRet.Add(name == string.Empty ? string.Format("No one ({0})", (char)((uint)'A' + i)) : name);
        }

        return(toRet.ToArray());
    }
Exemplo n.º 8
0
        private void HandleOffsetClause(SelectStatement selectStatement)
        {
            if (selectStatement.OffsetLimitClause != null)
            {
                var offsetStage = OffsetHelper.GetOffsetStage(LastStage, selectStatement.OffsetLimitClause, _visitorMetadata);

                //Check if we can push the values into the table scan
                if (LastStage is FromTableStage fromTableStage)
                {
                    fromTableStage.Limit  = offsetStage.Take;
                    fromTableStage.Offset = offsetStage.Skip;
                }
                else
                {
                    _stages.Add(OffsetHelper.GetOffsetStage(LastStage, selectStatement.OffsetLimitClause, _visitorMetadata));
                }
            }
        }
Exemplo n.º 9
0
        private static async Task <string[]> FetchPlayerNames(IConsoleConnectionAsync connection, uint rootInventoryOffset, uint playerSize, CancellationToken token)
        {
            List <string> toRet = new List <string>();

            for (int i = 0; i < 8; ++i)
            {
                ulong  address = OffsetHelper.getPlayerIdAddress(rootInventoryOffset) - 0xB8 + 0x20 + (playerSize * (ulong)i);
                byte[] pName   = await connection.ReadBytesAsync((uint)address, 20, token).ConfigureAwait(false);

                if (!isZeroArray(pName))
                {
                    string name = StringUtil.GetString(pName, 0, 10);
                    toRet.Add(name);
                }
            }

            return(toRet.ToArray());
        }
Exemplo n.º 10
0
        /// <summary>
        /// Converts to an adjusted date.
        /// </summary>
        /// <param name="referenceDate"></param>
        /// <param name="relativeDateOffset"></param>
        /// <param name="businessCalendar"></param>
        /// <returns></returns>
        public static DateTime ToAdjustedDate(IBusinessCalendar businessCalendar, DateTime referenceDate, RelativeDateOffset relativeDateOffset)
        {
            // handle  BusinessDatConventionEnum is NONE as a special case, since there might be no business centers provided.
            if (BusinessDayConventionEnum.NONE == relativeDateOffset.businessDayConvention)
            {
                return(referenceDate);
            }
            //The default day type.
            if (relativeDateOffset.dayTypeSpecified == false || relativeDateOffset.businessCenters == null)
            {
                relativeDateOffset.dayType = DayTypeEnum.Calendar;
            }
            //IBusinessCalendar businessCalendar = relativeDateOffset.businessCenters == null ? new Hell() : BusinessCenterHelper.ToBusinessCalendar(cache, relativeDateOffset.businessCenters);
            var      interval = PeriodHelper.Parse(relativeDateOffset.periodMultiplier + relativeDateOffset.period);
            var      offset   = OffsetHelper.FromInterval(interval, relativeDateOffset.dayType);
            DateTime result   = businessCalendar.Advance(referenceDate, offset, relativeDateOffset.businessDayConvention);

            return(result);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Adds the period.
        /// </summary>
        /// <param name="startDate">The start date.</param>
        /// <param name="tenorString">The tenor string.</param>
        /// <param name="calendar">The calendar.</param>
        /// <param name="rollConvention">The roll convention.</param>
        /// <param name="dayType">Type of the day.</param>
        /// <returns></returns>
        public static DateTime AddPeriod(DateTime startDate, string tenorString, IBusinessCalendar calendar, string rollConvention, string dayType)
        {
            const string defaultRollConvention = "FOLLOWING";

            if (calendar == null)
            {
                calendar = new Hell();
            }
            if (String.IsNullOrEmpty(rollConvention))
            {
                rollConvention = defaultRollConvention;
            }
            Period rollPeriod = PeriodHelper.Parse(tenorString);

            if (String.IsNullOrEmpty(dayType))
            {
                dayType = DayTypeStringFromRollPeriodInterval(rollPeriod);
            }
            var dayTypeEnum = (DayTypeEnum)Enum.Parse(typeof(DayTypeEnum), dayType, true);
            BusinessDayConventionEnum businessDayConvention = BusinessDayConventionHelper.Parse(rollConvention);
            DateTime endDate = calendar.Advance(startDate, OffsetHelper.FromInterval(rollPeriod, dayTypeEnum), businessDayConvention);

            return(endDate);
        }
Exemplo n.º 12
0
 // jpeg sizes are 100k-200k bytes so I gave up on this because the load time simply isn't worth it (around 15 seconds over usb)
 public void FetchPlayerJpeg(int playerNumber, IRAMReadWriter rw)
 {
     ulong address = OffsetHelper.getPlayerProfileMainAddress(SysBotController.CurrentOffsetFirstPlayerUInt) - 0xB8 + 0x10 + (OffsetHelper.PlayerSize * (ulong)playerNumber);
     int   length  = BitConverter.ToInt32(rw.ReadBytes((uint)address, 4), 0);
 }
        /// <summary>
        /// Gets the reset date.
        /// </summary>
        /// <param name="resetRelativeTo">The reset relative to.</param>
        /// <returns></returns>
        /// <param name="fixingDateRelativeOffset"></param>
        private DateTime GetResetDate(ResetRelativeToEnum resetRelativeTo, RelativeDateOffset fixingDateRelativeOffset)
        {
            var resetDate = AccrualStartDate;

            switch (resetRelativeTo)
            {
            case ResetRelativeToEnum.CalculationPeriodEndDate:
                resetDate = AccrualEndDate;
                break;
            }

            var interval = (Period)fixingDateRelativeOffset;

            if (fixingDateRelativeOffset != null)
            {
                var adjustment = BusinessDayAdjustmentsHelper.Create(fixingDateRelativeOffset.businessDayConvention, BusinessCentersHelper.BusinessCentersString(fixingDateRelativeOffset.businessCenters.businessCenter));
                resetDate = AdjustedDateHelper.ToAdjustedDate(FixingCalendar, resetDate, adjustment, OffsetHelper.FromInterval(interval, fixingDateRelativeOffset.dayType));
            }
            return(resetDate);
        }
 /// <summary>
 /// Gets the forward spot date.
 /// </summary>
 /// <returns></returns>
 protected DateTime GetForwardDate(DateTime spotDate, IBusinessCalendar paymentCalendar, Period tenor, BusinessDayConventionEnum businessDayConvention)
 {
     return(paymentCalendar.Advance(spotDate, OffsetHelper.FromInterval(tenor, DayTypeEnum.Calendar), businessDayConvention));
 }
Exemplo n.º 15
0
        /// <summary>
        ///
        /// </summary>
        public void CalcSettlementDate()
        {
            var rollDays = PeriodHelper.Parse(SettC); //TODO add dayType - Business/Calendar etc.

            SettlementDate = PaymentDateCalendar.Advance(DealDate, OffsetHelper.FromInterval(rollDays, DayTypeEnum.Calendar), BusinessDayConventionEnum.FOLLOWING);
        }
Exemplo n.º 16
0
 public NashaInstruction Translation(NashaSettings settings, MethodDef method, int index)
 {
     return(new NashaInstruction(NashaOpcodes.Brtrue, OffsetHelper.Get(method.Body.Instructions.IndexOf((Instruction)method.Body.Instructions[index].Operand))));
 }