public MemoryRangePointer(IMemorizable originalMemory, int from, int howmany) : base(howmany)
        {
            this.originalMemory = originalMemory;
            From = from;
            To   = from + howmany;

            content = originalMemory.GetValues(from, howmany);
        }
예제 #2
0
 /// <summary>
 /// Add to memory and trim the "(Clone)"-part
 /// </summary>
 /// <param name="container">Item to add</param>
 public static void UpdateMemory(Dictionary <Type, List <GameObject> > container)
 {
     memory = "";
     foreach (var items in container.Values)
     {
         foreach (GameObject go in items)
         {
             if (go)
             {
                 IMemorizable memorizableObject = go.GetComponent <IMemorizable>();
                 memory += "\n" + go.name.Substring(0, go.name.Length - 7) + " Room: " + memorizableObject.RoomID;
             }
         }
     }
 }
        private static IMemorizable[] GetIMemorizablesFromCommand(string cmd, ApplicationContext context)
        {
            IMemorizable GetMemorizableFromAssembly(string ass)   // FUNCTION
            {
                Register reg;

                if ((reg = context.Registers.Find(r => r.Name == ass)) != null)
                {
                    return(reg);
                }

                if (ass.IndexOf('[') < ass.IndexOf(']') && ass.IndexOf('[') != -1)
                {
                    // TODO Byte / Word

                    IMemorizable indirect = CheckForIndirectReference(ass.BetweenSubstring("[", "]"), context);

                    if (indirect != null)
                    {
                        return(indirect);
                    }

                    MemoryRangePointer pointer =
                        context.MainMemory.ExtractMemoryPointer(ass.BetweenSubstring("[", "]").ToInt(), 2);

                    return(pointer);
                }

                MySupport.NormalizeValueString(ref ass);

                return(new ImmediateNumber(MySupport.GetBytesArrayFromString(ass), true));
            }

            var memorizables = new IMemorizable[2];

            var splits = cmd.Split(',');

            for (int i = 0; i < splits.Length; i++)
            {
                splits[i] =
                    splits[i].Substring(splits[i].IndexOf(' ') != -1 ? splits[i].IndexOf(' ') : 0).TrimStart().TrimEnd();
                memorizables[i] = GetMemorizableFromAssembly(splits[i]);
            }

            return(memorizables);
        }
예제 #4
0
    /// <summary>
    /// Scan the area around the agent for memorable tiles.
    /// </summary>
    public void Scan()
    {
        var dungeon = Dungeon.Singleton;

        Physics2D.OverlapCircleNonAlloc(transform.position, sightRange, inVision, visionMask);
        foreach (var collision in inVision)
        {
            if (collision)
            {
                IMemorizable memorizableObject = collision.GetComponent <IMemorizable>();
                if (memorizableObject != null)
                {
                    if (memorizableObject.OfInterest)
                    {
                        GetComponent <BlackBoard>().AddTypePOI(memorizableObject.MemorizableType, collision.gameObject);
                        memorizableObject.OfInterest = false;
                    }
                }
            }
        }
        dungeon.CurrentRoom.RoomGraph.ExploreNodes(transform.position, sightRange - 1);
    }
예제 #5
0
        public static int GetCommandLength(ApplicationContext ctx, IMemorizable pointer)
        {
            int GetLenghtParms(CommandTemplate lenTemplate)
            {
                if (lenTemplate.OpCode.Count(c => c == '$') / 2 == 2)
                {
                    return
                        (int.Parse(
                             lenTemplate.ParTypes[0].ToString()
                             .Substring(lenTemplate.ParTypes[0].ToString().Length - 2, 2)) / 8 +
                         int.Parse(
                             lenTemplate.ParTypes[1].ToString()
                             .Substring(lenTemplate.ParTypes[1].ToString().Length - 2, 2)) / 8);
                }

                if (lenTemplate.OpCode.Count(c => c == '$') / 2 == 0)
                {
                    return(0);
                }

                int np = sbyte.Parse(lenTemplate.OpCode[lenTemplate.OpCode.IndexOf("$") + 3].ToString()) - 1;

                return
                    (int.Parse(
                         lenTemplate.ParTypes[np].ToString().Substring(lenTemplate.ParTypes[np].ToString().Length - 2, 2)) /
                     8);
            }

            CommandTemplate template =
                ctx.CommandTemplList.Find(c => c.OpCode.StartsWith(MySupport.ByteArrayToString(pointer.GetValues(0, 1))));

            // Params are always attched.

            string commandNoParms = template.OpCode.Contains("$")
                ? template.OpCode.Remove(template.OpCode.IndexOf("$")) : template.OpCode;

            return(commandNoParms.Length / 2 + GetLenghtParms(template));
        }
