[272] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Reflection;
|
---|
| 4 |
|
---|
| 5 | namespace AllocsFixes.CustomCommands
|
---|
| 6 | {
|
---|
| 7 | public class RepairChunkDensity : ConsoleCmdAbstract {
|
---|
| 8 | public override string GetDescription () {
|
---|
| 9 | return "check and optionally fix densities of a chunk";
|
---|
| 10 | }
|
---|
| 11 |
|
---|
| 12 | public override string GetHelp () {
|
---|
[273] | 13 | return "This command is used to check if the densities of blocks in a chunk match the actual block type.\n" +
|
---|
| 14 | "If there is a mismatch it can lead to the chunk rendering incorrectly or not at all, typically\n" +
|
---|
| 15 | "indicated by the error message \"Failed setting triangles. Some indices are referencing out of\n" +
|
---|
| 16 | "bounds vertices.\". It can also fix such mismatches within a chunk.\n" +
|
---|
| 17 | "Usage:\n" +
|
---|
[272] | 18 | " 1. repairchunkdensity <x> <z>\n" +
|
---|
| 19 | " 2. repairchunkdensity <x> <z> fix\n" +
|
---|
[273] | 20 | "1. Just checks the chunk and prints mismatched to the server log. x and z are the coordinates of any\n" +
|
---|
| 21 | " block within the chunk to check.\n" +
|
---|
| 22 | "2. Repairs any mismatch found in the chunk.";
|
---|
[272] | 23 | }
|
---|
| 24 |
|
---|
| 25 | public override string[] GetCommands () {
|
---|
| 26 | return new string[] { "repairchunkdensity", "rcd" };
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
|
---|
| 30 | try {
|
---|
| 31 | if (_params.Count < 2 || _params.Count > 3) {
|
---|
| 32 | SdtdConsole.Instance.Output ("Wrong number of arguments, expected 2 or 3, found " + _params.Count + ".");
|
---|
| 33 | return;
|
---|
| 34 | } else {
|
---|
| 35 | int x = int.MinValue;
|
---|
| 36 | int z = int.MinValue;
|
---|
| 37 |
|
---|
| 38 | int.TryParse (_params [0], out x);
|
---|
| 39 | int.TryParse (_params [1], out z);
|
---|
| 40 |
|
---|
| 41 | if (x == int.MinValue || z == int.MinValue) {
|
---|
| 42 | SdtdConsole.Instance.Output ("At least one of the given coordinates is not a valid integer");
|
---|
| 43 | return;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | Chunk c = GameManager.Instance.World.GetChunkFromWorldPos (x, 0, z) as Chunk;
|
---|
| 47 | if (c == null) {
|
---|
| 48 | SdtdConsole.Instance.Output ("No chunk could be loaded from the given coordinates");
|
---|
| 49 | return;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | if (_params.Count == 3) {
|
---|
| 53 | if (_params [2].ToLower () != "fix") {
|
---|
| 54 | SdtdConsole.Instance.Output ("Three parameters given but third parameter is not \"fix\"");
|
---|
| 55 | return;
|
---|
| 56 | }
|
---|
| 57 | c.RepairDensities ();
|
---|
| 58 | c.isModified = true;
|
---|
| 59 | SdtdConsole.Instance.Output ("Chunk repaired");
|
---|
| 60 | } else {
|
---|
| 61 | c.CheckDensities (true);
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
| 64 | } catch (Exception e) {
|
---|
| 65 | Log.Out ("Error in RepairChunkDensity.Execute: " + e);
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | }
|
---|
| 70 | }
|
---|