public static int getBigTilesAddr(int hierarchyLevel, int id) { GetBigBlocksAddrFunc getAddrFunc = null; if (hierarchyLevel < ConfigScript.getBigBlocksAddrFuncs.Length) { getAddrFunc = ConfigScript.getBigBlocksAddrFuncs[hierarchyLevel]; } return(getAddrFunc?.Invoke(id) ?? getBigTilesAddrDefault(hierarchyLevel, id)); }
public static void LoadFromFile(string fileName) { programStartDirectory = AppDomain.CurrentDomain.BaseDirectory + "/"; configDirectory = Path.GetDirectoryName(fileName) + "/"; var asm = new AsmHelper(CSScript.LoadCode(File.ReadAllText(fileName))); object data = null; bool metaDataExists = true; try { object metaData = null; try { metaData = asm.CreateObject("MetaData"); } catch (Exception) { metaDataExists = false; } if (metaDataExists) { var scriptText = callFromScript(asm, metaData, "*.makeConfig", ""); var patchDict = callFromScript(asm, metaData, "*.getPatchDictionary", new Dictionary <string, object>()); scriptText = Utils.patchConfigTemplate(scriptText, patchDict); asm = new AsmHelper(CSScript.LoadCode(scriptText)); data = asm.CreateObject("Data"); } } catch (Exception e) { MessageBox.Show(e.Message); } if (!metaDataExists) { try { data = asm.CreateObject("Data"); } catch (Exception) { return; } } screensOffset = new OffsetRec[1]; palOffset = callFromScript(asm, data, "*.getPalOffset", new OffsetRec(0, 1, 0)); videoOffset = callFromScript(asm, data, "*.getVideoOffset", new OffsetRec(0, 1, 0)); videoObjOffset = callFromScript(asm, data, "*.getVideoObjOffset", new OffsetRec(0, 1, 0)); blocksOffset = callFromScript(asm, data, "*.getBlocksOffset", new OffsetRec(0, 1, 0)); screensOffset[0] = callFromScript(asm, data, "*.getScreensOffset", new OffsetRec(0, 1, 0, -1, -1)); if ((screensOffset[0].beginAddr == 0) && (screensOffset[0].recSize == 0)) { screensOffset = callFromScript(asm, data, "*.getScreensOffsetsForLevels", new OffsetRec[1]); } if ((screensOffset[0].width <= 0) || (screensOffset[0].height <= 0)) { throw new Exception("Screen width and height must be defined and be positive numbers"); } screenVertical = callFromScript(asm, data, "*.getScreenVertical", false); screenDataStride = callFromScript(asm, data, "*.getScreenDataStride", 1); wordLen = callFromScript(asm, data, "*.getWordLen", 1); littleEndian = callFromScript(asm, data, "*.isLittleEndian", false); useSegaGraphics = callFromScript(asm, data, "*.isUseSegaGraphics", false); useGbGraphics = callFromScript(asm, data, "*.isUseGbGraphics", false); blockSize4x4 = callFromScript(asm, data, "*.isBlockSize4x4", false); buildScreenFromSmallBlocks = callFromScript(asm, data, "isBuildScreenFromSmallBlocks", false); getLevelRecsFunc = callFromScript <GetLevelRecsFunc>(asm, data, "*.getLevelRecsFunc", ConfigScript.getLevelRecsFuncDefault()); //todo: remove or change to many lists interface minObjCoordX = callFromScript(asm, data, "*.getMinObjCoordX", 0); minObjCoordY = callFromScript(asm, data, "*.getMinObjCoordY", 0); minObjType = callFromScript(asm, data, "*.getMinObjType", 0); maxObjCoordX = callFromScript(asm, data, "*.getMaxObjCoordX", -1); maxObjCoordY = callFromScript(asm, data, "*.getMaxObjCoordY", -1); maxObjType = callFromScript(asm, data, "*.getMaxObjType", -1); //256 bigBlocksHierarchyCount = callFromScript <int>(asm, data, "*.getBigBlocksHierarchyCount", 1); bigBlocksCounts = new int[bigBlocksHierarchyCount]; for (int hierLevel = 0; hierLevel < bigBlocksHierarchyCount; hierLevel++) { bigBlocksCounts[hierLevel] = callFromScript(asm, data, "*.getBigBlocksCountHierarchy", 256, hierLevel); } bigBlocksCounts[0] = callFromScript(asm, data, "*.getBigBlocksCount", bigBlocksCounts[0]); getBigBlocksCountFunc = callFromScript <GetBigBlocksCountFunc>(asm, data, "*.getBigBlocksCountFunc"); bigBlocksOffsets = new OffsetRec[bigBlocksHierarchyCount]; for (int hierLevel = 0; hierLevel < bigBlocksHierarchyCount; hierLevel++) { bigBlocksOffsets[hierLevel] = callFromScript(asm, data, "*.getBigBlocksOffsetHierarchy", new OffsetRec(0, 1, 0), hierLevel); } bigBlocksOffsets[0] = callFromScript(asm, data, "*.getBigBlocksOffset", bigBlocksOffsets[0]); getVideoPageAddrFunc = callFromScript <GetVideoPageAddrFunc>(asm, data, "*.getVideoPageAddrFunc"); getVideoChunkFunc = callFromScript <GetVideoChunkFunc>(asm, data, "*.getVideoChunkFunc"); setVideoChunkFunc = callFromScript <SetVideoChunkFunc>(asm, data, "*.setVideoChunkFunc"); getBigBlocksFuncs = new GetBigBlocksFunc[bigBlocksHierarchyCount]; setBigBlocksFuncs = new SetBigBlocksFunc[bigBlocksHierarchyCount]; getBigBlocksAddrFuncs = new GetBigBlocksAddrFunc[bigBlocksHierarchyCount]; getBigBlocksFuncs = callFromScript <GetBigBlocksFunc[]>(asm, data, "*.getBigBlocksFuncs", new GetBigBlocksFunc[1]); setBigBlocksFuncs = callFromScript <SetBigBlocksFunc[]>(asm, data, "*.setBigBlocksFuncs", new SetBigBlocksFunc[1]); getBigBlocksAddrFuncs = callFromScript <GetBigBlocksAddrFunc[]>(asm, data, "*.getBigBlocksAddrFuncs", new GetBigBlocksAddrFunc[1]); if (!buildScreenFromSmallBlocks) { getBigBlocksFuncs[0] = callFromScript <GetBigBlocksFunc>(asm, data, "*.getBigBlocksFunc", getBigBlocksFuncs[0]); setBigBlocksFuncs[0] = callFromScript <SetBigBlocksFunc>(asm, data, "*.setBigBlocksFunc", setBigBlocksFuncs[0]); getBigBlocksAddrFuncs[0] = callFromScript <GetBigBlocksAddrFunc>(asm, data, "*.getBigBlocksAddrFunc", getBigBlocksAddrFuncs[0]); } getSegaMappingFunc = callFromScript <GetSegaMappingFunc>(asm, data, "*.getSegaMappingFunc", (int index) => Utils.readLinearBigBlockData(0, index)); setSegaMappingFunc = callFromScript <SetSegaMappingFunc>(asm, data, "*.setSegaMappingFunc", (int index, byte[] bb) => { Utils.writeLinearBigBlockData(0, index, bb); }); getBlocksFunc = callFromScript <GetBlocksFunc>(asm, data, "*.getBlocksFunc"); setBlocksFunc = callFromScript <SetBlocksFunc>(asm, data, "*.setBlocksFunc"); getBlocksAddrFunc = callFromScript <GetBlocksAddrFunc> (asm, data, "*.getBlocksAddrFunc"); getPalFunc = callFromScript <GetPalFunc>(asm, data, "*.getPalFunc"); setPalFunc = callFromScript <SetPalFunc>(asm, data, "*.setPalFunc"); getObjectsFunc = callFromScript <GetObjectsFunc>(asm, data, "*.getObjectsFunc"); setObjectsFunc = callFromScript <SetObjectsFunc>(asm, data, "*.setObjectsFunc"); sortObjectsFunc = callFromScript <SortObjectsFunc>(asm, data, "*.sortObjectsFunc"); getLayoutFunc = callFromScript <GetLayoutFunc>(asm, data, "*.getLayoutFunc", Utils.getDefaultLayoutFunc()); setLayoutFunc = callFromScript <SetLayoutFunc>(asm, data, "*.setLayoutFunc", null); convertScreenTileFunc = callFromScript <ConvertScreenTileFunc>(asm, data, "*.getConvertScreenTileFunc"); backConvertScreenTileFunc = callFromScript <ConvertScreenTileFunc>(asm, data, "*.getBackConvertScreenTileFunc"); getBigTileNoFromScreenFunc = callFromScript <GetBigTileNoFromScreenFunc>(asm, data, "*.getBigTileNoFromScreenFunc", Utils.getBigTileNoFromScreen); setBigTileToScreenFunc = callFromScript <SetBigTileToScreenFunc>(asm, data, "*.setBigTileToScreenFunc", Utils.setBigTileToScreen); getObjectDictionaryFunc = callFromScript <GetObjectDictionaryFunc>(asm, data, "*.getObjectDictionaryFunc"); loadSegaBackFunc = callFromScript <LoadSegaBackFunc>(asm, data, "*.loadSegaBackFunc"); saveSegaBackFunc = callFromScript <SaveSegaBackFunc>(asm, data, "*.saveSegaBackFunc"); segaBackWidth = callFromScript(asm, data, "*.getSegaBackWidth", 64); segaBackHeight = callFromScript(asm, data, "*.getSegaBackHeight", 32); drawObjectFunc = callFromScript <DrawObjectFunc>(asm, data, "*.getDrawObjectFunc"); drawObjectBigFunc = callFromScript <DrawObjectBigFunc>(asm, data, "*.getDrawObjectBigFunc"); selectObjectBigFunc = callFromScript <SelectObjectBigFunc>(asm, data, "*.getSelectObjectBigFunc"); renderToMainScreenFunc = callFromScript <RenderToMainScreenFunc>(asm, data, "*.getRenderToMainScreenFunc"); isBigBlockEditorEnabled = callFromScript(asm, data, "*.isBigBlockEditorEnabled", true); isBlockEditorEnabled = callFromScript(asm, data, "*.isBlockEditorEnabled", true); isEnemyEditorEnabled = callFromScript(asm, data, "*.isEnemyEditorEnabled", true); objTypesPicturesDir = callFromScript(asm, data, "*.getObjTypesPicturesDir", "obj_sprites"); showScrollsInLayout = callFromScript(asm, data, "*.isShowScrollsInLayout", true); scrollsOffsetFromLayout = callFromScript(asm, data, "*.getScrollsOffsetFromLayout", 0); scrollByteArray = callFromScript(asm, data, "*.getScrollByteArray", new byte[0]); blocksCount = callFromScript(asm, data, "*.getBlocksCount", 256); getBlocksCountFunc = callFromScript <GetBlocksCountFunc>(asm, data, "*.getBlocksCountFunc"); blocksPicturesFilename = callFromScript(asm, data, "getBlocksFilename", ""); loadScreensFunc = callFromScript <LoadScreensFunc>(asm, data, "*.loadScreensFunc"); saveScreensFunc = callFromScript <SaveScreensFunc>(asm, data, "*.saveScreensFunc"); loadPhysicsLayerFunc = callFromScript <LoadPhysicsLayer>(asm, data, "*.loadPhysicsLayerFunc"); savePhysicsLayerFunc = callFromScript <SavePhysicsLayer>(asm, data, "*.savePhysicsLayerFunc"); physicsBlocksCount = callFromScript(asm, data, "*.getPhysicsBlocksCount", 256); if (blocksPicturesFilename != "") { if (!File.Exists(ConfigScript.getBlocksPicturesFilename())) { throw new Exception("File does not exists: " + ConfigScript.getBlocksPicturesFilename()); } } blocksPicturesWidth = callFromScript(asm, data, "getPictureBlocksWidth", 32); usePicturesInstedBlocks = blocksPicturesFilename != ""; blockTypeNames = callFromScript(asm, data, "getBlockTypeNames", defaultBlockTypeNames); getGroupsFunc = callFromScript <GetGroupsFunc>(asm, data, "*.getGroupsFunc", () => new GroupRec[0]); palBytesAddr = callFromScript(asm, data, "*.getPalBytesAddr", -1); physicsBytesAddr = callFromScript(asm, data, "*.getPhysicsBytesAddr", -1); getPalBytesAddrFunc = callFromScript <GetPalBytesAddrFunc>(asm, data, "*.getPalBytesAddrFunc"); defaultScale = callFromScript(asm, data, "*.getDefaultScale", -1.0f); loadAllPlugins(asm, data); ConfigScript.videoNes.updateColorsFromConfig(); }