Skip to content
Beta: this is a preview of the new SplitScreen.Me. Data may be reset before launch.

OpenTTD · handler “OpenTTD”

Version 1

Release notes

Transport Tycoon Deluxe, open source. Game available on: www.openttd.org

Released
Size
2.4 KB
Downloads
22
Check
Verified
SHA-256
d11b5ea0625300509b333fcd1a2b83389821b7bfc2427afd4d465424620dedbd
Download v1 (.nc)All versions

Files 1

PathSize
handler.js8.3 KB

handler.js

Plain text
Hub.Handler.Version = 1; // Released at https://hub.splitscreen.me/ on Fri Jun 28 2024 21:57:38 GMT+0000 (Coordinated Universal Time).
Hub.Handler.Id = "MYutujfMT93Duiriz";
Hub.Maintainer.Name = "messenils";
Hub.Maintainer.Id = "5NNQPxAD7mmwGuvKp";

var answers1 = ["ONE", "ALL", "NONE"];
Game.AddOption("Music", "How many instances play music.", "Music", answers1);
var answers2 = ["60", "0", "10", "20", "30", "40", "50", "70", "80", "90", "100"];
Game.AddOption("Music Volume", "music volume.", "Volume", answers2);
var answers3 = ["100", "0", "10", "20", "30", "40", "50", "60", "70", "80", "90"];
Game.AddOption("Sound Volume", "sound volume.", "SFVolume", answers3);
var answers4 = ["No Change", "75", "100", "125", "150", "175", "200", "225", "250", "275", "300", "325", "350", "375", "400"];
Game.AddOption("Interface size", "recommend from 150 to 300 depending on screen size", "Interface", answers4);

Game.SupportsMultipleKeyboardsAndMice = true;

//Game files
Game.HandlerInterval = 100;
Game.SymlinkExe = false;
Game.SymlinkGame = true;
Game.SymlinkFolders = true;
Game.ExecutableName = "openttd.exe";
Game.GUID = "OpenTTD";
Game.GameName = "OpenTTD";
Game.MaxPlayers = 16;
Game.MaxPlayersOneMonitor = 8;

//Window
Game.Hook.ForceFocus = true;
Game.Hook.ForceFocusWindowName = "OpenTTD";
Game.HasDynamicWindowTitle = true;
Game.WindowStyleEndChanges = ["~0xC00000", "0x8000000"];
Game.RefreshWindowAfterStart = true;
Game.ToggleUnfocusOnInputsLock = true;
Game.SetTopMostAtEnd = true;

//Environment
Game.UseNucleusEnvironment = true;
Game.DocumentsConfigPath = "OpenTTD";

//Controllers
Game.Hook.DInputEnabled = false;
Game.Hook.XInputEnabled = false;
Game.Hook.XInputReroute = false;
Game.Hook.CustomDllEnabled = false;

//Description
Game.Description =
  "Handler for OpenTTD: https://www.openttd.org/. Keyboards/mice only. After all the instances have launched, resized and positioned correctly, press the END key once to lock the input for all instances to have their own working cursor, you need to left click each mouse to make the emulated cursors appear after locking the input. Press the END key again to unlock the input when you finish playing.";

//USS deprecated options:
Game.HookSetCursorPos = false;
Game.HookGetCursorPos = false;
Game.HookGetKeyState = false;
Game.HookGetAsyncKeyState = false;
Game.HookGetKeyboardState = false;
Game.HookFilterRawInput = false;
Game.HookFilterMouseMessages = false;
Game.HookUseLegacyInput = false;
Game.HookDontUpdateLegacyInMouseMsg = false;
Game.HookMouseVisibility = false;
Game.InjectHookXinput = false;
Game.SendNormalMouseInput = false;
Game.SendNormalKeyboardInput = false;
Game.SendScrollWheel = false;
Game.ForwardRawKeyboardInput = false;
Game.ForwardRawMouseInput = false;
Game.HookReRegisterRawInput = false;
Game.HookReRegisterRawInputMouse = false;
Game.HookReRegisterRawInputKeyboard = false;
Game.DrawFakeMouseCursor = false;
Game.LockInputAtStart = false;

