/// <summary> /// Connects to the gameboy a new cartridge with the given contents. /// </summary> /// <param name="cartridgeData"></param> public bool LoadCartridge(string cartridgeFullFilename, byte[] cartridgeData) { if (_state.Run) { Reset(); } _cartridge = new Cartridge.Cartridge(); _cartridge.Load(cartridgeData); _cpu.ResetBreakpoints(); CartridgeFilename = Path.GetFileNameWithoutExtension(cartridgeFullFilename); CartridgeDirectory = Path.GetDirectoryName(cartridgeFullFilename); _apu.CartridgeFilename = this.CartridgeFilename; // We create the MemoryHandler according to the data // from the cartridge and set it to the memory. // From this point onwards, all the access to memory // are done throught the MemoryHandler MemoryHandler memoryHandler = MemoryHandlerFactory.CreateMemoryHandler(this); if (memoryHandler == null) { // We destroy all the info _cartridge = null; CartridgeFilename = ""; CartridgeDirectory = ""; _apu.CartridgeFilename = ""; return(false); } _memory.SetMemoryHandler(memoryHandler); return(true); }
public PlayerContainer(MemoryHandler Memory, int PlayerIndex) { this.Memory = Memory; this.PlayerIndex = PlayerIndex; resolveIndexes(); validName = Name; }
public KeyValuePair <uint, (string, bool)> GetCurrentPlayer() { var result = new KeyValuePair <uint, (string, bool)>(); if (!CanGetPlayerInfo() || !MemoryHandler.IsAttached) { return(result); } var playerInfoMap = (IntPtr)Scanner.Locations[Signatures.PlayerInformationKey]; if (playerInfoMap.ToInt64() <= 6496) { return(result); } try { var source = MemoryHandler.GetByteArray(playerInfoMap, MemoryHandler.Structures.CurrentPlayer.SourceSize); var actorId = SBitConverter.TryToUInt32(source, MemoryHandler.Structures.CurrentPlayer.ID); var playerName = MemoryHandler.GetStringFromBytes(source, MemoryHandler.Structures.CurrentPlayer.Name); var isCurrentlyBard = source[MemoryHandler.Structures.CurrentPlayer.JobID] == 0x17; if (ActorIdTools.RangeOkay(actorId) && !string.IsNullOrEmpty(playerName)) { result = new KeyValuePair <uint, (string, bool)>(actorId, (playerName, isCurrentlyBard)); } } catch (Exception ex) { MemoryHandler?.RaiseException(ex); } return(result); }
public List<Command> ProcessStatement(string statement, ref int pc, ref MemoryHandler mem, ref Dictionary<string, bool> compilerFlags) { var parts = statement.Split('='); var dest = parts[0].Trim(); var src = parts[1].Trim(); var commands = new List<Command>(); src = mem.MakeConstantIfNeeded(src, ref commands, ref pc); //Dump accumulator to mem98 //src to acc //dump accum tp dest //restore accumulator from mem98 if (dest == "acc") { commands.Add(new Command(Operator.ClearAccumulator, mem[src])); return Command.LoadToCards(commands, ref pc); } if (!compilerFlags["accumulatorIsVolatile"]) commands.Add(new Command(Operator.StoreAccumulator, 98)); commands.Add(new Command(Operator.ClearAccumulator, mem[src])); commands.Add(new Command(Operator.StoreAccumulator, mem[dest])); if (!compilerFlags["accumulatorIsVolatile"]) commands.Add(new Command(Operator.ClearAccumulator, 98)); return Command.LoadToCards(commands, ref pc); }
public Reader(MemoryHandler memoryHandler) { Scanner = memoryHandler.Scanner; MemoryHandler = memoryHandler; MemoryHandler.Reader = this; _chatLogReader = new ChatLogReader(memoryHandler); }
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) { var setPasswordDialog = new FormSetPassword(); if (_currentFileSystemDrive == null) { MessageBox.Show("Nothing to save!"); return; } var saveFileDialog = new SaveFileDialog { Filter = "FileSystemImage files (*.fsi)|*.fsi" }; if (saveFileDialog.ShowDialog() == DialogResult.OK) { _currentFileName = saveFileDialog.FileName; } else { return; } if (_currentFileName != null && setPasswordDialog.ShowDialog(this) == DialogResult.OK) { string password = setPasswordDialog.VerifiedPassword; SaveFileSystemImageToFile(_currentFileSystemDrive, _currentFileName, password); Log.Debug("Successfuly Saved file: {FileName}", saveFileDialog.FileName); } MemoryHandler.RunGarbageCollect(); }
public bool Set(MemoryHandler Memory) { this.Memory = Memory; Memory.RefreshMemory(); var process = Memory.Process; Address = Memory.GetAddress(Pointer); if (Address == null) { return(false); } foreach (ProcessThread th in process.Threads) { if (AffectedThreads.ContainsKey(th.Id)) { continue; } var hThread = Kernel32.OpenThread(ThreadAccess.THREAD_ALL_ACCESS, false, th.Id); if (hThread == IntPtr.Zero) { throw new BreakPointException("Can't open thread for access"); } SetToThread(hThread, th.Id); if (!Kernel32.CloseHandle(hThread)) { throw new BreakPointException("Failed to close thread handle"); } } return(true); }
public void UnSet(MemoryHandler Memory) { Memory.RefreshMemory(); var process = Memory.Process; foreach (ProcessThread th in process.Threads) { if (!AffectedThreads.ContainsKey(th.Id)) { continue; } var hThread = Kernel32.OpenThread(ThreadAccess.THREAD_ALL_ACCESS, false, th.Id); if (hThread == IntPtr.Zero) { throw new BreakPointException("Can't open thread for access"); } UnsetFromThread(hThread, th.Id); if (!Kernel32.CloseHandle(hThread)) { throw new BreakPointException("Failed to close thread handle"); } } AffectedThreads.Clear(); }
public MainWindow() { _numRegex = new Regex(@"^[0-9]+$"); _memoryHandler = new MemoryHandler(); InitializeComponent(); }
public static ChatLogItem Process(MemoryHandler memoryHandler, byte[] raw) { var chatLogEntry = new ChatLogItem(); try { chatLogEntry.Bytes = raw; chatLogEntry.TimeStamp = UnixTimeStampToDateTime(int.Parse(ByteArrayToString(raw.Take(4).Reverse().ToArray()), NumberStyles.HexNumber)); chatLogEntry.Code = ByteArrayToString(raw.Skip(4).Take(2).Reverse().ToArray()); chatLogEntry.Raw = Encoding.UTF8.GetString(raw.ToArray()); var cleanable = raw.Skip(8).ToArray(); var cleaned = new ChatCleaner(memoryHandler, cleanable).Result; var cut = cleaned.Substring(1, 1) == ":"? 2 : 1; chatLogEntry.Line = XMLCleaner.SanitizeXmlString(cleaned.Substring(cut)); chatLogEntry.Line = new ChatCleaner(memoryHandler, chatLogEntry.Line).Result; chatLogEntry.JP = IsJapanese(chatLogEntry.Line); chatLogEntry.Combined = $"{chatLogEntry.Code}:{chatLogEntry.Line}"; } catch (Exception) { chatLogEntry.Bytes = Array.Empty <byte>(); chatLogEntry.Raw = string.Empty; chatLogEntry.Line = string.Empty; chatLogEntry.Code = string.Empty; chatLogEntry.Combined = string.Empty; } return(chatLogEntry); }
public PartyMemberResolver(MemoryHandler memoryHandler, PCWorkerDelegate pcWorkerDelegate, NPCWorkerDelegate npcWorkerDelegate, MonsterWorkerDelegate monsterWorkerDelegate) { this._memoryHandler = memoryHandler; this._pcWorkerDelegate = pcWorkerDelegate; this._npcWorkerDelegate = npcWorkerDelegate; this._monsterWorkerDelegate = monsterWorkerDelegate; this._foundStatuses = new List <StatusItem>(); }
private void clearToolStripMenuItem_Click(object sender, EventArgs e) { FolderTreeView.Nodes.Clear(); FileListDataGridView.DataSource = null; _currentFileSystemDrive = null; _currentFileName = null; DirectoryInfoDataLabel.Text = ""; MemoryHandler.RunGarbageCollect(); }
public void Read(MemoryHandler Memory) { var bytes = new List <byte>(); for (var i = 0; i < Module.MemorySize; i += readCount) { bytes.AddRange(Memory.ReadBytes(IntPtr.Add(Module.BaseAddress, i), i + readCount >= Module.MemorySize ? Module.MemorySize - i : readCount)); } Data = bytes.ToArray(); }
private int ProcessArg(string arg, MemoryHandler mem) { arg = arg.Trim(' ', ')'); int result; if (int.TryParse(arg, out result)) { return result; } return mem[arg]; }
public Entity GetEntityByIndex(int index) { IntPtr address = MemoryHandler.ResolvePointer(MobArray + 4 * index); if (address == IntPtr.Zero) { return(null); } else { return(new Entity(MemoryHandler, address)); } }
public void LoadSnapshot(byte[] snapshotbytes, Zilog.Z80 cpu) { cpu.Reset(); //cpu.I = snapshotbytes[0]; //cpu.HLPrim = (ushort)(snapshotbytes[1] + 256 * snapshotbytes[2]); //cpu.DEPrim = (ushort)(snapshotbytes[3] + 256 * snapshotbytes[4]); //cpu.BCPrim = (ushort)(snapshotbytes[5] + 256 * snapshotbytes[6]); //cpu.AFPrim = (ushort)(snapshotbytes[7] + 256 * snapshotbytes[8]); //cpu.HL = (ushort)(snapshotbytes[9] + 256 * snapshotbytes[10]); //cpu.DE = (ushort)(snapshotbytes[11] + 256 * snapshotbytes[12]); //cpu.BC = (ushort)(snapshotbytes[13] + 256 * snapshotbytes[14]); //cpu.IY = (ushort)(snapshotbytes[15] + 256 * snapshotbytes[16]); //cpu.IX = (ushort)(snapshotbytes[17] + 256 * snapshotbytes[18]); //cpu.R = snapshotbytes[20]; //cpu.AF = (ushort)(snapshotbytes[21] + 256 * snapshotbytes[22]); //cpu.SP = (ushort)(snapshotbytes[23] + 256 * snapshotbytes[24]); cpu.I = snapshotbytes[0]; cpu.HLPrim = snapshotbytes[1] | (snapshotbytes[2] << 8); cpu.DEPrim = snapshotbytes[3] | (snapshotbytes[4] << 8); cpu.BCPrim = snapshotbytes[5] | (snapshotbytes[6] << 8); cpu.AFPrim = snapshotbytes[7] | (snapshotbytes[8] << 8); cpu.HL = snapshotbytes[9] | (snapshotbytes[10] << 8); cpu.DE = snapshotbytes[11] | (snapshotbytes[12] << 8); cpu.BC = snapshotbytes[13] | (snapshotbytes[14] << 8); cpu.IY = snapshotbytes[15] | (snapshotbytes[16] << 8); cpu.IX = snapshotbytes[17] | (snapshotbytes[18] << 8); cpu.IFF = cpu.IFF2 = ((snapshotbytes[19] & 0x04) == 0x04); cpu.R = snapshotbytes[20]; cpu.AF = snapshotbytes[21] | (snapshotbytes[22] << 8); cpu.SP = snapshotbytes[23] | (snapshotbytes[24] << 8); cpu.IM = (byte)(snapshotbytes[25] & 0x03); if (cpu.IM > 2) { cpu.IM = 2; } cpu.Out(254, snapshotbytes[26], 0); //Border Color //Memory MemoryHandler.LoadBytesintoMemory(snapshotbytes, 27, 0x4000, cpu); int pc = cpu.ReadWordFromMemory(cpu.SP); //Debug.WriteLine("Load PC:" + pc); //cpu.SP++; //cpu.SP++; cpu.PC = pc; cpu.RET(true, 0, 0); }
public List<Command> ProcessStatement(string statement, ref int pc, ref MemoryHandler mem, ref Dictionary<string, bool> compilerFlags) { var parts = statement.Split(' '); if (parts.Length == 3) { compilerFlags[parts[1]] = parts[2] == "true"; } else { compilerFlags[parts[1]] = true; } return new List<Command>(); }
protected void HandleSaveFileComplete(object sender, OutcomeEventArgs eventArgs) { LoadAndSaveProgressBar.Visible = false; saveAsToolStripMenuItem.Enabled = true; saveToolStripMenuItem.Enabled = true; LoadAndSaveProgressInfoLabel.Text = eventArgs.Successful ? "Successfuly saved file" : "Faild to save file"; Task.Run(async delegate { await Task.Delay(5000); ResetLoadAndSaveProgress(); }); MemoryHandler.RunGarbageCollect(); }
private void SetupSharlayanManager() { foreach (Process process in this._gameInstances) { SharlayanConfiguration sharlayanConfiguration = new SharlayanConfiguration { ProcessModel = new ProcessModel { Process = process, }, }; MemoryHandler handler = SharlayanMemoryManager.Instance.AddHandler(sharlayanConfiguration); handler.OnException += this.MemoryHandler_OnExceptionEvent; handler.OnMemoryHandlerDisposed += this.MemoryHandler_OnMemoryHandlerDisposedEvent; handler.OnMemoryLocationsFound += this.MemoryHandler_OnMemoryLocationsFoundEvent; } }
public void LoadSnapshot(byte[] snapshotbytes, Z80 cpu) { var entrypoint = snapshotbytes.AsSpan(0x100, 3).ToArray(); var title = ASCIIEncoding.ASCII.GetString(snapshotbytes.AsSpan(0x134..0x143)); var cartridgeType = snapshotbytes.AsSpan(0x147, 1).ToArray(); var romSize = snapshotbytes.AsSpan(0x148, 1).ToArray(); var ramSize = snapshotbytes.AsSpan(0x149, 1).ToArray(); var destination = snapshotbytes.AsSpan(0x14A, 1).ToArray(); var licensee = snapshotbytes.AsSpan(0x14B, 1).ToArray(); var version = snapshotbytes.AsSpan(0x14C, 1).ToArray(); var checksum = snapshotbytes.AsSpan(0x14D, 1).ToArray(); var globalChecksum = snapshotbytes.AsSpan(0x14E, 2).ToArray(); var rom = snapshotbytes.AsSpan().ToArray(); MemoryHandler.LoadBytesintoMemory(rom, 0, 0, cpu); }
public bool IsChatInputOpen() { if (!CanGetChatInput() || !MemoryHandler.IsAttached) { return(false); } try { var chatInputMap = (IntPtr)Scanner.Locations[Signatures.ChatInputKey]; var pointer = ((IntPtr)MemoryHandler.GetInt32(chatInputMap)) != IntPtr.Zero; return(pointer); } catch (Exception ex) { MemoryHandler?.RaiseException(ex); } return(false); }
private void DecorationListDisposer() { var memoryHandler = new MemoryHandler(_archive); var allList = memoryHandler.GetArchiveDecorations(); var list = new ArrayList(); Logger.Debug("allList.Count:" + allList.Count); _maxPage = allList.Count / 50 + 1; for (var i = (_nowPage - 1) * 50; i < _nowPage * 50; i++) { list.Add(i >= allList.Count ? new DecorationBean("锁定", 0, 0, 0) : allList[i]); } RefreshUi(list); }
/// <summary> /// Reads a value of specified field from memory. Does NOT support type TX with unspecified size /// </summary> /// <typeparam name="TX"></typeparam> /// <param name="field"></param> /// <returns></returns> internal virtual TX Read <TX>(string field) { IntPtr target = IntPtr.Add(BaseAddress, (int)Marshal.OffsetOf(typeof(T), field)); int bytesRead; byte[] _c = MemoryHandler.ReadAdress(target, (uint)Marshal.SizeOf(typeof(TX)), out bytesRead); GCHandle handle = GCHandle.Alloc(_c, GCHandleType.Pinned); TX structure = (TX)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(TX)); handle.Free(); return(structure); }
private void startButton_Click(object sender, EventArgs e) { int bytesRead; IntPtr baseAddress = myProcess.MainModule.BaseAddress; Console.WriteLine("Base Address: " + baseAddress); IntPtr newAddr = IntPtr.Add(baseAddress, 0xF8BEFC); IntPtr address = (IntPtr)BitConverter.ToInt32(MemoryHandler.ReadMemory(myProcess, newAddr, 4, out bytesRead), 0); IntPtr finalAddr = IntPtr.Add(address, 0x1690); Console.WriteLine("Final Address: " + finalAddr.ToString("X")); byte[] memoryOutput = MemoryHandler.ReadMemory(myProcess, finalAddr, 4, out bytesRead); int value = BitConverter.ToInt32(memoryOutput, 0); Console.WriteLine("Read Value: " + value); }
public List<Command> ProcessStatement(string statement, ref int pc, ref MemoryHandler mem, ref Dictionary<string, bool> compilerFlags) { var commands = new List<Command>(); var parts = statement.Split(' '); if (_reservedVarNames.Contains(parts[1])) throw new CompilerException($"Cannot use variable name {parts[1]} as it is reserved by the compiler", -1); mem.Reserve(parts[1]); if (parts.Length > 2) // var a = b { commands.Add(new Command(Operator.ReadCard, mem[parts[1]]) { NoEncode = true }); commands.Add(new Command(Operator.RawValue, int.Parse(parts[3])) { NoEncode = true }); } return commands; }
protected void HandleOpenFileComplete(object sender, EventArgs eventArgs) { LoadAndSaveProgressBar.Visible = false; LoadAndSaveProgressInfoLabel.Visible = false; openToolStripMenuItem.Enabled = true; if (_currentFileSystemDrive == null || _currentFileSystemDrive.DirectoryList == null) { MessageBox.Show("Faild to open file!"); } else { LoadFileSystemDrive(_currentFileSystemDrive); } MemoryHandler.RunGarbageCollect(); }
public void Init() { var config = new MemoryPosition { checksum = new ChecksumData[] { new ChecksumData { dataStartOffset = 0x1D29, dataEndOffset = 0x1D48, checksumOffset = 0x1D49, checksum = "16bit", name = "HIGHSCORE" } } }; memoryHandler = MemoryHandler.getInstance(config, Enumerable.Repeat((byte)0, 8192).ToArray()); }
public PostGameCarnageEntry(MemoryHandler memory, byte index) { this._memory = memory; this._index = index; this.calcBaseOffset = baseOffset + (0x94 * index); this.calcRTPCROffset = rtPCROffset + (0x36A * index); var tName = Gamertag; for (var i = 0; i < 16; i++) { if (tName == _memory.ReadStringUnicode(PCROffset + (i * 0x110), 16, true)) { calcPCROffset = PCROffset + (i * 0x110); EndGameIndex = i; } } }
public string GetWorld() { if (!CanGetWorld() || !MemoryHandler.IsAttached) { return(string.Empty); } var worldMap = (IntPtr)Scanner.Locations[Signatures.WorldKey]; try { var world = MemoryHandler.GetString(worldMap, MemoryHandler.Structures.World.Offset, MemoryHandler.Structures.World.SourceSize); return(world); } catch (Exception ex) { MemoryHandler?.RaiseException(ex); } return(string.Empty); }
public void FindSignatures() { Debug.Assert(MemoryHandler != null, "No memory handler was specified. Ensure MemoryHandler is not null before calling FindSignatures()."); // MobArray is the address that holds a pointer to the mob array. MobArrayPosition is the address that holds the position. this.MobArray = MemoryHandler.ResolvePointer(SignatureScanner.FindPattern(new byte[] { 0x8B, 0x56, 0x0C, 0x8B, 0x04, 0x2A, 0x8B, 0x04, 0x85 }, "xxxxxxxxx", 9)); this.MobArrayPosition = SignatureScanner.FindPattern(new byte[] { 0x66, 0xC7, 0x44, 0x24, 0x10, 0x79, 0x00, 0x50 }, "xxxxxxxx", 37); this.BuffPtr = MemoryHandler.ResolvePointer(SignatureScanner.FindPattern(new byte[] { 0xEB, 0x0E, 0x33, 0xDB, 0x8A, 0xF8, 0x8A, 0xD9, 0x66, 0x89, 0x1C, 0x55 }, "xxxxxxxxxxxx", 12)); this.ZonePtr = SignatureScanner.FindPattern(new byte[] { 0x7C, 0xE1, 0x8B, 0x4E, 0x08, 0x8B, 0x15 }, "xxxxxxx", 7); var index = (short)MemoryHandler.ResolvePointer(MemoryHandler.ResolvePointer(this.MobArrayPosition) + 4); this.PlayerEntity = new Entity(MemoryHandler, MemoryHandler.ResolvePointer(MobArray + 4 * index)); this.PlayerDisplay = new Display(MemoryHandler, PlayerEntity.Display); this.PlayerBuffs = new Buffs(MemoryHandler, this.BuffPtr); }
public List<Command> ProcessStatement(string statement, ref int pc, ref MemoryHandler mem, ref Dictionary<string, bool> compilerFlags) { var half = statement.Split('('); var commands = new List<Command>(); commands.Add(new Command(Operator.ReadCard, pc++)); Operator opSwitch; switch (half[0]) { case "readCard": opSwitch = Operator.ReadCard; break; case "clearAccumulator": opSwitch = Operator.ClearAccumulator; break; case "addToAccumulator": opSwitch = Operator.AddToAccumulator; break; //ToDo: Jump to flags case "jumpIfNegative": opSwitch = Operator.JumpIfNegative; break; case "shiftAccumulator": opSwitch = Operator.ShiftAccumulator; break; case "writeCard": opSwitch = Operator.WriteCard; break; case "storeAccumulator": opSwitch = Operator.StoreAccumulator; break; case "subtractFromAccumulator": opSwitch = Operator.SubtractFromAccumulator; break; case "halt": opSwitch = Operator.Halt; break; default: opSwitch = Operator.RawValue; break; } commands.Add(new Command(opSwitch, ProcessArg(half[1], mem))); return commands; }
public string GetCharacterId() { var id = ""; if (!CanGetCharacterId() || !MemoryHandler.IsAttached) { return(id); } var characterIdMap = (IntPtr)Scanner.Locations[Signatures.CharacterIdKey]; try { id = MemoryHandler.GetString(characterIdMap, MemoryHandler.Structures.CharacterId.Offset, MemoryHandler.Structures.CharacterId.SourceSize); } catch (Exception ex) { MemoryHandler?.RaiseException(ex); } return(id); }
public void Update() { var index = (short)MemoryHandler.ResolvePointer(MemoryHandler.ResolvePointer(this.MobArrayPosition) + 4); this.PlayerEntity.UpdateWithAddress(MemoryHandler.ResolvePointer(MobArray + 4 * index)); this.PlayerDisplay.UpdateWithAddress(PlayerEntity.Display); this.PlayerBuffs.UpdateWithAddress(BuffPtr); int ZoneTemp = (int)MemoryHandler.ResolvePointer(MemoryHandler.ResolvePointer(ZonePtr)); if (ZoneTemp > 0xFF) { Zone = ZoneTemp - 0x1BC; } else { Zone = ZoneTemp; } }
public List<Command> ProcessStatement(string statement, ref int pc, ref MemoryHandler mem, ref Dictionary<string, bool> compilerFlags) { var commands = new List<Command>(); var parts = statement.Split(' '); if (parts[0] == "flag") { _flags.Add(parts[1], pc); return commands; } if (parts[0] == "goto") { if (_flags.ContainsKey(parts[1])) { commands.Add(new Command(Operator.JumpTo, _flags[parts[1]])); return Command.LoadToCards(commands, ref pc); } } throw new CompilerException("Invalid Goto/Flag statement", -1); }
private void SetupSharlayanManager() { foreach (Process process in this._gameInstances) { SharlayanConfiguration sharlayanConfiguration = new SharlayanConfiguration { ProcessModel = new ProcessModel { Process = process, }, }; MemoryHandler handler = SharlayanMemoryManager.Instance.AddHandler(sharlayanConfiguration); handler.OnException += delegate { }; handler.OnMemoryLocationsFound += delegate(object sender, ConcurrentDictionary <string, MemoryLocation> memoryLocations, long processingTime) { foreach ((string key, MemoryLocation memoryLocation) in memoryLocations) { Console.WriteLine($"Process[{handler.Configuration.ProcessModel.ProcessID}] -> MemoryLocation Found -> {key} => {memoryLocation.GetAddress():X}"); } }; } }
public SortedDictionary <uint, string> GetPartyMembers() { var result = new SortedDictionary <uint, string>(); if (!CanGetPartyMembers() || !MemoryHandler.IsAttached) { return(result); } var partyInfoMap = (IntPtr)Scanner.Locations[Signatures.PartyMapKey]; var partyCountMap = Scanner.Locations[Signatures.PartyCountKey]; try { var partyCount = MemoryHandler.GetByte(partyCountMap); var sourceSize = MemoryHandler.Structures.PartyMember.SourceSize; if (partyCount > 1 && partyCount < 9) { for (uint i = 0; i < partyCount; i++) { var address = partyInfoMap.ToInt64() + i * (uint)sourceSize; var source = MemoryHandler.GetByteArray(new IntPtr(address), sourceSize); var actorId = SBitConverter.TryToUInt32(source, MemoryHandler.Structures.PartyMember.ID); var playerName = MemoryHandler.GetStringFromBytes(source, MemoryHandler.Structures.PartyMember.Name); if (ActorIdTools.RangeOkay(actorId) && !string.IsNullOrEmpty(playerName)) { result[actorId] = playerName; } } } if (result.Count == 1) { result.Clear(); } } catch (Exception ex) { MemoryHandler?.RaiseException(ex); } return(result); }
public List<Command> ProcessStatement(string statement, ref int pc, ref MemoryHandler mem, ref Dictionary<string, bool> compilerFlags) { //Fancy Linq for removing all spaces from the string var processedStatement = statement.Where(c => c != ' ').Aggregate("", (current, c) => current + c); if (processedStatement.Contains('=')) { var commands = new List<Command>(); if (processedStatement.Contains("+=") || processedStatement.Contains("-=")) { var parts = processedStatement.Split(new string[]{ "+=", "-=" }, StringSplitOptions.RemoveEmptyEntries); var resultName = parts[0]; var op = parts[1]; op = mem.MakeConstantIfNeeded(op, ref commands, ref pc); //If adding/subtracting to accumulator, can skip saving old if (resultName != "acc") { if (!compilerFlags["accumulatorIsVolatile"]) commands.Add(new Command(Operator.StoreAccumulator, 98)); commands.Add(new Command(Operator.ClearAccumulator, mem[resultName])); } if (processedStatement.Contains('+')) commands.Add(new Command(Operator.AddToAccumulator, mem[op])); else if (processedStatement.Contains('-')) commands.Add(new Command(Operator.SubtractFromAccumulator, mem[op])); //If adding/subtracting to accumulator, can skip restore and saving if (resultName != "acc") { if (!mem.IsReserved(resultName)) mem.Reserve(resultName); commands.Add(new Command(Operator.StoreAccumulator, mem[resultName])); if (!compilerFlags["accumulatorIsVolatile"]) { commands.Add(new Command(Operator.ClearAccumulator, 98)); } } return Command.LoadToCards(commands, ref pc); } else { //A=B+C var parts = processedStatement.Split('=', '*', '/', '+', '-'); var resultName = parts[0]; var op1 = parts[1]; //operand 1 var op2 = parts[2]; //operand 2 //Dump acc into mem(98) //put op1 in acc //add/sub to acc //Reserve mem for result (maybe) //dump acc to mem() //restore acc op1 = mem.MakeConstantIfNeeded(op1, ref commands, ref pc); op2 = mem.MakeConstantIfNeeded(op2, ref commands, ref pc); //If adding/subtracting to accumulator, can skip saving old //If adding/subtracting to accumulator, can skip saving old if (resultName != "acc") { if (!compilerFlags["accumulatorIsVolatile"]) commands.Add(new Command(Operator.StoreAccumulator, 98)); commands.Add(new Command(Operator.ClearAccumulator, mem[op1])); } if (processedStatement.Contains('+')) commands.Add(new Command(Operator.AddToAccumulator, mem[op2])); else if (processedStatement.Contains('-')) commands.Add(new Command(Operator.SubtractFromAccumulator, mem[op2])); //If adding/subtracting to accumulator, can skip restore and saving if (resultName != "acc") { if (!mem.IsReserved(resultName)) mem.Reserve(resultName); commands.Add(new Command(Operator.StoreAccumulator, mem[resultName])); if (!compilerFlags["accumulatorIsVolatile"]) { commands.Add(new Command(Operator.ClearAccumulator, 98)); } } return Command.LoadToCards(commands, ref pc); } } else { //A++, A-- var add = processedStatement.Contains('+'); var variable = processedStatement.Trim('+', '-'); var commands = new List<Command>(); //Store accumulator to 98 //Load variable //Increment/deincrement //Store variable //restore accumulator //if target is not acc we can skip saving the acc if (variable != "acc") { var memLocation = mem[variable]; commands.Add(new Command(Operator.StoreAccumulator, 98)); if (!compilerFlags["accumulatorIsVolatile"]) commands.Add(new Command(Operator.ClearAccumulator, memLocation)); } commands.Add(new Command(add ? Operator.AddToAccumulator : Operator.SubtractFromAccumulator, 96)); //mem(96) contains variable 'one' if (variable != "acc" && !compilerFlags["accumulatorIsVolatile"]) { commands.Add(new Command(Operator.StoreAccumulator, mem[variable])); if (!compilerFlags["accumulatorIsVolatile"]) commands.Add(new Command(Operator.ClearAccumulator, 98)); } return Command.LoadToCards(commands, ref pc); } }
public static void WriteVals(float min, float max, MemoryHandler m) { m.Write<float>(m.Process.MainModule.BaseAddress.Add(pSqrRad), min * max); m.Write<float>(m.Process.MainModule.BaseAddress.Add(pMaxRad), max); m.Write<float>(m.Process.MainModule.BaseAddress.Add(pMinRad), min); }
public static void WriteVals(bool enable, MemoryHandler m) { m.WriteByte(m.Process.MainModule.BaseAddress.Add(enableHiding), enable ? (byte)1 : (byte)0); }