Changeset 391
- Timestamp:
- Aug 7, 2022, 3:02:24 PM (2 years ago)
- Location:
- binary-improvements2
- Files:
-
- 77 added
- 11 deleted
- 26 edited
- 12 moved
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/7dtd-server-fixes/7dtd-server-fixes.csproj
r386 r391 91 91 <Compile Include="src\PersistentData\Players.cs" /> 92 92 <Compile Include="src\PersistentData\Player.cs" /> 93 <Compile Include="src\JSON\JSONNode.cs" /> 94 <Compile Include="src\JSON\JSONArray.cs" /> 95 <Compile Include="src\JSON\JSONObject.cs" /> 96 <Compile Include="src\JSON\JSONNumber.cs" /> 97 <Compile Include="src\JSON\JSONString.cs" /> 98 <Compile Include="src\JSON\JSONBoolean.cs" /> 99 <Compile Include="src\BlockingQueue.cs" /> 93 <Compile Include="src\JSON\JsonNode.cs" /> 94 <Compile Include="src\JSON\JsonArray.cs" /> 95 <Compile Include="src\JSON\JsonObject.cs" /> 96 <Compile Include="src\JSON\JsonNumber.cs" /> 97 <Compile Include="src\JSON\JsonString.cs" /> 98 <Compile Include="src\JSON\JsonBoolean.cs" /> 100 99 <Compile Include="src\JSON\Parser.cs" /> 101 <Compile Include="src\JSON\J SONNull.cs" />100 <Compile Include="src\JSON\JsonNull.cs" /> 102 101 <Compile Include="src\JSON\MalformedJSONException.cs" /> 103 102 <Compile Include="src\FileCache\AbstractCache.cs" /> … … 105 104 <Compile Include="src\FileCache\SimpleCache.cs" /> 106 105 <Compile Include="src\FileCache\MapTileCache.cs" /> 107 <Compile Include="src\ API.cs" />106 <Compile Include="src\ModApi.cs" /> 108 107 <Compile Include="src\AllocsUtils.cs" /> 109 108 <Compile Include="src\LandClaimList.cs" /> 110 109 <Compile Include="src\PersistentData\Attributes.cs" /> 111 <Compile Include="src\JSON\J SONValue.cs" />110 <Compile Include="src\JSON\JsonValue.cs" /> 112 111 <Compile Include="src\LiveData\EntityFilterList.cs" /> 113 112 </ItemGroup> … … 116 115 <Folder Include="src\" /> 117 116 <Folder Include="src\PersistentData\" /> 118 <Folder Include="src\JSON\Parser\" />119 117 <Folder Include="src\FileCache\" /> 120 118 </ItemGroup> -
binary-improvements2/7dtd-server-fixes/ModInfo.xml
r370 r391 2 2 <xml> 3 3 <ModInfo> 4 <Name value=" Allocs server fixes" />4 <Name value="Server extensions" /> 5 5 <Description value="Common functions" /> 6 <Author value=" Christian 'Alloc' Illy" />7 <Version value=" 24" />8 <Website value=" http://7dtd.illy.bz" />6 <Author value="The Fun Pimps LLC" /> 7 <Version value="1" /> 8 <Website value="" /> 9 9 </ModInfo> 10 10 </xml> -
binary-improvements2/7dtd-server-fixes/src/AllocsUtils.cs
r325 r391 4 4 public static class AllocsUtils { 5 5 public static string ColorToHex (Color _color) { 6 return string.Format ("{0:X02}{1:X02}{2:X02}", (int) (_color.r * 255), (int) (_color.g * 255), 7 (int) (_color.b * 255)); 6 return $"{(int)(_color.r * 255):X02}{(int)(_color.g * 255):X02}{(int)(_color.b * 255):X02}"; 8 7 } 9 8 } -
binary-improvements2/7dtd-server-fixes/src/AssemblyInfo.cs
r325 r391 7 7 [assembly: AssemblyDescription ("")] 8 8 [assembly: AssemblyConfiguration ("")] 9 [assembly: AssemblyCompany (" ")]9 [assembly: AssemblyCompany ("The Fun Pimps LLC")] 10 10 [assembly: AssemblyProduct ("")] 11 [assembly: AssemblyCopyright (" Alloc")]11 [assembly: AssemblyCopyright ("The Fun Pimps LLC")] 12 12 [assembly: AssemblyTrademark ("")] 13 13 [assembly: AssemblyCulture ("")] -
binary-improvements2/7dtd-server-fixes/src/FileCache/DirectAccess.cs
r351 r391 7 7 public override byte[] GetFileContent (string _filename) { 8 8 try { 9 if (!File.Exists (_filename)) { 10 return null; 11 } 12 13 return File.ReadAllBytes (_filename); 9 return File.Exists (_filename) ? File.ReadAllBytes (_filename) : null; 14 10 } catch (Exception e) { 15 11 Log.Out ("Error in DirectAccess.GetFileContent: " + e); -
binary-improvements2/7dtd-server-fixes/src/FileCache/MapTileCache.cs
r351 r391 36 36 lock (cache) { 37 37 CurrentZoomFile cacheEntry = cache [_zoomlevel]; 38 39 if (cacheEntry.filename == null || !cacheEntry.filename.Equals (_filename)) {40 cacheEntry.filename = _filename;41 38 42 if (!File.Exists (_filename)) { 43 cacheEntry.pngData = null; 44 return null; 45 } 39 if (cacheEntry.filename != null && cacheEntry.filename.Equals (_filename)) { 40 return cacheEntry.pngData; 41 } 46 42 47 Profiler.BeginSample ("ReadPng"); 48 cacheEntry.pngData = ReadAllBytes (_filename); 49 Profiler.EndSample (); 43 cacheEntry.filename = _filename; 44 45 if (!File.Exists (_filename)) { 46 cacheEntry.pngData = null; 47 return null; 50 48 } 49 50 Profiler.BeginSample ("ReadPng"); 51 cacheEntry.pngData = ReadAllBytes (_filename); 52 Profiler.EndSample (); 51 53 52 54 return cacheEntry.pngData; … … 103 105 } 104 106 105 if (!File.Exists (_filename)) { 106 return transparentTile; 107 } 108 109 return ReadAllBytes (_filename); 107 return !File.Exists (_filename) ? transparentTile : ReadAllBytes (_filename); 110 108 } 111 109 } catch (Exception e) { -
binary-improvements2/7dtd-server-fixes/src/FileCache/SimpleCache.cs
r351 r391 11 11 try { 12 12 lock (fileCache) { 13 if (!fileCache.ContainsKey (_filename)) { 14 if (!File.Exists (_filename)) { 15 return null; 16 } 13 if (fileCache.ContainsKey (_filename)) { 14 return fileCache [_filename]; 15 } 17 16 18 fileCache.Add (_filename, File.ReadAllBytes (_filename)); 17 if (!File.Exists (_filename)) { 18 return null; 19 19 } 20 21 fileCache.Add (_filename, File.ReadAllBytes (_filename)); 20 22 21 23 return fileCache [_filename]; -
binary-improvements2/7dtd-server-fixes/src/JSON/JSONArray.cs
r351 r391 3 3 4 4 namespace AllocsFixes.JSON { 5 public class J SONArray : JSONNode {6 private readonly List<J SONNode> nodes = new List<JSONNode> ();5 public class JsonArray : JsonNode { 6 private readonly List<JsonNode> nodes = new List<JsonNode> (); 7 7 8 public J SONNode this [int _index] {9 get { return nodes [_index]; }10 set { nodes [_index] = value; }8 public JsonNode this [int _index] { 9 get => nodes [_index]; 10 set => nodes [_index] = value; 11 11 } 12 12 13 public int Count { 14 get { return nodes.Count; } 15 } 13 public int Count => nodes.Count; 16 14 17 public void Add (J SONNode _node) {15 public void Add (JsonNode _node) { 18 16 nodes.Add (_node); 19 17 } … … 25 23 } 26 24 27 foreach (J SONNode n in nodes) {25 foreach (JsonNode n in nodes) { 28 26 if (_prettyPrint) { 29 27 _stringBuilder.Append (new string ('\t', _currentLevel + 1)); … … 48 46 } 49 47 50 public static J SONArray Parse (string _json, ref int _offset) {48 public static JsonArray Parse (string _json, ref int _offset) { 51 49 //Log.Out ("ParseArray enter (" + offset + ")"); 52 J SONArray arr = new JSONArray ();50 JsonArray arr = new JsonArray (); 53 51 54 52 bool nextElemAllowed = true; … … 63 61 _offset++; 64 62 } else { 65 throw new MalformedJ SONException (63 throw new MalformedJsonException ( 66 64 "Could not parse array, found a comma without a value first"); 67 65 } -
binary-improvements2/7dtd-server-fixes/src/JSON/JSONBoolean.cs
r389 r391 2 2 3 3 namespace AllocsFixes.JSON { 4 public class J SONBoolean : JSONValue {4 public class JsonBoolean : JsonValue { 5 5 private readonly bool value; 6 6 7 public J SONBoolean (bool _value) {7 public JsonBoolean (bool _value) { 8 8 value = _value; 9 9 } … … 17 17 } 18 18 19 public static J SONBoolean Parse (string _json, ref int _offset) {19 public static JsonBoolean Parse (string _json, ref int _offset) { 20 20 //Log.Out ("ParseBool enter (" + offset + ")"); 21 21 … … 23 23 //Log.Out ("JSON:Parsed Bool: true"); 24 24 _offset += 4; 25 return new J SONBoolean (true);25 return new JsonBoolean (true); 26 26 } 27 27 … … 29 29 //Log.Out ("JSON:Parsed Bool: false"); 30 30 _offset += 5; 31 return new J SONBoolean (false);31 return new JsonBoolean (false); 32 32 } 33 33 34 throw new MalformedJ SONException ("No valid boolean found");34 throw new MalformedJsonException ("No valid boolean found"); 35 35 } 36 36 -
binary-improvements2/7dtd-server-fixes/src/JSON/JSONNode.cs
r351 r391 2 2 3 3 namespace AllocsFixes.JSON { 4 public abstract class J SONNode {4 public abstract class JsonNode { 5 5 public abstract void ToString (StringBuilder _stringBuilder, bool _prettyPrint = false, int _currentLevel = 0); 6 6 -
binary-improvements2/7dtd-server-fixes/src/JSON/JSONNull.cs
r389 r391 3 3 4 4 namespace AllocsFixes.JSON { 5 public class J SONNull : JSONValue {5 public class JsonNull : JsonValue { 6 6 public override void ToString (StringBuilder _stringBuilder, bool _prettyPrint = false, int _currentLevel = 0) { 7 7 _stringBuilder.Append ("null"); 8 8 } 9 9 10 public static J SONNull Parse (string _json, ref int _offset) {10 public static JsonNull Parse (string _json, ref int _offset) { 11 11 //Log.Out ("ParseNull enter (" + offset + ")"); 12 12 13 13 if (!_json.Substring (_offset, 4).Equals ("null")) { 14 throw new MalformedJ SONException ("No valid null value found");14 throw new MalformedJsonException ("No valid null value found"); 15 15 } 16 16 17 17 //Log.Out ("JSON:Parsed Null"); 18 18 _offset += 4; 19 return new J SONNull ();19 return new JsonNull (); 20 20 } 21 21 -
binary-improvements2/7dtd-server-fixes/src/JSON/JSONNumber.cs
r389 r391 3 3 4 4 namespace AllocsFixes.JSON { 5 public class J SONNumber : JSONValue {5 public class JsonNumber : JsonValue { 6 6 private readonly double value; 7 7 8 public J SONNumber (double _value) {8 public JsonNumber (double _value) { 9 9 value = _value; 10 10 } … … 22 22 } 23 23 24 public static J SONNumber Parse (string _json, ref int _offset) {24 public static JsonNumber Parse (string _json, ref int _offset) { 25 25 //Log.Out ("ParseNumber enter (" + offset + ")"); 26 26 StringBuilder sbNum = new StringBuilder (); … … 37 37 } else if (_json [_offset] == '.') { 38 38 if (hasExp) { 39 throw new MalformedJ SONException ("Decimal separator in exponent");39 throw new MalformedJsonException ("Decimal separator in exponent"); 40 40 } 41 41 42 42 if (hasDec) { 43 throw new MalformedJ SONException ("Multiple decimal separators in number found");43 throw new MalformedJsonException ("Multiple decimal separators in number found"); 44 44 } 45 45 46 46 if (sbNum.Length == 0) { 47 throw new MalformedJ SONException ("No leading digits before decimal separator found");47 throw new MalformedJsonException ("No leading digits before decimal separator found"); 48 48 } 49 49 … … 53 53 if (hasExp) { 54 54 if (sbExp.Length > 0) { 55 throw new MalformedJ SONException ("Negative sign in exponent after digits");55 throw new MalformedJsonException ("Negative sign in exponent after digits"); 56 56 } 57 57 … … 59 59 } else { 60 60 if (sbNum.Length > 0) { 61 throw new MalformedJ SONException ("Negative sign in mantissa after digits");61 throw new MalformedJsonException ("Negative sign in mantissa after digits"); 62 62 } 63 63 … … 66 66 } else if (_json [_offset] == 'e' || _json [_offset] == 'E') { 67 67 if (hasExp) { 68 throw new MalformedJ SONException ("Multiple exponential markers in number found");68 throw new MalformedJsonException ("Multiple exponential markers in number found"); 69 69 } 70 70 71 71 if (sbNum.Length == 0) { 72 throw new MalformedJ SONException ("No leading digits before exponential marker found");72 throw new MalformedJsonException ("No leading digits before exponential marker found"); 73 73 } 74 74 … … 78 78 if (hasExp) { 79 79 if (sbExp.Length > 0) { 80 throw new MalformedJ SONException ("Positive sign in exponent after digits");80 throw new MalformedJsonException ("Positive sign in exponent after digits"); 81 81 } 82 82 83 83 sbExp.Append (_json [_offset]); 84 84 } else { 85 throw new MalformedJ SONException ("Positive sign in mantissa found");85 throw new MalformedJsonException ("Positive sign in mantissa found"); 86 86 } 87 87 } else { 88 double number; 89 if (!StringParsers.TryParseDouble (sbNum.ToString (), out number)) { 90 throw new MalformedJSONException ("Mantissa is not a valid decimal (\"" + sbNum + "\")"); 88 if (!StringParsers.TryParseDouble (sbNum.ToString (), out double number)) { 89 throw new MalformedJsonException ("Mantissa is not a valid decimal (\"" + sbNum + "\")"); 91 90 } 92 91 93 92 if (hasExp) { 94 int exp; 95 if (!int.TryParse (sbExp.ToString (), out exp)) { 96 throw new MalformedJSONException ("Exponent is not a valid integer (\"" + sbExp + "\")"); 93 if (!int.TryParse (sbExp.ToString (), out int exp)) { 94 throw new MalformedJsonException ("Exponent is not a valid integer (\"" + sbExp + "\")"); 97 95 } 98 96 99 number = number *Math.Pow (10, exp);97 number *= Math.Pow (10, exp); 100 98 } 101 99 102 100 //Log.Out ("JSON:Parsed Number: " + number.ToString ()); 103 return new J SONNumber (number);101 return new JsonNumber (number); 104 102 } 105 103 … … 107 105 } 108 106 109 throw new MalformedJ SONException ("End of JSON reached before parsing number finished");107 throw new MalformedJsonException ("End of JSON reached before parsing number finished"); 110 108 } 111 109 -
binary-improvements2/7dtd-server-fixes/src/JSON/JSONObject.cs
r389 r391 3 3 4 4 namespace AllocsFixes.JSON { 5 public class J SONObject : JSONNode {6 private readonly Dictionary<string, J SONNode> nodes = new Dictionary<string, JSONNode> ();5 public class JsonObject : JsonNode { 6 private readonly Dictionary<string, JsonNode> nodes = new Dictionary<string, JsonNode> (); 7 7 8 public J SONNode this [string _name] {8 public JsonNode this [string _name] { 9 9 get => nodes [_name]; 10 10 set => nodes [_name] = value; … … 19 19 } 20 20 21 public bool TryGetValue (string _name, out J SONNode _node) {21 public bool TryGetValue (string _name, out JsonNode _node) { 22 22 return nodes.TryGetValue (_name, out _node); 23 23 } 24 24 25 public void Add (string _name, J SONNode _node) {25 public void Add (string _name, JsonNode _node) { 26 26 nodes.Add (_name, _node); 27 27 } … … 33 33 } 34 34 35 foreach ( KeyValuePair<string, JSONNode> kvpin nodes) {35 foreach ((string key, JsonNode value) in nodes) { 36 36 if (_prettyPrint) { 37 37 _stringBuilder.Append (new string ('\t', _currentLevel + 1)); 38 38 } 39 39 40 _stringBuilder.Append ( string.Format ("\"{0}\":", kvp.Key));40 _stringBuilder.Append ($"\"{key}\":"); 41 41 if (_prettyPrint) { 42 42 _stringBuilder.Append (" "); 43 43 } 44 44 45 kvp.Value.ToString (_stringBuilder, _prettyPrint, _currentLevel + 1);45 value.ToString (_stringBuilder, _prettyPrint, _currentLevel + 1); 46 46 _stringBuilder.Append (","); 47 47 if (_prettyPrint) { … … 61 61 } 62 62 63 public static J SONObject Parse (string _json, ref int _offset) {63 public static JsonObject Parse (string _json, ref int _offset) { 64 64 //Log.Out ("ParseObject enter (" + offset + ")"); 65 J SONObject obj = new JSONObject ();65 JsonObject obj = new JsonObject (); 66 66 67 67 bool nextElemAllowed = true; … … 72 72 case '"': 73 73 if (nextElemAllowed) { 74 J SONString key = JSONString.Parse (_json, ref _offset);74 JsonString key = JsonString.Parse (_json, ref _offset); 75 75 Parser.SkipWhitespace (_json, ref _offset); 76 76 if (_json [_offset] != ':') { 77 throw new MalformedJ SONException (77 throw new MalformedJsonException ( 78 78 "Could not parse object, missing colon (\":\") after key"); 79 79 } 80 80 81 81 _offset++; 82 J SONNode val = Parser.ParseInternal (_json, ref _offset);82 JsonNode val = Parser.ParseInternal (_json, ref _offset); 83 83 obj.Add (key.GetString (), val); 84 84 nextElemAllowed = false; 85 85 } else { 86 throw new MalformedJ SONException (86 throw new MalformedJsonException ( 87 87 "Could not parse object, found new key without a separating comma"); 88 88 } … … 94 94 _offset++; 95 95 } else { 96 throw new MalformedJ SONException (96 throw new MalformedJsonException ( 97 97 "Could not parse object, found a comma without a key/value pair first"); 98 98 } -
binary-improvements2/7dtd-server-fixes/src/JSON/JSONString.cs
r389 r391 2 2 3 3 namespace AllocsFixes.JSON { 4 public class J SONString : JSONValue {4 public class JsonString : JsonValue { 5 5 private readonly string value; 6 6 7 public J SONString (string _value) {7 public JsonString (string _value) { 8 8 value = _value; 9 9 } … … 14 14 15 15 public override void ToString (StringBuilder _stringBuilder, bool _prettyPrint = false, int _currentLevel = 0) { 16 if ( value == null || value.Length == 0) {16 if (string.IsNullOrEmpty (value)) { 17 17 _stringBuilder.Append ("\"\""); 18 18 return; … … 64 64 } 65 65 66 public static J SONString Parse (string _json, ref int _offset) {66 public static JsonString Parse (string _json, ref int _offset) { 67 67 //Log.Out ("ParseString enter (" + offset + ")"); 68 68 StringBuilder sb = new StringBuilder (); … … 104 104 105 105 //Log.Out ("JSON:Parsed String: " + sb.ToString ()); 106 return new J SONString (sb.ToString ());106 return new JsonString (sb.ToString ()); 107 107 default: 108 108 sb.Append (_json [_offset]); … … 112 112 } 113 113 114 throw new MalformedJ SONException ("End of JSON reached before parsing string finished");114 throw new MalformedJsonException ("End of JSON reached before parsing string finished"); 115 115 } 116 116 -
binary-improvements2/7dtd-server-fixes/src/JSON/JSONValue.cs
r389 r391 1 1 namespace AllocsFixes.JSON { 2 public abstract class J SONValue : JSONNode {2 public abstract class JsonValue : JsonNode { 3 3 public abstract string AsString { get; } 4 4 public abstract int AsInt { get; } -
binary-improvements2/7dtd-server-fixes/src/JSON/JsonManualBuilder.cs
r354 r391 9 9 NonEmpty = 1, 10 10 Object = 2, 11 Array = 4 ,11 Array = 4 12 12 } 13 13 … … 20 20 private int currentLevelNumber; 21 21 22 private ELevelInfo CurrentLevelInfo { 23 get { return (ELevelInfo) (currentLevelType & levelBitsMask); } 24 } 25 26 private bool CurrentLevelIsNonEmpty { 27 get { return (CurrentLevelInfo & ELevelInfo.NonEmpty) == ELevelInfo.NonEmpty; } 28 } 29 30 private bool CurrentLevelIsArray { 31 get { return (CurrentLevelInfo & ELevelInfo.Array) != ELevelInfo.Array; } 32 } 33 34 private bool CurrentLevelIsObject { 35 get { return (CurrentLevelInfo & ELevelInfo.Object) != ELevelInfo.Object; } 36 } 37 22 private ELevelInfo CurrentLevelInfo => (ELevelInfo) (currentLevelType & levelBitsMask); 23 24 private bool CurrentLevelIsNonEmpty => (CurrentLevelInfo & ELevelInfo.NonEmpty) == ELevelInfo.NonEmpty; 25 26 private bool CurrentLevelIsArray => (CurrentLevelInfo & ELevelInfo.Array) != ELevelInfo.Array; 27 28 private bool CurrentLevelIsObject => (CurrentLevelInfo & ELevelInfo.Object) != ELevelInfo.Object; 29 38 30 public JsonManualBuilder (bool _prettyPrint) { 39 31 prettyPrint = _prettyPrint; … … 54 46 } 55 47 56 currentLevelType = currentLevelType |(long) ELevelInfo.NonEmpty;48 currentLevelType |= (long) ELevelInfo.NonEmpty; 57 49 } 58 50 … … 210 202 211 203 currentLevelNumber--; 212 currentLevelType = currentLevelType >>levelTypeBits;204 currentLevelType >>= levelTypeBits; 213 205 214 206 if (prettyPrint) { -
binary-improvements2/7dtd-server-fixes/src/JSON/MalformedJSONException.cs
r351 r391 3 3 4 4 namespace AllocsFixes.JSON { 5 public class MalformedJ SONException : ApplicationException {6 public MalformedJ SONException () {5 public class MalformedJsonException : ApplicationException { 6 public MalformedJsonException () { 7 7 } 8 8 9 public MalformedJ SONException (string _message) : base (_message) {9 public MalformedJsonException (string _message) : base (_message) { 10 10 } 11 11 12 public MalformedJ SONException (string _message, Exception _inner) : base (_message, _inner) {12 public MalformedJsonException (string _message, Exception _inner) : base (_message, _inner) { 13 13 } 14 14 15 protected MalformedJ SONException (SerializationInfo _info, StreamingContext _context) : base (_info, _context) {15 protected MalformedJsonException (SerializationInfo _info, StreamingContext _context) : base (_info, _context) { 16 16 } 17 17 } -
binary-improvements2/7dtd-server-fixes/src/JSON/Parser.cs
r351 r391 1 1 namespace AllocsFixes.JSON { 2 public class Parser {3 public static J SONNode Parse (string _json) {2 public static class Parser { 3 public static JsonNode Parse (string _json) { 4 4 int offset = 0; 5 5 return ParseInternal (_json, ref offset); 6 6 } 7 7 8 public static J SONNode ParseInternal (string _json, ref int _offset) {8 public static JsonNode ParseInternal (string _json, ref int _offset) { 9 9 SkipWhitespace (_json, ref _offset); 10 10 … … 12 12 switch (_json [_offset]) { 13 13 case '[': 14 return J SONArray.Parse (_json, ref _offset);14 return JsonArray.Parse (_json, ref _offset); 15 15 case '{': 16 return J SONObject.Parse (_json, ref _offset);16 return JsonObject.Parse (_json, ref _offset); 17 17 case '"': 18 return J SONString.Parse (_json, ref _offset);18 return JsonString.Parse (_json, ref _offset); 19 19 case 't': 20 20 case 'f': 21 return J SONBoolean.Parse (_json, ref _offset);21 return JsonBoolean.Parse (_json, ref _offset); 22 22 case 'n': 23 return J SONNull.Parse (_json, ref _offset);23 return JsonNull.Parse (_json, ref _offset); 24 24 default: 25 return J SONNumber.Parse (_json, ref _offset);25 return JsonNumber.Parse (_json, ref _offset); 26 26 } 27 27 } … … 42 42 } 43 43 44 throw new MalformedJ SONException ("End of JSON reached before parsing finished");44 throw new MalformedJsonException ("End of JSON reached before parsing finished"); 45 45 } 46 46 } -
binary-improvements2/7dtd-server-fixes/src/LandClaimList.cs
r369 r391 20 20 Dictionary<PersistentPlayerData, List<Vector3i>> owners = 21 21 new Dictionary<PersistentPlayerData, List<Vector3i>> (); 22 foreach ( KeyValuePair<Vector3i, PersistentPlayerData> kvpin d) {22 foreach ((Vector3i claimPos, PersistentPlayerData owner) in d) { 23 23 bool allowed = true; 24 24 if (_positionFilters != null) { 25 25 foreach (PositionFilter pf in _positionFilters) { 26 if (!pf (kvp.Key)) { 27 allowed = false; 28 break; 26 if (pf (claimPos)) { 27 continue; 29 28 } 29 30 allowed = false; 31 break; 30 32 } 31 33 } 32 34 33 if (allowed) { 34 if (!owners.ContainsKey (kvp.Value)) { 35 owners.Add (kvp.Value, new List<Vector3i> ()); 36 } 35 if (!allowed) { 36 continue; 37 } 37 38 38 owners [kvp.Value].Add (kvp.Key); 39 if (!owners.ContainsKey (owner)) { 40 owners.Add (owner, new List<Vector3i> ()); 39 41 } 42 43 owners [owner].Add (claimPos); 40 44 } 41 45 42 foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) { 43 Player p = PersistentContainer.Instance.Players [kvp.Key.UserIdentifier, false]; 44 if (p == null) { 45 p = new Player (kvp.Key.UserIdentifier); 46 } 46 foreach ((PersistentPlayerData owner, List<Vector3i> claimPositions) in owners) { 47 Player p = PersistentContainer.Instance.Players [owner.UserIdentifier, false] ?? new Player (owner.UserIdentifier); 47 48 48 49 bool allowed = true; 49 50 if (_ownerFilters != null) { 50 51 foreach (OwnerFilter of in _ownerFilters) { 51 if (!of (p)) { 52 allowed = false; 53 break; 52 if (of (p)) { 53 continue; 54 54 } 55 56 allowed = false; 57 break; 55 58 } 56 59 } 57 60 58 if (allowed) { 59 result.Add (p, new List<Vector3i> ()); 60 foreach (Vector3i v in kvp.Value) { 61 result [p].Add (v); 62 } 61 if (!allowed) { 62 continue; 63 } 64 65 result.Add (p, new List<Vector3i> ()); 66 foreach (Vector3i v in claimPositions) { 67 result [p].Add (v); 63 68 } 64 69 } -
binary-improvements2/7dtd-server-fixes/src/ModApi.cs
r390 r391 1 1 using System.Collections.Generic; 2 2 using AllocsFixes.PersistentData; 3 using JetBrains.Annotations; 3 4 using Platform.Steam; 4 5 5 6 namespace AllocsFixes { 6 public class API : IModApi { 7 [UsedImplicitly] 8 public class ModApi : IModApi { 7 9 public void InitMod (Mod _modInstance) { 8 10 ModEvents.GameStartDone.RegisterHandler (GameAwake); 9 ModEvents.GameShutdown.RegisterHandler (GameShutdown);10 11 ModEvents.SavePlayerData.RegisterHandler (SavePlayerData); 11 12 ModEvents.PlayerSpawning.RegisterHandler (PlayerSpawning); … … 15 16 } 16 17 17 p ublicvoid GameAwake () {18 private void GameAwake () { 18 19 PersistentContainer.Load (); 19 20 } 20 21 21 public void GameShutdown () { 22 } 23 24 public void SavePlayerData (ClientInfo _cInfo, PlayerDataFile _playerDataFile) { 22 private void SavePlayerData (ClientInfo _cInfo, PlayerDataFile _playerDataFile) { 25 23 PersistentContainer.Instance.Players [_cInfo.InternalId, true].Update (_playerDataFile); 26 24 } 27 25 28 p ublicvoid PlayerSpawning (ClientInfo _cInfo, int _chunkViewDim, PlayerProfile _playerProfile) {26 private void PlayerSpawning (ClientInfo _cInfo, int _chunkViewDim, PlayerProfile _playerProfile) { 29 27 string owner = null; 30 28 if (_cInfo.PlatformId is UserIdentifierSteam identifierSteam) { … … 42 40 } 43 41 44 p ublicvoid PlayerDisconnected (ClientInfo _cInfo, bool _bShutdown) {42 private void PlayerDisconnected (ClientInfo _cInfo, bool _bShutdown) { 45 43 Player p = PersistentContainer.Instance.Players [_cInfo.InternalId, false]; 46 44 if (p != null) { … … 53 51 } 54 52 55 p ublicvoid PlayerSpawned (ClientInfo _cInfo, RespawnType _respawnReason, Vector3i _spawnPos) {53 private void PlayerSpawned (ClientInfo _cInfo, RespawnType _respawnReason, Vector3i _spawnPos) { 56 54 PersistentContainer.Instance.Players [_cInfo.InternalId, true].SetOnline (_cInfo); 57 55 PersistentContainer.Instance.Save (); 58 56 } 59 57 60 private const string ANSWER=58 private const string testChatAnswer = 61 59 " [ff0000]I[-] [ff7f00]W[-][ffff00]A[-][80ff00]S[-] [00ffff]H[-][0080ff]E[-][0000ff]R[-][8b00ff]E[-]"; 62 60 63 p ublicbool ChatMessage (ClientInfo _cInfo, EChatType _type, int _senderId, string _msg, string _mainName,61 private bool ChatMessage (ClientInfo _cInfo, EChatType _type, int _senderId, string _msg, string _mainName, 64 62 bool _localizeMain, List<int> _recipientEntityIds) { 65 63 if (string.IsNullOrEmpty (_msg) || !_msg.EqualsCaseInsensitive ("/alloc")) { … … 69 67 if (_cInfo != null) { 70 68 Log.Out ("Sent chat hook reply to {0}", _cInfo.InternalId); 71 _cInfo.SendPackage (NetPackageManager.GetPackage<NetPackageChat> ().Setup (EChatType.Whisper, -1, ANSWER, "", false, null));69 _cInfo.SendPackage (NetPackageManager.GetPackage<NetPackageChat> ().Setup (EChatType.Whisper, -1, testChatAnswer, "", false, null)); 72 70 } else { 73 71 Log.Error ("ChatHookExample: Argument _cInfo null on message: {0}", _msg); -
binary-improvements2/7dtd-server-fixes/src/PersistentData/Attributes.cs
r326 r391 8 8 9 9 public bool HideChatCommands { 10 get { return hideChatCommands; }11 set { hideChatCommands = value; }10 get => hideChatCommands; 11 set => hideChatCommands = value; 12 12 } 13 13 14 14 public string HideChatCommandPrefix { 15 get { 16 if (hideChatCommandPrefix == null) { 17 hideChatCommandPrefix = ""; 18 } 19 20 return hideChatCommandPrefix; 21 } 22 set { hideChatCommandPrefix = value; } 15 get => hideChatCommandPrefix ?? (hideChatCommandPrefix = ""); 16 set => hideChatCommandPrefix = value; 23 17 } 24 18 } -
binary-improvements2/7dtd-server-fixes/src/PersistentData/PersistentContainer.cs
r369 r391 10 10 [OptionalField] private Attributes attributes; 11 11 12 public Players Players { 13 get { 14 if (players == null) { 15 players = new Players (); 16 } 12 public Players Players => players ?? (players = new Players ()); 17 13 18 return players; 19 } 20 } 21 22 public Attributes Attributes { 23 get { 24 if (attributes == null) { 25 attributes = new Attributes (); 26 } 27 28 return attributes; 29 } 30 } 14 public Attributes Attributes => attributes ?? (attributes = new Attributes ()); 31 15 32 16 private static PersistentContainer instance; 33 17 34 public static PersistentContainer Instance { 35 get { 36 if (instance == null) { 37 instance = new PersistentContainer (); 38 } 39 40 return instance; 41 } 42 } 18 public static PersistentContainer Instance => instance ?? (instance = new PersistentContainer ()); 43 19 44 20 private PersistentContainer () { … … 58 34 59 35 try { 60 PersistentContainer obj;61 36 Stream stream = File.Open (GameIO.GetSaveGameDir () + "/AllocsPeristentData.bin", FileMode.Open); 62 37 BinaryFormatter bFormatter = new BinaryFormatter (); 63 obj = (PersistentContainer) bFormatter.Deserialize (stream);38 PersistentContainer obj = (PersistentContainer) bFormatter.Deserialize (stream); 64 39 stream.Close (); 65 40 instance = obj; -
binary-improvements2/7dtd-server-fixes/src/PersistentData/Players.cs
r383 r391 41 41 42 42 if (int.TryParse (_nameOrId, out int entityId)) { 43 foreach ( KeyValuePair<PlatformUserIdentifierAbs, Player> kvpin Dict) {44 if ( kvp.Value.IsOnline && kvp.Value.EntityID == entityId) {45 return kvp.Key;43 foreach ((PlatformUserIdentifierAbs iUserId, Player player) in Dict) { 44 if (player.IsOnline && player.EntityID == entityId) { 45 return iUserId; 46 46 } 47 47 } 48 48 } 49 49 50 foreach ( KeyValuePair<PlatformUserIdentifierAbs, Player> kvpin Dict) {51 string name = kvp.Value.Name;50 foreach ((PlatformUserIdentifierAbs iUserId, Player player) in Dict) { 51 string name = player.Name; 52 52 if (_ignoreColorCodes) { 53 53 name = Regex.Replace (name, "\\[[0-9a-fA-F]{6}\\]", ""); 54 54 } 55 55 56 if ( kvp.Value.IsOnline && name.EqualsCaseInsensitive (_nameOrId)) {57 return kvp.Key;56 if (player.IsOnline && name.EqualsCaseInsensitive (_nameOrId)) { 57 return iUserId; 58 58 } 59 59 } -
binary-improvements2/MapRendering/MapRendering.csproj
r390 r391 16 16 <DebugType>none</DebugType> 17 17 <Optimize>true</Optimize> 18 <OutputPath>..\bin\Mods\ Allocs_WebAndMapRendering\</OutputPath>18 <OutputPath>..\bin\Mods\TFP_MapRendering\</OutputPath> 19 19 <ErrorReport>prompt</ErrorReport> 20 20 <WarningLevel>4</WarningLevel> … … 23 23 </PropertyGroup> 24 24 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_Profiler|AnyCPU' "> 25 <OutputPath>..\bin\Mods\ Allocs_WebAndMapRendering\</OutputPath>25 <OutputPath>..\bin\Mods\TFP_MapRendering\</OutputPath> 26 26 <DefineConstants>ENABLE_PROFILER</DefineConstants> 27 27 <Optimize>true</Optimize> … … 32 32 </PropertyGroup> 33 33 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> 34 <OutputPath>..\bin\Mods\ Allocs_WebAndMapRendering\</OutputPath>34 <OutputPath>..\bin\Mods\TFP_MapRendering\</OutputPath> 35 35 <DebugType>full</DebugType> 36 36 <DebugSymbols>true</DebugSymbols> … … 79 79 </ItemGroup> 80 80 <ItemGroup> 81 <Compile Include="AssemblyInfo.cs" /> 82 <Compile Include="Commands\Exception.cs" /> 83 <Compile Include="MapRendering\MapRendering.cs" /> 84 <Compile Include="MapRendering\MapRenderBlockBuffer.cs" /> 85 <Compile Include="MapRendering\Constants.cs" /> 86 <Compile Include="Commands\RenderMap.cs" /> 87 <Compile Include="Commands\EnableRendering.cs" /> 88 <Compile Include="API.cs" /> 89 <Compile Include="Web\API\AbsRestApi.cs" /> 90 <Compile Include="Web\API\GetAnimalsLocation.cs" /> 91 <Compile Include="Web\API\GetHostileLocation.cs" /> 92 <Compile Include="Web\API\GetWebMods.cs" /> 93 <Compile Include="Web\API\Null.cs" /> 94 <Compile Include="Web\Handlers\RewriteHandler.cs" /> 95 <Compile Include="Web\RequestContext.cs" /> 96 <Compile Include="Web\SSE\EventLog.cs" /> 97 <Compile Include="Web\SSE\SseHandler.cs" /> 98 <Compile Include="Web\SSE\EventBase.cs" /> 99 <Compile Include="Web\Web.cs" /> 100 <Compile Include="Web\MimeType.cs" /> 101 <Compile Include="Web\API\GetPlayersOnline.cs" /> 102 <Compile Include="Web\API\AbsWebAPI.cs" /> 103 <Compile Include="Web\API\GetPlayersLocation.cs" /> 104 <Compile Include="Web\API\GetPlayerInventory.cs" /> 105 <Compile Include="Web\API\GetLandClaims.cs" /> 106 <Compile Include="Commands\webstat.cs" /> 107 <Compile Include="Web\API\GetStats.cs" /> 108 <Compile Include="Web\WebConnection.cs" /> 109 <Compile Include="Web\OpenID.cs" /> 110 <Compile Include="Web\ConnectionHandler.cs" /> 111 <Compile Include="Web\WebMod.cs" /> 112 <Compile Include="Web\WebPermissions.cs" /> 113 <Compile Include="Web\Handlers\ApiHandler.cs" /> 114 <Compile Include="Web\Handlers\ItemIconHandler.cs" /> 115 <Compile Include="Web\Handlers\AbsHandler.cs" /> 116 <Compile Include="Web\Handlers\SimpleRedirectHandler.cs" /> 117 <Compile Include="Web\Handlers\StaticHandler.cs" /> 118 <Compile Include="Web\Handlers\SessionHandler.cs" /> 119 <Compile Include="Web\API\ExecuteConsoleCommand.cs" /> 120 <Compile Include="Commands\ReloadWebPermissions.cs" /> 121 <Compile Include="Web\Handlers\UserStatusHandler.cs" /> 122 <Compile Include="Commands\WebTokens.cs" /> 123 <Compile Include="Commands\WebPermissionsCmd.cs" /> 124 <Compile Include="Web\LogBuffer.cs" /> 125 <Compile Include="Web\API\GetLog.cs" /> 126 <Compile Include="Web\API\GetWebUIUpdates.cs" /> 127 <Compile Include="Web\API\GetServerInfo.cs" /> 128 <Compile Include="Web\API\GetPlayerList.cs" /> 129 <Compile Include="Web\WebCommandResult.cs" /> 130 <Compile Include="Web\API\GetAllowedCommands.cs" /> 131 <Compile Include="Commands\EnableOpenIDDebug.cs" /> 132 <Compile Include="Web\API\GetPlayerInventories.cs" /> 133 <Compile Include="Web\WebUtils.cs" /> 81 <Compile Include="src\Constants.cs" /> 82 <Compile Include="src\MapRenderBlockBuffer.cs" /> 83 <Compile Include="src\MapRenderer.cs" /> 84 <Compile Include="src\ModApi.cs" /> 85 <Compile Include="src\AssemblyInfo.cs" /> 86 <Compile Include="src\Commands\EnableRendering.cs" /> 87 <Compile Include="src\Commands\RenderMap.cs" /> 134 88 </ItemGroup> 135 89 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> … … 140 94 <Private>False</Private> 141 95 </ProjectReference> 142 <ProjectReference Include="..\SpaceWizards.HttpListener\SpaceWizards.HttpListener.csproj">143 <Project>{e273d042-57f9-4e2e-8268-5053527e5287}</Project>144 <Name>SpaceWizards.HttpListener</Name>145 </ProjectReference>146 96 </ItemGroup> 147 97 <ItemGroup> … … 149 99 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 150 100 </None> 151 <None Include="steam-intermediate.cer">152 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>153 </None>154 <None Include="steam-rootca.cer">155 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>156 </None>157 101 </ItemGroup> 158 102 </Project> -
binary-improvements2/MapRendering/ModInfo.xml
r370 r391 2 2 <xml> 3 3 <ModInfo> 4 <Name value=" Allocs MapRendering and Webinterface" />4 <Name value="TFP_MapRendering" /> 5 5 <Description value="Render the game map to image map tiles as it is uncovered" /> 6 <Author value=" Christian 'Alloc' Illy" />7 <Version value=" 39" />8 <Website value=" http://7dtd.illy.bz" />6 <Author value="The Fun Pimps LLC" /> 7 <Version value="1" /> 8 <Website value="" /> 9 9 </ModInfo> 10 10 </xml> -
binary-improvements2/MapRendering/src/AssemblyInfo.cs
r390 r391 7 7 [assembly: AssemblyDescription ("")] 8 8 [assembly: AssemblyConfiguration ("")] 9 [assembly: AssemblyCompany (" ")]9 [assembly: AssemblyCompany ("The Fun Pimps LLC")] 10 10 [assembly: AssemblyProduct ("")] 11 [assembly: AssemblyCopyright (" ci")]11 [assembly: AssemblyCopyright ("The Fun Pimps LLC")] 12 12 [assembly: AssemblyTrademark ("")] 13 13 [assembly: AssemblyCulture ("")] -
binary-improvements2/MapRendering/src/Commands/EnableRendering.cs
r390 r391 1 1 using System.Collections.Generic; 2 using JetBrains.Annotations; 2 3 3 namespace AllocsFixes.CustomCommands { 4 namespace MapRendering.Commands { 5 [UsedImplicitly] 4 6 public class EnableRendering : ConsoleCmdAbstract { 5 7 public override string GetDescription () { … … 13 15 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) { 14 16 if (_params.Count != 1) { 15 SdtdConsole.Instance.Output ("Current state: " + MapRender ing.MapRendering.renderingEnabled);17 SdtdConsole.Instance.Output ("Current state: " + MapRenderer.renderingEnabled); 16 18 return; 17 19 } 18 20 19 MapRender ing.MapRendering.renderingEnabled = _params [0].Equals ("1");21 MapRenderer.renderingEnabled = _params [0].Equals ("1"); 20 22 SdtdConsole.Instance.Output ("Set live map rendering to " + _params [0].Equals ("1")); 21 23 } -
binary-improvements2/MapRendering/src/Commands/RenderMap.cs
r390 r391 1 1 using System.Collections.Generic; 2 using JetBrains.Annotations; 2 3 3 namespace AllocsFixes.CustomCommands { 4 namespace MapRendering.Commands { 5 [UsedImplicitly] 4 6 public class RenderMap : ConsoleCmdAbstract { 5 7 public override string GetDescription () { … … 12 14 13 15 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) { 14 MapRender ing.MapRendering.Instance.RenderFullMap ();16 MapRenderer.Instance.RenderFullMap (); 15 17 16 18 SdtdConsole.Instance.Output ("Render map done"); -
binary-improvements2/MapRendering/src/Constants.cs
r390 r391 1 1 using UnityEngine; 2 2 3 namespace AllocsFixes.MapRendering {4 public class Constants {5 public static readonly TextureFormat D EFAULT_TEX_FORMAT= TextureFormat.ARGB32;6 public static int M AP_BLOCK_SIZE= 128;7 public const int M AP_CHUNK_SIZE= 16;8 public const int M AP_REGION_SIZE= 512;9 public static int Z OOMLEVELS= 5;10 public static string M AP_DIRECTORY= string.Empty;3 namespace MapRendering { 4 public static class Constants { 5 public static readonly TextureFormat DefaultTextureFormat = TextureFormat.ARGB32; 6 public static int MapBlockSize = 128; 7 public const int MapChunkSize = 16; 8 public const int MapRegionSize = 512; 9 public static int Zoomlevels = 5; 10 public static string MapDirectory = string.Empty; 11 11 12 public static int MAP_BLOCK_TO_CHUNK_DIV { 13 get { return MAP_BLOCK_SIZE / MAP_CHUNK_SIZE; } 14 } 12 public static int MAP_BLOCK_TO_CHUNK_DIV => MapBlockSize / MapChunkSize; 15 13 16 public static int MAP_REGION_TO_CHUNK_DIV { 17 get { return MAP_REGION_SIZE / MAP_CHUNK_SIZE; } 18 } 14 public static int MAP_REGION_TO_CHUNK_DIV => MapRegionSize / MapChunkSize; 19 15 } 20 16 } -
binary-improvements2/MapRendering/src/MapRenderBlockBuffer.cs
r390 r391 6 6 using UnityEngine.Profiling; 7 7 8 namespace AllocsFixes.MapRendering {8 namespace MapRendering { 9 9 public class MapRenderBlockBuffer { 10 private readonly Texture2D blockMap = new Texture2D (Constants.M AP_BLOCK_SIZE, Constants.MAP_BLOCK_SIZE, Constants.DEFAULT_TEX_FORMAT, false);10 private readonly Texture2D blockMap = new Texture2D (Constants.MapBlockSize, Constants.MapBlockSize, Constants.DefaultTextureFormat, false); 11 11 private readonly MapTileCache cache; 12 12 private readonly NativeArray<int> emptyImageData; 13 private readonly Texture2D zoomBuffer = new Texture2D (Constants.M AP_BLOCK_SIZE / 2, Constants.MAP_BLOCK_SIZE / 2, Constants.DEFAULT_TEX_FORMAT, false);13 private readonly Texture2D zoomBuffer = new Texture2D (Constants.MapBlockSize / 2, Constants.MapBlockSize / 2, Constants.DefaultTextureFormat, false); 14 14 private readonly int zoomLevel; 15 15 private readonly string folderBase; 16 16 17 private Vector2i currentBlockMapPos = new Vector2i ( Int32.MinValue, Int32.MinValue);17 private Vector2i currentBlockMapPos = new Vector2i (int.MinValue, int.MinValue); 18 18 private string currentBlockMapFolder = string.Empty; 19 19 … … 21 21 zoomLevel = _level; 22 22 cache = _cache; 23 folderBase = Constants.M AP_DIRECTORY+ "/" + zoomLevel + "/";23 folderBase = Constants.MapDirectory + "/" + zoomLevel + "/"; 24 24 25 25 { 26 26 // Initialize empty tile data 27 27 Color nullColor = new Color (0, 0, 0, 0); 28 for (int x = 0; x < Constants.M AP_BLOCK_SIZE; x++) {29 for (int y = 0; y < Constants.M AP_BLOCK_SIZE; y++) {28 for (int x = 0; x < Constants.MapBlockSize; x++) { 29 for (int y = 0; y < Constants.MapBlockSize; y++) { 30 30 blockMap.SetPixel (x, y, nullColor); 31 31 } … … 39 39 } 40 40 41 public TextureFormat FormatSelf { 42 get { return blockMap.format; } 43 } 41 public TextureFormat FormatSelf => blockMap.format; 44 42 45 43 public void ResetBlock () { 46 44 currentBlockMapFolder = string.Empty; 47 currentBlockMapPos = new Vector2i ( Int32.MinValue, Int32.MinValue);45 currentBlockMapPos = new Vector2i (int.MinValue, int.MinValue); 48 46 cache.ResetTile (zoomLevel); 49 47 } … … 94 92 95 93 public void SetPart (Vector2i _offset, int _partSize, Color32[] _pixels) { 96 if (_offset.x + _partSize > Constants.M AP_BLOCK_SIZE || _offset.y + _partSize > Constants.MAP_BLOCK_SIZE) {97 Log.Error ( string.Format ("MapBlockBuffer[{0}].SetPart ({1}, {2}, {3}) has blockMap.size ({4}/{5})",98 zoomLevel, _offset, _partSize, _pixels.Length, Constants.MAP_BLOCK_SIZE, Constants.MAP_BLOCK_SIZE));94 if (_offset.x + _partSize > Constants.MapBlockSize || _offset.y + _partSize > Constants.MapBlockSize) { 95 Log.Error ( 96 $"MapBlockBuffer[{zoomLevel}].SetPart ({_offset}, {_partSize}, {_pixels.Length}) has blockMap.size ({Constants.MapBlockSize}/{Constants.MapBlockSize})"); 99 97 return; 100 98 } … … 107 105 public Color32[] GetHalfScaled () { 108 106 Profiler.BeginSample ("HalfScaled.ResizeBuffer"); 109 zoomBuffer.Resize (Constants.M AP_BLOCK_SIZE, Constants.MAP_BLOCK_SIZE);107 zoomBuffer.Resize (Constants.MapBlockSize, Constants.MapBlockSize); 110 108 Profiler.EndSample (); 111 109 … … 125 123 126 124 Profiler.BeginSample ("HalfScaled.Scale"); 127 TextureScale.Point (zoomBuffer, Constants.M AP_BLOCK_SIZE / 2, Constants.MAP_BLOCK_SIZE/ 2);125 TextureScale.Point (zoomBuffer, Constants.MapBlockSize / 2, Constants.MapBlockSize / 2); 128 126 Profiler.EndSample (); 129 127 … … 136 134 137 135 public void SetPartNative (Vector2i _offset, int _partSize, NativeArray<int> _pixels) { 138 if (_offset.x + _partSize > Constants.M AP_BLOCK_SIZE || _offset.y + _partSize > Constants.MAP_BLOCK_SIZE) {139 Log.Error ( string.Format ("MapBlockBuffer[{0}].SetPart ({1}, {2}, {3}) has blockMap.size ({4}/{5})",140 zoomLevel, _offset, _partSize, _pixels.Length, Constants.MAP_BLOCK_SIZE, Constants.MAP_BLOCK_SIZE));136 if (_offset.x + _partSize > Constants.MapBlockSize || _offset.y + _partSize > Constants.MapBlockSize) { 137 Log.Error ( 138 $"MapBlockBuffer[{zoomLevel}].SetPart ({_offset}, {_partSize}, {_pixels.Length}) has blockMap.size ({Constants.MapBlockSize}/{Constants.MapBlockSize})"); 141 139 return; 142 140 } … … 157 155 public NativeArray<int> GetHalfScaledNative () { 158 156 Profiler.BeginSample ("HalfScaledNative.ResizeBuffer"); 159 if (zoomBuffer.format != blockMap.format || zoomBuffer.height != Constants.M AP_BLOCK_SIZE / 2 || zoomBuffer.width != Constants.MAP_BLOCK_SIZE/ 2) {160 zoomBuffer.Resize (Constants.M AP_BLOCK_SIZE / 2, Constants.MAP_BLOCK_SIZE/ 2, blockMap.format, false);157 if (zoomBuffer.format != blockMap.format || zoomBuffer.height != Constants.MapBlockSize / 2 || zoomBuffer.width != Constants.MapBlockSize / 2) { 158 zoomBuffer.Resize (Constants.MapBlockSize / 2, Constants.MapBlockSize / 2, blockMap.format, false); 161 159 } 162 160 Profiler.EndSample (); … … 178 176 int newHeight = _targetTex.height; 179 177 180 float ratioX = ( (float) oldWidth)/ newWidth;181 float ratioY = ( (float) oldHeight)/ newHeight;182 183 for ( vary = 0; y < newHeight; y++) {184 varoldLineStart = (int) (ratioY * y) * oldWidth;185 varnewLineStart = y * newWidth;186 for ( varx = 0; x < newWidth; x++) {178 float ratioX = (float) oldWidth / newWidth; 179 float ratioY = (float) oldHeight / newHeight; 180 181 for (int y = 0; y < newHeight; y++) { 182 int oldLineStart = (int) (ratioY * y) * oldWidth; 183 int newLineStart = y * newWidth; 184 for (int x = 0; x < newWidth; x++) { 187 185 targetData [newLineStart + x] = srcData [(int) (oldLineStart + ratioX * x)]; 188 186 } … … 198 196 199 197 Profiler.BeginSample ("LoadImage"); 200 if (array != null && blockMap.LoadImage (array) && blockMap.height == Constants.M AP_BLOCK_SIZE&&201 blockMap.width == Constants.M AP_BLOCK_SIZE) {198 if (array != null && blockMap.LoadImage (array) && blockMap.height == Constants.MapBlockSize && 199 blockMap.width == Constants.MapBlockSize) { 202 200 Profiler.EndSample (); 203 201 … … 211 209 } 212 210 213 if (blockMap.format != Constants.D EFAULT_TEX_FORMAT || blockMap.height != Constants.MAP_BLOCK_SIZE||214 blockMap.width != Constants.M AP_BLOCK_SIZE) {215 blockMap.Resize (Constants.M AP_BLOCK_SIZE, Constants.MAP_BLOCK_SIZE, Constants.DEFAULT_TEX_FORMAT,211 if (blockMap.format != Constants.DefaultTextureFormat || blockMap.height != Constants.MapBlockSize || 212 blockMap.width != Constants.MapBlockSize) { 213 blockMap.Resize (Constants.MapBlockSize, Constants.MapBlockSize, Constants.DefaultTextureFormat, 216 214 false); 217 215 } -
binary-improvements2/MapRendering/src/MapRenderer.cs
r390 r391 11 11 using Object = UnityEngine.Object; 12 12 13 namespace AllocsFixes.MapRendering {14 public class MapRender ing{15 private static MapRender inginstance;13 namespace MapRendering { 14 public class MapRenderer { 15 private static MapRenderer instance; 16 16 17 17 private static readonly object lockObject = new object (); 18 18 public static bool renderingEnabled = true; 19 private readonly MapTileCache cache = new MapTileCache (Constants.M AP_BLOCK_SIZE);19 private readonly MapTileCache cache = new MapTileCache (Constants.MapBlockSize); 20 20 private readonly Dictionary<Vector2i, Color32[]> dirtyChunks = new Dictionary<Vector2i, Color32[]> (); 21 21 private readonly MicroStopwatch msw = new MicroStopwatch (); … … 26 26 private bool shutdown; 27 27 28 private MapRender ing() {29 Constants.M AP_DIRECTORY= GameIO.GetSaveGameDir () + "/map";28 private MapRenderer () { 29 Constants.MapDirectory = GameIO.GetSaveGameDir () + "/map"; 30 30 31 31 lock (lockObject) { … … 35 35 } 36 36 37 cache.SetZoomCount (Constants.Z OOMLEVELS);38 39 zoomLevelBuffers = new MapRenderBlockBuffer[Constants.Z OOMLEVELS];40 for (int i = 0; i < Constants.Z OOMLEVELS; i++) {37 cache.SetZoomCount (Constants.Zoomlevels); 38 39 zoomLevelBuffers = new MapRenderBlockBuffer[Constants.Zoomlevels]; 40 for (int i = 0; i < Constants.Zoomlevels; i++) { 41 41 zoomLevelBuffers [i] = new MapRenderBlockBuffer (i, cache); 42 42 } … … 45 45 } 46 46 47 public static MapRendering Instance { 48 get { 49 if (instance == null) { 50 instance = new MapRendering (); 51 } 52 53 return instance; 54 } 55 } 47 public static MapRenderer Instance => instance ??= new MapRenderer (); 56 48 57 49 public static MapTileCache GetTileCache () { … … 77 69 ThreadPool.UnsafeQueueUserWorkItem (_o => { 78 70 try { 79 if (!Instance.renderingFullMap) { 80 lock (lockObject) { 81 Chunk c = (Chunk) _o; 82 Vector3i cPos = c.GetWorldPos (); 83 Vector2i cPos2 = new Vector2i (cPos.x / Constants.MAP_CHUNK_SIZE, 84 cPos.z / Constants.MAP_CHUNK_SIZE); 85 86 ushort[] mapColors = c.GetMapColors (); 87 if (mapColors != null) { 88 Color32[] realColors = 89 new Color32[Constants.MAP_CHUNK_SIZE * Constants.MAP_CHUNK_SIZE]; 90 for (int i_colors = 0; i_colors < mapColors.Length; i_colors++) { 91 realColors [i_colors] = shortColorToColor32 (mapColors [i_colors]); 92 } 93 94 Instance.dirtyChunks [cPos2] = realColors; 95 96 //Log.Out ("Add Dirty: " + cPos2); 97 } 71 if (Instance.renderingFullMap) { 72 return; 73 } 74 75 lock (lockObject) { 76 Chunk c = (Chunk) _o; 77 Vector3i cPos = c.GetWorldPos (); 78 Vector2i cPos2 = new Vector2i (cPos.x / Constants.MapChunkSize, 79 cPos.z / Constants.MapChunkSize); 80 81 ushort[] mapColors = c.GetMapColors (); 82 if (mapColors == null) { 83 return; 98 84 } 85 86 Color32[] realColors = 87 new Color32[Constants.MapChunkSize * Constants.MapChunkSize]; 88 for (int iColors = 0; iColors < mapColors.Length; iColors++) { 89 realColors [iColors] = shortColorToColor32 (mapColors [iColors]); 90 } 91 92 Instance.dirtyChunks [cPos2] = realColors; 93 94 //Log.Out ("Add Dirty: " + cPos2); 99 95 } 100 96 } catch (Exception e) { … … 112 108 Texture2D fullMapTexture = null; 113 109 114 Vector2i minChunk, maxChunk; 115 Vector2i minPos, maxPos; 116 int widthChunks, heightChunks, widthPix, heightPix; 117 getWorldExtent (rfm, out minChunk, out maxChunk, out minPos, out maxPos, out widthChunks, out heightChunks, 118 out widthPix, out heightPix); 119 120 Log.Out (string.Format ( 121 "RenderMap: min: {0}, max: {1}, minPos: {2}, maxPos: {3}, w/h: {4}/{5}, wP/hP: {6}/{7}", 122 minChunk.ToString (), maxChunk.ToString (), 123 minPos.ToString (), maxPos.ToString (), 124 widthChunks, heightChunks, 125 widthPix, heightPix) 110 getWorldExtent (rfm, out Vector2i minChunk, out Vector2i maxChunk, out Vector2i minPos, out Vector2i maxPos, out int widthChunks, out int heightChunks, 111 out int widthPix, out int heightPix); 112 113 Log.Out ( 114 $"RenderMap: min: {minChunk.ToString ()}, max: {maxChunk.ToString ()}, minPos: {minPos.ToString ()}, maxPos: {maxPos.ToString ()}, w/h: {widthChunks}/{heightChunks}, wP/hP: {widthPix}/{heightPix}" 126 115 ); 127 116 128 117 lock (lockObject) { 129 for (int i = 0; i < Constants.Z OOMLEVELS; i++) {118 for (int i = 0; i < Constants.Zoomlevels; i++) { 130 119 zoomLevelBuffers [i].ResetBlock (); 131 120 } 132 121 133 if (Directory.Exists (Constants.M AP_DIRECTORY)) {134 Directory.Delete (Constants.M AP_DIRECTORY, true);122 if (Directory.Exists (Constants.MapDirectory)) { 123 Directory.Delete (Constants.MapDirectory, true); 135 124 } 136 125 … … 143 132 } 144 133 145 Vector2i curFullMapPos = default (Vector2i);146 Vector2i curChunkPos = default (Vector2i);147 for (curFullMapPos.x = 0; curFullMapPos.x < widthPix; curFullMapPos.x += Constants.M AP_CHUNK_SIZE) {134 Vector2i curFullMapPos = default; 135 Vector2i curChunkPos = default; 136 for (curFullMapPos.x = 0; curFullMapPos.x < widthPix; curFullMapPos.x += Constants.MapChunkSize) { 148 137 for (curFullMapPos.y = 0; 149 138 curFullMapPos.y < heightPix; 150 curFullMapPos.y += Constants.M AP_CHUNK_SIZE) {151 curChunkPos.x = curFullMapPos.x / Constants.M AP_CHUNK_SIZE+ minChunk.x;152 curChunkPos.y = curFullMapPos.y / Constants.M AP_CHUNK_SIZE+ minChunk.y;139 curFullMapPos.y += Constants.MapChunkSize) { 140 curChunkPos.x = curFullMapPos.x / Constants.MapChunkSize + minChunk.x; 141 curChunkPos.y = curFullMapPos.y / Constants.MapChunkSize + minChunk.y; 153 142 154 143 try { … … 159 148 if (mapColors != null) { 160 149 Color32[] realColors = 161 new Color32[Constants.M AP_CHUNK_SIZE * Constants.MAP_CHUNK_SIZE];162 for (int i _colors = 0; i_colors < mapColors.Length; i_colors++) {163 realColors [i _colors] = shortColorToColor32 (mapColors [i_colors]);150 new Color32[Constants.MapChunkSize * Constants.MapChunkSize]; 151 for (int iColors = 0; iColors < mapColors.Length; iColors++) { 152 realColors [iColors] = shortColorToColor32 (mapColors [iColors]); 164 153 } 165 154 … … 167 156 if (fullMapTexture != null) { 168 157 fullMapTexture.SetPixels32 (curFullMapPos.x, curFullMapPos.y, 169 Constants.M AP_CHUNK_SIZE, Constants.MAP_CHUNK_SIZE, realColors);158 Constants.MapChunkSize, Constants.MapChunkSize, realColors); 170 159 } 171 160 } … … 180 169 } 181 170 182 Log.Out (string.Format ("RenderMap: {0}/{1} ({2}%)", curFullMapPos.x, widthPix, 183 (int) ((float) curFullMapPos.x / widthPix * 100))); 171 Log.Out ($"RenderMap: {curFullMapPos.x}/{widthPix} ({(int)((float)curFullMapPos.x / widthPix * 100)}%)"); 184 172 } 185 173 } … … 189 177 if (fullMapTexture != null) { 190 178 byte[] array = fullMapTexture.EncodeToPNG (); 191 File.WriteAllBytes (Constants.M AP_DIRECTORY+ "/map.png", array);179 File.WriteAllBytes (Constants.MapDirectory + "/map.png", array); 192 180 Object.Destroy (fullMapTexture); 193 181 } … … 200 188 201 189 private void SaveAllBlockMaps () { 202 for (int i = 0; i < Constants.Z OOMLEVELS; i++) {190 for (int i = 0; i < Constants.Zoomlevels; i++) { 203 191 zoomLevelBuffers [i].SaveBlock (); 204 192 } … … 246 234 //Log.Out ("Start Dirty: " + chunkPos); 247 235 248 getBlockNumber (chunkPos, out Vector2i block, out _, Constants.MAP_BLOCK_TO_CHUNK_DIV, Constants.M AP_CHUNK_SIZE);249 250 zoomLevelBuffers [Constants.Z OOMLEVELS- 1].LoadBlock (block);236 getBlockNumber (chunkPos, out Vector2i block, out _, Constants.MAP_BLOCK_TO_CHUNK_DIV, Constants.MapChunkSize); 237 238 zoomLevelBuffers [Constants.Zoomlevels - 1].LoadBlock (block); 251 239 Profiler.EndSample (); 252 240 253 241 Profiler.BeginSample ("RenderDirtyChunks.Work"); 254 242 // Write all chunks that are in the same image tile of the highest zoom level 255 Vector2i v_block, v_blockOffset;256 243 foreach (Vector2i v in chunksToRender) { 257 getBlockNumber (v, out v_block, out v_blockOffset, Constants.MAP_BLOCK_TO_CHUNK_DIV, 258 Constants.MAP_CHUNK_SIZE); 259 if (v_block.Equals (block)) { 260 //Log.Out ("Dirty: " + v + " render: true"); 261 chunksRendered.Add (v); 262 if (dirtyChunks [v].Length != Constants.MAP_CHUNK_SIZE * Constants.MAP_CHUNK_SIZE) { 263 Log.Error (string.Format ("Rendering chunk has incorrect data size of {0} instead of {1}", 264 dirtyChunks [v].Length, Constants.MAP_CHUNK_SIZE * Constants.MAP_CHUNK_SIZE)); 265 } 266 267 zoomLevelBuffers [Constants.ZOOMLEVELS - 1] 268 .SetPart (v_blockOffset, Constants.MAP_CHUNK_SIZE, dirtyChunks [v]); 269 } 244 getBlockNumber (v, out Vector2i vBlock, out Vector2i vBlockOffset, Constants.MAP_BLOCK_TO_CHUNK_DIV, 245 Constants.MapChunkSize); 246 if (!vBlock.Equals (block)) { 247 continue; 248 } 249 250 //Log.Out ("Dirty: " + v + " render: true"); 251 chunksRendered.Add (v); 252 if (dirtyChunks [v].Length != Constants.MapChunkSize * Constants.MapChunkSize) { 253 Log.Error ( 254 $"Rendering chunk has incorrect data size of {dirtyChunks [v].Length} instead of {Constants.MapChunkSize * Constants.MapChunkSize}"); 255 } 256 257 zoomLevelBuffers [Constants.Zoomlevels - 1] 258 .SetPart (vBlockOffset, Constants.MapChunkSize, dirtyChunks [v]); 270 259 } 271 260 Profiler.EndSample (); … … 285 274 private void RenderZoomLevel (Vector2i _innerBlock) { 286 275 Profiler.BeginSample ("RenderZoomLevel"); 287 int level = Constants.Z OOMLEVELS- 1;276 int level = Constants.Zoomlevels - 1; 288 277 while (level > 0) { 289 Vector2i block, blockOffset; 290 getBlockNumber (_innerBlock, out block, out blockOffset, 2, Constants.MAP_BLOCK_SIZE / 2); 278 getBlockNumber (_innerBlock, out Vector2i block, out Vector2i blockOffset, 2, Constants.MapBlockSize / 2); 291 279 292 280 zoomLevelBuffers [level - 1].LoadBlock (block); … … 296 284 zoomLevelBuffers [level].FormatSelf == TextureFormat.RGBA32) && 297 285 zoomLevelBuffers [level].FormatSelf == zoomLevelBuffers [level - 1].FormatSelf) { 298 zoomLevelBuffers [level - 1].SetPartNative (blockOffset, Constants.M AP_BLOCK_SIZE/ 2, zoomLevelBuffers [level].GetHalfScaledNative ());286 zoomLevelBuffers [level - 1].SetPartNative (blockOffset, Constants.MapBlockSize / 2, zoomLevelBuffers [level].GetHalfScaledNative ()); 299 287 } else { 300 zoomLevelBuffers [level - 1].SetPart (blockOffset, Constants.M AP_BLOCK_SIZE/ 2, zoomLevelBuffers [level].GetHalfScaled ());288 zoomLevelBuffers [level - 1].SetPart (blockOffset, Constants.MapBlockSize / 2, zoomLevelBuffers [level].GetHalfScaled ()); 301 289 } 302 290 Profiler.EndSample (); … … 310 298 private void getBlockNumber (Vector2i _innerPos, out Vector2i _block, out Vector2i _blockOffset, int _scaleFactor, 311 299 int _offsetSize) { 312 _block = default (Vector2i);313 _blockOffset = default (Vector2i);300 _block = default; 301 _blockOffset = default; 314 302 _block.x = (_innerPos.x + 16777216) / _scaleFactor - 16777216 / _scaleFactor; 315 303 _block.y = (_innerPos.y + 16777216) / _scaleFactor - 16777216 / _scaleFactor; … … 319 307 320 308 private void WriteMapInfo () { 321 J SONObject mapInfo = new JSONObject ();322 mapInfo.Add ("blockSize", new J SONNumber (Constants.MAP_BLOCK_SIZE));323 mapInfo.Add ("maxZoom", new J SONNumber (Constants.ZOOMLEVELS- 1));324 325 Directory.CreateDirectory (Constants.M AP_DIRECTORY);326 File.WriteAllText (Constants.M AP_DIRECTORY+ "/mapinfo.json", mapInfo.ToString (), Encoding.UTF8);309 JsonObject mapInfo = new JsonObject (); 310 mapInfo.Add ("blockSize", new JsonNumber (Constants.MapBlockSize)); 311 mapInfo.Add ("maxZoom", new JsonNumber (Constants.Zoomlevels - 1)); 312 313 Directory.CreateDirectory (Constants.MapDirectory); 314 File.WriteAllText (Constants.MapDirectory + "/mapinfo.json", mapInfo.ToString (), Encoding.UTF8); 327 315 } 328 316 329 317 private bool LoadMapInfo () { 330 if (!File.Exists (Constants.M AP_DIRECTORY+ "/mapinfo.json")) {318 if (!File.Exists (Constants.MapDirectory + "/mapinfo.json")) { 331 319 return false; 332 320 } 333 321 334 string json = File.ReadAllText (Constants.M AP_DIRECTORY+ "/mapinfo.json", Encoding.UTF8);322 string json = File.ReadAllText (Constants.MapDirectory + "/mapinfo.json", Encoding.UTF8); 335 323 try { 336 JSONNode node = Parser.Parse (json); 337 if (node is JSONObject) { 338 JSONObject jo = (JSONObject) node; 324 JsonNode node = Parser.Parse (json); 325 if (node is JsonObject jo) { 339 326 if (jo.ContainsKey ("blockSize")) { 340 Constants.M AP_BLOCK_SIZE = ((JSONNumber) jo ["blockSize"]).GetInt ();327 Constants.MapBlockSize = ((JsonNumber) jo ["blockSize"]).GetInt (); 341 328 } 342 329 343 330 if (jo.ContainsKey ("maxZoom")) { 344 Constants.Z OOMLEVELS = ((JSONNumber) jo ["maxZoom"]).GetInt () + 1;331 Constants.Zoomlevels = ((JsonNumber) jo ["maxZoom"]).GetInt () + 1; 345 332 } 346 333 347 334 return true; 348 335 } 349 } catch (MalformedJ SONException e) {336 } catch (MalformedJsonException e) { 350 337 Log.Out ("Exception in LoadMapInfo: " + e); 351 338 } catch (InvalidCastException e) { … … 360 347 out int _widthChunks, out int _heightChunks, 361 348 out int _widthPix, out int _heightPix) { 362 _minChunk = default (Vector2i);363 _maxChunk = default (Vector2i);364 _minPos = default (Vector2i);365 _maxPos = default (Vector2i);349 _minChunk = default; 350 _maxChunk = default; 351 _minPos = default; 352 _maxPos = default; 366 353 367 354 long[] keys = _rfm.GetAllChunkKeys (); … … 397 384 _maxChunk.y = maxY; 398 385 399 _minPos.x = minX * Constants.M AP_CHUNK_SIZE;400 _minPos.y = minY * Constants.M AP_CHUNK_SIZE;401 402 _maxPos.x = maxX * Constants.M AP_CHUNK_SIZE;403 _maxPos.y = maxY * Constants.M AP_CHUNK_SIZE;386 _minPos.x = minX * Constants.MapChunkSize; 387 _minPos.y = minY * Constants.MapChunkSize; 388 389 _maxPos.x = maxX * Constants.MapChunkSize; 390 _maxPos.y = maxY * Constants.MapChunkSize; 404 391 405 392 _widthChunks = maxX - minX + 1; 406 393 _heightChunks = maxY - minY + 1; 407 394 408 _widthPix = _widthChunks * Constants.M AP_CHUNK_SIZE;409 _heightPix = _heightChunks * Constants.M AP_CHUNK_SIZE;395 _widthPix = _widthChunks * Constants.MapChunkSize; 396 _heightPix = _heightChunks * Constants.MapChunkSize; 410 397 } 411 398 -
binary-improvements2/MapRendering/src/ModApi.cs
r390 r391 1 using AllocsFixes.NetConnections.Servers.Web; 2 using AllocsFixes.NetConnections.Servers.Web.Handlers; 1 using JetBrains.Annotations; 3 2 4 namespace AllocsFixes { 5 public class API : IModApi { 6 private Web webInstance; 7 private Mod modInstance; 8 3 namespace MapRendering { 4 [UsedImplicitly] 5 public class ModApi : IModApi { 9 6 public void InitMod (Mod _modInstance) { 10 ModEvents.GameStartDone.RegisterHandler (GameStartDone);11 7 ModEvents.GameShutdown.RegisterHandler (GameShutdown); 12 8 ModEvents.CalcChunkColorsDone.RegisterHandler (CalcChunkColorsDone); 13 modInstance = _modInstance;14 }15 16 private void GameStartDone () {17 // ReSharper disable once ObjectCreationAsStatement18 if (!ConnectionManager.Instance.IsServer) {19 return;20 }21 22 webInstance = new Web (modInstance.Path);23 LogBuffer.Init ();24 25 if (ItemIconHandler.Instance != null) {26 ItemIconHandler.Instance.LoadIcons ();27 }28 9 } 29 10 30 11 private void GameShutdown () { 31 webInstance?.Shutdown (); 32 MapRendering.MapRendering.Shutdown (); 12 MapRenderer.Shutdown (); 33 13 } 34 14 35 15 private void CalcChunkColorsDone (Chunk _chunk) { 36 MapRender ing.MapRendering.RenderSingleChunk (_chunk);16 MapRenderer.RenderSingleChunk (_chunk); 37 17 } 38 18 } -
binary-improvements2/MarkersMod/MarkersMod.csproj
r390 r391 8 8 <ProjectGuid>{2A008E16-6EB8-4B85-A175-3CB89D9FF4AE}</ProjectGuid> 9 9 <OutputType>Library</OutputType> 10 <RootNamespace> MarkersMod</RootNamespace>10 <RootNamespace>Examples</RootNamespace> 11 11 <AssemblyName>MarkersMod</AssemblyName> 12 12 <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> … … 16 16 <DebugType>none</DebugType> 17 17 <Optimize>true</Optimize> 18 <OutputPath>..\bin\Mods\ MarkersMod\</OutputPath>18 <OutputPath>..\bin\Mods\Xample_MarkersMod\</OutputPath> 19 19 <ErrorReport>prompt</ErrorReport> 20 20 <WarningLevel>4</WarningLevel> … … 23 23 </PropertyGroup> 24 24 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_Profiler|AnyCPU' "> 25 <OutputPath>..\bin\Mods\ MarkersMod\</OutputPath>25 <OutputPath>..\bin\Mods\Xample_MarkersMod\</OutputPath> 26 26 <DefineConstants>ENABLE_PROFILER</DefineConstants> 27 27 <Optimize>true</Optimize> … … 32 32 </PropertyGroup> 33 33 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> 34 <OutputPath>..\bin\Mods\ MarkersMod\</OutputPath>34 <OutputPath>..\bin\Mods\Xample_MarkersMod\</OutputPath> 35 35 <DebugType>full</DebugType> 36 36 <DebugSymbols>true</DebugSymbols> … … 55 55 </ItemGroup> 56 56 <ItemGroup> 57 <Compile Include=" AssemblyInfo.cs" />58 <Compile Include=" API.cs" />59 <Compile Include=" Markers.cs" />57 <Compile Include="src\ModApi.cs" /> 58 <Compile Include="src\AssemblyInfo.cs" /> 59 <Compile Include="src\Markers.cs" /> 60 60 </ItemGroup> 61 61 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> … … 71 71 <Private>False</Private> 72 72 </ProjectReference> 73 <ProjectReference Include="..\ MapRendering\WebAndMapRendering.csproj">74 <Project>{ a1847b5f-7bfc-4bcd-94aa-a6c9fb7e7c54}</Project>75 <Name>Web AndMapRendering</Name>73 <ProjectReference Include="..\WebServer\WebServer.csproj"> 74 <Project>{01b5f981-b9fd-4364-8f9e-9127130d2542}</Project> 75 <Name>WebServer</Name> 76 76 <Private>False</Private> 77 77 </ProjectReference> -
binary-improvements2/MarkersMod/src/AssemblyInfo.cs
r390 r391 7 7 [assembly: AssemblyDescription ("")] 8 8 [assembly: AssemblyConfiguration ("")] 9 [assembly: AssemblyCompany (" ")]9 [assembly: AssemblyCompany ("The Fun Pimps LLC")] 10 10 [assembly: AssemblyProduct ("")] 11 [assembly: AssemblyCopyright (" ")]11 [assembly: AssemblyCopyright ("The Fun Pimps LLC")] 12 12 [assembly: AssemblyTrademark ("")] 13 13 [assembly: AssemblyCulture ("")] -
binary-improvements2/MarkersMod/src/Markers.cs
r390 r391 2 2 using System.Net; 3 3 using AllocsFixes.JSON; 4 using AllocsFixes.NetConnections.Servers.Web;5 using AllocsFixes.NetConnections.Servers.Web.API;4 using Webserver; 5 using Webserver.WebAPI; 6 6 7 7 namespace Examples { 8 class Markers : AbsRestApi {9 private const int NumRandomMarkers = 5;8 public class Markers : AbsRestApi { 9 private const int numRandomMarkers = 5; 10 10 11 11 private readonly Dictionary<string, (int, int)> markers = new Dictionary<string, (int, int)> (); 12 12 13 private static readonly J SONArray emptyResult = new JSONArray ();13 private static readonly JsonArray emptyResult = new JsonArray (); 14 14 15 15 public Markers () { 16 16 GameRandom random = GameRandomManager.Instance.CreateGameRandom (); 17 17 18 for (int i = 0; i < NumRandomMarkers; i++) {18 for (int i = 0; i < numRandomMarkers; i++) { 19 19 int lat = random.RandomRange (-1000, 1001); 20 20 int lng = random.RandomRange (-1000, 1001); … … 28 28 29 29 if (string.IsNullOrEmpty (id)) { 30 J SONArray result = new JSONArray ();30 JsonArray result = new JsonArray (); 31 31 32 foreach ( KeyValuePair<string, (int, int)> kvpin markers) {33 J SONObject marker = new JSONObject ();34 marker.Add ("id", new J SONString (kvp.Key));35 marker.Add ("lat", new J SONNumber (kvp.Value.Item1));36 marker.Add ("lng", new J SONNumber (kvp.Value.Item2));32 foreach ((string markerId, (int, int) coordinates) in markers) { 33 JsonObject marker = new JsonObject (); 34 marker.Add ("id", new JsonString (markerId)); 35 marker.Add ("lat", new JsonNumber (coordinates.Item1)); 36 marker.Add ("lng", new JsonNumber (coordinates.Item2)); 37 37 result.Add (marker); 38 38 } … … 48 48 49 49 { 50 J SONArray result = new JSONArray ();51 J SONObject marker = new JSONObject ();52 marker.Add ("id", new J SONString (id));53 marker.Add ("lat", new J SONNumber (location.Item1));54 marker.Add ("lng", new J SONNumber (location.Item2));50 JsonArray result = new JsonArray (); 51 JsonObject marker = new JsonObject (); 52 marker.Add ("id", new JsonString (id)); 53 marker.Add ("lat", new JsonNumber (location.Item1)); 54 marker.Add ("lng", new JsonNumber (location.Item2)); 55 55 result.Add (marker); 56 56 SendEnvelopedResult (_context, result); … … 58 58 } 59 59 60 protected override void HandleRestPost (RequestContext _context, J SONNode _jsonBody) {61 if (!(_jsonBody is J SONObject bodyObject)) {60 protected override void HandleRestPost (RequestContext _context, JsonNode _jsonBody) { 61 if (!(_jsonBody is JsonObject bodyObject)) { 62 62 SendEnvelopedResult (_context, null, HttpStatusCode.BadRequest, _jsonBody, "BODY_NOT_OBJECT"); 63 63 return; … … 77 77 markers.Add (newId, (lat, lng)); 78 78 79 J SONString result = new JSONString (newId);80 SendEnvelopedResult (_context, result );79 JsonString result = new JsonString (newId); 80 SendEnvelopedResult (_context, result, HttpStatusCode.Created); 81 81 } 82 82 83 protected override void HandleRestPut (RequestContext _context, J SONNode _jsonBody) {84 if (!(_jsonBody is J SONObject bodyObject)) {83 protected override void HandleRestPut (RequestContext _context, JsonNode _jsonBody) { 84 if (!(_jsonBody is JsonObject bodyObject)) { 85 85 SendEnvelopedResult (_context, null, HttpStatusCode.BadRequest, _jsonBody, "BODY_NOT_OBJECT"); 86 86 return; … … 99 99 string id = _context.RequestPath; 100 100 101 if (!markers.TryGetValue (id, out (int, int) location)) {101 if (!markers.TryGetValue (id, out _)) { 102 102 SendEnvelopedResult (_context, null, HttpStatusCode.NotFound, _jsonBody, "ID_NOT_FOUND"); 103 103 return; … … 106 106 markers [id] = (lat, lng); 107 107 108 J SONObject result = new JSONObject ();109 result.Add ("id", new J SONString (id));110 result.Add ("lat", new J SONNumber (lat));111 result.Add ("lng", new J SONNumber (lng));108 JsonObject result = new JsonObject (); 109 result.Add ("id", new JsonString (id)); 110 result.Add ("lat", new JsonNumber (lat)); 111 result.Add ("lng", new JsonNumber (lng)); 112 112 SendEnvelopedResult (_context, result); 113 113 } -
binary-improvements2/MarkersMod/src/ModApi.cs
r390 r391 1 1 namespace Examples { 2 public class API: IModApi {2 public class ModApi : IModApi { 3 3 public void InitMod (Mod _modInstance) { 4 4 } -
binary-improvements2/SpaceWizards.HttpListener/SpaceWizards.HttpListener.csproj
r386 r391 17 17 <DebugType>none</DebugType> 18 18 <Optimize>true</Optimize> 19 <OutputPath>..\bin\Mods\ Allocs_WebAndMapRendering\</OutputPath>19 <OutputPath>..\bin\Mods\TFP_WebServer\</OutputPath> 20 20 <ErrorReport>prompt</ErrorReport> 21 21 <WarningLevel>4</WarningLevel> … … 26 26 </PropertyGroup> 27 27 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_Profiler|AnyCPU' "> 28 <OutputPath>..\bin\Mods\ Allocs_WebAndMapRendering\</OutputPath>28 <OutputPath>..\bin\Mods\TFP_WebServer\</OutputPath> 29 29 <DefineConstants>ENABLE_PROFILER;UNITY_NETFRAMEWORK</DefineConstants> 30 30 <Optimize>true</Optimize> … … 34 34 </PropertyGroup> 35 35 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> 36 <OutputPath>..\bin\Mods\ Allocs_WebAndMapRendering\</OutputPath>36 <OutputPath>..\bin\Mods\TFP_WebServer\</OutputPath> 37 37 <DebugType>full</DebugType> 38 38 <AllowUnsafeBlocks>true</AllowUnsafeBlocks> -
binary-improvements2/server-fixes.sln
r390 r391 4 4 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "7dtd-server-fixes", "7dtd-server-fixes\7dtd-server-fixes.csproj", "{81DA7F87-1A66-4920-AADA-6EAF1971F8D0}" 5 5 EndProject 6 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = " AllocsCommands", "AllocsCommands\AllocsCommands.csproj", "{E273D042-57F9-4E2E-8268-5053527E5287}"6 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommandExtensions", "CommandExtensions\CommandExtensions.csproj", "{E273D042-57F9-4E2E-8268-5053527E5287}" 7 7 EndProject 8 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = " WebAndMapRendering", "MapRendering\WebAndMapRendering.csproj", "{A1847B5F-7BFC-4BCD-94AA-A6C9FB7E7C54}"8 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MapRendering", "MapRendering\MapRendering.csproj", "{A1847B5F-7BFC-4BCD-94AA-A6C9FB7E7C54}" 9 9 EndProject 10 10 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpaceWizards.HttpListener", "SpaceWizards.HttpListener\SpaceWizards.HttpListener.csproj", "{E273D042-57F9-4E2E-8268-5053527E5287}" 11 11 EndProject 12 12 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MarkersMod", "MarkersMod\MarkersMod.csproj", "{2A008E16-6EB8-4B85-A175-3CB89D9FF4AE}" 13 EndProject 14 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebServer", "WebServer\WebServer.csproj", "{01B5F981-B9FD-4364-8F9E-9127130D2542}" 13 15 EndProject 14 16 Global … … 52 54 {2A008E16-6EB8-4B85-A175-3CB89D9FF4AE}.Release_Profiler|Any CPU.ActiveCfg = Release_Profiler|Any CPU 53 55 {2A008E16-6EB8-4B85-A175-3CB89D9FF4AE}.Release_Profiler|Any CPU.Build.0 = Release_Profiler|Any CPU 56 {01B5F981-B9FD-4364-8F9E-9127130D2542}.Release|Any CPU.ActiveCfg = Release|Any CPU 57 {01B5F981-B9FD-4364-8F9E-9127130D2542}.Release|Any CPU.Build.0 = Release|Any CPU 58 {01B5F981-B9FD-4364-8F9E-9127130D2542}.Release_Version|Any CPU.ActiveCfg = Release|Any CPU 59 {01B5F981-B9FD-4364-8F9E-9127130D2542}.Release_Version|Any CPU.Build.0 = Release|Any CPU 60 {01B5F981-B9FD-4364-8F9E-9127130D2542}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 61 {01B5F981-B9FD-4364-8F9E-9127130D2542}.Debug|Any CPU.Build.0 = Debug|Any CPU 62 {01B5F981-B9FD-4364-8F9E-9127130D2542}.Release_Profiler|Any CPU.ActiveCfg = Release_Profiler|Any CPU 63 {01B5F981-B9FD-4364-8F9E-9127130D2542}.Release_Profiler|Any CPU.Build.0 = Release_Profiler|Any CPU 54 64 EndGlobalSection 55 65 GlobalSection(MonoDevelopProperties) = preSolution
Note:
See TracChangeset
for help on using the changeset viewer.