//ProtoInput
Game.ProtoInput.AutoHideTaskbar = true;
Game.LockInputSuspendsExplorer = true;
Game.ProtoInput.FreezeExternalInputWhenInputNotLocked = false;
Game.ProtoInput.InjectStartup = false;
Game.ProtoInput.InjectRuntime_RemoteLoadMethod = false;
Game.ProtoInput.InjectRuntime_EasyHookMethod = false; // Usually this works best
Game.ProtoInput.InjectRuntime_EasyHookStealthMethod = true;
Game.ProtoInput.RegisterRawInputHook = true;
Game.ProtoInput.GetRawInputDataHook = true;
Game.ProtoInput.RawInputFilter = true;
Game.ProtoInput.MessageFilterHook = true;
Game.ProtoInput.GetCursorPosHook = true;
Game.ProtoInput.SetCursorPosHook = true;
Game.ProtoInput.GetKeyStateHook = true;
Game.ProtoInput.GetAsyncKeyStateHook = true;
Game.ProtoInput.GetKeyboardStateHook = true;
Game.ProtoInput.CursorVisibilityHook = true;
Game.ProtoInput.ClipCursorHook = true;
Game.ProtoInput.ClipCursorHookCreatesFakeClip = false;
Game.ProtoInput.AllowFakeCursorOutOfBounds = false;
Game.ProtoInput.FocusHooks = true;
Game.ProtoInput.DrawFakeCursor = false;
Game.ProtoInput.MouseMoveFilter = false;
Game.ProtoInput.MouseActivateFilter = true;
Game.ProtoInput.WindowActivateFilter = true;
Game.ProtoInput.WindowActvateAppFilter = true;
Game.ProtoInput.MouseWheelFilter = true;
Game.ProtoInput.MouseButtonFilter = true;
Game.ProtoInput.KeyboardButtonFilter = true;
Game.ProtoInput.SendMouseWheelMessages = true;
Game.ProtoInput.SendMouseButtonMessages = true;
Game.ProtoInput.SendMouseMovementMessages = true;
Game.ProtoInput.SendKeyboardButtonMessages = true;
Game.ProtoInput.XinputHook = false;
Game.ProtoInput.UseDinputRedirection = false;
Game.ProtoInput.UseOpenXinput = false;
Game.ProtoInput.DinputDeviceHook = false;
Game.ProtoInput.DinputHookAlsoHooksGetDeviceState = false;
Game.ProtoInput.EnableFocusMessageLoop = false;
Game.ProtoInput.FocusLoopIntervalMilliseconds = 5;
Game.ProtoInput.FocusLoop_WM_ACTIVATE = false;
Game.ProtoInput.FocusLoop_WM_ACTIVATEAPP = false;
Game.ProtoInput.FocusLoop_WM_NCACTIVATE = false;
Game.ProtoInput.FocusLoop_WM_SETFOCUS = false;
Game.ProtoInput.FocusLoop_WM_MOUSEACTIVATE = false;
Game.ProtoInput.WindowActivateFilter = false; // Filters take priority over blocks, so disable the filter
Game.ProtoInput.BlockedMessages = [0x0008, 0x2a3]; // Blocks WM_KILLFOCUS //WM_MOUSELEAVE

Game.PauseBetweenContextAndLaunch = 2;
Game.PauseBetweenProcessGrab = 5;
Game.PauseBetweenStarts = 10;

Game.Play = function() {
  var music = Context.Options["Music"];
  var volume = Context.Options["Volume"];
  var sfvolume = Context.Options["SFVolume"];
  var interface = Context.Options["Interface"];
  var txtPath = Context.EnvironmentPlayer + "\\Documents\\OpenTTD\\openttd.cfg";
  var dict = [
    Context.FindLineNumberInTextFile(txtPath, "resolution = ", Nucleus.SearchType.StartsWith) + "|resolution = " + Context.Width + "," + Context.Height,
    Context.FindLineNumberInTextFile(txtPath, "fullscreen = ", Nucleus.SearchType.StartsWith) + "|fullscreen = false",
    Context.FindLineNumberInTextFile(txtPath, "video_vsync = ", Nucleus.SearchType.StartsWith) + "|video_vsync = true",
    Context.FindLineNumberInTextFile(txtPath, "effect_vol = ", Nucleus.SearchType.StartsWith) + "|effect_vol = " + sfvolume
  ];
  Context.ReplaceLinesInTextFile(txtPath, dict);
  if (music == "ONE") {
    if (Context.PlayerID == 0) {
      var dict = [Context.FindLineNumberInTextFile(txtPath, "music_vol = ", Nucleus.SearchType.StartsWith) + "|music_vol = " + volume];
      Context.ReplaceLinesInTextFile(txtPath, dict);
    }
    if (Context.PlayerID > 0) {
      var dict = [Context.FindLineNumberInTextFile(txtPath, "music_vol = ", Nucleus.SearchType.StartsWith) + "|music_vol = 0"];
      Context.ReplaceLinesInTextFile(txtPath, dict);
    }
  }
  if (music == "ALL") {
    var dict = [Context.FindLineNumberInTextFile(txtPath, "music_vol = ", Nucleus.SearchType.StartsWith) + "|music_vol = " + volume];
    Context.ReplaceLinesInTextFile(txtPath, dict);
  }
  if (music == "NONE") {
    var dict = [Context.FindLineNumberInTextFile(txtPath, "music_vol = ", Nucleus.SearchType.StartsWith) + "|music_vol = 0"];
    Context.ReplaceLinesInTextFile(txtPath, dict);
  }
  if (interface != "No Change") {
    var dict = [Context.FindLineNumberInTextFile(txtPath, "gui_scale = ", Nucleus.SearchType.StartsWith) + "|gui_scale = " + interface];
    Context.ReplaceLinesInTextFile(txtPath, dict);
  }
  var txtPath = Context.EnvironmentPlayer + "\\Documents\\OpenTTD\\private.cfg";
  var dict = [
    Context.FindLineNumberInTextFile(txtPath, "client_name = ", Nucleus.SearchType.StartsWith) + "|client_name = " + Context.Nickname,
    Context.FindLineNumberInTextFile(txtPath, "server_name = ", Nucleus.SearchType.StartsWith) + "|server_name = nucleus server",
    Context.FindLineNumberInTextFile(txtPath, "connect_to_ip = ", Nucleus.SearchType.StartsWith) + "|connect_to_ip = 127.0.0.1",
    Context.FindLineNumberInTextFile(txtPath, "last_joined = ", Nucleus.SearchType.StartsWith) + "|last_joined = 127.0.0.1"
  ];
  Context.ReplaceLinesInTextFile(txtPath, dict);

  Game.ProtoInput.OnInputLocked = function() {
    for (var i = 0; i < PlayerList.Count; i++) {
      var player = PlayerList[i];
      ProtoInput.StartFocusMessageLoop(player.ProtoInputInstanceHandle, 0, true, true, true, true, true);
      System.Threading.Thread.Sleep(1000);
      ProtoInput.StopFocusMessageLoop(player.ProtoInputInstanceHandle);
    }
  };
};