| 105 | } |
| 106 | |
| 107 | void Init() |
| 108 | { |
| 109 | CIniReader iniReader(""); |
| 110 | Screen.nWidth = iniReader.ReadInteger("MAIN", "ResX", 0); |
| 111 | Screen.nHeight = iniReader.ReadInteger("MAIN", "ResY", 0); |
| 112 | bool bFixHud = iniReader.ReadInteger("MAIN", "FixHud", 1) != 0; |
| 113 | |
| 114 | if (!Screen.nWidth || !Screen.nHeight) |
| 115 | std::tie(Screen.nWidth, Screen.nHeight) = GetDesktopRes(); |
| 116 | |
| 117 | auto pattern1 = hook::pattern("68 ? ? ? ? 6A 01 68 ? ? ? ? 68 ? ? ? ? FF D6"); |
| 118 | auto pattern2 = hook::pattern("C6 05 ? ? ? ? 01 C7 05 ? ? ? ? 01 00 00 00"); |
| 119 | static auto dword_6CACDC = *hook::get_pattern<int32_t*>("C7 05 ? ? ? ? 00 04 00 00 C7 05 ? ? ? ? 00 03 00 00", 2); |
| 120 | static auto dword_6CACE0 = *hook::get_pattern<int32_t*>("C7 05 ? ? ? ? 00 04 00 00 C7 05 ? ? ? ? 00 03 00 00", 12); |
| 121 | struct ResHook |
| 122 | { |
| 123 | void operator()(injector::reg_pack& regs) |
| 124 | { |
| 125 | *dword_6CACDC = Screen.nWidth; |
| 126 | *dword_6CACE0 = Screen.nHeight; |
| 127 | |
| 128 | Screen.fWidth = static_cast<float>(Screen.nWidth); |
| 129 | Screen.fHeight = static_cast<float>(Screen.nHeight); |
| 130 | Screen.fAspectRatio = Screen.fWidth / Screen.fHeight; |
| 131 | Screen.nWidth43 = static_cast<uint32_t>(Screen.fHeight * (4.0f / 3.0f)); |
| 132 | Screen.fWidth43 = static_cast<float>(Screen.nWidth43); |
| 133 | Screen.fHudOffset = ((480.0f * Screen.fAspectRatio) - 640.0f) / 2.0f; |
| 134 | Screen.fHudOffsetReal = (Screen.fWidth - Screen.fHeight * (4.0f / 3.0f)) / 2.0f; |
| 135 | Screen.fHudScale = 1.0f / (((4.0f / 3.0f)) / (Screen.fAspectRatio)); |
| 136 | Screen.nAspectRatioDiff = static_cast<int32_t>(Screen.fWidth / (((4.0f / 3.0f)) / (Screen.fAspectRatio))); |
| 137 | } |
| 138 | }; injector::MakeInline<ResHook>(pattern1.count(3).get(2).get<void>(0), pattern2.count(2).get(1).get<void>(0)); //0x40DD33, 0x40DE21 |
| 139 | |
| 140 | //forcing 4:3 aspect, maybe better to hook sub_4BC320 |
| 141 | auto pattern = hook::pattern("A3 ? ? ? ? A1 ? ? ? ? 85 C0 0F 84 ? ? ? ? 6A 01"); |
| 142 | injector::MakeNOP(pattern.get_first(0), 5, true); |
| 143 | injector::WriteMemory(pattern2.count(2).get(1).get<uint32_t>(13), 0, true); |
| 144 | injector::WriteMemory(*pattern2.count(2).get(1).get<uint32_t>(9), 0, true); |
| 145 | |
| 146 | pattern = hook::pattern("05 94 00 00 00 D9 5C 24 08"); |
| 147 | struct AspectHook |
| 148 | { |
| 149 | void operator()(injector::reg_pack& regs) |
| 150 | { |
| 151 | regs.eax += 0x94; |
| 152 | *(int32_t*)(regs.eax - 0x4C) = Screen.nAspectRatioDiff; |
| 153 | } |
| 154 | }; injector::MakeInline<AspectHook>(pattern.get_first(0)); //0x41F45A |
| 155 | |
| 156 | if (bFixHud) |
| 157 | { |
| 158 | pattern = hook::pattern("E8 ? ? ? ? 83 C4 30 5F 5E 5B 8B E5 5D C3"); //0x57A783 |
| 159 | hb_538E80.fun = injector::MakeCALL(pattern.get_first(0), sub_538E80, true).get(); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | CEXP void InitializeASI() |
| 164 | { |
nothing calls this directly
no test coverage detected