You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

342 lines
8.9 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
  1. diff -uarN jcgo_Out/GameShll.c jcgo_Out_Patched/GameShll.c
  2. --- jcgo_Out/GameShll.c 2021-07-17 14:14:57.909182969 -0500
  3. +++ jcgo_Out_Patched/GameShll.c 2021-07-17 14:14:38.724958991 -0500
  4. @@ -12,6 +12,128 @@
  5. #include "jcgobchk.h"
  6. #endif
  7. +#include <stdio.h>
  8. +
  9. +void get_keycodes(jchar* charCode, jint* code) {
  10. + switch (event.key.keysym.scancode) {
  11. + case SDL_SCANCODE_LEFT:
  12. + *code = 37;
  13. + *charCode = 65535;
  14. + break;
  15. + case SDL_SCANCODE_RIGHT:
  16. + *code = 39;
  17. + *charCode = 65535;
  18. + break;
  19. + case SDL_SCANCODE_UP:
  20. + *code = 38;
  21. + *charCode = 65535;
  22. + break;
  23. + case SDL_SCANCODE_DOWN:
  24. + *code = 40;
  25. + *charCode = 65535;
  26. + break;
  27. + default:
  28. + *charCode = event.key.keysym.sym;
  29. + const char* keyName = SDL_GetKeyName(event.key.keysym.sym);
  30. +
  31. + if (strlen(keyName) == 1) {
  32. + *code = keyName[0];
  33. + } else {
  34. + *code = *charCode;
  35. + }
  36. +
  37. + // absolutely dumb hack but i don't want to use SDL's textinput
  38. + if (event.key.keysym.mod & KMOD_SHIFT) {
  39. + if (*charCode >= 'a' && *charCode <= 'z') {
  40. + *charCode -= 32;
  41. + } else {
  42. + switch (*charCode) {
  43. + case ';':
  44. + *charCode = ':';
  45. + break;
  46. + case '`':
  47. + *charCode = '~';
  48. + break;
  49. + case '1':
  50. + *charCode = '!';
  51. + break;
  52. + case '2':
  53. + *charCode = '@';
  54. + break;
  55. + case '3':
  56. + *charCode = '#';
  57. + break;
  58. + case '4':
  59. + *charCode = '$';
  60. + break;
  61. + case '5':
  62. + *charCode = '%';
  63. + break;
  64. + case '6':
  65. + *charCode = '^';
  66. + break;
  67. + case '7':
  68. + *charCode = '&';
  69. + break;
  70. + case '8':
  71. + *charCode = '*';
  72. + break;
  73. + case '9':
  74. + *charCode = '(';
  75. + break;
  76. + case '0':
  77. + *charCode = ')';
  78. + break;
  79. + case '-':
  80. + *charCode = '_';
  81. + break;
  82. + case '=':
  83. + *charCode = '+';
  84. + break;
  85. + }
  86. + }
  87. + }
  88. + break;
  89. + }
  90. +}
  91. +
  92. +void handle_sdl_events(package_GameShell This) {
  93. + while (SDL_PollEvent(&event)) {
  94. + switch (event.type) {
  95. + case SDL_QUIT:
  96. + exit(0);
  97. + break;
  98. + case SDL_KEYDOWN: {
  99. + jchar charCode;
  100. + jint code;
  101. + get_keycodes(&charCode, &code);
  102. + (package_GameShell__keyPressed__CI(This, code, charCode));
  103. + break;
  104. + }
  105. + case SDL_KEYUP: {
  106. + jchar charCode;
  107. + jint code;
  108. + get_keycodes(&charCode, &code);
  109. + (package_GameShell__keyReleased__I(This, code));
  110. + break;
  111. + }
  112. + case SDL_MOUSEMOTION:
  113. + (package_GameShell__mouseMoved__II(This, event.motion.x, event.motion.y));
  114. + break;
  115. + case SDL_MOUSEBUTTONDOWN: {
  116. + jint button = event.button.button == 3 ? 2 : 1;
  117. + (package_GameShell__mousePressed__III(This, event.button.x, event.button.y,
  118. + button));
  119. + break;
  120. + }
  121. + case SDL_MOUSEBUTTONUP:
  122. + (package_GameShell__mouseReleased__II(This, event.button.x,
  123. + event.button.y));
  124. + break;
  125. + }
  126. + }
  127. +}
  128. +
  129. JCGO_NOSEP_INLINE void CFASTCALL
  130. package_GameShell__keyPressed__CI( package_GameShell This, jint code,
  131. jchar chr )
  132. @@ -398,8 +520,25 @@
  133. {
  134. {
  135. ;
  136. - JCGO_FIELD_NZACCESS(This, appletWidth)= (jint)512;
  137. - JCGO_FIELD_NZACCESS(This, appletHeight)= (jint)344;
  138. + jint width;
  139. + jint height;
  140. + char* env_width = getenv("MUDCLIENT_WIDTH");
  141. + char* env_height = getenv("MUDCLIENT_HEIGHT");
  142. +
  143. + if (env_width) {
  144. + width = atoi(env_width);
  145. + } else {
  146. + width = 512;
  147. + }
  148. +
  149. + if (env_height) {
  150. + height = atoi(env_height);
  151. + } else {
  152. + height = 344;
  153. + }
  154. +
  155. + JCGO_FIELD_NZACCESS(This, appletWidth)= (jint)width;
  156. + JCGO_FIELD_NZACCESS(This, appletHeight)= (jint)height;
  157. JCGO_FIELD_NZACCESS(This, targetFps)= (jint)20;
  158. JCGO_FIELD_NZACCESS(This, maxDrawTime)= (jint)1000;
  159. JCGO_FIELD_NZACCESS(This, timings)= (jlongArr)jcgo_newArray(JCGO_CORECLASS_FOR(OBJT_jlong),
  160. @@ -507,6 +646,34 @@
  161. package_GameShell__run__( package_GameShell This )
  162. {
  163. {
  164. + jint width = JCGO_FIELD_NZACCESS(This, appletWidth);
  165. + jint height = JCGO_FIELD_NZACCESS(This, appletHeight) + 2;
  166. +
  167. + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
  168. + fprintf(stderr, "SDL_Init(): %s\n", SDL_GetError());
  169. + exit(1);
  170. + }
  171. +
  172. + wanted_audio.freq = 8000;
  173. + wanted_audio.format = AUDIO_S16;
  174. + wanted_audio.channels = 1;
  175. + wanted_audio.silence = 0;
  176. + wanted_audio.samples = 1024;
  177. + wanted_audio.callback = NULL;
  178. +
  179. + if (SDL_OpenAudio(&wanted_audio, NULL) < 0) {
  180. + fprintf(stderr, "SDL_OpenAudio(): %s\n", SDL_GetError());
  181. + exit(1);
  182. + }
  183. +
  184. + SDL_PauseAudio(0);
  185. +
  186. + window = SDL_CreateWindow("Runescape by Andrew Gower", SDL_WINDOWPOS_CENTERED,
  187. + SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_SHOWN);
  188. + screen = SDL_GetWindowSurface(window);
  189. + pixel_surface = SDL_CreateRGBSurface(0, width, height, 32, 0xff0000, 0x00ff00,
  190. + 0x0000ff, 0);
  191. +
  192. jint i;
  193. jint j;
  194. jint sleep;
  195. @@ -626,6 +793,7 @@
  196. while (i1 < (jint)256)
  197. {
  198. jint jcgo_rcvrI1;
  199. + handle_sdl_events(This);
  200. (JCGO_CALL_NZVFUNC(This)->handleInputs__(
  201. This));
  202. i1+= j;
  203. diff -uarN jcgo_Out/KeyEvent.h jcgo_Out_Patched/KeyEvent.h
  204. --- jcgo_Out/KeyEvent.h 2021-07-17 14:14:57.981183810 -0500
  205. +++ jcgo_Out_Patched/KeyEvent.h 2021-07-17 14:14:38.696958665 -0500
  206. @@ -2,21 +2,21 @@
  207. #ifdef JCGO_116
  208. -#define package_KeyEvent__VK_LEFT (-(jint)12345678L)
  209. +#define package_KeyEvent__VK_LEFT (37)
  210. -#define package_KeyEvent__VK_RIGHT (-(jint)12345678L)
  211. +#define package_KeyEvent__VK_RIGHT (39)
  212. -#define package_KeyEvent__VK_UP (-(jint)12345678L)
  213. +#define package_KeyEvent__VK_UP (38)
  214. -#define package_KeyEvent__VK_DOWN (-(jint)12345678L)
  215. +#define package_KeyEvent__VK_DOWN (40)
  216. -#define package_KeyEvent__VK_SPACE (-(jint)12345678L)
  217. +#define package_KeyEvent__VK_SPACE (SDLK_SPACE)
  218. -#define package_KeyEvent__VK_F1 (-(jint)12345678L)
  219. +#define package_KeyEvent__VK_F1 (SDL_SCANCODE_F1)
  220. -#define package_KeyEvent__VK_BACK_SPACE (-(jint)12345678L)
  221. +#define package_KeyEvent__VK_BACK_SPACE (SDLK_BACKSPACE)
  222. -#define package_KeyEvent__VK_ENTER (-(jint)12345678L)
  223. +#define package_KeyEvent__VK_ENTER (SDLK_RETURN)
  224. JCGO_NOSEP_STATIC package_KeyEvent CFASTCALL
  225. package_KeyEvent__this__( package_KeyEvent This );
  226. diff -uarN jcgo_Out/Main.c jcgo_Out_Patched/Main.c
  227. --- jcgo_Out/Main.c 2021-07-17 14:14:58.117185399 -0500
  228. +++ jcgo_Out_Patched/Main.c 2021-07-17 14:14:38.708958804 -0500
  229. @@ -1222,6 +1222,9 @@
  230. MAINENTRY
  231. ( int argc, JCGO_MAIN_TCHAR **targv )
  232. {
  233. +#ifdef __MINGW32__
  234. + putenv("SDL_AUDIODRIVER=DirectSound");
  235. +#endif
  236. JCGO_MAIN_LAUNCH(argc, targv);
  237. return 0;
  238. }
  239. diff -uarN jcgo_Out/Main.h jcgo_Out_Patched/Main.h
  240. --- jcgo_Out/Main.h 2021-07-17 14:14:58.057184698 -0500
  241. +++ jcgo_Out_Patched/Main.h 2021-07-17 14:14:38.724958991 -0500
  242. @@ -1557,4 +1557,16 @@
  243. JCGO_SEP_EXTERN CONST struct java_lang_Object_methods_s jObjectArr15_methods;
  244. JCGO_SEP_EXTERN CONST struct java_lang_Object_methods_s jObjectArr16_methods;
  245. +#define SDL_MAIN_HANDLED
  246. +
  247. +#include <SDL2/SDL.h>
  248. +
  249. +SDL_Window *window;
  250. +SDL_Surface *screen;
  251. +SDL_Surface *pixel_surface;
  252. +SDL_Event event;
  253. +SDL_AudioSpec wanted_audio;
  254. +
  255. +short pcm_out[1024 * 1024];
  256. +
  257. #endif
  258. diff -uarN jcgo_Out/StrmAdPl.c jcgo_Out_Patched/StrmAdPl.c
  259. --- jcgo_Out/StrmAdPl.c 2021-07-17 14:14:58.041184512 -0500
  260. +++ jcgo_Out_Patched/StrmAdPl.c 2021-07-17 14:14:38.724958991 -0500
  261. @@ -12,11 +12,33 @@
  262. #include "jcgobchk.h"
  263. #endif
  264. +#define SIGN_BIT (0x80) /* Sign bit for a A-law byte. */
  265. +#define QUANT_MASK (0xf) /* Quantization field mask. */
  266. +#define SEG_SHIFT (4) /* Left shift for segment number. */
  267. +#define SEG_MASK (0x70) /* Segment field mask. */
  268. +#define BIAS (0x84) /* Bias for linear code (for u-law). */
  269. +
  270. +int ulaw2linear(long size, unsigned char *u_ptr, short *out_ptr) {
  271. + short t;
  272. + unsigned char u_val;
  273. +
  274. + for (long i=0; i< size; i++) {
  275. + u_val = ~(*u_ptr);
  276. + u_ptr++;
  277. + t = ((u_val & QUANT_MASK) << 3) + BIAS;
  278. + t <<= ((unsigned)u_val & SEG_MASK) >> SEG_SHIFT;
  279. + *out_ptr++ = ((u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS));
  280. + }
  281. +
  282. + return 0;
  283. +}
  284. +
  285. JCGO_NOSEP_FRWINL void CFASTCALL
  286. package_StreamAudioPlayer__stopPlayer__( package_StreamAudioPlayer
  287. This )
  288. {
  289. {
  290. + SDL_PauseAudio(1);
  291. }
  292. }
  293. @@ -26,6 +48,14 @@
  294. {
  295. JCGO_SYNC_BLOCKSAFENZ(This)
  296. {
  297. + unsigned char ulaw[len];
  298. +
  299. + for (int i = 0; i < len; i += 1) {
  300. + ulaw[i] = JCGO_ARRAY_BACCESS(buff, i + off);
  301. + }
  302. +
  303. + ulaw2linear(len, ulaw, pcm_out);
  304. + SDL_QueueAudio(1, pcm_out, len * 2);
  305. }
  306. JCGO_SYNC_END
  307. }
  308. diff -uarN jcgo_Out/Surface.c jcgo_Out_Patched/Surface.c
  309. --- jcgo_Out/Surface.c 2021-07-17 14:14:58.025184324 -0500
  310. +++ jcgo_Out_Patched/Surface.c 2021-07-17 14:14:38.716958898 -0500
  311. @@ -786,6 +786,17 @@
  312. {
  313. (package_Surface__setcomplete__(
  314. This));
  315. +
  316. + if (!window) {
  317. + return;
  318. + }
  319. +
  320. + jint* pixel_bytes = (jint*) JCGO_FIELD_NZACCESS(This, pixels);
  321. + jint area = JCGO_FIELD_NZACCESS(This, width2) * JCGO_FIELD_NZACCESS(This,
  322. + height2);
  323. + memcpy(pixel_surface->pixels, pixel_bytes + 5, area * sizeof(jint));
  324. + SDL_BlitSurface(pixel_surface, NULL, screen, NULL);
  325. + SDL_UpdateWindowSurface(window);
  326. }
  327. }