Advertisement
Guest User

Untitled

a guest
Jun 4th, 2015
723
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. using System.IO;
  8. using Newtonsoft.Json.Linq;
  9.  
  10. namespace MiniPlacement
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             var ideMapping = new Dictionary<string, string[]>();
  17.  
  18.             //var sourceIde = @"Y:\dev\ydr\speed2\nj_liberty.ide";
  19.             var sourceIde = @"Y:\dls\gta_ldn\gta_ldn.ide";
  20.  
  21.             // read the source IDE
  22.             var lines = File.ReadAllLines(sourceIde);
  23.             var inObjs = false;
  24.  
  25.             foreach (var line in lines)
  26.             {
  27.                 if (line == "objs")
  28.                 {
  29.                     inObjs = true;
  30.                 }
  31.                 else if (inObjs)
  32.                 {
  33.                     if (line == "end")
  34.                     {
  35.                         break;
  36.                     }
  37.  
  38.                     var bits = line.Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries);
  39.  
  40.                     if (bits.Last() == "null")
  41.                     {
  42.                         ideMapping[bits[0].ToLower()] = bits;
  43.                     }
  44.                 }
  45.             }
  46.  
  47.             // read the source IPLs
  48.             var sourceIPLs = Directory.GetFiles(@"Y:\dls\gta_ldn", "*.opl");
  49.             var iplMapping = new List<string[]>();
  50.  
  51.             foreach (var ipl in sourceIPLs)
  52.             {
  53.                 lines = File.ReadAllLines(ipl);
  54.  
  55.                 inObjs = false;
  56.  
  57.                 foreach (var line in lines)
  58.                 {
  59.                     if (line == "inst")
  60.                     {
  61.                         inObjs = true;
  62.                     }
  63.                     else if (inObjs)
  64.                     {
  65.                         if (line == "end")
  66.                         {
  67.                             break;
  68.                         }
  69.  
  70.                         var bits = line.Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries);
  71.  
  72.                         if (ideMapping.ContainsKey(bits[7].ToLower()) || bits[7].StartsWith("hash:"))
  73.                         {
  74.                             iplMapping.Add(bits);
  75.                         }
  76.                     }
  77.                 }
  78.             }
  79.  
  80.             // write the object
  81.             var jo = new JObject();
  82.  
  83.             jo["$schema"] = "schema.json";
  84.  
  85.             var archetypes = new JArray();
  86.             jo["archetypes"] = archetypes;
  87.  
  88.             foreach (var entry in ideMapping)
  89.             {
  90.                 var at = new JObject();
  91.                 at["aabbMin"] = new JArray() { float.Parse(entry.Value[5]), float.Parse(entry.Value[6]), float.Parse(entry.Value[7]) };
  92.                 at["aabbMax"] = new JArray() { float.Parse(entry.Value[8]), float.Parse(entry.Value[9]), float.Parse(entry.Value[10]) };
  93.                 at["centroid"] = new JArray() { float.Parse(entry.Value[11]), float.Parse(entry.Value[12]), float.Parse(entry.Value[13]) };
  94.                 at["radius"] = float.Parse(entry.Value[14]);
  95.                 at["archetypeName"] = entry.Value[0];
  96.                 at["txdName"] = entry.Value[1];
  97.  
  98.                 archetypes.Add(at);
  99.             }
  100.  
  101.             var entities = new JArray();
  102.             jo["entities"] = entities;
  103.  
  104.             foreach (var entry in iplMapping)
  105.             {
  106.                 var et = new JObject();
  107.                 et["position"] = new JArray() { float.Parse(entry[0]), float.Parse(entry[1]), float.Parse(entry[2]) };
  108.                 et["rotation"] = new JArray() { float.Parse(entry[3]), float.Parse(entry[4]), float.Parse(entry[5]), float.Parse(entry[6]) };
  109.                 et["guid"] = Guid.NewGuid().ToString();
  110.                 et["archetypeName"] = entry[7];
  111.  
  112.                 entities.Add(et);
  113.             }
  114.  
  115.             File.WriteAllText(@"X:\gta\iv\citizenmp\citizenmp\bin\five\debug\citizen\common\data\levels\gta5\london.json", jo.ToString());
  116.         }
  117.     }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement