main.c 117 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477
  1. /*============================================================================
  2. MAIN.C: Main Windows interface for Homeworld game code, including message
  3. handling and window set-up.
  4. Created June 1997 by Luke Moloney.
  5. ============================================================================*/
  6. #define WIN32_LEAN_AND_MEAN
  7. #include <windows.h>
  8. #include <winreg.h>
  9. #include "leakyfaucet.h"
  10. #include "regkey.h"
  11. // guess what? The game code defines HKEY to 'H' which messes up the registry code. So the
  12. // registry code gets to go here
  13. int RegisterCommandLine(char *commandLine)
  14. {
  15. HKEY key;
  16. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, BASEKEYNAME,
  17. 0, KEY_SET_VALUE, &key) != ERROR_SUCCESS)
  18. {
  19. return FALSE;
  20. }
  21. if ((commandLine == NULL) || (commandLine[0] == 0))
  22. {
  23. if (RegSetValueEx(key, "CmdLine", 0, REG_SZ, "", 1) != ERROR_SUCCESS)
  24. {
  25. RegCloseKey(key);
  26. return FALSE;
  27. }
  28. }
  29. else
  30. {
  31. if (RegSetValueEx(key, "CmdLine", 0, REG_SZ, (BYTE *)commandLine, strlen(commandLine)+1) != ERROR_SUCCESS)
  32. {
  33. RegCloseKey(key);
  34. return FALSE;
  35. }
  36. }
  37. RegCloseKey(key);
  38. return TRUE;
  39. }
  40. #include <stdlib.h>
  41. #include <stdio.h>
  42. #include <string.h>
  43. #include <time.h>
  44. #include "glinc.h"
  45. #include "resource.h"
  46. #include "utility.h"
  47. #include "key.h"
  48. #include "mouse.h"
  49. #include "debugwnd.h"
  50. #include "debug.h"
  51. #include "memory.h"
  52. #include "file.h"
  53. #include "camera.h"
  54. #include "task.h"
  55. #include "mainrgn.h"
  56. #include "main.h"
  57. #include "globals.h"
  58. #include "soundevent.h"
  59. #include "soundlow.h"
  60. #include "nis.h"
  61. #include "aiplayer.h"
  62. #include "fontreg.h"
  63. #include "fereg.h"
  64. #include "demo.h"
  65. #include "researchapi.h"
  66. #include "objtypes.h"
  67. #include "formation.h"
  68. #include "glcaps.h"
  69. #include "mainswitches.h"
  70. #include "tactics.h"
  71. #include "render.h"
  72. #include "autolod.h"
  73. #include "captaincy.h"
  74. #include "options.h"
  75. #include "sensors.h"
  76. #include "btg.h"
  77. #include "researchgui.h"
  78. #include "consmgr.h"
  79. #include "rinit.h"
  80. #include "avi.h"
  81. #include "bink.h"
  82. #include "titannet.h"
  83. #include "multiplayergame.h"
  84. #include "subtitle.h"
  85. #include "dxdraw.h"
  86. #include "launchmgr.h"
  87. #include "colpick.h"
  88. #include "horserace.h"
  89. #include "glcompat.h"
  90. #include "sstglide.h"
  91. #include "particle.h"
  92. #include "commandlayer.h"
  93. #include "key.h"
  94. #include "strings.h"
  95. #include "zmouse.h"
  96. #ifndef WM_MOUSEWHEEL
  97. #define WM_MOUSEWHEEL WM_MOUSELAST+1
  98. #endif
  99. UINT uMSH_MOUSEWHEEL = 0;
  100. /*=============================================================================
  101. Data:
  102. =============================================================================*/
  103. extern udword gDevcaps, gDevcaps2;
  104. bool mainSafeGL = FALSE;
  105. udword* devTable = NULL;
  106. sdword devTableLength = 0;
  107. long FAR PASCAL WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  108. static bool mainActuallyQuit = TRUE;
  109. static DWORD style;
  110. bool selectedRES = FALSE;
  111. bool selectedDEVICE = FALSE;
  112. bool selectedGL = FALSE;
  113. sdword mainReinitRenderer = 0;
  114. static bool reinitInProgress = FALSE;
  115. bool bMustFree = TRUE;
  116. bool mainPlayAVIs;
  117. bool windowNeedsDeleting = FALSE;
  118. bool mainNoPerspective = FALSE;
  119. bool systemActive = FALSE; //active flag for the program
  120. static char classTitle[] = "Homeworld"; //name of registered class
  121. static char windowTitle[] = "Homeworld";//name of window
  122. //error strings
  123. char ersWindowInit[] = "Error creating window";
  124. //screen width, height
  125. sdword MAIN_WindowWidth = 640;
  126. sdword MAIN_WindowHeight = 480;
  127. sdword MAIN_WindowDepth = 16;
  128. sdword mainWidthAdd = 0;
  129. sdword mainHeightAdd = 0;
  130. sdword mainWindowWidth = 640;
  131. sdword mainWindowHeight = 480;
  132. sdword mainWindowDepth = 16;
  133. extern bool CompareBigfiles;
  134. extern bool IgnoreBigfiles;
  135. extern bool LogFileLoads;
  136. //command-line switches and parameters
  137. bool mainNoDrawPixels = FALSE;
  138. bool mainOutputCRC = FALSE;
  139. bool mainNoPalettes = FALSE;
  140. bool mainSoftwareDirectDraw = TRUE;
  141. bool mainDirectDraw = TRUE;
  142. bool mainRasterSkip = FALSE;
  143. bool mainDoubleIsTriple = FALSE;
  144. bool mainFastFrontend = TRUE;
  145. bool mainForceSoftware = FALSE;
  146. bool mainAutoRenderer = TRUE;
  147. bool mainForceKatmai = FALSE;
  148. bool mainAllowKatmai = FALSE;
  149. bool mainAllow3DNow = FALSE;
  150. bool enableAVI = TRUE;
  151. bool mainAllowPacking = TRUE;
  152. bool mainOnlyPacking = FALSE;
  153. bool gShowDamage = TRUE;
  154. bool DebugWindow = FALSE;
  155. sdword MemoryHeapSize = MEM_HeapSizeDefault;
  156. bool FilePathPrepended = FALSE;
  157. bool CDROMPathPrepended = FALSE;
  158. #if MAIN_MOUSE_FREE
  159. bool startupClipMouse = TRUE;
  160. #endif
  161. bool mouseClipped = FALSE;
  162. sdword showBackgrounds = TRUE;
  163. bool showBorder = TRUE;
  164. sdword enableTextures = TRUE;
  165. sdword enableSmoothing = TRUE;
  166. sdword enableStipple = FALSE;
  167. sdword enableTrails = TRUE;
  168. #if TR_NIL_TEXTURE
  169. bool GLOBAL_NO_TEXTURES = FALSE;
  170. #endif
  171. bool fullScreen = TRUE;
  172. bool slowBlits = FALSE;
  173. #if RND_VISUALIZATION
  174. bool dockLines = FALSE;
  175. bool gunLines = FALSE;
  176. bool8 RENDER_BOXES;
  177. bool8 RENDER_LIGHTLINES;
  178. #endif
  179. bool enableSFX = TRUE;
  180. bool enableSpeech = TRUE;
  181. bool reverseStereo = FALSE;
  182. bool useWaveout = FALSE;
  183. bool useDSound = FALSE;
  184. bool coopDSound = FALSE;
  185. bool accelFirst = FALSE;
  186. char mainDeviceToSelect[128] = "";
  187. char mainGLToSelect[512] = "";
  188. char mainD3DToSelect[128] = "";
  189. char deviceToSelect[128] = "";
  190. char glToSelect[512] = "rgl.dll";
  191. bool8 RENDER_BOXES = FALSE;
  192. bool8 RENDER_LIGHTLINES = FALSE;
  193. #if CL_TEXTFEEDBACK
  194. bool enableTextFeedback = FALSE;
  195. #endif
  196. #if FE_TEXTURES_DISABLABLE
  197. bool fetEnableTextures = TRUE;
  198. #endif
  199. bool noDefaultComputerPlayer = FALSE;
  200. bool8 ComputerPlayerEnabled[MAX_MULTIPLAYER_PLAYERS] = { FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE };
  201. //udword ComputerPlayerLevel[MAX_MULTIPLAYER_PLAYERS] = {2,2,2,2,2,2,2,2};
  202. bool gatherStats = FALSE;
  203. bool showStatsFight = FALSE;
  204. udword showStatsFightI = 0;
  205. udword showStatsFightJ = 0;
  206. bool showStatsFancyFight = FALSE;
  207. char showStatsFancyFightScriptFile[50];
  208. bool SecretWON = FALSE;
  209. bool forceLAN = FALSE;
  210. bool ShortCircuitWON = FALSE;
  211. #if DBW_TO_FILE
  212. bool debugToFile = FALSE;
  213. #endif
  214. bool debugPacketRecord = FALSE;
  215. bool recordPackets = FALSE;
  216. bool playPackets = FALSE;
  217. bool recordplayPacketsInGame = FALSE;
  218. bool recordFakeSendPackets = FALSE;
  219. char recordPacketFileName[MAX_RECORDPACKETFILENAME_STRLEN];
  220. char recordPacketSaveFileName[MAX_RECORDPACKETFILENAME_STRLEN];
  221. bool autoSaveDebug = FALSE;
  222. #ifdef DEBUG_TACTICS
  223. bool tacticsOn = TRUE;
  224. #endif
  225. bool noRetreat = FALSE;
  226. bool noPauseAltTab = FALSE;
  227. bool noMinimizeAltTab = FALSE;
  228. //options altered by a password function:
  229. bool mainSinglePlayerEnabled = FALSE;
  230. bool mainEnableSpecialMissions = FALSE;
  231. bool mainScreenShotsEnabled = FALSE;
  232. bool mainCDCheckEnabled = TRUE;
  233. //char versionString[MAX_VERSION_STRING_LEN] = "M23bCGWRC1";
  234. //char versionString[MAX_VERSION_STRING_LEN] = "M23dFinalRC1";
  235. //char versionString[MAX_VERSION_STRING_LEN] = "M24aFinalRC3";
  236. //char versionString[MAX_VERSION_STRING_LEN] = "M24bPublicBeta2";
  237. //char versionString[MAX_VERSION_STRING_LEN] = "M24cFinalRC4";
  238. //char versionString[MAX_VERSION_STRING_LEN] = "M24ePublicBeta2";
  239. //char versionString[MAX_VERSION_STRING_LEN] = "M24fFinalRC5";
  240. #if defined(Downloadable)
  241. //char networkVersion[] = "DownloadableRC1";
  242. char networkVersion[MAX_NETWORKVERSION_STRING_LEN] = "DLD_05";
  243. #elif defined(CGW)
  244. char networkVersion[MAX_NETWORKVERSION_STRING_LEN] = "CGWtronRC1";
  245. #elif defined(OEM)
  246. char networkVersion[MAX_NETWORKVERSION_STRING_LEN] = "OEMV1";
  247. #else
  248. char networkVersion[MAX_NETWORKVERSION_STRING_LEN] = "HomeworldV1C";
  249. #endif
  250. #if defined(OEM)
  251. char minorBuildVersion[] = "051";
  252. #else
  253. char minorBuildVersion[] = "06.1";
  254. #endif
  255. char languageVersion[50] = ""; // constructed at beginning of program
  256. // The version string is now constructed as follows:
  257. //
  258. // Network Version TAB Language TAB MinorBuild Version
  259. //
  260. // for example
  261. // "DownloadableRC2\tEnglish\tBuild1"
  262. //
  263. //
  264. // For purposes of games able to play each other on the network, just the networkVersion is consulted
  265. //
  266. // For purposes of whether a patch is required (valid version), the entire versionString (network language build) is consulted
  267. //
  268. // For finding out what directory to get the patch from, only the languageVersion is consulted
  269. char versionString[MAX_VERSION_STRING_LEN] = ""; // constructed at beginning of program
  270. //Windows-related handles
  271. HWND ghMainWindow;
  272. HINSTANCE ghInstance;
  273. UINT uHWCloseMsg;
  274. //location of window, for mouse movement and sizing
  275. POINT WindowTopLeft = {-1, -1};
  276. sdword mainWindowTotalWidth = 0;
  277. sdword mainWindowTotalHeight = 0;
  278. bool noAuthorization = FALSE;
  279. bool determCompPlayer = FALSE;
  280. #if MAIN_SENSOR_LEVEL
  281. udword initialSensorLevel = 0;
  282. #endif
  283. bool pilotView = FALSE;
  284. //data for password-protecting certain options
  285. #if MAIN_Password
  286. char *mainMonthStrings[12] =
  287. {
  288. "Jan",
  289. "Feb",
  290. "Mar",
  291. "Apr",
  292. "May",
  293. "Jun",
  294. "Jul",
  295. "Aug",
  296. "Sep",
  297. "Oct",
  298. "Nov",
  299. "Dec"
  300. };
  301. char mainCompileDate[] = __DATE__;
  302. //password: each character is xor'd with the corresponding character in this string:
  303. ubyte mainOperatorString[] = "132AS sdFmfm na5r\x0\\6234asSDFG,m.";
  304. char mainPassword0[] =
  305. {
  306. //"BravoCharlie": unlocks single player game only
  307. '1' ^ 'B',
  308. '3' ^ 'r',
  309. '2' ^ 'a',
  310. 'A' ^ 'v',
  311. 'S' ^ 'o',
  312. ' ' ^ 'C',
  313. 's' ^ 'h',
  314. 'd' ^ 'a',
  315. 'F' ^ 'r',
  316. 'm' ^ 'l',
  317. 'f' ^ 'i',
  318. 'm' ^ 'e',
  319. ' ' ^ 0,
  320. /*
  321. 'n' ^ '',
  322. 'a' ^ '',
  323. '5' ^ '',
  324. 'r' ^ '',
  325. 0] '',
  326. '\\] ^ '',
  327. '6' ^ '',
  328. '2' ^ '',
  329. '3' ^ '',
  330. '4' ^ '',
  331. 'a' ^ '',
  332. 's' ^ '',
  333. 'S' ^ '',
  334. 'D' ^ '',
  335. 'F' ^ '',
  336. 'G' ^ '',
  337. ',' ^ '',
  338. 'm' ^ '',
  339. '.' ^ '',
  340. */
  341. };
  342. char mainPassword1[] =
  343. {
  344. //"Cheeky-Monkey": unlocks all features
  345. '1' ^ 'C',
  346. '3' ^ 'h',
  347. '2' ^ 'e',
  348. 'A' ^ 'e',
  349. 'S' ^ 'k',
  350. ' ' ^ 'y',
  351. 's' ^ '-',
  352. 'd' ^ 'M',
  353. 'F' ^ 'o',
  354. 'm' ^ 'n',
  355. 'f' ^ 'k',
  356. 'm' ^ 'e',
  357. ' ' ^ 'y',
  358. 'n' ^ 0,
  359. /*
  360. 'a' ^ '',
  361. '5' ^ '',
  362. 'r' ^ '',
  363. 0] '',
  364. '\\] ^ '',
  365. '6' ^ '',
  366. '2' ^ '',
  367. '3' ^ '',
  368. '4' ^ '',
  369. 'a' ^ '',
  370. 's' ^ '',
  371. 'S' ^ '',
  372. 'D' ^ '',
  373. 'F' ^ '',
  374. 'G' ^ '',
  375. ',' ^ '',
  376. 'm' ^ '',
  377. '.' ^ '',
  378. */
  379. };
  380. udword mainPasswordChecksum0 =
  381. ((udword)0x0 ^ (udword)'B') +
  382. ((udword)0x1 ^ (udword)'r') +
  383. ((udword)0x2 ^ (udword)'a') +
  384. ((udword)0x3 ^ (udword)'v') +
  385. ((udword)0x4 ^ (udword)'o') +
  386. ((udword)0x5 ^ (udword)'C') +
  387. ((udword)0x6 ^ (udword)'h') +
  388. ((udword)0x7 ^ (udword)'a') +
  389. ((udword)0x8 ^ (udword)'r') +
  390. ((udword)0x9 ^ (udword)'l') +
  391. ((udword)0xa ^ (udword)'i') +
  392. ((udword)0xb ^ (udword)'e');
  393. udword mainPasswordChecksum1 =
  394. ((udword)0x0 ^ (udword)'C') +
  395. ((udword)0x1 ^ (udword)'h') +
  396. ((udword)0x2 ^ (udword)'e') +
  397. ((udword)0x3 ^ (udword)'e') +
  398. ((udword)0x4 ^ (udword)'k') +
  399. ((udword)0x5 ^ (udword)'y') +
  400. ((udword)0x6 ^ (udword)'-') +
  401. ((udword)0x7 ^ (udword)'M') +
  402. ((udword)0x8 ^ (udword)'o') +
  403. ((udword)0x9 ^ (udword)'n') +
  404. ((udword)0xa ^ (udword)'k') +
  405. ((udword)0xb ^ (udword)'e') +
  406. ((udword)0xc ^ (udword)'y');
  407. char *mainPasswordPtr = NULL;
  408. #endif //MAIN_Password
  409. /*-----------------------------------------------------------------------------
  410. Leak-tracing strings. Don't delete any old ones, and comment the
  411. desitination and date of each string. Make the string fairly long, and not
  412. obviously a leak string.
  413. -----------------------------------------------------------------------------*/
  414. //To: Scott Lynch. Date: Feb 04 98 By: Luke Moloney
  415. //static char leakString[] = "MainObjectWindowMenuHelpOptionsForwardCancelButtonMeshPolygon";
  416. //To: Siearra by CD burned 16 Feb 98 By: Luke Moloney
  417. //static char leakString[] = "MainObjectWindowMenuOptionOptionsForwardButtonCancelMeshPolygon";
  418. //To: Siearra by CD burned 05 Mar 98 By: Luke Moloney
  419. //static char leakString[] = "MainObjectFastMenuOptionOptionsUpwardButtonCancelMeshPolygon";
  420. //To: Siearra by CD burned 10 Mar 98 By: Luke Moloney
  421. //static char leakString[] = "MainObjectFastMenuOptionOptionsOnClickCancelMeshPolygonXZY";
  422. //To: Siearra by CD burned 17 Mar 98 By: Luke Moloney
  423. //static char leakString[] = "MainNonObjectFastMenuSequenceOptionsOnInteractiveCancelMeshPolygonXZY";
  424. //To: Scott, Jim Veevaert,Mark Hood by CD burned 18 Mar 98 By: Luke Moloney
  425. //static char leakString[] = "MainNonObjectFastMenuSequenceOptionsOnInteractiveNomenuMeshPolygonXZY";
  426. //To: Elliot Ness by CD burned 25 Mar 98 By: Luke Moloney
  427. //static char leakString[] = "MainNonObjectFastBackMenuSequenceOptionsHoochyOnInteractiveMeshPolygonXZYWaynot";
  428. //To: Scott Lynch by CD burned 25 Mar 98 By: Luke Moloney
  429. //static char leakString[] = "MainNonGalaxyFastBackMenuSequenceOptionsGrahamOnInteractiveMeshPolygonXZYWaynot";
  430. //To: 'The Press', numbered sequence 1 burned 25 Mar 98 By: Luke Moloney
  431. //static char leakString[] = "ETGGoodBallsBadBoobsDeadBeefBadCafePureSqueezedAsteroidsForRUsInTheNebula";
  432. //To: 'The Press', numbered sequence 2 burned 25 Mar 98 By: Luke Moloney
  433. //static char leakString[] = "ETGGoodBallsBadBloodDeadBoobsBeefBadCafePureFrequencyDomainAsteroidsForRUsInTheNebula";
  434. //To: 'The Press', numbered sequence 3 burned 25 Mar 98 By: Luke Moloney
  435. //static char leakString[] = "Press OK Press Cancel Press Next Press Back Press Forward Error Occurred Internal Error";
  436. //To: 'The Press', numbered sequence 4 burned 25 Mar 98 By: Luke Moloney
  437. //static char leakString[] = "Frame rate: %d, %d, %d\x0Poly count: %d\x0Number dots: %d\x0Bryce 3d usage: %d%%\x0Gaz level: %d";
  438. //To: Scott Lynch, numbered sequence 4 burned 15 May 98 By: Luke Moloney
  439. //static char leakString[] = "Sound event 0x%x ('%s')\n\x0Policy event 0x%x ('%s')\n\x0ETG event 0x%x ('%s')\n\x0";
  440. //To: E3, numbered sequence 4 burned 15 May 98 By: Luke Moloney
  441. //static char leakString[] = "EEPROM version = 0x%x\n\x0Fatal error in file %s, line %d\n%s\nx0Warning in file %s, line %d\n%s\n\x0Notice: %s\n\x0";
  442. //To: Europe(with Alex) numbered EXE 1, burned 12 June 98 By: Luke Moloney
  443. //static char leakString[] = "maxvelocity maxrot maxhealth\x0regVerify: invalid region 0x%x has va\x0ELASTIC_PULL_FACTOR CAMERA_OUTBY_SCALE_ZOOM";
  444. //To: Europe(with Alex) numbered EXE 2, burned 12 June 98 By: Luke Moloney
  445. //static char leakString[] = "maxvelocity maxrot maxhealth\x0regVerify: invalid region 0x%x has va\x0ELASTIC_PULL_FACTOR CAMERA_OUTBY_SCALE_ZOOM";
  446. //To: Europe(with Alex) numbered EXE 3, burned 12 June 98 By: Luke Moloney
  447. //static char leakString[] = "..\\Game\\commandlayer.c FALSE Assertion of (%s) failed.FA_ToggleButton || atom->type == FA_CheckBox || atom->type == FA_RadioButton";
  448. //To: Europe(with Alex) numbered EXE 4, burned 12 June 98 By: Luke Moloney
  449. //static char leakString[] = "..\\Game\\feflow.c atom != NULL Assertion of (%s) failed.Closing front end module Bananna Bananna feScreensLoad: Invalid header '%s'";
  450. //To: Europe(with Alex) numbered EXE 5, burned 12 June 98 By: Luke Moloney
  451. //static char leakString[] = "ObjectWindowMenuOption\x0burned 15 May 98 By: Luke Moloney\x0Warning in file %s, line %d\n%s\n\x0";
  452. //To: Scott Lynch, burned 16 June 98 By: Luke Moloney
  453. //static char leakString[] = "/debug\n/skipFE\n/noBG\n/noFilter\n/noBorder\n/noClamp\n/noTexture\n/noSmooth\n/nilTexture";
  454. //To: Magazines in SanFran, burned 08 July 98 By: Luke Moloney
  455. //static char leakString[] = "/stipple\n/aiplayerLog\n/demoRecord\n/demoPlay\n/hiRes\n/AllTech\n/nohint\n/tactics\n/noR1\n/noR2\n/noP0\n/noP1\n/noP2\n/noP3\n/noTraders\n";
  456. //To: Magazines in SanFran, burned 08 July 98 By: Luke Moloney
  457. //static char leakString[] = "/stipple\n/aiplayerLog\n/demoRecord\n/demoPlay\n/hiRes\n/AllTech\n/nohint\n/tactics\n/noR1\n/noR2\n/noP1\n/noP1\n/noP2\n/noP3\n/noTraders\n";
  458. //To: Magazines in SanFran, burned 08 July 98 By: Luke Moloney
  459. //static char leakString[] = "/stipple\n/aiplayerLog\n/demoRecord\n/demoPlay\n/hiRes\n/AllTech\n/nohint\n/tactics\n/noR1\n/noR2\n/noP2\n/noP1\n/noP2\n/noP3\n/noTraders\n";
  460. //To: Magazines in SanFran, burned 08 July 98 By: Luke Moloney
  461. //static char leakString[] = "/stipple\n/aiplayerLog\n/demoRecord\n/demoPlay\n/hiRes\n/AllTech\n/nohint\n/tactics\n/noR1\n/noR2\n/noP3\n/noP1\n/noP2\n/noP3\n/noTraders\n";
  462. //To: Magazines in SanFran, burned 08 July 98 By: Luke Moloney
  463. //static char leakString[] = "/stipple\n/aiplayerLog\n/demoRecord\n/demoPlay\n/hiRes\n/AllTech\n/nohint\n/tactics\n/noR1\n/noR2\n/noP4\n/noP1\n/noP2\n/noP3\n/noTraders\n";
  464. //To: Magazines in SanFran, burned 08 July 98 By: Luke Moloney
  465. //static char leakString[] = "/stipple\n/aiplayerLog\n/demoRecord\n/demoPlay\n/hiRes\n/AllTech\n/nohint\n/tactics\n/noR1\n/noR2\n/noP5\n/noP1\n/noP2\n/noP3\n/noTraders\n";
  466. //To: Magazines in SanFran, burned 08 July 98 By: Luke Moloney
  467. //static char leakString[] = "/stipple\n/aiplayerLog\n/demoRecord\n/demoPlay\n/hiRes\n/AllTech\n/nohint\n/tactics\n/noR1\n/noR2\n/noP6\n/noP1\n/noP2\n/noP3\n/noTraders\n";
  468. //To: Magazines in SanFran, burned 08 July 98 By: Luke Moloney
  469. //static char leakString[] = "/stipple\n/aiplayerLog\n/demoRecord\n/demoPlay\n/hiRes\n/AllTech\n/nohint\n/tactics\n/noR1\n/noR2\n/noP7\n/noP1\n/noP2\n/noP3\n/noTraders\n";
  470. //To: Magazines in SanFran, burned 08 July 98 By: Luke Moloney
  471. //static char leakString[] = "/stipple\n/aiplayerLog\n/demoRecord\n/demoPlay\n/hiRes\n/AllTech\n/nohint\n/tactics\n/noR1\n/noR2\n/noP8\n/noP1\n/noP2\n/noP3\n/noTraders\n";
  472. //To: Magazines in SanFran, burned 08 July 98 By: Luke Moloney
  473. //static char leakString[] = "/stipple\n/aiplayerLog\n/demoRecord\n/demoPlay\n/hiRes\n/AllTech\n/nohint\n/tactics\n/noR1\n/noR2\n/noP9\n/noP1\n/noP2\n/noP3\n/noTraders\n";
  474. //To: Scott/doug burned Jul 16 1998 by Luke Moloney. No Leak String
  475. //To: Stuart Seeley for beta testing burned Jul 16 1998 by Luke Moloney.
  476. //static char leakString[] = "/stipple\n/aiplayerLog\n/demoRecord\n/demoPlay\n/hiRes\n/AllTech\n/nohint\x0ELASTIC_PULL_FACTOR\x0ETG event 0x%x ('%s')\n\x0";
  477. //To: Scott Lynch burned Aug 13 1998 by Luke Moloney.
  478. //static char leakString[] = "/minVal\x0/maxVal\x0/AIFast\x0/speed\x0/800\x0/1024\x0/ComputerAI\x0/LogFileIO\x0/logPackets\x0/encryptPackets";
  479. //To: Game Works Press Show burned Aug 13 1998 by Luke Moloney.
  480. //static char leakString[] = "/minVal\x0/maxVal\x0/AIFast\x0/speed\x0/800x600\x0/1024x768\x0/ComputerAI\x0/LogFileIO\x0/logPackets\x0/encryptPackets";
  481. //To: ECTS (hex edit) burned Sept 3 1998 by Luke Moloney.
  482. //static char leakString[] = "/minVal\x0/maxVal\x0/AIFast\x0/speed\x0/948\x0/1280\x0/ComputerAl\x0/LogFileIO\x0/logPackets\x0/encryptPackets";
  483. //To: "The Press" burned Oct 1 1998 by Luke Moloney. (Hex edit of origional M16 .exe)
  484. //static char leakString[] = "8B D9 81 C1 C4 00 00 00 83 C0 31 3D 93 00 00 00 7C BF 8B 44 24 20 00 00 00 00 98 7C 0E 00 00 80 E2 FE 88 50 35 0F B6 80 BD 0B 00 00 85 C0 75 0A";
  485. //To: Scott and the gang burned Sept 15 1998 by Luke Moloney.
  486. //static char leakString[] = "8B D9 81 C1 C4 00 00 00 83 C0 31 3D 93 00 00 00 7C BF 8B 44 24 20 8A 50 35 89 98 7C 0E 00 00 80 E2 FE 88 50 35 0F B6 80 BD 0B 00 00 85 C0 75 0A";
  487. //To: Scott and the gang burned Oct 15 1998 by Luke Moloney.
  488. //static char leakString[] = "Left click-select\x0Left hold-bandbox\x0Right hold-rotate camra\x0Left/right hold-zoom\x0Centre click-focus\x0Alt-click-focus\x0Control-bandbox-attack\x0";
  489. //To: Scott and the gang burned Nov 24 1998 by Luke Moloney.
  490. //static char leakString[] = "Revolutionary ne 3-d space combat with an advanced camera model and excellent graphics.";
  491. //To: Scott and the gang burned Dec 21 1998 by Luke Moloney.
  492. //static char leakString[] = "BEGLEITFREGATTE\n\x0ANGRIFFSBOMBER\n\x0TRÄGERSCHIFF\n\x0TARNKAPPENJÄGER\n\x0TARNFELDGENERATOR\n\x0DROHNEN-FREGATTE\n";
  493. //To: Scott and the gang burned Dec 21 1998 by Luke Moloney.
  494. //static char leakString[] = "noPlug\x0nisNoLockout\x0nisCounter\x0noPause\x0password\x0smCentreCamera\x0onlyPacking\x0disablePacking\x0disableAVI\x0allowPacking/noPalettes";
  495. //To: Sierra/Sierra QA
  496. //static char leakString[] = "Welcome to Homeworld!\x0Press 'Next' to continue.\x0At any time, you can press 'Back' to go to the previous screen.";
  497. //To: Sierra/Sierra QA burned Dec 26, 1998 by Luke Moloney
  498. //static char leakString[] = "Welcome to Homeworld!\x0Press 'Next' to continue!\x0At any time, you can press 'Back' to go to the previous screen.";
  499. //To: Sierra/Sierra QA burned Feb 1, 1999 by Gary Shaw
  500. //static char leakString[] = "Welcome to Homeworld!\x0Press 'Next' to continue!\x0At any time, you press 'Back' to go to the previous screen.";
  501. //To: Intel: Cathy Avenatti & Mike Minahan burned Feb 3, 1999 by Keith Hentschel
  502. //static char leakString[] = "nisNoLockout\x0nisCounter\x0password\x0noPause\x0smCentreCamera\x0disablePacking\x0onlyPacking\x0disableAVI\x0allowPacking\x0/noPalettes";
  503. //To: Sierra/Sierra QA burned Feb 8, 1999 by Gary Shaw
  504. //static unsigned char leakString[] = { 0xff, 0xd7, 0x23, 0xb6, 0xed, 0x8c, 0xb8, 0xe4, 0x3f, 0xcb, 0x84, 0xde, 0xa6, 0xec, 0x89, 0x80 };
  505. //for the Europe press tour version of the above burn, the last 2 digits, '8980'
  506. //will be incremented by 1 for the number of burns we need by hex-editing the .exe file
  507. //Beta 4 Milestone M21
  508. //static char leakString[] = "nisNoLockout\x0nisCounter\x0passwd\x0noPause\x0smCentreCamera\x0disablePacking\x0onlyPacking\x0disableAVI\x0allowPacking\x0/noPalettes";
  509. //CGDC burn: full of bugs and whatnot. 10 burns to go out. The default at the end will be incremented for additional burns.
  510. //static char leakString[] = "/miniBeef[ = 0]\x0/lowBeef[ = 1]\x0/highBeef[ = 2]\x0/ultraBeef[ = 3]\x0/megaBeef[ = 4]\x0/insaneBeef[ = 5]\x0/default=00";
  511. //static char leakString[] = "/miniBeef[ = 0]\x0/lowBeef[ = 1]\x0/highBeef[ = 2]\x0/ultraBeef[ = 3]\x0/megaBeef[ = 4]\x0/insaneBeef[ = 5]\x0/default=05";
  512. //M22 burn: Sent to Sierra, Burned by Luke
  513. //for numbered burns, the first number, 0x45, is incremented
  514. //static ubyte leakString[] = {0x45, 0x65, 0x32, 0x89, 0x66, 0x48, 0x78, 0xf9, 0x1a, 0xaa, 0x45, 0x01};
  515. //Demo testing burn. Burned Apr 05/99 by Luke for Torsten and the crowd.
  516. //static char leakString[] = "/miniBeef[ = 1]\x0/lowBeef[ = 2]\x0/highBeef[ = 3]\x0/ultraBeef[ = 4]\x0/megaBeef[ = 5]\x0/insaneBeef[ = 6]\x0/default=00";
  517. //Downloadable demo (public beta) testing burn. Burned Apr 05/99 by Luke for Torsten and the crowd.
  518. //static char leakString[] = "MainObjectWindowMenuHelpOptionsForwardCancelButtonMeshPolygon";
  519. //Downloadable demo (public beta) testing burn. Burned Apr 16/99 by Luke for Torsten and the crowd.
  520. //static char leakString[] = "MainObjectWindowMenuOptionOptionsForwardButtonCancelMeshPolygon";
  521. //Downloadable demo (public beta) testing burn. Burned Apr 21/99 by Luke for Torsten and the crowd.
  522. //static char leakString[] = "MainObjectFastMenuOptionOptionsOnClickCancelMeshPolygonXZY";
  523. //Downloadable demo (public beta) testing burn. Burned Apr 28/99 by Luke for Torsten and the crowd.
  524. //static char leakString[] = "MainNonObjectFastBackMenuSequenceOptionsHoochyOnInteractiveMeshPolygonXZYWaynot";
  525. //M23 Burn by Luke for Sierra evaluation
  526. //static char leakString[] = "ETGGoodBallsBadBoobsDeadBeefBadCafePureSqueezedAsteroidsForRUsInTheNebula";
  527. //CGW Burn RC1 by Luke for bug testing
  528. //static char leakString[] = "1001010001001110100011010011101010010100010111010010101010101000011111110001001010";
  529. //E3 Burn RC1 by Luke for bug testing
  530. //static char leakString[] = "1001010001001110100011010011101010010100010111010010101010101000011111110001001010";
  531. //Update Burn RC1 by Luke for bug testing
  532. //static char leakString[] = "01001001010101010101100111001010110101010001010101010100010010101010110101010100101010";
  533. //M24. 2 years now. How very dragging. For Mark Hood and Torsten.
  534. //static char leakString[] = "10111101001000100100101010101010001000100110110010111011101011101010010111110101001110";
  535. //Public Beta 2 for torsten and lackies...
  536. //static char leakString[] = "10100101001010100101101011101010001000100110110010111011101011101010010111110101001110";
  537. //M24d Beta 2 Release Candidate 2 to torsten via FTP
  538. //static char leakString[] = "10100101001010100101101011101010001000100010110010101010101010101010010111110101001110";
  539. //M24e Beta 2 Release Candidate 3 to torsten via FTP
  540. //static char leakString[] = "1010010100101010011111111101010001000100010110010101010101010101010010111110101001110";
  541. //M24e Beta 2 Release Candidate 4 to torsten via FTP
  542. //static char leakString[] = "1010110100101010011111111101010001000100010110010101010101010101010010111110101001110";
  543. //For Torsten + focus group: m24ffinalrc5
  544. //static char leakString[] = "101011010010101001111111110101000100010101011000101011101010101010010111110101001110";
  545. //leak strings now defined in LeakyFaucet.h
  546. /*=============================================================================
  547. Functions:
  548. =============================================================================*/
  549. /*-----------------------------------------------------------------------------
  550. Command-line parsing functions called when a certain flags are set
  551. -----------------------------------------------------------------------------*/
  552. bool HeapSizeSet(char *string)
  553. {
  554. sscanf(string, "%d", &MemoryHeapSize);
  555. if (MemoryHeapSize <= MEM_BlockSize * 2)
  556. {
  557. MemoryHeapSize = MEM_HeapSizeDefault;
  558. }
  559. return TRUE;
  560. }
  561. bool PrependPathSet(char *string)
  562. {
  563. filePrependPathSet(string);
  564. FilePathPrepended = TRUE;
  565. return TRUE;
  566. }
  567. bool CDROMPathSet(char *string)
  568. {
  569. char message[80];
  570. if (GetDriveType(string) != DRIVE_CDROM)
  571. {
  572. sprintf(message, "'%s' Is not a valid CD-ROM; path ignored.", string);
  573. MessageBox(NULL, message, "Invalid CD-ROM path", MB_OK | MB_APPLMODAL);
  574. return FALSE;
  575. }
  576. fileCDROMPathSet(string);
  577. CDROMPathPrepended = TRUE;
  578. return TRUE;
  579. }
  580. bool EnableFileLoadLog(char *string)
  581. {
  582. logfileClear(FILELOADSLOG);
  583. return TRUE;
  584. }
  585. bool SelectDevice(char* string)
  586. {
  587. memStrncpy(deviceToSelect, string, 16 - 1);
  588. if (_stricmp(deviceToSelect, "d3d") == 0)
  589. {
  590. mainReinitRenderer = 2;
  591. }
  592. selectedDEVICE = TRUE;
  593. return TRUE;
  594. }
  595. bool SelectMSGL(char* string)
  596. {
  597. memStrncpy(glToSelect, "opengl32.dll", 512 - 1);
  598. return TRUE;
  599. }
  600. bool SelectD3D(char* string)
  601. {
  602. memStrncpy(glToSelect, "rgl.dll", 512 - 1);
  603. memStrncpy(deviceToSelect, "d3d", 16 - 1);
  604. selectedGL = TRUE;
  605. selectedDEVICE = TRUE;
  606. mainReinitRenderer = 2;
  607. return TRUE;
  608. }
  609. bool EnableRasterSkip(char* string)
  610. {
  611. mainRasterSkip = TRUE;
  612. return TRUE;
  613. }
  614. bool EnableDoubleIsTriple(char* string)
  615. {
  616. mainDoubleIsTriple = TRUE;
  617. return TRUE;
  618. }
  619. bool DisableFastFrontend(char* string)
  620. {
  621. mainFastFrontend = !mainFastFrontend;
  622. return TRUE;
  623. }
  624. bool EnableGatherStats(char *string)
  625. {
  626. noDefaultComputerPlayer = TRUE;
  627. return TRUE;
  628. }
  629. bool EnableShowStatsFancyFight(char *string)
  630. {
  631. showStatsFancyFight = TRUE;
  632. strcpy(showStatsFancyFightScriptFile,string);
  633. noDefaultComputerPlayer = TRUE;
  634. return TRUE;
  635. }
  636. bool EnableShowStatsFight(char *string)
  637. {
  638. sscanf(string, "%d", &showStatsFightI);
  639. if ((string = strtok(NULL, TS_Delimiters)) == NULL)
  640. return TRUE; //error??
  641. sscanf(string, "%d", &showStatsFightJ);
  642. showStatsFight = TRUE;
  643. noDefaultComputerPlayer = TRUE;
  644. return TRUE;
  645. }
  646. bool SpecifyLogFilePath(char *string)
  647. {
  648. strcpy(logFilePath,string);
  649. return TRUE;
  650. }
  651. /*
  652. void EnableComputerPlayers(char *string)
  653. {
  654. char playerStr[20];
  655. char *scanning = playerStr;
  656. char index;
  657. if ((string = strtok(NULL, TS_Delimiters)) == NULL)
  658. return;
  659. sscanf(string, "%s", playerStr);
  660. while (*scanning != '\0')
  661. {
  662. if ((*scanning >= '0') && (*scanning <= '9'))
  663. {
  664. index = (char)(*scanning - '0');
  665. dbgAssert(index < MAX_MULTIPLAYER_PLAYERS);
  666. dbgAssert(index >= 0);
  667. ComputerPlayerEnabled[index] = TRUE;
  668. }
  669. scanning++;
  670. }
  671. noDefaultComputerPlayer = TRUE;
  672. }
  673. */
  674. #if 0
  675. bool SetAIPlayerLevels(char *string)
  676. {
  677. char playerStr[20];
  678. char *scanning = playerStr;
  679. char level, i;
  680. if ((string = strtok(NULL, TS_Delimiters)) == NULL)
  681. return TRUE; //error?
  682. sscanf(string, "%s", playerStr);
  683. for (i=0;(*scanning != '\0') || (i > MAX_MULTIPLAYER_PLAYERS); )
  684. {
  685. if ((*scanning >= '0') && (*scanning <= '9'))
  686. {
  687. level = (char)(*scanning - '0');
  688. dbgAssert(level < (char)AI_NUM_LEVELS);
  689. dbgAssert(level >= 0);
  690. ComputerPlayerLevel[i] = level;
  691. i++;
  692. }
  693. scanning++;
  694. }
  695. return TRUE;
  696. }
  697. #endif
  698. #if NIS_TEST
  699. extern char *nisTestNIS;
  700. extern char *nisTestScript;
  701. bool TestNISSet(char *string)
  702. {
  703. static char staticString[256];
  704. if ((string = strtok(NULL, TS_Delimiters)) == NULL)
  705. return TRUE;
  706. memStrncpy(staticString, string, 255);
  707. nisTestNIS = staticString;
  708. return TRUE;
  709. }
  710. bool TestNISScriptSet(char *string)
  711. {
  712. static char staticString[256];
  713. if ((string = strtok(NULL, TS_Delimiters)) == NULL)
  714. return TRUE;
  715. memStrncpy(staticString, string, 255);
  716. nisTestScript = staticString;
  717. return TRUE;
  718. }
  719. #endif
  720. #if MAIN_SENSOR_LEVEL
  721. bool InitialSensorLevelSet(char *string)
  722. {
  723. sscanf(string, "%d", &initialSensorLevel);
  724. return TRUE;
  725. }
  726. #endif
  727. #if LOD_SCALE_DEBUG
  728. bool EnableLodScaleDebug(char *string)
  729. {
  730. sscanf(string, "%f", &lodDebugScaleFactor);
  731. return TRUE;
  732. }
  733. #endif
  734. bool EnableDemoRecord(char *string)
  735. {
  736. if (!demDemoPlaying)
  737. {
  738. demDemoRecording = TRUE;
  739. strcpy(demDemoFilename, string);
  740. }
  741. return TRUE;
  742. }
  743. bool EnableDemoPlayback(char *string)
  744. {
  745. if (!demDemoRecording)
  746. {
  747. wasDemoPlaying = demDemoPlaying = TRUE;
  748. noPauseAltTab = TRUE;
  749. strcpy(demDemoFilename, string);
  750. }
  751. return TRUE;
  752. }
  753. #if DEM_AUTO_DEMO
  754. bool AutoDemoWaitSet(char *string)
  755. {
  756. sscanf(string , "%f", &demAutoDemoWaitTime);
  757. return TRUE;
  758. }
  759. #endif
  760. bool EnablePacketPlay(char *string)
  761. {
  762. transferCaptaincyDisabled = TRUE;
  763. strcpy(recordPacketFileName, strtok(NULL, TS_Delimiters));
  764. return TRUE;
  765. }
  766. bool EnablePacketRecord(char *string)
  767. {
  768. debugPacketRecord = TRUE;
  769. return TRUE;
  770. }
  771. bool EnableDebugSync(char *string)
  772. {
  773. recordPackets = TRUE;
  774. logEnable = LOG_VERBOSE;
  775. autoSaveDebug = TRUE;
  776. return TRUE;
  777. }
  778. bool EnableAutoSaveDebug(char *string)
  779. {
  780. autoSaveDebug = TRUE;
  781. return TRUE;
  782. }
  783. bool EnableMiniRes(char* string)
  784. {
  785. selectedRES = TRUE;
  786. mainWindowWidth = 320;
  787. mainWindowHeight = 240;
  788. return TRUE;
  789. }
  790. bool EnableLoRes(char *string)
  791. {
  792. selectedRES = TRUE;
  793. mainWindowWidth = 640;
  794. mainWindowHeight = 480;
  795. return TRUE;
  796. }
  797. bool EnableHiRes(char *string)
  798. {
  799. selectedRES = TRUE;
  800. mainWindowWidth = 800;
  801. mainWindowHeight = 600;
  802. return TRUE;
  803. }
  804. bool EnableMegaRes(char *string)
  805. {
  806. selectedRES = TRUE;
  807. mainWindowWidth = 1024;
  808. mainWindowHeight = 768;
  809. return TRUE;
  810. }
  811. bool EnableUltraRes(char* string)
  812. {
  813. selectedRES = TRUE;
  814. mainWindowWidth = 1280;
  815. mainWindowHeight = 1024;
  816. return TRUE;
  817. }
  818. bool EnableInsaneRes(char* string)
  819. {
  820. selectedRES = TRUE;
  821. mainWindowWidth = 1600;
  822. mainWindowHeight = 1200;
  823. return TRUE;
  824. }
  825. bool Enable32Bit(char* string)
  826. {
  827. selectedRES = TRUE;
  828. MAIN_WindowDepth = 32;
  829. return TRUE;
  830. }
  831. bool Enable16Bit(char* string)
  832. {
  833. selectedRES = TRUE;
  834. MAIN_WindowDepth = 16;
  835. return TRUE;
  836. }
  837. bool Enable24Bit(char* string)
  838. {
  839. selectedRES = TRUE;
  840. MAIN_WindowDepth = 24;
  841. return TRUE;
  842. }
  843. #ifdef GOD_LIKE_SYNC_CHECKING
  844. #define GUESS_NUM_SHIPS 400
  845. bool syncDumpInit(char *string1)
  846. {
  847. if(sscanf(string1,"%d!%d",&syncDumpWindowSize,&syncDumpGranularity) != 2)
  848. {
  849. return FALSE;
  850. }
  851. syncDumpOn = TRUE;
  852. syncDumpWindowPos=0;
  853. syncDumpGranTrack=0;
  854. //MemoryHeapSize += sizeof(Ship)*400*syncDumpWindowSize;
  855. return TRUE;
  856. }
  857. #endif
  858. #if MAIN_Password
  859. bool SetPassword(char *string)
  860. {
  861. mainPasswordPtr = string;
  862. return TRUE;
  863. }
  864. /*-----------------------------------------------------------------------------
  865. Name : mainPasswordVerify
  866. Description : Verifies the system password and unlocks some features, or if
  867. there is no password, times the game out 30 days after compile.
  868. Inputs : string - password string or NULL of none specified.
  869. Outputs :
  870. Return : NULL if no errors, or error string pointer.
  871. ----------------------------------------------------------------------------*/
  872. char *mainPasswordVerify(char *string)
  873. {
  874. udword index;
  875. udword checksum;
  876. time_t time0;
  877. struct tm *time1;
  878. char dayString0[16];
  879. char monthString0[16];
  880. char monthString1[16];
  881. sdword day0, hour0, min0, sec0, year0, month0;
  882. sdword day1, year1, month1;
  883. sdword nScanned;
  884. sdword daysOld;
  885. if (string != NULL)
  886. {
  887. //tamper-detect the password
  888. for (index = checksum = 0; (mainPassword1[index] ^ mainOperatorString[index]) != 0; index++)
  889. {
  890. checksum += (udword)index ^ (udword)((ubyte)(mainPassword1[index] ^ mainOperatorString[index]));
  891. }
  892. if (checksum != mainPasswordChecksum1)
  893. {
  894. //... error: wrong password checksum (tampering?)
  895. return("Invalid binaries.");
  896. }
  897. for (index = checksum = 0; mainPassword1[index] != 0; index++)
  898. {
  899. if (mainPassword1[index] != (string[index] ^ mainOperatorString[index]))
  900. {
  901. //... error: invalid password
  902. goto checkNextPassword;
  903. }
  904. }
  905. //... enable screen shots, single player and disable CD check
  906. mainScreenShotsEnabled = TRUE;
  907. mainSinglePlayerEnabled = TRUE;
  908. mainEnableSpecialMissions = TRUE;
  909. mainCDCheckEnabled = FALSE;
  910. return(NULL); //they've got a password
  911. checkNextPassword:
  912. //tamper-detect the password
  913. for (index = checksum = 0; (mainPassword0[index] ^ mainOperatorString[index]) != 0; index++)
  914. {
  915. checksum += (udword)index ^ (udword)((ubyte)(mainPassword0[index] ^ mainOperatorString[index]));
  916. }
  917. if (checksum != mainPasswordChecksum0)
  918. {
  919. //... error: wrong password checksum (tampering?)
  920. return("Invalid binaries.");
  921. }
  922. for (index = checksum = 0; mainPassword0[index] != 0; index++)
  923. {
  924. if (mainPassword0[index] != (string[index] ^ mainOperatorString[index]))
  925. {
  926. //... error: invalid password
  927. return("Invalid password.");
  928. }
  929. }
  930. //... enable single player only
  931. mainSinglePlayerEnabled = TRUE;
  932. mainEnableSpecialMissions = TRUE;
  933. return(NULL); //they've got a password
  934. }
  935. else
  936. { //no password specified: see if it times out
  937. //tamper-detect the date
  938. /*
  939. for (index = checksum = 0; index < 10; index++)
  940. {
  941. checksum += mainCompileDate[index] ^ index;
  942. }
  943. if (checksum != mainCompileDateChecksum)
  944. {
  945. //... error: wrong date (tampering?)
  946. return("Invalid binaries/data.");
  947. }
  948. */
  949. //compare current date to compile date and determine time expired
  950. time(&time0);
  951. time1 = gmtime(&time0);
  952. nScanned = sscanf(asctime(time1), "%s %s %d %d:%d:%d %d", dayString0, monthString0, &day0, &hour0, &min0, &sec0, &year0);
  953. if (nScanned != 7)
  954. {
  955. //... error: bad scan
  956. return("Bad scan xx(1)");
  957. }
  958. nScanned = sscanf(mainCompileDate, "%s %d %d", monthString1, &day1, &year1);
  959. if (nScanned != 3)
  960. {
  961. //... error: bad scan
  962. return("Bad scan xx(2)");
  963. }
  964. month0 = month1 = -1;
  965. for (index = 0; index < 12; index++)
  966. {
  967. if (!_stricmp(monthString0, mainMonthStrings[index]))
  968. {
  969. month0 = index;
  970. }
  971. if (!_stricmp(monthString1, mainMonthStrings[index]))
  972. {
  973. month1 = index;
  974. }
  975. }
  976. if (month0 == -1 || month1 == -1)
  977. {
  978. //... error: bad month string
  979. return("I hate this month");
  980. }
  981. daysOld = 365 * (year1 - year0) + 30 * (month1 - month0) + (day1 - day0);
  982. // ^^^ ^^
  983. // I know 30 isn't the length of all months, but let's just assume for now
  984. //
  985. if (daysOld > MAIN_ExpiryTime)
  986. {
  987. //... error: Evaluation copy expired
  988. return("Skynyrd!");
  989. }
  990. }
  991. return(NULL);
  992. }
  993. #endif //MAIN_Password
  994. /*-----------------------------------------------------------------------------
  995. Structures used for command paramters and help
  996. -----------------------------------------------------------------------------*/
  997. #define entryFn(command, func, help) {COF_Visible, command, func, NULL, 0, help}
  998. #define entryVr(command, var, value, help) {COF_Visible, command, NULL, &var, value, help}
  999. #define entryFV(command, func, var, value, help) {COF_Visible, command, func, &var, value, help}
  1000. #define entryFnParam(command, func, help) {COF_Visible | COF_NextToken, command, func, NULL, 0, help}
  1001. #define entryFVParam(command, func, var, help) {COF_Visible | COF_NextToken, command, func, &var, value, help}
  1002. #define entryFnHidden(command, func, help) {0, command, func, NULL, 0, help}
  1003. #define entryVrHidden(command, var, value, help) {0, command, NULL, &var, value, help}
  1004. #define entryFVHidden(command, func, var, value, help) {0, command, func, &var, value, help}
  1005. #define entryFnParamHidden(command, func, help) {COF_NextToken, command, func, NULL, 0, help}
  1006. #define entryFVParamHidden(command, func, var, help) {COF_NextToken, command, func, &var, value, help}
  1007. #define entryComment(comment) {COF_Visible, comment, NULL, NULL, 0, NULL}
  1008. commandoption commandOptions[] =
  1009. {
  1010. #ifndef HW_Release
  1011. entryComment("DEBUGGING OPTIONS"),//-----------------------------------------------------
  1012. entryVr("/debug", DebugWindow, TRUE, " - Enable debug window."),
  1013. entryVr("/nodebugInt", dbgInt3Enabled,FALSE, " - Fatal errors don't genereate an int 3 before exiting."),
  1014. #if DBW_TO_FILE
  1015. entryVr("/debugToFile", debugToFile, TRUE, " - output debugging info to a file."),
  1016. #endif
  1017. #else
  1018. entryVrHidden("/debug", DebugWindow, TRUE, " - Enable debug window."),
  1019. entryVrHidden("/nodebugInt", dbgInt3Enabled,FALSE, " - Fatal errors don't genereate an int 3 before exiting."),
  1020. #if DBW_TO_FILE
  1021. entryVrHidden("/debugToFile", debugToFile, TRUE, " - output debugging info to a file."),
  1022. #endif
  1023. #endif
  1024. #if RAN_DEBUG_CALLER
  1025. entryVr("/ranCallerDebug", ranCallerDebug, TRUE, " - debug non-deterministic calling of random numbers."),
  1026. #endif
  1027. #ifndef HW_Release
  1028. entryFn("/autosavedebug", EnableAutoSaveDebug, " autosaves game frequently"),
  1029. #endif
  1030. entryComment("SYSTEM OPTIONS"), //-----------------------------------------------------
  1031. entryFnParam("/heap", HeapSizeSet, " <n> - Sets size of global memory heap to [n]."),
  1032. entryFnParam("/prepath", PrependPathSet, " <path> - Sets path to search for opening files."),
  1033. entryFnParam("/CDpath", CDROMPathSet, " <path> - Sets path to CD-ROM in case of ambiguity."),
  1034. #if MAIN_MOUSE_FREE
  1035. #ifndef HW_Release
  1036. entryVr("/freemouse", startupClipMouse, FALSE, " - Mouse free to move about entire screen at startup. Use <CTRL>F11 to toggle during play."),
  1037. #else
  1038. entryVrHidden("/freemouse", startupClipMouse, FALSE, " - Mouse free to move about entire screen at startup. Use <CTRL>F11 to toggle during play."),
  1039. #endif
  1040. #endif
  1041. #ifndef HW_Release
  1042. entryVr("/ignoreBigfiles", IgnoreBigfiles, TRUE, " - don't use anything from bigfile(s)"),
  1043. entryFV("/logFileLoads", EnableFileLoadLog,LogFileLoads,TRUE," - create log of data files loaded"),
  1044. #endif
  1045. entryComment("PROCESSOR OPTIONS"),//-----------------------------------------------------
  1046. entryVr("/enableSSE", mainAllowKatmai, TRUE, " - allow use of SSE if support is detected."),
  1047. entryVr("/forceSSE", mainForceKatmai, TRUE, " - force usage of SSE even if determined to be unavailable."),
  1048. entryVr("/enable3DNow", mainAllow3DNow, TRUE, " - allow use of 3DNow! if support is detected."),
  1049. entryComment("SOUND OPTIONS"), //-----------------------------------------------------
  1050. #if SE_DEBUG
  1051. entryVr("/noSound", enableSFX, FALSE, " - turn all sound effects off."),
  1052. entryVr("/noSpeech", enableSpeech, FALSE, " - turn all speech off."),
  1053. #endif
  1054. entryVr("/dsound", useDSound, TRUE, " - forces mixer to write to DirectSound driver, even if driver reports not certified."),
  1055. entryVr("/dsoundCoop", coopDSound, TRUE, " - switches to co-operative mode of DirectSound (if supported) to allow sharing with other applications."),
  1056. entryVr("/waveout", useWaveout, TRUE, " - forces mixer to write to Waveout even if a DirectSound supported object is available."),
  1057. entryVr("/reverseStereo", reverseStereo, TRUE, " - swap the left and right audio channels."),
  1058. entryComment("DETAIL OPTIONS"), //-----------------------------------------------------
  1059. entryFn("/rasterSkip", EnableRasterSkip, " - enable interlaced display with software renderer."),
  1060. entryVr("/noBG", showBackgrounds, FALSE, " - disable display of galaxy backgrounds."),
  1061. entryVr("/noFilter", texLinearFiltering,FALSE, " - disable bi-linear filtering of textures."),
  1062. entryVr("/noSmooth", enableSmoothing, FALSE, " - do not use polygon smoothing."),
  1063. #if TR_NIL_TEXTURE
  1064. entryVr("/nilTexture", GLOBAL_NO_TEXTURES,TRUE, " - don't ever load textures at all."),
  1065. #endif
  1066. #if ETG_DISABLEABLE
  1067. entryVr("/noEffects", etgEffectsEnabled,FALSE, " - disable all effects (Debug only)."),
  1068. #endif
  1069. #if FE_TEXTURES_DISABLABLE
  1070. entryVr("/NoFETextures", fetEnableTextures, FALSE, " - turns off front end textures"),
  1071. #endif
  1072. entryVr("/stipple", enableStipple, TRUE, " - enable stipple alpha with software renderer."),
  1073. entryVr("/noShowDamage", gShowDamage, FALSE, " - Disables showing ship damage effects."),
  1074. entryComment("VIDEO MODE OPTIONS"),//-----------------------------------------------------
  1075. entryVr("/safeGL", mainSafeGL, TRUE, " - don't use possibly buggy optimized features of OpenGL for rendering."),
  1076. entryFn("/triple", EnableDoubleIsTriple, " - use when frontend menus are flickering madly."),
  1077. entryVr("/nodrawpixels", mainNoDrawPixels, TRUE, " - use when background images don't appear while loading."),
  1078. entryVr("/noswddraw", mainSoftwareDirectDraw, FALSE, " - don't use DirectDraw for the software renderer."),
  1079. entryVr("/noglddraw", mainDirectDraw, FALSE, " - don't use DirectDraw to setup OpenGL renderers."),
  1080. entryVr("/sw", mainForceSoftware, TRUE, " - reset rendering system to defaults at startup."),
  1081. entryVrHidden("/noSavedMode", mainAutoRenderer, FALSE, " - disable recovery of previous display mode."),
  1082. entryFn("/noFastFE", DisableFastFrontend, " - disable fast frontend rendering."),
  1083. entryVr("/fullscreen", fullScreen, TRUE, " - display fullscreen with software renderer (default)."),
  1084. entryVr("/window", fullScreen, FALSE, " - display in a window."),
  1085. entryVr("/noBorder", showBorder, FALSE, " - no border on window."),
  1086. entryVrHidden("/d3dDeviceCRC", mainOutputCRC, TRUE, " - generate d3dDeviceCRC.txt for video troubleshooting."),
  1087. entryFnHidden("/minny", EnableMiniRes, " - run at 320x240 resolution."),
  1088. entryFn("/640", EnableLoRes, " - run at 640x480 resolution (default)."),
  1089. entryFn("/800", EnableHiRes, " - run at 800x600 resolution."),
  1090. entryFn("/1024", EnableMegaRes, " - run at 1024x768 resolution."),
  1091. entryFn("/1280", EnableUltraRes, " - run at 1280x1024 resolution."),
  1092. entryFn("/1600", EnableInsaneRes, " - run at 1600x1200 resolution."),
  1093. // entryFn("/d16", Enable16Bit, " - run in 16 bits of colour."),
  1094. // entryFn("/d24", Enable24Bit, " - run in 24 bits of colour."),
  1095. // entryFn("/d32", Enable32Bit, " - run in 32 bits of colour."),
  1096. // entryVr("/truecolor", trueColor, TRUE, " - try 24bit modes before 15/16bit."),
  1097. // entryVr("/slowBlits", slowBlits, TRUE, " - use slow screen blits if the default is buggy."),
  1098. entryFnParam("/device", SelectDevice, " <dev> - select an rGL device by name, eg. sw, fx, d3d."),
  1099. // entryFV("/gl", SelectMSGL, selectedGL, TRUE, " - select default OpenGL as renderer."),
  1100. // entryFn("/d3d", SelectD3D, " - select Direct3D as renderer."),
  1101. entryVr("/nohint", mainNoPerspective, TRUE, " - disable usage of OpenGL perspective correction hints."),
  1102. entryVrHidden("/noPause", noPauseAltTab, TRUE, " - don't pause when you alt-tab."),
  1103. entryVrHidden("/noMinimize", noMinimizeAltTab, TRUE, " - don't minimize when you alt-tab."),
  1104. #ifndef HW_Release
  1105. entryComment("CHEATS AND SHORTCUTS"), //-----------------------------------------------------
  1106. #if CM_CHEAP_SHIPS
  1107. entryVr("/cheapShips", cmCheapShips, TRUE, " - ships only cost 1 RU."),
  1108. #endif
  1109. #if MAIN_SENSOR_LEVEL
  1110. entryFnParam("/sensorLevel" , InitialSensorLevelSet, " <n> - set initial sensors level (0.. 2). Default is 0."),
  1111. #endif
  1112. entryVr("/noCompPlayer", noDefaultComputerPlayer, TRUE, " - disable default computer players"),
  1113. #ifdef DEBUG_TACTICS
  1114. entryVr("/notactics", tacticsOn, FALSE, " - Disables tactics."),
  1115. #endif
  1116. entryVr("/noretreat", noRetreat, TRUE, " - disables the 'retreat' feature of tactics"),
  1117. #endif
  1118. entryVrHidden("/disableAVI", enableAVI,FALSE, " - don't display intro sequences."),
  1119. #if RENDER_LIGHTLINES
  1120. entryComment("VISUALIZATION"), //-----------------------------------------------------
  1121. entryVr("/dockLines", dockLines, TRUE, " - show dock lines."),
  1122. entryVr("/gunLines", gunLines, TRUE, " - show gun lines."),
  1123. entryVr("/lightLines", RENDER_LIGHTLINES, TRUE, " - show light lines (Debug only)."),
  1124. entryVr("/boxes", RENDER_BOXES, TRUE, " - render bounding bowties on the ships."),
  1125. #endif
  1126. #if CL_TEXTFEEDBACK
  1127. entryVr("/textFeedback", enableTextFeedback, TRUE, " - enable text feedback for in game commands."),
  1128. #endif
  1129. #if TR_DEBUG_TEXTURES
  1130. entryVr("/specialTextures", trSpecialTextures, TRUE, " - enable special debugging textures."),
  1131. #endif
  1132. #if MESH_MORPH_DEBUG
  1133. entryVr("/morphDebug", meshMorphDebug, TRUE, " - enable debugging of morphed mesh rendering code."),
  1134. #endif
  1135. #if LOD_SCALE_DEBUG
  1136. entryFnParam("/lodScaleDebug", EnableLodScaleDebug, " - enable fixing a LOD scale factor."),
  1137. #endif
  1138. #if MR_CAN_FOCUS_ROIDS
  1139. entryVr("/focusRoids", mrCanFocusRoids, TRUE, " - enable focussing on asteroids and dust clouds."),
  1140. #endif
  1141. #if PIE_VISUALIZE_EXTENTS
  1142. entryVr("/showExtents", pieVisualizeExtents, TRUE, " - draw elliptical universe extents."),
  1143. #endif
  1144. #if UNIV_SHIP_LOADFREE_LOG
  1145. entryVr("/loadFreeLog", univLoadFreeLog, TRUE, " - enable logging of what was loaded and freed between missions."),
  1146. #endif
  1147. #ifndef HW_Release
  1148. entryVr("/NoBind", bkDisableKeyRemap, TRUE, " - disable key bindings so that debug keys work."),
  1149. #else
  1150. entryVrHidden("/NoBind", bkDisableKeyRemap, TRUE, " - disable key bindings so that debug keys work."),
  1151. #endif
  1152. #ifndef HW_Release
  1153. entryComment("COMPUTER PLAYER AND STATS"),//-----------------------------------------------------
  1154. // {"/compPlayer", EnableComputerPlayers, "=01234567 to enable all computer players"},
  1155. entryVr("/aiplayerLog", aiplayerLogEnable, TRUE, " - enable AI Player Logging"),
  1156. entryVr("/determCompPlayer", determCompPlayer, TRUE, " - makes computer players deterministic"),
  1157. entryFV("/gatherStats", EnableGatherStats, gatherStats, TRUE,"- enable gathering of stats"),
  1158. entryFnParam("/showStatsFight", EnableShowStatsFight, "=<i,j> to show stats fight i,j"),
  1159. entryFnParam("/showStatsFancyFight", EnableShowStatsFancyFight, "=filename.script"),
  1160. #endif
  1161. #ifndef HW_Release
  1162. entryComment("NETWORK PLAY"), //-----------------------------------------------------
  1163. //entryVr("/captaincyLogOff", captaincyLogEnable, FALSE, " - turns off captaincy log file" ),
  1164. //entryVr("/captaincyLogOn", captaincyLogEnable, TRUE, " - turns on captaincy log file" ),
  1165. entryVr("/logOff", logEnable, LOG_OFF, " - turns of network logging file"),
  1166. entryVr("/logOn", logEnable, LOG_ON,, " - turns network logging file on"),
  1167. entryVr("/logOnVerbose", logEnable, LOG_VERBOSE, " - turns verbose network logging file on"),
  1168. entryFnParam("/logFilePath", SpecifyLogFilePath, "=filepath.txt"),
  1169. entryFn("/debugSync", EnableDebugSync, " autosaves game frequently, records packets, logonverbose" ),
  1170. entryVrHidden("/noWon", SecretWON, TRUE, " - no WON stuff" ),
  1171. entryVr("/forceLAN", forceLAN, TRUE, " - allow LAN play regardless of version" ),
  1172. entryVrHidden("/noAuth", noAuthorization, TRUE, " - Disables WON Login"),
  1173. entryVrHidden("/shortWon", ShortCircuitWON, TRUE, " - short circuit WON stuff" ),
  1174. #else
  1175. entryVrHidden("/logOff", logEnable, LOG_OFF, " - turns of network logging file"),
  1176. entryVrHidden("/logOn", logEnable, LOG_ON,, " - turns network logging file on"),
  1177. entryVrHidden("/logOnVerbose", logEnable, LOG_VERBOSE, " - turns verbose network logging file on"),
  1178. entryFnParamHidden("/logFilePath",SpecifyLogFilePath, "=filepath.txt"),
  1179. //!!!shortwon in release mode!!! entryVrHidden("/shortWon", ShortCircuitWON, TRUE, " - short circuit WON stuff" ),
  1180. #endif
  1181. #ifdef DEBUG_GAME_STATS
  1182. entryVr("/statLogOn", statLogOn, TRUE, " - generates game stats log file"),
  1183. #endif
  1184. #ifdef GOD_LIKE_SYNC_CHECKING
  1185. entryFnParam("/BryceAndDrewAreGods", syncDumpInit, "=<X>!<Y> X = size of SyncDumpWindow Y = granularity in universe Frames"),
  1186. #endif
  1187. #if NIS_PRINT_INFO
  1188. entryComment("NIS OPTIONS"), //-----------------------------------------------------
  1189. #endif
  1190. #if NIS_TEST
  1191. entryFn("/testNIS" , TestNISSet, " <nisFile> - enables NIS testing mode using [nisFile]."),
  1192. entryFn("/testNISScript", TestNISScriptSet, " <scriptFile> - enables NIS testing mode using [scriptFile]."),
  1193. #endif
  1194. #if NIS_PRINT_INFO
  1195. entryVr("/nisCounter", nisPrintInfo,TRUE, " - display nis time index info by default."),
  1196. entryVr("/nisNoLockout", nisNoLockout, TRUE, " - don't lock out the interface when playing an NIS."),
  1197. #endif
  1198. /*
  1199. entryComment("RECORDED DEMOS"), //-----------------------------------------------------
  1200. entryFnParam("/demoRecord", EnableDemoRecord, " <fileName> - record a demo."),
  1201. entryFnParam("/demoPlay", EnableDemoPlayback, " <fileName> - play a demo."),
  1202. */
  1203. #ifndef HW_Release
  1204. entryFV("/packetRecord", EnablePacketRecord, recordPackets, TRUE, " - record packets of this multiplayer game"),
  1205. entryFV("/packetPlay", EnablePacketPlay, playPackets, TRUE," <fileName> - play back packet recording"),
  1206. #else
  1207. entryFVHidden("/packetRecord", EnablePacketRecord, recordPackets, TRUE, " - record packets of this multiplayer game"),
  1208. entryFVHidden("/packetPlay", EnablePacketPlay, playPackets, TRUE," <fileName> - play back packet recording"),
  1209. #endif
  1210. //entryVr("/compareBigfiles", CompareBigfiles, TRUE, " - file by file, use most recent (bigfile/filesystem)"),
  1211. #if DEM_AUTO_DEMO
  1212. entryVr("/disableAutoDemos", demAutoDemo,FALSE, " - don't automatically play demos."),
  1213. entryFnParam("/autoDemoWait", AutoDemoWaitSet, " <seconds> - time to wait on main screen before starting a demo."),
  1214. #endif
  1215. #if DEM_FAKE_RENDER_SWITCH
  1216. entryVr("/disableFakeRenders", demFakeRenders,FALSE, " - disable feature where playback will try to keep up with recorded demo."),
  1217. #endif
  1218. entryComment("TEXTURES"), //-----------------------------------------------------
  1219. entryVr("/nopal", mainNoPalettes, TRUE, " - disable paletted texture support."),
  1220. /*
  1221. entryVrHidden("/allowPacking", mainAllowPacking, TRUE, " - use the packed textures if available (default)."),
  1222. entryVr("/disablePacking", mainAllowPacking, FALSE, " - don't use the packed textures if available."),
  1223. #ifndef HW_Release
  1224. entryVr("/onlyPacking", mainOnlyPacking, TRUE, " - only display packed textures."),
  1225. #endif
  1226. */
  1227. entryComment("MISC OPTIONS"), //-----------------------------------------------------
  1228. entryVrHidden("/smCentreCamera", smCentreWorldPlane, FALSE, " - centres the SM world plane about 0,0,0 rather than the camera."),
  1229. #if MAIN_Password
  1230. entryFnParam("/password", SetPassword, " <password> - specify password to enable certain features."),
  1231. #endif
  1232. #if RND_PLUG_DISABLEABLE
  1233. entryVr("/noPlug", rndShamelessPlugEnabled, FALSE, " - don't display relic logo on pause."),
  1234. #endif
  1235. entryVrHidden("/closeCaptioned", subCloseCaptionsEnabled, TRUE, " - close captioned for the hearing impared."),
  1236. entryVr("/pilotView", pilotView, TRUE, " - enable pilot view. Focus on single ship and hit Q to toggle."),
  1237. {0, NULL, NULL}
  1238. };
  1239. /*-----------------------------------------------------------------------------
  1240. Command-line parsing functions to display a help message box.
  1241. -----------------------------------------------------------------------------*/
  1242. char *gHelpString;
  1243. BOOL CALLBACK CommandLineFunction(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  1244. {
  1245. switch (uMsg)
  1246. {
  1247. case WM_INITDIALOG:
  1248. SetDlgItemText(hDlg, IDC_CommandLine, gHelpString);
  1249. //... init the edit box
  1250. return(TRUE);
  1251. case WM_COMMAND:
  1252. if (LOWORD(wParam) == IDOK)
  1253. {
  1254. EndDialog(hDlg, 0);
  1255. }
  1256. return(TRUE);
  1257. default:
  1258. break;
  1259. }
  1260. return(FALSE);
  1261. }
  1262. /*-----------------------------------------------------------------------------
  1263. Name : DebugHelpDefault
  1264. Description : Print out command-line usage help to a dialog box
  1265. Inputs : string - the unrecognized command-line switch that causes this help.
  1266. Outputs :
  1267. Return :
  1268. ----------------------------------------------------------------------------*/
  1269. void DebugHelpDefault(char *string)
  1270. {
  1271. sdword index, length;
  1272. //calc length of help string
  1273. length = strlen("Invalid or unrecognised command line option: '%s'\x0d\x0a");
  1274. length += strlen(string);
  1275. for (index = 0; commandOptions[index].parameter; index++)
  1276. {
  1277. if (!bitTest(commandOptions[index].flags, COF_Visible))
  1278. {
  1279. continue;
  1280. }
  1281. if (commandOptions[index].helpString == NULL)
  1282. { //no help string: it's a comment
  1283. length += strlen(commandOptions[index].parameter) + 2;//just length of comment
  1284. }
  1285. else
  1286. { //else it's a real command line option
  1287. length += strlen(commandOptions[index].helpString); //length of help string
  1288. length += strlen(commandOptions[index].parameter) + MCL_IndentSpace;//parameter string
  1289. }
  1290. length += 2; //and a newline
  1291. }
  1292. if ((gHelpString = malloc(length)) == NULL) //allocate string
  1293. {
  1294. MessageBox(NULL, "Cannot allocate memory for help.", "Command-Line Usage", MB_OK | MB_APPLMODAL);
  1295. return;
  1296. }
  1297. //copy all help strings into one
  1298. sprintf(gHelpString, "Invalid or unrecognised command line option: '%s'\x0d\x0a", string);
  1299. for (index = 0; commandOptions[index].parameter; index++)
  1300. {
  1301. if (!bitTest(commandOptions[index].flags, COF_Visible))
  1302. {
  1303. continue;
  1304. }
  1305. if (commandOptions[index].helpString == NULL)
  1306. { //no help string: it's a comment
  1307. strcat(gHelpString, "\x0d\x0a");
  1308. strcat(gHelpString, commandOptions[index].parameter);
  1309. strcat(gHelpString, "\x0d\x0a");
  1310. }
  1311. else
  1312. { //else it's a real command line option
  1313. sprintf(gHelpString + strlen(gHelpString), " %s%s\x0d\x0a", commandOptions[index].parameter, commandOptions[index].helpString);
  1314. // ^ MCL_IndentSpace spaces
  1315. }
  1316. }
  1317. DialogBox(ghInstance, MAKEINTRESOURCE(IDD_CommandLine), NULL, CommandLineFunction);
  1318. free(gHelpString); //done with string, free it
  1319. }
  1320. /*-----------------------------------------------------------------------------
  1321. Name : ProcessCommandLine
  1322. Description : Tokenize and process all defined command-lien flags
  1323. Inputs : commandLine - command-line string, sans executable name
  1324. Outputs : sets command-line switch variables
  1325. Return : void
  1326. Remarks:
  1327. Here are the command-line switches for Homeworld:
  1328. -debug: Enable debug window by setting the DebugWindow flag
  1329. ----------------------------------------------------------------------------*/
  1330. sdword ProcessCommandLine(char *commandLine)
  1331. {
  1332. char *string, *nextString;
  1333. sdword index;
  1334. string = strtok(commandLine, TS_Delimiters); //initial tokenize
  1335. while (string != NULL)
  1336. {
  1337. if (string[0] == '-')
  1338. {
  1339. string[0] = '/';
  1340. }
  1341. for (index = 0; commandOptions[index].parameter; index++)
  1342. {
  1343. if (commandOptions[index].helpString == NULL)
  1344. { //don't compare against comment lines
  1345. continue;
  1346. }
  1347. if (!_stricmp(string, commandOptions[index].parameter))
  1348. { //if this is the correct option
  1349. dbgAssert(commandOptions[index].variableToModify || commandOptions[index].function);
  1350. if (commandOptions[index].variableToModify != NULL)
  1351. { //set a variable if applicable
  1352. *((udword *)(commandOptions[index].variableToModify)) = commandOptions[index].valueToSet;
  1353. }
  1354. if (commandOptions[index].function != NULL)
  1355. { //call the function associated, if applicable
  1356. if (bitTest(commandOptions[index].flags, COF_NextToken))
  1357. { //does the function take next token as a parameter?
  1358. nextString = strtok(NULL, TS_Delimiters);//get next token
  1359. if (nextString == NULL)
  1360. { //if no next token
  1361. break; //print usage
  1362. }
  1363. string = nextString;
  1364. }
  1365. if(!commandOptions[index].function(string))
  1366. {
  1367. //error occured in parsing function
  1368. break;
  1369. }
  1370. }
  1371. goto stringFound;
  1372. }
  1373. }
  1374. DebugHelpDefault(string); //no string found, print help
  1375. return(-1);
  1376. stringFound:;
  1377. string = strtok(NULL, TS_Delimiters); //get next token
  1378. }
  1379. return(OKAY);
  1380. }
  1381. /*-----------------------------------------------------------------------------
  1382. Name : CommandProcess
  1383. Description : processes command messages sent to WindowProc
  1384. Inputs : Same as WindowProc without the message WM_COMMAND integer
  1385. Outputs :
  1386. Return : void
  1387. ----------------------------------------------------------------------------*/
  1388. void CommandProcess(HWND hWnd, WPARAM wParam, LPARAM lParam)
  1389. {
  1390. switch(wParam)
  1391. {
  1392. case CID_ExitError: //error message posted, exit with a message box
  1393. SetWindowPos(hWnd, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
  1394. SWP_NOZORDER | SWP_HIDEWINDOW);
  1395. MessageBox(hWnd, dbgFatalErrorString, "Fatal Error", MB_ICONSTOP | MB_OK);
  1396. PostMessage(hWnd, WM_CLOSE, CID_ExitError, 0);
  1397. break;
  1398. case CID_ExitOK:
  1399. PostMessage(hWnd, WM_CLOSE, CID_ExitOK, 0);
  1400. break;
  1401. }
  1402. }
  1403. /*-----------------------------------------------------------------------------
  1404. Name : mainDevStatsInit
  1405. Description : initialize the devstats table. this table contains features
  1406. that need to be disabled on particular (D3D) devices
  1407. Inputs :
  1408. Outputs :
  1409. Return :
  1410. ----------------------------------------------------------------------------*/
  1411. void mainDevStatsInit(void)
  1412. {
  1413. filehandle handle;
  1414. char string[512];
  1415. crc32 crc;
  1416. udword flags0, flags1, flags2;
  1417. sdword size, index;
  1418. handle = fileOpen("devstats.dat", FF_IgnorePrepend | FF_TextMode | FF_IgnoreBIG);
  1419. for (devTableLength = 0;;)
  1420. {
  1421. if (fileLineRead(handle, string, 511) == FR_EndOfFile)
  1422. {
  1423. break;
  1424. }
  1425. if (string[0] == ';')
  1426. {
  1427. continue;
  1428. }
  1429. if (strlen(string) < 4)
  1430. {
  1431. continue;
  1432. }
  1433. //xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx ...
  1434. sscanf(string, "%X %X %X %X", &crc, &flags0, &flags1, &flags2);
  1435. if (crc != 0)
  1436. {
  1437. devTableLength++;
  1438. }
  1439. }
  1440. fileClose(handle);
  1441. if (devTableLength > 0)
  1442. {
  1443. size = 4 * sizeof(udword) * devTableLength;
  1444. devTable = (udword*)malloc(size);
  1445. if (devTable == NULL)
  1446. {
  1447. dbgFatal(DBG_Loc, "mainDevStatsInit couldn't allocate memory for devTable");
  1448. }
  1449. memset(devTable, 0, size);
  1450. handle = fileOpen("devstats.dat", FF_IgnorePrepend | FF_TextMode | FF_IgnoreBIG);
  1451. for (index = 0;;)
  1452. {
  1453. if (fileLineRead(handle, string, 511) == FR_EndOfFile)
  1454. {
  1455. break;
  1456. }
  1457. if (string[0] == ';')
  1458. {
  1459. continue;
  1460. }
  1461. if (strlen(string) < 4)
  1462. {
  1463. continue;
  1464. }
  1465. //xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx ...
  1466. sscanf(string, "%X %X %X %X", &crc, &flags0, &flags1, &flags2);
  1467. if (crc != 0)
  1468. {
  1469. devTable[index+0] = crc;
  1470. devTable[index+1] = flags0;
  1471. devTable[index+2] = flags1;
  1472. devTable[index+3] = flags2;
  1473. index += 4;
  1474. }
  1475. }
  1476. fileClose(handle);
  1477. }
  1478. }
  1479. /*-----------------------------------------------------------------------------
  1480. Name : mainDevStatsShutdown
  1481. Description : release memory used by the devstats table
  1482. Inputs :
  1483. Outputs :
  1484. Return :
  1485. ----------------------------------------------------------------------------*/
  1486. void mainDevStatsShutdown(void)
  1487. {
  1488. if (devTable != NULL)
  1489. {
  1490. free(devTable);
  1491. devTable = NULL;
  1492. }
  1493. }
  1494. void IntroDeactivateMe(HWND hWnd)
  1495. {
  1496. if (gl95)
  1497. {
  1498. return; //don't allow the program to deactivate under Windows 95
  1499. }
  1500. sounddeactivate(TRUE);
  1501. if (!binkDonePlaying)
  1502. {
  1503. binkPause(TRUE);
  1504. hwSetRes(0, 0, 0);
  1505. }
  1506. if (!noMinimizeAltTab && utyTest(SS2_SystemStarted))
  1507. {
  1508. ShowWindow(hWnd, SW_SHOWMINNOACTIVE);
  1509. }
  1510. wasDemoPlaying = demDemoPlaying; //save demo playback state
  1511. demDemoPlaying = FALSE; //stop the demo playback for now
  1512. #if MAIN_MOUSE_FREE
  1513. if (utySystemStarted)
  1514. {
  1515. utyClipMouse(FALSE);
  1516. }
  1517. #endif
  1518. utyTaskTimerClear(); //clear pending timer ticks
  1519. keyClearAll();
  1520. keyBufferClear();
  1521. systemActive = FALSE;
  1522. }
  1523. void IntroActivateMe(HWND hWnd)
  1524. {
  1525. sounddeactivate(FALSE);
  1526. hwSetRes(-1, -1, -1);
  1527. if (!noMinimizeAltTab && utyTest(SS2_SystemStarted))
  1528. {
  1529. ShowWindow(hWnd, SW_RESTORE);
  1530. }
  1531. demDemoPlaying = wasDemoPlaying; //keep playing demo if it was playing when we minimized
  1532. #if MAIN_MOUSE_FREE
  1533. if (utySystemStarted)
  1534. {
  1535. utyClipMouse(startupClipMouse); //optionally trap the mouse
  1536. }
  1537. #endif
  1538. systemActive = TRUE;
  1539. ShowWindow(hWnd, SW_RESTORE);
  1540. utyForceTopmost(fullScreen);
  1541. ShowCursor(FALSE);
  1542. //make sure that the mouse is rotating properly when we come back
  1543. utyMouseButtonsClear();
  1544. keyClearAll();
  1545. keyBufferClear();
  1546. mrTacticalOverlayState(utyCapsLockToggleState());
  1547. if (!binkDonePlaying)
  1548. {
  1549. binkPause(FALSE);
  1550. }
  1551. }
  1552. /*-----------------------------------------------------------------------------
  1553. Name : DeactivateMe
  1554. Description : deactivates this application and suspends processing
  1555. Inputs : hWnd
  1556. Outputs :
  1557. Return :
  1558. ----------------------------------------------------------------------------*/
  1559. void DeactivateMe(HWND hWnd)
  1560. {
  1561. if (gl95)
  1562. {
  1563. return; //don't allow the program to deactivate under Windows 95
  1564. }
  1565. sounddeactivate(TRUE);
  1566. if (RGL)
  1567. {
  1568. rglFeature(RGL_DEACTIVATE);
  1569. }
  1570. else
  1571. {
  1572. (void)hwActivate(FALSE);
  1573. }
  1574. if (!noMinimizeAltTab && utyTest(SS2_SystemStarted))
  1575. {
  1576. ShowWindow(hWnd, SW_SHOWMINNOACTIVE);
  1577. }
  1578. wasDemoPlaying = demDemoPlaying; //save demo playback state
  1579. demDemoPlaying = FALSE; //stop the demo playback for now
  1580. #if MAIN_MOUSE_FREE
  1581. utyClipMouse(FALSE);
  1582. #endif
  1583. utyTaskTimerClear(); //clear pending timer ticks
  1584. if (multiPlayerGame || noPauseAltTab)
  1585. { //only stop rendering if it's single player
  1586. taskSavePauseStatus();
  1587. taskPause(utyRenderTask);
  1588. taskPause(regTaskHandle);
  1589. }
  1590. else
  1591. {
  1592. taskFreezeAll(); //stop all tasks
  1593. }
  1594. keyClearAll();
  1595. keyBufferClear();
  1596. systemActive = FALSE;
  1597. if (!binkDonePlaying)
  1598. {
  1599. binkPause(TRUE);
  1600. }
  1601. /*
  1602. if (utyTest2(SS2_ToggleKeys))
  1603. {
  1604. utyToggleKeyStatesRestore();
  1605. }
  1606. */
  1607. }
  1608. /*-----------------------------------------------------------------------------
  1609. Name : ActivateMe
  1610. Description : activates this application and resumes processing
  1611. Inputs : hWnd
  1612. Outputs :
  1613. Return :
  1614. ----------------------------------------------------------------------------*/
  1615. void ActivateMe(HWND hWnd)
  1616. {
  1617. sounddeactivate(FALSE);
  1618. if (!noMinimizeAltTab && utyTest(SS2_SystemStarted))
  1619. {
  1620. ShowWindow(hWnd, SW_RESTORE);
  1621. }
  1622. demDemoPlaying = wasDemoPlaying; //keep playing demo if it was playing when we minimized
  1623. if (RGL)
  1624. {
  1625. rglFeature(RGL_ACTIVATE);
  1626. mainReinitRenderer = 2;
  1627. }
  1628. else
  1629. {
  1630. (void)hwActivate(TRUE);
  1631. }
  1632. if (glcActive())
  1633. {
  1634. glcRenderEverythingALot();
  1635. }
  1636. else
  1637. {
  1638. feRenderEverything = TRUE;
  1639. }
  1640. #if MAIN_MOUSE_FREE
  1641. if (utySystemStarted)
  1642. {
  1643. utyClipMouse(startupClipMouse); //optionally trap the mouse
  1644. }
  1645. #endif
  1646. if (utySystemStarted)
  1647. { //if game has started
  1648. taskResumeAll(); //resume all tasks
  1649. }
  1650. systemActive = TRUE;
  1651. ShowWindow(hWnd, SW_RESTORE);
  1652. utyForceTopmost(fullScreen);
  1653. ShowCursor(FALSE);
  1654. //make sure that the mouse is rotating proper when we come back
  1655. utyMouseButtonsClear();
  1656. keyClearAll();
  1657. keyBufferClear();
  1658. hrBackgroundReinit = TRUE;
  1659. /*
  1660. if (utyTest2(SS2_ToggleKeys))
  1661. {
  1662. utyToggleKeyStatesSave();
  1663. }
  1664. */
  1665. mrTacticalOverlayState(utyCapsLockToggleState());
  1666. if (!binkDonePlaying)
  1667. {
  1668. binkPause(FALSE);
  1669. }
  1670. }
  1671. static bool mainFileExists(char* filename)
  1672. {
  1673. FILE* file = fopen(filename, "rb");
  1674. if (file == NULL)
  1675. {
  1676. return FALSE;
  1677. }
  1678. else
  1679. {
  1680. fclose(file);
  1681. return TRUE;
  1682. }
  1683. }
  1684. static bool mainFind3DfxGL(char* path)
  1685. {
  1686. char* dir;
  1687. char subdir[8];
  1688. if (glCapNT())
  1689. {
  1690. strcpy(subdir, "WinNT");
  1691. }
  1692. else
  1693. {
  1694. strcpy(subdir, "Win9x");
  1695. }
  1696. //try cwd\3dfx\opengl32.dll first
  1697. sprintf(path, "3dfx\\%s\\opengl32.dll", subdir);
  1698. if (mainFileExists(path))
  1699. {
  1700. return TRUE;
  1701. }
  1702. //try $HW_Root\dll\opengl32.dll next
  1703. dir = getenv("HW_Root");
  1704. if (dir == NULL)
  1705. {
  1706. //not found, use default opengl
  1707. strcpy(path, "opengl32.dll");
  1708. return FALSE;
  1709. }
  1710. else
  1711. {
  1712. char concatdir[128];
  1713. strcpy(path, dir);
  1714. if (path[strlen(path)-1] == '\\')
  1715. {
  1716. sprintf(concatdir, "dll\\%s\\opengl32.dll", subdir);
  1717. }
  1718. else
  1719. {
  1720. sprintf(concatdir, "\\dll\\%s\\opengl32.dll", subdir);
  1721. }
  1722. strcat(path, concatdir);
  1723. return TRUE;
  1724. }
  1725. }
  1726. /*-----------------------------------------------------------------------------
  1727. Name : mainFreeLibrary
  1728. Description : release references to a given .dll
  1729. Inputs : libname - name of the library
  1730. Outputs :
  1731. Return :
  1732. ----------------------------------------------------------------------------*/
  1733. static void mainFreeLibrary(char* libname)
  1734. {
  1735. HINSTANCE lib;
  1736. lib = GetModuleHandle(libname);
  1737. if (lib != NULL)
  1738. {
  1739. while (FreeLibrary(lib)) ;
  1740. }
  1741. }
  1742. void mainFreeLibraries(void)
  1743. {
  1744. void glCapResetRGLAddresses(void);
  1745. mainFreeLibrary("rglsw.dll");
  1746. mainFreeLibrary("rgld3d.dll");
  1747. mainFreeLibrary("rgl.dll");
  1748. mainFreeLibrary("opengl32.dll");
  1749. mainFreeLibrary("3dfxvgl.dll");
  1750. RGL = FALSE;
  1751. glCapResetRGLAddresses();
  1752. }
  1753. /*-----------------------------------------------------------------------------
  1754. Name : mainRescaleMainWindow
  1755. Description : rescale the main window (ghMainWindow) and call fn to
  1756. reinit game systems that require it
  1757. Inputs :
  1758. Outputs :
  1759. Return :
  1760. ----------------------------------------------------------------------------*/
  1761. void mainRescaleMainWindow(void)
  1762. {
  1763. bool wasClipped;
  1764. mainWindowTotalWidth = MAIN_WindowWidth + mainWidthAdd;
  1765. mainWindowTotalHeight = MAIN_WindowHeight + mainHeightAdd;
  1766. wasClipped = mouseClipped;
  1767. utyClipMouse(FALSE);
  1768. SetWindowPos(ghMainWindow, HWND_TOP,
  1769. 0, 0,
  1770. mainWindowTotalWidth, mainWindowTotalHeight,
  1771. (showBorder) ? SWP_DRAWFRAME : 0);
  1772. if (wasClipped)
  1773. {
  1774. utyClipMouse(TRUE);
  1775. }
  1776. (void)utyChangeResolution(MAIN_WindowWidth, MAIN_WindowHeight, MAIN_WindowDepth);
  1777. }
  1778. /*-----------------------------------------------------------------------------
  1779. Name : mainStartupGL
  1780. Description : startup an OpenGL renderer
  1781. Inputs :
  1782. Outputs :
  1783. Return :
  1784. ----------------------------------------------------------------------------*/
  1785. bool mainStartupGL(char* data)
  1786. {
  1787. rndinitdata renderData;
  1788. mainRescaleMainWindow();
  1789. if (opUsing3DfxGL)
  1790. {
  1791. if (!mainFind3DfxGL(glToSelect))
  1792. {
  1793. memStrncpy(glToSelect, "opengl32.dll", 512 - 1);
  1794. }
  1795. }
  1796. else
  1797. {
  1798. memStrncpy(glToSelect, "opengl32.dll", 512 - 1);
  1799. }
  1800. if (!glCapLoadOpenGL(glToSelect))
  1801. {
  1802. return FALSE;
  1803. }
  1804. mainDeviceToSelect[0] = '\0';
  1805. mainD3DToSelect[0] = '\0';
  1806. memStrncpy(mainGLToSelect, glToSelect, 512 - 1);
  1807. if (!hwCreateWindow((int)ghMainWindow, MAIN_WindowWidth, MAIN_WindowHeight, MAIN_WindowDepth))
  1808. {
  1809. return FALSE;
  1810. }
  1811. renderData.width = MAIN_WindowWidth;
  1812. renderData.height = MAIN_WindowHeight;
  1813. renderData.hWnd = ghMainWindow;
  1814. if (!rndSmallInit(&renderData, TRUE))
  1815. {
  1816. (void)hwDeleteWindow();
  1817. return FALSE;
  1818. }
  1819. if (!glCapValidGL())
  1820. {
  1821. (void)hwDeleteWindow();
  1822. return FALSE;
  1823. }
  1824. utyForceTopmost(fullScreen);
  1825. glCapStartup();
  1826. return TRUE;
  1827. }
  1828. /*-----------------------------------------------------------------------------
  1829. Name : mainMemAlloc
  1830. Description : memory allocation wrapper (for rGL's benefit)
  1831. Inputs : len - amount of memory to allocate (bytes)
  1832. name - name of the memory handle
  1833. flags - flags for allocation, currently ignored
  1834. Outputs :
  1835. Return : pointer to new memory, or NULL if none available
  1836. ----------------------------------------------------------------------------*/
  1837. void* mainMemAlloc(GLint len, char* name, GLuint flags)
  1838. {
  1839. return memAllocAttempt(len, name, NonVolatile | ExtendedPool);
  1840. }
  1841. /*-----------------------------------------------------------------------------
  1842. Name : mainMemFree
  1843. Description : memory free wrapper (for rGL's benefit)
  1844. Inputs : pointer - the memory pointer to free
  1845. Outputs :
  1846. Return :
  1847. ----------------------------------------------------------------------------*/
  1848. void mainMemFree(void* pointer)
  1849. {
  1850. memFree(pointer);
  1851. }
  1852. /*-----------------------------------------------------------------------------
  1853. Name : mainContinueRGL
  1854. Description : set rGL's features
  1855. Inputs :
  1856. Outputs :
  1857. Return :
  1858. ----------------------------------------------------------------------------*/
  1859. void mainContinueRGL(char* data)
  1860. {
  1861. rglSetAllocs((MemAllocFunc)mainMemAlloc, (MemFreeFunc)mainMemFree);
  1862. if (fullScreen)
  1863. {
  1864. rglFeature(RGL_FULLSCREEN);
  1865. }
  1866. else
  1867. {
  1868. rglFeature(RGL_WINDOWED);
  1869. }
  1870. if (mainSoftwareDirectDraw)
  1871. {
  1872. rglFeature(RGL_HICOLOR);
  1873. }
  1874. else
  1875. {
  1876. rglFeature(RGL_TRUECOLOR);
  1877. }
  1878. if (slowBlits)
  1879. {
  1880. rglFeature(RGL_SLOWBLT);
  1881. }
  1882. else
  1883. {
  1884. rglFeature(RGL_FASTBLT);
  1885. }
  1886. if (accelFirst)
  1887. {
  1888. rglSelectDevice("fx", "");
  1889. lodScaleFactor = 1.0f;
  1890. }
  1891. if (deviceToSelect[0] != '\0')
  1892. {
  1893. rglSelectDevice(deviceToSelect, data);
  1894. if (strcmp(deviceToSelect, "sw"))
  1895. {
  1896. lodScaleFactor = 1.0f;
  1897. }
  1898. }
  1899. }
  1900. /*-----------------------------------------------------------------------------
  1901. Name : mainStartupParticularRGL
  1902. Description : startup rGL as a renderer and activate a particular device
  1903. Inputs : device - rGL device name
  1904. Outputs :
  1905. Return :
  1906. ----------------------------------------------------------------------------*/
  1907. bool mainStartupParticularRGL(char* device, char* data)
  1908. {
  1909. rndinitdata renderData;
  1910. mainRescaleMainWindow();
  1911. memStrncpy(glToSelect, "rgl.dll", 512 - 1);
  1912. if (!glCapLoadOpenGL(glToSelect))
  1913. {
  1914. return FALSE;
  1915. }
  1916. memStrncpy(mainDeviceToSelect, device, 16 - 1);
  1917. memStrncpy(mainD3DToSelect, data, 64 - 1);
  1918. memStrncpy(mainGLToSelect, glToSelect, 512 - 1);
  1919. mainContinueRGL(data);
  1920. rglSelectDevice(device, data);
  1921. renderData.width = MAIN_WindowWidth;
  1922. renderData.height = MAIN_WindowHeight;
  1923. renderData.hWnd = ghMainWindow;
  1924. if (!rndSmallInit(&renderData, FALSE))
  1925. {
  1926. return FALSE;
  1927. }
  1928. if (!glCapValidGL())
  1929. {
  1930. return FALSE;
  1931. }
  1932. utyForceTopmost(fullScreen);
  1933. glCapStartup();
  1934. return TRUE;
  1935. }
  1936. /*-----------------------------------------------------------------------------
  1937. Name : mainActiveRenderer
  1938. Description : returns the type of currently active renderer
  1939. Inputs :
  1940. Outputs :
  1941. Return : GLtype, D3Dtype, SWtype, [GLIDEtype]
  1942. ----------------------------------------------------------------------------*/
  1943. sdword mainActiveRenderer(void)
  1944. {
  1945. return RGLtype;
  1946. }
  1947. void mainRegisterClass(HANDLE hInstance)
  1948. {
  1949. WNDCLASS windowClass;
  1950. // set up and register window class
  1951. windowClass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  1952. windowClass.lpfnWndProc = WindowProc;
  1953. windowClass.cbClsExtra = 0;
  1954. windowClass.cbWndExtra = 0;
  1955. windowClass.hInstance = hInstance;
  1956. windowClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
  1957. windowClass.hCursor = NULL;
  1958. windowClass.hbrBackground = GetStockObject(BLACK_BRUSH);
  1959. windowClass.lpszMenuName = NULL;
  1960. windowClass.lpszClassName = classTitle;
  1961. if (!RegisterClass(&windowClass))
  1962. {
  1963. // __asm int 3
  1964. }
  1965. }
  1966. void mainUnregisterClass(HANDLE hInstance)
  1967. {
  1968. if (!UnregisterClass(classTitle, hInstance))
  1969. {
  1970. // __asm int 3
  1971. }
  1972. }
  1973. void mainDestroyWindow(void)
  1974. {
  1975. HWND hWindow;
  1976. mainActuallyQuit = FALSE;
  1977. (void)DestroyWindow(ghMainWindow);
  1978. mainWindowTotalWidth = MAIN_WindowWidth + mainWidthAdd;
  1979. mainWindowTotalHeight = MAIN_WindowHeight + mainHeightAdd;
  1980. if (DebugWindow)
  1981. {
  1982. dbwClose();
  1983. }
  1984. // mainUnregisterClass(ghInstance);
  1985. // mainRegisterClass(ghInstance);
  1986. hWindow = CreateWindow(
  1987. // 0,//WS_EX_TOPMOST,
  1988. classTitle, // class name string
  1989. windowTitle, // title string
  1990. style,
  1991. 0, 0,
  1992. mainWindowTotalWidth,
  1993. mainWindowTotalHeight,
  1994. NULL,
  1995. NULL,
  1996. ghInstance,
  1997. NULL );
  1998. if (hWindow == NULL)
  1999. {
  2000. return;
  2001. }
  2002. ShowWindow(hWindow, 0/*nCmdShow*/);
  2003. utyForceTopmost(fullScreen);
  2004. UpdateWindow(hWindow);
  2005. ghMainWindow = hWindow;
  2006. if (DebugWindow)
  2007. {
  2008. dbwStart((udword)ghInstance, (udword)ghMainWindow);
  2009. }
  2010. }
  2011. /*-----------------------------------------------------------------------------
  2012. Name : mainShutdownGL
  2013. Description : shutdown a GL renderer
  2014. Inputs :
  2015. Outputs :
  2016. Return :
  2017. ----------------------------------------------------------------------------*/
  2018. void mainShutdownGL(void)
  2019. {
  2020. rndClose();
  2021. if (sstLoaded())
  2022. {
  2023. sstShutdown();
  2024. }
  2025. hwDeleteWindow();
  2026. mainDestroyWindow();
  2027. }
  2028. /*-----------------------------------------------------------------------------
  2029. Name : mainShutdownRGL
  2030. Description : shutdown rGL as a renderer
  2031. Inputs :
  2032. Outputs :
  2033. Return :
  2034. ----------------------------------------------------------------------------*/
  2035. void mainShutdownRGL(void)
  2036. {
  2037. rndClose();
  2038. mainDestroyWindow();
  2039. }
  2040. /*-----------------------------------------------------------------------------
  2041. Name : mainResetRender
  2042. Description : inform necessary modules that the renderer is switching
  2043. Inputs :
  2044. Outputs :
  2045. Return :
  2046. ----------------------------------------------------------------------------*/
  2047. void mainResetRender(void)
  2048. {
  2049. glDLLReset();
  2050. rndResetGLState();
  2051. glcRenderEverythingALot();
  2052. feRenderEverything = TRUE;
  2053. frReset();
  2054. ferReset();
  2055. mouseReset();
  2056. feReset();
  2057. if (!reinitInProgress)
  2058. {
  2059. trReload();
  2060. }
  2061. }
  2062. /*-----------------------------------------------------------------------------
  2063. Name : mainCloseRender
  2064. Description : free module textures, call reset render
  2065. Inputs :
  2066. Outputs :
  2067. Return :
  2068. ----------------------------------------------------------------------------*/
  2069. void mainCloseRender(void)
  2070. {
  2071. partShutdown();
  2072. glcFreeTextures();
  2073. ferReset();
  2074. cpTexturesPurge();
  2075. lmFreeTextures();
  2076. cpPreviewImageDelete();
  2077. rndLoadShamelessPlug(FALSE); //shameless plug handles reloading itself
  2078. btgCloseTextures();
  2079. cmCloseTextures();
  2080. rmGUIShutdown();
  2081. mainResetRender();
  2082. if (!reinitInProgress)
  2083. {
  2084. trSetAllPending(FALSE);
  2085. trNoPalShutdown();
  2086. #if TR_ERROR_CHECKING
  2087. if (RGL)
  2088. {
  2089. rglFeature(RGL_TEXTURE_LOG);
  2090. }
  2091. #endif
  2092. }
  2093. }
  2094. /*-----------------------------------------------------------------------------
  2095. Name : mainOpenRender
  2096. Description : call reset render
  2097. Inputs :
  2098. Outputs :
  2099. Return :
  2100. ----------------------------------------------------------------------------*/
  2101. void mainOpenRender(void)
  2102. {
  2103. trNoPalStartup();
  2104. mainResetRender();
  2105. glcLoadTextures();
  2106. rmGUIStartup();
  2107. cmLoadTextures();
  2108. btgLoadTextures();
  2109. lmLoadTextures();
  2110. //shameless plug handles reloading itself
  2111. frReloadGL();
  2112. }
  2113. udword saveRGLtype;
  2114. sdword saveMAIN_WindowWidth;
  2115. sdword saveMAIN_WindowHeight;
  2116. sdword saveMAIN_WindowDepth;
  2117. char saveglToSelect[512];
  2118. char savedeviceToSelect[16];
  2119. char saved3dToSelect[64];
  2120. /*-----------------------------------------------------------------------------
  2121. Name : mainSaveRender
  2122. Description : save current renderer info in case a mode switch doesn't work
  2123. Inputs :
  2124. Outputs :
  2125. Return :
  2126. ----------------------------------------------------------------------------*/
  2127. void mainSaveRender(void)
  2128. {
  2129. saveRGLtype = RGLtype;
  2130. saveMAIN_WindowWidth = MAIN_WindowWidth;
  2131. saveMAIN_WindowHeight = MAIN_WindowHeight;
  2132. saveMAIN_WindowDepth = MAIN_WindowDepth;
  2133. memStrncpy(saveglToSelect, mainGLToSelect, 512 - 1);
  2134. memStrncpy(savedeviceToSelect, mainDeviceToSelect, 16 - 1);
  2135. memStrncpy(saved3dToSelect, mainD3DToSelect, 64 - 1);
  2136. }
  2137. void mainSetupSoftware(void)
  2138. {
  2139. strcpy(glToSelect, "rgl.dll");
  2140. strcpy(mainGLToSelect, "rgl.dll");
  2141. strcpy(deviceToSelect, "sw");
  2142. strcpy(mainDeviceToSelect, "sw");
  2143. strcpy(mainD3DToSelect, "");
  2144. mainWindowWidth = MAIN_WindowWidth = 640;
  2145. mainWindowHeight = MAIN_WindowHeight = 480;
  2146. mainWindowDepth = MAIN_WindowDepth = 16;
  2147. opDeviceIndex = -1;
  2148. gDevcaps = gDevcaps2 = 0;
  2149. }
  2150. /*-----------------------------------------------------------------------------
  2151. Name : mainRestoreSoftware
  2152. Description : load 640x480@16, rGL+software rendering system
  2153. Inputs :
  2154. Outputs :
  2155. Return :
  2156. ----------------------------------------------------------------------------*/
  2157. void mainRestoreSoftware(void)
  2158. {
  2159. mainSetupSoftware();
  2160. mainRescaleMainWindow();
  2161. bMustFree = FALSE;
  2162. if (!mainLoadParticularRGL("sw", ""))
  2163. {
  2164. /*
  2165. MessageBox(NULL,
  2166. "couldn't initialize default rendering system",
  2167. windowTitle, MB_APPLMODAL | MB_OK);
  2168. */
  2169. SetWindowPos(ghMainWindow, NULL, 0, 0, 0, 0,
  2170. SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_HIDEWINDOW);
  2171. MessageBox(ghMainWindow,
  2172. "couldn't initialize default rendering system",
  2173. "Fatal Error", MB_ICONSTOP | MB_OK);
  2174. PostMessage(ghMainWindow, WM_CLOSE, CID_ExitError, 0);
  2175. }
  2176. bMustFree = TRUE;
  2177. }
  2178. /*-----------------------------------------------------------------------------
  2179. Name : mainRestoreRender
  2180. Description : restore saved rendering system (mainSaveRender())
  2181. Inputs :
  2182. Outputs :
  2183. Return :
  2184. ----------------------------------------------------------------------------*/
  2185. void mainRestoreRender(void)
  2186. {
  2187. memStrncpy(glToSelect, saveglToSelect, 512 - 1);
  2188. memStrncpy(mainGLToSelect, saveglToSelect, 512 - 1);
  2189. memStrncpy(deviceToSelect, savedeviceToSelect, 16 - 1);
  2190. memStrncpy(mainDeviceToSelect, savedeviceToSelect, 16 - 1);
  2191. memStrncpy(mainD3DToSelect, saved3dToSelect, 64 - 1);
  2192. mainWindowWidth = MAIN_WindowWidth = saveMAIN_WindowWidth;
  2193. mainWindowHeight = MAIN_WindowHeight = saveMAIN_WindowHeight;
  2194. mainWindowDepth = MAIN_WindowDepth = saveMAIN_WindowDepth;
  2195. mainRescaleMainWindow();
  2196. RGLtype = saveRGLtype;
  2197. bMustFree = FALSE;
  2198. if (RGLtype == GLtype)
  2199. {
  2200. if (!mainLoadGL(NULL))
  2201. {
  2202. //couldn't restore, try basic software
  2203. mainRestoreSoftware();
  2204. }
  2205. }
  2206. else
  2207. {
  2208. if (!mainLoadParticularRGL(savedeviceToSelect, saved3dToSelect))
  2209. {
  2210. //couldn't restore, try basic software
  2211. mainRestoreSoftware();
  2212. }
  2213. }
  2214. bMustFree = TRUE;
  2215. feRenderEverything = TRUE;
  2216. glcRenderEverythingALot();
  2217. }
  2218. /*-----------------------------------------------------------------------------
  2219. Name : mainShutdownRenderer
  2220. Description : shutdown the existing renderer
  2221. Inputs :
  2222. Outputs :
  2223. Return : TRUE or FALSE
  2224. ----------------------------------------------------------------------------*/
  2225. bool mainShutdownRenderer(void)
  2226. {
  2227. dbgMessage("\nmainShutdownRenderer");
  2228. mainCloseRender();
  2229. if (RGLtype == GLtype)
  2230. {
  2231. mainShutdownGL();
  2232. }
  2233. else
  2234. {
  2235. mainShutdownRGL();
  2236. }
  2237. mainFreeLibraries();
  2238. return TRUE;
  2239. }
  2240. /*-----------------------------------------------------------------------------
  2241. Name : mainLoadGL
  2242. Description : close existing renderer, startup a GL
  2243. Inputs : data - possible name of GL .DLL
  2244. Outputs :
  2245. Return :
  2246. ----------------------------------------------------------------------------*/
  2247. bool mainLoadGL(char* data)
  2248. {
  2249. dbgMessage("\n-- load OpenGL --");
  2250. if (bMustFree)
  2251. {
  2252. mainCloseRender();
  2253. if (RGLtype == GLtype)
  2254. {
  2255. mainShutdownGL();
  2256. }
  2257. else
  2258. {
  2259. mainShutdownRGL();
  2260. }
  2261. mainFreeLibraries();
  2262. }
  2263. if (!mainStartupGL(data))
  2264. {
  2265. return FALSE;
  2266. }
  2267. mainOpenRender();
  2268. lodScaleFactor = 1.0f;
  2269. alodStartup();
  2270. return TRUE;
  2271. }
  2272. /*-----------------------------------------------------------------------------
  2273. Name : mainLoadParticularRGL
  2274. Description : close existing render, startup rGL w/ specified device
  2275. Inputs : device - device name {sw, d3d, fx}
  2276. Outputs :
  2277. Return :
  2278. ----------------------------------------------------------------------------*/
  2279. bool mainLoadParticularRGL(char* device, char* data)
  2280. {
  2281. dbgMessagef("\n-- load rGL device %s --", device);
  2282. if (bMustFree)
  2283. {
  2284. mainCloseRender();
  2285. if (RGLtype == GLtype)
  2286. {
  2287. mainShutdownGL();
  2288. }
  2289. else
  2290. {
  2291. mainShutdownRGL();
  2292. }
  2293. mainFreeLibraries();
  2294. }
  2295. if (!mainStartupParticularRGL(device, data))
  2296. {
  2297. return FALSE;
  2298. }
  2299. mainOpenRender();
  2300. lodScaleFactor = (RGLtype == SWtype) ? LOD_ScaleFactor : 1.0f;
  2301. alodStartup();
  2302. mainReinitRenderer = 2;
  2303. return TRUE;
  2304. }
  2305. /*-----------------------------------------------------------------------------
  2306. Name : mainReinitRGL
  2307. Description : reinitializes rGL, currently used to work around a disheartening
  2308. D3D problem wrt alpha textures
  2309. Inputs :
  2310. Outputs :
  2311. Return :
  2312. ----------------------------------------------------------------------------*/
  2313. bool mainReinitRGL(void)
  2314. {
  2315. if (RGLtype != D3Dtype)
  2316. {
  2317. return TRUE;
  2318. }
  2319. reinitInProgress = TRUE;
  2320. // mainCloseRender();
  2321. rglFeature(RGL_REINIT_RENDERER);
  2322. // glCapStartup();
  2323. // mainOpenRender();
  2324. // glCapStartup();
  2325. // lodScaleFactor = (RGLtype == SWtype) ? LOD_ScaleFactor : 1.0f;
  2326. // alodStartup();
  2327. dbgMessage("\n-- reinit rGL --");
  2328. reinitInProgress = FALSE;
  2329. return TRUE;
  2330. }
  2331. /*-----------------------------------------------------------------------------
  2332. Name : keyLanguageTranslate
  2333. Description : This function translates the virtual key into the ASCII character.
  2334. Inputs : virtkey and scancode
  2335. Outputs : converted character
  2336. Return : Uh-huh
  2337. ----------------------------------------------------------------------------*/
  2338. udword keyLanguageTranslate(udword wParam)
  2339. {
  2340. switch (strCurKeyboardLanguage)
  2341. {
  2342. case languageEnglish:
  2343. return(wParam);
  2344. break;
  2345. case languageFrench:
  2346. if (wParam < 256)
  2347. return(keyFrenchToEnglish(wParam));
  2348. else
  2349. return(0);
  2350. break;
  2351. case languageGerman:
  2352. if (wParam < 256)
  2353. return(keyGermanToEnglish(wParam));
  2354. else
  2355. return(0);
  2356. break;
  2357. case languageSpanish:
  2358. if (wParam < 256)
  2359. return(keySpanishToEnglish(wParam));
  2360. else
  2361. return(0);
  2362. break;
  2363. case languageItalian:
  2364. if (wParam < 256)
  2365. return(keyItalianToEnglish(wParam));
  2366. else
  2367. return(0);
  2368. break;
  2369. }
  2370. /* char buff[256], trankey[2];
  2371. sdword i,ret;
  2372. for (i=0;i<256;i++) buff[i] = 0;
  2373. ret = ToAscii(wParam, 0, buff, (uword *)trankey, 0);
  2374. if (ret==0)
  2375. {
  2376. return((udword)wParam);
  2377. }
  2378. else if (ret==1)
  2379. {
  2380. if ((trankey[0] >= 'a') && (trankey[0] <= 'z'))
  2381. {
  2382. trankey[0]-='a'-'A';
  2383. }
  2384. return ((udword)((ubyte)trankey[0]));
  2385. }
  2386. return (0);*/
  2387. }
  2388. /*-----------------------------------------------------------------------------
  2389. Name : WindowProc
  2390. Description : Message handling function for main window
  2391. Inputs : See Windows help.
  2392. Outputs : Ditto
  2393. Return : Uh-huh
  2394. ----------------------------------------------------------------------------*/
  2395. long FAR PASCAL WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
  2396. {
  2397. extern bool utilPlayingIntro;
  2398. #if MAIN_PRINT_MESSAGES
  2399. dbgMessagef("\nMessage = 0x%x, wParam = 0x%x, lParam = 0x%x", message, wParam, lParam);
  2400. #endif //MAIN_PRINT_MESSAGES
  2401. if (message == uHWCloseMsg)
  2402. {
  2403. goto destroy;
  2404. }
  2405. switch( message )
  2406. {
  2407. case WM_SYSCOMMAND:
  2408. if (wParam == SC_SCREENSAVE)
  2409. {
  2410. //render screensavers ineffective
  2411. return 0;
  2412. }
  2413. break;
  2414. case WM_ACTIVATEAPP:
  2415. #if 0
  2416. if (!mainActuallyQuit)
  2417. {
  2418. return 0;
  2419. }
  2420. #endif
  2421. if((bool)wParam && (systemActive == FALSE))
  2422. { //we're being activated
  2423. if (utilPlayingIntro)
  2424. {
  2425. IntroActivateMe(hWnd);
  2426. }
  2427. else
  2428. {
  2429. ActivateMe(hWnd);
  2430. }
  2431. }
  2432. else if (systemActive == TRUE)
  2433. { //we're being deactivated
  2434. if (utilPlayingIntro)
  2435. {
  2436. IntroDeactivateMe(hWnd);
  2437. }
  2438. else
  2439. {
  2440. DeactivateMe(hWnd);
  2441. }
  2442. }
  2443. else
  2444. break;
  2445. return 0; //per documentation
  2446. case WM_KEYUP: //keys up/down
  2447. switch (wParam)
  2448. {
  2449. case VK_ESCAPE:
  2450. if (!binkDonePlaying)
  2451. {
  2452. binkStop();
  2453. }
  2454. else
  2455. {
  2456. keyPressUp(KeyMapFromWindows(wParam));
  2457. }
  2458. #if MAIN_MOUSE_FREE
  2459. case VK_F11: //toggle clipped cursor
  2460. if (keyIsHit(CONTROLKEY))
  2461. {
  2462. utyClipMouse(mouseClipped ^ TRUE);
  2463. }
  2464. else
  2465. {
  2466. keyPressUp(KeyMapFromWindows(wParam));
  2467. }
  2468. break;
  2469. #endif
  2470. case VK_F12:
  2471. if (!RGL)
  2472. {
  2473. if (keyIsHit(SHIFTKEY) && keyIsHit(CONTROLKEY))
  2474. {
  2475. glcFreeTextures();
  2476. mainCloseRender();
  2477. mainShutdownGL();
  2478. mainRestoreSoftware();
  2479. mainOpenRender();
  2480. glCapStartup();
  2481. glcLoadTextures();
  2482. lodScaleFactor = LOD_ScaleFactor;
  2483. alodStartup();
  2484. }
  2485. }
  2486. else
  2487. {
  2488. dbgMessagef("\nprevious GL RENDERER: %s", glGetString(GL_RENDERER));
  2489. if (keyIsHit(SHIFTKEY) && keyIsHit(CONTROLKEY))
  2490. {
  2491. mainCloseRender();
  2492. mainShutdownRGL();
  2493. mainRestoreSoftware();
  2494. }
  2495. else
  2496. {
  2497. break;
  2498. }
  2499. glCapStartup();
  2500. mainOpenRender();
  2501. glCapStartup();
  2502. if (RGLtype == SWtype)
  2503. {
  2504. lodScaleFactor = LOD_ScaleFactor;
  2505. }
  2506. else
  2507. {
  2508. lodScaleFactor = 1.0f;
  2509. }
  2510. alodStartup();
  2511. dbgMessagef("\nnew GL RENDERER: %s", glGetString(GL_RENDERER));
  2512. }
  2513. break;
  2514. default:
  2515. keyPressUp(keyLanguageTranslate(wParam));//keyPressUp(KeyMapFromWindows(wParam));
  2516. }
  2517. return 0;
  2518. case WM_KEYDOWN:
  2519. if (lParam & BIT30)
  2520. { //if it's a repeating key
  2521. //keyRepeat(KeyMapFromWindows(wParam));
  2522. keyRepeat(keyLanguageTranslate(wParam));
  2523. }
  2524. else
  2525. { //else it's a freshly-pressed key
  2526. keyPressDown(keyLanguageTranslate(wParam));
  2527. //keyPressDown(KeyMapFromWindows(wParam));
  2528. }
  2529. return 0;
  2530. case WM_DEADCHAR:
  2531. return 0;
  2532. case WM_SYSKEYUP: //keys up/down
  2533. keyPressUp(keyLanguageTranslate(wParam));
  2534. return 0;
  2535. case WM_SYSKEYDOWN:
  2536. if (lParam & BIT30)
  2537. { //if it's a repeating key
  2538. keyRepeat(keyLanguageTranslate(wParam));
  2539. }
  2540. else
  2541. { //else it's a freshly-pressed key
  2542. keyPressDown(keyLanguageTranslate(wParam));
  2543. }
  2544. return 0;
  2545. case WM_COMMAND:
  2546. CommandProcess(hWnd, wParam, lParam);
  2547. return 0;
  2548. case WM_LBUTTONDBLCLK:
  2549. if (!mouseDisabled)
  2550. {
  2551. keyPressDown(KeyMapFromWindows(LMOUSE_DOUBLE));
  2552. }
  2553. break;
  2554. case WM_LBUTTONDOWN: //mouse buttons up/down
  2555. if (!mouseDisabled)
  2556. {
  2557. mouseLClick();
  2558. keyPressDown(KeyMapFromWindows(VK_LBUTTON));
  2559. }
  2560. break;
  2561. case WM_LBUTTONUP:
  2562. if (!mouseDisabled)
  2563. {
  2564. keyPressUp(KeyMapFromWindows(VK_LBUTTON));
  2565. keyPressUp(KeyMapFromWindows(LMOUSE_DOUBLE));
  2566. }
  2567. break;
  2568. case WM_RBUTTONDBLCLK:
  2569. if (!mouseDisabled)
  2570. {
  2571. keyPressDown(KeyMapFromWindows(RMOUSE_DOUBLE));
  2572. }
  2573. break;
  2574. case WM_RBUTTONDOWN:
  2575. if (!mouseDisabled)
  2576. {
  2577. keyPressDown(KeyMapFromWindows(VK_RBUTTON));
  2578. }
  2579. break;
  2580. case WM_RBUTTONUP:
  2581. if (!mouseDisabled)
  2582. {
  2583. keyPressUp(KeyMapFromWindows(VK_RBUTTON));
  2584. keyPressUp(KeyMapFromWindows(RMOUSE_DOUBLE));
  2585. }
  2586. break;
  2587. case WM_MBUTTONDOWN:
  2588. if (!mouseDisabled)
  2589. {
  2590. keyPressDown(KeyMapFromWindows(VK_MBUTTON));
  2591. }
  2592. break;
  2593. case WM_MBUTTONUP:
  2594. if (!mouseDisabled)
  2595. {
  2596. keyPressUp(KeyMapFromWindows(VK_MBUTTON));
  2597. keyPressUp(KeyMapFromWindows(MMOUSE_DOUBLE));
  2598. }
  2599. break;
  2600. case WM_MBUTTONDBLCLK:
  2601. if (!mouseDisabled)
  2602. {
  2603. keyPressDown(KeyMapFromWindows(MMOUSE_DOUBLE));
  2604. }
  2605. break;
  2606. case WM_DESTROY:
  2607. destroy:
  2608. if (mainActuallyQuit)
  2609. {
  2610. WindowsCleanup();
  2611. PostQuitMessage(0);
  2612. }
  2613. else
  2614. {
  2615. mainActuallyQuit = TRUE;
  2616. }
  2617. return 0;
  2618. case WM_CLOSE:
  2619. if ((wParam != CID_ExitError) && (wParam != CID_ExitOK))
  2620. { //if it's not one of the 'official' exit codes generated by the game
  2621. return 0; //don't let the game shut down by normal windows methods
  2622. }
  2623. break; //else close down as normal
  2624. case WM_ENTERIDLE: //game deactivated due to a pop-up (menu or dialog)
  2625. keyClearAll(); //don't leave any keys stuck in this case
  2626. break;
  2627. case WM_PAINT:
  2628. {
  2629. PAINTSTRUCT ps;
  2630. BeginPaint(hWnd, &ps);
  2631. EndPaint(hWnd, &ps);
  2632. return 0;
  2633. }
  2634. case WM_MOVE:
  2635. WindowTopLeft.x = (int)LOWORD(lParam);
  2636. WindowTopLeft.y = (int)HIWORD(lParam);
  2637. return 0;
  2638. case WM_GETMINMAXINFO:
  2639. {
  2640. RECT windowRect;
  2641. MINMAXINFO *info;
  2642. if (WindowTopLeft.x == -1) //if window hasn't moved yet
  2643. {
  2644. break; //don't force any size restrictions
  2645. }
  2646. info = (MINMAXINFO *)lParam;
  2647. GetWindowRect(ghMainWindow, &windowRect); //get window rect
  2648. info->ptMaxSize.x = mainWindowTotalWidth;
  2649. info->ptMaxSize.y = mainWindowTotalHeight;
  2650. GetSystemMetrics(SM_CYSIZEFRAME) * 2; //GetSystemMetrics( SM_CYSCREEN )
  2651. info->ptMaxPosition.x = windowRect.left; //maximise will not move it
  2652. info->ptMaxPosition.y = windowRect.top;
  2653. info->ptMinTrackSize = info->ptMaxSize; //can't change size
  2654. info->ptMaxTrackSize = info->ptMaxSize;
  2655. return 0;
  2656. }
  2657. case WM_MOUSEWHEEL:
  2658. if (!mouseDisabled)
  2659. {
  2660. if ((short)HIWORD(wParam) < 0)
  2661. keyPressDown(FLYWHEEL_DOWN);
  2662. else
  2663. keyPressDown(FLYWHEEL_UP);
  2664. }
  2665. break;
  2666. case WM_INPUTLANGCHANGE:
  2667. // keyboard locale has changed update settings ...
  2668. strSetCurKeyboard();
  2669. return 0;
  2670. default:
  2671. if (uMSH_MOUSEWHEEL != 0 && message == uMSH_MOUSEWHEEL)
  2672. {
  2673. if ((int)wParam < 0)
  2674. keyPressDown(FLYWHEEL_DOWN);
  2675. else
  2676. keyPressDown(FLYWHEEL_UP);
  2677. break;
  2678. }
  2679. return DefWindowProc(hWnd, message, wParam, lParam);
  2680. }
  2681. return DefWindowProc(hWnd, message, wParam, lParam);
  2682. } // WindowProc
  2683. /*-----------------------------------------------------------------------------
  2684. Name : InitWindow
  2685. Description : Creates and initializes the main game window, whether full-screen or not.
  2686. Inputs :
  2687. hInstance - instance handle for game.
  2688. nCmdShow - run state (minimized etc.)
  2689. Outputs :
  2690. Return : window handle
  2691. ----------------------------------------------------------------------------*/
  2692. static HWND InitWindow( HANDLE hInstance, int nCmdShow )
  2693. {
  2694. HWND hWindow;
  2695. char d3dToSelect[64];
  2696. mainRegisterClass(hInstance);
  2697. /*
  2698. * create a window
  2699. */
  2700. if (fullScreen)
  2701. {
  2702. showBorder = FALSE;
  2703. }
  2704. if (mainAutoRenderer)
  2705. {
  2706. if (selectedRES)
  2707. {
  2708. MAIN_WindowWidth = mainWindowWidth;
  2709. MAIN_WindowHeight = mainWindowHeight;
  2710. MAIN_WindowDepth = mainWindowDepth;
  2711. }
  2712. else
  2713. {
  2714. mainWindowWidth = MAIN_WindowWidth;
  2715. mainWindowHeight = MAIN_WindowHeight;
  2716. mainWindowDepth = MAIN_WindowDepth;
  2717. }
  2718. }
  2719. if (showBorder)
  2720. {
  2721. style = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_EX_TOPMOST;//WS_POPUP,
  2722. mainWidthAdd = GetSystemMetrics(SM_CXSIZEFRAME) * 2;
  2723. mainHeightAdd = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYSIZEFRAME) * 2;
  2724. }
  2725. else
  2726. {
  2727. style = WS_POPUP;
  2728. mainWidthAdd = 0;
  2729. mainHeightAdd = 0;
  2730. }
  2731. if (mainForceSoftware)
  2732. {
  2733. MAIN_WindowWidth = 640;
  2734. MAIN_WindowHeight = 480;
  2735. MAIN_WindowDepth = 16;
  2736. }
  2737. mainWindowTotalWidth = MAIN_WindowWidth + mainWidthAdd;
  2738. mainWindowTotalHeight = MAIN_WindowHeight + mainHeightAdd;
  2739. hWindow = CreateWindow(
  2740. // 0,//WS_EX_TOPMOST,
  2741. classTitle, // class name string
  2742. windowTitle, // title string
  2743. style,
  2744. 0, 0,
  2745. mainWindowTotalWidth,
  2746. mainWindowTotalHeight,
  2747. NULL,
  2748. NULL,
  2749. hInstance,
  2750. NULL );
  2751. if (hWindow == NULL)
  2752. {
  2753. return NULL;
  2754. }
  2755. mainDevStatsInit();
  2756. rinEnumerateDevices();
  2757. d3dToSelect[0] = '\0';
  2758. if (mainAutoRenderer &&
  2759. (strlen(mainGLToSelect) > 0))
  2760. {
  2761. if (selectedDEVICE)
  2762. {
  2763. d3dToSelect[0] = '\0';
  2764. }
  2765. else
  2766. {
  2767. memStrncpy(deviceToSelect, mainDeviceToSelect, 16 - 1);
  2768. memStrncpy(d3dToSelect, mainD3DToSelect, 64 - 1);
  2769. }
  2770. if (!selectedGL)
  2771. {
  2772. memStrncpy(glToSelect, mainGLToSelect, 512 - 1);
  2773. }
  2774. }
  2775. if (opDeviceCRC != rinDeviceCRC())
  2776. {
  2777. opDeviceIndex = -1;
  2778. if (mainAutoRenderer)
  2779. {
  2780. opDeviceCRC = rinDeviceCRC();
  2781. mainForceSoftware = TRUE;
  2782. }
  2783. }
  2784. if (mainForceSoftware)
  2785. {
  2786. strcpy(deviceToSelect, "sw");
  2787. strcpy(mainDeviceToSelect, "sw");
  2788. strcpy(glToSelect, "rgl.dll");
  2789. strcpy(mainGLToSelect, "rgl.dll");
  2790. d3dToSelect[0] = '\0';
  2791. mainD3DToSelect[0] = '\0';
  2792. MAIN_WindowWidth = 640;
  2793. MAIN_WindowHeight = 480;
  2794. MAIN_WindowDepth = 16;
  2795. ShowWindow(hWindow, nCmdShow);
  2796. utyForceTopmost(fullScreen);
  2797. UpdateWindow(hWindow);
  2798. ghMainWindow = hWindow;
  2799. mainRescaleMainWindow();
  2800. opDeviceIndex = -1;
  2801. gDevcaps = gDevcaps2 = 0;
  2802. }
  2803. else
  2804. {
  2805. extern udword loadedDevcaps, loadedDevcaps2;
  2806. //successfully re-using previous device,
  2807. //re-use previous devcaps
  2808. gDevcaps = loadedDevcaps;
  2809. if (gDevcaps == 0xFFFFFFFF)
  2810. {
  2811. gDevcaps = 0;
  2812. }
  2813. gDevcaps2 = loadedDevcaps2;
  2814. if (gDevcaps2 == 0xFFFFFFFF)
  2815. {
  2816. gDevcaps2 = 0;
  2817. }
  2818. }
  2819. if (!glCapLoadOpenGL(glToSelect))
  2820. {
  2821. mainSetupSoftware();
  2822. ShowWindow(hWindow, nCmdShow);
  2823. utyForceTopmost(fullScreen);
  2824. UpdateWindow(hWindow);
  2825. ghMainWindow = hWindow;
  2826. mainRescaleMainWindow();
  2827. if (!glCapLoadOpenGL(glToSelect))
  2828. {
  2829. SetWindowPos(ghMainWindow, NULL, 0, 0, 0, 0,
  2830. SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_HIDEWINDOW);
  2831. MessageBox(ghMainWindow,
  2832. "couldn't initialize default rendering system",
  2833. "Fatal Error", MB_ICONSTOP | MB_OK);
  2834. return NULL;
  2835. }
  2836. }
  2837. memStrncpy(mainDeviceToSelect, deviceToSelect, 16 - 1);
  2838. memStrncpy(mainGLToSelect, glToSelect, 512 - 1);
  2839. glCapStartup();
  2840. if (_stricmp(deviceToSelect, "d3d") == 0)
  2841. {
  2842. mainReinitRenderer = 2;
  2843. }
  2844. if (RGL)
  2845. {
  2846. rglSetAllocs((MemAllocFunc)mainMemAlloc, (MemFreeFunc)mainMemFree);
  2847. if (fullScreen)
  2848. {
  2849. rglFeature(RGL_FULLSCREEN);
  2850. }
  2851. else
  2852. {
  2853. rglFeature(RGL_WINDOWED);
  2854. }
  2855. if (mainSoftwareDirectDraw)
  2856. {
  2857. rglFeature(RGL_HICOLOR);
  2858. }
  2859. else
  2860. {
  2861. rglFeature(RGL_TRUECOLOR);
  2862. }
  2863. if (slowBlits)
  2864. {
  2865. rglFeature(RGL_SLOWBLT);
  2866. }
  2867. else
  2868. {
  2869. rglFeature(RGL_FASTBLT);
  2870. }
  2871. if (accelFirst)
  2872. {
  2873. rglSelectDevice("fx", "");
  2874. lodScaleFactor = 1.0f; //default scale factor is just right for 3dfx
  2875. }
  2876. if (deviceToSelect[0] != '\0')
  2877. {
  2878. rglSelectDevice(deviceToSelect, d3dToSelect);
  2879. if (strcmp(deviceToSelect, "sw"))
  2880. {
  2881. lodScaleFactor = 1.0f;
  2882. }
  2883. }
  2884. }
  2885. else
  2886. {
  2887. lodScaleFactor = 1.0f;
  2888. }
  2889. ShowWindow(hWindow, nCmdShow);
  2890. utyForceTopmost(fullScreen);
  2891. UpdateWindow(hWindow);
  2892. ghMainWindow = hWindow;
  2893. return hWindow;
  2894. } /* doInit */
  2895. /*-----------------------------------------------------------------------------
  2896. Name : WindowsCleanup
  2897. Description : Closes all windows, frees memory etc.
  2898. Inputs : void
  2899. Outputs : ..
  2900. Return : void
  2901. ----------------------------------------------------------------------------*/
  2902. void WindowsCleanup(void)
  2903. {
  2904. utyGameSystemsShutdown();
  2905. if (!RGL)
  2906. {
  2907. hwDeleteWindow();
  2908. }
  2909. rinFreeDevices();
  2910. }
  2911. /*-----------------------------------------------------------------------------
  2912. Name : mainCleanupAfterVideo
  2913. Description : possibly delete main DDraw window after playing an AVI if a renderer
  2914. is about to be initialized that wants to create its own
  2915. Inputs :
  2916. Outputs :
  2917. Return :
  2918. ----------------------------------------------------------------------------*/
  2919. void mainCleanupAfterVideo(void)
  2920. {
  2921. if (windowNeedsDeleting)
  2922. {
  2923. windowNeedsDeleting = FALSE;
  2924. //restore previous display mode
  2925. hwSetRes(0, 0, 0);
  2926. }
  2927. if (!RGL)
  2928. {
  2929. //create a window at appropriate res
  2930. (void)hwCreateWindow((int)ghMainWindow, MAIN_WindowWidth, MAIN_WindowHeight, MAIN_WindowDepth);
  2931. }
  2932. }
  2933. void RunPatcher(void)
  2934. {
  2935. DeactivateMe(ghMainWindow);
  2936. WinExec(PATCHNAME,SW_NORMAL);
  2937. // WindowsCleanup();
  2938. //PostQuitMessage(0);
  2939. }
  2940. /*-----------------------------------------------------------------------------
  2941. Name : WinMain
  2942. Description : Entry point to the game
  2943. Inputs :
  2944. hInstance - instance handle for application
  2945. hPrevInstance - warning! does nothing under Win32!
  2946. commandLine - un-tokenized command line string
  2947. nCmdShow - run state (minimized etc.)
  2948. Outputs :
  2949. Return : Exit code (Windows provides an intelligible number)
  2950. ----------------------------------------------------------------------------*/
  2951. int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  2952. LPSTR commandLine, int nCmdShow)
  2953. {
  2954. static MSG message;
  2955. static char *errorString = NULL;
  2956. static HWND hWnd;
  2957. static HANDLE hMapping;
  2958. static BOOL preInit;
  2959. //check to see if a copy of the program already running and just exit if so.
  2960. //This messy hack is required because hPrevInstance is not reliable under Win32.
  2961. hMapping = CreateFileMapping( (HANDLE) 0xffffffff,
  2962. NULL,
  2963. PAGE_READONLY,
  2964. 0,
  2965. 32,
  2966. "LSMap" );
  2967. if( hMapping )
  2968. {
  2969. if( GetLastError() == ERROR_ALREADY_EXISTS )
  2970. {
  2971. HWND hWndPrev;
  2972. // Already an instance running. If it has a window yet, restore it.
  2973. hWndPrev = FindWindow(windowTitle, NULL);
  2974. if (hWndPrev)
  2975. {
  2976. OutputDebugString("\r\nProgram already running.\r\n");
  2977. ShowWindow(hWndPrev, SW_RESTORE);
  2978. BringWindowToTop(hWndPrev);
  2979. UpdateWindow(hWndPrev);
  2980. }
  2981. return 0;
  2982. }
  2983. }
  2984. /*
  2985. if (strlen(leakString) != MAX_LEAK_STRING_LENGTH)
  2986. { // leakstring has not been plugged by the Fat-Assed plumber program
  2987. sdword index;
  2988. time_t tt;
  2989. index = time(&tt) % 5 + 3;
  2990. while (index--)
  2991. {
  2992. MessageBox(NULL, "The Executable is possibly corrupt. Please re-install Homeworld. Execution may FAIL!", "Faucet Error", MB_ABORTRETRYIGNORE);
  2993. }
  2994. }
  2995. */
  2996. uHWCloseMsg = RegisterWindowMessage("CloseHomeworld");
  2997. ghInstance = hInstance;
  2998. mainDeviceToSelect[0] = '\0';
  2999. //load in options from the options file
  3000. utyOptionsFileRead();
  3001. //copy keyboard redefinitions
  3002. opKeyboardLoad();
  3003. RegisterCommandLine(commandLine); // make sure you call this before ProcessCommandLine because
  3004. // ProcessCommandLine modifies commandLine
  3005. //process the command line, setting flags to be used later
  3006. if (ProcessCommandLine(commandLine) != OKAY)
  3007. {
  3008. return 0;
  3009. }
  3010. glNT = glCapNT();
  3011. gl95 = glCap95();
  3012. if (selectedRES)
  3013. {
  3014. MAIN_WindowWidth = mainWindowWidth;
  3015. MAIN_WindowHeight = mainWindowHeight;
  3016. MAIN_WindowDepth = mainWindowDepth;
  3017. }
  3018. #if MAIN_Password
  3019. if ((errorString = mainPasswordVerify(mainPasswordPtr)) != NULL)
  3020. {
  3021. MessageBox(NULL, errorString, "Homeworld Run-Time Error", MB_OK);
  3022. return 0;
  3023. }
  3024. #endif
  3025. //initial game systems startup
  3026. preInit = FALSE;
  3027. if (errorString == NULL)
  3028. {
  3029. errorString = utyGameSystemsPreInit();
  3030. }
  3031. //startup the game window
  3032. if (errorString == NULL)
  3033. {
  3034. if (DebugWindow)
  3035. {
  3036. dbwClose();
  3037. }
  3038. preInit = TRUE;
  3039. if ((hWnd = InitWindow(hInstance, nCmdShow)) == NULL)
  3040. {
  3041. errorString = ersWindowInit;
  3042. }
  3043. if (DebugWindow)
  3044. {
  3045. dbwStart((udword)ghInstance, (udword)ghMainWindow);
  3046. utySet(SSA_DebugWindow);
  3047. }
  3048. }
  3049. mainPlayAVIs = FALSE;
  3050. if (errorString == NULL)
  3051. {
  3052. #ifndef Downloadable
  3053. if (enableAVI && fullScreen)
  3054. {
  3055. windowNeedsDeleting = TRUE;
  3056. //set display mode
  3057. if (!hwSetRes(640, 480, 32))
  3058. {
  3059. hwSetRes(640, 480, 16);
  3060. }
  3061. utyForceTopmost(TRUE);
  3062. }
  3063. else if (!RGL)
  3064. {
  3065. windowNeedsDeleting = FALSE;
  3066. (void)hwCreateWindow((int)ghMainWindow, MAIN_WindowWidth, MAIN_WindowHeight, MAIN_WindowDepth);
  3067. utyForceTopmost(fullScreen);
  3068. }
  3069. #else
  3070. windowNeedsDeleting = FALSE;
  3071. (void)hwCreateWindow((int)ghMainWindow, MAIN_WindowWidth, MAIN_WindowHeight, MAIN_WindowDepth);
  3072. utyForceTopmost(fullScreen);
  3073. #endif
  3074. //startup game systems
  3075. if (errorString == NULL)
  3076. {
  3077. errorString = utyGameSystemsInit();
  3078. }
  3079. }
  3080. if (errorString == NULL)
  3081. {
  3082. preInit = FALSE;
  3083. uMSH_MOUSEWHEEL = RegisterWindowMessage(MSH_MOUSEWHEEL);
  3084. while(TRUE)
  3085. {
  3086. // Give sound a break :)
  3087. Sleep(0);
  3088. if(PeekMessage(&message, NULL, 0, 0, PM_NOREMOVE))
  3089. {
  3090. if(!GetMessage(&message, NULL, 0, 0))
  3091. break;
  3092. TranslateMessage(&message);
  3093. DispatchMessage(&message);
  3094. }
  3095. else
  3096. {
  3097. utyTasksDispatch(); //execute all tasks
  3098. }
  3099. if (opTimerActive)
  3100. {
  3101. if (taskTimeElapsed > (opTimerStart + opTimerLength))
  3102. {
  3103. opTimerExpired();
  3104. }
  3105. }
  3106. if (patchComplete)
  3107. {
  3108. RunPatcher();
  3109. patchComplete = 0;
  3110. }
  3111. }
  3112. }
  3113. else
  3114. { //some error on startup, either from preInit or Init()
  3115. if (preInit)
  3116. {
  3117. (void)utyGameSystemsPreShutdown();
  3118. }
  3119. MessageBox(NULL, errorString, windowTitle, MB_APPLMODAL|MB_OK);
  3120. return ERR_ErrorStart;
  3121. }
  3122. return message.wParam;
  3123. } /* WinMain */