diff --git a/changelog/snippets/fix.7160.md b/changelog/snippets/fix.7160.md new file mode 100644 index 00000000000..01fae951d9a --- /dev/null +++ b/changelog/snippets/fix.7160.md @@ -0,0 +1,3 @@ +- (#7160) Fix turning off the "force affinity" client option not disabling adjustment of process affinity. + +- (#7160) Set process priority to "above normal" instead of "high" to prevent game freezes from freezing the functionality or UI of other programs. diff --git a/init.lua b/init.lua index 007854a0e2a..af6f9a76c68 100644 --- a/init.lua +++ b/init.lua @@ -1,4 +1,4 @@ --- START OF COPY -- +--#region START OF COPY -- in an ideal world this file would be loaded (using dofile) by the other -- initialisation files to prevent code duplication. However, as it stands @@ -36,39 +36,44 @@ if SetProcessPriority and GetProcessAffinityMask and SetProcessAffinityMask then -- priority values can be found at: -- - https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setpriorityclass - local success = SetProcessPriority(0x00000080) + local success = SetProcessPriority(0x00008000) if success then - LOG("Process - priority set to: 'high'") + LOG("Process - priority set to: 'above normal'") else LOG("Process - Failed to adjust process priority, this may impact your framerate") end - -- affinity values acts like a bit mask, we retrieve the mask and shift it if we think there are sufficient computing units - local success, processAffinityMask, systemAffinityMask = GetProcessAffinityMask(); - if success then - -- system has 24 (logical) computing units or more, skip the first two computing units and all cores beyond the first 24. We need - -- to do this because of floating point imprecision - we simply can't deduct a few digits to prevent using the first two cores - if systemAffinityMask >= 16777215 then - processAffinityMask = 16777212 -- 2 ^ 24 - 3 - 1 - - -- system has 6 (logical) computing units or more, skip first two computing units - elseif (systemAffinityMask >= 63) then - processAffinityMask = systemAffinityMask - 3 -- (2 ^ 6 - 1) - 3 - end - - -- update the afinity mask - if processAffinityMask != systemAffinityMask then - local success = SetProcessAffinityMask(processAffinityMask); - if success then - LOG("Process - affinity set to: " .. tostring(processAffinityMask)) + local forceAffinity = ForceAffinity == "true" + if forceAffinity then + -- affinity values acts like a bit mask, we retrieve the mask and shift it if we think there are sufficient computing units + local success, processAffinityMask, systemAffinityMask = GetProcessAffinityMask(); + if success then + -- system has 24 (logical) computing units or more, skip the first two computing units and all cores beyond the first 24. We need + -- to do this because of floating point imprecision - we simply can't deduct a few digits to prevent using the first two cores + if systemAffinityMask >= 16777215 then + processAffinityMask = 16777212 -- 2 ^ 24 - 3 - 1 + + -- system has 6 (logical) computing units or more, skip first two computing units + elseif (systemAffinityMask >= 63) then + processAffinityMask = systemAffinityMask - 3 -- (2 ^ 6 - 1) - 3 + end + + -- update the afinity mask + if processAffinityMask != systemAffinityMask then + local success = SetProcessAffinityMask(processAffinityMask); + if success then + LOG("Process - affinity set to: " .. tostring(processAffinityMask)) + else + LOG("Process - Failed to adjust the process affinity, this may impact your framerate") + end else - LOG("Process - Failed to adjust the process affinity, this may impact your framerate") + LOG("Process - Failed to update the process affinity, this may impact your framerate") end else - LOG("Process - Failed to update the process affinity, this may impact your framerate") + LOG("Process - Failed to retrieve the process affinity, this may impact your framerate") end else - LOG("Process - Failed to retrieve the process affinity, this may impact your framerate") + LOG("Process - Process affinity adjustment is disabled in client settings, this may impact your framerate") end else LOG("Process - Failed to find process priority and affinity related functions, this may impact your framerate") @@ -581,7 +586,7 @@ local function LoadVaultContent(path) MountModContent(path .. '/mods') end --- END OF COPY -- +--#endregion END OF COPY -- -- minimum viable shader version - should be bumped to the next release version when we change the shaders -- local minimumShaderVersion = 3745 diff --git a/init_faf.lua b/init_faf.lua index 8ad09ae6d8c..642efdd3b0d 100644 --- a/init_faf.lua +++ b/init_faf.lua @@ -1,4 +1,4 @@ --- START OF COPY -- +--#region START OF COPY -- in an ideal world this file would be loaded (using dofile) by the other -- initialisation files to prevent code duplication. However, as it stands @@ -36,40 +36,44 @@ if SetProcessPriority and GetProcessAffinityMask and SetProcessAffinityMask then -- priority values can be found at: -- - https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setpriorityclass - local success = SetProcessPriority(0x00000080) + local success = SetProcessPriority(0x00008000) if success then - LOG("Process - priority set to: 'high'") + LOG("Process - priority set to: 'above normal'") else LOG("Process - Failed to adjust process priority, this may impact your framerate") end - -- affinity values acts like a bit mask, we retrieve the mask and - -- shift it if we think there are sufficient computing units - local success, processAffinityMask, systemAffinityMask = GetProcessAffinityMask(); - if success then - -- system has 24 (logical) computing units or more, skip the first two computing units and all cores beyond the first 24. We need - -- to do this because of floating point imprecision - we simply can't deduct a few digits to prevent using the first two cores - if systemAffinityMask >= 16777215 then - processAffinityMask = 16777212 -- 2 ^ 24 - 3 - 1 - - -- system has 6 (logical) computing units or more, skip first two computing units - elseif (systemAffinityMask >= 63) then - processAffinityMask = systemAffinityMask - 3 -- (2 ^ 6 - 1) - 3 - end - - -- update the afinity mask - if processAffinityMask != systemAffinityMask then - local success = SetProcessAffinityMask(processAffinityMask); - if success then - LOG("Process - affinity set to: " .. tostring(processAffinityMask)) + local forceAffinity = ForceAffinity == "true" + if forceAffinity then + -- affinity values acts like a bit mask, we retrieve the mask and shift it if we think there are sufficient computing units + local success, processAffinityMask, systemAffinityMask = GetProcessAffinityMask(); + if success then + -- system has 24 (logical) computing units or more, skip the first two computing units and all cores beyond the first 24. We need + -- to do this because of floating point imprecision - we simply can't deduct a few digits to prevent using the first two cores + if systemAffinityMask >= 16777215 then + processAffinityMask = 16777212 -- 2 ^ 24 - 3 - 1 + + -- system has 6 (logical) computing units or more, skip first two computing units + elseif (systemAffinityMask >= 63) then + processAffinityMask = systemAffinityMask - 3 -- (2 ^ 6 - 1) - 3 + end + + -- update the afinity mask + if processAffinityMask != systemAffinityMask then + local success = SetProcessAffinityMask(processAffinityMask); + if success then + LOG("Process - affinity set to: " .. tostring(processAffinityMask)) + else + LOG("Process - Failed to adjust the process affinity, this may impact your framerate") + end else - LOG("Process - Failed to adjust the process affinity, this may impact your framerate") + LOG("Process - Failed to update the process affinity, this may impact your framerate") end else - LOG("Process - Failed to update the process affinity, this may impact your framerate") + LOG("Process - Failed to retrieve the process affinity, this may impact your framerate") end else - LOG("Process - Failed to retrieve the process affinity, this may impact your framerate") + LOG("Process - Process affinity adjustment is disabled in client settings, this may impact your framerate") end else LOG("Process - Failed to find process priority and affinity related functions, this may impact your framerate") @@ -78,6 +82,10 @@ end --#endregion -- upvalued performance +local dofile = dofile + +local StringFind = string.find +local StringGsub = string.gsub local StringSub = string.sub local StringLower = string.lower @@ -118,21 +126,6 @@ local function LowerHashTable(t) return o end -local function FindFilesWithExtension(dir, extension, prepend, files) - files = files or { } - - for k, file in IoDir(dir .. "/*") do - if not (file == '.' or file == '..') then - if StringSub(file, -3) == extension then - TableInsert(files, prepend .. "/" .. file) - end - FindFilesWithExtension(dir .. "/" .. file, extension, prepend .. "/" .. file, files) - end - end - - return files -end - -- mods that have been integrated, based on folder name local integratedMods = { } integratedMods["nvidia fix"] = true @@ -209,8 +202,8 @@ allowedAssetsScd = LowerHashTable(allowedAssetsScd) -- default wave banks to prevent collisions local soundsBlocked = { } -local sounds = FindFilesWithExtension(fa_path .. '/sounds', "xwb", "/sounds") -for k, v in sounds do +local faSounds = IoDir(fa_path .. '/sounds/*') +for k, v in faSounds do if v == '.' or v == '..' then continue end @@ -365,16 +358,16 @@ local function MountMapContent(dir) MountDirectory(dir .. "/" .. map .. '/movies', '/movies') end elseif folder == 'sounds' then - local banks = FindFilesWithExtension(dir .. '/' .. map .. "/sounds", "xwb", "/sounds") - -- find conflicting files local conflictingFiles = { } - for _, bank in banks do - local identifier = StringLower(bank) - if soundsBlocked[identifier] then - TableInsert(conflictingFiles, { file = bank, conflict = soundsBlocked[identifier] }) - else - soundsBlocked[identifier] = StringLower(map) + for _, file in IoDir(dir .. '/' .. map .. '/sounds/*') do + if not (file == '.' or file == '..') then + local identifier = StringLower(file) + if soundsBlocked[identifier] then + TableInsert(conflictingFiles, { file = file, conflict = soundsBlocked[identifier] }) + else + soundsBlocked[identifier] = StringLower(map) + end end end @@ -542,23 +535,23 @@ local function MountModContent(dir) -- if we found a directory named 'sounds' then we mount its content if folder == 'sounds' then - local banks = FindFilesWithExtension(dir .. '/' .. mod .. "/sounds", "xwb", "/sounds") - -- find conflicting files local conflictingFiles = { } - for _, bank in banks do - local identifier = StringLower(bank) - if soundsBlocked[identifier] then - TableInsert(conflictingFiles, { file = bank, conflict = soundsBlocked[identifier] }) - else - soundsBlocked[identifier] = StringLower(mod) + for _, file in IoDir(dir .. '/' .. mod .. '/sounds/*') do + if not (file == '.' or file == '..') then + local identifier = StringLower(file) + if soundsBlocked[identifier] then + TableInsert(conflictingFiles, { file = file, conflict = soundsBlocked[identifier] }) + else + soundsBlocked[identifier] = StringLower(mod) + end end end -- report them if they exist and do not mount if TableGetn(conflictingFiles) > 0 then LOG("Found conflicting sound banks for mod: '" .. mod .. "', cannot mount the sound bank(s):") - for _, v in conflictingFiles do + for k, v in conflictingFiles do LOG(" - Conflicting sound bank: '" .. v.file .. "' of mod '" .. mod .. "' is conflicting with a sound bank from: '" .. v.conflict .. "'" ) end -- else, mount folder @@ -593,7 +586,7 @@ local function LoadVaultContent(path) MountModContent(path .. '/mods') end --- END OF COPY -- +--#endregion END OF COPY -- minimum viable shader version - should be bumped to the next release version when we change the shaders local minimumShaderVersion = 3759 diff --git a/init_fafbeta.lua b/init_fafbeta.lua index 26d83cce288..9adcb4d2795 100644 --- a/init_fafbeta.lua +++ b/init_fafbeta.lua @@ -1,4 +1,4 @@ --- START OF COPY -- +--#region START OF COPY -- in an ideal world this file would be loaded (using dofile) by the other -- initialisation files to prevent code duplication. However, as it stands @@ -36,39 +36,44 @@ if SetProcessPriority and GetProcessAffinityMask and SetProcessAffinityMask then -- priority values can be found at: -- - https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setpriorityclass - local success = SetProcessPriority(0x00000080) + local success = SetProcessPriority(0x00008000) if success then - LOG("Process - priority set to: 'high'") + LOG("Process - priority set to: 'above normal'") else LOG("Process - Failed to adjust process priority, this may impact your framerate") end - -- affinity values acts like a bit mask, we retrieve the mask and shift it if we think there are sufficient computing units - local success, processAffinityMask, systemAffinityMask = GetProcessAffinityMask(); - if success then - -- system has 24 (logical) computing units or more, skip the first two computing units and all cores beyond the first 24. We need - -- to do this because of floating point imprecision - we simply can't deduct a few digits to prevent using the first two cores - if systemAffinityMask >= 16777215 then - processAffinityMask = 16777212 -- 2 ^ 24 - 3 - 1 - - -- system has 6 (logical) computing units or more, skip first two computing units - elseif (systemAffinityMask >= 63) then - processAffinityMask = systemAffinityMask - 3 -- (2 ^ 6 - 1) - 3 - end - - -- update the afinity mask - if processAffinityMask != systemAffinityMask then - local success = SetProcessAffinityMask(processAffinityMask); - if success then - LOG("Process - affinity set to: " .. tostring(processAffinityMask)) + local forceAffinity = ForceAffinity == "true" + if forceAffinity then + -- affinity values acts like a bit mask, we retrieve the mask and shift it if we think there are sufficient computing units + local success, processAffinityMask, systemAffinityMask = GetProcessAffinityMask(); + if success then + -- system has 24 (logical) computing units or more, skip the first two computing units and all cores beyond the first 24. We need + -- to do this because of floating point imprecision - we simply can't deduct a few digits to prevent using the first two cores + if systemAffinityMask >= 16777215 then + processAffinityMask = 16777212 -- 2 ^ 24 - 3 - 1 + + -- system has 6 (logical) computing units or more, skip first two computing units + elseif (systemAffinityMask >= 63) then + processAffinityMask = systemAffinityMask - 3 -- (2 ^ 6 - 1) - 3 + end + + -- update the afinity mask + if processAffinityMask != systemAffinityMask then + local success = SetProcessAffinityMask(processAffinityMask); + if success then + LOG("Process - affinity set to: " .. tostring(processAffinityMask)) + else + LOG("Process - Failed to adjust the process affinity, this may impact your framerate") + end else - LOG("Process - Failed to adjust the process affinity, this may impact your framerate") + LOG("Process - Failed to update the process affinity, this may impact your framerate") end else - LOG("Process - Failed to update the process affinity, this may impact your framerate") + LOG("Process - Failed to retrieve the process affinity, this may impact your framerate") end else - LOG("Process - Failed to retrieve the process affinity, this may impact your framerate") + LOG("Process - Process affinity adjustment is disabled in client settings, this may impact your framerate") end else LOG("Process - Failed to find process priority and affinity related functions, this may impact your framerate") @@ -77,6 +82,10 @@ end --#endregion -- upvalued performance +local dofile = dofile + +local StringFind = string.find +local StringGsub = string.gsub local StringSub = string.sub local StringLower = string.lower @@ -117,21 +126,6 @@ local function LowerHashTable(t) return o end -local function FindFilesWithExtension(dir, extension, prepend, files) - files = files or { } - - for k, file in IoDir(dir .. "/*") do - if not (file == '.' or file == '..') then - if StringSub(file, -3) == extension then - TableInsert(files, prepend .. "/" .. file) - end - FindFilesWithExtension(dir .. "/" .. file, extension, prepend .. "/" .. file, files) - end - end - - return files -end - -- mods that have been integrated, based on folder name local integratedMods = { } integratedMods["nvidia fix"] = true @@ -208,8 +202,8 @@ allowedAssetsScd = LowerHashTable(allowedAssetsScd) -- default wave banks to prevent collisions local soundsBlocked = { } -local sounds = FindFilesWithExtension(fa_path .. '/sounds', "xwb", "/sounds") -for k, v in sounds do +local faSounds = IoDir(fa_path .. '/sounds/*') +for k, v in faSounds do if v == '.' or v == '..' then continue end @@ -364,16 +358,16 @@ local function MountMapContent(dir) MountDirectory(dir .. "/" .. map .. '/movies', '/movies') end elseif folder == 'sounds' then - local banks = FindFilesWithExtension(dir .. '/' .. map .. "/sounds", "xwb", "/sounds") - -- find conflicting files local conflictingFiles = { } - for _, bank in banks do - local identifier = StringLower(bank) - if soundsBlocked[identifier] then - TableInsert(conflictingFiles, { file = bank, conflict = soundsBlocked[identifier] }) - else - soundsBlocked[identifier] = StringLower(map) + for _, file in IoDir(dir .. '/' .. map .. '/sounds/*') do + if not (file == '.' or file == '..') then + local identifier = StringLower(file) + if soundsBlocked[identifier] then + TableInsert(conflictingFiles, { file = file, conflict = soundsBlocked[identifier] }) + else + soundsBlocked[identifier] = StringLower(map) + end end end @@ -541,23 +535,23 @@ local function MountModContent(dir) -- if we found a directory named 'sounds' then we mount its content if folder == 'sounds' then - local banks = FindFilesWithExtension(dir .. '/' .. mod .. "/sounds", "xwb", "/sounds") - -- find conflicting files local conflictingFiles = { } - for _, bank in banks do - local identifier = StringLower(bank) - if soundsBlocked[identifier] then - TableInsert(conflictingFiles, { file = bank, conflict = soundsBlocked[identifier] }) - else - soundsBlocked[identifier] = StringLower(mod) + for _, file in IoDir(dir .. '/' .. mod .. '/sounds/*') do + if not (file == '.' or file == '..') then + local identifier = StringLower(file) + if soundsBlocked[identifier] then + TableInsert(conflictingFiles, { file = file, conflict = soundsBlocked[identifier] }) + else + soundsBlocked[identifier] = StringLower(mod) + end end end -- report them if they exist and do not mount if TableGetn(conflictingFiles) > 0 then LOG("Found conflicting sound banks for mod: '" .. mod .. "', cannot mount the sound bank(s):") - for _, v in conflictingFiles do + for k, v in conflictingFiles do LOG(" - Conflicting sound bank: '" .. v.file .. "' of mod '" .. mod .. "' is conflicting with a sound bank from: '" .. v.conflict .. "'" ) end -- else, mount folder @@ -592,7 +586,7 @@ local function LoadVaultContent(path) MountModContent(path .. '/mods') end --- END OF COPY -- +--#endregion END OF COPY -- Clears out the shader cache as it takes a release to reset the shaders local shaderCache = SHGetFolderPath('LOCAL_APPDATA') .. 'Gas Powered Games/Supreme Commander Forged Alliance/cache' diff --git a/init_fafdevelop.lua b/init_fafdevelop.lua index 3d4569c530f..2be761200ae 100644 --- a/init_fafdevelop.lua +++ b/init_fafdevelop.lua @@ -1,4 +1,4 @@ --- START OF COPY -- +--#region START OF COPY -- in an ideal world this file would be loaded (using dofile) by the other -- initialisation files to prevent code duplication. However, as it stands @@ -36,39 +36,44 @@ if SetProcessPriority and GetProcessAffinityMask and SetProcessAffinityMask then -- priority values can be found at: -- - https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setpriorityclass - local success = SetProcessPriority(0x00000080) + local success = SetProcessPriority(0x00008000) if success then - LOG("Process - priority set to: 'high'") + LOG("Process - priority set to: 'above normal'") else LOG("Process - Failed to adjust process priority, this may impact your framerate") end - -- affinity values acts like a bit mask, we retrieve the mask and shift it if we think there are sufficient computing units - local success, processAffinityMask, systemAffinityMask = GetProcessAffinityMask(); - if success then - -- system has 24 (logical) computing units or more, skip the first two computing units and all cores beyond the first 24. We need - -- to do this because of floating point imprecision - we simply can't deduct a few digits to prevent using the first two cores - if systemAffinityMask >= 16777215 then - processAffinityMask = 16777212 -- 2 ^ 24 - 3 - 1 - - -- system has 6 (logical) computing units or more, skip first two computing units - elseif (systemAffinityMask >= 63) then - processAffinityMask = systemAffinityMask - 3 -- (2 ^ 6 - 1) - 3 - end - - -- update the afinity mask - if processAffinityMask != systemAffinityMask then - local success = SetProcessAffinityMask(processAffinityMask); - if success then - LOG("Process - affinity set to: " .. tostring(processAffinityMask)) + local forceAffinity = ForceAffinity == "true" + if forceAffinity then + -- affinity values acts like a bit mask, we retrieve the mask and shift it if we think there are sufficient computing units + local success, processAffinityMask, systemAffinityMask = GetProcessAffinityMask(); + if success then + -- system has 24 (logical) computing units or more, skip the first two computing units and all cores beyond the first 24. We need + -- to do this because of floating point imprecision - we simply can't deduct a few digits to prevent using the first two cores + if systemAffinityMask >= 16777215 then + processAffinityMask = 16777212 -- 2 ^ 24 - 3 - 1 + + -- system has 6 (logical) computing units or more, skip first two computing units + elseif (systemAffinityMask >= 63) then + processAffinityMask = systemAffinityMask - 3 -- (2 ^ 6 - 1) - 3 + end + + -- update the afinity mask + if processAffinityMask != systemAffinityMask then + local success = SetProcessAffinityMask(processAffinityMask); + if success then + LOG("Process - affinity set to: " .. tostring(processAffinityMask)) + else + LOG("Process - Failed to adjust the process affinity, this may impact your framerate") + end else - LOG("Process - Failed to adjust the process affinity, this may impact your framerate") + LOG("Process - Failed to update the process affinity, this may impact your framerate") end else - LOG("Process - Failed to update the process affinity, this may impact your framerate") + LOG("Process - Failed to retrieve the process affinity, this may impact your framerate") end else - LOG("Process - Failed to retrieve the process affinity, this may impact your framerate") + LOG("Process - Process affinity adjustment is disabled in client settings, this may impact your framerate") end else LOG("Process - Failed to find process priority and affinity related functions, this may impact your framerate") @@ -77,6 +82,10 @@ end --#endregion -- upvalued performance +local dofile = dofile + +local StringFind = string.find +local StringGsub = string.gsub local StringSub = string.sub local StringLower = string.lower @@ -117,21 +126,6 @@ local function LowerHashTable(t) return o end -local function FindFilesWithExtension(dir, extension, prepend, files) - files = files or { } - - for k, file in IoDir(dir .. "/*") do - if not (file == '.' or file == '..') then - if StringSub(file, -3) == extension then - TableInsert(files, prepend .. "/" .. file) - end - FindFilesWithExtension(dir .. "/" .. file, extension, prepend .. "/" .. file, files) - end - end - - return files -end - -- mods that have been integrated, based on folder name local integratedMods = { } integratedMods["nvidia fix"] = true @@ -208,8 +202,8 @@ allowedAssetsScd = LowerHashTable(allowedAssetsScd) -- default wave banks to prevent collisions local soundsBlocked = { } -local sounds = FindFilesWithExtension(fa_path .. '/sounds', "xwb", "/sounds") -for k, v in sounds do +local faSounds = IoDir(fa_path .. '/sounds/*') +for k, v in faSounds do if v == '.' or v == '..' then continue end @@ -364,16 +358,16 @@ local function MountMapContent(dir) MountDirectory(dir .. "/" .. map .. '/movies', '/movies') end elseif folder == 'sounds' then - local banks = FindFilesWithExtension(dir .. '/' .. map .. "/sounds", "xwb", "/sounds") - -- find conflicting files local conflictingFiles = { } - for _, bank in banks do - local identifier = StringLower(bank) - if soundsBlocked[identifier] then - TableInsert(conflictingFiles, { file = bank, conflict = soundsBlocked[identifier] }) - else - soundsBlocked[identifier] = StringLower(map) + for _, file in IoDir(dir .. '/' .. map .. '/sounds/*') do + if not (file == '.' or file == '..') then + local identifier = StringLower(file) + if soundsBlocked[identifier] then + TableInsert(conflictingFiles, { file = file, conflict = soundsBlocked[identifier] }) + else + soundsBlocked[identifier] = StringLower(map) + end end end @@ -541,23 +535,23 @@ local function MountModContent(dir) -- if we found a directory named 'sounds' then we mount its content if folder == 'sounds' then - local banks = FindFilesWithExtension(dir .. '/' .. mod .. "/sounds", "xwb", "/sounds") - -- find conflicting files local conflictingFiles = { } - for _, bank in banks do - local identifier = StringLower(bank) - if soundsBlocked[identifier] then - TableInsert(conflictingFiles, { file = bank, conflict = soundsBlocked[identifier] }) - else - soundsBlocked[identifier] = StringLower(mod) + for _, file in IoDir(dir .. '/' .. mod .. '/sounds/*') do + if not (file == '.' or file == '..') then + local identifier = StringLower(file) + if soundsBlocked[identifier] then + TableInsert(conflictingFiles, { file = file, conflict = soundsBlocked[identifier] }) + else + soundsBlocked[identifier] = StringLower(mod) + end end end -- report them if they exist and do not mount if TableGetn(conflictingFiles) > 0 then LOG("Found conflicting sound banks for mod: '" .. mod .. "', cannot mount the sound bank(s):") - for _, v in conflictingFiles do + for k, v in conflictingFiles do LOG(" - Conflicting sound bank: '" .. v.file .. "' of mod '" .. mod .. "' is conflicting with a sound bank from: '" .. v.conflict .. "'" ) end -- else, mount folder @@ -592,7 +586,7 @@ local function LoadVaultContent(path) MountModContent(path .. '/mods') end --- END OF COPY -- +--#endregion END OF COPY -- Clears out the shader cache as it takes a release to reset the shaders local shaderCache = SHGetFolderPath('LOCAL_APPDATA') .. 'Gas Powered Games/Supreme Commander Forged Alliance/cache' diff --git a/init_shared.lua b/init_shared.lua index 00b3551c078..6bf2096c725 100644 --- a/init_shared.lua +++ b/init_shared.lua @@ -1,4 +1,4 @@ --- START OF COPY -- +--#region START OF COPY -- in an ideal world this file would be loaded (using dofile) by the other -- initialisation files to prevent code duplication. However, as it stands @@ -36,39 +36,44 @@ if SetProcessPriority and GetProcessAffinityMask and SetProcessAffinityMask then -- priority values can be found at: -- - https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setpriorityclass - local success = SetProcessPriority(0x00000080) + local success = SetProcessPriority(0x00008000) if success then - LOG("Process - priority set to: 'high'") + LOG("Process - priority set to: 'above normal'") else LOG("Process - Failed to adjust process priority, this may impact your framerate") end - -- affinity values acts like a bit mask, we retrieve the mask and shift it if we think there are sufficient computing units - local success, processAffinityMask, systemAffinityMask = GetProcessAffinityMask(); - if success then - -- system has 24 (logical) computing units or more, skip the first two computing units and all cores beyond the first 24. We need - -- to do this because of floating point imprecision - we simply can't deduct a few digits to prevent using the first two cores - if systemAffinityMask >= 16777215 then - processAffinityMask = 16777212 -- 2 ^ 24 - 3 - 1 - - -- system has 6 (logical) computing units or more, skip first two computing units - elseif (systemAffinityMask >= 63) then - processAffinityMask = systemAffinityMask - 3 -- (2 ^ 6 - 1) - 3 - end - - -- update the afinity mask - if processAffinityMask != systemAffinityMask then - local success = SetProcessAffinityMask(processAffinityMask); - if success then - LOG("Process - affinity set to: " .. tostring(processAffinityMask)) + local forceAffinity = ForceAffinity == "true" + if forceAffinity then + -- affinity values acts like a bit mask, we retrieve the mask and shift it if we think there are sufficient computing units + local success, processAffinityMask, systemAffinityMask = GetProcessAffinityMask(); + if success then + -- system has 24 (logical) computing units or more, skip the first two computing units and all cores beyond the first 24. We need + -- to do this because of floating point imprecision - we simply can't deduct a few digits to prevent using the first two cores + if systemAffinityMask >= 16777215 then + processAffinityMask = 16777212 -- 2 ^ 24 - 3 - 1 + + -- system has 6 (logical) computing units or more, skip first two computing units + elseif (systemAffinityMask >= 63) then + processAffinityMask = systemAffinityMask - 3 -- (2 ^ 6 - 1) - 3 + end + + -- update the afinity mask + if processAffinityMask != systemAffinityMask then + local success = SetProcessAffinityMask(processAffinityMask); + if success then + LOG("Process - affinity set to: " .. tostring(processAffinityMask)) + else + LOG("Process - Failed to adjust the process affinity, this may impact your framerate") + end else - LOG("Process - Failed to adjust the process affinity, this may impact your framerate") + LOG("Process - Failed to update the process affinity, this may impact your framerate") end else - LOG("Process - Failed to update the process affinity, this may impact your framerate") + LOG("Process - Failed to retrieve the process affinity, this may impact your framerate") end else - LOG("Process - Failed to retrieve the process affinity, this may impact your framerate") + LOG("Process - Process affinity adjustment is disabled in client settings, this may impact your framerate") end else LOG("Process - Failed to find process priority and affinity related functions, this may impact your framerate") @@ -77,6 +82,10 @@ end --#endregion -- upvalued performance +local dofile = dofile + +local StringFind = string.find +local StringGsub = string.gsub local StringSub = string.sub local StringLower = string.lower @@ -117,21 +126,6 @@ local function LowerHashTable(t) return o end -local function FindFilesWithExtension(dir, extension, prepend, files) - files = files or { } - - for k, file in IoDir(dir .. "/*") do - if not (file == '.' or file == '..') then - if StringSub(file, -3) == extension then - TableInsert(files, prepend .. "/" .. file) - end - FindFilesWithExtension(dir .. "/" .. file, extension, prepend .. "/" .. file, files) - end - end - - return files -end - -- mods that have been integrated, based on folder name local integratedMods = { } integratedMods["nvidia fix"] = true @@ -208,8 +202,8 @@ allowedAssetsScd = LowerHashTable(allowedAssetsScd) -- default wave banks to prevent collisions local soundsBlocked = { } -local sounds = FindFilesWithExtension(fa_path .. '/sounds', "xwb", "/sounds") -for k, v in sounds do +local faSounds = IoDir(fa_path .. '/sounds/*') +for k, v in faSounds do if v == '.' or v == '..' then continue end @@ -364,19 +358,19 @@ local function MountMapContent(dir) MountDirectory(dir .. "/" .. map .. '/movies', '/movies') end elseif folder == 'sounds' then - local banks = FindFilesWithExtension(dir .. '/' .. map .. "/sounds", "xwb", "/sounds") - -- find conflicting files local conflictingFiles = { } - for _, bank in banks do - local identifier = StringLower(bank) - if soundsBlocked[identifier] then - TableInsert(conflictingFiles, { file = bank, conflict = soundsBlocked[identifier] }) - else - soundsBlocked[identifier] = StringLower(map) + for _, file in IoDir(dir .. '/' .. map .. '/sounds/*') do + if not (file == '.' or file == '..') then + local identifier = StringLower(file) + if soundsBlocked[identifier] then + TableInsert(conflictingFiles, { file = file, conflict = soundsBlocked[identifier] }) + else + soundsBlocked[identifier] = StringLower(map) + end end end - + -- report them if they exist and do not mount if TableGetn(conflictingFiles) > 0 then LOG("Found conflicting sound banks for map: '" .. map .. "', cannot mount the sound bank(s):") @@ -538,26 +532,26 @@ local function MountModContent(dir) -- look at each directory inside this mod for _, folder in IoDir(dir .. '/' .. mod .. '/*') do - + -- if we found a directory named 'sounds' then we mount its content if folder == 'sounds' then - local banks = FindFilesWithExtension(dir .. '/' .. mod .. "/sounds", "xwb", "/sounds") - -- find conflicting files local conflictingFiles = { } - for _, bank in banks do - local identifier = StringLower(bank) - if soundsBlocked[identifier] then - TableInsert(conflictingFiles, { file = bank, conflict = soundsBlocked[identifier] }) - else - soundsBlocked[identifier] = StringLower(mod) + for _, file in IoDir(dir .. '/' .. mod .. '/sounds/*') do + if not (file == '.' or file == '..') then + local identifier = StringLower(file) + if soundsBlocked[identifier] then + TableInsert(conflictingFiles, { file = file, conflict = soundsBlocked[identifier] }) + else + soundsBlocked[identifier] = StringLower(mod) + end end end - + -- report them if they exist and do not mount if TableGetn(conflictingFiles) > 0 then LOG("Found conflicting sound banks for mod: '" .. mod .. "', cannot mount the sound bank(s):") - for _, v in conflictingFiles do + for k, v in conflictingFiles do LOG(" - Conflicting sound bank: '" .. v.file .. "' of mod '" .. mod .. "' is conflicting with a sound bank from: '" .. v.conflict .. "'" ) end -- else, mount folder @@ -592,7 +586,7 @@ local function LoadVaultContent(path) MountModContent(path .. '/mods') end --- END OF COPY -- +--#endregion END OF COPY -- -- minimum viable shader version - should be bumped to the next release version when we change the shaders -- local minimumShaderVersion = 3745 diff --git a/setup/bin/init_local_development.lua b/setup/bin/init_local_development.lua index 80f682862e6..95dee00e2ca 100644 --- a/setup/bin/init_local_development.lua +++ b/setup/bin/init_local_development.lua @@ -3,7 +3,7 @@ -- for escaping characters and you can just use `/` in your path instead. local locationOfRepository = 'your-fa-repository-location' --- START OF COPY -- +--#region START OF COPY -- in an ideal world this file would be loaded (using dofile) by the other -- initialisation files to prevent code duplication. However, as it stands @@ -41,32 +41,44 @@ if SetProcessPriority and GetProcessAffinityMask and SetProcessAffinityMask then -- priority values can be found at: -- - https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setpriorityclass - local success = SetProcessPriority(0x00000080) + local success = SetProcessPriority(0x00008000) if success then - LOG("Process - priority set to: 'high'") + LOG("Process - priority set to: 'above normal'") else LOG("Process - Failed to adjust process priority, this may impact your framerate") end - -- affinity values acts like a bit mask, we retrieve the mask and shift it if we think there are sufficient computing units - local success, processAffinityMask, systemAffinityMask = GetProcessAffinityMask(); - if success then - - -- system has 6 (logical) threads or more, skip first two computing units - if systemAffinityMask >= 63 then - processAffinityMask = systemAffinityMask & (systemAffinityMask << 2) - end - - if processAffinityMask != systemAffinityMask then - local success = SetProcessAffinityMask(processAffinityMask); - if success then - LOG("Process - affinity set to: " .. tostring(processAffinityMask)) + local forceAffinity = ForceAffinity == "true" + if forceAffinity then + -- affinity values acts like a bit mask, we retrieve the mask and shift it if we think there are sufficient computing units + local success, processAffinityMask, systemAffinityMask = GetProcessAffinityMask(); + if success then + -- system has 24 (logical) computing units or more, skip the first two computing units and all cores beyond the first 24. We need + -- to do this because of floating point imprecision - we simply can't deduct a few digits to prevent using the first two cores + if systemAffinityMask >= 16777215 then + processAffinityMask = 16777212 -- 2 ^ 24 - 3 - 1 + + -- system has 6 (logical) computing units or more, skip first two computing units + elseif (systemAffinityMask >= 63) then + processAffinityMask = systemAffinityMask - 3 -- (2 ^ 6 - 1) - 3 + end + + -- update the afinity mask + if processAffinityMask != systemAffinityMask then + local success = SetProcessAffinityMask(processAffinityMask); + if success then + LOG("Process - affinity set to: " .. tostring(processAffinityMask)) + else + LOG("Process - Failed to adjust the process affinity, this may impact your framerate") + end else - LOG("Process - Failed to adjust the process affinity, this may impact your framerate") + LOG("Process - Failed to update the process affinity, this may impact your framerate") end + else + LOG("Process - Failed to retrieve the process affinity, this may impact your framerate") end else - LOG("Process - Failed to retrieve the process affinity, this may impact your framerate") + LOG("Process - Process affinity adjustment is disabled in client settings, this may impact your framerate") end else LOG("Process - Failed to find process priority and affinity related functions, this may impact your framerate") @@ -125,7 +137,6 @@ integratedMods["nvidia fix"] = true integratedMods = LowerHashTable(integratedMods) - -- take care that the folder name is properly spelled and Capitalized -- deprecatedMods["Mod Folder Name"] = deprecation status -- true: deprecated regardless of mod version @@ -135,11 +146,12 @@ local deprecatedMods = {} -- mods that are deprecated, based on mod folder name deprecatedMods["simspeed++"] = true deprecatedMods["#quality of performance 2022"] = true +deprecatedMods["em"] = "11" -- as per #4119 the control groups (called selection sets in code) are completely overhauled and extended feature-wise, -- because of that these mods are no longer viable / broken / integrated -deprecatedMods["group_split"] = true -deprecatedMods["Control Group Zoom Mod"] = true +deprecatedMods["group_split"] = "0.1" +deprecatedMods["Control Group Zoom Mod"] = "2" deprecatedMods["additionalControlGroupStuff"] = true -- as per #4124 the cursor and command interactions are complete overhauled and extended feature-wise, @@ -148,16 +160,17 @@ deprecatedMods["additionalCameraStuff"] = "3" deprecatedMods["RUI"] = "1.0" -- as per #4232 the reclaim view is completely overhauled -deprecatedMods["Advanced Reclaim&Selection Info"] = true -deprecatedMods["AdvancedReclaimInfo"] = true -deprecatedMods["BetterReclaimView"] = true -deprecatedMods["disableReclaimUI"] = true -deprecatedMods["DynamicReclaimGrouping"] = true -deprecatedMods["EzR"] = true -deprecatedMods["OnScreenReclaimCounter"] = true -deprecatedMods["ORV"] = true -deprecatedMods["SmartReclaimSupport"] = true +deprecatedMods["Advanced Reclaim&Selection Info"] = "1" +deprecatedMods["AdvancedReclaimInfo"] = "1" +deprecatedMods["BetterReclaimView"] = "2" +deprecatedMods["disableReclaimUI"] = "2" +deprecatedMods["DynamicReclaimGrouping"] = "1" +deprecatedMods["EzReclaim"] = "1.0" +deprecatedMods["OnScreenReclaimCounter"] = "8" +deprecatedMods["ORV"] = "1" +deprecatedMods["SmartReclaimSupport"] = "3" deprecatedMods["DrimsUIPack"] = "3" +deprecatedMods["Rheclaim"] = "2" -- convert all mod folder name keys to lower case to prevent typos deprecatedMods = LowerHashTable(deprecatedMods) @@ -182,6 +195,9 @@ allowedAssetsScd["loc_fr.scd"] = true allowedAssetsScd["loc_it.scd"] = true allowedAssetsScd["loc_de.scd"] = true allowedAssetsScd["loc_ru.scd"] = true +allowedAssetsScd["loc_cz.scd"] = true +allowedAssetsScd["loc_cn.scd"] = true +allowedAssetsScd["loc_pl.scd"] = true allowedAssetsScd["env.scd"] = true allowedAssetsScd["effects.scd"] = true allowedAssetsScd["editor.scd"] = false -- Unused @@ -189,13 +205,6 @@ allowedAssetsScd["ambience.scd"] = false -- Empty allowedAssetsScd["sc_music.scd"] = true allowedAssetsScd = LowerHashTable(allowedAssetsScd) --- typical backwards compatible packages -local allowedAssetsNxt = { } -allowedAssetsNxt["kyros.nxt"] = true -allowedAssetsNxt["advanced strategic icons.nxt"] = true -allowedAssetsNxt["advanced_strategic_icons.nxt"] = true -allowedAssetsNxt = LowerHashTable(allowedAssetsNxt) - -- default wave banks to prevent collisions local soundsBlocked = { } local faSounds = IoDir(fa_path .. '/sounds/*') @@ -235,7 +244,7 @@ local function MountAllowedContent(dir, pattern, allowedAssets) for _,entry in IoDir(dir .. pattern) do if entry != '.' and entry != '..' then local mp = StringLower(entry) - if allowedAssets[mp] then + if (not allowedAssets) or allowedAssets[mp] then LOG("mounting content: " .. entry) MountDirectory(dir .. "/" .. entry, '/') end @@ -427,7 +436,7 @@ end ---@param modinfo FileName ---@return string|nil | false local function GetModVersion(modinfo) - local handle = io.open(modinfo, 'r') + local handle = io.open(modinfo, 'rb') if not handle then return false -- can't read file end @@ -582,7 +591,7 @@ local function LoadVaultContent(path) MountModContent(path .. '/mods') end --- END OF COPY -- +--#endregion END OF COPY -- minimum viable shader version - should be bumped to the next release version when we change the shaders local minimumShaderVersion = 3729