protected virtual T Decode <T>(IConverterContext ctx, MPObject mpo, MPType mpt) { var t = typeof(T); if (mpo.Type == MPType.Nil) { if (!t.IsValueType) { return(default(T)); } if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Nullable <>)) { return((T)(object)null); } } if (mpo.Type == mpt) { return((T)mpo.Value); } throw new MPConversionException(typeof(T), mpo, message: $"cannot decode MP type [{mpo.Type}][{mpo.Value}] as intended MP type [{mpt}]"); }
/////////////////////////////////////////////////////////////////////////////// // Construction and Initializing methods // /////////////////////////////////////////////////////////////////////////////// #region CONSTRUCTION /// <summary> /// Initializes a new instance of the MPEnvelopes class. /// </summary> /// <param name="newDefaultValue">An <see cref="MPData"/> with the default value</param> /// <param name="newValidCaps">The valid capabilities</param> /// <param name="newMPType">The <see cref="MPType"/> of the envelope.</param> /// <param name="newMinValue">The <see cref="MPData"/> with the minimal value for the envelope.</param> /// <param name="newMaxValue">The <see cref="MPData"/> with the maximal value for the envelope.</param> public MPEnvelopes( MPData newDefaultValue, MPCaps newValidCaps, MPType newMPType, MPData newMinValue, MPData newMaxValue) { // Store the neutralValue, min/max value range, data type and supported curve types this.defaultValue = newDefaultValue; this.validCaps = (int)newValidCaps; this.dataType = newMPType; this.minValue = newMinValue; this.maxValue = newMaxValue; // Create an array to hold the segments (size = 3 was chosen arbitrarily) this.envelope = new ArrayList(3); // Create one segment that spans all time containing the default values MPEnvelopeSegment e = new MPEnvelopeSegment(); e.flags = MPFlags.BeginNeutralVal; e.iCurve = MPCaps.Jump; e.rtStart = 0; e.rtEnd = MaxTime; e.valStart = this.defaultValue; e.valEnd = this.defaultValue; this.envelope.Add(e); }
List <String> GetAllGeneratedDevCodes(MPType type, String GameRegion) { var Dir = default(String); if (type == MPType.PRIME) { if (File.Exists("ugc_mp1.list")) { return(File.ReadAllLines("ugc_mp1.list").ToList()); } Dir = DolphinConfigFolder + Path.DirectorySeparatorChar + "GameSettings"; if (!Directory.Exists(Dir)) { return(new List <String>()); } return(Directory.EnumerateFiles( Dir, MP1BaseString + GameRegion + "*.ini" ).Select((str) => { var match = Regex.Match(str, @"[A-Z0-9]{6}\.ini"); if (match.Success) { return match.Value.Substring(4, 2); } return str; }).ToList()); } if (type == MPType.PRIME_2) { if (File.Exists("ugc_mp2.list")) { return(File.ReadAllLines("ugc_mp2.list").ToList()); } Dir = DolphinConfigFolder + Path.DirectorySeparatorChar + "GameSettings"; if (!Directory.Exists(Dir)) { return(new List <String>()); } return(Directory.EnumerateFiles( Dir, MP2BaseString + GameRegion + "*.ini" ).Select((str) => { var match = Regex.Match(str, @"[A-Z0-9]{6}\.ini"); if (match.Success) { return match.Value.Substring(4, 2); } return str; }).ToList()); } throw new Exception("Game unsupported"); }
private void Patch_btn_Click(object sender, EventArgs e) { String GameCode = String.Empty; String GameRegion = String.Empty; String TargetGameCode = String.Empty; MPType GameType = MPType.UNK; String TargetConfigFile = String.Empty; if (this.ISOtoPatch_txtBox.Text == "") { MessageBox.Show("Set the path of the ISO you want to generate a game code"); return; } GameCode = ISOManager.GetISOGameCode(this.ISOtoPatch_txtBox.Text); if (GameCode == "ERROR") { MessageBox.Show("This is not a GC ISO"); return; } GameRegion = GameCode.Substring(3, 1); if (GameCode.Substring(0, 3) == MP1BaseString) { GameType = MPType.PRIME; } else if (GameCode.Substring(0, 3) == MP2BaseString) { GameType = MPType.PRIME_2; } else { MessageBox.Show("This game is not Metroid Prime 1 or 2!"); return; } TargetGameCode = RandomizeGameCode(GameType, GameRegion, comboBox1.Text == comboBox1.Items[1].ToString()); if (comboBox1.Text != comboBox1.Items[0].ToString()) { if (Directory.Exists(GameSettingsFolder)) { if (File.Exists(GameSettingsFolder + Path.DirectorySeparatorChar + GameCode.Substring(0, 4) + "01.ini")) { if (comboBox1.Text == comboBox1.Items[1].ToString()) { TargetConfigFile = GameSettingsFolder + "\\" + TargetGameCode + ".ini"; File.Copy(GameSettingsFolder + Path.DirectorySeparatorChar + GameCode.Substring(0, 4) + "01.ini", TargetConfigFile); File.WriteAllText(TargetConfigFile, File.ReadAllText(TargetConfigFile) + "\r\n\r\n# " + Path.GetFileNameWithoutExtension(this.ISOtoPatch_txtBox.Text)); } if (comboBox1.Text == comboBox1.Items[2].ToString()) { TargetConfigFile = Path.GetDirectoryName(this.ISOtoPatch_txtBox.Text) + Path.DirectorySeparatorChar + TargetGameCode + ".ini"; File.Copy(GameSettingsFolder + Path.DirectorySeparatorChar + GameCode.Substring(0, 4) + "01.ini", TargetConfigFile); File.WriteAllText(TargetConfigFile, File.ReadAllText(TargetConfigFile) + "\r\n\r\n# " + Path.GetFileNameWithoutExtension(this.ISOtoPatch_txtBox.Text)); } } } } ISOManager.PatchGameCode(this.ISOtoPatch_txtBox.Text, TargetGameCode); ISOManager.PatchGameTitle(this.ISOtoPatch_txtBox.Text, Path.GetFileNameWithoutExtension(this.ISOtoPatch_txtBox.Text)); MessageBox.Show("Game patched with Game Code \"" + TargetGameCode + "\"\r\nand with Game Title \"" + Path.GetFileNameWithoutExtension(this.ISOtoPatch_txtBox.Text) + "\""); }
public MPEnvelopes(MPData iDefaultValue, MPCaps iValidCaps, MPType mt, MPData min, MPData max) { // Store the neutralValue, min/max value range, data type and supported curve types m_DefaultValue = iDefaultValue; m_ValidCaps = (int)iValidCaps; m_DataType = mt; m_MinVal = min; m_MaxVal = max; // Create an array to hold the segments (size = 3 was chosen arbitrarily) m_Envelope = new ArrayList(3); // Create one segment that spans all time containing the default values MPEnvelopeSegment e = new MPEnvelopeSegment(); e.flags = MPFlags.BeginNeutralVal; e.iCurve = MPCaps.Jump; e.rtStart = 0; e.rtEnd = MAX_TIME; e.valStart = m_DefaultValue; e.valEnd = m_DefaultValue; m_Envelope.Add(e); }
public MPObject(MPType t, object v) { Type = t; Value = v; }
String RandomizeGameCode(MPType type, String GameRegion, bool saveToList = false) { const String AllowedChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const int AllowedCharsLen = 36; var devCode = default(String); var usedGameCodes = default(List <String>); devCode = "01"; if (saveToList) { usedGameCodes = GetAllGeneratedDevCodes(type, GameRegion); } else { usedGameCodes = new List <String>(); } // Reserved for vanilla game if (!usedGameCodes.Contains("01")) { usedGameCodes.Add("01"); } switch (type) { case MPType.PRIME: if (GameRegion == "E") { // Reserved for Practice Mod if (!usedGameCodes.Contains("PM")) { usedGameCodes.Add("PM"); } } if (GameRegion == "P") { // Reserved for Scan Dash Enabled version if (!usedGameCodes.Contains("SD")) { usedGameCodes.Add("SD"); } } break; case MPType.PRIME_2: default: break; } while (usedGameCodes.Contains(devCode)) { devCode = new String(new char[] { AllowedChars[rand.Next(AllowedCharsLen)], AllowedChars[rand.Next(AllowedCharsLen)] }); } usedGameCodes.Add(devCode); if (usedGameCodes.Contains("01")) { usedGameCodes.Remove("01"); } switch (type) { case MPType.PRIME: if (GameRegion == "E") { if (usedGameCodes.Contains("PM")) { usedGameCodes.Remove("PM"); } } if (GameRegion == "P") { if (usedGameCodes.Contains("SD")) { usedGameCodes.Remove("SD"); } } if (saveToList) { File.WriteAllLines("ugc_mp1_" + GameRegion.ToLower() + ".list", usedGameCodes); } return(MP1BaseString + GameRegion + devCode); case MPType.PRIME_2: if (saveToList) { File.WriteAllLines("ugc_mp2_" + GameRegion.ToLower() + ".list", usedGameCodes); } return(MP2BaseString + GameRegion + devCode); default: throw new Exception("Game unsupported"); } }