converting C++ typedef to nim-lang

2022-12-20 Thread nospher
About C int to a pointer i only following the code :c. About cint/cfloat THANKS 
fixed <33


converting C++ typedef to nim-lang

2022-12-20 Thread sls1005
Try using `cint`/`cfloat` instead of `int`/`float`. Their sizes are usually not 
the same, which is easily to cause bugs. Also I cannot understand why to cast a 
C int into a pointer.


converting C++ typedef to nim-lang

2022-12-19 Thread nospher
I have this code in C++ works without problem. but when i transpiled to 
nim-lang i crashed all times.


DWORD* floatingEnumInstance = *reinterpret_cast(base_address + 
0x24FB358);
typedef int(__thiscall* FloatingTextGetTextType)(DWORD* 
floatingEnumInstance,int textType);
FloatingTextGetTextType getFloatingTextType = 
*reinterpret_cast(base_address + 0x5FBDD0);
int* textType = (int*)getFloatingTextType(floatingEnumInstance, 1);

DWORD* floatingTextInstance = 
*reinterpret_cast(base_address + 0x24FB354);
typedef void(__thiscall* FloatingTextAddInternalLine)(
DWORD* floatingTextInstance,
core::game_object* object,
int* textType,
const char* msg, float, int, int animType, DWORD);
FloatingTextAddInternalLine showFloatingText = 
*reinterpret_cast(base_address + 0x5F1E50);

showFloatingText(
floatingTextInstance,
game->local_player,
textType,
"hello",
0.0f,
0,
0,
0
);


Run

My actual nim code


type
cstringConstImpl {.importcpp:"const char*".} = cstring
constChar* = distinct cstringConstImpl
  
  let floatingEnumInstance = cast[ptr ByteAddress](address + 0x24FB358)[]
  type FloatingTextGetType = proc(floatingEnumInstance: ByteAddress, 
textType: int): int {.gcsafe, thiscall.}
  let getFloatingTextType = cast[FloatingTextGetType](address + 0x5FBDD0)
  let textType = cast[uint](getFloatingTextType(floatingEnumInstance, 1))
  
  let floatingTextManagerInstance = cast[ptr ByteAddress](address + 
0x24FB354)[]
  type FloatingTextAddInternalLine = proc(
floatingTextInstance: ByteAddress,
target: ByteAddress,
textType: uint,
text: constChar,
idk1: float,
idk2: int,
animationType: int,
instance2: DWORD
  ): void {.gcsafe, thiscall.}
  let showFloatingTextFunction = cast[FloatingTextAddInternalLine](address 
+ 0x5F1E50)
  showFloatingTextFunction(floatingTextManagerInstance, cast[ptr 
ByteAddress](self.localPlayer)[], textType, constChar("hello"), 0.0,0,0,0)


Run

When i execute C++ code works without problem but nim code is crashing :/