private void SetCoachData(string line) { //"Coach,Team,fname,lname,Body,Photo"; string[] keyParts = Tool.CoachKey.Split(",".ToCharArray()); List <string> parts = ParseCoachLine(line); int teamIndex = Tool.GetTeamIndex(parts[1]); string[] enumNames = Enum.GetNames(typeof(CoachOffsets)); CoachOffsets current = CoachOffsets.Body; try { for (int i = 2; i < keyParts.Length; i++) { if (i == parts.Count) { break; // stop processing if we're out of parts } switch (keyParts[i].ToLower()) { case "firstname": case "fname": Tool.SetCoachAttribute(teamIndex, CoachOffsets.FirstName, parts[i]); break; case "lastname": case "lname": Tool.SetCoachAttribute(teamIndex, CoachOffsets.LastName, parts[i]); break; default: current = (CoachOffsets)Enum.Parse(typeof(CoachOffsets), keyParts[i], true); Tool.SetCoachAttribute(teamIndex, current, parts[i]); break; } } } catch (Exception) { StaticUtils.AddError(string.Format("Error setting data for line:\r\n{0}\r\n\r\nPerhaps check '{1}' attribute.", line, current.ToString())); } }
public string GetCoachAttribute(int teamIndex, CoachOffsets attr) { string retVal = "!!!!Invalid!!!!"; if (teamIndex < 32) { int coachPointer = GetCoachPointer(teamIndex); int coach_ptr = GetPointerDestination(coachPointer); int str_ptr = 0; int loc = coach_ptr + (int)attr; switch (attr) { case CoachOffsets.FirstName: case CoachOffsets.LastName: case CoachOffsets.Info1: case CoachOffsets.Info2: str_ptr = coach_ptr + (int)attr; retVal = GetName(str_ptr); break; case CoachOffsets.Body: int body_ptr = coach_ptr + (int)CoachOffsets.Body; int bodyNumber = GameSaveData[body_ptr]; retVal = mReverseCoachMap[bodyNumber]; break; case CoachOffsets.Photo: int val = GameSaveData[loc + 1] << 8; val += GameSaveData[loc]; retVal = "" + val; switch (retVal.Length) { case 3: retVal = "0" + retVal; break; case 2: retVal = "00" + retVal; break; case 1: retVal = "000" + retVal; break; } break; default: retVal = "" + GameSaveData[loc]; break; } } if (retVal.IndexOf(',') > -1) { retVal = "\"" + retVal + "\""; } return retVal; }
public void SetCoachAttribute(int teamIndex, CoachOffsets attr, string value) { if (teamIndex < 32) { int coachPointer = GetCoachPointer(teamIndex); int coach_loc = GetPointerDestination(coachPointer); int string_ptr = 0; int loc = coach_loc + (int)attr; int val, v1, v2; string strVal; switch (attr) { case CoachOffsets.FirstName: case CoachOffsets.LastName: case CoachOffsets.Info1: case CoachOffsets.Info2: //string_ptr = coach_ptr + (int)attr; SetCoachString(value.Replace("\"", ""), loc); break; case CoachOffsets.Photo: val = Int32.Parse(value); v1 = val & 0xff; v2 = val >> 8; SetByte(loc, (byte)v1); SetByte(loc + 1, (byte)v2); break; case CoachOffsets.Body: strVal = value.Replace("[", "").Replace("]", ""); if (mCoachMap.ContainsKey(strVal)) SetByte(loc, (byte)mCoachMap[strVal]); else StaticUtils.AddError(String.Format("Error Setting Body '{0}' value for {1} Coach ", value, mTeamsDataOrder[teamIndex])); break; default: v1 = Int32.Parse(value); SetByte(loc, (byte)v1); break; } } }