예제 #6
0
        public static AssemblableCommand Dissassemble(ApplicationContext ctx, IMemorizable pointer)
        {
            AssemblableCommand command;
            int inizioPar = -1;

            List <CommandTemplate> allcmds = ctx.CommandTemplList.Where(el => {
                var ret = true;

                for (var i = 0;; i += 2)
                {
                    if (pointer.Length < i || el.OpCode.Length <= i || el.OpCode.Substring(i, 2).Contains('$') || !ret)
                    {
                        inizioPar = i;
                        break;
                    }

                    ret = MySupport.ByteArrayToString(pointer.GetValues(i / 2, 1)) == el.OpCode.Substring(i, 2);
                }
                return(ret);
            }).ToList();

            if (allcmds.Count > 1)
            {
                throw new Exception("Multple commands with a single opCode");
            }


            CommandTemplate template = allcmds[0];

            if (!template.OpCode.Contains("$"))
            {
                return(new AssemblableCommand(template));
            }

            inizioPar = template.OpCode.IndexOf("$" /*, inizioPar*/); // TOLTO A CASO PERCHE NON ANDAVA

            int spar = -1;

            var parms = new string[2];

            if (inizioPar != template.OpCode.Length / 2)
            {
                int np = sbyte.Parse(template.OpCode[inizioPar + 3].ToString()) - 1;

                sbyte p2size =
                    sbyte.Parse(template.ParTypes[np].ToString().Substring(template.ParTypes[np].ToString().Length - 2));
                p2size /= 8;

                parms[np] = template.OpCode.Substring(inizioPar + 5, 2) != "le"
                    ? MySupport.ByteArrayToString(pointer.GetValues(inizioPar / 2, p2size))
                    : MySupport.ByteArrayToString(pointer.GetValues(inizioPar / 2, p2size).Reverse().ToArray());


                inizioPar = template.OpCode.IndexOf("$", template.OpCode.IndexOf("$", inizioPar + 1) + 1);
                spar      = inizioPar / 2 + p2size;
            }

            // Parameters are always attached.

            if (inizioPar != template.OpCode.Length / 2 && inizioPar != -1)
            {
                int np = sbyte.Parse(template.OpCode[inizioPar + 3].ToString()) - 1;

                sbyte p2size =
                    sbyte.Parse(template.ParTypes[np].ToString().Substring(template.ParTypes[np].ToString().Length - 2));
                p2size /= 8;

                parms[np] = template.OpCode.Substring(inizioPar + 5, 2) != "le"
                    ? MySupport.ByteArrayToString(pointer.GetValues(spar / 2, p2size))
                    : MySupport.ByteArrayToString(pointer.GetValues(spar / 2, p2size).Reverse().ToArray());
            }

            command = new AssemblableCommand(template, ctx, template.ParTypes, parms);

            return(command);
        }
예제 #7
0
        public static List <AssemblableCommand> MultiCommandDisassembler(ApplicationContext ctx, IMemorizable pointer, [Optional] ref List <int> ids)
        {
            var cmds = new List <AssemblableCommand>();

            for (var index = 0; index < pointer.Length;)
            {
                int length;

                try {
                    length = GetCommandLength(ctx, pointer.ExtractMemoryPointer(index, pointer.Length - index));
                } catch {
                    // ConsoleLogger.Write("Cannot find a command with OpCode " + (pointer.ExtractMemoryPointer(index, pointer.Length - index)).ToString(), "ERROR", ConsoleColor.Red);
                    index += 1;
                    cmds.Add(new AssemblableCommand(CommandTemplate.UNKNOWN));
                    ids.Add(index);
                    continue;
                }

                if (length > pointer.Length - index)
                {
                    break;
                }

                cmds.Add(Dissassemble(ctx, pointer.ExtractMemoryPointer(index, length)));
                ids.Add(index);
                index += length;
            }

            return(cmds);
        }
예제 #8
0
        public static AssemblableCommand DisassembleNextCommand(ApplicationContext context, IMemorizable memory)
        {
            AssemblableCommand cmd;
            uint lenght = 0;

            try {
                lenght = (uint)GetCommandLength(context, memory.ExtractMemoryPointer(0, memory.Length));
            } catch {
                cmd = new AssemblableCommand(CommandTemplate.UNKNOWN);
                return(cmd);
            }

            cmd = Dissassemble(context, memory.ExtractMemoryPointer(0, (int)lenght));

            return(cmd);
        }