public bool RomCrcValid(ROM rom) { if (LogicParser.SubParser.RomCrc != null) { return(PatchUtil.Crc32(rom.romData, rom.romData.Length) == LogicParser.SubParser.RomCrc); } else { return(true); } }
public static void Undo() { if (!isApplied) { return; } PatchUtil.Unpatch(new PatchUtil.MethodDefinition(typeof(global::CargoTruckAI), nameof(global::CargoTruckAI.ChangeVehicleType), BindingFlags.Static | BindingFlags.Public)); isApplied = false; }
public static void Revert() { if (!deployed) { return; } PatchUtil.Unpatch( new PatchUtil.MethodDefinition(typeof(BuildingInfo), nameof(BuildingInfo.InitializePrefab))); deployed = false; }
public static void Undo() { if (!deployed) { return; } PatchUtil.Unpatch( new PatchUtil.MethodDefinition(typeof(VehicleInfo), nameof(VehicleInfo.InitializePrefab))); deployed = false; }
public static void Apply() { if (deployed) { return; } PatchUtil.Patch( new PatchUtil.MethodDefinition(typeof(VehicleInfo), nameof(VehicleInfo.InitializePrefab)), new PatchUtil.MethodDefinition(typeof(InitializePrefabPatch), nameof(PreInitializePrefab))); deployed = true; }
public uint GetSettingHash() { byte[] settingBytes = LogicParser.SubParser.GetSettingBytes(); if (settingBytes.Length > 0) { return(PatchUtil.Crc32(settingBytes, settingBytes.Length)); } else { return(0); } }
public uint GetGimmickHash() { byte[] gimmickBytes = LogicParser.SubParser.GetGimmickBytes(); if (gimmickBytes.Length > 0) { return(PatchUtil.Crc32(gimmickBytes, gimmickBytes.Length)); } else { return(0); } }
public static void Apply() { if (isApplied) { return; } PatchUtil.Patch( new PatchUtil.MethodDefinition(typeof(global::CargoTruckAI), nameof(global::CargoTruckAI.ChangeVehicleType), BindingFlags.Static | BindingFlags.Public), null, null, new PatchUtil.MethodDefinition(typeof(ChangeVehicleTypePatch), (nameof(Transpile)))); isApplied = true; }
public static void Undo() { PatchUtil.Unpatch(new PatchUtil.MethodDefinition(typeof(PostVanAI), "StartPathFind", BindingFlags.Default, new[] { typeof(ushort), typeof(Vehicle).MakeByRefType(), typeof(Vector3), typeof(Vector3), typeof(bool), typeof(bool), typeof(bool) })); }
public static void Deploy() { if (deployed) { return; } PatchUtil.Patch( new PatchUtil.MethodDefinition(typeof(BuildingInfo), nameof(BuildingInfo.InitializePrefab)), new PatchUtil.MethodDefinition(typeof(InitializePrefabPatch), nameof(PreInitializeHook)), new PatchUtil.MethodDefinition(typeof(InitializePrefabPatch), nameof(PostInitializeHook)) ); deployed = true; }
public static void Apply() { PatchUtil.Patch( new PatchUtil.MethodDefinition(typeof(PostVanAI), "StartPathFind", BindingFlags.Default, new[] { typeof(ushort), typeof(Vehicle).MakeByRefType(), typeof(Vector3), typeof(Vector3), typeof(bool), typeof(bool), typeof(bool) }), null, null, new PatchUtil.MethodDefinition(typeof(VehicleTypeReplacingTranspiler), (nameof(VehicleTypeReplacingTranspiler.Transpile)))); }
private void LoadRom() { OpenFileDialog ofd = new OpenFileDialog { Filter = "GBA ROMs|*.gba|All Files|*.*", Title = "Select TMC ROM" }; if (ofd.ShowDialog() != DialogResult.OK) { return; } try { ROM_ = new ROM(ofd.FileName); } catch (Exception e) { Console.WriteLine(e); throw; } if (ROM.Instance.version.Equals(RegionVersion.None)) { MessageBox.Show("Invalid TMC ROM. Please Open a valid ROM.", "Incorrect ROM", MessageBoxButtons.OK); statusText.Text = "Unable to determine ROM."; ROM_ = null; return; } if (!shuffler.RomCrcValid(ROM_)) { Console.WriteLine(StringUtil.AsStringHex8((int)PatchUtil.Crc32(ROM_.romData, ROM_.romData.Length))); MessageBox.Show("ROM does not match the expected CRC for the logic file", "Incorrect ROM", MessageBoxButtons.OK); statusText.Text = "ROM not valid"; ROM_ = null; return; } }
private static void Transpile(Type type, string methodName) { PatchUtil.Patch(new PatchUtil.MethodDefinition(type, methodName), null, null, new PatchUtil.MethodDefinition(typeof(XYZBuildingAIPatch), nameof(TranspileMethod))); }
private static string MakeTextList(byte[] data, string title) { //Console.WriteLine($"MakeTextList: data length = {data.Length} bytes"); StringBuilder sb = new StringBuilder(); sb.Append("SINGLE patches:\n"); int offset = 0; for (int i = 0; i < SinglePatchCount; i++) { byte[] singleData = new byte[SinglePatch.DataSize]; Buffer.BlockCopy(data, offset, singleData, 0, SinglePatch.DataSize); //Console.WriteLine($"Constructing single patch from {singleData.Length} bytes of data starting at {offset}"); SinglePatch single = new SinglePatch(singleData); string name = PatchUtil.GetPatchName(i); sb.Append($"S{name} {single.Name}\n"); if ((i + 1) % 16 == 0) { sb.Append("\n"); } offset += SinglePatch.DataSize; } sb.Append("\n"); sb.Append("MULTI patches:\n"); for (int i = 0; i < MultiPatchCount; i++) { byte[] multiData = new byte[MultiPatch.DataSize]; Buffer.BlockCopy(data, offset, multiData, 0, MultiPatch.DataSize); //Console.WriteLine($"Constructing multi patch from {multiData.Length} bytes of data starting at {offset}"); MultiPatch multi = new MultiPatch(multiData); string name = PatchUtil.GetPatchName(i); sb.Append($"M{name} {multi.Name}\n"); if ((i + 1) % 16 == 0) { sb.Append("\n"); } offset += MultiPatch.DataSize; } /* * sb.Append("\n"); * sb.Append("DRUM:\n"); * byte[] drumData = new byte[DrumPatch.DataSize]; * Buffer.BlockCopy(data, offset, drumData, 0, DrumPatch.DataSize); * Console.WriteLine($"Constructing drum patch from {drumData.Length} bytes of data starting at {offset}"); * DrumPatch drumPatch = new DrumPatch(drumData); */ offset += DrumPatch.DataSize; sb.Append("\n"); sb.Append("EFFECT SETTINGS:\n"); for (int i = 0; i < 32; i++) { byte[] effectData = new byte[EffectPatch.DataSize]; Buffer.BlockCopy(data, offset, effectData, 0, EffectPatch.DataSize); //Console.WriteLine($"Constructing effect patch from {effectData.Length} bytes of data starting at {offset}"); EffectPatch effectPatch = new EffectPatch(effectData); sb.Append($"E-{i+1,2} {effectPatch}"); offset += EffectPatch.DataSize; } return(sb.ToString()); }
private static string MakeHtmlList(byte[] data, string title) { string GetNoteName(int noteNumber) { string[] notes = new string[] { "C", "C#", "D", "Eb", "E", "F", "F#", "G", "G#", "A", "Bb", "B" }; int octave = noteNumber / 12 + 1; string name = notes[noteNumber % 12]; return(name + octave); } StringBuilder sb = new StringBuilder(); sb.Append(String.Format("<h1>{0}</h1>\n", title)); SinglePatch[][] singleBanks = new SinglePatch[BankCount][]; //BankCount, PatchesPerBank]; int offset = 0; int patchSize = SinglePatch.DataSize; for (int bankNumber = 0; bankNumber < BankCount; bankNumber++) { SinglePatch[] patches = new SinglePatch[PatchesPerBank]; for (int patchNumber = 0; patchNumber < PatchesPerBank; patchNumber++) { byte[] singleData = new byte[patchSize]; Buffer.BlockCopy(data, offset, singleData, 0, patchSize); SinglePatch single = new SinglePatch(singleData); patches[patchNumber] = single; offset += patchSize; } singleBanks[bankNumber] = patches; } // Now we should have all the single patches collected in four lists of 16 each sb.Append("<table>\n"); sb.Append("<tr>\n <th>SINGLE</th>\n"); for (int bankNumber = 0; bankNumber < BankCount; bankNumber++) { char bankLetter = "ABCD"[bankNumber]; sb.Append(String.Format(" <th>{0}</th>\n", bankLetter)); } sb.Append("</tr>\n"); for (int patchNumber = 0; patchNumber < PatchesPerBank; patchNumber++) { sb.Append("<tr>\n"); sb.Append(String.Format(" <td>{0,2}</td>\n", patchNumber + 1)); for (int bankNumber = 0; bankNumber < BankCount; bankNumber++) { SinglePatch[] patches = singleBanks[bankNumber]; string patchId = PatchUtil.GetPatchName(bankNumber * patchNumber); SinglePatch single = patches[patchNumber]; sb.Append(String.Format($" <td>{single.Name:10}</td>\n")); } sb.Append("</tr>\n"); } sb.Append("</table>\n"); // // Multi patches // patchSize = MultiPatch.DataSize; MultiPatch[][] multiBanks = new MultiPatch[BankCount][]; for (int bankNumber = 0; bankNumber < BankCount; bankNumber++) { MultiPatch[] patches = new MultiPatch[PatchesPerBank]; for (int patchNumber = 0; patchNumber < PatchesPerBank; patchNumber++) { byte[] multiData = new byte[patchSize]; Buffer.BlockCopy(data, offset, multiData, 0, patchSize); MultiPatch multi = new MultiPatch(multiData); patches[patchNumber] = multi; offset += patchSize; } multiBanks[bankNumber] = patches; } sb.Append("<table>\n"); sb.Append("<tr>\n <th>MULTI</th>\n"); for (int bankNumber = 0; bankNumber < BankCount; bankNumber++) { char bankLetter = "ABCD"[bankNumber]; sb.Append(String.Format(" <th>{0}</th>\n", bankLetter)); } sb.Append("</tr>\n"); for (int patchNumber = 0; patchNumber < PatchesPerBank; patchNumber++) { sb.Append("<tr>\n"); sb.Append(String.Format(" <td>{0,2}</td>\n", patchNumber + 1)); for (int bankNumber = 0; bankNumber < BankCount; bankNumber++) { MultiPatch[] patches = multiBanks[bankNumber]; string patchId = PatchUtil.GetPatchName(bankNumber * patchNumber); MultiPatch single = patches[patchNumber]; sb.Append(String.Format($" <td>{single.Name:10}</td>\n")); } sb.Append("</tr>\n"); } sb.Append("</table>\n"); patchSize = DrumPatch.DataSize; // TODO: List drum // Crash when setting tune of drum note (value out of range) /* * sb.Append("<table>\n"); * sb.Append("<caption>DRUM</caption>\n"); * sb.Append("<tr><th>Note</th><th>Parameters</th></tr>\n"); * * patchSize = DrumPatch.DataSize; * byte[] drumData = new byte[patchSize]; * Buffer.BlockCopy(data, offset, drumData, 0, patchSize); * var drum = new DrumPatch(drumData); * for (int i = 0; i < 128; i++) * { * var note = drum.Notes[i]; * sb.Append($"<tr><td>E-{GetNoteName(i)}</td><td>{note}</td></tr>\n"); * } * * sb.Append("</table>\n"); */ offset += patchSize; sb.Append("<table>\n"); sb.Append("<caption>EFFECT</caption>\n"); sb.Append("<tr><th>#</th><th>Type and parameters</th></tr>\n"); patchSize = EffectPatch.DataSize; for (int i = 0; i < 32; i++) { byte[] effectData = new byte[patchSize]; Buffer.BlockCopy(data, offset, effectData, 0, patchSize); //Console.WriteLine($"Constructing effect patch from {effectData.Length} bytes of data starting at {offset}"); EffectPatch effectPatch = new EffectPatch(effectData); sb.Append($"<tr><td>E-{i+1,2}</td><td>{effectPatch}</td></tr>\n"); offset += patchSize; } sb.Append("</table>\n"); return(sb.ToString()); }
public static void Undo() { PatchUtil.Unpatch(new PatchUtil.MethodDefinition(typeof(CargoTruckAI), nameof(CargoTruckAI.ChangeVehicleType), BindingFlags.Static | BindingFlags.Public)); }
public static void Undo() { PatchUtil.Unpatch( new PatchUtil.MethodDefinition(typeof(TransportLine), nameof(TransportLine.SimulationStep)) ); }
public static void Undo() { PatchUtil.Unpatch( new PatchUtil.MethodDefinition(typeof(VehicleManager), "ReleaseWaterSource") ); }
public static void Undo() { PatchUtil.Unpatch( new PatchUtil.MethodDefinition(typeof(DepotAI), nameof(DepotAI.StartTransfer)) ); }
public static void Undo() { PatchUtil.Unpatch( new PatchUtil.MethodDefinition(typeof(NetManager), nameof(NetManager.ReleaseNode)) ); }
public static void Undo() { PatchUtil.Unpatch(new PatchUtil.MethodDefinition(typeof(PathFind), "ProcessItem", argumentTypes: FindProcessItemMethodArgTypes())); }
public static void Undo() { PatchUtil.Unpatch(new PatchUtil.MethodDefinition(typeof(DepotAI), "CreateVehicle", BindingFlags.Instance | BindingFlags.NonPublic)); }
public static void Undo() { PatchUtil.Unpatch( new PatchUtil.MethodDefinition(typeof(TransportLineAI), "AddLaneConnection") ); }
private static void Restore(Type type, string methodName) { PatchUtil.Unpatch(new PatchUtil.MethodDefinition(type, methodName)); }
private static void UnpatchLoadPassengers(Type type) { PatchUtil.Unpatch(new PatchUtil.MethodDefinition(type, LoadPassengersMethod)); }
public string GetEventWrites() { StringBuilder eventBuilder = new StringBuilder(); foreach (Location location in Locations) { location.WriteLocationEvent(eventBuilder); } foreach (EventDefine define in LogicParser.GetEventDefines()) { define.WriteDefineString(eventBuilder); } byte[] seedValues = new byte[4]; seedValues[0] = (byte)((Seed >> 00) & 0xFF); seedValues[1] = (byte)((Seed >> 08) & 0xFF); seedValues[2] = (byte)((Seed >> 16) & 0xFF); seedValues[3] = (byte)((Seed >> 24) & 0xFF); eventBuilder.AppendLine("#define seedHashed 0x" + StringUtil.AsStringHex8((int)PatchUtil.Crc32(seedValues, 4))); eventBuilder.AppendLine("#define settingHash 0x" + StringUtil.AsStringHex8((int)GetSettingHash())); return(eventBuilder.ToString()); }
public static void Undo() { PatchUtil.Unpatch(new PatchUtil.MethodDefinition(typeof(PanelExtenderCityService), "OnSelectedPrefabsChanged")); }
public static void Undo() { PatchUtil.Unpatch(new PatchUtil.MethodDefinition(typeof(FerryAI), nameof(FerryAI.SimulationStep), argumentTypes: new Type[] { typeof(ushort), typeof(Vehicle).MakeByRefType(), typeof(Vector3) })); }