public void Process(object website, ProcessEventArgs args) { var Request = args.Request; var Uri = Request.Uri; if (Uri.ToString().StartsWith("/admin/")) { args.IsProcessed = true; args.Response = new HttpResponse(); var Response = args.Response; switch (Uri.FileName) { case "": case "admin.aspx": AdminPage.Process(Request, Response); break; case "GMAction.action": GMAction.Process(Request, Response); break; default: args.Response = ErrorHelper.Build(404, 0, args.ServerName); break; } } }
/// <summary> /// Reads actions from a GM file /// </summary> private GMAction[] ReadActions() { // Get version. int version = ReadInt(); // Check version. if (version != 400) throw new Exception("Unsupported Pre-Action object version."); // Create an array of actions. GMAction[] actions = new GMAction[ReadInt()]; // Iterate through actions. for (int i = 0; i < actions.Length; i++) { // Create new action actions[i] = new GMAction(); // Get version. version = ReadInt(); // Check version. if (version != 440) throw new Exception("Unsupported Action object version."); // Get action properties. actions[i].LibraryId = ReadInt(); actions[i].ActionId = ReadInt(); actions[i].ActionKind = (ActionType)(ReadInt()); actions[i].AllowRelative = ReadBool(); actions[i].Question = ReadBool(); actions[i].CanApplyTo = ReadBool(); actions[i].ExecuteMode = (ExecutionType)(ReadInt()); // If the execute mode is a prefabbed function. if (actions[i].ExecuteMode == ExecutionType.Function) actions[i].ExecuteCode = ReadString(); else ReadBytes(ReadInt()); // If the execute mode is a script. if (actions[i].ExecuteMode == ExecutionType.Code) actions[i].ExecuteCode = ReadString(); else ReadBytes(ReadInt()); // Create an array of arguments. actions[i].Arguments = new GMArgument[ReadInt()]; // Number of argument types. int[] argTypes = new int[ReadInt()]; // Iterate through argument types for (int j = 0; j < argTypes.Length; j++) { // Read in argument type. argTypes[j] = ReadInt(); } // Read action data. actions[i].AppliesTo = ReadInt(); actions[i].Relative = ReadBool(); // Get actual number of arguments, most likely 8. int argsNum = ReadInt(); // Iterate through argument types. for (int k = 0; k < argsNum; k++) { // If the index is greater than or equal to the number of arguments, continue. if (k >= actions[i].Arguments.Length) { ReadBytes(ReadInt()); continue; } // Create a new argument object. actions[i].Arguments[k] = new GMArgument(); // Set what kind of argument. actions[i].Arguments[k].Type = (ArgumentType)(argTypes[k]); // Resource value. actions[i].Arguments[k].Value = ReadString(); } // If not checkbox has been checked. actions[i].Not = ReadBool(); } // Return action object. return actions; }
/// <summary> /// Writes actions from Game Maker project. /// </summary> private void WriteActions(GMAction[] actions, GMVersionType version) { // Write version. WriteInt(400); // Write the amount of actions. WriteInt(actions.Length); // Iterate through actions. for (int i = 0; i < actions.Length; i++) { // Write version. WriteInt(440); // Write action properties. WriteInt(actions[i].LibraryId); WriteInt(actions[i].ActionId); WriteInt((int)actions[i].ActionKind); WriteBool(actions[i].AllowRelative); WriteBool(actions[i].Question); WriteBool(actions[i].CanApplyTo); WriteInt((int)actions[i].ExecuteMode); // If the execute mode is a prefabbed function. if (actions[i].ExecuteMode == ExecutionType.Function) WriteString(actions[i].ExecuteCode); else WriteInt(0); // If the execute mode is a script. if (actions[i].ExecuteMode == ExecutionType.Code) WriteString(actions[i].ExecuteCode); else WriteInt(0); // Write the amount of arguments. WriteInt(actions[i].Arguments.Length); // Write the amount of argument types. WriteInt(8); // Iterate through argument types for (int j = 0; j < 8; j++) { // If the index is less than the actual arguments, write the type, else empty. if (j < actions[i].Arguments.Length) WriteInt((int)actions[i].Arguments[j].Type); else WriteInt(0); } // Write action data. WriteInt(actions[i].AppliesTo); WriteBool(actions[i].Relative); // Write the amount of actual arguments. WriteInt(8); // Iterate through arguments. for (int k = 0; k < 8; k++) { // If the index is greater than or equal to the number of arguments, continue. if (k >= actions[i].Arguments.Length) { WriteInt(1); WriteEmpty(1); continue; } // Write resource value. WriteString(actions[i].Arguments[k].Value); } // If not checkbox has been checked. WriteBool(actions[i].Not); } }