public ConditionExpression(string condition)
        {
            this.condition = condition;

            if (string.IsNullOrWhiteSpace(condition))
            {
                Test = (x, y) => true;
            }
            else
            {
                string        splitStr = "";
                ConditionType ct       = ConditionType.Invalid;

                if (condition.Contains("=="))
                {
                    splitStr = "==";
                    ct       = ConditionType.Equality;
                }
                else if (condition.Contains("!="))
                {
                    splitStr = "!=";
                    ct       = ConditionType.Inequality;
                }

                var splitIndex = condition.IndexOf(splitStr);
                var captureStr = condition.Substring(0, splitIndex).Trim();
                var valueStr   = condition.Substring(splitIndex + splitStr.Length).Trim();

                CaptureExpression capture = new CaptureExpression(captureStr);

                ushort value;
                if (valueStr.StartsWith("0x"))
                {
                    value = ushort.Parse(valueStr.Substring(2), NumberStyles.HexNumber);
                }
                else
                {
                    value = ushort.Parse(valueStr);
                }

                if (ct == ConditionType.Equality)
                {
                    Test = (x, getValueDelegate) =>
                    {
                        var GetValue = getValueDelegate(capture);
                        var v        = GetValue(x);
                        return(v == value);
                    };
                }
                else if (ct == ConditionType.Inequality)
                {
                    Test = (x, getValueDelegate) =>
                    {
                        var GetValue = getValueDelegate(capture);
                        var v        = GetValue(x);
                        return(v != value);
                    };
                }
            }
        }
예제 #2
0
        public XVariableParser(XVariable var, Game game)
        {
            this.item   = var;
            this.game   = game;
            this.hidden = (var.UI.Item is UIHidden);

            foreach (var v in var.Value)
            {
                short key = short.Parse(v.Data, NumberStyles.HexNumber);
                if (valueDefinitions.ContainsKey(key))
                {
                    Console.WriteLine($"Duplicate key: {key}, {v.Description} {v.Comment}");
                }
                else
                {
                    valueDefinitions.Add(key, v);
                }
            }

            capture   = new CaptureExpression(var.Capture);
            condition = new ConditionExpression(var.Condition);
            switch (var.UI.Item)
            {
            case UITextId textId:
                PrintVariable = (x, get) =>
                {
                    ushort baseId = ushort.Parse(textId.Base, NumberStyles.HexNumber);
                    return($"{item.Description}: { get(capture)(x) + baseId:X4}");
                }; break;

            case UISwitchFlag sf:
                PrintVariable = (x, get) => { return($"{item.Description}: {get(capture)(x):X2}"); }; break;

            case UIBitFlag bf:
                PrintVariable = (x, get) => { return($"{item.Description}: {get(capture)(x) > 0}"); }; break;

            default:
                PrintVariable = (x, get) =>
                {
                    short value = (short)get(capture)(x);
                    if (valueDefinitions.TryGetValue(value, out XVariableValue valueDef))
                    {
                        if (item.Description == "Type")
                        {
                            return(valueDef.Description);
                        }
                        else
                        {
                            return($"{item.Description}: {valueDef.Description}");
                        }
                    }
                    else
                    {
                        return($"{item.Description}: {value:X4}");
                    }
                }; break;
            }
        }
예제 #3
0
        private static Func <short[], ushort> GetActorValue(Game game, CaptureExpression capture)
        {
            int shift = (game == Game.OcarinaOfTime) ? 0 : 7;

            return(capture.VarType switch
            {
                CaptureVar.v => (x) => { return Shift.AsUInt16((ushort)x[7], (uint)capture.Mask); },
                CaptureVar.rx => (x) => { return Shift.AsUInt16((ushort)x[4], (uint)capture.Mask << shift); },
                CaptureVar.ry => (x) => { return Shift.AsUInt16((ushort)x[5], (uint)capture.Mask << shift); },
                CaptureVar.rz => (x) => { return Shift.AsUInt16((ushort)x[6], (uint)capture.Mask << shift); },
                _ => throw new NotImplementedException(),
            });
예제 #4
0
        public static Func <short[], ushort> GetTransitionActorValue(Game game, CaptureExpression capture)
        {
            int shift = (game == Game.OcarinaOfTime) ? 0 : 7;

            switch (capture.VarType)
            {
            case CaptureVar.v:
                return((x) => { return Shift.AsUInt16((ushort)x[7], (uint)capture.Mask); });

            case CaptureVar.ry:
                return((x) => { return Shift.AsUInt16((ushort)x[6], (uint)capture.Mask << shift); });

            default:
                throw new NotImplementedException();
            }
        }
예제 #5
0
        /// <summary>
        /// Prints the stats on a packed initialization variable
        /// </summary>
        /// <param name="sb"></param>
        /// <param name="var"></param>
        private static void PrintVariable(StringBuilder sb, XVariable var)
        {
            //sb.AppendFormat(" {0} {1} - {2} ",
            //    (var.maskType == MaskType.And) ? "&" : "|",
            //    var.mask,
            //    var.Description);
            sb.Append($";{var.Capture} = {var.Description}");
            //sb.Append($" {GetCaptureCatch(var.Capture)} - {var.Description} ");

            PrintComments(sb, var.Comment, true);
            sb.AppendLine();

            CaptureExpression capture = new CaptureExpression(var.Capture);

            foreach (XVariableValue value in var.Value)
            {
                PrintVariableValue(sb, value, capture);
            }
        }
예제 #6
0
 public static Func <short[], ushort> GetMMTransActorValue(CaptureExpression capture)
 {
     return(GetTransitionActorValue(Game.MajorasMask, capture));
 }
예제 #7
0
 public static Func <short[], ushort> GetOcaTransActorValue(CaptureExpression capture)
 {
     return(GetTransitionActorValue(Game.OcarinaOfTime, capture));
 }
예제 #8
0
        private static void PrintVariableValue(StringBuilder sb, XVariableValue value, CaptureExpression capture)
        {
            int    shiftback = ShiftBack(int.Parse(value.Data, System.Globalization.NumberStyles.HexNumber), capture.Mask);
            string obj       = null;

            if (SetGame != Game.OcarinaOfTime && capture.VarType != CaptureVar.v)
            {
                shiftback = ShiftBack(shiftback, 0xFF80);
            }

            if (value.Meta != null)
            {
                obj = string.Join(", ", value.Meta.Object);
            }
            obj = (!string.IsNullOrEmpty(obj)) ? $" ({obj})" : "";


            sb.AppendFormat(":{0} [{2:X4}]{1} {3} {4}",
                            value.Data,
                            (!string.IsNullOrEmpty(value.repeat)) ? "+" : "",
                            shiftback,
                            obj,
                            value.Description);
            PrintComments(sb, value.Comment, true);
            sb.AppendLine();
        }