public static void Load(string moduleName, bool instantiateModule = true) { data = new AuroraData(targetGame, moduleName, instantiateModule); }
void GetAllNCSFiles() { // Gets every NCS file in the game, including from all // modules files = new List <NCSFile>(); // Load base game files AuroraData data = new AuroraData( Game.KotOR, null ); Dictionary <string, int> baseGameActions = new Dictionary <string, int>(); foreach ((string resref, ResourceType key) in data.keyObject.resourceKeys.Keys) { // Type code for NCS scripts is 2010 if (key == ResourceType.NCS) { Debug.Log(resref); using (Stream stream = data.GetStream(resref, key)) { NCSFile file = new NCSFile(stream); foreach (NCSOperation op in file.operations) { if (op.opcode == 0x05) { // This operation is an action, so we have to find the type and // add it to the list string action = NWScript_Actions.ACTIONS[int.Parse(op.args[1])]; if (!baseGameActions.ContainsKey(action)) { baseGameActions.Add(action, 0); } baseGameActions[action]++; } } } } } Dictionary <string, Dictionary <string, int> > moduleActions = new Dictionary <string, Dictionary <string, int> >(); Debug.Log("Found " + baseGameActions.Count + " actions in base game"); // For each module, load the module data and get all the NCS files // First, get the list of modules string[] modules = Directory.GetFiles( AuroraData.GetPath("modules") ); HashSet <string> moduleNames = new HashSet <string>(); foreach (string module in modules) { string basename = Path.GetFileNameWithoutExtension(module.Replace("_s.rim", "")); moduleNames.Add(basename); } foreach (string module in moduleNames) { if (module != "end_m01aa") { // This is just for testing continue; } data.moduleName = module; data.LoadModuleFromGameFiles(false); Debug.Log("Loaded module " + module); // Now, get all the NCS files Dictionary <string, int> moduleCounts = new Dictionary <string, int>(); // Get all items from the rim, srim, dlg, and mod files // rim file if (data.srim != null) { RIMObject rim = (RIMObject)data.srim; foreach ((string resref, ResourceType key) in rim.resources.Keys) { // Type code for NCS scripts is 2010 if (key == ResourceType.NCS) { Debug.Log(resref); using (Stream stream = data.GetStream(resref, key)) { NCSFile file; try { file = new NCSFile(stream); } catch (Exception e) { Debug.LogWarning("Failed to load script '" + resref + "' from module " + module + ": " + e.Message); continue; } foreach (NCSOperation op in file.operations) { if (op.opcode == 0x05) { // This operation is an action, so we have to find the type and // add it to the list string action = NWScript_Actions.ACTIONS[int.Parse(op.args[1])]; if (!moduleCounts.ContainsKey(action)) { moduleCounts.Add(action, 0); } moduleCounts[action]++; } } } } } } // Save the counts moduleActions.Add(module, moduleCounts); } foreach (string module in moduleNames) { if (!moduleActions.ContainsKey(module)) { continue; } Debug.Log("Module " + module + " has " + moduleActions[module].Count + " actions"); } status = new ProjectStatus() { baseGameActions = baseGameActions, moduleActions = moduleActions }; }
public static Dictionary <string, Vector3> LoadLayout(string resref, AuroraData data) { // Debug.Log("Loading layout " + resref); Stream stream = data.GetStream(resref, ResourceType.LYT); // Debug.Log("Loaded stream " + stream); StreamReader reader = new StreamReader(stream, Encoding.ASCII); // string text = reader.ReadToEnd(); // Debug.Log(text); // Reset the reader back to the start // reader.BaseStream.Seek(0, SeekOrigin.Begin); Dictionary <string, Vector3> roomVectors = new Dictionary <string, Vector3>(); bool doingLayout = false; int parseType = 0; string line; while (!reader.EndOfStream) { line = reader.ReadLine(); Debug.Log(line); if (line.Contains("beginlayout")) { doingLayout = true; } else if (line.Contains("donelayout")) { doingLayout = false; } if (doingLayout) { if (line.Contains("roomcount")) { parseType = 1; continue; } else if (line.Contains("trackcount")) { parseType = 2; continue; } else if (line.Contains("obstaclecount")) { parseType = 3; continue; } else if (line.Contains("doorhookcount")) { parseType = 4; continue; } switch (parseType) { case 1: //rooms string[] arr = line.Trim().Split(' '); if (roomVectors != null) { roomVectors.Add(arr[0], new Vector3(float.Parse(arr[1]), float.Parse(arr[3]), float.Parse(arr[2]))); } break; default: //TODO: tracks, obstacles, door hooks break; } } } return(roomVectors); }
public Module(string name, AuroraData data, bool instantiateModule) { this.moduleName = name; this.data = data; if (!instantiateModule) { return; } if (stateManager == null) { stateManager = GameObject.Find("State System").GetComponent <StateSystem>(); } if (loader == null) { loader = GameObject.Find("Loading System").GetComponent <LoadingSystem>(); } ifo = data.Get <AuroraIFO>("module", ResourceType.IFO); Debug.Log(ifo); string areaName = ifo.Mod_Entry_Area; are = data.Get <AuroraARE>(areaName, ResourceType.ARE); git = data.Get <AuroraGIT>(areaName, ResourceType.GIT); entryPosition = new Vector3(ifo.Mod_Entry_X, ifo.Mod_Entry_Z, ifo.Mod_Entry_Y); Dictionary <string, Vector3> layout = Resources.LoadLayout(areaName, data); Debug.Log("Layout has " + layout.Count + " rooms."); area = Area.Create(are); GameObject parent = new GameObject("Models"); parent.transform.SetParent(area.transform); foreach (var value in layout) { loader.AddAction(() => { Debug.Log("Loading room " + value.Key); string resref = value.Key.ToLower(); GameObject room = Resources.LoadModel(resref); if (SetupSkybox(room)) { return; } // Set up the Navmesh SetLayerRecursive(room, LayerMask.NameToLayer("NavMeshStatic")); // Set the room's position and parent room.transform.position = value.Value; room.transform.SetParent(parent.transform); }); } LoadCreatures(); LoadPlaceables(); loader.AddAction(() => data.aiManager.BakeNavMesh()); LoadDoors(); LoadTriggers(); LoadEncounters(); LoadSounds(); LoadStores(); LoadWaypoints(); LoadCameras(); loader.AddAction(() => { // Load the music //int musicId = git.AreaProperties.MusicDay; //string musicResource = Resources.Load2DA("ambientmusic")[musicId, "resource"]; //ambientMusic = Resources.LoadAudio(musicResource); }); }