@@ -887,18 +887,63 @@ function pluginSdkExampleProject(projectDir, projectName, projectType, game2, ga
887887 }
888888end
889889
890- function generateNewPluginSource (projectDir , projectName , projectType , game2 , game3 , gameVc , gameSa , game4 , game3Unreal , gameVcUnreal , gameSaUnreal )
891- isTrilogy = false -- any of classic 3/VC/SA
892- if game3 or gameVc or gameSa then isTrilogy = true end
893- isTrilogyOnly = true -- only classic 3/VC/SA
894- if not isTrilogy or game2 or game4 or game3Unreal or gameVcUnreal or gameSaUnreal then isTrilogyOnly = false end
890+ function getSdkVerInfo ()
891+ local verNum = nil
892+ local verNumPrefix = " #define PLUGIN_SDK_VERSION "
893+
894+ local verDate = nil
895+ local verDatePrefix = " #define PLUGIN_SDK_DATE "
895896
896- isUnreal = false -- any of Definitive Edition
897- if game3Unreal or gameVcUnreal or gameSaUnreal then isUnreal = true end
898- isUnrealOnly = true -- only classic 3/VC/SA
899- if not isUnreal or game2 or game3 or gameVc or gameSa or game4 then isUnrealOnly = false end
897+ local file = io.open (path .join (sdkdir , " shared\\ plugin.h" ), " r" )
898+ if file then
899+ for line in file :lines () do
900+ if line :sub (1 , # verNumPrefix ) == verNumPrefix then
901+ verNum = line :sub (# verNumPrefix + 1 )
902+ end
903+
904+ if line :sub (1 , # verDatePrefix ) == verDatePrefix then
905+ verDate = line :sub (# verDatePrefix + 1 )
906+ end
907+ end
908+
909+ file :close ()
910+ end
911+
912+ local verTxt = nil
913+
914+ if verNum ~= nil then
915+ verTxt = " version " .. verNum
916+ end
917+
918+ if verDate ~= nil then
919+ if verTxt ~= nil then
920+ verTxt = verTxt .. " "
921+ end
922+
923+ verTxt = verTxt .. " from " .. verDate
924+ end
925+
926+ return verTxt
927+ end
900928
901- platformCount = 0
929+ function generateNewPluginSource (projectDir , projectName , projectType , game2 , game3 , gameVc , gameSa , game4 , game3Unreal , gameVcUnreal , gameSaUnreal )
930+ -- classis trilogy helper variables
931+ local trilogyDefs = {}
932+ if game3 then table.insert (trilogyDefs , " GTA3" ) end
933+ if gameVc then table.insert (trilogyDefs , " GTAVC" ) end
934+ if gameSa then table.insert (trilogyDefs , " GTASA" ) end
935+ local isTrilogy = (# trilogyDefs > 0 ) -- any of classic 3/VC/SA
936+ local isTrilogyOnly = isTrilogy and not (game2 or game4 or game3Unreal or gameVcUnreal or gameSaUnreal ) -- only classic 3/VC/SA
937+
938+ -- Unreal trilogy helper variables
939+ local unrealDefs = {}
940+ if game3Unreal then table.insert (unrealDefs , " GTA3_UNREAL" ) end
941+ if gameVcUnreal then table.insert (unrealDefs , " GTAVC_UNREAL" ) end
942+ if gameSaUnreal then table.insert (unrealDefs , " GTASA_UNREAL" ) end
943+ local isUnreal = (# unrealDefs > 0 ) -- any of Unreal 3/VC/SA
944+ local isUnrealOnly = isUnreal and not (game2 or game3 or gameVc or gameSa or game4 ) -- only Unreal 3/VC/SA
945+
946+ local platformCount = 0
902947 if game2 then platformCount = platformCount + 1 end
903948 if game3 or gameVc then platformCount = platformCount + 1 end -- 3 and VC are almost identical
904949 if gameSa then platformCount = platformCount + 1 end
@@ -907,23 +952,28 @@ function generateNewPluginSource(projectDir, projectName, projectType, game2, ga
907952 if gameVcUnreal then platformCount = platformCount + 1 end
908953 if gameSaUnreal then platformCount = platformCount + 1 end
909954
910- projectDir = path .normalize (projectDir )
911- sourceDir = path .join (projectDir , " source" )
955+ local projectDir = path .normalize (projectDir )
956+ local sourceDir = path .join (projectDir , " source" )
912957 os.execute (' if not exist "' .. sourceDir .. ' " (mkdir "' .. sourceDir .. ' ")' )
913958
914959 -- generate Main.cpp
915- main = io.open (path .join (sourceDir , " Main.cpp" ), ' w' )
960+ local main = io.open (path .join (sourceDir , " Main.cpp" ), ' w' )
916961
917962 -- includes
918- main :write ([[ #include <plugin.h>]] , ' \n ' )
963+ main :write ([[ #include <plugin.h>]] )
964+ local verStr = getSdkVerInfo ()
965+ if verStr ~= nil then
966+ main :write (' // Plugin-SDK ' , verStr )
967+ end
968+ main :write (' \n ' )
919969
920970 if game2 then
921971 if platformCount > 1 then main :write ([[ #if defined GTA2]] , ' \n ' ) end
922972 main :write ([[ #include <CHud.h>]] , ' \n ' )
923973 if platformCount > 1 then main :write ([[ #endif]] , ' \n ' ) end
924974 end
925975 if isTrilogy then
926- if not isTrilogyOnly then main :write ([[ #if defined GTA3 || defined GTAVC || defined GTASA ]] , ' \n ' ) end
976+ if not isTrilogyOnly then main :write ([[ #if defined ]] , table.concat ( trilogyDefs , " || defined " ) , ' \n ' ) end
927977 main :write ([[ #include <CMessages.h>]] , ' \n ' )
928978 if not isTrilogyOnly then main :write ([[ #endif]] , ' \n ' ) end
929979 end
@@ -933,7 +983,7 @@ function generateNewPluginSource(projectDir, projectName, projectType, game2, ga
933983 if platformCount > 1 then main :write ([[ #endif]] , ' \n ' ) end
934984 end
935985 if isUnreal then
936- if not isUnrealOnly then main :write ([[ #if defined GTA3_UNREAL || defined GTAVC_UNREAL || defined GTASA_UNREAL ]] , ' \n ' ) end
986+ if not isUnrealOnly then main :write ([[ #if defined ]] , table.concat ( unrealDefs , " || defined " ) , ' \n ' ) end
937987 -- main:write([[#include <CHud.h>]], '\n') -- TODO: DE trilogy include
938988 if not isUnrealOnly then main :write ([[ #endif]] , ' \n ' ) end
939989 end
@@ -956,8 +1006,8 @@ struct Main
9561006 {
9571007 m_frame++;
9581008
959- static wchar_t msg[255];
960- swprintf_s (msg, L "Hello world! Frame %d", m_frame);
1009+ static char msg[255];
1010+ sprintf_s (msg, "Hello world! Frame %d", m_frame);
9611011
9621012]] )
9631013
@@ -970,7 +1020,7 @@ struct Main
9701020
9711021 -- message printing classic trilogy
9721022 if isTrilogy then
973- if not isTrilogyOnly then main :write ([[ #if defined GTA3 or defined GTAVC or defined GTASA ]] , ' \n ' ) end
1023+ if not isTrilogyOnly then main :write ([[ #if defined ]] , table.concat ( trilogyDefs , " || defined " ) , ' \n ' ) end
9741024 main :write ([[ CMessages::AddMessageJumpQ(msg, 500, 0);]] , ' \n ' )
9751025 if not isTrilogyOnly then main :write ([[ #endif]] , ' \n ' ) end
9761026 end
@@ -984,7 +1034,7 @@ struct Main
9841034
9851035 -- message printing Definitive Edition trilogy
9861036 if isUnreal then
987- if not isUnrealOnly then main :write ([[ #if defined GTA3_UNREAL or defined GTAVC_UNREAL or defined GTASA_UNREAL ]] , ' \n ' ) end
1037+ if not isUnrealOnly then main :write ([[ #if defined ]] , table.concat ( unrealDefs , " || defined " ) , ' \n ' ) end
9881038 -- main:write([[ CMessages::AddMessageJumpQ(msg, 500, 0);]], '\n') TODO: DE trilogy message printing
9891039 if not isUnrealOnly then main :write ([[ #endif]] , ' \n ' ) end
9901040 end
0 commit comments