// change the text of a field message public static void SetText(FileSource fieldSource, string fieldName, int messageId, string newText) { var fieldPath = FieldScript.GetFieldPath(fieldName); var msdPath = Path.Combine(fieldPath, fieldName + Globals.MessageFileExtension); var innerSource = new FileSource(fieldPath, fieldSource); var fieldText = MessageFile.FromSource(innerSource, msdPath); fieldText.Messages[messageId] = newText; innerSource.ReplaceFile(msdPath, fieldText.Encode()); }
private static void GiveFieldReward(FileSource fieldSource, int encounterID, int opCode, int[] args, string message) { var boss = Boss.Encounters[encounterID]; var fieldPath = Field.FieldScript.GetFieldPath(boss.FieldID); var innerSource = new FileSource(fieldPath, fieldSource); // add message var msdPath = Path.Combine(fieldPath, boss.FieldID + Globals.MessageFileExtension); var fieldText = MessageFile.FromSource(innerSource, msdPath); var msgID = fieldText.Messages.Count; fieldText.Messages.Add(message); // give reward var field = Field.FieldScript.FromSource(fieldSource, boss.FieldID); var script = field.Entities[boss.FieldEntity].Scripts[boss.FieldScript]; var index = script.Instructions.FindLastIndex(i => i.OpCode == Field.FieldScript.OpCodesReverse["battle"]) + 1; var awardInstructions = new List <Field.Instruction>(); var push = Field.FieldScript.OpCodesReverse["pshn_l"]; foreach (var a in args) { awardInstructions.Add(new Field.Instruction(push, a)); } awardInstructions.Add(new Field.Instruction(opCode)); // show message awardInstructions.Add(new Field.Instruction(push, 0)); awardInstructions.Add(new Field.Instruction(push, msgID)); awardInstructions.Add(new Field.Instruction(push, 70)); awardInstructions.Add(new Field.Instruction(push, 70)); awardInstructions.Add(new Field.Instruction(Field.FieldScript.OpCodesReverse["amesw"])); // apply changes script.Instructions.InsertRange(index, awardInstructions); innerSource.ReplaceFile(msdPath, fieldText.Encode()); innerSource.ReplaceFile(Field.FieldScript.GetFieldPath(boss.FieldID) + "\\" + boss.FieldID + Globals.ScriptFileExtension, field.Encode()); }